From e899355dfb475a5016a733a5633d3ad015dd749a Mon Sep 17 00:00:00 2001 From: Timo Ley Date: Sun, 21 Jul 2024 16:48:38 +0200 Subject: [PATCH] feat: HBM compat --- build.gradle | 19 +++-- .../java/mekanism/api/MekanismConfig.java | 1 + .../java/mekanism/common/CommonProxy.java | 4 ++ .../common/base/EnergyAcceptorWrapper.java | 53 ++++++++++++++ .../mekanism/common/base/IEnergyWrapper.java | 8 ++- .../common/integration/MekanismHooks.java | 3 + .../container/ContainerPersonalChest.java | 4 +- .../common/multipart/MultipartMekanism.java | 5 ++ .../common/multipart/PartUniversalCable.java | 69 ++++++++++++++++++- .../common/network/PacketConfigSync.java | 2 + .../common/tile/TileEntityElectricBlock.java | 59 ++++++++++++++++ .../common/tile/TileEntityInductionPort.java | 54 ++++++++++++++- .../java/mekanism/common/util/CableUtils.java | 21 +++++- .../mekanism/common/util/MekanismUtils.java | 4 ++ .../tile/turbine/TileEntityTurbineValve.java | 53 +++++++++++++- 15 files changed, 342 insertions(+), 17 deletions(-) diff --git a/build.gradle b/build.gradle index 41e24fb8c..c0d269ea9 100644 --- a/build.gradle +++ b/build.gradle @@ -25,11 +25,19 @@ defaultTasks 'fullBuild' repositories { maven { - name 'central' - url 'https://maven.thorfusion.com/artifactory/central/' + url 'https://maven.tilera.xyz' } maven { - url 'https://maven.tilera.xyz' + url = "https://s3.tilera.xyz/cdn/minecraft/libs/" + metadataSources { artifact() } + } + maven { + name "central" + url "https://nexus.covers1624.net/repository/maven-hosted/" + } + maven { + url = "https://gregtech.overminddl1.com/" + metadataSources { artifact() } } } @@ -55,11 +63,12 @@ dependencies { compile "codechicken:ForgeMultipart:${config.minecraft_version}-${config.FMP_version}:dev" compile "codechicken:NotEnoughItems:${config.minecraft_version}-${config.NEI_version}:dev" compile "codechicken:CodeChickenCore:${config.minecraft_version}-${config.CCC_version}:dev" - compile "inventorytweaks:inventory-tweaks:1.7.10-1.60.0:api" - compile "net.industrial-craft:industrialcraft-2:2.2.828-experimental:api" + compile "inventorytweaks:InventoryTweaks:1.59-dev:api" + compile "net.industrial-craft:industrialcraft-2:2.2.827-experimental:dev" compile "mcp.mobius.waila:Waila:1.5.10_1.7.10:dev" compile "universalelectricity:basiccomponents:2.0.0:deobf" compile "universalelectricity:universalelectricity:5.1.0:deobf" + compile "com.hbm:HBM-NTM:1.0.27_X5000:deobf" } version = "${config.minecraft_version}-${config.mod_version}" diff --git a/src/main/java/mekanism/api/MekanismConfig.java b/src/main/java/mekanism/api/MekanismConfig.java index 9c30ff16a..01872bc6a 100644 --- a/src/main/java/mekanism/api/MekanismConfig.java +++ b/src/main/java/mekanism/api/MekanismConfig.java @@ -42,6 +42,7 @@ public class MekanismConfig { public static double minerSilkMultiplier = 6; public static boolean blacklistIC2; public static boolean blacklistRF; + public static boolean blacklistHBM; public static boolean destroyDisabledBlocks; public static boolean prefilledFluidTanks; public static boolean prefilledGasTanks; diff --git a/src/main/java/mekanism/common/CommonProxy.java b/src/main/java/mekanism/common/CommonProxy.java index 78ef732e8..c1d8e8d4b 100644 --- a/src/main/java/mekanism/common/CommonProxy.java +++ b/src/main/java/mekanism/common/CommonProxy.java @@ -545,6 +545,10 @@ public class CommonProxy implements IGuiProvider { = Mekanism.configuration .get(Configuration.CATEGORY_GENERAL, "BlacklistRFPower", false) .getBoolean(); + general.blacklistHBM + = Mekanism.configuration + .get(Configuration.CATEGORY_GENERAL, "BlacklistHBMPower", false) + .getBoolean(); general.EnableQuartzCompat = Mekanism.configuration diff --git a/src/main/java/mekanism/common/base/EnergyAcceptorWrapper.java b/src/main/java/mekanism/common/base/EnergyAcceptorWrapper.java index d0105ce63..229bbf7bd 100644 --- a/src/main/java/mekanism/common/base/EnergyAcceptorWrapper.java +++ b/src/main/java/mekanism/common/base/EnergyAcceptorWrapper.java @@ -1,5 +1,6 @@ package mekanism.common.base; +import api.hbm.energymk2.IEnergyReceiverMK2; import cofh.api.energy.IEnergyReceiver; import ic2.api.energy.tile.IEnergySink; import mekanism.api.Coord4D; @@ -26,6 +27,8 @@ public abstract class EnergyAcceptorWrapper implements IStrictEnergyAcceptor { wrapper = new RFAcceptor((IEnergyReceiver) tileEntity); } else if (MekanismUtils.useIC2() && CableUtils.getIC2Tile(tileEntity) instanceof IEnergySink) { wrapper = new IC2Acceptor((IEnergySink) CableUtils.getIC2Tile(tileEntity)); + } else if (MekanismUtils.useHBM() && tileEntity instanceof IEnergyReceiverMK2) { + wrapper = new HBMAcceptor((IEnergyReceiverMK2) tileEntity); } if (wrapper != null) { @@ -182,4 +185,54 @@ public abstract class EnergyAcceptorWrapper implements IStrictEnergyAcceptor { return eu * general.FROM_IC2; } } + + public static class HBMAcceptor extends EnergyAcceptorWrapper { + private IEnergyReceiverMK2 acceptor; + + public HBMAcceptor(IEnergyReceiverMK2 acceptor) { + this.acceptor = acceptor; + } + + @Override + public double transferEnergyToAcceptor(ForgeDirection side, double amount) { + if (!canReceiveEnergy(side)) return amount; + long toTransfer = Math.min(Math.min(toHE(amount), acceptor.getReceiverSpeed()), acceptor.getMaxPower() - acceptor.getPower()); + long leftover = acceptor.transferPower(toTransfer); + return fromHE(toTransfer - leftover); + } + + @Override + public boolean canReceiveEnergy(ForgeDirection side) { + return acceptor.canConnect(side); + } + + @Override + public double getEnergy() { + return fromHE(acceptor.getPower()); + } + + @Override + public void setEnergy(double energy) { + acceptor.setPower(toHE(energy)); + } + + @Override + public double getMaxEnergy() { + return fromHE(acceptor.getMaxPower()); + } + + @Override + public boolean needsEnergy(ForgeDirection side) { + return canReceiveEnergy(side) && acceptor.getPower() < acceptor.getMaxPower(); + } + + public long toHE(double joules) { + return (long)Math.floor(joules * general.TO_IC2); + } + + public double fromHE(long he) { + return he * general.FROM_IC2; + } + + } } diff --git a/src/main/java/mekanism/common/base/IEnergyWrapper.java b/src/main/java/mekanism/common/base/IEnergyWrapper.java index 55aacfea7..7098cbe38 100644 --- a/src/main/java/mekanism/common/base/IEnergyWrapper.java +++ b/src/main/java/mekanism/common/base/IEnergyWrapper.java @@ -2,6 +2,8 @@ package mekanism.common.base; import java.util.EnumSet; +import api.hbm.energymk2.IEnergyProviderMK2; +import api.hbm.energymk2.IEnergyReceiverMK2; import cofh.api.energy.IEnergyHandler; import cpw.mods.fml.common.Optional.Interface; import cpw.mods.fml.common.Optional.InterfaceList; @@ -17,11 +19,13 @@ import net.minecraftforge.common.util.ForgeDirection; @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 = "api.hbm.energymk2.IEnergyProviderMK2", modid = "hbm"), + @Interface(iface = "api.hbm.energymk2.IEnergyReceiverMK2", modid = "hbm") }) public interface IEnergyWrapper extends IStrictEnergyStorage, IEnergyHandler, IEnergySink, IEnergySource, - IEnergyStorage, IStrictEnergyAcceptor, ICableOutputter, IInventory { + IEnergyStorage, IStrictEnergyAcceptor, ICableOutputter, IInventory, IEnergyReceiverMK2, IEnergyProviderMK2 { public EnumSet getOutputtingSides(); public EnumSet getConsumingSides(); diff --git a/src/main/java/mekanism/common/integration/MekanismHooks.java b/src/main/java/mekanism/common/integration/MekanismHooks.java index 1d21a001c..550424309 100644 --- a/src/main/java/mekanism/common/integration/MekanismHooks.java +++ b/src/main/java/mekanism/common/integration/MekanismHooks.java @@ -39,6 +39,7 @@ public final class MekanismHooks { public boolean TELoaded = false; public boolean CCLoaded = false; public boolean AE2Loaded = false; + public boolean HBMLoaded = false; public void hook() { if (Loader.isModLoaded("CoFHCore")) @@ -53,6 +54,8 @@ public final class MekanismHooks { CCLoaded = true; if (Loader.isModLoaded("appliedenergistics2")) AE2Loaded = true; + if (Loader.isModLoaded("hbm")) + HBMLoaded = true; if (IC2Loaded) { hookIC2Recipes(); diff --git a/src/main/java/mekanism/common/inventory/container/ContainerPersonalChest.java b/src/main/java/mekanism/common/inventory/container/ContainerPersonalChest.java index 4983c887a..d2f8dbb55 100644 --- a/src/main/java/mekanism/common/inventory/container/ContainerPersonalChest.java +++ b/src/main/java/mekanism/common/inventory/container/ContainerPersonalChest.java @@ -1,6 +1,6 @@ package mekanism.common.inventory.container; -import invtweaks.api.container.ChestContainer; +//import invtweaks.api.container.ChestContainer; import mekanism.common.block.BlockMachine.MachineType; import mekanism.common.inventory.slot.SlotPersonalChest; import mekanism.common.tile.TileEntityPersonalChest; @@ -11,7 +11,7 @@ import net.minecraft.inventory.IInventory; import net.minecraft.inventory.Slot; import net.minecraft.item.ItemStack; -@ChestContainer(isLargeChest = true) +//@ChestContainer(isLargeChest = true) public class ContainerPersonalChest extends Container { private TileEntityPersonalChest tileEntity; private IInventory itemInventory; diff --git a/src/main/java/mekanism/common/multipart/MultipartMekanism.java b/src/main/java/mekanism/common/multipart/MultipartMekanism.java index f9e354c08..f21376453 100644 --- a/src/main/java/mekanism/common/multipart/MultipartMekanism.java +++ b/src/main/java/mekanism/common/multipart/MultipartMekanism.java @@ -9,10 +9,12 @@ import codechicken.multipart.MultiPartRegistry; import codechicken.multipart.MultiPartRegistry.IPartFactory; import codechicken.multipart.MultipartGenerator; import codechicken.multipart.TMultiPart; +import cpw.mods.fml.common.Loader; import cpw.mods.fml.common.event.FMLInterModComms; import mekanism.common.MekanismBlocks; import mekanism.common.Tier; import mekanism.common.block.BlockMachine.MachineType; +import mekanism.common.util.MekanismUtils; import net.minecraft.item.ItemStack; public class MultipartMekanism implements IPartFactory { @@ -72,6 +74,9 @@ public class MultipartMekanism implements IPartFactory { "mekanism.common.base.ITileNetwork" ); MultipartGenerator.registerPassThroughInterface("cofh.api.energy.IEnergyHandler"); + if (Loader.isModLoaded("hbm")) { + MultipartGenerator.registerPassThroughInterface("api.hbm.energymk2.IEnergyReceiverMK2"); + } registerMicroMaterials(); } diff --git a/src/main/java/mekanism/common/multipart/PartUniversalCable.java b/src/main/java/mekanism/common/multipart/PartUniversalCable.java index 76fce363a..d1f678016 100644 --- a/src/main/java/mekanism/common/multipart/PartUniversalCable.java +++ b/src/main/java/mekanism/common/multipart/PartUniversalCable.java @@ -3,11 +3,16 @@ package mekanism.common.multipart; import java.util.Collection; import java.util.List; +import api.hbm.energymk2.IEnergyProviderMK2; +import api.hbm.energymk2.IEnergyReceiverMK2; import codechicken.lib.data.MCDataInput; import codechicken.lib.data.MCDataOutput; import codechicken.lib.vec.Vector3; import cofh.api.energy.IEnergyHandler; import cofh.api.energy.IEnergyProvider; +import cpw.mods.fml.common.Optional.Interface; +import cpw.mods.fml.common.Optional.InterfaceList; +import cpw.mods.fml.common.Optional.Method; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; import ic2.api.energy.tile.IEnergySource; @@ -32,9 +37,12 @@ import net.minecraft.tileentity.TileEntity; import net.minecraft.util.IIcon; import net.minecraftforge.common.util.ForgeDirection; +@InterfaceList({ + @Interface(iface = "api.hbm.energymk2.IEnergyReceiverMK2", modid = "hbm") +}) public class PartUniversalCable extends PartTransmitter - implements IStrictEnergyAcceptor, IEnergyHandler { + implements IStrictEnergyAcceptor, IEnergyHandler, IEnergyReceiverMK2 { public Tier.CableTier tier; public static TransmitterIcons cableIcons = new TransmitterIcons(4, 8); @@ -44,6 +52,8 @@ public class PartUniversalCable public EnergyStack buffer = new EnergyStack(0); + public boolean isLoaded = false; + public PartUniversalCable(Tier.CableTier cableTier) { super(); tier = cableTier; @@ -61,6 +71,10 @@ public class PartUniversalCable } } else { updateShare(); + isLoaded = true; + if (MekanismUtils.useHBM()) { + receiveHe(); + } List sides = getConnections(ConnectionType.PULL); @@ -72,7 +86,6 @@ public class PartUniversalCable for (ForgeDirection side : sides) { if (connectedOutputters[side.ordinal()] != null) { TileEntity outputter = connectedOutputters[side.ordinal()]; - if (outputter instanceof ICableOutputter && outputter instanceof IStrictEnergyStorage) { if (((ICableOutputter) outputter) @@ -128,6 +141,14 @@ public class PartUniversalCable ((IEnergySource) CableUtils.getIC2Tile(outputter)) .drawEnergy(toDraw * general.TO_IC2); + } else if (MekanismUtils.useHBM() && outputter instanceof IEnergyProviderMK2) { + IEnergyProviderMK2 tile = (IEnergyProviderMK2) outputter; + double received = Math.min(Math.min(tile.getPower(), tile.getProviderSpeed()) * general.FROM_IC2, canDraw); + double toDraw = received; + if (received > 0) { + toDraw -= takeEnergy(received, true); + } + tile.usePower((long)(toDraw * general.TO_IC2)); } } } @@ -256,9 +277,16 @@ public class PartUniversalCable @Override public void onChunkUnload() { takeShare(); + isLoaded = false; super.onChunkUnload(); } + @Override + public void onRemoved() { + isLoaded = false; + super.onRemoved(); + } + @Override public Object getBuffer() { return buffer; @@ -408,4 +436,41 @@ public class PartUniversalCable super.writeDesc(packet); } + + @Override + @Method(modid = "hbm") + public long getPower() { + return Math.round(getEnergy() * general.TO_IC2); + } + + @Override + @Method(modid = "hbm") + public void setPower(long power) { + setEnergy(power * general.FROM_IC2); + } + + @Override + @Method(modid = "hbm") + public long getMaxPower() { + return Math.round(getMaxEnergy() * general.TO_IC2); + } + + @Method(modid = "hbm") + public void receiveHe() { + for (ForgeDirection dir : getConnections(ConnectionType.NORMAL)) + this.trySubscribe( + world(), + x() + dir.offsetX, + y() + dir.offsetY, + z() + dir.offsetZ, + dir + ); + } + + @Override + @Method(modid = "hbm") + public boolean isLoaded() { + return isLoaded; + } + } diff --git a/src/main/java/mekanism/common/network/PacketConfigSync.java b/src/main/java/mekanism/common/network/PacketConfigSync.java index c6d74c8f6..52a070d9c 100644 --- a/src/main/java/mekanism/common/network/PacketConfigSync.java +++ b/src/main/java/mekanism/common/network/PacketConfigSync.java @@ -49,6 +49,7 @@ public class PacketConfigSync implements IMessageHandler 0) { diff --git a/src/main/java/mekanism/common/util/MekanismUtils.java b/src/main/java/mekanism/common/util/MekanismUtils.java index 7ec65e808..3a27c5c46 100644 --- a/src/main/java/mekanism/common/util/MekanismUtils.java +++ b/src/main/java/mekanism/common/util/MekanismUtils.java @@ -1208,6 +1208,10 @@ public final class MekanismUtils { return !general.blacklistRF; } + public static boolean useHBM() { + return Mekanism.hooks.HBMLoaded && !general.blacklistHBM; + } + /** * Gets a clean view of a coordinate value without the dimension ID. * @param obj - coordinate to check 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 4635a9418..210942d87 100644 --- a/src/main/java/mekanism/generators/common/tile/turbine/TileEntityTurbineValve.java +++ b/src/main/java/mekanism/generators/common/tile/turbine/TileEntityTurbineValve.java @@ -36,6 +36,7 @@ import net.minecraftforge.fluids.IFluidHandler; public class TileEntityTurbineValve extends TileEntityTurbineCasing implements IFluidHandler, IEnergyWrapper { public boolean ic2Registered = false; + public boolean isLoaded = false; public TurbineFluidTank fluidTank; @@ -51,6 +52,10 @@ public class TileEntityTurbineValve if (!ic2Registered && MekanismUtils.useIC2()) { register(); } + if (MekanismUtils.useHBM()) { + receiveHe(); + } + isLoaded = true; if (!worldObj.isRemote) { if (structure != null) { @@ -138,14 +143,14 @@ public class TileEntityTurbineValve if (MekanismUtils.useIC2()) { deregister(); } - + isLoaded = false; super.onChunkUnload(); } @Override public void invalidate() { super.invalidate(); - + isLoaded = false; if (MekanismUtils.useIC2()) { deregister(); } @@ -356,4 +361,48 @@ public class TileEntityTurbineValve public String getInventoryName() { return LangUtils.localize("gui.industrialTurbine"); } + + @Override + @Method(modid = "hbm") + public long getPower() { + return Math.round(getEnergy() * general.TO_IC2); + } + + @Override + @Method(modid = "hbm") + public void setPower(long power) { + setEnergy(power * general.FROM_IC2); + } + + @Override + @Method(modid = "hbm") + public long getMaxPower() { + return Math.round(getMaxEnergy() * general.TO_IC2); + } + + @Override + @Method(modid = "hbm") + public long getProviderSpeed() { + return Math.round(getMaxOutput() * general.TO_IC2); + } + + @Method(modid = "hbm") + public void receiveHe() { + if (!worldObj.isRemote) { + for (ForgeDirection dir : getConsumingSides()) + this.trySubscribe( + worldObj, + xCoord + dir.offsetX, + yCoord + dir.offsetY, + zCoord + dir.offsetZ, + dir + ); + } + } + + @Override + @Method(modid = "hbm") + public boolean isLoaded() { + return isLoaded; + } }