From e83a5ba74e3ceb0918e0e7936581160d8ef09b89 Mon Sep 17 00:00:00 2001 From: TheDeathlyCow Date: Fri, 6 Oct 2023 19:27:05 +1300 Subject: [PATCH] fix broken tests --- .../frostiful/test/damage/HotFloorTests.java | 36 +++---- .../test/effects/LocalTemperatureTests.java | 39 ++++++-- .../sun_lichen/SunLichenCollisionTests.java | 95 +++++++++++++------ 3 files changed, 115 insertions(+), 55 deletions(-) diff --git a/src/testmod/java/com/github/thedeathlycow/frostiful/test/damage/HotFloorTests.java b/src/testmod/java/com/github/thedeathlycow/frostiful/test/damage/HotFloorTests.java index c0a0b537..e9eaa568 100644 --- a/src/testmod/java/com/github/thedeathlycow/frostiful/test/damage/HotFloorTests.java +++ b/src/testmod/java/com/github/thedeathlycow/frostiful/test/damage/HotFloorTests.java @@ -50,29 +50,33 @@ public void resetController(ServerWorld serverWorld) { @GameTest(batchId = "hotFloorTests", templateName = "frostiful-test:sun_lichen_tests.platform") public void when_villager_standing_on_magma_block_then_villager_is_heated(TestContext context) { - var config = Frostiful.getConfig(); - expectVillagerIsHeated(context, Blocks.MAGMA_BLOCK.getDefaultState(), config.freezingConfig.getHeatFromHotFloor()); - } + int temperatureChange = Frostiful.getConfig().freezingConfig.getHeatFromHotFloor(); - private static void expectVillagerIsHeated(TestContext context, BlockState state, int temperatureChange) { final BlockPos pos = new BlockPos(1, 3, 1); - final int temperature = -1000; + final int initialFreeze = -1000; final VillagerEntity entity = context.spawnMob(EntityType.VILLAGER, pos); - final Function temperatureGetter = TemperatureAware::thermoo$getTemperature; - - entity.thermoo$setTemperature(temperature); - context.expectEntityWithData(pos, EntityType.VILLAGER, temperatureGetter, temperature); - context.setBlockState(pos.down(), state); - context.waitAndRun(5, () -> context.addInstantFinalTask(() -> context.testEntityProperty( - entity, - temperatureGetter, - "temperature", - temperature + (temperatureChange * ((int) context.getTick() - 1)) - ))); + entity.thermoo$setTemperature(initialFreeze); + context.expectEntityWithData(pos, EntityType.VILLAGER, TemperatureAware::thermoo$getTemperature, initialFreeze); + context.setBlockState(pos.down(), Blocks.MAGMA_BLOCK.getDefaultState()); + context.waitAndRun( + 5, () -> { + context.addInstantFinalTask(() -> { + context.assertTrue( + entity.thermoo$getTemperature() > initialFreeze, + String.format( + "Villager temperature of %d is not greater than %d", + entity.thermoo$getTemperature(), + initialFreeze + ) + ); + } + ); + } + ); } } diff --git a/src/testmod/java/com/github/thedeathlycow/frostiful/test/effects/LocalTemperatureTests.java b/src/testmod/java/com/github/thedeathlycow/frostiful/test/effects/LocalTemperatureTests.java index f3ae03ff..eb6c8621 100644 --- a/src/testmod/java/com/github/thedeathlycow/frostiful/test/effects/LocalTemperatureTests.java +++ b/src/testmod/java/com/github/thedeathlycow/frostiful/test/effects/LocalTemperatureTests.java @@ -1,14 +1,19 @@ package com.github.thedeathlycow.frostiful.test.effects; import com.github.thedeathlycow.thermoo.api.temperature.EnvironmentController; +import com.github.thedeathlycow.thermoo.api.temperature.EnvironmentControllerDecorator; import com.github.thedeathlycow.thermoo.api.temperature.EnvironmentManager; import net.minecraft.block.Blocks; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityType; import net.minecraft.entity.passive.VillagerEntity; +import net.minecraft.server.world.ServerWorld; +import net.minecraft.test.AfterBatch; +import net.minecraft.test.BeforeBatch; import net.minecraft.test.GameTest; import net.minecraft.test.TestContext; import net.minecraft.util.math.BlockPos; +import net.minecraft.world.World; @SuppressWarnings("unused") public class LocalTemperatureTests { @@ -16,7 +21,7 @@ public class LocalTemperatureTests { @GameTest(templateName = "frostiful-test:effects.local_temperature") public void villager_is_warmed_by_torch(TestContext context) { BlockPos pos = new BlockPos(1, 2, 1); - int temperature = -5300; + int temperature = -2000; EnvironmentController controller = EnvironmentManager.INSTANCE.getController(); @@ -37,7 +42,11 @@ public void villager_is_warmed_by_torch(TestContext context) { () -> { context.addInstantFinalTask(() -> context.assertTrue( villager.thermoo$getTemperature() > temperature, - "Villager must be warmed" + String.format( + "Villager temperature of %d is not greater than %d", + villager.thermoo$getTemperature(), + temperature + ) )); } ); @@ -46,7 +55,7 @@ public void villager_is_warmed_by_torch(TestContext context) { @GameTest(templateName = "frostiful-test:effects.local_temperature") public void villager_in_boat_is_warmed_by_torch(TestContext context) { BlockPos pos = new BlockPos(1, 2, 1); - int temperature = -5300; + int temperature = -2000; EnvironmentController controller = EnvironmentManager.INSTANCE.getController(); @@ -81,7 +90,11 @@ public void villager_in_boat_is_warmed_by_torch(TestContext context) { () -> { context.addInstantFinalTask(() -> context.assertTrue( villager.thermoo$getTemperature() > temperature, - "Villager must be warmed" + String.format( + "Villager temperature of %d is not greater than %d", + villager.thermoo$getTemperature(), + temperature + ) )); } ); @@ -91,7 +104,7 @@ public void villager_in_boat_is_warmed_by_torch(TestContext context) { @GameTest(templateName = "frostiful-test:effects.local_temperature") public void villager_is_not_warmed(TestContext context) { BlockPos pos = new BlockPos(1, 2, 1); - int temperature = -5300; + int temperature = -2000; EnvironmentController controller = EnvironmentManager.INSTANCE.getController(); @@ -111,10 +124,18 @@ public void villager_is_not_warmed(TestContext context) { context.waitAndRun( 5L, () -> { - context.addInstantFinalTask(() -> context.assertTrue( - villager.thermoo$getTemperature() == temperature, - "Villager must be warmed" - )); + context.addInstantFinalTask(() -> { + int villagerTemperature = villager.thermoo$getTemperature(); + context.assertTrue( + villagerTemperature == temperature, + String.format( + "Villager temperature of %d does not match expected %d", + villagerTemperature, + temperature + ) + ); + } + ); } ); } diff --git a/src/testmod/java/com/github/thedeathlycow/frostiful/test/sun_lichen/SunLichenCollisionTests.java b/src/testmod/java/com/github/thedeathlycow/frostiful/test/sun_lichen/SunLichenCollisionTests.java index bc76e238..e413b12e 100644 --- a/src/testmod/java/com/github/thedeathlycow/frostiful/test/sun_lichen/SunLichenCollisionTests.java +++ b/src/testmod/java/com/github/thedeathlycow/frostiful/test/sun_lichen/SunLichenCollisionTests.java @@ -9,6 +9,7 @@ import com.github.thedeathlycow.thermoo.api.temperature.TemperatureAware; import net.fabricmc.fabric.api.gametest.v1.FabricGameTest; import net.minecraft.block.Block; +import net.minecraft.entity.Entity; import net.minecraft.entity.EntityType; import net.minecraft.entity.LivingEntity; import net.minecraft.entity.mob.MobEntity; @@ -66,6 +67,7 @@ public void hot_lichen_damages(TestContext context) { final BlockPos pos = new BlockPos(1, 2, 1); final MobEntity entity = context.spawnMob(EntityType.VILLAGER, pos); + context.expectEntityWithData(pos, EntityType.VILLAGER, LivingEntity::getHealth, entity.getMaxHealth()); context.setBlockState(pos, FBlocks.HOT_SUN_LICHEN.getDefaultState()); @@ -73,56 +75,89 @@ public void hot_lichen_damages(TestContext context) { } @GameTest(batchId = "sunLichenCollision", templateName = "frostiful-test:sun_lichen_tests.platform") - public void hot_lichen_warms_appropriate_amount(TestContext context) { - expectVillagerIsWarmedWithFreezing(context, FBlocks.HOT_SUN_LICHEN); + public void cold_lichen_does_not_warm(TestContext context) { + final BlockPos pos = new BlockPos(1, 2, 1); + + final MobEntity entity = context.spawnMob(EntityType.VILLAGER, pos); + final Function frostGetter = TemperatureAware::thermoo$getTemperature; + + entity.thermoo$setTemperature(0); + context.expectEntityWithData(pos, EntityType.VILLAGER, frostGetter, 0); + + context.setBlockState(pos, FBlocks.COLD_SUN_LICHEN.getDefaultState()); + + context.expectEntityWithDataEnd(pos, EntityType.VILLAGER, frostGetter, 0); } @GameTest(batchId = "sunLichenCollision", templateName = "frostiful-test:sun_lichen_tests.platform") - public void warm_lichen_warms_appropriate_amount(TestContext context) { - expectVillagerIsWarmedWithFreezing(context, FBlocks.WARM_SUN_LICHEN); + public void sun_lichen_does_not_overheat(TestContext context) { + final BlockPos pos = new BlockPos(1, 2, 1); + + final MobEntity entity = context.spawnMob(EntityType.VILLAGER, pos); + final Function frostGetter = TemperatureAware::thermoo$getTemperature; + + int freezeAmount = -500; + entity.thermoo$setTemperature(freezeAmount); + context.expectEntityWithData(pos, EntityType.VILLAGER, frostGetter, freezeAmount); + + context.setBlockState(pos, FBlocks.HOT_SUN_LICHEN.getDefaultState()); + + context.expectEntityWithDataEnd(pos, EntityType.VILLAGER, frostGetter, 0); } @GameTest(batchId = "sunLichenCollision", templateName = "frostiful-test:sun_lichen_tests.platform") - public void cool_lichen_warms_appropriate_amount(TestContext context) { - expectVillagerIsWarmedWithFreezing(context, FBlocks.COOL_SUN_LICHEN); + public void sun_lichen_overheat_burns_villager(TestContext context) { + final BlockPos pos = new BlockPos(1, 2, 1); + + final MobEntity entity = context.spawnMob(EntityType.VILLAGER, pos); + + int freezeAmount = -500; + entity.thermoo$setTemperature(freezeAmount); + context.expectEntityWithData(pos, EntityType.VILLAGER, TemperatureAware::thermoo$getTemperature, freezeAmount); + + context.setBlockState(pos, FBlocks.HOT_SUN_LICHEN.getDefaultState()); + + context.expectEntityWithDataEnd(pos, EntityType.VILLAGER, Entity::isOnFire, true); } @GameTest(batchId = "sunLichenCollision", templateName = "frostiful-test:sun_lichen_tests.platform") - public void cold_lichen_does_not_warm(TestContext context) { - expectVillagerIsWarmedWithFreezing(context, FBlocks.COLD_SUN_LICHEN); + public void hot_lichen_warms(TestContext context) { + expectWarmLichenWarmsVillager(context, FBlocks.HOT_SUN_LICHEN); } @GameTest(batchId = "sunLichenCollision", templateName = "frostiful-test:sun_lichen_tests.platform") - public void sun_lichen_does_not_overheat(TestContext context) { - expectVillagerIsWarmedWithFreezing(context, FBlocks.HOT_SUN_LICHEN, -500, 0); + public void warm_lichen_warms(TestContext context) { + expectWarmLichenWarmsVillager(context, FBlocks.WARM_SUN_LICHEN); } - private static void expectVillagerIsWarmedWithFreezing(TestContext context, Block block) { - FrostifulConfig config = Frostiful.getConfig(); - - final int level = ((SunLichenBlock) block).getHeatLevel(); - int freezeAmount = -3000; - int expectedTemperature = freezeAmount + level * config.freezingConfig.getSunLichenHeatPerLevel(); - - expectVillagerIsWarmedWithFreezing(context, block, freezeAmount, expectedTemperature); + @GameTest(batchId = "sunLichenCollision", templateName = "frostiful-test:sun_lichen_tests.platform") + public void cool_lichen_warms(TestContext context) { + expectWarmLichenWarmsVillager(context, FBlocks.COOL_SUN_LICHEN); } - private static void expectVillagerIsWarmedWithFreezing( - TestContext context, - Block block, - int freezeAmount, - int expectedTemperature - ) { + private static void expectWarmLichenWarmsVillager(TestContext context, Block warmLichen) { final BlockPos pos = new BlockPos(1, 2, 1); final MobEntity entity = context.spawnMob(EntityType.VILLAGER, pos); final Function frostGetter = TemperatureAware::thermoo$getTemperature; - entity.thermoo$setTemperature(freezeAmount); - context.expectEntityWithData(pos, EntityType.VILLAGER, frostGetter, freezeAmount); - - context.setBlockState(pos, block.getDefaultState()); - - context.expectEntityWithDataEnd(pos, EntityType.VILLAGER, frostGetter, expectedTemperature); + int initialTemperature = -2000; + entity.thermoo$setTemperature(initialTemperature); + context.expectEntityWithData(pos, EntityType.VILLAGER, frostGetter, initialTemperature); + + context.setBlockState(pos, warmLichen.getDefaultState()); + + context.waitAndRun(10, () -> { + context.addInstantFinalTask(() -> { + context.assertTrue( + entity.thermoo$getTemperature() > -2000, + String.format( + "Villager temperature of %d is not greater than %d", + entity.thermoo$getTemperature(), + initialTemperature + ) + ); + }); + }); } }