|
13 | 13 | import net.minecraft.entity.LivingEntity; |
14 | 14 | import net.minecraft.entity.player.PlayerEntity; |
15 | 15 | import net.minecraft.item.ItemStack; |
16 | | -import net.minecraft.item.Items; |
17 | 16 | import net.minecraft.sound.SoundCategory; |
18 | 17 | import net.minecraft.sound.SoundEvents; |
19 | 18 | import net.minecraft.util.ActionResult; |
20 | | -import net.minecraft.util.Hand; |
21 | 19 | import net.minecraft.util.hit.BlockHitResult; |
22 | 20 | import net.minecraft.util.math.BlockPos; |
23 | 21 | import net.minecraft.util.math.Vec3d; |
24 | 22 | import net.minecraft.util.shape.VoxelShape; |
25 | 23 | import net.minecraft.world.BlockView; |
26 | 24 | import net.minecraft.world.World; |
27 | 25 | import net.minecraft.world.WorldView; |
| 26 | +import net.minecraft.world.event.GameEvent; |
28 | 27 |
|
29 | 28 | public class BrambleBerryBushBlock extends SweetBerryBushBlock { |
30 | 29 | private static final VoxelShape SMALL_SHAPE = Block.createCuboidShape(3.0D, 0.0D, 3.0D, 13.0D, 8.0D, 13.0D); |
@@ -65,20 +64,21 @@ public VoxelShape getOutlineShape(BlockState state, BlockView world, BlockPos po |
65 | 64 | } |
66 | 65 |
|
67 | 66 | @Override |
68 | | - public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) { |
69 | | - int i = state.get(AGE); |
70 | | - boolean bl = i == 3; |
71 | | - if (!bl && player.getStackInHand(hand).getItem() == Items.BONE_MEAL) { |
72 | | - return ActionResult.PASS; |
73 | | - } else if (i > 1) { |
74 | | - int j = 1 + world.random.nextInt(2); |
75 | | - dropStack(world, pos, new ItemStack(CinderscapesItems.BRAMBLE_BERRIES, j + (bl ? 1 : 0))); |
76 | | - world.playSound(null, pos, SoundEvents.BLOCK_SWEET_BERRY_BUSH_PICK_BERRIES, SoundCategory.BLOCKS, 1.0F, 0.8F + world.random.nextFloat() * 0.4F); |
77 | | - world.setBlockState(pos, state.with(AGE, 1), 2); |
78 | | - return ActionResult.SUCCESS; |
79 | | - } else { |
80 | | - return super.onUse(state, world, pos, player, hand, hit); |
| 67 | + public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, BlockHitResult hit) { |
| 68 | + int age = state.get(AGE); |
| 69 | + |
| 70 | + if (age > 1) { |
| 71 | + int count = age - 1 + world.random.nextInt(2); |
| 72 | + dropStack(world, pos, new ItemStack(CinderscapesItems.BRAMBLE_BERRIES, count)); |
| 73 | + world.playSound(null, pos, SoundEvents.BLOCK_SWEET_BERRY_BUSH_PICK_BERRIES, SoundCategory.BLOCKS, 1.0f, 0.8f + world.random.nextFloat() * 0.4f); |
| 74 | + BlockState newState = state.with(AGE, 1); |
| 75 | + world.setBlockState(pos, newState, 2); |
| 76 | + world.emitGameEvent(GameEvent.BLOCK_CHANGE, pos, GameEvent.Emitter.of(player, newState)); |
| 77 | + |
| 78 | + return ActionResult.success(world.isClient); |
81 | 79 | } |
| 80 | + |
| 81 | + return super.onUse(state, world, pos, player, hit); |
82 | 82 | } |
83 | 83 |
|
84 | 84 | @Override |
|
0 commit comments