Unfinished work, nothing to see here, got a baby to feed!

This commit is contained in:
Pahimar 2014-09-09 22:52:46 -04:00
parent b5974a02b0
commit f39b047c0a
3 changed files with 115 additions and 1 deletions

View file

@ -1,5 +1,8 @@
package com.pahimar.ee3.command;
import com.pahimar.ee3.api.EnergyValue;
import com.pahimar.ee3.exchange.EnergyValueRegistry;
import com.pahimar.ee3.exchange.WrappedStack;
import com.pahimar.ee3.util.LogHelper;
import net.minecraft.command.ICommandSender;
import net.minecraft.command.WrongUsageException;
@ -67,6 +70,8 @@ public class CommandSetEnergyValue extends CommandEE
return;
}
}
EnergyValueRegistry.getInstance().setEnergyValue(new WrappedStack(itemStack), new EnergyValue(energyValue));
}
}

View file

@ -653,7 +653,8 @@ public class EnergyValueRegistry implements INBTTaggable
NBTTagList stackMappingTagList = new NBTTagList();
for (WrappedStack wrappedStack : stackMappings.keySet())
{
if (wrappedStack != null && stackMappings.get(wrappedStack) != null) {
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)));
@ -662,4 +663,49 @@ public class EnergyValueRegistry implements INBTTaggable
}
nbtTagCompound.setTag("stackMappingList", stackMappingTagList);
}
public void setEnergyValue(WrappedStack wrappedStack, EnergyValue energyValue)
{
HashMap<WrappedStack, EnergyValue> stackValueMap = new HashMap<WrappedStack, EnergyValue>();
/**
* Read stack value mappings from NBTTagCompound
*/
stackValueMap.putAll(stackMappings);
stackValueMap.put(wrappedStack, energyValue);
ImmutableSortedMap.Builder<WrappedStack, EnergyValue> stackMappingsBuilder = ImmutableSortedMap.naturalOrder();
stackMappingsBuilder.putAll(stackValueMap);
stackMappings = stackMappingsBuilder.build();
/**
* Resolve value stack mappings from the newly loaded stack mappings
*/
SortedMap<EnergyValue, List<WrappedStack>> tempValueMappings = new TreeMap<EnergyValue, List<WrappedStack>>();
for (WrappedStack stack : stackMappings.keySet())
{
if (stack != null)
{
EnergyValue value = stackMappings.get(stack);
if (value != null)
{
if (tempValueMappings.containsKey(value))
{
if (!(tempValueMappings.get(value).contains(stack)))
{
tempValueMappings.get(value).add(stack);
}
}
else
{
tempValueMappings.put(value, new ArrayList<WrappedStack>(Arrays.asList(stack)));
}
}
}
}
valueMappings = ImmutableSortedMap.copyOf(tempValueMappings);
}
}

View file

@ -0,0 +1,63 @@
package com.pahimar.ee3.network.message;
import com.pahimar.ee3.api.EnergyValue;
import com.pahimar.ee3.exchange.WrappedStack;
import cpw.mods.fml.common.network.simpleimpl.IMessage;
import cpw.mods.fml.common.network.simpleimpl.IMessageHandler;
import cpw.mods.fml.common.network.simpleimpl.MessageContext;
import io.netty.buffer.ByteBuf;
import net.minecraft.nbt.CompressedStreamTools;
import net.minecraft.nbt.NBTTagCompound;
import java.io.IOException;
public class MessageSetEnergyValue implements IMessage, IMessageHandler<MessageSetEnergyValue, IMessage>
{
public NBTTagCompound energyValueMappingNBT;
public MessageSetEnergyValue()
{
}
public MessageSetEnergyValue(WrappedStack wrappedStack, EnergyValue energyValue)
{
}
@Override
public void fromBytes(ByteBuf buf)
{
}
@Override
public void toBytes(ByteBuf buf)
{
byte[] compressedNBT = null;
try
{
compressedNBT = CompressedStreamTools.compress(energyValueMappingNBT);
}
catch (IOException e)
{
e.printStackTrace();
}
if (compressedNBT != null)
{
buf.writeInt(compressedNBT.length);
buf.writeBytes(compressedNBT);
}
else
{
buf.writeInt(0);
}
}
@Override
public IMessage onMessage(MessageSetEnergyValue message, MessageContext ctx)
{
return null;
}
}