Class MobEffectDataStorage
java.lang.Object
etithespirit.orimod.util.extension.MobEffectDataStorage
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 -
Method Summary
Modifier and TypeMethodDescriptionstatic net.minecraft.nbt.CompoundTag
accessData
(net.minecraft.world.effect.MobEffectInstance instance) Gets aCompoundTag
storing data for the givenMobEffectInstance
.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.
-
Field Details
-
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 aCompoundTag
storing data for the givenMobEffectInstance
. 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
- TheMobEffectInstance
that the data pertains to.- Returns:
- A
CompoundTag
with the data for the givenMobEffectInstance
-
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.
-