Skip to content

Commit

Permalink
Backport gametests (not working perfectly)
Browse files Browse the repository at this point in the history
  • Loading branch information
embeddedt committed Sep 4, 2024
1 parent 15883f6 commit 00ded87
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@
import net.minecraft.world.level.block.RenderShape;
import net.minecraft.world.level.block.state.BlockBehaviour;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.material.Material;

public class NotAnAirBlock extends AirBlock {
public NotAnAirBlock() {
super(BlockBehaviour.Properties.of().noCollission().noLootTable().air());
super(BlockBehaviour.Properties.of(Material.AIR).noCollission().noLootTable().air());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,22 @@
import net.minecraft.client.resources.model.BakedModel;
import net.minecraft.client.resources.model.ModelBakery;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Registry;
import net.minecraft.core.RegistryAccess;
import net.minecraft.core.Vec3i;
import net.minecraft.core.registries.Registries;
import net.minecraft.gametest.framework.*;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.Difficulty;
import net.minecraft.world.level.DataPackConfig;
import net.minecraft.world.level.GameRules;
import net.minecraft.world.level.GameType;
import net.minecraft.world.level.LevelSettings;
import net.minecraft.world.level.WorldDataConfiguration;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.Rotation;
import net.minecraft.world.level.block.entity.BlockEntityType;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.levelgen.WorldOptions;
import net.minecraft.world.level.levelgen.presets.WorldPresets;
import net.minecraft.world.level.levelgen.structure.templatesystem.StructureTemplate;
import net.minecraftforge.client.event.ModelEvent;
Expand Down Expand Up @@ -100,7 +100,7 @@ public static void register(FMLConstructModEvent event) {
NETWORK_CHANNEL.registerMessage(0, SyncS2CPacket.class, SyncS2CPacket::encode, SyncS2CPacket::new, SyncS2CPacket::handle);
}

private static void registerModelForAllStates(ModelEvent.ModifyBakingResult event, Block block, BakedModel model) {
private static void registerModelForAllStates(ModelEvent.BakingCompleted event, Block block, BakedModel model) {
for(BlockState state : block.getStateDefinition().getPossibleStates()) {
event.getModels().put(BlockModelShaper.stateToModelLocation(state), model);
}
Expand All @@ -110,7 +110,7 @@ private static void registerModelForAllStates(ModelEvent.ModifyBakingResult even
* Inject custom models for test content.
*/
@SubscribeEvent
public static void onBakingModify(ModelEvent.ModifyBakingResult event) {
public static void onBakingModify(ModelEvent.BakingCompleted event) {
registerModelForAllStates(event, TEST_BLOCK.get(), new TestModel(event.getModels().get(ModelBakery.MISSING_MODEL_LOCATION)));
registerModelForAllStates(event, NOT_AN_AIR_BLOCK.get(), new InstrumentingModelWrapper<>(event.getModels().get(BlockModelShaper.stateToModelLocation(Blocks.STONE.defaultBlockState()))));
}
Expand All @@ -131,17 +131,17 @@ public static void createEmptyTemplate(ServerAboutToStartEvent event) {

@SubscribeEvent
public static void onScreenInit(ScreenEvent.Init.Post event) {
if(IS_AUTOMATED_TEST_RUN && (event.getScreen() instanceof TitleScreen || event.getScreen() instanceof AccessibilityOnboardingScreen) && !hasSeenMainMenu) {
if(IS_AUTOMATED_TEST_RUN && (event.getScreen() instanceof TitleScreen) && !hasSeenMainMenu) {
// Go for main engine start (create a new superflat automatically)
hasSeenMainMenu = true;
var mc = Minecraft.getInstance();
mc.options.renderDebug = true;
mc.forceSetScreen(new GenericDirtMessageScreen(Component.literal("Bootstrapping gametests...")));
String levelName = "embeddium-test-" + UUID.randomUUID();
LevelSettings settings = new LevelSettings(levelName, GameType.CREATIVE, false, Difficulty.PEACEFUL, true, new GameRules(), WorldDataConfiguration.DEFAULT);
mc.createWorldOpenFlows().createFreshLevel(settings.levelName(), settings, new WorldOptions(1024, false, false), registry -> {
return registry.registryOrThrow(Registries.WORLD_PRESET).getHolderOrThrow(WorldPresets.FLAT).value().createWorldDimensions();
});
LevelSettings settings = new LevelSettings(levelName, GameType.CREATIVE, false, Difficulty.PEACEFUL, true, new GameRules(), DataPackConfig.DEFAULT);
RegistryAccess registry = RegistryAccess.builtinCopy().freeze();
mc.createWorldOpenFlows().createFreshLevel(settings.levelName(), settings, registry,
registry.registryOrThrow(Registry.WORLD_PRESET_REGISTRY).getHolderOrThrow(WorldPresets.FLAT).value().createWorldGenSettings(1024, false, false));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.gametest.framework.GameTest;
import net.minecraft.gametest.framework.GameTestAssertException;
import net.minecraft.gametest.framework.GameTestHelper;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.state.BlockState;
Expand All @@ -13,6 +14,18 @@
import org.embeddedt.embeddium.impl.gametest.util.TestUtils;

public class EmbeddiumGameTests {
private static void assertTrue(boolean condition, String failMessage) {
if (!condition) {
throw new GameTestAssertException(failMessage);
}
}

private static void assertFalse(boolean condition, String failMessage) {
if (condition) {
throw new GameTestAssertException(failMessage);
}
}

/**
* Test that the hidesNeighborFace Forge extension is used correctly.
*/
Expand All @@ -24,9 +37,9 @@ public static void testBlockHidingNeighborFace(GameTestHelper helper) {
BlockState selfState = TestRegistry.TEST_BLOCK.get().defaultBlockState();
helper.setBlock(selfPos, selfState);
helper.setBlock(selfPos.relative(Direction.EAST), Blocks.STONE);
helper.assertTrue(cache.shouldDrawSide(selfState, helper.getLevel(), helper.absolutePos(selfPos), Direction.EAST), "Did not show face of neighbor block as expected");
assertTrue(cache.shouldDrawSide(selfState, helper.getLevel(), helper.absolutePos(selfPos), Direction.EAST), "Did not show face of neighbor block as expected");
helper.setBlock(selfPos.relative(Direction.EAST), selfState);
helper.assertFalse(cache.shouldDrawSide(selfState, helper.getLevel(), helper.absolutePos(selfPos), Direction.EAST), "Did not hide face of neighbor block as expected");
assertFalse(cache.shouldDrawSide(selfState, helper.getLevel(), helper.absolutePos(selfPos), Direction.EAST), "Did not hide face of neighbor block as expected");
helper.succeed();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public static Vec3 getClientPosition() {
public static boolean isChunkVisible(Vec3 position) {
return Minecraft.getInstance().submit(() -> {
// Verify chunk is rendered
BlockPos pos = BlockPos.containing(position.x, position.y, position.z);
BlockPos pos = new BlockPos(position.x, position.y, position.z);
return Minecraft.getInstance().levelRenderer.isChunkCompiled(pos);
}).join();
}
Expand Down

0 comments on commit 00ded87

Please sign in to comment.