Getting close now
This commit is contained in:
parent
87e1f9fb1a
commit
74bb716395
|
@ -2,5 +2,5 @@
|
||||||
#Sat Dec 28 00:14:08 EST 2013
|
#Sat Dec 28 00:14:08 EST 2013
|
||||||
minecraft_version = 1.7.10
|
minecraft_version = 1.7.10
|
||||||
forge_version = 10.13.2.1291
|
forge_version = 10.13.2.1291
|
||||||
mod_version = 0.2
|
mod_version = 0.3
|
||||||
release_type = alpha
|
release_type = beta
|
||||||
|
|
|
@ -14,7 +14,7 @@ import net.minecraft.world.World;
|
||||||
public class AlchemyArray implements Comparable<AlchemyArray>
|
public class AlchemyArray implements Comparable<AlchemyArray>
|
||||||
{
|
{
|
||||||
private ResourceLocation texture;
|
private ResourceLocation texture;
|
||||||
private String unLocalizedName;
|
private String unlocalizedName;
|
||||||
private String className;
|
private String className;
|
||||||
private int lightLevel;
|
private int lightLevel;
|
||||||
private int chalkPerBlockCost;
|
private int chalkPerBlockCost;
|
||||||
|
@ -24,10 +24,10 @@ public class AlchemyArray implements Comparable<AlchemyArray>
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public AlchemyArray(ResourceLocation texture, String unLocalizedName)
|
public AlchemyArray(ResourceLocation texture, String unlocalizedName)
|
||||||
{
|
{
|
||||||
this.texture = texture;
|
this.texture = texture;
|
||||||
this.unLocalizedName = unLocalizedName;
|
this.unlocalizedName = unlocalizedName;
|
||||||
this.chalkPerBlockCost = 1;
|
this.chalkPerBlockCost = 1;
|
||||||
this.lightLevel = 0;
|
this.lightLevel = 0;
|
||||||
}
|
}
|
||||||
|
@ -42,19 +42,19 @@ public class AlchemyArray implements Comparable<AlchemyArray>
|
||||||
this.texture = texture;
|
this.texture = texture;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getUnLocalizedName()
|
public String getUnlocalizedName()
|
||||||
{
|
{
|
||||||
return unLocalizedName;
|
return unlocalizedName;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setUnLocalizedName(String unLocalizedName)
|
public void setUnlocalizedName(String unlocalizedName)
|
||||||
{
|
{
|
||||||
this.unLocalizedName = unLocalizedName;
|
this.unlocalizedName = unlocalizedName;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getDisplayName()
|
public String getDisplayName()
|
||||||
{
|
{
|
||||||
return StatCollector.translateToLocal(unLocalizedName);
|
return StatCollector.translateToLocal(unlocalizedName);
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getChalkCostPerBlock()
|
public int getChalkCostPerBlock()
|
||||||
|
@ -90,13 +90,13 @@ public class AlchemyArray implements Comparable<AlchemyArray>
|
||||||
this.texture = new ResourceLocation("");
|
this.texture = new ResourceLocation("");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (nbtTagCompound.hasKey("unLocalizedName"))
|
if (nbtTagCompound.hasKey("unlocalizedName"))
|
||||||
{
|
{
|
||||||
this.unLocalizedName = nbtTagCompound.getString("unLocalizedName");
|
this.unlocalizedName = nbtTagCompound.getString("unlocalizedName");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
this.unLocalizedName = "";
|
this.unlocalizedName = "";
|
||||||
}
|
}
|
||||||
|
|
||||||
if (nbtTagCompound.hasKey("className"))
|
if (nbtTagCompound.hasKey("className"))
|
||||||
|
@ -120,7 +120,7 @@ public class AlchemyArray implements Comparable<AlchemyArray>
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
this.texture = new ResourceLocation("");
|
this.texture = new ResourceLocation("");
|
||||||
this.unLocalizedName = "";
|
this.unlocalizedName = "";
|
||||||
this.className = "";
|
this.className = "";
|
||||||
this.lightLevel = 0;
|
this.lightLevel = 0;
|
||||||
}
|
}
|
||||||
|
@ -130,7 +130,7 @@ public class AlchemyArray implements Comparable<AlchemyArray>
|
||||||
{
|
{
|
||||||
nbtTagCompound.setString("textureDomain", texture.getResourceDomain());
|
nbtTagCompound.setString("textureDomain", texture.getResourceDomain());
|
||||||
nbtTagCompound.setString("texturePath", texture.getResourcePath());
|
nbtTagCompound.setString("texturePath", texture.getResourcePath());
|
||||||
nbtTagCompound.setString("unLocalizedName", unLocalizedName);
|
nbtTagCompound.setString("unlocalizedName", unlocalizedName);
|
||||||
nbtTagCompound.setString("className", this.getClass().getCanonicalName());
|
nbtTagCompound.setString("className", this.getClass().getCanonicalName());
|
||||||
nbtTagCompound.setInteger("lightLevel", lightLevel);
|
nbtTagCompound.setInteger("lightLevel", lightLevel);
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,8 +16,6 @@ import com.pahimar.ee3.util.SerializationHelper;
|
||||||
import cpw.mods.fml.common.FMLCommonHandler;
|
import cpw.mods.fml.common.FMLCommonHandler;
|
||||||
import net.minecraft.item.Item;
|
import net.minecraft.item.Item;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.nbt.NBTTagCompound;
|
|
||||||
import net.minecraft.nbt.NBTTagList;
|
|
||||||
import net.minecraftforge.fluids.FluidStack;
|
import net.minecraftforge.fluids.FluidStack;
|
||||||
import net.minecraftforge.oredict.OreDictionary;
|
import net.minecraftforge.oredict.OreDictionary;
|
||||||
|
|
||||||
|
@ -585,24 +583,10 @@ public class EnergyValueRegistry implements JsonSerializer<EnergyValueRegistry>,
|
||||||
return stacksInRange;
|
return stacksInRange;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void readFromNBT(NBTTagCompound nbtTagCompound)
|
public void loadFromMap(Map<WrappedStack, EnergyValue> stackValueMap)
|
||||||
{
|
{
|
||||||
if (nbtTagCompound != null && nbtTagCompound.hasKey("stackMappingList"))
|
if (stackValueMap != null)
|
||||||
{
|
{
|
||||||
TreeMap<WrappedStack, EnergyValue> stackValueMap = new TreeMap<WrappedStack, EnergyValue>();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Read stack value mappings from NBTTagCompound
|
|
||||||
*/
|
|
||||||
NBTTagList stackMappingTagList = nbtTagCompound.getTagList("stackMappingList", 10);
|
|
||||||
for (int i = 0; i < stackMappingTagList.tagCount(); i++)
|
|
||||||
{
|
|
||||||
NBTTagCompound tagCompound = stackMappingTagList.getCompoundTagAt(i);
|
|
||||||
WrappedStack wrappedStack = WrappedStack.fromNBTTagCompound(tagCompound.getCompoundTag("wrappedStack"));
|
|
||||||
EnergyValue energyValue = EnergyValue.loadEnergyValueFromNBT(tagCompound.getCompoundTag("energyValue"));
|
|
||||||
stackValueMap.put(wrappedStack, energyValue);
|
|
||||||
}
|
|
||||||
|
|
||||||
ImmutableSortedMap.Builder<WrappedStack, EnergyValue> stackMappingsBuilder = ImmutableSortedMap.naturalOrder();
|
ImmutableSortedMap.Builder<WrappedStack, EnergyValue> stackMappingsBuilder = ImmutableSortedMap.naturalOrder();
|
||||||
stackMappingsBuilder.putAll(stackValueMap);
|
stackMappingsBuilder.putAll(stackValueMap);
|
||||||
stackMappings = stackMappingsBuilder.build();
|
stackMappings = stackMappingsBuilder.build();
|
||||||
|
@ -614,23 +598,6 @@ public class EnergyValueRegistry implements JsonSerializer<EnergyValueRegistry>,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void writeToNBT(NBTTagCompound nbtTagCompound)
|
|
||||||
{
|
|
||||||
NBTTagList stackMappingTagList = new NBTTagList();
|
|
||||||
for (WrappedStack wrappedStack : stackMappings.keySet())
|
|
||||||
{
|
|
||||||
if (wrappedStack != null && stackMappings.get(wrappedStack) != null)
|
|
||||||
{
|
|
||||||
NBTTagCompound stackMappingCompound = new NBTTagCompound();
|
|
||||||
stackMappingCompound.setTag("wrappedStack", WrappedStack.toNBTTagCompound(wrappedStack));
|
|
||||||
stackMappingCompound.setTag("energyValue", EnergyValue.writeEnergyValueToNBT(stackMappings.get(wrappedStack)));
|
|
||||||
stackMappingTagList.appendTag(stackMappingCompound);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
nbtTagCompound.setTag("stackMappingList", stackMappingTagList);
|
|
||||||
nbtTagCompound.setString("modListMD5", SerializationHelper.getModListMD5());
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setEnergyValue(WrappedStack wrappedStack, EnergyValue energyValue)
|
public void setEnergyValue(WrappedStack wrappedStack, EnergyValue energyValue)
|
||||||
{
|
{
|
||||||
if (wrappedStack != null && energyValue != null && Float.compare(energyValue.getValue(), 0f) > 0)
|
if (wrappedStack != null && energyValue != null && Float.compare(energyValue.getValue(), 0f) > 0)
|
||||||
|
@ -740,26 +707,33 @@ public class EnergyValueRegistry implements JsonSerializer<EnergyValueRegistry>,
|
||||||
|
|
||||||
if (!Settings.DynamicEnergyValueGeneration.regenerateEnergyValuesWhen.equalsIgnoreCase("Always"))
|
if (!Settings.DynamicEnergyValueGeneration.regenerateEnergyValuesWhen.equalsIgnoreCase("Always"))
|
||||||
{
|
{
|
||||||
if (md5EnergyValuesFile.exists())
|
if (Settings.DynamicEnergyValueGeneration.regenerateEnergyValuesWhen.equalsIgnoreCase("When Mods Change"))
|
||||||
{
|
{
|
||||||
LogHelper.info("Attempting to load energy values from file: " + md5EnergyValuesFile.getAbsolutePath());
|
if (md5EnergyValuesFile.exists())
|
||||||
stackValueMap = SerializationHelper.decompressEnergyValueStackMapFromFile(md5EnergyValuesFile);
|
{
|
||||||
|
LogHelper.info("Attempting to load energy values from file: " + md5EnergyValuesFile.getAbsolutePath());
|
||||||
|
stackValueMap = SerializationHelper.decompressEnergyValueStackMapFromFile(md5EnergyValuesFile);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
else if (Settings.DynamicEnergyValueGeneration.regenerateEnergyValuesWhen.equalsIgnoreCase("Never"))
|
||||||
if (staticEnergyValuesFile.exists())
|
|
||||||
{
|
{
|
||||||
LogHelper.info("Attempting to load energy values from file: " + staticEnergyValuesFile.getAbsolutePath());
|
if (staticEnergyValuesFile.exists())
|
||||||
stackValueMap = SerializationHelper.decompressEnergyValueStackMapFromFile(staticEnergyValuesFile);
|
{
|
||||||
|
LogHelper.info("Attempting to load energy values from file: " + staticEnergyValuesFile.getAbsolutePath());
|
||||||
|
stackValueMap = SerializationHelper.decompressEnergyValueStackMapFromFile(staticEnergyValuesFile);
|
||||||
|
}
|
||||||
|
else if (md5EnergyValuesFile.exists())
|
||||||
|
{
|
||||||
|
LogHelper.info("Attempting to load energy values from file: " + md5EnergyValuesFile.getAbsolutePath());
|
||||||
|
stackValueMap = SerializationHelper.decompressEnergyValueStackMapFromFile(md5EnergyValuesFile);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (stackValueMap != null)
|
if (stackValueMap != null)
|
||||||
{
|
{
|
||||||
|
loadFromMap(stackValueMap);
|
||||||
LogHelper.info("Successfully loaded energy values from file");
|
LogHelper.info("Successfully loaded energy values from file");
|
||||||
for (WrappedStack wrappedStack : stackValueMap.keySet())
|
return true;
|
||||||
{
|
|
||||||
LogHelper.info(String.format("Stack: %s, Value: %s", wrappedStack, stackValueMap.get(wrappedStack)));
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,20 +1,25 @@
|
||||||
package com.pahimar.ee3.network.message;
|
package com.pahimar.ee3.network.message;
|
||||||
|
|
||||||
|
import com.google.gson.stream.JsonReader;
|
||||||
|
import com.pahimar.ee3.api.EnergyValue;
|
||||||
import com.pahimar.ee3.exchange.EnergyValueRegistry;
|
import com.pahimar.ee3.exchange.EnergyValueRegistry;
|
||||||
|
import com.pahimar.ee3.exchange.EnergyValueStackMapping;
|
||||||
|
import com.pahimar.ee3.exchange.WrappedStack;
|
||||||
|
import com.pahimar.ee3.util.CompressionHelper;
|
||||||
import com.pahimar.ee3.util.LogHelper;
|
import com.pahimar.ee3.util.LogHelper;
|
||||||
import cpw.mods.fml.common.network.simpleimpl.IMessage;
|
import cpw.mods.fml.common.network.simpleimpl.IMessage;
|
||||||
import cpw.mods.fml.common.network.simpleimpl.IMessageHandler;
|
import cpw.mods.fml.common.network.simpleimpl.IMessageHandler;
|
||||||
import cpw.mods.fml.common.network.simpleimpl.MessageContext;
|
import cpw.mods.fml.common.network.simpleimpl.MessageContext;
|
||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
import net.minecraft.nbt.CompressedStreamTools;
|
|
||||||
import net.minecraft.nbt.NBTTagCompound;
|
|
||||||
|
|
||||||
import java.io.ByteArrayInputStream;
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.io.StringReader;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.TreeMap;
|
||||||
|
|
||||||
public class MessageSyncEnergyValues implements IMessage, IMessageHandler<MessageSyncEnergyValues, IMessage>
|
public class MessageSyncEnergyValues implements IMessage, IMessageHandler<MessageSyncEnergyValues, IMessage>
|
||||||
{
|
{
|
||||||
public NBTTagCompound energyValueRegistryNBT;
|
public String jsonEnergyValueRegistry;
|
||||||
|
|
||||||
public MessageSyncEnergyValues()
|
public MessageSyncEnergyValues()
|
||||||
{
|
{
|
||||||
|
@ -22,8 +27,7 @@ public class MessageSyncEnergyValues implements IMessage, IMessageHandler<Messag
|
||||||
|
|
||||||
public MessageSyncEnergyValues(EnergyValueRegistry energyValueRegistry)
|
public MessageSyncEnergyValues(EnergyValueRegistry energyValueRegistry)
|
||||||
{
|
{
|
||||||
energyValueRegistryNBT = new NBTTagCompound();
|
this.jsonEnergyValueRegistry = energyValueRegistry.toJson();
|
||||||
energyValueRegistry.writeToNBT(energyValueRegistryNBT);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -34,24 +38,17 @@ public class MessageSyncEnergyValues implements IMessage, IMessageHandler<Messag
|
||||||
@Override
|
@Override
|
||||||
public void fromBytes(ByteBuf buf)
|
public void fromBytes(ByteBuf buf)
|
||||||
{
|
{
|
||||||
byte[] compressedNBT = null;
|
byte[] compressedBytes = null;
|
||||||
int readableBytes = buf.readInt();
|
int readableBytes = buf.readInt();
|
||||||
|
|
||||||
if (readableBytes > 0)
|
if (readableBytes > 0)
|
||||||
{
|
{
|
||||||
compressedNBT = buf.readBytes(readableBytes).array();
|
compressedBytes = buf.readBytes(readableBytes).array();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (compressedNBT != null)
|
if (compressedBytes != null)
|
||||||
{
|
{
|
||||||
try
|
this.jsonEnergyValueRegistry = CompressionHelper.decompressStringFromByteArray(compressedBytes);
|
||||||
{
|
|
||||||
this.energyValueRegistryNBT = CompressedStreamTools.readCompressed(new ByteArrayInputStream(compressedNBT));
|
|
||||||
}
|
|
||||||
catch (IOException e)
|
|
||||||
{
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -63,24 +60,17 @@ public class MessageSyncEnergyValues implements IMessage, IMessageHandler<Messag
|
||||||
@Override
|
@Override
|
||||||
public void toBytes(ByteBuf buf)
|
public void toBytes(ByteBuf buf)
|
||||||
{
|
{
|
||||||
byte[] compressedNBT = null;
|
byte[] compressedBytes = null;
|
||||||
|
|
||||||
try
|
if (jsonEnergyValueRegistry != null)
|
||||||
{
|
{
|
||||||
if (energyValueRegistryNBT != null)
|
compressedBytes = CompressionHelper.compressStringToByteArray(jsonEnergyValueRegistry);
|
||||||
{
|
|
||||||
compressedNBT = CompressedStreamTools.compress(energyValueRegistryNBT);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (IOException e)
|
|
||||||
{
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (compressedNBT != null)
|
if (compressedBytes != null)
|
||||||
{
|
{
|
||||||
buf.writeInt(compressedNBT.length);
|
buf.writeInt(compressedBytes.length);
|
||||||
buf.writeBytes(compressedNBT);
|
buf.writeBytes(compressedBytes);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -99,9 +89,35 @@ public class MessageSyncEnergyValues implements IMessage, IMessageHandler<Messag
|
||||||
@Override
|
@Override
|
||||||
public IMessage onMessage(MessageSyncEnergyValues message, MessageContext ctx)
|
public IMessage onMessage(MessageSyncEnergyValues message, MessageContext ctx)
|
||||||
{
|
{
|
||||||
if (message.energyValueRegistryNBT != null)
|
if (message.jsonEnergyValueRegistry != null)
|
||||||
{
|
{
|
||||||
EnergyValueRegistry.getInstance().readFromNBT(message.energyValueRegistryNBT);
|
Map<WrappedStack, EnergyValue> energyValueStackMap = new TreeMap<WrappedStack, EnergyValue>();
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
JsonReader jsonReader = new JsonReader(new StringReader(message.jsonEnergyValueRegistry));
|
||||||
|
jsonReader.beginArray();
|
||||||
|
while (jsonReader.hasNext())
|
||||||
|
{
|
||||||
|
EnergyValueStackMapping energyValueStackMapping = EnergyValueStackMapping.jsonSerializer.fromJson(jsonReader, EnergyValueStackMapping.class);
|
||||||
|
if (energyValueStackMapping != null)
|
||||||
|
{
|
||||||
|
energyValueStackMap.put(energyValueStackMapping.wrappedStack, energyValueStackMapping.energyValue);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
jsonReader.endArray();
|
||||||
|
jsonReader.close();
|
||||||
|
}
|
||||||
|
catch (IOException e)
|
||||||
|
{
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
for (WrappedStack wrappedStack : energyValueStackMap.keySet())
|
||||||
|
{
|
||||||
|
LogHelper.info(String.format("Object: %s, Value: %s", wrappedStack, energyValueStackMap.get(wrappedStack)));
|
||||||
|
}
|
||||||
|
EnergyValueRegistry.getInstance().loadFromMap(energyValueStackMap);
|
||||||
LogHelper.info("Client successfully received EnergyValues from server");
|
LogHelper.info("Client successfully received EnergyValues from server");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
Loading…
Reference in a new issue