Convert diamond pipes to use the new pipe data sync.
This commit is contained in:
parent
4c05ccbde9
commit
2b64be0179
4 changed files with 31 additions and 72 deletions
|
@ -10,7 +10,6 @@ public class PacketIds {
|
||||||
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;
|
||||||
public static final int DIAMOND_PIPE_CONTENTS = 30;
|
|
||||||
public static final int DIAMOND_PIPE_SELECT = 31;
|
public static final int DIAMOND_PIPE_SELECT = 31;
|
||||||
public static final int GATE_ACTIONS = 40;
|
public static final int GATE_ACTIONS = 40;
|
||||||
public static final int GATE_REQUEST_INIT = 41;
|
public static final int GATE_REQUEST_INIT = 41;
|
||||||
|
|
|
@ -36,11 +36,6 @@ public class PacketHandlerTransport implements IPacketHandler {
|
||||||
|
|
||||||
PacketUpdate packet = new PacketUpdate();
|
PacketUpdate packet = new PacketUpdate();
|
||||||
switch (packetID) {
|
switch (packetID) {
|
||||||
case PacketIds.DIAMOND_PIPE_CONTENTS:
|
|
||||||
PacketNBT packetN = new PacketNBT();
|
|
||||||
packetN.readData(data);
|
|
||||||
onDiamondContents((EntityPlayer)player, packetN);
|
|
||||||
break;
|
|
||||||
case PacketIds.PIPE_POWER:
|
case PacketIds.PIPE_POWER:
|
||||||
PacketPowerUpdate packetPower= new PacketPowerUpdate();
|
PacketPowerUpdate packetPower= new PacketPowerUpdate();
|
||||||
packetPower.readData(data);
|
packetPower.readData(data);
|
||||||
|
@ -245,42 +240,6 @@ public class PacketHandlerTransport implements IPacketHandler {
|
||||||
((PipeTransportLiquids) pipe.pipe.transport).handleLiquidPacket(packetLiquid);
|
((PipeTransportLiquids) pipe.pipe.transport).handleLiquidPacket(packetLiquid);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Updates contents of a diamond pipe.
|
|
||||||
*
|
|
||||||
* @param packet
|
|
||||||
*/
|
|
||||||
private void onDiamondContents(EntityPlayer player, PacketNBT packet) {
|
|
||||||
|
|
||||||
World world = player.worldObj;
|
|
||||||
|
|
||||||
if (!world.blockExists(packet.posX, packet.posY, packet.posZ))
|
|
||||||
return;
|
|
||||||
|
|
||||||
TileEntity entity = world.getBlockTileEntity(packet.posX, packet.posY, packet.posZ);
|
|
||||||
if (!(entity instanceof TileGenericPipe))
|
|
||||||
return;
|
|
||||||
|
|
||||||
TileGenericPipe pipe = (TileGenericPipe) entity;
|
|
||||||
if (pipe.pipe == null)
|
|
||||||
return;
|
|
||||||
|
|
||||||
if (!(pipe.pipe.logic instanceof PipeLogicDiamond))
|
|
||||||
return;
|
|
||||||
|
|
||||||
((PipeLogicDiamond) pipe.pipe.logic).handleFilterSet(packet);
|
|
||||||
|
|
||||||
// / FIXME: Unsure how to handle this
|
|
||||||
/*
|
|
||||||
BlockIndex index = new BlockIndex(packet.posX, packet.posY, packet.posZ);
|
|
||||||
|
|
||||||
if (BuildCraftCore.bufferedDescriptions.containsKey(index))
|
|
||||||
BuildCraftCore.bufferedDescriptions.remove(index);
|
|
||||||
|
|
||||||
BuildCraftCore.bufferedDescriptions.put(index, packet);
|
|
||||||
*/
|
|
||||||
}
|
|
||||||
|
|
||||||
/******************** SERVER ******************** **/
|
/******************** SERVER ******************** **/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -8,21 +8,28 @@
|
||||||
|
|
||||||
package buildcraft.transport.pipes;
|
package buildcraft.transport.pipes;
|
||||||
|
|
||||||
|
import java.io.DataInputStream;
|
||||||
|
import java.io.DataOutputStream;
|
||||||
|
import java.io.IOException;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
|
|
||||||
|
import cpw.mods.fml.common.FMLLog;
|
||||||
|
|
||||||
|
import net.minecraft.src.Item;
|
||||||
|
import net.minecraft.src.ItemStack;
|
||||||
|
import net.minecraft.src.NBTBase;
|
||||||
|
import net.minecraft.src.NBTTagCompound;
|
||||||
import buildcraft.BuildCraftTransport;
|
import buildcraft.BuildCraftTransport;
|
||||||
import buildcraft.api.core.Orientations;
|
import buildcraft.api.core.Orientations;
|
||||||
import buildcraft.api.core.Position;
|
import buildcraft.api.core.Position;
|
||||||
import buildcraft.api.transport.IPipedItem;
|
import buildcraft.api.transport.IPipedItem;
|
||||||
import buildcraft.core.DefaultProps;
|
import buildcraft.core.DefaultProps;
|
||||||
|
import buildcraft.core.network.IClientState;
|
||||||
import buildcraft.transport.IPipeTransportItemsHook;
|
import buildcraft.transport.IPipeTransportItemsHook;
|
||||||
import buildcraft.transport.Pipe;
|
import buildcraft.transport.Pipe;
|
||||||
import buildcraft.transport.PipeTransportItems;
|
import buildcraft.transport.PipeTransportItems;
|
||||||
|
|
||||||
import net.minecraft.src.Item;
|
public class PipeItemsDiamond extends Pipe implements IPipeTransportItemsHook, IClientState {
|
||||||
import net.minecraft.src.ItemStack;
|
|
||||||
|
|
||||||
public class PipeItemsDiamond extends Pipe implements IPipeTransportItemsHook {
|
|
||||||
|
|
||||||
public PipeItemsDiamond(int itemID) {
|
public PipeItemsDiamond(int itemID) {
|
||||||
super(new PipeTransportItems(), new PipeLogicDiamond(), itemID);
|
super(new PipeTransportItems(), new PipeLogicDiamond(), itemID);
|
||||||
|
@ -86,4 +93,20 @@ public class PipeItemsDiamond extends Pipe implements IPipeTransportItemsHook {
|
||||||
((PipeTransportItems) transport).defaultReajustSpeed(item);
|
((PipeTransportItems) transport).defaultReajustSpeed(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ICLIENTSTATE
|
||||||
|
@Override
|
||||||
|
public void writeData(DataOutputStream data) throws IOException {
|
||||||
|
NBTTagCompound nbt = new NBTTagCompound();
|
||||||
|
((PipeLogicDiamond) logic).writeToNBT(nbt);
|
||||||
|
NBTBase.writeNamedTag(nbt, data);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void readData(DataInputStream data) throws IOException {
|
||||||
|
NBTBase nbt = NBTBase.readNamedTag(data);
|
||||||
|
if (nbt instanceof NBTTagCompound) {
|
||||||
|
logic.readFromNBT((NBTTagCompound) nbt);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,7 +29,6 @@ import net.minecraft.src.NBTTagCompound;
|
||||||
public class PipeLogicDiamond extends PipeLogic implements ISpecialInventory {
|
public class PipeLogicDiamond extends PipeLogic implements ISpecialInventory {
|
||||||
|
|
||||||
private SimpleInventory filters = new SimpleInventory(54, "items", 1);
|
private SimpleInventory filters = new SimpleInventory(54, "items", 1);
|
||||||
private final SafeTimeTracker tracker = new SafeTimeTracker();
|
|
||||||
|
|
||||||
/* PIPE LOGIC */
|
/* PIPE LOGIC */
|
||||||
@Override
|
@Override
|
||||||
|
@ -50,14 +49,6 @@ public class PipeLogicDiamond extends PipeLogic implements ISpecialInventory {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* UPDATING */
|
|
||||||
@Override
|
|
||||||
public void updateEntity() {
|
|
||||||
if (tracker.markTimeIfDelay(worldObj, 20 * BuildCraftCore.updateFactor))
|
|
||||||
if (CoreProxy.proxy.isSimulating(container.worldObj))
|
|
||||||
sendFilterSet();
|
|
||||||
}
|
|
||||||
|
|
||||||
/* SAVING & LOADING */
|
/* SAVING & LOADING */
|
||||||
@Override
|
@Override
|
||||||
public void readFromNBT(NBTTagCompound nbttagcompound) {
|
public void readFromNBT(NBTTagCompound nbttagcompound) {
|
||||||
|
@ -96,8 +87,8 @@ public class PipeLogicDiamond extends PipeLogic implements ISpecialInventory {
|
||||||
public ItemStack decrStackSize(int i, int j) {
|
public ItemStack decrStackSize(int i, int j) {
|
||||||
ItemStack stack = filters.decrStackSize(i, j);
|
ItemStack stack = filters.decrStackSize(i, j);
|
||||||
|
|
||||||
if (CoreProxy.proxy.isSimulating(container.worldObj))
|
if (CoreProxy.proxy.isSimulating(worldObj))
|
||||||
sendFilterSet();
|
worldObj.markBlockNeedsUpdate(xCoord, yCoord, zCoord);
|
||||||
|
|
||||||
return stack;
|
return stack;
|
||||||
}
|
}
|
||||||
|
@ -106,22 +97,9 @@ public class PipeLogicDiamond extends PipeLogic implements ISpecialInventory {
|
||||||
public void setInventorySlotContents(int i, ItemStack itemstack) {
|
public void setInventorySlotContents(int i, ItemStack itemstack) {
|
||||||
|
|
||||||
filters.setInventorySlotContents(i, itemstack);
|
filters.setInventorySlotContents(i, itemstack);
|
||||||
if (CoreProxy.proxy.isSimulating(container.worldObj))
|
if (CoreProxy.proxy.isSimulating(worldObj))
|
||||||
sendFilterSet();
|
worldObj.markBlockNeedsUpdate(xCoord, yCoord, zCoord);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* SERVER SIDE */
|
|
||||||
public void sendFilterSet() {
|
|
||||||
NBTTagCompound nbttagcompound = new NBTTagCompound();
|
|
||||||
this.writeToNBT(nbttagcompound);
|
|
||||||
PacketNBT packet = new PacketNBT(PacketIds.DIAMOND_PIPE_CONTENTS, nbttagcompound, xCoord, yCoord, zCoord);
|
|
||||||
CoreProxy.proxy.sendToPlayers(packet.getPacket(), worldObj, xCoord, yCoord, zCoord, DefaultProps.NETWORK_UPDATE_RANGE);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* CLIENT SIDE */
|
|
||||||
public void handleFilterSet(PacketNBT packet) {
|
|
||||||
this.readFromNBT(packet.getTagCompound());
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue