Improved diamond pipe client synch.
This commit is contained in:
parent
f4a018c286
commit
9077e9dedf
5 changed files with 32 additions and 138 deletions
|
@ -2,6 +2,7 @@ package net.minecraft.src.buildcraft.core;
|
|||
|
||||
import net.minecraft.src.Container;
|
||||
import net.minecraft.src.GuiContainer;
|
||||
import net.minecraft.src.IInventory;
|
||||
import net.minecraft.src.ItemStack;
|
||||
import net.minecraft.src.OpenGlHelper;
|
||||
import net.minecraft.src.RenderHelper;
|
||||
|
@ -85,6 +86,27 @@ public abstract class GuiAdvancedInterface extends GuiBuildCraft {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* More dynamic slot displaying an inventory stack at specified position in the passed IInventory
|
||||
*/
|
||||
public class IInventorySlot extends AdvancedSlot {
|
||||
|
||||
private IInventory tile;
|
||||
private int slot;
|
||||
|
||||
public IInventorySlot(int x, int y, IInventory tile, int slot) {
|
||||
super(x, y);
|
||||
this.tile = tile;
|
||||
this.slot = slot;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getItemStack() {
|
||||
return tile.getStackInSlot(slot);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public AdvancedSlot[] slots;
|
||||
|
||||
public GuiAdvancedInterface(Container container) {
|
||||
|
|
|
@ -38,11 +38,7 @@ public class GuiDiamondPipe extends GuiAdvancedInterface {
|
|||
for(int k = 0; k < 6; k++)
|
||||
for(int j1 = 0; j1 < 9; j1++) {
|
||||
int id = k * 9 + j1;
|
||||
slots [id] = new ItemSlot(8 + j1 * 18, 18 + k * 18);
|
||||
ItemStack stack = filterInventory.getStackInSlot(j1 + k * 9);
|
||||
|
||||
if (stack != null)
|
||||
((ItemSlot) slots[id]).stack = stack.copy();
|
||||
slots [id] = new IInventorySlot(8 + j1 * 18, 18 + k * 18, filterInventory, j1 + k * 9);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -78,10 +74,10 @@ public class GuiDiamondPipe extends GuiAdvancedInterface {
|
|||
|
||||
int position = getSlotAtLocation (i - cornerX, j - cornerY);
|
||||
|
||||
ItemSlot slot = null;
|
||||
IInventorySlot slot = null;
|
||||
|
||||
if (position != -1)
|
||||
slot = (ItemSlot) slots[position];
|
||||
slot = (IInventorySlot) slots[position];
|
||||
|
||||
if (slot != null) {
|
||||
ItemStack playerStack = mc.thePlayer.inventory.getItemStack();
|
||||
|
@ -92,7 +88,6 @@ public class GuiDiamondPipe extends GuiAdvancedInterface {
|
|||
else
|
||||
newStack = null;
|
||||
|
||||
slot.stack = newStack;
|
||||
filterInventory.setInventorySlotContents(position, newStack);
|
||||
|
||||
if(APIProxy.isRemote()) {
|
||||
|
|
|
@ -156,6 +156,7 @@ public class PacketHandler implements IPacketHandler {
|
|||
* @param packet
|
||||
*/
|
||||
private void onDiamondContents(PacketUpdate packet) {
|
||||
|
||||
World world = ModLoader.getMinecraftInstance().theWorld;
|
||||
|
||||
if(!world.blockExists(packet.posX, packet.posY, packet.posZ))
|
||||
|
|
|
@ -65,6 +65,9 @@ public class TilePacketWrapper {
|
|||
}
|
||||
}
|
||||
|
||||
public PacketPayload toPayload(Object obj) {
|
||||
return toPayload(0, 0, 0, new Object [] {obj});
|
||||
}
|
||||
public PacketPayload toPayload(int x, int y, int z, Object obj) {
|
||||
return toPayload(x, y, z, new Object [] {obj});
|
||||
}
|
||||
|
@ -148,133 +151,4 @@ public class TilePacketWrapper {
|
|||
}
|
||||
}
|
||||
|
||||
/*
|
||||
public Packet230ModLoader toPacket (TileEntity tile) {
|
||||
Packet230ModLoader packet = new Packet230ModLoader();
|
||||
packet.modId = mod_BuildCraftCore.instance.getId();
|
||||
packet.isChunkDataPacket = true;
|
||||
packet.packetType = packetType.ordinal();
|
||||
|
||||
int sizeF = 0, sizeS = 0;
|
||||
|
||||
for (int i = 0; i < rootMappings.length; ++i) {
|
||||
int [] size = rootMappings [i].getSize();
|
||||
|
||||
sizeF += size [1];
|
||||
sizeS += size [2];
|
||||
}
|
||||
|
||||
packet.dataFloat = new float [sizeF];
|
||||
packet.dataString = new String [sizeS];
|
||||
|
||||
ByteBuffer buf = new ByteBuffer();
|
||||
|
||||
buf.writeInt(tile.xCoord);
|
||||
buf.writeInt(tile.yCoord);
|
||||
buf.writeInt(tile.zCoord);
|
||||
|
||||
try {
|
||||
rootMappings [0].setData(tile, buf, packet.dataFloat,
|
||||
packet.dataString, new Indexes(0, 0));
|
||||
|
||||
packet.dataInt = buf.readIntArray();
|
||||
|
||||
return packet;
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public Packet230ModLoader toPacket (int x, int y, int z, Object obj) {
|
||||
return toPacket(x, y, z, new Object [] {obj});
|
||||
}
|
||||
|
||||
public Packet230ModLoader toPacket (int x, int y, int z, Object [] obj) {
|
||||
Packet230ModLoader packet = new Packet230ModLoader();
|
||||
packet.modId = mod_BuildCraftCore.instance.getId();
|
||||
packet.isChunkDataPacket = true;
|
||||
packet.packetType = packetType.ordinal();
|
||||
|
||||
int sizeF = 0, sizeS = 0;
|
||||
|
||||
for (int i = 0; i < rootMappings.length; ++i) {
|
||||
int [] size = rootMappings [i].getSize();
|
||||
|
||||
sizeF += size [1];
|
||||
sizeS += size [2];
|
||||
}
|
||||
|
||||
packet.dataFloat = new float [sizeF];
|
||||
packet.dataString = new String [sizeS];
|
||||
|
||||
ByteBuffer buf = new ByteBuffer();
|
||||
|
||||
buf.writeInt(x);
|
||||
buf.writeInt(y);
|
||||
buf.writeInt(z);
|
||||
|
||||
try {
|
||||
Indexes ind = new Indexes(0, 0);
|
||||
|
||||
for (int i = 0; i < rootMappings.length; ++i) {
|
||||
rootMappings [i].setData(obj [i], buf, packet.dataFloat,
|
||||
packet.dataString, ind);
|
||||
}
|
||||
|
||||
packet.dataInt = buf.readIntArray();
|
||||
|
||||
return packet;
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
|
||||
return null;
|
||||
}
|
||||
}*/
|
||||
|
||||
|
||||
/*
|
||||
public void updateFromPacket (Object obj, Packet230ModLoader packet) {
|
||||
updateFromPacket(new Object [] {obj}, packet);
|
||||
}
|
||||
|
||||
public void updateFromPacket (Object [] obj, Packet230ModLoader packet) {
|
||||
try {
|
||||
ByteBuffer buf = new ByteBuffer();
|
||||
buf.writeIntArray(packet.dataInt);
|
||||
buf.readInt();
|
||||
buf.readInt();
|
||||
buf.readInt();
|
||||
|
||||
Indexes ind = new Indexes(0, 0);
|
||||
|
||||
for (int i = 0; i < rootMappings.length; ++i)
|
||||
rootMappings [i].updateFromData(obj [i], buf, packet.dataFloat,
|
||||
packet.dataString, ind);
|
||||
|
||||
packet.dataInt = buf.readIntArray();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public void updateFromPacket (TileEntity tile, Packet230ModLoader packet) {
|
||||
try {
|
||||
ByteBuffer buf = new ByteBuffer();
|
||||
buf.writeIntArray(packet.dataInt);
|
||||
buf.readInt();
|
||||
buf.readInt();
|
||||
buf.readInt();
|
||||
|
||||
rootMappings [0].updateFromData(tile, buf, packet.dataFloat,
|
||||
packet.dataString, new Indexes(0, 0));
|
||||
|
||||
packet.dataInt = buf.readIntArray();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
|
|
@ -179,6 +179,7 @@ public class PipeLogicDiamond extends PipeLogic {
|
|||
return null;
|
||||
}
|
||||
|
||||
/** SERVER SIDE **/
|
||||
public Packet getContentsPacket(int num) {
|
||||
PacketStack stacks = new PacketStack();
|
||||
stacks.num = num;
|
||||
|
@ -192,10 +193,11 @@ public class PipeLogicDiamond extends PipeLogic {
|
|||
stacks.dmg [j] = items [j + num * 9].getItemDamage();
|
||||
}
|
||||
|
||||
return new PacketUpdate(PacketIds.DIAMOND_PIPE_CONTENTS, networkPacket.toPayload(xCoord, yCoord, zCoord, stacks)).getPacket();
|
||||
return new PacketUpdate(PacketIds.DIAMOND_PIPE_CONTENTS, xCoord, yCoord, zCoord, networkPacket.toPayload(stacks)).getPacket();
|
||||
|
||||
}
|
||||
|
||||
/** CLIENT SIDE **/
|
||||
public void handleContentsPacket (PacketUpdate packet) {
|
||||
PacketStack stacks = new PacketStack();
|
||||
|
||||
|
|
Loading…
Reference in a new issue