From ec6bf66f0e5060ec100851cf8f3862ad7fcd6a8c Mon Sep 17 00:00:00 2001 From: TheRealWormbo Date: Sat, 23 Mar 2024 17:56:35 +0100 Subject: [PATCH] The Spectator also scans donkeys, mules, llamas, and allays --- .../item/equipment/bauble/SpectatorItem.java | 10 ++++++++++ .../botania/mixin/AbstractHorseAccessor.java | 4 ++++ .../botania/test/item/SpectatorScanTest.java | 20 ++++++++++++++++++- .../structures/item/spectator_scan.snbt | 1 + 4 files changed, 34 insertions(+), 1 deletion(-) diff --git a/Xplat/src/main/java/vazkii/botania/common/item/equipment/bauble/SpectatorItem.java b/Xplat/src/main/java/vazkii/botania/common/item/equipment/bauble/SpectatorItem.java index 5a5724adf8..a5510e071b 100644 --- a/Xplat/src/main/java/vazkii/botania/common/item/equipment/bauble/SpectatorItem.java +++ b/Xplat/src/main/java/vazkii/botania/common/item/equipment/bauble/SpectatorItem.java @@ -26,6 +26,7 @@ import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.EquipmentSlot; import net.minecraft.world.entity.LivingEntity; +import net.minecraft.world.entity.animal.allay.Allay; import net.minecraft.world.entity.animal.horse.AbstractChestedHorse; import net.minecraft.world.entity.item.ItemEntity; import net.minecraft.world.entity.player.Player; @@ -44,6 +45,7 @@ import vazkii.botania.client.render.AccessoryRenderer; import vazkii.botania.common.helper.ItemNBTHelper; import vazkii.botania.common.proxy.Proxy; +import vazkii.botania.mixin.AbstractHorseAccessor; import vazkii.botania.mixin.RandomizableContainerBlockEntityAccessor; import java.util.List; @@ -162,6 +164,14 @@ private int[] scanEntities(Player player, ItemStack mainHandStack, ItemStack off entityIds.add(targetPlayer.getId()); } } + } else if (e instanceof AbstractChestedHorse horse && horse.hasChest()) { + if (scanInventory(((AbstractHorseAccessor) horse).getInventory(), mainHandStack, offHandStack)) { + entityIds.add(horse.getId()); + } + } else if (e instanceof Allay allay && allay.hasItemInHand()) { + if (equalStacks(allay.getMainHandItem(), mainHandStack, offHandStack)) { + entityIds.add(allay.getId()); + } } else if (e instanceof Merchant villager) { for (MerchantOffer offer : villager.getOffers()) { if (equalStacks(offer.getBaseCostA(), mainHandStack, offHandStack) diff --git a/Xplat/src/main/java/vazkii/botania/mixin/AbstractHorseAccessor.java b/Xplat/src/main/java/vazkii/botania/mixin/AbstractHorseAccessor.java index 1d6da9dfac..d3d5f27b92 100644 --- a/Xplat/src/main/java/vazkii/botania/mixin/AbstractHorseAccessor.java +++ b/Xplat/src/main/java/vazkii/botania/mixin/AbstractHorseAccessor.java @@ -13,9 +13,13 @@ import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.gen.Accessor; +import org.spongepowered.asm.mixin.gen.Invoker; @Mixin(AbstractHorse.class) public interface AbstractHorseAccessor { @Accessor SimpleContainer getInventory(); + + @Invoker("createInventory") + void botania_createInventory(); } diff --git a/Xplat/src/main/java/vazkii/botania/test/item/SpectatorScanTest.java b/Xplat/src/main/java/vazkii/botania/test/item/SpectatorScanTest.java index cef00aedb5..de4360ff65 100644 --- a/Xplat/src/main/java/vazkii/botania/test/item/SpectatorScanTest.java +++ b/Xplat/src/main/java/vazkii/botania/test/item/SpectatorScanTest.java @@ -4,6 +4,7 @@ import net.minecraft.gametest.framework.GameTest; import net.minecraft.gametest.framework.GameTestHelper; import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.InteractionHand; import net.minecraft.world.entity.EntityType; import net.minecraft.world.entity.EquipmentSlot; import net.minecraft.world.entity.npc.VillagerData; @@ -18,6 +19,7 @@ import vazkii.botania.common.helper.ItemNBTHelper; import vazkii.botania.common.item.BotaniaItems; import vazkii.botania.common.item.equipment.bauble.SpectatorItem; +import vazkii.botania.mixin.AbstractHorseAccessor; import vazkii.botania.mixin.RandomizableContainerBlockEntityAccessor; import vazkii.botania.test.TestingUtil; @@ -31,6 +33,8 @@ public class SpectatorScanTest { private static final BlockPos POSITION_CART_LOOT = new BlockPos(9, 2, 6); private static final BlockPos POSITION_ITEM = new BlockPos(7, 3, 3); private static final BlockPos POSITION_VILLAGER = new BlockPos(4, 2, 3); + private static final BlockPos POSITION_DONKEY = new BlockPos(19, 2, 6); + private static final BlockPos POSITION_ALLAY = new BlockPos(19, 2, 16); private static final String LOOT_TABLE_CHEST = "minecraft:chests/simple_dungeon"; private static final String LOOT_TABLE_CART = "minecraft:chests/abandoned_mineshaft"; @@ -74,6 +78,17 @@ private static void performTest(GameTestHelper helper, BiConsumer "Chest position " + helper.absolutePos(POSITION_CHEST_NORMAL) + " not in result, but found " + chestPos); int[] entities = ItemNBTHelper.getIntArray(spectatorStack, SpectatorItem.TAG_ENTITY_POSITIONS); - TestingUtil.assertEquals(entities.length, 3, () -> "Expected 3 entity hits, but got " + entities.length); + TestingUtil.assertEquals(entities.length, 5, () -> "Expected 5 entity hits, but got " + entities.length); TestingUtil.assertThat(Arrays.stream(entities).anyMatch(id -> villager.getId() == id), () -> "Villager not in result"); TestingUtil.assertThat(Arrays.stream(entities).anyMatch(id -> itemEntity.getId() == id), () -> "Item entity not in result"); TestingUtil.assertThat(Arrays.stream(entities).anyMatch(id -> regularChestCart.getId() == id), () -> "Minecart not in result"); + TestingUtil.assertThat(Arrays.stream(entities).anyMatch(id -> donkey.getId() == id), () -> "Donkey not in result"); + TestingUtil.assertThat(Arrays.stream(entities).anyMatch(id -> allay.getId() == id), () -> "Allay not in result"); + helper.killAllEntities(); helper.succeed(); } } diff --git a/Xplat/src/main/resources/data/botania/gametest/structures/item/spectator_scan.snbt b/Xplat/src/main/resources/data/botania/gametest/structures/item/spectator_scan.snbt index 21fcc0498e..b8c673c153 100644 --- a/Xplat/src/main/resources/data/botania/gametest/structures/item/spectator_scan.snbt +++ b/Xplat/src/main/resources/data/botania/gametest/structures/item/spectator_scan.snbt @@ -5,6 +5,7 @@ {pos: [4, 0, 3], state: "minecraft:polished_andesite_slab{type:top,waterlogged:false}"}, {pos: [9, 0, 6], state: "minecraft:polished_andesite_slab{type:top,waterlogged:false}"}, {pos: [11, 0, 6], state: "minecraft:polished_andesite_slab{type:top,waterlogged:false}"}, + {pos: [19, 0, 6], state: "minecraft:polished_andesite_slab{type:top,waterlogged:false}"}, {pos: [3, 1, 3], state: "minecraft:polished_andesite_slab{type:top,waterlogged:false}"}, {pos: [4, 1, 2], state: "minecraft:polished_andesite_slab{type:top,waterlogged:false}"}, {pos: [4, 1, 4], state: "minecraft:polished_andesite_slab{type:top,waterlogged:false}"},