1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
|
--- a/net/minecraft/world/level/block/TntBlock.java
+++ b/net/minecraft/world/level/block/TntBlock.java
@@ -6,7 +6,7 @@
import net.minecraft.sounds.SoundEvents;
import net.minecraft.sounds.SoundSource;
import net.minecraft.stats.Stats;
-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.LivingEntity;
@@ -19,93 +19,109 @@
import net.minecraft.world.level.Explosion;
import net.minecraft.world.level.Level;
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.BooleanProperty;
import net.minecraft.world.level.gameevent.GameEvent;
import net.minecraft.world.phys.BlockHitResult;
+// CraftBukkit start
+import org.bukkit.craftbukkit.event.CraftEventFactory;
+import org.bukkit.event.block.TNTPrimeEvent.PrimeCause;
+// CraftBukkit end
public class TntBlock extends Block {
+
public static final MapCodec<TntBlock> CODEC = simpleCodec(TntBlock::new);
public static final BooleanProperty UNSTABLE = BlockStateProperties.UNSTABLE;
@Override
public MapCodec<TntBlock> codec() {
- return CODEC;
+ return TntBlock.CODEC;
}
public TntBlock(BlockBehaviour.Properties properties) {
super(properties);
- this.registerDefaultState(this.defaultBlockState().setValue(UNSTABLE, Boolean.valueOf(false)));
+ this.registerDefaultState((IBlockData) this.defaultBlockState().setValue(TntBlock.UNSTABLE, false));
}
@Override
- public void onPlace(BlockState state, Level level, BlockPos pos, BlockState oldState, boolean isMoving) {
+ public void onPlace(IBlockData state, Level level, BlockPos pos, IBlockData oldState, boolean isMoving) {
if (!oldState.is(state.getBlock())) {
- if (level.hasNeighborSignal(pos)) {
+ if (level.hasNeighborSignal(pos) && CraftEventFactory.callTNTPrimeEvent(level, pos, PrimeCause.REDSTONE, null, null)) { // CraftBukkit - TNTPrimeEvent
explode(level, pos);
level.removeBlock(pos, false);
}
+
}
}
@Override
- public void neighborChanged(BlockState state, Level level, BlockPos pos, Block block, BlockPos fromPos, boolean isMoving) {
- if (level.hasNeighborSignal(pos)) {
+ public void neighborChanged(IBlockData state, Level level, BlockPos pos, Block block, BlockPos fromPos, boolean isMoving) {
+ if (level.hasNeighborSignal(pos) && CraftEventFactory.callTNTPrimeEvent(level, pos, PrimeCause.REDSTONE, null, fromPos)) { // CraftBukkit - TNTPrimeEvent
explode(level, pos);
level.removeBlock(pos, false);
}
+
}
@Override
- public BlockState playerWillDestroy(Level level, BlockPos blockPos, BlockState blockState, Player player) {
- if (!level.isClientSide() && !player.isCreative() && blockState.getValue(UNSTABLE)) {
- explode(level, blockPos);
+ public IBlockData playerWillDestroy(Level world, BlockPos blockposition, IBlockData iblockdata, Player entityhuman) {
+ if (!world.isClientSide() && !entityhuman.isCreative() && (Boolean) iblockdata.getValue(TntBlock.UNSTABLE) && CraftEventFactory.callTNTPrimeEvent(world, blockposition, PrimeCause.BLOCK_BREAK, entityhuman, null)) { // CraftBukkit - TNTPrimeEvent
+ explode(world, blockposition);
}
- return super.playerWillDestroy(level, blockPos, blockState, player);
+ return super.playerWillDestroy(world, blockposition, iblockdata, entityhuman);
}
@Override
public void wasExploded(Level level, BlockPos pos, Explosion explosion) {
if (!level.isClientSide) {
- PrimedTnt primedTnt = new PrimedTnt(
- level, (double)pos.getX() + 0.5, (double)pos.getY(), (double)pos.getZ() + 0.5, explosion.getIndirectSourceEntity()
- );
- int fuse = primedTnt.getFuse();
- primedTnt.setFuse((short)(level.random.nextInt(fuse / 4) + fuse / 8));
- level.addFreshEntity(primedTnt);
+ PrimedTnt entitytntprimed = new PrimedTnt(level, (double) pos.getX() + 0.5D, (double) pos.getY(), (double) pos.getZ() + 0.5D, explosion.getIndirectSourceEntity());
+ int i = entitytntprimed.getFuse();
+
+ entitytntprimed.setFuse((short) (level.random.nextInt(i / 4) + i / 8));
+ level.addFreshEntity(entitytntprimed);
}
}
public static void explode(Level level, BlockPos pos) {
- explode(level, pos, null);
+ explode(level, pos, (LivingEntity) null);
}
private static void explode(Level level, BlockPos pos, @Nullable LivingEntity entity) {
if (!level.isClientSide) {
- PrimedTnt primedTnt = new PrimedTnt(level, (double)pos.getX() + 0.5, (double)pos.getY(), (double)pos.getZ() + 0.5, entity);
- level.addFreshEntity(primedTnt);
- level.playSound(null, primedTnt.getX(), primedTnt.getY(), primedTnt.getZ(), SoundEvents.TNT_PRIMED, SoundSource.BLOCKS, 1.0F, 1.0F);
- level.gameEvent(entity, GameEvent.PRIME_FUSE, pos);
+ PrimedTnt entitytntprimed = new PrimedTnt(level, (double) pos.getX() + 0.5D, (double) pos.getY(), (double) pos.getZ() + 0.5D, entity);
+
+ level.addFreshEntity(entitytntprimed);
+ level.playSound((Player) null, entitytntprimed.getX(), entitytntprimed.getY(), entitytntprimed.getZ(), SoundEvents.TNT_PRIMED, SoundSource.BLOCKS, 1.0F, 1.0F);
+ level.gameEvent((Entity) entity, GameEvent.PRIME_FUSE, pos);
}
}
@Override
- public InteractionResult use(BlockState state, Level level, BlockPos pos, Player player, InteractionHand hand, BlockHitResult hit) {
- ItemStack itemInHand = player.getItemInHand(hand);
- if (!itemInHand.is(Items.FLINT_AND_STEEL) && !itemInHand.is(Items.FIRE_CHARGE)) {
+ public InteractionResult use(IBlockData state, Level level, BlockPos pos, Player player, EnumHand hand, BlockHitResult hit) {
+ ItemStack itemstack = player.getItemInHand(hand);
+
+ if (!itemstack.is(Items.FLINT_AND_STEEL) && !itemstack.is(Items.FIRE_CHARGE)) {
return super.use(state, level, pos, player, hand, hit);
} else {
+ // CraftBukkit start - TNTPrimeEvent
+ if (!CraftEventFactory.callTNTPrimeEvent(level, pos, PrimeCause.PLAYER, player, null)) {
+ return InteractionResult.CONSUME;
+ }
+ // CraftBukkit end
explode(level, pos, player);
level.setBlock(pos, Blocks.AIR.defaultBlockState(), 11);
- Item item = itemInHand.getItem();
+ Item item = itemstack.getItem();
+
if (!player.isCreative()) {
- if (itemInHand.is(Items.FLINT_AND_STEEL)) {
- itemInHand.hurtAndBreak(1, player, user -> user.broadcastBreakEvent(hand));
+ if (itemstack.is(Items.FLINT_AND_STEEL)) {
+ itemstack.hurtAndBreak(1, player, (entityhuman1) -> {
+ entityhuman1.broadcastBreakEvent(hand);
+ });
} else {
- itemInHand.shrink(1);
+ itemstack.shrink(1);
}
}
@@ -115,15 +131,22 @@
}
@Override
- public void onProjectileHit(Level level, BlockState state, BlockHitResult hit, Projectile projectile) {
+ public void onProjectileHit(Level level, IBlockData state, BlockHitResult hit, Projectile projectile) {
if (!level.isClientSide) {
- BlockPos blockPos = hit.getBlockPos();
- Entity owner = projectile.getOwner();
- if (projectile.isOnFire() && projectile.mayInteract(level, blockPos)) {
- explode(level, blockPos, owner instanceof LivingEntity ? (LivingEntity)owner : null);
- level.removeBlock(blockPos, false);
+ BlockPos blockposition = hit.getBlockPos();
+ Entity entity = projectile.getOwner();
+
+ if (projectile.isOnFire() && projectile.mayInteract(level, blockposition)) {
+ // CraftBukkit start
+ if (!org.bukkit.craftbukkit.event.CraftEventFactory.callEntityChangeBlockEvent(projectile, blockposition, Blocks.AIR.defaultBlockState()) || !CraftEventFactory.callTNTPrimeEvent(level, blockposition, PrimeCause.PROJECTILE, projectile, null)) {
+ return;
+ }
+ // CraftBukkit end
+ explode(level, blockposition, entity instanceof LivingEntity ? (LivingEntity) entity : null);
+ level.removeBlock(blockposition, false);
}
}
+
}
@Override
@@ -132,7 +155,7 @@
}
@Override
- protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> builder) {
- builder.add(UNSTABLE);
+ protected void createBlockStateDefinition(StateDefinition.Builder<Block, IBlockData> builder) {
+ builder.add(TntBlock.UNSTABLE);
}
}
|