Fix server crash when handling dye recipes (#1250)

This commit is contained in:
Nicholas Ignoffo 2018-03-13 23:10:13 -07:00
parent 46389368ec
commit 924dc7b38d
3 changed files with 24 additions and 6 deletions

View file

@ -1,6 +1,7 @@
package WayofTime.bloodmagic.recipe.alchemyTable;
import WayofTime.bloodmagic.util.Constants;
import WayofTime.bloodmagic.util.Utils;
import net.minecraft.init.Items;
import net.minecraft.item.EnumDyeColor;
import net.minecraft.item.ItemBanner;
@ -76,7 +77,7 @@ public class AlchemyTableDyeableRecipe extends AlchemyTableRecipe {
outputStack.setTagCompound(new NBTTagCompound());
}
outputStack.getTagCompound().setString(Constants.NBT.COLOR, String.valueOf(dyeColor.getColorValue()));
outputStack.getTagCompound().setString(Constants.NBT.COLOR, String.valueOf(Utils.DYE_COLOR_VALUES.getOrDefault(dyeColor, 0)));
return outputStack;
}

View file

@ -8,6 +8,7 @@ import WayofTime.bloodmagic.network.BloodMagicPacketHandler;
import WayofTime.bloodmagic.network.PlayerVelocityPacketProcessor;
import WayofTime.bloodmagic.tile.TileInventory;
import com.google.common.collect.Iterables;
import com.google.common.collect.Maps;
import net.minecraft.block.Block;
import net.minecraft.block.BlockLiquid;
import net.minecraft.block.BlockPortal;
@ -23,6 +24,7 @@ import net.minecraft.init.MobEffects;
import net.minecraft.init.SoundEvents;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.ISidedInventory;
import net.minecraft.item.EnumDyeColor;
import net.minecraft.item.Item;
import net.minecraft.item.ItemArmor;
import net.minecraft.item.ItemStack;
@ -39,6 +41,7 @@ import net.minecraftforge.common.IPlantable;
import net.minecraftforge.common.ISpecialArmor;
import net.minecraftforge.common.ISpecialArmor.ArmorProperties;
import net.minecraftforge.fluids.IFluidBlock;
import net.minecraftforge.fml.relauncher.ReflectionHelper;
import net.minecraftforge.items.CapabilityItemHandler;
import net.minecraftforge.items.IItemHandler;
import net.minecraftforge.items.ItemHandlerHelper;
@ -47,12 +50,25 @@ import net.minecraftforge.items.wrapper.PlayerMainInvWrapper;
import net.minecraftforge.items.wrapper.SidedInvWrapper;
import javax.annotation.Nullable;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import java.util.UUID;
import java.lang.reflect.Field;
import java.util.*;
public class Utils {
public static final EnumMap<EnumDyeColor, Integer> DYE_COLOR_VALUES = Maps.newEnumMap(EnumDyeColor.class);
static {
try {
Field colorValue = ReflectionHelper.findField(EnumDyeColor.class, "field_193351_w", "colorValue");
colorValue.setAccessible(true);
for (EnumDyeColor color : EnumDyeColor.values()) {
DYE_COLOR_VALUES.put(color, (int) colorValue.get(color));
}
} catch (IllegalAccessException e) {
BMLog.DEFAULT.error("Error grabbing color values: {}", e.getMessage());
}
}
public static float addAbsorptionToMaximum(EntityLivingBase entity, float added, int maximum, int duration) {
float currentAmount = entity.getAbsorptionAmount();
added = Math.min(maximum - currentAmount, added);

View file

@ -6,6 +6,7 @@ import WayofTime.bloodmagic.util.Constants;
import WayofTime.bloodmagic.event.AltarCraftedEvent;
import WayofTime.bloodmagic.iface.IUpgradeTrainer;
import WayofTime.bloodmagic.livingArmour.LivingArmourUpgrade;
import WayofTime.bloodmagic.util.Utils;
import WayofTime.bloodmagic.util.helper.ItemHelper;
import WayofTime.bloodmagic.util.helper.NBTHelper;
import WayofTime.bloodmagic.block.BlockLifeEssence;
@ -86,7 +87,7 @@ public class CraftingHandler {
ItemStack output = event.getLeft().copy();
if (!output.hasTagCompound())
output.setTagCompound(new NBTTagCompound());
output.getTagCompound().setString(Constants.NBT.COLOR, String.valueOf(dyeColor.getColorValue()));
output.getTagCompound().setString(Constants.NBT.COLOR, String.valueOf(Utils.DYE_COLOR_VALUES.getOrDefault(dyeColor, 0)));
event.setCost(1);
event.setOutput(output);