From 08d01c039457255b6e5041dd9203972e0d8b1a24 Mon Sep 17 00:00:00 2001 From: SpaceToad Date: Sat, 11 Jan 2014 13:59:30 +0100 Subject: [PATCH] Re-introduction of the builder block Added back the builder block to the world, with fixes of initial obvious errors. TileArchitect is now passing its name through RPCs. --- common/buildcraft/builders/BlockBuilder.java | 5 ++++- common/buildcraft/builders/ItemBlueprint.java | 4 ++++ common/buildcraft/builders/TileArchitect.java | 11 +++++++++-- .../builders/blueprints/BlueprintMeta.java | 4 ++-- common/buildcraft/builders/gui/GuiTemplate.java | 13 +++++-------- common/buildcraft/core/network/RPCHandler.java | 6 ++++++ 6 files changed, 30 insertions(+), 13 deletions(-) diff --git a/common/buildcraft/builders/BlockBuilder.java b/common/buildcraft/builders/BlockBuilder.java index 0fa76e91..030e2883 100644 --- a/common/buildcraft/builders/BlockBuilder.java +++ b/common/buildcraft/builders/BlockBuilder.java @@ -10,12 +10,15 @@ package buildcraft.builders; import buildcraft.BuildCraftBuilders; import buildcraft.api.core.Position; import buildcraft.api.tools.IToolWrench; +import buildcraft.core.CreativeTabBuildCraft; import buildcraft.core.GuiIds; import buildcraft.core.proxy.CoreProxy; import buildcraft.core.utils.Utils; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; + import java.util.ArrayList; + import net.minecraft.block.BlockContainer; import net.minecraft.block.material.Material; import net.minecraft.client.renderer.texture.IconRegister; @@ -37,7 +40,7 @@ public class BlockBuilder extends BlockContainer { public BlockBuilder(int i) { super(i, Material.iron); setHardness(5F); - setCreativeTab(null); + setCreativeTab(CreativeTabBuildCraft.MACHINES.get()); } @Override diff --git a/common/buildcraft/builders/ItemBlueprint.java b/common/buildcraft/builders/ItemBlueprint.java index c9adc9a7..1e24f5dd 100644 --- a/common/buildcraft/builders/ItemBlueprint.java +++ b/common/buildcraft/builders/ItemBlueprint.java @@ -41,6 +41,10 @@ public abstract class ItemBlueprint extends ItemBuildCraft { } public static Blueprint getBlueprint(ItemStack stack) { + if (stack == null) { + return null; + } + NBTTagCompound nbt = NBTUtils.getItemData(stack); byte[] idRaw = nbt.getByteArray("blueprint"); BlueprintId id = BlueprintId.fromRawId(idRaw); diff --git a/common/buildcraft/builders/TileArchitect.java b/common/buildcraft/builders/TileArchitect.java index b6ada357..4f154cdf 100644 --- a/common/buildcraft/builders/TileArchitect.java +++ b/common/buildcraft/builders/TileArchitect.java @@ -16,9 +16,13 @@ import buildcraft.core.Box; import buildcraft.core.TileBuildCraft; import buildcraft.core.network.PacketUpdate; import buildcraft.core.network.NetworkData; +import buildcraft.core.network.RPC; +import buildcraft.core.network.RPCSide; import buildcraft.core.proxy.CoreProxy; import buildcraft.core.utils.Utils; + import java.io.IOException; + import net.minecraft.block.Block; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.IInventory; @@ -34,8 +38,9 @@ public class TileArchitect extends TileBuildCraft implements IInventory { private ItemStack items[] = new ItemStack[2]; private boolean isComputing = false; public int computingTime = 0; - public @NetworkData - String name = ""; + + @NetworkData + public String name = ""; @Override public void updateEntity() { @@ -139,6 +144,7 @@ public class TileArchitect extends TileBuildCraft implements IInventory { return blueprint; } + @RPC public void handleClientInput(char c) { if (c == 8) { if (name.length() > 0) { @@ -333,4 +339,5 @@ public class TileArchitect extends TileBuildCraft implements IInventory { @Override public void closeChest() { } + } diff --git a/common/buildcraft/builders/blueprints/BlueprintMeta.java b/common/buildcraft/builders/blueprints/BlueprintMeta.java index 7fffe044..6c4b77b0 100644 --- a/common/buildcraft/builders/blueprints/BlueprintMeta.java +++ b/common/buildcraft/builders/blueprints/BlueprintMeta.java @@ -11,10 +11,10 @@ public class BlueprintMeta { public BlueprintId id; @NetworkData - public String name; + public String name = ""; @NetworkData - public String creator; + public String creator = ""; public BlueprintMeta() { diff --git a/common/buildcraft/builders/gui/GuiTemplate.java b/common/buildcraft/builders/gui/GuiTemplate.java index 680cf74e..5ba60ec4 100644 --- a/common/buildcraft/builders/gui/GuiTemplate.java +++ b/common/buildcraft/builders/gui/GuiTemplate.java @@ -14,6 +14,7 @@ import buildcraft.core.network.PacketIds; import buildcraft.core.network.PacketPayload; import buildcraft.core.network.PacketPayloadStream; import buildcraft.core.network.PacketUpdate; +import buildcraft.core.network.RPCHandler; import buildcraft.core.proxy.CoreProxy; import buildcraft.core.utils.StringUtils; @@ -82,19 +83,15 @@ public class GuiTemplate extends GuiBuildCraft { @Override protected void keyTyped(char c, int i) { - // FIXME: Not much point to port this to stream payload at this stage, - // should use a RPC instead. - /*if (i != 1 && editMode) { + if (i != 1 && editMode) { if (c == 13) { editMode = false; return; } - PacketPayloadStream payload = new PacketPayloadStream(); - payload.intPayload = new int[]{c}; - PacketUpdate packet = new PacketUpdate(PacketIds.ARCHITECT_NAME, template.xCoord, template.yCoord, template.zCoord, payload); - CoreProxy.proxy.sendToServer(packet.getPacket()); + + RPCHandler.rpcServer(template, "handleClientInput", c); } else { super.keyTyped(c, i); - }*/ + } } } diff --git a/common/buildcraft/core/network/RPCHandler.java b/common/buildcraft/core/network/RPCHandler.java index b7fbd038..50b040bb 100755 --- a/common/buildcraft/core/network/RPCHandler.java +++ b/common/buildcraft/core/network/RPCHandler.java @@ -73,6 +73,8 @@ public class RPCHandler { for (int j = 0; j < mapping.parameters.length; ++j) { if (mapping.parameters [j].equals(int.class)) { // accepted + } else if (mapping.parameters [j].equals(char.class)) { + // accepted } else if (mapping.parameters [j].equals(String.class)) { // accepted } else if (mapping.parameters [j].equals(RPCMessageInfo.class)) { @@ -156,6 +158,8 @@ public class RPCHandler { for (int i = 0; i < actuals.length; ++i) { if (formals [i].equals(int.class)) { data.writeInt((Integer) actuals [i]); + } else if (formals [i].equals(char.class)) { + data.writeChar((Character) actuals [i]); } else if (formals [i].equals(String.class)) { data.writeUTF((String) actuals [i]); } else { @@ -191,6 +195,8 @@ public class RPCHandler { for (int i = 0; i < expectedParameters; ++i) { if (formals [i].equals(int.class)) { actuals [i] = data.readInt(); + } else if (formals [i].equals(char.class)) { + actuals [i] = data.readChar(); } else if (formals [i].equals(String.class)) { actuals [i] = data.readUTF(); } else {