1
1
package world .bentobox .caveblock .generators .populators ;
2
2
3
3
4
+ import java .util .Arrays ;
5
+ import java .util .EnumMap ;
6
+ import java .util .HashMap ;
7
+ import java .util .List ;
8
+ import java .util .Map ;
9
+ import java .util .Random ;
10
+ import java .util .stream .Collectors ;
11
+
4
12
import org .bukkit .Location ;
5
13
import org .bukkit .Material ;
6
14
import org .bukkit .World .Environment ;
7
15
import org .bukkit .entity .Entity ;
8
16
import org .bukkit .entity .EntityType ;
9
17
import org .bukkit .entity .LivingEntity ;
18
+ import org .bukkit .entity .WaterMob ;
10
19
import org .bukkit .generator .BlockPopulator ;
11
20
import org .bukkit .generator .LimitedRegion ;
12
21
import org .bukkit .generator .WorldInfo ;
17
26
import world .bentobox .caveblock .CaveBlock ;
18
27
import world .bentobox .caveblock .Utils ;
19
28
20
- import java .util .*;
21
- import java .util .stream .Collectors ;
22
-
23
29
/**
24
30
* This class populates generated chunk with entities by random chance.
25
31
*/
@@ -29,17 +35,6 @@ public class EntitiesPopulator extends BlockPopulator {
29
35
// Section: Variables
30
36
// ---------------------------------------------------------------------
31
37
32
- /**
33
- * Water entities
34
- */
35
- private static final List <EntityType > WATER_ENTITIES = Arrays .asList (EntityType .GUARDIAN ,
36
- EntityType .SQUID ,
37
- EntityType .COD ,
38
- EntityType .SALMON ,
39
- EntityType .PUFFERFISH ,
40
- EntityType .TROPICAL_FISH ,
41
- EntityType .DROWNED ,
42
- EntityType .DOLPHIN );
43
38
/**
44
39
* CaveBlock addon.
45
40
*/
@@ -170,12 +165,16 @@ private void tryToPlaceEntity(WorldInfo worldInfo, Location location, LimitedReg
170
165
if (!limitedRegion .isInRegion (location )) return ;
171
166
if (!limitedRegion .getType (location ).equals (originalMaterial )) return ;
172
167
173
- BoundingBox bb = this .getEntityBoundingBox (entityType , location );
168
+ // Spawn the entity and then make space for it
169
+ Entity entity = limitedRegion .spawnEntity (location , entityType );
170
+ BoundingBox bb = entity .getBoundingBox ();
174
171
175
172
for (int x = (int ) Math .floor (bb .getMinX ()); x < bb .getMaxX (); x ++) {
176
173
for (int z = (int ) Math .floor (bb .getMinZ ()); z < bb .getMaxZ (); z ++) {
177
174
int y = (int ) Math .floor (bb .getMinY ());
178
175
if (!limitedRegion .isInRegion (x , y , z )) {
176
+ // Only spawn if it's in the region
177
+ entity .remove ();
179
178
return ;
180
179
}
181
180
@@ -186,96 +185,26 @@ private void tryToPlaceEntity(WorldInfo worldInfo, Location location, LimitedReg
186
185
187
186
if (!limitedRegion .isInRegion (x , y , z ) || !limitedRegion .getType (x , y , z ).equals (originalMaterial )) {
188
187
// Cannot place entity
188
+ entity .remove ();
189
189
return ;
190
190
}
191
- limitedRegion .setType (x , y , z , WATER_ENTITIES . contains ( entityType ) ? Material .WATER : Material .AIR );
191
+ limitedRegion .setType (x , y , z , entity instanceof WaterMob ? Material .WATER : Material .AIR );
192
192
}
193
193
// Add air block on top for all water entities (required for dolphin, okay for others)
194
- if (WATER_ENTITIES .contains (entityType ) && limitedRegion .isInRegion (x , y , z ) && limitedRegion .getType (x , y , z ).equals (originalMaterial )) {
194
+ if (entity instanceof WaterMob && limitedRegion .isInRegion (x , y , z )
195
+ && limitedRegion .getType (x , y , z ).equals (originalMaterial )) {
195
196
limitedRegion .setType (x , y , z , Material .CAVE_AIR );
196
197
}
197
198
}
198
199
}
199
200
200
- Entity entity = limitedRegion .spawnEntity (location , entityType );
201
-
202
201
if (entity instanceof LivingEntity livingEntity )
203
202
{
204
203
livingEntity .setAI (hasAI );
205
204
livingEntity .setRemoveWhenFarAway (false );
206
205
}
207
206
}
208
207
209
-
210
- /**
211
- * This is manual bounding box calculation base on entity type.
212
- * @param entityType Entity type which bounding box should be created.
213
- * @param location Location of the bounding box.
214
- * @return Approximate bounding box of the entity type.
215
- */
216
- private BoundingBox getEntityBoundingBox (EntityType entityType , Location location )
217
- {
218
- BoundingBox boundingBox = new BoundingBox ();
219
- // Set bounding box to 1 for all entities
220
- boundingBox .expand (1 );
221
- // Shift to correct location.
222
- boundingBox .shift (location );
223
-
224
- switch (entityType )
225
- {
226
- // Turtles base size is 1.1
227
- case TURTLE -> boundingBox .expand (-0.05 , 0 , -0.05 , 0.05 , 0 , 0.05 );
228
- // Panda base size is 1.3 and height is 1.25
229
- case PANDA -> boundingBox .expand (-0.15 , 0 , -0.15 , 0.15 , 0.25 , 0.15 );
230
- // Sheep height is 1.3
231
- case SHEEP -> boundingBox .expand (0 , 0 , 0 , 0 , 0.3 , 0 );
232
- // Cow height is 1.4
233
- case COW , MUSHROOM_COW -> boundingBox .expand (0 , 0 , 0 , 0 , 0.4 , 0 );
234
- // Polar Bear base size is 1.3 and height is 1.4
235
- case POLAR_BEAR -> boundingBox .expand (-0.15 , 0 , -0.15 , 0.15 , 0.4 , 0.15 );
236
- // Horse base size is 1.3964
237
- case HORSE , ZOMBIE_HORSE , SKELETON_HORSE -> boundingBox .expand (-0.2 , 0 , -0.2 , 0.2 , 0.6 , 0.2 );
238
- // Llama height is 1.875
239
- case LLAMA -> boundingBox .expand (0 , 0 , 0 , 0 , 0.875 , 0 );
240
- // Ravager base size is 1.95 and height is 2.2
241
- case RAVAGER -> boundingBox .expand (-0.48 , 0 , -0.48 , 0.48 , 1.2 , 0.48 );
242
- // Spider base size is 1.4
243
- case SPIDER -> boundingBox .expand (-0.2 , 0 , -0.2 , 0.2 , 0 , 0.2 );
244
- // Creeper height 1.7
245
- case CREEPER -> boundingBox .expand (0 , 0 , 0 , 0 , 0.7 , 0 );
246
- // Blaze height 1.8
247
- case BLAZE -> boundingBox .expand (0 , 0 , 0 , 0 , 0.8 , 0 );
248
- // Zombie, evoker, villager, husk, witch, vindicator, illusioner, drowned, pigman, villager and pillager height is 1.95
249
- case ZOMBIE , EVOKER , VILLAGER , HUSK , WITCH , VINDICATOR , ILLUSIONER , DROWNED , PIGLIN , PIGLIN_BRUTE , ZOMBIFIED_PIGLIN , ZOMBIE_VILLAGER , PILLAGER , WANDERING_TRADER ->
250
- boundingBox .expand (0 , 0 , 0 , 0 , 0.95 , 0 );
251
- // Skeletons height is 1.99
252
- case SKELETON , STRAY -> boundingBox .expand (0 , 0 , 0 , 0 , 0.99 , 0 );
253
- // Elder Guardians base height is 2
254
- case ELDER_GUARDIAN -> boundingBox .expand (-0.5 , 0 , -0.5 , 0.5 , 1 , 0.5 );
255
- // Slimes are up to 2.04
256
- case SLIME -> boundingBox .expand (-0.5 , 0 , -0.5 , 0.5 , 1 , 0.5 );
257
- // Wither skeletons height is 2.4
258
- case WITHER_SKELETON -> boundingBox .expand (0 , 0 , 0 , 0 , 1.4 , 0 );
259
- // Wither height is 3.5
260
- case WITHER -> boundingBox .expand (0 , 0 , 0 , 0 , 2.5 , 0 );
261
- // Enderman height is 2.9
262
- case ENDERMAN -> boundingBox .expand (0 , 0 , 0 , 0 , 1.9 , 0 );
263
- // Ghast base size is 4
264
- case GHAST -> boundingBox .expand (-2 , 0 , -2 , 2 , 3 , 2 );
265
- // Iron Golem base size is 1.4 and height is 2.7
266
- case IRON_GOLEM -> boundingBox .expand (-0.2 , 0 , -0.2 , 0.2 , 1.7 , 0.2 );
267
- // Snowman height is 1.9
268
- case SNOWMAN -> boundingBox .expand (0 , 0 , 0 , 0 , 0.9 , 0 );
269
- // Hoglin base size is 1.4 and height is 1.3965
270
- case HOGLIN , ZOGLIN -> boundingBox .expand (-0.2 , 0 , -0.2 , 0.2 , 0.4 , 0.2 );
271
- // Warden height is 2.9
272
- case WARDEN -> boundingBox .expand (0 , 0 , 0 , 0 , 1.9 , 0 );
273
- }
274
-
275
- return boundingBox ;
276
- }
277
-
278
-
279
208
// ---------------------------------------------------------------------
280
209
// Section: Private Classes
281
210
// ---------------------------------------------------------------------
0 commit comments