diff --git a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/util/InteractUtils.java b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/util/InteractUtils.java index 2809910b7..39cbba3da 100644 --- a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/util/InteractUtils.java +++ b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/util/InteractUtils.java @@ -1,5 +1,6 @@ package net.momirealms.craftengine.bukkit.util; +import io.papermc.paper.entity.Shearable; import net.momirealms.craftengine.bukkit.item.BukkitItemManager; import net.momirealms.craftengine.bukkit.item.recipe.BukkitRecipeManager; import net.momirealms.craftengine.core.block.BlockKeys; @@ -52,6 +53,9 @@ public class InteractUtils { registerInteraction(BlockKeys.GREEN_CANDLE_CAKE, (player, item, blockState, result) -> !canEat(player, false)); registerInteraction(BlockKeys.RED_CANDLE_CAKE, (player, item, blockState, result) -> !canEat(player, false)); registerInteraction(BlockKeys.BLACK_CANDLE_CAKE, (player, item, blockState, result) -> !canEat(player, false)); + registerInteraction(BlockKeys.BEE_NEST, (player, item, blockState, result) -> item.vanillaId().equals(ItemKeys.SHEARS) || item.vanillaId().equals(ItemKeys.GLASS_BOTTLE)); + registerInteraction(BlockKeys.BEEHIVE, (player, item, blockState, result) -> item.vanillaId().equals(ItemKeys.SHEARS) || item.vanillaId().equals(ItemKeys.GLASS_BOTTLE)); + registerInteraction(BlockKeys.POWDER_SNOW, (player, item, blockState, result) -> item.vanillaId().equals(ItemKeys.BUCKET)); registerInteraction(BlockKeys.BELL, (player, item, blockState, result) -> { Direction direction = result.getDirection(); BlockPos pos = result.getBlockPos(); @@ -270,9 +274,14 @@ public class InteractUtils { registerInteraction(BlockKeys.RED_BED, (player, item, blockState, result) -> true); registerInteraction(BlockKeys.BLACK_BED, (player, item, blockState, result) -> true); registerInteraction(BlockKeys.DRAGON_EGG, (player, item, blockState, result) -> true); - registerInteraction(BlockKeys.REPEATING_COMMAND_BLOCK, (player, item, blockState, result) -> true); - registerInteraction(BlockKeys.CHAIN_COMMAND_BLOCK, (player, item, blockState, result) -> true); registerInteraction(BlockKeys.COMMAND_BLOCK, (player, item, blockState, result) -> true); + registerInteraction(BlockKeys.CHAIN_COMMAND_BLOCK, (player, item, blockState, result) -> true); + registerInteraction(BlockKeys.REPEATING_COMMAND_BLOCK, (player, item, blockState, result) -> true); + registerInteraction(BlockKeys.JIGSAW, (player, item, blockState, result) -> true); + registerInteraction(BlockKeys.STRUCTURE_BLOCK, (player, item, blockState, result) -> true); + registerInteraction(BlockKeys.TEST_INSTANCE_BLOCK, (player, item, blockState, result) -> true); + registerInteraction(BlockKeys.TEST_BLOCK, (player, item, blockState, result) -> true); + registerInteraction(BlockKeys.LIGHT, (player, item, blockState, result) -> true); registerInteraction(BlockKeys.REDSTONE_ORE, (player, item, blockState, result) -> true); registerInteraction(BlockKeys.DEEPSLATE_REDSTONE_ORE, (player, item, blockState, result) -> true); } @@ -283,12 +292,53 @@ public class InteractUtils { } static { - registerEntityInteraction(EntityKeys.PIGLIN, (player, entity, item) -> item != null && item.vanillaId().equals(ItemKeys.GOLD_INGOT)); - registerEntityInteraction(EntityKeys.PIG, (player, entity, item) -> hasSaddle(player, entity) && !player.isSneaking()); - registerEntityInteraction(EntityKeys.STRIDER, (player, entity, item) -> hasSaddle(player, entity) && !player.isSneaking()); - registerEntityInteraction(EntityKeys.WOLF, (player, entity, item) -> isPetOwner(player, entity)); - registerEntityInteraction(EntityKeys.CAT, (player, entity, item) -> isPetOwner(player, entity)); - registerEntityInteraction(EntityKeys.PARROT, (player, entity, item) -> isPetOwner(player, entity)); + registerEntityInteraction(EntityKeys.BEE, (player, entity, item) -> canFeed(entity, item)); + registerEntityInteraction(EntityKeys.FOX, (player, entity, item) -> canFeed(entity, item)); + registerEntityInteraction(EntityKeys.FROG, (player, entity, item) -> canFeed(entity, item)); + registerEntityInteraction(EntityKeys.PANDA, (player, entity, item) -> canFeed(entity, item)); + registerEntityInteraction(EntityKeys.HOGLIN, (player, entity, item) -> canFeed(entity, item)); + registerEntityInteraction(EntityKeys.OCELOT, (player, entity, item) -> canFeed(entity, item)); + registerEntityInteraction(EntityKeys.RABBIT, (player, entity, item) -> canFeed(entity, item)); + registerEntityInteraction(EntityKeys.TURTLE, (player, entity, item) -> canFeed(entity, item)); + registerEntityInteraction(EntityKeys.CHICKEN, (player, entity, item) -> canFeed(entity, item)); + registerEntityInteraction(EntityKeys.SNIFFER, (player, entity, item) -> canFeed(entity, item)); + registerEntityInteraction(EntityKeys.AXOLOTL, (player, entity, item) -> + canFeed(entity, item) || (item != null && item.vanillaId().equals(ItemKeys.WATER_BUCKET))); + registerEntityInteraction(EntityKeys.COD, (player, entity, item) -> + item != null && item.vanillaId().equals(ItemKeys.WATER_BUCKET)); + registerEntityInteraction(EntityKeys.SALMON, (player, entity, item) -> + item != null && item.vanillaId().equals(ItemKeys.WATER_BUCKET)); + registerEntityInteraction(EntityKeys.TROPICAL_FISH, (player, entity, item) -> + item != null && item.vanillaId().equals(ItemKeys.WATER_BUCKET)); + registerEntityInteraction(EntityKeys.PUFFERFISH, (player, entity, item) -> + item != null && item.vanillaId().equals(ItemKeys.WATER_BUCKET)); + registerEntityInteraction(EntityKeys.TADPOLE, (player, entity, item) -> + item != null && item.vanillaId().equals(ItemKeys.WATER_BUCKET)); + registerEntityInteraction(EntityKeys.SNOW_GOLEM, (player, entity, item) -> shearable(entity, item)); + registerEntityInteraction(EntityKeys.SHEEP, (player, entity, item) -> canFeed(entity, item) || shearable(entity, item)); + registerEntityInteraction(EntityKeys.BOGGED, (player, entity, item) -> canFeed(entity, item) || shearable(entity, item)); + registerEntityInteraction(EntityKeys.MOOSHROOM, (player, entity, item) -> + canFeed(entity, item) || shearable(entity, item) || (item != null && (item.vanillaId().equals(ItemKeys.BUCKET) || item.vanillaId().equals(ItemKeys.BOWL)))); + registerEntityInteraction(EntityKeys.COW, (player, entity, item) -> + canFeed(entity, item) || (item != null && item.vanillaId().equals(ItemKeys.BUCKET))); + registerEntityInteraction(EntityKeys.GOAT, (player, entity, item) -> + canFeed(entity, item) || (item != null && item.vanillaId().equals(ItemKeys.BUCKET))); + registerEntityInteraction(EntityKeys.CREEPER, (player, entity, item) -> + item != null && item.vanillaId().equals(ItemKeys.FLINT_AND_STEEL)); + registerEntityInteraction(EntityKeys.PIGLIN, (player, entity, item) -> + item != null && item.vanillaId().equals(ItemKeys.GOLD_INGOT)); + registerEntityInteraction(EntityKeys.ARMADILLO, (player, entity, item) -> + canFeed(entity, item) || (item != null && item.vanillaId().equals(ItemKeys.BRUSH))); + registerEntityInteraction(EntityKeys.ZOMBIE_HORSE, (player, entity, item) -> + entity instanceof Tameable tameable && tameable.isTamed()); + registerEntityInteraction(EntityKeys.SKELETON_HORSE, (player, entity, item) -> + entity instanceof Tameable tameable && tameable.isTamed()); + registerEntityInteraction(EntityKeys.PIG, (player, entity, item) -> + canFeed(entity, item) || (hasSaddle(player, entity) && !player.isSneaking())); + registerEntityInteraction(EntityKeys.STRIDER, (player, entity, item) -> + canFeed(entity, item) || (hasSaddle(player, entity) && !player.isSneaking())); + registerEntityInteraction(EntityKeys.WOLF, (player, entity, item) -> canFeed(entity, item) || isPetOwner(player, entity)); + registerEntityInteraction(EntityKeys.CAT, (player, entity, item) -> canFeed(entity, item) || isPetOwner(player, entity)); registerEntityInteraction(EntityKeys.ACACIA_BOAT, (player, entity, item) -> !player.isSneaking()); registerEntityInteraction(EntityKeys.BAMBOO_BOAT, (player, entity, item) -> !player.isSneaking()); registerEntityInteraction(EntityKeys.BIRCH_BOAT, (player, entity, item) -> !player.isSneaking()); @@ -299,19 +349,21 @@ public class InteractUtils { registerEntityInteraction(EntityKeys.OAK_BOAT, (player, entity, item) -> !player.isSneaking()); registerEntityInteraction(EntityKeys.SPRUCE_BOAT, (player, entity, item) -> !player.isSneaking()); registerEntityInteraction(EntityKeys.MINECART, (player, entity, item) -> !player.isSneaking()); + registerEntityInteraction(EntityKeys.PARROT, (player, entity, item) -> { + if (item != null && item.is(Key.of("parrot_poisonous_food"))) return true; + return canFeed(entity, item) || isPetOwner(player, entity); + }); registerEntityInteraction(EntityKeys.HAPPY_GHAST, (player, entity, item) -> { if (!VersionHelper.isOrAbove1_21_6()) return false; - if (entity instanceof HappyGhast happyGhast) { + if (entity instanceof HappyGhast happyGhast && !player.isSneaking()) { ItemStack bodyItem = happyGhast.getEquipment().getItem(EquipmentSlot.BODY); - Item wrapped = BukkitItemManager.instance().wrap(bodyItem); - return wrapped.is(Key.of("harnesses")); + Item wrap = BukkitItemManager.instance().wrap(bodyItem); + return wrap.is(Key.of("harnesses")); } - return false; + return canFeed(entity, item); }); registerEntityInteraction(EntityKeys.ALLAY, (player, entity, item) -> true); registerEntityInteraction(EntityKeys.HORSE, (player, entity, item) -> true); - registerEntityInteraction(EntityKeys.ZOMBIE_HORSE, (player, entity, item) -> true); - registerEntityInteraction(EntityKeys.SKELETON_HORSE, (player, entity, item) -> true); registerEntityInteraction(EntityKeys.DONKEY, (player, entity, item) -> true); registerEntityInteraction(EntityKeys.MULE, (player, entity, item) -> true); registerEntityInteraction(EntityKeys.VILLAGER, (player, entity, item) -> true); @@ -392,11 +444,19 @@ public class InteractUtils { return ignoreHunger || player.isInvulnerable() || player.getFoodLevel() < 20; } - public static boolean hasSaddle(Player player, Entity entity) { + private static boolean canFeed(Entity entity, Item item) { + return entity instanceof Animals animals && item.is(Key.of(animals.getType().toString().toLowerCase() + "_food")); + } + + private static boolean hasSaddle(Player player, Entity entity) { return entity instanceof Steerable steerable && steerable.hasSaddle() && !player.isSneaking(); } - public static boolean isPetOwner(Player player, Entity entity) { + private static boolean shearable(Entity entity, Item item) { + return entity instanceof Shearable shearable && item.vanillaId().equals(ItemKeys.SHEARS) && shearable.readyToBeSheared(); + } + + private static boolean isPetOwner(Player player, Entity entity) { return entity instanceof Tameable tameable && tameable.isTamed() && player.getUniqueId().equals(tameable.getOwnerUniqueId()); } } diff --git a/core/src/main/java/net/momirealms/craftengine/core/block/BlockKeys.java b/core/src/main/java/net/momirealms/craftengine/core/block/BlockKeys.java index 4e377f7d2..9da2f4f3f 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/block/BlockKeys.java +++ b/core/src/main/java/net/momirealms/craftengine/core/block/BlockKeys.java @@ -41,10 +41,22 @@ public final class BlockKeys { public static final Key COMMAND_BLOCK = Key.of("minecraft:command_block"); public static final Key CHAIN_COMMAND_BLOCK = Key.of("minecraft:chain_command_block"); public static final Key REPEATING_COMMAND_BLOCK = Key.of("minecraft:repeating_command_block"); + public static final Key JIGSAW = Key.of("minecraft:jigsaw"); + public static final Key STRUCTURE_BLOCK = Key.of("minecraft:structure_block"); + public static final Key TEST_INSTANCE_BLOCK = Key.of("minecraft:test_instance_block"); + public static final Key TEST_BLOCK = Key.of("minecraft:test_block"); + public static final Key LIGHT = Key.of("minecraft:light"); public static final Key DECORATED_POT = Key.of("minecraft:decorated_pot"); public static final Key CHISELED_BOOKSHELF = Key.of("minecraft:chiseled_bookshelf"); public static final Key REDSTONE_ORE = Key.of("minecraft:redstone_ore"); public static final Key DEEPSLATE_REDSTONE_ORE = Key.of("minecraft:deepslate_redstone_ore"); + public static final Key BEE_NEST = Key.of("minecraft:bee_nest"); + public static final Key BEEHIVE = Key.of("minecraft:beehive"); + public static final Key POWDER_SNOW = Key.of("minecraft:powder_snow"); + public static final Key COMPOSTER = Key.of("minecraft:composter"); + public static final Key CAULDRON = Key.of("minecraft:cauldron"); + public static final Key WATER_CAULDRON = Key.of("minecraft:water_cauldron"); + public static final Key LAVA_CAULDRON = Key.of("minecraft:lava_cauldron"); public static final Key CAKE = Key.of("minecraft:cake"); public static final Key CANDLE_CAKE = Key.of("minecraft:candle_cake"); @@ -161,6 +173,8 @@ public final class BlockKeys { public static final Key WAXED_OXIDIZED_COPPER_TRAPDOOR = Key.of("minecraft:waxed_oxidized_copper_trapdoor"); public static final Key WAXED_WEATHERED_COPPER_TRAPDOOR = Key.of("minecraft:waxed_weathered_copper_trapdoor"); + + public static final Key OAK_FENCE_GATE = Key.of("minecraft:oak_fence_gate"); public static final Key SPRUCE_FENCE_GATE = Key.of("minecraft:spruce_fence_gate"); public static final Key BIRCH_FENCE_GATE = Key.of("minecraft:birch_fence_gate"); diff --git a/core/src/main/java/net/momirealms/craftengine/core/entity/EntityKeys.java b/core/src/main/java/net/momirealms/craftengine/core/entity/EntityKeys.java index 6f075e3d6..721302092 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/entity/EntityKeys.java +++ b/core/src/main/java/net/momirealms/craftengine/core/entity/EntityKeys.java @@ -5,6 +5,29 @@ import net.momirealms.craftengine.core.util.Key; public class EntityKeys { private EntityKeys() {} + public static final Key BEE = Key.of("minecraft:BEE"); + public static final Key FOX = Key.of("minecraft:FOX"); + public static final Key FROG = Key.of("minecraft:FROG"); + public static final Key PANDA = Key.of("minecraft:PANDA"); + public static final Key SHEEP = Key.of("minecraft:SHEEP"); + public static final Key BOGGED = Key.of("minecraft:BOGGED"); + public static final Key SNOW_GOLEM = Key.of("minecraft:SNOW_GOLEM"); + public static final Key HOGLIN = Key.of("minecraft:HOGLIN"); + public static final Key OCELOT = Key.of("minecraft:OCELOT"); + public static final Key RABBIT = Key.of("minecraft:RABBIT"); + public static final Key TURTLE = Key.of("minecraft:TURTLE"); + public static final Key AXOLOTL = Key.of("minecraft:AXOLOTL"); + public static final Key CHICKEN = Key.of("minecraft:CHICKEN"); + public static final Key SNIFFER = Key.of("minecraft:SNIFFER"); + public static final Key ARMADILLO = Key.of("minecraft:ARMADILLO"); + public static final Key COD = Key.of("minecraft:COD"); + public static final Key SALMON = Key.of("minecraft:SALMON"); + public static final Key TROPICAL_FISH = Key.of("minecraft:TROPICAL_FISH"); + public static final Key PUFFERFISH = Key.of("minecraft:PUFFERFISH"); + public static final Key TADPOLE = Key.of("minecraft:TADPOLE"); + public static final Key COW = Key.of("minecraft:COW"); + public static final Key MOOSHROOM = Key.of("minecraft:MOOSHROOM"); + public static final Key GOAT = Key.of("minecraft:GOAT"); public static final Key PIG = Key.of("minecraft:PIG"); public static final Key STRIDER = Key.of("minecraft:STRIDER"); public static final Key WOLF = Key.of("minecraft:WOLF"); @@ -22,6 +45,7 @@ public class EntityKeys { public static final Key MINECART = Key.of("minecraft:MINECART"); public static final Key HAPPY_GHAST = Key.of("minecraft:HAPPY_GHAST"); public static final Key PIGLIN = Key.of("minecraft:PIGLIN"); + public static final Key CREEPER = Key.of("minecraft:CREEPER"); public static final Key ALLAY = Key.of("minecraft:ALLAY"); public static final Key HORSE = Key.of("minecraft:HORSE"); public static final Key ZOMBIE_HORSE = Key.of("minecraft:ZOMBIE_HORSE"); diff --git a/core/src/main/java/net/momirealms/craftengine/core/item/ItemKeys.java b/core/src/main/java/net/momirealms/craftengine/core/item/ItemKeys.java index 7fc6b799a..148b73bb3 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/item/ItemKeys.java +++ b/core/src/main/java/net/momirealms/craftengine/core/item/ItemKeys.java @@ -26,6 +26,7 @@ public class ItemKeys { public static final Key TROPICAL_FISH_BUCKET = Key.of("minecraft:tropical_fish_bucket"); public static final Key PUFFERFISH_BUCKET = Key.of("minecraft:pufferfish_bucket"); public static final Key AXOLOTL_BUCKET = Key.of("minecraft:axolotl_bucket"); + public static final Key LAVA_BUCKET = Key.of("minecraft:lava_bucket"); public static final Key BUCKET = Key.of("minecraft:bucket"); public static final Key BONE_MEAL = Key.of("minecraft:bone_meal"); public static final Key ENCHANTED_BOOK = Key.of("minecraft:enchanted_book"); @@ -34,6 +35,10 @@ public class ItemKeys { public static final Key CACTUS = Key.of("minecraft:cactus"); public static final Key REDSTONE = Key.of("minecraft:redstone"); public static final Key GOLD_INGOT = Key.of("minecraft:gold_ingot"); + public static final Key SHEARS = Key.of("minecraft:shears"); + public static final Key BRUSH = Key.of("minecraft:brush"); + public static final Key BOWL = Key.of("minecraft:bowl"); + public static final Key GLASS_BOTTLE = Key.of("minecraft:glass_bottle"); public static final Key[] AXES = new Key[] { WOODEN_AXE, STONE_AXE, IRON_AXE, GOLDEN_AXE, DIAMOND_AXE, NETHERITE_AXE