Skip to content

Commit

Permalink
The Spectator also scans donkeys, mules, llamas, and allays
Browse files Browse the repository at this point in the history
  • Loading branch information
TheRealWormbo committed Apr 2, 2024
1 parent 465b0a9 commit ec6bf66
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

Expand All @@ -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";
Expand Down Expand Up @@ -74,6 +78,17 @@ private static void performTest(GameTestHelper helper, BiConsumer<GameTestHelper
regularChest.setItem(3, new ItemStack(Items.FLINT));
regularChest.setItem(7, new ItemStack(Items.IRON_INGOT));

var donkey = helper.spawnWithNoFreeWill(EntityType.DONKEY, POSITION_DONKEY);
donkey.setTamed(true);
donkey.setChest(true);
((AbstractHorseAccessor) donkey).botania_createInventory();
var donkeyInventory = ((AbstractHorseAccessor) donkey).getInventory();
donkeyInventory.setItem(3, new ItemStack(Items.COAL));
donkeyInventory.setItem(4, new ItemStack(Items.IRON_INGOT));

var allay = helper.spawnWithNoFreeWill(EntityType.ALLAY, POSITION_ALLAY);
allay.setItemInHand(InteractionHand.MAIN_HAND, new ItemStack(Items.IRON_INGOT));

// set loot tables
var lootChestCart = helper.spawn(EntityType.CHEST_MINECART, POSITION_CART_LOOT);
lootChestCart.setLootTable(new ResourceLocation(LOOT_TABLE_CART), 1L);
Expand Down Expand Up @@ -103,11 +118,14 @@ private static void performTest(GameTestHelper helper, BiConsumer<GameTestHelper
() -> "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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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}"},
Expand Down

0 comments on commit ec6bf66

Please sign in to comment.