Broken stuff

This commit is contained in:
pahimar 2015-04-20 21:16:48 -04:00
parent cf6a1bf77a
commit 301e8b75c7
13 changed files with 1706 additions and 1615 deletions

View file

@ -124,11 +124,9 @@ public class EquivalentExchange3
{
WorldEventHandler.hasInitilialized = false;
EnergyValueRegistry.getInstance().saveEnergyValueRegistryToFile();
EnergyValueRegistry.getInstance().save();
TransmutationKnowledgeRegistry.getInstance().saveAll();
AbilityRegistry.getInstance().saveAbilityRegistryToFile();
AbilityRegistry.getInstance().save();
}
public EnergyValueRegistry getEnergyValueRegistry()

View file

@ -458,7 +458,7 @@ public class EnergyValueRegistry implements INBTTaggable, JsonSerializer<EnergyV
// Serialize values to disk
LogHelper.info("Saving energy values to disk");
saveEnergyValueRegistryToFile();
save();
}
private void generateValueStackMappings()
@ -707,7 +707,7 @@ public class EnergyValueRegistry implements INBTTaggable, JsonSerializer<EnergyV
return valueMappings;
}
public void saveEnergyValueRegistryToFile()
public void save()
{
File energyValuesDataDirectory = new File(FMLCommonHandler.instance().getMinecraftServerInstance().getEntityWorld().getSaveHandler().getWorldDirectory(), "data" + File.separator + Reference.LOWERCASE_MOD_ID + File.separator + "energyvalues");
energyValuesDataDirectory.mkdirs();
@ -715,24 +715,39 @@ public class EnergyValueRegistry implements INBTTaggable, JsonSerializer<EnergyV
if (shouldRegenNextRestart)
{
File staticEnergyValuesFile = new File(energyValuesDataDirectory, Files.STATIC_ENERGY_VALUES);
File staticEnergyValuesJsonFile = new File(energyValuesDataDirectory, Files.STATIC_ENERGY_VALUES_JSON);
File md5EnergyValuesFile = new File(energyValuesDataDirectory, SerializationHelper.getModListMD5() + ".dat");
File md5EnergyValuesJsonFile = new File(energyValuesDataDirectory, SerializationHelper.getModListMD5() + ".json");
// NBT
if (staticEnergyValuesFile.exists())
{
staticEnergyValuesFile.delete();
}
if (md5EnergyValuesFile.exists())
{
md5EnergyValuesFile.delete();
}
// JSON
if (staticEnergyValuesJsonFile.exists())
{
staticEnergyValuesJsonFile.delete();
}
if (md5EnergyValuesJsonFile.exists())
{
md5EnergyValuesJsonFile.delete();
}
shouldRegenNextRestart = false;
}
else
{
SerializationHelper.writeNBTToFile(energyValuesDataDirectory, Files.STATIC_ENERGY_VALUES, this);
SerializationHelper.writeNBTToFile(energyValuesDataDirectory, SerializationHelper.getModListMD5() + ".dat", this);
SerializationHelper.writeEnergyValueStackMapToJsonFile(new File(energyValuesDataDirectory, Files.STATIC_ENERGY_VALUES_JSON), energyValueRegistry.stackMappings);
SerializationHelper.writeEnergyValueStackMapToJsonFile(new File(energyValuesDataDirectory, SerializationHelper.getModListMD5() + ".json"), energyValueRegistry.stackMappings);
}
}
@ -744,6 +759,9 @@ public class EnergyValueRegistry implements INBTTaggable, JsonSerializer<EnergyV
File staticEnergyValuesFile = new File(energyValuesDataDirectory, Files.STATIC_ENERGY_VALUES);
File md5EnergyValuesFile = new File(energyValuesDataDirectory, SerializationHelper.getModListMD5() + ".dat");
File staticEnergyValuesJsonFile = new File(energyValuesDataDirectory, Files.STATIC_ENERGY_VALUES_JSON);
File md5EnergyValuesJsonFile = new File(energyValuesDataDirectory, SerializationHelper.getModListMD5() + ".json");
NBTTagCompound nbtTagCompound = null;
// TODO Re-enable this once the NPE related to mod changes in the serialized value file bug is resolved

View file

@ -272,27 +272,27 @@ public class WrappedStack implements Comparable<WrappedStack>, JsonDeserializer<
{
NBTTagCompound wrappedItemTagCompound = new NBTTagCompound();
((ItemStack) wrappedStack.getWrappedObject()).writeToNBT(wrappedItemTagCompound);
wrappedStackTagCompound.setInteger("wrappedStack_type", 0);
wrappedStackTagCompound.setTag("wrappedStack_data", wrappedItemTagCompound);
wrappedStackTagCompound.setInteger("wrappedStack_stackSize", wrappedStack.getStackSize());
wrappedStackTagCompound.setInteger("type", 0);
wrappedStackTagCompound.setTag("objectData", wrappedItemTagCompound);
wrappedStackTagCompound.setInteger("stackSize", wrappedStack.getStackSize());
return wrappedStackTagCompound;
}
else if (wrappedStack.getWrappedObject() instanceof OreStack)
{
NBTTagCompound wrappedOreTagCompound = new NBTTagCompound();
((OreStack) wrappedStack.getWrappedObject()).writeToNBT(wrappedOreTagCompound);
wrappedStackTagCompound.setInteger("wrappedStack_type", 1);
wrappedStackTagCompound.setTag("wrappedStack_data", wrappedOreTagCompound);
wrappedStackTagCompound.setInteger("wrappedStack_stackSize", wrappedStack.getStackSize());
wrappedStackTagCompound.setInteger("type", 1);
wrappedStackTagCompound.setTag("objectData", wrappedOreTagCompound);
wrappedStackTagCompound.setInteger("stackSize", wrappedStack.getStackSize());
return wrappedStackTagCompound;
}
else if (wrappedStack.getWrappedObject() instanceof FluidStack)
{
NBTTagCompound wrappedFluidTagCompound = new NBTTagCompound();
((FluidStack) wrappedStack.getWrappedObject()).writeToNBT(wrappedFluidTagCompound);
wrappedStackTagCompound.setInteger("wrappedStack_type", 2);
wrappedStackTagCompound.setTag("wrappedStack_data", wrappedFluidTagCompound);
wrappedStackTagCompound.setInteger("wrappedStack_stackSize", wrappedStack.getStackSize());
wrappedStackTagCompound.setInteger("type", 2);
wrappedStackTagCompound.setTag("objectData", wrappedFluidTagCompound);
wrappedStackTagCompound.setInteger("stackSize", wrappedStack.getStackSize());
return wrappedStackTagCompound;
}
}
@ -302,24 +302,24 @@ public class WrappedStack implements Comparable<WrappedStack>, JsonDeserializer<
public static WrappedStack fromNBTTagCompound(NBTTagCompound nbtTagCompound)
{
if (nbtTagCompound.hasKey("wrappedStack_type") && nbtTagCompound.hasKey("wrappedStack_data") && nbtTagCompound.hasKey("wrappedStack_stackSize"))
if (nbtTagCompound.hasKey("type") && nbtTagCompound.hasKey("objectData") && nbtTagCompound.hasKey("stackSize"))
{
int objectType = nbtTagCompound.getInteger("wrappedStack_type");
int stackSize = nbtTagCompound.getInteger("wrappedStack_stackSize");
int objectType = nbtTagCompound.getInteger("type");
int stackSize = nbtTagCompound.getInteger("stackSize");
if (objectType == 0)
{
ItemStack itemStack = ItemStack.loadItemStackFromNBT(nbtTagCompound.getCompoundTag("wrappedStack_data"));
ItemStack itemStack = ItemStack.loadItemStackFromNBT(nbtTagCompound.getCompoundTag("objectData"));
return new WrappedStack(itemStack, stackSize);
}
else if (objectType == 1)
{
OreStack oreStack = OreStack.loadOreStackFromNBT(nbtTagCompound.getCompoundTag("wrappedStack_data"));
OreStack oreStack = OreStack.loadOreStackFromNBT(nbtTagCompound.getCompoundTag("objectData"));
return new WrappedStack(oreStack, stackSize);
}
else if (objectType == 2)
{
FluidStack fluidStack = FluidStack.loadFluidStackFromNBT(nbtTagCompound.getCompoundTag("wrappedStack_data"));
FluidStack fluidStack = FluidStack.loadFluidStackFromNBT(nbtTagCompound.getCompoundTag("objectData"));
return new WrappedStack(fluidStack, stackSize);
}
else
@ -401,23 +401,23 @@ public class WrappedStack implements Comparable<WrappedStack>, JsonDeserializer<
String objectType = null;
Object stackObject = null;
if (jsonWrappedStack.get("wrappedStack_type") != null)
if (jsonWrappedStack.get("type") != null)
{
objectType = jsonWrappedStack.get("wrappedStack_type").getAsString();
objectType = jsonWrappedStack.get("type").getAsString();
}
if (jsonWrappedStack.get("wrappedStack_stackSize") != null)
if (jsonWrappedStack.get("stackSize") != null)
{
stackSize = jsonWrappedStack.get("wrappedStack_stackSize").getAsInt();
stackSize = jsonWrappedStack.get("stackSize").getAsInt();
}
if (jsonWrappedStack.get("wrappedStack_data") != null && !jsonWrappedStack.get("wrappedStack_data").isJsonPrimitive())
if (jsonWrappedStack.get("objectData") != null && !jsonWrappedStack.get("objectData").isJsonPrimitive())
{
if (objectType != null)
{
if (objectType.equalsIgnoreCase("ItemStack"))
{
JsonItemStack jsonItemStack = JsonItemStack.jsonSerializer.fromJson(jsonWrappedStack.get("wrappedStack_data"), JsonItemStack.class);
JsonItemStack jsonItemStack = JsonItemStack.jsonSerializer.fromJson(jsonWrappedStack.get("objectData"), JsonItemStack.class);
ItemStack itemStack = null;
Item item = (Item) Item.itemRegistry.getObject(jsonItemStack.itemName);
if (stackSize > 0 && item != null)
@ -432,7 +432,7 @@ public class WrappedStack implements Comparable<WrappedStack>, JsonDeserializer<
}
else if (objectType.equalsIgnoreCase("OreStack"))
{
OreStack oreStack = jsonSerializer.fromJson(jsonWrappedStack.get("wrappedStack_data"), OreStack.class);
OreStack oreStack = jsonSerializer.fromJson(jsonWrappedStack.get("objectData"), OreStack.class);
if (stackSize > 0)
{
@ -442,7 +442,7 @@ public class WrappedStack implements Comparable<WrappedStack>, JsonDeserializer<
}
else if (objectType.equalsIgnoreCase("FluidStack"))
{
FluidStack fluidStack = jsonSerializer.fromJson(jsonWrappedStack.get("wrappedStack_data"), FluidStack.class);
FluidStack fluidStack = jsonSerializer.fromJson(jsonWrappedStack.get("objectData"), FluidStack.class);
if (stackSize > 0)
{
@ -490,8 +490,8 @@ public class WrappedStack implements Comparable<WrappedStack>, JsonDeserializer<
Gson gson = new Gson();
jsonWrappedStack.addProperty("wrappedStack_type", wrappedStack.objectType);
jsonWrappedStack.addProperty("wrappedStack_stackSize", wrappedStack.stackSize);
jsonWrappedStack.addProperty("type", wrappedStack.objectType);
jsonWrappedStack.addProperty("stackSize", wrappedStack.stackSize);
if (wrappedStack.wrappedStack instanceof ItemStack)
{
@ -502,15 +502,15 @@ public class WrappedStack implements Comparable<WrappedStack>, JsonDeserializer<
{
jsonItemStack.itemNBTTagCompound = ((ItemStack) wrappedStack.wrappedStack).stackTagCompound;
}
jsonWrappedStack.add("wrappedStack_data", JsonItemStack.jsonSerializer.toJsonTree(jsonItemStack, JsonItemStack.class));
jsonWrappedStack.add("objectData", JsonItemStack.jsonSerializer.toJsonTree(jsonItemStack, JsonItemStack.class));
}
else if (wrappedStack.wrappedStack instanceof OreStack)
{
jsonWrappedStack.add("wrappedStack_data", gson.toJsonTree(wrappedStack.wrappedStack, OreStack.class));
jsonWrappedStack.add("objectData", gson.toJsonTree(wrappedStack.wrappedStack, OreStack.class));
}
else if (wrappedStack.wrappedStack instanceof FluidStack)
{
jsonWrappedStack.add("wrappedStack_data", gson.toJsonTree(wrappedStack.wrappedStack, FluidStack.class));
jsonWrappedStack.add("objectData", gson.toJsonTree(wrappedStack.wrappedStack, FluidStack.class));
}
return jsonWrappedStack;

View file

@ -14,7 +14,7 @@ public class AbilityRegistrySerializationHandler
{
if (FMLCommonHandler.instance().getMinecraftServerInstance().getEntityWorld().getWorldTime() % 600 == 0)
{
AbilityRegistry.getInstance().saveAbilityRegistryToFile();
AbilityRegistry.getInstance().save();
}
}
}

View file

@ -241,6 +241,13 @@ public class ContainerTransmutationTablet extends ContainerEE implements IElemen
return null;
}
}
else if (slotIndex >= TileEntityTransmutationTablet.INVENTORY_SIZE && slotIndex < 40)
{
// if (!this.mergeItemStackFromTransmutationOutput(slotItemStack, TileEntityTransmutationTablet.INVENTORY_SIZE, inventorySlots.size(), false))
// {
return null;
// }
}
else
{
if (slotItemStack.getItem() instanceof ItemAlchemicalTome)
@ -279,6 +286,21 @@ public class ContainerTransmutationTablet extends ContainerEE implements IElemen
return itemStack;
}
@Override
public ItemStack slotClick(int slotIndex, int mouseButton, int shiftPressed, EntityPlayer entityPlayer)
{
if (slotIndex < TileEntityTransmutationTablet.INVENTORY_SIZE)
{
return super.slotClick(slotIndex, mouseButton, shiftPressed, entityPlayer);
}
else
{
return super.slotClick(slotIndex, mouseButton, shiftPressed, entityPlayer);
}
// return null;
}
@Override
public void handleElementButtonClick(String elementName, int mouseButton)
{
@ -395,13 +417,14 @@ public class ContainerTransmutationTablet extends ContainerEE implements IElemen
@Override
public boolean canTakeStack(EntityPlayer entityPlayer)
{
return false;
return true;
}
@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()));
}

View file

@ -241,7 +241,7 @@ public class AbilityRegistry implements JsonSerializer<AbilityRegistry>, JsonDes
return jsonAbilityRegistry;
}
public void saveAbilityRegistryToFile()
public void save()
{
if (abilityDirectory != null)
{

View file

@ -6,7 +6,7 @@ import java.util.Comparator;
public class Comparators
{
public static final Comparator[] itemComparators = {ItemHelper.displayNameComparator, ItemHelper.energyValueComparator, ItemHelper.idComparator};
public static final Comparator[] itemComparators = {ItemHelper.displayNameComparator, ItemHelper.energyValueItemStackComparator, ItemHelper.idComparator};
public static Comparator<String> stringComparator = new Comparator<String>()
{

View file

@ -7,4 +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";
}

View file

@ -1,10 +1,14 @@
package com.pahimar.ee3.test;
import com.pahimar.ee3.reference.Reference;
import cpw.mods.fml.common.FMLCommonHandler;
import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
import net.minecraft.item.ItemStack;
import net.minecraftforge.oredict.OreDictionary;
import java.io.File;
public class VanillaEnergyValueTest extends EnergyValueMappingsTestSuite
{
public VanillaEnergyValueTest()
@ -595,4 +599,11 @@ public class VanillaEnergyValueTest extends EnergyValueMappingsTestSuite
add(Items.netherbrick, 1);
add(Items.quartz, 256);
}
public void save()
{
File energyValuesDataDirectory = new File(FMLCommonHandler.instance().getMinecraftServerInstance().getEntityWorld().getSaveHandler().getWorldDirectory(), "data" + File.separator + Reference.LOWERCASE_MOD_ID + File.separator + "energyvalues" + File.separator + "testcases");
energyValuesDataDirectory.mkdirs();
this.saveTestSuite(new File(energyValuesDataDirectory, "minecraft-v1710-vanilla-test-suite.json"));
}
}

View file

@ -1,6 +1,7 @@
package com.pahimar.ee3.tileentity;
import com.pahimar.ee3.api.EnergyValue;
import com.pahimar.ee3.api.EnergyValueRegistryProxy;
import com.pahimar.ee3.block.BlockAshInfusedStoneSlab;
import com.pahimar.ee3.exchange.EnergyValueRegistry;
import com.pahimar.ee3.item.ItemAlchemicalTome;
@ -59,14 +60,53 @@ public class TileEntityTransmutationTablet extends TileEntityEE implements ISide
return storedEnergyValue;
}
public void consumeInventoryForEnergyValue(ItemStack outputItemStack)
{
EnergyValue outputEnergyValue = EnergyValueRegistryProxy.getEnergyValue(outputItemStack);
/**
* Algorithm:
*
* 1) Check the Stone slot, and attempt to take EMC out of the stone there (til 0)
* 2) Search the inventory for items that will most make up the difference, decrement them and consume their EMC
* 3) Repeat 2 until Stored EMC > outputItemStack EMC
* 4) Profit
*/
if (this.storedEnergyValue.compareTo(outputEnergyValue) >= 0)
{
this.storedEnergyValue = new EnergyValue(this.storedEnergyValue.getValue() - outputEnergyValue.getValue());
}
else
{
while (this.storedEnergyValue.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
}
}
if (this.storedEnergyValue.getValue() >= outputEnergyValue.getValue())
{
this.storedEnergyValue = new EnergyValue(this.storedEnergyValue.getValue() - outputEnergyValue.getValue());
}
}
updateEnergyValueFromInventory();
}
public void updateEnergyValueFromInventory()
{
float newEnergyValue = storedEnergyValue.getValue();
for (int i = 0; i <= STONE_INDEX; i++)
{
if (inventory[i] != null && EnergyValueRegistry.getInstance().hasEnergyValue(inventory[i]))
if (inventory[i] != null && EnergyValueRegistryProxy.hasEnergyValue(inventory[i]))
{
newEnergyValue += EnergyValueRegistry.getInstance().getEnergyValueForStack(inventory[i]).getValue();
newEnergyValue += EnergyValueRegistryProxy.getEnergyValueForStack(inventory[i]).getValue();
}
}
this.availableEnergyValue = new EnergyValue(newEnergyValue);

View file

@ -120,7 +120,7 @@ public class ItemHelper
}
};
public static Comparator<ItemStack> energyValueComparator = new Comparator<ItemStack>()
public static Comparator<ItemStack> energyValueItemStackComparator = new Comparator<ItemStack>()
{
@Override
public int compare(ItemStack itemStack1, ItemStack itemStack2)

View file

@ -243,7 +243,7 @@ public class SerializationHelper
jsonWriter.beginArray();
for (WrappedStack wrappedStack : energyValueMap.keySet())
{
if (wrappedStack.getWrappedObject() != null)
if (wrappedStack != null && wrappedStack.getWrappedObject() != null)
{
EnergyValueStackMapping.jsonSerializer.toJson(new EnergyValueStackMapping(wrappedStack, energyValueMap.get(wrappedStack)), EnergyValueStackMapping.class, jsonWriter);
}

File diff suppressed because it is too large Load diff