Add PipeContent NBT sync.
This commit is contained in:
parent
a0eab6d603
commit
0c88fbda6a
6 changed files with 172 additions and 1 deletions
|
@ -7,6 +7,8 @@ public class PacketIds {
|
||||||
public static final int PIPE_CONTENTS = 2;
|
public static final int PIPE_CONTENTS = 2;
|
||||||
public static final int PIPE_LIQUID = 3;
|
public static final int PIPE_LIQUID = 3;
|
||||||
public static final int PIPE_POWER = 4;
|
public static final int PIPE_POWER = 4;
|
||||||
|
public static final int REQUEST_ITEM_NBT = 5;
|
||||||
|
public static final int PIPE_ITEM_NBT = 6;
|
||||||
public static final int SELECTION_ASSEMBLY_GET = 20;
|
public static final int SELECTION_ASSEMBLY_GET = 20;
|
||||||
public static final int SELECTION_ASSEMBLY = 21;
|
public static final int SELECTION_ASSEMBLY = 21;
|
||||||
public static final int SELECTION_ASSEMBLY_SEND = 22;
|
public static final int SELECTION_ASSEMBLY_SEND = 22;
|
||||||
|
|
|
@ -20,6 +20,7 @@ import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import net.minecraft.entity.item.EntityItem;
|
import net.minecraft.entity.item.EntityItem;
|
||||||
|
import net.minecraft.entity.player.EntityPlayer;
|
||||||
import net.minecraft.inventory.IInventory;
|
import net.minecraft.inventory.IInventory;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.nbt.NBTTagCompound;
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
|
@ -42,7 +43,10 @@ import buildcraft.core.proxy.CoreProxy;
|
||||||
import buildcraft.core.utils.BlockUtil;
|
import buildcraft.core.utils.BlockUtil;
|
||||||
import buildcraft.core.utils.Utils;
|
import buildcraft.core.utils.Utils;
|
||||||
import buildcraft.transport.network.PacketPipeTransportContent;
|
import buildcraft.transport.network.PacketPipeTransportContent;
|
||||||
|
import buildcraft.transport.network.PacketPipeTransportNBT;
|
||||||
|
import buildcraft.transport.network.PacketSimpleId;
|
||||||
import cpw.mods.fml.common.network.PacketDispatcher;
|
import cpw.mods.fml.common.network.PacketDispatcher;
|
||||||
|
import cpw.mods.fml.common.network.Player;
|
||||||
|
|
||||||
public class PipeTransportItems extends PipeTransport {
|
public class PipeTransportItems extends PipeTransport {
|
||||||
|
|
||||||
|
@ -450,7 +454,19 @@ public class PipeTransportItems extends PipeTransport {
|
||||||
item = data.item;
|
item = data.item;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(item.getItemStack() == null) {
|
||||||
item.setItemStack(new ItemStack(packet.getItemId(), packet.getStackSize(), packet.getItemDamage()));
|
item.setItemStack(new ItemStack(packet.getItemId(), packet.getStackSize(), packet.getItemDamage()));
|
||||||
|
if(packet.hasNBT()) {
|
||||||
|
PacketDispatcher.sendPacketToServer(new PacketSimpleId(PacketIds.REQUEST_ITEM_NBT, this.xCoord, this.yCoord, this.zCoord, packet.getEntityId()).getPacket());
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if(item.getItemStack().itemID != packet.getItemId() || item.getItemStack().stackSize != packet.getStackSize() || item.getItemStack().getItemDamage() != packet.getItemDamage() || item.getItemStack().hasTagCompound() != packet.hasNBT()) {
|
||||||
|
item.setItemStack(new ItemStack(packet.getItemId(), packet.getStackSize(), packet.getItemDamage()));
|
||||||
|
if(packet.hasNBT()) {
|
||||||
|
PacketDispatcher.sendPacketToServer(new PacketSimpleId(PacketIds.REQUEST_ITEM_NBT, this.xCoord, this.yCoord, this.zCoord, packet.getEntityId()).getPacket());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (item.getPosition() == null) {
|
if (item.getPosition() == null) {
|
||||||
item.setPosition(packet.getPosX(), packet.getPosY(), packet.getPosZ());
|
item.setPosition(packet.getPosX(), packet.getPosY(), packet.getPosZ());
|
||||||
|
@ -468,6 +484,24 @@ public class PipeTransportItems extends PipeTransport {
|
||||||
travelingEntities.put(item.getEntityId(), data);
|
travelingEntities.put(item.getEntityId(), data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handles the NBT tag Request from player of the entityId
|
||||||
|
*/
|
||||||
|
public void handleNBTRequestPacket(EntityPlayer player, int entityId) {
|
||||||
|
EntityData data = travelingEntities.get(entityId);
|
||||||
|
if(data == null || data.item == null || data.item.getItemStack() == null) return;
|
||||||
|
PacketDispatcher.sendPacketToPlayer(new PacketPipeTransportNBT(PacketIds.PIPE_ITEM_NBT, this.xCoord, this.yCoord, this.zCoord, entityId, data.item.getItemStack().getTagCompound()).getPacket(), (Player) player);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handles the Item NBT tag information of the packet
|
||||||
|
*/
|
||||||
|
public void handleNBTPacket(PacketPipeTransportNBT packet) {
|
||||||
|
EntityData data = travelingEntities.get(packet.getEntityId());
|
||||||
|
if(data == null || data.item == null || data.item.getItemStack() == null) return;
|
||||||
|
data.item.getItemStack().setTagCompound(packet.getTagCompound());
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a packet describing a stack of items inside a pipe.
|
* Creates a packet describing a stack of items inside a pipe.
|
||||||
*
|
*
|
||||||
|
|
|
@ -66,6 +66,11 @@ public class PacketHandlerTransport implements IPacketHandler {
|
||||||
packet.readData(data);
|
packet.readData(data);
|
||||||
onGateSelection((EntityPlayer) player, packet);
|
onGateSelection((EntityPlayer) player, packet);
|
||||||
break;
|
break;
|
||||||
|
case PacketIds.PIPE_ITEM_NBT:
|
||||||
|
PacketPipeTransportNBT packetD = new PacketPipeTransportNBT();
|
||||||
|
packetD.readData(data);
|
||||||
|
onPipeContentNBT((EntityPlayer) player, packetD);
|
||||||
|
break;
|
||||||
|
|
||||||
/** SERVER SIDE **/
|
/** SERVER SIDE **/
|
||||||
case PacketIds.DIAMOND_PIPE_SELECT: {
|
case PacketIds.DIAMOND_PIPE_SELECT: {
|
||||||
|
@ -99,6 +104,12 @@ public class PacketHandlerTransport implements IPacketHandler {
|
||||||
packet3.readData(data);
|
packet3.readData(data);
|
||||||
onGateSelectionChange((EntityPlayerMP) player, packet3);
|
onGateSelectionChange((EntityPlayerMP) player, packet3);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case PacketIds.REQUEST_ITEM_NBT:
|
||||||
|
PacketSimpleId packet4 = new PacketSimpleId();
|
||||||
|
packet4.readData(data);
|
||||||
|
onItemNBTRequest((EntityPlayerMP) player, packet4);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
|
@ -148,6 +159,20 @@ public class PacketHandlerTransport implements IPacketHandler {
|
||||||
((ContainerGateInterface) container).setSelection(packet);
|
((ContainerGateInterface) container).setSelection(packet);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void onPipeContentNBT(EntityPlayer player, PacketPipeTransportNBT packet) {
|
||||||
|
TileGenericPipe pipe = getPipe(player.worldObj, packet.posX, packet.posY, packet.posZ);
|
||||||
|
if (pipe == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (pipe.pipe == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (!(pipe.pipe.transport instanceof PipeTransportItems))
|
||||||
|
return;
|
||||||
|
|
||||||
|
((PipeTransportItems)pipe.pipe.transport).handleNBTPacket(packet);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handles a pipe description packet. (Creates the pipe object client side if needed.)
|
* Handles a pipe description packet. (Creates the pipe object client side if needed.)
|
||||||
*
|
*
|
||||||
|
@ -317,4 +342,22 @@ public class PacketHandlerTransport implements IPacketHandler {
|
||||||
((PipeItemsEmerald) pipe.pipe).setInventorySlotContents(packet.slot, packet.stack);
|
((PipeItemsEmerald) pipe.pipe).setInventorySlotContents(packet.slot, packet.stack);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handles the client request for tag data
|
||||||
|
* @param player
|
||||||
|
* @param packet
|
||||||
|
*/
|
||||||
|
private void onItemNBTRequest(EntityPlayerMP player, PacketSimpleId packet) {
|
||||||
|
TileGenericPipe pipe = getPipe(player.worldObj, packet.posX, packet.posY, packet.posZ);
|
||||||
|
if (pipe == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (pipe.pipe == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (!(pipe.pipe.transport instanceof PipeTransportItems))
|
||||||
|
return;
|
||||||
|
|
||||||
|
((PipeTransportItems) pipe.pipe.transport).handleNBTRequestPacket(player, packet.entityId);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,6 +23,7 @@ public class PacketPipeTransportContent extends BuildCraftPacket {
|
||||||
private float itemY;
|
private float itemY;
|
||||||
private float itemZ;
|
private float itemZ;
|
||||||
private float speed;
|
private float speed;
|
||||||
|
private boolean hasNBT;
|
||||||
public int posX;
|
public int posX;
|
||||||
public int posY;
|
public int posY;
|
||||||
public int posZ;
|
public int posZ;
|
||||||
|
@ -50,6 +51,7 @@ public class PacketPipeTransportContent extends BuildCraftPacket {
|
||||||
data.writeShort(entityData.item.getItemStack().getItemDamage());
|
data.writeShort(entityData.item.getItemStack().getItemDamage());
|
||||||
|
|
||||||
data.writeFloat(entityData.item.getSpeed());
|
data.writeFloat(entityData.item.getSpeed());
|
||||||
|
data.writeBoolean(entityData.item.getItemStack().hasTagCompound());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -72,6 +74,7 @@ public class PacketPipeTransportContent extends BuildCraftPacket {
|
||||||
this.itemDamage = data.readShort();
|
this.itemDamage = data.readShort();
|
||||||
|
|
||||||
this.speed = data.readFloat();
|
this.speed = data.readFloat();
|
||||||
|
this.hasNBT = data.readBoolean();
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getEntityId() {
|
public int getEntityId() {
|
||||||
|
@ -114,6 +117,10 @@ public class PacketPipeTransportContent extends BuildCraftPacket {
|
||||||
return speed;
|
return speed;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean hasNBT() {
|
||||||
|
return hasNBT;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getID() {
|
public int getID() {
|
||||||
return PacketIds.PIPE_CONTENTS;
|
return PacketIds.PIPE_CONTENTS;
|
||||||
|
|
|
@ -0,0 +1,53 @@
|
||||||
|
package buildcraft.transport.network;
|
||||||
|
|
||||||
|
import java.io.DataInputStream;
|
||||||
|
import java.io.DataOutputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
import net.minecraft.nbt.CompressedStreamTools;
|
||||||
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
|
import buildcraft.core.network.PacketCoordinates;
|
||||||
|
|
||||||
|
public class PacketPipeTransportNBT extends PacketCoordinates {
|
||||||
|
|
||||||
|
private NBTTagCompound tag;
|
||||||
|
private int entityId;
|
||||||
|
|
||||||
|
public PacketPipeTransportNBT() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public PacketPipeTransportNBT(int id, int x, int y, int z, int entityId, NBTTagCompound tag) {
|
||||||
|
super(id, x, y, z);
|
||||||
|
this.entityId = entityId;
|
||||||
|
this.tag = tag;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void writeData(DataOutputStream data) throws IOException {
|
||||||
|
super.writeData(data);
|
||||||
|
|
||||||
|
data.writeInt(entityId);
|
||||||
|
byte[] compressed = CompressedStreamTools.compress(tag);
|
||||||
|
data.writeShort(compressed.length);
|
||||||
|
data.write(compressed);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void readData(DataInputStream data) throws IOException {
|
||||||
|
super.readData(data);
|
||||||
|
|
||||||
|
this.entityId = data.readInt();
|
||||||
|
short length = data.readShort();
|
||||||
|
byte[] compressed = new byte[length];
|
||||||
|
data.readFully(compressed);
|
||||||
|
this.tag = CompressedStreamTools.decompress(compressed);
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getEntityId() {
|
||||||
|
return entityId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public NBTTagCompound getTagCompound() {
|
||||||
|
return tag;
|
||||||
|
}
|
||||||
|
}
|
32
common/buildcraft/transport/network/PacketSimpleId.java
Normal file
32
common/buildcraft/transport/network/PacketSimpleId.java
Normal file
|
@ -0,0 +1,32 @@
|
||||||
|
package buildcraft.transport.network;
|
||||||
|
|
||||||
|
import java.io.DataInputStream;
|
||||||
|
import java.io.DataOutputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
import buildcraft.core.network.PacketCoordinates;
|
||||||
|
|
||||||
|
public class PacketSimpleId extends PacketCoordinates {
|
||||||
|
|
||||||
|
public int entityId;
|
||||||
|
public PacketSimpleId() {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
|
||||||
|
public PacketSimpleId(int id, int x, int y, int z, int entityId) {
|
||||||
|
super(id, x, y, z);
|
||||||
|
this.entityId = entityId;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void writeData(DataOutputStream data) throws IOException {
|
||||||
|
super.writeData(data);
|
||||||
|
data.writeInt(entityId);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void readData(DataInputStream data) throws IOException {
|
||||||
|
super.readData(data);
|
||||||
|
entityId = data.readInt();
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue