Skip to content

Commit

Permalink
25w03a game tests (#4385)
Browse files Browse the repository at this point in the history
* 25w03a game tests

* Cleanup and improvements

* Update fabric-gametest-api-v1/src/main/java/net/fabricmc/fabric/impl/gametest/TestAnnotationLocator.java

Co-authored-by: Joseph Burton <[email protected]>

* Use an 8x8 empty structure by default

* Use a dedicated RegistryLoaderMixin instead of hacking around registry sync's api

* Fix

* Checkstyle

---------

Co-authored-by: Joseph Burton <[email protected]>
  • Loading branch information
modmuss50 and Earthcomputer authored Jan 21, 2025
1 parent bcdf965 commit 73a52b4
Show file tree
Hide file tree
Showing 45 changed files with 849 additions and 802 deletions.
12 changes: 6 additions & 6 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -631,12 +631,12 @@ subprojects {
testmodImplementation sourceSets.main.output

// Make all modules depend on the gametest api (and thus res loader) to try and promote its usage.
// if (project.name != "fabric-gametest-api-v1") {
// testmodImplementation project(path: ':fabric-gametest-api-v1', configuration: 'namedElements')
// testmodClientImplementation project(":fabric-gametest-api-v1").sourceSets.client.output
// testmodImplementation project(path: ':fabric-resource-loader-v0', configuration: 'namedElements')
// testmodClientImplementation project(":fabric-resource-loader-v0").sourceSets.client.output
// }
if (project.name != "fabric-gametest-api-v1") {
testmodImplementation project(path: ':fabric-gametest-api-v1', configuration: 'namedElements')
testmodClientImplementation project(":fabric-gametest-api-v1").sourceSets.client.output
testmodImplementation project(path: ':fabric-resource-loader-v0', configuration: 'namedElements')
testmodClientImplementation project(":fabric-resource-loader-v0").sourceSets.client.output
}

// Make all testmods run with registry-sync-v0 as it is required to register new objects.
if (project.name != "fabric-registry-sync-v0") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@

import net.minecraft.test.TestContext;

import net.fabricmc.fabric.api.gametest.v1.GameTest;

public class FabricApiBaseGameTest {
//@GameTest(templateName = FabricGameTest.EMPTY_STRUCTURE) TODO 1.21.5 tests
@GameTest
public void auditMixins(TestContext context) {
MixinEnvironment.getCurrentEnvironment().audit();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,16 @@
import net.minecraft.test.TestContext;
import net.minecraft.util.math.BlockPos;

import net.fabricmc.fabric.api.gametest.v1.GameTest;

public class EntitySelectorGameTest {
private void spawn(TestContext context, float health) {
MobEntity entity = context.spawnMob(EntityType.CREEPER, BlockPos.ORIGIN);
entity.setAiDisabled(true);
entity.setHealth(health);
}

// @GameTest(templateName = FabricGameTest.EMPTY_STRUCTURE) TODO 1.21.5 tests
@GameTest
public void testEntitySelector(TestContext context) {
BlockPos absolute = context.getAbsolutePos(BlockPos.ORIGIN);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,33 @@

package net.fabricmc.fabric.test.content.registry;

import java.util.function.BiConsumer;
import java.util.function.Consumer;

import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.block.ComposterBlock;
import net.minecraft.block.HopperBlock;
import net.minecraft.block.entity.AbstractFurnaceBlockEntity;
import net.minecraft.block.entity.BrewingStandBlockEntity;
import net.minecraft.block.entity.HopperBlockEntity;
import net.minecraft.component.DataComponentTypes;
import net.minecraft.component.type.PotionContentsComponent;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.potion.Potions;
import net.minecraft.test.TestContext;
import net.minecraft.text.Text;
import net.minecraft.util.Hand;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
import net.minecraft.world.GameMode;

import net.fabricmc.fabric.api.gametest.v1.GameTest;

public class ContentRegistryGameTest {
/* TODO 1.21.5 tests
@GameTest(templateName = FabricGameTest.EMPTY_STRUCTURE)
@GameTest
public void testCompostingChanceRegistry(TestContext context) {
BlockPos pos = new BlockPos(0, 1, 0);
context.setBlockState(pos, Blocks.COMPOSTER);
Expand All @@ -28,11 +52,11 @@ public void testCompostingChanceRegistry(TestContext context) {
// If on level 0, composting always increases composter level
context.useBlock(pos, player);
context.expectBlockProperty(pos, ComposterBlock.LEVEL, 1);
context.assertEquals(obsidian.getCount(), 63, "obsidian stack count");
context.assertEquals(obsidian.getCount(), 63, Text.literal("obsidian stack count"));
context.complete();
}

@GameTest(templateName = FabricGameTest.EMPTY_STRUCTURE)
@GameTest
public void testFlattenableBlockRegistry(TestContext context) {
BlockPos pos = new BlockPos(0, 1, 0);
context.setBlockState(pos, Blocks.RED_WOOL);
Expand All @@ -41,7 +65,7 @@ public void testFlattenableBlockRegistry(TestContext context) {
player.setStackInHand(Hand.MAIN_HAND, shovel);
context.useBlock(pos, player);
context.expectBlock(Blocks.YELLOW_WOOL, pos);
context.assertEquals(shovel.getDamage(), 1, "shovel damage");
context.assertEquals(shovel.getDamage(), 1, Text.literal("shovel damage"));
context.complete();
}

Expand All @@ -52,21 +76,15 @@ private void smelt(TestContext context, ItemStack fuelStack, BiConsumer<Abstract
BlockState furnaceState = Blocks.BLAST_FURNACE.getDefaultState();

context.setBlockState(furnacePos, furnaceState);
if (!(context.getBlockEntity(furnacePos) instanceof AbstractFurnaceBlockEntity furnace)) {
throw new AssertionError("Furnace was not placed");
}
AbstractFurnaceBlockEntity furnace = context.getBlockEntity(furnacePos, AbstractFurnaceBlockEntity.class);

// Create a hopper that attempts to insert fuel into the furnace
BlockPos hopperPos = furnacePos.east();
BlockState hopperState = Blocks.HOPPER.getDefaultState()
.with(HopperBlock.FACING, context.getRotation().rotate(Direction.WEST));

context.setBlockState(hopperPos, hopperState);
if (!(context.getBlockEntity(hopperPos) instanceof HopperBlockEntity hopper)) {
throw new AssertionError("Hopper was not placed");
}
HopperBlockEntity hopper = context.getBlockEntity(hopperPos, HopperBlockEntity.class);

// Insert the fuel into the hopper, which transfers it into the furnace
hopper.setStack(0, fuelStack.copy());
Expand All @@ -80,53 +98,53 @@ private void smelt(TestContext context, ItemStack fuelStack, BiConsumer<Abstract

private void smeltCompleted(TestContext context, ItemStack fuelStack) {
smelt(context, fuelStack, (furnace, hopper) -> {
context.assertTrue(hopper.isEmpty(), "fuel hopper should have been emptied");
context.assertTrue(hopper.isEmpty(), Text.literal("fuel hopper should have been emptied"));

context.assertTrue(furnace.getStack(0).isEmpty(), "furnace input slot should have been emptied");
context.assertTrue(furnace.getStack(0).isEmpty(), "furnace fuel slot should have been emptied");
context.assertTrue(ItemStack.areEqual(furnace.getStack(2), new ItemStack(Items.IRON_INGOT, 1)), "one iron ingot should have been smelted and placed into the furnace output slot");
context.assertTrue(furnace.getStack(0).isEmpty(), Text.literal("furnace input slot should have been emptied"));
context.assertTrue(furnace.getStack(0).isEmpty(), Text.literal("furnace fuel slot should have been emptied"));
context.assertTrue(ItemStack.areEqual(furnace.getStack(2), new ItemStack(Items.IRON_INGOT, 1)), Text.literal("one iron ingot should have been smelted and placed into the furnace output slot"));

context.complete();
});
}

private void smeltFailed(TestContext context, ItemStack fuelStack) {
smelt(context, fuelStack, (furnace, hopper) -> {
context.assertTrue(ItemStack.areEqual(hopper.getStack(0), fuelStack), "fuel hopper should not have been emptied");
context.assertTrue(ItemStack.areEqual(hopper.getStack(0), fuelStack), Text.literal("fuel hopper should not have been emptied"));

context.assertTrue(ItemStack.areEqual(furnace.getStack(0), new ItemStack(Items.RAW_IRON, 1)), "furnace input slot should not have been emptied");
context.assertTrue(furnace.getStack(1).isEmpty(), "furnace fuel slot should not have been filled");
context.assertTrue(furnace.getStack(2).isEmpty(), "furnace output slot should not have been filled");
context.assertTrue(ItemStack.areEqual(furnace.getStack(0), new ItemStack(Items.RAW_IRON, 1)), Text.literal("furnace input slot should not have been emptied"));
context.assertTrue(furnace.getStack(1).isEmpty(), Text.literal("furnace fuel slot should not have been filled"));
context.assertTrue(furnace.getStack(2).isEmpty(), Text.literal("furnace output slot should not have been filled"));

context.complete();
});
}

@GameTest(templateName = FabricGameTest.EMPTY_STRUCTURE, tickLimit = 110)
@GameTest(maxTicks = 110)
public void testSmeltingFuelIncludedByItem(TestContext context) {
// Item with 50 fuel time x4 = 200 fuel time
smeltCompleted(context, new ItemStack(ContentRegistryTest.SMELTING_FUEL_INCLUDED_BY_ITEM, 4));
}

@GameTest(templateName = FabricGameTest.EMPTY_STRUCTURE, tickLimit = 110)
@GameTest(maxTicks = 110)
public void testSmeltingFuelIncludedByTag(TestContext context) {
// Item in tag with 100 fuel time x2 = 200 fuel time
smeltCompleted(context, new ItemStack(ContentRegistryTest.SMELTING_FUEL_INCLUDED_BY_TAG, 2));
}

@GameTest(templateName = FabricGameTest.EMPTY_STRUCTURE, tickLimit = 110)
@GameTest(maxTicks = 110)
public void testSmeltingFuelExcludedByTag(TestContext context) {
// Item is in both the smelting fuels tag and the excluded smithing fuels tag
smeltFailed(context, new ItemStack(ContentRegistryTest.SMELTING_FUEL_EXCLUDED_BY_TAG));
}

@GameTest(templateName = FabricGameTest.EMPTY_STRUCTURE, tickLimit = 110)
@GameTest(maxTicks = 110)
public void testSmeltingFuelExcludedByVanillaTag(TestContext context) {
// Item is in both the smelting fuel tag and vanilla's excluded non-flammable wood tag
smeltFailed(context, new ItemStack(ContentRegistryTest.SMELTING_FUEL_EXCLUDED_BY_VANILLA_TAG));
}

@GameTest(templateName = FabricGameTest.EMPTY_STRUCTURE)
@GameTest
public void testStrippableBlockRegistry(TestContext context) {
BlockPos pos = new BlockPos(0, 1, 0);
context.setBlockState(pos, Blocks.QUARTZ_PILLAR);
Expand All @@ -135,11 +153,11 @@ public void testStrippableBlockRegistry(TestContext context) {
player.setStackInHand(Hand.MAIN_HAND, axe);
context.useBlock(pos, player);
context.expectBlock(Blocks.HAY_BLOCK, pos);
context.assertEquals(axe.getDamage(), 1, "axe damage");
context.assertEquals(axe.getDamage(), 1, Text.literal("axe damage"));
context.complete();
}

@GameTest(templateName = FabricGameTest.EMPTY_STRUCTURE)
@GameTest
public void testTillableBlockRegistry(TestContext context) {
BlockPos pos = new BlockPos(0, 1, 0);
context.setBlockState(pos, Blocks.GREEN_WOOL);
Expand All @@ -148,11 +166,11 @@ public void testTillableBlockRegistry(TestContext context) {
player.setStackInHand(Hand.MAIN_HAND, hoe);
context.useBlock(pos, player);
context.expectBlock(Blocks.LIME_WOOL, pos);
context.assertEquals(hoe.getDamage(), 1, "hoe damage");
context.assertEquals(hoe.getDamage(), 1, Text.literal("hoe damage"));
context.complete();
}

@GameTest(templateName = FabricGameTest.EMPTY_STRUCTURE)
@GameTest
public void testOxidizableBlocksRegistry(TestContext context) {
// Test de-oxidation. (the registry does not make the blocks oxidize.)
PlayerEntity player = context.createMockPlayer(GameMode.SURVIVAL);
Expand All @@ -162,15 +180,15 @@ public void testOxidizableBlocksRegistry(TestContext context) {
player.setStackInHand(Hand.MAIN_HAND, axe);
context.useBlock(pos, player);
context.expectBlock(Blocks.GOLD_ORE, pos);
context.assertEquals(axe.getDamage(), 1, "axe damage");
context.assertEquals(axe.getDamage(), 1, Text.literal("axe damage"));
context.useBlock(pos, player);
context.expectBlock(Blocks.IRON_ORE, pos);
context.useBlock(pos, player);
context.expectBlock(Blocks.COPPER_ORE, pos);
context.complete();
}

@GameTest(templateName = FabricGameTest.EMPTY_STRUCTURE)
@GameTest
public void testWaxableBlocksRegistry(TestContext context) {
PlayerEntity player = context.createMockPlayer(GameMode.SURVIVAL);
BlockPos pos = new BlockPos(0, 1, 0);
Expand All @@ -179,47 +197,42 @@ public void testWaxableBlocksRegistry(TestContext context) {
player.setStackInHand(Hand.MAIN_HAND, honeycomb);
context.useBlock(pos, player);
context.expectBlock(Blocks.DEEPSLATE_DIAMOND_ORE, pos);
context.assertEquals(honeycomb.getCount(), 63, "honeycomb count");
context.assertEquals(honeycomb.getCount(), 63, Text.literal("honeycomb count"));
ItemStack axe = new ItemStack(Items.NETHERITE_AXE);
player.setStackInHand(Hand.MAIN_HAND, axe);
context.useBlock(pos, player);
context.expectBlock(Blocks.DIAMOND_ORE, pos);
context.assertEquals(axe.getDamage(), 1, "axe damage");
context.assertEquals(axe.getDamage(), 1, Text.literal("axe damage"));
context.complete();
}

private void brew(TestContext context, ItemStack input, ItemStack bottle, Consumer<BrewingStandBlockEntity> callback) {
BlockPos pos = new BlockPos(0, 1, 0);
context.setBlockState(pos, Blocks.BREWING_STAND);
if (!(context.getBlockEntity(pos) instanceof BrewingStandBlockEntity brewingStand)) {
throw new AssertionError("Brewing stand was not placed");
}
BrewingStandBlockEntity brewingStand = context.getBlockEntity(pos, BrewingStandBlockEntity.class);

brewingStand.setStack(0, bottle);
brewingStand.setStack(3, input);
brewingStand.setStack(4, new ItemStack(Items.BLAZE_POWDER, 64));
context.waitAndRun(401, () -> callback.accept(brewingStand));
}

@GameTest(templateName = FabricGameTest.EMPTY_STRUCTURE, tickLimit = 410)
@GameTest(maxTicks = 410)
public void testBrewingFlower(TestContext context) {
brew(context, new ItemStack(Items.DANDELION), PotionContentsComponent.createStack(Items.POTION, Potions.AWKWARD), brewingStand -> {
ItemStack bottle = brewingStand.getStack(0);
PotionContentsComponent potion = bottle.getOrDefault(DataComponentTypes.POTION_CONTENTS, PotionContentsComponent.DEFAULT);
context.assertEquals(potion.potion().orElseThrow(), Potions.HEALING, "brewed potion");
context.assertEquals(potion.potion().orElseThrow(), Potions.HEALING, Text.literal("brewed potion"));
context.complete();
});
}

@GameTest(templateName = FabricGameTest.EMPTY_STRUCTURE, tickLimit = 410)
@GameTest(maxTicks = 410)
public void testBrewingDirt(TestContext context) {
brew(context, new ItemStack(Items.DIRT), PotionContentsComponent.createStack(Items.POTION, Potions.AWKWARD), brewingStand -> {
ItemStack bottle = brewingStand.getStack(0);
context.assertTrue(bottle.getItem() instanceof ContentRegistryTest.DirtyPotionItem, "potion became dirty");
context.assertTrue(bottle.getItem() instanceof ContentRegistryTest.DirtyPotionItem, Text.literal("potion became dirty"));
context.complete();
});
}
*/
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,17 @@
import net.minecraft.test.TestContext;
import net.minecraft.text.Text;

import net.fabricmc.fabric.api.gametest.v1.GameTest;
import net.fabricmc.fabric.api.registry.FlammableBlockRegistry;

public class FlammableTest {
/**
* Regression test for <a href="https://github.com/FabricMC/fabric/issues/2108">FlammableBlockRegistry ignoring tags on first load</a>.
*/
// @GameTest(templateName = FabricGameTest.EMPTY_STRUCTURE) TODO 1.21.5 tests
@GameTest
public void testFlammableTag(TestContext context) {
if (FlammableBlockRegistry.getDefaultInstance().get(Blocks.SAND).getBurnChance() != 4) {
context.method_66943(Text.literal("Expected blocks in the sand tag to be flammable!"));
throw context.createError(Text.literal("Expected blocks in the sand tag to be flammable!"));
}

context.complete();
Expand Down
Loading

0 comments on commit 73a52b4

Please sign in to comment.