diff --git a/src/gametest/java/carpetextra/test/WartFarming.java b/src/gametest/java/carpetextra/test/WartFarming.java index 54064fc8..6408694b 100644 --- a/src/gametest/java/carpetextra/test/WartFarming.java +++ b/src/gametest/java/carpetextra/test/WartFarming.java @@ -15,12 +15,12 @@ public class WartFarming { private static final String STRUCTURE = "carpet-extra:wartbase"; - private static final String ENV = "carpet-extra:warts"; // turns rule on + private static final String WART_FARMING_ENABLED = "carpet-extra:warts"; BlockPos soulSand = new BlockPos(0, 0, 0); BlockPos lapis = new BlockPos(3, 1, 0); - @GameTest(environment = ENV, structure = STRUCTURE, maxTicks = 1500) + @GameTest(environment = WART_FARMING_ENABLED, structure = STRUCTURE, maxTicks = 1500) public void placesWarts(TestContext ctx) { ctx.spawnItem(Items.NETHER_WART, lapis); ctx.spawnEntity(EntityType.VILLAGER, lapis); @@ -30,7 +30,7 @@ public void placesWarts(TestContext ctx) { }); } - @GameTest(environment = ENV, structure = STRUCTURE, maxTicks = 1500) + @GameTest(environment = WART_FARMING_ENABLED, structure = STRUCTURE, maxTicks = 1500) public void collectsWarts(TestContext ctx) { ctx.setBlockState(soulSand.up(), Blocks.NETHER_WART.getDefaultState().with(AGE, MAX_AGE)); VillagerEntity villager = ctx.spawnEntity(EntityType.VILLAGER, lapis); @@ -43,6 +43,17 @@ public void collectsWarts(TestContext ctx) { }); } + @GameTest(/* no env */ structure = STRUCTURE, maxTicks = 200) + public void doesntPickupWartsWithoutRule(TestContext ctx) { + ctx.spawnItem(Items.NETHER_WART, lapis); + ctx.spawnEntity(EntityType.VILLAGER, lapis); + + ctx.runAtEveryTick(() -> { + ctx.expectItem(Items.NETHER_WART); + }); + ctx.runAtTick(200, ctx::complete); + } + /* Too slow @GameTest(environment = ENV, structure = STRUCTURE, maxTicks = 1500) public void doesntCollectNonGrown(TestContext ctx) { diff --git a/src/main/java/carpetextra/mixins/VillagerProfession_wartFarmMixin.java b/src/main/java/carpetextra/mixins/VillagerProfession_wartFarmMixin.java index 4ba38bc5..eb6bf07b 100644 --- a/src/main/java/carpetextra/mixins/VillagerProfession_wartFarmMixin.java +++ b/src/main/java/carpetextra/mixins/VillagerProfession_wartFarmMixin.java @@ -4,7 +4,6 @@ import net.minecraft.block.Block; import net.minecraft.block.Blocks; import net.minecraft.item.Item; -import net.minecraft.item.Items; import net.minecraft.registry.Registry; import net.minecraft.registry.RegistryKey; import net.minecraft.registry.entry.RegistryEntry; @@ -35,13 +34,15 @@ private static VillagerProfession register( ) { throw new AssertionError(); } + private static boolean handled = false; @Inject(method = "register(Lnet/minecraft/registry/Registry;Lnet/minecraft/registry/RegistryKey;Ljava/util/function/Predicate;Ljava/util/function/Predicate;Lcom/google/common/collect/ImmutableSet;Lcom/google/common/collect/ImmutableSet;Lnet/minecraft/sound/SoundEvent;)Lnet/minecraft/village/VillagerProfession;", cancellable = true, at = @At("HEAD")) private static void registerCleric(Registry registry, RegistryKey key, Predicate> heldWorkstation, Predicate> acquirableWorkstation, ImmutableSet gatherableItems, ImmutableSet secondaryJobSites, @Nullable SoundEvent workSound, CallbackInfoReturnable cir) { - if (key.equals("cleric")) + if (key == VillagerProfession.CLERIC && !handled) { - cir.setReturnValue(register(registry, key, heldWorkstation, acquirableWorkstation, ImmutableSet.of(Items.NETHER_WART), ImmutableSet.of(Blocks.SOUL_SAND), workSound)); + handled = true; // recursion otherwise. Probably should just be a redirect but let's see if this works. Or even better redirect the accessors/accesses so other mod code doesn't break + cir.setReturnValue(register(registry, key, heldWorkstation, acquirableWorkstation, gatherableItems, ImmutableSet.of(Blocks.SOUL_SAND), workSound)); } } }