diff options
Diffstat (limited to 'patch-remap/mache-vineflower/net/minecraft/world/level/block/SweetBerryBushBlock.java.patch')
-rw-r--r-- | patch-remap/mache-vineflower/net/minecraft/world/level/block/SweetBerryBushBlock.java.patch | 189 |
1 files changed, 189 insertions, 0 deletions
diff --git a/patch-remap/mache-vineflower/net/minecraft/world/level/block/SweetBerryBushBlock.java.patch b/patch-remap/mache-vineflower/net/minecraft/world/level/block/SweetBerryBushBlock.java.patch new file mode 100644 index 0000000000..5e553362ce --- /dev/null +++ b/patch-remap/mache-vineflower/net/minecraft/world/level/block/SweetBerryBushBlock.java.patch @@ -0,0 +1,189 @@ +--- a/net/minecraft/world/level/block/SweetBerryBushBlock.java ++++ b/net/minecraft/world/level/block/SweetBerryBushBlock.java +@@ -6,7 +6,7 @@ + import net.minecraft.sounds.SoundEvents; + import net.minecraft.sounds.SoundSource; + import net.minecraft.util.RandomSource; +-import net.minecraft.world.InteractionHand; ++import net.minecraft.world.EnumHand; + import net.minecraft.world.InteractionResult; + import net.minecraft.world.entity.Entity; + import net.minecraft.world.entity.EntityType; +@@ -18,7 +18,7 @@ + import net.minecraft.world.level.Level; + import net.minecraft.world.level.LevelReader; + 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; +@@ -27,81 +27,103 @@ + import net.minecraft.world.phys.Vec3; + import net.minecraft.world.phys.shapes.CollisionContext; + import net.minecraft.world.phys.shapes.VoxelShape; ++// CraftBukkit start ++import java.util.Collections; ++import org.bukkit.craftbukkit.block.CraftBlock; ++import org.bukkit.craftbukkit.event.CraftEventFactory; ++import org.bukkit.craftbukkit.inventory.CraftItemStack; ++import org.bukkit.event.player.PlayerHarvestBlockEvent; ++// CraftBukkit end + + public class SweetBerryBushBlock extends BushBlock implements BonemealableBlock { ++ + public static final MapCodec<SweetBerryBushBlock> CODEC = simpleCodec(SweetBerryBushBlock::new); + private static final float HURT_SPEED_THRESHOLD = 0.003F; + public static final int MAX_AGE = 3; + public static final IntegerProperty AGE = BlockStateProperties.AGE_3; +- private static final VoxelShape SAPLING_SHAPE = Block.box(3.0, 0.0, 3.0, 13.0, 8.0, 13.0); +- private static final VoxelShape MID_GROWTH_SHAPE = Block.box(1.0, 0.0, 1.0, 15.0, 16.0, 15.0); ++ private static final VoxelShape SAPLING_SHAPE = Block.box(3.0D, 0.0D, 3.0D, 13.0D, 8.0D, 13.0D); ++ private static final VoxelShape MID_GROWTH_SHAPE = Block.box(1.0D, 0.0D, 1.0D, 15.0D, 16.0D, 15.0D); + + @Override + public MapCodec<SweetBerryBushBlock> codec() { +- return CODEC; ++ return SweetBerryBushBlock.CODEC; + } + + public SweetBerryBushBlock(BlockBehaviour.Properties properties) { + super(properties); +- this.registerDefaultState(this.stateDefinition.any().setValue(AGE, Integer.valueOf(0))); ++ this.registerDefaultState((IBlockData) ((IBlockData) this.stateDefinition.any()).setValue(SweetBerryBushBlock.AGE, 0)); + } + + @Override +- public ItemStack getCloneItemStack(LevelReader levelReader, BlockPos blockPos, BlockState blockState) { ++ public ItemStack getCloneItemStack(LevelReader iworldreader, BlockPos blockposition, IBlockData iblockdata) { + return new ItemStack(Items.SWEET_BERRIES); + } + + @Override +- public VoxelShape getShape(BlockState state, BlockGetter level, BlockPos pos, CollisionContext context) { +- if (state.getValue(AGE) == 0) { +- return SAPLING_SHAPE; +- } else { +- return state.getValue(AGE) < 3 ? MID_GROWTH_SHAPE : super.getShape(state, level, pos, context); +- } ++ public VoxelShape getShape(IBlockData state, BlockGetter level, BlockPos pos, CollisionContext context) { ++ return (Integer) state.getValue(SweetBerryBushBlock.AGE) == 0 ? SweetBerryBushBlock.SAPLING_SHAPE : ((Integer) state.getValue(SweetBerryBushBlock.AGE) < 3 ? SweetBerryBushBlock.MID_GROWTH_SHAPE : super.getShape(state, level, pos, context)); + } + + @Override +- public boolean isRandomlyTicking(BlockState state) { +- return state.getValue(AGE) < 3; ++ public boolean isRandomlyTicking(IBlockData state) { ++ return (Integer) state.getValue(SweetBerryBushBlock.AGE) < 3; + } + + @Override +- public void randomTick(BlockState state, ServerLevel level, BlockPos pos, RandomSource random) { +- int i = state.getValue(AGE); ++ public void randomTick(IBlockData state, ServerLevel level, BlockPos pos, RandomSource random) { ++ int i = (Integer) state.getValue(SweetBerryBushBlock.AGE); ++ + if (i < 3 && random.nextInt(5) == 0 && level.getRawBrightness(pos.above(), 0) >= 9) { +- BlockState blockState = state.setValue(AGE, Integer.valueOf(i + 1)); +- level.setBlock(pos, blockState, 2); +- level.gameEvent(GameEvent.BLOCK_CHANGE, pos, GameEvent.Context.of(blockState)); ++ IBlockData iblockdata1 = (IBlockData) state.setValue(SweetBerryBushBlock.AGE, i + 1); ++ ++ if (!CraftEventFactory.handleBlockGrowEvent(level, pos, iblockdata1, 2)) return; // CraftBukkit ++ level.gameEvent(GameEvent.BLOCK_CHANGE, pos, GameEvent.Context.of(iblockdata1)); + } ++ + } + + @Override +- public void entityInside(BlockState state, Level level, BlockPos pos, Entity entity) { ++ public void entityInside(IBlockData state, Level level, BlockPos pos, Entity entity) { + if (entity instanceof LivingEntity && entity.getType() != EntityType.FOX && entity.getType() != EntityType.BEE) { +- entity.makeStuckInBlock(state, new Vec3(0.8F, 0.75, 0.8F)); +- if (!level.isClientSide && state.getValue(AGE) > 0 && (entity.xOld != entity.getX() || entity.zOld != entity.getZ())) { +- double abs = Math.abs(entity.getX() - entity.xOld); +- double abs1 = Math.abs(entity.getZ() - entity.zOld); +- if (abs >= 0.003F || abs1 >= 0.003F) { ++ entity.makeStuckInBlock(state, new Vec3(0.800000011920929D, 0.75D, 0.800000011920929D)); ++ if (!level.isClientSide && (Integer) state.getValue(SweetBerryBushBlock.AGE) > 0 && (entity.xOld != entity.getX() || entity.zOld != entity.getZ())) { ++ double d0 = Math.abs(entity.getX() - entity.xOld); ++ double d1 = Math.abs(entity.getZ() - entity.zOld); ++ ++ if (d0 >= 0.003000000026077032D || d1 >= 0.003000000026077032D) { ++ CraftEventFactory.blockDamage = CraftBlock.at(level, pos); // CraftBukkit + entity.hurt(level.damageSources().sweetBerryBush(), 1.0F); ++ CraftEventFactory.blockDamage = null; // CraftBukkit + } + } ++ + } + } + + @Override +- public InteractionResult use(BlockState state, Level level, BlockPos pos, Player player, InteractionHand hand, BlockHitResult hit) { +- int i = state.getValue(AGE); ++ public InteractionResult use(IBlockData state, Level level, BlockPos pos, Player player, EnumHand hand, BlockHitResult hit) { ++ int i = (Integer) state.getValue(SweetBerryBushBlock.AGE); + boolean flag = i == 3; ++ + if (!flag && player.getItemInHand(hand).is(Items.BONE_MEAL)) { + return InteractionResult.PASS; + } else if (i > 1) { +- int i1 = 1 + level.random.nextInt(2); +- popResource(level, pos, new ItemStack(Items.SWEET_BERRIES, i1 + (flag ? 1 : 0))); +- level.playSound(null, pos, SoundEvents.SWEET_BERRY_BUSH_PICK_BERRIES, SoundSource.BLOCKS, 1.0F, 0.8F + level.random.nextFloat() * 0.4F); +- BlockState blockState = state.setValue(AGE, Integer.valueOf(1)); +- level.setBlock(pos, blockState, 2); +- level.gameEvent(GameEvent.BLOCK_CHANGE, pos, GameEvent.Context.of(player, blockState)); ++ int j = 1 + level.random.nextInt(2); ++ ++ // CraftBukkit start ++ PlayerHarvestBlockEvent event = CraftEventFactory.callPlayerHarvestBlockEvent(level, pos, player, hand, Collections.singletonList(new ItemStack(Items.SWEET_BERRIES, j + (flag ? 1 : 0)))); ++ if (event.isCancelled()) { ++ return InteractionResult.SUCCESS; // We need to return a success either way, because making it PASS or FAIL will result in a bug where cancelling while harvesting w/ block in hand places block ++ } ++ for (org.bukkit.inventory.ItemStack itemStack : event.getItemsHarvested()) { ++ popResource(level, pos, CraftItemStack.asNMSCopy(itemStack)); ++ } ++ // CraftBukkit end ++ level.playSound((Player) null, pos, SoundEvents.SWEET_BERRY_BUSH_PICK_BERRIES, SoundSource.BLOCKS, 1.0F, 0.8F + level.random.nextFloat() * 0.4F); ++ IBlockData iblockdata1 = (IBlockData) state.setValue(SweetBerryBushBlock.AGE, 1); ++ ++ level.setBlock(pos, iblockdata1, 2); ++ level.gameEvent(GameEvent.BLOCK_CHANGE, pos, GameEvent.Context.of(player, iblockdata1)); + return InteractionResult.sidedSuccess(level.isClientSide); + } else { + return super.use(state, level, pos, player, hand, hit); +@@ -109,23 +131,24 @@ + } + + @Override +- protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> builder) { +- builder.add(AGE); ++ protected void createBlockStateDefinition(StateDefinition.Builder<Block, IBlockData> builder) { ++ builder.add(SweetBerryBushBlock.AGE); + } + + @Override +- public boolean isValidBonemealTarget(LevelReader levelReader, BlockPos blockPos, BlockState blockState) { +- return blockState.getValue(AGE) < 3; ++ public boolean isValidBonemealTarget(LevelReader iworldreader, BlockPos blockposition, IBlockData iblockdata) { ++ return (Integer) iblockdata.getValue(SweetBerryBushBlock.AGE) < 3; + } + + @Override +- public boolean isBonemealSuccess(Level level, RandomSource random, BlockPos pos, BlockState state) { ++ public boolean isBonemealSuccess(Level level, RandomSource random, BlockPos pos, IBlockData state) { + return true; + } + + @Override +- public void performBonemeal(ServerLevel level, RandomSource random, BlockPos pos, BlockState state) { +- int min = Math.min(3, state.getValue(AGE) + 1); +- level.setBlock(pos, state.setValue(AGE, Integer.valueOf(min)), 2); ++ public void performBonemeal(ServerLevel level, RandomSource random, BlockPos pos, IBlockData state) { ++ int i = Math.min(3, (Integer) state.getValue(SweetBerryBushBlock.AGE) + 1); ++ ++ level.setBlock(pos, (IBlockData) state.setValue(SweetBerryBushBlock.AGE, i), 2); + } + } |