diff --git a/build.gradle b/build.gradle index 8b1661c5a..b10543750 100644 --- a/build.gradle +++ b/build.gradle @@ -1,5 +1,6 @@ buildscript { repositories { + mavenCentral() maven { name = "central" url = "https://maven.thorfusion.com/artifactory/central/" @@ -31,7 +32,9 @@ repositories { name 'central' url 'https://maven.thorfusion.com/artifactory/central/' } - + maven { + url 'https://maven.tilera.xyz' + } } idea { @@ -59,6 +62,7 @@ dependencies { compile "inventorytweaks:inventory-tweaks:1.7.10-1.60.0:api" compile "net.industrial-craft:industrialcraft-2:2.2.828-experimental:api" compile "mcp.mobius.waila:Waila:1.5.10_1.7.10:dev" + compile "universalelectricity:basiccomponents:1.1.0:deobf" } version = "${config.minecraft_version}-${config.mod_version}" diff --git a/src/main/java/mekanism/common/Mekanism.java b/src/main/java/mekanism/common/Mekanism.java index ac6ea86f3..2e5626ec8 100644 --- a/src/main/java/mekanism/common/Mekanism.java +++ b/src/main/java/mekanism/common/Mekanism.java @@ -135,7 +135,7 @@ import cpw.mods.fml.common.registry.GameRegistry; * */ @Mod(modid = "Mekanism", name = "Mekanism", version = "GRADLE_MODVERSION", guiFactory = "mekanism.client.gui.ConfigGuiFactory", - dependencies = "after:ForgeMultipart;after:BuildCraft;after:BuildCraftAPI;after:IC2;after:CoFHCore;" + + dependencies = "after:basiccomponents;after:ForgeMultipart;after:BuildCraft;after:BuildCraftAPI;after:IC2;after:CoFHCore;" + "after:ComputerCraft;after:Galacticraft;after:MineTweaker3") public class Mekanism { diff --git a/src/main/java/mekanism/common/base/IEnergyWrapper.java b/src/main/java/mekanism/common/base/IEnergyWrapper.java index e1df80f7e..d5a839b4a 100644 --- a/src/main/java/mekanism/common/base/IEnergyWrapper.java +++ b/src/main/java/mekanism/common/base/IEnergyWrapper.java @@ -11,6 +11,9 @@ import mekanism.api.energy.IStrictEnergyAcceptor; import mekanism.api.energy.IStrictEnergyStorage; import net.minecraft.inventory.IInventory; import net.minecraftforge.common.util.ForgeDirection; +import universalelectricity.compat.IElectricityTileHandler; +import universalelectricity.core.block.IConnector; +import universalelectricity.core.block.IVoltage; import cofh.api.energy.IEnergyHandler; import cpw.mods.fml.common.Optional.Interface; import cpw.mods.fml.common.Optional.InterfaceList; @@ -18,9 +21,12 @@ import cpw.mods.fml.common.Optional.InterfaceList; @InterfaceList({ @Interface(iface = "ic2.api.energy.tile.IEnergySink", modid = "IC2"), @Interface(iface = "ic2.api.energy.tile.IEnergySource", modid = "IC2"), - @Interface(iface = "ic2.api.tile.IEnergyStorage", modid = "IC2") + @Interface(iface = "ic2.api.tile.IEnergyStorage", modid = "IC2"), + @Interface(iface = "universalelectricity.compat.IElectricityTileHandler", modid = "basiccomponents"), + @Interface(iface = "universalelectricity.core.block.IConnector", modid = "basiccomponents"), + @Interface(iface = "universalelectricity.core.block.IVoltage", modid = "basiccomponents") }) -public interface IEnergyWrapper extends IStrictEnergyStorage, IEnergyHandler, IEnergySink, IEnergySource, IEnergyStorage, IStrictEnergyAcceptor, ICableOutputter, IInventory +public interface IEnergyWrapper extends IStrictEnergyStorage, IEnergyHandler, IEnergySink, IEnergySource, IEnergyStorage, IStrictEnergyAcceptor, ICableOutputter, IInventory, IConnector, IVoltage, IElectricityTileHandler { public EnumSet getOutputtingSides(); diff --git a/src/main/java/mekanism/common/integration/ue/UEDriverProxy.java b/src/main/java/mekanism/common/integration/ue/UEDriverProxy.java new file mode 100644 index 000000000..9e79a3e75 --- /dev/null +++ b/src/main/java/mekanism/common/integration/ue/UEDriverProxy.java @@ -0,0 +1,20 @@ +package mekanism.common.integration.ue; + +import cpw.mods.fml.common.Loader; +import mekanism.common.base.IEnergyWrapper; + +public abstract class UEDriverProxy { + + public abstract void tick(); + + public abstract void invalidate(); + + public static UEDriverProxy createProxy(IEnergyWrapper wrapper) { + if (Loader.isModLoaded("basiccomponents")) { + return new UELoaded(wrapper); + } else { + return new UEUnloaded(); + } + } + +} diff --git a/src/main/java/mekanism/common/integration/ue/UELoaded.java b/src/main/java/mekanism/common/integration/ue/UELoaded.java new file mode 100644 index 000000000..02cc19e5f --- /dev/null +++ b/src/main/java/mekanism/common/integration/ue/UELoaded.java @@ -0,0 +1,24 @@ +package mekanism.common.integration.ue; + +import mekanism.common.base.IEnergyWrapper; +import universalelectricity.prefab.tile.ElectricTileDriver; + +public class UELoaded extends UEDriverProxy { + + private ElectricTileDriver driver; + + public UELoaded(IEnergyWrapper wrapper) { + driver = new ElectricTileDriver(wrapper); + } + + @Override + public void tick() { + driver.tick(); + } + + @Override + public void invalidate() { + driver.invalidate(); + } + +} diff --git a/src/main/java/mekanism/common/integration/ue/UEUnloaded.java b/src/main/java/mekanism/common/integration/ue/UEUnloaded.java new file mode 100644 index 000000000..698bc4349 --- /dev/null +++ b/src/main/java/mekanism/common/integration/ue/UEUnloaded.java @@ -0,0 +1,15 @@ +package mekanism.common.integration.ue; + +public class UEUnloaded extends UEDriverProxy { + + @Override + public void tick() { + + } + + @Override + public void invalidate() { + + } + +} diff --git a/src/main/java/mekanism/common/tile/TileEntityElectricBlock.java b/src/main/java/mekanism/common/tile/TileEntityElectricBlock.java index 04afbe4b4..3f0c4f4af 100644 --- a/src/main/java/mekanism/common/tile/TileEntityElectricBlock.java +++ b/src/main/java/mekanism/common/tile/TileEntityElectricBlock.java @@ -14,11 +14,13 @@ import mekanism.api.Coord4D; import mekanism.api.MekanismConfig.general; import mekanism.api.transmitters.ITransmitterTile; import mekanism.common.base.IEnergyWrapper; +import mekanism.common.integration.ue.UEDriverProxy; import mekanism.common.util.MekanismUtils; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.tileentity.TileEntity; import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.common.util.ForgeDirection; +import universalelectricity.core.electricity.ElectricityPack; import cpw.mods.fml.common.Optional.Method; public abstract class TileEntityElectricBlock extends TileEntityContainerBlock implements IEnergyWrapper @@ -35,6 +37,8 @@ public abstract class TileEntityElectricBlock extends TileEntityContainerBlock i /** Is this registered with IC2 */ public boolean ic2Registered = false; + private UEDriverProxy driver; + /** * The base of all blocks that deal with electricity. It has a facing state, initialized state, * and a current amount of stored energy. @@ -46,6 +50,7 @@ public abstract class TileEntityElectricBlock extends TileEntityContainerBlock i super(name); BASE_MAX_ENERGY = baseMaxEnergy; maxEnergy = BASE_MAX_ENERGY; + driver = UEDriverProxy.createProxy(this); } @Method(modid = "IC2") @@ -91,6 +96,9 @@ public abstract class TileEntityElectricBlock extends TileEntityContainerBlock i { register(); } + if (!this.worldObj.isRemote) { + driver.tick(); + } } @Override @@ -169,7 +177,7 @@ public abstract class TileEntityElectricBlock extends TileEntityContainerBlock i { deregister(); } - + driver.invalidate(); super.onChunkUnload(); } @@ -177,7 +185,7 @@ public abstract class TileEntityElectricBlock extends TileEntityContainerBlock i public void invalidate() { super.invalidate(); - + driver.invalidate(); if(MekanismUtils.useIC2()) { deregister(); @@ -400,4 +408,78 @@ public abstract class TileEntityElectricBlock extends TileEntityContainerBlock i return toUse; } + + @Override + @Method(modid = "basiccomponents") + public boolean canConnect(ForgeDirection side) { + return getConsumingSides().contains(side) || getOutputtingSides().contains(side); + } + + @Override + @Method(modid = "basiccomponents") + public double getVoltage() { + return 120.0; + } + + @Override + @Method(modid = "basiccomponents") + public boolean canInsert() { + return getConsumingSides().size() > 0; + } + + @Override + @Method(modid = "basiccomponents") + public boolean canExtract() { + return getOutputtingSides().size() > 0; + } + + @Override + @Method(modid = "basiccomponents") + public boolean canInsertOn(ForgeDirection side) { + return getConsumingSides().contains(side); + } + + @Override + @Method(modid = "basiccomponents") + public boolean canExtractOn(ForgeDirection side) { + return getOutputtingSides().contains(side); + } + + @Override + @Method(modid = "basiccomponents") + public void insert(ElectricityPack pack, ForgeDirection side) { + setEnergy(Math.min(getEnergy() + pack.getWatts(), getMaxEnergy())); + } + + @Override + @Method(modid = "basiccomponents") + public void extract(ElectricityPack pack, ForgeDirection side) { + setEnergy(Math.max(getEnergy() - pack.getWatts(), 0)); + } + + @Override + @Method(modid = "basiccomponents") + public ElectricityPack getDemandedJoules() { + if (canInsert()) + return new ElectricityPack((getMaxEnergy() - getEnergy()) / getVoltage(), getVoltage()); + else + return new ElectricityPack(); + } + + @Override + @Method(modid = "basiccomponents") + public ElectricityPack getProvidedJoules() { + if (canExtract()) + return new ElectricityPack(Math.min(getEnergy(), getMaxOutput()) / getVoltage(), getVoltage()); + else + return new ElectricityPack(); + + } + + @Override + @Method(modid = "basiccomponents") + public TileEntity getTile() { + return this; + } + } diff --git a/src/main/java/mekanism/common/tile/TileEntityInductionPort.java b/src/main/java/mekanism/common/tile/TileEntityInductionPort.java index 8a928c29e..03470c5a3 100644 --- a/src/main/java/mekanism/common/tile/TileEntityInductionPort.java +++ b/src/main/java/mekanism/common/tile/TileEntityInductionPort.java @@ -19,6 +19,7 @@ import mekanism.api.transmitters.ITransmitterTile; import mekanism.common.Mekanism; import mekanism.common.base.IActiveState; import mekanism.common.base.IEnergyWrapper; +import mekanism.common.integration.ue.UEDriverProxy; import mekanism.common.network.PacketTileEntity.TileEntityMessage; import mekanism.common.util.CableUtils; import mekanism.common.util.LangUtils; @@ -29,6 +30,7 @@ import net.minecraft.tileentity.TileEntity; import net.minecraft.util.ChatComponentText; import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.common.util.ForgeDirection; +import universalelectricity.core.electricity.ElectricityPack; import cpw.mods.fml.common.Optional.Interface; import cpw.mods.fml.common.Optional.InterfaceList; import cpw.mods.fml.common.Optional.Method; @@ -45,9 +47,12 @@ public class TileEntityInductionPort extends TileEntityInductionCasing implement /** false = input, true = output */ public boolean mode; + private UEDriverProxy driver; + public TileEntityInductionPort() { super("InductionPort"); + driver = UEDriverProxy.createProxy(this); } @Override @@ -68,6 +73,7 @@ public class TileEntityInductionPort extends TileEntityInductionCasing implement CableUtils.emit(this); structure.remainingOutput -= (prev-getEnergy()); } + driver.tick(); } } @@ -195,6 +201,8 @@ public class TileEntityInductionPort extends TileEntityInductionCasing implement deregister(); } + driver.invalidate(); + super.onChunkUnload(); } @@ -203,6 +211,8 @@ public class TileEntityInductionPort extends TileEntityInductionCasing implement { super.invalidate(); + driver.invalidate(); + if(MekanismUtils.useIC2()) { deregister(); @@ -472,4 +482,78 @@ public class TileEntityInductionPort extends TileEntityInductionCasing implement { return false; } + + @Override + @Method(modid = "basiccomponents") + public boolean canConnect(ForgeDirection side) { + return getConsumingSides().contains(side) || getOutputtingSides().contains(side); + } + + @Override + @Method(modid = "basiccomponents") + public double getVoltage() { + return 120.0; + } + + @Override + @Method(modid = "basiccomponents") + public boolean canInsert() { + return getConsumingSides().size() > 0; + } + + @Override + @Method(modid = "basiccomponents") + public boolean canExtract() { + return getOutputtingSides().size() > 0; + } + + @Override + @Method(modid = "basiccomponents") + public boolean canInsertOn(ForgeDirection side) { + return getConsumingSides().contains(side); + } + + @Override + @Method(modid = "basiccomponents") + public boolean canExtractOn(ForgeDirection side) { + return getOutputtingSides().contains(side); + } + + @Override + @Method(modid = "basiccomponents") + public void insert(ElectricityPack pack, ForgeDirection side) { + setEnergy(Math.min(getEnergy() + pack.getWatts(), getMaxEnergy())); + } + + @Override + @Method(modid = "basiccomponents") + public void extract(ElectricityPack pack, ForgeDirection side) { + setEnergy(Math.max(getEnergy() - pack.getWatts(), 0)); + } + + @Override + @Method(modid = "basiccomponents") + public ElectricityPack getDemandedJoules() { + if (canInsert()) + return new ElectricityPack((getMaxEnergy() - getEnergy()) / getVoltage(), getVoltage()); + else + return new ElectricityPack(); + } + + @Override + @Method(modid = "basiccomponents") + public ElectricityPack getProvidedJoules() { + if (canExtract()) + return new ElectricityPack(Math.min(getEnergy(), getMaxOutput()) / getVoltage(), getVoltage()); + else + return new ElectricityPack(); + + } + + @Override + @Method(modid = "basiccomponents") + public TileEntity getTile() { + return this; + } + } \ No newline at end of file diff --git a/src/main/java/mekanism/generators/common/tile/turbine/TileEntityTurbineValve.java b/src/main/java/mekanism/generators/common/tile/turbine/TileEntityTurbineValve.java index 45732d6b1..f9622f496 100644 --- a/src/main/java/mekanism/generators/common/tile/turbine/TileEntityTurbineValve.java +++ b/src/main/java/mekanism/generators/common/tile/turbine/TileEntityTurbineValve.java @@ -10,6 +10,7 @@ import java.util.EnumSet; import mekanism.api.Coord4D; import mekanism.api.MekanismConfig.general; import mekanism.common.base.IEnergyWrapper; +import mekanism.common.integration.ue.UEDriverProxy; import mekanism.common.tile.TileEntityGasTank.GasMode; import mekanism.common.util.CableUtils; import mekanism.common.util.LangUtils; @@ -24,6 +25,7 @@ import net.minecraftforge.fluids.FluidRegistry; import net.minecraftforge.fluids.FluidStack; import net.minecraftforge.fluids.FluidTankInfo; import net.minecraftforge.fluids.IFluidHandler; +import universalelectricity.core.electricity.ElectricityPack; import cpw.mods.fml.common.Optional.Interface; import cpw.mods.fml.common.Optional.InterfaceList; import cpw.mods.fml.common.Optional.Method; @@ -39,10 +41,13 @@ public class TileEntityTurbineValve extends TileEntityTurbineCasing implements I public TurbineFluidTank fluidTank; + private UEDriverProxy driver; + public TileEntityTurbineValve() { super("TurbineValve"); fluidTank = new TurbineFluidTank(this); + driver = UEDriverProxy.createProxy(this); } @Override @@ -62,6 +67,7 @@ public class TileEntityTurbineValve extends TileEntityTurbineCasing implements I double prev = getEnergy(); CableUtils.emit(this); } + driver.tick(); } } @@ -160,6 +166,8 @@ public class TileEntityTurbineValve extends TileEntityTurbineCasing implements I deregister(); } + driver.invalidate(); + super.onChunkUnload(); } @@ -168,6 +176,8 @@ public class TileEntityTurbineValve extends TileEntityTurbineCasing implements I { super.invalidate(); + driver.invalidate(); + if(MekanismUtils.useIC2()) { deregister(); @@ -407,4 +417,75 @@ public class TileEntityTurbineValve extends TileEntityTurbineCasing implements I { return LangUtils.localize("gui.industrialTurbine"); } + + @Override + @Method(modid = "basiccomponents") + public boolean canConnect(ForgeDirection side) { + return getOutputtingSides().contains(side); + } + + @Override + @Method(modid = "basiccomponents") + public double getVoltage() { + return 120.0; + } + + @Override + @Method(modid = "basiccomponents") + public boolean canInsert() { + return false; + } + + @Override + @Method(modid = "basiccomponents") + public boolean canExtract() { + return getOutputtingSides().size() > 0; + } + + @Override + @Method(modid = "basiccomponents") + public boolean canInsertOn(ForgeDirection side) { + return false; + } + + @Override + @Method(modid = "basiccomponents") + public boolean canExtractOn(ForgeDirection side) { + return getOutputtingSides().contains(side); + } + + @Override + @Method(modid = "basiccomponents") + public void insert(ElectricityPack pack, ForgeDirection side) { + + } + + @Override + @Method(modid = "basiccomponents") + public void extract(ElectricityPack pack, ForgeDirection side) { + setEnergy(Math.max(getEnergy() - pack.getWatts(), 0)); + } + + @Override + @Method(modid = "basiccomponents") + public ElectricityPack getDemandedJoules() { + return new ElectricityPack(); + } + + @Override + @Method(modid = "basiccomponents") + public ElectricityPack getProvidedJoules() { + if (canExtract()) + return new ElectricityPack(Math.min(getEnergy(), getMaxOutput()) / getVoltage(), getVoltage()); + else + return new ElectricityPack(); + + } + + @Override + @Method(modid = "basiccomponents") + public TileEntity getTile() { + return this; + } + }