Reliquary Reincarnations

Reliquary Reincarnations

51M Downloads

[1.20.1-2.0.36.1199] NPE Crash in AI with Twilight Cloak and Hoglins

TigerWalts opened this issue ยท 2 comments

commented

Having the Twilight Cloak near Hoglins may result in a crash. This has been observed in ATM9 0.0.45. It can also be reproduced with just Reliquary.

  • Forge 1.20.1 47.1.0
  • Reliquary 1.20.1-2.0.36.1199
  1. Create a world with cheats on
  2. Change your gamemode to creative and give yourself the Twilight Cloak
  3. Go somewhere dark enough for the cloak to give you the invisibility effect
  4. Give yourself a Hoglin spawn egg and use it to spawn a hoglin
  5. Change the gamemode to survival
  6. Drop the cloak and pick it up
    Repeat until the game crashes
  7. Reloading into the game will likely immediately crash if your saved state is to be near the hoglin in survival mode with the cloak
java.lang.NullPointerException: Ticking entity
	at java.util.Objects.requireNonNull(Objects.java:208) ~[?:?] {}
	at java.util.Optional.of(Optional.java:113) ~[?:?] {}
	at net.minecraft.world.entity.ai.behavior.declarative.MemoryAccessor.m_257512_(MemoryAccessor.java:30) ~[client-1.20.1-20230612.114412-srg.jar%23158!/:?] {re:classloading}
	at net.minecraft.world.entity.ai.behavior.StartAttacking.m_257271_(StartAttacking.java:37) ~[client-1.20.1-20230612.114412-srg.jar%23158!/:?] {re:classloading}
	at net.minecraft.world.entity.ai.behavior.declarative.BehaviorBuilder$1.m_257808_(BehaviorBuilder.java:53) ~[client-1.20.1-20230612.114412-srg.jar%23158!/:?] {re:classloading}
	at net.minecraft.world.entity.ai.behavior.OneShot.m_22554_(OneShot.java:20) ~[client-1.20.1-20230612.114412-srg.jar%23158!/:?] {re:classloading}
	at net.minecraft.world.entity.ai.Brain.m_21957_(Brain.java:533) ~[client-1.20.1-20230612.114412-srg.jar%23158!/:?] {re:classloading}
	at net.minecraft.world.entity.ai.Brain.m_21865_(Brain.java:492) ~[client-1.20.1-20230612.114412-srg.jar%23158!/:?] {re:classloading}
	at net.minecraft.world.entity.monster.hoglin.Hoglin.m_8024_(Hoglin.java:124) ~[client-1.20.1-20230612.114412-srg.jar%23158!/:?] {re:classloading}
        ...
	at net.minecraft.world.level.entity.EntityTickList.m_156910_(EntityTickList.java:54) ~[client-1.20.1-20230612.114412-srg.jar%23158!/:?] {re:classloading}

I checked the hoglin's save data between a crashing state and a normal state and their 'brain` tags are the same, containing an empty memories collection.

Because it didn't crash each time the invisibility effect was applied there may be a race involved.

The MobHelper.resetTarget() call may need to be run as a task at another point in the tick cycle, even though I can't see why it could cause this crash as it doesn't appear to remove any memories and sets them to Empty.

public static void resetTarget(Mob entity) {
resetTarget(entity, false);
}
public static void resetTarget(Mob entity, boolean resetRevengeTarget) {
Brain<?> brain = entity.getBrain();
for (var memory : TARGET_MEMORIES) {
if (brain.hasMemoryValue(memory)) {
emptyMemory(brain, memory);
}
}
entity.setTarget(null);
if (resetRevengeTarget) {
entity.setLastHurtByMob(null);
}
}
private static <T> void emptyMemory(Brain<?> brain, MemoryModuleType<T> memory) {
brain.setMemory(memory, Optional.empty());
}

commented

This affects the twilight cloak and the mob charm items.
The problem is that both use event.setNewTarget(null); in the LivingChangeTargetEvent when they should be simply cancelling the event via event.setCanceled(true);

commented

For those running into this problem and need a fix, you can disable the item in the player's Curios inventory as follows:

  1. Open the player's save data in an NBT editor:
  1. Locate the Cloak or Charm in the Curios inventory
  • The tag path to the inventory is: ForgeCaps>curios:inventory>Curios
  • Inside each Curios inventory you'll find the items in the tag path StacksHandler>Stacks>Items
  1. Once you have found the item, open the tag tag and set the enabled tag inside it to 0

CloakFix

If the item is in the main Inventory tag and is passively enabled, you may have to resort to deleting it.