From f8bfa1dddef3dfaea09cbf05f16d4d57727f960e Mon Sep 17 00:00:00 2001 From: Calclavia Date: Fri, 20 Dec 2013 21:59:52 +0800 Subject: [PATCH] Updated UE --- src/resonantinduction/ClientProxy.java | 2 +- src/resonantinduction/CommonProxy.java | 2 +- src/resonantinduction/ResonantInduction.java | 6 +- .../battery/BatteryUpdateProtocol.java | 2 +- .../battery/SynchronizedBatteryData.java | 2 +- .../battery/TileEntityBattery.java | 2 +- .../contractor/BlockEMContractor.java | 2 +- .../contractor/PathfinderEMContractor.java | 2 +- .../contractor/ThreadEMPathfinding.java | 2 +- .../contractor/TileEntityEMContractor.java | 2 +- .../entangler/ItemCoordLink.java | 2 +- .../entangler/ItemLinker.java | 2 +- .../entangler/ItemQuantumEntangler.java | 2 +- .../furnace/TileEntityAdvancedFurnace.java | 47 +---- src/resonantinduction/fx/FXElectricBolt.java | 2 +- src/resonantinduction/gui/GuiBattery.java | 4 +- .../multimeter/MultimeterEventHandler.java | 18 +- .../render/RenderBattery.java | 2 +- .../render/RenderMultimeter.java | 4 +- .../render/RenderPartWire.java | 2 +- src/resonantinduction/render/RenderWire.java | 2 +- src/resonantinduction/tesla/BlockTesla.java | 2 +- .../tesla/TileEntityTesla.java | 2 +- .../wire/EnumWireMaterial.java | 2 +- src/resonantinduction/wire/ItemBlockWire.java | 4 +- src/resonantinduction/wire/ItemPartWire.java | 4 +- src/resonantinduction/wire/PartConductor.java | 166 ++++++++++++------ .../wire/PartUniversalConductor.java | 6 +- src/resonantinduction/wire/PartWire.java | 2 +- .../wire/TileEntityWire.java | 6 +- 30 files changed, 167 insertions(+), 138 deletions(-) diff --git a/src/resonantinduction/ClientProxy.java b/src/resonantinduction/ClientProxy.java index 949387be..dfa4a8bb 100644 --- a/src/resonantinduction/ClientProxy.java +++ b/src/resonantinduction/ClientProxy.java @@ -19,7 +19,7 @@ import resonantinduction.render.RenderTesla; import resonantinduction.render.RenderWire; import resonantinduction.tesla.TileEntityTesla; import resonantinduction.wire.TileEntityWire; -import universalelectricity.core.vector.Vector3; +import universalelectricity.api.vector.Vector3; import cpw.mods.fml.client.FMLClientHandler; import cpw.mods.fml.client.registry.ClientRegistry; import cpw.mods.fml.client.registry.RenderingRegistry; diff --git a/src/resonantinduction/CommonProxy.java b/src/resonantinduction/CommonProxy.java index 21b20625..cadfdf0b 100644 --- a/src/resonantinduction/CommonProxy.java +++ b/src/resonantinduction/CommonProxy.java @@ -10,7 +10,7 @@ import resonantinduction.battery.ContainerBattery; import resonantinduction.battery.TileEntityBattery; import resonantinduction.multimeter.ContainerMultimeter; import resonantinduction.multimeter.TileEntityMultimeter; -import universalelectricity.core.vector.Vector3; +import universalelectricity.api.vector.Vector3; import cpw.mods.fml.common.network.IGuiHandler; /** diff --git a/src/resonantinduction/ResonantInduction.java b/src/resonantinduction/ResonantInduction.java index 39130dda..42d2af1f 100644 --- a/src/resonantinduction/ResonantInduction.java +++ b/src/resonantinduction/ResonantInduction.java @@ -41,9 +41,9 @@ import resonantinduction.wire.BlockWire; import resonantinduction.wire.EnumWireMaterial; import resonantinduction.wire.ItemBlockWire; import resonantinduction.wire.TileEntityWire; -import universalelectricity.compatibility.Compatibility; +import universalelectricity.api.Compatibility; +import universalelectricity.api.vector.Vector3; import universalelectricity.core.item.IItemElectric; -import universalelectricity.core.vector.Vector3; import basiccomponents.api.BasicRegistry; import calclavia.lib.UniversalRecipe; import calclavia.lib.network.PacketHandler; @@ -310,8 +310,6 @@ public class ResonantInduction LOGGER.severe("Failed to initiate Resonant Induction multipart module."); } } - - Compatibility.initiate(); } @EventHandler diff --git a/src/resonantinduction/battery/BatteryUpdateProtocol.java b/src/resonantinduction/battery/BatteryUpdateProtocol.java index e172721b..6aa3c731 100644 --- a/src/resonantinduction/battery/BatteryUpdateProtocol.java +++ b/src/resonantinduction/battery/BatteryUpdateProtocol.java @@ -11,7 +11,7 @@ import net.minecraft.tileentity.TileEntity; import net.minecraft.world.World; import net.minecraftforge.common.ForgeDirection; import resonantinduction.base.ListUtil; -import universalelectricity.core.vector.Vector3; +import universalelectricity.api.vector.Vector3; public class BatteryUpdateProtocol { diff --git a/src/resonantinduction/battery/SynchronizedBatteryData.java b/src/resonantinduction/battery/SynchronizedBatteryData.java index d7adbc69..0dfa0539 100644 --- a/src/resonantinduction/battery/SynchronizedBatteryData.java +++ b/src/resonantinduction/battery/SynchronizedBatteryData.java @@ -7,8 +7,8 @@ import java.util.Set; import net.minecraft.item.ItemStack; import resonantinduction.base.ListUtil; +import universalelectricity.api.vector.Vector3; import universalelectricity.core.item.IItemElectric; -import universalelectricity.core.vector.Vector3; public class SynchronizedBatteryData { diff --git a/src/resonantinduction/battery/TileEntityBattery.java b/src/resonantinduction/battery/TileEntityBattery.java index 6040bfa5..51013fb2 100644 --- a/src/resonantinduction/battery/TileEntityBattery.java +++ b/src/resonantinduction/battery/TileEntityBattery.java @@ -22,10 +22,10 @@ import net.minecraftforge.common.ForgeDirection; import resonantinduction.ResonantInduction; import resonantinduction.api.ICapacitor; import resonantinduction.base.ListUtil; +import universalelectricity.api.vector.Vector3; import universalelectricity.compatibility.TileEntityUniversalElectrical; import universalelectricity.core.electricity.ElectricityPack; import universalelectricity.core.item.IItemElectric; -import universalelectricity.core.vector.Vector3; import calclavia.lib.network.IPacketReceiver; import calclavia.lib.network.IPacketSender; diff --git a/src/resonantinduction/contractor/BlockEMContractor.java b/src/resonantinduction/contractor/BlockEMContractor.java index 558c334a..e0254fce 100644 --- a/src/resonantinduction/contractor/BlockEMContractor.java +++ b/src/resonantinduction/contractor/BlockEMContractor.java @@ -11,7 +11,7 @@ import resonantinduction.ResonantInduction; import resonantinduction.base.BlockBase; import resonantinduction.entangler.ItemCoordLink; import resonantinduction.render.BlockRenderingHandler; -import universalelectricity.core.vector.Vector3; +import universalelectricity.api.vector.Vector3; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; diff --git a/src/resonantinduction/contractor/PathfinderEMContractor.java b/src/resonantinduction/contractor/PathfinderEMContractor.java index aa8b1168..eb952681 100644 --- a/src/resonantinduction/contractor/PathfinderEMContractor.java +++ b/src/resonantinduction/contractor/PathfinderEMContractor.java @@ -11,7 +11,7 @@ import java.util.Set; import net.minecraft.world.World; import net.minecraftforge.common.ForgeDirection; -import universalelectricity.core.vector.Vector3; +import universalelectricity.api.vector.Vector3; /** * Uses the well known A* Pathfinding algorithm. diff --git a/src/resonantinduction/contractor/ThreadEMPathfinding.java b/src/resonantinduction/contractor/ThreadEMPathfinding.java index 2d068c7d..858deab6 100644 --- a/src/resonantinduction/contractor/ThreadEMPathfinding.java +++ b/src/resonantinduction/contractor/ThreadEMPathfinding.java @@ -3,7 +3,7 @@ */ package resonantinduction.contractor; -import universalelectricity.core.vector.Vector3; +import universalelectricity.api.vector.Vector3; /** * @author Calclavia diff --git a/src/resonantinduction/contractor/TileEntityEMContractor.java b/src/resonantinduction/contractor/TileEntityEMContractor.java index 3445fb19..32cdc729 100644 --- a/src/resonantinduction/contractor/TileEntityEMContractor.java +++ b/src/resonantinduction/contractor/TileEntityEMContractor.java @@ -23,7 +23,7 @@ import net.minecraftforge.common.ForgeDirection; import net.minecraftforge.fluids.IFluidBlock; import resonantinduction.ResonantInduction; import resonantinduction.tesla.TileEntityTesla; -import universalelectricity.core.vector.Vector3; +import universalelectricity.api.vector.Vector3; import calclavia.lib.InventoryHelper; import calclavia.lib.network.IPacketReceiver; import calclavia.lib.network.IPacketSender; diff --git a/src/resonantinduction/entangler/ItemCoordLink.java b/src/resonantinduction/entangler/ItemCoordLink.java index 7a9885ec..df8daad7 100644 --- a/src/resonantinduction/entangler/ItemCoordLink.java +++ b/src/resonantinduction/entangler/ItemCoordLink.java @@ -9,7 +9,7 @@ import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import resonantinduction.base.ItemBase; -import universalelectricity.core.vector.Vector3; +import universalelectricity.api.vector.Vector3; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; diff --git a/src/resonantinduction/entangler/ItemLinker.java b/src/resonantinduction/entangler/ItemLinker.java index 85541e62..f2ca487b 100644 --- a/src/resonantinduction/entangler/ItemLinker.java +++ b/src/resonantinduction/entangler/ItemLinker.java @@ -6,7 +6,7 @@ package resonantinduction.entangler; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; import net.minecraft.world.World; -import universalelectricity.core.vector.Vector3; +import universalelectricity.api.vector.Vector3; /** * @author Calclavia diff --git a/src/resonantinduction/entangler/ItemQuantumEntangler.java b/src/resonantinduction/entangler/ItemQuantumEntangler.java index 6099b135..c2d2e6f1 100644 --- a/src/resonantinduction/entangler/ItemQuantumEntangler.java +++ b/src/resonantinduction/entangler/ItemQuantumEntangler.java @@ -4,7 +4,7 @@ import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.item.ItemStack; import net.minecraft.world.World; -import universalelectricity.core.vector.Vector3; +import universalelectricity.api.vector.Vector3; /** * diff --git a/src/resonantinduction/furnace/TileEntityAdvancedFurnace.java b/src/resonantinduction/furnace/TileEntityAdvancedFurnace.java index 8589f067..3017d926 100644 --- a/src/resonantinduction/furnace/TileEntityAdvancedFurnace.java +++ b/src/resonantinduction/furnace/TileEntityAdvancedFurnace.java @@ -6,15 +6,15 @@ import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntityFurnace; import net.minecraftforge.common.ForgeDirection; import resonantinduction.ResonantInduction; -import universalelectricity.api.IEnergyInterface; -import universalelectricity.api.IVoltage; import universalelectricity.api.UniversalClass; +import universalelectricity.api.electricity.IVoltage; +import universalelectricity.api.energy.IEnergyInterface; +import universalelectricity.api.vector.Vector3; +import universalelectricity.api.vector.VectorHelper; import universalelectricity.core.block.IConductor; import universalelectricity.core.electricity.ElectricityHelper; import universalelectricity.core.electricity.ElectricityPack; -import universalelectricity.core.grid.IElectricityNetwork; -import universalelectricity.core.vector.Vector3; -import universalelectricity.core.vector.VectorHelper; +import universalelectricity.core.grid.IEnergyNetwork; /** * Meant to replace the furnace class. @@ -72,7 +72,7 @@ public class TileEntityAdvancedFurnace extends TileEntityFurnace implements IEne { if (this.furnaceBurnTime > 0) { - this.produceUE(direction); + this.energyBuffer += ResonantInduction.FURNACE_WATTAGE / 20; } hasRequest = true; @@ -139,41 +139,6 @@ public class TileEntityAdvancedFurnace extends TileEntityFurnace implements IEne } } - /** - * Produces UE power towards a specific direction. - * - * @param outputDirection - The output direction. - */ - public boolean produceUE(ForgeDirection outputDirection) - { - if (!this.worldObj.isRemote && outputDirection != null && outputDirection != ForgeDirection.UNKNOWN) - { - float provide = this.onReceiveEnergy(null, Integer.MAX_VALUE, false); - - if (provide > 0) - { - TileEntity outputTile = VectorHelper.getConnectorFromSide(this.worldObj, new Vector3(this), outputDirection); - IElectricityNetwork outputNetwork = ElectricityHelper.getNetworkFromTileEntity(outputTile, outputDirection); - - if (outputNetwork != null) - { - ElectricityPack powerRequest = outputNetwork.getRequest(this); - - if (powerRequest.getWatts() > 0) - { - ElectricityPack sendPack = ElectricityPack.getFromWatts(provide, this.getVoltage(null)); - float rejectedPower = outputNetwork.produce(sendPack, this); - this.onExtractEnergy(outputDirection.getOpposite(), (int) (sendPack.getWatts() - rejectedPower), true); - } - - return true; - } - } - } - - return false; - } - @Override public boolean canConnect(ForgeDirection direction) { diff --git a/src/resonantinduction/fx/FXElectricBolt.java b/src/resonantinduction/fx/FXElectricBolt.java index 3f75c24a..8953ba04 100644 --- a/src/resonantinduction/fx/FXElectricBolt.java +++ b/src/resonantinduction/fx/FXElectricBolt.java @@ -27,7 +27,7 @@ import net.minecraft.world.World; import org.lwjgl.opengl.GL11; import resonantinduction.ResonantInduction; -import universalelectricity.core.vector.Vector3; +import universalelectricity.api.vector.Vector3; import cpw.mods.fml.client.FMLClientHandler; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; diff --git a/src/resonantinduction/gui/GuiBattery.java b/src/resonantinduction/gui/GuiBattery.java index d64ceb9a..914245a5 100644 --- a/src/resonantinduction/gui/GuiBattery.java +++ b/src/resonantinduction/gui/GuiBattery.java @@ -10,8 +10,8 @@ import org.lwjgl.opengl.GL11; import resonantinduction.ResonantInduction; import resonantinduction.battery.ContainerBattery; import resonantinduction.battery.TileEntityBattery; -import universalelectricity.core.electricity.ElectricityDisplay; -import universalelectricity.core.electricity.ElectricityDisplay.ElectricUnit; +import universalelectricity.api.electricity.ElectricityDisplay; +import universalelectricity.api.electricity.ElectricityDisplay.ElectricUnit; public class GuiBattery extends GuiContainer { diff --git a/src/resonantinduction/multimeter/MultimeterEventHandler.java b/src/resonantinduction/multimeter/MultimeterEventHandler.java index 866c6d33..f8466ca1 100644 --- a/src/resonantinduction/multimeter/MultimeterEventHandler.java +++ b/src/resonantinduction/multimeter/MultimeterEventHandler.java @@ -4,8 +4,8 @@ import java.util.HashMap; import net.minecraft.world.World; import net.minecraftforge.event.ForgeSubscribe; -import universalelectricity.core.electricity.ElectricalEvent.ElectricityProductionEvent; -import universalelectricity.core.grid.IElectricityNetwork; +import universalelectricity.api.electricity.ElectricalEvent.EnergyUpdateEvent; +import universalelectricity.core.grid.IEnergyNetwork; /** * @author Calclavia @@ -13,12 +13,12 @@ import universalelectricity.core.grid.IElectricityNetwork; */ public class MultimeterEventHandler { - private static final HashMap networkEnergyCache = new HashMap(); + private static final HashMap networkEnergyCache = new HashMap(); private static long lastCheckTime = 0; - public static HashMap getCache(World worldObj) + public static HashMap getCache(World worldObj) { - HashMap returnCache = (HashMap) networkEnergyCache.clone(); + HashMap returnCache = (HashMap) networkEnergyCache.clone(); if (Math.abs(worldObj.getWorldTime() - lastCheckTime) >= 40) { @@ -30,13 +30,13 @@ public class MultimeterEventHandler } @ForgeSubscribe - public void event(ElectricityProductionEvent evt) + public void event(EnergyUpdateEvent evt) { - IElectricityNetwork network = evt.network; + IEnergyNetwork network = evt.network; - if (evt.electricityPack.getWatts() != 0) + if (network.getDistribution(null) != 0) { - networkEnergyCache.put(network, evt.electricityPack.getWatts()); + networkEnergyCache.put(network, network.getDistribution(null)); } } } diff --git a/src/resonantinduction/render/RenderBattery.java b/src/resonantinduction/render/RenderBattery.java index ab30855e..6c649f41 100644 --- a/src/resonantinduction/render/RenderBattery.java +++ b/src/resonantinduction/render/RenderBattery.java @@ -25,7 +25,7 @@ import org.lwjgl.opengl.GL11; import resonantinduction.ResonantInduction; import resonantinduction.battery.TileEntityBattery; import resonantinduction.model.ModelBattery; -import universalelectricity.core.vector.Vector3; +import universalelectricity.api.vector.Vector3; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; diff --git a/src/resonantinduction/render/RenderMultimeter.java b/src/resonantinduction/render/RenderMultimeter.java index 451ecfa2..b7421a4f 100644 --- a/src/resonantinduction/render/RenderMultimeter.java +++ b/src/resonantinduction/render/RenderMultimeter.java @@ -11,8 +11,8 @@ import org.lwjgl.opengl.GL11; import resonantinduction.ResonantInduction; import resonantinduction.model.ModelMultimeter; import resonantinduction.multimeter.TileEntityMultimeter; -import universalelectricity.core.electricity.ElectricityDisplay; -import universalelectricity.core.electricity.ElectricityDisplay.ElectricUnit; +import universalelectricity.api.electricity.ElectricityDisplay; +import universalelectricity.api.electricity.ElectricityDisplay.ElectricUnit; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; diff --git a/src/resonantinduction/render/RenderPartWire.java b/src/resonantinduction/render/RenderPartWire.java index 9c1de9c3..26629f0e 100644 --- a/src/resonantinduction/render/RenderPartWire.java +++ b/src/resonantinduction/render/RenderPartWire.java @@ -14,7 +14,7 @@ import org.lwjgl.opengl.GL11; import resonantinduction.ResonantInduction; import resonantinduction.wire.PartConductor; import resonantinduction.wire.PartWire; -import universalelectricity.core.vector.Vector3; +import universalelectricity.api.vector.Vector3; import codechicken.lib.colour.Colour; import codechicken.lib.colour.ColourRGBA; import codechicken.lib.lighting.LightModel; diff --git a/src/resonantinduction/render/RenderWire.java b/src/resonantinduction/render/RenderWire.java index 394f4e03..867eec7c 100644 --- a/src/resonantinduction/render/RenderWire.java +++ b/src/resonantinduction/render/RenderWire.java @@ -11,7 +11,7 @@ import resonantinduction.model.ModelInsulation; import resonantinduction.model.ModelWire; import resonantinduction.wire.EnumWireMaterial; import resonantinduction.wire.TileEntityWire; -import universalelectricity.core.vector.Vector3; +import universalelectricity.api.vector.Vector3; import cpw.mods.fml.client.FMLClientHandler; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; diff --git a/src/resonantinduction/tesla/BlockTesla.java b/src/resonantinduction/tesla/BlockTesla.java index 24be3fab..94a26422 100644 --- a/src/resonantinduction/tesla/BlockTesla.java +++ b/src/resonantinduction/tesla/BlockTesla.java @@ -13,7 +13,7 @@ import resonantinduction.ResonantInduction; import resonantinduction.base.BlockBase; import resonantinduction.entangler.ItemCoordLink; import resonantinduction.render.BlockRenderingHandler; -import universalelectricity.core.vector.Vector3; +import universalelectricity.api.vector.Vector3; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; diff --git a/src/resonantinduction/tesla/TileEntityTesla.java b/src/resonantinduction/tesla/TileEntityTesla.java index 8b14346f..469540a9 100644 --- a/src/resonantinduction/tesla/TileEntityTesla.java +++ b/src/resonantinduction/tesla/TileEntityTesla.java @@ -23,9 +23,9 @@ import net.minecraft.world.World; import net.minecraftforge.common.ForgeDirection; import resonantinduction.ResonantInduction; import resonantinduction.api.ITesla; +import universalelectricity.api.vector.Vector3; import universalelectricity.compatibility.TileEntityUniversalElectrical; import universalelectricity.core.electricity.ElectricityPack; -import universalelectricity.core.vector.Vector3; import calclavia.lib.network.IPacketReceiver; import calclavia.lib.network.IPacketSender; diff --git a/src/resonantinduction/wire/EnumWireMaterial.java b/src/resonantinduction/wire/EnumWireMaterial.java index 345d1e7f..cb00ec91 100644 --- a/src/resonantinduction/wire/EnumWireMaterial.java +++ b/src/resonantinduction/wire/EnumWireMaterial.java @@ -4,7 +4,7 @@ import net.minecraft.block.Block; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraftforge.oredict.OreDictionary; -import universalelectricity.core.vector.Vector3; +import universalelectricity.api.vector.Vector3; /** * An enumerator for different wire materials. The metadata of the wire determines the type of the diff --git a/src/resonantinduction/wire/ItemBlockWire.java b/src/resonantinduction/wire/ItemBlockWire.java index 9f9d32e6..0dc50ae0 100644 --- a/src/resonantinduction/wire/ItemBlockWire.java +++ b/src/resonantinduction/wire/ItemBlockWire.java @@ -7,8 +7,8 @@ import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemBlock; import net.minecraft.item.ItemStack; import net.minecraft.util.Icon; -import universalelectricity.core.electricity.ElectricityDisplay; -import universalelectricity.core.electricity.ElectricityDisplay.ElectricUnit; +import universalelectricity.api.electricity.ElectricityDisplay; +import universalelectricity.api.electricity.ElectricityDisplay.ElectricUnit; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; diff --git a/src/resonantinduction/wire/ItemPartWire.java b/src/resonantinduction/wire/ItemPartWire.java index b2e43a0a..0075c512 100644 --- a/src/resonantinduction/wire/ItemPartWire.java +++ b/src/resonantinduction/wire/ItemPartWire.java @@ -12,8 +12,8 @@ import net.minecraftforge.common.Configuration; import resonantinduction.ResonantInduction; import resonantinduction.TabRI; import resonantinduction.render.RenderPartWire; -import universalelectricity.core.electricity.ElectricityDisplay; -import universalelectricity.core.electricity.ElectricityDisplay.ElectricUnit; +import universalelectricity.api.electricity.ElectricityDisplay; +import universalelectricity.api.electricity.ElectricityDisplay.ElectricUnit; import codechicken.lib.vec.BlockCoord; import codechicken.lib.vec.Vector3; import codechicken.multipart.JItemMultiPart; diff --git a/src/resonantinduction/wire/PartConductor.java b/src/resonantinduction/wire/PartConductor.java index 6885f519..b62f0940 100644 --- a/src/resonantinduction/wire/PartConductor.java +++ b/src/resonantinduction/wire/PartConductor.java @@ -2,23 +2,83 @@ package resonantinduction.wire; import net.minecraft.tileentity.TileEntity; import net.minecraftforge.common.ForgeDirection; -import universalelectricity.core.block.IConductor; -import universalelectricity.core.block.IConnector; -import universalelectricity.core.block.INetworkProvider; -import universalelectricity.core.electricity.NetworkLoader; -import universalelectricity.core.grid.IElectricityNetwork; -import universalelectricity.core.vector.Vector3; -import universalelectricity.core.vector.VectorHelper; +import universalelectricity.api.IConnector; +import universalelectricity.api.INetworkProvider; +import universalelectricity.api.energy.IConductor; +import universalelectricity.api.energy.IEnergyInterface; +import universalelectricity.api.vector.Vector3; +import universalelectricity.api.vector.VectorHelper; +import universalelectricity.core.grid.EnergyNetworkLoader; +import universalelectricity.core.grid.IEnergyNetwork; import codechicken.multipart.TileMultipart; public abstract class PartConductor extends PartAdvanced implements IConductor { - private IElectricityNetwork network; + private IEnergyNetwork network; + private int buffer = 0; public TileEntity[] adjacentConnections = null; public byte currentWireConnections = 0x00; public byte currentAcceptorConnections = 0x00; + @Override + public int onReceiveEnergy(ForgeDirection from, int receive, boolean doReceive) + { + int energyReceived = Math.min(this.getEnergyCapacitance() - this.buffer, receive); + + if (doReceive) + { + this.buffer += energyReceived; + } + + return energyReceived; + } + + @Override + public int onExtractEnergy(ForgeDirection from, int request, boolean doExtract) + { + int energyExtracted = Math.min(this.buffer, request); + + if (doExtract) + { + this.buffer -= energyExtracted; + } + + return energyExtracted; + } + + @Override + public void distribute() + { + Object[] receivers = this.getAdjacentConnections(); + int energyUsed = 0; + + for (int i = 0; i < receivers.length; i++) + { + ForgeDirection direction = ForgeDirection.getOrientation(i); + Object receiver = receivers[i]; + + if (receiver instanceof IEnergyInterface && !(receiver instanceof IConductor)) + { + energyUsed += ((IEnergyInterface) receiver).onReceiveEnergy(direction.getOpposite(), this.getNetwork().getDistribution(this), true); + } + } + + this.onExtractEnergy(null, energyUsed, true); + } + + @Override + public int getEnergyLoss() + { + return 0; + } + + @Override + public int getEnergyCapacitance() + { + return 0; + } + public byte getAllCurrentConnections() { return (byte) (currentWireConnections | currentAcceptorConnections); @@ -30,16 +90,23 @@ public abstract class PartConductor extends PartAdvanced implements IConductor return ((connections & tester) > 0); } + @Override + public void onMoved() + { + this.refresh(); + } + @Override public void bind(TileMultipart t) { - if(tile() != null && network != null) + if (tile() != null && network != null) { - getNetwork().getConductors().remove(tile()); + getNetwork().getConnectors().remove(tile()); super.bind(t); - getNetwork().getConductors().add((IConductor) tile()); + getNetwork().getConnectors().add((IConductor) tile()); } - else { + else + { super.bind(t); } } @@ -47,7 +114,7 @@ public abstract class PartConductor extends PartAdvanced implements IConductor @Override public void preRemove() { - if(!world().isRemote && tile() instanceof IConductor) + if (!world().isRemote && tile() instanceof IConductor) { getNetwork().split((IConductor) tile()); } @@ -62,11 +129,11 @@ public abstract class PartConductor extends PartAdvanced implements IConductor } @Override - public IElectricityNetwork getNetwork() + public IEnergyNetwork getNetwork() { - if(network == null && tile() instanceof IConductor) + if (network == null && tile() instanceof IConductor) { - setNetwork(NetworkLoader.getNewNetwork((IConductor)tile())); + setNetwork(EnergyNetworkLoader.getNewNetwork((IConductor) tile())); } return network; @@ -76,16 +143,16 @@ public abstract class PartConductor extends PartAdvanced implements IConductor { boolean notPrevented = !isConnectionPrevented(tile, side); - if(tile instanceof IConnector) + if (tile instanceof IConnector) { - notPrevented &= ((IConnector)tile).canConnect(side.getOpposite()); + notPrevented &= ((IConnector) tile).canConnect(side.getOpposite()); } - + return notPrevented; } @Override - public void setNetwork(IElectricityNetwork net) + public void setNetwork(IEnergyNetwork net) { network = net; } @@ -106,16 +173,16 @@ public abstract class PartConductor extends PartAdvanced implements IConductor { byte connections = 0x00; - for(ForgeDirection side : ForgeDirection.VALID_DIRECTIONS) + for (ForgeDirection side : ForgeDirection.VALID_DIRECTIONS) { TileEntity tileEntity = VectorHelper.getTileEntityFromSide(world(), new Vector3(tile()), side); - - if(tileEntity instanceof INetworkProvider && canConnectBothSides(tileEntity, side)) + + if (tileEntity instanceof INetworkProvider && canConnectBothSides(tileEntity, side)) { connections |= 1 << side.ordinal(); } } - + return connections; } @@ -123,16 +190,16 @@ public abstract class PartConductor extends PartAdvanced implements IConductor { byte connections = 0x00; - for(ForgeDirection side : ForgeDirection.VALID_DIRECTIONS) + for (ForgeDirection side : ForgeDirection.VALID_DIRECTIONS) { TileEntity tileEntity = VectorHelper.getTileEntityFromSide(world(), new Vector3(tile()), side); - - if(isValidAcceptor(tileEntity) && canConnectBothSides(tileEntity, side)) + + if (isValidAcceptor(tileEntity) && canConnectBothSides(tileEntity, side)) { connections |= 1 << side.ordinal(); } } - + return connections; } @@ -144,48 +211,46 @@ public abstract class PartConductor extends PartAdvanced implements IConductor return tile instanceof IConnector; } - @Override public void refresh() { - if(!world().isRemote) + if (!world().isRemote) { adjacentConnections = null; - + byte possibleWireConnections = getPossibleWireConnections(); byte possibleAcceptorConnections = getPossibleAcceptorConnections(); - if(possibleWireConnections != currentWireConnections) + if (possibleWireConnections != currentWireConnections) { byte or = (byte) (possibleWireConnections | currentWireConnections); - - if(or != possibleWireConnections) // Connections have been removed + + if (or != possibleWireConnections) // Connections have been removed { getNetwork().split((IConductor) tile()); setNetwork(null); } - for(ForgeDirection side : ForgeDirection.VALID_DIRECTIONS) + for (ForgeDirection side : ForgeDirection.VALID_DIRECTIONS) { - if(connectionMapContainsSide(possibleWireConnections, side)) + if (connectionMapContainsSide(possibleWireConnections, side)) { TileEntity tileEntity = VectorHelper.getConnectorFromSide(world(), new Vector3(tile()), side); - if(tileEntity instanceof INetworkProvider) + if (tileEntity instanceof IConductor) { - getNetwork().merge(((INetworkProvider) tileEntity).getNetwork()); + getNetwork().merge(((IConductor) tileEntity).getNetwork()); } } } - currentWireConnections = possibleWireConnections; + this.currentWireConnections = possibleWireConnections; } - currentAcceptorConnections = possibleAcceptorConnections; - - getNetwork().refresh(); - sendDescUpdate(); + this.currentAcceptorConnections = possibleAcceptorConnections; + + this.sendDescUpdate(); } - + tile().markRender(); } @@ -196,22 +261,22 @@ public abstract class PartConductor extends PartAdvanced implements IConductor @Override public TileEntity[] getAdjacentConnections() { - if(adjacentConnections == null) + if (this.adjacentConnections == null) { - adjacentConnections = new TileEntity[6]; + this.adjacentConnections = new TileEntity[6]; - for(byte i = 0; i < 6; i++) + for (byte i = 0; i < 6; i++) { ForgeDirection side = ForgeDirection.getOrientation(i); TileEntity tileEntity = VectorHelper.getTileEntityFromSide(world(), new Vector3(tile()), side); - if(isCurrentlyConnected(side)) + if (isCurrentlyConnected(side)) { - adjacentConnections[i] = tileEntity; + this.adjacentConnections[i] = tileEntity; } } } - return adjacentConnections; + return this.adjacentConnections; } public boolean isCurrentlyConnected(ForgeDirection side) @@ -250,4 +315,5 @@ public abstract class PartConductor extends PartAdvanced implements IConductor super.onNeighborChanged(); refresh(); } + } diff --git a/src/resonantinduction/wire/PartUniversalConductor.java b/src/resonantinduction/wire/PartUniversalConductor.java index 3794b515..1bf6295d 100644 --- a/src/resonantinduction/wire/PartUniversalConductor.java +++ b/src/resonantinduction/wire/PartUniversalConductor.java @@ -12,10 +12,10 @@ import net.minecraft.tileentity.TileEntity; import net.minecraft.world.World; import net.minecraftforge.common.ForgeDirection; import net.minecraftforge.common.MinecraftForge; -import universalelectricity.compatibility.Compatibility; +import universalelectricity.api.Compatibility; +import universalelectricity.api.vector.Vector3; +import universalelectricity.api.vector.VectorHelper; import universalelectricity.core.electricity.ElectricityPack; -import universalelectricity.core.vector.Vector3; -import universalelectricity.core.vector.VectorHelper; import buildcraft.api.power.IPowerReceptor; import buildcraft.api.power.PowerHandler; import buildcraft.api.power.PowerHandler.PowerReceiver; diff --git a/src/resonantinduction/wire/PartWire.java b/src/resonantinduction/wire/PartWire.java index d54da40a..825965dc 100644 --- a/src/resonantinduction/wire/PartWire.java +++ b/src/resonantinduction/wire/PartWire.java @@ -21,7 +21,7 @@ import net.minecraft.util.Icon; import net.minecraft.util.MovingObjectPosition; import net.minecraftforge.common.ForgeDirection; import resonantinduction.render.RenderPartWire; -import universalelectricity.compatibility.Compatibility; +import universalelectricity.api.Compatibility; import buildcraft.api.power.PowerHandler; import codechicken.lib.data.MCDataInput; import codechicken.lib.data.MCDataOutput; diff --git a/src/resonantinduction/wire/TileEntityWire.java b/src/resonantinduction/wire/TileEntityWire.java index 91822d11..b9243f2b 100644 --- a/src/resonantinduction/wire/TileEntityWire.java +++ b/src/resonantinduction/wire/TileEntityWire.java @@ -8,11 +8,11 @@ import net.minecraft.nbt.NBTTagCompound; import net.minecraft.network.packet.Packet; import net.minecraft.tileentity.TileEntity; import net.minecraftforge.common.ForgeDirection; -import universalelectricity.compatibility.Compatibility; +import universalelectricity.api.Compatibility; +import universalelectricity.api.vector.Vector3; +import universalelectricity.api.vector.VectorHelper; import universalelectricity.compatibility.TileEntityUniversalConductor; import universalelectricity.core.block.INetworkProvider; -import universalelectricity.core.vector.Vector3; -import universalelectricity.core.vector.VectorHelper; import buildcraft.api.power.PowerHandler; import calclavia.lib.network.IPacketReceiver; import calclavia.lib.network.IPacketSender;