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
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
|
--- a/net/minecraft/world/level/block/CarvedPumpkinBlock.java
+++ b/net/minecraft/world/level/block/CarvedPumpkinBlock.java
@@ -1,6 +1,7 @@
package net.minecraft.world.level.block;
import com.mojang.serialization.MapCodec;
+import java.util.Iterator;
import java.util.function.Predicate;
import javax.annotation.Nullable;
import net.minecraft.advancements.CriteriaTriggers;
@@ -15,15 +16,19 @@
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.pattern.BlockInWorld;
import net.minecraft.world.level.block.state.pattern.BlockPattern;
import net.minecraft.world.level.block.state.pattern.BlockPatternBuilder;
import net.minecraft.world.level.block.state.predicate.BlockStatePredicate;
import net.minecraft.world.level.block.state.properties.DirectionProperty;
+// CraftBukkit start
+import org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason;
+// CraftBukkit end
public class CarvedPumpkinBlock extends HorizontalDirectionalBlock {
+
public static final MapCodec<CarvedPumpkinBlock> CODEC = simpleCodec(CarvedPumpkinBlock::new);
public static final DirectionProperty FACING = HorizontalDirectionalBlock.FACING;
@Nullable
@@ -34,21 +39,22 @@
private BlockPattern ironGolemBase;
@Nullable
private BlockPattern ironGolemFull;
- private static final Predicate<BlockState> PUMPKINS_PREDICATE = state -> state != null
- && (state.is(Blocks.CARVED_PUMPKIN) || state.is(Blocks.JACK_O_LANTERN));
+ private static final Predicate<IBlockData> PUMPKINS_PREDICATE = (iblockdata) -> {
+ return iblockdata != null && (iblockdata.is(Blocks.CARVED_PUMPKIN) || iblockdata.is(Blocks.JACK_O_LANTERN));
+ };
@Override
public MapCodec<? extends CarvedPumpkinBlock> codec() {
- return CODEC;
+ return CarvedPumpkinBlock.CODEC;
}
protected CarvedPumpkinBlock(BlockBehaviour.Properties properties) {
super(properties);
- this.registerDefaultState(this.stateDefinition.any().setValue(FACING, Direction.NORTH));
+ this.registerDefaultState((IBlockData) ((IBlockData) this.stateDefinition.any()).setValue(CarvedPumpkinBlock.FACING, Direction.NORTH));
}
@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())) {
this.trySpawnGolem(level, pos);
}
@@ -59,71 +65,85 @@
}
private void trySpawnGolem(Level level, BlockPos pos) {
- BlockPattern.BlockPatternMatch blockPatternMatch = this.getOrCreateSnowGolemFull().find(level, pos);
- if (blockPatternMatch != null) {
- SnowGolem snowGolem = EntityType.SNOW_GOLEM.create(level);
- if (snowGolem != null) {
- spawnGolemInWorld(level, blockPatternMatch, snowGolem, blockPatternMatch.getBlock(0, 2, 0).getPos());
+ BlockPattern.BlockPatternMatch shapedetector_shapedetectorcollection = this.getOrCreateSnowGolemFull().find(level, pos);
+
+ if (shapedetector_shapedetectorcollection != null) {
+ SnowGolem entitysnowman = (SnowGolem) EntityType.SNOW_GOLEM.create(level);
+
+ if (entitysnowman != null) {
+ spawnGolemInWorld(level, shapedetector_shapedetectorcollection, entitysnowman, shapedetector_shapedetectorcollection.getBlock(0, 2, 0).getPos());
}
} else {
- BlockPattern.BlockPatternMatch blockPatternMatch1 = this.getOrCreateIronGolemFull().find(level, pos);
- if (blockPatternMatch1 != null) {
- IronGolem ironGolem = EntityType.IRON_GOLEM.create(level);
- if (ironGolem != null) {
- ironGolem.setPlayerCreated(true);
- spawnGolemInWorld(level, blockPatternMatch1, ironGolem, blockPatternMatch1.getBlock(1, 2, 0).getPos());
+ BlockPattern.BlockPatternMatch shapedetector_shapedetectorcollection1 = this.getOrCreateIronGolemFull().find(level, pos);
+
+ if (shapedetector_shapedetectorcollection1 != null) {
+ IronGolem entityirongolem = (IronGolem) EntityType.IRON_GOLEM.create(level);
+
+ if (entityirongolem != null) {
+ entityirongolem.setPlayerCreated(true);
+ spawnGolemInWorld(level, shapedetector_shapedetectorcollection1, entityirongolem, shapedetector_shapedetectorcollection1.getBlock(1, 2, 0).getPos());
}
}
}
+
}
private static void spawnGolemInWorld(Level level, BlockPattern.BlockPatternMatch patternMatch, Entity golem, BlockPos pos) {
- clearPatternBlocks(level, patternMatch);
- golem.moveTo((double)pos.getX() + 0.5, (double)pos.getY() + 0.05, (double)pos.getZ() + 0.5, 0.0F, 0.0F);
- level.addFreshEntity(golem);
+ // clearPatternBlocks(world, shapedetector_shapedetectorcollection); // CraftBukkit - moved down
+ golem.moveTo((double) pos.getX() + 0.5D, (double) pos.getY() + 0.05D, (double) pos.getZ() + 0.5D, 0.0F, 0.0F);
+ // CraftBukkit start
+ if (!level.addFreshEntity(golem, SpawnReason.BUILD_IRONGOLEM)) {
+ return;
+ }
+ clearPatternBlocks(level, patternMatch); // CraftBukkit - from above
+ // CraftBukkit end
+ Iterator iterator = level.getEntitiesOfClass(ServerPlayer.class, golem.getBoundingBox().inflate(5.0D)).iterator();
- for (ServerPlayer serverPlayer : level.getEntitiesOfClass(ServerPlayer.class, golem.getBoundingBox().inflate(5.0))) {
- CriteriaTriggers.SUMMONED_ENTITY.trigger(serverPlayer, golem);
+ while (iterator.hasNext()) {
+ ServerPlayer entityplayer = (ServerPlayer) iterator.next();
+
+ CriteriaTriggers.SUMMONED_ENTITY.trigger(entityplayer, golem);
}
updatePatternBlocks(level, patternMatch);
}
public static void clearPatternBlocks(Level level, BlockPattern.BlockPatternMatch patternMatch) {
- for (int i = 0; i < patternMatch.getWidth(); i++) {
- for (int i1 = 0; i1 < patternMatch.getHeight(); i1++) {
- BlockInWorld block = patternMatch.getBlock(i, i1, 0);
- level.setBlock(block.getPos(), Blocks.AIR.defaultBlockState(), 2);
- level.levelEvent(2001, block.getPos(), Block.getId(block.getState()));
+ for (int i = 0; i < patternMatch.getWidth(); ++i) {
+ for (int j = 0; j < patternMatch.getHeight(); ++j) {
+ BlockInWorld shapedetectorblock = patternMatch.getBlock(i, j, 0);
+
+ level.setBlock(shapedetectorblock.getPos(), Blocks.AIR.defaultBlockState(), 2);
+ level.levelEvent(2001, shapedetectorblock.getPos(), Block.getId(shapedetectorblock.getState()));
}
}
+
}
public static void updatePatternBlocks(Level level, BlockPattern.BlockPatternMatch patternMatch) {
- for (int i = 0; i < patternMatch.getWidth(); i++) {
- for (int i1 = 0; i1 < patternMatch.getHeight(); i1++) {
- BlockInWorld block = patternMatch.getBlock(i, i1, 0);
- level.blockUpdated(block.getPos(), Blocks.AIR);
+ for (int i = 0; i < patternMatch.getWidth(); ++i) {
+ for (int j = 0; j < patternMatch.getHeight(); ++j) {
+ BlockInWorld shapedetectorblock = patternMatch.getBlock(i, j, 0);
+
+ level.blockUpdated(shapedetectorblock.getPos(), Blocks.AIR);
}
}
+
}
@Override
- public BlockState getStateForPlacement(BlockPlaceContext context) {
- return this.defaultBlockState().setValue(FACING, context.getHorizontalDirection().getOpposite());
+ public IBlockData getStateForPlacement(BlockPlaceContext context) {
+ return (IBlockData) this.defaultBlockState().setValue(CarvedPumpkinBlock.FACING, context.getHorizontalDirection().getOpposite());
}
@Override
- protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> builder) {
- builder.add(FACING);
+ protected void createBlockStateDefinition(StateDefinition.Builder<Block, IBlockData> builder) {
+ builder.add(CarvedPumpkinBlock.FACING);
}
private BlockPattern getOrCreateSnowGolemBase() {
if (this.snowGolemBase == null) {
- this.snowGolemBase = BlockPatternBuilder.start()
- .aisle(" ", "#", "#")
- .where('#', BlockInWorld.hasState(BlockStatePredicate.forBlock(Blocks.SNOW_BLOCK)))
- .build();
+ this.snowGolemBase = BlockPatternBuilder.start().aisle(" ", "#", "#").where('#', BlockInWorld.hasState(BlockStatePredicate.forBlock(Blocks.SNOW_BLOCK))).build();
}
return this.snowGolemBase;
@@ -131,11 +151,7 @@
private BlockPattern getOrCreateSnowGolemFull() {
if (this.snowGolemFull == null) {
- this.snowGolemFull = BlockPatternBuilder.start()
- .aisle("^", "#", "#")
- .where('^', BlockInWorld.hasState(PUMPKINS_PREDICATE))
- .where('#', BlockInWorld.hasState(BlockStatePredicate.forBlock(Blocks.SNOW_BLOCK)))
- .build();
+ this.snowGolemFull = BlockPatternBuilder.start().aisle("^", "#", "#").where('^', BlockInWorld.hasState(CarvedPumpkinBlock.PUMPKINS_PREDICATE)).where('#', BlockInWorld.hasState(BlockStatePredicate.forBlock(Blocks.SNOW_BLOCK))).build();
}
return this.snowGolemFull;
@@ -143,11 +159,9 @@
private BlockPattern getOrCreateIronGolemBase() {
if (this.ironGolemBase == null) {
- this.ironGolemBase = BlockPatternBuilder.start()
- .aisle("~ ~", "###", "~#~")
- .where('#', BlockInWorld.hasState(BlockStatePredicate.forBlock(Blocks.IRON_BLOCK)))
- .where('~', block -> block.getState().isAir())
- .build();
+ this.ironGolemBase = BlockPatternBuilder.start().aisle("~ ~", "###", "~#~").where('#', BlockInWorld.hasState(BlockStatePredicate.forBlock(Blocks.IRON_BLOCK))).where('~', (shapedetectorblock) -> {
+ return shapedetectorblock.getState().isAir();
+ }).build();
}
return this.ironGolemBase;
@@ -155,12 +169,9 @@
private BlockPattern getOrCreateIronGolemFull() {
if (this.ironGolemFull == null) {
- this.ironGolemFull = BlockPatternBuilder.start()
- .aisle("~^~", "###", "~#~")
- .where('^', BlockInWorld.hasState(PUMPKINS_PREDICATE))
- .where('#', BlockInWorld.hasState(BlockStatePredicate.forBlock(Blocks.IRON_BLOCK)))
- .where('~', block -> block.getState().isAir())
- .build();
+ this.ironGolemFull = BlockPatternBuilder.start().aisle("~^~", "###", "~#~").where('^', BlockInWorld.hasState(CarvedPumpkinBlock.PUMPKINS_PREDICATE)).where('#', BlockInWorld.hasState(BlockStatePredicate.forBlock(Blocks.IRON_BLOCK))).where('~', (shapedetectorblock) -> {
+ return shapedetectorblock.getState().isAir();
+ }).build();
}
return this.ironGolemFull;
|