From 9feaae03bbcbb6c1119148d7f85af89b645d1ddd Mon Sep 17 00:00:00 2001 From: Aidan Brady Date: Thu, 26 Dec 2013 19:44:11 -0500 Subject: [PATCH] Multipart BC support, fixed recipe --- common/mekanism/common/Mekanism.java | 2 +- .../common/multipart/MultipartMekanism.java | 2 +- .../common/multipart/PartUniversalCable.java | 66 ++++++++++++++++++- 3 files changed, 67 insertions(+), 3 deletions(-) diff --git a/common/mekanism/common/Mekanism.java b/common/mekanism/common/Mekanism.java index ed40200f1..2d87cb97d 100644 --- a/common/mekanism/common/Mekanism.java +++ b/common/mekanism/common/Mekanism.java @@ -603,7 +603,7 @@ public class Mekanism RecipeHandler.addPurificationChamberRecipe(new ItemStack(Block.cobblestone), new ItemStack(Block.gravel)); //Chemical Injection Chamber Recipes - RecipeHandler.addPurificationChamberRecipe(new ItemStack(Block.obsidian), new ItemStack(Shard, 3, 6)); + RecipeHandler.addChemicalInjectionChamberRecipe(new ItemStack(Block.obsidian), new ItemStack(Shard, 3, 6)); //Metallurgic Infuser Recipes RecipeHandler.addMetallurgicInfuserRecipe(InfusionInput.getInfusion(InfuseRegistry.get("CARBON"), 10, new ItemStack(Item.ingotIron)), new ItemStack(EnrichedIron)); diff --git a/common/mekanism/common/multipart/MultipartMekanism.java b/common/mekanism/common/multipart/MultipartMekanism.java index 946735c70..120549f27 100644 --- a/common/mekanism/common/multipart/MultipartMekanism.java +++ b/common/mekanism/common/multipart/MultipartMekanism.java @@ -1,6 +1,5 @@ package mekanism.common.multipart; -import mekanism.api.transmitters.TransmissionType; import mekanism.common.Mekanism; import net.minecraft.world.World; import codechicken.lib.vec.BlockCoord; @@ -28,6 +27,7 @@ public class MultipartMekanism implements IPartFactory, IPartConverter MultipartGenerator.registerPassThroughInterface("mekanism.api.transmitters.IGridTransmitter"); MultipartGenerator.registerPassThroughInterface("mekanism.common.ILogisticalTransporter"); MultipartGenerator.registerPassThroughInterface("ic2.api.energy.tile.IEnergySink"); + MultipartGenerator.registerPassThroughInterface("buildcraft.api.power.IPowerReceptor"); MultipartGenerator.registerPassThroughInterface("cofh.api.energy.IEnergyHandler"); MultipartGenerator.registerPassThroughInterface("mekanism.common.IConfigurable"); MultipartGenerator.registerPassThroughInterface("mekanism.common.ITileNetwork"); diff --git a/common/mekanism/common/multipart/PartUniversalCable.java b/common/mekanism/common/multipart/PartUniversalCable.java index bda62eaaa..302841320 100644 --- a/common/mekanism/common/multipart/PartUniversalCable.java +++ b/common/mekanism/common/multipart/PartUniversalCable.java @@ -15,25 +15,40 @@ import mekanism.client.render.RenderPartTransmitter; import mekanism.common.EnergyNetwork; import mekanism.common.Mekanism; import mekanism.common.util.CableUtils; +import mekanism.common.util.MekanismUtils; import net.minecraft.client.renderer.texture.IconRegister; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.Icon; +import net.minecraft.world.World; import net.minecraftforge.common.ForgeDirection; import net.minecraftforge.common.MinecraftForge; +import buildcraft.api.power.IPowerReceptor; +import buildcraft.api.power.PowerHandler; +import buildcraft.api.power.PowerHandler.PowerReceiver; import codechicken.lib.vec.Vector3; import cofh.api.energy.IEnergyHandler; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; -public class PartUniversalCable extends PartTransmitter implements IStrictEnergyAcceptor, IEnergySink, IEnergyHandler +public class PartUniversalCable extends PartTransmitter implements IStrictEnergyAcceptor, IEnergySink, IEnergyHandler, IPowerReceptor { + /** A fake power handler used to initiate energy transfer calculations. */ + public PowerHandler powerHandler; + public static TransmitterIcons cableIcons; public double currentPower = 0; public double cacheEnergy = 0; public double lastWrite = 0; + + public PartUniversalCable() + { + powerHandler = new PowerHandler(this, PowerHandler.Type.STORAGE); + powerHandler.configurePowerPerdition(0, 0); + powerHandler.configure(0, 0, 0, 0); + } @Override public void update() @@ -58,6 +73,14 @@ public class PartUniversalCable extends PartTransmitter implement super.update(); } + @Override + public void refreshTransmitterNetwork() + { + super.refreshTransmitterNetwork(); + + reconfigure(); + } + @Override public TransmitterType getTransmitter() { @@ -327,4 +350,45 @@ public class PartUniversalCable extends PartTransmitter implement { getTransmitterNetwork().electricityStored = energy; } + + @Override + public PowerReceiver getPowerReceiver(ForgeDirection side) + { + if(getTransmitterNetwork().getEnergyNeeded() == 0) + { + return null; + } + + return powerHandler.getPowerReceiver(); + } + + @Override + public World getWorld() + { + return world(); + } + + private void reconfigure() + { + if(MekanismUtils.useBuildCraft()) + { + float needed = (float)(getTransmitterNetwork().getEnergyNeeded()*Mekanism.TO_BC); + powerHandler.configure(1, needed, 0, needed); + } + } + + @Override + public void doWork(PowerHandler workProvider) + { + if(MekanismUtils.useBuildCraft()) + { + if(powerHandler.getEnergyStored() > 0) + { + getTransmitterNetwork().emit(powerHandler.getEnergyStored()*Mekanism.FROM_BC); + } + + powerHandler.setEnergy(0); + reconfigure(); + } + } }