From 041f8ff5cd380ba2057546c4419d9c23f577c3ad Mon Sep 17 00:00:00 2001 From: Calclavia Date: Tue, 24 Dec 2013 15:38:09 +0800 Subject: [PATCH] Tweaked multimeter detection code and gui --- Calclavia-Library | 2 +- Universal-Electricity | 2 +- .../battery/TileBattery.java | 4 +-- .../furnace/TileAdvancedFurnace.java | 25 +++++++++++-- src/resonantinduction/gui/GuiMultimeter.java | 7 ++-- .../multimeter/PartMultimeter.java | 35 ++----------------- src/resonantinduction/tesla/TileTesla.java | 4 +-- src/resonantinduction/wire/ItemWire.java | 4 +-- 8 files changed, 38 insertions(+), 45 deletions(-) diff --git a/Calclavia-Library b/Calclavia-Library index bf91ef82..1d94973d 160000 --- a/Calclavia-Library +++ b/Calclavia-Library @@ -1 +1 @@ -Subproject commit bf91ef825b4f6328e877857360a84039d71723df +Subproject commit 1d94973d405930d7b68a25cc0040c82a671a8fc6 diff --git a/Universal-Electricity b/Universal-Electricity index 5579379b..e69dcdcd 160000 --- a/Universal-Electricity +++ b/Universal-Electricity @@ -1 +1 @@ -Subproject commit 5579379bc616b74e7b82c64c12d8fadf8df85e94 +Subproject commit e69dcdcd40ba67043852826a9486eaf132fbe0dc diff --git a/src/resonantinduction/battery/TileBattery.java b/src/resonantinduction/battery/TileBattery.java index 3cac5681..7bbc64c4 100644 --- a/src/resonantinduction/battery/TileBattery.java +++ b/src/resonantinduction/battery/TileBattery.java @@ -12,10 +12,10 @@ import net.minecraft.entity.player.EntityPlayer; import net.minecraft.nbt.NBTTagCompound; import net.minecraftforge.common.ForgeDirection; import resonantinduction.ResonantInduction; +import universalelectricity.api.energy.EnergyStorageHandler; import universalelectricity.api.vector.Vector3; import calclavia.lib.network.IPacketReceiver; import calclavia.lib.network.IPacketSender; -import calclavia.lib.tile.EnergyStorage; import calclavia.lib.tile.TileEntityElectrical; import com.google.common.io.ByteArrayDataInput; @@ -45,7 +45,7 @@ public class TileBattery extends TileEntityElectrical implements IPacketSender, public TileBattery() { - this.energy = new EnergyStorage(1000); + this.energy = new EnergyStorageHandler(1000); } @Override diff --git a/src/resonantinduction/furnace/TileAdvancedFurnace.java b/src/resonantinduction/furnace/TileAdvancedFurnace.java index fc789b90..3829aac5 100644 --- a/src/resonantinduction/furnace/TileAdvancedFurnace.java +++ b/src/resonantinduction/furnace/TileAdvancedFurnace.java @@ -8,9 +8,10 @@ import net.minecraftforge.common.ForgeDirection; import resonantinduction.ResonantInduction; import universalelectricity.api.CompatibilityModule; import universalelectricity.api.UniversalClass; +import universalelectricity.api.energy.EnergyStorageHandler; +import universalelectricity.api.energy.IEnergyContainer; import universalelectricity.api.energy.IEnergyInterface; import universalelectricity.api.vector.Vector3; -import calclavia.lib.tile.EnergyStorage; /** * Meant to replace the furnace class. @@ -19,11 +20,11 @@ import calclavia.lib.tile.EnergyStorage; * */ @UniversalClass -public class TileAdvancedFurnace extends TileEntityFurnace implements IEnergyInterface +public class TileAdvancedFurnace extends TileEntityFurnace implements IEnergyInterface, IEnergyContainer { private static final float WATTAGE = 5; - private EnergyStorage energy = new EnergyStorage(ResonantInduction.FURNACE_WATTAGE * 5); + private EnergyStorageHandler energy = new EnergyStorageHandler(ResonantInduction.FURNACE_WATTAGE * 5); @Override public void updateEntity() @@ -193,4 +194,22 @@ public class TileAdvancedFurnace extends TileEntityFurnace implements IEnergyInt { return this.energy.extractEnergy(request, doProvide); } + + @Override + public void setEnergy(ForgeDirection from, long energy) + { + this.energy.setEnergy(energy); + } + + @Override + public long getEnergy(ForgeDirection from) + { + return this.energy.getEnergy(); + } + + @Override + public long getEnergyCapacity(ForgeDirection from) + { + return this.energy.getEnergyCapacity(); + } } diff --git a/src/resonantinduction/gui/GuiMultimeter.java b/src/resonantinduction/gui/GuiMultimeter.java index 5e099cf5..23003190 100644 --- a/src/resonantinduction/gui/GuiMultimeter.java +++ b/src/resonantinduction/gui/GuiMultimeter.java @@ -10,6 +10,7 @@ import net.minecraft.util.ResourceLocation; import resonantinduction.ResonantInduction; import resonantinduction.multimeter.ContainerMultimeter; import resonantinduction.multimeter.PartMultimeter; +import universalelectricity.api.energy.UnitDisplay.Unit; import calclavia.lib.gui.GuiContainerBase; import calclavia.lib.prefab.TranslationHelper; import cpw.mods.fml.relauncher.Side; @@ -75,8 +76,10 @@ public class GuiMultimeter extends GuiContainerBase { String s = TranslationHelper.getLocal("tile.resonantinduction:multimeter.name"); this.fontRenderer.drawString(s, this.xSize / 2 - this.fontRenderer.getStringWidth(s) / 2, 15, 4210752); - this.fontRenderer.drawString("Average Energy: " + Math.round(this.multimeter.getAverageDetectedEnergy()) + " J", 35, 25, 4210752); - this.fontRenderer.drawString("Energy: " + Math.round(this.multimeter.getDetectedEnergy()) + " J", 35, 35, 4210752); + this.fontRenderer.drawString("Average Energy:", 35, 15, 4210752); + this.renderUniversalDisplay(35, 25, this.multimeter.getAverageDetectedEnergy(), par1, par2, Unit.JOULES); + this.fontRenderer.drawString("Energy:", 35, 35, 4210752); + this.renderUniversalDisplay(35, 45, this.multimeter.getDetectedEnergy(), par1, par2, Unit.JOULES); this.fontRenderer.drawString("Output Redstone If... ", 35, 54, 4210752); this.fontRenderer.drawString(this.multimeter.getMode().display, 35, 65, 4210752); this.fontRenderer.drawString("KiloJoules", 35, 100, 4210752); diff --git a/src/resonantinduction/multimeter/PartMultimeter.java b/src/resonantinduction/multimeter/PartMultimeter.java index 3206e969..9a59104e 100644 --- a/src/resonantinduction/multimeter/PartMultimeter.java +++ b/src/resonantinduction/multimeter/PartMultimeter.java @@ -15,22 +15,15 @@ import net.minecraft.nbt.NBTTagCompound; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.MovingObjectPosition; import net.minecraftforge.common.ForgeDirection; - -import org.lwjgl.opengl.GL11; - import resonantinduction.ResonantInduction; import resonantinduction.base.PartAdvanced; -import universalelectricity.api.CompatibilityType; +import universalelectricity.api.CompatibilityModule; import universalelectricity.api.energy.IConductor; -import universalelectricity.api.energy.IEnergyContainer; import universalelectricity.api.energy.IEnergyNetwork; import universalelectricity.api.net.IConnectable; -import buildcraft.api.power.IPowerReceptor; import codechicken.lib.data.MCDataInput; import codechicken.lib.data.MCDataOutput; import codechicken.lib.raytracer.IndexedCuboid6; -import codechicken.lib.render.CCRenderState; -import codechicken.lib.render.TextureUtils; import codechicken.lib.vec.Cuboid6; import codechicken.lib.vec.Rotation; import codechicken.lib.vec.Vector3; @@ -38,8 +31,6 @@ import codechicken.multipart.JNormalOcclusion; import codechicken.multipart.NormalOcclusionTest; import codechicken.multipart.TFacePart; import codechicken.multipart.TMultiPart; -import cofh.api.energy.IEnergyHandler; -import cofh.api.energy.TileEnergyHandler; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; @@ -212,35 +203,15 @@ public class PartMultimeter extends PartAdvanced implements IConnectable, TFaceP return ForgeDirection.getOrientation(this.side); } - // TODO: Check if side is correct. public static long getDetectedEnergy(ForgeDirection side, TileEntity tileEntity) { - if (tileEntity instanceof IEnergyContainer) - { - return ((IEnergyContainer) tileEntity).getEnergy(side); - } - else if (tileEntity instanceof IConductor) + if (tileEntity instanceof IConductor) { IEnergyNetwork network = ((IConductor) tileEntity).getNetwork(); return network.getLastBuffer(); } - else if (tileEntity instanceof IEnergyHandler) - { - return (long) (((IEnergyHandler) tileEntity).getEnergyStored(side) * CompatibilityType.INDUSTRIALCRAFT.reciprocal_ratio); - } - else if (tileEntity instanceof TileEnergyHandler) - { - return (long) (((TileEnergyHandler) tileEntity).getEnergyStored(side.getOpposite()) * CompatibilityType.THERMAL_EXPANSION.reciprocal_ratio); - } - else if (tileEntity instanceof IPowerReceptor) - { - if (((IPowerReceptor) tileEntity).getPowerReceiver(side) != null) - { - return (long) (((IPowerReceptor) tileEntity).getPowerReceiver(side).getEnergyStored() * CompatibilityType.BUILDCRAFT.reciprocal_ratio); - } - } - return 0; + return CompatibilityModule.getEnergy(tileEntity, side); } public void updateDetection(long detected) diff --git a/src/resonantinduction/tesla/TileTesla.java b/src/resonantinduction/tesla/TileTesla.java index a62c56ef..66bf1104 100644 --- a/src/resonantinduction/tesla/TileTesla.java +++ b/src/resonantinduction/tesla/TileTesla.java @@ -22,11 +22,11 @@ import net.minecraft.world.World; import net.minecraftforge.common.ForgeDirection; import resonantinduction.ResonantInduction; import resonantinduction.api.ITesla; +import universalelectricity.api.energy.EnergyStorageHandler; import universalelectricity.api.vector.Vector3; import calclavia.lib.network.IPacketReceiver; import calclavia.lib.network.IPacketSender; import calclavia.lib.prefab.CustomDamageSource; -import calclavia.lib.tile.EnergyStorage; import calclavia.lib.tile.TileEntityElectrical; import com.google.common.io.ByteArrayDataInput; @@ -77,7 +77,7 @@ public class TileTesla extends TileEntityElectrical implements ITesla, IPacketSe public TileTesla() { - this.energy = new EnergyStorage(TRANSFER_CAP); + this.energy = new EnergyStorageHandler(TRANSFER_CAP); } @Override diff --git a/src/resonantinduction/wire/ItemWire.java b/src/resonantinduction/wire/ItemWire.java index 59ad060c..8381ce36 100644 --- a/src/resonantinduction/wire/ItemWire.java +++ b/src/resonantinduction/wire/ItemWire.java @@ -84,9 +84,9 @@ public class ItemWire extends JItemMultiPart else { list.add("Resistance: " + UnitDisplay.getDisplay(EnumWireMaterial.values()[itemstack.getItemDamage()].resistance, Unit.RESISTANCE)); - list.add("Max Amperage: " + UnitDisplay.getDisplay(EnumWireMaterial.values()[itemstack.getItemDamage()].maxAmps, Unit.AMPERE)); + list.add("Current Capacity: " + UnitDisplay.getDisplay(EnumWireMaterial.values()[itemstack.getItemDamage()].maxAmps, Unit.AMPERE)); list.add("Shock Damage: " + EnumWireMaterial.values()[itemstack.getItemDamage()].damage); - list.addAll(Calclavia.splitStringPerWord("The maximum transfer capacity can be increased and the energy loss may be reduced by using higher voltage.", 5)); + list.addAll(Calclavia.splitStringPerWord("The maximum energy transfer rate can be increased and the energy loss may be reduced by using higher the voltage of the network.", 5)); } }