synch NBT as well for crystal chest
This commit is contained in:
parent
b8f8d10f68
commit
0c086f5569
|
@ -10,10 +10,13 @@
|
||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
package cpw.mods.ironchest;
|
package cpw.mods.ironchest;
|
||||||
|
|
||||||
|
import cpw.mods.fml.common.network.ByteBufUtils;
|
||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
import io.netty.channel.ChannelHandlerContext;
|
import io.netty.channel.ChannelHandlerContext;
|
||||||
import io.netty.channel.SimpleChannelInboundHandler;
|
import io.netty.channel.SimpleChannelInboundHandler;
|
||||||
import java.util.EnumMap;
|
import java.util.EnumMap;
|
||||||
|
|
||||||
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.network.Packet;
|
import net.minecraft.network.Packet;
|
||||||
import net.minecraft.tileentity.TileEntity;
|
import net.minecraft.tileentity.TileEntity;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
|
@ -85,7 +88,7 @@ public enum PacketHandler {
|
||||||
{
|
{
|
||||||
TileEntityIronChest icte = (TileEntityIronChest) te;
|
TileEntityIronChest icte = (TileEntityIronChest) te;
|
||||||
icte.setFacing(msg.facing);
|
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 z;
|
||||||
int type;
|
int type;
|
||||||
int facing;
|
int facing;
|
||||||
int[] items;
|
ItemStack[] itemStacks;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -135,14 +138,12 @@ public enum PacketHandler {
|
||||||
target.writeInt(msg.z);
|
target.writeInt(msg.z);
|
||||||
int typeAndFacing = ((msg.type & 0x0F) | ((msg.facing & 0x0F) << 4)) & 0xFF;
|
int typeAndFacing = ((msg.type & 0x0F) | ((msg.facing & 0x0F) << 4)) & 0xFF;
|
||||||
target.writeByte(typeAndFacing);
|
target.writeByte(typeAndFacing);
|
||||||
target.writeBoolean(msg.items != null);
|
target.writeBoolean(msg.itemStacks != null);
|
||||||
if (msg.items != null)
|
if (msg.itemStacks != null)
|
||||||
{
|
{
|
||||||
int[] items = msg.items;
|
for (ItemStack i: msg.itemStacks)
|
||||||
for (int j = 0; j < items.length; j++)
|
|
||||||
{
|
{
|
||||||
int i = items[j];
|
ByteBufUtils.writeItemStack(target, i);
|
||||||
target.writeInt(i);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -157,13 +158,13 @@ public enum PacketHandler {
|
||||||
msg.type = (byte)(typDat & 0xf);
|
msg.type = (byte)(typDat & 0xf);
|
||||||
msg.facing = (byte)((typDat >> 4) & 0xf);
|
msg.facing = (byte)((typDat >> 4) & 0xf);
|
||||||
boolean hasStacks = dat.readBoolean();
|
boolean hasStacks = dat.readBoolean();
|
||||||
msg.items = new int[0];
|
msg.itemStacks = new ItemStack[0];
|
||||||
if (hasStacks)
|
if (hasStacks)
|
||||||
{
|
{
|
||||||
msg.items = new int[24];
|
msg.itemStacks = new ItemStack[8];
|
||||||
for (int i = 0; i < msg.items.length; i++)
|
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.z = tileEntityIronChest.zCoord;
|
||||||
msg.type = tileEntityIronChest.getType().ordinal();
|
msg.type = tileEntityIronChest.getType().ordinal();
|
||||||
msg.facing = tileEntityIronChest.getFacing();
|
msg.facing = tileEntityIronChest.getFacing();
|
||||||
msg.items = tileEntityIronChest.buildIntDataList();
|
msg.itemStacks = tileEntityIronChest.buildItemStackDataList();
|
||||||
return INSTANCE.channels.get(Side.SERVER).generatePacketFrom(msg);
|
return INSTANCE.channels.get(Side.SERVER).generatePacketFrom(msg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,10 +15,10 @@ import java.util.Comparator;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import cpw.mods.fml.common.FMLCommonHandler;
|
||||||
import net.minecraft.entity.EntityLivingBase;
|
import net.minecraft.entity.EntityLivingBase;
|
||||||
import net.minecraft.entity.player.EntityPlayer;
|
import net.minecraft.entity.player.EntityPlayer;
|
||||||
import net.minecraft.inventory.IInventory;
|
import net.minecraft.inventory.IInventory;
|
||||||
import net.minecraft.item.Item;
|
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.nbt.NBTTagCompound;
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
import net.minecraft.nbt.NBTTagList;
|
import net.minecraft.nbt.NBTTagList;
|
||||||
|
@ -421,7 +421,7 @@ public class TileEntityIronChest extends TileEntity implements IInventory {
|
||||||
return PacketHandler.getPacket(this);
|
return PacketHandler.getPacket(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void handlePacketData(int typeData, int[] intData)
|
public void handlePacketData(int typeData, ItemStack[] intData)
|
||||||
{
|
{
|
||||||
TileEntityIronChest chest = this;
|
TileEntityIronChest chest = this;
|
||||||
if (this.type.ordinal() != typeData)
|
if (this.type.ordinal() != typeData)
|
||||||
|
@ -431,46 +431,36 @@ public class TileEntityIronChest extends TileEntity implements IInventory {
|
||||||
if (IronChestType.values()[typeData].isTransparent() && intData != null)
|
if (IronChestType.values()[typeData].isTransparent() && intData != null)
|
||||||
{
|
{
|
||||||
int pos = 0;
|
int pos = 0;
|
||||||
if (intData.length < chest.topStacks.length * 3)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
for (int i = 0; i < chest.topStacks.length; i++)
|
for (int i = 0; i < chest.topStacks.length; i++)
|
||||||
{
|
{
|
||||||
if (intData[pos + 2] != 0)
|
if (intData[pos] != null)
|
||||||
{
|
{
|
||||||
Item it = Item.getItemById(intData[pos]);
|
chest.topStacks[i] = intData[pos];
|
||||||
ItemStack is = new ItemStack(it, intData[pos + 2], intData[pos + 1]);
|
|
||||||
chest.topStacks[i] = is;
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
chest.topStacks[i] = null;
|
chest.topStacks[i] = null;
|
||||||
}
|
}
|
||||||
pos += 3;
|
pos ++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public int[] buildIntDataList()
|
public ItemStack[] buildItemStackDataList()
|
||||||
{
|
{
|
||||||
if (type.isTransparent())
|
if (type.isTransparent())
|
||||||
{
|
{
|
||||||
int[] sortList = new int[topStacks.length * 3];
|
ItemStack[] sortList = new ItemStack[topStacks.length];
|
||||||
int pos = 0;
|
int pos = 0;
|
||||||
for (ItemStack is : topStacks)
|
for (ItemStack is : topStacks)
|
||||||
{
|
{
|
||||||
if (is != null)
|
if (is != null)
|
||||||
{
|
{
|
||||||
sortList[pos++] = Item.getIdFromItem(is.getItem());
|
sortList[pos++] = is;
|
||||||
sortList[pos++] = is.getItemDamage();
|
|
||||||
sortList[pos++] = is.stackSize;
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
sortList[pos++] = 0;
|
sortList[pos++] = null;
|
||||||
sortList[pos++] = 0;
|
|
||||||
sortList[pos++] = 0;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return sortList;
|
return sortList;
|
||||||
|
|
Loading…
Reference in New Issue