Skip to content

Commit

Permalink
fix broken tests
Browse files Browse the repository at this point in the history
  • Loading branch information
TheDeathlyCow committed Oct 6, 2023
1 parent a74fa3b commit e83a5ba
Show file tree
Hide file tree
Showing 3 changed files with 115 additions and 55 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<VillagerEntity, Integer> 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
)
);
}
);
}
);
}

}
Original file line number Diff line number Diff line change
@@ -1,22 +1,27 @@
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 {

@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();

Expand All @@ -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
)
));
}
);
Expand All @@ -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();

Expand Down Expand Up @@ -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
)
));
}
);
Expand All @@ -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();

Expand All @@ -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
)
);
}
);
}
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -66,63 +67,97 @@ 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());
context.expectEntityWithDataEnd(pos, EntityType.VILLAGER, LivingEntity::getHealth, entity.getMaxHealth() - 1.0f);
}

@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<VillagerEntity, Integer> 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<VillagerEntity, Integer> 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<VillagerEntity, Integer> 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
)
);
});
});
}
}

0 comments on commit e83a5ba

Please sign in to comment.