Class MobEffectDataStorage

java.lang.Object
etithespirit.orimod.util.extension.MobEffectDataStorage

public final class MobEffectDataStorage extends Object
A very hacky method of reading and writing data in a single effect instance without creating a custom instance type. This oddball method that is alarmingly compatible with vanilla code was given to me by diesieben07, so kudos to him!
Author:
Eti
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final String
    The name of the NBT tag that stores data.
  • Method Summary

    Modifier and Type
    Method
    Description
    static net.minecraft.nbt.CompoundTag
    accessData(net.minecraft.world.effect.MobEffectInstance instance)
    Gets a CompoundTag storing data for the given MobEffectInstance.
    static void
    addMaxDuration(net.minecraft.world.effect.MobEffectInstance instance, int offset)
    An alias method that adds a custom max duration value, or, the duration this effect started with.
    static int
    getMaxDuration(net.minecraft.world.effect.MobEffectInstance instance)
    An alias method that returns a custom max duration value, or, the duration this effect started with.
    static void
    setMaxDuration(net.minecraft.world.effect.MobEffectInstance instance, int maxDuration)
    An alias method that sets a custom max duration value, or, the duration this effect started with.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • DATA_STORAGE_TAG_NAME

      public static final String DATA_STORAGE_TAG_NAME
      The name of the NBT tag that stores data.
      See Also:
  • Method Details

    • accessData

      public static net.minecraft.nbt.CompoundTag accessData(net.minecraft.world.effect.MobEffectInstance instance)
      Gets a CompoundTag storing data for the given MobEffectInstance. This also creates new data if the instance doesn't have it.
      Behaviorally, this adds air as a curative item (though this does nothing). Modifying the curative items array MUST retain this dummy air item, or else the data will be wiped or malformed.
      Parameters:
      instance - The MobEffectInstance that the data pertains to.
      Returns:
      A CompoundTag with the data for the given MobEffectInstance
    • getMaxDuration

      public static int getMaxDuration(net.minecraft.world.effect.MobEffectInstance instance)
      An alias method that returns a custom max duration value, or, the duration this effect started with.
      Parameters:
      instance - The effect to look at.
      Returns:
      A value representing the maximum duration, or 0 if it was never registered.
    • setMaxDuration

      public static void setMaxDuration(net.minecraft.world.effect.MobEffectInstance instance, int maxDuration)
      An alias method that sets a custom max duration value, or, the duration this effect started with.
      Parameters:
      instance - The effect to modify.
      maxDuration - The maximum duration of this effect instance itself (how much time it had when instantiated)
    • addMaxDuration

      public static void addMaxDuration(net.minecraft.world.effect.MobEffectInstance instance, int offset)
      An alias method that adds a custom max duration value, or, the duration this effect started with. Does nothing if this does not have the data registered.
      Parameters:
      instance - The effect to modify.
      offset - An increase to the maximum duration of this effect instance itself (how much time it had when instantiated). If the effect's duration has been expanded, then this should go up.