|
23 | 23 |
|
24 | 24 | import com.cryptomorin.xseries.base.XBase; |
25 | 25 | import org.bukkit.Material; |
| 26 | +import org.bukkit.event.entity.EntitySpawnEvent; |
26 | 27 | import org.bukkit.inventory.ItemStack; |
27 | 28 | import org.jetbrains.annotations.NotNull; |
28 | 29 | import org.jetbrains.annotations.Nullable; |
@@ -79,11 +80,16 @@ public final class XTag<T extends XBase<?, ?>> { |
79 | 80 | */ |
80 | 81 | @NotNull |
81 | 82 | public static final XTag<XMaterial> ALIVE_CORAL_PLANTS; |
82 | | - /** |
83 | | - * |
84 | | - */ |
85 | 83 | @NotNull |
86 | 84 | public static final XTag<XMaterial> ALIVE_CORAL_WALL_FANS; |
| 85 | + |
| 86 | + @NotNull |
| 87 | + public static final XTag<XMaterial> SPAWN_EGGS = TagBuilder.of( |
| 88 | + Arrays.stream(XMaterial.values()) |
| 89 | + .filter(x -> x.name().endsWith("_SPAWN_EGG")) |
| 90 | + .toArray(XMaterial[]::new) |
| 91 | + ).build(); |
| 92 | + |
87 | 93 | /** |
88 | 94 | * Tag representing all possible blocks available for animals to spawn on |
89 | 95 | */ |
@@ -1107,6 +1113,17 @@ public final class XTag<T extends XBase<?, ?>> { |
1107 | 1113 | XPotion.WEAKNESS, XPotion.WITHER |
1108 | 1114 | ); |
1109 | 1115 |
|
| 1116 | + /** |
| 1117 | + * What entity spawns when a material is placed down? |
| 1118 | + * Mostly for things that spawn instantly after a single |
| 1119 | + * right-click whether it requires a block or free air. |
| 1120 | + * <p> |
| 1121 | + * It doesn't work for bows and arrows, TNT, fishing bobs |
| 1122 | + * or EXP bottles. |
| 1123 | + */ |
| 1124 | + @SuppressWarnings("MapReplaceableByEnumMap") |
| 1125 | + public static final Map<XMaterial, XEntityType> MATERIAL_TO_ENTITY = new HashMap<>(); |
| 1126 | + |
1110 | 1127 | static { // logs |
1111 | 1128 | ACACIA_LOGS = TagBuilder.simple( |
1112 | 1129 | XMaterial.STRIPPED_ACACIA_LOG, |
@@ -2468,22 +2485,64 @@ public final class XTag<T extends XBase<?, ?>> { |
2468 | 2485 | static { |
2469 | 2486 | INVENTORY_NOT_DISPLAYABLE = TagBuilder |
2470 | 2487 | .of( |
2471 | | - XMaterial.BIG_DRIPLEAF_STEM, XMaterial.SWEET_BERRY_BUSH, XMaterial.KELP_PLANT, |
2472 | | - XMaterial.FROSTED_ICE, XMaterial.ATTACHED_MELON_STEM, XMaterial.ATTACHED_PUMPKIN_STEM, |
2473 | | - XMaterial.COCOA, XMaterial.MOVING_PISTON, XMaterial.PISTON_HEAD, XMaterial.PITCHER_CROP, |
2474 | | - XMaterial.POWDER_SNOW, XMaterial.REDSTONE_WIRE, XMaterial.TALL_SEAGRASS, XMaterial.TRIPWIRE, |
2475 | | - XMaterial.TORCHFLOWER_CROP, XMaterial.BUBBLE_COLUMN, XMaterial.TWISTING_VINES_PLANT, |
2476 | | - XMaterial.WEEPING_VINES_PLANT, XMaterial.BAMBOO_SAPLING |
| 2488 | + XMaterial.FROSTED_ICE, |
| 2489 | + XMaterial.MOVING_PISTON, XMaterial.PISTON_HEAD, XMaterial.BUBBLE_COLUMN, |
| 2490 | + XMaterial.POWDER_SNOW, XMaterial.REDSTONE_WIRE, XMaterial.TRIPWIRE, |
| 2491 | + |
| 2492 | + // Saplings, stems and crops |
| 2493 | + XMaterial.BIG_DRIPLEAF_STEM, XMaterial.SWEET_BERRY_BUSH, |
| 2494 | + XMaterial.TORCHFLOWER_CROP, XMaterial.TWISTING_VINES_PLANT, |
| 2495 | + XMaterial.WEEPING_VINES_PLANT, XMaterial.BAMBOO_SAPLING, |
| 2496 | + XMaterial.CARROT, XMaterial.CARROTS, XMaterial.POTATO, XMaterial.POTATOES, |
| 2497 | + XMaterial.BAMBOO_SAPLING, XMaterial.BAMBOO, XMaterial.CHORUS_PLANT, |
| 2498 | + XMaterial.KELP_PLANT, XMaterial.COCOA, XMaterial.TALL_SEAGRASS, |
| 2499 | + XMaterial.MELON_STEM, XMaterial.PUMPKIN_STEM, |
| 2500 | + XMaterial.ATTACHED_MELON_STEM, XMaterial.ATTACHED_PUMPKIN_STEM |
2477 | 2501 | ) |
2478 | 2502 | .inheritFrom( |
2479 | 2503 | AIR, CAVE_VINES, FILLED_CAULDRONS, FIRE, FLUID, PORTALS, |
2480 | 2504 | WALL_SIGNS, WALL_HANGING_SIGNS, WALL_TORCHES, ALIVE_CORAL_WALL_FANS, |
2481 | 2505 | DEAD_CORAL_WALL_FANS, WALL_HEADS, CANDLE_CAKES, WALL_BANNERS, |
2482 | | - FLOWER_POTS.without(XMaterial.FLOWER_POT), |
2483 | | - CROPS.without(XMaterial.WHEAT_SEEDS, XMaterial.WHEAT) |
| 2506 | + FLOWER_POTS.without(XMaterial.FLOWER_POT) |
2484 | 2507 | ).build(); |
2485 | 2508 | } |
2486 | 2509 |
|
| 2510 | + static { |
| 2511 | + // Minecarts |
| 2512 | + MATERIAL_TO_ENTITY.put(XMaterial.MINECART, XEntityType.MINECART); |
| 2513 | + MATERIAL_TO_ENTITY.put(XMaterial.CHEST_MINECART, XEntityType.CHEST_MINECART); |
| 2514 | + MATERIAL_TO_ENTITY.put(XMaterial.COMMAND_BLOCK_MINECART, XEntityType.COMMAND_BLOCK_MINECART); |
| 2515 | + MATERIAL_TO_ENTITY.put(XMaterial.TNT_MINECART, XEntityType.TNT_MINECART); |
| 2516 | + MATERIAL_TO_ENTITY.put(XMaterial.FURNACE_MINECART, XEntityType.FURNACE_MINECART); |
| 2517 | + MATERIAL_TO_ENTITY.put(XMaterial.HOPPER_MINECART, XEntityType.HOPPER_MINECART); |
| 2518 | + |
| 2519 | + // MATERIAL_TO_ENTITY.put(XMaterial.TNT, XEntityType.TNT); |
| 2520 | + // MATERIAL_TO_ENTITY.put(XMaterial.TRIDENT, XEntityType.TRIDENT); |
| 2521 | + MATERIAL_TO_ENTITY.put(XMaterial.END_CRYSTAL, XEntityType.END_CRYSTAL); |
| 2522 | + MATERIAL_TO_ENTITY.put(XMaterial.PAINTING, XEntityType.PAINTING); |
| 2523 | + MATERIAL_TO_ENTITY.put(XMaterial.ITEM_FRAME, XEntityType.ITEM_FRAME); |
| 2524 | + MATERIAL_TO_ENTITY.put(XMaterial.GLOW_ITEM_FRAME, XEntityType.GLOW_ITEM_FRAME); |
| 2525 | + MATERIAL_TO_ENTITY.put(XMaterial.WIND_CHARGE, XEntityType.WIND_CHARGE); |
| 2526 | + MATERIAL_TO_ENTITY.put(XMaterial.EGG, XEntityType.EGG); |
| 2527 | + MATERIAL_TO_ENTITY.put(XMaterial.SNOWBALL, XEntityType.SNOWBALL); |
| 2528 | + MATERIAL_TO_ENTITY.put(XMaterial.ENDER_PEARL, XEntityType.ENDER_PEARL); |
| 2529 | + MATERIAL_TO_ENTITY.put(XMaterial.ENDER_EYE, XEntityType.EYE_OF_ENDER); |
| 2530 | + |
| 2531 | + // Boats |
| 2532 | + for (XMaterial boat : ITEMS_BOATS.values) { |
| 2533 | + XEntityType entityType = XEntityType.of(boat.name()) |
| 2534 | + .orElseThrow(() -> new IllegalStateException("Cannot find entity type for boat: " + boat)); |
| 2535 | + MATERIAL_TO_ENTITY.put(boat, entityType); |
| 2536 | + } |
| 2537 | + |
| 2538 | + // Spawn Eggs |
| 2539 | + for (XMaterial spawnEgg : SPAWN_EGGS.values) { |
| 2540 | + XEntityType entityType = XEntityType.of(spawnEgg.name()) |
| 2541 | + .orElseThrow(() -> new IllegalStateException("Cannot find entity type for spawn egg: " + spawnEgg)); |
| 2542 | + MATERIAL_TO_ENTITY.put(spawnEgg, entityType); |
| 2543 | + } |
| 2544 | + } |
| 2545 | + |
2487 | 2546 | @NotNull |
2488 | 2547 | private final Set<T> values; |
2489 | 2548 |
|
|
0 commit comments