Apotheosis

Apotheosis

81M Downloads

Crash issue with apoth_attrModifiedEvent, and it not checking for a null pointer exception. Includes the coding to fix it.

BladeAndFeather opened this issue ยท 1 comments

commented

package dev.shadowsoffire.attributeslib.mixin
class AttributeMapMixin
method apoth_attrModifiedEvent(AttributeInstance inst, CallbackInfo ci)

There is an issue with the above method.
Below is the current code, and below that is the code to fix the crashing.

    public void apoth_attrModifiedEvent(AttributeInstance inst, CallbackInfo ci) {
        if (!owner.level().isClientSide) {
            // This call site is only valid on the server, because the client nukes and reapplies all attribute modifiers when received.
            double oldValue = ((AttributeInstanceAccessor) inst).getCachedValue();
            double newValue = inst.getValue(); // Calling getValue will compute the value once marked dirty.
            if (oldValue != newValue) {
                MinecraftForge.EVENT_BUS.post(new AttributeChangedValueEvent(getOwner(), inst, oldValue, newValue));
            }
        }
    }

And this in the fix


    public void apoth_attrModifiedEvent(AttributeInstance inst, CallbackInfo ci) {
	if(owner != null){  // This line is added
		if (!owner.level().isClientSide) {
			// This call site is only valid on the server, because the client nukes and reapplies all attribute modifiers when received.
			double oldValue = ((AttributeInstanceAccessor) inst).getCachedValue();
			double newValue = inst.getValue(); // Calling getValue will compute the value once marked dirty.
			if (oldValue != newValue) {
				MinecraftForge.EVENT_BUS.post(new AttributeChangedValueEvent(getOwner(), inst, oldValue, newValue));
			}
		}
	} // This line is added
    }