mirror of
https://github.com/Thorfusion/Mekanism-Community-Edition.git
synced 2026-11-26 23:03:01 +00:00
try to avoid creating an nbt tag where its only going to be read
This commit is contained in:
1 parent
4f7db32e6f
commit
da0497b8f1
4 files changed
+24
-4
No files matched your search
@@ -15,6 +15,8 @@ import net.minecraft.nbt.NBTTagList;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraftforge.common.util.Constants.NBT;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
public enum Upgrade
|
||||
{
|
||||
SPEED("speed", 8, EnumColor.RED),
|
||||
@@ -127,7 +129,7 @@ public enum Upgrade
|
||||
return ret;
|
||||
}
|
||||
|
||||
public static Map<Upgrade, Integer> buildMap(NBTTagCompound nbtTags)
|
||||
public static Map<Upgrade, Integer> buildMap(@Nullable NBTTagCompound nbtTags)
|
||||
{
|
||||
Map<Upgrade, Integer> upgrades = new HashMap<>();
|
||||
|
||||
|
||||
@@ -289,7 +289,7 @@ public class TileEntityFactory extends TileEntityMachine implements IComputerInt
|
||||
|
||||
upgradeComponent.write(ItemDataUtils.getDataMap(returnStack));
|
||||
upgradeComponent.setSupported(Upgrade.GAS, toSet.fuelEnergyUpgrades());
|
||||
upgradeComponent.read(ItemDataUtils.getDataMap(inventory.get(2)));
|
||||
upgradeComponent.read(ItemDataUtils.getDataMapIfPresentNN(inventory.get(2)));
|
||||
|
||||
inventory.set(2, ItemStack.EMPTY);
|
||||
inventory.set(3, returnStack);
|
||||
|
||||
@@ -5,16 +5,32 @@ import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
import net.minecraftforge.common.util.Constants.NBT;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
public final class ItemDataUtils
|
||||
{
|
||||
public static final String DATA_ID = "mekData";
|
||||
|
||||
@Nonnull
|
||||
public static NBTTagCompound getDataMap(ItemStack stack)
|
||||
{
|
||||
initStack(stack);
|
||||
|
||||
return stack.getTagCompound().getCompoundTag(DATA_ID);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static NBTTagCompound getDataMapIfPresent(ItemStack stack)
|
||||
{
|
||||
return hasDataTag(stack) ? getDataMap(stack) : null;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
public static NBTTagCompound getDataMapIfPresentNN(ItemStack stack)
|
||||
{
|
||||
return hasDataTag(stack) ? getDataMap(stack) : new NBTTagCompound();
|
||||
}
|
||||
|
||||
public static boolean hasData(ItemStack stack, String key)
|
||||
{
|
||||
|
||||
@@ -92,7 +92,9 @@ public class RecipeUtils
|
||||
}
|
||||
}
|
||||
|
||||
((IEnergizedItem)toReturn.getItem()).setEnergy(toReturn, Math.min(((IEnergizedItem)toReturn.getItem()).getMaxEnergy(toReturn), energyFound));
|
||||
double energyToSet = Math.min(((IEnergizedItem) toReturn.getItem()).getMaxEnergy(toReturn), energyFound);
|
||||
if (energyToSet > 0)
|
||||
((IEnergizedItem)toReturn.getItem()).setEnergy(toReturn, energyToSet);
|
||||
}
|
||||
|
||||
if(toReturn.getItem() instanceof IGasItem)
|
||||
@@ -230,7 +232,7 @@ public class RecipeUtils
|
||||
|
||||
if(!itemstack.isEmpty() && BlockStateMachine.MachineType.get(itemstack) != null && BlockStateMachine.MachineType.get(itemstack).supportsUpgrades)
|
||||
{
|
||||
Map<Upgrade, Integer> stackMap = Upgrade.buildMap(ItemDataUtils.getDataMap(itemstack));
|
||||
Map<Upgrade, Integer> stackMap = Upgrade.buildMap(ItemDataUtils.getDataMapIfPresent(itemstack));
|
||||
|
||||
for(Map.Entry<Upgrade, Integer> entry : stackMap.entrySet())
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user