mirror of
https://github.com/GTNewHorizons/ForestryMC.git
synced 2026-11-21 12:32:23 +00:00
#561 refactor networking
Use more DataStreams and less NBT Add packet for error states changing Reduce network use by Clockwork Engine
This commit is contained in:
1 parent
ce00a33593
commit
9fccfd1198
115 files changed
+1850
-1855
No files matched your search
@@ -10,6 +10,9 @@
|
||||
******************************************************************************/
|
||||
package forestry.apiculture.gadgets;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.Collection;
|
||||
import java.util.LinkedList;
|
||||
|
||||
@@ -31,7 +34,6 @@ import forestry.core.config.ForestryBlock;
|
||||
import forestry.core.gadgets.TileForestry;
|
||||
import forestry.core.inventory.FakeInventoryAdapter;
|
||||
import forestry.core.inventory.IInventoryAdapter;
|
||||
import forestry.core.network.PacketPayload;
|
||||
import forestry.core.proxy.Proxies;
|
||||
|
||||
import buildcraft.api.statements.ITriggerExternal;
|
||||
@@ -106,24 +108,23 @@ public abstract class TileAlveary extends TileForestry implements IAlvearyCompon
|
||||
}
|
||||
|
||||
@Override
|
||||
public PacketPayload getPacketPayload() {
|
||||
PacketPayload payload = new PacketPayload(0, 2);
|
||||
payload.shortPayload[0] = (short) (isMaster() ? 1 : 0);
|
||||
public void writeData(DataOutputStream data) throws IOException {
|
||||
super.writeData(data);
|
||||
data.writeBoolean(isMaster);
|
||||
|
||||
// so the client can know if it is part of an integrated structure
|
||||
payload.shortPayload[1] = (short) this.masterY;
|
||||
|
||||
return payload;
|
||||
data.writeShort(masterY);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fromPacketPayload(PacketPayload payload) {
|
||||
if (payload.shortPayload[0] > 0) {
|
||||
public void readData(DataInputStream data) throws IOException {
|
||||
super.readData(data);
|
||||
if (data.readBoolean()) {
|
||||
makeMaster();
|
||||
}
|
||||
|
||||
// so the client can know if it is part of an integrated structure
|
||||
this.masterY = payload.shortPayload[1];
|
||||
masterY = data.readShort();
|
||||
}
|
||||
|
||||
/* ITILESTRUCTURE */
|
||||
|
||||
@@ -10,12 +10,15 @@
|
||||
******************************************************************************/
|
||||
package forestry.apiculture.gadgets;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
import forestry.api.apiculture.IAlvearyComponent;
|
||||
import forestry.core.network.PacketPayload;
|
||||
import forestry.energy.EnergyManager;
|
||||
|
||||
import cofh.api.energy.IEnergyHandler;
|
||||
@@ -109,24 +112,23 @@ public abstract class TileAlvearyClimatiser extends TileAlveary implements IEner
|
||||
nbttagcompound.setInteger("Heating", workingTime);
|
||||
}
|
||||
|
||||
|
||||
/* NETWORK */
|
||||
@Override
|
||||
public void fromPacketPayload(PacketPayload payload) {
|
||||
short workingTime = payload.shortPayload[0];
|
||||
public void writeData(DataOutputStream data) throws IOException {
|
||||
super.writeData(data);
|
||||
data.writeShort(workingTime);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readData(DataInputStream data) throws IOException {
|
||||
super.readData(data);
|
||||
short workingTime = data.readShort();
|
||||
if (this.workingTime != workingTime) {
|
||||
this.workingTime = workingTime;
|
||||
worldObj.func_147479_m(xCoord, yCoord, zCoord);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public PacketPayload getPacketPayload() {
|
||||
PacketPayload payload = new PacketPayload(0, 1);
|
||||
payload.shortPayload[0] = (short) workingTime;
|
||||
return payload;
|
||||
}
|
||||
|
||||
/* IEnergyHandler */
|
||||
@Override
|
||||
public int receiveEnergy(ForgeDirection from, int maxReceive, boolean simulate) {
|
||||
|
||||
@@ -48,10 +48,9 @@ import forestry.core.inventory.IInventoryAdapter;
|
||||
import forestry.core.inventory.InvTools;
|
||||
import forestry.core.inventory.TileInventoryAdapter;
|
||||
import forestry.core.network.GuiId;
|
||||
import forestry.core.network.PacketIds;
|
||||
import forestry.core.network.PacketId;
|
||||
import forestry.core.network.PacketInventoryStack;
|
||||
import forestry.core.proxy.Proxies;
|
||||
import forestry.core.utils.Utils;
|
||||
|
||||
public class TileAlvearyPlain extends TileAlveary implements ISidedInventory, IBeeHousing, IClimatised, IHintSource {
|
||||
|
||||
@@ -59,7 +58,7 @@ public class TileAlvearyPlain extends TileAlveary implements ISidedInventory, IB
|
||||
public static final int SLOT_QUEEN = 0;
|
||||
public static final int SLOT_DRONE = 1;
|
||||
public static final int SLOT_PRODUCT_1 = 2;
|
||||
public static final int SLOT_PRODUCTION_COUNT = 7;
|
||||
public static final int SLOT_PRODUCT_COUNT = 7;
|
||||
public static final int BLOCK_META = 0;
|
||||
|
||||
// / MEMBERS
|
||||
@@ -444,7 +443,7 @@ public class TileAlvearyPlain extends TileAlveary implements ISidedInventory, IB
|
||||
return false;
|
||||
}
|
||||
|
||||
return InvTools.tryAddStack(inventory, product, SLOT_PRODUCT_1, inventory.getSizeInventory() - SLOT_PRODUCT_1, all);
|
||||
return InvTools.tryAddStack(inventory, product, SLOT_PRODUCT_1, SLOT_PRODUCT_COUNT, all);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
@@ -469,8 +468,8 @@ public class TileAlvearyPlain extends TileAlveary implements ISidedInventory, IB
|
||||
return;
|
||||
}
|
||||
|
||||
Proxies.net.sendNetworkPacket(new PacketInventoryStack(PacketIds.IINVENTORY_STACK, xCoord, yCoord, zCoord, SLOT_QUEEN, queenStack), xCoord, yCoord,
|
||||
zCoord);
|
||||
PacketInventoryStack packet = new PacketInventoryStack(PacketId.IINVENTORY_STACK, xCoord, yCoord, zCoord, SLOT_QUEEN, queenStack);
|
||||
Proxies.net.sendNetworkPacket(packet);
|
||||
|
||||
for (IBeeListener eventHandler : eventHandlers) {
|
||||
eventHandler.onQueenChange(queenStack);
|
||||
@@ -654,16 +653,10 @@ public class TileAlvearyPlain extends TileAlveary implements ISidedInventory, IB
|
||||
return Config.hints.get("alveary");
|
||||
}
|
||||
|
||||
/* IOWNABLE */
|
||||
@Override
|
||||
public boolean isOwnable() {
|
||||
return true;
|
||||
}
|
||||
|
||||
/* IHousing */
|
||||
@Override
|
||||
public GameProfile getOwnerName() {
|
||||
return this.getOwnerProfile();
|
||||
return this.getOwner();
|
||||
}
|
||||
|
||||
private static class AlvearyInventoryAdapter extends TileInventoryAdapter<TileAlvearyPlain> {
|
||||
|
||||
@@ -10,6 +10,9 @@
|
||||
******************************************************************************/
|
||||
package forestry.apiculture.gadgets;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Stack;
|
||||
|
||||
@@ -32,7 +35,6 @@ import forestry.core.inventory.TileInventoryAdapter;
|
||||
import forestry.core.inventory.wrappers.IInvSlot;
|
||||
import forestry.core.inventory.wrappers.InventoryIterator;
|
||||
import forestry.core.network.GuiId;
|
||||
import forestry.core.network.PacketPayload;
|
||||
import forestry.core.utils.StackUtils;
|
||||
|
||||
public class TileAlvearySwarmer extends TileAlveary implements ISidedInventory {
|
||||
@@ -41,7 +43,7 @@ public class TileAlvearySwarmer extends TileAlveary implements ISidedInventory {
|
||||
public static final int BLOCK_META = 2;
|
||||
|
||||
private final Stack<ItemStack> pendingSpawns = new Stack<ItemStack>();
|
||||
private boolean isActive;
|
||||
private boolean active;
|
||||
|
||||
public TileAlvearySwarmer() {
|
||||
super(BLOCK_META);
|
||||
@@ -144,27 +146,28 @@ public class TileAlvearySwarmer extends TileAlveary implements ISidedInventory {
|
||||
}
|
||||
|
||||
private void setIsActive(boolean isActive) {
|
||||
if (this.isActive != isActive) {
|
||||
this.isActive = isActive;
|
||||
if (this.active != isActive) {
|
||||
this.active = isActive;
|
||||
setNeedsNetworkUpdate();
|
||||
}
|
||||
}
|
||||
|
||||
/* NETWORK */
|
||||
|
||||
@Override
|
||||
public void fromPacketPayload(PacketPayload payload) {
|
||||
boolean act = payload.shortPayload[0] > 0;
|
||||
if (this.isActive != act) {
|
||||
this.isActive = act;
|
||||
worldObj.func_147479_m(xCoord, yCoord, zCoord);
|
||||
}
|
||||
public void writeData(DataOutputStream data) throws IOException {
|
||||
super.writeData(data);
|
||||
data.writeBoolean(active);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PacketPayload getPacketPayload() {
|
||||
PacketPayload payload = new PacketPayload(0, 1);
|
||||
payload.shortPayload[0] = (short) (isActive ? 1 : 0);
|
||||
return payload;
|
||||
public void readData(DataInputStream data) throws IOException {
|
||||
super.readData(data);
|
||||
boolean active = data.readBoolean();
|
||||
if (this.active != active) {
|
||||
this.active = active;
|
||||
worldObj.func_147479_m(xCoord, yCoord, zCoord);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -179,7 +182,7 @@ public class TileAlvearySwarmer extends TileAlveary implements ISidedInventory {
|
||||
return BlockAlveary.BOTTOM;
|
||||
}
|
||||
|
||||
if (isActive) {
|
||||
if (active) {
|
||||
return BlockAlveary.ALVEARY_SWARMER_ON;
|
||||
} else {
|
||||
return BlockAlveary.ALVEARY_SWARMER_OFF;
|
||||
|
||||
@@ -37,18 +37,16 @@ import forestry.core.EnumErrorCode;
|
||||
import forestry.core.config.Config;
|
||||
import forestry.core.config.ForestryItem;
|
||||
import forestry.core.gadgets.TileBase;
|
||||
import forestry.core.gadgets.TileForestry;
|
||||
import forestry.core.interfaces.IClimatised;
|
||||
import forestry.core.inventory.IInventoryAdapter;
|
||||
import forestry.core.inventory.InvTools;
|
||||
import forestry.core.inventory.TileInventoryAdapter;
|
||||
import forestry.core.network.GuiId;
|
||||
import forestry.core.network.PacketIds;
|
||||
import forestry.core.network.PacketId;
|
||||
import forestry.core.network.PacketInventoryStack;
|
||||
import forestry.core.network.PacketTileUpdate;
|
||||
import forestry.core.network.PacketTileStream;
|
||||
import forestry.core.proxy.Proxies;
|
||||
import forestry.core.utils.GuiUtil;
|
||||
import forestry.core.utils.Utils;
|
||||
|
||||
public class TileBeehouse extends TileBase implements IBeeHousing, IClimatised {
|
||||
// CONSTANTS
|
||||
@@ -200,9 +198,8 @@ public class TileBeehouse extends TileBase implements IBeeHousing, IClimatised {
|
||||
return;
|
||||
}
|
||||
|
||||
Proxies.net.sendNetworkPacket(new PacketInventoryStack(PacketIds.IINVENTORY_STACK, xCoord, yCoord, zCoord, SLOT_QUEEN, queenStack), xCoord, yCoord,
|
||||
zCoord);
|
||||
Proxies.net.sendNetworkPacket(new PacketTileUpdate(this), xCoord, yCoord, zCoord);
|
||||
Proxies.net.sendNetworkPacket(new PacketInventoryStack(PacketId.IINVENTORY_STACK, xCoord, yCoord, zCoord, SLOT_QUEEN, queenStack));
|
||||
Proxies.net.sendNetworkPacket(new PacketTileStream(this));
|
||||
}
|
||||
|
||||
/* STATE INFORMATION */
|
||||
@@ -409,7 +406,7 @@ public class TileBeehouse extends TileBase implements IBeeHousing, IClimatised {
|
||||
/* IHousing */
|
||||
@Override
|
||||
public GameProfile getOwnerName() {
|
||||
return this.getOwnerProfile();
|
||||
return this.getOwner();
|
||||
}
|
||||
|
||||
protected static class BeehouseInventoryAdapter extends TileInventoryAdapter<TileBeehouse> {
|
||||
|
||||
@@ -20,9 +20,9 @@ import forestry.core.gui.ContainerItemInventory;
|
||||
import forestry.core.gui.IGuiSelectable;
|
||||
import forestry.core.gui.slots.SlotFiltered;
|
||||
import forestry.core.gui.slots.SlotOutput;
|
||||
import forestry.core.network.PacketIds;
|
||||
import forestry.core.network.PacketPayload;
|
||||
import forestry.core.network.PacketUpdate;
|
||||
import forestry.core.network.ForestryPacket;
|
||||
import forestry.core.network.PacketGuiSelect;
|
||||
import forestry.core.network.PacketId;
|
||||
import forestry.core.proxy.Proxies;
|
||||
|
||||
public class ContainerImprinter extends ContainerItemInventory<ImprinterInventory> implements IGuiSelectable {
|
||||
@@ -57,50 +57,36 @@ public class ContainerImprinter extends ContainerItemInventory<ImprinterInventor
|
||||
}
|
||||
}
|
||||
|
||||
public void advanceSelection(int index, World world) {
|
||||
PacketPayload payload = new PacketPayload(2, 0, 0);
|
||||
payload.intPayload[0] = index;
|
||||
payload.intPayload[1] = 0;
|
||||
sendSelectionChange(payload);
|
||||
public void advanceSelection(int index) {
|
||||
sendSelectionChange(index, 0);
|
||||
}
|
||||
|
||||
public void regressSelection(int index, World world) {
|
||||
PacketPayload payload = new PacketPayload(2, 0, 0);
|
||||
payload.intPayload[0] = index;
|
||||
payload.intPayload[1] = 1;
|
||||
sendSelectionChange(payload);
|
||||
}
|
||||
|
||||
private void sendSelectionChange(PacketPayload payload) {
|
||||
PacketUpdate packet = new PacketUpdate(PacketIds.GUI_SELECTION_CHANGE, payload);
|
||||
Proxies.net.sendToServer(packet);
|
||||
isNetSynced = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSelection(PacketUpdate packet) {
|
||||
inventory.setPrimaryIndex(packet.payload.intPayload[0]);
|
||||
inventory.setSecondaryIndex(packet.payload.intPayload[1]);
|
||||
public void regressSelection(int index) {
|
||||
sendSelectionChange(index, 1);
|
||||
}
|
||||
|
||||
public void updateContainer(World world) {
|
||||
if (!isNetSynced && !Proxies.common.isSimulating(world)) {
|
||||
isNetSynced = true;
|
||||
Proxies.net.sendToServer(new PacketUpdate(PacketIds.IMPRINT_SELECTION_GET));
|
||||
Proxies.net.sendToServer(new ForestryPacket(PacketId.IMPRINT_SELECTION_GET));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleSelectionChange(EntityPlayer player, PacketUpdate packet) {
|
||||
private void sendSelectionChange(int index, int advance) {
|
||||
ForestryPacket packet = new PacketGuiSelect(PacketId.GUI_SELECTION_CHANGE, index, advance);
|
||||
Proxies.net.sendToServer(packet);
|
||||
isNetSynced = false;
|
||||
}
|
||||
|
||||
if (packet.payload.intPayload[1] == 0) {
|
||||
if (packet.payload.intPayload[0] == 0) {
|
||||
@Override
|
||||
public void handleSelectionChange(EntityPlayer player, PacketGuiSelect packet) {
|
||||
if (packet.getSecondaryIndex() == 0) {
|
||||
if (packet.getPrimaryIndex() == 0) {
|
||||
inventory.advancePrimary();
|
||||
} else {
|
||||
inventory.advanceSecondary();
|
||||
}
|
||||
|
||||
} else if (packet.payload.intPayload[0] == 0) {
|
||||
} else if (packet.getPrimaryIndex() == 0) {
|
||||
inventory.regressPrimary();
|
||||
} else {
|
||||
inventory.regressSecondary();
|
||||
@@ -108,9 +94,13 @@ public class ContainerImprinter extends ContainerItemInventory<ImprinterInventor
|
||||
}
|
||||
|
||||
public void sendSelection(EntityPlayer player) {
|
||||
PacketPayload payload = new PacketPayload(2, 0, 0);
|
||||
payload.intPayload[0] = inventory.getPrimaryIndex();
|
||||
payload.intPayload[1] = inventory.getSecondaryIndex();
|
||||
Proxies.net.sendToPlayer(new PacketUpdate(PacketIds.GUI_SELECTION, payload), player);
|
||||
ForestryPacket packet = new PacketGuiSelect(PacketId.GUI_SELECTION_SET, inventory.getPrimaryIndex(), inventory.getSecondaryIndex());
|
||||
Proxies.net.sendToPlayer(packet, player);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSelection(PacketGuiSelect packetPayload) {
|
||||
inventory.setPrimaryIndex(packetPayload.getPrimaryIndex());
|
||||
inventory.setSecondaryIndex(packetPayload.getSecondaryIndex());
|
||||
}
|
||||
}
|
||||
@@ -106,9 +106,9 @@ public class GuiImprinter extends GuiForestry<ContainerImprinter, ImprinterInven
|
||||
}
|
||||
|
||||
if (k == 0) {
|
||||
container.advanceSelection(slot, Proxies.common.getRenderWorld());
|
||||
container.advanceSelection(slot);
|
||||
} else {
|
||||
container.regressSelection(slot, Proxies.common.getRenderWorld());
|
||||
container.regressSelection(slot);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -18,30 +18,28 @@ import net.minecraft.tileentity.TileEntity;
|
||||
|
||||
import forestry.apiculture.gadgets.TileCandle;
|
||||
import forestry.apiculture.gui.ContainerImprinter;
|
||||
import forestry.core.interfaces.IPacketHandler;
|
||||
import forestry.core.network.IPacketHandler;
|
||||
import forestry.core.network.PacketCoordinates;
|
||||
import forestry.core.network.PacketIds;
|
||||
import forestry.core.network.PacketId;
|
||||
import forestry.core.proxy.Proxies;
|
||||
|
||||
public class PacketHandlerApiculture implements IPacketHandler {
|
||||
|
||||
@Override
|
||||
public boolean onPacketData(int packetID, DataInputStream data, EntityPlayer player) throws IOException {
|
||||
public boolean onPacketData(PacketId packetID, DataInputStream data, EntityPlayer player) throws IOException {
|
||||
|
||||
switch (packetID) {
|
||||
case PacketIds.HABITAT_BIOME_POINTER: {
|
||||
PacketCoordinates packetC = new PacketCoordinates();
|
||||
packetC.readData(data);
|
||||
Proxies.common.setHabitatLocatorCoordinates(player, packetC.getCoordinates());
|
||||
case HABITAT_BIOME_POINTER: {
|
||||
PacketCoordinates packet = new PacketCoordinates(data);
|
||||
Proxies.common.setHabitatLocatorCoordinates(player, packet.getCoordinates());
|
||||
return true;
|
||||
}
|
||||
case PacketIds.IMPRINT_SELECTION_GET: {
|
||||
case IMPRINT_SELECTION_GET: {
|
||||
onImprintSelectionGet(player);
|
||||
return true;
|
||||
}
|
||||
case PacketIds.CANDLE: {
|
||||
PacketUpdateCandle updateCandle = new PacketUpdateCandle();
|
||||
updateCandle.readData(data);
|
||||
case CANDLE: {
|
||||
PacketUpdateCandle updateCandle = new PacketUpdateCandle(data);
|
||||
onCandleUpdate(updateCandle);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -6,19 +6,19 @@ import java.io.IOException;
|
||||
|
||||
import forestry.apiculture.gadgets.TileCandle;
|
||||
import forestry.core.network.PacketCoordinates;
|
||||
import forestry.core.network.PacketIds;
|
||||
import forestry.core.network.PacketId;
|
||||
|
||||
public class PacketUpdateCandle extends PacketCoordinates {
|
||||
|
||||
private int colour;
|
||||
private boolean lit;
|
||||
|
||||
public PacketUpdateCandle() {
|
||||
|
||||
public PacketUpdateCandle(DataInputStream data) throws IOException {
|
||||
super(data);
|
||||
}
|
||||
|
||||
public PacketUpdateCandle(TileCandle tileCandle) {
|
||||
super(PacketIds.CANDLE, tileCandle);
|
||||
super(PacketId.CANDLE, tileCandle);
|
||||
|
||||
colour = tileCandle.getColour();
|
||||
lit = tileCandle.isLit();
|
||||
|
||||
@@ -17,35 +17,19 @@ import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
|
||||
import forestry.arboriculture.gadgets.TileLeaves;
|
||||
import forestry.arboriculture.gadgets.TileSapling;
|
||||
import forestry.arboriculture.network.PacketLeaf;
|
||||
import forestry.arboriculture.network.PacketRipeningUpdate;
|
||||
import forestry.arboriculture.network.PacketSapling;
|
||||
import forestry.core.interfaces.IPacketHandler;
|
||||
import forestry.core.network.PacketIds;
|
||||
import forestry.core.network.IPacketHandler;
|
||||
import forestry.core.network.PacketId;
|
||||
import forestry.core.proxy.Proxies;
|
||||
|
||||
public class PacketHandlerArboriculture implements IPacketHandler {
|
||||
|
||||
@Override
|
||||
public boolean onPacketData(int packetID, DataInputStream data, EntityPlayer player) throws IOException {
|
||||
public boolean onPacketData(PacketId packetID, DataInputStream data, EntityPlayer player) throws IOException {
|
||||
|
||||
switch (packetID) {
|
||||
case PacketIds.SAPLING: {
|
||||
PacketSapling packet = new PacketSapling();
|
||||
packet.readData(data);
|
||||
onSaplingPacket(packet);
|
||||
return true;
|
||||
}
|
||||
case PacketIds.LEAF: {
|
||||
PacketLeaf packet = new PacketLeaf();
|
||||
packet.readData(data);
|
||||
onLeafPacket(packet);
|
||||
return true;
|
||||
}
|
||||
case PacketIds.RIPENING_UPDATE: {
|
||||
PacketRipeningUpdate packet = new PacketRipeningUpdate();
|
||||
packet.readData(data);
|
||||
case RIPENING_UPDATE: {
|
||||
PacketRipeningUpdate packet = new PacketRipeningUpdate(data);
|
||||
onRipeningUpdate(packet);
|
||||
return true;
|
||||
}
|
||||
@@ -54,29 +38,10 @@ public class PacketHandlerArboriculture implements IPacketHandler {
|
||||
return false;
|
||||
}
|
||||
|
||||
private void onSaplingPacket(PacketSapling packet) {
|
||||
TileEntity tile = packet.getTarget(Proxies.common.getRenderWorld());
|
||||
if (tile instanceof TileSapling) {
|
||||
((TileSapling) tile).fromPacket(packet);
|
||||
}
|
||||
}
|
||||
|
||||
private void onLeafPacket(PacketLeaf packet) {
|
||||
|
||||
TileEntity tile = packet.getTarget(Proxies.common.getRenderWorld());
|
||||
if (tile instanceof TileLeaves) {
|
||||
((TileLeaves) tile).fromPacket(packet);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void onRipeningUpdate(PacketRipeningUpdate packet) {
|
||||
|
||||
private static void onRipeningUpdate(PacketRipeningUpdate packet) {
|
||||
TileEntity tile = packet.getTarget(Proxies.common.getRenderWorld());
|
||||
if (tile instanceof TileLeaves) {
|
||||
((TileLeaves) tile).fromRipeningPacket(packet);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -79,7 +79,7 @@ public class BlockArbStairs extends BlockStairs {
|
||||
|
||||
ItemStack stack = new ItemStack(this, 1, 0);
|
||||
NBTTagCompound compound = new NBTTagCompound();
|
||||
stairs.getType().saveToCompound(compound);
|
||||
stairs.getWoodType().saveToCompound(compound);
|
||||
stack.setTagCompound(compound);
|
||||
StackUtils.dropItemStackAsEntity(stack, world, x, y, z);
|
||||
}
|
||||
@@ -122,11 +122,11 @@ public class BlockArbStairs extends BlockStairs {
|
||||
TileStairs stairs = getStairTile(world, x, y, z);
|
||||
|
||||
NBTTagCompound nbttagcompound = new NBTTagCompound();
|
||||
if (stairs == null || stairs.getType() == null) {
|
||||
if (stairs == null || stairs.getWoodType() == null) {
|
||||
return nbttagcompound;
|
||||
}
|
||||
|
||||
stairs.getType().saveToCompound(nbttagcompound);
|
||||
stairs.getWoodType().saveToCompound(nbttagcompound);
|
||||
return nbttagcompound;
|
||||
}
|
||||
|
||||
@@ -141,8 +141,8 @@ public class BlockArbStairs extends BlockStairs {
|
||||
@Override
|
||||
public IIcon getIcon(IBlockAccess world, int x, int y, int z, int side) {
|
||||
TileStairs stairs = getStairTile(world, x, y, z);
|
||||
if (stairs != null && stairs.getType() != null) {
|
||||
return stairs.getType().getPlankIcon();
|
||||
if (stairs != null && stairs.getWoodType() != null) {
|
||||
return stairs.getWoodType().getPlankIcon();
|
||||
} else {
|
||||
return WoodType.LARCH.getPlankIcon();
|
||||
}
|
||||
|
||||
@@ -10,6 +10,9 @@
|
||||
******************************************************************************/
|
||||
package forestry.arboriculture.gadgets;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
@@ -28,15 +31,13 @@ import forestry.api.genetics.AlleleManager;
|
||||
import forestry.api.genetics.IAllele;
|
||||
import forestry.api.genetics.IFruitBearer;
|
||||
import forestry.api.genetics.IFruitFamily;
|
||||
import forestry.core.network.ForestryPacket;
|
||||
import forestry.core.network.INetworkedEntity;
|
||||
import forestry.core.network.PacketIds;
|
||||
import forestry.core.network.PacketPayload;
|
||||
import forestry.core.network.PacketUpdate;
|
||||
import forestry.arboriculture.network.PacketRipeningUpdate;
|
||||
import forestry.core.network.IStreamable;
|
||||
import forestry.core.network.PacketTileStream;
|
||||
import forestry.core.proxy.Proxies;
|
||||
import forestry.core.render.TextureManager;
|
||||
|
||||
public class TileFruitPod extends TileEntity implements INetworkedEntity, IFruitBearer {
|
||||
public class TileFruitPod extends TileEntity implements IFruitBearer, IStreamable {
|
||||
|
||||
private static final short MAX_MATURITY = 2;
|
||||
|
||||
@@ -130,37 +131,11 @@ public class TileFruitPod extends TileEntity implements INetworkedEntity, IFruit
|
||||
/* NETWORK */
|
||||
@Override
|
||||
public Packet getDescriptionPacket() {
|
||||
return toPacket().getPacket();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendNetworkUpdate() {
|
||||
Proxies.net.sendNetworkPacket(toPacket(), xCoord, yCoord, zCoord);
|
||||
return new PacketTileStream(this).getPacket();
|
||||
}
|
||||
|
||||
private void sendNetworkUpdateRipening() {
|
||||
Proxies.net.sendNetworkPacket(new PacketUpdate(PacketIds.TILE_UPDATE, xCoord, yCoord, zCoord, maturity), xCoord, yCoord, zCoord);
|
||||
}
|
||||
|
||||
private ForestryPacket toPacket() {
|
||||
|
||||
PacketPayload payload = new PacketPayload(indices.length, 1);
|
||||
payload.shortPayload[0] = maturity;
|
||||
payload.intPayload = indices;
|
||||
|
||||
return new PacketUpdate(PacketIds.TILE_UPDATE, xCoord, yCoord, zCoord, payload);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fromPacket(ForestryPacket packetRaw) {
|
||||
PacketUpdate packet = (PacketUpdate) packetRaw;
|
||||
maturity = packet.payload.shortPayload[0];
|
||||
|
||||
if (packet.payload.intPayload != null && packet.payload.intPayload.length > 0) {
|
||||
indices = packet.payload.intPayload;
|
||||
}
|
||||
|
||||
worldObj.func_147479_m(xCoord, yCoord, zCoord);
|
||||
Proxies.net.sendNetworkPacket(new PacketRipeningUpdate(this));
|
||||
}
|
||||
|
||||
/* IFRUITBEARER */
|
||||
@@ -183,7 +158,6 @@ public class TileFruitPod extends TileEntity implements INetworkedEntity, IFruit
|
||||
return new ArrayList<ItemStack>();
|
||||
}
|
||||
|
||||
|
||||
Collection<ItemStack> fruits = Arrays.asList(getDrop());
|
||||
maturity = 0;
|
||||
sendNetworkUpdateRipening();
|
||||
@@ -201,4 +175,24 @@ public class TileFruitPod extends TileEntity implements INetworkedEntity, IFruit
|
||||
sendNetworkUpdateRipening();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeData(DataOutputStream data) throws IOException {
|
||||
data.writeShort(maturity);
|
||||
data.writeShort(indices.length);
|
||||
for (int i : indices) {
|
||||
data.writeInt(i);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readData(DataInputStream data) throws IOException {
|
||||
maturity = data.readShort();
|
||||
int indicesLength = data.readShort();
|
||||
indices = new int[indicesLength];
|
||||
for (int i = 0; i < indicesLength; i++) {
|
||||
indices[i] = data.readInt();
|
||||
}
|
||||
|
||||
worldObj.func_147479_m(xCoord, yCoord, zCoord);
|
||||
}
|
||||
}
|
||||
@@ -12,6 +12,9 @@ package forestry.arboriculture.gadgets;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
@@ -33,6 +36,7 @@ import net.minecraftforge.common.EnumPlantType;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
|
||||
import forestry.api.arboriculture.EnumTreeChromosome;
|
||||
import forestry.api.arboriculture.IAlleleTreeSpecies;
|
||||
import forestry.api.arboriculture.IFruitProvider;
|
||||
import forestry.api.arboriculture.ILeafTickHandler;
|
||||
@@ -43,6 +47,7 @@ import forestry.api.core.EnumHumidity;
|
||||
import forestry.api.core.EnumTemperature;
|
||||
import forestry.api.core.IErrorState;
|
||||
import forestry.api.genetics.AlleleManager;
|
||||
import forestry.api.genetics.IAllele;
|
||||
import forestry.api.genetics.IEffectData;
|
||||
import forestry.api.genetics.IFruitBearer;
|
||||
import forestry.api.genetics.IFruitFamily;
|
||||
@@ -52,11 +57,10 @@ import forestry.api.lepidopterology.IButterfly;
|
||||
import forestry.api.lepidopterology.IButterflyGenome;
|
||||
import forestry.api.lepidopterology.IButterflyNursery;
|
||||
import forestry.api.lepidopterology.IButterflyRoot;
|
||||
import forestry.arboriculture.network.PacketLeaf;
|
||||
import forestry.arboriculture.network.PacketRipeningUpdate;
|
||||
import forestry.core.EnumErrorCode;
|
||||
import forestry.core.genetics.alleles.Allele;
|
||||
import forestry.core.network.ForestryPacket;
|
||||
import forestry.core.network.PacketTileStream;
|
||||
import forestry.core.proxy.Proxies;
|
||||
import forestry.core.render.TextureManager;
|
||||
import forestry.core.utils.GeneticsUtil;
|
||||
@@ -330,13 +334,11 @@ public class TileLeaves extends TileTreeContainer implements IPollinatable, IFru
|
||||
/* NETWORK */
|
||||
@Override
|
||||
public Packet getDescriptionPacket() {
|
||||
return new PacketLeaf(this).getPacket();
|
||||
return new PacketTileStream(this).getPacket();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendNetworkUpdate() {
|
||||
PacketLeaf packet = new PacketLeaf(this);
|
||||
Proxies.net.sendNetworkPacket(packet, xCoord, yCoord, zCoord);
|
||||
Proxies.net.sendNetworkPacket(new PacketTileStream(this));
|
||||
}
|
||||
|
||||
private void sendNetworkUpdateRipening() {
|
||||
@@ -347,31 +349,76 @@ public class TileLeaves extends TileTreeContainer implements IPollinatable, IFru
|
||||
colourFruits = newColourFruits;
|
||||
|
||||
PacketRipeningUpdate ripeningUpdate = new PacketRipeningUpdate(this);
|
||||
Proxies.net.sendNetworkPacket(ripeningUpdate, xCoord, yCoord, zCoord);
|
||||
Proxies.net.sendNetworkPacket(ripeningUpdate);
|
||||
}
|
||||
|
||||
private static final short hasFruitFlag = 1;
|
||||
private static final short isPollinatedFlag = 1 << 1;
|
||||
|
||||
@Override
|
||||
public void writeData(DataOutputStream data) throws IOException {
|
||||
super.writeData(data);
|
||||
|
||||
byte leafState = 0;
|
||||
boolean hasFruit = hasFruit();
|
||||
|
||||
if (isPollinated()) {
|
||||
leafState |= isPollinatedFlag;
|
||||
}
|
||||
|
||||
if (hasFruit) {
|
||||
leafState |= hasFruitFlag;
|
||||
}
|
||||
|
||||
data.writeByte(leafState);
|
||||
|
||||
if (hasFruit) {
|
||||
String fruitAlleleUID = getTree().getGenome().getActiveAllele(EnumTreeChromosome.FRUITS).getUID();
|
||||
int colourFruits = getFruitColour();
|
||||
|
||||
data.writeUTF(fruitAlleleUID);
|
||||
data.writeInt(colourFruits);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fromPacket(ForestryPacket packetRaw) {
|
||||
PacketLeaf packet = (PacketLeaf) packetRaw;
|
||||
public void readData(DataInputStream data) throws IOException {
|
||||
|
||||
isFruitLeaf = packet.isFruitLeaf();
|
||||
isPollinatedState = packet.isPollinated();
|
||||
String speciesUID = data.readUTF(); // this is called instead of super.readData, be careful!
|
||||
|
||||
colourFruits = packet.getColourFruits();
|
||||
byte leafState = data.readByte();
|
||||
boolean hasFruit = (leafState & hasFruitFlag) > 0;
|
||||
boolean isPollinated = (leafState & isPollinatedFlag) > 0;
|
||||
String fruitAlleleUID = null;
|
||||
|
||||
ITree tree = getTree();
|
||||
if (!packet.matchesTree(tree)) {
|
||||
ITree newTree = packet.getTree();
|
||||
if (newTree != null) {
|
||||
setTree(newTree);
|
||||
if (hasFruit) {
|
||||
fruitAlleleUID = data.readUTF();
|
||||
colourFruits = data.readInt();
|
||||
}
|
||||
|
||||
IAllele[] treeTemplate = PluginArboriculture.treeInterface.getTemplate(speciesUID);
|
||||
|
||||
if (fruitAlleleUID != null) {
|
||||
IAllele fruitAllele = AlleleManager.alleleRegistry.getAllele(fruitAlleleUID);
|
||||
if (fruitAllele != null) {
|
||||
treeTemplate[EnumTreeChromosome.FRUITS.ordinal()] = fruitAllele;
|
||||
}
|
||||
}
|
||||
|
||||
worldObj.func_147479_m(xCoord, yCoord, zCoord);
|
||||
if (treeTemplate != null) {
|
||||
ITree tree = PluginArboriculture.treeInterface.templateAsIndividual(treeTemplate);
|
||||
if (isPollinated) {
|
||||
tree.mate(tree);
|
||||
}
|
||||
|
||||
setTree(tree);
|
||||
|
||||
worldObj.func_147479_m(xCoord, yCoord, zCoord);
|
||||
}
|
||||
}
|
||||
|
||||
public void fromRipeningPacket(PacketRipeningUpdate packet) {
|
||||
int newColourFruits = packet.getColourFruits();
|
||||
int newColourFruits = packet.getValue();
|
||||
if (newColourFruits == colourFruits) {
|
||||
return;
|
||||
}
|
||||
@@ -465,7 +512,7 @@ public class TileLeaves extends TileTreeContainer implements IPollinatable, IFru
|
||||
}
|
||||
}
|
||||
|
||||
private void attemptButterflySpawn(World world, IButterfly butterfly, double x, double y, double z) {
|
||||
private static void attemptButterflySpawn(World world, IButterfly butterfly, double x, double y, double z) {
|
||||
IButterflyRoot butterflyRoot = (IButterflyRoot) AlleleManager.alleleRegistry.getSpeciesRoot("rootButterflies");
|
||||
if (butterflyRoot.spawnButterflyInWorld(world, butterfly.copy(), x, y + 0.1f, z) != null) {
|
||||
Proxies.log.finest("A caterpillar '%s' hatched at %s/%s/%s.", butterfly.getDisplayName(), x, y, z);
|
||||
@@ -560,6 +607,6 @@ public class TileLeaves extends TileTreeContainer implements IPollinatable, IFru
|
||||
/* IHousing */
|
||||
@Override
|
||||
public GameProfile getOwnerName() {
|
||||
return this.getOwnerProfile();
|
||||
return this.getOwner();
|
||||
}
|
||||
}
|
||||
@@ -14,10 +14,7 @@ import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.network.Packet;
|
||||
import net.minecraft.world.gen.feature.WorldGenerator;
|
||||
|
||||
import forestry.api.arboriculture.ITree;
|
||||
import forestry.arboriculture.network.PacketSapling;
|
||||
import forestry.core.network.ForestryPacket;
|
||||
import forestry.core.proxy.Proxies;
|
||||
import forestry.core.network.PacketTileStream;
|
||||
import forestry.plugins.PluginArboriculture;
|
||||
|
||||
public class TileSapling extends TileTreeContainer {
|
||||
@@ -67,7 +64,7 @@ public class TileSapling extends TileTreeContainer {
|
||||
|
||||
WorldGenerator generator = this.getTree().getTreeGenerator(worldObj, xCoord, yCoord, zCoord, bonemealed);
|
||||
if (generator.generate(worldObj, worldObj.rand, xCoord, yCoord, zCoord)) {
|
||||
PluginArboriculture.treeInterface.getBreedingTracker(worldObj, getOwnerProfile()).registerBirth(getTree());
|
||||
PluginArboriculture.treeInterface.getBreedingTracker(worldObj, getOwner()).registerBirth(getTree());
|
||||
return 2;
|
||||
}
|
||||
|
||||
@@ -76,31 +73,6 @@ public class TileSapling extends TileTreeContainer {
|
||||
|
||||
@Override
|
||||
public Packet getDescriptionPacket() {
|
||||
return new PacketSapling(this).getPacket();
|
||||
return new PacketTileStream(this).getPacket();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendNetworkUpdate() {
|
||||
PacketSapling saplingPacket = new PacketSapling(this);
|
||||
Proxies.net.sendNetworkPacket(saplingPacket, xCoord, yCoord, zCoord);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fromPacket(ForestryPacket packetRaw) {
|
||||
PacketSapling packet = (PacketSapling) packetRaw;
|
||||
|
||||
ITree tree = getTree();
|
||||
if (packet.matchesTree(tree)) {
|
||||
return;
|
||||
}
|
||||
|
||||
ITree newTree = packet.getTree();
|
||||
if (newTree == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
setTree(newTree);
|
||||
worldObj.func_147479_m(xCoord, yCoord, zCoord);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -10,27 +10,29 @@
|
||||
******************************************************************************/
|
||||
package forestry.arboriculture.gadgets;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.network.Packet;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
|
||||
import forestry.arboriculture.WoodType;
|
||||
import forestry.core.network.ForestryPacket;
|
||||
import forestry.core.network.INetworkedEntity;
|
||||
import forestry.core.network.PacketIds;
|
||||
import forestry.core.network.PacketTileNBT;
|
||||
import forestry.core.network.IStreamable;
|
||||
import forestry.core.network.PacketTileStream;
|
||||
import forestry.core.proxy.Proxies;
|
||||
|
||||
public class TileStairs extends TileEntity implements INetworkedEntity {
|
||||
public class TileStairs extends TileEntity implements IStreamable {
|
||||
|
||||
private WoodType type;
|
||||
private WoodType woodType;
|
||||
|
||||
public WoodType getType() {
|
||||
return this.type;
|
||||
public WoodType getWoodType() {
|
||||
return this.woodType;
|
||||
}
|
||||
|
||||
public void setType(WoodType type) {
|
||||
this.type = type;
|
||||
public void setWoodType(WoodType woodType) {
|
||||
this.woodType = woodType;
|
||||
sendNetworkUpdate();
|
||||
}
|
||||
|
||||
@@ -40,7 +42,7 @@ public class TileStairs extends TileEntity implements INetworkedEntity {
|
||||
super.readFromNBT(nbttagcompound);
|
||||
|
||||
if (nbttagcompound.hasKey("WT")) {
|
||||
type = WoodType.VALUES[nbttagcompound.getShort("WT")];
|
||||
woodType = WoodType.VALUES[nbttagcompound.getShort("WT")];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -48,8 +50,8 @@ public class TileStairs extends TileEntity implements INetworkedEntity {
|
||||
public void writeToNBT(NBTTagCompound nbttagcompound) {
|
||||
super.writeToNBT(nbttagcompound);
|
||||
|
||||
if (type != null) {
|
||||
nbttagcompound.setShort("WT", (short) type.ordinal());
|
||||
if (woodType != null) {
|
||||
nbttagcompound.setShort("WT", (short) woodType.ordinal());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -66,19 +68,22 @@ public class TileStairs extends TileEntity implements INetworkedEntity {
|
||||
/* INETWORKEDENTITY */
|
||||
@Override
|
||||
public Packet getDescriptionPacket() {
|
||||
return new PacketTileNBT(PacketIds.TILE_NBT, this).getPacket();
|
||||
return new PacketTileStream(this).getPacket();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendNetworkUpdate() {
|
||||
Proxies.net.sendNetworkPacket(new PacketTileNBT(PacketIds.TILE_NBT, this), xCoord, yCoord, zCoord);
|
||||
Proxies.net.sendNetworkPacket(new PacketTileStream(this));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fromPacket(ForestryPacket packetRaw) {
|
||||
PacketTileNBT packet = (PacketTileNBT) packetRaw;
|
||||
this.readFromNBT(packet.getTagCompound());
|
||||
public void writeData(DataOutputStream data) throws IOException {
|
||||
data.writeShort(woodType.ordinal());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readData(DataInputStream data) throws IOException {
|
||||
short woodTypeOrdinal = data.readShort();
|
||||
woodType = WoodType.values()[woodTypeOrdinal];
|
||||
worldObj.func_147479_m(xCoord, yCoord, zCoord);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -10,6 +10,10 @@
|
||||
******************************************************************************/
|
||||
package forestry.arboriculture.gadgets;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTUtil;
|
||||
@@ -19,17 +23,19 @@ import net.minecraft.tileentity.TileEntity;
|
||||
import com.mojang.authlib.GameProfile;
|
||||
|
||||
import forestry.api.arboriculture.ITree;
|
||||
import forestry.api.genetics.IAllele;
|
||||
import forestry.arboriculture.genetics.Tree;
|
||||
import forestry.core.interfaces.IOwnable;
|
||||
import forestry.core.network.INetworkedEntity;
|
||||
import forestry.core.network.IStreamable;
|
||||
import forestry.core.utils.PlayerUtil;
|
||||
import forestry.plugins.PluginArboriculture;
|
||||
|
||||
/**
|
||||
* This is the base TE class for any block that needs to contain tree genome information.
|
||||
*
|
||||
* @author SirSengir
|
||||
*/
|
||||
public abstract class TileTreeContainer extends TileEntity implements INetworkedEntity, IOwnable {
|
||||
public abstract class TileTreeContainer extends TileEntity implements IStreamable, IOwnable {
|
||||
|
||||
private ITree containedTree;
|
||||
|
||||
@@ -44,7 +50,6 @@ public abstract class TileTreeContainer extends TileEntity implements INetworked
|
||||
if (nbttagcompound.hasKey("owner")) {
|
||||
owner = NBTUtil.func_152459_a(nbttagcompound.getCompoundTag("owner"));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -61,7 +66,31 @@ public abstract class TileTreeContainer extends TileEntity implements INetworked
|
||||
NBTUtil.func_152460_a(nbt, owner);
|
||||
nbttagcompound.setTag("owner", nbt);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeData(DataOutputStream data) throws IOException {
|
||||
String speciesUID = "";
|
||||
ITree tree = getTree();
|
||||
if (tree != null) {
|
||||
speciesUID = tree.getIdent();
|
||||
}
|
||||
data.writeUTF(speciesUID);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readData(DataInputStream data) throws IOException {
|
||||
String speciesUID = data.readUTF();
|
||||
ITree tree = getTree(speciesUID);
|
||||
setTree(tree);
|
||||
}
|
||||
|
||||
public static ITree getTree(String speciesUID) {
|
||||
IAllele[] treeTemplate = PluginArboriculture.treeInterface.getTemplate(speciesUID);
|
||||
if (treeTemplate == null) {
|
||||
return null;
|
||||
}
|
||||
return PluginArboriculture.treeInterface.templateAsIndividual(treeTemplate);
|
||||
}
|
||||
|
||||
/* CLIENT INFORMATION */
|
||||
@@ -102,18 +131,13 @@ public abstract class TileTreeContainer extends TileEntity implements INetworked
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isOwnable() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isOwned() {
|
||||
return owner != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public GameProfile getOwnerProfile() {
|
||||
public GameProfile getOwner() {
|
||||
return owner;
|
||||
}
|
||||
|
||||
|
||||
@@ -60,7 +60,7 @@ public class ItemStairs extends ItemForestryBlock {
|
||||
return false;
|
||||
}
|
||||
|
||||
((TileStairs) tile).setType(type);
|
||||
((TileStairs) tile).setWoodType(type);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,105 +0,0 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2011-2014 SirSengir.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the GNU Lesser Public License v3
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.gnu.org/licenses/lgpl-3.0.txt
|
||||
*
|
||||
* Various Contributors including, but not limited to:
|
||||
* SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges
|
||||
******************************************************************************/
|
||||
package forestry.arboriculture.network;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
import forestry.api.arboriculture.EnumTreeChromosome;
|
||||
import forestry.api.arboriculture.ITree;
|
||||
import forestry.api.genetics.AlleleManager;
|
||||
import forestry.api.genetics.IAllele;
|
||||
import forestry.arboriculture.gadgets.TileLeaves;
|
||||
import forestry.core.network.PacketIds;
|
||||
import forestry.plugins.PluginArboriculture;
|
||||
|
||||
public class PacketLeaf extends PacketTreeContainer {
|
||||
|
||||
private static final short hasFruitFlag = 1;
|
||||
private static final short isPollinatedFlag = 1 << 1;
|
||||
|
||||
private byte leafState = 0;
|
||||
private int colourFruits = -1;
|
||||
private String fruitAlleleUID;
|
||||
|
||||
public PacketLeaf() {
|
||||
|
||||
}
|
||||
|
||||
public PacketLeaf(TileLeaves leaves) {
|
||||
super(PacketIds.LEAF, leaves);
|
||||
|
||||
if (leaves.hasFruit()) {
|
||||
leafState |= hasFruitFlag;
|
||||
fruitAlleleUID = leaves.getTree().getGenome().getActiveAllele(EnumTreeChromosome.FRUITS).getUID();
|
||||
colourFruits = leaves.getFruitColour();
|
||||
}
|
||||
if (leaves.isPollinated()) {
|
||||
leafState |= isPollinatedFlag;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeData(DataOutputStream data) throws IOException {
|
||||
super.writeData(data);
|
||||
data.writeByte(leafState);
|
||||
|
||||
if (isFruitLeaf()) {
|
||||
data.writeUTF(fruitAlleleUID);
|
||||
data.writeInt(colourFruits);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readData(DataInputStream data) throws IOException {
|
||||
super.readData(data);
|
||||
leafState = data.readByte();
|
||||
|
||||
if (isFruitLeaf()) {
|
||||
fruitAlleleUID = data.readUTF();
|
||||
colourFruits = data.readInt();
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isFruitLeaf() {
|
||||
return (leafState & hasFruitFlag) > 0;
|
||||
}
|
||||
|
||||
public boolean isPollinated() {
|
||||
return (leafState & isPollinatedFlag) > 0;
|
||||
}
|
||||
|
||||
public int getColourFruits() {
|
||||
return colourFruits;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ITree getTree() {
|
||||
IAllele[] treeTemplate = PluginArboriculture.treeInterface.getTemplate(speciesUID);
|
||||
if (treeTemplate == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (fruitAlleleUID != null) {
|
||||
IAllele fruitAllele = AlleleManager.alleleRegistry.getAllele(fruitAlleleUID);
|
||||
if (fruitAllele != null) {
|
||||
treeTemplate[EnumTreeChromosome.FRUITS.ordinal()] = fruitAllele;
|
||||
}
|
||||
}
|
||||
|
||||
ITree tree = PluginArboriculture.treeInterface.templateAsIndividual(treeTemplate);
|
||||
if (isPollinated()) {
|
||||
tree.mate(tree);
|
||||
}
|
||||
return tree;
|
||||
}
|
||||
}
|
||||
@@ -14,54 +14,42 @@ import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import forestry.arboriculture.gadgets.TileFruitPod;
|
||||
import forestry.arboriculture.gadgets.TileLeaves;
|
||||
import forestry.core.network.ForestryPacket;
|
||||
import forestry.core.network.PacketIds;
|
||||
import forestry.core.network.PacketCoordinates;
|
||||
import forestry.core.network.PacketId;
|
||||
|
||||
public class PacketRipeningUpdate extends ForestryPacket {
|
||||
public class PacketRipeningUpdate extends PacketCoordinates {
|
||||
|
||||
private int colourFruits;
|
||||
private int posX, posY, posZ;
|
||||
private int value;
|
||||
|
||||
public PacketRipeningUpdate() {
|
||||
public PacketRipeningUpdate(DataInputStream data) throws IOException {
|
||||
super(data);
|
||||
}
|
||||
|
||||
public PacketRipeningUpdate(TileFruitPod fruitPod) {
|
||||
super(PacketId.RIPENING_UPDATE, fruitPod);
|
||||
value = fruitPod.getMaturity();
|
||||
}
|
||||
|
||||
public PacketRipeningUpdate(TileLeaves leaves) {
|
||||
super(PacketIds.RIPENING_UPDATE);
|
||||
posX = leaves.xCoord;
|
||||
posY = leaves.yCoord;
|
||||
posZ = leaves.zCoord;
|
||||
colourFruits = leaves.getFruitColour();
|
||||
super(PacketId.RIPENING_UPDATE, leaves);
|
||||
value = leaves.getFruitColour();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeData(DataOutputStream data) throws IOException {
|
||||
super.writeData(data);
|
||||
|
||||
data.writeInt(posX);
|
||||
data.writeInt(posY);
|
||||
data.writeInt(posZ);
|
||||
data.writeInt(colourFruits);
|
||||
data.writeInt(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readData(DataInputStream data) throws IOException {
|
||||
super.readData(data);
|
||||
|
||||
posX = data.readInt();
|
||||
posY = data.readInt();
|
||||
posZ = data.readInt();
|
||||
colourFruits = data.readInt();
|
||||
value = data.readInt();
|
||||
}
|
||||
|
||||
public int getColourFruits() {
|
||||
return colourFruits;
|
||||
}
|
||||
|
||||
public TileEntity getTarget(World world) {
|
||||
return world.getTileEntity(posX, posY, posZ);
|
||||
public int getValue() {
|
||||
return value;
|
||||
}
|
||||
}
|
||||
@@ -1,16 +0,0 @@
|
||||
package forestry.arboriculture.network;
|
||||
|
||||
import forestry.arboriculture.gadgets.TileSapling;
|
||||
import forestry.core.network.PacketIds;
|
||||
|
||||
public class PacketSapling extends PacketTreeContainer {
|
||||
|
||||
public PacketSapling() {
|
||||
|
||||
}
|
||||
|
||||
public PacketSapling(TileSapling sapling) {
|
||||
super(PacketIds.SAPLING, sapling);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,57 +0,0 @@
|
||||
package forestry.arboriculture.network;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
import forestry.api.arboriculture.ITree;
|
||||
import forestry.api.genetics.IAllele;
|
||||
import forestry.arboriculture.gadgets.TileTreeContainer;
|
||||
import forestry.core.network.PacketCoordinates;
|
||||
import forestry.plugins.PluginArboriculture;
|
||||
|
||||
public class PacketTreeContainer extends PacketCoordinates {
|
||||
|
||||
protected String speciesUID = "";
|
||||
|
||||
public PacketTreeContainer() {
|
||||
|
||||
}
|
||||
|
||||
public PacketTreeContainer(int id, TileTreeContainer treeContainer) {
|
||||
super(id, treeContainer);
|
||||
|
||||
ITree tree = treeContainer.getTree();
|
||||
if (tree != null) {
|
||||
speciesUID = tree.getIdent();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeData(DataOutputStream data) throws IOException {
|
||||
super.writeData(data);
|
||||
data.writeUTF(speciesUID);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readData(DataInputStream data) throws IOException {
|
||||
super.readData(data);
|
||||
speciesUID = data.readUTF();
|
||||
}
|
||||
|
||||
public boolean matchesTree(ITree tree) {
|
||||
if (tree == null) {
|
||||
return speciesUID.isEmpty();
|
||||
} else {
|
||||
return tree.getIdent().equals(speciesUID);
|
||||
}
|
||||
}
|
||||
|
||||
public ITree getTree() {
|
||||
IAllele[] treeTemplate = PluginArboriculture.treeInterface.getTemplate(speciesUID);
|
||||
if (treeTemplate != null) {
|
||||
return PluginArboriculture.treeInterface.templateAsIndividual(treeTemplate);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -65,7 +65,7 @@ public abstract class WorldGenArboriculture extends WorldGenBase {
|
||||
private GameProfile getOwner() {
|
||||
TileEntity tile = world.getTileEntity(startX, startY, startZ);
|
||||
if (tile instanceof TileSapling) {
|
||||
return ((TileSapling) tile).getOwnerProfile();
|
||||
return ((TileSapling) tile).getOwner();
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -18,9 +18,9 @@ import forestry.core.gui.ContainerItemInventory;
|
||||
import forestry.core.gui.IGuiSelectable;
|
||||
import forestry.core.gui.slots.SlotFiltered;
|
||||
import forestry.core.gui.slots.SlotOutput;
|
||||
import forestry.core.network.PacketIds;
|
||||
import forestry.core.network.PacketPayload;
|
||||
import forestry.core.network.PacketUpdate;
|
||||
import forestry.core.network.PacketGuiSelect;
|
||||
import forestry.core.network.PacketId;
|
||||
import forestry.core.network.PacketString;
|
||||
import forestry.core.proxy.Proxies;
|
||||
|
||||
public class ContainerSolderingIron extends ContainerItemInventory<SolderingInventory> implements IGuiSelectable {
|
||||
@@ -46,38 +46,26 @@ public class ContainerSolderingIron extends ContainerItemInventory<SolderingInve
|
||||
}
|
||||
|
||||
public static void advanceSelection(int index) {
|
||||
PacketPayload payload = new PacketPayload(2, 0, 0);
|
||||
payload.intPayload[0] = index;
|
||||
payload.intPayload[1] = 0;
|
||||
sendSelectionChange(payload);
|
||||
sendSelectionChange(index, 0);
|
||||
}
|
||||
|
||||
public static void regressSelection(int index) {
|
||||
PacketPayload payload = new PacketPayload(2, 0, 0);
|
||||
payload.intPayload[0] = index;
|
||||
payload.intPayload[1] = 1;
|
||||
sendSelectionChange(payload);
|
||||
sendSelectionChange(index, 1);
|
||||
}
|
||||
|
||||
private static void sendSelectionChange(PacketPayload payload) {
|
||||
PacketUpdate packet = new PacketUpdate(PacketIds.GUI_SELECTION_CHANGE, payload);
|
||||
private static void sendSelectionChange(int index, int advance) {
|
||||
PacketGuiSelect packet = new PacketGuiSelect(PacketId.GUI_SELECTION_CHANGE, index, advance);
|
||||
Proxies.net.sendToServer(packet);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSelection(PacketUpdate packet) {
|
||||
inventory.setLayout(packet.payload.stringPayload[0]);
|
||||
}
|
||||
public void handleSelectionChange(EntityPlayer player, PacketGuiSelect packet) {
|
||||
|
||||
@Override
|
||||
public void handleSelectionChange(EntityPlayer player, PacketUpdate packet) {
|
||||
|
||||
if (packet.payload.intPayload[1] == 0) {
|
||||
if (packet.payload.intPayload[0] == 0) {
|
||||
if (packet.getSecondaryIndex() == 0) {
|
||||
if (packet.getPrimaryIndex() == 0) {
|
||||
inventory.advanceLayout();
|
||||
}
|
||||
|
||||
} else if (packet.payload.intPayload[0] == 0) {
|
||||
} else if (packet.getPrimaryIndex() == 0) {
|
||||
inventory.regressLayout();
|
||||
}
|
||||
|
||||
@@ -85,9 +73,15 @@ public class ContainerSolderingIron extends ContainerItemInventory<SolderingInve
|
||||
}
|
||||
|
||||
public void sendSelection(EntityPlayer player) {
|
||||
PacketPayload payload = new PacketPayload(0, 0, 1);
|
||||
payload.stringPayload[0] = inventory.getLayout().getUID();
|
||||
Proxies.net.sendToPlayer(new PacketUpdate(PacketIds.GUI_SELECTION, payload), player);
|
||||
PacketString packet = new PacketString(PacketId.GUI_LAYOUT_SELECT, inventory.getLayout().getUID());
|
||||
Proxies.net.sendToPlayer(packet, player);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSelection(PacketGuiSelect packet) {
|
||||
}
|
||||
|
||||
public void setLayout(String layoutUID) {
|
||||
inventory.setLayout(layoutUID);
|
||||
}
|
||||
}
|
||||
@@ -115,7 +115,7 @@ public final class CommandSaveStats extends SubCommand {
|
||||
}
|
||||
}
|
||||
|
||||
File file = new File(Proxies.common.getForestryRoot(), "config/" + Defaults.MOD.toLowerCase(Locale.ENGLISH) + "/stats/" + player.getDisplayName() + "-" + saveHelper.getFileSuffix() + ".log");
|
||||
File file = new File(Proxies.common.getForestryRoot(), "config/" + Defaults.MOD.toLowerCase(Locale.ENGLISH) + "/stats/" + player.getDisplayName() + '-' + saveHelper.getFileSuffix() + ".log");
|
||||
try {
|
||||
File folder = file.getParentFile();
|
||||
if (folder != null && !folder.exists()) {
|
||||
|
||||
@@ -216,7 +216,7 @@ public class BlockBase extends BlockForestry {
|
||||
return world.setBlockToAir(x, y, z);
|
||||
}
|
||||
|
||||
if (tile.isOwnable() && !tile.allowsRemoval(player)) {
|
||||
if (tile.isOwned() && !tile.allowsRemoval(player)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -37,7 +37,7 @@ public abstract class BlockForestry extends BlockContainer {
|
||||
@Override
|
||||
public boolean removedByPlayer(World world, EntityPlayer player, int x, int y, int z) {
|
||||
IOwnable tile = (IOwnable) world.getTileEntity(x, y, z);
|
||||
if (!tile.isOwnable() || tile.allowsRemoval(player)) {
|
||||
if (!tile.isOwned() || tile.allowsRemoval(player)) {
|
||||
return super.removedByPlayer(world, player, x, y, z);
|
||||
} else {
|
||||
return false;
|
||||
|
||||
@@ -10,6 +10,10 @@
|
||||
******************************************************************************/
|
||||
package forestry.core.gadgets;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.inventory.Container;
|
||||
import net.minecraft.inventory.ICrafting;
|
||||
@@ -23,7 +27,6 @@ import net.minecraftforge.common.util.ForgeDirection;
|
||||
import forestry.core.EnumErrorCode;
|
||||
import forestry.core.TemperatureState;
|
||||
import forestry.core.config.Defaults;
|
||||
import forestry.core.network.PacketPayload;
|
||||
import forestry.core.utils.BlockUtil;
|
||||
import forestry.energy.EnergyManager;
|
||||
|
||||
@@ -31,33 +34,7 @@ import cofh.api.energy.IEnergyConnection;
|
||||
|
||||
public abstract class Engine extends TileBase implements IEnergyConnection {
|
||||
|
||||
@Override
|
||||
public PacketPayload getPacketPayload() {
|
||||
PacketPayload payload = new PacketPayload(3, 1, 0);
|
||||
|
||||
if (this.isActive) {
|
||||
payload.intPayload[0] = 1;
|
||||
} else {
|
||||
payload.intPayload[0] = 0;
|
||||
}
|
||||
payload.intPayload[1] = energyManager.toPacketInt();
|
||||
payload.intPayload[2] = heat;
|
||||
|
||||
payload.floatPayload[0] = pistonSpeedServer;
|
||||
return payload;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fromPacketPayload(PacketPayload payload) {
|
||||
|
||||
isActive = payload.intPayload[0] > 0;
|
||||
energyManager.fromPacketInt(payload.intPayload[1]);
|
||||
heat = payload.intPayload[2];
|
||||
|
||||
pistonSpeedServer = payload.floatPayload[0];
|
||||
}
|
||||
|
||||
public boolean isActive = false; // Used for smp.
|
||||
public boolean active = false; // Used for smp.
|
||||
/**
|
||||
* Indicates whether the piston is receding from or approaching the
|
||||
* combustion chamber
|
||||
@@ -118,7 +95,7 @@ public abstract class Engine extends TileBase implements IEnergyConnection {
|
||||
stagePiston = 0;
|
||||
progress = 0;
|
||||
}
|
||||
} else if (this.isActive) {
|
||||
} else if (this.active) {
|
||||
stagePiston = 1;
|
||||
}
|
||||
}
|
||||
@@ -181,11 +158,11 @@ public abstract class Engine extends TileBase implements IEnergyConnection {
|
||||
}
|
||||
|
||||
private void setActive(boolean isActive) {
|
||||
if (this.isActive == isActive) {
|
||||
if (this.active == isActive) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.isActive = isActive;
|
||||
this.active = isActive;
|
||||
setNeedsNetworkUpdate();
|
||||
}
|
||||
|
||||
@@ -296,6 +273,25 @@ public abstract class Engine extends TileBase implements IEnergyConnection {
|
||||
nbt.setBoolean("ForceCooldown", forceCooldown);
|
||||
}
|
||||
|
||||
/* NETWORK */
|
||||
@Override
|
||||
public void writeData(DataOutputStream data) throws IOException {
|
||||
super.writeData(data);
|
||||
data.writeBoolean(active);
|
||||
data.writeInt(heat);
|
||||
data.writeFloat(pistonSpeedServer);
|
||||
energyManager.writeData(data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readData(DataInputStream data) throws IOException {
|
||||
super.readData(data);
|
||||
active = data.readBoolean();
|
||||
heat = data.readInt();
|
||||
pistonSpeedServer = data.readFloat();
|
||||
energyManager.readData(data);
|
||||
}
|
||||
|
||||
/* SMP GUI */
|
||||
public abstract void getGUINetworkData(int i, int j);
|
||||
|
||||
|
||||
@@ -10,7 +10,9 @@
|
||||
******************************************************************************/
|
||||
package forestry.core.gadgets;
|
||||
|
||||
import forestry.core.network.PacketPayload;
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
public abstract class Mill extends TileBase {
|
||||
|
||||
@@ -34,21 +36,19 @@ public abstract class Mill extends TileBase {
|
||||
}
|
||||
|
||||
@Override
|
||||
public PacketPayload getPacketPayload() {
|
||||
PacketPayload payload = new PacketPayload(2, 1, 0);
|
||||
payload.intPayload[0] = charge;
|
||||
payload.intPayload[1] = stage;
|
||||
|
||||
payload.floatPayload[0] = speed;
|
||||
return payload;
|
||||
public void writeData(DataOutputStream data) throws IOException {
|
||||
super.writeData(data);
|
||||
data.writeInt(charge);
|
||||
data.writeFloat(speed);
|
||||
data.writeInt(stage);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fromPacketPayload(PacketPayload payload) {
|
||||
charge = payload.intPayload[0];
|
||||
stage = payload.intPayload[1];
|
||||
|
||||
speed = payload.floatPayload[0];
|
||||
public void readData(DataInputStream data) throws IOException {
|
||||
super.readData(data);
|
||||
charge = data.readInt();
|
||||
speed = data.readFloat();
|
||||
stage = data.readInt();
|
||||
}
|
||||
|
||||
private void update(boolean isSimulating) {
|
||||
|
||||
@@ -10,8 +10,13 @@
|
||||
******************************************************************************/
|
||||
package forestry.core.gadgets;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
import net.minecraft.inventory.IInventory;
|
||||
@@ -23,14 +28,16 @@ import forestry.api.core.INBTTagable;
|
||||
import forestry.api.genetics.AlleleManager;
|
||||
import forestry.api.genetics.IIndividual;
|
||||
import forestry.api.genetics.ISpeciesRoot;
|
||||
import forestry.core.network.IStreamable;
|
||||
import forestry.core.network.PacketHelper;
|
||||
import forestry.core.utils.StringUtil;
|
||||
import forestry.core.utils.Utils;
|
||||
|
||||
public class NaturalistGame implements INBTTagable {
|
||||
public class NaturalistGame implements INBTTagable, IStreamable {
|
||||
|
||||
public static final int BOUNTY_MAX = 16;
|
||||
|
||||
public static class GameToken implements INBTTagable {
|
||||
public static class GameToken implements INBTTagable, IStreamable {
|
||||
|
||||
private static final String[] OVERLAY_NONE = new String[0];
|
||||
private static final String[] OVERLAY_FAILED = new String[]{"errors/errored"};
|
||||
@@ -41,6 +48,10 @@ public class NaturalistGame implements INBTTagable {
|
||||
protected boolean isProbed = false;
|
||||
protected boolean isRevealed = false;
|
||||
|
||||
public GameToken() {
|
||||
|
||||
}
|
||||
|
||||
public GameToken(ItemStack tokenStack) {
|
||||
this.tokenStack = tokenStack;
|
||||
}
|
||||
@@ -73,6 +84,25 @@ public class NaturalistGame implements INBTTagable {
|
||||
}
|
||||
}
|
||||
|
||||
/* NETWORK */
|
||||
@Override
|
||||
public void writeData(DataOutputStream data) throws IOException {
|
||||
data.writeBoolean(isFailed);
|
||||
data.writeBoolean(isProbed);
|
||||
data.writeBoolean(isRevealed);
|
||||
|
||||
PacketHelper.writeItemStack(tokenStack, data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readData(DataInputStream data) throws IOException {
|
||||
isFailed = data.readBoolean();
|
||||
isProbed = data.readBoolean();
|
||||
isRevealed = data.readBoolean();
|
||||
|
||||
tokenStack = PacketHelper.readItemStack(data);
|
||||
}
|
||||
|
||||
public boolean isVisible() {
|
||||
return isRevealed;
|
||||
}
|
||||
@@ -163,6 +193,29 @@ public class NaturalistGame implements INBTTagable {
|
||||
lastUpdate = System.currentTimeMillis();
|
||||
}
|
||||
|
||||
/* NETWORK */
|
||||
@Override
|
||||
public void writeData(DataOutputStream data) throws IOException {
|
||||
data.writeBoolean(isEnded);
|
||||
data.writeInt(bountyLevel);
|
||||
data.writeLong(lastUpdate);
|
||||
|
||||
List<GameToken> gameTokensList = gameTokens == null ? null : Arrays.asList(gameTokens);
|
||||
PacketHelper.writeStreamables(gameTokensList, data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readData(DataInputStream data) throws IOException {
|
||||
isEnded = data.readBoolean();
|
||||
bountyLevel = data.readInt();
|
||||
lastUpdate = data.readLong();
|
||||
|
||||
List<GameToken> gameTokensList = PacketHelper.readStreamables(GameToken.class, data);
|
||||
if (gameTokensList != null) {
|
||||
this.gameTokens = gameTokensList.toArray(new GameToken[gameTokensList.size()]);
|
||||
}
|
||||
}
|
||||
|
||||
/* INTERACTION */
|
||||
public void initialize(ItemStack specimen) {
|
||||
IIndividual individual = AlleleManager.alleleRegistry.getIndividual(specimen);
|
||||
@@ -284,8 +337,9 @@ public class NaturalistGame implements INBTTagable {
|
||||
continue;
|
||||
}
|
||||
|
||||
gameTokens[tokenIndices[processedTokens]].isProbed = true;
|
||||
gameTokens[tokenIndices[processedTokens]].isRevealed = true;
|
||||
GameToken token = gameTokens[tokenIndices[processedTokens]];
|
||||
token.isProbed = true;
|
||||
token.isRevealed = true;
|
||||
|
||||
processedTokens++;
|
||||
if (processedTokens >= tokenIndices.length) {
|
||||
@@ -296,32 +350,34 @@ public class NaturalistGame implements INBTTagable {
|
||||
lastUpdate = System.currentTimeMillis();
|
||||
}
|
||||
|
||||
public void choose(int tokenIndex) {
|
||||
public void choose(final int tokenIndex) {
|
||||
if (isEnded) {
|
||||
return;
|
||||
}
|
||||
if (gameTokens == null || tokenIndex >= gameTokens.length) {
|
||||
return;
|
||||
}
|
||||
if (gameTokens[tokenIndex].isRevealed && !gameTokens[tokenIndex].isProbed) {
|
||||
|
||||
GameToken token = gameTokens[tokenIndex];
|
||||
if (token.isRevealed && !token.isProbed) {
|
||||
return;
|
||||
}
|
||||
hideProbedTokens();
|
||||
|
||||
Collection<GameToken> singles = getRevealedSingles(gameTokens[tokenIndex]);
|
||||
Collection<GameToken> singles = getRevealedSingles(token);
|
||||
if (singles.size() > 0) {
|
||||
boolean matched = false;
|
||||
for (GameToken single : singles) {
|
||||
if (single.matches(gameTokens[tokenIndex])) {
|
||||
if (single.matches(token)) {
|
||||
matched = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!matched) {
|
||||
gameTokens[tokenIndex].isFailed = true;
|
||||
token.isFailed = true;
|
||||
}
|
||||
}
|
||||
gameTokens[tokenIndex].isRevealed = true;
|
||||
token.isRevealed = true;
|
||||
checkGameEnd();
|
||||
lastUpdate = System.currentTimeMillis();
|
||||
}
|
||||
@@ -420,10 +476,6 @@ public class NaturalistGame implements INBTTagable {
|
||||
}
|
||||
|
||||
/* RETRIEVAL */
|
||||
public int getBoardSize() {
|
||||
return gameTokens != null ? gameTokens.length : 0;
|
||||
}
|
||||
|
||||
public int getSampleSize() {
|
||||
if (gameTokens == null) {
|
||||
return 0;
|
||||
@@ -436,11 +488,4 @@ public class NaturalistGame implements INBTTagable {
|
||||
public GameToken getToken(int index) {
|
||||
return gameTokens != null ? index < gameTokens.length ? gameTokens[index] : null : null;
|
||||
}
|
||||
|
||||
public void setToken(int index, NBTTagCompound nbttagcompound) {
|
||||
if (gameTokens == null) {
|
||||
gameTokens = new GameToken[24];
|
||||
}
|
||||
gameTokens[index] = new GameToken(nbttagcompound);
|
||||
}
|
||||
}
|
||||
@@ -10,6 +10,9 @@
|
||||
******************************************************************************/
|
||||
package forestry.core.gadgets;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
@@ -38,7 +41,6 @@ import forestry.core.fluids.FluidHelper;
|
||||
import forestry.core.fluids.Fluids;
|
||||
import forestry.core.fluids.TankManager;
|
||||
import forestry.core.fluids.tanks.FilteredTank;
|
||||
import forestry.core.interfaces.IErrorSource;
|
||||
import forestry.core.interfaces.ILiquidTankContainer;
|
||||
import forestry.core.inventory.InvTools;
|
||||
import forestry.core.inventory.TileInventoryAdapter;
|
||||
@@ -46,7 +48,6 @@ import forestry.core.inventory.wrappers.IInvSlot;
|
||||
import forestry.core.inventory.wrappers.InventoryIterator;
|
||||
import forestry.core.inventory.wrappers.InventoryMapper;
|
||||
import forestry.core.network.GuiId;
|
||||
import forestry.core.network.PacketPayload;
|
||||
import forestry.core.utils.GeneticsUtil;
|
||||
import forestry.core.utils.GuiUtil;
|
||||
|
||||
@@ -197,30 +198,33 @@ public class TileAnalyzer extends TilePowered implements ISidedInventory, ILiqui
|
||||
}
|
||||
|
||||
/* Network */
|
||||
public PacketPayload getPacketPayload() {
|
||||
@Override
|
||||
public void writeData(DataOutputStream data) throws IOException {
|
||||
super.writeData(data);
|
||||
ItemStack displayStack = getIndividualOnDisplay();
|
||||
if (displayStack == null) {
|
||||
return null;
|
||||
data.writeBoolean(false);
|
||||
} else {
|
||||
data.writeBoolean(true);
|
||||
|
||||
IIndividual displayIndividual = AlleleManager.alleleRegistry.getIndividual(displayStack);
|
||||
int type = BeeManager.beeRoot.getType(displayStack).ordinal();
|
||||
|
||||
data.writeUTF(displayIndividual.getIdent());
|
||||
data.writeShort(type);
|
||||
data.writeShort(displayStack.stackSize);
|
||||
}
|
||||
|
||||
IIndividual displayIndividual = AlleleManager.alleleRegistry.getIndividual(displayStack);
|
||||
int type = BeeManager.beeRoot.getType(displayStack).ordinal();
|
||||
|
||||
PacketPayload payload = new PacketPayload();
|
||||
payload.stringPayload = new String[1];
|
||||
payload.shortPayload = new short[2];
|
||||
payload.stringPayload[0] = displayIndividual.getIdent();
|
||||
payload.shortPayload[0] = (short) type;
|
||||
payload.shortPayload[1] = (short) displayStack.stackSize;
|
||||
return payload;
|
||||
}
|
||||
|
||||
public void fromPacketPayload(PacketPayload payload) {
|
||||
@Override
|
||||
public void readData(DataInputStream data) throws IOException {
|
||||
super.readData(data);
|
||||
|
||||
ItemStack newIndividualOnDisplay = null;
|
||||
if (!payload.isEmpty()) {
|
||||
String individualUID = payload.stringPayload[0];
|
||||
int type = payload.shortPayload[0];
|
||||
int stackSize = payload.shortPayload[1];
|
||||
if (data.readBoolean()) {
|
||||
String individualUID = data.readUTF();
|
||||
int type = data.readShort();
|
||||
int stackSize = data.readShort();
|
||||
|
||||
IAllele[] template = BeeManager.beeRoot.getTemplate(individualUID);
|
||||
IIndividual individual = BeeManager.beeRoot.templateAsIndividual(template);
|
||||
|
||||
@@ -13,31 +13,14 @@ package forestry.core.gadgets;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
|
||||
import forestry.core.interfaces.IHintSource;
|
||||
import forestry.core.network.PacketPayload;
|
||||
import forestry.core.proxy.Proxies;
|
||||
|
||||
public abstract class TileBase extends TileForestry implements IHintSource {
|
||||
|
||||
@Override
|
||||
public boolean isOwnable() {
|
||||
return true;
|
||||
}
|
||||
|
||||
/* UPDATING */
|
||||
@Override
|
||||
public void initialize() {
|
||||
}
|
||||
|
||||
/* NETWORK */
|
||||
@Override
|
||||
public PacketPayload getPacketPayload() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fromPacketPayload(PacketPayload payload) {
|
||||
}
|
||||
|
||||
/* INTERACTION */
|
||||
public abstract void openGui(EntityPlayer player, TileBase tile);
|
||||
|
||||
|
||||
@@ -10,6 +10,10 @@
|
||||
******************************************************************************/
|
||||
package forestry.core.gadgets;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.ISidedInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
@@ -24,11 +28,8 @@ import forestry.core.interfaces.ICrafter;
|
||||
import forestry.core.interfaces.IRenderableMachine;
|
||||
import forestry.core.inventory.InvTools;
|
||||
import forestry.core.inventory.TileInventoryAdapter;
|
||||
import forestry.core.network.ForestryPacket;
|
||||
import forestry.core.network.GuiId;
|
||||
import forestry.core.network.PacketIds;
|
||||
import forestry.core.network.PacketTileNBT;
|
||||
import forestry.core.network.PacketTileUpdate;
|
||||
import forestry.core.network.PacketTileStream;
|
||||
import forestry.core.proxy.Proxies;
|
||||
import forestry.core.utils.EnumTankLevel;
|
||||
import forestry.core.utils.GeneticsUtil;
|
||||
@@ -56,13 +57,6 @@ public class TileEscritoire extends TileBase implements ISidedInventory, IRender
|
||||
}
|
||||
|
||||
/* SAVING & LOADING */
|
||||
@Override
|
||||
public void writeToNBT(NBTTagCompound nbttagcompound) {
|
||||
super.writeToNBT(nbttagcompound);
|
||||
|
||||
game.writeToNBT(nbttagcompound);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFromNBT(NBTTagCompound nbttagcompound) {
|
||||
super.readFromNBT(nbttagcompound);
|
||||
@@ -70,6 +64,13 @@ public class TileEscritoire extends TileBase implements ISidedInventory, IRender
|
||||
game.readFromNBT(nbttagcompound);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToNBT(NBTTagCompound nbttagcompound) {
|
||||
super.writeToNBT(nbttagcompound);
|
||||
|
||||
game.writeToNBT(nbttagcompound);
|
||||
}
|
||||
|
||||
/* GAME */
|
||||
public NaturalistGame getGame() {
|
||||
return game;
|
||||
@@ -109,19 +110,21 @@ public class TileEscritoire extends TileBase implements ISidedInventory, IRender
|
||||
}
|
||||
|
||||
/* NETWORK */
|
||||
@Override
|
||||
public void fromPacket(ForestryPacket packetRaw) {
|
||||
if (packetRaw instanceof PacketTileUpdate) {
|
||||
super.fromPacket(packetRaw);
|
||||
return;
|
||||
}
|
||||
|
||||
PacketTileNBT packet = (PacketTileNBT) packetRaw;
|
||||
readFromNBT(packet.getTagCompound());
|
||||
@Override
|
||||
public void writeData(DataOutputStream data) throws IOException {
|
||||
super.writeData(data);
|
||||
game.writeData(data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readData(DataInputStream data) throws IOException {
|
||||
super.readData(data);
|
||||
game.readData(data);
|
||||
}
|
||||
|
||||
public void sendBoard(EntityPlayer player) {
|
||||
Proxies.net.sendToPlayer(new PacketTileNBT(PacketIds.TILE_NBT, this), player);
|
||||
Proxies.net.sendToPlayer(new PacketTileStream(this), player);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -12,10 +12,14 @@ package forestry.core.gadgets;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.Random;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
@@ -35,18 +39,20 @@ import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
import cpw.mods.fml.common.Optional;
|
||||
|
||||
import forestry.api.core.ErrorStateRegistry;
|
||||
import forestry.api.core.IErrorState;
|
||||
import forestry.core.config.Config;
|
||||
import forestry.core.config.Defaults;
|
||||
import forestry.core.fluids.TankManager;
|
||||
import forestry.core.interfaces.IErrorSource;
|
||||
import forestry.core.interfaces.IFilterSlotDelegate;
|
||||
import forestry.core.interfaces.ILiquidTankContainer;
|
||||
import forestry.core.interfaces.IRestrictedAccess;
|
||||
import forestry.core.inventory.FakeInventoryAdapter;
|
||||
import forestry.core.inventory.IInventoryAdapter;
|
||||
import forestry.core.network.ForestryPacket;
|
||||
import forestry.core.network.INetworkedEntity;
|
||||
import forestry.core.network.PacketPayload;
|
||||
import forestry.core.network.PacketTileUpdate;
|
||||
import forestry.core.network.IStreamable;
|
||||
import forestry.core.network.PacketErrorUpdate;
|
||||
import forestry.core.network.PacketTileStream;
|
||||
import forestry.core.proxy.Proxies;
|
||||
import forestry.core.utils.AdjacentTileCache;
|
||||
import forestry.core.utils.EnumAccess;
|
||||
@@ -59,15 +65,17 @@ import buildcraft.api.statements.ITriggerInternal;
|
||||
import buildcraft.api.statements.ITriggerProvider;
|
||||
|
||||
@Optional.Interface(iface = "buildcraft.api.statements.ITriggerProvider", modid = "BuildCraftAPI|statements")
|
||||
public abstract class TileForestry extends TileEntity implements INetworkedEntity, IRestrictedAccess, IErrorSource, ITriggerProvider, ISidedInventory, IFilterSlotDelegate {
|
||||
public abstract class TileForestry extends TileEntity implements IStreamable, IRestrictedAccess, IErrorSource, ITriggerProvider, ISidedInventory, IFilterSlotDelegate {
|
||||
|
||||
private static final Random rand = new Random();
|
||||
|
||||
protected final AdjacentTileCache tileCache = new AdjacentTileCache(this);
|
||||
protected boolean isInited = false;
|
||||
private IInventoryAdapter inventory = FakeInventoryAdapter.instance();
|
||||
private int tickCount = rand.nextInt(256);
|
||||
private boolean needsNetworkUpdate = false;
|
||||
private ForgeDirection orientation = ForgeDirection.WEST;
|
||||
|
||||
protected final AdjacentTileCache tileCache = new AdjacentTileCache(this);
|
||||
protected boolean isInited = false;
|
||||
|
||||
public AdjacentTileCache getTileCache() {
|
||||
return tileCache;
|
||||
@@ -110,6 +118,8 @@ public abstract class TileForestry extends TileEntity implements INetworkedEntit
|
||||
|
||||
}
|
||||
|
||||
private ImmutableSet<IErrorState> previousErrorStates;
|
||||
|
||||
// / UPDATING
|
||||
@Override
|
||||
public final void updateEntity() {
|
||||
@@ -126,10 +136,16 @@ public abstract class TileForestry extends TileEntity implements INetworkedEntit
|
||||
updateClientSide();
|
||||
}
|
||||
|
||||
ImmutableSet<IErrorState> errorStates = getErrorStates();
|
||||
|
||||
if (needsNetworkUpdate) {
|
||||
needsNetworkUpdate = false;
|
||||
sendNetworkUpdate();
|
||||
} else if (!errorStates.equals(previousErrorStates)) {
|
||||
sendErrorUpdate();
|
||||
}
|
||||
|
||||
previousErrorStates = errorStates;
|
||||
}
|
||||
|
||||
protected void updateClientSide() {
|
||||
@@ -184,37 +200,84 @@ public abstract class TileForestry extends TileEntity implements INetworkedEntit
|
||||
}
|
||||
|
||||
@Override
|
||||
public Packet getDescriptionPacket() {
|
||||
PacketTileUpdate packet = new PacketTileUpdate(this);
|
||||
public final Packet getDescriptionPacket() {
|
||||
PacketTileStream packet = new PacketTileStream(this);
|
||||
return packet.getPacket();
|
||||
}
|
||||
|
||||
/* INetworkedEntity */
|
||||
@Override
|
||||
public void sendNetworkUpdate() {
|
||||
PacketTileUpdate packet = new PacketTileUpdate(this);
|
||||
Proxies.net.sendNetworkPacket(packet, xCoord, yCoord, zCoord);
|
||||
public final void sendNetworkUpdate() {
|
||||
PacketTileStream packet = new PacketTileStream(this);
|
||||
Proxies.net.sendNetworkPacket(packet);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fromPacket(ForestryPacket packetRaw) {
|
||||
PacketTileUpdate packet = (PacketTileUpdate) packetRaw;
|
||||
if (orientation != packet.getOrientation()) {
|
||||
orientation = packet.getOrientation();
|
||||
worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
|
||||
public final void sendErrorUpdate() {
|
||||
PacketErrorUpdate packet = new PacketErrorUpdate(this);
|
||||
Proxies.net.sendNetworkPacket(packet);
|
||||
}
|
||||
|
||||
public void writeData(DataOutputStream data) throws IOException {
|
||||
data.writeByte(orientation.ordinal());
|
||||
|
||||
writeErrorData(data);
|
||||
|
||||
// TODO: Should this really be sent to the client? Huge network cost.
|
||||
// As far as I know, only GUIs need it, and there are better ways to get the information to a GUI.
|
||||
// -CovertJaguar
|
||||
if (owner == null) {
|
||||
data.writeBoolean(false);
|
||||
} else {
|
||||
data.writeBoolean(true);
|
||||
data.writeByte(access.ordinal());
|
||||
data.writeLong(owner.getId().getMostSignificantBits());
|
||||
data.writeLong(owner.getId().getLeastSignificantBits());
|
||||
data.writeUTF(owner.getName());
|
||||
}
|
||||
|
||||
errorStates.clear();
|
||||
errorStates.addAll(packet.getErrorStates());
|
||||
|
||||
owner = packet.getOwner();
|
||||
access = packet.getAccess();
|
||||
fromPacketPayload(packet.payload);
|
||||
if (this instanceof ILiquidTankContainer) {
|
||||
TankManager tankManager = ((ILiquidTankContainer) this).getTankManager();
|
||||
if (tankManager != null) {
|
||||
tankManager.writePacketData(data);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public abstract PacketPayload getPacketPayload();
|
||||
public void readData(DataInputStream data) throws IOException {
|
||||
orientation = ForgeDirection.getOrientation(data.readByte());
|
||||
|
||||
public abstract void fromPacketPayload(PacketPayload payload);
|
||||
readErrorData(data);
|
||||
|
||||
if (data.readBoolean()) {
|
||||
byte accessOrdinal = data.readByte();
|
||||
access = EnumAccess.values()[accessOrdinal];
|
||||
owner = new GameProfile(new UUID(data.readLong(), data.readLong()), data.readUTF());
|
||||
}
|
||||
|
||||
if (this instanceof ILiquidTankContainer) {
|
||||
TankManager tankManager = ((ILiquidTankContainer) this).getTankManager();
|
||||
if (tankManager != null) {
|
||||
tankManager.readPacketData(data);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public final void writeErrorData(DataOutputStream data) throws IOException {
|
||||
data.writeShort(errorStates.size());
|
||||
for (IErrorState errorState : errorStates) {
|
||||
data.writeShort(errorState.getID());
|
||||
}
|
||||
}
|
||||
|
||||
public final void readErrorData(DataInputStream data) throws IOException {
|
||||
errorStates.clear();
|
||||
|
||||
short errorStateCount = data.readShort();
|
||||
for (int i = 0; i < errorStateCount; i++) {
|
||||
short errorStateId = data.readShort();
|
||||
IErrorState errorState = ErrorStateRegistry.getErrorState(errorStateId);
|
||||
errorStates.add(errorState);
|
||||
}
|
||||
}
|
||||
|
||||
public void onRemoval() {
|
||||
}
|
||||
@@ -233,17 +296,11 @@ public abstract class TileForestry extends TileEntity implements INetworkedEntit
|
||||
}
|
||||
|
||||
// / REDSTONE INFO
|
||||
|
||||
/**
|
||||
* @return true if tile is activated by redstone current.
|
||||
*/
|
||||
public boolean isRedstoneActivated() {
|
||||
return worldObj.isBlockIndirectlyGettingPowered(xCoord, yCoord, zCoord);
|
||||
}
|
||||
|
||||
// / ORIENTATION
|
||||
private ForgeDirection orientation = ForgeDirection.WEST;
|
||||
|
||||
public ForgeDirection getOrientation() {
|
||||
return this.orientation;
|
||||
}
|
||||
@@ -265,29 +322,20 @@ public abstract class TileForestry extends TileEntity implements INetworkedEntit
|
||||
|
||||
public final boolean setErrorCondition(boolean condition, IErrorState errorState) {
|
||||
if (condition) {
|
||||
if (errorStates.add(errorState)) {
|
||||
setNeedsNetworkUpdate();
|
||||
}
|
||||
errorStates.add(errorState);
|
||||
} else {
|
||||
if (errorStates.remove(errorState)) {
|
||||
setNeedsNetworkUpdate();
|
||||
}
|
||||
errorStates.remove(errorState);
|
||||
}
|
||||
return condition;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
protected final void addErrorState(IErrorState state) {
|
||||
if (errorStates.add(state)) {
|
||||
setNeedsNetworkUpdate();
|
||||
}
|
||||
errorStates.add(state);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
protected final void removeErrorStates() {
|
||||
if (errorStates.size() > 0) {
|
||||
setNeedsNetworkUpdate();
|
||||
}
|
||||
errorStates.clear();
|
||||
}
|
||||
|
||||
@@ -310,7 +358,7 @@ public abstract class TileForestry extends TileEntity implements INetworkedEntit
|
||||
|
||||
@Override
|
||||
public final boolean allowsRemoval(EntityPlayer player) {
|
||||
return Config.disablePermissions || getAccess() == EnumAccess.SHARED || !isOwnable() || !isOwned() || isOwner(player) || Proxies.common.isOp(player);
|
||||
return Config.disablePermissions || getAccess() == EnumAccess.SHARED || !isOwned() || isOwner(player) || Proxies.common.isOp(player);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -332,18 +380,13 @@ public abstract class TileForestry extends TileEntity implements INetworkedEntit
|
||||
return access;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isOwnable() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isOwned() {
|
||||
return owner != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public GameProfile getOwnerProfile() {
|
||||
public GameProfile getOwner() {
|
||||
return owner;
|
||||
}
|
||||
|
||||
@@ -391,7 +434,7 @@ public abstract class TileForestry extends TileEntity implements INetworkedEntit
|
||||
*/
|
||||
public String getUnlocalizedName() {
|
||||
String blockUnlocalizedName = getBlockType().getUnlocalizedName().replace("tile.for.", "");
|
||||
return blockUnlocalizedName + "." + getBlockMetadata() + ".name";
|
||||
return blockUnlocalizedName + '.' + getBlockMetadata() + ".name";
|
||||
}
|
||||
|
||||
/* INVENTORY BASICS */
|
||||
|
||||
@@ -28,7 +28,7 @@ import forestry.api.genetics.IBreedingTracker;
|
||||
import forestry.api.genetics.IIndividual;
|
||||
import forestry.api.genetics.IMutation;
|
||||
import forestry.api.genetics.ISpeciesRoot;
|
||||
import forestry.core.network.PacketIds;
|
||||
import forestry.core.network.PacketId;
|
||||
import forestry.core.network.PacketNBT;
|
||||
import forestry.core.proxy.Proxies;
|
||||
|
||||
@@ -77,7 +77,7 @@ public abstract class BreedingTracker extends WorldSavedData implements IBreedin
|
||||
|
||||
NBTTagCompound nbttagcompound = new NBTTagCompound();
|
||||
encodeToNBT(nbttagcompound);
|
||||
Proxies.net.sendToPlayer(new PacketNBT(PacketIds.GENOME_TRACKER_UPDATE, nbttagcompound), player);
|
||||
Proxies.net.sendToPlayer(new PacketNBT(PacketId.GENOME_TRACKER_UPDATE, nbttagcompound), player);
|
||||
}
|
||||
|
||||
/* HELPER FUNCTIONS TO PREVENT OBFUSCATION OF INTERFACE METHODS */
|
||||
|
||||
@@ -15,10 +15,7 @@ import net.minecraft.entity.player.EntityPlayer;
|
||||
import forestry.core.gadgets.TileEscritoire;
|
||||
import forestry.core.gui.slots.SlotFiltered;
|
||||
import forestry.core.gui.slots.SlotOutput;
|
||||
import forestry.core.network.PacketIds;
|
||||
import forestry.core.network.PacketPayload;
|
||||
import forestry.core.network.PacketUpdate;
|
||||
import forestry.core.proxy.Proxies;
|
||||
import forestry.core.network.PacketGuiSelect;
|
||||
|
||||
public class ContainerEscritoire extends ContainerTile<TileEscritoire> implements IGuiSelectable {
|
||||
|
||||
@@ -56,35 +53,20 @@ public class ContainerEscritoire extends ContainerTile<TileEscritoire> implement
|
||||
tile.sendBoard(player);
|
||||
}
|
||||
|
||||
public void sendTokenClick(int index) {
|
||||
PacketPayload payload = new PacketPayload(1, 0, 0);
|
||||
payload.intPayload[0] = index;
|
||||
PacketUpdate packet = new PacketUpdate(PacketIds.GUI_SELECTION_CHANGE, payload);
|
||||
Proxies.net.sendToServer(packet);
|
||||
}
|
||||
|
||||
public void sendProbeClick() {
|
||||
PacketPayload payload = new PacketPayload(1, 0, 0);
|
||||
payload.intPayload[0] = -1;
|
||||
PacketUpdate packet = new PacketUpdate(PacketIds.GUI_SELECTION_CHANGE, payload);
|
||||
Proxies.net.sendToServer(packet);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleSelectionChange(EntityPlayer player, PacketUpdate packet) {
|
||||
public void handleSelectionChange(EntityPlayer player, PacketGuiSelect packet) {
|
||||
if (!tile.getGame().isEnded()) {
|
||||
int index = packet.payload.intPayload[0];
|
||||
int index = packet.getPrimaryIndex();
|
||||
if (index == -1) {
|
||||
tile.probe();
|
||||
} else {
|
||||
tile.getGame().choose(packet.payload.intPayload[0]);
|
||||
tile.getGame().choose(index);
|
||||
tile.processTurnResult(player.getGameProfile());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSelection(PacketUpdate packet) {
|
||||
public void setSelection(PacketGuiSelect packet) {
|
||||
}
|
||||
|
||||
}
|
||||
@@ -26,9 +26,8 @@ import forestry.api.core.IToolPipette;
|
||||
import forestry.core.fluids.tanks.StandardTank;
|
||||
import forestry.core.gadgets.TileForestry;
|
||||
import forestry.core.interfaces.ILiquidTankContainer;
|
||||
import forestry.core.network.PacketIds;
|
||||
import forestry.core.network.PacketPayload;
|
||||
import forestry.core.network.PacketUpdate;
|
||||
import forestry.core.network.PacketId;
|
||||
import forestry.core.network.PacketSlotClick;
|
||||
import forestry.core.proxy.Proxies;
|
||||
|
||||
public class ContainerLiquidTanks<T extends TileForestry & ILiquidTankContainer> extends ContainerTile<T> {
|
||||
@@ -44,9 +43,7 @@ public class ContainerLiquidTanks<T extends TileForestry & ILiquidTankContainer>
|
||||
return;
|
||||
}
|
||||
|
||||
PacketPayload payload = new PacketPayload(1, 0, 0);
|
||||
payload.intPayload[0] = slot;
|
||||
Proxies.net.sendToServer(new PacketUpdate(PacketIds.PIPETTE_CLICK, payload));
|
||||
Proxies.net.sendToServer(new PacketSlotClick(PacketId.PIPETTE_CLICK, tile, slot));
|
||||
}
|
||||
|
||||
public void handlePipetteClick(int slot, EntityPlayerMP player) {
|
||||
|
||||
@@ -15,7 +15,7 @@ import net.minecraft.entity.player.InventoryPlayer;
|
||||
|
||||
import forestry.core.gadgets.TileNaturalistChest;
|
||||
import forestry.core.gui.slots.SlotFiltered;
|
||||
import forestry.core.network.PacketUpdate;
|
||||
import forestry.core.network.PacketGuiSelect;
|
||||
|
||||
public class ContainerNaturalistInventory extends ContainerTile<TileNaturalistChest> implements IGuiSelectable {
|
||||
|
||||
@@ -31,11 +31,11 @@ public class ContainerNaturalistInventory extends ContainerTile<TileNaturalistCh
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleSelectionChange(EntityPlayer player, PacketUpdate packet) {
|
||||
tile.flipPage(player, packet.payload.intPayload[0]);
|
||||
public void handleSelectionChange(EntityPlayer player, PacketGuiSelect packet) {
|
||||
tile.flipPage(player, packet.getPrimaryIndex());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSelection(PacketUpdate packet) {
|
||||
public void setSelection(PacketGuiSelect packet) {
|
||||
}
|
||||
}
|
||||
@@ -13,14 +13,12 @@ package forestry.core.gui;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.InventoryPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
|
||||
import forestry.core.gadgets.TileForestry;
|
||||
import forestry.core.interfaces.ISocketable;
|
||||
import forestry.core.network.PacketIds;
|
||||
import forestry.core.network.PacketPayload;
|
||||
import forestry.core.network.PacketId;
|
||||
import forestry.core.network.PacketSlotClick;
|
||||
import forestry.core.network.PacketSocketUpdate;
|
||||
import forestry.core.network.PacketUpdate;
|
||||
import forestry.core.proxy.Proxies;
|
||||
import forestry.core.utils.StackUtils;
|
||||
|
||||
@@ -32,9 +30,8 @@ public class ContainerSocketed<T extends TileForestry & ISocketable> extends Con
|
||||
|
||||
public void handleChipsetClick(int slot, EntityPlayer player, ItemStack itemstack) {
|
||||
if (!Proxies.common.isSimulating(player.worldObj)) {
|
||||
PacketPayload payload = new PacketPayload(1, 0, 0);
|
||||
payload.intPayload[0] = slot;
|
||||
Proxies.net.sendToServer(new PacketUpdate(PacketIds.CHIPSET_CLICK, payload));
|
||||
PacketSlotClick packet = new PacketSlotClick(PacketId.CHIPSET_CLICK, tile, slot);
|
||||
Proxies.net.sendToServer(packet);
|
||||
player.inventory.setItemStack(null);
|
||||
return;
|
||||
}
|
||||
@@ -50,18 +47,16 @@ public class ContainerSocketed<T extends TileForestry & ISocketable> extends Con
|
||||
player.inventory.setItemStack(null);
|
||||
}
|
||||
Proxies.net.inventoryChangeNotify(player);
|
||||
|
||||
TileEntity te = (TileEntity) tile;
|
||||
Proxies.net.sendToPlayer(new PacketSocketUpdate(PacketIds.SOCKET_UPDATE, te.xCoord, te.yCoord, te.zCoord, tile), player);
|
||||
}
|
||||
|
||||
PacketSocketUpdate packet = new PacketSocketUpdate(PacketId.SOCKET_UPDATE, tile);
|
||||
Proxies.net.sendToPlayer(packet, player);
|
||||
}
|
||||
}
|
||||
|
||||
public void handleSolderingIronClick(int slot, EntityPlayer player, ItemStack itemstack) {
|
||||
if (!Proxies.common.isSimulating(player.worldObj)) {
|
||||
PacketPayload payload = new PacketPayload(1, 0, 0);
|
||||
payload.intPayload[0] = slot;
|
||||
Proxies.net.sendToServer(new PacketUpdate(PacketIds.SOLDERING_IRON_CLICK, payload));
|
||||
PacketSlotClick packet = new PacketSlotClick(PacketId.SOLDERING_IRON_CLICK, tile, slot);
|
||||
Proxies.net.sendToServer(packet);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -82,9 +77,7 @@ public class ContainerSocketed<T extends TileForestry & ISocketable> extends Con
|
||||
player.inventory.setItemStack(null);
|
||||
}
|
||||
|
||||
TileEntity te = (TileEntity) tile;
|
||||
Proxies.net.sendToPlayer(new PacketSocketUpdate(PacketIds.SOCKET_UPDATE, te.xCoord, te.yCoord, te.zCoord, tile), player);
|
||||
|
||||
PacketSocketUpdate packet = new PacketSocketUpdate(PacketId.SOCKET_UPDATE, tile);
|
||||
Proxies.net.sendToPlayer(packet, player);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -28,6 +28,8 @@ import forestry.core.gadgets.NaturalistGame;
|
||||
import forestry.core.gadgets.NaturalistGame.GameToken;
|
||||
import forestry.core.gadgets.TileEscritoire;
|
||||
import forestry.core.gui.widgets.Widget;
|
||||
import forestry.core.network.PacketGuiSelect;
|
||||
import forestry.core.network.PacketId;
|
||||
import forestry.core.proxy.Proxies;
|
||||
import forestry.core.render.SpriteSheet;
|
||||
import forestry.core.render.TextureManager;
|
||||
@@ -120,7 +122,8 @@ public class GuiEscritoire extends GuiForestry<ContainerEscritoire, TileEscritoi
|
||||
|
||||
@Override
|
||||
public void handleMouseClick(int mouseX, int mouseY, int mouseButton) {
|
||||
container.sendTokenClick(index);
|
||||
PacketGuiSelect packet = new PacketGuiSelect(PacketId.GUI_SELECTION_CHANGE, index, 0);
|
||||
Proxies.net.sendToServer(packet);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -149,7 +152,8 @@ public class GuiEscritoire extends GuiForestry<ContainerEscritoire, TileEscritoi
|
||||
@Override
|
||||
public void handleMouseClick(int mouseX, int mouseY, int mouseButton) {
|
||||
pressed = true;
|
||||
container.sendProbeClick();
|
||||
PacketGuiSelect packet = new PacketGuiSelect(PacketId.GUI_SELECTION_CHANGE, -1, 0);
|
||||
Proxies.net.sendToServer(packet);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -10,7 +10,6 @@
|
||||
******************************************************************************/
|
||||
package forestry.core.gui;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.awt.Color;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
@@ -98,7 +97,7 @@ public abstract class GuiForestry<C extends Container, I extends IInventory> ext
|
||||
ledgerManager.add(new HintLedger(ledgerManager, (IHintSource) inventory));
|
||||
}
|
||||
|
||||
if (inventory instanceof IOwnable && ((IOwnable) inventory).isOwnable()) {
|
||||
if (inventory instanceof IOwnable && ((IOwnable) inventory).isOwned()) {
|
||||
ledgerManager.add(new OwnerLedger(ledgerManager, (IOwnable) inventory));
|
||||
}
|
||||
|
||||
|
||||
@@ -30,9 +30,9 @@ import forestry.core.config.Defaults;
|
||||
import forestry.core.genetics.EnumMutateChance;
|
||||
import forestry.core.gui.buttons.GuiBetterButton;
|
||||
import forestry.core.gui.buttons.StandardButtonTextureSets;
|
||||
import forestry.core.network.PacketIds;
|
||||
import forestry.core.network.PacketPayload;
|
||||
import forestry.core.network.PacketUpdate;
|
||||
import forestry.core.network.ForestryPacket;
|
||||
import forestry.core.network.PacketGuiSelect;
|
||||
import forestry.core.network.PacketId;
|
||||
import forestry.core.proxy.Proxies;
|
||||
import forestry.core.utils.StringUtil;
|
||||
|
||||
@@ -93,10 +93,8 @@ public class GuiNaturalistInventory extends GuiForestry<Container, IPagedInvento
|
||||
buttonList.add(new GuiBetterButton(2, guiLeft + 180, guiTop + 7, StandardButtonTextureSets.RIGHT_BUTTON_SMALL));
|
||||
}
|
||||
|
||||
private void flipPage(int page) {
|
||||
PacketPayload payload = new PacketPayload(1, 0, 0);
|
||||
payload.intPayload[0] = page;
|
||||
PacketUpdate packet = new PacketUpdate(PacketIds.GUI_SELECTION_CHANGE, payload);
|
||||
private static void flipPage(int page) {
|
||||
ForestryPacket packet = new PacketGuiSelect(PacketId.GUI_SELECTION_CHANGE, page, 0);
|
||||
Proxies.net.sendToServer(packet);
|
||||
}
|
||||
|
||||
|
||||
@@ -12,10 +12,10 @@ package forestry.core.gui;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
|
||||
import forestry.core.network.PacketUpdate;
|
||||
import forestry.core.network.PacketGuiSelect;
|
||||
|
||||
public interface IGuiSelectable {
|
||||
void handleSelectionChange(EntityPlayer player, PacketUpdate packet);
|
||||
void handleSelectionChange(EntityPlayer player, PacketGuiSelect packet);
|
||||
|
||||
void setSelection(PacketUpdate packet);
|
||||
void setSelection(PacketGuiSelect packetPayload);
|
||||
}
|
||||
@@ -18,7 +18,7 @@ import net.minecraft.util.IIcon;
|
||||
import forestry.core.interfaces.IOwnable;
|
||||
import forestry.core.interfaces.IRestrictedAccess;
|
||||
import forestry.core.network.PacketCoordinates;
|
||||
import forestry.core.network.PacketIds;
|
||||
import forestry.core.network.PacketId;
|
||||
import forestry.core.proxy.Proxies;
|
||||
import forestry.core.render.TextureManager;
|
||||
import forestry.core.utils.EnumAccess;
|
||||
@@ -99,7 +99,7 @@ public class OwnerLedger extends Ledger {
|
||||
if (isAccessButton(x, y) && tile instanceof IRestrictedAccess) {
|
||||
if (!Proxies.common.isSimulating(((TileEntity) tile).getWorldObj())) {
|
||||
TileEntity te = (TileEntity) tile;
|
||||
Proxies.net.sendToServer(new PacketCoordinates(PacketIds.ACCESS_SWITCH, te.xCoord, te.yCoord, te.zCoord));
|
||||
Proxies.net.sendToServer(new PacketCoordinates(PacketId.ACCESS_SWITCH, te));
|
||||
}
|
||||
|
||||
((IRestrictedAccess) tile).switchAccessRule(manager.minecraft.thePlayer);
|
||||
|
||||
@@ -16,11 +16,9 @@ import com.mojang.authlib.GameProfile;
|
||||
|
||||
public interface IOwnable {
|
||||
|
||||
boolean isOwnable();
|
||||
|
||||
boolean isOwned();
|
||||
|
||||
GameProfile getOwnerProfile();
|
||||
GameProfile getOwner();
|
||||
|
||||
void setOwner(EntityPlayer player);
|
||||
|
||||
|
||||
@@ -10,6 +10,10 @@
|
||||
******************************************************************************/
|
||||
package forestry.core.inventory;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
@@ -17,12 +21,14 @@ import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
|
||||
import forestry.core.config.Defaults;
|
||||
import forestry.core.network.IStreamable;
|
||||
import forestry.core.network.PacketHelper;
|
||||
import forestry.core.utils.PlainInventory;
|
||||
|
||||
/**
|
||||
* With permission from Krapht.
|
||||
*/
|
||||
public class InventoryAdapter implements IInventoryAdapter {
|
||||
public class InventoryAdapter implements IInventoryAdapter, IStreamable {
|
||||
|
||||
protected final IInventory inventory;
|
||||
private boolean allowAutomation = true;
|
||||
@@ -206,4 +212,14 @@ public class InventoryAdapter implements IInventoryAdapter {
|
||||
}
|
||||
nbttagcompound.setTag(inventory.getInventoryName(), nbttaglist);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeData(DataOutputStream data) throws IOException {
|
||||
PacketHelper.writeInventory(inventory, data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readData(DataInputStream data) throws IOException {
|
||||
PacketHelper.readInventory(inventory, data);
|
||||
}
|
||||
}
|
||||
@@ -10,40 +10,35 @@
|
||||
******************************************************************************/
|
||||
package forestry.core.network;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.CompressedStreamTools;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
||||
import cpw.mods.fml.common.network.internal.FMLProxyPacket;
|
||||
import cpw.mods.fml.common.registry.GameData;
|
||||
|
||||
import io.netty.buffer.Unpooled;
|
||||
|
||||
public class ForestryPacket {
|
||||
|
||||
protected static final String channel = "FOR";
|
||||
protected int id;
|
||||
private final PacketId id;
|
||||
|
||||
public ForestryPacket() {
|
||||
public ForestryPacket(DataInputStream data) throws IOException {
|
||||
this.id = PacketId.INVALID;
|
||||
readData(data);
|
||||
}
|
||||
|
||||
public ForestryPacket(int id) {
|
||||
public ForestryPacket(PacketId id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public FMLProxyPacket getPacket() {
|
||||
public final FMLProxyPacket getPacket() {
|
||||
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
|
||||
DataOutputStream data = new DataOutputStream(bytes);
|
||||
|
||||
try {
|
||||
data.writeByte(getID());
|
||||
data.writeByte(id.ordinal());
|
||||
writeData(data);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
@@ -52,73 +47,9 @@ public class ForestryPacket {
|
||||
return new FMLProxyPacket(Unpooled.wrappedBuffer(bytes.toByteArray()), channel);
|
||||
}
|
||||
|
||||
public int getID() {
|
||||
return id;
|
||||
protected void writeData(DataOutputStream data) throws IOException {
|
||||
}
|
||||
|
||||
protected ItemStack readItemStack(DataInputStream data) throws IOException {
|
||||
ItemStack itemstack = null;
|
||||
String itemName = data.readUTF();
|
||||
|
||||
if (!itemName.isEmpty()) {
|
||||
Item item = GameData.getItemRegistry().getRaw(itemName);
|
||||
byte stackSize = data.readByte();
|
||||
short meta = data.readShort();
|
||||
itemstack = new ItemStack(item, stackSize, meta);
|
||||
|
||||
if (item.isDamageable() || item.getShareTag()) {
|
||||
itemstack.stackTagCompound = this.readNBTTagCompound(data);
|
||||
}
|
||||
}
|
||||
|
||||
return itemstack;
|
||||
protected void readData(DataInputStream data) throws IOException {
|
||||
}
|
||||
|
||||
protected void writeItemStack(ItemStack itemstack, DataOutputStream data) throws IOException {
|
||||
|
||||
if (itemstack == null) {
|
||||
data.writeUTF("");
|
||||
} else {
|
||||
data.writeUTF(GameData.getItemRegistry().getNameForObject(itemstack.getItem()));
|
||||
data.writeByte(itemstack.stackSize);
|
||||
data.writeShort(itemstack.getItemDamage());
|
||||
|
||||
if (itemstack.getItem().isDamageable() || itemstack.getItem().getShareTag()) {
|
||||
this.writeNBTTagCompound(itemstack.stackTagCompound, data);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected NBTTagCompound readNBTTagCompound(DataInputStream data) throws IOException {
|
||||
|
||||
short length = data.readShort();
|
||||
|
||||
if (length < 0) {
|
||||
return null;
|
||||
} else {
|
||||
byte[] compressed = new byte[length];
|
||||
data.readFully(compressed);
|
||||
return CompressedStreamTools.readCompressed(new ByteArrayInputStream(compressed));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
protected void writeNBTTagCompound(NBTTagCompound nbttagcompound, DataOutputStream data) throws IOException {
|
||||
|
||||
if (nbttagcompound == null) {
|
||||
data.writeShort(-1);
|
||||
} else {
|
||||
byte[] compressed = CompressedStreamTools.compress(nbttagcompound);
|
||||
data.writeShort((short) compressed.length);
|
||||
data.write(compressed);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void writeData(DataOutputStream data) throws IOException {
|
||||
}
|
||||
|
||||
public void readData(DataInputStream data) throws IOException {
|
||||
}
|
||||
|
||||
}
|
||||
@@ -15,4 +15,8 @@ import net.minecraft.world.World;
|
||||
|
||||
public interface ILocatedPacket {
|
||||
TileEntity getTarget(World world);
|
||||
|
||||
int getPosX();
|
||||
int getPosY();
|
||||
int getPosZ();
|
||||
}
|
||||
Executable → Regular
+2
-2
@@ -8,7 +8,7 @@
|
||||
* Various Contributors including, but not limited to:
|
||||
* SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges
|
||||
******************************************************************************/
|
||||
package forestry.core.interfaces;
|
||||
package forestry.core.network;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.IOException;
|
||||
@@ -18,6 +18,6 @@ import net.minecraft.entity.player.EntityPlayer;
|
||||
public interface IPacketHandler {
|
||||
|
||||
/** Returns true if the packet has been handled */
|
||||
boolean onPacketData(int packetID, DataInputStream data, EntityPlayer player) throws IOException;
|
||||
boolean onPacketData(PacketId packetID, DataInputStream data, EntityPlayer player) throws IOException;
|
||||
|
||||
}
|
||||
Executable → Regular
+20
-19
@@ -1,19 +1,20 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2011-2014 SirSengir.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the GNU Lesser Public License v3
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.gnu.org/licenses/lgpl-3.0.txt
|
||||
*
|
||||
* Various Contributors including, but not limited to:
|
||||
* SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges
|
||||
******************************************************************************/
|
||||
package forestry.core.network;
|
||||
|
||||
public interface INetworkedEntity {
|
||||
|
||||
void sendNetworkUpdate();
|
||||
|
||||
void fromPacket(ForestryPacket packet);
|
||||
|
||||
}
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2011-2014 SirSengir.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the GNU Lesser Public License v3
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.gnu.org/licenses/lgpl-3.0.txt
|
||||
*
|
||||
* Various Contributors including, but not limited to:
|
||||
* SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges
|
||||
******************************************************************************/
|
||||
package forestry.core.network;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
public interface IStreamable {
|
||||
void writeData(DataOutputStream data) throws IOException;
|
||||
void readData(DataInputStream data) throws IOException;
|
||||
}
|
||||
@@ -24,18 +24,19 @@ public class PacketCoordinates extends ForestryPacket implements ILocatedPacket
|
||||
private int posY;
|
||||
private int posZ;
|
||||
|
||||
public PacketCoordinates() {
|
||||
public PacketCoordinates(DataInputStream data) throws IOException {
|
||||
super(data);
|
||||
}
|
||||
|
||||
public PacketCoordinates(int id, TileEntity tileEntity) {
|
||||
public PacketCoordinates(PacketId id, TileEntity tileEntity) {
|
||||
this(id, tileEntity.xCoord, tileEntity.yCoord, tileEntity.zCoord);
|
||||
}
|
||||
|
||||
public PacketCoordinates(int id, ChunkCoordinates coordinates) {
|
||||
public PacketCoordinates(PacketId id, ChunkCoordinates coordinates) {
|
||||
this(id, coordinates.posX, coordinates.posY, coordinates.posZ);
|
||||
}
|
||||
|
||||
public PacketCoordinates(int id, int posX, int posY, int posZ) {
|
||||
public PacketCoordinates(PacketId id, int posX, int posY, int posZ) {
|
||||
super(id);
|
||||
this.posX = posX;
|
||||
this.posY = posY;
|
||||
@@ -43,42 +44,37 @@ public class PacketCoordinates extends ForestryPacket implements ILocatedPacket
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeData(DataOutputStream data) throws IOException {
|
||||
|
||||
protected void writeData(DataOutputStream data) throws IOException {
|
||||
data.writeInt(posX);
|
||||
data.writeInt(posY);
|
||||
data.writeInt(posZ);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readData(DataInputStream data) throws IOException {
|
||||
|
||||
protected void readData(DataInputStream data) throws IOException {
|
||||
posX = data.readInt();
|
||||
posY = data.readInt();
|
||||
posZ = data.readInt();
|
||||
|
||||
}
|
||||
|
||||
public ChunkCoordinates getCoordinates() {
|
||||
public final ChunkCoordinates getCoordinates() {
|
||||
return new ChunkCoordinates(posX, posY, posZ);
|
||||
}
|
||||
|
||||
public int getPosX() {
|
||||
public final int getPosX() {
|
||||
return posX;
|
||||
}
|
||||
|
||||
public int getPosY() {
|
||||
public final int getPosY() {
|
||||
return posY;
|
||||
}
|
||||
|
||||
public int getPosZ() {
|
||||
public final int getPosZ() {
|
||||
return posZ;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TileEntity getTarget(World world) {
|
||||
public final TileEntity getTarget(World world) {
|
||||
return world.getTileEntity(posX, posY, posZ);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2011-2014 SirSengir.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the GNU Lesser Public License v3
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.gnu.org/licenses/lgpl-3.0.txt
|
||||
*
|
||||
* Various Contributors including, but not limited to:
|
||||
* SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges
|
||||
******************************************************************************/
|
||||
package forestry.core.network;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
|
||||
import forestry.core.gadgets.TileForestry;
|
||||
import forestry.core.proxy.Proxies;
|
||||
|
||||
public class PacketErrorUpdate extends PacketCoordinates {
|
||||
|
||||
private TileForestry tileForestry;
|
||||
|
||||
public PacketErrorUpdate(DataInputStream data) throws IOException {
|
||||
super(data);
|
||||
}
|
||||
|
||||
public PacketErrorUpdate(TileForestry tileForestry) {
|
||||
super(PacketId.TILE_FORESTRY_ERROR_UPDATE, tileForestry);
|
||||
this.tileForestry = tileForestry;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void writeData(DataOutputStream data) throws IOException {
|
||||
super.writeData(data);
|
||||
tileForestry.writeErrorData(data);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void readData(DataInputStream data) throws IOException {
|
||||
super.readData(data);
|
||||
|
||||
TileEntity tile = getTarget(Proxies.common.getRenderWorld());
|
||||
if (tile instanceof TileForestry) {
|
||||
((TileForestry) tile).readErrorData(data);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -30,11 +30,13 @@ public class PacketFXSignal extends PacketCoordinates {
|
||||
NONE(""), BLOCK_DESTROY(""), BLOCK_PLACE(""), LEAF("step.grass"), LOG("dig.wood"), DIRT("dig.gravel");
|
||||
|
||||
public final String soundFile;
|
||||
public final float volume = 1.0f;
|
||||
public final float pitch = 1.0f;
|
||||
public final float volume;
|
||||
public final float pitch;
|
||||
|
||||
SoundFXType(String soundFile) {
|
||||
this.soundFile = soundFile;
|
||||
this.volume = 1.0f;
|
||||
this.pitch = 1.0f;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -44,7 +46,8 @@ public class PacketFXSignal extends PacketCoordinates {
|
||||
private Block block;
|
||||
private int meta;
|
||||
|
||||
public PacketFXSignal() {
|
||||
public PacketFXSignal(DataInputStream data) throws IOException {
|
||||
super(data);
|
||||
}
|
||||
|
||||
public PacketFXSignal(VisualFXType type, int xCoord, int yCoord, int zCoord, Block block, int meta) {
|
||||
@@ -56,7 +59,7 @@ public class PacketFXSignal extends PacketCoordinates {
|
||||
}
|
||||
|
||||
public PacketFXSignal(VisualFXType visualFX, SoundFXType soundFX, int xCoord, int yCoord, int zCoord, Block block, int meta) {
|
||||
super(PacketIds.FX_SIGNAL, xCoord, yCoord, zCoord);
|
||||
super(PacketId.FX_SIGNAL, xCoord, yCoord, zCoord);
|
||||
this.visualFX = visualFX;
|
||||
this.soundFX = soundFX;
|
||||
this.block = block;
|
||||
@@ -73,7 +76,7 @@ public class PacketFXSignal extends PacketCoordinates {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readData(DataInputStream data) throws IOException {
|
||||
protected void readData(DataInputStream data) throws IOException {
|
||||
super.readData(data);
|
||||
this.visualFX = VisualFXType.values()[data.readShort()];
|
||||
this.soundFX = SoundFXType.values()[data.readShort()];
|
||||
@@ -95,5 +98,4 @@ public class PacketFXSignal extends PacketCoordinates {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -26,11 +26,12 @@ public class PacketGuiInteger extends ForestryPacket {
|
||||
|
||||
private int windowId, dataId, value;
|
||||
|
||||
public PacketGuiInteger() {
|
||||
super();
|
||||
public PacketGuiInteger(DataInputStream data) throws IOException {
|
||||
super(data);
|
||||
}
|
||||
|
||||
public PacketGuiInteger(int windowId, int dataId, int value) {
|
||||
super(PacketId.GUI_INTEGER);
|
||||
this.windowId = windowId;
|
||||
this.dataId = dataId;
|
||||
this.value = value;
|
||||
@@ -44,7 +45,7 @@ public class PacketGuiInteger extends ForestryPacket {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readData(DataInputStream data) throws IOException {
|
||||
protected void readData(DataInputStream data) throws IOException {
|
||||
windowId = data.readByte();
|
||||
dataId = data.readByte();
|
||||
value = data.readInt();
|
||||
@@ -55,10 +56,4 @@ public class PacketGuiInteger extends ForestryPacket {
|
||||
player.openContainer.updateProgressBar(dataId, value);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getID() {
|
||||
return PacketIds.GUI_INTEGER;
|
||||
}
|
||||
|
||||
}
|
||||
Executable → Regular
+52
-66
@@ -1,66 +1,52 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2011-2014 SirSengir.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the GNU Lesser Public License v3
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.gnu.org/licenses/lgpl-3.0.txt
|
||||
*
|
||||
* Various Contributors including, but not limited to:
|
||||
* SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges
|
||||
******************************************************************************/
|
||||
package forestry.core.network;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public class PacketTileNBT extends PacketNBT implements ILocatedPacket {
|
||||
|
||||
private int posX;
|
||||
private int posY;
|
||||
private int posZ;
|
||||
|
||||
public PacketTileNBT() {
|
||||
}
|
||||
|
||||
public PacketTileNBT(int id, TileEntity tile) {
|
||||
super(id);
|
||||
|
||||
posX = tile.xCoord;
|
||||
posY = tile.yCoord;
|
||||
posZ = tile.zCoord;
|
||||
|
||||
this.nbttagcompound = new NBTTagCompound();
|
||||
tile.writeToNBT(nbttagcompound);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeData(DataOutputStream data) throws IOException {
|
||||
|
||||
data.writeInt(posX);
|
||||
data.writeInt(posY);
|
||||
data.writeInt(posZ);
|
||||
|
||||
super.writeData(data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readData(DataInputStream data) throws IOException {
|
||||
|
||||
posX = data.readInt();
|
||||
posY = data.readInt();
|
||||
posZ = data.readInt();
|
||||
|
||||
super.readData(data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TileEntity getTarget(World world) {
|
||||
return world.getTileEntity(posX, posY, posZ);
|
||||
}
|
||||
|
||||
}
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2011-2014 SirSengir.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the GNU Lesser Public License v3
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.gnu.org/licenses/lgpl-3.0.txt
|
||||
*
|
||||
* Various Contributors including, but not limited to:
|
||||
* SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges
|
||||
******************************************************************************/
|
||||
package forestry.core.network;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
public class PacketGuiSelect extends ForestryPacket {
|
||||
private int primaryIndex;
|
||||
private int secondaryIndex;
|
||||
|
||||
public PacketGuiSelect(DataInputStream data) throws IOException {
|
||||
super(data);
|
||||
}
|
||||
|
||||
public PacketGuiSelect(PacketId id, int primaryIndex, int secondaryIndex) {
|
||||
super(id);
|
||||
this.primaryIndex = primaryIndex;
|
||||
this.secondaryIndex = secondaryIndex;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeData(DataOutputStream data) throws IOException {
|
||||
super.writeData(data);
|
||||
data.writeInt(primaryIndex);
|
||||
data.writeInt(secondaryIndex);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void readData(DataInputStream data) throws IOException {
|
||||
super.readData(data);
|
||||
primaryIndex = data.readInt();
|
||||
secondaryIndex = data.readInt();
|
||||
}
|
||||
|
||||
public int getPrimaryIndex() {
|
||||
return primaryIndex;
|
||||
}
|
||||
|
||||
public int getSecondaryIndex() {
|
||||
return secondaryIndex;
|
||||
}
|
||||
}
|
||||
@@ -35,6 +35,7 @@ import forestry.api.core.ForestryEvent;
|
||||
import forestry.api.genetics.AlleleManager;
|
||||
import forestry.api.genetics.IBreedingTracker;
|
||||
import forestry.api.genetics.ISpeciesRoot;
|
||||
import forestry.core.circuits.ContainerSolderingIron;
|
||||
import forestry.core.circuits.ItemCircuitBoard;
|
||||
import forestry.core.gadgets.TileForestry;
|
||||
import forestry.core.gui.ContainerLiquidTanks;
|
||||
@@ -47,6 +48,8 @@ import forestry.plugins.PluginManager;
|
||||
import io.netty.buffer.ByteBufInputStream;
|
||||
|
||||
public class PacketHandler {
|
||||
private final FMLEventChannel channel;
|
||||
|
||||
public PacketHandler() {
|
||||
channel = NetworkRegistry.INSTANCE.newEventDrivenChannel(ForestryPacket.channel);
|
||||
channel.register(this);
|
||||
@@ -54,101 +57,103 @@ public class PacketHandler {
|
||||
|
||||
@SubscribeEvent
|
||||
public void onPacket(ServerCustomPacketEvent event) {
|
||||
onPacketData(new ByteBufInputStream(event.packet.payload()),
|
||||
((NetHandlerPlayServer) event.handler).playerEntity);
|
||||
onPacketData(event.packet, ((NetHandlerPlayServer) event.handler).playerEntity);
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void onPacket(ClientCustomPacketEvent event) {
|
||||
onPacketData(new ByteBufInputStream(event.packet.payload()), null);
|
||||
onPacketData(event.packet, null);
|
||||
}
|
||||
|
||||
/** Returns true if the packet has been handled */
|
||||
public boolean onPacketData(InputStream is, EntityPlayerMP player) {
|
||||
private static boolean onPacketData(FMLProxyPacket fmlPacket, EntityPlayerMP player) {
|
||||
InputStream is = new ByteBufInputStream(fmlPacket.payload());
|
||||
DataInputStream data = new DataInputStream(is);
|
||||
PacketUpdate packetU;
|
||||
|
||||
try {
|
||||
int packetId = data.readByte();
|
||||
int packetIdOrdinal = data.readByte();
|
||||
if (packetIdOrdinal >= PacketId.VALUES.length) {
|
||||
return false;
|
||||
}
|
||||
PacketId packetId = PacketId.VALUES[packetIdOrdinal];
|
||||
|
||||
switch (packetId) {
|
||||
|
||||
case PacketIds.TILE_FORESTRY_UPDATE:
|
||||
PacketTileUpdate packetT = new PacketTileUpdate();
|
||||
packetT.readData(data);
|
||||
onTileUpdate(packetT);
|
||||
case TILE_FORESTRY_UPDATE: {
|
||||
PacketTileStream packet = new PacketTileStream(data);
|
||||
return true;
|
||||
case PacketIds.TILE_UPDATE:
|
||||
PacketUpdate packetUpdate = new PacketUpdate();
|
||||
packetUpdate.readData(data);
|
||||
onTileUpdate(packetUpdate);
|
||||
}
|
||||
case TILE_FORESTRY_ERROR_UPDATE: {
|
||||
PacketErrorUpdate packet = new PacketErrorUpdate(data);
|
||||
return true;
|
||||
case PacketIds.TILE_NBT:
|
||||
PacketTileNBT packetN = new PacketTileNBT();
|
||||
packetN.readData(data);
|
||||
onTileUpdate(packetN);
|
||||
return true;
|
||||
case PacketIds.SOCKET_UPDATE:
|
||||
PacketSocketUpdate packetS = new PacketSocketUpdate();
|
||||
packetS.readData(data);
|
||||
}
|
||||
case SOCKET_UPDATE: {
|
||||
PacketSocketUpdate packetS = new PacketSocketUpdate(data);
|
||||
onSocketUpdate(packetS);
|
||||
return true;
|
||||
case PacketIds.IINVENTORY_STACK:
|
||||
PacketInventoryStack packetQ = new PacketInventoryStack();
|
||||
packetQ.readData(data);
|
||||
onInventoryStack(packetQ);
|
||||
}
|
||||
case IINVENTORY_STACK: {
|
||||
PacketInventoryStack packet = new PacketInventoryStack(data);
|
||||
onInventoryStack(packet);
|
||||
return true;
|
||||
case PacketIds.FX_SIGNAL:
|
||||
PacketFXSignal packetF = new PacketFXSignal();
|
||||
packetF.readData(data);
|
||||
packetF.executeFX();
|
||||
}
|
||||
case FX_SIGNAL: {
|
||||
PacketFXSignal packet = new PacketFXSignal(data);
|
||||
packet.executeFX();
|
||||
return true;
|
||||
}
|
||||
|
||||
case PacketIds.PIPETTE_CLICK:
|
||||
packetU = new PacketUpdate();
|
||||
packetU.readData(data);
|
||||
onPipetteClick(packetU, player);
|
||||
case PIPETTE_CLICK: {
|
||||
PacketSlotClick packet = new PacketSlotClick(data);
|
||||
onPipetteClick(packet, player);
|
||||
return true;
|
||||
case PacketIds.SOLDERING_IRON_CLICK:
|
||||
packetU = new PacketUpdate();
|
||||
packetU.readData(data);
|
||||
onSolderingIronClick(packetU, player);
|
||||
}
|
||||
case SOLDERING_IRON_CLICK: {
|
||||
PacketSlotClick packet = new PacketSlotClick(data);
|
||||
onSolderingIronClick(packet, player);
|
||||
return true;
|
||||
case PacketIds.CHIPSET_CLICK:
|
||||
packetU = new PacketUpdate();
|
||||
packetU.readData(data);
|
||||
onChipsetClick(packetU, player);
|
||||
}
|
||||
case CHIPSET_CLICK: {
|
||||
PacketSlotClick packet = new PacketSlotClick(data);
|
||||
onChipsetClick(packet, player);
|
||||
return true;
|
||||
case PacketIds.ACCESS_SWITCH:
|
||||
PacketCoordinates packetC = new PacketCoordinates();
|
||||
packetC.readData(data);
|
||||
onAccessSwitch(packetC, player);
|
||||
}
|
||||
case ACCESS_SWITCH: {
|
||||
PacketCoordinates packet = new PacketCoordinates(data);
|
||||
onAccessSwitch(packet, player);
|
||||
return true;
|
||||
case PacketIds.GUI_SELECTION:
|
||||
PacketUpdate packetI = new PacketUpdate();
|
||||
packetI.readData(data);
|
||||
onGuiSelection(packetI);
|
||||
}
|
||||
case GUI_SELECTION_SET: {
|
||||
PacketGuiSelect packet = new PacketGuiSelect(data);
|
||||
onGuiSelection(packet);
|
||||
return true;
|
||||
case PacketIds.GUI_SELECTION_CHANGE:
|
||||
PacketUpdate packetZ = new PacketUpdate();
|
||||
packetZ.readData(data);
|
||||
onGuiChange(player, packetZ);
|
||||
}
|
||||
case GUI_SELECTION_CHANGE: {
|
||||
PacketGuiSelect packet = new PacketGuiSelect(data);
|
||||
onGuiChange(player, packet);
|
||||
return true;
|
||||
case PacketIds.GENOME_TRACKER_UPDATE:
|
||||
PacketNBT packetTR = new PacketNBT();
|
||||
packetTR.readData(data);
|
||||
onGenomeTrackerUpdate(packetTR);
|
||||
}
|
||||
case GUI_LAYOUT_SELECT: {
|
||||
PacketString packet = new PacketString(data);
|
||||
onGuiLayoutSelect(packet);
|
||||
return true;
|
||||
case PacketIds.GUI_INTEGER:
|
||||
PacketGuiInteger packet = new PacketGuiInteger();
|
||||
packet.readData(data);
|
||||
}
|
||||
case GENOME_TRACKER_UPDATE: {
|
||||
PacketNBT packet = new PacketNBT(data);
|
||||
onGenomeTrackerUpdate(packet);
|
||||
return true;
|
||||
default:
|
||||
for (forestry.core.interfaces.IPacketHandler handler : PluginManager.packetHandlers) {
|
||||
}
|
||||
case GUI_INTEGER: {
|
||||
PacketGuiInteger packet = new PacketGuiInteger(data);
|
||||
return true;
|
||||
}
|
||||
default: {
|
||||
for (IPacketHandler handler : PluginManager.packetHandlers) {
|
||||
if (handler.onPacketData(packetId, data, player)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
@@ -157,19 +162,11 @@ public class PacketHandler {
|
||||
return false;
|
||||
}
|
||||
|
||||
public void sendPacket(FMLProxyPacket packet) {
|
||||
if (FMLCommonHandler.instance().getEffectiveSide().isClient()) {
|
||||
channel.sendToServer(packet);
|
||||
} else {
|
||||
channel.sendToAll(packet);
|
||||
}
|
||||
}
|
||||
|
||||
public void sendPacket(FMLProxyPacket packet, EntityPlayerMP player) {
|
||||
channel.sendTo(packet, player);
|
||||
}
|
||||
|
||||
private void onGenomeTrackerUpdate(PacketNBT packet) {
|
||||
private static void onGenomeTrackerUpdate(PacketNBT packet) {
|
||||
assert FMLCommonHandler.instance().getEffectiveSide().isClient();
|
||||
|
||||
EntityPlayer player = Proxies.common.getPlayer();
|
||||
@@ -186,7 +183,7 @@ public class PacketHandler {
|
||||
}
|
||||
}
|
||||
|
||||
private void onGuiChange(EntityPlayer player, PacketUpdate packet) {
|
||||
private static void onGuiChange(EntityPlayer player, PacketGuiSelect packet) {
|
||||
assert FMLCommonHandler.instance().getEffectiveSide().isServer();
|
||||
|
||||
if (!(player.openContainer instanceof IGuiSelectable)) {
|
||||
@@ -196,7 +193,7 @@ public class PacketHandler {
|
||||
((IGuiSelectable) player.openContainer).handleSelectionChange(player, packet);
|
||||
}
|
||||
|
||||
private void onGuiSelection(PacketUpdate packet) {
|
||||
private static void onGuiSelection(PacketGuiSelect packet) {
|
||||
assert FMLCommonHandler.instance().getEffectiveSide().isClient();
|
||||
|
||||
EntityPlayer player = Proxies.common.getPlayer();
|
||||
@@ -207,10 +204,22 @@ public class PacketHandler {
|
||||
}
|
||||
|
||||
((IGuiSelectable) container).setSelection(packet);
|
||||
|
||||
}
|
||||
|
||||
private void onSocketUpdate(PacketSocketUpdate packet) {
|
||||
private static void onGuiLayoutSelect(PacketString packet) {
|
||||
assert FMLCommonHandler.instance().getEffectiveSide().isClient();
|
||||
|
||||
EntityPlayer player = Proxies.common.getPlayer();
|
||||
|
||||
Container container = player.openContainer;
|
||||
if (!(container instanceof ContainerSolderingIron)) {
|
||||
return;
|
||||
}
|
||||
|
||||
((ContainerSolderingIron) container).setLayout(packet.getString());
|
||||
}
|
||||
|
||||
private static void onSocketUpdate(PacketSocketUpdate packet) {
|
||||
assert FMLCommonHandler.instance().getEffectiveSide().isClient();
|
||||
|
||||
TileEntity tile = packet.getTarget(Proxies.common.getRenderWorld());
|
||||
@@ -219,21 +228,12 @@ public class PacketHandler {
|
||||
}
|
||||
|
||||
ISocketable socketable = (ISocketable) tile;
|
||||
for (int i = 0; i < packet.itemstacks.length; i++) {
|
||||
socketable.setSocket(i, packet.itemstacks[i]);
|
||||
for (int i = 0; i < packet.itemStacks.length; i++) {
|
||||
socketable.setSocket(i, packet.itemStacks[i]);
|
||||
}
|
||||
}
|
||||
|
||||
private void onTileUpdate(ForestryPacket packet) {
|
||||
|
||||
TileEntity tile = ((ILocatedPacket) packet).getTarget(Proxies.common.getRenderWorld());
|
||||
if (tile instanceof INetworkedEntity) {
|
||||
((INetworkedEntity) tile).fromPacket(packet);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void onInventoryStack(PacketInventoryStack packet) {
|
||||
private static void onInventoryStack(PacketInventoryStack packet) {
|
||||
|
||||
TileEntity tile = packet.getTarget(Proxies.common.getRenderWorld());
|
||||
if (tile == null) {
|
||||
@@ -245,7 +245,7 @@ public class PacketHandler {
|
||||
}
|
||||
}
|
||||
|
||||
private void onChipsetClick(PacketUpdate packet, EntityPlayer player) {
|
||||
private static void onChipsetClick(PacketSlotClick packet, EntityPlayer player) {
|
||||
assert FMLCommonHandler.instance().getEffectiveSide().isServer();
|
||||
|
||||
if (!(player.openContainer instanceof ContainerSocketed)) {
|
||||
@@ -256,11 +256,10 @@ public class PacketHandler {
|
||||
return;
|
||||
}
|
||||
|
||||
((ContainerSocketed) player.openContainer).handleChipsetClick(packet.payload.intPayload[0], player, itemstack);
|
||||
|
||||
((ContainerSocketed) player.openContainer).handleChipsetClick(packet.getSlot(), player, itemstack);
|
||||
}
|
||||
|
||||
private void onSolderingIronClick(PacketUpdate packet, EntityPlayer player) {
|
||||
private static void onSolderingIronClick(PacketSlotClick packet, EntityPlayer player) {
|
||||
assert FMLCommonHandler.instance().getEffectiveSide().isServer();
|
||||
|
||||
if (!(player.openContainer instanceof ContainerSocketed)) {
|
||||
@@ -268,10 +267,10 @@ public class PacketHandler {
|
||||
}
|
||||
ItemStack itemstack = player.inventory.getItemStack();
|
||||
|
||||
((ContainerSocketed) player.openContainer).handleSolderingIronClick(packet.payload.intPayload[0], player, itemstack);
|
||||
((ContainerSocketed) player.openContainer).handleSolderingIronClick(packet.getSlot(), player, itemstack);
|
||||
}
|
||||
|
||||
private void onAccessSwitch(PacketCoordinates packet, EntityPlayer playerEntity) {
|
||||
private static void onAccessSwitch(PacketCoordinates packet, EntityPlayer playerEntity) {
|
||||
assert FMLCommonHandler.instance().getEffectiveSide().isServer();
|
||||
|
||||
TileForestry tile = (TileForestry) packet.getTarget(playerEntity.worldObj);
|
||||
@@ -282,15 +281,13 @@ public class PacketHandler {
|
||||
tile.switchAccessRule(playerEntity);
|
||||
}
|
||||
|
||||
private void onPipetteClick(PacketUpdate packet, EntityPlayerMP player) {
|
||||
private static void onPipetteClick(PacketSlotClick packet, EntityPlayerMP player) {
|
||||
assert FMLCommonHandler.instance().getEffectiveSide().isServer();
|
||||
|
||||
if (!(player.openContainer instanceof ContainerLiquidTanks)) {
|
||||
return;
|
||||
}
|
||||
|
||||
((ContainerLiquidTanks) player.openContainer).handlePipetteClick(packet.payload.intPayload[0], player);
|
||||
((ContainerLiquidTanks) player.openContainer).handlePipetteClick(packet.getSlot(), player);
|
||||
}
|
||||
|
||||
private final FMLEventChannel channel;
|
||||
}
|
||||
@@ -0,0 +1,161 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2011-2014 SirSengir.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the GNU Lesser Public License v3
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.gnu.org/licenses/lgpl-3.0.txt
|
||||
*
|
||||
* Various Contributors including, but not limited to:
|
||||
* SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges
|
||||
******************************************************************************/
|
||||
package forestry.core.network;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.CompressedStreamTools;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
||||
import cpw.mods.fml.common.registry.GameData;
|
||||
|
||||
import forestry.core.proxy.Proxies;
|
||||
|
||||
public class PacketHelper {
|
||||
|
||||
public static ItemStack readItemStack(DataInputStream data) throws IOException {
|
||||
ItemStack itemstack = null;
|
||||
String itemName = data.readUTF();
|
||||
|
||||
if (!itemName.isEmpty()) {
|
||||
Item item = GameData.getItemRegistry().getRaw(itemName);
|
||||
byte stackSize = data.readByte();
|
||||
short meta = data.readShort();
|
||||
itemstack = new ItemStack(item, stackSize, meta);
|
||||
|
||||
if (item.isDamageable() || item.getShareTag()) {
|
||||
itemstack.stackTagCompound = readNBTTagCompound(data);
|
||||
}
|
||||
}
|
||||
|
||||
return itemstack;
|
||||
}
|
||||
|
||||
public static void writeItemStack(ItemStack itemstack, DataOutputStream data) throws IOException {
|
||||
|
||||
if (itemstack == null) {
|
||||
data.writeUTF("");
|
||||
} else {
|
||||
data.writeUTF(GameData.getItemRegistry().getNameForObject(itemstack.getItem()));
|
||||
data.writeByte(itemstack.stackSize);
|
||||
data.writeShort(itemstack.getItemDamage());
|
||||
|
||||
if (itemstack.getItem().isDamageable() || itemstack.getItem().getShareTag()) {
|
||||
writeNBTTagCompound(itemstack.stackTagCompound, data);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static ItemStack[] readItemStacks(DataInputStream data) throws IOException {
|
||||
int stackCount = data.readShort();
|
||||
ItemStack[] itemStacks = new ItemStack[stackCount];
|
||||
for (int i = 0; i < stackCount; i++) {
|
||||
itemStacks[i] = PacketHelper.readItemStack(data);
|
||||
}
|
||||
return itemStacks;
|
||||
}
|
||||
|
||||
public static void writeItemStacks(ItemStack[] itemStacks, DataOutputStream data) throws IOException {
|
||||
data.writeShort(itemStacks.length);
|
||||
for (ItemStack itemstack : itemStacks) {
|
||||
PacketHelper.writeItemStack(itemstack, data);
|
||||
}
|
||||
}
|
||||
|
||||
public static void writeInventory(IInventory inventory, DataOutputStream data) throws IOException {
|
||||
int size = inventory.getSizeInventory();
|
||||
data.writeShort(size);
|
||||
|
||||
for (int i = 0; i < size; i++) {
|
||||
ItemStack stack = inventory.getStackInSlot(i);
|
||||
PacketHelper.writeItemStack(stack, data);
|
||||
}
|
||||
}
|
||||
|
||||
public static void readInventory(IInventory inventory, DataInputStream data) throws IOException {
|
||||
int size = data.readShort();
|
||||
|
||||
for (int i = 0; i < size; i++) {
|
||||
ItemStack stack = PacketHelper.readItemStack(data);
|
||||
inventory.setInventorySlotContents(i, stack);
|
||||
}
|
||||
}
|
||||
|
||||
public static <T extends IStreamable> void writeStreamables(List<T> streamables, DataOutputStream data) throws IOException {
|
||||
if (streamables == null) {
|
||||
data.writeInt(0);
|
||||
} else {
|
||||
data.writeInt(streamables.size());
|
||||
for (IStreamable streamable : streamables) {
|
||||
if (streamable != null) {
|
||||
data.writeBoolean(true);
|
||||
streamable.writeData(data);
|
||||
} else {
|
||||
data.writeBoolean(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static <T extends IStreamable> List<T> readStreamables(Class<T> streamableClass, DataInputStream data) throws IOException {
|
||||
int length = data.readInt();
|
||||
List<T> streamables = new ArrayList<T>(length);
|
||||
|
||||
try {
|
||||
if (length > 0) {
|
||||
for (int i = 0; i < length; i++) {
|
||||
if (data.readBoolean()) {
|
||||
T streamable = streamableClass.newInstance();
|
||||
streamable.readData(data);
|
||||
streamables.add(streamable);
|
||||
} else {
|
||||
streamables.add(null);
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (ReflectiveOperationException e) {
|
||||
Proxies.log.severe("Failed to read Streamables for class " + streamableClass + " with error " + e);
|
||||
}
|
||||
return streamables;
|
||||
}
|
||||
|
||||
private static NBTTagCompound readNBTTagCompound(DataInputStream data) throws IOException {
|
||||
|
||||
short length = data.readShort();
|
||||
|
||||
if (length < 0) {
|
||||
return null;
|
||||
} else {
|
||||
byte[] compressed = new byte[length];
|
||||
data.readFully(compressed);
|
||||
return CompressedStreamTools.readCompressed(new ByteArrayInputStream(compressed));
|
||||
}
|
||||
}
|
||||
|
||||
private static void writeNBTTagCompound(NBTTagCompound nbttagcompound, DataOutputStream data) throws IOException {
|
||||
|
||||
if (nbttagcompound == null) {
|
||||
data.writeShort(-1);
|
||||
} else {
|
||||
byte[] compressed = CompressedStreamTools.compress(nbttagcompound);
|
||||
data.writeShort((short) compressed.length);
|
||||
data.write(compressed);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2011-2014 SirSengir.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the GNU Lesser Public License v3
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.gnu.org/licenses/lgpl-3.0.txt
|
||||
*
|
||||
* Various Contributors including, but not limited to:
|
||||
* SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges
|
||||
******************************************************************************/
|
||||
package forestry.core.network;
|
||||
|
||||
public enum PacketId {
|
||||
INVALID,
|
||||
|
||||
TILE_FORESTRY_UPDATE,
|
||||
TILE_FORESTRY_ERROR_UPDATE,
|
||||
IINVENTORY_STACK,
|
||||
FX_SIGNAL,
|
||||
|
||||
HABITAT_BIOME_POINTER,
|
||||
CANDLE,
|
||||
|
||||
GUI_SELECTION_CHANGE,
|
||||
IMPRINT_SELECTION_GET,
|
||||
GUI_SELECTION_SET,
|
||||
|
||||
GUI_LAYOUT_SELECT,
|
||||
|
||||
PIPETTE_CLICK,
|
||||
|
||||
ACCESS_SWITCH,
|
||||
|
||||
GENOME_TRACKER_UPDATE,
|
||||
GAME_TOKEN_SET,
|
||||
|
||||
CHIPSET_CLICK,
|
||||
SOLDERING_IRON_CLICK,
|
||||
SOCKET_UPDATE,
|
||||
|
||||
LETTER_REQUEST_INFO,
|
||||
LETTER_TEXT,
|
||||
TRADING_ADDRESS_SET,
|
||||
LETTER_INFO,
|
||||
POBOX_INFO,
|
||||
POBOX_INFO_REQUEST,
|
||||
|
||||
RIPENING_UPDATE,
|
||||
|
||||
GUI_INTEGER,
|
||||
|
||||
// Propolis pipe
|
||||
PROP_SEND_FILTER_SET,
|
||||
PROP_REQUEST_FILTER_SET,
|
||||
PROP_SEND_FILTER_CHANGE_GENOME,
|
||||
PROP_SEND_FILTER_CHANGE_TYPE
|
||||
;
|
||||
|
||||
public static final PacketId[] VALUES = values();
|
||||
}
|
||||
@@ -1,63 +0,0 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2011-2014 SirSengir.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the GNU Lesser Public License v3
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.gnu.org/licenses/lgpl-3.0.txt
|
||||
*
|
||||
* Various Contributors including, but not limited to:
|
||||
* SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges
|
||||
******************************************************************************/
|
||||
package forestry.core.network;
|
||||
|
||||
/**
|
||||
* Valid ids: 0 - 127
|
||||
*/
|
||||
public class PacketIds {
|
||||
|
||||
public static final int TILE_FORESTRY_UPDATE = 0;
|
||||
public static final int TILE_UPDATE = 1;
|
||||
public static final int TILE_DESCRIPTION = 2;
|
||||
public static final int IINVENTORY_STACK = 3;
|
||||
public static final int FX_SIGNAL = 4;
|
||||
public static final int TILE_NBT = 5;
|
||||
|
||||
public static final int HABITAT_BIOME_POINTER = 20;
|
||||
public static final int CANDLE = 21;
|
||||
|
||||
public static final int GUI_SELECTION_CHANGE = 30;
|
||||
public static final int IMPRINT_SELECTION_GET = 31;
|
||||
public static final int GUI_SELECTION = 32;
|
||||
|
||||
public static final int PIPETTE_CLICK = 40;
|
||||
|
||||
public static final int ACCESS_SWITCH = 50;
|
||||
|
||||
public static final int GENOME_TRACKER_UPDATE = 60;
|
||||
public static final int GAME_TOKEN_SET = 61;
|
||||
|
||||
public static final int CHIPSET_CLICK = 70;
|
||||
public static final int SOLDERING_IRON_CLICK = 71;
|
||||
public static final int SOCKET_UPDATE = 72;
|
||||
|
||||
public static final int LETTER_RECIPIENT = 80;
|
||||
public static final int LETTER_TEXT = 81;
|
||||
public static final int TRADING_ADDRESS_SET = 82;
|
||||
public static final int LETTER_INFO = 83;
|
||||
public static final int POBOX_INFO = 85;
|
||||
public static final int POBOX_INFO_REQUEST = 86;
|
||||
|
||||
public static final int SAPLING = 89;
|
||||
public static final int LEAF = 90;
|
||||
public static final int RIPENING_UPDATE = 91;
|
||||
|
||||
public static final int GUI_INTEGER = 92;
|
||||
|
||||
// Propolis pipe
|
||||
public static final int PROP_SEND_FILTER_SET = 100;
|
||||
public static final int PROP_REQUEST_FILTER_SET = 101;
|
||||
public static final int PROP_SEND_FILTER_CHANGE_GENOME = 102;
|
||||
public static final int PROP_SEND_FILTER_CHANGE_TYPE = 103;
|
||||
|
||||
|
||||
}
|
||||
@@ -21,27 +21,27 @@ public class PacketInventoryStack extends PacketCoordinates {
|
||||
public int slotIndex;
|
||||
public ItemStack itemstack;
|
||||
|
||||
public PacketInventoryStack() {
|
||||
public PacketInventoryStack(DataInputStream data) throws IOException {
|
||||
super(data);
|
||||
}
|
||||
|
||||
public PacketInventoryStack(int id, int posX, int posY, int posZ, int slotIndex, ItemStack itemstack) {
|
||||
public PacketInventoryStack(PacketId id, int posX, int posY, int posZ, int slotIndex, ItemStack itemstack) {
|
||||
super(id, posX, posY, posZ);
|
||||
this.slotIndex = slotIndex;
|
||||
this.itemstack = itemstack;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeData(DataOutputStream data) throws IOException {
|
||||
protected void writeData(DataOutputStream data) throws IOException {
|
||||
super.writeData(data);
|
||||
data.writeInt(slotIndex);
|
||||
writeItemStack(itemstack, data);
|
||||
PacketHelper.writeItemStack(itemstack, data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readData(DataInputStream data) throws IOException {
|
||||
protected void readData(DataInputStream data) throws IOException {
|
||||
super.readData(data);
|
||||
slotIndex = data.readInt();
|
||||
itemstack = readItemStack(data);
|
||||
itemstack = PacketHelper.readItemStack(data);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -22,14 +22,11 @@ public class PacketNBT extends ForestryPacket {
|
||||
|
||||
protected NBTTagCompound nbttagcompound;
|
||||
|
||||
public PacketNBT() {
|
||||
public PacketNBT(DataInputStream data) throws IOException {
|
||||
super(data);
|
||||
}
|
||||
|
||||
public PacketNBT(int id) {
|
||||
super(id);
|
||||
}
|
||||
|
||||
public PacketNBT(int id, NBTTagCompound nbttagcompound) {
|
||||
public PacketNBT(PacketId id, NBTTagCompound nbttagcompound) {
|
||||
super(id);
|
||||
this.nbttagcompound = nbttagcompound;
|
||||
}
|
||||
@@ -42,7 +39,7 @@ public class PacketNBT extends ForestryPacket {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readData(DataInputStream data) throws IOException {
|
||||
protected void readData(DataInputStream data) throws IOException {
|
||||
short length = data.readShort();
|
||||
byte[] compressed = new byte[length];
|
||||
data.readFully(compressed);
|
||||
|
||||
@@ -1,66 +0,0 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2011-2014 SirSengir.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the GNU Lesser Public License v3
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.gnu.org/licenses/lgpl-3.0.txt
|
||||
*
|
||||
* Various Contributors including, but not limited to:
|
||||
* SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges
|
||||
******************************************************************************/
|
||||
package forestry.core.network;
|
||||
|
||||
import forestry.core.utils.Utils;
|
||||
|
||||
public class PacketPayload {
|
||||
public int[] intPayload = new int[0];
|
||||
public short[] shortPayload = new short[0];
|
||||
public float[] floatPayload = new float[0];
|
||||
public String[] stringPayload = new String[0];
|
||||
|
||||
public PacketPayload() {
|
||||
}
|
||||
|
||||
public PacketPayload(int intSize, int floatSize, int stringSize) {
|
||||
intPayload = new int[intSize];
|
||||
floatPayload = new float[floatSize];
|
||||
stringPayload = new String[stringSize];
|
||||
}
|
||||
|
||||
public PacketPayload(int intSize, int shortSize) {
|
||||
intPayload = new int[intSize];
|
||||
shortPayload = new short[shortSize];
|
||||
}
|
||||
|
||||
public void append(PacketPayload other) {
|
||||
if (other == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (other.intPayload.length > 0) {
|
||||
this.intPayload = Utils.concat(this.intPayload, other.intPayload);
|
||||
}
|
||||
if (other.shortPayload.length > 0) {
|
||||
this.shortPayload = Utils.concat(this.shortPayload, other.shortPayload);
|
||||
}
|
||||
if (other.floatPayload.length > 0) {
|
||||
this.floatPayload = Utils.concat(this.floatPayload, other.floatPayload);
|
||||
}
|
||||
if (other.stringPayload.length > 0) {
|
||||
this.stringPayload = Utils.concat(this.stringPayload, other.stringPayload);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void append(int[] other) {
|
||||
if (other == null || other.length < 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.intPayload = Utils.concat(this.intPayload, other);
|
||||
}
|
||||
|
||||
public boolean isEmpty() {
|
||||
return intPayload.length == 0 && shortPayload.length == 0 && floatPayload.length == 0 && stringPayload.length == 0;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2011-2014 SirSengir.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the GNU Lesser Public License v3
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.gnu.org/licenses/lgpl-3.0.txt
|
||||
*
|
||||
* Various Contributors including, but not limited to:
|
||||
* SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges
|
||||
******************************************************************************/
|
||||
package forestry.core.network;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
|
||||
public class PacketSlotClick extends PacketCoordinates {
|
||||
private int slot;
|
||||
|
||||
public PacketSlotClick(DataInputStream data) throws IOException {
|
||||
super(data);
|
||||
}
|
||||
|
||||
public PacketSlotClick(PacketId id, TileEntity tile, int slot) {
|
||||
super(id, tile);
|
||||
this.slot = slot;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void readData(DataInputStream data) throws IOException {
|
||||
super.readData(data);
|
||||
this.slot = data.readInt();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void writeData(DataOutputStream data) throws IOException {
|
||||
super.writeData(data);
|
||||
data.writeInt(slot);
|
||||
}
|
||||
|
||||
public int getSlot() {
|
||||
return slot;
|
||||
}
|
||||
}
|
||||
@@ -16,42 +16,37 @@ import java.io.IOException;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import forestry.core.gadgets.TileForestry;
|
||||
import forestry.core.interfaces.ISocketable;
|
||||
|
||||
public class PacketSocketUpdate extends PacketCoordinates {
|
||||
|
||||
public ItemStack[] itemstacks;
|
||||
public ItemStack[] itemStacks;
|
||||
|
||||
public PacketSocketUpdate() {
|
||||
public PacketSocketUpdate(DataInputStream data) throws IOException {
|
||||
super(data);
|
||||
}
|
||||
|
||||
public PacketSocketUpdate(int id, int posX, int posY, int posZ, ISocketable tile) {
|
||||
super(id, posX, posY, posZ);
|
||||
public <T extends TileForestry & ISocketable> PacketSocketUpdate(PacketId id, T tile) {
|
||||
super(id, tile);
|
||||
|
||||
itemstacks = new ItemStack[tile.getSocketCount()];
|
||||
itemStacks = new ItemStack[tile.getSocketCount()];
|
||||
for (int i = 0; i < tile.getSocketCount(); i++) {
|
||||
itemstacks[i] = tile.getSocket(i);
|
||||
itemStacks[i] = tile.getSocket(i);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeData(DataOutputStream data) throws IOException {
|
||||
protected void writeData(DataOutputStream data) throws IOException {
|
||||
super.writeData(data);
|
||||
|
||||
data.writeShort(itemstacks.length);
|
||||
for (ItemStack itemstack : itemstacks) {
|
||||
writeItemStack(itemstack, data);
|
||||
}
|
||||
PacketHelper.writeItemStacks(itemStacks, data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readData(DataInputStream data) throws IOException {
|
||||
protected void readData(DataInputStream data) throws IOException {
|
||||
super.readData(data);
|
||||
|
||||
int sockets = data.readShort();
|
||||
itemstacks = new ItemStack[sockets];
|
||||
for (int i = 0; i < sockets; i++) {
|
||||
itemstacks[i] = readItemStack(data);
|
||||
}
|
||||
itemStacks = PacketHelper.readItemStacks(data);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2011-2014 SirSengir.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the GNU Lesser Public License v3
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.gnu.org/licenses/lgpl-3.0.txt
|
||||
*
|
||||
* Various Contributors including, but not limited to:
|
||||
* SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges
|
||||
******************************************************************************/
|
||||
package forestry.core.network;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
public class PacketString extends ForestryPacket {
|
||||
|
||||
private String string;
|
||||
|
||||
public PacketString(DataInputStream data) throws IOException {
|
||||
super(data);
|
||||
}
|
||||
|
||||
public PacketString(PacketId id, String string) {
|
||||
super(id);
|
||||
this.string = string;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void writeData(DataOutputStream data) throws IOException {
|
||||
super.writeData(data);
|
||||
data.writeUTF(string);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void readData(DataInputStream data) throws IOException {
|
||||
super.readData(data);
|
||||
string = data.readUTF();
|
||||
}
|
||||
|
||||
public String getString() {
|
||||
return string;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2011-2014 SirSengir.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the GNU Lesser Public License v3
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.gnu.org/licenses/lgpl-3.0.txt
|
||||
*
|
||||
* Various Contributors including, but not limited to:
|
||||
* SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges
|
||||
******************************************************************************/
|
||||
package forestry.core.network;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
|
||||
import forestry.core.proxy.Proxies;
|
||||
|
||||
public class PacketTileStream extends PacketCoordinates {
|
||||
|
||||
private IStreamable streamable;
|
||||
|
||||
public PacketTileStream(DataInputStream data) throws IOException {
|
||||
super(data);
|
||||
}
|
||||
|
||||
public <T extends TileEntity & IStreamable> PacketTileStream(T streamable) {
|
||||
super(PacketId.TILE_FORESTRY_UPDATE, streamable);
|
||||
this.streamable = streamable;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void writeData(DataOutputStream data) throws IOException {
|
||||
super.writeData(data);
|
||||
streamable.writeData(data);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void readData(DataInputStream data) throws IOException {
|
||||
super.readData(data);
|
||||
|
||||
TileEntity tile = getTarget(Proxies.common.getRenderWorld());
|
||||
if (tile instanceof IStreamable) {
|
||||
((IStreamable) tile).readData(data);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,123 +0,0 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2011-2014 SirSengir.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the GNU Lesser Public License v3
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.gnu.org/licenses/lgpl-3.0.txt
|
||||
*
|
||||
* Various Contributors including, but not limited to:
|
||||
* SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges
|
||||
******************************************************************************/
|
||||
package forestry.core.network;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
import com.mojang.authlib.GameProfile;
|
||||
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
import forestry.api.core.ErrorStateRegistry;
|
||||
import forestry.api.core.IErrorState;
|
||||
import forestry.core.gadgets.TileForestry;
|
||||
import forestry.core.utils.EnumAccess;
|
||||
|
||||
public class PacketTileUpdate extends PacketUpdate {
|
||||
|
||||
private ForgeDirection orientation = ForgeDirection.WEST;
|
||||
private final Set<IErrorState> errorStates;
|
||||
|
||||
private boolean isOwnable = false;
|
||||
private EnumAccess access = EnumAccess.SHARED;
|
||||
private GameProfile owner = null;
|
||||
|
||||
public PacketTileUpdate() {
|
||||
errorStates = new HashSet<IErrorState>();
|
||||
}
|
||||
|
||||
public PacketTileUpdate(TileForestry tile) {
|
||||
super(PacketIds.TILE_FORESTRY_UPDATE, tile);
|
||||
|
||||
orientation = tile.getOrientation();
|
||||
errorStates = tile.getErrorStates();
|
||||
|
||||
isOwnable = tile.isOwnable();
|
||||
access = tile.getAccess();
|
||||
owner = tile.getOwnerProfile();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeData(DataOutputStream data) throws IOException {
|
||||
super.writeData(data);
|
||||
|
||||
data.writeByte(orientation.ordinal());
|
||||
|
||||
data.writeShort(errorStates.size());
|
||||
for (IErrorState errorState : errorStates) {
|
||||
data.writeShort(errorState.getID());
|
||||
}
|
||||
|
||||
// TODO: Should this really be sent to the client? Huge network cost.
|
||||
// As far as I know, only GUIs need it, and there are better ways to get the information to a GUI.
|
||||
// -CovertJaguar
|
||||
if (isOwnable) {
|
||||
data.writeByte(access.ordinal());
|
||||
if (owner == null) {
|
||||
data.writeBoolean(false);
|
||||
} else {
|
||||
data.writeBoolean(true);
|
||||
data.writeLong(owner.getId().getMostSignificantBits());
|
||||
data.writeLong(owner.getId().getLeastSignificantBits());
|
||||
data.writeUTF(owner.getName());
|
||||
}
|
||||
} else {
|
||||
data.writeInt(-1);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readData(DataInputStream data) throws IOException {
|
||||
super.readData(data);
|
||||
|
||||
orientation = ForgeDirection.getOrientation(data.readByte());
|
||||
|
||||
short errorStateCount = data.readShort();
|
||||
for (int i = 0; i < errorStateCount; i++) {
|
||||
short errorStateId = data.readShort();
|
||||
IErrorState errorState = ErrorStateRegistry.getErrorState(errorStateId);
|
||||
errorStates.add(errorState);
|
||||
}
|
||||
|
||||
int ordinal = data.readByte();
|
||||
isOwnable = ordinal >= 0;
|
||||
if (isOwnable) {
|
||||
access = EnumAccess.values()[ordinal];
|
||||
|
||||
if (data.readBoolean()) {
|
||||
owner = new GameProfile(new UUID(data.readLong(), data.readLong()), data.readUTF());
|
||||
} else {
|
||||
owner = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public ForgeDirection getOrientation() {
|
||||
return orientation;
|
||||
}
|
||||
|
||||
public Set<IErrorState> getErrorStates() {
|
||||
return errorStates;
|
||||
}
|
||||
|
||||
public EnumAccess getAccess() {
|
||||
return access;
|
||||
}
|
||||
|
||||
public GameProfile getOwner() {
|
||||
return owner;
|
||||
}
|
||||
}
|
||||
@@ -1,120 +0,0 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2011-2014 SirSengir.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the GNU Lesser Public License v3
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.gnu.org/licenses/lgpl-3.0.txt
|
||||
*
|
||||
* Various Contributors including, but not limited to:
|
||||
* SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges
|
||||
******************************************************************************/
|
||||
package forestry.core.network;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
import forestry.core.gadgets.TileForestry;
|
||||
|
||||
public class PacketUpdate extends PacketCoordinates {
|
||||
|
||||
public PacketPayload payload;
|
||||
|
||||
public PacketUpdate() {
|
||||
}
|
||||
|
||||
public PacketUpdate(int id) {
|
||||
this(id, 0, 0, 0, null);
|
||||
}
|
||||
|
||||
public PacketUpdate(int id, TileForestry tile) {
|
||||
super(id, tile);
|
||||
this.payload = tile.getPacketPayload();
|
||||
}
|
||||
|
||||
public PacketUpdate(int id, PacketPayload payload) {
|
||||
this(id, 0, 0, 0, payload);
|
||||
}
|
||||
|
||||
public PacketUpdate(int id, int posX, int posY, int posZ, PacketPayload payload) {
|
||||
super(id, posX, posY, posZ);
|
||||
|
||||
this.payload = payload;
|
||||
}
|
||||
|
||||
public PacketUpdate(int id, int posX, int posY, int posZ, short val) {
|
||||
super(id, posX, posY, posZ);
|
||||
|
||||
this.payload = new PacketPayload(0, 1);
|
||||
this.payload.shortPayload[0] = val;
|
||||
}
|
||||
|
||||
public PacketUpdate(int id, int posX, int posY, int posZ, int val) {
|
||||
super(id, posX, posY, posZ);
|
||||
|
||||
this.payload = new PacketPayload(1, 0);
|
||||
this.payload.intPayload[0] = val;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeData(DataOutputStream data) throws IOException {
|
||||
|
||||
super.writeData(data);
|
||||
|
||||
// No payload means no data
|
||||
if (payload == null) {
|
||||
data.writeInt(0);
|
||||
data.writeInt(0);
|
||||
data.writeInt(0);
|
||||
data.writeInt(0);
|
||||
return;
|
||||
}
|
||||
|
||||
data.writeInt(payload.intPayload.length);
|
||||
data.writeInt(payload.shortPayload.length);
|
||||
data.writeInt(payload.floatPayload.length);
|
||||
data.writeInt(payload.stringPayload.length);
|
||||
|
||||
for (int intData : payload.intPayload) {
|
||||
data.writeInt(intData);
|
||||
}
|
||||
for (int shortData : payload.shortPayload) {
|
||||
data.writeShort(shortData);
|
||||
}
|
||||
for (float floatData : payload.floatPayload) {
|
||||
data.writeFloat(floatData);
|
||||
}
|
||||
for (String stringData : payload.stringPayload) {
|
||||
data.writeUTF(stringData);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readData(DataInputStream data) throws IOException {
|
||||
|
||||
super.readData(data);
|
||||
|
||||
payload = new PacketPayload();
|
||||
|
||||
payload.intPayload = new int[data.readInt()];
|
||||
payload.shortPayload = new short[data.readInt()];
|
||||
payload.floatPayload = new float[data.readInt()];
|
||||
payload.stringPayload = new String[data.readInt()];
|
||||
|
||||
for (int i = 0; i < payload.intPayload.length; i++) {
|
||||
payload.intPayload[i] = data.readInt();
|
||||
}
|
||||
for (int i = 0; i < payload.shortPayload.length; i++) {
|
||||
payload.shortPayload[i] = data.readShort();
|
||||
}
|
||||
for (int i = 0; i < payload.floatPayload.length; i++) {
|
||||
payload.floatPayload[i] = data.readFloat();
|
||||
}
|
||||
for (int i = 0; i < payload.stringPayload.length; i++) {
|
||||
payload.stringPayload[i] = data.readUTF();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -55,7 +55,7 @@ import forestry.core.config.ForestryBlock;
|
||||
import forestry.core.config.ForestryItem;
|
||||
import forestry.core.network.PacketCoordinates;
|
||||
import forestry.core.network.PacketFXSignal;
|
||||
import forestry.core.network.PacketIds;
|
||||
import forestry.core.network.PacketId;
|
||||
import forestry.core.render.SpriteSheet;
|
||||
import forestry.core.utils.StringUtil;
|
||||
import forestry.plugins.PluginManager;
|
||||
@@ -145,7 +145,7 @@ public class ProxyCommon {
|
||||
|
||||
public void setHabitatLocatorCoordinates(Entity player, ChunkCoordinates coordinates) {
|
||||
if (coordinates != null) {
|
||||
Forestry.packetHandler.sendPacket(new PacketCoordinates(PacketIds.HABITAT_BIOME_POINTER, coordinates).getPacket(), (EntityPlayerMP) player);
|
||||
Forestry.packetHandler.sendPacket(new PacketCoordinates(PacketId.HABITAT_BIOME_POINTER, coordinates).getPacket(), (EntityPlayerMP) player);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -203,7 +203,7 @@ public class ProxyCommon {
|
||||
}
|
||||
|
||||
public void playSoundFX(World world, int x, int y, int z, Block block) {
|
||||
Proxies.net.sendNetworkPacket(new PacketFXSignal(PacketFXSignal.SoundFXType.LEAF, x, y, z, block, 0), x, y, z);
|
||||
Proxies.net.sendNetworkPacket(new PacketFXSignal(PacketFXSignal.SoundFXType.LEAF, x, y, z, block, 0));
|
||||
}
|
||||
|
||||
public void playSoundFX(World world, int x, int y, int z, String sound, float volume, float pitch) {
|
||||
@@ -235,7 +235,7 @@ public class ProxyCommon {
|
||||
public void sendFXSignal(PacketFXSignal.VisualFXType visualFX, PacketFXSignal.SoundFXType soundFX, World world, int xCoord, int yCoord, int zCoord,
|
||||
Block block, int i) {
|
||||
if (Proxies.common.isSimulating(world)) {
|
||||
Proxies.net.sendNetworkPacket(new PacketFXSignal(visualFX, soundFX, xCoord, yCoord, zCoord, block, i), xCoord, yCoord, zCoord);
|
||||
Proxies.net.sendNetworkPacket(new PacketFXSignal(visualFX, soundFX, xCoord, yCoord, zCoord, block, i));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -20,27 +20,35 @@ import net.minecraftforge.common.util.FakePlayer;
|
||||
import forestry.Forestry;
|
||||
import forestry.core.config.Defaults;
|
||||
import forestry.core.network.ForestryPacket;
|
||||
import forestry.core.network.ILocatedPacket;
|
||||
|
||||
public class ProxyNetwork {
|
||||
|
||||
public void sendNetworkPacket(ForestryPacket packet, int x, int y, int z) {
|
||||
public <P extends ForestryPacket & ILocatedPacket> void sendNetworkPacket(P packet) {
|
||||
if (packet == null) {
|
||||
return;
|
||||
}
|
||||
int x = packet.getPosX();
|
||||
int y = packet.getPosY();
|
||||
int z = packet.getPosZ();
|
||||
|
||||
World[] worlds = DimensionManager.getWorlds();
|
||||
for (World world : worlds) {
|
||||
for (int j = 0; j < world.playerEntities.size(); j++) {
|
||||
EntityPlayerMP player = (EntityPlayerMP) world.playerEntities.get(j);
|
||||
|
||||
if (Math.abs(player.posX - x) <= Defaults.NET_MAX_UPDATE_DISTANCE && Math.abs(player.posY - y) <= Defaults.NET_MAX_UPDATE_DISTANCE
|
||||
&& Math.abs(player.posZ - z) <= Defaults.NET_MAX_UPDATE_DISTANCE) {
|
||||
if (isPlayerInRange(player, x, y, z)) {
|
||||
Forestry.packetHandler.sendPacket(packet.getPacket(), player);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean isPlayerInRange(EntityPlayerMP player, int x, int y, int z) {
|
||||
return Math.abs(player.posX - x) <= Defaults.NET_MAX_UPDATE_DISTANCE &&
|
||||
Math.abs(player.posY - y) <= Defaults.NET_MAX_UPDATE_DISTANCE &&
|
||||
Math.abs(player.posZ - z) <= Defaults.NET_MAX_UPDATE_DISTANCE;
|
||||
}
|
||||
|
||||
public void sendToPlayer(ForestryPacket packet, EntityPlayer entityplayer) {
|
||||
if (!(entityplayer instanceof EntityPlayerMP) || (entityplayer instanceof FakePlayer)) {
|
||||
return;
|
||||
|
||||
@@ -26,7 +26,7 @@ public class PlayerUtil {
|
||||
}
|
||||
|
||||
public static String getOwnerName(IOwnable ownable) {
|
||||
GameProfile profile = ownable.getOwnerProfile();
|
||||
GameProfile profile = ownable.getOwner();
|
||||
if (profile == null) {
|
||||
return StringUtil.localize("gui.derelict");
|
||||
} else {
|
||||
|
||||
@@ -102,7 +102,7 @@ public class StringUtil {
|
||||
public static String line(int length) {
|
||||
StringBuilder line = new StringBuilder();
|
||||
for (int i = 0; i < length; i++) {
|
||||
line.append("-");
|
||||
line.append('-');
|
||||
}
|
||||
|
||||
return line.toString();
|
||||
|
||||
@@ -10,7 +10,6 @@
|
||||
******************************************************************************/
|
||||
package forestry.core.utils;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Random;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
@@ -25,7 +24,6 @@ import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.MathHelper;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.biome.BiomeGenBase;
|
||||
|
||||
import cpw.mods.fml.common.registry.EntityRegistry;
|
||||
|
||||
@@ -104,30 +102,6 @@ public class Utils {
|
||||
|
||||
}
|
||||
|
||||
public static <T> T[] concat(T[] first, T[] second) {
|
||||
T[] result = Arrays.copyOf(first, first.length + second.length);
|
||||
System.arraycopy(second, 0, result, first.length, second.length);
|
||||
return result;
|
||||
}
|
||||
|
||||
public static int[] concat(int[] first, int[] second) {
|
||||
int[] result = Arrays.copyOf(first, first.length + second.length);
|
||||
System.arraycopy(second, 0, result, first.length, second.length);
|
||||
return result;
|
||||
}
|
||||
|
||||
public static short[] concat(short[] first, short[] second) {
|
||||
short[] result = Arrays.copyOf(first, first.length + second.length);
|
||||
System.arraycopy(second, 0, result, first.length, second.length);
|
||||
return result;
|
||||
}
|
||||
|
||||
public static float[] concat(float[] first, float[] second) {
|
||||
float[] result = Arrays.copyOf(first, first.length + second.length);
|
||||
System.arraycopy(second, 0, result, first.length, second.length);
|
||||
return result;
|
||||
}
|
||||
|
||||
public static boolean canWrench(EntityPlayer player, int x, int y, int z) {
|
||||
|
||||
ItemStack itemstack = player.getCurrentEquippedItem();
|
||||
|
||||
@@ -1,18 +1,23 @@
|
||||
package forestry.energy;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
import forestry.core.GameMode;
|
||||
import forestry.core.network.IStreamable;
|
||||
import forestry.core.utils.BlockUtil;
|
||||
|
||||
import cofh.api.energy.EnergyStorage;
|
||||
import cofh.api.energy.IEnergyHandler;
|
||||
import cofh.api.energy.IEnergyReceiver;
|
||||
|
||||
public class EnergyManager implements IEnergyHandler {
|
||||
public class EnergyManager implements IEnergyHandler, IStreamable {
|
||||
private enum EnergyTransferMode {
|
||||
EXTRACT, RECEIVE, BOTH
|
||||
}
|
||||
@@ -79,11 +84,23 @@ public class EnergyManager implements IEnergyHandler {
|
||||
}
|
||||
|
||||
/* Packets */
|
||||
public int toPacketInt() {
|
||||
@Override
|
||||
public void writeData(DataOutputStream data) throws IOException {
|
||||
int energyStored = energyStorage.getEnergyStored();
|
||||
data.writeInt(energyStored);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readData(DataInputStream data) throws IOException {
|
||||
int energyStored = data.readInt();
|
||||
energyStorage.setEnergyStored(energyStored);
|
||||
}
|
||||
|
||||
public int toGuiInt() {
|
||||
return energyStorage.getEnergyStored();
|
||||
}
|
||||
|
||||
public void fromPacketInt(int packetInt) {
|
||||
public void fromGuiInt(int packetInt) {
|
||||
energyStorage.setEnergyStored(packetInt);
|
||||
}
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@ import net.minecraft.world.World;
|
||||
|
||||
import forestry.core.GuiHandlerBase;
|
||||
import forestry.core.network.GuiId;
|
||||
import forestry.core.network.PacketIds;
|
||||
import forestry.core.network.PacketId;
|
||||
import forestry.core.network.PacketSocketUpdate;
|
||||
import forestry.core.proxy.Proxies;
|
||||
import forestry.energy.gadgets.EngineBronze;
|
||||
@@ -76,7 +76,7 @@ public class GuiHandlerEnergy extends GuiHandlerBase {
|
||||
|
||||
case EngineTinGUI:
|
||||
EngineTin tile = (EngineTin) getTileForestry(world, x, y, z);
|
||||
Proxies.net.sendToPlayer(new PacketSocketUpdate(PacketIds.SOCKET_UPDATE, x, y, z, tile), player);
|
||||
Proxies.net.sendToPlayer(new PacketSocketUpdate(PacketId.SOCKET_UPDATE, tile), player);
|
||||
return new ContainerEngineTin(player.inventory, tile);
|
||||
|
||||
case GeneratorGUI:
|
||||
|
||||
@@ -10,6 +10,10 @@
|
||||
******************************************************************************/
|
||||
package forestry.energy.gadgets;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.Container;
|
||||
import net.minecraft.inventory.ICrafting;
|
||||
@@ -40,34 +44,12 @@ import forestry.core.interfaces.ILiquidTankContainer;
|
||||
import forestry.core.inventory.IInventoryAdapter;
|
||||
import forestry.core.inventory.TileInventoryAdapter;
|
||||
import forestry.core.network.GuiId;
|
||||
import forestry.core.network.PacketPayload;
|
||||
|
||||
public class EngineBronze extends Engine implements ISidedInventory, ILiquidTankContainer {
|
||||
|
||||
/* CONSTANTS */
|
||||
public static final short SLOT_CAN = 0;
|
||||
|
||||
/* NETWORK */
|
||||
@Override
|
||||
public PacketPayload getPacketPayload() {
|
||||
PacketPayload payload = super.getPacketPayload();
|
||||
|
||||
if (shutdown) {
|
||||
payload.append(new int[]{1});
|
||||
} else {
|
||||
payload.append(new int[]{0});
|
||||
}
|
||||
|
||||
return payload;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fromPacketPayload(PacketPayload payload) {
|
||||
super.fromPacketPayload(payload);
|
||||
|
||||
shutdown = payload.intPayload[3] > 0;
|
||||
}
|
||||
|
||||
private final FilteredTank fuelTank;
|
||||
private final FilteredTank heatingTank;
|
||||
private final TankManager tankManager;
|
||||
@@ -156,7 +138,7 @@ public class EngineBronze extends Engine implements ISidedInventory, ILiquidTank
|
||||
currentOutput = determineFuelValue(FluidRegistry.getFluid(currentFluidId));
|
||||
energyManager.generateEnergy(currentOutput);
|
||||
} else {
|
||||
burnTime = totalTime = this.determineBurnTime(fuelTank.getFluid().getFluid());
|
||||
burnTime = totalTime = determineBurnTime(fuelTank.getFluid().getFluid());
|
||||
currentFluidId = fuelTank.getFluid().getFluid().getID();
|
||||
fuelTank.drain(Defaults.BUCKET_VOLUME, true);
|
||||
}
|
||||
@@ -228,7 +210,7 @@ public class EngineBronze extends Engine implements ISidedInventory, ILiquidTank
|
||||
/**
|
||||
* Returns the fuel value (power per cycle) an item of the passed fluid
|
||||
*/
|
||||
private int determineFuelValue(Fluid fluid) {
|
||||
private static int determineFuelValue(Fluid fluid) {
|
||||
if (FuelManager.bronzeEngineFuel.containsKey(fluid)) {
|
||||
return FuelManager.bronzeEngineFuel.get(fluid).powerPerCycle;
|
||||
} else {
|
||||
@@ -239,7 +221,7 @@ public class EngineBronze extends Engine implements ISidedInventory, ILiquidTank
|
||||
/**
|
||||
* @return Duration of burn cycle of one bucket
|
||||
*/
|
||||
private int determineBurnTime(Fluid fluid) {
|
||||
private static int determineBurnTime(Fluid fluid) {
|
||||
if (FuelManager.bronzeEngineFuel.containsKey(fluid)) {
|
||||
return FuelManager.bronzeEngineFuel.get(fluid).burnDuration;
|
||||
} else {
|
||||
@@ -299,6 +281,19 @@ public class EngineBronze extends Engine implements ISidedInventory, ILiquidTank
|
||||
tankManager.writeTanksToNBT(nbt);
|
||||
}
|
||||
|
||||
/* NETWORK */
|
||||
@Override
|
||||
public void writeData(DataOutputStream data) throws IOException {
|
||||
super.writeData(data);
|
||||
data.writeBoolean(shutdown);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readData(DataInputStream data) throws IOException {
|
||||
super.readData(data);
|
||||
shutdown = data.readBoolean();
|
||||
}
|
||||
|
||||
/* GUI */
|
||||
@Override
|
||||
public void getGUINetworkData(int id, int data) {
|
||||
@@ -315,7 +310,7 @@ public class EngineBronze extends Engine implements ISidedInventory, ILiquidTank
|
||||
currentOutput = data;
|
||||
break;
|
||||
case 3:
|
||||
energyManager.fromPacketInt(data);
|
||||
energyManager.fromGuiInt(data);
|
||||
break;
|
||||
case 4:
|
||||
heat = data;
|
||||
@@ -332,7 +327,7 @@ public class EngineBronze extends Engine implements ISidedInventory, ILiquidTank
|
||||
iCrafting.sendProgressBarUpdate(containerEngine, i, burnTime);
|
||||
iCrafting.sendProgressBarUpdate(containerEngine, i + 1, totalTime);
|
||||
iCrafting.sendProgressBarUpdate(containerEngine, i + 2, currentOutput);
|
||||
iCrafting.sendProgressBarUpdate(containerEngine, i + 3, energyManager.toPacketInt());
|
||||
iCrafting.sendProgressBarUpdate(containerEngine, i + 3, energyManager.toGuiInt());
|
||||
iCrafting.sendProgressBarUpdate(containerEngine, i + 4, heat);
|
||||
iCrafting.sendProgressBarUpdate(containerEngine, i + 5, currentFluidId);
|
||||
}
|
||||
|
||||
@@ -155,7 +155,10 @@ public class EngineClockwork extends Engine {
|
||||
}
|
||||
|
||||
float fromClockwork = (tension / ENGINE_CLOCKWORK_WIND_MAX) * Defaults.ENGINE_PISTON_SPEED_MAX;
|
||||
return fromClockwork >= 0.01f ? fromClockwork : 0;
|
||||
|
||||
fromClockwork = Math.round(fromClockwork * 100f) / 100f;
|
||||
|
||||
return fromClockwork;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -328,7 +328,7 @@ public class EngineCopper extends Engine implements ISidedInventory {
|
||||
currentOutput = j;
|
||||
break;
|
||||
case 3:
|
||||
energyManager.fromPacketInt(j);
|
||||
energyManager.fromGuiInt(j);
|
||||
break;
|
||||
case 4:
|
||||
heat = j;
|
||||
@@ -341,7 +341,7 @@ public class EngineCopper extends Engine implements ISidedInventory {
|
||||
iCrafting.sendProgressBarUpdate(containerEngine, 0, burnTime);
|
||||
iCrafting.sendProgressBarUpdate(containerEngine, 1, totalBurnTime);
|
||||
iCrafting.sendProgressBarUpdate(containerEngine, 2, currentOutput);
|
||||
iCrafting.sendProgressBarUpdate(containerEngine, 3, energyManager.toPacketInt());
|
||||
iCrafting.sendProgressBarUpdate(containerEngine, 3, energyManager.toGuiInt());
|
||||
iCrafting.sendProgressBarUpdate(containerEngine, 4, heat);
|
||||
}
|
||||
|
||||
|
||||
@@ -31,7 +31,6 @@ import forestry.core.inventory.InventoryAdapter;
|
||||
import forestry.core.inventory.TileInventoryAdapter;
|
||||
import forestry.core.network.GuiId;
|
||||
import forestry.core.utils.DelayTimer;
|
||||
import forestry.core.utils.EnumTankLevel;
|
||||
import forestry.plugins.PluginIC2;
|
||||
|
||||
import ic2.api.energy.prefab.BasicSink;
|
||||
@@ -227,21 +226,6 @@ public class EngineTin extends Engine implements ISocketable, IInventory {
|
||||
return Math.min(i, (int) (ic2EnergySink.getEnergyStored() * i) / ic2EnergySink.getCapacity());
|
||||
}
|
||||
|
||||
public static EnumTankLevel rateLevel(int scaled) {
|
||||
|
||||
if (scaled < 5) {
|
||||
return EnumTankLevel.EMPTY;
|
||||
} else if (scaled < 30) {
|
||||
return EnumTankLevel.LOW;
|
||||
} else if (scaled < 60) {
|
||||
return EnumTankLevel.MEDIUM;
|
||||
} else if (scaled < 90) {
|
||||
return EnumTankLevel.HIGH;
|
||||
} else {
|
||||
return EnumTankLevel.MAXIMUM;
|
||||
}
|
||||
}
|
||||
|
||||
// / SMP GUI
|
||||
@Override
|
||||
public void getGUINetworkData(int i, int j) {
|
||||
@@ -252,7 +236,7 @@ public class EngineTin extends Engine implements ISocketable, IInventory {
|
||||
currentOutput = j;
|
||||
break;
|
||||
case 1:
|
||||
energyManager.fromPacketInt(j);
|
||||
energyManager.fromGuiInt(j);
|
||||
break;
|
||||
case 2:
|
||||
heat = j;
|
||||
@@ -269,7 +253,7 @@ public class EngineTin extends Engine implements ISocketable, IInventory {
|
||||
@Override
|
||||
public void sendGUINetworkData(Container containerEngine, ICrafting iCrafting) {
|
||||
iCrafting.sendProgressBarUpdate(containerEngine, 0, currentOutput);
|
||||
iCrafting.sendProgressBarUpdate(containerEngine, 1, energyManager.toPacketInt());
|
||||
iCrafting.sendProgressBarUpdate(containerEngine, 1, energyManager.toGuiInt());
|
||||
iCrafting.sendProgressBarUpdate(containerEngine, 2, heat);
|
||||
if (ic2EnergySink != null) {
|
||||
iCrafting.sendProgressBarUpdate(containerEngine, 3, (short) ic2EnergySink.getEnergyStored());
|
||||
|
||||
@@ -31,11 +31,26 @@ public class GuiEngineTin extends GuiEngine<ContainerEngineTin, EngineTin> {
|
||||
EngineTin engine = inventory;
|
||||
int storageHeight = engine.getStorageScaled(46);
|
||||
int storageMaxHeight = engine.getStorageScaled(100);
|
||||
EnumTankLevel rated = engine.rateLevel(storageMaxHeight);
|
||||
EnumTankLevel rated = rateLevel(storageMaxHeight);
|
||||
|
||||
drawHealthMeter(guiLeft + 74, guiTop + 25, storageHeight, rated);
|
||||
}
|
||||
|
||||
public static EnumTankLevel rateLevel(int scaled) {
|
||||
|
||||
if (scaled < 5) {
|
||||
return EnumTankLevel.EMPTY;
|
||||
} else if (scaled < 30) {
|
||||
return EnumTankLevel.LOW;
|
||||
} else if (scaled < 60) {
|
||||
return EnumTankLevel.MEDIUM;
|
||||
} else if (scaled < 90) {
|
||||
return EnumTankLevel.HIGH;
|
||||
} else {
|
||||
return EnumTankLevel.MAXIMUM;
|
||||
}
|
||||
}
|
||||
|
||||
private void drawHealthMeter(int x, int y, int height, EnumTankLevel rated) {
|
||||
int i = 176;
|
||||
int k = 0;
|
||||
|
||||
@@ -435,7 +435,7 @@ public class MachineCarpenter extends TilePowered implements ISidedInventory, IL
|
||||
}
|
||||
|
||||
private boolean removeSets(int count, ItemStack[] set) {
|
||||
EntityPlayer player = Proxies.common.getPlayer(worldObj, getOwnerProfile());
|
||||
EntityPlayer player = Proxies.common.getPlayer(worldObj, getOwner());
|
||||
return InvTools.removeSets(getInternalInventory(), count, set, SLOT_INVENTORY_1, SLOT_INVENTORY_COUNT, player, true, true, true);
|
||||
}
|
||||
|
||||
|
||||
@@ -282,7 +282,7 @@ public class MachineSqueezer extends TilePowered implements ISidedInventory, ILi
|
||||
}
|
||||
|
||||
private boolean removeResources(ItemStack[] stacks) {
|
||||
EntityPlayer player = Proxies.common.getPlayer(worldObj, getOwnerProfile());
|
||||
EntityPlayer player = Proxies.common.getPlayer(worldObj, getOwner());
|
||||
return InvTools.removeSets(getInternalInventory(), 1, stacks, SLOT_RESOURCE_1, SLOTS_RESOURCE_COUNT, player, false, true, true);
|
||||
}
|
||||
|
||||
|
||||
@@ -10,6 +10,10 @@
|
||||
******************************************************************************/
|
||||
package forestry.factory.gadgets;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.inventory.InventoryCrafting;
|
||||
@@ -23,11 +27,8 @@ import forestry.core.interfaces.ICrafter;
|
||||
import forestry.core.inventory.InvTools;
|
||||
import forestry.core.inventory.InventoryAdapter;
|
||||
import forestry.core.inventory.TileInventoryAdapter;
|
||||
import forestry.core.network.ForestryPacket;
|
||||
import forestry.core.network.GuiId;
|
||||
import forestry.core.network.PacketIds;
|
||||
import forestry.core.network.PacketTileNBT;
|
||||
import forestry.core.network.PacketTileUpdate;
|
||||
import forestry.core.network.PacketTileStream;
|
||||
import forestry.core.proxy.Proxies;
|
||||
import forestry.core.utils.GuiUtil;
|
||||
import forestry.core.utils.RecipeUtil;
|
||||
@@ -66,7 +67,6 @@ public class TileWorktable extends TileBase implements ICrafter {
|
||||
super.writeToNBT(nbttagcompound);
|
||||
|
||||
craftingInventory.writeToNBT(nbttagcompound);
|
||||
|
||||
memorized.writeToNBT(nbttagcompound);
|
||||
}
|
||||
|
||||
@@ -75,24 +75,28 @@ public class TileWorktable extends TileBase implements ICrafter {
|
||||
super.readFromNBT(nbttagcompound);
|
||||
|
||||
craftingInventory.readFromNBT(nbttagcompound);
|
||||
|
||||
memorized.readFromNBT(nbttagcompound);
|
||||
}
|
||||
|
||||
/* NETWORK */
|
||||
@Override
|
||||
public void fromPacket(ForestryPacket packetRaw) {
|
||||
if (packetRaw instanceof PacketTileUpdate) {
|
||||
super.fromPacket(packetRaw);
|
||||
return;
|
||||
}
|
||||
public void writeData(DataOutputStream data) throws IOException {
|
||||
super.writeData(data);
|
||||
|
||||
PacketTileNBT packet = (PacketTileNBT) packetRaw;
|
||||
readFromNBT(packet.getTagCompound());
|
||||
craftingInventory.writeData(data);
|
||||
memorized.writeData(data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readData(DataInputStream data) throws IOException {
|
||||
super.readData(data);
|
||||
|
||||
craftingInventory.readData(data);
|
||||
memorized.readData(data);
|
||||
}
|
||||
|
||||
public void sendAll(EntityPlayer player) {
|
||||
Proxies.net.sendToPlayer(new PacketTileNBT(PacketIds.TILE_NBT, this), player);
|
||||
Proxies.net.sendToPlayer(new PacketTileStream(this), player);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -21,9 +21,8 @@ import forestry.core.gui.IGuiSelectable;
|
||||
import forestry.core.gui.slots.SlotCraftMatrix;
|
||||
import forestry.core.gui.slots.SlotCrafter;
|
||||
import forestry.core.interfaces.IContainerCrafting;
|
||||
import forestry.core.network.PacketIds;
|
||||
import forestry.core.network.PacketPayload;
|
||||
import forestry.core.network.PacketUpdate;
|
||||
import forestry.core.network.PacketGuiSelect;
|
||||
import forestry.core.network.PacketId;
|
||||
import forestry.core.proxy.Proxies;
|
||||
import forestry.core.utils.StackUtils;
|
||||
import forestry.factory.gadgets.TileWorktable;
|
||||
@@ -105,26 +104,23 @@ public class ContainerWorktable extends ContainerTile<TileWorktable> implements
|
||||
sendRecipeClick(0, tile.getMemory().capacity);
|
||||
}
|
||||
|
||||
public void sendRecipeClick(int mouseButton, int recipeIndex) {
|
||||
PacketPayload payload = new PacketPayload(2, 0, 0);
|
||||
payload.intPayload[0] = mouseButton;
|
||||
payload.intPayload[1] = recipeIndex;
|
||||
PacketUpdate packet = new PacketUpdate(PacketIds.GUI_SELECTION_CHANGE, payload);
|
||||
public static void sendRecipeClick(int mouseButton, int recipeIndex) {
|
||||
PacketGuiSelect packet = new PacketGuiSelect(PacketId.GUI_SELECTION_CHANGE, mouseButton, recipeIndex);
|
||||
Proxies.net.sendToServer(packet);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleSelectionChange(EntityPlayer player, PacketUpdate packet) {
|
||||
if (packet.payload.intPayload[0] > 0) {
|
||||
tile.getMemory().toggleLock(player.worldObj, packet.payload.intPayload[1]);
|
||||
public void handleSelectionChange(EntityPlayer player, PacketGuiSelect packet) {
|
||||
if (packet.getPrimaryIndex() > 0) {
|
||||
tile.getMemory().toggleLock(player.worldObj, packet.getSecondaryIndex());
|
||||
} else {
|
||||
tile.chooseRecipe(packet.payload.intPayload[1]);
|
||||
tile.chooseRecipe(packet.getSecondaryIndex());
|
||||
updateMatrix();
|
||||
updateRecipe();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSelection(PacketUpdate packet) {
|
||||
public void setSelection(PacketGuiSelect packet) {
|
||||
}
|
||||
}
|
||||
@@ -10,6 +10,9 @@
|
||||
******************************************************************************/
|
||||
package forestry.factory.recipes;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
@@ -28,17 +31,22 @@ import net.minecraft.world.World;
|
||||
import forestry.api.core.INBTTagable;
|
||||
import forestry.core.gui.ContainerDummy;
|
||||
import forestry.core.inventory.InventoryAdapter;
|
||||
import forestry.core.network.IStreamable;
|
||||
import forestry.core.network.PacketHelper;
|
||||
import forestry.core.utils.PlainInventory;
|
||||
|
||||
public class RecipeMemory implements INBTTagable {
|
||||
public class RecipeMemory implements INBTTagable, IStreamable {
|
||||
|
||||
public static final class Recipe implements INBTTagable {
|
||||
public static final class Recipe implements INBTTagable, IStreamable {
|
||||
|
||||
private InventoryAdapter matrix;
|
||||
private long lastUsed;
|
||||
private boolean locked;
|
||||
private ItemStack cachedRecipeOutput;
|
||||
|
||||
public Recipe() {
|
||||
}
|
||||
|
||||
public Recipe(InventoryCrafting crafting) {
|
||||
this.matrix = new InventoryAdapter(new PlainInventory(crafting));
|
||||
}
|
||||
@@ -106,6 +114,23 @@ public class RecipeMemory implements INBTTagable {
|
||||
nbttagcompound.setBoolean("Locked", locked);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeData(DataOutputStream data) throws IOException {
|
||||
sanitizeMatrix();
|
||||
matrix.writeData(data);
|
||||
data.writeLong(lastUsed);
|
||||
data.writeBoolean(locked);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readData(DataInputStream data) throws IOException {
|
||||
matrix = new InventoryAdapter(new InventoryCrafting(DUMMY_CONTAINER, 3, 3));
|
||||
matrix.readData(data);
|
||||
sanitizeMatrix();
|
||||
lastUsed = data.readLong();
|
||||
locked = data.readBoolean();
|
||||
}
|
||||
|
||||
/**
|
||||
* This is a nasty hack to hide a bug where the recipe stacks somehow
|
||||
* get the stackSize set to -1. Which makes the recipe no longer work,
|
||||
@@ -275,4 +300,15 @@ public class RecipeMemory implements INBTTagable {
|
||||
nbttagcompound.setTag("RecipeMemory", nbttaglist);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeData(DataOutputStream data) throws IOException {
|
||||
PacketHelper.writeStreamables(recipes, data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readData(DataInputStream data) throws IOException {
|
||||
recipes.clear();
|
||||
List<Recipe> newRecipes = PacketHelper.readStreamables(Recipe.class, data);
|
||||
recipes.addAll(newRecipes);
|
||||
}
|
||||
}
|
||||
@@ -15,7 +15,7 @@ import net.minecraft.world.World;
|
||||
|
||||
import forestry.core.GuiHandlerBase;
|
||||
import forestry.core.network.GuiId;
|
||||
import forestry.core.network.PacketIds;
|
||||
import forestry.core.network.PacketId;
|
||||
import forestry.core.network.PacketSocketUpdate;
|
||||
import forestry.core.proxy.Proxies;
|
||||
import forestry.farming.gadgets.TileFarmPlain;
|
||||
@@ -34,7 +34,7 @@ public class GuiHandlerFarming extends GuiHandlerBase {
|
||||
switch (GuiId.values()[id]) {
|
||||
case MultiFarmGUI:
|
||||
TileFarmPlain tile = (TileFarmPlain) getTileForestry(world, x, y, z);
|
||||
Proxies.net.sendToPlayer(new PacketSocketUpdate(PacketIds.SOCKET_UPDATE, x, y, z, tile), player);
|
||||
Proxies.net.sendToPlayer(new PacketSocketUpdate(PacketId.SOCKET_UPDATE, tile), player);
|
||||
return new ContainerFarm(player.inventory, tile);
|
||||
default:
|
||||
return null;
|
||||
|
||||
@@ -10,6 +10,10 @@
|
||||
******************************************************************************/
|
||||
package forestry.farming.gadgets;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
@@ -27,8 +31,6 @@ import forestry.api.farming.IFarmListener;
|
||||
import forestry.core.gadgets.TileForestry;
|
||||
import forestry.core.inventory.IInventoryAdapter;
|
||||
import forestry.core.network.GuiId;
|
||||
import forestry.core.network.PacketPayload;
|
||||
import forestry.core.proxy.Proxies;
|
||||
|
||||
public abstract class TileFarm extends TileForestry implements IFarmComponent {
|
||||
|
||||
@@ -129,28 +131,28 @@ public abstract class TileFarm extends TileForestry implements IFarmComponent {
|
||||
}
|
||||
|
||||
/* TILEFORESTRY */
|
||||
@Override
|
||||
public PacketPayload getPacketPayload() {
|
||||
PacketPayload payload = new PacketPayload(0, 3);
|
||||
payload.shortPayload[0] = (short) farmBlock.ordinal();
|
||||
|
||||
payload.shortPayload[1] = (short) (isMaster() ? 1 : 0);
|
||||
@Override
|
||||
public void writeData(DataOutputStream data) throws IOException {
|
||||
super.writeData(data);
|
||||
data.writeShort(farmBlock.ordinal());
|
||||
data.writeBoolean(isMaster());
|
||||
|
||||
// so the client can know if it is part of an integrated structure
|
||||
payload.shortPayload[2] = (short) masterY;
|
||||
|
||||
return payload;
|
||||
data.writeShort(masterY);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fromPacketPayload(PacketPayload payload) {
|
||||
EnumFarmBlock farmType = EnumFarmBlock.values()[payload.shortPayload[0]];
|
||||
if (payload.shortPayload[1] > 0 && !isMaster()) {
|
||||
public void readData(DataInputStream data) throws IOException {
|
||||
super.readData(data);
|
||||
short farmBlockOrdinal = data.readShort();
|
||||
EnumFarmBlock farmType = EnumFarmBlock.values()[farmBlockOrdinal];
|
||||
if (data.readBoolean() && !isMaster()) {
|
||||
makeMaster();
|
||||
}
|
||||
|
||||
// so the client can know if it is part of an integrated structure
|
||||
this.masterY = payload.shortPayload[2];
|
||||
this.masterY = data.readShort();
|
||||
|
||||
if (this.farmBlock != farmType) {
|
||||
this.farmBlock = farmType;
|
||||
|
||||
@@ -62,7 +62,6 @@ import forestry.core.proxy.Proxies;
|
||||
import forestry.core.utils.DelayTimer;
|
||||
import forestry.core.utils.GuiUtil;
|
||||
import forestry.core.utils.StackUtils;
|
||||
import forestry.core.utils.Utils;
|
||||
import forestry.core.vect.Vect;
|
||||
import forestry.core.vect.VectUtil;
|
||||
import forestry.farming.FarmHelper;
|
||||
@@ -776,7 +775,7 @@ public class TileFarmPlain extends TileFarm implements IFarmHousing, ISocketable
|
||||
|
||||
@Override
|
||||
public void removeResources(ItemStack[] resources) {
|
||||
EntityPlayer player = Proxies.common.getPlayer(worldObj, getOwnerProfile());
|
||||
EntityPlayer player = Proxies.common.getPlayer(worldObj, getOwner());
|
||||
InvTools.removeSets(getInternalInventory(), 1, resources, SLOT_RESOURCES_1, SLOT_RESOURCES_COUNT, player, false, true, true);
|
||||
}
|
||||
|
||||
@@ -805,7 +804,7 @@ public class TileFarmPlain extends TileFarm implements IFarmHousing, ISocketable
|
||||
continue;
|
||||
}
|
||||
|
||||
EntityPlayer player = Proxies.common.getPlayer(world, getOwnerProfile());
|
||||
EntityPlayer player = Proxies.common.getPlayer(world, getOwner());
|
||||
if (!germling.plantSaplingAt(player, inventory.getStackInSlot(i), world, x, y, z)) {
|
||||
continue;
|
||||
}
|
||||
@@ -992,12 +991,6 @@ public class TileFarmPlain extends TileFarm implements IFarmHousing, ISocketable
|
||||
return Config.hints.get("farm");
|
||||
}
|
||||
|
||||
/* IOWNABLE */
|
||||
@Override
|
||||
public boolean isOwnable() {
|
||||
return true;
|
||||
}
|
||||
|
||||
private static class FarmPlainInventoryAdapter extends TileInventoryAdapter<TileFarmPlain> {
|
||||
public FarmPlainInventoryAdapter(TileFarmPlain tile) {
|
||||
super(tile, TileFarmPlain.SLOT_COUNT, "Items");
|
||||
|
||||
@@ -121,7 +121,7 @@ public class MailAddress implements INBTTagable, IMailAddress {
|
||||
public String toString() {
|
||||
String name = getName().toLowerCase(Locale.ENGLISH);
|
||||
if (isPlayer()) {
|
||||
return type + "-" + name + "-" + gameProfile.getId();
|
||||
return type + "-" + name + '-' + gameProfile.getId();
|
||||
} else {
|
||||
return type + "-" + name;
|
||||
}
|
||||
|
||||
@@ -16,9 +16,9 @@ import java.io.IOException;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.Container;
|
||||
|
||||
import forestry.core.interfaces.IPacketHandler;
|
||||
import forestry.core.network.PacketIds;
|
||||
import forestry.core.network.PacketUpdate;
|
||||
import forestry.core.network.IPacketHandler;
|
||||
import forestry.core.network.PacketId;
|
||||
import forestry.core.network.PacketString;
|
||||
import forestry.core.proxy.Proxies;
|
||||
import forestry.mail.gui.ContainerCatalogue;
|
||||
import forestry.mail.gui.ContainerLetter;
|
||||
@@ -26,48 +26,49 @@ import forestry.mail.gui.ContainerTradeName;
|
||||
import forestry.mail.gui.GuiMailboxInfo;
|
||||
import forestry.mail.network.PacketLetterInfo;
|
||||
import forestry.mail.network.PacketPOBoxInfo;
|
||||
import forestry.mail.network.PacketRequestLetterInfo;
|
||||
|
||||
public class PacketHandlerMail implements IPacketHandler {
|
||||
|
||||
@Override
|
||||
public boolean onPacketData(int packetID, DataInputStream data, EntityPlayer player) throws IOException {
|
||||
public boolean onPacketData(PacketId packetID, DataInputStream data, EntityPlayer player) throws IOException {
|
||||
|
||||
PacketUpdate packet;
|
||||
switch (packetID) {
|
||||
case PacketIds.LETTER_INFO:
|
||||
PacketLetterInfo packetT = new PacketLetterInfo();
|
||||
packetT.readData(data);
|
||||
onLetterInfo(packetT);
|
||||
case LETTER_INFO: {
|
||||
PacketLetterInfo packet = new PacketLetterInfo(data);
|
||||
onLetterInfo(packet);
|
||||
return true;
|
||||
case PacketIds.POBOX_INFO:
|
||||
PacketPOBoxInfo packetP = new PacketPOBoxInfo();
|
||||
packetP.readData(data);
|
||||
onPOBoxInfo(packetP);
|
||||
}
|
||||
case POBOX_INFO: {
|
||||
PacketPOBoxInfo packet = new PacketPOBoxInfo(data);
|
||||
onPOBoxInfo(packet);
|
||||
return true;
|
||||
case PacketIds.LETTER_RECIPIENT:
|
||||
packet = new PacketUpdate();
|
||||
packet.readData(data);
|
||||
onLetterRecipient(player, packet);
|
||||
}
|
||||
case LETTER_REQUEST_INFO: {
|
||||
PacketRequestLetterInfo packet = new PacketRequestLetterInfo(data);
|
||||
onLetterRequestInfo(player, packet);
|
||||
return true;
|
||||
case PacketIds.LETTER_TEXT:
|
||||
packet = new PacketUpdate();
|
||||
packet.readData(data);
|
||||
}
|
||||
case LETTER_TEXT: {
|
||||
PacketString packet = new PacketString(data);
|
||||
onLetterText(player, packet);
|
||||
return true;
|
||||
case PacketIds.TRADING_ADDRESS_SET:
|
||||
packet = new PacketUpdate();
|
||||
packet.readData(data);
|
||||
}
|
||||
case TRADING_ADDRESS_SET: {
|
||||
PacketString packet = new PacketString(data);
|
||||
onAddressSet(player, packet);
|
||||
return true;
|
||||
case PacketIds.POBOX_INFO_REQUEST:
|
||||
}
|
||||
case POBOX_INFO_REQUEST: {
|
||||
onPOBoxInfoRequest(player);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private void onLetterInfo(PacketLetterInfo packet) {
|
||||
private static void onLetterInfo(PacketLetterInfo packet) {
|
||||
|
||||
Container container = Proxies.common.getClientInstance().thePlayer.openContainer;
|
||||
if (container instanceof ContainerLetter) {
|
||||
@@ -78,11 +79,11 @@ public class PacketHandlerMail implements IPacketHandler {
|
||||
|
||||
}
|
||||
|
||||
private void onPOBoxInfo(PacketPOBoxInfo packet) {
|
||||
private static void onPOBoxInfo(PacketPOBoxInfo packet) {
|
||||
GuiMailboxInfo.instance.setPOBoxInfo(packet.poboxInfo);
|
||||
}
|
||||
|
||||
private void onAddressSet(EntityPlayer player, PacketUpdate packet) {
|
||||
private static void onAddressSet(EntityPlayer player, PacketString packet) {
|
||||
if (!(player.openContainer instanceof ContainerTradeName)) {
|
||||
return;
|
||||
}
|
||||
@@ -90,7 +91,7 @@ public class PacketHandlerMail implements IPacketHandler {
|
||||
((ContainerTradeName) player.openContainer).handleSetAddress(packet);
|
||||
}
|
||||
|
||||
private void onLetterText(EntityPlayer player, PacketUpdate packet) {
|
||||
private static void onLetterText(EntityPlayer player, PacketString packet) {
|
||||
if (!(player.openContainer instanceof ContainerLetter)) {
|
||||
return;
|
||||
}
|
||||
@@ -98,22 +99,22 @@ public class PacketHandlerMail implements IPacketHandler {
|
||||
((ContainerLetter) player.openContainer).handleSetText(packet);
|
||||
}
|
||||
|
||||
private void onLetterRecipient(EntityPlayer player, PacketUpdate packet) {
|
||||
private static void onLetterRequestInfo(EntityPlayer player, PacketRequestLetterInfo packet) {
|
||||
if (!(player.openContainer instanceof ContainerLetter)) {
|
||||
return;
|
||||
}
|
||||
|
||||
((ContainerLetter) player.openContainer).handleSetRecipient(player, packet);
|
||||
((ContainerLetter) player.openContainer).handleRequestLetterInfo(player, packet);
|
||||
}
|
||||
|
||||
private void onPOBoxInfoRequest(EntityPlayer player) {
|
||||
private static void onPOBoxInfoRequest(EntityPlayer player) {
|
||||
MailAddress address = new MailAddress(player.getGameProfile());
|
||||
POBox pobox = PostRegistry.getPOBox(player.worldObj, address);
|
||||
if (pobox == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
Proxies.net.sendToPlayer(new PacketPOBoxInfo(PacketIds.POBOX_INFO, pobox.getPOBoxInfo()), player);
|
||||
Proxies.net.sendToPlayer(new PacketPOBoxInfo(PacketId.POBOX_INFO, pobox.getPOBoxInfo()), player);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -30,7 +30,7 @@ import forestry.api.mail.IPostalCarrier;
|
||||
import forestry.api.mail.ITradeStation;
|
||||
import forestry.api.mail.PostManager;
|
||||
import forestry.core.config.ForestryItem;
|
||||
import forestry.core.network.PacketIds;
|
||||
import forestry.core.network.PacketId;
|
||||
import forestry.core.proxy.Proxies;
|
||||
import forestry.mail.items.ItemLetter;
|
||||
import forestry.mail.network.PacketPOBoxInfo;
|
||||
@@ -75,7 +75,7 @@ public class PostRegistry implements IPostRegistry {
|
||||
|
||||
EntityPlayer player = Proxies.common.getPlayer(world, address.getPlayerProfile());
|
||||
if (player != null) {
|
||||
Proxies.net.sendToPlayer(new PacketPOBoxInfo(PacketIds.POBOX_INFO, pobox.getPOBoxInfo()), player);
|
||||
Proxies.net.sendToPlayer(new PacketPOBoxInfo(PacketId.POBOX_INFO, pobox.getPOBoxInfo()), player);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -25,7 +25,7 @@ import forestry.api.mail.IPostalCarrier;
|
||||
import forestry.api.mail.IPostalState;
|
||||
import forestry.api.mail.ITradeStation;
|
||||
import forestry.api.mail.PostManager;
|
||||
import forestry.core.network.PacketIds;
|
||||
import forestry.core.network.PacketId;
|
||||
import forestry.core.proxy.Proxies;
|
||||
import forestry.core.render.TextureManager;
|
||||
import forestry.core.utils.StringUtil;
|
||||
@@ -87,7 +87,7 @@ public class PostalCarrier implements IPostalCarrier {
|
||||
} else {
|
||||
EntityPlayer player = Proxies.common.getPlayer(world, recipient.getPlayerProfile());
|
||||
if (player != null) {
|
||||
Proxies.net.sendToPlayer(new PacketPOBoxInfo(PacketIds.POBOX_INFO, pobox.getPOBoxInfo()), player);
|
||||
Proxies.net.sendToPlayer(new PacketPOBoxInfo(PacketId.POBOX_INFO, pobox.getPOBoxInfo()), player);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@ import cpw.mods.fml.common.gameevent.TickEvent.Phase;
|
||||
import cpw.mods.fml.common.gameevent.TickEvent.RenderTickEvent;
|
||||
|
||||
import forestry.core.network.ForestryPacket;
|
||||
import forestry.core.network.PacketIds;
|
||||
import forestry.core.network.PacketId;
|
||||
import forestry.core.proxy.Proxies;
|
||||
import forestry.mail.gui.GuiMailboxInfo;
|
||||
|
||||
@@ -34,7 +34,7 @@ public class TickHandlerMailClient {
|
||||
if (GuiMailboxInfo.instance.hasPOBoxInfo()) {
|
||||
GuiMailboxInfo.instance.render(0, 0);
|
||||
} else {
|
||||
Proxies.net.sendToServer(new ForestryPacket(PacketIds.POBOX_INFO_REQUEST));
|
||||
Proxies.net.sendToServer(new ForestryPacket(PacketId.POBOX_INFO_REQUEST));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -80,7 +80,7 @@ public class MachineMailbox extends TileBase implements IMailContainer {
|
||||
@Override
|
||||
public void updateServerSide() {
|
||||
if (!isLinked) {
|
||||
getOrCreateMailInventory(worldObj, getOwnerProfile());
|
||||
getOrCreateMailInventory(worldObj, getOwner());
|
||||
isLinked = true;
|
||||
}
|
||||
}
|
||||
@@ -112,7 +112,7 @@ public class MachineMailbox extends TileBase implements IMailContainer {
|
||||
@Override
|
||||
public boolean hasMail() {
|
||||
|
||||
IInventory mailInventory = getOrCreateMailInventory(worldObj, getOwnerProfile());
|
||||
IInventory mailInventory = getOrCreateMailInventory(worldObj, getOwner());
|
||||
for (int i = 0; i < mailInventory.getSizeInventory(); i++) {
|
||||
if (mailInventory.getStackInSlot(i) != null) {
|
||||
return true;
|
||||
|
||||
@@ -10,6 +10,9 @@
|
||||
******************************************************************************/
|
||||
package forestry.mail.gadgets;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.Collection;
|
||||
import java.util.LinkedList;
|
||||
|
||||
@@ -32,7 +35,6 @@ import forestry.core.EnumErrorCode;
|
||||
import forestry.core.gadgets.TileBase;
|
||||
import forestry.core.inventory.IInventoryAdapter;
|
||||
import forestry.core.network.GuiId;
|
||||
import forestry.core.network.PacketPayload;
|
||||
import forestry.core.proxy.Proxies;
|
||||
import forestry.core.utils.StackUtils;
|
||||
import forestry.mail.MailAddress;
|
||||
@@ -87,26 +89,19 @@ public class MachineTrader extends TileBase {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public PacketPayload getPacketPayload() {
|
||||
if (address == null || address.getName() == null) {
|
||||
return null;
|
||||
}
|
||||
/* NETWORK */
|
||||
|
||||
PacketPayload payload = new PacketPayload(0, 0, 1);
|
||||
payload.stringPayload[0] = address.getName();
|
||||
return payload;
|
||||
@Override
|
||||
public void writeData(DataOutputStream data) throws IOException {
|
||||
super.writeData(data);
|
||||
data.writeUTF(address.getName());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fromPacketPayload(PacketPayload payload) {
|
||||
if (payload.isEmpty()) {
|
||||
address = null;
|
||||
return;
|
||||
}
|
||||
|
||||
String addressName = payload.stringPayload[0];
|
||||
address = PostManager.postRegistry.getMailAddress(addressName);
|
||||
public void readData(DataInputStream data) throws IOException {
|
||||
super.readData(data);
|
||||
String address = data.readUTF();
|
||||
this.address = PostManager.postRegistry.getMailAddress(address);
|
||||
}
|
||||
|
||||
/* UPDATING */
|
||||
@@ -263,7 +258,7 @@ public class MachineTrader extends TileBase {
|
||||
|
||||
if (hasValidTradeAddress & hasUniqueTradeAddress) {
|
||||
this.address = address;
|
||||
PostManager.postRegistry.getOrCreateTradeStation(worldObj, getOwnerProfile(), address);
|
||||
PostManager.postRegistry.getOrCreateTradeStation(worldObj, getOwner(), address);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -275,7 +270,7 @@ public class MachineTrader extends TileBase {
|
||||
return super.getInternalInventory();
|
||||
}
|
||||
|
||||
return (TradeStation) PostManager.postRegistry.getOrCreateTradeStation(worldObj, getOwnerProfile(), address);
|
||||
return (TradeStation) PostManager.postRegistry.getOrCreateTradeStation(worldObj, getOwner(), address);
|
||||
}
|
||||
|
||||
/* ITRIGGERPROVIDER */
|
||||
|
||||
@@ -29,9 +29,8 @@ import forestry.api.mail.ITradeStation;
|
||||
import forestry.api.mail.PostManager;
|
||||
import forestry.api.mail.TradeStationInfo;
|
||||
import forestry.core.gui.IGuiSelectable;
|
||||
import forestry.core.network.PacketIds;
|
||||
import forestry.core.network.PacketPayload;
|
||||
import forestry.core.network.PacketUpdate;
|
||||
import forestry.core.network.PacketGuiSelect;
|
||||
import forestry.core.network.PacketId;
|
||||
import forestry.core.proxy.Proxies;
|
||||
import forestry.mail.EnumStationState;
|
||||
import forestry.mail.network.PacketLetterInfo;
|
||||
@@ -132,9 +131,7 @@ public class ContainerCatalogue extends Container implements IGuiSelectable {
|
||||
|
||||
public void cycleFilter() {
|
||||
if (!Proxies.common.isSimulating(player.worldObj)) {
|
||||
PacketPayload payload = new PacketPayload(1, 0, 0);
|
||||
payload.intPayload[0] = 2;
|
||||
PacketUpdate packet = new PacketUpdate(PacketIds.GUI_SELECTION_CHANGE, payload);
|
||||
PacketGuiSelect packet = new PacketGuiSelect(PacketId.GUI_SELECTION_CHANGE, 2, 0);
|
||||
Proxies.net.sendToServer(packet);
|
||||
return;
|
||||
}
|
||||
@@ -144,10 +141,9 @@ public class ContainerCatalogue extends Container implements IGuiSelectable {
|
||||
rebuildStationsList();
|
||||
}
|
||||
|
||||
private void sendSelection(boolean advance) {
|
||||
PacketPayload payload = new PacketPayload(1, 0, 0);
|
||||
payload.intPayload[0] = advance ? 0 : 1;
|
||||
PacketUpdate packet = new PacketUpdate(PacketIds.GUI_SELECTION_CHANGE, payload);
|
||||
private static void sendSelection(boolean advance) {
|
||||
int value = advance ? 0 : 1;
|
||||
PacketGuiSelect packet = new PacketGuiSelect(PacketId.GUI_SELECTION_CHANGE, value, 0);
|
||||
Proxies.net.sendToServer(packet);
|
||||
}
|
||||
|
||||
@@ -191,7 +187,7 @@ public class ContainerCatalogue extends Container implements IGuiSelectable {
|
||||
crafter.sendProgressBarUpdate(this, 2, currentFilter);
|
||||
}
|
||||
|
||||
Proxies.net.sendToPlayer(new PacketLetterInfo(PacketIds.LETTER_INFO, EnumAddressee.TRADER, currentTrade, null), player);
|
||||
Proxies.net.sendToPlayer(new PacketLetterInfo(PacketId.LETTER_INFO, EnumAddressee.TRADER, currentTrade, null), player);
|
||||
needsSynch = false;
|
||||
}
|
||||
}
|
||||
@@ -217,21 +213,24 @@ public class ContainerCatalogue extends Container implements IGuiSelectable {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleSelectionChange(EntityPlayer player, PacketUpdate packet) {
|
||||
public void handleSelectionChange(EntityPlayer player, PacketGuiSelect packet) {
|
||||
|
||||
if (packet.payload.intPayload[0] == 0) {
|
||||
nextPage();
|
||||
} else if (packet.payload.intPayload[0] == 1) {
|
||||
previousPage();
|
||||
} else if (packet.payload.intPayload[0] == 2) {
|
||||
cycleFilter();
|
||||
switch (packet.getPrimaryIndex()) {
|
||||
case 0:
|
||||
nextPage();
|
||||
break;
|
||||
case 1:
|
||||
previousPage();
|
||||
break;
|
||||
case 2:
|
||||
cycleFilter();
|
||||
break;
|
||||
}
|
||||
|
||||
needsSynch = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSelection(PacketUpdate packet) {
|
||||
public void setSelection(PacketGuiSelect packet) {
|
||||
}
|
||||
|
||||
}
|
||||
@@ -13,8 +13,6 @@ package forestry.mail.gui;
|
||||
import java.util.Iterator;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.world.World;
|
||||
@@ -30,13 +28,13 @@ import forestry.api.mail.PostManager;
|
||||
import forestry.api.mail.TradeStationInfo;
|
||||
import forestry.core.gui.ContainerItemInventory;
|
||||
import forestry.core.gui.slots.SlotFiltered;
|
||||
import forestry.core.network.PacketIds;
|
||||
import forestry.core.network.PacketPayload;
|
||||
import forestry.core.network.PacketUpdate;
|
||||
import forestry.core.network.PacketId;
|
||||
import forestry.core.network.PacketString;
|
||||
import forestry.core.proxy.Proxies;
|
||||
import forestry.mail.Letter;
|
||||
import forestry.mail.items.ItemLetter.LetterInventory;
|
||||
import forestry.mail.network.PacketLetterInfo;
|
||||
import forestry.mail.network.PacketRequestLetterInfo;
|
||||
|
||||
public class ContainerLetter extends ContainerItemInventory<LetterInventory> {
|
||||
|
||||
@@ -123,37 +121,11 @@ public class ContainerLetter extends ContainerItemInventory<LetterInventory> {
|
||||
setCarrierType(postal.getType());
|
||||
}
|
||||
|
||||
public static void setRecipient(String recipientName, EnumAddressee type) {
|
||||
if (StringUtils.isBlank(recipientName) || type == null) {
|
||||
return;
|
||||
}
|
||||
public void handleRequestLetterInfo(EntityPlayer player, PacketRequestLetterInfo packet) {
|
||||
String recipientName = packet.getRecipientName();
|
||||
EnumAddressee type = packet.getAddressType();
|
||||
|
||||
// / Send to server
|
||||
PacketPayload payload = new PacketPayload(0, 0, 2);
|
||||
payload.stringPayload[0] = recipientName;
|
||||
payload.stringPayload[1] = type.toString();
|
||||
|
||||
PacketUpdate packet = new PacketUpdate(PacketIds.LETTER_RECIPIENT, payload);
|
||||
Proxies.net.sendToServer(packet);
|
||||
}
|
||||
|
||||
public void handleSetRecipient(EntityPlayer player, PacketUpdate packet) {
|
||||
String recipientName = packet.payload.stringPayload[0];
|
||||
String typeName = packet.payload.stringPayload[1];
|
||||
|
||||
EnumAddressee type = EnumAddressee.fromString(typeName);
|
||||
IMailAddress recipient;
|
||||
if (type == EnumAddressee.PLAYER) {
|
||||
GameProfile gameProfile = MinecraftServer.getServer().func_152358_ax().func_152655_a(recipientName);
|
||||
if (gameProfile == null) {
|
||||
gameProfile = new GameProfile(new UUID(0, 0), recipientName);
|
||||
}
|
||||
recipient = PostManager.postRegistry.getMailAddress(gameProfile);
|
||||
} else if (type == EnumAddressee.TRADER) {
|
||||
recipient = PostManager.postRegistry.getMailAddress(recipientName);
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
IMailAddress recipient = getRecipient(recipientName, type);
|
||||
|
||||
getLetter().setRecipient(recipient);
|
||||
|
||||
@@ -163,7 +135,24 @@ public class ContainerLetter extends ContainerItemInventory<LetterInventory> {
|
||||
}
|
||||
|
||||
// Update info on client
|
||||
Proxies.net.sendToPlayer(new PacketLetterInfo(PacketIds.LETTER_INFO, type, tradeInfo, recipient), player);
|
||||
Proxies.net.sendToPlayer(new PacketLetterInfo(PacketId.LETTER_INFO, type, tradeInfo, recipient), player);
|
||||
}
|
||||
|
||||
public static IMailAddress getRecipient(String recipientName, EnumAddressee type) {
|
||||
switch (type) {
|
||||
case PLAYER: {
|
||||
GameProfile gameProfile = MinecraftServer.getServer().func_152358_ax().func_152655_a(recipientName);
|
||||
if (gameProfile == null) {
|
||||
gameProfile = new GameProfile(new UUID(0, 0), recipientName);
|
||||
}
|
||||
return PostManager.postRegistry.getMailAddress(gameProfile);
|
||||
}
|
||||
case TRADER: {
|
||||
return PostManager.postRegistry.getMailAddress(recipientName);
|
||||
}
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public IMailAddress getRecipient() {
|
||||
@@ -181,17 +170,13 @@ public class ContainerLetter extends ContainerItemInventory<LetterInventory> {
|
||||
public void setText(String text) {
|
||||
getLetter().setText(text);
|
||||
|
||||
// / Send to server
|
||||
PacketPayload payload = new PacketPayload(0, 0, 1);
|
||||
payload.stringPayload[0] = text;
|
||||
|
||||
PacketUpdate packet = new PacketUpdate(PacketIds.LETTER_TEXT, payload);
|
||||
PacketString packet = new PacketString(PacketId.LETTER_TEXT, text);
|
||||
Proxies.net.sendToServer(packet);
|
||||
|
||||
}
|
||||
|
||||
public void handleSetText(PacketUpdate packet) {
|
||||
String text = packet.payload.stringPayload[0];
|
||||
public void handleSetText(PacketString packet) {
|
||||
String text = packet.getString();
|
||||
getLetter().setText(text);
|
||||
}
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@ import net.minecraft.item.ItemStack;
|
||||
|
||||
import forestry.core.gui.ContainerTile;
|
||||
import forestry.core.gui.slots.SlotOutput;
|
||||
import forestry.core.network.PacketIds;
|
||||
import forestry.core.network.PacketId;
|
||||
import forestry.core.proxy.Proxies;
|
||||
import forestry.core.utils.GuiUtil;
|
||||
import forestry.mail.POBox;
|
||||
@@ -56,7 +56,7 @@ public class ContainerMailbox extends ContainerTile<MachineMailbox> {
|
||||
if (GuiUtil.isIndexInRange(slotIndex, SLOT_LETTERS, SLOT_LETTERS_COUNT)) {
|
||||
if (Proxies.common.isSimulating(player.worldObj) && mailInventory != null) {
|
||||
POBoxInfo info = mailInventory.getPOBoxInfo();
|
||||
Proxies.net.sendToPlayer(new PacketPOBoxInfo(PacketIds.POBOX_INFO, info), player);
|
||||
Proxies.net.sendToPlayer(new PacketPOBoxInfo(PacketId.POBOX_INFO, info), player);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -18,9 +18,8 @@ import net.minecraft.inventory.Container;
|
||||
|
||||
import forestry.api.mail.IMailAddress;
|
||||
import forestry.api.mail.PostManager;
|
||||
import forestry.core.network.PacketIds;
|
||||
import forestry.core.network.PacketPayload;
|
||||
import forestry.core.network.PacketUpdate;
|
||||
import forestry.core.network.PacketId;
|
||||
import forestry.core.network.PacketString;
|
||||
import forestry.core.proxy.Proxies;
|
||||
import forestry.mail.gadgets.MachineTrader;
|
||||
|
||||
@@ -42,18 +41,15 @@ public class ContainerTradeName extends Container {
|
||||
return;
|
||||
}
|
||||
|
||||
PacketPayload payload = new PacketPayload(0, 0, 1);
|
||||
payload.stringPayload[0] = addressName;
|
||||
|
||||
PacketUpdate packet = new PacketUpdate(PacketIds.TRADING_ADDRESS_SET, payload);
|
||||
PacketString packet = new PacketString(PacketId.TRADING_ADDRESS_SET, addressName);
|
||||
Proxies.net.sendToServer(packet);
|
||||
|
||||
IMailAddress address = PostManager.postRegistry.getMailAddress(addressName);
|
||||
machine.setAddress(address);
|
||||
}
|
||||
|
||||
public void handleSetAddress(PacketUpdate packet) {
|
||||
String addressName = packet.payload.stringPayload[0];
|
||||
public void handleSetAddress(PacketString packet) {
|
||||
String addressName = packet.getString();
|
||||
IMailAddress address = PostManager.postRegistry.getMailAddress(addressName);
|
||||
machine.setAddress(address);
|
||||
}
|
||||
|
||||
@@ -32,6 +32,7 @@ import forestry.core.gui.widgets.Widget;
|
||||
import forestry.core.proxy.Proxies;
|
||||
import forestry.core.utils.StringUtil;
|
||||
import forestry.mail.items.ItemLetter.LetterInventory;
|
||||
import forestry.mail.network.PacketRequestLetterInfo;
|
||||
|
||||
public class GuiLetter extends GuiForestry<ContainerLetter, LetterInventory> {
|
||||
|
||||
@@ -271,7 +272,8 @@ public class GuiLetter extends GuiForestry<ContainerLetter, LetterInventory> {
|
||||
return;
|
||||
}
|
||||
|
||||
container.setRecipient(recipientName, type);
|
||||
PacketRequestLetterInfo packet = new PacketRequestLetterInfo(recipientName, type);
|
||||
Proxies.net.sendToServer(packet);
|
||||
}
|
||||
|
||||
private void setText() {
|
||||
|
||||
@@ -24,6 +24,8 @@ import forestry.api.mail.IMailAddress;
|
||||
import forestry.api.mail.PostManager;
|
||||
import forestry.api.mail.TradeStationInfo;
|
||||
import forestry.core.network.ForestryPacket;
|
||||
import forestry.core.network.PacketHelper;
|
||||
import forestry.core.network.PacketId;
|
||||
import forestry.mail.EnumStationState;
|
||||
|
||||
public class PacketLetterInfo extends ForestryPacket {
|
||||
@@ -32,10 +34,11 @@ public class PacketLetterInfo extends ForestryPacket {
|
||||
public TradeStationInfo tradeInfo;
|
||||
public IMailAddress address;
|
||||
|
||||
public PacketLetterInfo() {
|
||||
public PacketLetterInfo(DataInputStream data) throws IOException {
|
||||
super(data);
|
||||
}
|
||||
|
||||
public PacketLetterInfo(int id, EnumAddressee type, TradeStationInfo info, IMailAddress address) {
|
||||
public PacketLetterInfo(PacketId id, EnumAddressee type, TradeStationInfo info, IMailAddress address) {
|
||||
super(id);
|
||||
this.type = type;
|
||||
if (type == EnumAddressee.TRADER) {
|
||||
@@ -85,11 +88,9 @@ public class PacketLetterInfo extends ForestryPacket {
|
||||
data.writeLong(tradeInfo.owner.getId().getLeastSignificantBits());
|
||||
data.writeUTF(tradeInfo.owner.getName());
|
||||
|
||||
writeItemStack(tradeInfo.tradegood, data);
|
||||
data.writeShort(tradeInfo.required.length);
|
||||
for (int i = 0; i < tradeInfo.required.length; i++) {
|
||||
writeItemStack(tradeInfo.required[i], data);
|
||||
}
|
||||
PacketHelper.writeItemStack(tradeInfo.tradegood, data);
|
||||
PacketHelper.writeItemStacks(tradeInfo.required, data);
|
||||
|
||||
data.writeShort(tradeInfo.state.ordinal());
|
||||
}
|
||||
}
|
||||
@@ -119,11 +120,8 @@ public class PacketLetterInfo extends ForestryPacket {
|
||||
ItemStack tradegood;
|
||||
ItemStack[] required;
|
||||
|
||||
tradegood = readItemStack(data);
|
||||
required = new ItemStack[data.readShort()];
|
||||
for (int i = 0; i < required.length; i++) {
|
||||
required[i] = readItemStack(data);
|
||||
}
|
||||
tradegood = PacketHelper.readItemStack(data);
|
||||
required = PacketHelper.readItemStacks(data);
|
||||
|
||||
this.tradeInfo = new TradeStationInfo(address, owner, tradegood, required, EnumStationState.values()[data.readShort()]);
|
||||
}
|
||||
|
||||
Loaded 100 of 115 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user