From 48a2a6ade7f3cfc4fbae680565a050a5e49638d3 Mon Sep 17 00:00:00 2001 From: Aidan Brady Date: Fri, 7 Jun 2013 11:16:47 -0400 Subject: [PATCH] v5.5.6 Beta #15 *Revamped packet system. *Fixed up recipe system bugs. *Deleted spam on Electric Pump. *Minor API change, MDK users (@micdoodle, @LiQuiD, @pixlepix) please update. --- .../mekanism/api/IEnergizedItem.java | 6 + .../client/ClientPlayerTickHandler.java | 10 +- .../client/GuiPortableTeleporter.java | 3 +- .../mekanism/client/GuiRobitMain.java | 8 +- .../mekanism/client/GuiStopwatch.java | 9 +- .../mekanism/client/GuiWeatherOrb.java | 9 +- src/minecraft/mekanism/common/BlockBasic.java | 6 +- .../mekanism/common/EnumPacketType.java | 16 +- .../mekanism/common/ItemBlockEnergyCube.java | 6 + .../mekanism/common/ItemBlockMachine.java | 6 + .../mekanism/common/ItemEnergized.java | 6 + src/minecraft/mekanism/common/Mekanism.java | 21 +- .../mekanism/common/MekanismRecipe.java | 64 +- .../mekanism/common/PacketHandler.java | 849 ++++++------------ .../common/TileEntityElectricChest.java | 4 +- .../common/TileEntityElectricPump.java | 1 - .../generators/common/ItemBlockGenerator.java | 6 + .../mekanism/nei/MekanismRecipeHandler.java | 43 +- 18 files changed, 390 insertions(+), 683 deletions(-) diff --git a/src/minecraft/mekanism/api/IEnergizedItem.java b/src/minecraft/mekanism/api/IEnergizedItem.java index 2948864b7..344fd0961 100644 --- a/src/minecraft/mekanism/api/IEnergizedItem.java +++ b/src/minecraft/mekanism/api/IEnergizedItem.java @@ -50,4 +50,10 @@ public interface IEnergizedItem * @return if the item can send energy */ public boolean canSend(ItemStack itemStack); + + /** + * Returns whether or not this item contains metadata-specific subtypes instead of using metadata for damage display. + * @return if the item contains metadata-specific subtypes + */ + public boolean isMetadataSpecific(); } diff --git a/src/minecraft/mekanism/client/ClientPlayerTickHandler.java b/src/minecraft/mekanism/client/ClientPlayerTickHandler.java index b74c1541f..4bb4a1c84 100644 --- a/src/minecraft/mekanism/client/ClientPlayerTickHandler.java +++ b/src/minecraft/mekanism/client/ClientPlayerTickHandler.java @@ -2,17 +2,17 @@ package mekanism.client; import java.util.EnumSet; -import org.lwjgl.input.Keyboard; - import mekanism.api.EnumColor; import mekanism.common.EnumPacketType; import mekanism.common.ItemConfigurator; import mekanism.common.ItemElectricBow; -import mekanism.common.MekanismUtils; import mekanism.common.PacketHandler; +import mekanism.common.PacketHandler.Transmission; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; +import org.lwjgl.input.Keyboard; + import cpw.mods.fml.common.ITickHandler; import cpw.mods.fml.common.TickType; import cpw.mods.fml.relauncher.Side; @@ -47,7 +47,7 @@ public class ClientPlayerTickHandler implements ITickHandler if(!lastTickConfiguratorChange) { item.setState(stack, (byte)(item.getState(stack) < 3 ? item.getState(stack)+1 : 0)); - PacketHandler.sendPacketDataInt(EnumPacketType.CONFIGURATOR_STATE, item.getState(stack)); + PacketHandler.sendPacketData(EnumPacketType.CONFIGURATOR_STATE, Transmission.SERVER, item.getState(stack)); entityPlayer.sendChatToPlayer(EnumColor.DARK_BLUE + "[Mekanism] " + EnumColor.GREY + "Configure State: " + item.getColor(item.getState(stack)) + item.getState(item.getState(stack))); lastTickConfiguratorChange = true; } @@ -65,7 +65,7 @@ public class ClientPlayerTickHandler implements ITickHandler if(!lastTickElectricBowChange) { item.setFireState(stack, !item.getFireState(stack)); - PacketHandler.sendPacketDataInt(EnumPacketType.ELECTRIC_BOW_STATE, item.getFireState(stack) ? 1 : 0); + PacketHandler.sendPacketData(EnumPacketType.ELECTRIC_BOW_STATE, Transmission.SERVER, item.getFireState(stack) ? 1 : 0); entityPlayer.sendChatToPlayer(EnumColor.DARK_BLUE + "[Mekanism] " + EnumColor.GREY + "Fire Mode: " + (item.getFireState(stack) ? (EnumColor.DARK_GREEN + "ON") : (EnumColor.DARK_RED + "OFF"))); lastTickElectricBowChange = true; } diff --git a/src/minecraft/mekanism/client/GuiPortableTeleporter.java b/src/minecraft/mekanism/client/GuiPortableTeleporter.java index 2dde8597e..56394b778 100644 --- a/src/minecraft/mekanism/client/GuiPortableTeleporter.java +++ b/src/minecraft/mekanism/client/GuiPortableTeleporter.java @@ -3,6 +3,7 @@ package mekanism.client; import mekanism.common.EnumPacketType; import mekanism.common.ItemPortableTeleporter; import mekanism.common.PacketHandler; +import mekanism.common.PacketHandler.Transmission; import net.minecraft.client.gui.GuiButton; import net.minecraft.client.gui.GuiScreen; import net.minecraft.entity.player.EntityPlayer; @@ -78,7 +79,7 @@ public class GuiPortableTeleporter extends GuiScreen { if(guibutton.id == 0) { - PacketHandler.sendPacketDataInt(EnumPacketType.PORTABLE_TELEPORT, 0); + PacketHandler.sendPacketData(EnumPacketType.PORTABLE_TELEPORT, Transmission.SERVER, 0); mc.setIngameFocus(); } } diff --git a/src/minecraft/mekanism/client/GuiRobitMain.java b/src/minecraft/mekanism/client/GuiRobitMain.java index 93c6f9f84..6d94bffb4 100644 --- a/src/minecraft/mekanism/client/GuiRobitMain.java +++ b/src/minecraft/mekanism/client/GuiRobitMain.java @@ -5,6 +5,8 @@ import mekanism.common.EntityRobit; import mekanism.common.EnumPacketType; import mekanism.common.Mekanism; import mekanism.common.PacketHandler; +import mekanism.common.PacketHandler.RobitPacket; +import mekanism.common.PacketHandler.Transmission; import net.minecraft.client.gui.GuiButton; import net.minecraft.client.gui.GuiTextField; import net.minecraft.client.gui.inventory.GuiContainer; @@ -282,7 +284,7 @@ public class GuiRobitMain extends GuiContainer else if(xAxis >= 152 && xAxis <= 170 && yAxis >= 54 && yAxis <= 72) { mc.sndManager.playSoundFX("random.click", 1.0F, 1.0F); - PacketHandler.sendPacketDataInt(EnumPacketType.FOLLOW_UPDATE, robit.entityId); + PacketHandler.sendPacketData(EnumPacketType.ROBIT, Transmission.SERVER, RobitPacket.FOLLOW.ordinal(), robit.entityId); } else if(xAxis >= 6 && xAxis <= 24 && yAxis >= 54 && yAxis <= 72) { @@ -292,12 +294,12 @@ public class GuiRobitMain extends GuiContainer else if(xAxis >= 6 && xAxis <= 24 && yAxis >= 16 && yAxis <= 34) { mc.sndManager.playSoundFX("random.click", 1.0F, 1.0F); - PacketHandler.sendPacketDataInt(EnumPacketType.GO_HOME, robit.entityId); + PacketHandler.sendPacketData(EnumPacketType.ROBIT, Transmission.SERVER, RobitPacket.GO_HOME.ordinal(), robit.entityId); } else if(xAxis >= 6 && xAxis <= 24 && yAxis >= 35 && yAxis <= 53) { mc.sndManager.playSoundFX("random.click", 1.0F, 1.0F); - PacketHandler.sendPacketDataInt(EnumPacketType.DROP_PICKUP_UPDATE, robit.entityId); + PacketHandler.sendPacketData(EnumPacketType.ROBIT, Transmission.SERVER, RobitPacket.DROP_PICKUP.ordinal(), robit.entityId); } } } diff --git a/src/minecraft/mekanism/client/GuiStopwatch.java b/src/minecraft/mekanism/client/GuiStopwatch.java index 22cacc9da..bbcc2944b 100644 --- a/src/minecraft/mekanism/client/GuiStopwatch.java +++ b/src/minecraft/mekanism/client/GuiStopwatch.java @@ -3,6 +3,7 @@ package mekanism.client; import mekanism.common.EnumPacketType; import mekanism.common.MekanismUtils; import mekanism.common.PacketHandler; +import mekanism.common.PacketHandler.Transmission; import net.minecraft.client.gui.GuiButton; import net.minecraft.client.gui.GuiScreen; import net.minecraft.entity.player.EntityPlayer; @@ -71,25 +72,25 @@ public class GuiStopwatch extends GuiScreen if(guibutton.id == 0) { MekanismUtils.doFakeEntityExplosion(player); - PacketHandler.sendPacketDataInt(EnumPacketType.TIME, 0); + PacketHandler.sendPacketData(EnumPacketType.TIME, Transmission.SERVER, 0); mc.displayGuiScreen(null); } if(guibutton.id == 1) { MekanismUtils.doFakeEntityExplosion(player); - PacketHandler.sendPacketDataInt(EnumPacketType.TIME, 6); + PacketHandler.sendPacketData(EnumPacketType.TIME, Transmission.SERVER, 6); mc.displayGuiScreen(null); } if(guibutton.id == 2) { MekanismUtils.doFakeEntityExplosion(player); - PacketHandler.sendPacketDataInt(EnumPacketType.TIME, 12); + PacketHandler.sendPacketData(EnumPacketType.TIME, Transmission.SERVER, 12); mc.displayGuiScreen(null); } if(guibutton.id == 3) { MekanismUtils.doFakeEntityExplosion(player); - PacketHandler.sendPacketDataInt(EnumPacketType.TIME, 18); + PacketHandler.sendPacketData(EnumPacketType.TIME, Transmission.SERVER, 18); mc.displayGuiScreen(null); } if(guibutton.id == 4) diff --git a/src/minecraft/mekanism/client/GuiWeatherOrb.java b/src/minecraft/mekanism/client/GuiWeatherOrb.java index 9d40e4bdd..27faa4a92 100644 --- a/src/minecraft/mekanism/client/GuiWeatherOrb.java +++ b/src/minecraft/mekanism/client/GuiWeatherOrb.java @@ -4,6 +4,7 @@ import mekanism.common.EnumPacketType; import mekanism.common.EnumWeatherType; import mekanism.common.MekanismUtils; import mekanism.common.PacketHandler; +import mekanism.common.PacketHandler.Transmission; import net.minecraft.client.gui.GuiButton; import net.minecraft.client.gui.GuiScreen; import net.minecraft.entity.player.EntityPlayer; @@ -72,25 +73,25 @@ public class GuiWeatherOrb extends GuiScreen if(guibutton.id == 0) { MekanismUtils.doFakeEntityExplosion(player); - PacketHandler.sendPacketDataInt(EnumPacketType.WEATHER, EnumWeatherType.CLEAR.id); + PacketHandler.sendPacketData(EnumPacketType.WEATHER, Transmission.SERVER, EnumWeatherType.CLEAR.id); mc.displayGuiScreen(null); } if(guibutton.id == 1) { MekanismUtils.doFakeEntityExplosion(player); - PacketHandler.sendPacketDataInt(EnumPacketType.WEATHER, EnumWeatherType.STORM.id); + PacketHandler.sendPacketData(EnumPacketType.WEATHER, Transmission.SERVER, EnumWeatherType.STORM.id); mc.displayGuiScreen(null); } if(guibutton.id == 2) { MekanismUtils.doFakeEntityExplosion(player); - PacketHandler.sendPacketDataInt(EnumPacketType.WEATHER, EnumWeatherType.HAZE.id); + PacketHandler.sendPacketData(EnumPacketType.WEATHER, Transmission.SERVER, EnumWeatherType.HAZE.id); mc.displayGuiScreen(null); } if(guibutton.id == 3) { MekanismUtils.doFakeEntityExplosion(player); - PacketHandler.sendPacketDataInt(EnumPacketType.WEATHER, EnumWeatherType.RAIN.id); + PacketHandler.sendPacketData(EnumPacketType.WEATHER, Transmission.SERVER, EnumWeatherType.RAIN.id); mc.displayGuiScreen(null); } if(guibutton.id == 4) diff --git a/src/minecraft/mekanism/common/BlockBasic.java b/src/minecraft/mekanism/common/BlockBasic.java index 858ce0b47..72246e2e2 100644 --- a/src/minecraft/mekanism/common/BlockBasic.java +++ b/src/minecraft/mekanism/common/BlockBasic.java @@ -1,8 +1,11 @@ package mekanism.common; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; +import java.util.Map; +import mekanism.api.Object3D; import mekanism.client.ClientProxy; import net.minecraft.block.Block; import net.minecraft.block.material.Material; @@ -17,6 +20,7 @@ import net.minecraft.tileentity.TileEntity; import net.minecraft.util.Icon; import net.minecraft.world.IBlockAccess; import net.minecraft.world.World; +import net.minecraftforge.common.ForgeDirection; import net.minecraftforge.liquids.LiquidContainerRegistry; import net.minecraftforge.liquids.LiquidStack; import cpw.mods.fml.relauncher.Side; @@ -192,7 +196,7 @@ public class BlockBasic extends Block return false; } - public boolean manageInventory(EntityPlayer player, TileEntityDynamicTank tileEntity) + private boolean manageInventory(EntityPlayer player, TileEntityDynamicTank tileEntity) { ItemStack itemStack = player.getCurrentEquippedItem(); diff --git a/src/minecraft/mekanism/common/EnumPacketType.java b/src/minecraft/mekanism/common/EnumPacketType.java index 83d85c7f8..200d8561d 100644 --- a/src/minecraft/mekanism/common/EnumPacketType.java +++ b/src/minecraft/mekanism/common/EnumPacketType.java @@ -66,20 +66,8 @@ public enum EnumPacketType /** Used to send an electrolytic separator particle to all clients. */ ELECTROLYTIC_SEPARATOR_PARTICLE(18), - /** Used to send a Robit GUI request to the server. */ - ROBIT_GUI(19), - - /** Used to send a Robit follow update packet to the server. */ - FOLLOW_UPDATE(20), - - /** Used to send a Robit name update packet to the server. */ - NAME_UPDATE(21), - - /** Used to send a Robit 'go home' packet to the server. */ - GO_HOME(22), - - /** Used to send a Robit drop pickup update packet to the server. */ - DROP_PICKUP_UPDATE(23), + /** Robit-based packets. */ + ROBIT(19), /** A custom packet type. Handled in PacketHandler. */ CUSTOM(-1); diff --git a/src/minecraft/mekanism/common/ItemBlockEnergyCube.java b/src/minecraft/mekanism/common/ItemBlockEnergyCube.java index 82d8a29f6..4226d2da8 100644 --- a/src/minecraft/mekanism/common/ItemBlockEnergyCube.java +++ b/src/minecraft/mekanism/common/ItemBlockEnergyCube.java @@ -392,4 +392,10 @@ public class ItemBlockEnergyCube extends ItemBlock implements IEnergizedItem, II { return (float)(getMaxEnergy(theItem)*Mekanism.TO_BC); } + + @Override + public boolean isMetadataSpecific() + { + return true; + } } diff --git a/src/minecraft/mekanism/common/ItemBlockMachine.java b/src/minecraft/mekanism/common/ItemBlockMachine.java index a85baafd4..1fd86681c 100644 --- a/src/minecraft/mekanism/common/ItemBlockMachine.java +++ b/src/minecraft/mekanism/common/ItemBlockMachine.java @@ -820,4 +820,10 @@ public class ItemBlockMachine extends ItemBlock implements IEnergizedItem, IItem { return (float)(getMaxEnergy(theItem)*Mekanism.TO_BC); } + + @Override + public boolean isMetadataSpecific() + { + return true; + } } diff --git a/src/minecraft/mekanism/common/ItemEnergized.java b/src/minecraft/mekanism/common/ItemEnergized.java index 2a2778ab8..13abb7f2a 100644 --- a/src/minecraft/mekanism/common/ItemEnergized.java +++ b/src/minecraft/mekanism/common/ItemEnergized.java @@ -302,4 +302,10 @@ public class ItemEnergized extends ItemMekanism implements IEnergizedItem, IItem { return (float)(getMaxEnergy(theItem)*Mekanism.TO_BC); } + + @Override + public boolean isMetadataSpecific() + { + return false; + } } diff --git a/src/minecraft/mekanism/common/Mekanism.java b/src/minecraft/mekanism/common/Mekanism.java index b747a038c..a94021015 100644 --- a/src/minecraft/mekanism/common/Mekanism.java +++ b/src/minecraft/mekanism/common/Mekanism.java @@ -259,7 +259,7 @@ public class Mekanism CraftingManager.getInstance().getRecipeList().add(new MekanismRecipe(StorageTank.getEmptyItem(), new Object[] { "III", "IDI", "III", Character.valueOf('I'), Item.ingotIron, Character.valueOf('D'), "dustIron" })); - CraftingManager.getInstance().getRecipeList().add(new MekanismRecipe(GasTank, new Object[] { + CraftingManager.getInstance().getRecipeList().add(new MekanismRecipe(new ItemStack(GasTank), new Object[] { "PPP", "PDP", "PPP", Character.valueOf('P'), "ingotOsmium", Character.valueOf('D'), "dustIron" })); CraftingManager.getInstance().getRecipeList().add(new MekanismRecipe(MekanismUtils.getEnergyCube(EnergyCubeTier.BASIC), new Object[] { @@ -326,7 +326,7 @@ public class Mekanism "SGS", "CcC", "SSS", Character.valueOf('S'), "ingotSteel", Character.valueOf('G'), Block.glass, Character.valueOf('C'), Block.chest, Character.valueOf('c'), ControlCircuit })); CraftingManager.getInstance().getRecipeList().add(new MekanismRecipe(new ItemStack(Transmitter, 8, 2), new Object[] { - "O O", Character.valueOf('O'), "ingotOsmium" + "OBO", Character.valueOf('O'), "ingotOsmium", Character.valueOf('B'), Item.bucketEmpty })); CraftingManager.getInstance().getRecipeList().add(new MekanismRecipe(new ItemStack(BasicBlock, 4, 9), new Object[] { " I ", "ISI", " I ", Character.valueOf('I'), "ingotSteel", Character.valueOf('S'), Block.cobblestone @@ -981,9 +981,6 @@ public class Mekanism } } catch(Exception e) {} - /** Here we go through every Metallurgy metal set and add recipes to handle the new metals added - * There is no API way to iterate all the metal types, so we use hardcode :( - */ if(hooks.MetallurgyCoreLoaded) { try { @@ -994,10 +991,7 @@ public class Mekanism for(IOreInfo oreInfo : MetallurgyAPI.getMetalSet(setName).getOreList().values()) { switch(oreInfo.getType()) - { - /** Alloy metal don't drop, they are only produced by combining other metals - * only adding crusher - */ + { case ALLOY: { if(oreInfo.getIngot() != null && oreInfo.getDust() != null) @@ -1007,11 +1001,6 @@ public class Mekanism break; } - - /** DROP-type ores normally drop something else then the ore itself, so here we add - * bonus items given by enrichment chamber if silk touch or other way gives the player the ore block - * Maybe add combiner recipe, but seems pointless now - */ case DROP: { ItemStack ore = oreInfo.getOre(); @@ -1025,10 +1014,6 @@ public class Mekanism break; } - - /** - * For all other types we don't really care, just try the general stencil - */ default: { ItemStack ore = oreInfo.getOre(); diff --git a/src/minecraft/mekanism/common/MekanismRecipe.java b/src/minecraft/mekanism/common/MekanismRecipe.java index 8997a2434..8ce9ea817 100644 --- a/src/minecraft/mekanism/common/MekanismRecipe.java +++ b/src/minecraft/mekanism/common/MekanismRecipe.java @@ -27,16 +27,6 @@ public class MekanismRecipe implements IRecipe public int width = 0; public int height = 0; private boolean mirrored = true; - - public MekanismRecipe(Block result, Object... recipe) - { - this(new ItemStack(result), recipe); - } - - public MekanismRecipe(Item result, Object... recipe) - { - this(new ItemStack(result), recipe); - } public MekanismRecipe(ItemStack result, Object... recipe) { @@ -84,12 +74,13 @@ public class MekanismRecipe implements IRecipe { String ret = "Invalid shaped ore recipe: "; - for (Object tmp : recipe) + for(Object tmp : recipe) { ret += tmp + ", "; } ret += output; + throw new RuntimeException(ret); } @@ -110,7 +101,7 @@ public class MekanismRecipe implements IRecipe } else if(in instanceof Block) { - itemMap.put(chr, new ItemStack((Block)in, 1, OreDictionary.WILDCARD_VALUE)); + itemMap.put(chr, new ItemStack((Block)in)); } else if(in instanceof String) { @@ -256,11 +247,18 @@ public class MekanismRecipe implements IRecipe { if(input == null && target != null || input != null && target == null) { + System.out.println("False"); return false; } + else if(input == null && target == null) + { + System.out.println("True"); + return true; + } if(target.itemID != input.itemID) { + System.out.println("False"); return false; } @@ -268,32 +266,42 @@ public class MekanismRecipe implements IRecipe { if(target.getItemDamage() != input.getItemDamage()) { + System.out.println("False"); return false; } } - else if(target.getItem() instanceof IEnergyCube && input.getItem() instanceof IEnergyCube) - { - if(((IEnergyCube)target.getItem()).getEnergyCubeTier(target) != ((IEnergyCube)input.getItem()).getEnergyCubeTier(input)) + else { + if(((IEnergizedItem)target.getItem()).isMetadataSpecific() && ((IEnergizedItem)input.getItem()).isMetadataSpecific()) { - return false; - } - } - else if(target.getItem() instanceof IFactory && input.getItem() instanceof IFactory) - { - if(((IFactory)target.getItem()).isFactory(target) && ((IFactory)input.getItem()).isFactory(input)) - { - if(target.getItemDamage() != input.getItemDamage()) - { - return false; - } - - if(((IFactory)target.getItem()).getRecipeType(target) != ((IFactory)input.getItem()).getRecipeType(input)) + if(target.getItemDamage() != input.getItemDamage()) { + System.out.println("False"); return false; } } + + if(target.getItem() instanceof IEnergyCube && input.getItem() instanceof IEnergyCube) + { + if(((IEnergyCube)target.getItem()).getEnergyCubeTier(target) != ((IEnergyCube)input.getItem()).getEnergyCubeTier(input)) + { + System.out.println("False"); + return false; + } + } + else if(target.getItem() instanceof IFactory && input.getItem() instanceof IFactory) + { + if(((IFactory)target.getItem()).isFactory(target) && ((IFactory)input.getItem()).isFactory(input)) + { + if(((IFactory)target.getItem()).getRecipeType(target) != ((IFactory)input.getItem()).getRecipeType(input)) + { + System.out.println("False"); + return false; + } + } + } } + System.out.println("True"); return true; } diff --git a/src/minecraft/mekanism/common/PacketHandler.java b/src/minecraft/mekanism/common/PacketHandler.java index 1023ef572..451f77139 100644 --- a/src/minecraft/mekanism/common/PacketHandler.java +++ b/src/minecraft/mekanism/common/PacketHandler.java @@ -468,99 +468,84 @@ public class PacketHandler implements IPacketHandler e.printStackTrace(); } } - else if(packetType == EnumPacketType.ROBIT_GUI.id) + else if(packetType == EnumPacketType.ROBIT.id) { try { - int type = dataStream.readInt(); - int id = dataStream.readInt(); + int subType = dataStream.readInt(); - if(type == 0) + if(subType == 0) { - entityplayer.openGui(Mekanism.instance, 21, entityplayer.worldObj, id, 0, 0); + int type = dataStream.readInt(); + int id = dataStream.readInt(); + + if(type == 0) + { + entityplayer.openGui(Mekanism.instance, 21, entityplayer.worldObj, id, 0, 0); + } + else if(type == 1) + { + entityplayer.openGui(Mekanism.instance, 22, entityplayer.worldObj, id, 0, 0); + } + else if(type == 2) + { + entityplayer.openGui(Mekanism.instance, 23, entityplayer.worldObj, id, 0, 0); + } + else if(type == 3) + { + entityplayer.openGui(Mekanism.instance, 24, entityplayer.worldObj, id, 0, 0); + } + else if(type == 4) + { + entityplayer.openGui(Mekanism.instance, 25, entityplayer.worldObj, id, 0, 0); + } } - else if(type == 1) + else if(subType == 1) { - entityplayer.openGui(Mekanism.instance, 22, entityplayer.worldObj, id, 0, 0); + int id = dataStream.readInt(); + + EntityRobit robit = (EntityRobit)entityplayer.worldObj.getEntityByID(id); + + if(robit != null) + { + robit.setFollowing(!robit.getFollowing()); + } } - else if(type == 2) + else if(subType == 2) { - entityplayer.openGui(Mekanism.instance, 23, entityplayer.worldObj, id, 0, 0); + String name = dataStream.readUTF(); + int id = dataStream.readInt(); + + EntityRobit robit = (EntityRobit)entityplayer.worldObj.getEntityByID(id); + + if(robit != null) + { + robit.setName(name); + } } - else if(type == 3) + else if(subType == 3) { - entityplayer.openGui(Mekanism.instance, 24, entityplayer.worldObj, id, 0, 0); + int id = dataStream.readInt(); + + EntityRobit robit = (EntityRobit)entityplayer.worldObj.getEntityByID(id); + + if(robit != null) + { + robit.goHome(); + } } - else if(type == 4) + else if(subType == 4) { - entityplayer.openGui(Mekanism.instance, 25, entityplayer.worldObj, id, 0, 0); + int id = dataStream.readInt(); + + EntityRobit robit = (EntityRobit)entityplayer.worldObj.getEntityByID(id); + + if(robit != null) + { + robit.setDropPickup(!robit.getDropPickup()); + } } } catch(Exception e) { - System.err.println("[Mekanism] Error while handling robit GUI packet."); - e.printStackTrace(); - } - } - else if(packetType == EnumPacketType.FOLLOW_UPDATE.id) - { - try { - int id = dataStream.readInt(); - - EntityRobit robit = (EntityRobit)entityplayer.worldObj.getEntityByID(id); - - if(robit != null) - { - robit.setFollowing(!robit.getFollowing()); - } - } catch(Exception e) { - System.err.println("[Mekanism] Error while handling follow update packet."); - e.printStackTrace(); - } - } - else if(packetType == EnumPacketType.NAME_UPDATE.id) - { - try { - String name = dataStream.readUTF(); - int id = dataStream.readInt(); - - EntityRobit robit = (EntityRobit)entityplayer.worldObj.getEntityByID(id); - - if(robit != null) - { - robit.setName(name); - } - } catch(Exception e) { - System.err.println("[Mekanism] Error while handling name update packet."); - e.printStackTrace(); - } - } - else if(packetType == EnumPacketType.GO_HOME.id) - { - try { - int id = dataStream.readInt(); - - EntityRobit robit = (EntityRobit)entityplayer.worldObj.getEntityByID(id); - - if(robit != null) - { - robit.goHome(); - } - } catch(Exception e) { - System.err.println("[Mekanism] Error while handling go home packet."); - e.printStackTrace(); - } - } - else if(packetType == EnumPacketType.DROP_PICKUP_UPDATE.id) - { - try { - int id = dataStream.readInt(); - - EntityRobit robit = (EntityRobit)entityplayer.worldObj.getEntityByID(id); - - if(robit != null) - { - robit.setDropPickup(!robit.getDropPickup()); - } - } catch(Exception e) { - System.err.println("[Mekanism] Error while handling drop pickup update packet."); + System.err.println("[Mekanism] Error while handling robit packet."); e.printStackTrace(); } } @@ -581,146 +566,25 @@ public class PacketHandler implements IPacketHandler */ public static void sendTileEntityPacketToServer(TileEntity sender, ArrayList dataValues) { - ByteArrayOutputStream bytes = new ByteArrayOutputStream(); - DataOutputStream output = new DataOutputStream(bytes); - - try { - output.writeInt(EnumPacketType.TILE_ENTITY.id); - output.writeInt(sender.xCoord); - output.writeInt(sender.yCoord); - output.writeInt(sender.zCoord); - - for(Object data : dataValues) - { - if(data instanceof Integer) - { - output.writeInt((Integer)data); - } - else if(data instanceof Boolean) - { - output.writeBoolean((Boolean)data); - } - else if(data instanceof Double) - { - output.writeDouble((Double)data); - } - else if(data instanceof Float) - { - output.writeFloat((Float)data); - } - else if(data instanceof String) - { - output.writeUTF((String)data); - } - else if(data instanceof Byte) - { - output.writeByte((Byte)data); - } - else if(data instanceof int[]) - { - for(int i : (int[])data) - { - output.writeInt(i); - } - } - else if(data instanceof byte[]) - { - for(byte b : (byte[])data) - { - output.writeByte(b); - } - } - } - - Packet250CustomPayload packet = new Packet250CustomPayload(); - packet.channel = "Mekanism"; - packet.data = bytes.toByteArray(); - packet.length = packet.data.length; - - PacketDispatcher.sendPacketToServer(packet); - } catch (IOException e) { - System.err.println("[Mekanism] Error while writing tile entity packet."); - e.printStackTrace(); - } + sendPacketData(EnumPacketType.TILE_ENTITY, Transmission.SERVER, sender.xCoord, sender.yCoord, sender.zCoord, dataValues); } /** * Sends a packet from server to client with the TILE_ENTITY ID as well as an undefined amount of objects. - * While it won't give you an error, you cannot send anything other than integers or booleans. This can - * also be sent with a defined range, so players far away won't receive the packet. + * This can also be sent with a defined range, so players far away won't receive the packet. * @param sender - sending tile entity * @param distance - distance to send the packet, 0 if infinite range * @param dataValues - data to send */ public static void sendTileEntityPacketToClients(TileEntity sender, double distance, ArrayList dataValues) { - ByteArrayOutputStream bytes = new ByteArrayOutputStream(); - DataOutputStream output = new DataOutputStream(bytes); - - try { - output.writeInt(EnumPacketType.TILE_ENTITY.id); - output.writeInt(sender.xCoord); - output.writeInt(sender.yCoord); - output.writeInt(sender.zCoord); - - for(Object data : dataValues) - { - if(data instanceof Integer) - { - output.writeInt((Integer)data); - } - else if(data instanceof Boolean) - { - output.writeBoolean((Boolean)data); - } - else if(data instanceof Double) - { - output.writeDouble((Double)data); - } - else if(data instanceof Float) - { - output.writeFloat((Float)data); - } - else if(data instanceof String) - { - output.writeUTF((String)data); - } - else if(data instanceof Byte) - { - output.writeByte((Byte)data); - } - else if(data instanceof int[]) - { - for(int i : (int[])data) - { - output.writeInt(i); - } - } - else if(data instanceof byte[]) - { - for(byte b : (byte[])data) - { - output.writeByte(b); - } - } - } - - Packet250CustomPayload packet = new Packet250CustomPayload(); - packet.channel = "Mekanism"; - packet.data = bytes.toByteArray(); - packet.length = packet.data.length; - - if(distance == 0) - { - PacketDispatcher.sendPacketToAllPlayers(packet); - } - else { - PacketDispatcher.sendPacketToAllAround(sender.xCoord, sender.yCoord, sender.zCoord, distance, sender.worldObj.provider.dimensionId, packet); - } - } catch (IOException e) { - System.err.println("[Mekanism] Error while writing tile entity packet."); - e.printStackTrace(); - } + if(distance == 0) + { + sendPacketData(EnumPacketType.TILE_ENTITY, Transmission.ALL_CLIENTS, sender.xCoord, sender.yCoord, sender.zCoord, dataValues); + } + else { + sendPacketData(EnumPacketType.TILE_ENTITY, Transmission.CLIENTS_RANGE, Object3D.get(sender), distance, sender.xCoord, sender.yCoord, sender.zCoord, dataValues); + } } /** @@ -739,32 +603,7 @@ public class PacketHandler implements IPacketHandler */ public static void sendGuiRequest(String modClass, String modInstance, int x, int y, int z, int guiId) { - ByteArrayOutputStream bytes = new ByteArrayOutputStream(); - DataOutputStream data = new DataOutputStream(bytes); - - try { - data.writeInt(EnumPacketType.CONTROL_PANEL.id); - data.writeUTF(modClass); - data.writeUTF(modInstance); - data.writeInt(x); - data.writeInt(y); - data.writeInt(z); - data.writeInt(guiId); - } catch (IOException e) { - System.out.println("[Mekanism] An error occured while writing packet data."); - e.printStackTrace(); - } - - Packet250CustomPayload packet = new Packet250CustomPayload(); - packet.channel = "Mekanism"; - packet.data = bytes.toByteArray(); - packet.length = packet.data.length; - PacketDispatcher.sendPacketToServer(packet); - - if(Mekanism.logPackets) - { - System.out.println("[Mekanism] Sent control panel packet to server."); - } + sendPacketData(EnumPacketType.CONTROL_PANEL, Transmission.SERVER, modClass, modInstance, x, y, z, guiId); } /** @@ -776,29 +615,7 @@ public class PacketHandler implements IPacketHandler */ public static void sendPortalFX(int x, int y, int z, int id) { - ByteArrayOutputStream bytes = new ByteArrayOutputStream(); - DataOutputStream data = new DataOutputStream(bytes); - - try { - data.writeInt(EnumPacketType.PORTAL_FX.id); - data.writeInt(x); - data.writeInt(y); - data.writeInt(z); - } catch (IOException e) { - System.out.println("[Mekanism] An error occured while writing packet data."); - e.printStackTrace(); - } - - Packet250CustomPayload packet = new Packet250CustomPayload(); - packet.channel = "Mekanism"; - packet.data = bytes.toByteArray(); - packet.length = packet.data.length; - PacketDispatcher.sendPacketToAllAround(x, y, z, 40, id, packet); - - if(Mekanism.logPackets) - { - System.out.println("[Mekanism] Sent portal FX packet to clients."); - } + sendPacketData(EnumPacketType.PORTAL_FX, Transmission.CLIENTS_RANGE, new Object3D(x, y, z, id), 40D, x, y, z); } /** @@ -808,28 +625,7 @@ public class PacketHandler implements IPacketHandler */ public static void sendDigitUpdate(int index, int digit) { - ByteArrayOutputStream bytes = new ByteArrayOutputStream(); - DataOutputStream data = new DataOutputStream(bytes); - - try { - data.writeInt(EnumPacketType.DIGIT_UPDATE.id); - data.writeInt(index); - data.writeInt(digit); - } catch (IOException e) { - System.out.println("[Mekanism] An error occured while writing packet data."); - e.printStackTrace(); - } - - Packet250CustomPayload packet = new Packet250CustomPayload(); - packet.channel = "Mekanism"; - packet.data = bytes.toByteArray(); - packet.length = packet.data.length; - PacketDispatcher.sendPacketToServer(packet); - - if(Mekanism.logPackets) - { - System.out.println("[Mekanism] Sent digit update packet to server."); - } + sendPacketData(EnumPacketType.DIGIT_UPDATE, Transmission.SERVER, index, digit); } /** @@ -839,27 +635,7 @@ public class PacketHandler implements IPacketHandler */ public static void sendStatusUpdate(EntityPlayer entityplayer, int status) { - ByteArrayOutputStream bytes = new ByteArrayOutputStream(); - DataOutputStream data = new DataOutputStream(bytes); - - try { - data.writeInt(EnumPacketType.STATUS_UPDATE.id); - data.writeInt(status); - } catch (IOException e) { - System.out.println("[Mekanism] An error occured while writing packet data."); - e.printStackTrace(); - } - - Packet250CustomPayload packet = new Packet250CustomPayload(); - packet.channel = "Mekanism"; - packet.data = bytes.toByteArray(); - packet.length = packet.data.length; - PacketDispatcher.sendPacketToPlayer(packet, (Player)entityplayer); - - if(Mekanism.logPackets) - { - System.out.println("[Mekanism] Sent status update packet to " + entityplayer.username); - } + sendPacketData(EnumPacketType.STATUS_UPDATE, Transmission.SERVER, status); } /** @@ -872,36 +648,22 @@ public class PacketHandler implements IPacketHandler */ public static void sendChestOpenToPlayer(EntityPlayer player, TileEntity tileEntity, int i, int windowId, boolean isBlock) { - ByteArrayOutputStream bytes = new ByteArrayOutputStream(); - DataOutputStream data = new DataOutputStream(bytes); - - try { - data.writeInt(EnumPacketType.ELECTRIC_CHEST_CLIENT_OPEN.id); - data.writeInt(i); - data.writeInt(windowId); - data.writeBoolean(isBlock); - - if(isBlock) - { - data.writeInt(tileEntity.xCoord); - data.writeInt(tileEntity.yCoord); - data.writeInt(tileEntity.zCoord); - } - } catch (IOException e) { - System.out.println("[Mekanism] An error occured while writing packet data."); - e.printStackTrace(); - } - - Packet250CustomPayload packet = new Packet250CustomPayload(); - packet.channel = "Mekanism"; - packet.data = bytes.toByteArray(); - packet.length = packet.data.length; - ((EntityPlayerMP)player).playerNetServerHandler.sendPacketToPlayer(packet); - - if(Mekanism.logPackets) - { - System.out.println("[Mekanism] Sent electric chest open packet to " + player.username); - } + ArrayList dataValues = new ArrayList(); + + dataValues.add(player); + + dataValues.add(i); + dataValues.add(windowId); + dataValues.add(isBlock); + + if(isBlock) + { + dataValues.add(tileEntity.xCoord); + dataValues.add(tileEntity.yCoord); + dataValues.add(tileEntity.zCoord); + } + + sendPacketData(EnumPacketType.ELECTRIC_CHEST_CLIENT_OPEN, Transmission.SINGLE_CLIENT, dataValues); } /** @@ -912,35 +674,19 @@ public class PacketHandler implements IPacketHandler */ public static void sendChestOpen(TileEntity tileEntity, boolean isBlock, boolean useEnergy) { - ByteArrayOutputStream bytes = new ByteArrayOutputStream(); - DataOutputStream data = new DataOutputStream(bytes); - - try { - data.writeInt(EnumPacketType.ELECTRIC_CHEST_SERVER_OPEN.id); - data.writeBoolean(isBlock); - data.writeBoolean(useEnergy); - - if(isBlock) - { - data.writeInt(tileEntity.xCoord); - data.writeInt(tileEntity.yCoord); - data.writeInt(tileEntity.zCoord); - } - } catch (IOException e) { - System.out.println("[Mekanism] An error occured while writing packet data."); - e.printStackTrace(); - } - - Packet250CustomPayload packet = new Packet250CustomPayload(); - packet.channel = "Mekanism"; - packet.data = bytes.toByteArray(); - packet.length = packet.data.length; - PacketDispatcher.sendPacketToServer(packet); - - if(Mekanism.logPackets) - { - System.out.println("[Mekanism] Sent electric chest open packet to server."); - } + ArrayList dataValues = new ArrayList(); + + dataValues.add(isBlock); + dataValues.add(useEnergy); + + if(isBlock) + { + dataValues.add(tileEntity.xCoord); + dataValues.add(tileEntity.yCoord); + dataValues.add(tileEntity.zCoord); + } + + sendPacketData(EnumPacketType.ELECTRIC_CHEST_SERVER_OPEN, Transmission.SERVER, dataValues); } /** @@ -951,35 +697,19 @@ public class PacketHandler implements IPacketHandler */ public static void sendPasswordChange(TileEntity tileEntity, String password, boolean isBlock) { - ByteArrayOutputStream bytes = new ByteArrayOutputStream(); - DataOutputStream data = new DataOutputStream(bytes); - - try { - data.writeInt(EnumPacketType.ELECTRIC_CHEST_PASSWORD.id); - data.writeBoolean(isBlock); - data.writeUTF(password); - - if(isBlock) - { - data.writeInt(tileEntity.xCoord); - data.writeInt(tileEntity.yCoord); - data.writeInt(tileEntity.zCoord); - } - } catch (IOException e) { - System.out.println("[Mekanism] An error occured while writing packet data."); - e.printStackTrace(); - } - - Packet250CustomPayload packet = new Packet250CustomPayload(); - packet.channel = "Mekanism"; - packet.data = bytes.toByteArray(); - packet.length = packet.data.length; - PacketDispatcher.sendPacketToServer(packet); - - if(Mekanism.logPackets) - { - System.out.println("[Mekanism] Sent electric chest password packet to server."); - } + ArrayList dataValues = new ArrayList(); + + dataValues.add(isBlock); + dataValues.add(password); + + if(isBlock) + { + dataValues.add(tileEntity.xCoord); + dataValues.add(tileEntity.yCoord); + dataValues.add(tileEntity.zCoord); + } + + sendPacketData(EnumPacketType.ELECTRIC_CHEST_PASSWORD, Transmission.SERVER, dataValues); } /** @@ -990,35 +720,19 @@ public class PacketHandler implements IPacketHandler */ public static void sendLockChange(TileEntity tileEntity, boolean locked, boolean isBlock) { - ByteArrayOutputStream bytes = new ByteArrayOutputStream(); - DataOutputStream data = new DataOutputStream(bytes); - - try { - data.writeInt(EnumPacketType.ELECTRIC_CHEST_LOCK.id); - data.writeBoolean(isBlock); - data.writeBoolean(locked); - - if(isBlock) - { - data.writeInt(tileEntity.xCoord); - data.writeInt(tileEntity.yCoord); - data.writeInt(tileEntity.zCoord); - } - } catch (IOException e) { - System.out.println("[Mekanism] An error occured while writing packet data."); - e.printStackTrace(); - } - - Packet250CustomPayload packet = new Packet250CustomPayload(); - packet.channel = "Mekanism"; - packet.data = bytes.toByteArray(); - packet.length = packet.data.length; - PacketDispatcher.sendPacketToServer(packet); - - if(Mekanism.logPackets) - { - System.out.println("[Mekanism] Sent electric chest lock packet to server."); - } + ArrayList dataValues = new ArrayList(); + + dataValues.add(isBlock); + dataValues.add(locked); + + if(isBlock) + { + dataValues.add(tileEntity.xCoord); + dataValues.add(tileEntity.yCoord); + dataValues.add(tileEntity.zCoord); + } + + sendPacketData(EnumPacketType.ELECTRIC_CHEST_LOCK, Transmission.SERVER, dataValues); } /** @@ -1028,29 +742,7 @@ public class PacketHandler implements IPacketHandler */ public static void sendLiquidTransferUpdate(TileEntity head, LiquidStack resource) { - ByteArrayOutputStream bytes = new ByteArrayOutputStream(); - DataOutputStream output = new DataOutputStream(bytes); - - try { - output.writeInt(EnumPacketType.LIQUID_TRANSFER_UPDATE.id); - - output.writeInt(head.xCoord); - output.writeInt(head.yCoord); - output.writeInt(head.zCoord); - - output.writeInt(resource.itemID); - output.writeInt(resource.amount); - output.writeInt(resource.itemMeta); - - Packet250CustomPayload packet = new Packet250CustomPayload(); - packet.channel = "Mekanism"; - packet.data = bytes.toByteArray(); - packet.length = packet.data.length; - PacketDispatcher.sendPacketToAllPlayers(packet); - } catch (IOException e) { - System.err.println("[Mekanism] Error while writing liquid transfer update packet."); - e.printStackTrace(); - } + sendPacketData(EnumPacketType.LIQUID_TRANSFER_UPDATE, Transmission.ALL_CLIENTS, head.xCoord, head.yCoord, head.zCoord, resource.itemID, resource.amount, resource.itemMeta); } /** @@ -1059,25 +751,7 @@ public class PacketHandler implements IPacketHandler */ public static void sendEnergyTransferUpdate(TileEntity head) { - ByteArrayOutputStream bytes = new ByteArrayOutputStream(); - DataOutputStream output = new DataOutputStream(bytes); - - try { - output.writeInt(EnumPacketType.ENERGY_TRANSFER_UPDATE.id); - - output.writeInt(head.xCoord); - output.writeInt(head.yCoord); - output.writeInt(head.zCoord); - - Packet250CustomPayload packet = new Packet250CustomPayload(); - packet.channel = "Mekanism"; - packet.data = bytes.toByteArray(); - packet.length = packet.data.length; - PacketDispatcher.sendPacketToAllPlayers(packet); - } catch (IOException e) { - System.err.println("[Mekanism] Error while writing energy transfer update packet."); - e.printStackTrace(); - } + sendPacketData(EnumPacketType.ENERGY_TRANSFER_UPDATE, Transmission.ALL_CLIENTS, head.xCoord, head.yCoord, head.zCoord); } /** @@ -1086,27 +760,7 @@ public class PacketHandler implements IPacketHandler */ public static void sendGasTransferUpdate(TileEntity head, EnumGas type) { - ByteArrayOutputStream bytes = new ByteArrayOutputStream(); - DataOutputStream output = new DataOutputStream(bytes); - - try { - output.writeInt(EnumPacketType.GAS_TRANSFER_UPDATE.id); - - output.writeInt(head.xCoord); - output.writeInt(head.yCoord); - output.writeInt(head.zCoord); - - output.writeUTF(type.name); - - Packet250CustomPayload packet = new Packet250CustomPayload(); - packet.channel = "Mekanism"; - packet.data = bytes.toByteArray(); - packet.length = packet.data.length; - PacketDispatcher.sendPacketToAllPlayers(packet); - } catch (IOException e) { - System.err.println("[Mekanism] Error while writing gas transfer update packet."); - e.printStackTrace(); - } + sendPacketData(EnumPacketType.GAS_TRANSFER_UPDATE, Transmission.ALL_CLIENTS, head.xCoord, head.yCoord, head.zCoord, type.name); } /** @@ -1115,25 +769,7 @@ public class PacketHandler implements IPacketHandler */ public static void sendElectrolyticSeparatorParticle(TileEntityElectrolyticSeparator tileEntity) { - ByteArrayOutputStream bytes = new ByteArrayOutputStream(); - DataOutputStream output = new DataOutputStream(bytes); - - try { - output.writeInt(EnumPacketType.ELECTROLYTIC_SEPARATOR_PARTICLE.id); - - output.writeInt(tileEntity.xCoord); - output.writeInt(tileEntity.yCoord); - output.writeInt(tileEntity.zCoord); - - Packet250CustomPayload packet = new Packet250CustomPayload(); - packet.channel = "Mekanism"; - packet.data = bytes.toByteArray(); - packet.length = packet.data.length; - PacketDispatcher.sendPacketToAllAround(tileEntity.xCoord, tileEntity.yCoord, tileEntity.zCoord, 40, tileEntity.worldObj.provider.dimensionId, packet); - } catch (IOException e) { - System.err.println("[Mekanism] Error while writing tile entity packet."); - e.printStackTrace(); - } + sendPacketData(EnumPacketType.ELECTROLYTIC_SEPARATOR_PARTICLE, Transmission.CLIENTS_RANGE, Object3D.get(tileEntity), 40D, tileEntity.xCoord, tileEntity.yCoord, tileEntity.zCoord); } /** @@ -1143,28 +779,7 @@ public class PacketHandler implements IPacketHandler */ public static void sendRobitGui(int type, int id) { - ByteArrayOutputStream bytes = new ByteArrayOutputStream(); - DataOutputStream data = new DataOutputStream(bytes); - - try { - data.writeInt(EnumPacketType.ROBIT_GUI.id); - data.writeInt(type); - data.writeInt(id); - } catch (IOException e) { - System.out.println("[Mekanism] An error occured while writing packet data."); - e.printStackTrace(); - } - - Packet250CustomPayload packet = new Packet250CustomPayload(); - packet.channel = "Mekanism"; - packet.data = bytes.toByteArray(); - packet.length = packet.data.length; - PacketDispatcher.sendPacketToServer(packet); - - if(Mekanism.logPackets) - { - System.out.println("[Mekanism] Sent robit GUI packet to server."); - } + sendPacketData(EnumPacketType.ROBIT, Transmission.SERVER, 0, type, id); } /** @@ -1174,58 +789,7 @@ public class PacketHandler implements IPacketHandler */ public static void sendNameUpdate(String name, int id) { - ByteArrayOutputStream bytes = new ByteArrayOutputStream(); - DataOutputStream data = new DataOutputStream(bytes); - - try { - data.writeInt(EnumPacketType.NAME_UPDATE.id); - data.writeUTF(name); - data.writeInt(id); - } catch (IOException e) { - System.out.println("[Mekanism] An error occured while writing packet data."); - e.printStackTrace(); - } - - Packet250CustomPayload packet = new Packet250CustomPayload(); - packet.channel = "Mekanism"; - packet.data = bytes.toByteArray(); - packet.length = packet.data.length; - PacketDispatcher.sendPacketToServer(packet); - - if(Mekanism.logPackets) - { - System.out.println("[Mekanism] Sentname update packet to server."); - } - } - - /** - * Sends the server the defined packet data int. - * @param type - packet type - * @param i - int to send - */ - public static void sendPacketDataInt(EnumPacketType type, int i) - { - ByteArrayOutputStream bytes = new ByteArrayOutputStream(); - DataOutputStream data = new DataOutputStream(bytes); - - try { - data.writeInt(type.id); - data.writeInt(i); - } catch (IOException e) { - System.out.println("[Mekanism] An error occured while writing packet data."); - e.printStackTrace(); - } - - Packet250CustomPayload packet = new Packet250CustomPayload(); - packet.channel = "Mekanism"; - packet.data = bytes.toByteArray(); - packet.length = packet.data.length; - PacketDispatcher.sendPacketToServer(packet); - - if(Mekanism.logPackets) - { - System.out.println("[Mekanism] Sent data int packet '" + type.id + ":" + i + "' to server"); - } + sendPacketData(EnumPacketType.ROBIT, Transmission.SERVER, 2, name, id); } /** @@ -1234,30 +798,145 @@ public class PacketHandler implements IPacketHandler * @param tileEntity */ public static void sendDataRequest(TileEntity tileEntity) + { + sendPacketData(EnumPacketType.DATA_REQUEST, Transmission.SERVER, tileEntity.xCoord, tileEntity.yCoord, tileEntity.zCoord, tileEntity.worldObj.provider.dimensionId); + } + + /** + * Sends the server the defined packet type with an undefined amount of data. + * @param type - packet type + * @param dataValues - data to send + */ + public static void sendPacketData(EnumPacketType type, Transmission trans, Object... dataValues) { ByteArrayOutputStream bytes = new ByteArrayOutputStream(); DataOutputStream data = new DataOutputStream(bytes); try { - data.writeInt(EnumPacketType.DATA_REQUEST.id); - data.writeInt(tileEntity.xCoord); - data.writeInt(tileEntity.yCoord); - data.writeInt(tileEntity.zCoord); - data.writeInt(tileEntity.worldObj.provider.dimensionId); - } catch (IOException e) { - System.out.println("[Mekanism] An error occured while writing packet data."); - e.printStackTrace(); - } + data.writeInt(type.id); + encode(dataValues, data, trans.parameters); + } catch (IOException e) { + System.out.println("[Mekanism] An error occured while writing packet data."); + e.printStackTrace(); + } Packet250CustomPayload packet = new Packet250CustomPayload(); packet.channel = "Mekanism"; packet.data = bytes.toByteArray(); packet.length = packet.data.length; - PacketDispatcher.sendPacketToServer(packet); + + switch(trans) + { + case SERVER: + PacketDispatcher.sendPacketToServer(packet); + break; + case ALL_CLIENTS: + PacketDispatcher.sendPacketToAllPlayers(packet); + break; + case CLIENTS_RANGE: + Object3D obj = (Object3D)dataValues[0]; + PacketDispatcher.sendPacketToAllAround(obj.xCoord, obj.yCoord, obj.zCoord, (Double)dataValues[1], obj.dimensionId, packet); + break; + case SINGLE_CLIENT: + ((EntityPlayerMP)dataValues[0]).playerNetServerHandler.sendPacketToPlayer(packet); + break; + } if(Mekanism.logPackets) { - System.out.println("[Mekanism] Sent data request packet to server."); + System.out.println("[Mekanism] Sent data int packet '" + type.id + "' to server"); } } + + public static void encode(Object[] dataValues, DataOutputStream output, int ignore) + { + int iterations = 0; + + try { + for(Object data : dataValues) + { + if(iterations++ < ignore) + { + continue; + } + + if(data instanceof Integer) + { + output.writeInt((Integer)data); + } + else if(data instanceof Boolean) + { + output.writeBoolean((Boolean)data); + } + else if(data instanceof Double) + { + output.writeDouble((Double)data); + } + else if(data instanceof Float) + { + output.writeFloat((Float)data); + } + else if(data instanceof String) + { + output.writeUTF((String)data); + } + else if(data instanceof Byte) + { + output.writeByte((Byte)data); + } + else if(data instanceof int[]) + { + for(int i : (int[])data) + { + output.writeInt(i); + } + } + else if(data instanceof byte[]) + { + for(byte b : (byte[])data) + { + output.writeByte(b); + } + } + else if(data instanceof ArrayList) + { + encode(((ArrayList)data).toArray(), output, 0); + } + } + } catch(Exception e) { + System.err.println("[Mekanism] Error while encoding packet data."); + e.printStackTrace(); + } + } + + public static enum Transmission + { + /** No additional parameters. */ + SERVER(0), + + /** No additional parameters. */ + ALL_CLIENTS(0), + + /** 2 parameters - Object3D representing the location of the transmission, and a double of the distance this packet can be sent in. */ + CLIENTS_RANGE(2), + + /** 1 parameter - EntityPlayer to send this packet to. */ + SINGLE_CLIENT(1); + + public int parameters; + + private Transmission(int params) + { + parameters = params; + } + } + + public static enum RobitPacket + { + GUI, + FOLLOW, + NAME, + GO_HOME, + DROP_PICKUP; + } } diff --git a/src/minecraft/mekanism/common/TileEntityElectricChest.java b/src/minecraft/mekanism/common/TileEntityElectricChest.java index 8985c24e4..a375c47c0 100644 --- a/src/minecraft/mekanism/common/TileEntityElectricChest.java +++ b/src/minecraft/mekanism/common/TileEntityElectricChest.java @@ -145,12 +145,12 @@ public class TileEntityElectricChest extends TileEntityElectricBlock { if(side == 0) { - return new int[] {1}; + return new int[] {54}; } else { int[] ret = new int[54]; - for(int i = 0; i <= 54; i++) + for(int i = 0; i <= ret.length; i++) { ret[i] = i; } diff --git a/src/minecraft/mekanism/common/TileEntityElectricPump.java b/src/minecraft/mekanism/common/TileEntityElectricPump.java index 8d65c4536..03e9aa132 100644 --- a/src/minecraft/mekanism/common/TileEntityElectricPump.java +++ b/src/minecraft/mekanism/common/TileEntityElectricPump.java @@ -51,7 +51,6 @@ public class TileEntityElectricPump extends TileEntityElectricBlock implements I @Override public void onUpdate() { - System.out.println(worldObj.isRemote + " " + (liquidTank.getLiquid() != null ? liquidTank.getLiquid().amount : "ASDF")); ChargeUtils.discharge(2, this); if(inventory[0] != null) diff --git a/src/minecraft/mekanism/generators/common/ItemBlockGenerator.java b/src/minecraft/mekanism/generators/common/ItemBlockGenerator.java index ba40e8105..4fcbddb42 100644 --- a/src/minecraft/mekanism/generators/common/ItemBlockGenerator.java +++ b/src/minecraft/mekanism/generators/common/ItemBlockGenerator.java @@ -515,4 +515,10 @@ public class ItemBlockGenerator extends ItemBlock implements IEnergizedItem, IIt { return (float)(getMaxEnergy(theItem)*Mekanism.TO_BC); } + + @Override + public boolean isMetadataSpecific() + { + return true; + } } diff --git a/src/minecraft/mekanism/nei/MekanismRecipeHandler.java b/src/minecraft/mekanism/nei/MekanismRecipeHandler.java index 7a29c6bce..4474a4357 100644 --- a/src/minecraft/mekanism/nei/MekanismRecipeHandler.java +++ b/src/minecraft/mekanism/nei/MekanismRecipeHandler.java @@ -5,9 +5,9 @@ import java.util.Collection; import java.util.List; import mekanism.api.IEnergizedItem; -import mekanism.common.MekanismRecipe; import mekanism.common.IEnergyCube; import mekanism.common.IFactory; +import mekanism.common.MekanismRecipe; import net.minecraft.item.ItemStack; import net.minecraft.item.crafting.CraftingManager; import net.minecraft.item.crafting.IRecipe; @@ -80,10 +80,14 @@ public class MekanismRecipeHandler extends ShapedRecipeHandler public static boolean areItemsEqual(ItemStack stack1, ItemStack stack2) { - if(stack1 == null || stack2 == null) + if(stack1 == null && stack2 != null || stack1 != null && stack2 == null) { return false; } + else if(stack1 == null && stack2 == null) + { + return true; + } if(stack1.itemID != stack2.itemID) { @@ -97,27 +101,32 @@ public class MekanismRecipeHandler extends ShapedRecipeHandler return false; } } - else if(stack1.getItem() instanceof IEnergyCube && stack2.getItem() instanceof IEnergyCube) - { - if(((IEnergyCube)stack1.getItem()).getEnergyCubeTier(stack1) != ((IEnergyCube)stack2.getItem()).getEnergyCubeTier(stack2)) - { - return false; - } - } - else if(stack1.getItem() instanceof IFactory && stack2.getItem() instanceof IFactory) - { - if(((IFactory)stack1.getItem()).isFactory(stack1) && ((IFactory)stack2.getItem()).isFactory(stack2)) + else { + if(((IEnergizedItem)stack1.getItem()).isMetadataSpecific() && ((IEnergizedItem)stack2.getItem()).isMetadataSpecific()) { if(stack1.getItemDamage() != stack2.getItemDamage()) { return false; } - - if(((IFactory)stack1.getItem()).getRecipeType(stack1) != ((IFactory)stack2.getItem()).getRecipeType(stack2)) - { - return false; - } } + + if(stack1.getItem() instanceof IEnergyCube && stack2.getItem() instanceof IEnergyCube) + { + if(((IEnergyCube)stack1.getItem()).getEnergyCubeTier(stack1) != ((IEnergyCube)stack2.getItem()).getEnergyCubeTier(stack2)) + { + return false; + } + } + else if(stack1.getItem() instanceof IFactory && stack2.getItem() instanceof IFactory) + { + if(((IFactory)stack1.getItem()).isFactory(stack1) && ((IFactory)stack2.getItem()).isFactory(stack2)) + { + if(((IFactory)stack1.getItem()).getRecipeType(stack1) != ((IFactory)stack2.getItem()).getRecipeType(stack2)) + { + return false; + } + } + } } return true;