From 5d26f8e229c3460a238a3dc4256b757c4ee04f5c Mon Sep 17 00:00:00 2001 From: Aidan Brady Date: Fri, 26 Jul 2013 18:16:21 -0400 Subject: [PATCH] Updated to new UE, not done with complete implementation --- .../client/GuiAdvancedElectricMachine.java | 2 +- .../mekanism/client/GuiElectricMachine.java | 2 +- common/mekanism/client/GuiElectricPump.java | 4 +- common/mekanism/client/GuiEnergyCube.java | 2 +- common/mekanism/client/GuiFactory.java | 2 +- .../client/GuiMetallurgicInfuser.java | 2 +- common/mekanism/client/GuiRobitMain.java | 4 +- common/mekanism/client/GuiTeleporter.java | 2 +- common/mekanism/common/BlockEnergyCube.java | 39 +- common/mekanism/common/BlockGasTank.java | 33 +- common/mekanism/common/BlockMachine.java | 33 +- common/mekanism/common/BlockTransmitter.java | 17 +- common/mekanism/common/CableUtils.java | 6 - common/mekanism/common/ChargeUtils.java | 4 +- .../ContainerAdvancedElectricMachine.java | 2 +- .../mekanism/common/ContainerDynamicTank.java | 29 +- .../common/ContainerElectricChest.java | 2 +- .../common/ContainerElectricMachine.java | 2 +- .../common/ContainerElectricPump.java | 4 +- .../mekanism/common/ContainerEnergyCube.java | 16 +- common/mekanism/common/ContainerFactory.java | 2 +- .../common/ContainerMetallurgicInfuser.java | 2 +- .../mekanism/common/ContainerTeleporter.java | 2 +- common/mekanism/common/EntityRobit.java | 2 +- .../common/ItemAtomicDisassembler.java | 6 - .../mekanism/common/ItemBlockEnergyCube.java | 166 +++--- common/mekanism/common/ItemBlockMachine.java | 132 +++-- common/mekanism/common/ItemConfigurator.java | 19 +- common/mekanism/common/ItemElectricBow.java | 6 - common/mekanism/common/ItemEnergized.java | 170 +++--- common/mekanism/common/ItemEnergyMeter.java | 4 +- .../common/ItemPortableTeleporter.java | 6 - common/mekanism/common/ItemRobit.java | 6 - common/mekanism/common/MekanismHooks.java | 9 +- common/mekanism/common/MekanismUtils.java | 69 ++- common/mekanism/common/SlotEnergy.java | 7 +- common/mekanism/common/Tier.java | 4 +- .../TileEntityAdvancedElectricMachine.java | 9 +- .../common/TileEntityBasicMachine.java | 12 +- .../mekanism/common/TileEntityChargepad.java | 2 +- .../common/TileEntityElectricBlock.java | 108 ++-- .../common/TileEntityElectricChest.java | 9 +- .../common/TileEntityElectricMachine.java | 10 +- .../common/TileEntityElectricPump.java | 10 +- .../mekanism/common/TileEntityEnergyCube.java | 79 ++- common/mekanism/common/TileEntityFactory.java | 10 +- .../common/TileEntityMetallurgicInfuser.java | 10 +- .../mekanism/common/TileEntityTeleporter.java | 8 +- .../network/PacketPortableTeleport.java | 2 +- .../generators/client/GuiBioGenerator.java | 4 +- .../client/GuiElectrolyticSeparator.java | 2 +- .../generators/client/GuiHeatGenerator.java | 4 +- .../client/GuiHydrogenGenerator.java | 4 +- .../generators/client/GuiSolarGenerator.java | 4 +- .../generators/client/GuiWindTurbine.java | 4 +- .../generators/common/BlockGenerator.java | 29 +- .../common/ContainerBioGenerator.java | 5 +- .../ContainerElectrolyticSeparator.java | 6 +- .../common/ContainerHeatGenerator.java | 3 +- .../common/ContainerHydrogenGenerator.java | 5 +- .../common/ContainerSolarGenerator.java | 7 +- .../common/ContainerWindTurbine.java | 5 +- .../generators/common/ItemBlockGenerator.java | 148 +++-- .../common/TileEntityBioGenerator.java | 3 +- .../TileEntityElectrolyticSeparator.java | 10 +- .../common/TileEntityGenerator.java | 47 +- .../common/TileEntityHeatGenerator.java | 7 +- .../common/TileEntityHydrogenGenerator.java | 9 +- .../common/TileEntitySolarGenerator.java | 8 +- .../tools/common/ItemMekanismArmor.java | 10 + .../mekanism/tools/common/MekanismTools.java | 4 +- .../core/UniversalElectricity.java | 52 +- .../core/block/IConductor.java | 13 +- .../core/block/IElectrical.java | 53 ++ .../core/block/IElectricalStorage.java | 24 + .../core/block/IElectricityStorage.java | 24 - ...nProvider.java => INetworkConnection.java} | 7 +- .../core/block/INetworkProvider.java | 2 +- .../core/block/IVoltage.java | 17 - .../core/electricity/ElectricalEvent.java | 61 +++ .../core/electricity/ElectricityDisplay.java | 27 +- .../core/electricity/ElectricityHelper.java | 206 +++++++ .../core/electricity/ElectricityNetwork.java | 511 ------------------ .../electricity/ElectricityNetworkHelper.java | 230 -------- .../core/electricity/ElectricityPack.java | 107 +++- .../core/electricity/IConductorRegistry.java | 17 - .../core/electricity/IElectricityNetwork.java | 138 ----- .../core/electricity/NetworkLoader.java | 64 +++ .../core/grid/ElectricityNetwork.java | 353 ++++++++++++ .../core/grid/IElectricityNetwork.java | 38 ++ .../core/grid/IGridNetwork.java | 66 +++ .../core/item/ElectricItemHelper.java | 33 +- .../core/item/IItemElectric.java | 58 +- .../core/item/IItemElectricityStorage.java | 21 - .../core/item/IItemVoltage.java | 18 - .../core/item/ItemElectric.java | 82 ++- .../core/path/PathfinderChecker.java | 4 +- .../core/vector/Vector2.java | 6 +- .../core/vector/Vector3.java | 60 +- .../core/vector/VectorHelper.java | 2 +- .../prefab/CustomDamageSource.java | 41 -- .../universalelectricity/prefab/GuiBase.java | 197 ------- .../prefab/RecipeHelper.java | 192 ------- .../prefab/SlotSpecific.java | 95 ---- .../prefab/TranslationHelper.java | 81 --- .../prefab/implement/IDisableable.java | 25 - .../prefab/implement/IRedstoneProvider.java | 16 - .../prefab/implement/IRedstoneReceptor.java | 21 - .../prefab/implement/IRotatable.java | 25 - .../prefab/implement/ITier.java | 24 - .../prefab/implement/IToolConfigurator.java | 33 -- .../prefab/multiblock/BlockMulti.java | 138 ----- .../prefab/multiblock/IBlockActivate.java | 17 - .../prefab/multiblock/IMultiBlock.java | 28 - .../prefab/multiblock/TileEntityMulti.java | 148 ----- .../prefab/network/IPacketReceiver.java | 15 - .../prefab/network/PacketManager.java | 304 ----------- .../prefab/ore/OreGenBase.java | 99 ---- .../prefab/ore/OreGenReplace.java | 153 ------ .../prefab/ore/OreGenReplaceStone.java | 17 - .../prefab/ore/OreGenerator.java | 78 --- .../prefab/potion/CustomPotion.java | 35 -- .../prefab/potion/CustomPotionEffect.java | 40 -- .../prefab/tile/TileEntityAdvanced.java | 62 --- .../prefab/tile/TileEntityConductor.java | 186 ------- .../prefab/tile/TileEntityDisableable.java | 46 -- .../prefab/tile/TileEntityElectrical.java | 38 -- .../tile/TileEntityElectricityRunnable.java | 96 ---- .../tile/TileEntityElectricityStorage.java | 110 ---- .../prefab/vector/Region2.java | 36 -- .../prefab/vector/Region3.java | 131 ----- .../{ => assets/mekanism}/armor/bronze_1.png | Bin .../{ => assets/mekanism}/armor/bronze_2.png | Bin .../mekanism}/armor/glowstone_1.png | Bin .../mekanism}/armor/glowstone_2.png | Bin .../{ => assets/mekanism}/armor/lazuli_1.png | Bin .../{ => assets/mekanism}/armor/lazuli_2.png | Bin .../mekanism}/armor/obsidian_1.png | Bin .../mekanism}/armor/obsidian_2.png | Bin .../{ => assets/mekanism}/armor/osmium_1.png | Bin .../{ => assets/mekanism}/armor/osmium_2.png | Bin .../{ => assets/mekanism}/armor/steel_1.png | Bin .../{ => assets/mekanism}/armor/steel_2.png | Bin 143 files changed, 1813 insertions(+), 4424 deletions(-) create mode 100644 common/universalelectricity/core/block/IElectrical.java create mode 100644 common/universalelectricity/core/block/IElectricalStorage.java delete mode 100644 common/universalelectricity/core/block/IElectricityStorage.java rename common/universalelectricity/core/block/{IConnectionProvider.java => INetworkConnection.java} (65%) delete mode 100644 common/universalelectricity/core/block/IVoltage.java create mode 100644 common/universalelectricity/core/electricity/ElectricalEvent.java create mode 100644 common/universalelectricity/core/electricity/ElectricityHelper.java delete mode 100644 common/universalelectricity/core/electricity/ElectricityNetwork.java delete mode 100644 common/universalelectricity/core/electricity/ElectricityNetworkHelper.java delete mode 100644 common/universalelectricity/core/electricity/IConductorRegistry.java delete mode 100644 common/universalelectricity/core/electricity/IElectricityNetwork.java create mode 100644 common/universalelectricity/core/electricity/NetworkLoader.java create mode 100644 common/universalelectricity/core/grid/ElectricityNetwork.java create mode 100644 common/universalelectricity/core/grid/IElectricityNetwork.java create mode 100644 common/universalelectricity/core/grid/IGridNetwork.java delete mode 100644 common/universalelectricity/core/item/IItemElectricityStorage.java delete mode 100644 common/universalelectricity/core/item/IItemVoltage.java delete mode 100644 common/universalelectricity/prefab/CustomDamageSource.java delete mode 100644 common/universalelectricity/prefab/GuiBase.java delete mode 100644 common/universalelectricity/prefab/RecipeHelper.java delete mode 100644 common/universalelectricity/prefab/SlotSpecific.java delete mode 100644 common/universalelectricity/prefab/TranslationHelper.java delete mode 100644 common/universalelectricity/prefab/implement/IDisableable.java delete mode 100644 common/universalelectricity/prefab/implement/IRedstoneProvider.java delete mode 100644 common/universalelectricity/prefab/implement/IRedstoneReceptor.java delete mode 100644 common/universalelectricity/prefab/implement/IRotatable.java delete mode 100644 common/universalelectricity/prefab/implement/ITier.java delete mode 100644 common/universalelectricity/prefab/implement/IToolConfigurator.java delete mode 100644 common/universalelectricity/prefab/multiblock/BlockMulti.java delete mode 100644 common/universalelectricity/prefab/multiblock/IBlockActivate.java delete mode 100644 common/universalelectricity/prefab/multiblock/IMultiBlock.java delete mode 100644 common/universalelectricity/prefab/multiblock/TileEntityMulti.java delete mode 100644 common/universalelectricity/prefab/network/IPacketReceiver.java delete mode 100644 common/universalelectricity/prefab/network/PacketManager.java delete mode 100644 common/universalelectricity/prefab/ore/OreGenBase.java delete mode 100644 common/universalelectricity/prefab/ore/OreGenReplace.java delete mode 100644 common/universalelectricity/prefab/ore/OreGenReplaceStone.java delete mode 100644 common/universalelectricity/prefab/ore/OreGenerator.java delete mode 100644 common/universalelectricity/prefab/potion/CustomPotion.java delete mode 100644 common/universalelectricity/prefab/potion/CustomPotionEffect.java delete mode 100644 common/universalelectricity/prefab/tile/TileEntityAdvanced.java delete mode 100644 common/universalelectricity/prefab/tile/TileEntityConductor.java delete mode 100644 common/universalelectricity/prefab/tile/TileEntityDisableable.java delete mode 100644 common/universalelectricity/prefab/tile/TileEntityElectrical.java delete mode 100644 common/universalelectricity/prefab/tile/TileEntityElectricityRunnable.java delete mode 100644 common/universalelectricity/prefab/tile/TileEntityElectricityStorage.java delete mode 100644 common/universalelectricity/prefab/vector/Region2.java delete mode 100644 common/universalelectricity/prefab/vector/Region3.java rename resources/{ => assets/mekanism}/armor/bronze_1.png (100%) rename resources/{ => assets/mekanism}/armor/bronze_2.png (100%) rename resources/{ => assets/mekanism}/armor/glowstone_1.png (100%) rename resources/{ => assets/mekanism}/armor/glowstone_2.png (100%) rename resources/{ => assets/mekanism}/armor/lazuli_1.png (100%) rename resources/{ => assets/mekanism}/armor/lazuli_2.png (100%) rename resources/{ => assets/mekanism}/armor/obsidian_1.png (100%) rename resources/{ => assets/mekanism}/armor/obsidian_2.png (100%) rename resources/{ => assets/mekanism}/armor/osmium_1.png (100%) rename resources/{ => assets/mekanism}/armor/osmium_2.png (100%) rename resources/{ => assets/mekanism}/armor/steel_1.png (100%) rename resources/{ => assets/mekanism}/armor/steel_2.png (100%) diff --git a/common/mekanism/client/GuiAdvancedElectricMachine.java b/common/mekanism/client/GuiAdvancedElectricMachine.java index 5b9bde74b..bb53c7f4f 100644 --- a/common/mekanism/client/GuiAdvancedElectricMachine.java +++ b/common/mekanism/client/GuiAdvancedElectricMachine.java @@ -41,7 +41,7 @@ public class GuiAdvancedElectricMachine extends GuiContainer if(xAxis >= 165 && xAxis <= 169 && yAxis >= 17 && yAxis <= 69) { - drawCreativeTabHoveringText(ElectricityDisplay.getDisplayShort(tileEntity.electricityStored, ElectricUnit.JOULES), xAxis, yAxis); + drawCreativeTabHoveringText(ElectricityDisplay.getDisplayShort((float)tileEntity.electricityStored, ElectricUnit.JOULES), xAxis, yAxis); } if(xAxis >= 179 && xAxis <= 198 && yAxis >= 47 && yAxis <= 54) diff --git a/common/mekanism/client/GuiElectricMachine.java b/common/mekanism/client/GuiElectricMachine.java index 57842978c..d3257b0c1 100644 --- a/common/mekanism/client/GuiElectricMachine.java +++ b/common/mekanism/client/GuiElectricMachine.java @@ -41,7 +41,7 @@ public class GuiElectricMachine extends GuiContainer if(xAxis >= 165 && xAxis <= 169 && yAxis >= 17 && yAxis <= 69) { - drawCreativeTabHoveringText(ElectricityDisplay.getDisplayShort(tileEntity.electricityStored, ElectricUnit.JOULES), xAxis, yAxis); + drawCreativeTabHoveringText(ElectricityDisplay.getDisplayShort((float)tileEntity.electricityStored, ElectricUnit.JOULES), xAxis, yAxis); } if(xAxis >= 179 && xAxis <= 198 && yAxis >= 47 && yAxis <= 54) diff --git a/common/mekanism/client/GuiElectricPump.java b/common/mekanism/client/GuiElectricPump.java index 082206e20..2a4162d3d 100644 --- a/common/mekanism/client/GuiElectricPump.java +++ b/common/mekanism/client/GuiElectricPump.java @@ -39,7 +39,7 @@ public class GuiElectricPump extends GuiContainer fontRenderer.drawString(tileEntity.fullName, 45, 6, 0x404040); fontRenderer.drawString("Inventory", 8, (ySize - 94) + 2, 0x404040); - fontRenderer.drawString(ElectricityDisplay.getDisplayShort(tileEntity.electricityStored, ElectricUnit.JOULES), 51, 26, 0x00CD00); + fontRenderer.drawString(ElectricityDisplay.getDisplayShort((float)tileEntity.electricityStored, ElectricUnit.JOULES), 51, 26, 0x00CD00); fontRenderer.drawString(tileEntity.fluidTank.getFluid() != null ? FluidRegistry.getFluidName(tileEntity.fluidTank.getFluid()) + ": " + tileEntity.fluidTank.getFluid().amount : "No fluid.", 51, 35, 0x00CD00); fontRenderer.drawString(tileEntity.getVoltage() + "v", 51, 44, 0x00CD00); @@ -50,7 +50,7 @@ public class GuiElectricPump extends GuiContainer if(xAxis >= 165 && xAxis <= 169 && yAxis >= 17 && yAxis <= 69) { - drawCreativeTabHoveringText(ElectricityDisplay.getDisplayShort(tileEntity.electricityStored, ElectricUnit.JOULES), xAxis, yAxis); + drawCreativeTabHoveringText(ElectricityDisplay.getDisplayShort((float)tileEntity.electricityStored, ElectricUnit.JOULES), xAxis, yAxis); } } diff --git a/common/mekanism/client/GuiEnergyCube.java b/common/mekanism/client/GuiEnergyCube.java index d599f3e59..510fc93c3 100644 --- a/common/mekanism/client/GuiEnergyCube.java +++ b/common/mekanism/client/GuiEnergyCube.java @@ -34,7 +34,7 @@ public class GuiEnergyCube extends GuiContainer @Override protected void drawGuiContainerForegroundLayer(int par1, int par2) { - String capacityInfo = ElectricityDisplay.getDisplayShort(tileEntity.electricityStored, ElectricUnit.JOULES) + "/" + ElectricityDisplay.getDisplayShort(tileEntity.tier.MAX_ELECTRICITY, ElectricUnit.JOULES); + String capacityInfo = ElectricityDisplay.getDisplayShort((float)tileEntity.electricityStored, ElectricUnit.JOULES) + "/" + ElectricityDisplay.getDisplayShort((float)tileEntity.tier.MAX_ELECTRICITY, ElectricUnit.JOULES); String outputInfo = "Voltage: " + tileEntity.getVoltage() + "v"; fontRenderer.drawString(tileEntity.tier.name + " Energy Cube", 43, 6, 0x404040); fontRenderer.drawString(capacityInfo, 45, 40, 0x00CD00); diff --git a/common/mekanism/client/GuiFactory.java b/common/mekanism/client/GuiFactory.java index 17080f611..d0fe505db 100644 --- a/common/mekanism/client/GuiFactory.java +++ b/common/mekanism/client/GuiFactory.java @@ -44,7 +44,7 @@ public class GuiFactory extends GuiContainer if(xAxis >= 165 && xAxis <= 169 && yAxis >= 17 && yAxis <= 69) { - drawCreativeTabHoveringText(ElectricityDisplay.getDisplayShort(tileEntity.electricityStored, ElectricUnit.JOULES), xAxis, yAxis); + drawCreativeTabHoveringText(ElectricityDisplay.getDisplayShort((float)tileEntity.electricityStored, ElectricUnit.JOULES), xAxis, yAxis); } if(xAxis >= 179 && xAxis <= 198 && yAxis >= 47 && yAxis <= 54) diff --git a/common/mekanism/client/GuiMetallurgicInfuser.java b/common/mekanism/client/GuiMetallurgicInfuser.java index 9e852ffee..dbefb5820 100644 --- a/common/mekanism/client/GuiMetallurgicInfuser.java +++ b/common/mekanism/client/GuiMetallurgicInfuser.java @@ -70,7 +70,7 @@ public class GuiMetallurgicInfuser extends GuiContainer if(xAxis >= 165 && xAxis <= 169 && yAxis >= 17 && yAxis <= 69) { - drawCreativeTabHoveringText(ElectricityDisplay.getDisplayShort(tileEntity.electricityStored, ElectricUnit.JOULES), xAxis, yAxis); + drawCreativeTabHoveringText(ElectricityDisplay.getDisplayShort((float)tileEntity.electricityStored, ElectricUnit.JOULES), xAxis, yAxis); } } diff --git a/common/mekanism/client/GuiRobitMain.java b/common/mekanism/client/GuiRobitMain.java index 1cd3092e9..6fd0179b7 100644 --- a/common/mekanism/client/GuiRobitMain.java +++ b/common/mekanism/client/GuiRobitMain.java @@ -112,7 +112,7 @@ public class GuiRobitMain extends GuiContainer if(!displayNameChange) { fontRenderer.drawString("Hi, I'm " + robit.getTranslatedEntityName() + "!", 29, 18, 0x00CD00); - fontRenderer.drawString("Energy: " + ElectricityDisplay.getDisplayShort(robit.getEnergy(), ElectricUnit.JOULES), 29, 36-4, 0x00CD00); + fontRenderer.drawString("Energy: " + ElectricityDisplay.getDisplayShort((float)robit.getEnergy(), ElectricUnit.JOULES), 29, 36-4, 0x00CD00); fontRenderer.drawString("Following: " + robit.getFollowing(), 29, 45-4, 0x00CD00); fontRenderer.drawString("Drop pickup: " + robit.getDropPickup(), 29, 54-4, 0x00CD00); fontRenderer.drawString("Owner: " + robit.getOwnerName(), 29, 63-4, 0x00CD00); @@ -123,7 +123,7 @@ public class GuiRobitMain extends GuiContainer if(xAxis >= 28 && xAxis <= 148 && yAxis >= 75 && yAxis <= 79) { - drawCreativeTabHoveringText(ElectricityDisplay.getDisplayShort(robit.getEnergy(), ElectricUnit.JOULES), xAxis, yAxis); + drawCreativeTabHoveringText(ElectricityDisplay.getDisplayShort((float)robit.getEnergy(), ElectricUnit.JOULES), xAxis, yAxis); } else if(xAxis >= 152 && xAxis <= 170 && yAxis >= 54 && yAxis <= 72) { diff --git a/common/mekanism/client/GuiTeleporter.java b/common/mekanism/client/GuiTeleporter.java index 4958b9c20..c1de3221e 100644 --- a/common/mekanism/client/GuiTeleporter.java +++ b/common/mekanism/client/GuiTeleporter.java @@ -45,7 +45,7 @@ public class GuiTeleporter extends GuiContainer if(xAxis >= 165 && xAxis <= 169 && yAxis >= 17 && yAxis <= 69) { - drawCreativeTabHoveringText(ElectricityDisplay.getDisplayShort(tileEntity.electricityStored, ElectricUnit.JOULES), xAxis, yAxis); + drawCreativeTabHoveringText(ElectricityDisplay.getDisplayShort((float)tileEntity.electricityStored, ElectricUnit.JOULES), xAxis, yAxis); } } diff --git a/common/mekanism/common/BlockEnergyCube.java b/common/mekanism/common/BlockEnergyCube.java index c8702bfe8..e35d9017f 100644 --- a/common/mekanism/common/BlockEnergyCube.java +++ b/common/mekanism/common/BlockEnergyCube.java @@ -20,7 +20,6 @@ import net.minecraft.util.MathHelper; import net.minecraft.util.MovingObjectPosition; import net.minecraft.world.IBlockAccess; import net.minecraft.world.World; -import universalelectricity.prefab.implement.IToolConfigurator; import buildcraft.api.tools.IToolWrench; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; @@ -169,42 +168,8 @@ public class BlockEnergyCube extends BlockContainer if(entityplayer.getCurrentEquippedItem() != null) { Item tool = entityplayer.getCurrentEquippedItem().getItem(); - if(tool instanceof IToolConfigurator) - { - if(((IToolConfigurator)tool).canWrench(entityplayer, x, y, z)) - { - ((IToolConfigurator)tool).wrenchUsed(entityplayer, x, y, z); - - int change = 0; - - switch(tileEntity.facing) - { - case 3: - change = 5; - break; - case 5: - change = 2; - break; - case 2: - change = 4; - break; - case 4: - change = 1; - break; - case 1: - change = 0; - break; - case 0: - change = 3; - break; - } - - tileEntity.setFacing((short)change); - world.notifyBlocksOfNeighborChange(x, y, z, blockID); - return true; - } - } - else if(tool instanceof IToolWrench && !tool.getUnlocalizedName().contains("omniwrench")) + + if(tool instanceof IToolWrench && !tool.getUnlocalizedName().contains("omniwrench")) { if(((IToolWrench)tool).canWrench(entityplayer, x, y, z)) { diff --git a/common/mekanism/common/BlockGasTank.java b/common/mekanism/common/BlockGasTank.java index 2d627b345..39f9ec977 100644 --- a/common/mekanism/common/BlockGasTank.java +++ b/common/mekanism/common/BlockGasTank.java @@ -16,7 +16,6 @@ import net.minecraft.util.Icon; import net.minecraft.util.MathHelper; import net.minecraft.world.IBlockAccess; import net.minecraft.world.World; -import universalelectricity.prefab.implement.IToolConfigurator; import buildcraft.api.tools.IToolWrench; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; @@ -162,36 +161,8 @@ public class BlockGasTank extends BlockContainer if(entityplayer.getCurrentEquippedItem() != null) { Item tool = entityplayer.getCurrentEquippedItem().getItem(); - if(tool instanceof IToolConfigurator) - { - if(((IToolConfigurator)tool).canWrench(entityplayer, x, y, z)) - { - ((IToolConfigurator)tool).wrenchUsed(entityplayer, x, y, z); - - int change = 0; - - switch(tileEntity.facing) - { - case 3: - change = 5; - break; - case 5: - change = 2; - break; - case 2: - change = 4; - break; - case 4: - change = 3; - break; - } - - tileEntity.setFacing((short)change); - world.notifyBlocksOfNeighborChange(x, y, z, blockID); - return true; - } - } - else if(tool instanceof IToolWrench && !tool.getUnlocalizedName().contains("omniwrench")) + + if(tool instanceof IToolWrench && !tool.getUnlocalizedName().contains("omniwrench")) { if(((IToolWrench)tool).canWrench(entityplayer, x, y, z)) { diff --git a/common/mekanism/common/BlockMachine.java b/common/mekanism/common/BlockMachine.java index 77d5159b2..51dcb2161 100644 --- a/common/mekanism/common/BlockMachine.java +++ b/common/mekanism/common/BlockMachine.java @@ -30,7 +30,6 @@ import net.minecraft.util.MovingObjectPosition; import net.minecraft.world.IBlockAccess; import net.minecraft.world.World; import net.minecraftforge.common.ForgeDirection; -import universalelectricity.prefab.implement.IToolConfigurator; import buildcraft.api.tools.IToolWrench; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; @@ -507,36 +506,8 @@ public class BlockMachine extends BlockContainer implements ISpecialBounds if(entityplayer.getCurrentEquippedItem() != null) { Item tool = entityplayer.getCurrentEquippedItem().getItem(); - if(tool instanceof IToolConfigurator) - { - if(((IToolConfigurator)tool).canWrench(entityplayer, x, y, z)) - { - ((IToolConfigurator)tool).wrenchUsed(entityplayer, x, y, z); - - int change = 0; - - switch(tileEntity.facing) - { - case 3: - change = 5; - break; - case 5: - change = 2; - break; - case 2: - change = 4; - break; - case 4: - change = 3; - break; - } - - tileEntity.setFacing((short)change); - world.notifyBlocksOfNeighborChange(x, y, z, blockID); - return true; - } - } - else if(tool instanceof IToolWrench && !tool.getUnlocalizedName().contains("omniwrench")) + + if(tool instanceof IToolWrench && !tool.getUnlocalizedName().contains("omniwrench")) { if(((IToolWrench)tool).canWrench(entityplayer, x, y, z)) { diff --git a/common/mekanism/common/BlockTransmitter.java b/common/mekanism/common/BlockTransmitter.java index 07bf31451..0d74772fb 100644 --- a/common/mekanism/common/BlockTransmitter.java +++ b/common/mekanism/common/BlockTransmitter.java @@ -3,7 +3,6 @@ package mekanism.common; import java.util.Arrays; import java.util.List; -import universalelectricity.prefab.implement.IToolConfigurator; import buildcraft.api.tools.IToolWrench; import mekanism.api.GasTransmission; @@ -340,15 +339,15 @@ public class BlockTransmitter extends Block if(entityplayer.getCurrentEquippedItem() != null) { Item tool = entityplayer.getCurrentEquippedItem().getItem(); - if((tool instanceof IToolConfigurator && ((IToolConfigurator)tool).canWrench(entityplayer, x, y, z)) - ||(tool instanceof IToolWrench && ((IToolWrench)tool).canWrench(entityplayer, x, y, z))) + + if(tool instanceof IToolWrench && ((IToolWrench)tool).canWrench(entityplayer, x, y, z)) { - if(entityplayer.isSneaking()) - { - dismantleBlock(world, x, y, z, false); - } - - return true; + if(entityplayer.isSneaking()) + { + dismantleBlock(world, x, y, z, false); + } + + return true; } } diff --git a/common/mekanism/common/CableUtils.java b/common/mekanism/common/CableUtils.java index 331bdc07c..2c4f55396 100644 --- a/common/mekanism/common/CableUtils.java +++ b/common/mekanism/common/CableUtils.java @@ -14,7 +14,6 @@ import mekanism.api.IStrictEnergyAcceptor; import mekanism.api.Object3D; import net.minecraft.tileentity.TileEntity; import net.minecraftforge.common.ForgeDirection; -import universalelectricity.core.block.IConnectionProvider; import buildcraft.api.power.IPowerReceptor; public final class CableUtils @@ -146,11 +145,6 @@ public final class CableUtils return true; } - if(tileEntity instanceof IConnectionProvider && ((IConnectionProvider)tileEntity).canConnect(side.getOpposite())) - { - return true; - } - if(tileEntity instanceof IEnergyAcceptor && ((IEnergyAcceptor)tileEntity).acceptsEnergyFrom(tile, MekanismUtils.toIC2Direction(side).getInverse())) { return true; diff --git a/common/mekanism/common/ChargeUtils.java b/common/mekanism/common/ChargeUtils.java index 0b1194e18..6e200f3ee 100644 --- a/common/mekanism/common/ChargeUtils.java +++ b/common/mekanism/common/ChargeUtils.java @@ -27,7 +27,7 @@ public final class ChargeUtils } else if(storer.inventory[slotID].getItem() instanceof IItemElectric) { - storer.setEnergy(storer.getEnergy() + ElectricItemHelper.dechargeItem(storer.inventory[slotID], storer.getMaxEnergy() - storer.getEnergy(), storer.getVoltage())); + storer.setEnergy(storer.getEnergy() + ElectricItemHelper.dischargeItem(storer.inventory[slotID], (float)(storer.getMaxEnergy() - storer.getEnergy()))); } else if(Mekanism.hooks.IC2Loaded && storer.inventory[slotID].getItem() instanceof IElectricItem) { @@ -78,7 +78,7 @@ public final class ChargeUtils } else if(storer.inventory[slotID].getItem() instanceof IItemElectric) { - storer.setEnergy(storer.getEnergy() - ElectricItemHelper.chargeItem(storer.inventory[slotID], storer.getEnergy(), storer.getVoltage())); + storer.setEnergy(storer.getEnergy() - ElectricItemHelper.chargeItem(storer.inventory[slotID], (float)storer.getEnergy())); } else if(Mekanism.hooks.IC2Loaded && storer.inventory[slotID].getItem() instanceof IElectricItem) { diff --git a/common/mekanism/common/ContainerAdvancedElectricMachine.java b/common/mekanism/common/ContainerAdvancedElectricMachine.java index dd1e0a708..e28ca6f80 100644 --- a/common/mekanism/common/ContainerAdvancedElectricMachine.java +++ b/common/mekanism/common/ContainerAdvancedElectricMachine.java @@ -90,7 +90,7 @@ public class ContainerAdvancedElectricMachine extends Container } } } - else if((slotStack.getItem() instanceof IElectricItem && ((IElectricItem)slotStack.getItem()).canProvideEnergy(slotStack)) || (slotStack.getItem() instanceof IItemElectric && ((IItemElectric)slotStack.getItem()).getProvideRequest(slotStack).amperes != 0) || slotStack.itemID == Item.redstone.itemID) + else if(MekanismUtils.canBeDischarged(slotStack)) { if(slotID != 0 && slotID != 1 && slotID != 2 && slotID != 3) { diff --git a/common/mekanism/common/ContainerDynamicTank.java b/common/mekanism/common/ContainerDynamicTank.java index deec1a0f1..c851ef4b3 100644 --- a/common/mekanism/common/ContainerDynamicTank.java +++ b/common/mekanism/common/ContainerDynamicTank.java @@ -63,24 +63,7 @@ public class ContainerDynamicTank extends Container ItemStack slotStack = currentSlot.getStack(); stack = slotStack.copy(); - if((slotStack.getItem() instanceof IElectricItem && ((IElectricItem)slotStack.getItem()).canProvideEnergy(slotStack)) || (slotStack.getItem() instanceof IItemElectric && ((IItemElectric)slotStack.getItem()).getProvideRequest(slotStack).amperes != 0) || slotStack.itemID == Item.redstone.itemID) - { - if(slotID != 2) - { - if (!mergeItemStack(slotStack, 2, 3, false)) - { - return null; - } - } - else if(slotID == 2) - { - if(!mergeItemStack(slotStack, 3, inventorySlots.size(), true)) - { - return null; - } - } - } - else if(FluidContainerRegistry.isEmptyContainer(slotStack) || FluidContainerRegistry.isFilledContainer(slotStack)) + if(FluidContainerRegistry.isEmptyContainer(slotStack) || FluidContainerRegistry.isFilledContainer(slotStack)) { if(slotID != 0 && slotID != 1) { @@ -90,29 +73,29 @@ public class ContainerDynamicTank extends Container } } else { - if(!mergeItemStack(slotStack, 3, inventorySlots.size(), true)) + if(!mergeItemStack(slotStack, 2, inventorySlots.size(), true)) { return null; } } } else { - if(slotID >= 3 && slotID <= 29) + if(slotID >= 2 && slotID <= 8) { - if(!mergeItemStack(slotStack, 30, inventorySlots.size(), false)) + if(!mergeItemStack(slotStack, 29, inventorySlots.size(), false)) { return null; } } else if(slotID > 28) { - if(!mergeItemStack(slotStack, 3, 29, false)) + if(!mergeItemStack(slotStack, 2, 28, false)) { return null; } } else { - if(!mergeItemStack(slotStack, 3, inventorySlots.size(), true)) + if(!mergeItemStack(slotStack, 2, inventorySlots.size(), true)) { return null; } diff --git a/common/mekanism/common/ContainerElectricChest.java b/common/mekanism/common/ContainerElectricChest.java index f409f668c..500fc6c5b 100644 --- a/common/mekanism/common/ContainerElectricChest.java +++ b/common/mekanism/common/ContainerElectricChest.java @@ -106,7 +106,7 @@ public class ContainerElectricChest extends Container ItemStack slotStack = currentSlot.getStack(); stack = slotStack.copy(); - if((slotStack.getItem() instanceof IElectricItem && ((IElectricItem)slotStack.getItem()).canProvideEnergy(slotStack)) || (slotStack.getItem() instanceof IItemElectric && ((IItemElectric)slotStack.getItem()).getProvideRequest(slotStack).amperes != 0) || slotStack.itemID == Item.redstone.itemID) + if(MekanismUtils.canBeDischarged(slotStack)) { if(slotID != 54) { diff --git a/common/mekanism/common/ContainerElectricMachine.java b/common/mekanism/common/ContainerElectricMachine.java index 66289536b..ebc6e1488 100644 --- a/common/mekanism/common/ContainerElectricMachine.java +++ b/common/mekanism/common/ContainerElectricMachine.java @@ -72,7 +72,7 @@ public class ContainerElectricMachine extends Container return null; } } - else if((slotStack.getItem() instanceof IElectricItem && ((IElectricItem)slotStack.getItem()).canProvideEnergy(slotStack)) || (slotStack.getItem() instanceof IItemElectric && ((IItemElectric)slotStack.getItem()).getProvideRequest(slotStack).amperes != 0) || slotStack.itemID == Item.redstone.itemID) + else if(MekanismUtils.canBeDischarged(slotStack)) { if(slotID != 1) { diff --git a/common/mekanism/common/ContainerElectricPump.java b/common/mekanism/common/ContainerElectricPump.java index 1415f4bbc..17bab4f0a 100644 --- a/common/mekanism/common/ContainerElectricPump.java +++ b/common/mekanism/common/ContainerElectricPump.java @@ -65,11 +65,11 @@ public class ContainerElectricPump extends Container ItemStack slotStack = currentSlot.getStack(); stack = slotStack.copy(); - if((slotStack.getItem() instanceof IElectricItem && ((IElectricItem)slotStack.getItem()).canProvideEnergy(slotStack)) || (slotStack.getItem() instanceof IItemElectric && ((IItemElectric)slotStack.getItem()).getProvideRequest(slotStack).amperes != 0) || slotStack.itemID == Item.redstone.itemID) + if(MekanismUtils.canBeDischarged(slotStack)) { if(slotID != 2) { - if (!mergeItemStack(slotStack, 2, 3, false)) + if(!mergeItemStack(slotStack, 2, 3, false)) { return null; } diff --git a/common/mekanism/common/ContainerEnergyCube.java b/common/mekanism/common/ContainerEnergyCube.java index 19380556c..c814bd12e 100644 --- a/common/mekanism/common/ContainerEnergyCube.java +++ b/common/mekanism/common/ContainerEnergyCube.java @@ -86,11 +86,11 @@ public class ContainerEnergyCube extends Container else { if(slotID != 1 && slotID != 0) { - if((slotStack.getItem() instanceof IElectricItem && ((IElectricItem)slotStack.getItem()).canProvideEnergy(slotStack)) || (slotStack.getItem() instanceof IItemElectric && ((IItemElectric)slotStack.getItem()).getProvideRequest(slotStack).amperes != 0) || slotStack.itemID == Item.redstone.itemID) + if(MekanismUtils.canBeDischarged(slotStack)) { if(!mergeItemStack(slotStack, 1, 2, false)) { - if((slotStack.getItem() instanceof IItemElectric && ((IItemElectric)slotStack.getItem()).getReceiveRequest(slotStack).amperes != 0) || (slotStack.getItem() instanceof IElectricItem && (!(slotStack.getItem() instanceof IItemElectric) || ((IItemElectric)slotStack.getItem()).getProvideRequest(slotStack).amperes == 0))) + if(canTransfer(slotStack)) { if(!mergeItemStack(slotStack, 0, 1, false)) { @@ -99,7 +99,7 @@ public class ContainerEnergyCube extends Container } } } - else if((slotStack.getItem() instanceof IItemElectric && ((IItemElectric)slotStack.getItem()).getReceiveRequest(slotStack).amperes != 0) || (slotStack.getItem() instanceof IElectricItem && (!(slotStack.getItem() instanceof IItemElectric) || ((IItemElectric)slotStack.getItem()).getProvideRequest(slotStack).amperes == 0))) + else if(canTransfer(slotStack)) { if(!mergeItemStack(slotStack, 0, 1, false)) { @@ -109,7 +109,7 @@ public class ContainerEnergyCube extends Container } else if(slotID == 1) { - if((slotStack.getItem() instanceof IItemElectric && ((IItemElectric)slotStack.getItem()).getReceiveRequest(slotStack).amperes != 0) || (slotStack.getItem() instanceof IElectricItem && (!(slotStack.getItem() instanceof IItemElectric) || ((IItemElectric)slotStack.getItem()).getProvideRequest(slotStack).amperes == 0))) + if(canTransfer(slotStack)) { if(!mergeItemStack(slotStack, 0, 1, false)) { @@ -176,4 +176,12 @@ public class ContainerEnergyCube extends Container return stack; } + + private boolean canTransfer(ItemStack slotStack) + { + return (slotStack.getItem() instanceof IItemElectric && + ((IItemElectric)slotStack.getItem()).recharge(slotStack, 1, false) != 0) || + (slotStack.getItem() instanceof IElectricItem && (!(slotStack.getItem() instanceof IItemElectric) || + ((IItemElectric)slotStack.getItem()).discharge(slotStack, 1, false) == 0)); + } } diff --git a/common/mekanism/common/ContainerFactory.java b/common/mekanism/common/ContainerFactory.java index c5b1e73a7..08f7712d2 100644 --- a/common/mekanism/common/ContainerFactory.java +++ b/common/mekanism/common/ContainerFactory.java @@ -140,7 +140,7 @@ public class ContainerFactory extends Container return null; } } - else if((slotStack.getItem() instanceof IElectricItem && ((IElectricItem)slotStack.getItem()).canProvideEnergy(slotStack)) || (slotStack.getItem() instanceof IItemElectric && ((IItemElectric)slotStack.getItem()).getProvideRequest(slotStack).amperes != 0) || slotStack.itemID == Item.redstone.itemID) + else if(MekanismUtils.canBeDischarged(slotStack)) { if(slotID != 1) { diff --git a/common/mekanism/common/ContainerMetallurgicInfuser.java b/common/mekanism/common/ContainerMetallurgicInfuser.java index b252dab8e..8dec0079e 100644 --- a/common/mekanism/common/ContainerMetallurgicInfuser.java +++ b/common/mekanism/common/ContainerMetallurgicInfuser.java @@ -85,7 +85,7 @@ public class ContainerMetallurgicInfuser extends Container return null; } } - else if((slotStack.getItem() instanceof IElectricItem && ((IElectricItem)slotStack.getItem()).canProvideEnergy(slotStack)) || (slotStack.getItem() instanceof IItemElectric && ((IItemElectric)slotStack.getItem()).getProvideRequest(slotStack).amperes != 0) || slotStack.itemID == Item.redstone.itemID) + else if(MekanismUtils.canBeDischarged(slotStack)) { if(!mergeItemStack(slotStack, 4, 5, false)) { diff --git a/common/mekanism/common/ContainerTeleporter.java b/common/mekanism/common/ContainerTeleporter.java index 68c9ca2b1..8effb5aad 100644 --- a/common/mekanism/common/ContainerTeleporter.java +++ b/common/mekanism/common/ContainerTeleporter.java @@ -62,7 +62,7 @@ public class ContainerTeleporter extends Container ItemStack slotStack = currentSlot.getStack(); stack = slotStack.copy(); - if((slotStack.getItem() instanceof IElectricItem && ((IElectricItem)slotStack.getItem()).canProvideEnergy(slotStack)) || (slotStack.getItem() instanceof IItemElectric && ((IItemElectric)slotStack.getItem()).getProvideRequest(slotStack).amperes != 0) || slotStack.itemID == Item.redstone.itemID) + if(MekanismUtils.canBeDischarged(slotStack)) { if(slotID != 0) { diff --git a/common/mekanism/common/EntityRobit.java b/common/mekanism/common/EntityRobit.java index 850c93bc7..d4ed0e500 100644 --- a/common/mekanism/common/EntityRobit.java +++ b/common/mekanism/common/EntityRobit.java @@ -161,7 +161,7 @@ public class EntityRobit extends EntityCreature implements IInventory, ISustaine } else if(inventory[27].getItem() instanceof IItemElectric) { - setEnergy(getEnergy() + ElectricItemHelper.dechargeItem(inventory[27], MAX_ELECTRICITY - getEnergy(), 120/*VOLTAGE*/)); + setEnergy(getEnergy() + ElectricItemHelper.dischargeItem(inventory[27], (float)(MAX_ELECTRICITY - getEnergy()))); } else if(Mekanism.hooks.IC2Loaded && inventory[27].getItem() instanceof IElectricItem) { diff --git a/common/mekanism/common/ItemAtomicDisassembler.java b/common/mekanism/common/ItemAtomicDisassembler.java index 971d3c60e..c2a9ec66c 100644 --- a/common/mekanism/common/ItemAtomicDisassembler.java +++ b/common/mekanism/common/ItemAtomicDisassembler.java @@ -73,12 +73,6 @@ public class ItemAtomicDisassembler extends ItemEnergized return true; } - @Override - public ElectricityPack getProvideRequest(ItemStack itemStack) - { - return new ElectricityPack(); - } - @Override public ItemStack onItemRightClick(ItemStack itemstack, World world, EntityPlayer entityplayer) { diff --git a/common/mekanism/common/ItemBlockEnergyCube.java b/common/mekanism/common/ItemBlockEnergyCube.java index d279b6479..5d0963ed9 100644 --- a/common/mekanism/common/ItemBlockEnergyCube.java +++ b/common/mekanism/common/ItemBlockEnergyCube.java @@ -52,7 +52,7 @@ public class ItemBlockEnergyCube extends ItemBlock implements IEnergizedItem, II list.add("Hold " + EnumColor.AQUA + "shift" + EnumColor.GREY + " for more details."); } else { - list.add(EnumColor.BRIGHT_GREEN + "Stored Energy: " + EnumColor.GREY + ElectricityDisplay.getDisplayShort(getJoules(itemstack), ElectricUnit.JOULES)); + list.add(EnumColor.BRIGHT_GREEN + "Stored Energy: " + EnumColor.GREY + ElectricityDisplay.getDisplayShort((float)getEnergy(itemstack), ElectricUnit.JOULES)); list.add(EnumColor.BRIGHT_GREEN + "Voltage: " + EnumColor.GREY + getVoltage(itemstack) + "v"); list.add(EnumColor.AQUA + "Inventory: " + EnumColor.GREY + (getInventory(itemstack) != null && getInventory(itemstack).tagCount() != 0)); } @@ -67,62 +67,10 @@ public class ItemBlockEnergyCube extends ItemBlock implements IEnergizedItem, II } @Override - public double getJoules(ItemStack itemStack) - { - return getEnergy(itemStack); - } - - @Override - public void setJoules(double wattHours, ItemStack itemStack) - { - setEnergy(itemStack, wattHours); - } - - @Override - public double getMaxJoules(ItemStack itemStack) - { - return getMaxEnergy(itemStack); - } - - @Override - public double getVoltage(ItemStack itemStack) + public float getVoltage(ItemStack itemStack) { return getEnergyCubeTier(itemStack).VOLTAGE; } - - @Override - public ElectricityPack onReceive(ElectricityPack electricityPack, ItemStack itemStack) - { - double rejectedElectricity = Math.max((getJoules(itemStack) + electricityPack.getWatts()) - getMaxJoules(itemStack), 0); - double joulesToStore = electricityPack.getWatts() - rejectedElectricity; - setJoules(getJoules(itemStack) + joulesToStore, itemStack); - return ElectricityPack.getFromWatts(joulesToStore, getVoltage(itemStack)); - } - - @Override - public ElectricityPack onProvide(ElectricityPack electricityPack, ItemStack itemStack) - { - double electricityToUse = Math.min(getJoules(itemStack), electricityPack.getWatts()); - setJoules(getJoules(itemStack) - electricityToUse, itemStack); - return ElectricityPack.getFromWatts(electricityToUse, getVoltage(itemStack)); - } - - @Override - public ElectricityPack getReceiveRequest(ItemStack itemStack) - { - return ElectricityPack.getFromWatts(Math.min(getMaxJoules(itemStack) - getJoules(itemStack), getTransferRate(itemStack)), getVoltage(itemStack)); - } - - @Override - public ElectricityPack getProvideRequest(ItemStack itemStack) - { - return ElectricityPack.getFromWatts(Math.min(getJoules(itemStack), getTransferRate(itemStack)), getVoltage(itemStack)); - } - - public double getTransferRate(ItemStack itemStack) - { - return getMaxTransfer(itemStack); - } @Override public String getUnlocalizedName(ItemStack itemstack) @@ -139,7 +87,7 @@ public class ItemBlockEnergyCube extends ItemBlock implements IEnergizedItem, II { TileEntityEnergyCube tileEntity = (TileEntityEnergyCube)world.getBlockTileEntity(x, y, z); tileEntity.tier = ((IEnergyCube)stack.getItem()).getEnergyCubeTier(stack); - tileEntity.electricityStored = getJoules(stack); + tileEntity.electricityStored = getEnergy(stack); ((ISustainedInventory)tileEntity).setInventory(getInventory(stack)); @@ -187,35 +135,45 @@ public class ItemBlockEnergyCube extends ItemBlock implements IEnergizedItem, II @Override public int charge(ItemStack itemStack, int amount, int tier, boolean ignoreTransferLimit, boolean simulate) { - double energyNeeded = getMaxEnergy(itemStack)-getEnergy(itemStack); - double energyToStore = Math.min(Math.min(amount*Mekanism.FROM_IC2, getMaxEnergy(itemStack)*0.01), energyNeeded); - - if(!simulate) + if(canReceive(itemStack)) { - setEnergy(itemStack, getEnergy(itemStack) + energyToStore); + double energyNeeded = getMaxEnergy(itemStack)-getEnergy(itemStack); + double energyToStore = Math.min(Math.min(amount*Mekanism.FROM_IC2, getMaxEnergy(itemStack)*0.01), energyNeeded); + + if(!simulate) + { + setEnergy(itemStack, getEnergy(itemStack) + energyToStore); + } + + return (int)(energyToStore*Mekanism.TO_IC2); } - return (int)(energyToStore*Mekanism.TO_IC2); + return 0; } @Override public int discharge(ItemStack itemStack, int amount, int tier, boolean ignoreTransferLimit, boolean simulate) { - double energyWanted = amount*Mekanism.FROM_IC2; - double energyToGive = Math.min(Math.min(energyWanted, getMaxEnergy(itemStack)*0.01), getJoules(itemStack)); - - if(!simulate) + if(canSend(itemStack)) { - setJoules(getJoules(itemStack) - energyToGive, itemStack); + double energyWanted = amount*Mekanism.FROM_IC2; + double energyToGive = Math.min(Math.min(energyWanted, getMaxEnergy(itemStack)*0.01), getEnergy(itemStack)); + + if(!simulate) + { + setEnergy(itemStack, getEnergy(itemStack) - energyToGive); + } + + return (int)(energyToGive*Mekanism.TO_IC2); } - return (int)(energyToGive*Mekanism.TO_IC2); + return 0; } @Override public boolean canUse(ItemStack itemStack, int amount) { - return getJoules(itemStack) >= amount*Mekanism.FROM_IC2; + return getEnergy(itemStack) >= amount*Mekanism.FROM_IC2; } @Override @@ -316,7 +274,7 @@ public class ItemBlockEnergyCube extends ItemBlock implements IEnergizedItem, II itemStack.setTagCompound(new NBTTagCompound()); } - double electricityStored = Math.max(Math.min(amount, getMaxJoules(itemStack)), 0); + double electricityStored = Math.max(Math.min(amount, getMaxEnergy(itemStack)), 0); itemStack.stackTagCompound.setDouble("electricity", electricityStored); itemStack.setItemDamage((int)Math.max(1, (Math.abs(((electricityStored/getMaxEnergy(itemStack))*100)-100)))); } @@ -348,29 +306,39 @@ public class ItemBlockEnergyCube extends ItemBlock implements IEnergizedItem, II @Override public float receiveEnergy(ItemStack theItem, float energy, boolean doReceive) { - double energyNeeded = getMaxEnergy(theItem)-getEnergy(theItem); - double toReceive = Math.min(energy*Mekanism.FROM_BC, energyNeeded); - - if(doReceive) + if(canReceive(theItem)) { - setEnergy(theItem, getEnergy(theItem) + toReceive); + double energyNeeded = getMaxEnergy(theItem)-getEnergy(theItem); + double toReceive = Math.min(energy*Mekanism.FROM_BC, energyNeeded); + + if(doReceive) + { + setEnergy(theItem, getEnergy(theItem) + toReceive); + } + + return (float)(toReceive*Mekanism.TO_BC); } - return (float)(toReceive*Mekanism.TO_BC); + return 0; } @Override public float transferEnergy(ItemStack theItem, float energy, boolean doTransfer) { - double energyRemaining = getEnergy(theItem); - double toSend = Math.min(energy*Mekanism.FROM_BC, energyRemaining); - - if(doTransfer) + if(canSend(theItem)) { - setEnergy(theItem, getEnergy(theItem) - toSend); + double energyRemaining = getEnergy(theItem); + double toSend = Math.min(energy*Mekanism.FROM_BC, energyRemaining); + + if(doTransfer) + { + setEnergy(theItem, getEnergy(theItem) - toSend); + } + + return (float)(toSend*Mekanism.TO_BC); } - return (float)(toSend*Mekanism.TO_BC); + return 0; } @Override @@ -390,4 +358,40 @@ public class ItemBlockEnergyCube extends ItemBlock implements IEnergizedItem, II { return false; } + + @Override + public float recharge(ItemStack itemStack, float energy, boolean doRecharge) + { + return receiveEnergy(itemStack, energy, doRecharge); + } + + @Override + public float discharge(ItemStack itemStack, float energy, boolean doDischarge) + { + return transferEnergy(itemStack, energy, doDischarge); + } + + @Override + public float getElectricityStored(ItemStack theItem) + { + return (float)getEnergy(theItem); + } + + @Override + public float getMaxElectricityStored(ItemStack theItem) + { + return (float)getMaxEnergy(theItem); + } + + @Override + public void setElectricity(ItemStack itemStack, float joules) + { + setEnergy(itemStack, joules); + } + + @Override + public float getTransfer(ItemStack itemStack) + { + return (float)getMaxTransfer(itemStack); + } } diff --git a/common/mekanism/common/ItemBlockMachine.java b/common/mekanism/common/ItemBlockMachine.java index 72e2f6d93..3c5712368 100644 --- a/common/mekanism/common/ItemBlockMachine.java +++ b/common/mekanism/common/ItemBlockMachine.java @@ -151,7 +151,7 @@ public class ItemBlockMachine extends ItemBlock implements IEnergizedItem, IItem list.add(EnumColor.INDIGO + "Locked: " + EnumColor.GREY + getLocked(itemstack)); } - list.add(EnumColor.BRIGHT_GREEN + "Stored Energy: " + EnumColor.GREY + ElectricityDisplay.getDisplayShort(getJoules(itemstack), ElectricUnit.JOULES)); + list.add(EnumColor.BRIGHT_GREEN + "Stored Energy: " + EnumColor.GREY + ElectricityDisplay.getDisplayShort((float)getEnergy(itemstack), ElectricUnit.JOULES)); list.add(EnumColor.BRIGHT_GREEN + "Voltage: " + EnumColor.GREY + getVoltage(itemstack) + "v"); if(hasTank(itemstack)) @@ -176,60 +176,10 @@ public class ItemBlockMachine extends ItemBlock implements IEnergizedItem, IItem } @Override - public double getJoules(ItemStack itemStack) - { - return getEnergy(itemStack); - } - - @Override - public void setJoules(double wattHours, ItemStack itemStack) - { - setEnergy(itemStack, wattHours); - } - - @Override - public double getMaxJoules(ItemStack itemStack) - { - return getMaxEnergy(itemStack); - } - - @Override - public double getVoltage(ItemStack itemStack) + public float getVoltage(ItemStack itemStack) { return 120; } - - @Override - public ElectricityPack onReceive(ElectricityPack electricityPack, ItemStack itemStack) - { - double rejectedElectricity = Math.max((getJoules(itemStack) + electricityPack.getWatts()) - getMaxJoules(itemStack), 0); - double joulesToStore = electricityPack.getWatts() - rejectedElectricity; - this.setJoules(getJoules(itemStack) + joulesToStore, itemStack); - return ElectricityPack.getFromWatts(joulesToStore, getVoltage(itemStack)); - } - - @Override - public ElectricityPack onProvide(ElectricityPack electricityPack, ItemStack itemStack) - { - return new ElectricityPack(); - } - - @Override - public ElectricityPack getReceiveRequest(ItemStack itemStack) - { - return ElectricityPack.getFromWatts(Math.min(getMaxJoules(itemStack) - getJoules(itemStack), getTransferRate(itemStack)), getVoltage(itemStack)); - } - - @Override - public ElectricityPack getProvideRequest(ItemStack itemStack) - { - return new ElectricityPack(); - } - - public double getTransferRate(ItemStack itemStack) - { - return getMaxTransfer(itemStack); - } @Override public boolean placeBlockAt(ItemStack stack, EntityPlayer player, World world, int x, int y, int z, int side, float hitX, float hitY, float hitZ, int metadata) @@ -268,7 +218,7 @@ public class ItemBlockMachine extends ItemBlock implements IEnergizedItem, IItem ((ISustainedInventory)tileEntity).setInventory(getInventory(stack)); - tileEntity.electricityStored = getJoules(stack); + tileEntity.electricityStored = getEnergy(stack); } return place; @@ -277,15 +227,20 @@ public class ItemBlockMachine extends ItemBlock implements IEnergizedItem, IItem @Override public int charge(ItemStack itemStack, int amount, int tier, boolean ignoreTransferLimit, boolean simulate) { - double energyNeeded = getMaxEnergy(itemStack)-getEnergy(itemStack); - double energyToStore = Math.min(Math.min(amount*Mekanism.FROM_IC2, getMaxEnergy(itemStack)*0.01), energyNeeded); - - if(!simulate) + if(canReceive(itemStack)) { - setEnergy(itemStack, getEnergy(itemStack) + energyToStore); + double energyNeeded = getMaxEnergy(itemStack)-getEnergy(itemStack); + double energyToStore = Math.min(Math.min(amount*Mekanism.FROM_IC2, getMaxEnergy(itemStack)*0.01), energyNeeded); + + if(!simulate) + { + setEnergy(itemStack, getEnergy(itemStack) + energyToStore); + } + + return (int)(energyToStore*Mekanism.TO_IC2); } - return (int)(energyToStore*Mekanism.TO_IC2); + return 0; } @Override @@ -297,7 +252,7 @@ public class ItemBlockMachine extends ItemBlock implements IEnergizedItem, IItem @Override public boolean canUse(ItemStack itemStack, int amount) { - return getJoules(itemStack) >= amount*Mekanism.FROM_IC2; + return getEnergy(itemStack) >= amount*Mekanism.FROM_IC2; } @Override @@ -477,7 +432,7 @@ public class ItemBlockMachine extends ItemBlock implements IEnergizedItem, IItem { PacketHandler.sendPacket(Transmission.SINGLE_CLIENT, new PacketElectricChest().setParams(ElectricChestPacketType.CLIENT_OPEN, 2, 0, false), entityplayer); } - else if(getLocked(itemstack) && getJoules(itemstack) > 0) + else if(getLocked(itemstack) && getEnergy(itemstack) > 0) { PacketHandler.sendPacket(Transmission.SINGLE_CLIENT, new PacketElectricChest().setParams(ElectricChestPacketType.CLIENT_OPEN, 1, 0, false), entityplayer); } @@ -758,7 +713,7 @@ public class ItemBlockMachine extends ItemBlock implements IEnergizedItem, IItem itemStack.setTagCompound(new NBTTagCompound()); } - double electricityStored = Math.max(Math.min(amount, getMaxJoules(itemStack)), 0); + double electricityStored = Math.max(Math.min(amount, getMaxEnergy(itemStack)), 0); itemStack.stackTagCompound.setDouble("electricity", electricityStored); } @@ -789,15 +744,20 @@ public class ItemBlockMachine extends ItemBlock implements IEnergizedItem, IItem @Override public float receiveEnergy(ItemStack theItem, float energy, boolean doReceive) { - double energyNeeded = getMaxEnergy(theItem)-getEnergy(theItem); - double toReceive = Math.min(energy*Mekanism.FROM_BC, energyNeeded); - - if(doReceive) + if(canReceive(theItem)) { - setEnergy(theItem, getEnergy(theItem) + toReceive); + double energyNeeded = getMaxEnergy(theItem)-getEnergy(theItem); + double toReceive = Math.min(energy*Mekanism.FROM_BC, energyNeeded); + + if(doReceive) + { + setEnergy(theItem, getEnergy(theItem) + toReceive); + } + + return (float)(toReceive*Mekanism.TO_BC); } - return (float)(toReceive*Mekanism.TO_BC); + return 0; } @Override @@ -823,4 +783,40 @@ public class ItemBlockMachine extends ItemBlock implements IEnergizedItem, IItem { return true; } + + @Override + public float recharge(ItemStack itemStack, float energy, boolean doRecharge) + { + return receiveEnergy(itemStack, energy, doRecharge); + } + + @Override + public float discharge(ItemStack itemStack, float energy, boolean doDischarge) + { + return transferEnergy(itemStack, energy, doDischarge); + } + + @Override + public float getElectricityStored(ItemStack theItem) + { + return (float)getEnergy(theItem); + } + + @Override + public float getMaxElectricityStored(ItemStack theItem) + { + return (float)getMaxEnergy(theItem); + } + + @Override + public void setElectricity(ItemStack itemStack, float joules) + { + setEnergy(itemStack, joules); + } + + @Override + public float getTransfer(ItemStack itemStack) + { + return (float)getMaxTransfer(itemStack); + } } diff --git a/common/mekanism/common/ItemConfigurator.java b/common/mekanism/common/ItemConfigurator.java index ec78524c6..d9e507fd7 100644 --- a/common/mekanism/common/ItemConfigurator.java +++ b/common/mekanism/common/ItemConfigurator.java @@ -99,13 +99,17 @@ public class ItemConfigurator extends ItemEnergized if(!(tileEntity instanceof TileEntityElectricChest) || (((TileEntityElectricChest)tileEntity).canAccess())) { - for(int i = 0; i < tileEntity.getSizeInventory(); ++i) + for(int i = 0; i < tileEntity.getSizeInventory(); i++) { ItemStack slotStack = tileEntity.getStackInSlot(i); - itemAmount += slotStack != null ? slotStack.stackSize : 0; if(slotStack != null) { + if(getEnergy(stack) < ENERGY_PER_ITEM_DUMP) + { + break; + } + float xRandom = random.nextFloat() * 0.8F + 0.1F; float yRandom = random.nextFloat() * 0.8F + 0.1F; float zRandom = random.nextFloat() * 0.8F + 0.1F; @@ -132,12 +136,13 @@ public class ItemConfigurator extends ItemEnergized item.motionY = random.nextGaussian() * k + 0.2F; item.motionZ = random.nextGaussian() * k; world.spawnEntityInWorld(item); + + tileEntity.inventory[i] = null; + setEnergy(stack, getEnergy(stack) - ENERGY_PER_ITEM_DUMP); } } } - tileEntity.inventory = new ItemStack[tileEntity.getSizeInventory()]; - onProvide(new ElectricityPack((ENERGY_PER_ITEM_DUMP*itemAmount)/120, 120), stack); return true; } else { @@ -233,12 +238,6 @@ public class ItemConfigurator extends ItemEnergized return state; } - - @Override - public ElectricityPack getProvideRequest(ItemStack itemStack) - { - return new ElectricityPack(); - } @Override public boolean canSend(ItemStack itemStack) diff --git a/common/mekanism/common/ItemElectricBow.java b/common/mekanism/common/ItemElectricBow.java index eeb575a9f..c3355a845 100644 --- a/common/mekanism/common/ItemElectricBow.java +++ b/common/mekanism/common/ItemElectricBow.java @@ -141,12 +141,6 @@ public class ItemElectricBow extends ItemEnergized return state; } - - @Override - public ElectricityPack getProvideRequest(ItemStack itemStack) - { - return new ElectricityPack(); - } @Override public boolean canSend(ItemStack itemStack) diff --git a/common/mekanism/common/ItemEnergized.java b/common/mekanism/common/ItemEnergized.java index 9ed344ec7..0d6dda513 100644 --- a/common/mekanism/common/ItemEnergized.java +++ b/common/mekanism/common/ItemEnergized.java @@ -23,9 +23,9 @@ public class ItemEnergized extends ItemMekanism implements IEnergizedItem, IItem public double MAX_ELECTRICITY; /** How fast this item can transfer energy. */ - public double VOLTAGE; + public float VOLTAGE; - public ItemEnergized(int id, double maxElectricity, double voltage) + public ItemEnergized(int id, double maxElectricity, float voltage) { super(id); MAX_ELECTRICITY = maxElectricity; @@ -39,7 +39,7 @@ public class ItemEnergized extends ItemMekanism implements IEnergizedItem, IItem @Override public void addInformation(ItemStack itemstack, EntityPlayer entityplayer, List list, boolean flag) { - list.add(EnumColor.AQUA + "Stored Energy: " + EnumColor.GREY + ElectricityDisplay.getDisplayShort(getJoules(itemstack), ElectricUnit.JOULES)); + list.add(EnumColor.AQUA + "Stored Energy: " + EnumColor.GREY + ElectricityDisplay.getDisplayShort((float)getEnergy(itemstack), ElectricUnit.JOULES)); list.add(EnumColor.AQUA + "Voltage: " + EnumColor.GREY + getVoltage(itemstack) + "v"); } @@ -63,100 +63,58 @@ public class ItemEnergized extends ItemMekanism implements IEnergizedItem, IItem discharged.setItemDamage(100); list.add(discharged); ItemStack charged = new ItemStack(this); - setJoules(((IItemElectric)charged.getItem()).getMaxJoules(charged), charged); + setEnergy(charged, ((IEnergizedItem)charged.getItem()).getMaxEnergy(charged)); list.add(charged); } @Override - public double getJoules(ItemStack itemStack) - { - return getEnergy(itemStack); - } - - @Override - public void setJoules(double wattHours, ItemStack itemStack) - { - setEnergy(itemStack, wattHours); - } - - @Override - public double getMaxJoules(ItemStack itemStack) - { - return getMaxEnergy(itemStack); - } - - @Override - public double getVoltage(ItemStack itemStack) + public float getVoltage(ItemStack itemStack) { return VOLTAGE; } - - @Override - public ElectricityPack onReceive(ElectricityPack electricityPack, ItemStack itemStack) - { - double rejectedElectricity = Math.max((getJoules(itemStack) + electricityPack.getWatts()) - getMaxJoules(itemStack), 0); - double joulesToStore = electricityPack.getWatts() - rejectedElectricity; - this.setJoules(getJoules(itemStack) + joulesToStore, itemStack); - return ElectricityPack.getFromWatts(joulesToStore, getVoltage(itemStack)); - } - - @Override - public ElectricityPack onProvide(ElectricityPack electricityPack, ItemStack itemStack) - { - double electricityToUse = Math.min(getJoules(itemStack), electricityPack.getWatts()); - setJoules(getJoules(itemStack) - electricityToUse, itemStack); - return ElectricityPack.getFromWatts(electricityToUse, getVoltage(itemStack)); - } - - @Override - public ElectricityPack getReceiveRequest(ItemStack itemStack) - { - return ElectricityPack.getFromWatts(Math.min(getMaxJoules(itemStack) - getJoules(itemStack), getTransferRate(itemStack)), getVoltage(itemStack)); - } - - @Override - public ElectricityPack getProvideRequest(ItemStack itemStack) - { - return ElectricityPack.getFromWatts(Math.min(getJoules(itemStack), getTransferRate(itemStack)), getVoltage(itemStack)); - } - - public double getTransferRate(ItemStack itemStack) - { - return getMaxTransfer(itemStack); - } @Override public int charge(ItemStack itemStack, int amount, int tier, boolean ignoreTransferLimit, boolean simulate) { - double energyNeeded = getMaxEnergy(itemStack)-getEnergy(itemStack); - double energyToStore = Math.min(Math.min(amount*Mekanism.FROM_IC2, getMaxEnergy(itemStack)*0.01), energyNeeded); - - if(!simulate) + if(canReceive(itemStack)) { - setEnergy(itemStack, getEnergy(itemStack) + energyToStore); + double energyNeeded = getMaxEnergy(itemStack)-getEnergy(itemStack); + double energyToStore = Math.min(Math.min(amount*Mekanism.FROM_IC2, getMaxEnergy(itemStack)*0.01), energyNeeded); + + if(!simulate) + { + setEnergy(itemStack, getEnergy(itemStack) + energyToStore); + } + + return (int)(energyToStore*Mekanism.TO_IC2); } - return (int)(energyToStore*Mekanism.TO_IC2); + return 0; } @Override public int discharge(ItemStack itemStack, int amount, int tier, boolean ignoreTransferLimit, boolean simulate) { - double energyWanted = amount*Mekanism.FROM_IC2; - double energyToGive = Math.min(Math.min(energyWanted, getMaxEnergy(itemStack)*0.01), getJoules(itemStack)); - - if(!simulate) + if(canSend(itemStack)) { - setJoules(getJoules(itemStack) - energyToGive, itemStack); + double energyWanted = amount*Mekanism.FROM_IC2; + double energyToGive = Math.min(Math.min(energyWanted, getMaxEnergy(itemStack)*0.01), getEnergy(itemStack)); + + if(!simulate) + { + setEnergy(itemStack, getEnergy(itemStack) - energyToGive); + } + + return (int)(energyToGive*Mekanism.TO_IC2); } - return (int)(energyToGive*Mekanism.TO_IC2); + return 0; } @Override public boolean canUse(ItemStack itemStack, int amount) { - return getJoules(itemStack) >= amount*Mekanism.FROM_IC2; + return getEnergy(itemStack) >= amount*Mekanism.FROM_IC2; } @Override @@ -223,7 +181,7 @@ public class ItemEnergized extends ItemMekanism implements IEnergizedItem, IItem itemStack.setTagCompound(new NBTTagCompound()); } - double electricityStored = Math.max(Math.min(amount, getMaxJoules(itemStack)), 0); + double electricityStored = Math.max(Math.min(amount, getMaxEnergy(itemStack)), 0); itemStack.stackTagCompound.setDouble("electricity", electricityStored); itemStack.setItemDamage((int)Math.max(1, (Math.abs(((electricityStored/getMaxEnergy(itemStack))*100)-100)))); } @@ -255,29 +213,39 @@ public class ItemEnergized extends ItemMekanism implements IEnergizedItem, IItem @Override public float receiveEnergy(ItemStack theItem, float energy, boolean doReceive) { - double energyNeeded = getMaxEnergy(theItem)-getEnergy(theItem); - double toReceive = Math.min(energy*Mekanism.FROM_BC, energyNeeded); - - if(doReceive) + if(canReceive(theItem)) { - setEnergy(theItem, getEnergy(theItem) + toReceive); + double energyNeeded = getMaxEnergy(theItem)-getEnergy(theItem); + double toReceive = Math.min(energy*Mekanism.FROM_BC, energyNeeded); + + if(doReceive) + { + setEnergy(theItem, getEnergy(theItem) + toReceive); + } + + return (float)(toReceive*Mekanism.TO_BC); } - return (float)(toReceive*Mekanism.TO_BC); + return 0; } @Override public float transferEnergy(ItemStack theItem, float energy, boolean doTransfer) { - double energyRemaining = getEnergy(theItem); - double toSend = Math.min(energy*Mekanism.FROM_BC, energyRemaining); - - if(doTransfer) + if(canSend(theItem)) { - setEnergy(theItem, getEnergy(theItem) - toSend); + double energyRemaining = getEnergy(theItem); + double toSend = Math.min(energy*Mekanism.FROM_BC, energyRemaining); + + if(doTransfer) + { + setEnergy(theItem, getEnergy(theItem) - toSend); + } + + return (float)(toSend*Mekanism.TO_BC); } - return (float)(toSend*Mekanism.TO_BC); + return 0; } @Override @@ -297,4 +265,40 @@ public class ItemEnergized extends ItemMekanism implements IEnergizedItem, IItem { return false; } + + @Override + public float recharge(ItemStack itemStack, float energy, boolean doRecharge) + { + return receiveEnergy(itemStack, energy, doRecharge); + } + + @Override + public float discharge(ItemStack itemStack, float energy, boolean doDischarge) + { + return transferEnergy(itemStack, energy, doDischarge); + } + + @Override + public float getElectricityStored(ItemStack theItem) + { + return (float)getEnergy(theItem); + } + + @Override + public float getMaxElectricityStored(ItemStack theItem) + { + return (float)getMaxEnergy(theItem); + } + + @Override + public void setElectricity(ItemStack itemStack, float joules) + { + setEnergy(itemStack, joules); + } + + @Override + public float getTransfer(ItemStack itemStack) + { + return (float)getMaxTransfer(itemStack); + } } diff --git a/common/mekanism/common/ItemEnergyMeter.java b/common/mekanism/common/ItemEnergyMeter.java index 3ec63476a..7cc9713bb 100644 --- a/common/mekanism/common/ItemEnergyMeter.java +++ b/common/mekanism/common/ItemEnergyMeter.java @@ -39,8 +39,8 @@ public class ItemEnergyMeter extends ItemEnergized player.sendChatToPlayer(ChatMessageComponent.func_111066_d(EnumColor.GREY + "------------- " + EnumColor.DARK_BLUE + "[Mekanism]" + EnumColor.GREY + " -------------")); player.sendChatToPlayer(ChatMessageComponent.func_111066_d(EnumColor.GREY + " *Cables: " + EnumColor.DARK_GREY + cable.getNetwork().cables.size())); player.sendChatToPlayer(ChatMessageComponent.func_111066_d(EnumColor.GREY + " *Acceptors: " + EnumColor.DARK_GREY + cable.getNetwork().possibleAcceptors.size())); - player.sendChatToPlayer(ChatMessageComponent.func_111066_d(EnumColor.GREY + " *Needed energy: " + EnumColor.DARK_GREY + ElectricityDisplay.getDisplay(cable.getNetwork().getEnergyNeeded(new ArrayList()), ElectricUnit.JOULES))); - player.sendChatToPlayer(ChatMessageComponent.func_111066_d(EnumColor.GREY + " *Power: " + EnumColor.DARK_GREY + ElectricityDisplay.getDisplay(cable.getNetwork().getPower(), ElectricUnit.WATT))); + player.sendChatToPlayer(ChatMessageComponent.func_111066_d(EnumColor.GREY + " *Needed energy: " + EnumColor.DARK_GREY + ElectricityDisplay.getDisplay((float)cable.getNetwork().getEnergyNeeded(new ArrayList()), ElectricUnit.JOULES))); + player.sendChatToPlayer(ChatMessageComponent.func_111066_d(EnumColor.GREY + " *Power: " + EnumColor.DARK_GREY + ElectricityDisplay.getDisplay((float)cable.getNetwork().getPower(), ElectricUnit.WATT))); player.sendChatToPlayer(ChatMessageComponent.func_111066_d(EnumColor.GREY + "------------- " + EnumColor.DARK_BLUE + "[=======]" + EnumColor.GREY + " -------------")); } } diff --git a/common/mekanism/common/ItemPortableTeleporter.java b/common/mekanism/common/ItemPortableTeleporter.java index 77fc0d859..6542d303f 100644 --- a/common/mekanism/common/ItemPortableTeleporter.java +++ b/common/mekanism/common/ItemPortableTeleporter.java @@ -103,12 +103,6 @@ public class ItemPortableTeleporter extends ItemEnergized itemstack.stackTagCompound.setInteger("digit"+index, digit); } - @Override - public ElectricityPack getProvideRequest(ItemStack itemStack) - { - return new ElectricityPack(); - } - @Override public boolean canSend(ItemStack itemStack) { diff --git a/common/mekanism/common/ItemRobit.java b/common/mekanism/common/ItemRobit.java index de4b38bc7..3fc0fdbfa 100644 --- a/common/mekanism/common/ItemRobit.java +++ b/common/mekanism/common/ItemRobit.java @@ -25,12 +25,6 @@ public class ItemRobit extends ItemEnergized implements ISustainedInventory @SideOnly(Side.CLIENT) public void registerIcons(IconRegister register) {} - @Override - public ElectricityPack getProvideRequest(ItemStack itemStack) - { - return new ElectricityPack(); - } - @Override @SideOnly(Side.CLIENT) public void addInformation(ItemStack itemstack, EntityPlayer entityplayer, List list, boolean flag) diff --git a/common/mekanism/common/MekanismHooks.java b/common/mekanism/common/MekanismHooks.java index ca7243c4c..abaebe8c4 100644 --- a/common/mekanism/common/MekanismHooks.java +++ b/common/mekanism/common/MekanismHooks.java @@ -10,7 +10,6 @@ import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import thermalexpansion.api.crafting.CraftingManagers; import thermalexpansion.api.crafting.IPulverizerRecipe; -import universalelectricity.prefab.RecipeHelper; import cpw.mods.fml.common.Loader; /** @@ -97,14 +96,14 @@ public final class MekanismHooks { if(Mekanism.disableBCSteelCrafting) { - RecipeHelper.removeRecipes(getBasicComponentsItem("itemSteelDust")); - RecipeHelper.removeRecipes(getBasicComponentsItem("itemSteelIngot")); + MekanismUtils.removeRecipes(getBasicComponentsItem("itemSteelDust")); + MekanismUtils.removeRecipes(getBasicComponentsItem("itemSteelIngot")); } if(Mekanism.disableBCBronzeCrafting) { - RecipeHelper.removeRecipes(getBasicComponentsItem("itemBronzeDust")); - RecipeHelper.removeRecipes(getBasicComponentsItem("itemBronzeIngot")); + MekanismUtils.removeRecipes(getBasicComponentsItem("itemBronzeDust")); + MekanismUtils.removeRecipes(getBasicComponentsItem("itemBronzeIngot")); } System.out.println("[Mekanism] Hooked into BasicComponents successfully."); diff --git a/common/mekanism/common/MekanismUtils.java b/common/mekanism/common/MekanismUtils.java index 995ec3a68..b8624005e 100644 --- a/common/mekanism/common/MekanismUtils.java +++ b/common/mekanism/common/MekanismUtils.java @@ -1,6 +1,7 @@ package mekanism.common; import ic2.api.Direction; +import ic2.api.item.IElectricItem; import java.io.BufferedReader; import java.io.IOException; @@ -9,6 +10,7 @@ import java.lang.reflect.Field; import java.net.HttpURLConnection; import java.net.URL; import java.util.ArrayList; +import java.util.Iterator; import mekanism.api.EnumColor; import mekanism.api.IConfigurable; @@ -23,8 +25,10 @@ import net.minecraft.block.Block; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.inventory.IInventory; +import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.item.crafting.CraftingManager; +import net.minecraft.item.crafting.IRecipe; import net.minecraft.network.packet.Packet3Chat; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.ResourceLocation; @@ -38,6 +42,7 @@ import net.minecraftforge.fluids.FluidStack; import net.minecraftforge.fluids.IFluidBlock; import net.minecraftforge.oredict.OreDictionary; import net.minecraftforge.oredict.ShapedOreRecipe; +import universalelectricity.core.item.IItemElectric; import cpw.mods.fml.common.network.PacketDispatcher; import cpw.mods.fml.server.FMLServerHandler; @@ -632,11 +637,11 @@ public final class MekanismUtils if((id == Block.waterStill.blockID || id == Block.waterMoving.blockID) && meta == 0) { - return new FluidStack(Block.waterStill.blockID, FluidContainerRegistry.BUCKET_VOLUME); + return new FluidStack(FluidRegistry.WATER, FluidContainerRegistry.BUCKET_VOLUME); } else if((id == Block.lavaStill.blockID || id == Block.lavaMoving.blockID) && meta == 0) { - return new FluidStack(Block.lavaStill.blockID, FluidContainerRegistry.BUCKET_VOLUME); + return new FluidStack(FluidRegistry.LAVA, FluidContainerRegistry.BUCKET_VOLUME); } else if(Block.blocksList[id] instanceof IFluidBlock) { @@ -867,6 +872,66 @@ public final class MekanismUtils return new ResourceLocation("mekanism", type.getPrefix() + name); } + public static boolean canBeDischarged(ItemStack itemstack) + { + return (itemstack.getItem() instanceof IElectricItem && ((IElectricItem)itemstack.getItem()).canProvideEnergy(itemstack)) || + (itemstack.getItem() instanceof IItemElectric && ((IItemElectric)itemstack.getItem()).discharge(itemstack, 1, false) != 0) || + itemstack.itemID == Item.redstone.itemID; + } + + public static boolean canBeCharged(ItemStack itemstack) + { + return itemstack.getItem() instanceof IElectricItem || + (itemstack.getItem() instanceof IItemElectric && ((IItemElectric)itemstack.getItem()).recharge(itemstack, 1, false) != 0); + } + + public static boolean canBeOutputted(ItemStack itemstack, boolean chargeSlot) + { + if(chargeSlot) + { + return (itemstack.getItem() instanceof IItemElectric && ((IItemElectric)itemstack.getItem()).recharge(itemstack, 1, false) == 0) || + (itemstack.getItem() instanceof IElectricItem && (!(itemstack.getItem() instanceof IItemElectric) || + ((IItemElectric)itemstack.getItem()).recharge(itemstack, 1, false) == 0)); + } + else { + return (itemstack.getItem() instanceof IItemElectric && ((IItemElectric)itemstack.getItem()).discharge(itemstack, 1, false) == 0) || + (itemstack.getItem() instanceof IElectricItem && ((IElectricItem)itemstack.getItem()).canProvideEnergy(itemstack) && + (!(itemstack.getItem() instanceof IItemElectric) || + ((IItemElectric)itemstack.getItem()).discharge(itemstack, 1, false) == 0)); + } + } + + public static boolean removeRecipes(ItemStack... itemStacks) + { + boolean didRemove = false; + + for(Iterator itr = CraftingManager.getInstance().getRecipeList().iterator(); itr.hasNext();) + { + Object obj = itr.next(); + + if(obj != null) + { + if(obj instanceof IRecipe) + { + if(((IRecipe)obj).getRecipeOutput() != null) + { + for(ItemStack itemStack : itemStacks) + { + if(((IRecipe)obj).getRecipeOutput().isItemEqual(itemStack)) + { + itr.remove(); + didRemove = true; + break; + } + } + } + } + } + } + + return didRemove; + } + public static enum ResourceType { GUI("gui"), diff --git a/common/mekanism/common/SlotEnergy.java b/common/mekanism/common/SlotEnergy.java index 95deb20ed..3b4cd74ed 100644 --- a/common/mekanism/common/SlotEnergy.java +++ b/common/mekanism/common/SlotEnergy.java @@ -19,8 +19,7 @@ public class SlotEnergy @Override public boolean isItemValid(ItemStack itemstack) { - return (itemstack.getItem() instanceof IItemElectric && ((IItemElectric)itemstack.getItem()).getReceiveRequest(itemstack).amperes != 0) || - itemstack.getItem() instanceof IElectricItem; + return MekanismUtils.canBeCharged(itemstack); } } @@ -34,9 +33,7 @@ public class SlotEnergy @Override public boolean isItemValid(ItemStack itemstack) { - return (itemstack.getItem() instanceof IElectricItem && ((IElectricItem)itemstack.getItem()).canProvideEnergy(itemstack)) || - (itemstack.getItem() instanceof IItemElectric && ((IItemElectric)itemstack.getItem()).getProvideRequest(itemstack).amperes != 0) || - itemstack.itemID == Item.redstone.itemID; + return MekanismUtils.canBeDischarged(itemstack); } } } diff --git a/common/mekanism/common/Tier.java b/common/mekanism/common/Tier.java index 45bd5b30c..cfd344741 100644 --- a/common/mekanism/common/Tier.java +++ b/common/mekanism/common/Tier.java @@ -22,7 +22,7 @@ public final class Tier ULTIMATE("Ultimate", 128000000, 480, 51200); public double MAX_ELECTRICITY; - public double VOLTAGE; + public float VOLTAGE; public double OUTPUT; public String name; @@ -40,7 +40,7 @@ public final class Tier return BASIC; } - private EnergyCubeTier(String s, double maxEnergy, double voltage, int out) + private EnergyCubeTier(String s, double maxEnergy, float voltage, int out) { name = s; MAX_ELECTRICITY = maxEnergy; diff --git a/common/mekanism/common/TileEntityAdvancedElectricMachine.java b/common/mekanism/common/TileEntityAdvancedElectricMachine.java index e4bfb15d3..eb9c89808 100644 --- a/common/mekanism/common/TileEntityAdvancedElectricMachine.java +++ b/common/mekanism/common/TileEntityAdvancedElectricMachine.java @@ -203,9 +203,7 @@ public abstract class TileEntityAdvancedElectricMachine extends TileEntityBasicM } else if(slotID == 3) { - return (itemstack.getItem() instanceof IElectricItem && ((IElectricItem)itemstack.getItem()).canProvideEnergy(itemstack)) || - (itemstack.getItem() instanceof IItemElectric && ((IItemElectric)itemstack.getItem()).getProvideRequest(itemstack).amperes != 0) || - itemstack.itemID == Item.redstone.itemID; + return MekanismUtils.canBeDischarged(itemstack); } else if(slotID == 1) { @@ -319,10 +317,7 @@ public abstract class TileEntityAdvancedElectricMachine extends TileEntityBasicM { if(slotID == 3) { - return (itemstack.getItem() instanceof IItemElectric && ((IItemElectric)itemstack.getItem()).getProvideRequest(itemstack).getWatts() == 0) || - (itemstack.getItem() instanceof IElectricItem && ((IElectricItem)itemstack.getItem()).canProvideEnergy(itemstack) && - (!(itemstack.getItem() instanceof IItemElectric) || - ((IItemElectric)itemstack.getItem()).getProvideRequest(itemstack).getWatts() == 0)); + return MekanismUtils.canBeOutputted(itemstack, false); } else if(slotID == 2) { diff --git a/common/mekanism/common/TileEntityBasicMachine.java b/common/mekanism/common/TileEntityBasicMachine.java index 44ced88c2..763aadb82 100644 --- a/common/mekanism/common/TileEntityBasicMachine.java +++ b/common/mekanism/common/TileEntityBasicMachine.java @@ -175,12 +175,6 @@ public abstract class TileEntityBasicMachine extends TileEntityElectricBlock imp } } - @Override - public int getMaxSafeInput() - { - return 2048; - } - @Override public int demandsEnergy() { @@ -323,6 +317,12 @@ public abstract class TileEntityBasicMachine extends TileEntityElectricBlock imp return (int)Math.min(((MekanismUtils.getEnergy(energyMultiplier, MAX_ELECTRICITY)-electricityStored)*Mekanism.TO_BC), 100); } + @Override + public int getMaxSafeInput() + { + return 2048; + } + @Override public ArrayList getSideData() { diff --git a/common/mekanism/common/TileEntityChargepad.java b/common/mekanism/common/TileEntityChargepad.java index cbe10eb9a..b2c9abf92 100644 --- a/common/mekanism/common/TileEntityChargepad.java +++ b/common/mekanism/common/TileEntityChargepad.java @@ -130,7 +130,7 @@ public class TileEntityChargepad extends TileEntityElectricBlock implements IAct } else if(itemstack.getItem() instanceof IItemElectric) { - setEnergy(getEnergy() - ElectricItemHelper.chargeItem(itemstack, getEnergy(), getVoltage())); + setEnergy(getEnergy() - ElectricItemHelper.chargeItem(itemstack, (float)getEnergy())); } else if(Mekanism.hooks.IC2Loaded && itemstack.getItem() instanceof IElectricItem) { diff --git a/common/mekanism/common/TileEntityElectricBlock.java b/common/mekanism/common/TileEntityElectricBlock.java index 9be174308..f0bdb8958 100644 --- a/common/mekanism/common/TileEntityElectricBlock.java +++ b/common/mekanism/common/TileEntityElectricBlock.java @@ -13,16 +13,15 @@ import net.minecraft.nbt.NBTTagCompound; import net.minecraftforge.common.ForgeDirection; import net.minecraftforge.common.MinecraftForge; import universalelectricity.core.block.IConnector; -import universalelectricity.core.block.IElectricityStorage; -import universalelectricity.core.block.IVoltage; -import universalelectricity.core.electricity.ElectricityNetworkHelper; +import universalelectricity.core.block.IElectrical; +import universalelectricity.core.block.IElectricalStorage; import universalelectricity.core.electricity.ElectricityPack; import buildcraft.api.power.IPowerProvider; import buildcraft.api.power.IPowerReceptor; import com.google.common.io.ByteArrayDataInput; -public abstract class TileEntityElectricBlock extends TileEntityContainerBlock implements IWrenchable, ITileNetwork, IPowerReceptor, IEnergyTile, IElectricityStorage, IVoltage, IConnector, IStrictEnergyStorage +public abstract class TileEntityElectricBlock extends TileEntityContainerBlock implements IWrenchable, ITileNetwork, IPowerReceptor, IEnergyTile, IElectrical, IElectricalStorage, IConnector, IStrictEnergyStorage { /** How much energy is stored in this block. */ public double electricityStored; @@ -60,12 +59,6 @@ public abstract class TileEntityElectricBlock extends TileEntityContainerBlock i initialized = true; } - - if(!worldObj.isRemote) - { - ElectricityPack electricityPack = ElectricityNetworkHelper.consumeFromMultipleSides(this, getConsumingSides(), getRequest()); - setEnergy(getEnergy()+electricityPack.getWatts()); - } } protected EnumSet getConsumingSides() @@ -73,15 +66,15 @@ public abstract class TileEntityElectricBlock extends TileEntityContainerBlock i return EnumSet.allOf(ForgeDirection.class); } + protected EnumSet getOutputtingSides() + { + return EnumSet.noneOf(ForgeDirection.class); + } + @Override public boolean canConnect(ForgeDirection direction) { - return true; - } - - public ElectricityPack getRequest() - { - return new ElectricityPack((getMaxEnergy() - getEnergy()) / getVoltage(), getVoltage()); + return getConsumingSides().contains(direction) || getOutputtingSides().contains(direction); } @Override @@ -103,25 +96,7 @@ public abstract class TileEntityElectricBlock extends TileEntityContainerBlock i } @Override - public double getMaxJoules() - { - return getMaxEnergy(); - } - - @Override - public double getJoules() - { - return getEnergy(); - } - - @Override - public void setJoules(double joules) - { - setEnergy(joules); - } - - @Override - public double getVoltage() + public float getVoltage() { return 120; } @@ -144,8 +119,6 @@ public abstract class TileEntityElectricBlock extends TileEntityContainerBlock i @Override public void invalidate() { - ElectricityNetworkHelper.invalidate(this); - if(initialized && !worldObj.isRemote) { if(Mekanism.hooks.IC2Loaded) @@ -191,9 +164,68 @@ public abstract class TileEntityElectricBlock extends TileEntityContainerBlock i @Override public int powerRequest(ForgeDirection side) { - return (int)Math.min(((MAX_ELECTRICITY-electricityStored)*Mekanism.TO_BC), 100); + return (int)Math.min(((getMaxEnergy()-getEnergy())*Mekanism.TO_BC), 100); } @Override public void doWork() {} + + @Override + public float receiveElectricity(ForgeDirection from, ElectricityPack receive, boolean doReceive) + { + if(getConsumingSides().contains(from)) + { + float toAdd = (float)Math.min(getMaxEnergy()-getEnergy(), receive.getWatts()); + + if(doReceive) + { + setEnergy(getEnergy() + toAdd); + } + + return toAdd; + } + + return 0; + } + + @Override + public ElectricityPack provideElectricity(ForgeDirection from, ElectricityPack request, boolean doProvide) + { + return null; + } + + @Override + public float getRequest(ForgeDirection direction) + { + if(getConsumingSides().contains(direction)) + { + return (float)(getMaxEnergy()-getEnergy()); + } + + return 0; + } + + @Override + public float getProvide(ForgeDirection direction) + { + return 0; + } + + @Override + public void setEnergyStored(float energy) + { + setEnergy(energy); + } + + @Override + public float getEnergyStored() + { + return (float)getEnergy(); + } + + @Override + public float getMaxEnergyStored() + { + return (float)getMaxEnergy(); + } } diff --git a/common/mekanism/common/TileEntityElectricChest.java b/common/mekanism/common/TileEntityElectricChest.java index 94b82c614..651e5a152 100644 --- a/common/mekanism/common/TileEntityElectricChest.java +++ b/common/mekanism/common/TileEntityElectricChest.java @@ -126,9 +126,7 @@ public class TileEntityElectricChest extends TileEntityElectricBlock { if(slotID == 54) { - return (itemstack.getItem() instanceof IElectricItem && ((IElectricItem)itemstack.getItem()).canProvideEnergy(itemstack)) || - (itemstack.getItem() instanceof IItemElectric && ((IItemElectric)itemstack.getItem()).getProvideRequest(itemstack).amperes != 0) || - itemstack.itemID == Item.redstone.itemID; + return MekanismUtils.canBeDischarged(itemstack); } else { return true; @@ -164,10 +162,7 @@ public class TileEntityElectricChest extends TileEntityElectricBlock { if(slotID == 54) { - return (itemstack.getItem() instanceof IItemElectric && ((IItemElectric)itemstack.getItem()).getProvideRequest(itemstack).getWatts() == 0) || - (itemstack.getItem() instanceof IElectricItem && ((IElectricItem)itemstack.getItem()).canProvideEnergy(itemstack) && - (!(itemstack.getItem() instanceof IItemElectric) || - ((IItemElectric)itemstack.getItem()).getProvideRequest(itemstack).getWatts() == 0)); + return MekanismUtils.canBeOutputted(itemstack, false); } else { return true; diff --git a/common/mekanism/common/TileEntityElectricMachine.java b/common/mekanism/common/TileEntityElectricMachine.java index 0cd11e0be..71ac57c65 100644 --- a/common/mekanism/common/TileEntityElectricMachine.java +++ b/common/mekanism/common/TileEntityElectricMachine.java @@ -142,10 +142,9 @@ public abstract class TileEntityElectricMachine extends TileEntityBasicMachine } else if(slotID == 1) { - return (itemstack.getItem() instanceof IElectricItem && ((IElectricItem)itemstack.getItem()).canProvideEnergy(itemstack)) || - (itemstack.getItem() instanceof IItemElectric && ((IItemElectric)itemstack.getItem()).getProvideRequest(itemstack).amperes != 0) || - itemstack.itemID == Item.redstone.itemID; + return MekanismUtils.canBeDischarged(itemstack); } + return true; } @@ -202,10 +201,7 @@ public abstract class TileEntityElectricMachine extends TileEntityBasicMachine { if(slotID == 1) { - return (itemstack.getItem() instanceof IItemElectric && ((IItemElectric)itemstack.getItem()).getProvideRequest(itemstack).getWatts() == 0) || - (itemstack.getItem() instanceof IElectricItem && ((IElectricItem)itemstack.getItem()).canProvideEnergy(itemstack) && - (!(itemstack.getItem() instanceof IItemElectric) || - ((IItemElectric)itemstack.getItem()).getProvideRequest(itemstack).getWatts() == 0)); + return MekanismUtils.canBeOutputted(itemstack, false); } else if(slotID == 2) { diff --git a/common/mekanism/common/TileEntityElectricPump.java b/common/mekanism/common/TileEntityElectricPump.java index 4ed5245c9..c30463985 100644 --- a/common/mekanism/common/TileEntityElectricPump.java +++ b/common/mekanism/common/TileEntityElectricPump.java @@ -402,10 +402,9 @@ public class TileEntityElectricPump extends TileEntityElectricBlock implements I } else if(slotID == 2) { - return (itemstack.getItem() instanceof IElectricItem && ((IElectricItem)itemstack.getItem()).canProvideEnergy(itemstack)) || - (itemstack.getItem() instanceof IItemElectric && ((IItemElectric)itemstack.getItem()).getProvideRequest(itemstack).amperes != 0) || - itemstack.itemID == Item.redstone.itemID; + return MekanismUtils.canBeDischarged(itemstack); } + return true; } @@ -414,10 +413,7 @@ public class TileEntityElectricPump extends TileEntityElectricBlock implements I { if(slotID == 2) { - return (itemstack.getItem() instanceof IItemElectric && ((IItemElectric)itemstack.getItem()).getProvideRequest(itemstack).getWatts() == 0) || - (itemstack.getItem() instanceof IElectricItem && ((IElectricItem)itemstack.getItem()).canProvideEnergy(itemstack) && - (!(itemstack.getItem() instanceof IItemElectric) || - ((IItemElectric)itemstack.getItem()).getProvideRequest(itemstack).getWatts() == 0)); + return MekanismUtils.canBeOutputted(itemstack, false); } else if(slotID == 1) { diff --git a/common/mekanism/common/TileEntityEnergyCube.java b/common/mekanism/common/TileEntityEnergyCube.java index d22d37cc3..9c0c78dda 100644 --- a/common/mekanism/common/TileEntityEnergyCube.java +++ b/common/mekanism/common/TileEntityEnergyCube.java @@ -6,7 +6,6 @@ import ic2.api.energy.tile.IEnergyAcceptor; import ic2.api.energy.tile.IEnergyConductor; import ic2.api.energy.tile.IEnergySink; import ic2.api.energy.tile.IEnergySource; -import ic2.api.item.IElectricItem; import ic2.api.tile.IEnergyStorage; import java.util.ArrayList; @@ -17,7 +16,6 @@ import mekanism.api.ICableOutputter; import mekanism.api.IStrictEnergyAcceptor; import mekanism.api.Object3D; import mekanism.common.Tier.EnergyCubeTier; -import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.tileentity.TileEntity; @@ -25,11 +23,10 @@ import net.minecraft.util.MathHelper; import net.minecraftforge.common.ForgeDirection; import net.minecraftforge.common.MinecraftForge; import universalelectricity.core.block.IConductor; -import universalelectricity.core.block.IElectricityStorage; -import universalelectricity.core.block.IVoltage; -import universalelectricity.core.electricity.ElectricityNetworkHelper; -import universalelectricity.core.electricity.IElectricityNetwork; -import universalelectricity.core.item.IItemElectric; +import universalelectricity.core.block.IElectricalStorage; +import universalelectricity.core.electricity.ElectricityHelper; +import universalelectricity.core.electricity.ElectricityPack; +import universalelectricity.core.grid.IElectricityNetwork; import buildcraft.api.power.IPowerProvider; import buildcraft.api.power.IPowerReceptor; import buildcraft.api.power.PowerProvider; @@ -39,7 +36,7 @@ import com.google.common.io.ByteArrayDataInput; import dan200.computer.api.IComputerAccess; import dan200.computer.api.IPeripheral; -public class TileEntityEnergyCube extends TileEntityElectricBlock implements IEnergySink, IEnergySource, IEnergyStorage, IPowerReceptor, IElectricityStorage, IVoltage, IPeripheral, ICableOutputter, IStrictEnergyAcceptor +public class TileEntityEnergyCube extends TileEntityElectricBlock implements IEnergySink, IEnergySource, IEnergyStorage, IPowerReceptor, IPeripheral, ICableOutputter, IStrictEnergyAcceptor { /** This Energy Cube's tier. */ public EnergyCubeTier tier = EnergyCubeTier.BASIC; @@ -100,37 +97,24 @@ public class TileEntityEnergyCube extends TileEntityElectricBlock implements IEn if(tileEntity instanceof IConductor) { ForgeDirection outputDirection = ForgeDirection.getOrientation(facing); - - ArrayList inputNetworks = new ArrayList(); - - for(ForgeDirection direction : ForgeDirection.VALID_DIRECTIONS) + float provide = getProvide(outputDirection); + + if(provide > 0) { - if(direction != outputDirection) + IElectricityNetwork outputNetwork = ElectricityHelper.getNetworkFromTileEntity(tileEntity, outputDirection); + + if(outputNetwork != null) { - IElectricityNetwork network = ElectricityNetworkHelper.getNetworkFromTileEntity(Object3D.get(this).getFromSide(direction).getTileEntity(worldObj), direction); + ElectricityPack request = outputNetwork.getRequest(this); - if(network != null) + if(request.getWatts() > 0) { - inputNetworks.add(network); + ElectricityPack sendPack = ElectricityPack.min(ElectricityPack.getFromWatts(getEnergyStored(), getVoltage()), ElectricityPack.getFromWatts(provide, getVoltage())); + float rejectedPower = outputNetwork.produce(sendPack, this); + setEnergyStored(getEnergyStored() - (sendPack.getWatts() - rejectedPower)); } } } - - IElectricityNetwork outputNetwork = ElectricityNetworkHelper.getNetworkFromTileEntity(tileEntity, outputDirection); - - if(outputNetwork != null && !inputNetworks.contains(outputNetwork)) - { - double outputWatts = Math.min(outputNetwork.getRequest().getWatts(), Math.min(getEnergy(), 10000)); - - if(getEnergy() > 0 && outputWatts > 0 && getEnergy()-outputWatts >= 0) - { - outputNetwork.startProducing(this, Math.min(outputWatts, getEnergy()) / getVoltage(), getVoltage()); - setEnergy(electricityStored - outputWatts); - } - else { - outputNetwork.stopProducing(this); - } - } } } } @@ -140,15 +124,13 @@ public class TileEntityEnergyCube extends TileEntityElectricBlock implements IEn { if(slotID == 0) { - return itemstack.getItem() instanceof IElectricItem || - (itemstack.getItem() instanceof IItemElectric && ((IItemElectric)itemstack.getItem()).getReceiveRequest(itemstack).amperes != 0); + return MekanismUtils.canBeCharged(itemstack); } else if(slotID == 1) { - return (itemstack.getItem() instanceof IElectricItem && ((IElectricItem)itemstack.getItem()).canProvideEnergy(itemstack)) || - (itemstack.getItem() instanceof IItemElectric && ((IItemElectric)itemstack.getItem()).getProvideRequest(itemstack).amperes != 0) || - itemstack.itemID == Item.redstone.itemID; + return MekanismUtils.canBeDischarged(itemstack); } + return true; } @@ -167,12 +149,24 @@ public class TileEntityEnergyCube extends TileEntityElectricBlock implements IEn return EnumSet.copyOf(set); } + + @Override + protected EnumSet getOutputtingSides() + { + return EnumSet.of(ForgeDirection.getOrientation(facing)); + } @Override public boolean acceptsEnergyFrom(TileEntity emitter, Direction direction) { return direction.toForgeDirection() != ForgeDirection.getOrientation(facing); } + + @Override + public float getProvide(ForgeDirection direction) + { + return getOutputtingSides().contains(direction) ? (float)Math.min(getMaxEnergy()-getEnergy(), tier.OUTPUT) : 0; + } @Override public int getStored() @@ -271,23 +265,18 @@ public class TileEntityEnergyCube extends TileEntityElectricBlock implements IEn { if(slotID == 1) { - return (itemstack.getItem() instanceof IItemElectric && ((IItemElectric)itemstack.getItem()).getProvideRequest(itemstack).getWatts() == 0) || - (itemstack.getItem() instanceof IElectricItem && ((IElectricItem)itemstack.getItem()).canProvideEnergy(itemstack) && - (!(itemstack.getItem() instanceof IItemElectric) || - ((IItemElectric)itemstack.getItem()).getProvideRequest(itemstack).getWatts() == 0)); + return MekanismUtils.canBeOutputted(itemstack, false); } else if(slotID == 0) { - return (itemstack.getItem() instanceof IItemElectric && ((IItemElectric)itemstack.getItem()).getReceiveRequest(itemstack).getWatts() == 0) || - (itemstack.getItem() instanceof IElectricItem && (!(itemstack.getItem() instanceof IItemElectric) || - ((IItemElectric)itemstack.getItem()).getReceiveRequest(itemstack).getWatts() == 0)); + return MekanismUtils.canBeOutputted(itemstack, true); } return false; } @Override - public double getVoltage() + public float getVoltage() { return tier.VOLTAGE; } diff --git a/common/mekanism/common/TileEntityFactory.java b/common/mekanism/common/TileEntityFactory.java index d74a10659..67232725a 100644 --- a/common/mekanism/common/TileEntityFactory.java +++ b/common/mekanism/common/TileEntityFactory.java @@ -287,10 +287,7 @@ public class TileEntityFactory extends TileEntityElectricBlock implements IEnerg { if(slotID == 1) { - return (itemstack.getItem() instanceof IItemElectric && ((IItemElectric)itemstack.getItem()).getProvideRequest(itemstack).getWatts() == 0) || - (itemstack.getItem() instanceof IElectricItem && ((IElectricItem)itemstack.getItem()).canProvideEnergy(itemstack) && - (!(itemstack.getItem() instanceof IItemElectric) || - ((IItemElectric)itemstack.getItem()).getProvideRequest(itemstack).getWatts() == 0)); + return MekanismUtils.canBeOutputted(itemstack, false); } else if(tier == FactoryTier.BASIC && slotID >= 7 && slotID <= 9) { @@ -351,10 +348,9 @@ public class TileEntityFactory extends TileEntityElectricBlock implements IEnerg } else if(slotID == 1) { - return (itemstack.getItem() instanceof IElectricItem && ((IElectricItem)itemstack.getItem()).canProvideEnergy(itemstack)) || - (itemstack.getItem() instanceof IItemElectric && ((IItemElectric)itemstack.getItem()).getProvideRequest(itemstack).amperes != 0) || - itemstack.itemID == Item.redstone.itemID; + return MekanismUtils.canBeDischarged(itemstack); } + return true; } diff --git a/common/mekanism/common/TileEntityMetallurgicInfuser.java b/common/mekanism/common/TileEntityMetallurgicInfuser.java index e55992c8f..76fa57673 100644 --- a/common/mekanism/common/TileEntityMetallurgicInfuser.java +++ b/common/mekanism/common/TileEntityMetallurgicInfuser.java @@ -221,10 +221,7 @@ public class TileEntityMetallurgicInfuser extends TileEntityElectricBlock implem { if(slotID == 4) { - return (itemstack.getItem() instanceof IItemElectric && ((IItemElectric)itemstack.getItem()).getProvideRequest(itemstack).getWatts() == 0) || - (itemstack.getItem() instanceof IElectricItem && ((IElectricItem)itemstack.getItem()).canProvideEnergy(itemstack) && - (!(itemstack.getItem() instanceof IItemElectric) || - ((IItemElectric)itemstack.getItem()).getProvideRequest(itemstack).getWatts() == 0)); + return MekanismUtils.canBeOutputted(itemstack, false); } else if(slotID == 3) { @@ -271,10 +268,9 @@ public class TileEntityMetallurgicInfuser extends TileEntityElectricBlock implem } else if(slotID == 4) { - return (itemstack.getItem() instanceof IElectricItem && ((IElectricItem)itemstack.getItem()).canProvideEnergy(itemstack)) || - (itemstack.getItem() instanceof IItemElectric && ((IItemElectric)itemstack.getItem()).getProvideRequest(itemstack).amperes != 0) || - itemstack.itemID == Item.redstone.itemID; + return MekanismUtils.canBeDischarged(itemstack); } + return true; } diff --git a/common/mekanism/common/TileEntityTeleporter.java b/common/mekanism/common/TileEntityTeleporter.java index cbdb48010..1bea6c011 100644 --- a/common/mekanism/common/TileEntityTeleporter.java +++ b/common/mekanism/common/TileEntityTeleporter.java @@ -105,9 +105,7 @@ public class TileEntityTeleporter extends TileEntityElectricBlock implements IEn { if(slotID == 0) { - return (itemstack.getItem() instanceof IElectricItem && ((IElectricItem)itemstack.getItem()).canProvideEnergy(itemstack)) || - (itemstack.getItem() instanceof IItemElectric && ((IItemElectric)itemstack.getItem()).getProvideRequest(itemstack).amperes != 0) || - itemstack.itemID == Item.redstone.itemID; + return MekanismUtils.canBeDischarged(itemstack); } return true; @@ -363,9 +361,7 @@ public class TileEntityTeleporter extends TileEntityElectricBlock implements IEn @Override public boolean canExtractItem(int slotID, ItemStack itemstack, int side) { - return (itemstack.getItem() instanceof IItemElectric && ((IItemElectric)itemstack.getItem()).getProvideRequest(itemstack).getWatts() == 0) || - (itemstack.getItem() instanceof IElectricItem && (!(itemstack.getItem() instanceof IItemElectric) || - ((IItemElectric)itemstack.getItem()).getProvideRequest(itemstack).getWatts() == 0)); + return MekanismUtils.canBeOutputted(itemstack, false); } @Override diff --git a/common/mekanism/common/network/PacketPortableTeleport.java b/common/mekanism/common/network/PacketPortableTeleport.java index e1356a5b9..0a21a6a50 100644 --- a/common/mekanism/common/network/PacketPortableTeleport.java +++ b/common/mekanism/common/network/PacketPortableTeleport.java @@ -44,7 +44,7 @@ public class PacketPortableTeleport implements IMekanismPacket { Object3D coords = MekanismUtils.getClosestCoords(new Teleporter.Code(item.getDigit(itemstack, 0), item.getDigit(itemstack, 1), item.getDigit(itemstack, 2), item.getDigit(itemstack, 3)), player); - item.onProvide(new ElectricityPack(item.calculateEnergyCost(player, coords)/120, 120), itemstack); + item.setEnergy(itemstack, item.getEnergy(itemstack) - item.calculateEnergyCost(player, coords)); if(world.provider.dimensionId != coords.dimensionId) { diff --git a/common/mekanism/generators/client/GuiBioGenerator.java b/common/mekanism/generators/client/GuiBioGenerator.java index 09c4b0e65..a1e541836 100644 --- a/common/mekanism/generators/client/GuiBioGenerator.java +++ b/common/mekanism/generators/client/GuiBioGenerator.java @@ -37,13 +37,13 @@ public class GuiBioGenerator extends GuiContainer fontRenderer.drawString(tileEntity.fullName, 45, 6, 0x404040); fontRenderer.drawString("Inventory", 8, (ySize - 96) + 2, 0x404040); - fontRenderer.drawString(ElectricityDisplay.getDisplayShort(tileEntity.electricityStored, ElectricUnit.JOULES), 51, 26, 0x00CD00); + fontRenderer.drawString(ElectricityDisplay.getDisplayShort((float)tileEntity.electricityStored, ElectricUnit.JOULES), 51, 26, 0x00CD00); fontRenderer.drawString("BioFuel: " + tileEntity.bioFuelSlot.fluidStored, 51, 35, 0x00CD00); fontRenderer.drawString(tileEntity.getVoltage() + "v", 51, 44, 0x00CD00); if(xAxis >= 165 && xAxis <= 169 && yAxis >= 17 && yAxis <= 69) { - drawCreativeTabHoveringText(ElectricityDisplay.getDisplayShort(tileEntity.electricityStored, ElectricUnit.JOULES), xAxis, yAxis); + drawCreativeTabHoveringText(ElectricityDisplay.getDisplayShort((float)tileEntity.electricityStored, ElectricUnit.JOULES), xAxis, yAxis); } } diff --git a/common/mekanism/generators/client/GuiElectrolyticSeparator.java b/common/mekanism/generators/client/GuiElectrolyticSeparator.java index 291bd5970..494efb4c8 100644 --- a/common/mekanism/generators/client/GuiElectrolyticSeparator.java +++ b/common/mekanism/generators/client/GuiElectrolyticSeparator.java @@ -106,7 +106,7 @@ public class GuiElectrolyticSeparator extends GuiContainer if(xAxis >= 165 && xAxis <= 169 && yAxis >= 17 && yAxis <= 69) { - drawCreativeTabHoveringText(ElectricityDisplay.getDisplayShort(tileEntity.electricityStored, ElectricUnit.JOULES), xAxis, yAxis); + drawCreativeTabHoveringText(ElectricityDisplay.getDisplayShort((float)tileEntity.electricityStored, ElectricUnit.JOULES), xAxis, yAxis); } } diff --git a/common/mekanism/generators/client/GuiHeatGenerator.java b/common/mekanism/generators/client/GuiHeatGenerator.java index 0773553f8..abf35f876 100644 --- a/common/mekanism/generators/client/GuiHeatGenerator.java +++ b/common/mekanism/generators/client/GuiHeatGenerator.java @@ -38,13 +38,13 @@ public class GuiHeatGenerator extends GuiContainer fontRenderer.drawString(tileEntity.fullName, 45, 6, 0x404040); fontRenderer.drawString("Inventory", 8, (ySize - 96) + 2, 0x404040); - fontRenderer.drawString(ElectricityDisplay.getDisplayShort(tileEntity.electricityStored, ElectricUnit.JOULES), 51, 26, 0x00CD00); + fontRenderer.drawString(ElectricityDisplay.getDisplayShort((float)tileEntity.electricityStored, ElectricUnit.JOULES), 51, 26, 0x00CD00); fontRenderer.drawString("Fuel: " + (tileEntity.lavaTank.getFluid() != null ? tileEntity.lavaTank.getFluid().amount : 0), 51, 35, 0x00CD00); fontRenderer.drawString(tileEntity.getVoltage() + "v", 51, 44, 0x00CD00); if(xAxis >= 165 && xAxis <= 169 && yAxis >= 17 && yAxis <= 69) { - drawCreativeTabHoveringText(ElectricityDisplay.getDisplayShort(tileEntity.electricityStored, ElectricUnit.JOULES), xAxis, yAxis); + drawCreativeTabHoveringText(ElectricityDisplay.getDisplayShort((float)tileEntity.electricityStored, ElectricUnit.JOULES), xAxis, yAxis); } } diff --git a/common/mekanism/generators/client/GuiHydrogenGenerator.java b/common/mekanism/generators/client/GuiHydrogenGenerator.java index d7796e197..22f817292 100644 --- a/common/mekanism/generators/client/GuiHydrogenGenerator.java +++ b/common/mekanism/generators/client/GuiHydrogenGenerator.java @@ -38,13 +38,13 @@ public class GuiHydrogenGenerator extends GuiContainer fontRenderer.drawString(tileEntity.fullName, 45, 6, 0x404040); fontRenderer.drawString("Inventory", 8, (ySize - 96) + 2, 0x404040); - fontRenderer.drawString(ElectricityDisplay.getDisplayShort(tileEntity.electricityStored, ElectricUnit.JOULES), 51, 26, 0x00CD00); + fontRenderer.drawString(ElectricityDisplay.getDisplayShort((float)tileEntity.electricityStored, ElectricUnit.JOULES), 51, 26, 0x00CD00); fontRenderer.drawString("H: " + tileEntity.hydrogenStored, 51, 35, 0x00CD00); fontRenderer.drawString(tileEntity.getVoltage() + "v", 51, 44, 0x00CD00); if(xAxis >= 165 && xAxis <= 169 && yAxis >= 17 && yAxis <= 69) { - drawCreativeTabHoveringText(ElectricityDisplay.getDisplayShort(tileEntity.electricityStored, ElectricUnit.JOULES), xAxis, yAxis); + drawCreativeTabHoveringText(ElectricityDisplay.getDisplayShort((float)tileEntity.electricityStored, ElectricUnit.JOULES), xAxis, yAxis); } } diff --git a/common/mekanism/generators/client/GuiSolarGenerator.java b/common/mekanism/generators/client/GuiSolarGenerator.java index 31357f235..bdf7d392a 100644 --- a/common/mekanism/generators/client/GuiSolarGenerator.java +++ b/common/mekanism/generators/client/GuiSolarGenerator.java @@ -38,13 +38,13 @@ public class GuiSolarGenerator extends GuiContainer fontRenderer.drawString(tileEntity.fullName, tileEntity.fullName != "Advanced Solar Generator" ? 45 : 30, 6, 0x404040); fontRenderer.drawString("Inventory", 8, (ySize - 96) + 2, 0x404040); - fontRenderer.drawString(ElectricityDisplay.getDisplayShort(tileEntity.electricityStored, ElectricUnit.JOULES), 51, 26, 0x00CD00); + fontRenderer.drawString(ElectricityDisplay.getDisplayShort((float)tileEntity.electricityStored, ElectricUnit.JOULES), 51, 26, 0x00CD00); fontRenderer.drawString("Sun: " + tileEntity.seesSun, 51, 35, 0x00CD00); fontRenderer.drawString(tileEntity.getVoltage() + "v", 51, 44, 0x00CD00); if(xAxis >= 165 && xAxis <= 169 && yAxis >= 17 && yAxis <= 69) { - drawCreativeTabHoveringText(ElectricityDisplay.getDisplayShort(tileEntity.electricityStored, ElectricUnit.JOULES), xAxis, yAxis); + drawCreativeTabHoveringText(ElectricityDisplay.getDisplayShort((float)tileEntity.electricityStored, ElectricUnit.JOULES), xAxis, yAxis); } } diff --git a/common/mekanism/generators/client/GuiWindTurbine.java b/common/mekanism/generators/client/GuiWindTurbine.java index 74d5bee3f..ea77c8cad 100644 --- a/common/mekanism/generators/client/GuiWindTurbine.java +++ b/common/mekanism/generators/client/GuiWindTurbine.java @@ -39,7 +39,7 @@ public class GuiWindTurbine extends GuiContainer fontRenderer.drawString(tileEntity.fullName, 45, 6, 0x404040); fontRenderer.drawString("Inventory", 8, (ySize - 96) + 2, 0x404040); - fontRenderer.drawString(ElectricityDisplay.getDisplayShort(tileEntity.electricityStored, ElectricUnit.JOULES), 51, 26, 0x00CD00); + fontRenderer.drawString(ElectricityDisplay.getDisplayShort((float)tileEntity.electricityStored, ElectricUnit.JOULES), 51, 26, 0x00CD00); fontRenderer.drawString("Power: " + MekanismGenerators.windGeneration*tileEntity.getMultiplier(), 51, 35, 0x00CD00); fontRenderer.drawString(tileEntity.getVoltage() + "v", 51, 44, 0x00CD00); @@ -53,7 +53,7 @@ public class GuiWindTurbine extends GuiContainer if(xAxis >= 165 && xAxis <= 169 && yAxis >= 17 && yAxis <= 69) { - drawCreativeTabHoveringText(ElectricityDisplay.getDisplayShort(tileEntity.electricityStored, ElectricUnit.JOULES), xAxis, yAxis); + drawCreativeTabHoveringText(ElectricityDisplay.getDisplayShort((float)tileEntity.electricityStored, ElectricUnit.JOULES), xAxis, yAxis); } } diff --git a/common/mekanism/generators/common/BlockGenerator.java b/common/mekanism/generators/common/BlockGenerator.java index f83a7242a..a7daed1c8 100644 --- a/common/mekanism/generators/common/BlockGenerator.java +++ b/common/mekanism/generators/common/BlockGenerator.java @@ -30,7 +30,6 @@ import net.minecraft.util.MovingObjectPosition; import net.minecraft.world.IBlockAccess; import net.minecraft.world.World; import net.minecraftforge.common.ForgeDirection; -import universalelectricity.prefab.implement.IToolConfigurator; import buildcraft.api.tools.IToolWrench; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; @@ -364,33 +363,7 @@ public class BlockGenerator extends BlockContainer implements ISpecialBounds if(entityplayer.getCurrentEquippedItem() != null) { - if(entityplayer.getCurrentEquippedItem().getItem() instanceof IToolConfigurator) - { - ((IToolConfigurator)entityplayer.getCurrentEquippedItem().getItem()).wrenchUsed(entityplayer, x, y, z); - - int change = 0; - - switch(tileEntity.facing) - { - case 3: - change = 5; - break; - case 5: - change = 2; - break; - case 2: - change = 4; - break; - case 4: - change = 3; - break; - } - - tileEntity.setFacing((short)change); - world.notifyBlocksOfNeighborChange(x, y, z, blockID); - return true; - } - else if(entityplayer.getCurrentEquippedItem().getItem() instanceof IToolWrench && !entityplayer.getCurrentEquippedItem().getItemName().contains("omniwrench")) + if(entityplayer.getCurrentEquippedItem().getItem() instanceof IToolWrench && !entityplayer.getCurrentEquippedItem().getItemName().contains("omniwrench")) { if(entityplayer.isSneaking()) { diff --git a/common/mekanism/generators/common/ContainerBioGenerator.java b/common/mekanism/generators/common/ContainerBioGenerator.java index afa8041f9..91cad5a6f 100644 --- a/common/mekanism/generators/common/ContainerBioGenerator.java +++ b/common/mekanism/generators/common/ContainerBioGenerator.java @@ -2,6 +2,7 @@ package mekanism.generators.common; import ic2.api.item.IElectricItem; import mekanism.common.Mekanism; +import mekanism.common.MekanismUtils; import mekanism.common.SlotEnergy.SlotCharge; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.InventoryPlayer; @@ -63,11 +64,11 @@ public class ContainerBioGenerator extends Container ItemStack slotStack = currentSlot.getStack(); stack = slotStack.copy(); - if((slotStack.getItem() instanceof IItemElectric && ((IItemElectric)slotStack.getItem()).getReceiveRequest(slotStack).amperes != 0) || slotStack.getItem() instanceof IElectricItem) + if(MekanismUtils.canBeCharged(slotStack)) { if(slotID != 1) { - if (!mergeItemStack(slotStack, 1, 2, false)) + if(!mergeItemStack(slotStack, 1, 2, false)) { return null; } diff --git a/common/mekanism/generators/common/ContainerElectrolyticSeparator.java b/common/mekanism/generators/common/ContainerElectrolyticSeparator.java index 08e35f4a5..e8272635f 100644 --- a/common/mekanism/generators/common/ContainerElectrolyticSeparator.java +++ b/common/mekanism/generators/common/ContainerElectrolyticSeparator.java @@ -1,20 +1,18 @@ package mekanism.generators.common; -import ic2.api.item.IElectricItem; import mekanism.api.EnumGas; import mekanism.api.IStorageTank; +import mekanism.common.MekanismUtils; import mekanism.common.SlotEnergy.SlotDischarge; import mekanism.common.SlotStorageTank; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.inventory.Container; import net.minecraft.inventory.Slot; -import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraftforge.fluids.FluidContainerRegistry; import net.minecraftforge.fluids.FluidRegistry; import net.minecraftforge.fluids.FluidStack; -import universalelectricity.core.item.IItemElectric; public class ContainerElectrolyticSeparator extends Container { @@ -107,7 +105,7 @@ public class ContainerElectrolyticSeparator extends Container } } } - else if((slotStack.getItem() instanceof IElectricItem && ((IElectricItem)slotStack.getItem()).canProvideEnergy(slotStack)) || (slotStack.getItem() instanceof IItemElectric && ((IItemElectric)slotStack.getItem()).getProvideRequest(slotStack).amperes != 0) || slotStack.itemID == Item.redstone.itemID) + else if(MekanismUtils.canBeDischarged(slotStack)) { if(!mergeItemStack(slotStack, 3, 4, false)) { diff --git a/common/mekanism/generators/common/ContainerHeatGenerator.java b/common/mekanism/generators/common/ContainerHeatGenerator.java index a13b2eda4..21af45f69 100644 --- a/common/mekanism/generators/common/ContainerHeatGenerator.java +++ b/common/mekanism/generators/common/ContainerHeatGenerator.java @@ -1,6 +1,7 @@ package mekanism.generators.common; import ic2.api.item.IElectricItem; +import mekanism.common.MekanismUtils; import mekanism.common.SlotEnergy.SlotCharge; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.InventoryPlayer; @@ -62,7 +63,7 @@ public class ContainerHeatGenerator extends Container ItemStack slotStack = currentSlot.getStack(); stack = slotStack.copy(); - if((slotStack.getItem() instanceof IItemElectric && ((IItemElectric)slotStack.getItem()).getReceiveRequest(slotStack).amperes != 0) || slotStack.getItem() instanceof IElectricItem) + if(MekanismUtils.canBeCharged(slotStack)) { if(slotID != 1) { diff --git a/common/mekanism/generators/common/ContainerHydrogenGenerator.java b/common/mekanism/generators/common/ContainerHydrogenGenerator.java index 218e2611d..c8ed083e2 100644 --- a/common/mekanism/generators/common/ContainerHydrogenGenerator.java +++ b/common/mekanism/generators/common/ContainerHydrogenGenerator.java @@ -3,6 +3,7 @@ package mekanism.generators.common; import ic2.api.item.IElectricItem; import mekanism.api.EnumGas; import mekanism.api.IStorageTank; +import mekanism.common.MekanismUtils; import mekanism.common.SlotEnergy.SlotCharge; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.InventoryPlayer; @@ -64,11 +65,11 @@ public class ContainerHydrogenGenerator extends Container ItemStack slotStack = currentSlot.getStack(); stack = slotStack.copy(); - if((slotStack.getItem() instanceof IItemElectric && ((IItemElectric)slotStack.getItem()).getReceiveRequest(slotStack).amperes != 0) || slotStack.getItem() instanceof IElectricItem) + if(MekanismUtils.canBeCharged(slotStack)) { if(slotID != 1) { - if (!mergeItemStack(slotStack, 1, 2, false)) + if(!mergeItemStack(slotStack, 1, 2, false)) { return null; } diff --git a/common/mekanism/generators/common/ContainerSolarGenerator.java b/common/mekanism/generators/common/ContainerSolarGenerator.java index c4b236d6c..a5efb2a0d 100644 --- a/common/mekanism/generators/common/ContainerSolarGenerator.java +++ b/common/mekanism/generators/common/ContainerSolarGenerator.java @@ -1,13 +1,12 @@ package mekanism.generators.common; -import ic2.api.item.IElectricItem; +import mekanism.common.MekanismUtils; import mekanism.common.SlotEnergy.SlotCharge; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.inventory.Container; import net.minecraft.inventory.Slot; import net.minecraft.item.ItemStack; -import universalelectricity.core.item.IItemElectric; public class ContainerSolarGenerator extends Container { @@ -61,11 +60,11 @@ public class ContainerSolarGenerator extends Container ItemStack slotStack = currentSlot.getStack(); stack = slotStack.copy(); - if((slotStack.getItem() instanceof IItemElectric && ((IItemElectric)slotStack.getItem()).getReceiveRequest(slotStack).amperes != 0) || slotStack.getItem() instanceof IElectricItem) + if(MekanismUtils.canBeCharged(slotStack)) { if(slotID != 0) { - if (!mergeItemStack(slotStack, 0, 1, false)) + if(!mergeItemStack(slotStack, 0, 1, false)) { return null; } diff --git a/common/mekanism/generators/common/ContainerWindTurbine.java b/common/mekanism/generators/common/ContainerWindTurbine.java index e192f8673..c89692ee7 100644 --- a/common/mekanism/generators/common/ContainerWindTurbine.java +++ b/common/mekanism/generators/common/ContainerWindTurbine.java @@ -1,6 +1,7 @@ package mekanism.generators.common; import ic2.api.item.IElectricItem; +import mekanism.common.MekanismUtils; import mekanism.common.SlotEnergy.SlotCharge; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.InventoryPlayer; @@ -61,11 +62,11 @@ public class ContainerWindTurbine extends Container ItemStack slotStack = currentSlot.getStack(); stack = slotStack.copy(); - if((slotStack.getItem() instanceof IItemElectric && ((IItemElectric)slotStack.getItem()).getReceiveRequest(slotStack).amperes != 0) || slotStack.getItem() instanceof IElectricItem) + if(MekanismUtils.canBeCharged(slotStack)) { if(slotID != 0) { - if (!mergeItemStack(slotStack, 0, 1, false)) + if(!mergeItemStack(slotStack, 0, 1, false)) { return null; } diff --git a/common/mekanism/generators/common/ItemBlockGenerator.java b/common/mekanism/generators/common/ItemBlockGenerator.java index c701097d0..289b10b43 100644 --- a/common/mekanism/generators/common/ItemBlockGenerator.java +++ b/common/mekanism/generators/common/ItemBlockGenerator.java @@ -111,7 +111,7 @@ public class ItemBlockGenerator extends ItemBlock implements IEnergizedItem, IIt list.add("Hold " + EnumColor.AQUA + "shift" + EnumColor.GREY + " for details."); } else { - list.add(EnumColor.BRIGHT_GREEN + "Stored Energy: " + EnumColor.GREY + ElectricityDisplay.getDisplayShort(getJoules(itemstack), ElectricUnit.JOULES)); + list.add(EnumColor.BRIGHT_GREEN + "Stored Energy: " + EnumColor.GREY + ElectricityDisplay.getDisplayShort((float)getEnergy(itemstack), ElectricUnit.JOULES)); list.add(EnumColor.BRIGHT_GREEN + "Voltage: " + EnumColor.GREY + getVoltage(itemstack) + "v"); if(hasTank(itemstack)) @@ -127,72 +127,10 @@ public class ItemBlockGenerator extends ItemBlock implements IEnergizedItem, IIt } @Override - public double getJoules(ItemStack itemStack) - { - return getEnergy(itemStack); - } - - @Override - public void setJoules(double wattHours, ItemStack itemStack) - { - setEnergy(itemStack, wattHours); - } - - @Override - public double getMaxJoules(ItemStack itemStack) - { - return getMaxEnergy(itemStack); - } - - @Override - public double getVoltage(ItemStack itemStack) + public float getVoltage(ItemStack itemStack) { return itemStack.getItemDamage() == 3 ? 240 : 120; } - - @Override - public ElectricityPack onReceive(ElectricityPack electricityPack, ItemStack itemStack) - { - if(itemStack.getItemDamage() == 2) - { - double rejectedElectricity = Math.max((getJoules(itemStack) + electricityPack.getWatts()) - getMaxJoules(itemStack), 0); - double joulesToStore = electricityPack.getWatts() - rejectedElectricity; - this.setJoules(getJoules(itemStack) + joulesToStore, itemStack); - return ElectricityPack.getFromWatts(joulesToStore, getVoltage(itemStack)); - } - - return new ElectricityPack(); - } - - @Override - public ElectricityPack onProvide(ElectricityPack electricityPack, ItemStack itemStack) - { - if(itemStack.getItemDamage() != 2) - { - double electricityToUse = Math.min(getJoules(itemStack), electricityPack.getWatts()); - setJoules(getJoules(itemStack) - electricityToUse, itemStack); - return ElectricityPack.getFromWatts(electricityToUse, getVoltage(itemStack)); - } - - return new ElectricityPack(); - } - - @Override - public ElectricityPack getReceiveRequest(ItemStack itemStack) - { - return itemStack.getItemDamage() == 2 ? ElectricityPack.getFromWatts(Math.min(getMaxJoules(itemStack) - getJoules(itemStack), getTransferRate(itemStack)), getVoltage(itemStack)) : new ElectricityPack(); - } - - @Override - public ElectricityPack getProvideRequest(ItemStack itemStack) - { - return itemStack.getItemDamage() != 2 ? ElectricityPack.getFromWatts(Math.min(getJoules(itemStack), getTransferRate(itemStack)), getVoltage(itemStack)) : new ElectricityPack(); - } - - public double getTransferRate(ItemStack itemStack) - { - return getMaxJoules(itemStack)*0.01; - } @Override public boolean placeBlockAt(ItemStack stack, EntityPlayer player, World world, int x, int y, int z, int side, float hitX, float hitY, float hitZ, int metadata) @@ -240,7 +178,7 @@ public class ItemBlockGenerator extends ItemBlock implements IEnergizedItem, IIt if(place && super.placeBlockAt(stack, player, world, x, y, z, side, hitX, hitY, hitZ, metadata)) { TileEntityElectricBlock tileEntity = (TileEntityElectricBlock)world.getBlockTileEntity(x, y, z); - tileEntity.electricityStored = getJoules(stack); + tileEntity.electricityStored = getEnergy(stack); ((ISustainedInventory)tileEntity).setInventory(getInventory(stack)); @@ -261,7 +199,7 @@ public class ItemBlockGenerator extends ItemBlock implements IEnergizedItem, IIt @Override public int charge(ItemStack itemStack, int amount, int tier, boolean ignoreTransferLimit, boolean simulate) { - if(itemStack.getItemDamage() == 2) + if(canReceive(itemStack)) { double energyNeeded = getMaxEnergy(itemStack)-getEnergy(itemStack); double energyToStore = Math.min(Math.min(amount*Mekanism.FROM_IC2, getMaxEnergy(itemStack)*0.01), energyNeeded); @@ -280,14 +218,14 @@ public class ItemBlockGenerator extends ItemBlock implements IEnergizedItem, IIt @Override public int discharge(ItemStack itemStack, int amount, int tier, boolean ignoreTransferLimit, boolean simulate) { - if(itemStack.getItemDamage() != 2) + if(canSend(itemStack)) { double energyWanted = amount*Mekanism.FROM_IC2; - double energyToGive = Math.min(Math.min(energyWanted, getMaxEnergy(itemStack)*0.01), getJoules(itemStack)); + double energyToGive = Math.min(Math.min(energyWanted, getMaxEnergy(itemStack)*0.01), getEnergy(itemStack)); if(!simulate) { - setJoules(getJoules(itemStack) - energyToGive, itemStack); + setEnergy(itemStack, getEnergy(itemStack) - energyToGive); } return (int)(energyToGive*Mekanism.TO_IC2); @@ -299,7 +237,7 @@ public class ItemBlockGenerator extends ItemBlock implements IEnergizedItem, IIt @Override public boolean canUse(ItemStack itemStack, int amount) { - return getJoules(itemStack) >= amount*Mekanism.FROM_IC2; + return getEnergy(itemStack) >= amount*Mekanism.FROM_IC2; } @Override @@ -311,7 +249,7 @@ public class ItemBlockGenerator extends ItemBlock implements IEnergizedItem, IIt @Override public boolean canProvideEnergy(ItemStack itemStack) { - return itemStack.getItemDamage() != 2; + return canSend(itemStack); } @Override @@ -445,7 +383,7 @@ public class ItemBlockGenerator extends ItemBlock implements IEnergizedItem, IIt itemStack.setTagCompound(new NBTTagCompound()); } - double electricityStored = Math.max(Math.min(amount, getMaxJoules(itemStack)), 0); + double electricityStored = Math.max(Math.min(amount, getMaxEnergy(itemStack)), 0); itemStack.stackTagCompound.setDouble("electricity", electricityStored); } @@ -476,21 +414,39 @@ public class ItemBlockGenerator extends ItemBlock implements IEnergizedItem, IIt @Override public float receiveEnergy(ItemStack theItem, float energy, boolean doReceive) { + if(canReceive(theItem)) + { + double energyNeeded = getMaxEnergy(theItem)-getEnergy(theItem); + double toReceive = Math.min(energy*Mekanism.FROM_BC, energyNeeded); + + if(doReceive) + { + setEnergy(theItem, getEnergy(theItem) + toReceive); + } + + return (float)(toReceive*Mekanism.TO_BC); + } + return 0; } @Override public float transferEnergy(ItemStack theItem, float energy, boolean doTransfer) { - double energyRemaining = getEnergy(theItem); - double toSend = Math.min(energy*Mekanism.FROM_BC, energyRemaining); - - if(doTransfer) + if(canSend(theItem)) { - setEnergy(theItem, getEnergy(theItem) - toSend); + double energyRemaining = getEnergy(theItem); + double toSend = Math.min(energy*Mekanism.FROM_BC, energyRemaining); + + if(doTransfer) + { + setEnergy(theItem, getEnergy(theItem) - toSend); + } + + return (float)(toSend*Mekanism.TO_BC); } - return (float)(toSend*Mekanism.TO_BC); + return 0; } @Override @@ -510,4 +466,40 @@ public class ItemBlockGenerator extends ItemBlock implements IEnergizedItem, IIt { return true; } + + @Override + public float recharge(ItemStack itemStack, float energy, boolean doRecharge) + { + return receiveEnergy(itemStack, energy, doRecharge); + } + + @Override + public float discharge(ItemStack itemStack, float energy, boolean doDischarge) + { + return transferEnergy(itemStack, energy, doDischarge); + } + + @Override + public float getElectricityStored(ItemStack theItem) + { + return (float)getEnergy(theItem); + } + + @Override + public float getMaxElectricityStored(ItemStack theItem) + { + return (float)getMaxEnergy(theItem); + } + + @Override + public void setElectricity(ItemStack itemStack, float joules) + { + setEnergy(itemStack, joules); + } + + @Override + public float getTransfer(ItemStack itemStack) + { + return (float)getMaxTransfer(itemStack); + } } diff --git a/common/mekanism/generators/common/TileEntityBioGenerator.java b/common/mekanism/generators/common/TileEntityBioGenerator.java index 782961e8b..76f566284 100644 --- a/common/mekanism/generators/common/TileEntityBioGenerator.java +++ b/common/mekanism/generators/common/TileEntityBioGenerator.java @@ -156,8 +156,7 @@ public class TileEntityBioGenerator extends TileEntityGenerator implements IFlui } else if(slotID == 1) { - return itemstack.getItem() instanceof IElectricItem || - (itemstack.getItem() instanceof IItemElectric && ((IItemElectric)itemstack.getItem()).getReceiveRequest(itemstack).amperes != 0); + return MekanismUtils.canBeCharged(itemstack); } return true; diff --git a/common/mekanism/generators/common/TileEntityElectrolyticSeparator.java b/common/mekanism/generators/common/TileEntityElectrolyticSeparator.java index 2643ccd6c..f48604b7b 100644 --- a/common/mekanism/generators/common/TileEntityElectrolyticSeparator.java +++ b/common/mekanism/generators/common/TileEntityElectrolyticSeparator.java @@ -241,10 +241,7 @@ public class TileEntityElectrolyticSeparator extends TileEntityElectricBlock imp { if(slotID == 3) { - return (itemstack.getItem() instanceof IItemElectric && ((IItemElectric)itemstack.getItem()).getProvideRequest(itemstack).getWatts() > 0) || - (itemstack.getItem() instanceof IElectricItem && ((IElectricItem)itemstack.getItem()).canProvideEnergy(itemstack) && - (!(itemstack.getItem() instanceof IItemElectric) || - ((IItemElectric)itemstack.getItem()).getProvideRequest(itemstack).getWatts() > 0)); + return MekanismUtils.canBeOutputted(itemstack, false); } else if(slotID == 0) { @@ -279,10 +276,9 @@ public class TileEntityElectrolyticSeparator extends TileEntityElectricBlock imp } else if(slotID == 3) { - return (itemstack.getItem() instanceof IElectricItem && ((IElectricItem)itemstack.getItem()).canProvideEnergy(itemstack)) || - (itemstack.getItem() instanceof IItemElectric && ((IItemElectric)itemstack.getItem()).getProvideRequest(itemstack).amperes != 0) || - itemstack.itemID == Item.redstone.itemID; + return MekanismUtils.canBeDischarged(itemstack); } + return true; } diff --git a/common/mekanism/generators/common/TileEntityGenerator.java b/common/mekanism/generators/common/TileEntityGenerator.java index c5941d241..7f0e5b494 100644 --- a/common/mekanism/generators/common/TileEntityGenerator.java +++ b/common/mekanism/generators/common/TileEntityGenerator.java @@ -28,8 +28,9 @@ import net.minecraft.util.AxisAlignedBB; import net.minecraftforge.common.ForgeDirection; import net.minecraftforge.common.MinecraftForge; import universalelectricity.core.block.IConductor; -import universalelectricity.core.electricity.ElectricityNetworkHelper; -import universalelectricity.core.electricity.IElectricityNetwork; +import universalelectricity.core.electricity.ElectricityHelper; +import universalelectricity.core.electricity.ElectricityPack; +import universalelectricity.core.grid.IElectricityNetwork; import buildcraft.api.power.IPowerProvider; import buildcraft.api.power.IPowerReceptor; import buildcraft.api.power.PowerProvider; @@ -114,23 +115,25 @@ public abstract class TileEntityGenerator extends TileEntityElectricBlock implem } } - if(!worldObj.isRemote && tileEntity instanceof IConductor) + if(tileEntity instanceof IConductor) { ForgeDirection outputDirection = ForgeDirection.getOrientation(facing); + float provide = getProvide(outputDirection); - IElectricityNetwork outputNetwork = ElectricityNetworkHelper.getNetworkFromTileEntity(tileEntity, outputDirection); - - if(outputNetwork != null) + if(provide > 0) { - double outputWatts = Math.min(outputNetwork.getRequest().getWatts(), Math.min(getEnergy(), 10000)); - - if(getEnergy() > 0 && outputWatts > 0 && getEnergy()-outputWatts >= 0) + IElectricityNetwork outputNetwork = ElectricityHelper.getNetworkFromTileEntity(tileEntity, outputDirection); + + if(outputNetwork != null) { - outputNetwork.startProducing(this, outputWatts / getVoltage(), getVoltage()); - setEnergy(electricityStored - outputWatts); - } - else { - outputNetwork.stopProducing(this); + ElectricityPack request = outputNetwork.getRequest(this); + + if(request.getWatts() > 0) + { + ElectricityPack sendPack = ElectricityPack.min(ElectricityPack.getFromWatts(getEnergyStored(), getVoltage()), ElectricityPack.getFromWatts(provide, getVoltage())); + float rejectedPower = outputNetwork.produce(sendPack, this); + setEnergyStored(getEnergyStored() - (sendPack.getWatts() - rejectedPower)); + } } } } @@ -144,9 +147,21 @@ public abstract class TileEntityGenerator extends TileEntityElectricBlock implem } @Override - public boolean canConnect(ForgeDirection direction) + protected EnumSet getOutputtingSides() { - return direction == ForgeDirection.getOrientation(facing); + return EnumSet.of(ForgeDirection.getOrientation(facing)); + } + + @Override + public float getRequest(ForgeDirection direction) + { + return 0; + } + + @Override + public float getProvide(ForgeDirection direction) + { + return getOutputtingSides().contains(direction) ? (float)Math.min(getMaxEnergy()-getEnergy(), output) : 0; } @Override diff --git a/common/mekanism/generators/common/TileEntityHeatGenerator.java b/common/mekanism/generators/common/TileEntityHeatGenerator.java index 695cd2b6d..346cf5cc7 100644 --- a/common/mekanism/generators/common/TileEntityHeatGenerator.java +++ b/common/mekanism/generators/common/TileEntityHeatGenerator.java @@ -115,8 +115,7 @@ public class TileEntityHeatGenerator extends TileEntityGenerator implements IFlu } else if(slotID == 1) { - return itemstack.getItem() instanceof IElectricItem || - (itemstack.getItem() instanceof IItemElectric && ((IItemElectric)itemstack.getItem()).getReceiveRequest(itemstack).amperes != 0); + return MekanismUtils.canBeCharged(itemstack); } return true; @@ -155,9 +154,7 @@ public class TileEntityHeatGenerator extends TileEntityGenerator implements IFlu { if(slotID == 1) { - return (itemstack.getItem() instanceof IItemElectric && ((IItemElectric)itemstack.getItem()).getReceiveRequest(itemstack).getWatts() == 0) || - (itemstack.getItem() instanceof IElectricItem && (!(itemstack.getItem() instanceof IItemElectric) || - ((IItemElectric)itemstack.getItem()).getReceiveRequest(itemstack).getWatts() == 0)); + return MekanismUtils.canBeOutputted(itemstack, true); } else if(slotID == 0) { diff --git a/common/mekanism/generators/common/TileEntityHydrogenGenerator.java b/common/mekanism/generators/common/TileEntityHydrogenGenerator.java index 00eef42b7..89a80258d 100644 --- a/common/mekanism/generators/common/TileEntityHydrogenGenerator.java +++ b/common/mekanism/generators/common/TileEntityHydrogenGenerator.java @@ -86,9 +86,7 @@ public class TileEntityHydrogenGenerator extends TileEntityGenerator implements { if(slotID == 1) { - return (itemstack.getItem() instanceof IItemElectric && ((IItemElectric)itemstack.getItem()).getReceiveRequest(itemstack).getWatts() == 0) || - (itemstack.getItem() instanceof IElectricItem && (!(itemstack.getItem() instanceof IItemElectric) || - ((IItemElectric)itemstack.getItem()).getReceiveRequest(itemstack).getWatts() == 0)); + return MekanismUtils.canBeOutputted(itemstack, true); } else if(slotID == 0) { @@ -107,8 +105,7 @@ public class TileEntityHydrogenGenerator extends TileEntityGenerator implements } else if(slotID == 1) { - return itemstack.getItem() instanceof IElectricItem || - (itemstack.getItem() instanceof IItemElectric && ((IItemElectric)itemstack.getItem()).getReceiveRequest(itemstack).amperes != 0); + return MekanismUtils.canBeCharged(itemstack); } return true; @@ -222,7 +219,7 @@ public class TileEntityHydrogenGenerator extends TileEntityGenerator implements } @Override - public double getVoltage() + public float getVoltage() { return 240; } diff --git a/common/mekanism/generators/common/TileEntitySolarGenerator.java b/common/mekanism/generators/common/TileEntitySolarGenerator.java index 453d9d760..99db9e40f 100644 --- a/common/mekanism/generators/common/TileEntitySolarGenerator.java +++ b/common/mekanism/generators/common/TileEntitySolarGenerator.java @@ -6,6 +6,7 @@ import java.util.ArrayList; import mekanism.api.Object3D; import mekanism.common.ChargeUtils; +import mekanism.common.MekanismUtils; import mekanism.generators.common.BlockGenerator.GeneratorType; import micdoodle8.mods.galacticraft.API.ISolarLevel; import net.minecraft.block.Block; @@ -105,9 +106,7 @@ public class TileEntitySolarGenerator extends TileEntityGenerator { if(slotID == 0) { - return (itemstack.getItem() instanceof IItemElectric && ((IItemElectric)itemstack.getItem()).getReceiveRequest(itemstack).getWatts() == 0) || - (itemstack.getItem() instanceof IElectricItem && (!(itemstack.getItem() instanceof IItemElectric) || - ((IItemElectric)itemstack.getItem()).getReceiveRequest(itemstack).getWatts() == 0)); + return MekanismUtils.canBeOutputted(itemstack, true); } return false; @@ -118,8 +117,7 @@ public class TileEntitySolarGenerator extends TileEntityGenerator { if(slotID == 0) { - return itemstack.getItem() instanceof IElectricItem || - (itemstack.getItem() instanceof IItemElectric && ((IItemElectric)itemstack.getItem()).getReceiveRequest(itemstack).amperes != 0); + return MekanismUtils.canBeCharged(itemstack); } return true; diff --git a/common/mekanism/tools/common/ItemMekanismArmor.java b/common/mekanism/tools/common/ItemMekanismArmor.java index 0c7fcd582..8f9d37bfb 100644 --- a/common/mekanism/tools/common/ItemMekanismArmor.java +++ b/common/mekanism/tools/common/ItemMekanismArmor.java @@ -4,6 +4,7 @@ import java.util.List; import mekanism.common.Mekanism; import net.minecraft.client.renderer.texture.IconRegister; +import net.minecraft.entity.Entity; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.EnumArmorMaterial; import net.minecraft.item.ItemArmor; @@ -11,9 +12,12 @@ import net.minecraft.item.ItemStack; public class ItemMekanismArmor extends ItemArmor { + protected EnumArmorMaterial material; + public ItemMekanismArmor(int id, EnumArmorMaterial enumarmormaterial, int renderIndex, int armorType) { super(id, enumarmormaterial, renderIndex, armorType); + material = enumarmormaterial; setCreativeTab(Mekanism.tabMekanism); } @@ -28,4 +32,10 @@ public class ItemMekanismArmor extends ItemArmor { itemIcon = register.registerIcon("mekanism:" + getUnlocalizedName().replace("item.", "")); } + + @Override + public String getArmorTexture(ItemStack stack, Entity entity, int slot, int layer) + { + return "/assets/mekanism/armor/" + material.name().toLowerCase() + "_" + layer + ".png"; + } } diff --git a/common/mekanism/tools/common/MekanismTools.java b/common/mekanism/tools/common/MekanismTools.java index 999a5b353..59d37f149 100644 --- a/common/mekanism/tools/common/MekanismTools.java +++ b/common/mekanism/tools/common/MekanismTools.java @@ -18,7 +18,7 @@ import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.event.ForgeSubscribe; import net.minecraftforge.event.entity.living.LivingSpawnEvent; import cpw.mods.fml.common.Mod; -import cpw.mods.fml.common.Mod.Init; +import cpw.mods.fml.common.Mod.EventHandler; import cpw.mods.fml.common.Mod.Instance; import cpw.mods.fml.common.event.FMLInitializationEvent; import cpw.mods.fml.common.network.NetworkMod; @@ -136,7 +136,7 @@ public class MekanismTools implements IModule public static Item SteelLeggings; public static Item SteelBoots; - @Init + @EventHandler public void init(FMLInitializationEvent event) { //Add this module to the core list diff --git a/common/universalelectricity/core/UniversalElectricity.java b/common/universalelectricity/core/UniversalElectricity.java index 63543a71e..a2016d707 100644 --- a/common/universalelectricity/core/UniversalElectricity.java +++ b/common/universalelectricity/core/UniversalElectricity.java @@ -5,6 +5,7 @@ import java.io.File; import net.minecraft.block.material.MapColor; import net.minecraft.block.material.Material; import net.minecraftforge.common.Configuration; +import net.minecraftforge.common.MinecraftForge; import cpw.mods.fml.common.Loader; /** @@ -29,18 +30,6 @@ public class UniversalElectricity */ public static final Configuration CONFIGURATION = new Configuration(new File(Loader.instance().getConfigDir(), "UniversalElectricity.cfg")); - /** - * Multiply this to convert foreign energy into UE Joules. - */ - public static double IC2_RATIO = 40; - public static double BC3_RATIO = 100; - - /** - * Multiply this to convert UE Joules into foreign energy. - */ - public static double TO_IC2_RATIO = 1 / IC2_RATIO; - public static double TO_BC_RATIO = 1 / BC3_RATIO; - /** * Is Universal Electricity currently being voltage sensitive? If so, all machines should * explode under high voltage and react to different amounts of voltage differently. @@ -52,6 +41,7 @@ public class UniversalElectricity * the ElectricityNetwork. Examples would be a mod that adds any sort of wire. This value will * be true as long as there is a way to conduct electricity. */ + @Deprecated public static boolean isNetworkActive = false; /** @@ -59,19 +49,35 @@ public class UniversalElectricity */ public static final Material machine = new Material(MapColor.ironColor); + private static boolean INIT = false; + static { - /** - * Loads the configuration and sets all the values. - */ - CONFIGURATION.load(); - IC2_RATIO = CONFIGURATION.get("Compatiblity", "IndustrialCraft Conversion Ratio", IC2_RATIO).getDouble(IC2_RATIO); - BC3_RATIO = CONFIGURATION.get("Compatiblity", "BuildCraft Conversion Ratio", BC3_RATIO).getDouble(BC3_RATIO); - TO_IC2_RATIO = 1 / IC2_RATIO; - TO_BC_RATIO = 1 / BC3_RATIO; + initiate(); + } - isVoltageSensitive = CONFIGURATION.get("Compatiblity", "Is Voltage Sensitive", isVoltageSensitive).getBoolean(isVoltageSensitive); - isNetworkActive = CONFIGURATION.get("Compatiblity", "Is Network Active", isNetworkActive).getBoolean(isNetworkActive); - CONFIGURATION.save(); + public static void initiate() + { + if (!INIT) + { + /** + * Loads the configuration and sets all the values. + */ + CONFIGURATION.load(); + isVoltageSensitive = CONFIGURATION.get("Compatiblity", "Is Voltage Sensitive", isVoltageSensitive).getBoolean(isVoltageSensitive); + isNetworkActive = CONFIGURATION.get("Compatiblity", "Is Network Active", isNetworkActive).getBoolean(isNetworkActive); + CONFIGURATION.save(); + + try + { + MinecraftForge.EVENT_BUS.register(Class.forName("universalelectricity.core.electricity.ElectricityHelper").newInstance()); + } + catch (Exception e) + { + e.printStackTrace(); + } + } + + INIT = true; } } diff --git a/common/universalelectricity/core/block/IConductor.java b/common/universalelectricity/core/block/IConductor.java index c558f09af..3adc83a1f 100644 --- a/common/universalelectricity/core/block/IConductor.java +++ b/common/universalelectricity/core/block/IConductor.java @@ -1,24 +1,17 @@ package universalelectricity.core.block; -/** - * Must be applied to all tile entities that are conductors. - * - * @author Calclavia - * - */ -public interface IConductor extends INetworkProvider, IConnectionProvider +public interface IConductor extends INetworkProvider, INetworkConnection { - /** * Gets the resistance of the conductor. Used to calculate energy loss. A higher resistance * means a higher energy loss. * * @return The amount of resistance in Ohms. */ - public double getResistance(); + public float getResistance(); /** * @return The maximum amount of amps this conductor can handle before melting down. */ - public double getCurrentCapcity(); + public float getCurrentCapacity(); } diff --git a/common/universalelectricity/core/block/IElectrical.java b/common/universalelectricity/core/block/IElectrical.java new file mode 100644 index 000000000..7c4fe75c1 --- /dev/null +++ b/common/universalelectricity/core/block/IElectrical.java @@ -0,0 +1,53 @@ +package universalelectricity.core.block; + +import net.minecraftforge.common.ForgeDirection; +import universalelectricity.core.electricity.ElectricityPack; + +/** + * Applied to all TileEntities that can interact with electricity. + * + * @author Calclavia, King_Lemming + * + */ +public interface IElectrical extends IConnector +{ + /** + * Adds electricity to an block. Returns the quantity of electricity that was accepted. This + * should always return 0 if the block cannot be externally charged. + * + * @param from Orientation the electricity is sent in from. + * @param receive Maximum amount of electricity to be sent into the block. + * @param doReceive If false, the charge will only be simulated. + * @return Amount of energy that was accepted by the block. + */ + public float receiveElectricity(ForgeDirection from, ElectricityPack receive, boolean doReceive); + + /** + * Adds electricity to an block. Returns the ElectricityPack, the electricity provided. This + * should always return null if the block cannot be externally discharged. + * + * @param from Orientation the electricity is requested from. + * @param energy Maximum amount of energy to be sent into the block. + * @param doReceive If false, the charge will only be simulated. + * @return Amount of energy that was given out by the block. + */ + public ElectricityPack provideElectricity(ForgeDirection from, ElectricityPack request, boolean doProvide); + + /** + * @return How much energy does this TileEntity want? + */ + public float getRequest(ForgeDirection direction); + + /** + * @return How much energy does this TileEntity want to provide? + */ + public float getProvide(ForgeDirection direction); + + /** + * Gets the voltage of this TileEntity. + * + * @return The amount of volts. E.g 120v or 240v + */ + public float getVoltage(); + +} diff --git a/common/universalelectricity/core/block/IElectricalStorage.java b/common/universalelectricity/core/block/IElectricalStorage.java new file mode 100644 index 000000000..758c34dba --- /dev/null +++ b/common/universalelectricity/core/block/IElectricalStorage.java @@ -0,0 +1,24 @@ +package universalelectricity.core.block; + +/** + * This interface is to be applied to all TileEntities which stores electricity within them. + * + * @author Calclavia + */ +public interface IElectricalStorage +{ + /** + * Sets the amount of joules this unit has stored. + */ + public void setEnergyStored(float energy); + + /** + * * @return Get the amount of energy currently stored in the block. + */ + public float getEnergyStored(); + + /** + * @return Get the max amount of energy that can be stored in the block. + */ + public float getMaxEnergyStored(); +} diff --git a/common/universalelectricity/core/block/IElectricityStorage.java b/common/universalelectricity/core/block/IElectricityStorage.java deleted file mode 100644 index 906cb92fb..000000000 --- a/common/universalelectricity/core/block/IElectricityStorage.java +++ /dev/null @@ -1,24 +0,0 @@ -package universalelectricity.core.block; - -/** - * This interface is to be applied to all TileEntities which stores electricity within them. - * - * @author Calclavia - */ -public interface IElectricityStorage -{ - /** - * Returns the amount of joules this unit has stored. - */ - public double getJoules(); - - /** - * Sets the amount of joules this unit has stored. - */ - public void setJoules(double joules); - - /** - * Gets the maximum amount of joules this unit can store. - */ - public double getMaxJoules(); -} diff --git a/common/universalelectricity/core/block/IConnectionProvider.java b/common/universalelectricity/core/block/INetworkConnection.java similarity index 65% rename from common/universalelectricity/core/block/IConnectionProvider.java rename to common/universalelectricity/core/block/INetworkConnection.java index 888dada50..e20669e4a 100644 --- a/common/universalelectricity/core/block/IConnectionProvider.java +++ b/common/universalelectricity/core/block/INetworkConnection.java @@ -8,7 +8,7 @@ import net.minecraft.tileentity.TileEntity; * @author Calclavia * */ -public interface IConnectionProvider extends IConnector +public interface INetworkConnection extends IConnector { /** @@ -20,8 +20,7 @@ public interface IConnectionProvider extends IConnector public TileEntity[] getAdjacentConnections(); /** - * Instantly refreshes all connected blocks around the conductor, recalculating the connected - * blocks. + * Refreshes the conductor */ - public void updateAdjacentConnections(); + public void refresh(); } diff --git a/common/universalelectricity/core/block/INetworkProvider.java b/common/universalelectricity/core/block/INetworkProvider.java index 64020439a..1e2a6c443 100644 --- a/common/universalelectricity/core/block/INetworkProvider.java +++ b/common/universalelectricity/core/block/INetworkProvider.java @@ -1,6 +1,6 @@ package universalelectricity.core.block; -import universalelectricity.core.electricity.IElectricityNetwork; +import universalelectricity.core.grid.IElectricityNetwork; /** * Applied to TileEntities that has an instance of an electricity network. diff --git a/common/universalelectricity/core/block/IVoltage.java b/common/universalelectricity/core/block/IVoltage.java deleted file mode 100644 index 5347be95e..000000000 --- a/common/universalelectricity/core/block/IVoltage.java +++ /dev/null @@ -1,17 +0,0 @@ -package universalelectricity.core.block; - -/** - * Applies to all objects that has a voltage. - * - * @author Calclavia - * - */ -public interface IVoltage -{ - /** - * Gets the voltage of this object. - * - * @return The amount of volts. E.g 120v or 240v - */ - public double getVoltage(); -} diff --git a/common/universalelectricity/core/electricity/ElectricalEvent.java b/common/universalelectricity/core/electricity/ElectricalEvent.java new file mode 100644 index 000000000..35b9a2962 --- /dev/null +++ b/common/universalelectricity/core/electricity/ElectricalEvent.java @@ -0,0 +1,61 @@ +package universalelectricity.core.electricity; + +import net.minecraft.tileentity.TileEntity; +import net.minecraft.world.World; +import net.minecraftforge.event.Cancelable; +import net.minecraftforge.event.Event; +import universalelectricity.core.block.IElectrical; + +public class ElectricalEvent extends Event +{ + /** + * Call this to have your TileEntity produce power into the network. + * + * @author Calclavia + * + */ + @Cancelable + public static class ElectricityProduceEvent extends ElectricalEvent + { + public World world; + public IElectrical tileEntity; + + public ElectricityProduceEvent(IElectrical tileEntity) + { + this.tileEntity = tileEntity; + this.world = ((TileEntity) this.tileEntity).worldObj; + } + } + + /** + * Internal Events + * + * @author Calclavia + * + */ + @Cancelable + public static class ElectricityProductionEvent extends ElectricalEvent + { + public ElectricityPack electricityPack; + public TileEntity[] ignoreTiles; + + public ElectricityProductionEvent(ElectricityPack electricityPack, TileEntity... ignoreTiles) + { + this.electricityPack = electricityPack; + this.ignoreTiles = ignoreTiles; + } + } + + public static class ElectricityRequestEvent extends ElectricalEvent + { + public ElectricityPack electricityPack; + public TileEntity[] ignoreTiles; + + public ElectricityRequestEvent(ElectricityPack electricityPack, TileEntity... ignoreTiles) + { + this.electricityPack = electricityPack; + this.ignoreTiles = ignoreTiles; + } + } + +} diff --git a/common/universalelectricity/core/electricity/ElectricityDisplay.java b/common/universalelectricity/core/electricity/ElectricityDisplay.java index bc003e162..56a20b4d9 100644 --- a/common/universalelectricity/core/electricity/ElectricityDisplay.java +++ b/common/universalelectricity/core/electricity/ElectricityDisplay.java @@ -8,6 +8,11 @@ package universalelectricity.core.electricity; public class ElectricityDisplay { + /** + * Universal Electricity's units are in KILOJOULES, KILOWATTS and KILOVOLTS. Try to make your + * energy ratio as close to real life as possible. + * + */ public static enum ElectricUnit { AMPERE("Amp", "I"), AMP_HOUR("Amp Hour", "Ah"), VOLTAGE("Volt", "V"), WATT("Watt", "W"), @@ -32,7 +37,7 @@ public class ElectricityDisplay public static enum MeasurementUnit { MICRO("Micro", "mi", 0.000001), MILLI("Milli", "m", 0.001), KILO("Kilo", "k", 1000), - MEGA("Mega", "M", 1000000); + MEGA("Mega", "M", 1000000), GIGA("Giga", "G", 1000000000); public String name; public String symbol; @@ -63,11 +68,21 @@ public class ElectricityDisplay } } + /** + * By default, mods should store energy in Kilo-Joules, hence a multiplier of 1/1000. + */ + public static String getDisplay(float value, ElectricUnit unit, int decimalPlaces, boolean isShort) + { + return getDisplay(value, unit, decimalPlaces, isShort, 1000); + } + /** * Displays the unit as text. Works only for positive numbers. */ - public static String getDisplay(double value, ElectricUnit unit, int decimalPlaces, boolean isShort) + public static String getDisplay(float value, ElectricUnit unit, int decimalPlaces, boolean isShort, float multiplier) { + value *= multiplier; + String unitName = unit.name; if (isShort) @@ -107,22 +122,22 @@ public class ElectricityDisplay return roundDecimals(value, decimalPlaces) + " " + unitName; } - public static String getDisplay(double value, ElectricUnit unit) + public static String getDisplay(float value, ElectricUnit unit) { return getDisplay(value, unit, 2, false); } - public static String getDisplayShort(double value, ElectricUnit unit) + public static String getDisplayShort(float value, ElectricUnit unit) { return getDisplay(value, unit, 2, true); } - public static String getDisplayShort(double value, ElectricUnit unit, int decimalPlaces) + public static String getDisplayShort(float value, ElectricUnit unit, int decimalPlaces) { return getDisplay(value, unit, decimalPlaces, true); } - public static String getDisplaySimple(double value, ElectricUnit unit, int decimalPlaces) + public static String getDisplaySimple(float value, ElectricUnit unit, int decimalPlaces) { if (value > 1) { diff --git a/common/universalelectricity/core/electricity/ElectricityHelper.java b/common/universalelectricity/core/electricity/ElectricityHelper.java new file mode 100644 index 000000000..e8b8b7eb8 --- /dev/null +++ b/common/universalelectricity/core/electricity/ElectricityHelper.java @@ -0,0 +1,206 @@ +package universalelectricity.core.electricity; + +import java.util.EnumSet; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Set; + +import net.minecraft.tileentity.TileEntity; +import net.minecraftforge.common.ForgeDirection; +import net.minecraftforge.event.ForgeSubscribe; +import universalelectricity.core.block.IConnector; +import universalelectricity.core.block.INetworkProvider; +import universalelectricity.core.electricity.ElectricalEvent.ElectricityProduceEvent; +import universalelectricity.core.grid.IElectricityNetwork; +import universalelectricity.core.vector.Vector3; +import universalelectricity.core.vector.VectorHelper; + +/** + * A helper class that provides additional useful functions to interact with the ElectricityNetwork + * + * @author Calclavia + * + */ +public class ElectricityHelper +{ + @ForgeSubscribe + public void onProduce(ElectricityProduceEvent evt) + { + // Needs work with shuffling to be able to evenly distribute to all + // connected networks + // instead of just defaulting to one of them. + Vector3 position = new Vector3((TileEntity) evt.tileEntity); + HashMap networks = new HashMap(); + + for (ForgeDirection direction : getDirections((TileEntity) evt.tileEntity)) + { + IElectricityNetwork network = getNetworkFromTileEntity(VectorHelper.getTileEntityFromSide(evt.world, position, direction), direction.getOpposite()); + + if (network != null) + { + networks.put(network, direction); + ElectricityPack provided = evt.tileEntity.provideElectricity(direction, network.getRequest((TileEntity) evt.tileEntity), true); + + if (provided != null && provided.getWatts() > 0) + { + network.produce(provided, (TileEntity) evt.tileEntity); + } + } + } + + /* + * ElectricityPack request = this.getNetwork().getRequest(this); + * + * if (request.getWatts() > 0) { List providedPacks = new + * ArrayList(); List tileEntities = new + * ArrayList(); + * + * for (ForgeDirection direction : ForgeDirection.VALID_DIRECTIONS) { Vector3 position = new + * Vector3(this).modifyPositionFromSide(direction); TileEntity tileEntity = + * position.getTileEntity(this.worldObj); + * + * if (tileEntity instanceof IElectrical) { tileEntities.add(tileEntity); IElectrical + * electrical = (IElectrical) tileEntity; + * + * if (electrical.canConnect(direction.getOpposite())) { if + * (electrical.getProvide(direction.getOpposite()) > 0) { providedPacks.add + * (electrical.provideElectricity(direction.getOpposite(), request, true)); } } } } + * + * ElectricityPack mergedPack = ElectricityPack.merge(providedPacks); + * + * if (mergedPack.getWatts() > 0) { this.getNetwork().produce(mergedPack, + * tileEntities.toArray(new TileEntity[0])); } } + */ + } + + public static EnumSet getDirections(TileEntity tileEntity) + { + EnumSet possibleSides = EnumSet.noneOf(ForgeDirection.class); + + if (tileEntity instanceof IConnector) + { + for (int i = 0; i < 6; i++) + { + ForgeDirection direction = ForgeDirection.getOrientation(i); + if (((IConnector) tileEntity).canConnect(direction)) + { + possibleSides.add(direction); + } + } + } + + return possibleSides; + } + + @Deprecated + public static ElectricityPack produceFromMultipleSides(TileEntity tileEntity, ElectricityPack electricityPack) + { + return ElectricityHelper.produceFromMultipleSides(tileEntity, getDirections(tileEntity), electricityPack); + } + + /** + * Produces electricity from all specified sides. Use this as a simple helper function. + * + * @param tileEntity - The TileEntity consuming the electricity. + * @param approachDirection - The sides in which you can connect to. + * @param producePack - The amount of electricity to be produced. + * @return What remained in the electricity pack. + */ + @Deprecated + public static ElectricityPack produceFromMultipleSides(TileEntity tileEntity, EnumSet approachingDirection, ElectricityPack producingPack) + { + ElectricityPack remainingElectricity = producingPack.clone(); + + if (tileEntity != null && approachingDirection != null) + { + final Set connectedNetworks = ElectricityHelper.getNetworksFromMultipleSides(tileEntity, approachingDirection); + + if (connectedNetworks.size() > 0) + { + /** + * Requests an even amount of electricity from all sides. + */ + float wattsPerSide = (producingPack.getWatts() / connectedNetworks.size()); + float voltage = producingPack.voltage; + + for (IElectricityNetwork network : connectedNetworks) + { + if (wattsPerSide > 0 && producingPack.getWatts() > 0) + { + float amperes = Math.min(wattsPerSide / voltage, network.getRequest(tileEntity).getWatts() / voltage); + + if (amperes > 0) + { + network.produce(new ElectricityPack(amperes, voltage)); + remainingElectricity.amperes -= amperes; + } + } + } + } + } + + return remainingElectricity; + } + + /** + * @param tileEntity - The TileEntity's sides. + * @param approachingDirection - The directions that can be connected. + * @return A list of networks from all specified sides. There will be no repeated + * ElectricityNetworks and it will never return null. + */ + public static Set getNetworksFromMultipleSides(TileEntity tileEntity, EnumSet approachingDirection) + { + final Set connectedNetworks = new HashSet(); + + for (ForgeDirection side : ForgeDirection.VALID_DIRECTIONS) + { + if (approachingDirection.contains(side)) + { + Vector3 position = new Vector3(tileEntity); + position.modifyPositionFromSide(side); + + TileEntity outputConductor = position.getTileEntity(tileEntity.worldObj); + IElectricityNetwork electricityNetwork = ElectricityHelper.getNetworkFromTileEntity(outputConductor, side); + + if (electricityNetwork != null) + { + connectedNetworks.add(electricityNetwork); + } + } + } + + return connectedNetworks; + } + + /** + * Tries to find the electricity network based in a tile entity and checks to see if it is a + * conductor. All machines should use this function to search for a connecting conductor around + * it. + * + * @param conductor - The TileEntity conductor + * @param approachDirection - The direction you are approaching this wire from. + * @return The ElectricityNetwork or null if not found. + */ + public static IElectricityNetwork getNetworkFromTileEntity(TileEntity tileEntity, ForgeDirection approachDirection) + { + if (tileEntity != null) + { + if (tileEntity instanceof INetworkProvider) + { + if (tileEntity instanceof IConnector) + { + if (((IConnector) tileEntity).canConnect(approachDirection.getOpposite())) + { + return ((INetworkProvider) tileEntity).getNetwork(); + } + } + else + { + return ((INetworkProvider) tileEntity).getNetwork(); + } + } + } + + return null; + } +} diff --git a/common/universalelectricity/core/electricity/ElectricityNetwork.java b/common/universalelectricity/core/electricity/ElectricityNetwork.java deleted file mode 100644 index f2fdb53c9..000000000 --- a/common/universalelectricity/core/electricity/ElectricityNetwork.java +++ /dev/null @@ -1,511 +0,0 @@ -package universalelectricity.core.electricity; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.Set; - -import net.minecraft.tileentity.TileEntity; -import net.minecraftforge.common.ForgeDirection; -import universalelectricity.core.block.IConductor; -import universalelectricity.core.block.IConnectionProvider; -import universalelectricity.core.block.INetworkProvider; -import universalelectricity.core.path.Pathfinder; -import universalelectricity.core.path.PathfinderChecker; -import universalelectricity.core.vector.Vector3; -import universalelectricity.core.vector.VectorHelper; -import cpw.mods.fml.common.FMLLog; - -/** - * An Electrical Network specifies a wire connection. Each wire connection line will have its own - * electrical network. Do not include this class if you do not intend to have custom wires in your - * mod. This will increase future compatibility. - * - * @author Calclavia - * - */ -public class ElectricityNetwork implements IElectricityNetwork -{ - private final HashMap producers = new HashMap(); - private final HashMap consumers = new HashMap(); - - private final Set conductors = new HashSet(); - - public ElectricityNetwork() - { - - } - - public ElectricityNetwork(IConductor... conductors) - { - this.conductors.addAll(Arrays.asList(conductors)); - } - - @Override - public void startProducing(TileEntity tileEntity, ElectricityPack electricityPack) - { - if (tileEntity != null && electricityPack.getWatts() > 0) - { - this.producers.put(tileEntity, electricityPack); - } - } - - @Override - public void startProducing(TileEntity tileEntity, double amperes, double voltage) - { - this.startProducing(tileEntity, new ElectricityPack(amperes, voltage)); - } - - @Override - public boolean isProducing(TileEntity tileEntity) - { - return this.producers.containsKey(tileEntity); - } - - /** - * Sets this tile entity to stop producing energy in this network. - */ - @Override - public void stopProducing(TileEntity tileEntity) - { - this.producers.remove(tileEntity); - } - - /** - * Sets this tile entity to start producing energy in this network. - */ - @Override - public void startRequesting(TileEntity tileEntity, ElectricityPack electricityPack) - { - if (tileEntity != null && electricityPack.getWatts() > 0) - { - this.consumers.put(tileEntity, electricityPack); - } - } - - @Override - public void startRequesting(TileEntity tileEntity, double amperes, double voltage) - { - this.startRequesting(tileEntity, new ElectricityPack(amperes, voltage)); - } - - @Override - public boolean isRequesting(TileEntity tileEntity) - { - return this.consumers.containsKey(tileEntity); - } - - /** - * Sets this tile entity to stop producing energy in this network. - */ - @Override - public void stopRequesting(TileEntity tileEntity) - { - this.consumers.remove(tileEntity); - } - - /** - * @param ignoreTiles The TileEntities to ignore during this calculation. Null will make it not - * ignore any. - * @return The electricity produced in this electricity network - */ - @Override - public ElectricityPack getProduced(TileEntity... ignoreTiles) - { - ElectricityPack totalElectricity = new ElectricityPack(0, 0); - - Iterator it = this.producers.entrySet().iterator(); - - loop: - while (it.hasNext()) - { - Map.Entry pairs = (Map.Entry) it.next(); - - if (pairs != null) - { - TileEntity tileEntity = (TileEntity) pairs.getKey(); - - if (tileEntity == null) - { - it.remove(); - continue; - } - - if (tileEntity.isInvalid()) - { - it.remove(); - continue; - } - - if (tileEntity.worldObj.getBlockTileEntity(tileEntity.xCoord, tileEntity.yCoord, tileEntity.zCoord) != tileEntity) - { - it.remove(); - continue; - } - - if (ignoreTiles != null) - { - for (TileEntity ignoreTile : ignoreTiles) - { - if (tileEntity == ignoreTile) - { - continue loop; - } - } - } - - ElectricityPack pack = (ElectricityPack) pairs.getValue(); - - if (pairs.getKey() != null && pairs.getValue() != null && pack != null) - { - double newWatts = totalElectricity.getWatts() + pack.getWatts(); - double newVoltage = Math.max(totalElectricity.voltage, pack.voltage); - - totalElectricity.amperes = newWatts / newVoltage; - totalElectricity.voltage = newVoltage; - } - } - } - - return totalElectricity; - } - - /** - * @return How much electricity this network needs. - */ - @Override - public ElectricityPack getRequest(TileEntity... ignoreTiles) - { - ElectricityPack totalElectricity = this.getRequestWithoutReduction(); - totalElectricity.amperes = Math.max(totalElectricity.amperes - this.getProduced(ignoreTiles).amperes, 0); - return totalElectricity; - } - - @Override - public ElectricityPack getRequestWithoutReduction() - { - ElectricityPack totalElectricity = new ElectricityPack(0, 0); - - Iterator it = this.consumers.entrySet().iterator(); - - while (it.hasNext()) - { - Map.Entry pairs = (Map.Entry) it.next(); - - if (pairs != null) - { - TileEntity tileEntity = (TileEntity) pairs.getKey(); - - if (tileEntity == null) - { - it.remove(); - continue; - } - - if (tileEntity.isInvalid()) - { - it.remove(); - continue; - } - - if (tileEntity.worldObj.getBlockTileEntity(tileEntity.xCoord, tileEntity.yCoord, tileEntity.zCoord) != tileEntity) - { - it.remove(); - continue; - } - - ElectricityPack pack = (ElectricityPack) pairs.getValue(); - - if (pack != null) - { - totalElectricity.amperes += pack.amperes; - totalElectricity.voltage = Math.max(totalElectricity.voltage, pack.voltage); - } - } - } - - return totalElectricity; - } - - /** - * @param tileEntity - * @return The electricity being input into this tile entity. - */ - @Override - public ElectricityPack consumeElectricity(TileEntity tileEntity) - { - ElectricityPack totalElectricity = new ElectricityPack(0, 0); - - try - { - ElectricityPack tileRequest = this.consumers.get(tileEntity); - - if (this.consumers.containsKey(tileEntity) && tileRequest != null) - { - // Calculate the electricity this TileEntity is receiving in percentage. - totalElectricity = this.getProduced(); - - if (totalElectricity.getWatts() > 0) - { - ElectricityPack totalRequest = this.getRequestWithoutReduction(); - totalElectricity.amperes *= (tileRequest.amperes / totalRequest.amperes); - - double ampsReceived = totalElectricity.amperes - (totalElectricity.amperes * totalElectricity.amperes * this.getTotalResistance()) / totalElectricity.voltage; - double voltsReceived = totalElectricity.voltage - (totalElectricity.amperes * this.getTotalResistance()); - - totalElectricity.amperes = ampsReceived; - totalElectricity.voltage = voltsReceived; - - return totalElectricity; - } - } - } - catch (Exception e) - { - FMLLog.severe("Failed to consume electricity!"); - e.printStackTrace(); - } - - return totalElectricity; - } - - /** - * @return Returns all producers in this electricity network. - */ - @Override - public HashMap getProducers() - { - return this.producers; - } - - /** - * Gets all the electricity receivers. - */ - @Override - public List getProviders() - { - List providers = new ArrayList(); - providers.addAll(this.producers.keySet()); - return providers; - } - - /** - * @return Returns all consumers in this electricity network. - */ - @Override - public HashMap getConsumers() - { - return this.consumers; - } - - /** - * Gets all the electricity receivers. - */ - @Override - public List getReceivers() - { - List receivers = new ArrayList(); - receivers.addAll(this.consumers.keySet()); - return receivers; - } - - @Override - public void cleanUpConductors() - { - Iterator it = this.conductors.iterator(); - - while (it.hasNext()) - { - IConductor conductor = (IConductor) it.next(); - - if (conductor == null) - { - it.remove(); - } - else if (((TileEntity) conductor).isInvalid()) - { - it.remove(); - } - else - { - conductor.setNetwork(this); - } - } - } - - /** - * This function is called to refresh all conductors in this network - */ - @Override - public void refreshConductors() - { - this.cleanUpConductors(); - - try - { - Iterator it = this.conductors.iterator(); - - while (it.hasNext()) - { - IConductor conductor = it.next(); - conductor.updateAdjacentConnections(); - } - } - catch (Exception e) - { - FMLLog.severe("Universal Electricity: Failed to refresh conductor."); - e.printStackTrace(); - } - } - - @Override - public double getTotalResistance() - { - double resistance = 0; - - for (IConductor conductor : this.conductors) - { - resistance += conductor.getResistance(); - } - - return resistance; - } - - @Override - public double getLowestCurrentCapacity() - { - double lowestAmp = 0; - - for (IConductor conductor : this.conductors) - { - if (lowestAmp == 0 || conductor.getCurrentCapcity() < lowestAmp) - { - lowestAmp = conductor.getCurrentCapcity(); - } - } - - return lowestAmp; - } - - @Override - public Set getConductors() - { - return this.conductors; - } - - @Override - public void mergeConnection(IElectricityNetwork network) - { - if (network != null && network != this) - { - ElectricityNetwork newNetwork = new ElectricityNetwork(); - newNetwork.getConductors().addAll(this.getConductors()); - newNetwork.getConductors().addAll(network.getConductors()); - newNetwork.cleanUpConductors(); - } - } - - @Override - public void splitNetwork(IConnectionProvider splitPoint) - { - if (splitPoint instanceof TileEntity) - { - this.getConductors().remove(splitPoint); - - for (ForgeDirection dir : ForgeDirection.values()) - { - if (dir != ForgeDirection.UNKNOWN) - { - Vector3 splitVec = new Vector3((TileEntity) splitPoint); - TileEntity tileAroundSplit = VectorHelper.getTileEntityFromSide(((TileEntity) splitPoint).worldObj, splitVec, dir); - - if (this.producers.containsKey(tileAroundSplit)) - { - this.stopProducing(tileAroundSplit); - this.stopRequesting(tileAroundSplit); - } - } - } - - /** - * Loop through the connected blocks and attempt to see if there are connections between - * the two points elsewhere. - */ - TileEntity[] connectedBlocks = splitPoint.getAdjacentConnections(); - - for (int i = 0; i < connectedBlocks.length; i++) - { - TileEntity connectedBlockA = connectedBlocks[i]; - - if (connectedBlockA instanceof IConnectionProvider) - { - for (int ii = 0; ii < connectedBlocks.length; ii++) - { - final TileEntity connectedBlockB = connectedBlocks[ii]; - - if (connectedBlockA != connectedBlockB && connectedBlockB instanceof IConnectionProvider) - { - Pathfinder finder = new PathfinderChecker(((TileEntity) splitPoint).worldObj, (IConnectionProvider) connectedBlockB, splitPoint); - finder.init(new Vector3(connectedBlockA)); - - if (finder.results.size() > 0) - { - /** - * The connections A and B are still intact elsewhere. Set all - * references of wire connection into one network. - */ - - for (Vector3 node : finder.closedSet) - { - TileEntity nodeTile = node.getTileEntity(((TileEntity) splitPoint).worldObj); - - if (nodeTile instanceof INetworkProvider) - { - if (nodeTile != splitPoint) - { - ((INetworkProvider) nodeTile).setNetwork(this); - } - } - } - } - else - { - /** - * The connections A and B are not connected anymore. Give both of - * them a new network. - */ - IElectricityNetwork newNetwork = new ElectricityNetwork(); - - for (Vector3 node : finder.closedSet) - { - TileEntity nodeTile = node.getTileEntity(((TileEntity) splitPoint).worldObj); - - if (nodeTile instanceof INetworkProvider) - { - if (nodeTile != splitPoint) - { - newNetwork.getConductors().add((IConductor) nodeTile); - } - } - } - - newNetwork.cleanUpConductors(); - } - } - } - } - } - } - } - - @Override - public String toString() - { - return "ElectricityNetwork[" + this.hashCode() + "|Wires:" + this.conductors.size() + "]"; - } - -} diff --git a/common/universalelectricity/core/electricity/ElectricityNetworkHelper.java b/common/universalelectricity/core/electricity/ElectricityNetworkHelper.java deleted file mode 100644 index 41d22bf2a..000000000 --- a/common/universalelectricity/core/electricity/ElectricityNetworkHelper.java +++ /dev/null @@ -1,230 +0,0 @@ -package universalelectricity.core.electricity; - -import java.util.ArrayList; -import java.util.EnumSet; -import java.util.List; - -import net.minecraft.tileentity.TileEntity; -import net.minecraftforge.common.ForgeDirection; -import universalelectricity.core.block.IConnector; -import universalelectricity.core.block.INetworkProvider; -import universalelectricity.core.vector.Vector3; -import universalelectricity.core.vector.VectorHelper; - -/** - * A helper class that provides additional useful functions to interact with the ElectricityNetwork - * - * @author Calclavia - * - */ -public class ElectricityNetworkHelper -{ - - /** - * Invalidates a TileEntity from the electrical network, thereby removing it from all - * electricity network that are adjacent to it. - */ - public static void invalidate(TileEntity tileEntity) - { - for (int i = 0; i < 6; i++) - { - ForgeDirection direction = ForgeDirection.getOrientation(i); - TileEntity checkTile = VectorHelper.getConnectorFromSide(tileEntity.worldObj, new Vector3(tileEntity), direction); - - if (checkTile instanceof INetworkProvider) - { - IElectricityNetwork network = ((INetworkProvider) checkTile).getNetwork(); - - if (network != null) - { - network.stopRequesting(tileEntity); - network.stopProducing(tileEntity); - } - } - } - } - - public static EnumSet getDirections(TileEntity tileEntity) - { - EnumSet possibleSides = EnumSet.noneOf(ForgeDirection.class); - - if (tileEntity instanceof IConnector) - { - for (int i = 0; i < 6; i++) - { - ForgeDirection direction = ForgeDirection.getOrientation(i); - if (((IConnector) tileEntity).canConnect(direction)) - { - possibleSides.add(direction); - } - } - } - - return possibleSides; - } - - public static ElectricityPack produceFromMultipleSides(TileEntity tileEntity, ElectricityPack electricityPack) - { - return ElectricityNetworkHelper.produceFromMultipleSides(tileEntity, getDirections(tileEntity), electricityPack); - } - - /** - * Produces electricity from all specified sides. Use this as a simple helper function. - * - * @param tileEntity- The TileEntity consuming the electricity. - * @param approachDirection - The sides in which you can connect to. - * @param producePack - The amount of electricity to be produced. - * @return What remained in the electricity pack. - */ - public static ElectricityPack produceFromMultipleSides(TileEntity tileEntity, EnumSet approachingDirection, ElectricityPack producingPack) - { - ElectricityPack remainingElectricity = producingPack.clone(); - - if (tileEntity != null && approachingDirection != null) - { - final List connectedNetworks = ElectricityNetworkHelper.getNetworksFromMultipleSides(tileEntity, approachingDirection); - - if (connectedNetworks.size() > 0) - { - /** - * Requests an even amount of electricity from all sides. - */ - double wattsPerSide = (producingPack.getWatts() / connectedNetworks.size()); - double voltage = producingPack.voltage; - - for (IElectricityNetwork network : connectedNetworks) - { - if (wattsPerSide > 0 && producingPack.getWatts() > 0) - { - double amperes = Math.min(wattsPerSide / voltage, network.getRequest(tileEntity).amperes); - - if (amperes > 0) - { - network.startProducing(tileEntity, amperes, voltage); - remainingElectricity.amperes -= amperes; - } - } - else - { - network.stopProducing(tileEntity); - } - } - } - } - - return remainingElectricity; - } - - public static ElectricityPack consumeFromMultipleSides(TileEntity tileEntity, ElectricityPack electricityPack) - { - return ElectricityNetworkHelper.consumeFromMultipleSides(tileEntity, getDirections(tileEntity), electricityPack); - } - - /** - * Requests and attempts to consume electricity from all specified sides. Use this as a simple - * helper function. - * - * @param tileEntity- The TileEntity consuming the electricity. - * @param approachDirection - The sides in which you can connect. - * @param requestPack - The amount of electricity to be requested. - * @return The consumed ElectricityPack. - */ - public static ElectricityPack consumeFromMultipleSides(TileEntity tileEntity, EnumSet approachingDirection, ElectricityPack requestPack) - { - ElectricityPack consumedPack = new ElectricityPack(); - - if (tileEntity != null && approachingDirection != null) - { - final List connectedNetworks = ElectricityNetworkHelper.getNetworksFromMultipleSides(tileEntity, approachingDirection); - - if (connectedNetworks.size() > 0) - { - /** - * Requests an even amount of electricity from all sides. - */ - double wattsPerSide = (requestPack.getWatts() / connectedNetworks.size()); - double voltage = requestPack.voltage; - - for (IElectricityNetwork network : connectedNetworks) - { - if (wattsPerSide > 0 && requestPack.getWatts() > 0) - { - network.startRequesting(tileEntity, wattsPerSide / voltage, voltage); - ElectricityPack receivedPack = network.consumeElectricity(tileEntity); - consumedPack.amperes += receivedPack.amperes; - consumedPack.voltage = Math.max(consumedPack.voltage, receivedPack.voltage); - } - else - { - network.stopRequesting(tileEntity); - } - } - } - } - - return consumedPack; - } - - /** - * @param tileEntity - The TileEntity's sides. - * @param approachingDirection - The directions that can be connected. - * @return A list of networks from all specified sides. There will be no repeated - * ElectricityNetworks and it will never return null. - */ - public static List getNetworksFromMultipleSides(TileEntity tileEntity, EnumSet approachingDirection) - { - final List connectedNetworks = new ArrayList(); - - for (int i = 0; i < 6; i++) - { - ForgeDirection direction = ForgeDirection.getOrientation(i); - - if (approachingDirection.contains(direction)) - { - Vector3 position = new Vector3(tileEntity); - position.modifyPositionFromSide(direction); - TileEntity outputConductor = position.getTileEntity(tileEntity.worldObj); - IElectricityNetwork electricityNetwork = ElectricityNetworkHelper.getNetworkFromTileEntity(outputConductor, direction); - - if (electricityNetwork != null && !connectedNetworks.contains(connectedNetworks)) - { - connectedNetworks.add(electricityNetwork); - } - } - } - - return connectedNetworks; - } - - /** - * Tries to find the electricity network based in a tile entity and checks to see if it is a - * conductor. All machines should use this function to search for a connecting conductor around - * it. - * - * @param conductor - The TileEntity conductor - * @param approachDirection - The direction you are approaching this wire from. - * @return The ElectricityNetwork or null if not found. - */ - public static IElectricityNetwork getNetworkFromTileEntity(TileEntity tileEntity, ForgeDirection approachDirection) - { - if (tileEntity != null) - { - if (tileEntity instanceof INetworkProvider) - { - if (tileEntity instanceof IConnector) - { - if (((IConnector) tileEntity).canConnect(approachDirection.getOpposite())) - { - return ((INetworkProvider) tileEntity).getNetwork(); - } - } - else - { - return ((INetworkProvider) tileEntity).getNetwork(); - } - } - } - - return null; - } -} diff --git a/common/universalelectricity/core/electricity/ElectricityPack.java b/common/universalelectricity/core/electricity/ElectricityPack.java index 218ce8c55..0bf6fded6 100644 --- a/common/universalelectricity/core/electricity/ElectricityPack.java +++ b/common/universalelectricity/core/electricity/ElectricityPack.java @@ -1,5 +1,7 @@ package universalelectricity.core.electricity; +import java.util.List; + /** * A simple way to store electrical data. * @@ -8,10 +10,10 @@ package universalelectricity.core.electricity; */ public class ElectricityPack implements Cloneable { - public double amperes; - public double voltage; + public float amperes; + public float voltage; - public ElectricityPack(double amperes, double voltage) + public ElectricityPack(float amperes, float voltage) { this.amperes = amperes; this.voltage = voltage; @@ -22,92 +24,155 @@ public class ElectricityPack implements Cloneable this(0, 0); } - public static ElectricityPack getFromWatts(double watts, double voltage) + public static ElectricityPack getFromWatts(float watts, float voltage) { return new ElectricityPack(watts / voltage, voltage); } - public double getWatts() + /** + * Merges multiple ElectricityPacks together to form one with an average voltage. + */ + public static ElectricityPack merge(ElectricityPack... packs) + { + float totalEnergy = 0; + float totalVoltage = 0; + + for (ElectricityPack pack : packs) + { + totalEnergy += pack.getWatts(); + totalVoltage += pack.voltage; + } + + if (totalEnergy <= 0 || totalVoltage <= 0) + { + return new ElectricityPack(); + } + + return ElectricityPack.getFromWatts(totalEnergy, totalVoltage / packs.length); + } + + public static ElectricityPack merge(List providedPacks) + { + return merge(providedPacks.toArray(new ElectricityPack[0])); + } + + /** + * @return Returns the ElectricityPack with the largest amount of energy. + */ + public static ElectricityPack max(ElectricityPack... packs) + { + ElectricityPack optimalPack = null; + + for (ElectricityPack pack : packs) + { + if (optimalPack == null || (optimalPack != null && pack.getWatts() > optimalPack.getWatts())) + { + optimalPack = pack; + } + } + + return optimalPack; + } + + /** + * @return Returns the ElectricityPack with the smallest amount of energy. + */ + public static ElectricityPack min(ElectricityPack... packs) + { + ElectricityPack optimalPack = null; + + for (ElectricityPack pack : packs) + { + if (optimalPack == null || (optimalPack != null && pack.getWatts() < optimalPack.getWatts())) + { + optimalPack = pack; + } + } + + return optimalPack; + } + + public float getWatts() { return getWatts(amperes, voltage); } - public double getConductance() + public float getConductance() { return getConductance(amperes, voltage); } - public double getResistance() + public float getResistance() { return getResistance(amperes, voltage); } - public static double getJoules(double watts, double seconds) + public static float getJoules(float watts, float seconds) { return watts * seconds; } - public static double getJoules(double amps, double voltage, double seconds) + public static float getJoules(float amps, float voltage, float seconds) { return amps * voltage * seconds; } - public static double getWattsFromJoules(double joules, double seconds) + public static float getWattsFromJoules(float joules, float seconds) { return joules / seconds; } - public static double getAmps(double watts, double voltage) + public static float getAmps(float watts, float voltage) { return watts / voltage; } - public static double getAmps(double ampHours) + public static float getAmps(float ampHours) { return ampHours * 3600; } - public static double getAmpsFromWattHours(double wattHours, double voltage) + public static float getAmpsFromWattHours(float wattHours, float voltage) { return getWatts(wattHours) / voltage; } - public static double getWattHoursFromAmpHours(double ampHours, double voltage) + public static float getWattHoursFromAmpHours(float ampHours, float voltage) { return ampHours * voltage; } - public static double getAmpHours(double amps) + public static float getAmpHours(float amps) { return amps / 3600; } - public static double getWatts(double amps, double voltage) + public static float getWatts(float amps, float voltage) { return amps * voltage; } - public static double getWatts(double wattHours) + public static float getWatts(float wattHours) { return wattHours * 3600; } - public static double getWattHours(double watts) + public static float getWattHours(float watts) { return watts / 3600; } - public static double getWattHours(double amps, double voltage) + public static float getWattHours(float amps, float voltage) { return getWattHours(getWatts(amps, voltage)); } - public static double getResistance(double amps, double voltage) + public static float getResistance(float amps, float voltage) { return voltage / amps; } - public static double getConductance(double amps, double voltage) + public static float getConductance(float amps, float voltage) { return amps / voltage; } diff --git a/common/universalelectricity/core/electricity/IConductorRegistry.java b/common/universalelectricity/core/electricity/IConductorRegistry.java deleted file mode 100644 index 41f210f86..000000000 --- a/common/universalelectricity/core/electricity/IConductorRegistry.java +++ /dev/null @@ -1,17 +0,0 @@ -package universalelectricity.core.electricity; - -import java.util.List; - -import universalelectricity.core.block.IConductor; - -public interface IConductorRegistry -{ - - void register(IConductor conductor); - - void cleanConductors(); - - void resetAllConnections(); - - List getConductors(); -} diff --git a/common/universalelectricity/core/electricity/IElectricityNetwork.java b/common/universalelectricity/core/electricity/IElectricityNetwork.java deleted file mode 100644 index 3667141fb..000000000 --- a/common/universalelectricity/core/electricity/IElectricityNetwork.java +++ /dev/null @@ -1,138 +0,0 @@ -package universalelectricity.core.electricity; - -import java.util.HashMap; -import java.util.List; -import java.util.Set; - -import net.minecraft.tileentity.TileEntity; -import universalelectricity.core.block.IConductor; -import universalelectricity.core.block.IConnectionProvider; - -/** - * The Electrical Network in interface form. - * - * @author Calclavia - * - */ -public interface IElectricityNetwork -{ - /** - * Sets this TileEntity to start producing energy in this network. - */ - public void startProducing(TileEntity tileEntity, ElectricityPack electricityPack); - - public void startProducing(TileEntity tileEntity, double amperes, double voltage); - - /** - * Is this TileEntity producing electricity? - */ - public boolean isProducing(TileEntity tileEntity); - - /** - * Stops the TileEntity from producing electricity. - */ - public void stopProducing(TileEntity tileEntity); - - /** - * Sets a TileEntity to start requesting electricity from the network. - */ - public void startRequesting(TileEntity tileEntity, ElectricityPack electricityPack); - - public void startRequesting(TileEntity tileEntity, double amperes, double voltage); - - /** - * Is this TileEntity requesting electricity? - */ - public boolean isRequesting(TileEntity tileEntity); - - /** - * Stops the TileEntity from requesting electricity from the network. - */ - public void stopRequesting(TileEntity tileEntity); - - /** - * Gets the total amount of electricity produced in the electricity network. - * - * @param ignoreTiles The TileEntities to ignore during this calculation (optional). - */ - public ElectricityPack getProduced(TileEntity... ignoreTiles); - - /** - * Gets the total amount of electricity requested in the electricity network. Takes account of - * electricity being produced in the network. - * - * @param ignoreTiles The TileEntities to ignore during this calculation (optional). - */ - public ElectricityPack getRequest(TileEntity... ignoreTiles); - - /** - * Gets the total amount of electricity requested WITHOUT accounting in the electricity already - * being produced. - */ - public ElectricityPack getRequestWithoutReduction(); - - /** - * Attemps to consume electricity for this TileEntity based on what was requested. - * - * @return The actual amount of electricity consumed. - */ - public ElectricityPack consumeElectricity(TileEntity tileEntity); - - /** - * @return Gets a list of TileEntities currently producing electricity in the network. - * - */ - public HashMap getProducers(); - - public List getProviders(); - - /** - * @return Gets a list of TileEntities currently receiving electricity from the network. - * - */ - public HashMap getConsumers(); - - public List getReceivers(); - - /** - * @return A list of all conductors in this electrical network. - */ - public Set getConductors(); - - /** - * @return The total amount of resistance of this electrical network. In Ohms. - */ - public double getTotalResistance(); - - /** - * @return The lowest amount of current (amperage) that this electrical network can tolerate. - */ - public double getLowestCurrentCapacity(); - - /** - * Cleans up and updates the list of conductors in the electricity network, removing dead ones. - */ - public void cleanUpConductors(); - - /** - * Refreshes and recalculates wire connections in this electrical network. - * - */ - public void refreshConductors(); - - /** - * Merges another electrical network into this one, destroying the other network's existence. - * - * @param network - */ - public void mergeConnection(IElectricityNetwork network); - - /** - * Splits the electricity network at a given TileEntity position. Called usually when a wire is - * broken to split the electrical network. - * - * @param splitPoint - The TileEntity that is being split. - */ - public void splitNetwork(IConnectionProvider splitPoint); - -} diff --git a/common/universalelectricity/core/electricity/NetworkLoader.java b/common/universalelectricity/core/electricity/NetworkLoader.java new file mode 100644 index 000000000..08560cfc7 --- /dev/null +++ b/common/universalelectricity/core/electricity/NetworkLoader.java @@ -0,0 +1,64 @@ +package universalelectricity.core.electricity; + +import java.util.Arrays; +import java.util.HashSet; +import java.util.Set; + +import universalelectricity.core.block.IConductor; +import universalelectricity.core.grid.IElectricityNetwork; +import cpw.mods.fml.common.FMLLog; + +@SuppressWarnings("unchecked") +public class NetworkLoader +{ + /** + * The default IElectricityNetwork used for primary electrical networks. + */ + public static Class NETWORK_CLASS; + public static final Set> NETWORK_CLASS_REGISTRY = new HashSet>(); + + static + { + setNetworkClass("universalelectricity.core.grid.ElectricityNetwork"); + } + + public static void setNetworkClass(Class networkClass) + { + NETWORK_CLASS_REGISTRY.add(networkClass); + NETWORK_CLASS = networkClass; + } + + public static void setNetworkClass(String className) + { + try + { + setNetworkClass((Class) Class.forName(className)); + } + catch (Exception e) + { + FMLLog.severe("Universal Electricity: Failed to set network class with name " + className); + e.printStackTrace(); + } + } + + public static IElectricityNetwork getNewNetwork(IConductor... conductors) + { + try + { + IElectricityNetwork network = NETWORK_CLASS.newInstance(); + network.getConductors().addAll(Arrays.asList(conductors)); + return network; + } + catch (InstantiationException e) + { + e.printStackTrace(); + } + catch (IllegalAccessException e) + { + e.printStackTrace(); + } + + return null; + } + +} \ No newline at end of file diff --git a/common/universalelectricity/core/grid/ElectricityNetwork.java b/common/universalelectricity/core/grid/ElectricityNetwork.java new file mode 100644 index 000000000..ef695f125 --- /dev/null +++ b/common/universalelectricity/core/grid/ElectricityNetwork.java @@ -0,0 +1,353 @@ +package universalelectricity.core.grid; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import net.minecraft.tileentity.TileEntity; +import net.minecraftforge.common.ForgeDirection; +import net.minecraftforge.common.MinecraftForge; +import universalelectricity.core.block.IConductor; +import universalelectricity.core.block.IConnector; +import universalelectricity.core.block.IElectrical; +import universalelectricity.core.block.INetworkConnection; +import universalelectricity.core.block.INetworkProvider; +import universalelectricity.core.electricity.ElectricalEvent.ElectricityProductionEvent; +import universalelectricity.core.electricity.ElectricalEvent.ElectricityRequestEvent; +import universalelectricity.core.electricity.ElectricityPack; +import universalelectricity.core.path.Pathfinder; +import universalelectricity.core.path.PathfinderChecker; +import universalelectricity.core.vector.Vector3; +import universalelectricity.core.vector.VectorHelper; +import cpw.mods.fml.common.FMLLog; + +/** + * An Electrical Network specifies a wire connection. Each wire connection line will have its own + * electrical network. + * + * !! Do not include this class if you do not intend to have custom wires in your mod. This will + * increase future compatibility. !! + * + * @author Calclavia + * + */ +public class ElectricityNetwork implements IElectricityNetwork +{ + public Map> electricalTiles = new HashMap>(); + + private final Set conductors = new HashSet(); + + @Override + public float produce(ElectricityPack electricity, TileEntity... ignoreTiles) + { + ElectricityProductionEvent evt = new ElectricityProductionEvent(electricity, ignoreTiles); + MinecraftForge.EVENT_BUS.post(evt); + + float energy = electricity.getWatts(); + float totalEnergy = energy; + float voltage = electricity.voltage; + + if (!evt.isCanceled()) + { + Set avaliableEnergyTiles = this.getAcceptors(); + + if (!avaliableEnergyTiles.isEmpty()) + { + final float totalEnergyRequest = this.getRequest(ignoreTiles).getWatts(); + + if (totalEnergyRequest > 0) + { + for (TileEntity tileEntity : avaliableEnergyTiles) + { + if (tileEntity instanceof IElectrical && !Arrays.asList(ignoreTiles).contains(tileEntity)) + { + IElectrical electricalTile = (IElectrical) tileEntity; + + for (ForgeDirection direction : ForgeDirection.VALID_DIRECTIONS) + { + if (electricalTile.canConnect(direction) && this.getConductors().contains(VectorHelper.getConnectorFromSide(tileEntity.worldObj, new Vector3(tileEntity), direction))) + { + float energyToSend = totalEnergy * (electricalTile.getRequest(direction) / totalEnergyRequest); + + if (energyToSend > 0) + { + ElectricityPack electricityToSend = ElectricityPack.getFromWatts(energyToSend, voltage); + + // Calculate energy loss caused by resistance. + float ampsReceived = electricityToSend.amperes - (electricityToSend.amperes * electricityToSend.amperes * this.getTotalResistance()) / electricityToSend.voltage; + float voltsReceived = electricityToSend.voltage - (electricityToSend.amperes * this.getTotalResistance()); + + electricityToSend = new ElectricityPack(ampsReceived, voltsReceived); + + energy -= ((IElectrical) tileEntity).receiveElectricity(direction, electricityToSend, true); + } + } + } + } + } + } + } + } + + return energy; + } + + /** + * @return How much electricity this network needs. + */ + @Override + public ElectricityPack getRequest(TileEntity... ignoreTiles) + { + List requests = new ArrayList(); + + Iterator it = this.getAcceptors().iterator(); + + while (it.hasNext()) + { + TileEntity tileEntity = it.next(); + + if (Arrays.asList(ignoreTiles).contains(tileEntity)) + { + continue; + } + + if (tileEntity instanceof IElectrical) + { + if (!tileEntity.isInvalid()) + { + if (tileEntity.worldObj.getBlockTileEntity(tileEntity.xCoord, tileEntity.yCoord, tileEntity.zCoord) == tileEntity) + { + for (ForgeDirection direction : ForgeDirection.VALID_DIRECTIONS) + { + if (((IElectrical) tileEntity).canConnect(direction) && this.getConductors().contains(VectorHelper.getConnectorFromSide(tileEntity.worldObj, new Vector3(tileEntity), direction))) + { + requests.add(ElectricityPack.getFromWatts(((IElectrical) tileEntity).getRequest(direction), ((IElectrical) tileEntity).getVoltage())); + continue; + } + } + } + } + } + } + + ElectricityPack mergedPack = ElectricityPack.merge(requests); + ElectricityRequestEvent evt = new ElectricityRequestEvent(mergedPack, ignoreTiles); + MinecraftForge.EVENT_BUS.post(evt); + return mergedPack; + } + + /** + * @return Returns all producers in this electricity network. + */ + @Override + public Set getAcceptors() + { + return this.electricalTiles.keySet(); + } + + /** + * @param tile The tile to get connections for + * @return The list of directions that can be connected to for the provided tile + */ + @Override + public ArrayList getPossibleDirections(TileEntity tile) + { + return this.electricalTiles.containsKey(tile) ? this.electricalTiles.get(tile) : null; + } + + /** + * This function is called to refresh all conductors in this network + */ + @Override + public void refresh() + { + this.electricalTiles.clear(); + + try + { + Iterator it = this.conductors.iterator(); + + while (it.hasNext()) + { + IConductor conductor = it.next(); + + if (conductor == null) + { + it.remove(); + } + else if (((TileEntity) conductor).isInvalid()) + { + it.remove(); + } + else + { + conductor.setNetwork(this); + } + + for (int i = 0; i < conductor.getAdjacentConnections().length; i++) + { + TileEntity acceptor = conductor.getAdjacentConnections()[i]; + + if (!(acceptor instanceof IConductor) && acceptor instanceof IConnector) + { + ArrayList possibleDirections = null; + + if (this.electricalTiles.containsKey(acceptor)) + { + possibleDirections = this.electricalTiles.get(acceptor); + } + else + { + possibleDirections = new ArrayList(); + } + + possibleDirections.add(ForgeDirection.getOrientation(i)); + + this.electricalTiles.put(acceptor, possibleDirections); + } + } + } + } + catch (Exception e) + { + FMLLog.severe("Universal Electricity: Failed to refresh conductor."); + e.printStackTrace(); + } + } + + @Override + public float getTotalResistance() + { + float resistance = 0; + + for (IConductor conductor : this.conductors) + { + resistance += conductor.getResistance(); + } + + return resistance; + } + + @Override + public float getLowestCurrentCapacity() + { + float lowestAmperage = 0; + + for (IConductor conductor : this.conductors) + { + if (lowestAmperage == 0 || conductor.getCurrentCapacity() < lowestAmperage) + { + lowestAmperage = conductor.getCurrentCapacity(); + } + } + + return lowestAmperage; + } + + @Override + public Set getConductors() + { + return this.conductors; + } + + @Override + public void merge(IElectricityNetwork network) + { + if (network != null && network != this) + { + ElectricityNetwork newNetwork = new ElectricityNetwork(); + newNetwork.getConductors().addAll(this.getConductors()); + newNetwork.getConductors().addAll(network.getConductors()); + newNetwork.refresh(); + } + } + + @Override + public void split(IConductor splitPoint) + { + if (splitPoint instanceof TileEntity) + { + this.getConductors().remove(splitPoint); + + /** + * Loop through the connected blocks and attempt to see if there are connections between + * the two points elsewhere. + */ + TileEntity[] connectedBlocks = splitPoint.getAdjacentConnections(); + + for (int i = 0; i < connectedBlocks.length; i++) + { + TileEntity connectedBlockA = connectedBlocks[i]; + + if (connectedBlockA instanceof INetworkConnection) + { + for (int ii = 0; ii < connectedBlocks.length; ii++) + { + final TileEntity connectedBlockB = connectedBlocks[ii]; + + if (connectedBlockA != connectedBlockB && connectedBlockB instanceof INetworkConnection) + { + Pathfinder finder = new PathfinderChecker(((TileEntity) splitPoint).worldObj, (INetworkConnection) connectedBlockB, splitPoint); + finder.init(new Vector3(connectedBlockA)); + + if (finder.results.size() > 0) + { + /** + * The connections A and B are still intact elsewhere. Set all + * references of wire connection into one network. + */ + + for (Vector3 node : finder.closedSet) + { + TileEntity nodeTile = node.getTileEntity(((TileEntity) splitPoint).worldObj); + + if (nodeTile instanceof INetworkProvider) + { + if (nodeTile != splitPoint) + { + ((INetworkProvider) nodeTile).setNetwork(this); + } + } + } + } + else + { + /** + * The connections A and B are not connected anymore. Give both of + * them a new network. + */ + IElectricityNetwork newNetwork = new ElectricityNetwork(); + + for (Vector3 node : finder.closedSet) + { + TileEntity nodeTile = node.getTileEntity(((TileEntity) splitPoint).worldObj); + + if (nodeTile instanceof INetworkProvider) + { + if (nodeTile != splitPoint) + { + newNetwork.getConductors().add((IConductor) nodeTile); + } + } + } + + newNetwork.refresh(); + } + } + } + } + } + } + } + + @Override + public String toString() + { + return "ElectricityNetwork[" + this.hashCode() + "|Wires:" + this.conductors.size() + "|Acceptors:" + this.electricalTiles.size() + "]"; + } +} diff --git a/common/universalelectricity/core/grid/IElectricityNetwork.java b/common/universalelectricity/core/grid/IElectricityNetwork.java new file mode 100644 index 000000000..3f6f30050 --- /dev/null +++ b/common/universalelectricity/core/grid/IElectricityNetwork.java @@ -0,0 +1,38 @@ +package universalelectricity.core.grid; + +import net.minecraft.tileentity.TileEntity; +import universalelectricity.core.block.IConductor; +import universalelectricity.core.electricity.ElectricityPack; + +/** + * The Electrical Network in interface form. + * + * @author Calclavia + * + */ +public interface IElectricityNetwork extends IGridNetwork +{ + /** + * Produces electricity in this electrical network. + * + * @return Rejected energy in Joules. + */ + public float produce(ElectricityPack electricityPack, TileEntity... ignoreTiles); + + /** + * Gets the total amount of electricity requested/needed in the electricity network. + * + * @param ignoreTiles The TileEntities to ignore during this calculation (optional). + */ + public ElectricityPack getRequest(TileEntity... ignoreTiles); + + /** + * @return The total amount of resistance of this electrical network. In Ohms. + */ + public float getTotalResistance(); + + /** + * @return The lowest amount of current (amperage) that this electrical network can tolerate. + */ + public float getLowestCurrentCapacity(); +} diff --git a/common/universalelectricity/core/grid/IGridNetwork.java b/common/universalelectricity/core/grid/IGridNetwork.java new file mode 100644 index 000000000..26d55a8e4 --- /dev/null +++ b/common/universalelectricity/core/grid/IGridNetwork.java @@ -0,0 +1,66 @@ +package universalelectricity.core.grid; + +import java.util.ArrayList; +import java.util.Set; + +import net.minecraft.tileentity.TileEntity; +import net.minecraftforge.common.ForgeDirection; + +/** + * Implement this in your network class/interface if you plan to have your own network defined by + * specific conductors and acceptors. + * + * @author aidancbrady + * + * @param - the class/interface Type value in which you implement this + * @param - the class/interface Type which makes up the network's conductor Set + * @param - the class/interface Type which makes up the network's acceptor Set + */ +public interface IGridNetwork +{ + /** + * Refreshes and cleans up conductor references of this network, as well as updating the + * acceptor set. + */ + public void refresh(); + + /** + * Gets the Set of conductors that make up this network. + * + * @return conductor set + */ + public Set getConductors(); + + /** + * Gets the Set of AVAILABLE acceptors in this network. Make sure this doesn't include any stray + * acceptors which cannot accept resources. + * + * @return available acceptor set + */ + public Set getAcceptors(); + + /** + * Gets the list of possible connection directions for the provided TileEntity. Tile must be in + * this network. + * + * @param tile The tile to get connections for + * @return The list of directions that can be connected to for the provided tile + */ + public ArrayList getPossibleDirections(TileEntity tile); + + /** + * Creates a new network that makes up the current network and the network defined in the + * parameters. Be sure to refresh the new network inside this method. + * + * @param network - network to merge + */ + public void merge(N network); + + /** + * Splits a network by the conductor referenced in the parameters. It will then create and + * refresh the new independent networks possibly created by this operation. + * + * @param connection + */ + public void split(C connection); +} diff --git a/common/universalelectricity/core/item/ElectricItemHelper.java b/common/universalelectricity/core/item/ElectricItemHelper.java index 0bf487e18..ef0d9657e 100644 --- a/common/universalelectricity/core/item/ElectricItemHelper.java +++ b/common/universalelectricity/core/item/ElectricItemHelper.java @@ -2,7 +2,6 @@ package universalelectricity.core.item; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; -import universalelectricity.core.electricity.ElectricityPack; /** * Some helper functions for electric items. @@ -16,23 +15,15 @@ public class ElectricItemHelper * Recharges an electric item. * * @param joules - The joules being provided to the electric item - * @param voltage - The voltage in which is used to charge the electric item * @return The total amount of joules provided by the provider. */ - public static double chargeItem(ItemStack itemStack, double joules, double voltage) + public static float chargeItem(ItemStack itemStack, float joules) { if (itemStack != null) { if (itemStack.getItem() instanceof IItemElectric) { - IItemElectric electricItem = (IItemElectric) itemStack.getItem(); - double providingWatts = Math.min(joules, electricItem.getReceiveRequest(itemStack).getWatts()); - - if (providingWatts > 0) - { - ElectricityPack providedElectricity = electricItem.onReceive(ElectricityPack.getFromWatts(providingWatts, voltage), itemStack); - return providedElectricity.getWatts(); - } + return ((IItemElectric) itemStack.getItem()).recharge(itemStack, Math.min(((IItemElectric) itemStack.getItem()).getTransfer(itemStack), joules), true); } } @@ -43,23 +34,15 @@ public class ElectricItemHelper * Decharges an electric item. * * @param joules - The joules being withdrawn from the electric item - * @param voltage - The voltage in which is used to decharge the electric item * @return The total amount of joules the provider received. */ - public static double dechargeItem(ItemStack itemStack, double joules, double voltage) + public static float dischargeItem(ItemStack itemStack, float joules) { if (itemStack != null) { if (itemStack.getItem() instanceof IItemElectric) { - IItemElectric electricItem = (IItemElectric) itemStack.getItem(); - double requestingWatts = Math.min(joules, electricItem.getProvideRequest(itemStack).getWatts()); - - if (requestingWatts > 0) - { - ElectricityPack receivedElectricity = electricItem.onProvide(ElectricityPack.getFromWatts(requestingWatts, voltage), itemStack); - return receivedElectricity.getWatts(); - } + return ((IItemElectric) itemStack.getItem()).discharge(itemStack, Math.min(((IItemElectric) itemStack.getItem()).getMaxElectricityStored(itemStack), joules), true); } } @@ -73,13 +56,13 @@ public class ElectricItemHelper * * @return An electrical ItemStack with a specific charge. */ - public static ItemStack getWithCharge(ItemStack itemStack, double joules) + public static ItemStack getWithCharge(ItemStack itemStack, float joules) { if (itemStack != null) { if (itemStack.getItem() instanceof IItemElectric) { - ((IItemElectric) itemStack.getItem()).setJoules(joules, itemStack); + ((IItemElectric) itemStack.getItem()).setElectricity(itemStack, joules); return itemStack; } } @@ -87,12 +70,12 @@ public class ElectricItemHelper return itemStack; } - public static ItemStack getWithCharge(Item item, double joules) + public static ItemStack getWithCharge(Item item, float joules) { return getWithCharge(new ItemStack(item), joules); } - public static ItemStack getCloneWithCharge(ItemStack itemStack, double joules) + public static ItemStack getCloneWithCharge(ItemStack itemStack, float joules) { return getWithCharge(itemStack.copy(), joules); } diff --git a/common/universalelectricity/core/item/IItemElectric.java b/common/universalelectricity/core/item/IItemElectric.java index 6b5f5cb9e..cf3b1cf34 100644 --- a/common/universalelectricity/core/item/IItemElectric.java +++ b/common/universalelectricity/core/item/IItemElectric.java @@ -1,40 +1,56 @@ package universalelectricity.core.item; import net.minecraft.item.ItemStack; -import universalelectricity.core.electricity.ElectricityPack; -/** - * An interface applied to all electrical items. Should be applied to the Item class. - * - * @author Calclavia - * - */ -public interface IItemElectric extends IItemElectricityStorage, IItemVoltage +public interface IItemElectric { /** - * Called when this item receives electricity; being charged. + * Adds energy to an item. Returns the quantity of energy that was accepted. This should always + * return 0 if the item cannot be externally charged. * - * @return The amount of electricity that was added to the electric item. + * @param itemStack ItemStack to be charged. + * @param energy Maximum amount of energy to be sent into the item. + * @param doRecharge If false, the charge will only be simulated. + * @return Amount of energy that was accepted by the item. */ - public ElectricityPack onReceive(ElectricityPack electricityPack, ItemStack itemStack); + public float recharge(ItemStack itemStack, float energy, boolean doRecharge); /** - * Called when something requests electricity from this item; being decharged. + * Removes energy from an item. Returns the quantity of energy that was removed. This should + * always return 0 if the item cannot be externally discharged. * - * @return - The amount of electricity that was removed from the electric item. + * @param itemStack ItemStack to be discharged. + * @param energy Maximum amount of energy to be removed from the item. + * @param doDischarge If false, the discharge will only be simulated. + * @return Amount of energy that was removed from the item. */ - public ElectricityPack onProvide(ElectricityPack electricityPack, ItemStack itemStack); + public float discharge(ItemStack itemStack, float energy, boolean doDischarge); /** - * @return How much electricity does this item want to receive/take? This will affect the speed - * in which items get charged per tick. + * Get the amount of energy currently stored in the item. */ - public ElectricityPack getReceiveRequest(ItemStack itemStack); + public float getElectricityStored(ItemStack theItem); /** - * - * @return How much electricity does this item want to provide/give out? This will affect the - * speed in which items get decharged per tick. + * Get the max amount of energy that can be stored in the item. */ - public ElectricityPack getProvideRequest(ItemStack itemStack); + public float getMaxElectricityStored(ItemStack theItem); + + /** + * Sets the amount of energy in the ItemStack. + * + * @param itemStack - the ItemStack. + * @param joules - Amount of electrical energy. + */ + public void setElectricity(ItemStack itemStack, float joules); + + /** + * @return the energy request this ItemStack demands. + */ + public float getTransfer(ItemStack itemStack); + + /** + * @return The voltage in which this item runs on. + */ + public float getVoltage(ItemStack itemStack); } diff --git a/common/universalelectricity/core/item/IItemElectricityStorage.java b/common/universalelectricity/core/item/IItemElectricityStorage.java deleted file mode 100644 index cbce9c94d..000000000 --- a/common/universalelectricity/core/item/IItemElectricityStorage.java +++ /dev/null @@ -1,21 +0,0 @@ -package universalelectricity.core.item; - -import net.minecraft.item.ItemStack; - -public interface IItemElectricityStorage -{ - /** - * Returns the amount of joules this unit has stored. - */ - public double getJoules(ItemStack itemStack); - - /** - * Sets the amount of joules this unit has stored. - */ - public void setJoules(double joules, ItemStack itemStack); - - /** - * Gets the maximum amount of joules this unit can store. - */ - public double getMaxJoules(ItemStack itemStack); -} diff --git a/common/universalelectricity/core/item/IItemVoltage.java b/common/universalelectricity/core/item/IItemVoltage.java deleted file mode 100644 index b42f9334c..000000000 --- a/common/universalelectricity/core/item/IItemVoltage.java +++ /dev/null @@ -1,18 +0,0 @@ -package universalelectricity.core.item; - -import net.minecraft.item.ItemStack; - -/** - * Applies to items that has a voltage. - * - * @author Calclavia - * - */ -public interface IItemVoltage -{ - - /** - * @return The voltage in which this item runs on. - */ - public double getVoltage(ItemStack itemStack); -} diff --git a/common/universalelectricity/core/item/ItemElectric.java b/common/universalelectricity/core/item/ItemElectric.java index 01fc031be..449214945 100644 --- a/common/universalelectricity/core/item/ItemElectric.java +++ b/common/universalelectricity/core/item/ItemElectric.java @@ -10,7 +10,6 @@ import net.minecraft.nbt.NBTTagCompound; import net.minecraft.world.World; import universalelectricity.core.electricity.ElectricityDisplay; import universalelectricity.core.electricity.ElectricityDisplay.ElectricUnit; -import universalelectricity.core.electricity.ElectricityPack; /** * Extend from this class if your item requires electricity or to be charged. Optionally, you can @@ -33,13 +32,13 @@ public abstract class ItemElectric extends Item implements IItemElectric public void addInformation(ItemStack itemStack, EntityPlayer entityPlayer, List list, boolean par4) { String color = ""; - double joules = this.getJoules(itemStack); + float joules = this.getElectricityStored(itemStack); - if (joules <= this.getMaxJoules(itemStack) / 3) + if (joules <= this.getMaxElectricityStored(itemStack) / 3) { color = "\u00a74"; } - else if (joules > this.getMaxJoules(itemStack) * 2 / 3) + else if (joules > this.getMaxElectricityStored(itemStack) * 2 / 3) { color = "\u00a72"; } @@ -48,7 +47,7 @@ public abstract class ItemElectric extends Item implements IItemElectric color = "\u00a76"; } - list.add(color + ElectricityDisplay.getDisplay(joules, ElectricUnit.JOULES) + "/" + ElectricityDisplay.getDisplay(this.getMaxJoules(itemStack), ElectricUnit.JOULES)); + list.add(color + ElectricityDisplay.getDisplay(joules, ElectricUnit.JOULES) + "/" + ElectricityDisplay.getDisplay(this.getMaxElectricityStored(itemStack), ElectricUnit.JOULES)); } /** @@ -58,51 +57,44 @@ public abstract class ItemElectric extends Item implements IItemElectric @Override public void onCreated(ItemStack itemStack, World par2World, EntityPlayer par3EntityPlayer) { - this.setJoules(0, itemStack); + this.setElectricity(itemStack, 0); } @Override - public ElectricityPack onReceive(ElectricityPack electricityPack, ItemStack itemStack) + public float recharge(ItemStack itemStack, float energy, boolean doReceive) { - double rejectedElectricity = Math.max((this.getJoules(itemStack) + electricityPack.getWatts()) - this.getMaxJoules(itemStack), 0); - double joulesToStore = electricityPack.getWatts() - rejectedElectricity; - this.setJoules(this.getJoules(itemStack) + joulesToStore, itemStack); - return ElectricityPack.getFromWatts(joulesToStore, this.getVoltage(itemStack)); + float rejectedElectricity = Math.max((this.getElectricityStored(itemStack) + energy) - this.getMaxElectricityStored(itemStack), 0); + float energyToReceive = energy - rejectedElectricity; + + if (doReceive) + { + this.setElectricity(itemStack, this.getElectricityStored(itemStack) + energyToReceive); + } + + return energyToReceive; } @Override - public ElectricityPack onProvide(ElectricityPack electricityPack, ItemStack itemStack) + public float discharge(ItemStack itemStack, float energy, boolean doTransfer) { - double electricityToUse = Math.min(this.getJoules(itemStack), electricityPack.getWatts()); - this.setJoules(this.getJoules(itemStack) - electricityToUse, itemStack); - return ElectricityPack.getFromWatts(electricityToUse, this.getVoltage(itemStack)); + float energyToTransfer = Math.min(this.getElectricityStored(itemStack), energy); + + if (doTransfer) + { + this.setElectricity(itemStack, this.getElectricityStored(itemStack) - energyToTransfer); + } + + return energyToTransfer; } @Override - public ElectricityPack getReceiveRequest(ItemStack itemStack) + public float getVoltage(ItemStack itemStack) { - return ElectricityPack.getFromWatts(Math.min(this.getMaxJoules(itemStack) - this.getJoules(itemStack), this.getTransferRate(itemStack)), this.getVoltage(itemStack)); + return 120; } @Override - public ElectricityPack getProvideRequest(ItemStack itemStack) - { - return ElectricityPack.getFromWatts(Math.min(this.getJoules(itemStack), this.getTransferRate(itemStack)), this.getVoltage(itemStack)); - } - - public double getTransferRate(ItemStack itemStack) - { - return this.getMaxJoules(itemStack) * 0.01; - } - - /** - * This function sets the electriicty. Do not directly call this function. Try to use - * onReceiveElectricity or onUseElectricity instead. - * - * @param joules - The amount of electricity in joules - */ - @Override - public void setJoules(double joules, ItemStack itemStack) + public void setElectricity(ItemStack itemStack, float joules) { // Saves the frequency in the ItemStack if (itemStack.getTagCompound() == null) @@ -110,13 +102,19 @@ public abstract class ItemElectric extends Item implements IItemElectric itemStack.setTagCompound(new NBTTagCompound()); } - double electricityStored = Math.max(Math.min(joules, this.getMaxJoules(itemStack)), 0); - itemStack.getTagCompound().setDouble("electricity", electricityStored); + float electricityStored = Math.max(Math.min(joules, this.getMaxElectricityStored(itemStack)), 0); + itemStack.getTagCompound().setFloat("electricity", electricityStored); /** * Sets the damage as a percentage to render the bar properly. */ - itemStack.setItemDamage((int) (100 - (electricityStored / getMaxJoules(itemStack)) * 100)); + itemStack.setItemDamage((int) (100 - (electricityStored / getMaxElectricityStored(itemStack)) * 100)); + } + + @Override + public float getTransfer(ItemStack itemStack) + { + return this.getMaxElectricityStored(itemStack) - this.getElectricityStored(itemStack); } /** @@ -125,19 +123,19 @@ public abstract class ItemElectric extends Item implements IItemElectric * @return - The amount of electricity stored in watts */ @Override - public double getJoules(ItemStack itemStack) + public float getElectricityStored(ItemStack itemStack) { if (itemStack.getTagCompound() == null) { return 0; } - double electricityStored = itemStack.getTagCompound().getDouble("electricity"); + float electricityStored = itemStack.getTagCompound().getFloat("electricity"); /** * Sets the damage as a percentage to render the bar properly. */ - itemStack.setItemDamage((int) (100 - (electricityStored / getMaxJoules(itemStack)) * 100)); + itemStack.setItemDamage((int) (100 - (electricityStored / getMaxElectricityStored(itemStack)) * 100)); return electricityStored; } @@ -148,6 +146,6 @@ public abstract class ItemElectric extends Item implements IItemElectric par3List.add(ElectricItemHelper.getUncharged(new ItemStack(this))); // Add an electric item to the creative list that is fully charged ItemStack chargedItem = new ItemStack(this); - par3List.add(ElectricItemHelper.getWithCharge(chargedItem, this.getMaxJoules(chargedItem))); + par3List.add(ElectricItemHelper.getWithCharge(chargedItem, this.getMaxElectricityStored(chargedItem))); } } diff --git a/common/universalelectricity/core/path/PathfinderChecker.java b/common/universalelectricity/core/path/PathfinderChecker.java index 652f0e24f..ca242cb4c 100644 --- a/common/universalelectricity/core/path/PathfinderChecker.java +++ b/common/universalelectricity/core/path/PathfinderChecker.java @@ -8,7 +8,7 @@ import net.minecraft.tileentity.TileEntity; import net.minecraft.world.World; import net.minecraftforge.common.ForgeDirection; import universalelectricity.core.block.IConductor; -import universalelectricity.core.block.IConnectionProvider; +import universalelectricity.core.block.INetworkConnection; import universalelectricity.core.vector.Vector3; /** @@ -19,7 +19,7 @@ import universalelectricity.core.vector.Vector3; */ public class PathfinderChecker extends Pathfinder { - public PathfinderChecker(final World world, final IConnectionProvider targetConnector, final IConnectionProvider... ignoreConnector) + public PathfinderChecker(final World world, final INetworkConnection targetConnector, final INetworkConnection... ignoreConnector) { super(new IPathCallBack() { diff --git a/common/universalelectricity/core/vector/Vector2.java b/common/universalelectricity/core/vector/Vector2.java index c94b6dbd6..1f130d4c0 100644 --- a/common/universalelectricity/core/vector/Vector2.java +++ b/common/universalelectricity/core/vector/Vector2.java @@ -1,7 +1,5 @@ package universalelectricity.core.vector; -import net.minecraft.util.MathHelper; - /** * Vector2 Class is used for defining objects in a 2D space. * @@ -52,7 +50,7 @@ public class Vector2 implements Cloneable { double xDifference = point1.x - point2.x; double yDiference = point1.y - point2.y; - return MathHelper.sqrt_double(xDifference * xDifference + yDiference * yDiference); + return Math.sqrt(xDifference * xDifference + yDiference * yDiference); } public static double slope(Vector2 point1, Vector2 point2) @@ -66,7 +64,7 @@ public class Vector2 implements Cloneable { double xDifference = this.x - target.x; double yDifference = this.y - target.y; - return MathHelper.sqrt_double(xDifference * xDifference + yDifference * yDifference); + return Math.sqrt(xDifference * xDifference + yDifference * yDifference); } public Vector2 add(Vector2 par1) diff --git a/common/universalelectricity/core/vector/Vector3.java b/common/universalelectricity/core/vector/Vector3.java index 312e905c4..ff0d7f421 100644 --- a/common/universalelectricity/core/vector/Vector3.java +++ b/common/universalelectricity/core/vector/Vector3.java @@ -7,7 +7,6 @@ import net.minecraft.nbt.NBTTagCompound; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.AxisAlignedBB; import net.minecraft.util.ChunkCoordinates; -import net.minecraft.util.MathHelper; import net.minecraft.util.MovingObjectPosition; import net.minecraft.util.Vec3; import net.minecraft.world.IBlockAccess; @@ -22,6 +21,7 @@ import net.minecraftforge.common.ForgeDirection; public class Vector3 implements Cloneable { + public double x; public double y; public double z; @@ -190,7 +190,7 @@ public class Vector3 implements Cloneable double var2 = par1.x - par2.x; double var4 = par1.y - par2.y; double var6 = par1.z - par2.z; - return MathHelper.sqrt_double(var2 * var2 + var4 * var4 + var6 * var6); + return Math.sqrt(var2 * var2 + var4 * var4 + var6 * var6); } public double distanceTo(Vector3 vector3) @@ -198,7 +198,7 @@ public class Vector3 implements Cloneable double var2 = vector3.x - this.x; double var4 = vector3.y - this.y; double var6 = vector3.z - this.z; - return MathHelper.sqrt_double(var2 * var2 + var4 * var4 + var6 * var6); + return Math.sqrt(var2 * var2 + var4 * var4 + var6 * var6); } public Vector3 add(Vector3 par1) @@ -290,6 +290,30 @@ public class Vector3 implements Cloneable return new Vector3(Math.floor(this.x), Math.floor(this.y), Math.floor(this.z)); } + public Vector3 toRound() + { + this.x = Math.round(this.x); + this.y = Math.round(this.y); + this.z = Math.round(this.z); + return this; + } + + public Vector3 toCeil() + { + this.x = Math.ceil(this.x); + this.y = Math.ceil(this.y); + this.z = Math.ceil(this.z); + return this; + } + + public Vector3 toFloor() + { + this.x = Math.floor(this.x); + this.y = Math.floor(this.y); + this.z = Math.floor(this.z); + return this; + } + /** * Gets all entities inside of this position in block space. */ @@ -363,6 +387,36 @@ public class Vector3 implements Cloneable return par1NBTTagCompound; } + public static Vector3 UP() + { + return new Vector3(0, 1, 0); + } + + public static Vector3 DOWN() + { + return new Vector3(0, -1, 0); + } + + public static Vector3 NORTH() + { + return new Vector3(0, 0, -1); + } + + public static Vector3 SOUTH() + { + return new Vector3(0, 0, 1); + } + + public static Vector3 WEST() + { + return new Vector3(-1, 0, 0); + } + + public static Vector3 EAST() + { + return new Vector3(1, 0, 0); + } + @Override public int hashCode() { diff --git a/common/universalelectricity/core/vector/VectorHelper.java b/common/universalelectricity/core/vector/VectorHelper.java index 7ede19769..e447b7e20 100644 --- a/common/universalelectricity/core/vector/VectorHelper.java +++ b/common/universalelectricity/core/vector/VectorHelper.java @@ -7,7 +7,7 @@ import universalelectricity.core.block.IConnector; public class VectorHelper { - public static final int[][] RELATIVE_MATRIX = { { 3, 2, 1, 0, 5, 4 }, { 4, 5, 0, 1, 2, 3 }, { 0, 1, 3, 2, 5, 4 }, { 0, 1, 2, 3, 4, 5 }, { 0, 1, 5, 4, 3, 2 }, { 0, 1, 4, 5, 2, 3 } }; + public static final int[][] RELATIVE_MATRIX = { { 3, 2, 1, 0, 5, 4 }, { 4, 5, 0, 1, 2, 3 }, { 0, 1, 3, 2, 4, 5 }, { 0, 1, 2, 3, 5, 4 }, { 0, 1, 5, 4, 3, 2 }, { 0, 1, 4, 5, 2, 3 } }; /** * Finds the direction relative to a base direction. diff --git a/common/universalelectricity/prefab/CustomDamageSource.java b/common/universalelectricity/prefab/CustomDamageSource.java deleted file mode 100644 index 87365a361..000000000 --- a/common/universalelectricity/prefab/CustomDamageSource.java +++ /dev/null @@ -1,41 +0,0 @@ -package universalelectricity.prefab; - -import net.minecraft.util.DamageSource; -import cpw.mods.fml.common.registry.LanguageRegistry; - -public class CustomDamageSource extends DamageSource -{ - /** - * Use this damage source for all types of electrical attacks. - */ - public static final CustomDamageSource electrocution = ((CustomDamageSource) new CustomDamageSource("electrocution").setDamageBypassesArmor()).setDeathMessage("%1$s got electrocuted!"); - - public CustomDamageSource(String damageType) - { - super(damageType); - } - - public CustomDamageSource setDeathMessage(String deathMessage) - { - LanguageRegistry.instance().addStringLocalization("death.attack." + this.damageType, deathMessage); - return this; - } - - @Override - public DamageSource setDamageBypassesArmor() - { - return super.setDamageBypassesArmor(); - } - - @Override - public DamageSource setDamageAllowedInCreativeMode() - { - return super.setDamageAllowedInCreativeMode(); - } - - @Override - public DamageSource setFireDamage() - { - return super.setFireDamage(); - } -} diff --git a/common/universalelectricity/prefab/GuiBase.java b/common/universalelectricity/prefab/GuiBase.java deleted file mode 100644 index 54ea78e12..000000000 --- a/common/universalelectricity/prefab/GuiBase.java +++ /dev/null @@ -1,197 +0,0 @@ -package universalelectricity.prefab; - -import net.minecraft.client.gui.GuiScreen; -import net.minecraft.client.renderer.OpenGlHelper; -import net.minecraft.client.renderer.RenderHelper; - -import org.lwjgl.opengl.GL11; -import org.lwjgl.opengl.GL12; - -import cpw.mods.fml.relauncher.Side; -import cpw.mods.fml.relauncher.SideOnly; - -@SideOnly(Side.CLIENT) -public abstract class GuiBase extends GuiScreen -{ - /** - * The X size of the inventory window in pixels. - */ - protected int xSize = 176; - - /** - * The Y size of the inventory window in pixels. - */ - protected int ySize = 166; - - /** - * Starting X position for the Gui. Inconsistent use for Gui backgrounds. - */ - protected int guiLeft; - - /** - * Starting Y position for the Gui. Inconsistent use for Gui backgrounds. - */ - protected int guiTop; - - /** - * Adds the buttons (and other controls) to the screen in question. - */ - @Override - public void initGui() - { - super.initGui(); - this.guiLeft = (this.width - this.xSize) / 2; - this.guiTop = (this.height - this.ySize) / 2; - } - - /** - * Draws the screen and all the components in it. - */ - @Override - public void drawScreen(int par1, int par2, float par3) - { - this.drawDefaultBackground(); - int var4 = this.guiLeft; - int var5 = this.guiTop; - this.drawBackgroundLayer(par1, par2, par3); - GL11.glPushMatrix(); - GL11.glTranslatef(var4, var5, 0.0F); - GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); - GL11.glEnable(GL12.GL_RESCALE_NORMAL); - short var7 = 240; - short var8 = 240; - OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit, var7 / 1.0F, var8 / 1.0F); - GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); - - this.drawForegroundLayer(par1, par2, par3); - - GL11.glDisable(GL12.GL_RESCALE_NORMAL); - GL11.glDisable(GL11.GL_LIGHTING); - GL11.glDisable(GL11.GL_DEPTH_TEST); - - GL11.glPopMatrix(); - super.drawScreen(par1, par2, par3); - GL11.glEnable(GL11.GL_LIGHTING); - GL11.glEnable(GL11.GL_DEPTH_TEST); - } - - /** - * Draws the foreground layer for the GUI - */ - protected abstract void drawForegroundLayer(int var2, int var3, float var1); - - /** - * Draws the background layer for the GUI - */ - - protected abstract void drawBackgroundLayer(int var2, int var3, float var1); - - /** - * Fired when a key is typed. This is the equivalent of KeyListener.keyTyped(KeyEvent e). - */ - @Override - protected void keyTyped(char x, int y) - { - if (y == 1 || y == this.mc.gameSettings.keyBindInventory.keyCode) - { - this.mc.thePlayer.closeScreen(); - } - } - - /** - * Returns true if this GUI should pause the game when it is displayed in single-player - */ - @Override - public boolean doesGuiPauseGame() - { - return false; - } - - /** - * Called from the main game loop to update the screen. - */ - @Override - public void updateScreen() - { - super.updateScreen(); - - if (!this.mc.thePlayer.isEntityAlive() || this.mc.thePlayer.isDead) - { - this.mc.thePlayer.closeScreen(); - } - } - - public void drawTooltip(int x, int y, String... toolTips) - { - GL11.glDisable(GL12.GL_RESCALE_NORMAL); - RenderHelper.disableStandardItemLighting(); - GL11.glDisable(GL11.GL_LIGHTING); - GL11.glDisable(GL11.GL_DEPTH_TEST); - - if (toolTips != null) - { - int var5 = 0; - int var6; - int var7; - - for (var6 = 0; var6 < toolTips.length; ++var6) - { - var7 = this.fontRenderer.getStringWidth(toolTips[var6]); - - if (var7 > var5) - { - var5 = var7; - } - } - - var6 = x + 12; - var7 = y - 12; - int var9 = 8; - - if (toolTips.length > 1) - { - var9 += 2 + (toolTips.length - 1) * 10; - } - - if (this.guiTop + var7 + var9 + 6 > this.height) - { - var7 = this.height - var9 - this.guiTop - 6; - } - - this.zLevel = 300.0F; - int var10 = -267386864; - this.drawGradientRect(var6 - 3, var7 - 4, var6 + var5 + 3, var7 - 3, var10, var10); - this.drawGradientRect(var6 - 3, var7 + var9 + 3, var6 + var5 + 3, var7 + var9 + 4, var10, var10); - this.drawGradientRect(var6 - 3, var7 - 3, var6 + var5 + 3, var7 + var9 + 3, var10, var10); - this.drawGradientRect(var6 - 4, var7 - 3, var6 - 3, var7 + var9 + 3, var10, var10); - this.drawGradientRect(var6 + var5 + 3, var7 - 3, var6 + var5 + 4, var7 + var9 + 3, var10, var10); - int var11 = 1347420415; - int var12 = (var11 & 16711422) >> 1 | var11 & -16777216; - this.drawGradientRect(var6 - 3, var7 - 3 + 1, var6 - 3 + 1, var7 + var9 + 3 - 1, var11, var12); - this.drawGradientRect(var6 + var5 + 2, var7 - 3 + 1, var6 + var5 + 3, var7 + var9 + 3 - 1, var11, var12); - this.drawGradientRect(var6 - 3, var7 - 3, var6 + var5 + 3, var7 - 3 + 1, var11, var11); - this.drawGradientRect(var6 - 3, var7 + var9 + 2, var6 + var5 + 3, var7 + var9 + 3, var12, var12); - - for (int var13 = 0; var13 < toolTips.length; ++var13) - { - String var14 = toolTips[var13]; - - this.fontRenderer.drawStringWithShadow(var14, var6, var7, -1); - - if (var13 == 0) - { - var7 += 2; - } - - var7 += 10; - } - - this.zLevel = 0.0F; - } - - GL11.glEnable(GL11.GL_DEPTH_TEST); - GL11.glEnable(GL11.GL_LIGHTING); - RenderHelper.enableGUIStandardItemLighting(); - GL11.glEnable(GL12.GL_RESCALE_NORMAL); - } -} \ No newline at end of file diff --git a/common/universalelectricity/prefab/RecipeHelper.java b/common/universalelectricity/prefab/RecipeHelper.java deleted file mode 100644 index 7471c1d89..000000000 --- a/common/universalelectricity/prefab/RecipeHelper.java +++ /dev/null @@ -1,192 +0,0 @@ -package universalelectricity.prefab; - -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; - -import net.minecraft.item.ItemStack; -import net.minecraft.item.crafting.CraftingManager; -import net.minecraft.item.crafting.IRecipe; -import net.minecraftforge.common.Configuration; -import cpw.mods.fml.common.registry.GameRegistry; - -/** - * This class is used to replace recipes that are already added in the existing recipe pool for - * crafting and smelting. All recipe functions take account of the Forge Ore Dictionary. It also - * includes some recipe helper functions to shorten some of your function calls. - * - * @author Calclavia - * - */ -public class RecipeHelper -{ - public static List getRecipesByOutput(ItemStack output) - { - List list = new ArrayList(); - - for (Object obj : CraftingManager.getInstance().getRecipeList()) - { - if (obj instanceof IRecipe) - { - if (((IRecipe) obj).getRecipeOutput() == output) - { - list.add((IRecipe) obj); - } - } - } - - return list; - } - - /** - * Replaces a recipe with a new IRecipe. - * - * @return True if successful - */ - public static boolean replaceRecipe(IRecipe recipe, IRecipe newRecipe) - { - for (Object obj : CraftingManager.getInstance().getRecipeList()) - { - if (obj instanceof IRecipe) - { - if (((IRecipe) obj).equals(recipe) || obj == recipe) - { - CraftingManager.getInstance().getRecipeList().remove(obj); - CraftingManager.getInstance().getRecipeList().add(newRecipe); - return true; - } - } - } - - return false; - } - - /** - * Replaces a recipe with the resulting ItemStack with a new IRecipe. - * - * @return True if successful - */ - public static boolean replaceRecipe(ItemStack recipe, IRecipe newRecipe) - { - if (removeRecipe(recipe)) - { - CraftingManager.getInstance().getRecipeList().add(newRecipe); - return true; - } - - return false; - } - - /** - * Removes a recipe by its IRecipe class. - * - * @return True if successful - */ - public static boolean removeRecipe(IRecipe recipe) - { - for (Object obj : CraftingManager.getInstance().getRecipeList()) - { - if (obj != null) - { - if (obj instanceof IRecipe) - { - if (((IRecipe) obj).equals(recipe) || obj == recipe) - { - CraftingManager.getInstance().getRecipeList().remove(obj); - return true; - } - } - } - } - - return false; - } - - /** - * Removes the first recipe found by its output. - * - * @return True if successful - */ - public static boolean removeRecipe(ItemStack stack) - { - for (Object obj : CraftingManager.getInstance().getRecipeList()) - { - if (obj != null) - { - if (obj instanceof IRecipe) - { - if (((IRecipe) obj).getRecipeOutput() != null) - { - if (((IRecipe) obj).getRecipeOutput().isItemEqual(stack)) - { - CraftingManager.getInstance().getRecipeList().remove(obj); - return true; - } - } - } - } - } - - return false; - } - - /** - * Removes all recipes found that has this output. You may use this with Forge Ore Dictionary to - * remove all recipes with the FoD ID. - * - * @return True if successful - */ - public static boolean removeRecipes(ItemStack... itemStacks) - { - boolean didRemove = false; - - for (Iterator itr = CraftingManager.getInstance().getRecipeList().iterator(); itr.hasNext();) - { - Object obj = itr.next(); - - if (obj != null) - { - if (obj instanceof IRecipe) - { - if (((IRecipe) obj).getRecipeOutput() != null) - { - for (ItemStack itemStack : itemStacks) - { - if (((IRecipe) obj).getRecipeOutput().isItemEqual(itemStack)) - { - itr.remove(); - didRemove = true; - break; - } - } - } - } - } - } - - return didRemove; - } - - /** - * Use this function if you want to check if the recipe is allowed in the configuration file. - */ - public static void addRecipe(IRecipe recipe, String name, Configuration configuration, boolean defaultBoolean) - { - if (configuration != null) - { - configuration.load(); - - if (configuration.get("Crafting", "Allow " + name + " Crafting", defaultBoolean).getBoolean(defaultBoolean)) - { - GameRegistry.addRecipe(recipe); - } - - configuration.save(); - } - } - - public static void addRecipe(IRecipe recipe, Configuration config, boolean defaultBoolean) - { - addRecipe(recipe, recipe.getRecipeOutput().getItemName(), config, defaultBoolean); - } -} diff --git a/common/universalelectricity/prefab/SlotSpecific.java b/common/universalelectricity/prefab/SlotSpecific.java deleted file mode 100644 index 989df4b81..000000000 --- a/common/universalelectricity/prefab/SlotSpecific.java +++ /dev/null @@ -1,95 +0,0 @@ -package universalelectricity.prefab; - -import net.minecraft.inventory.IInventory; -import net.minecraft.inventory.Slot; -import net.minecraft.item.ItemStack; - -/** - * Creates a slot with a specific amount of items that matches the slot's requirements. Allows easy - * shift right clicking management and slot blocking in classes. In your container you can use - * this.getSlot(i).isItemValid to justify the player's shift clicking actions to match the slot. - * - * @author Calclavia - * - */ -public class SlotSpecific extends Slot -{ - public ItemStack[] validItemStacks = new ItemStack[0]; - public Class[] validClasses = new Class[0]; - - public boolean isInverted = false; - public boolean isMetadataSensitive = false; - - public SlotSpecific(IInventory par2IInventory, int par3, int par4, int par5, ItemStack... itemStacks) - { - super(par2IInventory, par3, par4, par5); - this.setItemStacks(itemStacks); - } - - public SlotSpecific(IInventory par2IInventory, int par3, int par4, int par5, Class... validClasses) - { - super(par2IInventory, par3, par4, par5); - this.setClasses(validClasses); - } - - public SlotSpecific setMetadataSensitive() - { - this.isMetadataSensitive = true; - return this; - } - - public SlotSpecific setItemStacks(ItemStack... validItemStacks) - { - this.validItemStacks = validItemStacks; - return this; - } - - public SlotSpecific setClasses(Class... validClasses) - { - this.validClasses = validClasses; - return this; - } - - public SlotSpecific toggleInverted() - { - this.isInverted = !this.isInverted; - return this; - } - - /** - * Check if the stack is a valid item for this slot. Always true beside for the armor slots. - */ - @Override - public boolean isItemValid(ItemStack compareStack) - { - boolean returnValue = false; - - for (ItemStack itemStack : this.validItemStacks) - { - if (compareStack.isItemEqual(itemStack) || (!this.isMetadataSensitive && compareStack.itemID == itemStack.itemID)) - { - returnValue = true; - break; - } - } - - if (!returnValue) - { - for (Class clazz : this.validClasses) - { - if (clazz.equals(compareStack.getItem().getClass()) || clazz.isInstance(compareStack.getItem())) - { - returnValue = true; - break; - } - } - } - - if (this.isInverted) - { - return !returnValue; - } - - return returnValue; - } -} diff --git a/common/universalelectricity/prefab/TranslationHelper.java b/common/universalelectricity/prefab/TranslationHelper.java deleted file mode 100644 index b0f0c9da4..000000000 --- a/common/universalelectricity/prefab/TranslationHelper.java +++ /dev/null @@ -1,81 +0,0 @@ -package universalelectricity.prefab; - -import cpw.mods.fml.common.FMLLog; -import cpw.mods.fml.common.registry.LanguageRegistry; - -/** - * A class to help you out with translations. - * - * @author Calclavia - * - */ -public class TranslationHelper -{ - /** - * Loads all the language files for a mod. This supports the loading of "child" language files - * for sub-languages to be loaded all from one file instead of creating multiple of them. An - * example of this usage would be different Spanish sub-translations (es_MX, es_YU). - * - * @param languagePath - The path to the mod's language file folder. - * @param languageSupported - The languages supported. E.g: new String[]{"en_US", "en_AU", - * "en_UK"} - * @return The amount of language files loaded successfully. - */ - public static int loadLanguages(String languagePath, String[] languageSupported) - { - int languages = 0; - - /** - * Load all languages. - */ - for (String language : languageSupported) - { - LanguageRegistry.instance().loadLocalization(languagePath + language + ".properties", language, false); - - if (LanguageRegistry.instance().getStringLocalization("children", language) != "") - { - try - { - String[] children = LanguageRegistry.instance().getStringLocalization("children", language).split(","); - - for (String child : children) - { - if (child != "" || child != null) - { - LanguageRegistry.instance().loadLocalization(languagePath + language + ".properties", child, false); - languages++; - } - } - } - catch (Exception e) - { - FMLLog.severe("Failed to load a child language file."); - e.printStackTrace(); - } - } - - languages++; - } - - return languages; - } - - /** - * Gets the local text of your translation based on the given key. This will look through your - * mod's translation file that was previously registered. Make sure you enter the full name - * - * @param key - e.g tile.block.name - * @return The translated string or the default English translation if none was found. - */ - public static String getLocal(String key) - { - String text = LanguageRegistry.instance().getStringLocalization(key); - - if (text == null || text == "") - { - text = LanguageRegistry.instance().getStringLocalization(key, "en_US"); - } - - return text; - } -} diff --git a/common/universalelectricity/prefab/implement/IDisableable.java b/common/universalelectricity/prefab/implement/IDisableable.java deleted file mode 100644 index f4e0398d5..000000000 --- a/common/universalelectricity/prefab/implement/IDisableable.java +++ /dev/null @@ -1,25 +0,0 @@ -package universalelectricity.prefab.implement; - -/** - * This class should be applied to all tile entities (mainly machines) that can be disabled (by - * things like EMP, short circuit etc.). - * - * @author Calclavia - * - */ -public interface IDisableable -{ - /** - * This is called when the tile entity is to be disabled. - * - * @param duration - The duration of the disable in ticks. - */ - public void onDisable(int duration); - - /** - * Called to see if this tile entity is disabled. - * - * @return True if the tile entity is disabled. - */ - public boolean isDisabled(); -} diff --git a/common/universalelectricity/prefab/implement/IRedstoneProvider.java b/common/universalelectricity/prefab/implement/IRedstoneProvider.java deleted file mode 100644 index 3b03e9b43..000000000 --- a/common/universalelectricity/prefab/implement/IRedstoneProvider.java +++ /dev/null @@ -1,16 +0,0 @@ -package universalelectricity.prefab.implement; - -import net.minecraftforge.common.ForgeDirection; - -/** - * This should be applied on tile entities that can provide redstone power - * - * @author Calclavia - * - */ -public interface IRedstoneProvider -{ - public boolean isPoweringTo(ForgeDirection side); - - public boolean isIndirectlyPoweringTo(ForgeDirection side); -} diff --git a/common/universalelectricity/prefab/implement/IRedstoneReceptor.java b/common/universalelectricity/prefab/implement/IRedstoneReceptor.java deleted file mode 100644 index 0ad177a10..000000000 --- a/common/universalelectricity/prefab/implement/IRedstoneReceptor.java +++ /dev/null @@ -1,21 +0,0 @@ -package universalelectricity.prefab.implement; - -/** - * This interface should be applied onto all tile entities that needs to receive redstone power. - * Look at TileEntityBatteryBox for reference. - * - * @author Calclavia - * - */ -public interface IRedstoneReceptor -{ - /** - * Called when the block is powered on by redstone - */ - public void onPowerOn(); - - /** - * Called when the block is powered off by redstone - */ - public void onPowerOff(); -} diff --git a/common/universalelectricity/prefab/implement/IRotatable.java b/common/universalelectricity/prefab/implement/IRotatable.java deleted file mode 100644 index 03f22d0f2..000000000 --- a/common/universalelectricity/prefab/implement/IRotatable.java +++ /dev/null @@ -1,25 +0,0 @@ -package universalelectricity.prefab.implement; - -import net.minecraft.world.IBlockAccess; -import net.minecraft.world.World; -import net.minecraftforge.common.ForgeDirection; - -/** - * The interface is applied to Blocks and TileEntities that can rotate. - * - * @author Calclavia - * - */ - -public interface IRotatable -{ - /** - * @return Gets the facing direction. Always returns the front side of the block. - */ - public ForgeDirection getDirection(IBlockAccess world, int x, int y, int z); - - /** - * @param Sets the facing direction. - */ - public void setDirection(World world, int x, int y, int z, ForgeDirection facingDirection); -} diff --git a/common/universalelectricity/prefab/implement/ITier.java b/common/universalelectricity/prefab/implement/ITier.java deleted file mode 100644 index 6c6801f2e..000000000 --- a/common/universalelectricity/prefab/implement/ITier.java +++ /dev/null @@ -1,24 +0,0 @@ -package universalelectricity.prefab.implement; - -/** - * This interface should be applied to all things that has a tier/level. - * - * @author Calclavia - * - */ -public interface ITier -{ - /** - * Gets the tier of this object - * - * @return - The tier - */ - public int getTier(); - - /** - * Sets the tier of the object - * - * @param tier - The tier to be set - */ - public void setTier(int tier); -} diff --git a/common/universalelectricity/prefab/implement/IToolConfigurator.java b/common/universalelectricity/prefab/implement/IToolConfigurator.java deleted file mode 100644 index c12d47d0e..000000000 --- a/common/universalelectricity/prefab/implement/IToolConfigurator.java +++ /dev/null @@ -1,33 +0,0 @@ -package universalelectricity.prefab.implement; - -import net.minecraft.entity.player.EntityPlayer; - -/** - * Code written by Buildcraft. Applied to items that acts as a block configurator such as wrenches, - * screw drivers and such. - * - * @author Buildcraft Team - */ -public interface IToolConfigurator -{ - - /*** - * Called to ensure that the wrench can be used. To get the ItemStack that is used, check - * player.inventory.getCurrentItem() - * - * @param player - The player doing the wrenching - * @param x ,y,z - The coordinates for the block being wrenched - * - * @return true if wrenching is allowed, false if not - */ - public boolean canWrench(EntityPlayer player, int x, int y, int z); - - /*** - * Callback after the wrench has been used. This can be used to decrease durability or for other - * purposes. To get the ItemStack that was used, check player.inventory.getCurrentItem() - * - * @param player - The player doing the wrenching - * @param x ,y,z - The coordinates of the block being wrenched - */ - public void wrenchUsed(EntityPlayer player, int x, int y, int z); -} diff --git a/common/universalelectricity/prefab/multiblock/BlockMulti.java b/common/universalelectricity/prefab/multiblock/BlockMulti.java deleted file mode 100644 index 57de5b248..000000000 --- a/common/universalelectricity/prefab/multiblock/BlockMulti.java +++ /dev/null @@ -1,138 +0,0 @@ -package universalelectricity.prefab.multiblock; - -import java.util.Random; - -import net.minecraft.block.Block; -import net.minecraft.block.BlockContainer; -import net.minecraft.client.renderer.texture.IconRegister; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.item.ItemStack; -import net.minecraft.tileentity.TileEntity; -import net.minecraft.util.MovingObjectPosition; -import net.minecraft.world.World; -import universalelectricity.core.UniversalElectricity; -import universalelectricity.core.vector.Vector3; -import cpw.mods.fml.relauncher.Side; -import cpw.mods.fml.relauncher.SideOnly; - -public class BlockMulti extends BlockContainer -{ - public String textureName = null; - public String channel = ""; - - public BlockMulti(int id) - { - super(id, UniversalElectricity.machine); - this.setHardness(0.8F); - this.setUnlocalizedName("multiBlock"); - } - - public BlockMulti setChannel(String channel) - { - this.channel = channel; - return this; - } - - public BlockMulti setTextureName(String name) - { - this.textureName = name; - return this; - } - - public void makeFakeBlock(World worldObj, Vector3 position, Vector3 mainBlock) - { - worldObj.setBlock(position.intX(), position.intY(), position.intZ(), this.blockID); - ((TileEntityMulti) worldObj.getBlockTileEntity(position.intX(), position.intY(), position.intZ())).setMainBlock(mainBlock); - } - - @SideOnly(Side.CLIENT) - @Override - public void registerIcons(IconRegister iconRegister) - { - if (this.textureName != null) - { - this.blockIcon = iconRegister.registerIcon(this.textureName); - } - else - { - super.registerIcons(iconRegister); - } - } - - @Override - public void breakBlock(World world, int x, int y, int z, int par5, int par6) - { - TileEntity tileEntity = world.getBlockTileEntity(x, y, z); - - if (tileEntity instanceof TileEntityMulti) - { - ((TileEntityMulti) tileEntity).onBlockRemoval(); - } - - super.breakBlock(world, x, y, z, par5, par6); - } - - /** - * Called when the block is right clicked by the player. This modified version detects electric - * items and wrench actions on your machine block. Do not override this function. Use - * machineActivated instead! (It does the same thing) - */ - @Override - public boolean onBlockActivated(World par1World, int x, int y, int z, EntityPlayer par5EntityPlayer, int par6, float par7, float par8, float par9) - { - TileEntityMulti tileEntity = (TileEntityMulti) par1World.getBlockTileEntity(x, y, z); - return tileEntity.onBlockActivated(par1World, x, y, z, par5EntityPlayer); - } - - /** - * Returns the quantity of items to drop on block destruction. - */ - @Override - public int quantityDropped(Random par1Random) - { - return 0; - } - - @Override - public int getRenderType() - { - return -1; - } - - @Override - public boolean isOpaqueCube() - { - return false; - } - - @Override - public boolean renderAsNormalBlock() - { - return false; - } - - @Override - public TileEntity createNewTileEntity(World var1) - { - return new TileEntityMulti(this.channel); - } - - @Override - public ItemStack getPickBlock(MovingObjectPosition target, World par1World, int x, int y, int z) - { - TileEntity tileEntity = par1World.getBlockTileEntity(x, y, z); - Vector3 mainBlockPosition = ((TileEntityMulti) tileEntity).mainBlockPosition; - - if (mainBlockPosition != null) - { - int mainBlockID = par1World.getBlockId(mainBlockPosition.intX(), mainBlockPosition.intY(), mainBlockPosition.intZ()); - - if (mainBlockID > 0) - { - return Block.blocksList[mainBlockID].getPickBlock(target, par1World, mainBlockPosition.intX(), mainBlockPosition.intY(), mainBlockPosition.intZ()); - } - } - - return null; - } -} \ No newline at end of file diff --git a/common/universalelectricity/prefab/multiblock/IBlockActivate.java b/common/universalelectricity/prefab/multiblock/IBlockActivate.java deleted file mode 100644 index 3d4922603..000000000 --- a/common/universalelectricity/prefab/multiblock/IBlockActivate.java +++ /dev/null @@ -1,17 +0,0 @@ -package universalelectricity.prefab.multiblock; - -import net.minecraft.entity.player.EntityPlayer; - -/** - * A general interface to be implemented by anything that needs it. - * - * @author Calclavia - * - */ -public interface IBlockActivate -{ - /** - * Called when activated - */ - public boolean onActivated(EntityPlayer entityPlayer); -} \ No newline at end of file diff --git a/common/universalelectricity/prefab/multiblock/IMultiBlock.java b/common/universalelectricity/prefab/multiblock/IMultiBlock.java deleted file mode 100644 index 4558897bd..000000000 --- a/common/universalelectricity/prefab/multiblock/IMultiBlock.java +++ /dev/null @@ -1,28 +0,0 @@ -package universalelectricity.prefab.multiblock; - -import net.minecraft.tileentity.TileEntity; -import universalelectricity.core.vector.Vector3; - -/** - * Interface to be applied to tile entity blocks that occupies more than one block space. Useful for - * large machines. - * - * @author Calclavia - * - */ -public interface IMultiBlock extends IBlockActivate -{ - /** - * Called when this multiblock is created - * - * @param placedPosition - The position the block was placed at - */ - public void onCreate(Vector3 placedPosition); - - /** - * Called when one of the multiblocks of this block is destroyed - * - * @param callingBlock - The tile entity who called the onDestroy function - */ - public void onDestroy(TileEntity callingBlock); -} diff --git a/common/universalelectricity/prefab/multiblock/TileEntityMulti.java b/common/universalelectricity/prefab/multiblock/TileEntityMulti.java deleted file mode 100644 index f478fde82..000000000 --- a/common/universalelectricity/prefab/multiblock/TileEntityMulti.java +++ /dev/null @@ -1,148 +0,0 @@ -package universalelectricity.prefab.multiblock; - -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.network.INetworkManager; -import net.minecraft.network.packet.Packet; -import net.minecraft.network.packet.Packet250CustomPayload; -import net.minecraft.tileentity.TileEntity; -import net.minecraft.world.World; -import universalelectricity.core.vector.Vector3; -import universalelectricity.prefab.network.IPacketReceiver; -import universalelectricity.prefab.network.PacketManager; - -import com.google.common.io.ByteArrayDataInput; - -/** - * This is a multiblock to be used for blocks that are bigger than one block. - * - * @author Calclavia - * - */ -public class TileEntityMulti extends TileEntity implements IPacketReceiver -{ - // The the position of the main block - public Vector3 mainBlockPosition; - public String channel; - - public TileEntityMulti() - { - - } - - public TileEntityMulti(String channel) - { - this.channel = channel; - } - - public void setMainBlock(Vector3 mainBlock) - { - this.mainBlockPosition = mainBlock; - - if (!this.worldObj.isRemote) - { - this.worldObj.markBlockForUpdate(this.xCoord, this.yCoord, this.zCoord); - } - } - - @Override - public Packet getDescriptionPacket() - { - if (this.mainBlockPosition != null) - { - if (this.channel == null || this.channel == "" && this.getBlockType() instanceof BlockMulti) - { - this.channel = ((BlockMulti) this.getBlockType()).channel; - } - - return PacketManager.getPacket(this.channel, this, this.mainBlockPosition.intX(), this.mainBlockPosition.intY(), this.mainBlockPosition.intZ()); - - } - - return null; - } - - public void onBlockRemoval() - { - if (this.mainBlockPosition != null) - { - TileEntity tileEntity = this.worldObj.getBlockTileEntity(this.mainBlockPosition.intX(), this.mainBlockPosition.intY(), this.mainBlockPosition.intZ()); - - if (tileEntity != null && tileEntity instanceof IMultiBlock) - { - IMultiBlock mainBlock = (IMultiBlock) tileEntity; - - if (mainBlock != null) - { - mainBlock.onDestroy(this); - } - } - } - } - - public boolean onBlockActivated(World par1World, int x, int y, int z, EntityPlayer par5EntityPlayer) - { - if (this.mainBlockPosition != null) - { - TileEntity tileEntity = this.worldObj.getBlockTileEntity(this.mainBlockPosition.intX(), this.mainBlockPosition.intY(), this.mainBlockPosition.intZ()); - - if (tileEntity != null) - { - if (tileEntity instanceof IMultiBlock) - { - return ((IMultiBlock) tileEntity).onActivated(par5EntityPlayer); - } - } - } - - return false; - } - - /** - * Reads a tile entity from NBT. - */ - @Override - public void readFromNBT(NBTTagCompound nbt) - { - super.readFromNBT(nbt); - this.mainBlockPosition = Vector3.readFromNBT(nbt.getCompoundTag("mainBlockPosition")); - } - - /** - * Writes a tile entity to NBT. - */ - @Override - public void writeToNBT(NBTTagCompound nbt) - { - super.writeToNBT(nbt); - - if (this.mainBlockPosition != null) - { - nbt.setCompoundTag("mainBlockPosition", this.mainBlockPosition.writeToNBT(new NBTTagCompound())); - } - } - - /** - * Determines if this TileEntity requires update calls. - * - * @return True if you want updateEntity() to be called, false if not - */ - @Override - public boolean canUpdate() - { - return false; - } - - @Override - public void handlePacketData(INetworkManager network, int packetType, Packet250CustomPayload packet, EntityPlayer player, ByteArrayDataInput dataStream) - { - try - { - this.mainBlockPosition = new Vector3(dataStream.readInt(), dataStream.readInt(), dataStream.readInt()); - } - catch (Exception e) - { - e.printStackTrace(); - } - } -} \ No newline at end of file diff --git a/common/universalelectricity/prefab/network/IPacketReceiver.java b/common/universalelectricity/prefab/network/IPacketReceiver.java deleted file mode 100644 index 65f638332..000000000 --- a/common/universalelectricity/prefab/network/IPacketReceiver.java +++ /dev/null @@ -1,15 +0,0 @@ -package universalelectricity.prefab.network; - -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.network.INetworkManager; -import net.minecraft.network.packet.Packet250CustomPayload; - -import com.google.common.io.ByteArrayDataInput; - -public interface IPacketReceiver -{ - /** - * Sends some data to the tile entity. - */ - public void handlePacketData(INetworkManager network, int packetType, Packet250CustomPayload packet, EntityPlayer player, ByteArrayDataInput dataStream); -} diff --git a/common/universalelectricity/prefab/network/PacketManager.java b/common/universalelectricity/prefab/network/PacketManager.java deleted file mode 100644 index 9311e9e96..000000000 --- a/common/universalelectricity/prefab/network/PacketManager.java +++ /dev/null @@ -1,304 +0,0 @@ -package universalelectricity.prefab.network; - -import java.io.ByteArrayOutputStream; -import java.io.DataOutputStream; -import java.io.IOException; - -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.nbt.CompressedStreamTools; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.network.INetworkManager; -import net.minecraft.network.packet.Packet; -import net.minecraft.network.packet.Packet250CustomPayload; -import net.minecraft.tileentity.TileEntity; -import net.minecraft.world.World; -import universalelectricity.core.vector.Vector3; - -import com.google.common.io.ByteArrayDataInput; -import com.google.common.io.ByteStreams; - -import cpw.mods.fml.common.network.IPacketHandler; -import cpw.mods.fml.common.network.PacketDispatcher; -import cpw.mods.fml.common.network.Player; - -/** - * This class is used for sending and receiving packets between the server and the client. You can - * directly use this by registering this packet manager with NetworkMod. Example: - * - * @NetworkMod(channels = { "BasicComponents" }, clientSideRequired = true, serverSideRequired = - * false, packetHandler = PacketManager.class) - * - * Check out {@link #BasicComponents} for better reference. - * - * @author Calclavia - */ -public class PacketManager implements IPacketHandler, IPacketReceiver -{ - public enum PacketType - { - UNSPECIFIED, TILEENTITY; - - public static PacketType get(int id) - { - if (id >= 0 && id < PacketType.values().length) - { - return PacketType.values()[id]; - } - return UNSPECIFIED; - } - } - - /** - * Writes a compressed NBTTagCompound to the OutputStream - */ - public static void writeNBTTagCompound(NBTTagCompound tag, DataOutputStream dataStream) throws IOException - { - if (tag == null) - { - dataStream.writeShort(-1); - } - else - { - byte[] var2 = CompressedStreamTools.compress(tag); - dataStream.writeShort((short) var2.length); - dataStream.write(var2); - } - } - - /** - * Reads a compressed NBTTagCompount in a ByteStream. - */ - public static NBTTagCompound readNBTTagCompound(ByteArrayDataInput dataStream) throws IOException - { - short var1 = dataStream.readShort(); - - if (var1 < 0) - { - return null; - } - else - { - byte[] var2 = new byte[var1]; - dataStream.readFully(var2); - return CompressedStreamTools.decompress(var2); - } - } - - @SuppressWarnings("resource") - public static Packet getPacketWithID(String channelName, int id, Object... sendData) - { - ByteArrayOutputStream bytes = new ByteArrayOutputStream(); - DataOutputStream data = new DataOutputStream(bytes); - - try - { - data.writeInt(id); - data = encodeDataStream(data, sendData); - - Packet250CustomPayload packet = new Packet250CustomPayload(); - packet.channel = channelName; - packet.data = bytes.toByteArray(); - packet.length = packet.data.length; - - return packet; - } - catch (IOException e) - { - System.out.println("Failed to create packet."); - e.printStackTrace(); - } - - return null; - } - - public static Packet getPacket(String channelName, Object... sendData) - { - return getPacketWithID(channelName, PacketType.UNSPECIFIED.ordinal(), sendData); - } - - /** - * Gets a packet for the tile entity. - * - * @return - */ - @SuppressWarnings("resource") - public static Packet getPacket(String channelName, TileEntity sender, Object... sendData) - { - ByteArrayOutputStream bytes = new ByteArrayOutputStream(); - DataOutputStream data = new DataOutputStream(bytes); - - try - { - data.writeInt(PacketType.TILEENTITY.ordinal()); - - data.writeInt(sender.xCoord); - data.writeInt(sender.yCoord); - data.writeInt(sender.zCoord); - data = encodeDataStream(data, sendData); - - Packet250CustomPayload packet = new Packet250CustomPayload(); - packet.channel = channelName; - packet.data = bytes.toByteArray(); - packet.length = packet.data.length; - - return packet; - } - catch (IOException e) - { - System.out.println("Failed to create packet."); - e.printStackTrace(); - } - - return null; - } - - /** - * Sends packets to clients around a specific coordinate. A wrapper using Vector3. See - * {@PacketDispatcher} for detailed information. - */ - public static void sendPacketToClients(Packet packet, World worldObj, Vector3 position, double range) - { - try - { - PacketDispatcher.sendPacketToAllAround(position.x, position.y, position.z, range, worldObj.provider.dimensionId, packet); - } - catch (Exception e) - { - System.out.println("Sending packet to client failed."); - e.printStackTrace(); - } - } - - /** - * Sends a packet to all the clients on this server. - */ - public static void sendPacketToClients(Packet packet, World worldObj) - { - try - { - PacketDispatcher.sendPacketToAllInDimension(packet, worldObj.provider.dimensionId); - } - catch (Exception e) - { - System.out.println("Sending packet to client failed."); - e.printStackTrace(); - } - } - - public static void sendPacketToClients(Packet packet) - { - try - { - PacketDispatcher.sendPacketToAllPlayers(packet); - } - catch (Exception e) - { - System.out.println("Sending packet to client failed."); - e.printStackTrace(); - } - } - - public static DataOutputStream encodeDataStream(DataOutputStream data, Object... sendData) - { - try - { - for (Object dataValue : sendData) - { - if (dataValue instanceof Integer) - { - data.writeInt((Integer) dataValue); - } - else if (dataValue instanceof Float) - { - data.writeFloat((Float) dataValue); - } - else if (dataValue instanceof Double) - { - data.writeDouble((Double) dataValue); - } - else if (dataValue instanceof Byte) - { - data.writeByte((Byte) dataValue); - } - else if (dataValue instanceof Boolean) - { - data.writeBoolean((Boolean) dataValue); - } - else if (dataValue instanceof String) - { - data.writeUTF((String) dataValue); - } - else if (dataValue instanceof Short) - { - data.writeShort((Short) dataValue); - } - else if (dataValue instanceof Long) - { - data.writeLong((Long) dataValue); - } - else if (dataValue instanceof NBTTagCompound) - { - writeNBTTagCompound((NBTTagCompound) dataValue, data); - } - } - - return data; - } - catch (IOException e) - { - System.out.println("Packet data encoding failed."); - e.printStackTrace(); - } - - return data; - } - - @Override - public void onPacketData(INetworkManager network, Packet250CustomPayload packet, Player player) - { - try - { - ByteArrayDataInput data = ByteStreams.newDataInput(packet.data); - - int packetTypeID = data.readInt(); - - PacketType packetType = PacketType.get(packetTypeID); - - if (packetType == PacketType.TILEENTITY) - { - int x = data.readInt(); - int y = data.readInt(); - int z = data.readInt(); - - World world = ((EntityPlayer) player).worldObj; - - if (world != null) - { - TileEntity tileEntity = world.getBlockTileEntity(x, y, z); - - if (tileEntity != null) - { - if (tileEntity instanceof IPacketReceiver) - { - ((IPacketReceiver) tileEntity).handlePacketData(network, packetTypeID, packet, ((EntityPlayer) player), data); - } - } - } - } - else - { - this.handlePacketData(network, packetTypeID, packet, ((EntityPlayer) player), data); - } - } - catch (Exception e) - { - e.printStackTrace(); - } - } - - @Override - public void handlePacketData(INetworkManager network, int packetType, Packet250CustomPayload packet, EntityPlayer player, ByteArrayDataInput dataStream) - { - - } -} \ No newline at end of file diff --git a/common/universalelectricity/prefab/ore/OreGenBase.java b/common/universalelectricity/prefab/ore/OreGenBase.java deleted file mode 100644 index 486d43516..000000000 --- a/common/universalelectricity/prefab/ore/OreGenBase.java +++ /dev/null @@ -1,99 +0,0 @@ -package universalelectricity.prefab.ore; - -import java.util.Random; - -import net.minecraft.block.Block; -import net.minecraft.item.ItemStack; -import net.minecraft.world.World; -import net.minecraft.world.chunk.IChunkProvider; -import net.minecraftforge.common.Configuration; -import net.minecraftforge.common.MinecraftForge; -import net.minecraftforge.oredict.OreDictionary; -import cpw.mods.fml.common.FMLLog; - -/** - * This class is used for storing ore generation data. If you are too lazy to generate your own - * ores, you can do {@link #OreGenerator.ORES_TO_GENERATE.add()} to add your ore to the list of ores - * to generate. - * - * @author Calclavia - * - */ -public abstract class OreGenBase -{ - public String name; - - public String oreDictionaryName; - - public boolean shouldGenerate = false; - - public int blockIndexTexture; - - public ItemStack oreStack; - - public int oreID; - - public int oreMeta; - - /** - * What harvest level does this machine need to be acquired? - */ - public int harvestLevel; - - /** - * The predefined tool classes are "pickaxe", "shovel", "axe". You can add others for custom - * tools. - */ - public String harvestTool; - - /** - * @param name - The name of the ore for display - * @param textureFile - The 16x16 png texture of your ore to override - * @param minGenerateLevel - The highest generation level of your ore - * @param maxGenerateLevel - The lowest generation level of your ore - * @param amountPerChunk - The amount of ores to generate per chunk - * @param amountPerBranch - The amount of ores to generate in a clutter. E.g coal generates with - * a lot of other coal next to it. How much do you want? - */ - public OreGenBase(String name, String oreDiectionaryName, ItemStack stack, String harvestTool, int harvestLevel) - { - if (stack != null) - { - this.name = name; - this.harvestTool = harvestTool; - this.harvestLevel = harvestLevel; - this.oreDictionaryName = oreDiectionaryName; - this.oreStack = stack; - this.oreID = stack.itemID; - this.oreMeta = stack.getItemDamage(); - - OreDictionary.registerOre(oreDictionaryName, stack); - MinecraftForge.setBlockHarvestLevel(Block.blocksList[stack.itemID], stack.getItemDamage(), harvestTool, harvestLevel); - } - else - { - FMLLog.severe("ItemStack is null while registering ore generation!"); - } - } - - public OreGenBase enable(Configuration config) - { - this.shouldGenerate = shouldGenerateOre(config, this.name); - return this; - } - - /** - * Checks the config file and see if Universal Electricity should generate this ore - */ - private static boolean shouldGenerateOre(Configuration configuration, String oreName) - { - configuration.load(); - boolean shouldGenerate = configuration.get("Ore_Generation", "Generate " + oreName, true).getBoolean(true); - configuration.save(); - return shouldGenerate; - } - - public abstract void generate(World world, Random random, int varX, int varZ); - - public abstract boolean isOreGeneratedInWorld(World world, IChunkProvider chunkGenerator); -} diff --git a/common/universalelectricity/prefab/ore/OreGenReplace.java b/common/universalelectricity/prefab/ore/OreGenReplace.java deleted file mode 100644 index 6f674e6ae..000000000 --- a/common/universalelectricity/prefab/ore/OreGenReplace.java +++ /dev/null @@ -1,153 +0,0 @@ -package universalelectricity.prefab.ore; - -import java.util.Random; - -import net.minecraft.item.ItemStack; -import net.minecraft.util.MathHelper; -import net.minecraft.world.World; -import net.minecraft.world.chunk.IChunkProvider; -import net.minecraft.world.gen.ChunkProviderEnd; -import net.minecraft.world.gen.ChunkProviderGenerate; -import net.minecraft.world.gen.ChunkProviderHell; - -/** - * This class is used for storing ore generation data. If you are too lazy to generate your own - * ores, you can do {@link #OreGenerator.ORES_TO_GENERATE.add()} to add your ore to the list of ores - * to generate. - * - * @author Calclavia - * - */ -public class OreGenReplace extends OreGenBase -{ - - public int minGenerateLevel; - public int maxGenerateLevel; - public int amountPerChunk; - public int amountPerBranch; - public int replaceID; - - /** - * Dimensions to ignore ore generation - */ - public boolean ignoreSurface = false; - public boolean ignoreNether = true; - public boolean ignoreEnd = true; - - /** - * @param name - The name of the ore for display - * @param textureFile - The 16x16 png texture of your ore to override - * @param minGenerateLevel - The highest generation level of your ore - * @param maxGenerateLevel - The lowest generation level of your ore - * @param amountPerChunk - The amount of ores to generate per chunk - * @param amountPerBranch - The amount of ores to generate in a clutter. E.g coal generates with - * a lot of other coal next to it. How much do you want? - */ - public OreGenReplace(String name, String oreDiectionaryName, ItemStack stack, int replaceID, int minGenerateLevel, int maxGenerateLevel, int amountPerChunk, int amountPerBranch, String harvestTool, int harvestLevel) - { - super(name, oreDiectionaryName, stack, harvestTool, harvestLevel); - this.minGenerateLevel = minGenerateLevel; - this.maxGenerateLevel = maxGenerateLevel; - this.amountPerChunk = amountPerChunk; - this.amountPerBranch = amountPerBranch; - this.replaceID = replaceID; - } - - @Override - public void generate(World world, Random random, int varX, int varZ) - { - try - { - for (int i = 0; i < this.amountPerChunk; i++) - { - int x = varX + random.nextInt(16); - int z = varZ + random.nextInt(16); - int y = random.nextInt(Math.max(this.maxGenerateLevel - this.minGenerateLevel, 0)) + this.minGenerateLevel; - this.generateReplace(world, random, x, y, z); - } - } - catch (Exception e) - { - System.out.println("Error generating ore: " + this.name); - e.printStackTrace(); - } - } - - public boolean generateReplace(World par1World, Random par2Random, int par3, int par4, int par5) - { - float var6 = par2Random.nextFloat() * (float) Math.PI; - double var7 = par3 + 8 + MathHelper.sin(var6) * this.amountPerBranch / 8.0F; - double var9 = par3 + 8 - MathHelper.sin(var6) * this.amountPerBranch / 8.0F; - double var11 = par5 + 8 + MathHelper.cos(var6) * this.amountPerBranch / 8.0F; - double var13 = par5 + 8 - MathHelper.cos(var6) * this.amountPerBranch / 8.0F; - double var15 = par4 + par2Random.nextInt(3) - 2; - double var17 = par4 + par2Random.nextInt(3) - 2; - - for (int var19 = 0; var19 <= this.amountPerBranch; ++var19) - { - double var20 = var7 + (var9 - var7) * var19 / this.amountPerBranch; - double var22 = var15 + (var17 - var15) * var19 / this.amountPerBranch; - double var24 = var11 + (var13 - var11) * var19 / this.amountPerBranch; - double var26 = par2Random.nextDouble() * this.amountPerBranch / 16.0D; - double var28 = (MathHelper.sin(var19 * (float) Math.PI / this.amountPerBranch) + 1.0F) * var26 + 1.0D; - double var30 = (MathHelper.sin(var19 * (float) Math.PI / this.amountPerBranch) + 1.0F) * var26 + 1.0D; - int var32 = MathHelper.floor_double(var20 - var28 / 2.0D); - int var33 = MathHelper.floor_double(var22 - var30 / 2.0D); - int var34 = MathHelper.floor_double(var24 - var28 / 2.0D); - int var35 = MathHelper.floor_double(var20 + var28 / 2.0D); - int var36 = MathHelper.floor_double(var22 + var30 / 2.0D); - int var37 = MathHelper.floor_double(var24 + var28 / 2.0D); - - for (int var38 = var32; var38 <= var35; ++var38) - { - double var39 = (var38 + 0.5D - var20) / (var28 / 2.0D); - - if (var39 * var39 < 1.0D) - { - for (int var41 = var33; var41 <= var36; ++var41) - { - double var42 = (var41 + 0.5D - var22) / (var30 / 2.0D); - - if (var39 * var39 + var42 * var42 < 1.0D) - { - for (int var44 = var34; var44 <= var37; ++var44) - { - double var45 = (var44 + 0.5D - var24) / (var28 / 2.0D); - - int block = par1World.getBlockId(var38, var41, var44); - if (var39 * var39 + var42 * var42 + var45 * var45 < 1.0D && (this.replaceID == 0 || block == this.replaceID)) - { - par1World.setBlock(var38, var41, var44, this.oreID, this.oreMeta, 2); - } - } - } - } - } - } - } - - return true; - } - - @Override - public boolean isOreGeneratedInWorld(World world, IChunkProvider chunkGenerator) - { - if (!this.shouldGenerate) - { - return false; - } - if (this.ignoreSurface && chunkGenerator instanceof ChunkProviderGenerate) - { - return false; - } - if (this.ignoreNether && chunkGenerator instanceof ChunkProviderHell) - { - return false; - } - if (this.ignoreEnd && chunkGenerator instanceof ChunkProviderEnd) - { - return false; - } - return true; - } -} diff --git a/common/universalelectricity/prefab/ore/OreGenReplaceStone.java b/common/universalelectricity/prefab/ore/OreGenReplaceStone.java deleted file mode 100644 index 151be2d47..000000000 --- a/common/universalelectricity/prefab/ore/OreGenReplaceStone.java +++ /dev/null @@ -1,17 +0,0 @@ -package universalelectricity.prefab.ore; - -import net.minecraft.item.ItemStack; - -public class OreGenReplaceStone extends OreGenReplace -{ - public OreGenReplaceStone(String name, String oreDiectionaryName, ItemStack stack, int minGenerateLevel, int maxGenerateLevel, int amountPerChunk, int amountPerBranch, String harvestTool, int harvestLevel) - { - super(name, oreDiectionaryName, stack, 1, minGenerateLevel, maxGenerateLevel, amountPerChunk, amountPerBranch, harvestTool, harvestLevel); - } - - // A simplified version of the constructor - public OreGenReplaceStone(String name, String oreDiectionaryName, ItemStack stack, int maxGenerateLevel, int amountPerChunk, int amountPerBranch) - { - this(name, oreDiectionaryName, stack, 0, maxGenerateLevel, amountPerChunk, amountPerBranch, "pickaxe", 1); - } -} diff --git a/common/universalelectricity/prefab/ore/OreGenerator.java b/common/universalelectricity/prefab/ore/OreGenerator.java deleted file mode 100644 index e0b2796a5..000000000 --- a/common/universalelectricity/prefab/ore/OreGenerator.java +++ /dev/null @@ -1,78 +0,0 @@ -package universalelectricity.prefab.ore; - -import java.util.ArrayList; -import java.util.List; -import java.util.Random; - -import net.minecraft.world.World; -import net.minecraft.world.chunk.IChunkProvider; -import cpw.mods.fml.common.IWorldGenerator; -import cpw.mods.fml.common.registry.GameRegistry; - -public class OreGenerator implements IWorldGenerator -{ - public static boolean isInitiated = false; - - /** - * Add your ore data to this list of ores for it to automatically generate! No hassle indeed! - */ - private static final List ORES_TO_GENERATE = new ArrayList(); - - /** - * Adds an ore to the ore generate list. Do this in pre-init. - */ - public static void addOre(OreGenBase data) - { - if (!isInitiated) - { - GameRegistry.registerWorldGenerator(new OreGenerator()); - } - - ORES_TO_GENERATE.add(data); - } - - /** - * Checks to see if this ore - * - * @param oreName - * @return - */ - public static boolean oreExists(String oreName) - { - for (OreGenBase ore : ORES_TO_GENERATE) - { - if (ore.oreDictionaryName == oreName) - { - return true; - } - } - - return false; - } - - /** - * Removes an ore to the ore generate list. Do this in init. - */ - public static void removeOre(OreGenBase data) - { - ORES_TO_GENERATE.remove(data); - } - - @Override - public void generate(Random rand, int chunkX, int chunkZ, World world, IChunkProvider chunkGenerator, IChunkProvider chunkProvider) - { - chunkX = chunkX << 4; - chunkZ = chunkZ << 4; - - // Checks to make sure this is the normal - // world - for (OreGenBase oreData : ORES_TO_GENERATE) - { - if (oreData.shouldGenerate && oreData.isOreGeneratedInWorld(world, chunkGenerator)) - { - oreData.generate(world, rand, chunkX, chunkZ); - } - - } - } -} diff --git a/common/universalelectricity/prefab/potion/CustomPotion.java b/common/universalelectricity/prefab/potion/CustomPotion.java deleted file mode 100644 index 0dc997cab..000000000 --- a/common/universalelectricity/prefab/potion/CustomPotion.java +++ /dev/null @@ -1,35 +0,0 @@ -package universalelectricity.prefab.potion; - -import net.minecraft.potion.Potion; - -public abstract class CustomPotion extends Potion -{ - /** - * Creates a new type of potion - * - * @param id - The ID of this potion. Make it greater than 20. - * @param isBadEffect - Is this potion a good potion or a bad one? - * @param color - The color of this potion. - * @param name - The name of this potion. - */ - public CustomPotion(int id, boolean isBadEffect, int color, String name) - { - super(id, isBadEffect, color); - this.setPotionName("potion." + name); - Potion.potionTypes[this.getId()] = this; - } - - @Override - public Potion setIconIndex(int par1, int par2) - { - super.setIconIndex(par1, par2); - return this; - } - - @Override - protected Potion setEffectiveness(double par1) - { - super.setEffectiveness(par1); - return this; - } -} diff --git a/common/universalelectricity/prefab/potion/CustomPotionEffect.java b/common/universalelectricity/prefab/potion/CustomPotionEffect.java deleted file mode 100644 index 788b623d4..000000000 --- a/common/universalelectricity/prefab/potion/CustomPotionEffect.java +++ /dev/null @@ -1,40 +0,0 @@ -package universalelectricity.prefab.potion; - -import java.util.ArrayList; -import java.util.List; - -import net.minecraft.item.ItemStack; -import net.minecraft.potion.Potion; -import net.minecraft.potion.PotionEffect; - -public class CustomPotionEffect extends PotionEffect -{ - public CustomPotionEffect(int potionID, int duration, int amplifier) - { - super(potionID, duration, amplifier); - } - - public CustomPotionEffect(Potion potion, int duration, int amplifier) - { - this(potion.getId(), duration, amplifier); - } - - /** - * Creates a potion effect with custom curable items. - * - * @param curativeItems - ItemStacks that can cure this potion effect - */ - public CustomPotionEffect(int potionID, int duration, int amplifier, List curativeItems) - { - super(potionID, duration, amplifier); - - if (curativeItems == null) - { - this.setCurativeItems(new ArrayList()); - } - else - { - this.setCurativeItems(curativeItems); - } - } -} diff --git a/common/universalelectricity/prefab/tile/TileEntityAdvanced.java b/common/universalelectricity/prefab/tile/TileEntityAdvanced.java deleted file mode 100644 index 7da0f23d0..000000000 --- a/common/universalelectricity/prefab/tile/TileEntityAdvanced.java +++ /dev/null @@ -1,62 +0,0 @@ -package universalelectricity.prefab.tile; - -import net.minecraft.block.Block; -import net.minecraft.tileentity.TileEntity; - -/** - * A TileEntity with some pre-added functionalities. - * - * @author Calclavia - * - */ -public abstract class TileEntityAdvanced extends TileEntity -{ - protected long ticks = 0; - - @Override - public void updateEntity() - { - if (this.ticks == 0) - { - this.initiate(); - } - - if (this.ticks >= Long.MAX_VALUE) - { - this.ticks = 1; - } - - this.ticks++; - } - - /** - * Called on the TileEntity's first tick. - * DEPRECATED: Use validate instead! - */ - @Deprecated - public void initiate() - { - } - - @Override - public int getBlockMetadata() - { - if (this.blockMetadata == -1) - { - this.blockMetadata = this.worldObj.getBlockMetadata(this.xCoord, this.yCoord, this.zCoord); - } - - return this.blockMetadata; - } - - @Override - public Block getBlockType() - { - if (this.blockType == null) - { - this.blockType = Block.blocksList[this.worldObj.getBlockId(this.xCoord, this.yCoord, this.zCoord)]; - } - - return this.blockType; - } -} diff --git a/common/universalelectricity/prefab/tile/TileEntityConductor.java b/common/universalelectricity/prefab/tile/TileEntityConductor.java deleted file mode 100644 index 1e2bed63b..000000000 --- a/common/universalelectricity/prefab/tile/TileEntityConductor.java +++ /dev/null @@ -1,186 +0,0 @@ -package universalelectricity.prefab.tile; - -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.network.INetworkManager; -import net.minecraft.network.packet.Packet; -import net.minecraft.network.packet.Packet250CustomPayload; -import net.minecraft.tileentity.TileEntity; -import net.minecraft.util.AxisAlignedBB; -import net.minecraftforge.common.ForgeDirection; - -import org.bouncycastle.util.Arrays; - -import universalelectricity.core.block.IConductor; -import universalelectricity.core.block.IConnector; -import universalelectricity.core.block.INetworkProvider; -import universalelectricity.core.electricity.ElectricityNetwork; -import universalelectricity.core.electricity.IElectricityNetwork; -import universalelectricity.core.vector.Vector3; -import universalelectricity.core.vector.VectorHelper; -import universalelectricity.prefab.network.IPacketReceiver; -import universalelectricity.prefab.network.PacketManager; - -import com.google.common.io.ByteArrayDataInput; - -import cpw.mods.fml.relauncher.Side; -import cpw.mods.fml.relauncher.SideOnly; - -/** - * This tile entity pre-fabricated for all conductors. - * - * @author Calclavia - * - */ -public abstract class TileEntityConductor extends TileEntityAdvanced implements IConductor, IPacketReceiver -{ - private IElectricityNetwork network; - - /** - * Used client side to render. - */ - public boolean[] visuallyConnected = { false, false, false, false, false, false }; - - /** - * Stores information on the blocks that this conductor is connected to. - */ - public TileEntity[] connectedBlocks = { null, null, null, null, null, null }; - - protected String channel = ""; - - public void updateConnection(TileEntity tileEntity, ForgeDirection side) - { - if (!this.worldObj.isRemote) - { - if (tileEntity instanceof IConnector) - { - if (((IConnector) tileEntity).canConnect(side.getOpposite())) - { - this.connectedBlocks[side.ordinal()] = tileEntity; - this.visuallyConnected[side.ordinal()] = true; - - if (tileEntity.getClass() == this.getClass() && tileEntity instanceof INetworkProvider) - { - this.getNetwork().mergeConnection(((INetworkProvider) tileEntity).getNetwork()); - } - - return; - } - } - - if (this.connectedBlocks[side.ordinal()] != null) - { - this.getNetwork().stopProducing(this.connectedBlocks[side.ordinal()]); - this.getNetwork().stopRequesting(this.connectedBlocks[side.ordinal()]); - } - - this.connectedBlocks[side.ordinal()] = null; - this.visuallyConnected[side.ordinal()] = false; - } - } - - @Override - public void handlePacketData(INetworkManager network, int type, Packet250CustomPayload packet, EntityPlayer player, ByteArrayDataInput dataStream) - { - if (this.worldObj.isRemote) - { - this.visuallyConnected[0] = dataStream.readBoolean(); - this.visuallyConnected[1] = dataStream.readBoolean(); - this.visuallyConnected[2] = dataStream.readBoolean(); - this.visuallyConnected[3] = dataStream.readBoolean(); - this.visuallyConnected[4] = dataStream.readBoolean(); - this.visuallyConnected[5] = dataStream.readBoolean(); - } - } - - @Override - public void validate() - { - this.updateAdjacentConnections(); - super.validate(); - } - - @Override - public void invalidate() - { - if (!this.worldObj.isRemote) - { - this.getNetwork().splitNetwork(this); - } - - super.invalidate(); - } - - @Override - public boolean canUpdate() - { - return false; - } - - @Override - public void updateAdjacentConnections() - { - if (this.worldObj != null) - { - if (!this.worldObj.isRemote) - { - boolean[] previousConnections = this.visuallyConnected.clone(); - - for (byte i = 0; i < 6; i++) - { - this.updateConnection(VectorHelper.getConnectorFromSide(this.worldObj, new Vector3(this), ForgeDirection.getOrientation(i)), ForgeDirection.getOrientation(i)); - } - - /** - * Only send packet updates if visuallyConnected changed. - */ - if (!Arrays.areEqual(previousConnections, this.visuallyConnected)) - { - this.worldObj.markBlockForUpdate(this.xCoord, this.yCoord, this.zCoord); - } - } - - } - } - - @Override - public Packet getDescriptionPacket() - { - return PacketManager.getPacket(this.channel, this, this.visuallyConnected[0], this.visuallyConnected[1], this.visuallyConnected[2], this.visuallyConnected[3], this.visuallyConnected[4], this.visuallyConnected[5]); - } - - @Override - public IElectricityNetwork getNetwork() - { - if (this.network == null) - { - this.setNetwork(new ElectricityNetwork(this)); - } - - return this.network; - } - - @Override - public void setNetwork(IElectricityNetwork network) - { - this.network = network; - } - - @Override - public TileEntity[] getAdjacentConnections() - { - return this.connectedBlocks; - } - - @Override - public boolean canConnect(ForgeDirection direction) - { - return true; - } - - @Override - @SideOnly(Side.CLIENT) - public AxisAlignedBB getRenderBoundingBox() - { - return AxisAlignedBB.getAABBPool().getAABB(this.xCoord, this.yCoord, this.zCoord, this.xCoord + 1, this.yCoord + 1, this.zCoord + 1); - } -} diff --git a/common/universalelectricity/prefab/tile/TileEntityDisableable.java b/common/universalelectricity/prefab/tile/TileEntityDisableable.java deleted file mode 100644 index 8347a113f..000000000 --- a/common/universalelectricity/prefab/tile/TileEntityDisableable.java +++ /dev/null @@ -1,46 +0,0 @@ -package universalelectricity.prefab.tile; - -import universalelectricity.prefab.implement.IDisableable; - -/** - * An easier way to implement the methods from IElectricityDisableable with default values set. - * - * @author Calclavia - */ -public abstract class TileEntityDisableable extends TileEntityAdvanced implements IDisableable -{ - protected int disabledTicks = 0; - - @Override - public void updateEntity() - { - super.updateEntity(); - - if (this.disabledTicks > 0) - { - this.disabledTicks--; - this.whileDisable(); - return; - } - } - - /** - * Called every tick while this tile entity is disabled. - */ - protected void whileDisable() - { - - } - - @Override - public void onDisable(int duration) - { - this.disabledTicks = duration; - } - - @Override - public boolean isDisabled() - { - return this.disabledTicks > 0; - } -} diff --git a/common/universalelectricity/prefab/tile/TileEntityElectrical.java b/common/universalelectricity/prefab/tile/TileEntityElectrical.java deleted file mode 100644 index 3d2dcb015..000000000 --- a/common/universalelectricity/prefab/tile/TileEntityElectrical.java +++ /dev/null @@ -1,38 +0,0 @@ -package universalelectricity.prefab.tile; - -import universalelectricity.core.block.IConnector; -import universalelectricity.core.block.IVoltage; -import universalelectricity.core.electricity.ElectricityNetworkHelper; - -/** - * Extend this if your TileEntity is electrical. - * - * @author Calclavia - */ -public abstract class TileEntityElectrical extends TileEntityDisableable implements IConnector, IVoltage -{ - public TileEntityElectrical() - { - super(); - } - - @Override - public void updateEntity() - { - super.updateEntity(); - } - - @Override - public double getVoltage() - { - return 120; - } - - @Override - public void invalidate() - { - ElectricityNetworkHelper.invalidate(this); - super.invalidate(); - - } -} diff --git a/common/universalelectricity/prefab/tile/TileEntityElectricityRunnable.java b/common/universalelectricity/prefab/tile/TileEntityElectricityRunnable.java deleted file mode 100644 index 5256ab656..000000000 --- a/common/universalelectricity/prefab/tile/TileEntityElectricityRunnable.java +++ /dev/null @@ -1,96 +0,0 @@ -package universalelectricity.prefab.tile; - -import java.util.EnumSet; - -import net.minecraftforge.common.ForgeDirection; -import universalelectricity.core.UniversalElectricity; -import universalelectricity.core.electricity.ElectricityNetworkHelper; -import universalelectricity.core.electricity.ElectricityPack; - -/** - * This class should be extended by TileEntities that run on electricity but do not store them. - * Things such as electric furnaces should extend this. Take this class mainly as an example. - * - * @author Calclavia - * - */ -public abstract class TileEntityElectricityRunnable extends TileEntityElectrical -{ - /** - * The amount of watts received this tick. This variable should be deducted when used. - */ - public double prevWatts, wattsReceived = 0; - - @Override - public void updateEntity() - { - super.updateEntity(); - - this.prevWatts = this.wattsReceived; - - /** - * ElectricityManager works on server side. - */ - if (!this.worldObj.isRemote) - { - /** - * If the machine is disabled, stop requesting electricity. - */ - if (!this.isDisabled()) - { - ElectricityPack electricityPack = ElectricityNetworkHelper.consumeFromMultipleSides(this, this.getConsumingSides(), this.getRequest()); - this.onReceive(electricityPack); - } - else - { - ElectricityNetworkHelper.consumeFromMultipleSides(this, new ElectricityPack()); - } - } - } - - protected EnumSet getConsumingSides() - { - return ElectricityNetworkHelper.getDirections(this); - } - - /** - * Returns the amount of energy being requested this tick. Return an empty ElectricityPack if no - * electricity is desired. - */ - public ElectricityPack getRequest() - { - return new ElectricityPack(); - } - - /** - * Called right after electricity is transmitted to the TileEntity. Override this if you wish to - * have another effect for a voltage overcharge. - * - * @param electricityPack - */ - public void onReceive(ElectricityPack electricityPack) - { - /** - * Creates an explosion if the voltage is too high. - */ - if (UniversalElectricity.isVoltageSensitive) - { - if (electricityPack.voltage > this.getVoltage()) - { - this.worldObj.createExplosion(null, this.xCoord, this.yCoord, this.zCoord, 1.5f, true); - return; - } - } - - this.wattsReceived = Math.min(this.wattsReceived + electricityPack.getWatts(), this.getWattBuffer()); - } - - /** - * @return The amount of internal buffer that may be stored within this machine. This will make - * the machine run smoother as electricity might not always be consistent. - */ - public double getWattBuffer() - { - return this.getRequest().getWatts() * 2; - } -} \ No newline at end of file diff --git a/common/universalelectricity/prefab/tile/TileEntityElectricityStorage.java b/common/universalelectricity/prefab/tile/TileEntityElectricityStorage.java deleted file mode 100644 index f3214e376..000000000 --- a/common/universalelectricity/prefab/tile/TileEntityElectricityStorage.java +++ /dev/null @@ -1,110 +0,0 @@ -package universalelectricity.prefab.tile; - -import java.util.EnumSet; - -import net.minecraft.nbt.NBTTagCompound; -import net.minecraftforge.common.ForgeDirection; -import universalelectricity.core.UniversalElectricity; -import universalelectricity.core.block.IElectricityStorage; -import universalelectricity.core.electricity.ElectricityNetworkHelper; -import universalelectricity.core.electricity.ElectricityPack; - -public abstract class TileEntityElectricityStorage extends TileEntityElectrical implements IElectricityStorage -{ - /** - * The amount of joules stored within this machine. Use get and set functions instead of - * referencing to this variable. - */ - private double joules = 0; - - public double prevJoules = 0; - - @Override - public void updateEntity() - { - super.updateEntity(); - - this.prevJoules = joules; - - if (!this.worldObj.isRemote) - { - if (!this.isDisabled()) - { - ElectricityPack electricityPack = ElectricityNetworkHelper.consumeFromMultipleSides(this, this.getConsumingSides(), this.getRequest()); - this.onReceive(electricityPack); - } - else - { - ElectricityNetworkHelper.consumeFromMultipleSides(this, new ElectricityPack()); - } - } - - } - - protected EnumSet getConsumingSides() - { - return ElectricityNetworkHelper.getDirections(this); - } - - /** - * Returns the amount of energy being requested this tick. Return an empty ElectricityPack if no - * electricity is desired. - */ - public ElectricityPack getRequest() - { - return new ElectricityPack((this.getMaxJoules() - this.getJoules()) / this.getVoltage(), this.getVoltage()); - } - - /** - * Called right after electricity is transmitted to the TileEntity. Override this if you wish to - * have another effect for a voltage overcharge. - * - * @param electricityPack - */ - public void onReceive(ElectricityPack electricityPack) - { - /** - * Creates an explosion if the voltage is too high. - */ - if (UniversalElectricity.isVoltageSensitive) - { - if (electricityPack.voltage > this.getVoltage()) - { - this.worldObj.createExplosion(null, this.xCoord, this.yCoord, this.zCoord, 1.5f, true); - return; - } - } - - this.setJoules(this.getJoules() + electricityPack.getWatts()); - } - - @Override - public void readFromNBT(NBTTagCompound par1NBTTagCompound) - { - super.readFromNBT(par1NBTTagCompound); - this.joules = par1NBTTagCompound.getDouble("joules"); - } - - /** - * Writes a tile entity to NBT. - */ - @Override - public void writeToNBT(NBTTagCompound par1NBTTagCompound) - { - super.writeToNBT(par1NBTTagCompound); - - par1NBTTagCompound.setDouble("joules", this.joules); - } - - @Override - public double getJoules() - { - return this.joules; - } - - @Override - public void setJoules(double joules) - { - this.joules = Math.max(Math.min(joules, this.getMaxJoules()), 0); - } -} \ No newline at end of file diff --git a/common/universalelectricity/prefab/vector/Region2.java b/common/universalelectricity/prefab/vector/Region2.java deleted file mode 100644 index 6d52a746c..000000000 --- a/common/universalelectricity/prefab/vector/Region2.java +++ /dev/null @@ -1,36 +0,0 @@ -package universalelectricity.prefab.vector; - -import universalelectricity.core.vector.Vector2; - -public class Region2 -{ - public Vector2 min; - public Vector2 max; - - public Region2() - { - this(new Vector2(), new Vector2()); - } - - public Region2(Vector2 min, Vector2 max) - { - this.min = min; - this.max = max; - } - - /** - * Checks if a point is located inside a region - */ - public boolean isIn(Vector2 point) - { - return (point.x > this.min.x && point.x < this.max.x) && (point.y > this.min.y && point.y < this.max.y); - } - - /** - * Returns whether the given region intersects with this one. - */ - public boolean isIn(Region2 region) - { - return region.max.x > this.min.x && region.min.x < this.max.x ? (region.max.y > this.min.y && region.min.y < this.max.y ? true : false) : false; - } -} diff --git a/common/universalelectricity/prefab/vector/Region3.java b/common/universalelectricity/prefab/vector/Region3.java deleted file mode 100644 index 278a984b2..000000000 --- a/common/universalelectricity/prefab/vector/Region3.java +++ /dev/null @@ -1,131 +0,0 @@ -package universalelectricity.prefab.vector; - -import java.util.ArrayList; -import java.util.List; - -import net.minecraft.entity.Entity; -import net.minecraft.util.AxisAlignedBB; -import net.minecraft.world.World; -import universalelectricity.core.vector.Vector3; - -/** - * A cubical region class. - * - * @author Calclavia - */ -public class Region3 -{ - public Vector3 min; - public Vector3 max; - - public Region3() - { - this(new Vector3(), new Vector3()); - } - - public Region3(Vector3 min, Vector3 max) - { - this.min = min; - this.max = max; - } - - public Region3(AxisAlignedBB aabb) - { - this.min = new Vector3(aabb.minX, aabb.minY, aabb.minZ); - this.max = new Vector3(aabb.maxX, aabb.maxY, aabb.maxZ); - } - - public AxisAlignedBB toAABB() - { - return AxisAlignedBB.getBoundingBox(this.min.x, this.min.y, this.min.z, this.max.x, this.max.y, this.max.z); - } - - public Region2 toRegion2() - { - return new Region2(this.min.toVector2(), this.max.toVector2()); - } - - /** - * Checks if a point is located inside a region - */ - public boolean isIn(Vector3 point) - { - return (point.x > this.min.x && point.x < this.max.x) && (point.y > this.min.y && point.y < this.max.y) && (point.z > this.min.z && point.z < this.max.z); - } - - /** - * Returns whether the given region intersects with this one. - */ - public boolean isIn(Region3 region) - { - return region.max.x > this.min.x && region.min.x < this.max.x ? (region.max.y > this.min.y && region.min.y < this.max.y ? region.max.z > this.min.z && region.min.z < this.max.z : false) : false; - } - - public void expand(Vector3 difference) - { - this.min.subtract(difference); - this.max.add(difference); - } - - /** - * @return List of vectors within this region. - */ - public List getVectors() - { - List vectors = new ArrayList(); - - for (int x = this.min.intX(); x < this.max.intX(); x++) - { - for (int y = this.min.intY(); x < this.max.intY(); y++) - { - for (int z = this.min.intZ(); x < this.max.intZ(); z++) - { - vectors.add(new Vector3(x, y, z)); - } - } - } - - return vectors; - } - - public List getVectors(Vector3 center, int radius) - { - List vectors = new ArrayList(); - - for (int x = this.min.intX(); x < this.max.intX(); x++) - { - for (int y = this.min.intY(); x < this.max.intY(); y++) - { - for (int z = this.min.intZ(); x < this.max.intZ(); z++) - { - Vector3 vector3 = new Vector3(x, y, z); - - if (center.distanceTo(vector3) <= radius) - { - vectors.add(vector3); - } - } - } - } - - return vectors; - } - - /** - * Returns all entities in this region. - */ - public List getEntities(World world, Class entityClass) - { - return world.getEntitiesWithinAABB(entityClass, this.toAABB()); - } - - public List getEntitiesExlude(World world, Entity entity) - { - return world.getEntitiesWithinAABBExcludingEntity(entity, this.toAABB()); - } - - public List getEntities(World world) - { - return this.getEntities(world, Entity.class); - } -} diff --git a/resources/armor/bronze_1.png b/resources/assets/mekanism/armor/bronze_1.png similarity index 100% rename from resources/armor/bronze_1.png rename to resources/assets/mekanism/armor/bronze_1.png diff --git a/resources/armor/bronze_2.png b/resources/assets/mekanism/armor/bronze_2.png similarity index 100% rename from resources/armor/bronze_2.png rename to resources/assets/mekanism/armor/bronze_2.png diff --git a/resources/armor/glowstone_1.png b/resources/assets/mekanism/armor/glowstone_1.png similarity index 100% rename from resources/armor/glowstone_1.png rename to resources/assets/mekanism/armor/glowstone_1.png diff --git a/resources/armor/glowstone_2.png b/resources/assets/mekanism/armor/glowstone_2.png similarity index 100% rename from resources/armor/glowstone_2.png rename to resources/assets/mekanism/armor/glowstone_2.png diff --git a/resources/armor/lazuli_1.png b/resources/assets/mekanism/armor/lazuli_1.png similarity index 100% rename from resources/armor/lazuli_1.png rename to resources/assets/mekanism/armor/lazuli_1.png diff --git a/resources/armor/lazuli_2.png b/resources/assets/mekanism/armor/lazuli_2.png similarity index 100% rename from resources/armor/lazuli_2.png rename to resources/assets/mekanism/armor/lazuli_2.png diff --git a/resources/armor/obsidian_1.png b/resources/assets/mekanism/armor/obsidian_1.png similarity index 100% rename from resources/armor/obsidian_1.png rename to resources/assets/mekanism/armor/obsidian_1.png diff --git a/resources/armor/obsidian_2.png b/resources/assets/mekanism/armor/obsidian_2.png similarity index 100% rename from resources/armor/obsidian_2.png rename to resources/assets/mekanism/armor/obsidian_2.png diff --git a/resources/armor/osmium_1.png b/resources/assets/mekanism/armor/osmium_1.png similarity index 100% rename from resources/armor/osmium_1.png rename to resources/assets/mekanism/armor/osmium_1.png diff --git a/resources/armor/osmium_2.png b/resources/assets/mekanism/armor/osmium_2.png similarity index 100% rename from resources/armor/osmium_2.png rename to resources/assets/mekanism/armor/osmium_2.png diff --git a/resources/armor/steel_1.png b/resources/assets/mekanism/armor/steel_1.png similarity index 100% rename from resources/armor/steel_1.png rename to resources/assets/mekanism/armor/steel_1.png diff --git a/resources/armor/steel_2.png b/resources/assets/mekanism/armor/steel_2.png similarity index 100% rename from resources/armor/steel_2.png rename to resources/assets/mekanism/armor/steel_2.png