Stuffs on fire yo
This commit is contained in:
parent
55d679120b
commit
34cda981c0
|
@ -743,7 +743,8 @@ public class EnergyValueRegistry implements INBTTaggable, JsonSerializer<EnergyV
|
|||
}
|
||||
else
|
||||
{
|
||||
SerializationHelper.writeNBTToFile(energyValuesDataDirectory, Files.STATIC_ENERGY_VALUES, this);
|
||||
// SerializationHelper.writeNBTToFile(energyValuesDataDirectory, Files.STATIC_ENERGY_VALUES, this);
|
||||
SerializationHelper.compressEnergyValueRegistryToFile(new File(energyValuesDataDirectory, Files.STATIC_ENERGY_VALUES));
|
||||
SerializationHelper.writeNBTToFile(energyValuesDataDirectory, SerializationHelper.getModListMD5() + ".dat", this);
|
||||
|
||||
SerializationHelper.writeEnergyValueStackMapToJsonFile(new File(energyValuesDataDirectory, Files.STATIC_ENERGY_VALUES_JSON), energyValueRegistry.stackMappings);
|
||||
|
@ -753,6 +754,7 @@ public class EnergyValueRegistry implements INBTTaggable, JsonSerializer<EnergyV
|
|||
|
||||
public boolean loadEnergyValueRegistryFromFile()
|
||||
{
|
||||
// TODO Come back here
|
||||
File energyValuesDataDirectory = new File(FMLCommonHandler.instance().getMinecraftServerInstance().getEntityWorld().getSaveHandler().getWorldDirectory(), "data" + File.separator + Reference.LOWERCASE_MOD_ID + File.separator + "energyvalues");
|
||||
energyValuesDataDirectory.mkdirs();
|
||||
|
||||
|
|
|
@ -12,14 +12,12 @@ public class OreStack implements Comparable<OreStack>
|
|||
public int stackSize;
|
||||
public static Comparator<OreStack> comparator = new Comparator<OreStack>()
|
||||
{
|
||||
|
||||
@Override
|
||||
public int compare(OreStack oreStack1, OreStack oreStack2)
|
||||
{
|
||||
|
||||
if (oreStack1 != null)
|
||||
if (oreStack1 != null && oreStack1.oreName != null)
|
||||
{
|
||||
if (oreStack2 != null)
|
||||
if (oreStack2 != null && oreStack2.oreName != null)
|
||||
{
|
||||
if (oreStack1.oreName.equalsIgnoreCase(oreStack2.oreName))
|
||||
{
|
||||
|
|
|
@ -17,6 +17,7 @@ import com.pahimar.ee3.reference.Comparators;
|
|||
import com.pahimar.ee3.tileentity.TileEntityTransmutationTablet;
|
||||
import com.pahimar.ee3.util.FilterUtils;
|
||||
import com.pahimar.ee3.util.ItemHelper;
|
||||
import cpw.mods.fml.common.FMLCommonHandler;
|
||||
import cpw.mods.fml.common.network.NetworkRegistry;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
|
@ -107,6 +108,12 @@ public class ContainerTransmutationTablet extends ContainerEE implements IElemen
|
|||
this.updateInventory();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canInteractWith(EntityPlayer entityPlayer)
|
||||
{
|
||||
return this.tileEntityTransmutationTablet != null && this.tileEntityTransmutationTablet.isStructureValid();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void detectAndSendChanges()
|
||||
{
|
||||
|
@ -244,7 +251,7 @@ public class ContainerTransmutationTablet extends ContainerEE implements IElemen
|
|||
}
|
||||
else if (slotIndex >= TileEntityTransmutationTablet.INVENTORY_SIZE && slotIndex < 40)
|
||||
{
|
||||
if (!this.mergeTransmutationItemStack(slotItemStack, 40, inventorySlots.size(), false))
|
||||
if (!this.mergeTransmutatedItemStack(entityPlayer, slot, slotItemStack, 40, inventorySlots.size(), false))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
@ -287,13 +294,15 @@ public class ContainerTransmutationTablet extends ContainerEE implements IElemen
|
|||
return itemStack;
|
||||
}
|
||||
|
||||
protected boolean mergeTransmutationItemStack(ItemStack itemStack, int slotMin, int slotMax, boolean ascending)
|
||||
protected boolean mergeTransmutatedItemStack(EntityPlayer entityPlayer, Slot transmutationOutputSlot, ItemStack itemStack, int slotMin, int slotMax, boolean ascending)
|
||||
{
|
||||
if (this.tileEntityTransmutationTablet.getAvailableEnergyValue().compareTo(EnergyValueRegistryProxy.getEnergyValue(itemStack)) < 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
transmutationOutputSlot.onPickupFromSlot(entityPlayer, itemStack);
|
||||
|
||||
boolean slotFound = false;
|
||||
int currentSlotIndex = ascending ? slotMax - 1 : slotMin;
|
||||
|
||||
|
@ -314,7 +323,7 @@ public class ContainerTransmutationTablet extends ContainerEE implements IElemen
|
|||
|
||||
if (combinedStackSize <= slotStackSizeLimit)
|
||||
{
|
||||
itemStack.stackSize = 1;
|
||||
itemStack.stackSize = 0;
|
||||
stackInSlot.stackSize = combinedStackSize;
|
||||
slot.onSlotChanged();
|
||||
slotFound = true;
|
||||
|
@ -357,8 +366,8 @@ public class ContainerTransmutationTablet extends ContainerEE implements IElemen
|
|||
|
||||
currentSlotIndex += ascending ? -1 : 1;
|
||||
}
|
||||
itemStack.stackSize = 1;
|
||||
}
|
||||
itemStack.stackSize = 1;
|
||||
return slotFound;
|
||||
}
|
||||
|
||||
|
@ -478,15 +487,29 @@ public class ContainerTransmutationTablet extends ContainerEE implements IElemen
|
|||
@Override
|
||||
public boolean canTakeStack(EntityPlayer entityPlayer)
|
||||
{
|
||||
return true;
|
||||
return this.getHasStack();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPickupFromSlot(EntityPlayer entityPlayer, ItemStack itemStack)
|
||||
{
|
||||
super.onPickupFromSlot(entityPlayer, itemStack);
|
||||
// this.containerTransmutationTablet.tileEntityTransmutationTablet.consumeInventoryForEnergyValue(itemStack);
|
||||
// this.containerTransmutationTablet.inventoryTransmutationTablet.setInventorySlotContents(this.getSlotIndex(), new ItemStack(itemStack.getItem(), 1, itemStack.getItemDamage()));
|
||||
|
||||
if (this.getHasStack())
|
||||
{
|
||||
this.containerTransmutationTablet.tileEntityTransmutationTablet.consumeInventoryForEnergyValue(itemStack);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSlotChanged()
|
||||
{
|
||||
super.onSlotChanged();
|
||||
|
||||
if (FMLCommonHandler.instance().getEffectiveSide().isServer())
|
||||
{
|
||||
this.containerTransmutationTablet.tileEntityTransmutationTablet.updateEnergyValueFromInventory();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -7,5 +7,5 @@ public class Files
|
|||
public static final String TEMPLATE_JSON_FILE = "template.json";
|
||||
public static final String ABILITIES_JSON_FILE = "abilities.json";
|
||||
public static final String STATIC_ENERGY_VALUES = "energy-values.dat";
|
||||
public static final String STATIC_ENERGY_VALUES_JSON = "energy-values.json";
|
||||
public static final String STATIC_ENERGY_VALUES_JSON = "energy-values.json.gz";
|
||||
}
|
||||
|
|
|
@ -79,14 +79,16 @@ public class TileEntityTransmutationTablet extends TileEntityEE implements ISide
|
|||
}
|
||||
else
|
||||
{
|
||||
while (this.storedEnergyValue.compareTo(outputEnergyValue) < 0)
|
||||
while (this.storedEnergyValue.compareTo(outputEnergyValue) < 0 && this.availableEnergyValue.compareTo(outputEnergyValue) >= 0)
|
||||
{
|
||||
int candidateSlotIndex = Integer.MIN_VALUE;
|
||||
float candidateEnergyValue = Float.MIN_VALUE;
|
||||
|
||||
for (int i = 0; i < STONE_INDEX; i++)
|
||||
{
|
||||
// Sick as hell algorithm that solves everything and makes me look cool on a skateboard
|
||||
ItemStack stackInSlot = getStackInSlot(i);
|
||||
if (stackInSlot != null && EnergyValueRegistryProxy.hasEnergyValue(stackInSlot))
|
||||
{
|
||||
this.storedEnergyValue = new EnergyValue(this.storedEnergyValue.getValue() + EnergyValueRegistryProxy.getEnergyValue(stackInSlot).getValue());
|
||||
decrStackSize(i, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -3,6 +3,7 @@ package com.pahimar.ee3.util;
|
|||
import com.google.gson.stream.JsonReader;
|
||||
import com.google.gson.stream.JsonWriter;
|
||||
import com.pahimar.ee3.api.EnergyValue;
|
||||
import com.pahimar.ee3.exchange.EnergyValueRegistry;
|
||||
import com.pahimar.ee3.exchange.EnergyValueStackMapping;
|
||||
import com.pahimar.ee3.exchange.WrappedStack;
|
||||
import com.pahimar.ee3.knowledge.TransmutationKnowledge;
|
||||
|
@ -257,4 +258,33 @@ public class SerializationHelper
|
|||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public static void compressEnergyValueStackMapToFile(String fileName, Map<WrappedStack, EnergyValue> energyValueMap)
|
||||
{
|
||||
File energyValuesDataDirectory = new File(FMLCommonHandler.instance().getMinecraftServerInstance().getEntityWorld().getSaveHandler().getWorldDirectory(), "data" + File.separator + Reference.LOWERCASE_MOD_ID + File.separator + "energyvalues");
|
||||
compressEnergyValueStackMapToFile(new File(energyValuesDataDirectory, fileName), energyValueMap);
|
||||
}
|
||||
|
||||
public static void compressEnergyValueStackMapToFile(File file, Map<WrappedStack, EnergyValue> energyValueMap)
|
||||
{
|
||||
try
|
||||
{
|
||||
byte[] energyValueRegistryArray = CompressionHelper.compressStringToByteArray(EnergyValueRegistry.getInstance().toJson());
|
||||
FileOutputStream fos = new FileOutputStream(file);
|
||||
fos.write(energyValueRegistryArray);
|
||||
fos.close();
|
||||
}
|
||||
catch (UnsupportedEncodingException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
catch (FileNotFoundException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue