diff options
Diffstat (limited to 'patch-remap/mache-vineflower/net/minecraft/world/level/block/FarmBlock.java.patch')
-rw-r--r-- | patch-remap/mache-vineflower/net/minecraft/world/level/block/FarmBlock.java.patch | 211 |
1 files changed, 211 insertions, 0 deletions
diff --git a/patch-remap/mache-vineflower/net/minecraft/world/level/block/FarmBlock.java.patch b/patch-remap/mache-vineflower/net/minecraft/world/level/block/FarmBlock.java.patch new file mode 100644 index 0000000000..c4f556126e --- /dev/null +++ b/patch-remap/mache-vineflower/net/minecraft/world/level/block/FarmBlock.java.patch @@ -0,0 +1,211 @@ +--- a/net/minecraft/world/level/block/FarmBlock.java ++++ b/net/minecraft/world/level/block/FarmBlock.java +@@ -1,6 +1,7 @@ + package net.minecraft.world.level.block; + + import com.mojang.serialization.MapCodec; ++import java.util.Iterator; + import javax.annotation.Nullable; + import net.minecraft.core.BlockPos; + import net.minecraft.core.Direction; +@@ -19,101 +20,128 @@ + import net.minecraft.world.level.LevelReader; + import net.minecraft.world.level.block.piston.MovingPistonBlock; + import net.minecraft.world.level.block.state.BlockBehaviour; +-import net.minecraft.world.level.block.state.BlockState; ++import net.minecraft.world.level.block.state.IBlockData; + import net.minecraft.world.level.block.state.StateDefinition; + import net.minecraft.world.level.block.state.properties.BlockStateProperties; + import net.minecraft.world.level.block.state.properties.IntegerProperty; + import net.minecraft.world.level.gameevent.GameEvent; +-import net.minecraft.world.level.pathfinder.PathComputationType; ++import net.minecraft.world.level.pathfinder.PathMode; + import net.minecraft.world.phys.shapes.CollisionContext; + import net.minecraft.world.phys.shapes.VoxelShape; ++// CraftBukkit start ++import org.bukkit.event.entity.EntityInteractEvent; ++import org.bukkit.craftbukkit.event.CraftEventFactory; ++// CraftBukkit end + + public class FarmBlock extends Block { ++ + public static final MapCodec<FarmBlock> CODEC = simpleCodec(FarmBlock::new); + public static final IntegerProperty MOISTURE = BlockStateProperties.MOISTURE; +- protected static final VoxelShape SHAPE = Block.box(0.0, 0.0, 0.0, 16.0, 15.0, 16.0); ++ protected static final VoxelShape SHAPE = Block.box(0.0D, 0.0D, 0.0D, 16.0D, 15.0D, 16.0D); + public static final int MAX_MOISTURE = 7; + + @Override + public MapCodec<FarmBlock> codec() { +- return CODEC; ++ return FarmBlock.CODEC; + } + + protected FarmBlock(BlockBehaviour.Properties properties) { + super(properties); +- this.registerDefaultState(this.stateDefinition.any().setValue(MOISTURE, Integer.valueOf(0))); ++ this.registerDefaultState((IBlockData) ((IBlockData) this.stateDefinition.any()).setValue(FarmBlock.MOISTURE, 0)); + } + + @Override +- public BlockState updateShape(BlockState state, Direction facing, BlockState facingState, LevelAccessor level, BlockPos currentPos, BlockPos facingPos) { ++ public IBlockData updateShape(IBlockData state, Direction facing, IBlockData facingState, LevelAccessor level, BlockPos currentPos, BlockPos facingPos) { + if (facing == Direction.UP && !state.canSurvive(level, currentPos)) { +- level.scheduleTick(currentPos, this, 1); ++ level.scheduleTick(currentPos, (Block) this, 1); + } + + return super.updateShape(state, facing, facingState, level, currentPos, facingPos); + } + + @Override +- public boolean canSurvive(BlockState state, LevelReader level, BlockPos pos) { +- BlockState blockState = level.getBlockState(pos.above()); +- return !blockState.isSolid() || blockState.getBlock() instanceof FenceGateBlock || blockState.getBlock() instanceof MovingPistonBlock; ++ public boolean canSurvive(IBlockData state, LevelReader level, BlockPos pos) { ++ IBlockData iblockdata1 = level.getBlockState(pos.above()); ++ ++ return !iblockdata1.isSolid() || iblockdata1.getBlock() instanceof FenceGateBlock || iblockdata1.getBlock() instanceof MovingPistonBlock; + } + + @Override +- public BlockState getStateForPlacement(BlockPlaceContext context) { +- return !this.defaultBlockState().canSurvive(context.getLevel(), context.getClickedPos()) +- ? Blocks.DIRT.defaultBlockState() +- : super.getStateForPlacement(context); ++ public IBlockData getStateForPlacement(BlockPlaceContext context) { ++ return !this.defaultBlockState().canSurvive(context.getLevel(), context.getClickedPos()) ? Blocks.DIRT.defaultBlockState() : super.getStateForPlacement(context); + } + + @Override +- public boolean useShapeForLightOcclusion(BlockState state) { ++ public boolean useShapeForLightOcclusion(IBlockData state) { + return true; + } + + @Override +- public VoxelShape getShape(BlockState state, BlockGetter level, BlockPos pos, CollisionContext context) { +- return SHAPE; ++ public VoxelShape getShape(IBlockData state, BlockGetter level, BlockPos pos, CollisionContext context) { ++ return FarmBlock.SHAPE; + } + + @Override +- public void tick(BlockState state, ServerLevel level, BlockPos pos, RandomSource random) { ++ public void tick(IBlockData state, ServerLevel level, BlockPos pos, RandomSource random) { + if (!state.canSurvive(level, pos)) { +- turnToDirt(null, state, level, pos); ++ turnToDirt((Entity) null, state, level, pos); + } ++ + } + + @Override +- public void randomTick(BlockState state, ServerLevel level, BlockPos pos, RandomSource random) { +- int i = state.getValue(MOISTURE); ++ public void randomTick(IBlockData state, ServerLevel level, BlockPos pos, RandomSource random) { ++ int i = (Integer) state.getValue(FarmBlock.MOISTURE); ++ + if (!isNearWater(level, pos) && !level.isRainingAt(pos.above())) { + if (i > 0) { +- level.setBlock(pos, state.setValue(MOISTURE, Integer.valueOf(i - 1)), 2); ++ org.bukkit.craftbukkit.event.CraftEventFactory.handleMoistureChangeEvent(level, pos, (IBlockData) state.setValue(FarmBlock.MOISTURE, i - 1), 2); // CraftBukkit + } else if (!shouldMaintainFarmland(level, pos)) { +- turnToDirt(null, state, level, pos); ++ turnToDirt((Entity) null, state, level, pos); + } + } else if (i < 7) { +- level.setBlock(pos, state.setValue(MOISTURE, Integer.valueOf(7)), 2); ++ org.bukkit.craftbukkit.event.CraftEventFactory.handleMoistureChangeEvent(level, pos, (IBlockData) state.setValue(FarmBlock.MOISTURE, 7), 2); // CraftBukkit + } ++ + } + + @Override +- public void fallOn(Level level, BlockState state, BlockPos pos, Entity entity, float fallDistance) { +- if (!level.isClientSide +- && level.random.nextFloat() < fallDistance - 0.5F +- && entity instanceof LivingEntity +- && (entity instanceof Player || level.getGameRules().getBoolean(GameRules.RULE_MOBGRIEFING)) +- && entity.getBbWidth() * entity.getBbWidth() * entity.getBbHeight() > 0.512F) { ++ public void fallOn(Level level, IBlockData state, BlockPos pos, Entity entity, float fallDistance) { ++ super.fallOn(level, state, pos, entity, fallDistance); // CraftBukkit - moved here as game rules / events shouldn't affect fall damage. ++ if (!level.isClientSide && level.random.nextFloat() < fallDistance - 0.5F && entity instanceof LivingEntity && (entity instanceof Player || level.getGameRules().getBoolean(GameRules.RULE_MOBGRIEFING)) && entity.getBbWidth() * entity.getBbWidth() * entity.getBbHeight() > 0.512F) { ++ // CraftBukkit start - Interact soil ++ org.bukkit.event.Cancellable cancellable; ++ if (entity instanceof Player) { ++ cancellable = CraftEventFactory.callPlayerInteractEvent((Player) entity, org.bukkit.event.block.Action.PHYSICAL, pos, null, null, null); ++ } else { ++ cancellable = new EntityInteractEvent(entity.getBukkitEntity(), level.getWorld().getBlockAt(pos.getX(), pos.getY(), pos.getZ())); ++ level.getCraftServer().getPluginManager().callEvent((EntityInteractEvent) cancellable); ++ } ++ ++ if (cancellable.isCancelled()) { ++ return; ++ } ++ ++ if (!CraftEventFactory.callEntityChangeBlockEvent(entity, pos, Blocks.DIRT.defaultBlockState())) { ++ return; ++ } ++ // CraftBukkit end + turnToDirt(entity, state, level, pos); + } + +- super.fallOn(level, state, pos, entity, fallDistance); ++ // super.fallOn(world, iblockdata, blockposition, entity, f); // CraftBukkit - moved up + } + +- public static void turnToDirt(@Nullable Entity entity, BlockState state, Level level, BlockPos pos) { +- BlockState blockState = pushEntitiesUp(state, Blocks.DIRT.defaultBlockState(), level, pos); +- level.setBlockAndUpdate(pos, blockState); +- level.gameEvent(GameEvent.BLOCK_CHANGE, pos, GameEvent.Context.of(entity, blockState)); ++ public static void turnToDirt(@Nullable Entity entity, IBlockData state, Level level, BlockPos pos) { ++ // CraftBukkit start ++ if (CraftEventFactory.callBlockFadeEvent(level, pos, Blocks.DIRT.defaultBlockState()).isCancelled()) { ++ return; ++ } ++ // CraftBukkit end ++ IBlockData iblockdata1 = pushEntitiesUp(state, Blocks.DIRT.defaultBlockState(), level, pos); ++ ++ level.setBlockAndUpdate(pos, iblockdata1); ++ level.gameEvent(GameEvent.BLOCK_CHANGE, pos, GameEvent.Context.of(entity, iblockdata1)); + } + + private static boolean shouldMaintainFarmland(BlockGetter level, BlockPos pos) { +@@ -121,22 +149,28 @@ + } + + private static boolean isNearWater(LevelReader level, BlockPos pos) { +- for (BlockPos blockPos : BlockPos.betweenClosed(pos.offset(-4, 0, -4), pos.offset(4, 1, 4))) { +- if (level.getFluidState(blockPos).is(FluidTags.WATER)) { +- return true; ++ Iterator iterator = BlockPos.betweenClosed(pos.offset(-4, 0, -4), pos.offset(4, 1, 4)).iterator(); ++ ++ BlockPos blockposition1; ++ ++ do { ++ if (!iterator.hasNext()) { ++ return false; + } +- } + +- return false; ++ blockposition1 = (BlockPos) iterator.next(); ++ } while (!level.getFluidState(blockposition1).is(FluidTags.WATER)); ++ ++ return true; + } + + @Override +- protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> builder) { +- builder.add(MOISTURE); ++ protected void createBlockStateDefinition(StateDefinition.Builder<Block, IBlockData> builder) { ++ builder.add(FarmBlock.MOISTURE); + } + + @Override +- public boolean isPathfindable(BlockState state, BlockGetter level, BlockPos pos, PathComputationType type) { ++ public boolean isPathfindable(IBlockData state, BlockGetter level, BlockPos pos, PathMode type) { + return false; + } + } |