From bbe89086a1d00db27f057df4c20f207e609a23de Mon Sep 17 00:00:00 2001 From: Calclavia Date: Sun, 22 Dec 2013 22:33:50 +0800 Subject: [PATCH] Reworked vanilla electric furnace --- src/resonantinduction/MultipartRI.java | 5 +- src/resonantinduction/ResonantInduction.java | 2 +- .../furnace/TileEntityAdvancedFurnace.java | 108 +++++++++--------- .../multimeter/MultimeterEventHandler.java | 2 +- .../tesla/TileEntityTesla.java | 1 - .../wire/part/PartConductor.java | 2 +- .../wire/part/TraitConductor.java | 18 ++- 7 files changed, 70 insertions(+), 68 deletions(-) diff --git a/src/resonantinduction/MultipartRI.java b/src/resonantinduction/MultipartRI.java index 65007421f..90d9010db 100644 --- a/src/resonantinduction/MultipartRI.java +++ b/src/resonantinduction/MultipartRI.java @@ -13,9 +13,10 @@ public class MultipartRI implements IPartFactory public MultipartRI() { MultiPartRegistry.registerParts(this, new String[] { "resonant_induction_flat_wire" }); - MultipartGenerator.registerTrait("ic2.api.energy.tile.IEnergySink", "resonantinduction.wire.part.TraitEnergySink"); MultipartGenerator.registerTrait("universalelectricity.api.energy.IConductor", "resonantinduction.wire.part.TraitConductor"); - + // MultipartGenerator.registerTrait("resonantinduction.wire.part.ITest", + // "resonantinduction.wire.part.TraitTest"); + MultipartGenerator.registerTrait("ic2.api.energy.tile.IEnergySink", "resonantinduction.wire.part.TraitEnergySink"); } @Override diff --git a/src/resonantinduction/ResonantInduction.java b/src/resonantinduction/ResonantInduction.java index 5206684d2..b2c7b99d7 100644 --- a/src/resonantinduction/ResonantInduction.java +++ b/src/resonantinduction/ResonantInduction.java @@ -110,7 +110,7 @@ public class ResonantInduction * Settings */ public static final Configuration CONFIGURATION = new Configuration(new File(Loader.instance().getConfigDir(), NAME + ".cfg")); - public static int FURNACE_WATTAGE = 50000; + public static int FURNACE_WATTAGE = 25000; public static boolean SOUND_FXS = true; public static boolean LO_FI_INSULATION = false; public static boolean SHINY_SILVER = true; diff --git a/src/resonantinduction/furnace/TileEntityAdvancedFurnace.java b/src/resonantinduction/furnace/TileEntityAdvancedFurnace.java index 5b5c1bcb7..7cd124c08 100644 --- a/src/resonantinduction/furnace/TileEntityAdvancedFurnace.java +++ b/src/resonantinduction/furnace/TileEntityAdvancedFurnace.java @@ -7,9 +7,6 @@ import net.minecraft.tileentity.TileEntityFurnace; import net.minecraftforge.common.ForgeDirection; import resonantinduction.ResonantInduction; import universalelectricity.api.CompatibilityModule; -import universalelectricity.api.UniversalClass; -import universalelectricity.api.electricity.IVoltage; -import universalelectricity.api.energy.IConductor; import universalelectricity.api.energy.IEnergyInterface; import universalelectricity.api.vector.Vector3; import calclavia.lib.tile.EnergyStorage; @@ -20,7 +17,7 @@ import calclavia.lib.tile.EnergyStorage; * @author Calclavia * */ -public class TileEntityAdvancedFurnace extends TileEntityFurnace implements IEnergyInterface, IVoltage +public class TileEntityAdvancedFurnace extends TileEntityFurnace implements IEnergyInterface { private static final float WATTAGE = 5; @@ -29,50 +26,10 @@ public class TileEntityAdvancedFurnace extends TileEntityFurnace implements IEne @Override public void updateEntity() { - boolean canSmelt = canSmelt() && this.getStackInSlot(1) == null && this.furnaceBurnTime == 0; - boolean canBurn = this.getStackInSlot(0) == null && TileEntityFurnace.getItemBurnTime(this.getStackInSlot(1)) > 0; - - if (canSmelt) - { - if (this.energy.checkExtract(ResonantInduction.FURNACE_WATTAGE / 20)) - { - this.furnaceCookTime++; - - if (this.furnaceCookTime == 200) - { - this.furnaceCookTime = 0; - this.smeltItem(); - this.onInventoryChanged(); - } - - this.energy.extractEnergy(ResonantInduction.FURNACE_WATTAGE / 20, true); - } - } - else if (!this.energy.isFull()) - { - boolean doBlockStateUpdate = this.furnaceBurnTime > 0; - - if (this.furnaceBurnTime == 0) - { - int burnTime = TileEntityFurnace.getItemBurnTime(this.getStackInSlot(1)); - this.decrStackSize(1, 1); - this.furnaceBurnTime = burnTime; - } - - if (this.furnaceBurnTime > 0) - { - this.energy.receiveEnergy(ResonantInduction.FURNACE_WATTAGE / 20, true); - - this.produce(); - } - - if (doBlockStateUpdate != this.furnaceBurnTime > 0) - { - // TODO: Send descript packet. - this.worldObj.markBlockForUpdate(this.xCoord, this.yCoord, this.zCoord); - } - } - else + /** + * If we have fuel and can smelt properly, do the vanilla process. + */ + if (this.canSmelt() && TileEntityFurnace.getItemBurnTime(this.getStackInSlot(1)) > 0) { boolean flag = this.furnaceBurnTime > 0; boolean flag1 = false; @@ -132,6 +89,47 @@ public class TileEntityAdvancedFurnace extends TileEntityFurnace implements IEne this.onInventoryChanged(); } } + else if (this.getStackInSlot(1) == null && canSmelt() && this.furnaceBurnTime == 0) + { + if (this.energy.checkExtract(ResonantInduction.FURNACE_WATTAGE / 20)) + { + this.furnaceCookTime++; + + if (this.furnaceCookTime == 200) + { + this.furnaceCookTime = 0; + this.smeltItem(); + this.onInventoryChanged(); + } + + this.energy.extractEnergy(ResonantInduction.FURNACE_WATTAGE / 20, true); + } + } + else if (this.getStackInSlot(0) == null) + { + boolean doBlockStateUpdate = this.furnaceBurnTime > 0; + + if (!this.energy.isFull() && this.furnaceBurnTime == 0) + { + int burnTime = TileEntityFurnace.getItemBurnTime(this.getStackInSlot(1)); + this.decrStackSize(1, 1); + this.furnaceBurnTime = burnTime; + } + + if (this.furnaceBurnTime > 0) + { + this.energy.receiveEnergy(ResonantInduction.FURNACE_WATTAGE / 20, true); + this.furnaceBurnTime--; + } + + if (doBlockStateUpdate != this.furnaceBurnTime > 0) + { + // TODO: Send descript packet. + this.worldObj.markBlockForUpdate(this.xCoord, this.yCoord, this.zCoord); + } + + this.produce(); + } } private void produce() @@ -141,7 +139,12 @@ public class TileEntityAdvancedFurnace extends TileEntityFurnace implements IEne if (this.energy.getEnergy() > 0) { TileEntity tileEntity = new Vector3(this).modifyPositionFromSide(direction).getTileEntity(this.worldObj); - this.energy.extractEnergy(CompatibilityModule.receiveEnergy(tileEntity, direction.getOpposite(), this.energy.extractEnergy(this.energy.getEnergy(), false), true), true); + + if (tileEntity != null) + { + long used = CompatibilityModule.receiveEnergy(tileEntity, direction.getOpposite(), this.energy.extractEnergy(this.energy.getEnergy(), false), true); + this.energy.extractEnergy(used, true); + } } } } @@ -188,11 +191,4 @@ public class TileEntityAdvancedFurnace extends TileEntityFurnace implements IEne { return this.energy.extractEnergy(request, doProvide); } - - @Override - public long getVoltage(ForgeDirection direction) - { - return 100; - } - } diff --git a/src/resonantinduction/multimeter/MultimeterEventHandler.java b/src/resonantinduction/multimeter/MultimeterEventHandler.java index 835c6b052..ff577e89b 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.api.electricity.ElectricalEvent.EnergyUpdateEvent; import universalelectricity.api.energy.IEnergyNetwork; +import universalelectricity.api.net.NetworkEvent.EnergyUpdateEvent; /** * @author Calclavia diff --git a/src/resonantinduction/tesla/TileEntityTesla.java b/src/resonantinduction/tesla/TileEntityTesla.java index 316d30c23..75a0e826d 100644 --- a/src/resonantinduction/tesla/TileEntityTesla.java +++ b/src/resonantinduction/tesla/TileEntityTesla.java @@ -23,7 +23,6 @@ import net.minecraft.world.World; import net.minecraftforge.common.ForgeDirection; import resonantinduction.ResonantInduction; import resonantinduction.api.ITesla; -import universalelectricity.api.electricity.ElectricityPack; import universalelectricity.api.vector.Vector3; import calclavia.lib.network.IPacketReceiver; import calclavia.lib.network.IPacketSender; diff --git a/src/resonantinduction/wire/part/PartConductor.java b/src/resonantinduction/wire/part/PartConductor.java index 8669a4f98..897068fbc 100644 --- a/src/resonantinduction/wire/part/PartConductor.java +++ b/src/resonantinduction/wire/part/PartConductor.java @@ -24,7 +24,7 @@ public abstract class PartConductor extends PartAdvanced implements IAdvancedCon @Override public long onReceiveEnergy(ForgeDirection from, long receive, boolean doReceive) { - return this.getNetwork().produce(receive); + return this.getNetwork().produce(this, receive, doReceive); } @Override diff --git a/src/resonantinduction/wire/part/TraitConductor.java b/src/resonantinduction/wire/part/TraitConductor.java index 4276cda6b..8e3f0c94b 100644 --- a/src/resonantinduction/wire/part/TraitConductor.java +++ b/src/resonantinduction/wire/part/TraitConductor.java @@ -88,15 +88,21 @@ public class TraitConductor extends TileMultipart implements IConductor @Override public long onReceiveEnergy(ForgeDirection from, long receive, boolean doReceive) { - TMultiPart part = this.partMap(from.ordinal()); + System.out.println("RECEIVING"+receive); - if (this.interfaces.contains(part) && part instanceof IConductor) + /*TMultiPart part = partMap(from.ordinal()); + + if (part != null) { - //((IConductor) part).onReceiveEnergy(from, receive, doReceive); - - System.out.println("RECEIVING"); + for (IConductor conductor : this.interfaces) + { + if (conductor == part) + { + conductor.onReceiveEnergy(from, receive, doReceive); + } + } } - +*/ return 0; }