parent
8fb3197276
commit
17e7cb9a11
2 changed files with 57 additions and 38 deletions
|
@ -47,8 +47,9 @@ public class TriggerParameter implements ITriggerParameter {
|
||||||
@Override
|
@Override
|
||||||
public void writeToNBT(NBTTagCompound compound) {
|
public void writeToNBT(NBTTagCompound compound) {
|
||||||
if (stack != null) {
|
if (stack != null) {
|
||||||
compound.setInteger("itemID", stack.itemID);
|
NBTTagCompound tagCompound = new NBTTagCompound();
|
||||||
compound.setInteger("itemDMG", stack.getItemDamage());
|
stack.writeToNBT(tagCompound);
|
||||||
|
compound.setCompoundTag("stack", tagCompound);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -59,11 +60,14 @@ public class TriggerParameter implements ITriggerParameter {
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void readFromNBT(NBTTagCompound compound) {
|
public void readFromNBT(NBTTagCompound compound) {
|
||||||
|
// Legacy code to prevent existing gates from losing their contents
|
||||||
int itemID = compound.getInteger("itemID");
|
int itemID = compound.getInteger("itemID");
|
||||||
|
|
||||||
if (itemID != 0) {
|
if (itemID != 0) {
|
||||||
stack = new ItemStack(itemID, 1, compound.getInteger("itemDMG"));
|
stack = new ItemStack(itemID, 1, compound.getInteger("itemDMG"));
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
stack = ItemStack.loadItemStackFromNBT(compound.getCompoundTag("stack"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -18,21 +18,28 @@ import buildcraft.core.network.PacketCoordinates;
|
||||||
import buildcraft.core.network.PacketIds;
|
import buildcraft.core.network.PacketIds;
|
||||||
import buildcraft.core.network.PacketPayload;
|
import buildcraft.core.network.PacketPayload;
|
||||||
import buildcraft.core.network.PacketPayloadArrays;
|
import buildcraft.core.network.PacketPayloadArrays;
|
||||||
|
import buildcraft.core.network.PacketPayloadStream;
|
||||||
import buildcraft.core.network.PacketUpdate;
|
import buildcraft.core.network.PacketUpdate;
|
||||||
import buildcraft.core.proxy.CoreProxy;
|
import buildcraft.core.proxy.CoreProxy;
|
||||||
import buildcraft.core.utils.BCLog;
|
import buildcraft.core.utils.BCLog;
|
||||||
import buildcraft.transport.Gate;
|
import buildcraft.transport.Gate;
|
||||||
import buildcraft.transport.Pipe;
|
import buildcraft.transport.Pipe;
|
||||||
|
|
||||||
|
import java.io.DataInputStream;
|
||||||
|
import java.io.DataOutputStream;
|
||||||
|
import java.io.IOException;
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.NavigableSet;
|
import java.util.NavigableSet;
|
||||||
import java.util.TreeSet;
|
import java.util.TreeSet;
|
||||||
|
|
||||||
import net.minecraft.block.Block;
|
import net.minecraft.block.Block;
|
||||||
import net.minecraft.entity.player.EntityPlayer;
|
import net.minecraft.entity.player.EntityPlayer;
|
||||||
import net.minecraft.inventory.ICrafting;
|
import net.minecraft.inventory.ICrafting;
|
||||||
import net.minecraft.inventory.IInventory;
|
import net.minecraft.inventory.IInventory;
|
||||||
import net.minecraft.inventory.Slot;
|
import net.minecraft.inventory.Slot;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
|
import net.minecraft.network.packet.Packet;
|
||||||
import net.minecraft.tileentity.TileEntity;
|
import net.minecraft.tileentity.TileEntity;
|
||||||
import net.minecraft.util.ResourceLocation;
|
import net.minecraft.util.ResourceLocation;
|
||||||
import net.minecraftforge.common.ForgeDirection;
|
import net.minecraftforge.common.ForgeDirection;
|
||||||
|
@ -159,45 +166,53 @@ public class ContainerGateInterface extends BuildCraftContainer {
|
||||||
* @param packet
|
* @param packet
|
||||||
*/
|
*/
|
||||||
public void setSelection(PacketUpdate packet, boolean notify) {
|
public void setSelection(PacketUpdate packet, boolean notify) {
|
||||||
PacketPayloadArrays payload = (PacketPayloadArrays) packet.payload;
|
try {
|
||||||
int position = payload.intPayload[0];
|
PacketPayloadStream payload = (PacketPayloadStream) packet.payload;
|
||||||
|
DataInputStream data = payload.stream;
|
||||||
setTrigger(position, ActionManager.triggers.get(payload.stringPayload[0]), notify);
|
|
||||||
setAction(position, ActionManager.actions.get(payload.stringPayload[1]), notify);
|
int position = data.readInt();
|
||||||
|
|
||||||
int itemID = payload.intPayload[1];
|
setTrigger(position, ActionManager.triggers.get(data.readUTF()), notify);
|
||||||
if (itemID <= 0) {
|
setAction(position, ActionManager.actions.get(data.readUTF()), notify);
|
||||||
setTriggerParameter(position, null, notify);
|
|
||||||
return;
|
ItemStack parameter = Packet.readItemStack(data);
|
||||||
|
if(parameter != null) {
|
||||||
|
ITriggerParameter param = new TriggerParameter();
|
||||||
|
param.set(parameter);
|
||||||
|
setTriggerParameter(position, param, notify);
|
||||||
|
} else {
|
||||||
|
setTriggerParameter(position, null, notify);
|
||||||
|
}
|
||||||
|
} catch(IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
ITriggerParameter param = new TriggerParameter();
|
|
||||||
param.set(new ItemStack(itemID, payload.intPayload[2], payload.intPayload[3]));
|
|
||||||
setTriggerParameter(position, param, notify);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private PacketPayload getSelectionPayload(final int position) {
|
||||||
|
PacketPayloadStream payload = new PacketPayloadStream(new PacketPayloadStream.StreamWriter() {
|
||||||
|
@Override
|
||||||
|
public void writeData(DataOutputStream data) throws IOException {
|
||||||
|
data.writeInt(position);
|
||||||
|
|
||||||
|
if (pipe.gate.triggers[position] != null) {
|
||||||
|
data.writeUTF(pipe.gate.triggers[position].getUniqueTag());
|
||||||
|
} else {
|
||||||
|
data.writeUTF("");
|
||||||
|
}
|
||||||
|
|
||||||
private PacketPayload getSelectionPayload(int position) {
|
if (pipe.gate.actions[position] != null) {
|
||||||
PacketPayloadArrays payload = new PacketPayloadArrays(4, 0, 2);
|
data.writeUTF(pipe.gate.actions[position].getUniqueTag());
|
||||||
|
} else {
|
||||||
|
data.writeUTF("");
|
||||||
|
}
|
||||||
|
|
||||||
payload.intPayload[0] = position;
|
if (pipe.gate.triggerParameters[position] != null && pipe.gate.triggerParameters[position].getItemStack() != null) {
|
||||||
|
Packet.writeItemStack(pipe.gate.triggerParameters[position].getItemStack().copy(), data);
|
||||||
if (pipe.gate.triggers[position] != null) {
|
} else {
|
||||||
payload.stringPayload[0] = pipe.gate.triggers[position].getUniqueTag();
|
Packet.writeItemStack(null, data);
|
||||||
} else {
|
}
|
||||||
payload.stringPayload[0] = "";
|
}
|
||||||
}
|
});
|
||||||
|
|
||||||
if (pipe.gate.actions[position] != null) {
|
|
||||||
payload.stringPayload[1] = pipe.gate.actions[position].getUniqueTag();
|
|
||||||
} else {
|
|
||||||
payload.stringPayload[1] = "";
|
|
||||||
}
|
|
||||||
|
|
||||||
if (pipe.gate.triggerParameters[position] != null && pipe.gate.triggerParameters[position].getItemStack() != null) {
|
|
||||||
payload.intPayload[1] = pipe.gate.triggerParameters[position].getItemStack().itemID;
|
|
||||||
payload.intPayload[2] = pipe.gate.triggerParameters[position].getItemStack().stackSize;
|
|
||||||
payload.intPayload[3] = pipe.gate.triggerParameters[position].getItemStack().getItemDamage();
|
|
||||||
}
|
|
||||||
|
|
||||||
return payload;
|
return payload;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue