From 918264d1c141c3ddb68cd4772acdbb877d394242 Mon Sep 17 00:00:00 2001 From: Aidan Brady Date: Fri, 12 Apr 2013 21:32:43 -0400 Subject: [PATCH] Attempts to fix server-side crash. --- .../mekanism/client/ClientProxy.java | 55 +++++++++++++++++++ src/minecraft/mekanism/client/IHasSound.java | 3 + .../mekanism/common/CommonProxy.java | 12 ++++ .../mekanism/common/PacketHandler.java | 53 +----------------- .../common/TileEntityBasicMachine.java | 2 + .../mekanism/common/TileEntityFactory.java | 2 + .../common/TileEntityMetallurgicInfuser.java | 2 + .../common/TileEntityGenerator.java | 2 + 8 files changed, 79 insertions(+), 52 deletions(-) diff --git a/src/minecraft/mekanism/client/ClientProxy.java b/src/minecraft/mekanism/client/ClientProxy.java index be477c168..82054fe9a 100644 --- a/src/minecraft/mekanism/client/ClientProxy.java +++ b/src/minecraft/mekanism/client/ClientProxy.java @@ -3,6 +3,8 @@ package mekanism.client; import mekanism.common.CommonProxy; import mekanism.common.EntityObsidianTNT; +import mekanism.common.IElectricChest; +import mekanism.common.InventoryElectricChest; import mekanism.common.ItemPortableTeleporter; import mekanism.common.Mekanism; import mekanism.common.TileEntityAdvancedElectricMachine; @@ -56,6 +58,59 @@ public class ClientProxy extends CommonProxy return RenderingRegistry.addNewArmourRendererPrefix(string); } + @Override + public void openElectricChest(EntityPlayer entityplayer, int id, int windowId, boolean isBlock, int x, int y, int z) + { + TileEntityElectricChest tileEntity = (TileEntityElectricChest)entityplayer.worldObj.getBlockTileEntity(x, y, z); + + if(id == 0) + { + if(isBlock) + { + FMLClientHandler.instance().displayGuiScreen(entityplayer, new GuiElectricChest(entityplayer.inventory, tileEntity)); + entityplayer.openContainer.windowId = windowId; + } + else { + FMLClientHandler.instance().getClient().sndManager.playSoundFX("random.chestopen", 1.0F, 1.0F); + ItemStack stack = entityplayer.getCurrentEquippedItem(); + if(stack != null && stack.getItem() instanceof IElectricChest && ((IElectricChest)stack.getItem()).isElectricChest(stack)) + { + InventoryElectricChest inventory = new InventoryElectricChest(stack); + FMLClientHandler.instance().displayGuiScreen(entityplayer, new GuiElectricChest(entityplayer.inventory, inventory)); + entityplayer.openContainer.windowId = windowId; + } + } + } + else if(id == 1) + { + if(isBlock) + { + FMLClientHandler.instance().displayGuiScreen(entityplayer, new GuiPasswordEnter(tileEntity)); + } + else { + ItemStack stack = entityplayer.getCurrentEquippedItem(); + if(stack != null && stack.getItem() instanceof IElectricChest && ((IElectricChest)stack.getItem()).isElectricChest(stack)) + { + FMLClientHandler.instance().displayGuiScreen(entityplayer, new GuiPasswordEnter(stack)); + } + } + } + else if(id == 2) + { + if(isBlock) + { + FMLClientHandler.instance().displayGuiScreen(entityplayer, new GuiPasswordModify(tileEntity)); + } + else { + ItemStack stack = entityplayer.getCurrentEquippedItem(); + if(stack != null && stack.getItem() instanceof IElectricChest && ((IElectricChest)stack.getItem()).isElectricChest(stack)) + { + FMLClientHandler.instance().displayGuiScreen(entityplayer, new GuiPasswordModify(stack)); + } + } + } + } + @Override public void registerSpecialTileEntities() { diff --git a/src/minecraft/mekanism/client/IHasSound.java b/src/minecraft/mekanism/client/IHasSound.java index 82abc1d9c..a7e0be687 100644 --- a/src/minecraft/mekanism/client/IHasSound.java +++ b/src/minecraft/mekanism/client/IHasSound.java @@ -15,15 +15,18 @@ public interface IHasSound * Gets the sound. * @return sound */ + @SideOnly(Side.CLIENT) public Sound getSound(); /** * Removes the sound; */ + @SideOnly(Side.CLIENT) public void removeSound(); /** * Ticks and updates the block's sound. */ + @SideOnly(Side.CLIENT) public void updateSound(); } diff --git a/src/minecraft/mekanism/common/CommonProxy.java b/src/minecraft/mekanism/common/CommonProxy.java index 4ef8d0c41..caa5cc340 100644 --- a/src/minecraft/mekanism/common/CommonProxy.java +++ b/src/minecraft/mekanism/common/CommonProxy.java @@ -29,6 +29,18 @@ public class CommonProxy GameRegistry.registerTileEntity(TileEntityElectricChest.class, "ElectricChest"); } + /** + * Handles an ELECTRIC_CHEST_CLIENT_OPEN packet via the proxy, not handled on the server-side. + * @param entityplayer - player the packet was sent from + * @param id - the electric chest gui ID to open + * @param windowId - the container-specific window ID + * @param isBlock - if the chest is a block + * @param x - x coordinate + * @param y - y coordinate + * @param z - z coordinate + */ + public void openElectricChest(EntityPlayer entityplayer, int id, int windowId, boolean isBlock, int x, int y, int z) {} + /** * Register and load client-only render information. */ diff --git a/src/minecraft/mekanism/common/PacketHandler.java b/src/minecraft/mekanism/common/PacketHandler.java index 1eacef69b..2fd64da00 100644 --- a/src/minecraft/mekanism/common/PacketHandler.java +++ b/src/minecraft/mekanism/common/PacketHandler.java @@ -9,9 +9,6 @@ import java.util.Random; import universalelectricity.core.electricity.ElectricityPack; import universalelectricity.core.item.IItemElectric; -import mekanism.client.GuiElectricChest; -import mekanism.client.GuiPasswordEnter; -import mekanism.client.GuiPasswordModify; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.item.ItemStack; @@ -23,7 +20,6 @@ import net.minecraft.world.World; import com.google.common.io.ByteArrayDataInput; import com.google.common.io.ByteStreams; -import cpw.mods.fml.client.FMLClientHandler; import cpw.mods.fml.common.FMLCommonHandler; import cpw.mods.fml.common.network.IPacketHandler; import cpw.mods.fml.common.network.PacketDispatcher; @@ -328,54 +324,7 @@ public class PacketHandler implements IPacketHandler z = dataStream.readInt(); } - TileEntityElectricChest tileEntity = (TileEntityElectricChest)entityplayer.worldObj.getBlockTileEntity(x, y, z); - - if(id == 0) - { - if(isBlock) - { - FMLClientHandler.instance().displayGuiScreen(entityplayer, new GuiElectricChest(entityplayer.inventory, tileEntity)); - entityplayer.openContainer.windowId = windowId; - } - else { - FMLClientHandler.instance().getClient().sndManager.playSoundFX("random.chestopen", 1.0F, 1.0F); - ItemStack stack = entityplayer.getCurrentEquippedItem(); - if(stack != null && stack.getItem() instanceof IElectricChest && ((IElectricChest)stack.getItem()).isElectricChest(stack)) - { - InventoryElectricChest inventory = new InventoryElectricChest(stack); - FMLClientHandler.instance().displayGuiScreen(entityplayer, new GuiElectricChest(entityplayer.inventory, inventory)); - entityplayer.openContainer.windowId = windowId; - } - } - } - else if(id == 1) - { - if(isBlock) - { - FMLClientHandler.instance().displayGuiScreen(entityplayer, new GuiPasswordEnter(tileEntity)); - } - else { - ItemStack stack = entityplayer.getCurrentEquippedItem(); - if(stack != null && stack.getItem() instanceof IElectricChest && ((IElectricChest)stack.getItem()).isElectricChest(stack)) - { - FMLClientHandler.instance().displayGuiScreen(entityplayer, new GuiPasswordEnter(stack)); - } - } - } - else if(id == 2) - { - if(isBlock) - { - FMLClientHandler.instance().displayGuiScreen(entityplayer, new GuiPasswordModify(tileEntity)); - } - else { - ItemStack stack = entityplayer.getCurrentEquippedItem(); - if(stack != null && stack.getItem() instanceof IElectricChest && ((IElectricChest)stack.getItem()).isElectricChest(stack)) - { - FMLClientHandler.instance().displayGuiScreen(entityplayer, new GuiPasswordModify(stack)); - } - } - } + Mekanism.proxy.openElectricChest(entityplayer, id, windowId, isBlock, x, y, z); } catch(Exception e) { System.err.println("[Mekanism] Error while handling electric chest open packet."); e.printStackTrace(); diff --git a/src/minecraft/mekanism/common/TileEntityBasicMachine.java b/src/minecraft/mekanism/common/TileEntityBasicMachine.java index c6af87f78..412583bc5 100644 --- a/src/minecraft/mekanism/common/TileEntityBasicMachine.java +++ b/src/minecraft/mekanism/common/TileEntityBasicMachine.java @@ -419,12 +419,14 @@ public abstract class TileEntityBasicMachine extends TileEntityElectricBlock imp } @Override + @SideOnly(Side.CLIENT) public Sound getSound() { return audio; } @Override + @SideOnly(Side.CLIENT) public void removeSound() { audio = null; diff --git a/src/minecraft/mekanism/common/TileEntityFactory.java b/src/minecraft/mekanism/common/TileEntityFactory.java index 242955ae9..54677c39c 100644 --- a/src/minecraft/mekanism/common/TileEntityFactory.java +++ b/src/minecraft/mekanism/common/TileEntityFactory.java @@ -765,12 +765,14 @@ public class TileEntityFactory extends TileEntityElectricBlock implements IEnerg } @Override + @SideOnly(Side.CLIENT) public Sound getSound() { return audio; } @Override + @SideOnly(Side.CLIENT) public void removeSound() { audio = null; diff --git a/src/minecraft/mekanism/common/TileEntityMetallurgicInfuser.java b/src/minecraft/mekanism/common/TileEntityMetallurgicInfuser.java index 42f26790e..d2846f81c 100644 --- a/src/minecraft/mekanism/common/TileEntityMetallurgicInfuser.java +++ b/src/minecraft/mekanism/common/TileEntityMetallurgicInfuser.java @@ -691,12 +691,14 @@ public class TileEntityMetallurgicInfuser extends TileEntityElectricBlock implem } @Override + @SideOnly(Side.CLIENT) public Sound getSound() { return audio; } @Override + @SideOnly(Side.CLIENT) public void removeSound() { audio = null; diff --git a/src/minecraft/mekanism/generators/common/TileEntityGenerator.java b/src/minecraft/mekanism/generators/common/TileEntityGenerator.java index a13d0663a..4e92fbb37 100644 --- a/src/minecraft/mekanism/generators/common/TileEntityGenerator.java +++ b/src/minecraft/mekanism/generators/common/TileEntityGenerator.java @@ -379,12 +379,14 @@ public abstract class TileEntityGenerator extends TileEntityElectricBlock implem } @Override + @SideOnly(Side.CLIENT) public Sound getSound() { return audio; } @Override + @SideOnly(Side.CLIENT) public void removeSound() { audio = null;