mirror of
https://github.com/Ellpeck/ActuallyAdditions.git
synced 2024-11-22 23:28:35 +01:00
Fix the coffee effect storing
This commit is contained in:
parent
ba64232ac1
commit
56402e46eb
1 changed files with 17 additions and 6 deletions
|
@ -14,6 +14,7 @@ import de.ellpeck.actuallyadditions.api.internal.IAtomicReconstructor;
|
||||||
import de.ellpeck.actuallyadditions.api.internal.IMethodHandler;
|
import de.ellpeck.actuallyadditions.api.internal.IMethodHandler;
|
||||||
import de.ellpeck.actuallyadditions.api.lens.Lens;
|
import de.ellpeck.actuallyadditions.api.lens.Lens;
|
||||||
import de.ellpeck.actuallyadditions.api.recipe.CoffeeIngredient;
|
import de.ellpeck.actuallyadditions.api.recipe.CoffeeIngredient;
|
||||||
|
import de.ellpeck.actuallyadditions.mod.ActuallyAdditions;
|
||||||
import de.ellpeck.actuallyadditions.mod.blocks.BlockLaserRelay;
|
import de.ellpeck.actuallyadditions.mod.blocks.BlockLaserRelay;
|
||||||
import de.ellpeck.actuallyadditions.mod.crafting.CoffeeIngredientRecipe;
|
import de.ellpeck.actuallyadditions.mod.crafting.CoffeeIngredientRecipe;
|
||||||
import de.ellpeck.actuallyadditions.mod.crafting.LaserRecipe;
|
import de.ellpeck.actuallyadditions.mod.crafting.LaserRecipe;
|
||||||
|
@ -24,7 +25,10 @@ import net.minecraft.core.Direction;
|
||||||
import net.minecraft.core.Vec3i;
|
import net.minecraft.core.Vec3i;
|
||||||
import net.minecraft.core.registries.BuiltInRegistries;
|
import net.minecraft.core.registries.BuiltInRegistries;
|
||||||
import net.minecraft.nbt.CompoundTag;
|
import net.minecraft.nbt.CompoundTag;
|
||||||
|
import net.minecraft.resources.ResourceLocation;
|
||||||
|
import net.minecraft.world.effect.MobEffect;
|
||||||
import net.minecraft.world.effect.MobEffectInstance;
|
import net.minecraft.world.effect.MobEffectInstance;
|
||||||
|
import net.minecraft.world.effect.MobEffects;
|
||||||
import net.minecraft.world.entity.item.ItemEntity;
|
import net.minecraft.world.entity.item.ItemEntity;
|
||||||
import net.minecraft.world.item.BlockItem;
|
import net.minecraft.world.item.BlockItem;
|
||||||
import net.minecraft.world.item.ItemStack;
|
import net.minecraft.world.item.ItemStack;
|
||||||
|
@ -123,7 +127,7 @@ public class MethodHandler implements IMethodHandler {
|
||||||
|
|
||||||
int prevCounter = tag.getInt("Counter");
|
int prevCounter = tag.getInt("Counter");
|
||||||
CompoundTag compound = new CompoundTag();
|
CompoundTag compound = new CompoundTag();
|
||||||
//compound.putInt("ID", Potion.getIdFromPotion(effect.getEffect())); //TODO ?!
|
compound.putString("ID", BuiltInRegistries.MOB_EFFECT.getKey(effect.getEffect()).toString());
|
||||||
compound.putInt("Duration", effect.getDuration());
|
compound.putInt("Duration", effect.getDuration());
|
||||||
compound.putInt("Amplifier", effect.getAmplifier());
|
compound.putInt("Amplifier", effect.getAmplifier());
|
||||||
|
|
||||||
|
@ -140,13 +144,20 @@ public class MethodHandler implements IMethodHandler {
|
||||||
CompoundTag tag = stack.getOrCreateTag();
|
CompoundTag tag = stack.getOrCreateTag();
|
||||||
int counter = tag.getInt("Counter");
|
int counter = tag.getInt("Counter");
|
||||||
while (counter > 0) {
|
while (counter > 0) {
|
||||||
CompoundTag compound = (CompoundTag) tag.get(counter + "");
|
CompoundTag compound = tag.getCompound(counter + "");
|
||||||
MobEffectInstance effect = new MobEffectInstance(BuiltInRegistries.MOB_EFFECT.byId(compound.getInt("ID")), compound.getInt("Duration"), compound.getByte("Amplifier"));
|
String id = compound.getString("ID");
|
||||||
effects.add(effect);
|
ResourceLocation effectID = id.isEmpty() ? new ResourceLocation("speed") : ResourceLocation.tryParse(id);
|
||||||
|
MobEffect effect = BuiltInRegistries.MOB_EFFECT.get(effectID);
|
||||||
|
if (effect == null) {
|
||||||
|
ActuallyAdditions.LOGGER.error("Unable to find effect with ID: {}, defaulting to speed", effectID);
|
||||||
|
effect = MobEffects.MOVEMENT_SPEED;
|
||||||
|
}
|
||||||
|
MobEffectInstance effectInstance = new MobEffectInstance(effect, compound.getInt("Duration"), compound.getByte("Amplifier"));
|
||||||
|
effects.add(effectInstance);
|
||||||
counter--;
|
counter--;
|
||||||
}
|
}
|
||||||
return effects.size() > 0
|
return !effects.isEmpty()
|
||||||
? effects.toArray(new MobEffectInstance[effects.size()])
|
? effects.toArray(new MobEffectInstance[0])
|
||||||
: null;
|
: null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue