synch NBT as well for crystal chest

This commit is contained in:
Progwml6 2014-09-04 20:52:03 -04:00
parent b8f8d10f68
commit 0c086f5569
2 changed files with 23 additions and 32 deletions

View File

@ -10,10 +10,13 @@
******************************************************************************/
package cpw.mods.ironchest;
import cpw.mods.fml.common.network.ByteBufUtils;
import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;
import java.util.EnumMap;
import net.minecraft.item.ItemStack;
import net.minecraft.network.Packet;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
@ -85,7 +88,7 @@ public enum PacketHandler {
{
TileEntityIronChest icte = (TileEntityIronChest) te;
icte.setFacing(msg.facing);
icte.handlePacketData(msg.type, msg.items);
icte.handlePacketData(msg.type, msg.itemStacks);
}
}
}
@ -106,7 +109,7 @@ public enum PacketHandler {
int z;
int type;
int facing;
int[] items;
ItemStack[] itemStacks;
}
/**
@ -135,14 +138,12 @@ public enum PacketHandler {
target.writeInt(msg.z);
int typeAndFacing = ((msg.type & 0x0F) | ((msg.facing & 0x0F) << 4)) & 0xFF;
target.writeByte(typeAndFacing);
target.writeBoolean(msg.items != null);
if (msg.items != null)
target.writeBoolean(msg.itemStacks != null);
if (msg.itemStacks != null)
{
int[] items = msg.items;
for (int j = 0; j < items.length; j++)
for (ItemStack i: msg.itemStacks)
{
int i = items[j];
target.writeInt(i);
ByteBufUtils.writeItemStack(target, i);
}
}
}
@ -157,13 +158,13 @@ public enum PacketHandler {
msg.type = (byte)(typDat & 0xf);
msg.facing = (byte)((typDat >> 4) & 0xf);
boolean hasStacks = dat.readBoolean();
msg.items = new int[0];
msg.itemStacks = new ItemStack[0];
if (hasStacks)
{
msg.items = new int[24];
for (int i = 0; i < msg.items.length; i++)
msg.itemStacks = new ItemStack[8];
for (int i = 0; i < msg.itemStacks.length; i++)
{
msg.items[i] = dat.readInt();
msg.itemStacks[i] = ByteBufUtils.readItemStack(dat);
}
}
}
@ -194,7 +195,7 @@ public enum PacketHandler {
msg.z = tileEntityIronChest.zCoord;
msg.type = tileEntityIronChest.getType().ordinal();
msg.facing = tileEntityIronChest.getFacing();
msg.items = tileEntityIronChest.buildIntDataList();
msg.itemStacks = tileEntityIronChest.buildItemStackDataList();
return INSTANCE.channels.get(Side.SERVER).generatePacketFrom(msg);
}
}

View File

@ -15,10 +15,10 @@ import java.util.Comparator;
import java.util.Iterator;
import java.util.List;
import cpw.mods.fml.common.FMLCommonHandler;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
@ -421,7 +421,7 @@ public class TileEntityIronChest extends TileEntity implements IInventory {
return PacketHandler.getPacket(this);
}
public void handlePacketData(int typeData, int[] intData)
public void handlePacketData(int typeData, ItemStack[] intData)
{
TileEntityIronChest chest = this;
if (this.type.ordinal() != typeData)
@ -431,46 +431,36 @@ public class TileEntityIronChest extends TileEntity implements IInventory {
if (IronChestType.values()[typeData].isTransparent() && intData != null)
{
int pos = 0;
if (intData.length < chest.topStacks.length * 3)
{
return;
}
for (int i = 0; i < chest.topStacks.length; i++)
{
if (intData[pos + 2] != 0)
if (intData[pos] != null)
{
Item it = Item.getItemById(intData[pos]);
ItemStack is = new ItemStack(it, intData[pos + 2], intData[pos + 1]);
chest.topStacks[i] = is;
chest.topStacks[i] = intData[pos];
}
else
{
chest.topStacks[i] = null;
}
pos += 3;
pos ++;
}
}
}
public int[] buildIntDataList()
public ItemStack[] buildItemStackDataList()
{
if (type.isTransparent())
{
int[] sortList = new int[topStacks.length * 3];
ItemStack[] sortList = new ItemStack[topStacks.length];
int pos = 0;
for (ItemStack is : topStacks)
{
if (is != null)
{
sortList[pos++] = Item.getIdFromItem(is.getItem());
sortList[pos++] = is.getItemDamage();
sortList[pos++] = is.stackSize;
sortList[pos++] = is;
}
else
{
sortList[pos++] = 0;
sortList[pos++] = 0;
sortList[pos++] = 0;
sortList[pos++] = null;
}
}
return sortList;