Skip to content

Commit a4de4e2

Browse files
thiakilshartte
andauthored
Refactor the living entity damage tests to detect prior damage and be much faster (#2312)
Co-authored-by: shartte <shartte@users.noreply.github.com>
1 parent bef5d09 commit a4de4e2

1 file changed

Lines changed: 9 additions & 4 deletions

File tree

tests/src/main/java/net/neoforged/neoforge/debug/entity/living/LivingEntityEventTests.java

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,7 @@ static void slimeSplitEvent(final DynamicTest test) {
277277
helper.assertTrue(!childSlimes.isEmpty(), "No child slimes received by event");
278278
for (Mob s : childSlimes) {
279279
helper.assertValueEqual("whatever", s.getPersistentData().getString("test.something").orElse(null), "NBT Data not copied");
280+
s.kill(helper.getLevel());
280281
}
281282

282283
Slime childlessSlime = helper.spawnWithNoFreeWill(EntityType.SLIME, 1, 1, 1);
@@ -355,10 +356,14 @@ static void livingDamageSequenceEvents(final DynamicTest test, final Registratio
355356
EnchantmentHelper.setEnchantments(player.getItemBySlot(EquipmentSlot.CHEST), enchants.toImmutable());
356357
player.getFoodData().setFoodLevel(1);
357358
})
358-
/* ServerPlayers have spawn invulnerability. This waits out that period.*/
359-
.thenIdle(2001)
360-
/* The player is damaged with a single point of damage which will be modified in the event listeners*/
361-
.thenExecute(player -> player.hurtServer(helper.getLevel(), new DamageSource(helper.getLevel().registryAccess().lookupOrThrow(Registries.DAMAGE_TYPE).getOrThrow(DamageTypes.MOB_ATTACK)), 1))
359+
.thenIdle(5)
360+
.thenExecute(player -> {
361+
// remove spawn invulnerability
362+
player.setClientLoaded(true);
363+
helper.assertTrue(player.getHealth() == player.getMaxHealth(), "Expected player to be at max health: " + player.getHealth() + " / " + player.getMaxHealth() + " - " + player.getLastDamageSource());
364+
/* The player is damaged with a single point of damage which will be modified in the event listeners*/
365+
player.hurtServer(helper.getLevel(), new DamageSource(helper.getLevel().registryAccess().lookupOrThrow(Registries.DAMAGE_TYPE).getOrThrow(DamageTypes.MOB_ATTACK)), 1);
366+
})
362367
/* The player's health and all the stored values from the events are checked to ensure they match the
363368
* expected values from our reduction functions and changes to the damage value.*/
364369
.thenWaitUntil(player -> {

0 commit comments

Comments
 (0)