Skip to content

Commit

Permalink
Fix potion test
Browse files Browse the repository at this point in the history
  • Loading branch information
TheEpicBlock committed May 13, 2024
1 parent 7f94c15 commit 522ddb9
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
4 changes: 3 additions & 1 deletion src/testmod/java/nl/theepicblock/polymc/testmod/Testmod.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@
import java.util.EnumMap;
import java.util.List;

import static nl.theepicblock.polymc.testmod.YellowStatusEffect.YELLOW;

public class Testmod implements ModInitializer {
private static final String MODID = "polymc-testmod";

Expand Down Expand Up @@ -82,7 +84,7 @@ public class Testmod implements ModInitializer {
public static final EntityType<?> TEST_ENTITY_OTHER = FabricEntityTypeBuilder.create().entityFactory(TestOtherEntity::new).trackRangeChunks(4).dimensions(EntityDimensions.fixed(0.5f, 0.5f)).build();
public static final EntityType<?> TEST_FLYING_WAXED_WEATHERED_CUT_COPPER_STAIRS_ENTITY = FabricEntityTypeBuilder.create().entityFactory(TestFlyingWaxedWeatheredCutCopperStairs::new).trackRangeChunks(4).dimensions(EntityDimensions.fixed(0.5f, 0.5f)).build();

public static final RegistryEntry<StatusEffect> TEST_EFFECT = Registry.registerReference(Registries.STATUS_EFFECT, id("yellow_effect"), new YellowStatusEffect(StatusEffectCategory.HARMFUL, 0xf4e42c));
public static final RegistryEntry<StatusEffect> TEST_EFFECT = Registry.registerReference(Registries.STATUS_EFFECT, id("yellow_effect"), new YellowStatusEffect(StatusEffectCategory.HARMFUL, YELLOW));
public static final Potion TEST_POTION_TYPE = Registry.register(Registries.POTION, id("yellow_potion"), new Potion(new StatusEffectInstance(TEST_EFFECT, 9600)));

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import net.minecraft.entity.effect.StatusEffectCategory;

public class YellowStatusEffect extends StatusEffect {
public static int YELLOW = 0xfff4e42c;
/**
* Helpful for automatic testing, to simulate the fact that
* this status effect will not be a registered one on the client
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@

import java.util.Objects;

import static nl.theepicblock.polymc.testmod.YellowStatusEffect.YELLOW;

public class MiscTests implements FabricGameTest {
// These tests are broken, I am aware

Expand Down Expand Up @@ -95,16 +97,17 @@ public void potionItem(TestContext ctx) {

// Create a potion item
var serverPotion = testPotion();
TestUtil.assertEq(serverPotion.get(DataComponentTypes.POTION_CONTENTS).getColor(), YELLOW, "Sanity check");
var clientPotion = map.getClientItem(serverPotion, null, ItemLocation.INVENTORY);

try {
YellowStatusEffect.SIMULATE_UNAVAILABLE = true;
var clientPotionData = clientPotion.get(DataComponentTypes.POTION_CONTENTS);
TestUtil.assertNonNull(clientPotionData, "polyd potions should still have potion data");
TestUtil.assertEq(clientPotionData.getColor(), 0xf4e42c, "potion should be yellow");
TestUtil.assertEq(clientPotionData.getColor(), YELLOW, "potion should be yellow");
TestUtil.assertEq(clientPotion.getName().getLiteralString(), serverPotion.getName().getLiteralString());

TestUtil.assertDifferent(serverPotion.get(DataComponentTypes.POTION_CONTENTS).customColor(), 0xf4e42c, "Untransformed item should be broken. This test may be invalid");
TestUtil.assertDifferent(serverPotion.get(DataComponentTypes.POTION_CONTENTS).getColor(), YELLOW, "Untransformed item should be broken. This test may be invalid");
} finally {
YellowStatusEffect.SIMULATE_UNAVAILABLE = false;
}
Expand Down

0 comments on commit 522ddb9

Please sign in to comment.