I have a really strange issue with variable initialization during a constructor call, in certain classes.
This issue occurs in that project and for example on that line.
I tried to debug it and even at the end of initEntity()
method the variable pickupDelay
has its value, but if I try to print its value after that method, it's magically null. I have similar problems if I try to extend class Entity
, and initialize its fields, during constructor call. And variable is not set to null anywhere in the code.
This probably doesn't happen to static variables.
So maybe better question would be, what can cause that already initialized (final or not final) variablse are set to null.
short video about the issue https://youtu.be/otizERrYSVU
my code to test the issue:
CompoundTag itemTag = NBTIO.putItemHelper(Item.get(0));
itemTag.setName("Item");
CompoundTag nbt = new CompoundTag().putList(new ListTag<DoubleTag>("Pos").add(new DoubleTag("", 0))
.add(new DoubleTag("", 0)).add(new DoubleTag("", 0)))
.putList(new ListTag<DoubleTag>("Motion").add(new DoubleTag("", 0))
.add(new DoubleTag("", 0)).add(new DoubleTag("", 0)))
.putList(new ListTag<FloatTag>("Rotation")
.add(new FloatTag("", new java.util.Random().nextFloat() * 360))
.add(new FloatTag("", 0)))
.putShort("Health", 5).putCompound("Item", itemTag).putShort("PickupDelay", 40); //value 40
EntityItem item = new EntityItem(this.defaultLevel.getChunk(0, 0, true), nbt); //new instance
item.pickupDelay changes to 0 unexpectedly