From 8f7f8d31ad3323f6b17e72ad51b95b28c873d7dd Mon Sep 17 00:00:00 2001 From: SpaceToad Date: Mon, 10 Feb 2014 18:06:44 +0100 Subject: [PATCH] fixed player in net handler and deprecated proxies --- common/buildcraft/BuildCraftMod.java | 5 - .../buildcraft/builders/BlockArchitect.java | 2 +- .../builders/BlockBlueprintLibrary.java | 4 +- common/buildcraft/builders/BlockBuilder.java | 2 +- common/buildcraft/builders/BlockFiller.java | 2 +- common/buildcraft/builders/ItemBptBase.java | 2 +- common/buildcraft/builders/TileArchitect.java | 4 +- .../builders/TileBlueprintLibrary.java | 6 +- common/buildcraft/builders/TileBuilder.java | 8 +- common/buildcraft/builders/TileFiller.java | 6 +- common/buildcraft/builders/TileMarker.java | 7 +- .../buildcraft/builders/TilePathMarker.java | 13 ++- .../network/PacketHandlerBuilders.java | 7 +- common/buildcraft/core/EntityLaser.java | 4 +- common/buildcraft/core/EntityRobot.java | 2 +- common/buildcraft/core/TileBuildCraft.java | 2 +- .../core/gui/GuiAdvancedInterface.java | 3 +- .../core/network/PacketHandler.java | 8 +- .../buildcraft/core/network/PacketUpdate.java | 2 + common/buildcraft/core/proxy/CoreProxy.java | 28 ++---- .../core/proxy/CoreProxyClient.java | 7 +- common/buildcraft/core/utils/Utils.java | 18 +++- common/buildcraft/energy/TileEngine.java | 11 ++- common/buildcraft/energy/TileEngineIron.java | 6 +- common/buildcraft/energy/TileEngineStone.java | 2 +- common/buildcraft/energy/TileEngineWood.java | 2 +- .../factory/BlockAutoWorkbench.java | 2 +- common/buildcraft/factory/BlockHopper.java | 2 +- common/buildcraft/factory/BlockQuarry.java | 4 +- .../buildcraft/factory/TileAutoWorkbench.java | 2 +- common/buildcraft/factory/TileFloodGate.java | 2 +- common/buildcraft/factory/TileHopper.java | 2 +- common/buildcraft/factory/TileQuarry.java | 10 +- common/buildcraft/factory/TileRefinery.java | 2 +- common/buildcraft/factory/TileTank.java | 2 +- .../factory/gui/ContainerAutoWorkbench.java | 2 +- .../factory/gui/ContainerRefinery.java | 2 +- .../factory/network/PacketHandlerFactory.java | 5 +- .../buildcraft/silicon/BlockLaserTable.java | 2 +- .../silicon/TileAdvancedCraftingTable.java | 4 +- common/buildcraft/silicon/TileLaser.java | 2 +- .../silicon/gui/GuiAssemblyTable.java | 7 +- .../silicon/network/PacketHandlerSilicon.java | 4 +- .../transport/BlockFilteredBuffer.java | 2 +- .../transport/BlockGenericPipe.java | 8 +- common/buildcraft/transport/Gate.java | 2 +- .../transport/PipeTransportFluids.java | 3 +- .../transport/PipeTransportPower.java | 3 +- .../buildcraft/transport/TileGenericPipe.java | 2 +- .../buildcraft/transport/TravelingItem.java | 2 +- .../transport/gui/ContainerGateInterface.java | 99 +++++++++++++------ .../transport/gui/GuiEmeraldPipe.java | 2 +- .../transport/gui/GuiGateInterface.java | 38 ++++--- .../network/PacketHandlerTransport.java | 23 ++--- .../PacketPipeTransportItemStackRequest.java | 2 +- .../transport/pipes/PipeItemsDiamond.java | 2 +- .../transport/pipes/PipeItemsEmerald.java | 2 +- .../transport/pipes/PipeItemsEmzuli.java | 2 +- .../transport/pipes/PipeItemsObsidian.java | 3 +- .../transport/pipes/PipeLogicWood.java | 4 +- 60 files changed, 237 insertions(+), 181 deletions(-) diff --git a/common/buildcraft/BuildCraftMod.java b/common/buildcraft/BuildCraftMod.java index 73874e92..37474249 100755 --- a/common/buildcraft/BuildCraftMod.java +++ b/common/buildcraft/BuildCraftMod.java @@ -30,11 +30,6 @@ public class BuildCraftMod { channels.get(Side.SERVER).attr(FMLOutboundHandler.FML_MESSAGETARGETARGS).set(entityplayer); channels.get(Side.SERVER).writeOutbound(packet); } - - public void replyToPlayer(EntityPlayer entityplayer, BuildCraftPacket packet) { - channels.get(Side.SERVER).attr(FMLOutboundHandler.FML_MESSAGETARGET).set(OutboundTarget.REPLY); - channels.get(Side.SERVER).writeOutbound(packet); - } public void sendToServer(BuildCraftPacket packet) { channels.get(Side.CLIENT).attr(FMLOutboundHandler.FML_MESSAGETARGET).set(OutboundTarget.TOSERVER); diff --git a/common/buildcraft/builders/BlockArchitect.java b/common/buildcraft/builders/BlockArchitect.java index 0cfa5775..cb2f3420 100644 --- a/common/buildcraft/builders/BlockArchitect.java +++ b/common/buildcraft/builders/BlockArchitect.java @@ -86,7 +86,7 @@ public class BlockArchitect extends BlockContainer { return true; } else { - if (!CoreProxy.proxy.isRenderWorld(world)) { + if (!world.isRemote) { entityplayer.openGui(BuildCraftBuilders.instance, GuiIds.ARCHITECT_TABLE, world, i, j, k); } return true; diff --git a/common/buildcraft/builders/BlockBlueprintLibrary.java b/common/buildcraft/builders/BlockBlueprintLibrary.java index 03f2eee8..dd78f65e 100644 --- a/common/buildcraft/builders/BlockBlueprintLibrary.java +++ b/common/buildcraft/builders/BlockBlueprintLibrary.java @@ -47,7 +47,7 @@ public class BlockBlueprintLibrary extends BlockContainer { TileBlueprintLibrary tile = (TileBlueprintLibrary) world.getTileEntity(i, j, k); if (!tile.locked || entityplayer.getDisplayName().equals(tile.owner)) - if (!CoreProxy.proxy.isRenderWorld(world)) { + if (!world.isRemote) { entityplayer.openGui(BuildCraftBuilders.instance, GuiIds.BLUEPRINT_LIBRARY, world, i, j, k); } @@ -72,7 +72,7 @@ public class BlockBlueprintLibrary extends BlockContainer { @Override public void onBlockPlacedBy(World world, int i, int j, int k, EntityLivingBase entityliving, ItemStack stack) { - if (CoreProxy.proxy.isSimulating(world) && entityliving instanceof EntityPlayer) { + if (!world.isRemote && entityliving instanceof EntityPlayer) { TileBlueprintLibrary tile = (TileBlueprintLibrary) world.getTileEntity(i, j, k); tile.owner = ((EntityPlayer) entityliving).getDisplayName(); } diff --git a/common/buildcraft/builders/BlockBuilder.java b/common/buildcraft/builders/BlockBuilder.java index 41dd7365..b3a29888 100644 --- a/common/buildcraft/builders/BlockBuilder.java +++ b/common/buildcraft/builders/BlockBuilder.java @@ -97,7 +97,7 @@ public class BlockBuilder extends BlockContainer { return true; } else { - if (!CoreProxy.proxy.isRenderWorld(world)) { + if (!world.isRemote) { entityplayer.openGui(BuildCraftBuilders.instance, GuiIds.BUILDER, world, i, j, k); } return true; diff --git a/common/buildcraft/builders/BlockFiller.java b/common/buildcraft/builders/BlockFiller.java index 63ad1ea6..f38fe06e 100644 --- a/common/buildcraft/builders/BlockFiller.java +++ b/common/buildcraft/builders/BlockFiller.java @@ -52,7 +52,7 @@ public class BlockFiller extends BlockContainer { if (entityplayer.isSneaking()) return false; - if (!CoreProxy.proxy.isRenderWorld(world)) { + if (!world.isRemote) { entityplayer.openGui(BuildCraftBuilders.instance, GuiIds.FILLER, world, i, j, k); } return true; diff --git a/common/buildcraft/builders/ItemBptBase.java b/common/buildcraft/builders/ItemBptBase.java index 8d81ea6a..46a9b2b2 100644 --- a/common/buildcraft/builders/ItemBptBase.java +++ b/common/buildcraft/builders/ItemBptBase.java @@ -44,7 +44,7 @@ public abstract class ItemBptBase extends ItemBuildCraft { @Override public ItemStack onItemRightClick(ItemStack itemStack, World world, EntityPlayer player) { - if (CoreProxy.proxy.isSimulating(world)) { + if (!world.isRemote) { BptBase bpt = BuildCraftBuilders.getBptRootIndex().getBluePrint(itemStack.getItemDamage()); if (bpt != null) return BuildCraftBuilders.getBptItemStack(itemStack.getItem(), itemStack.getItemDamage(), bpt.getName()); diff --git a/common/buildcraft/builders/TileArchitect.java b/common/buildcraft/builders/TileArchitect.java index 5c8e2566..ac7c00d3 100644 --- a/common/buildcraft/builders/TileArchitect.java +++ b/common/buildcraft/builders/TileArchitect.java @@ -45,7 +45,7 @@ public class TileArchitect extends TileBuildCraft implements IInventory { public void updateEntity() { super.updateEntity(); - if (CoreProxy.proxy.isSimulating(worldObj) && isComputing) { + if (!worldObj.isRemote && isComputing) { if (computingTime < 200) { computingTime++; } else { @@ -68,7 +68,7 @@ public class TileArchitect extends TileBuildCraft implements IInventory { } } - if (!CoreProxy.proxy.isRenderWorld(worldObj) && box.isInitialized()) { + if (!worldObj.isRemote && box.isInitialized()) { box.createLasers(worldObj, LaserKind.Stripes); } diff --git a/common/buildcraft/builders/TileBlueprintLibrary.java b/common/buildcraft/builders/TileBlueprintLibrary.java index f1239550..c8f7ac40 100644 --- a/common/buildcraft/builders/TileBlueprintLibrary.java +++ b/common/buildcraft/builders/TileBlueprintLibrary.java @@ -44,7 +44,7 @@ public class TileBlueprintLibrary extends TileBuildCraft implements IInventory { @Override public void initialize() { super.initialize(); - if (CoreProxy.proxy.isSimulating(worldObj)) { + if (!worldObj.isRemote) { setCurrentPage(getNextPage(null)); } } @@ -250,8 +250,10 @@ public class TileBlueprintLibrary extends TileBuildCraft implements IInventory { @Override public void updateEntity() { super.updateEntity(); - if (CoreProxy.proxy.isRenderWorld(worldObj)) + + if (worldObj.isRemote) { return; + } if (progressIn > 0 && progressIn < 100) { progressIn++; diff --git a/common/buildcraft/builders/TileBuilder.java b/common/buildcraft/builders/TileBuilder.java index 0ce0f28c..1e705e62 100644 --- a/common/buildcraft/builders/TileBuilder.java +++ b/common/buildcraft/builders/TileBuilder.java @@ -177,8 +177,9 @@ public class TileBuilder extends TileBuildCraft implements IBuilderInventory, IP public void initialize() { super.initialize(); - if (CoreProxy.proxy.isRenderWorld(worldObj)) + if (worldObj.isRemote) { return; + } for (int x = xCoord - 1; x <= xCoord + 1; ++x) { for (int y = yCoord - 1; y <= yCoord + 1; ++y) { @@ -264,8 +265,9 @@ public class TileBuilder extends TileBuildCraft implements IBuilderInventory, IP @Override public void doWork(PowerHandler workProvider) { - if (CoreProxy.proxy.isRenderWorld(worldObj)) + if (worldObj.isRemote) { return; + } if (done) return; @@ -566,7 +568,7 @@ public class TileBuilder extends TileBuildCraft implements IBuilderInventory, IP box.deleteLasers(); box.reset(); - if (CoreProxy.proxy.isSimulating(worldObj)) { + if (!worldObj.isRemote) { sendNetworkUpdate(BuildCraftBuilders.instance); } diff --git a/common/buildcraft/builders/TileFiller.java b/common/buildcraft/builders/TileFiller.java index 833bbd86..b6f07b97 100644 --- a/common/buildcraft/builders/TileFiller.java +++ b/common/buildcraft/builders/TileFiller.java @@ -74,7 +74,7 @@ public class TileFiller extends TileBuildCraft implements IInventory, IPowerRece public void initialize() { super.initialize(); - if (!CoreProxy.proxy.isRenderWorld(worldObj)) { + if (!worldObj.isRemote) { IAreaProvider a = Utils.getNearbyAreaProvider(worldObj, xCoord, yCoord, zCoord); if (a != null) { @@ -84,7 +84,7 @@ public class TileFiller extends TileBuildCraft implements IInventory, IPowerRece ((TileMarker) a).removeFromWorld(); } - if (!CoreProxy.proxy.isRenderWorld(worldObj) && box.isInitialized()) { + if (!worldObj.isRemote && box.isInitialized()) { box.createLasers(worldObj, LaserKind.Stripes); } sendNetworkUpdate(BuildCraftBuilders.instance); @@ -104,7 +104,7 @@ public class TileFiller extends TileBuildCraft implements IInventory, IPowerRece @Override public void doWork(PowerHandler workProvider) { - if (CoreProxy.proxy.isRenderWorld(worldObj)) + if (worldObj.isRemote) return; if (done) return; diff --git a/common/buildcraft/builders/TileMarker.java b/common/buildcraft/builders/TileMarker.java index d6502907..6b365d56 100644 --- a/common/buildcraft/builders/TileMarker.java +++ b/common/buildcraft/builders/TileMarker.java @@ -91,7 +91,7 @@ public class TileMarker extends TileBuildCraft implements IAreaProvider { boolean showSignals = false; public void updateSignals() { - if (CoreProxy.proxy.isSimulating(worldObj)) { + if (!worldObj.isRemote) { showSignals = worldObj.isBlockIndirectlyGettingPowered(xCoord, yCoord, zCoord); sendNetworkUpdate(BuildCraftBuilders.instance); } @@ -153,8 +153,9 @@ public class TileMarker extends TileBuildCraft implements IAreaProvider { } public void tryConnection() { - if (CoreProxy.proxy.isRenderWorld(worldObj)) + if (worldObj.isRemote) { return; + } for (int j = 0; j < 3; ++j) { if (!origin.isSet() || !origin.vect[j].isSet()) { @@ -390,7 +391,7 @@ public class TileMarker extends TileBuildCraft implements IAreaProvider { signals = null; - if (CoreProxy.proxy.isSimulating(worldObj) && markerOrigin != null && markerOrigin != this) { + if (!worldObj.isRemote && markerOrigin != null && markerOrigin != this) { markerOrigin.sendNetworkUpdate(BuildCraftBuilders.instance); } } diff --git a/common/buildcraft/builders/TilePathMarker.java b/common/buildcraft/builders/TilePathMarker.java index dcf2e8bc..d00e01d1 100644 --- a/common/buildcraft/builders/TilePathMarker.java +++ b/common/buildcraft/builders/TilePathMarker.java @@ -55,8 +55,9 @@ public class TilePathMarker extends TileMarker { public void createLaserAndConnect(TilePathMarker pathMarker) { - if (CoreProxy.proxy.isRenderWorld(worldObj)) + if (worldObj.isRemote) { return; + } EntityPowerLaser laser = new EntityPowerLaser(worldObj, new Position(xCoord + 0.5, yCoord + 0.5, zCoord + 0.5), new Position(pathMarker.xCoord + 0.5, pathMarker.yCoord + 0.5, pathMarker.zCoord + 0.5)); @@ -97,8 +98,9 @@ public class TilePathMarker extends TileMarker { @Override public void tryConnection() { - if (CoreProxy.proxy.isRenderWorld(worldObj) || isFullyConnected()) + if (worldObj.isRemote || isFullyConnected()) { return; + } tryingToConnect = !tryingToConnect; // Allow the user to stop the path marker from searching for new path markers to connect sendNetworkUpdate(BuildCraftBuilders.instance); @@ -108,8 +110,9 @@ public class TilePathMarker extends TileMarker { public void updateEntity() { super.updateEntity(); - if (CoreProxy.proxy.isRenderWorld(worldObj)) + if (worldObj.isRemote) { return; + } if (tryingToConnect) { TilePathMarker nearestPathMarker = findNearestAvailablePathMarker(); @@ -171,7 +174,7 @@ public class TilePathMarker extends TileMarker { public void initialize() { super.initialize(); - if (CoreProxy.proxy.isSimulating(worldObj) && !isFullyConnected()) { + if (!worldObj.isRemote && !isFullyConnected()) { availableMarkers.add(this); } @@ -207,7 +210,7 @@ public class TilePathMarker extends TileMarker { links[1] = null; } - if (!isFullyConnected() && !availableMarkers.contains(this) && CoreProxy.proxy.isSimulating(worldObj)) { + if (!isFullyConnected() && !availableMarkers.contains(this) && !worldObj.isRemote) { availableMarkers.add(this); } } diff --git a/common/buildcraft/builders/network/PacketHandlerBuilders.java b/common/buildcraft/builders/network/PacketHandlerBuilders.java index aa1d0cd4..857d5fd5 100644 --- a/common/buildcraft/builders/network/PacketHandlerBuilders.java +++ b/common/buildcraft/builders/network/PacketHandlerBuilders.java @@ -9,6 +9,7 @@ import buildcraft.core.network.PacketIds; import buildcraft.core.network.PacketPayloadArrays; import buildcraft.core.network.PacketUpdate; import buildcraft.core.proxy.CoreProxy; +import buildcraft.core.utils.Utils; import cpw.mods.fml.common.network.NetworkRegistry; import io.netty.buffer.ByteBuf; import io.netty.channel.ChannelHandlerContext; @@ -27,10 +28,8 @@ public class PacketHandlerBuilders extends BuildCraftChannelHandler { super.decodeInto(ctx, data, packet); try { - INetHandler netHandler = ctx.channel().attr(NetworkRegistry.NET_HANDLER).get(); - - EntityPlayer player = - CoreProxy.proxy.getPlayerFromNetHandler(netHandler); + INetHandler netHandler = ctx.channel().attr(NetworkRegistry.NET_HANDLER).get(); + EntityPlayer player = Utils.getPlayerFromNetHandler(netHandler); int packetID = packet.getID(); diff --git a/common/buildcraft/core/EntityLaser.java b/common/buildcraft/core/EntityLaser.java index f0fc3260..c5a88532 100644 --- a/common/buildcraft/core/EntityLaser.java +++ b/common/buildcraft/core/EntityLaser.java @@ -68,12 +68,12 @@ public abstract class EntityLaser extends Entity { if (head == null || tail == null) return; - if (CoreProxy.proxy.isSimulating(worldObj) && needsUpdate) { + if (!worldObj.isRemote && needsUpdate) { updateDataServer(); needsUpdate = false; } - if (CoreProxy.proxy.isRenderWorld(worldObj)) { + if (worldObj.isRemote) { updateDataClient(); } diff --git a/common/buildcraft/core/EntityRobot.java b/common/buildcraft/core/EntityRobot.java index ca01412d..880cb562 100644 --- a/common/buildcraft/core/EntityRobot.java +++ b/common/buildcraft/core/EntityRobot.java @@ -210,7 +210,7 @@ public class EntityRobot extends Entity implements IEntityAdditionalSpawnData { //System.out.printf("RobotChanging %d %d %d %s\n",target.x, target.y, target.z, target.mode); if (wait <= 0 && BlockUtil.canChangeBlock(worldObj, target.x, target.y, target.z)) { - if (!CoreProxy.proxy.isRenderWorld(worldObj)) { + if (!worldObj.isRemote) { if (target.mode == Mode.ClearIfInvalid) { diff --git a/common/buildcraft/core/TileBuildCraft.java b/common/buildcraft/core/TileBuildCraft.java index 256b4586..5545aa33 100644 --- a/common/buildcraft/core/TileBuildCraft.java +++ b/common/buildcraft/core/TileBuildCraft.java @@ -99,7 +99,7 @@ public abstract class TileBuildCraft extends TileEntity implements ISynchronized } public void sendNetworkUpdate(BuildCraftMod mod) { - if (CoreProxy.proxy.isSimulating(worldObj)) { + if (!worldObj.isRemote) { mod.sendToPlayers(getUpdatePacket(), worldObj, xCoord, yCoord, zCoord, DefaultProps.NETWORK_UPDATE_RANGE); } } diff --git a/common/buildcraft/core/gui/GuiAdvancedInterface.java b/common/buildcraft/core/gui/GuiAdvancedInterface.java index 34656dc3..36164f34 100644 --- a/common/buildcraft/core/gui/GuiAdvancedInterface.java +++ b/common/buildcraft/core/gui/GuiAdvancedInterface.java @@ -49,8 +49,9 @@ public abstract class GuiAdvancedInterface extends GuiBuildCraft { } public void drawSprite(int cornerX, int cornerY) { - if (!isDefined()) + if (!isDefined()) { return; + } if (getItemStack() != null) { drawStack(getItemStack()); diff --git a/common/buildcraft/core/network/PacketHandler.java b/common/buildcraft/core/network/PacketHandler.java index 8eb67b67..59c831a7 100644 --- a/common/buildcraft/core/network/PacketHandler.java +++ b/common/buildcraft/core/network/PacketHandler.java @@ -8,8 +8,11 @@ import java.io.DataInputStream; import java.io.IOException; import buildcraft.core.proxy.CoreProxy; +import buildcraft.core.utils.Utils; import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.network.INetHandler; +import net.minecraft.network.NetHandlerPlayServer; import net.minecraft.tileentity.TileEntity; import net.minecraft.world.World; import cpw.mods.fml.common.network.NetworkRegistry; @@ -39,11 +42,8 @@ public class PacketHandler extends BuildCraftChannelHandler { super.decodeInto(ctx, data, packet); try { - INetHandler netHandler = ctx.channel().attr(NetworkRegistry.NET_HANDLER).get(); - - EntityPlayer player = - CoreProxy.proxy.getPlayerFromNetHandler(netHandler); + EntityPlayer player = Utils.getPlayerFromNetHandler(netHandler); int packetID = packet.getID(); diff --git a/common/buildcraft/core/network/PacketUpdate.java b/common/buildcraft/core/network/PacketUpdate.java index 1010feff..25ca15c4 100644 --- a/common/buildcraft/core/network/PacketUpdate.java +++ b/common/buildcraft/core/network/PacketUpdate.java @@ -38,6 +38,7 @@ public class PacketUpdate extends BuildCraftPacket { @Override public void writeData(ByteBuf data) { + data.writeByte(packetId); data.writeInt(posX); data.writeInt(posY); data.writeInt(posZ); @@ -52,6 +53,7 @@ public class PacketUpdate extends BuildCraftPacket { @Override public void readData(ByteBuf data) { + packetId = data.readByte(); posX = data.readInt(); posY = data.readInt(); posZ = data.readInt(); diff --git a/common/buildcraft/core/proxy/CoreProxy.java b/common/buildcraft/core/proxy/CoreProxy.java index 7d7e7153..df2ecbbd 100644 --- a/common/buildcraft/core/proxy/CoreProxy.java +++ b/common/buildcraft/core/proxy/CoreProxy.java @@ -32,8 +32,6 @@ import net.minecraft.item.Item; import net.minecraft.item.ItemBlock; import net.minecraft.item.ItemStack; import net.minecraft.item.crafting.CraftingManager; -import net.minecraft.network.INetHandler; -import net.minecraft.network.NetHandlerPlayServer; import net.minecraft.network.Packet; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.ChunkCoordinates; @@ -42,6 +40,12 @@ import net.minecraft.world.World; import net.minecraftforge.oredict.ShapedOreRecipe; import net.minecraftforge.oredict.ShapelessOreRecipe; + +/** + * This class comes from the old times where there were two Minecrafts + * codebases, one client and one server. We should slowly aim at removing it. + */ +@Deprecated public class CoreProxy { @SidedProxy(clientSide = "buildcraft.core.proxy.CoreProxyClient", serverSide = "buildcraft.core.proxy.CoreProxy") @@ -60,15 +64,6 @@ public class CoreProxy { return null; } - /* SIMULATION */ - public boolean isSimulating(World world) { - return !world.isRemote; - } - - public boolean isRenderWorld(World world) { - return world.isRemote; - } - public String getCurrentLanguage() { return null; } @@ -219,15 +214,4 @@ public class CoreProxy { public EntityBlock newEntityBlock(World world, double i, double j, double k, double iSize, double jSize, double kSize, LaserKind laserKind) { return new EntityBlock(world, i, j, k, iSize, jSize, kSize); } - - /** - * This function returns either the player from the handler if it's on the - * server, or directly from the minecraft instance if it's the client. - * - * TODO: This is a bit kludgy, probably better to separate the client and - * server channels instead. - */ - public EntityPlayer getPlayerFromNetHandler (INetHandler hander) { - return ((NetHandlerPlayServer) hander).playerEntity; - } } diff --git a/common/buildcraft/core/proxy/CoreProxyClient.java b/common/buildcraft/core/proxy/CoreProxyClient.java index df801110..03134c45 100644 --- a/common/buildcraft/core/proxy/CoreProxyClient.java +++ b/common/buildcraft/core/proxy/CoreProxyClient.java @@ -67,7 +67,7 @@ public class CoreProxyClient extends CoreProxy { public void removeEntity(Entity entity) { super.removeEntity(entity); - if (isRenderWorld(entity.worldObj)) { + if (entity.worldObj.isRemote) { ((WorldClient) entity.worldObj).removeEntityFromWorld(entity.getEntityId()); } } @@ -184,9 +184,4 @@ public class CoreProxyClient extends CoreProxy { } return eb; } - - @Override - public EntityPlayer getPlayerFromNetHandler (INetHandler hander) { - return Minecraft.getMinecraft().thePlayer; - } } diff --git a/common/buildcraft/core/utils/Utils.java b/common/buildcraft/core/utils/Utils.java index 69f0423b..2f472f79 100644 --- a/common/buildcraft/core/utils/Utils.java +++ b/common/buildcraft/core/utils/Utils.java @@ -42,7 +42,9 @@ import java.util.Random; import cpw.mods.fml.common.network.internal.FMLProxyPacket; import net.minecraft.block.Block; +import net.minecraft.client.Minecraft; import net.minecraft.entity.EntityLivingBase; +import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.IInventory; import net.minecraft.inventory.InventoryLargeChest; import net.minecraft.item.ItemStack; @@ -60,6 +62,8 @@ import net.minecraft.nbt.NBTTagList; import net.minecraft.nbt.NBTTagLong; import net.minecraft.nbt.NBTTagShort; import net.minecraft.nbt.NBTTagString; +import net.minecraft.network.INetHandler; +import net.minecraft.network.NetHandlerPlayServer; import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntityChest; import net.minecraft.util.MathHelper; @@ -334,7 +338,7 @@ public class Utils { public static void preDestroyBlock(World world, int i, int j, int k) { TileEntity tile = world.getTileEntity(i, j, k); - if (tile instanceof IInventory && !CoreProxy.proxy.isRenderWorld(world)) { + if (tile instanceof IInventory && !world.isRemote) { if (!(tile instanceof IDropControlInventory) || ((IDropControlInventory) tile).doDrop()) { InvUtils.dropItems(world, (IInventory) tile, i, j, k); InvUtils.wipeInventory((IInventory) tile); @@ -508,4 +512,16 @@ public class Utils { return new FMLProxyPacket(buf, DefaultProps.NET_CHANNEL_NAME + "-CORE"); } + + /** + * This function returns either the player from the handler if it's on the + * server, or directly from the minecraft instance if it's the client. + */ + public static EntityPlayer getPlayerFromNetHandler (INetHandler handler) { + if (handler instanceof NetHandlerPlayServer) { + return ((NetHandlerPlayServer) handler).playerEntity; + } else { + return Minecraft.getMinecraft().thePlayer; + } + } } diff --git a/common/buildcraft/energy/TileEngine.java b/common/buildcraft/energy/TileEngine.java index c2263bc5..9b8b2816 100644 --- a/common/buildcraft/energy/TileEngine.java +++ b/common/buildcraft/energy/TileEngine.java @@ -73,7 +73,7 @@ public abstract class TileEngine extends TileBuildCraft implements IPowerRecepto @Override public void initialize() { - if (!CoreProxy.proxy.isRenderWorld(worldObj)) { + if (!worldObj.isRemote) { powerHandler.configure(minEnergyReceived(), maxEnergyReceived(), 1, getMaxEnergy()); checkRedstonePower(); } @@ -104,7 +104,7 @@ public abstract class TileEngine extends TileBuildCraft implements IPowerRecepto } public final EnergyStage getEnergyStage() { - if (CoreProxy.proxy.isSimulating(worldObj)) { + if (!worldObj.isRemote) { if (energyStage == EnergyStage.OVERHEAT) return energyStage; EnergyStage newStage = computeEnergyStage(); @@ -135,7 +135,7 @@ public abstract class TileEngine extends TileBuildCraft implements IPowerRecepto } public float getPistonSpeed() { - if (CoreProxy.proxy.isSimulating(worldObj)) { + if (!worldObj.isRemote) { return Math.max(0.16f * getHeatLevel(), 0.01f); } @@ -157,7 +157,7 @@ public abstract class TileEngine extends TileBuildCraft implements IPowerRecepto public void updateEntity() { super.updateEntity(); - if (CoreProxy.proxy.isRenderWorld(worldObj)) { + if (worldObj.isRemote) { if (progressPart != 0) { progress += getPistonSpeed(); @@ -381,8 +381,9 @@ public abstract class TileEngine extends TileBuildCraft implements IPowerRecepto @Override public void doWork(PowerHandler workProvider) { - if (CoreProxy.proxy.isRenderWorld(worldObj)) + if (worldObj.isRemote) { return; + } addEnergy(powerHandler.useEnergy(1, maxEnergyReceived(), true) * 0.95F); } diff --git a/common/buildcraft/energy/TileEngineIron.java b/common/buildcraft/energy/TileEngineIron.java index e204418d..a29846d0 100644 --- a/common/buildcraft/energy/TileEngineIron.java +++ b/common/buildcraft/energy/TileEngineIron.java @@ -72,7 +72,7 @@ public class TileEngineIron extends TileEngineWithInventory implements IFluidHan } ItemStack current = player.getCurrentEquippedItem(); if (current != null) { - if (CoreProxy.proxy.isSimulating(worldObj)) { + if (!worldObj.isRemote) { if (FluidUtils.handleRightClick(this, side, player, true, true)) { return true; } @@ -83,7 +83,7 @@ public class TileEngineIron extends TileEngineWithInventory implements IFluidHan } } } - if (!CoreProxy.proxy.isRenderWorld(worldObj)) { + if (!worldObj.isRemote) { player.openGui(BuildCraftEnergy.instance, GuiIds.ENGINE_IRON, worldObj, xCoord, yCoord, zCoord); } return true; @@ -96,7 +96,7 @@ public class TileEngineIron extends TileEngineWithInventory implements IFluidHan @Override public float getPistonSpeed() { - if (CoreProxy.proxy.isSimulating(worldObj)) { + if (!worldObj.isRemote) { return Math.max(0.07f * getHeatLevel(), 0.01f); } switch (getEnergyStage()) { diff --git a/common/buildcraft/energy/TileEngineStone.java b/common/buildcraft/energy/TileEngineStone.java index 58303889..9e654075 100644 --- a/common/buildcraft/energy/TileEngineStone.java +++ b/common/buildcraft/energy/TileEngineStone.java @@ -43,7 +43,7 @@ public class TileEngineStone extends TileEngineWithInventory { @Override public boolean onBlockActivated(EntityPlayer player, ForgeDirection side) { - if (!CoreProxy.proxy.isRenderWorld(worldObj)) { + if (!worldObj.isRemote) { player.openGui(BuildCraftEnergy.instance, GuiIds.ENGINE_STONE, worldObj, xCoord, yCoord, zCoord); } return true; diff --git a/common/buildcraft/energy/TileEngineWood.java b/common/buildcraft/energy/TileEngineWood.java index 6891ae8d..103b628a 100644 --- a/common/buildcraft/energy/TileEngineWood.java +++ b/common/buildcraft/energy/TileEngineWood.java @@ -52,7 +52,7 @@ public class TileEngineWood extends TileEngine { @Override public float getPistonSpeed() { - if (CoreProxy.proxy.isSimulating(worldObj)) + if (!worldObj.isRemote) return Math.max(0.08f * getHeatLevel(), 0.01f); switch (getEnergyStage()) { case GREEN: diff --git a/common/buildcraft/factory/BlockAutoWorkbench.java b/common/buildcraft/factory/BlockAutoWorkbench.java index 19ff1746..7a82f03c 100644 --- a/common/buildcraft/factory/BlockAutoWorkbench.java +++ b/common/buildcraft/factory/BlockAutoWorkbench.java @@ -56,7 +56,7 @@ public class BlockAutoWorkbench extends BlockBuildCraft { return false; } - if (!CoreProxy.proxy.isRenderWorld(world)) { + if (!world.isRemote) { entityplayer.openGui(BuildCraftFactory.instance, GuiIds.AUTO_CRAFTING_TABLE, world, i, j, k); } diff --git a/common/buildcraft/factory/BlockHopper.java b/common/buildcraft/factory/BlockHopper.java index a7b6cfda..90514c9c 100644 --- a/common/buildcraft/factory/BlockHopper.java +++ b/common/buildcraft/factory/BlockHopper.java @@ -60,7 +60,7 @@ public class BlockHopper extends BlockBuildCraft { } } - if (!CoreProxy.proxy.isRenderWorld(world)) { + if (!world.isRemote) { entityplayer.openGui(BuildCraftFactory.instance, GuiIds.HOPPER, world, x, y, z); } diff --git a/common/buildcraft/factory/BlockQuarry.java b/common/buildcraft/factory/BlockQuarry.java index 6867dcda..b13bc0ed 100644 --- a/common/buildcraft/factory/BlockQuarry.java +++ b/common/buildcraft/factory/BlockQuarry.java @@ -135,9 +135,9 @@ public class BlockQuarry extends BlockBuildCraft { @Override public void breakBlock(World world, int i, int j, int k, Block block, int par6) { - - if (!CoreProxy.proxy.isSimulating(world)) + if (world.isRemote) { return; + } TileEntity tile = world.getTileEntity(i, j, k); if (tile instanceof TileQuarry) { diff --git a/common/buildcraft/factory/TileAutoWorkbench.java b/common/buildcraft/factory/TileAutoWorkbench.java index 61f08438..7eb89a63 100644 --- a/common/buildcraft/factory/TileAutoWorkbench.java +++ b/common/buildcraft/factory/TileAutoWorkbench.java @@ -187,7 +187,7 @@ public class TileAutoWorkbench extends TileBuildCraft implements ISidedInventory @Override public void updateEntity() { super.updateEntity(); - if (CoreProxy.proxy.isRenderWorld(worldObj)) { + if (worldObj.isRemote) { return; } diff --git a/common/buildcraft/factory/TileFloodGate.java b/common/buildcraft/factory/TileFloodGate.java index fc29e601..1841048a 100644 --- a/common/buildcraft/factory/TileFloodGate.java +++ b/common/buildcraft/factory/TileFloodGate.java @@ -62,7 +62,7 @@ public class TileFloodGate extends TileBuildCraft implements IFluidHandler { public void updateEntity() { super.updateEntity(); - if (CoreProxy.proxy.isRenderWorld(worldObj)) + if (worldObj.isRemote) return; if (powered) diff --git a/common/buildcraft/factory/TileHopper.java b/common/buildcraft/factory/TileHopper.java index 2b3cd0f5..9fd30905 100644 --- a/common/buildcraft/factory/TileHopper.java +++ b/common/buildcraft/factory/TileHopper.java @@ -34,7 +34,7 @@ public class TileHopper extends TileBuildCraft implements IInventory { @Override public void updateEntity() { super.updateEntity(); - if (CoreProxy.proxy.isRenderWorld(worldObj) || worldObj.getTotalWorldTime() % 2 != 0) + if (worldObj.isRemote || worldObj.getTotalWorldTime() % 2 != 0) return; TileEntity tile = this.getWorldObj().getTileEntity(xCoord, yCoord - 1, zCoord); diff --git a/common/buildcraft/factory/TileQuarry.java b/common/buildcraft/factory/TileQuarry.java index 3fec53a2..3375d61d 100644 --- a/common/buildcraft/factory/TileQuarry.java +++ b/common/buildcraft/factory/TileQuarry.java @@ -139,11 +139,11 @@ public class TileQuarry extends TileBuildCraft implements IMachine, IPowerRecept @Override public void updateEntity() { - if (!isAlive && CoreProxy.proxy.isSimulating(worldObj)) { + if (!isAlive && !worldObj.isRemote) { super.updateEntity(); return; } - if (!CoreProxy.proxy.isSimulating(worldObj) && isAlive) { + if (!!worldObj.isRemote && isAlive) { super.updateEntity(); return; } @@ -158,7 +158,7 @@ public class TileQuarry extends TileBuildCraft implements IMachine, IPowerRecept } } - if (CoreProxy.proxy.isSimulating(worldObj) && inProcess) { + if (!worldObj.isRemote && inProcess) { sendNetworkUpdate(BuildCraftFactory.instance); } if (inProcess || !isDigging) @@ -530,7 +530,7 @@ public class TileQuarry extends TileBuildCraft implements IMachine, IPowerRecept } if (chunkTicket == null) { isAlive = false; - if (placedBy != null && CoreProxy.proxy.isSimulating(worldObj)) { + if (placedBy != null && !worldObj.isRemote) { ((EntityPlayerMP) placedBy) .addChatMessage(new ChatComponentText( String.format( @@ -673,7 +673,7 @@ public class TileQuarry extends TileBuildCraft implements IMachine, IPowerRecept public void initialize() { super.initialize(); - if (CoreProxy.proxy.isSimulating(this.getWorldObj()) && !box.initialized) { + if (!this.getWorldObj().isRemote && !box.initialized) { setBoundaries(false); } diff --git a/common/buildcraft/factory/TileRefinery.java b/common/buildcraft/factory/TileRefinery.java index deced7de..396edefe 100644 --- a/common/buildcraft/factory/TileRefinery.java +++ b/common/buildcraft/factory/TileRefinery.java @@ -124,7 +124,7 @@ public class TileRefinery extends TileBuildCraft implements IFluidHandler, IPowe @Override public void updateEntity() { - if (CoreProxy.proxy.isRenderWorld(worldObj)) { + if (worldObj.isRemote) { simpleAnimationIterate(); return; } diff --git a/common/buildcraft/factory/TileTank.java b/common/buildcraft/factory/TileTank.java index 4a004f2f..096ba5bd 100644 --- a/common/buildcraft/factory/TileTank.java +++ b/common/buildcraft/factory/TileTank.java @@ -45,7 +45,7 @@ public class TileTank extends TileBuildCraft implements IFluidHandler { /* UPDATING */ @Override public void updateEntity() { - if (CoreProxy.proxy.isRenderWorld(worldObj)) { + if (worldObj.isRemote) { int lightValue = getFluidLightLevel(); if (prevLightValue != lightValue) { prevLightValue = lightValue; diff --git a/common/buildcraft/factory/gui/ContainerAutoWorkbench.java b/common/buildcraft/factory/gui/ContainerAutoWorkbench.java index 6cbd3dc6..10c52491 100644 --- a/common/buildcraft/factory/gui/ContainerAutoWorkbench.java +++ b/common/buildcraft/factory/gui/ContainerAutoWorkbench.java @@ -39,7 +39,7 @@ public class ContainerAutoWorkbench extends BuildCraftContainer { @Override public void setInventorySlotContents(int slot, ItemStack stack) { super.setInventorySlotContents(slot, stack); - if (stack != null && tile.isLast() && CoreProxy.proxy.isRenderWorld(tile.getWorldObj())) { + if (stack != null && tile.isLast() && tile.getWorldObj().isRemote) { InvUtils.addItemToolTip(stack, EnumChatFormatting.YELLOW + StringUtils.localize("gui.clickcraft")); } } diff --git a/common/buildcraft/factory/gui/ContainerRefinery.java b/common/buildcraft/factory/gui/ContainerRefinery.java index b03634a5..efe6faa7 100644 --- a/common/buildcraft/factory/gui/ContainerRefinery.java +++ b/common/buildcraft/factory/gui/ContainerRefinery.java @@ -55,7 +55,7 @@ public class ContainerRefinery extends BuildCraftContainer { refinery.setFilter(slot, filter); - if (CoreProxy.proxy.isRenderWorld(refinery.getWorldObj())) { + if (refinery.getWorldObj().isRemote) { PacketPayloadStream payload = new PacketPayloadStream(new PacketPayloadStream.StreamWriter() { @Override public void writeData(ByteBuf data) { diff --git a/common/buildcraft/factory/network/PacketHandlerFactory.java b/common/buildcraft/factory/network/PacketHandlerFactory.java index eba22fc0..10e300f4 100644 --- a/common/buildcraft/factory/network/PacketHandlerFactory.java +++ b/common/buildcraft/factory/network/PacketHandlerFactory.java @@ -7,6 +7,7 @@ import buildcraft.core.network.PacketPayload; import buildcraft.core.network.PacketPayloadStream; import buildcraft.core.network.PacketUpdate; import buildcraft.core.proxy.CoreProxy; +import buildcraft.core.utils.Utils; import buildcraft.factory.TileRefinery; import io.netty.buffer.ByteBuf; import io.netty.channel.ChannelHandlerContext; @@ -30,9 +31,7 @@ public class PacketHandlerFactory extends BuildCraftChannelHandler { try { INetHandler netHandler = ctx.channel().attr(NetworkRegistry.NET_HANDLER).get(); - - EntityPlayer player = - CoreProxy.proxy.getPlayerFromNetHandler(netHandler); + EntityPlayer player = Utils.getPlayerFromNetHandler(netHandler); int packetID = packet.getID(); diff --git a/common/buildcraft/silicon/BlockLaserTable.java b/common/buildcraft/silicon/BlockLaserTable.java index 447f868b..7ef5bdb5 100644 --- a/common/buildcraft/silicon/BlockLaserTable.java +++ b/common/buildcraft/silicon/BlockLaserTable.java @@ -54,7 +54,7 @@ public class BlockLaserTable extends BlockContainer { if (entityplayer.isSneaking()) return false; - if (!CoreProxy.proxy.isRenderWorld(world)) { + if (!world.isRemote) { int meta = world.getBlockMetadata(i, j, k); entityplayer.openGui(BuildCraftSilicon.instance, meta, world, i, j, k); } diff --git a/common/buildcraft/silicon/TileAdvancedCraftingTable.java b/common/buildcraft/silicon/TileAdvancedCraftingTable.java index c73f1860..03089f29 100644 --- a/common/buildcraft/silicon/TileAdvancedCraftingTable.java +++ b/common/buildcraft/silicon/TileAdvancedCraftingTable.java @@ -242,7 +242,7 @@ public class TileAdvancedCraftingTable extends TileLaserTableBase implements IIn craftSlot = new SlotCrafting(internalPlayer, internalInventoryCrafting, craftResult, 0, 0, 0); updateRecipe(); } - if (!CoreProxy.proxy.isSimulating(worldObj)) + if (!!worldObj.isRemote) return; if (lastMode == ActionMachineControl.Mode.Off) return; @@ -369,7 +369,7 @@ public class TileAdvancedCraftingTable extends TileLaserTableBase implements IIn public void updateCraftingMatrix(int slot, ItemStack stack) { craftingSlots.setInventorySlotContents(slot, stack); updateRecipe(); - if (CoreProxy.proxy.isRenderWorld(worldObj)) { + if (worldObj.isRemote) { PacketSlotChange packet = new PacketSlotChange(PacketIds.ADVANCED_WORKBENCH_SETSLOT, xCoord, yCoord, zCoord, slot, stack); BuildCraftSilicon.instance.sendToServer(packet); } diff --git a/common/buildcraft/silicon/TileLaser.java b/common/buildcraft/silicon/TileLaser.java index 636388a5..48c66049 100644 --- a/common/buildcraft/silicon/TileLaser.java +++ b/common/buildcraft/silicon/TileLaser.java @@ -59,7 +59,7 @@ public class TileLaser extends TileBuildCraft implements IPowerReceptor, IAction public void updateEntity() { super.updateEntity(); - if (!CoreProxy.proxy.isSimulating(worldObj)) + if (!!worldObj.isRemote) return; // If a gate disabled us, remove laser and do nothing. diff --git a/common/buildcraft/silicon/gui/GuiAssemblyTable.java b/common/buildcraft/silicon/gui/GuiAssemblyTable.java index 578f1d44..58f08d05 100644 --- a/common/buildcraft/silicon/gui/GuiAssemblyTable.java +++ b/common/buildcraft/silicon/gui/GuiAssemblyTable.java @@ -115,7 +115,7 @@ public class GuiAssemblyTable extends GuiAdvancedInterface { updateRecipes(); // Request current selection from server - if (CoreProxy.proxy.isRenderWorld(assemblyTable.getWorldObj())) { + if (assemblyTable.getWorldObj().isRemote) { BuildCraftSilicon.instance.sendToServer(new PacketCoordinates(PacketIds.SELECTION_ASSEMBLY_GET, assemblyTable.xCoord, assemblyTable.yCoord, assemblyTable.zCoord)); } @@ -197,14 +197,11 @@ public class GuiAssemblyTable extends GuiAdvancedInterface { message.stack = slot.recipe.output; - if (CoreProxy.proxy.isRenderWorld(table.getWorldObj())) { - + if (table.getWorldObj().isRemote) { PacketNBT packet = new PacketNBT(PacketIds.SELECTION_ASSEMBLY, message.getNBT(), table.xCoord, table.yCoord, table.zCoord); - BuildCraftSilicon.instance.sendToServer(packet); } } - } @Override diff --git a/common/buildcraft/silicon/network/PacketHandlerSilicon.java b/common/buildcraft/silicon/network/PacketHandlerSilicon.java index f1b14249..d5bb2baa 100644 --- a/common/buildcraft/silicon/network/PacketHandlerSilicon.java +++ b/common/buildcraft/silicon/network/PacketHandlerSilicon.java @@ -7,6 +7,7 @@ import buildcraft.core.network.PacketIds; import buildcraft.core.network.PacketNBT; import buildcraft.core.network.PacketSlotChange; import buildcraft.core.proxy.CoreProxy; +import buildcraft.core.utils.Utils; import buildcraft.silicon.TileAdvancedCraftingTable; import buildcraft.silicon.TileAssemblyTable; import buildcraft.silicon.TileAssemblyTable.SelectionMessage; @@ -33,8 +34,7 @@ public class PacketHandlerSilicon extends BuildCraftChannelHandler { try { INetHandler netHandler = ctx.channel().attr(NetworkRegistry.NET_HANDLER).get(); - EntityPlayer player = - CoreProxy.proxy.getPlayerFromNetHandler(netHandler); + EntityPlayer player = Utils.getPlayerFromNetHandler(netHandler); int packetID = packet.getID(); diff --git a/common/buildcraft/transport/BlockFilteredBuffer.java b/common/buildcraft/transport/BlockFilteredBuffer.java index c8424961..638e2547 100644 --- a/common/buildcraft/transport/BlockFilteredBuffer.java +++ b/common/buildcraft/transport/BlockFilteredBuffer.java @@ -57,7 +57,7 @@ public class BlockFilteredBuffer extends BlockBuildCraft { } } - if (!CoreProxy.proxy.isRenderWorld(world)) { + if (!world.isRemote) { entityplayer.openGui(BuildCraftTransport.instance, GuiIds.FILTERED_BUFFER, world, x, y, z); } diff --git a/common/buildcraft/transport/BlockGenericPipe.java b/common/buildcraft/transport/BlockGenericPipe.java index e683aef8..fcce9722 100644 --- a/common/buildcraft/transport/BlockGenericPipe.java +++ b/common/buildcraft/transport/BlockGenericPipe.java @@ -514,7 +514,7 @@ public class BlockGenericPipe extends BlockBuildCraft { @Override public ArrayList getDrops(World world, int x, int y, int z, int metadata, int fortune) { - if (CoreProxy.proxy.isRenderWorld(world)) + if (world.isRemote) return null; ArrayList list = new ArrayList(); @@ -545,7 +545,7 @@ public class BlockGenericPipe extends BlockBuildCraft { @Override public void dropBlockAsItemWithChance(World world, int i, int j, int k, int l, float f, int dmg) { - if (CoreProxy.proxy.isRenderWorld(world)) + if (world.isRemote) return; int i1 = quantityDropped(world.rand); @@ -743,7 +743,7 @@ public class BlockGenericPipe extends BlockBuildCraft { private boolean stripGate(Pipe pipe) { if (pipe.hasGate()) { - if (!CoreProxy.proxy.isRenderWorld(pipe.container.getWorldObj())) { + if (!pipe.container.getWorldObj().isRemote) { pipe.gate.dropGate(); } pipe.resetGate(); @@ -774,7 +774,7 @@ public class BlockGenericPipe extends BlockBuildCraft { private boolean stripWire(Pipe pipe, PipeWire color) { if (pipe.wireSet[color.ordinal()]) { - if (!CoreProxy.proxy.isRenderWorld(pipe.container.getWorldObj())) { + if (!pipe.container.getWorldObj().isRemote) { dropWire(color, pipe); } pipe.wireSet[color.ordinal()] = false; diff --git a/common/buildcraft/transport/Gate.java b/common/buildcraft/transport/Gate.java index f6eaf3fc..808e6e10 100644 --- a/common/buildcraft/transport/Gate.java +++ b/common/buildcraft/transport/Gate.java @@ -147,7 +147,7 @@ public final class Gate { // GUI public void openGui(EntityPlayer player) { - if (!CoreProxy.proxy.isRenderWorld(player.worldObj)) { + if (!player.worldObj.isRemote) { player.openGui(BuildCraftTransport.instance, GuiIds.GATES, pipe.container.getWorldObj(), pipe.container.xCoord, pipe.container.yCoord, pipe.container.zCoord); } } diff --git a/common/buildcraft/transport/PipeTransportFluids.java b/common/buildcraft/transport/PipeTransportFluids.java index c2154cfd..7b69a912 100644 --- a/common/buildcraft/transport/PipeTransportFluids.java +++ b/common/buildcraft/transport/PipeTransportFluids.java @@ -188,8 +188,9 @@ public class PipeTransportFluids extends PipeTransport implements IFluidHandler @Override public void updateEntity() { - if (CoreProxy.proxy.isRenderWorld(container.getWorldObj())) + if (container.getWorldObj().isRemote) { return; + } moveFluids(); diff --git a/common/buildcraft/transport/PipeTransportPower.java b/common/buildcraft/transport/PipeTransportPower.java index e91cf4d7..b12a5532 100644 --- a/common/buildcraft/transport/PipeTransportPower.java +++ b/common/buildcraft/transport/PipeTransportPower.java @@ -134,8 +134,9 @@ public class PipeTransportPower extends PipeTransport { @Override public void updateEntity() { - if (CoreProxy.proxy.isRenderWorld(container.getWorldObj())) + if (container.getWorldObj().isRemote) { return; + } step(); diff --git a/common/buildcraft/transport/TileGenericPipe.java b/common/buildcraft/transport/TileGenericPipe.java index ab1618d5..e8614ba4 100644 --- a/common/buildcraft/transport/TileGenericPipe.java +++ b/common/buildcraft/transport/TileGenericPipe.java @@ -198,7 +198,7 @@ public class TileGenericPipe extends TileEntity implements IPowerReceptor, IFlui public boolean initialized = false; @Override - public void updateEntity() { + public void updateEntity() { if (!worldObj.isRemote) { if (deletePipe) { worldObj.setBlockToAir(xCoord, yCoord, zCoord); diff --git a/common/buildcraft/transport/TravelingItem.java b/common/buildcraft/transport/TravelingItem.java index c8967104..b5e30428 100644 --- a/common/buildcraft/transport/TravelingItem.java +++ b/common/buildcraft/transport/TravelingItem.java @@ -192,7 +192,7 @@ public final class TravelingItem { } public EntityItem toEntityItem() { - if (container != null && !CoreProxy.proxy.isRenderWorld(container.getWorldObj())) { + if (container != null && !container.getWorldObj().isRemote) { if (getItemStack().stackSize <= 0) return null; diff --git a/common/buildcraft/transport/gui/ContainerGateInterface.java b/common/buildcraft/transport/gui/ContainerGateInterface.java index c6ad1c02..10276041 100644 --- a/common/buildcraft/transport/gui/ContainerGateInterface.java +++ b/common/buildcraft/transport/gui/ContainerGateInterface.java @@ -36,6 +36,7 @@ import java.util.NavigableSet; import java.util.TreeSet; import net.minecraft.block.Block; +import net.minecraft.client.Minecraft; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.ICrafting; import net.minecraft.inventory.IInventory; @@ -51,18 +52,21 @@ public class ContainerGateInterface extends BuildCraftContainer { IInventory playerIInventory; Pipe pipe; + private final NavigableSet _potentialTriggers = new TreeSet(new Comparator() { @Override public int compare(ITrigger o1, ITrigger o2) { return o1.getUniqueTag().compareTo(o2.getUniqueTag()); } }); + private final NavigableSet _potentialActions = new TreeSet(new Comparator() { @Override public int compare(IAction o1, IAction o2) { return o1.getUniqueTag().compareTo(o2.getUniqueTag()); } }); + private boolean isSynchronized = false; private boolean isNetInitialized = false; public boolean[] triggerState = new boolean[8]; @@ -70,6 +74,7 @@ public class ContainerGateInterface extends BuildCraftContainer { public ContainerGateInterface(IInventory playerInventory, Pipe pipe) { super(0); + this.playerIInventory = playerInventory; for (int y = 0; y < 3; y++) { @@ -86,7 +91,7 @@ public class ContainerGateInterface extends BuildCraftContainer { // Do not attempt to create a list of potential actions and triggers on // the client. - if (!CoreProxy.proxy.isRenderWorld(pipe.container.getWorldObj())) { + if (!pipe.container.getWorldObj().isRemote) { _potentialActions.addAll(pipe.getActions()); _potentialTriggers.addAll(ActionManager.getPipeTriggers(pipe.container)); @@ -103,10 +108,13 @@ public class ContainerGateInterface extends BuildCraftContainer { if (!pipe.gate.material.hasParameterSlot) { Iterator it = _potentialTriggers.iterator(); + while (it.hasNext()) { ITrigger trigger = it.next(); - if (trigger.requiresParameter()) + + if (trigger.requiresParameter()) { it.remove(); + } } } } @@ -114,9 +122,11 @@ public class ContainerGateInterface extends BuildCraftContainer { @Override public boolean canInteractWith(EntityPlayer player) { - if (pipe == null || pipe.gate == null) + if (pipe == null || pipe.gate == null) { return false; - return true; + } else { + return true; + } } /** @@ -138,6 +148,7 @@ public class ContainerGateInterface extends BuildCraftContainer { public void updateActions(PacketUpdate packet) { _potentialActions.clear(); PacketPayloadArrays payload = (PacketPayloadArrays) packet.payload; + int length = payload.intPayload[0]; for (int i = 0; i < length; i++) { @@ -215,7 +226,12 @@ public class ContainerGateInterface extends BuildCraftContainer { } public void sendSelectionChange(int position) { - BuildCraftTransport.instance.sendToServer(new PacketUpdate(PacketIds.GATE_SELECTION_CHANGE, pipe.container.xCoord, pipe.container.yCoord, pipe.container.zCoord, getSelectionPayload(position))); + if (pipe.container.getWorld().isRemote) { + BuildCraftTransport.instance.sendToServer(new PacketUpdate( + PacketIds.GATE_SELECTION_CHANGE, pipe.container.xCoord, + pipe.container.yCoord, pipe.container.zCoord, + getSelectionPayload(position))); + } } /** @@ -223,13 +239,12 @@ public class ContainerGateInterface extends BuildCraftContainer { * (re-)requests the current selection on the gate if needed. */ public void synchronize() { - - if (!isNetInitialized && CoreProxy.proxy.isRenderWorld(pipe.container.getWorldObj())) { + if (!isNetInitialized && pipe.container.getWorldObj().isRemote) { isNetInitialized = true; BuildCraftTransport.instance.sendToServer(new PacketCoordinates(PacketIds.GATE_REQUEST_INIT, pipe.container.xCoord, pipe.container.yCoord, pipe.container.zCoord)); } - if (!isSynchronized && CoreProxy.proxy.isRenderWorld(pipe.container.getWorldObj())) { + if (!isSynchronized && pipe.container.getWorldObj().isRemote) { isSynchronized = true; BuildCraftTransport.instance.sendToServer(new PacketCoordinates(PacketIds.GATE_REQUEST_SELECTION, pipe.container.xCoord, pipe.container.yCoord, pipe.container.zCoord)); } @@ -249,28 +264,36 @@ public class ContainerGateInterface extends BuildCraftContainer { * SERVER SIDE * */ private int calculateTriggerState() { - if (pipe.gate == null) + if (pipe.gate == null) { return 0; + } + int state = 0; + for (int i = 0; i < triggerState.length; i++) { if (pipe.gate.triggers[i] != null) { triggerState[i] = isNearbyTriggerActive(pipe.gate.triggers[i], pipe.gate.getTriggerParameter(i)); } + state |= triggerState[i] ? 0x01 << i : 0x0; } + return state; } @Override public void detectAndSendChanges() { super.detectAndSendChanges(); + int state = calculateTriggerState(); + if (state != lastTriggerState) { for (int i = 0; i < this.crafters.size(); i++) { ICrafting viewingPlayer = (ICrafting) this.crafters.get(i); viewingPlayer.sendProgressBarUpdate(this, 0 /* State update */, state); } + lastTriggerState = state; } } @@ -287,13 +310,15 @@ public class ContainerGateInterface extends BuildCraftContainer { * @param player */ private void sendActions(EntityPlayer player) { - // Compose update packet int length = _potentialActions.size(); + PacketPayloadArrays payload = new PacketPayloadArrays(1, 0, length); payload.intPayload[0] = length; + int i = 0; + for (IAction action : _potentialActions) { payload.stringPayload[i++] = action.getUniqueTag(); } @@ -310,7 +335,6 @@ public class ContainerGateInterface extends BuildCraftContainer { * @param player */ private void sendTriggers(EntityPlayer player) { - // Compose update packet int length = _potentialTriggers.size(); PacketPayloadArrays payload = new PacketPayloadArrays(1, 0, length); @@ -333,13 +357,13 @@ public class ContainerGateInterface extends BuildCraftContainer { * @param player */ public void sendSelection(EntityPlayer player) { - if (pipe == null || pipe.gate == null) + if (pipe == null || pipe.gate == null) { return; + } + for (int position = 0; position < pipe.gate.material.numSlots; position++) { BuildCraftTransport.instance.sendToPlayer(player, new PacketUpdate(PacketIds.GATE_SELECTION, pipe.container.xCoord, pipe.container.yCoord, pipe.container.zCoord, getSelectionPayload(position))); } - - // System.out.println("Sending current selection to player"); } /** @@ -350,15 +374,19 @@ public class ContainerGateInterface extends BuildCraftContainer { } public ITrigger getFirstTrigger() { - if (_potentialTriggers.isEmpty()) + if (_potentialTriggers.isEmpty()) { return null; - return _potentialTriggers.first(); + } else { + return _potentialTriggers.first(); + } } public ITrigger getLastTrigger() { - if (_potentialTriggers.isEmpty()) + if (_potentialTriggers.isEmpty()) { return null; - return _potentialTriggers.last(); + } else { + return _potentialTriggers.last(); + } } public Iterator getTriggerIterator(boolean descending) { @@ -366,25 +394,33 @@ public class ContainerGateInterface extends BuildCraftContainer { } public boolean isNearbyTriggerActive(ITrigger trigger, ITriggerParameter parameter) { - if (pipe.gate == null) + if (pipe.gate == null) { return false; - return pipe.gate.isNearbyTriggerActive(trigger, parameter); + } else { + return pipe.gate.isNearbyTriggerActive(trigger, parameter); + } } public void setTrigger(int position, ITrigger trigger, boolean notify) { - if (pipe.gate == null) + if (pipe.gate == null) { return; + } + pipe.gate.setTrigger(position, trigger); - if (CoreProxy.proxy.isRenderWorld(pipe.container.getWorldObj()) && notify) { + + if (pipe.container.getWorldObj().isRemote && notify) { sendSelectionChange(position); } } public void setTriggerParameter(int position, ITriggerParameter parameter, boolean notify) { - if (pipe.gate == null) + if (pipe.gate == null) { return; + } + pipe.gate.setTriggerParameter(position, parameter); - if (CoreProxy.proxy.isRenderWorld(pipe.container.getWorldObj()) && notify) { + + if (pipe.container.getWorldObj().isRemote && notify) { sendSelectionChange(position); } } @@ -397,15 +433,19 @@ public class ContainerGateInterface extends BuildCraftContainer { } public IAction getFirstAction() { - if (_potentialActions.isEmpty()) + if (_potentialActions.isEmpty()) { return null; - return _potentialActions.first(); + } else { + return _potentialActions.first(); + } } public IAction getLastAction() { - if (_potentialActions.isEmpty()) + if (_potentialActions.isEmpty()) { return null; - return _potentialActions.last(); + } else { + return _potentialActions.last(); + } } public Iterator getActionIterator(boolean descending) { @@ -414,7 +454,8 @@ public class ContainerGateInterface extends BuildCraftContainer { public void setAction(int position, IAction action, boolean notify) { pipe.gate.setAction(position, action); - if (CoreProxy.proxy.isRenderWorld(pipe.container.getWorldObj()) && notify) { + + if (pipe.container.getWorldObj().isRemote && notify) { sendSelectionChange(position); } } diff --git a/common/buildcraft/transport/gui/GuiEmeraldPipe.java b/common/buildcraft/transport/gui/GuiEmeraldPipe.java index fb788657..baf26460 100644 --- a/common/buildcraft/transport/gui/GuiEmeraldPipe.java +++ b/common/buildcraft/transport/gui/GuiEmeraldPipe.java @@ -51,7 +51,7 @@ public class GuiEmeraldPipe extends GuiBuildCraft { @Override public void onGuiClosed() { - if (CoreProxy.proxy.isRenderWorld(pipe.getWorld())) { + if (pipe.getWorld().isRemote) { pipe.getStateController().setCurrentState(button.getController().getCurrentState()); PacketGuiReturn pkt = new PacketGuiReturn(pipe.getContainer()); pkt.sendPacket(); diff --git a/common/buildcraft/transport/gui/GuiGateInterface.java b/common/buildcraft/transport/gui/GuiGateInterface.java index fb8595b5..3f82d56e 100644 --- a/common/buildcraft/transport/gui/GuiGateInterface.java +++ b/common/buildcraft/transport/gui/GuiGateInterface.java @@ -46,20 +46,24 @@ public class GuiGateInterface extends GuiAdvancedInterface { @Override public String getDescription() { ITrigger trigger = pipe.gate.getTrigger(slot); - if (trigger != null) + + if (trigger != null) { return trigger.getDescription(); - else + } else { return ""; + } } @SideOnly(Side.CLIENT) @Override public IIcon getIcon() { ITrigger trigger = pipe.gate.getTrigger(slot); - if (trigger != null) + + if (trigger != null) { return trigger.getIcon(); - else + } else { return null; + } } @Override @@ -87,30 +91,37 @@ public class GuiGateInterface extends GuiAdvancedInterface { @Override public String getDescription() { IAction action = pipe.gate.getAction(slot); - if (action != null) + if (action != null) { return action.getDescription(); - else + } else { return ""; + } } @SideOnly(Side.CLIENT) @Override public IIcon getIcon() { IAction action = pipe.gate.getAction(slot); - if (action != null) + + if (action != null) { return action.getIcon(); - else + } else { return null; + } } @Override public ResourceLocation getTexture() { IAction action = pipe.gate.getAction(slot); + if (action instanceof BCAction) { BCAction bcAction = (BCAction) action; - if (bcAction.getTextureMap() == 0) + + if (bcAction.getTextureMap() == 0) { return TextureMap.locationBlocksTexture; + } } + return super.getTexture(); } @@ -144,10 +155,12 @@ public class GuiGateInterface extends GuiAdvancedInterface { @Override public ItemStack getItemStack() { ITriggerParameter parameter = pipe.gate.getTriggerParameter(slot); - if (parameter != null) + + if (parameter != null) { return parameter.getItemStack(); - else + } else { return null; + } } public ITriggerParameter getTriggerParameter() { @@ -290,8 +303,9 @@ public class GuiGateInterface extends GuiAdvancedInterface { AdvancedSlot slot = null; - if (position < 0) + if (position < 0) { return; + } slot = slots[position]; diff --git a/common/buildcraft/transport/network/PacketHandlerTransport.java b/common/buildcraft/transport/network/PacketHandlerTransport.java index dd3f1873..b4db6609 100644 --- a/common/buildcraft/transport/network/PacketHandlerTransport.java +++ b/common/buildcraft/transport/network/PacketHandlerTransport.java @@ -7,12 +7,14 @@ import buildcraft.core.network.PacketIds; import buildcraft.core.network.PacketSlotChange; import buildcraft.core.network.PacketUpdate; import buildcraft.core.proxy.CoreProxy; +import buildcraft.core.utils.Utils; import buildcraft.transport.PipeTransportItems; import buildcraft.transport.PipeTransportPower; import buildcraft.transport.TileGenericPipe; import buildcraft.transport.gui.ContainerGateInterface; import buildcraft.transport.pipes.PipeItemsDiamond; import buildcraft.transport.pipes.PipeItemsEmerald; +import cpw.mods.fml.common.network.FMLOutboundHandler; import cpw.mods.fml.common.network.NetworkRegistry; import io.netty.buffer.ByteBuf; import io.netty.channel.ChannelHandlerContext; @@ -42,10 +44,8 @@ public class PacketHandlerTransport extends BuildCraftChannelHandler { public void decodeInto(ChannelHandlerContext ctx, ByteBuf data, BuildCraftPacket packet) { super.decodeInto(ctx, data, packet); try { - INetHandler netHandler = ctx.channel().attr(NetworkRegistry.NET_HANDLER).get(); - - EntityPlayer player = - CoreProxy.proxy.getPlayerFromNetHandler(netHandler); + INetHandler netHandler = ctx.channel().attr(NetworkRegistry.NET_HANDLER).get(); + EntityPlayer player = Utils.getPlayerFromNetHandler(netHandler); int packetID = packet.getID(); @@ -82,29 +82,29 @@ public class PacketHandlerTransport extends BuildCraftChannelHandler { * SERVER SIDE * */ case PacketIds.DIAMOND_PIPE_SELECT: { - onDiamondPipeSelect((EntityPlayer) player, (PacketSlotChange) packet); + onDiamondPipeSelect(player, (PacketSlotChange) packet); break; } case PacketIds.EMERALD_PIPE_SELECT: { - onEmeraldPipeSelect((EntityPlayer) player, (PacketSlotChange) packet); + onEmeraldPipeSelect(player, (PacketSlotChange) packet); break; } case PacketIds.GATE_REQUEST_INIT: - onGateInitRequest((EntityPlayer) player, (PacketCoordinates) packet); + onGateInitRequest(player, (PacketCoordinates) packet); break; case PacketIds.GATE_REQUEST_SELECTION: - onGateSelectionRequest((EntityPlayer) player, (PacketCoordinates) packet); + onGateSelectionRequest(player, (PacketCoordinates) packet); break; case PacketIds.GATE_SELECTION_CHANGE: - onGateSelectionChange((EntityPlayer) player, (PacketUpdate) packet); + onGateSelectionChange(player, (PacketUpdate) packet); break; case PacketIds.PIPE_ITEMSTACK_REQUEST: { - ((PacketPipeTransportItemStackRequest) packet).sendDataToPlayer((EntityPlayer) player); + ((PacketPipeTransportItemStackRequest) packet).sendDataToPlayer(player); break; } } @@ -216,8 +216,9 @@ public class PacketHandlerTransport extends BuildCraftChannelHandler { * @param packet */ private void onGateSelectionChange(EntityPlayer playerEntity, PacketUpdate packet) { - if (!(playerEntity.openContainer instanceof ContainerGateInterface)) + if (!(playerEntity.openContainer instanceof ContainerGateInterface)) { return; + } ((ContainerGateInterface) playerEntity.openContainer).setSelection(packet, true); } diff --git a/common/buildcraft/transport/network/PacketPipeTransportItemStackRequest.java b/common/buildcraft/transport/network/PacketPipeTransportItemStackRequest.java index 917159fb..db0fff7e 100644 --- a/common/buildcraft/transport/network/PacketPipeTransportItemStackRequest.java +++ b/common/buildcraft/transport/network/PacketPipeTransportItemStackRequest.java @@ -39,7 +39,7 @@ public class PacketPipeTransportItemStackRequest extends BuildCraftPacket { public void sendDataToPlayer (EntityPlayer player) { if (item != null) { - BuildCraftTransport.instance.replyToPlayer( + BuildCraftTransport.instance.sendToPlayer( player, new PacketPipeTransportItemStack(travelerID, item .getItemStack())); diff --git a/common/buildcraft/transport/pipes/PipeItemsDiamond.java b/common/buildcraft/transport/pipes/PipeItemsDiamond.java index 830c1f32..c11dcf67 100644 --- a/common/buildcraft/transport/pipes/PipeItemsDiamond.java +++ b/common/buildcraft/transport/pipes/PipeItemsDiamond.java @@ -89,7 +89,7 @@ public class PipeItemsDiamond extends Pipe implements IClien if (Block.getBlockFromItem(entityplayer.getCurrentEquippedItem().getItem()) instanceof BlockGenericPipe) return false; - if (!CoreProxy.proxy.isRenderWorld(container.getWorldObj())) { + if (!container.getWorldObj().isRemote) { entityplayer.openGui(BuildCraftTransport.instance, GuiIds.PIPE_DIAMOND, container.getWorldObj(), container.xCoord, container.yCoord, container.zCoord); } diff --git a/common/buildcraft/transport/pipes/PipeItemsEmerald.java b/common/buildcraft/transport/pipes/PipeItemsEmerald.java index 94c8195d..5e017d61 100644 --- a/common/buildcraft/transport/pipes/PipeItemsEmerald.java +++ b/common/buildcraft/transport/pipes/PipeItemsEmerald.java @@ -96,7 +96,7 @@ public class PipeItemsEmerald extends PipeItemsWood implements IClientState, IGu return true; } - if (!CoreProxy.proxy.isRenderWorld(container.getWorldObj())) { + if (!container.getWorldObj().isRemote) { entityplayer.openGui(BuildCraftTransport.instance, GuiIds.PIPE_EMERALD_ITEM, container.getWorldObj(), container.xCoord, container.yCoord, container.zCoord); } diff --git a/common/buildcraft/transport/pipes/PipeItemsEmzuli.java b/common/buildcraft/transport/pipes/PipeItemsEmzuli.java index bf23c38e..482a1dfe 100644 --- a/common/buildcraft/transport/pipes/PipeItemsEmzuli.java +++ b/common/buildcraft/transport/pipes/PipeItemsEmzuli.java @@ -71,7 +71,7 @@ public class PipeItemsEmzuli extends PipeItemsWood implements IGuiReturnHandler return true; } - if (!CoreProxy.proxy.isRenderWorld(container.getWorldObj())) { + if (!container.getWorldObj().isRemote) { entityplayer.openGui(BuildCraftTransport.instance, GuiIds.PIPE_LOGEMERALD_ITEM, container.getWorldObj(), container.xCoord, container.yCoord, container.zCoord); } diff --git a/common/buildcraft/transport/pipes/PipeItemsObsidian.java b/common/buildcraft/transport/pipes/PipeItemsObsidian.java index b8cea000..0bca644f 100644 --- a/common/buildcraft/transport/pipes/PipeItemsObsidian.java +++ b/common/buildcraft/transport/pipes/PipeItemsObsidian.java @@ -192,8 +192,9 @@ public class PipeItemsObsidian extends Pipe implements IPowe } public void pullItemIntoPipe(Entity entity, int distance) { - if (CoreProxy.proxy.isRenderWorld(container.getWorldObj())) + if (container.getWorldObj().isRemote) { return; + } ForgeDirection orientation = getOpenOrientation().getOpposite(); diff --git a/common/buildcraft/transport/pipes/PipeLogicWood.java b/common/buildcraft/transport/pipes/PipeLogicWood.java index 192f5c54..b23f8e70 100644 --- a/common/buildcraft/transport/pipes/PipeLogicWood.java +++ b/common/buildcraft/transport/pipes/PipeLogicWood.java @@ -70,7 +70,7 @@ public abstract class PipeLogicWood { protected abstract boolean isValidConnectingTile(TileEntity tile); public void initialize() { - if (!CoreProxy.proxy.isRenderWorld(pipe.container.getWorldObj())) { + if (!pipe.container.getWorldObj().isRemote) { switchSourceIfNeeded(); } } @@ -87,7 +87,7 @@ public abstract class PipeLogicWood { } public void onNeighborBlockChange(int blockId) { - if (!CoreProxy.proxy.isRenderWorld(pipe.container.getWorldObj())) { + if (!pipe.container.getWorldObj().isRemote) { switchSourceIfNeeded(); } }