LLibrary

LLibrary

67M Downloads

latest update for Llbrary mod breaks minecolonies

CharCharthemonkey opened this issue · 10 comments

commented

when updating to the latest version of the mod it corrupts the colonies.dat file for minecolonies and only way to fix would be to load from a backup after downgrading and deleting the Llibrary files from the instance folder

commented

I'm one of the main devs of minecolonies, it seems you are trying to access the hashCode (in this case removing it from a map for example) before the entity stopped loading.

commented

@Raycoms I'm not quite following. Why is your hashCode throwing an NPE? It is by contract that hashCode should not crash. Your hash should also consistently return the same value.

commented

The hash doesn't need to consistently return same value as long as Object#equals(Object) reflects the change.

However, there is another violation the Object#hashCode() contract. It has the possiblity of two entities being equal determined by EntityCitizen#equals(Object), but with different hashcodes from EntityCitizen#hashCode(), given by the hash including super.hashCode(), which uses Entity#entityId, while equality does not include super.equals(Object) to involve Entity#entityId as well.

The contract states this requirement as:

If two objects are equal according to the equals(Object) method, then calling the hashCode method on each of the two objects must produce the same integer result.

commented

It crashes because for some reason your library calls the hash method on one of our citizens before the entity has finished instantiating.
(The only chance an object inside the hash is null)

commented

I also removed the super.hashCode(), yeah that shouldn't be there, it should be determined by only colonyId and CitizenId.

commented

Can you confirm that LLibrary is causing this?

commented

Correct, our code here is happening during capability attachment, which is before an entity has finished instantiation. There just needs to be improved null safety in equals and hashCode of EntityCitizen to support this.

commented
commented

You could fallback to super behavior instead, therefore using entityId.