Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions src/gametest/java/carpetextra/test/WartFarming.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<VillagerProfession> registry, RegistryKey<VillagerProfession> key, Predicate<RegistryEntry<PointOfInterestType>> heldWorkstation, Predicate<RegistryEntry<PointOfInterestType>> acquirableWorkstation, ImmutableSet<Item> gatherableItems, ImmutableSet<Block> secondaryJobSites, @Nullable SoundEvent workSound, CallbackInfoReturnable<VillagerProfession> 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));
}
}
}
Loading