From c732a5ec899573c0f780b2b9a5ae1fbd1af74e64 Mon Sep 17 00:00:00 2001 From: gjmhmm8 Date: Wed, 10 Apr 2024 14:58:18 +0800 Subject: [PATCH] =?UTF-8?q?=E9=80=9A=E9=87=8F=E8=AE=BF=E9=97=AE=E7=82=B9?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E5=88=B0Long?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build.gradle | 10 ++- gradle.properties | 2 +- .../appflux/common/caps/NetworkFEPower.java | 6 +- .../appflux/common/caps/NetworkFEPowerL.java | 68 +++++++++++++++++++ .../common/tileentities/TileFluxAccessor.java | 66 ++++++++++++++---- .../github/appflux/xmod/mek/MekEnergy.java | 1 - 6 files changed, 135 insertions(+), 18 deletions(-) create mode 100644 src/main/java/com/glodblock/github/appflux/common/caps/NetworkFEPowerL.java diff --git a/build.gradle b/build.gradle index df6c6875..96047f2e 100644 --- a/build.gradle +++ b/build.gradle @@ -80,16 +80,20 @@ repositories { dependencies { minecraft "net.neoforged:forge:${minecraft_version}-${forge_version}" + implementation fg.deobf("curse.maven:glodium-957920:5024300") implementation fg.deobf("appeng:appliedenergistics2-forge:15.0.12") - compileOnly fg.deobf("mekanism:Mekanism:1.20.1-10.4.0.14:all") - compileOnly fg.deobf("mezz.jei:jei-1.20.1-forge:15.0.0.12") + compileOnly fg.deobf("mekanism:Mekanism:${minecraft_version}-${mekanism_version}:api") + implementation fg.deobf("mekanism:Mekanism:${minecraft_version}-${mekanism_version}") + implementation fg.deobf("curse.maven:flux-networks-248020:5234697") + compileOnly fg.deobf("mezz.jei:jei-1.20.1-forge:15.2.0.27") // for some reason this deobf jar fails to load at file correctly compileOnly fg.deobf("curse.maven:jade-324717:4768593") annotationProcessor 'org.spongepowered:mixin:0.8.4:processor' // runtime test - runtimeOnly fg.deobf("mezz.jei:jei-1.20.1-forge:15.0.0.12") + runtimeOnly fg.deobf("mezz.jei:jei-1.20.1-forge:15.2.0.27") runtimeOnly fg.deobf("curse.maven:jade-324717:4768593") + } tasks.named('processResources', ProcessResources).configure { diff --git a/gradle.properties b/gradle.properties index 576533d2..3298c4e8 100644 --- a/gradle.properties +++ b/gradle.properties @@ -11,7 +11,7 @@ loader_version_range=[47,) mapping_channel=official mapping_version=1.20.1 - +mekanism_version=10.4.4.18 mod_id=appflux mod_name=AppliedFlux mod_license=LGPL-3.0 diff --git a/src/main/java/com/glodblock/github/appflux/common/caps/NetworkFEPower.java b/src/main/java/com/glodblock/github/appflux/common/caps/NetworkFEPower.java index b825c517..d04773c4 100644 --- a/src/main/java/com/glodblock/github/appflux/common/caps/NetworkFEPower.java +++ b/src/main/java/com/glodblock/github/appflux/common/caps/NetworkFEPower.java @@ -8,7 +8,8 @@ import com.glodblock.github.appflux.util.AFUtil; import net.minecraftforge.energy.IEnergyStorage; -public record NetworkFEPower(IStorageService storage, IActionSource source) implements IEnergyStorage { + +public record NetworkFEPower(IStorageService storage, IActionSource source) implements IEnergyStorage{ @Override public int receiveEnergy(int maxReceive, boolean simulate) { @@ -31,6 +32,7 @@ public int getMaxEnergyStored() { return AFUtil.clampLong(space + this.getEnergyStored()); } + @Override public boolean canExtract() { return true; @@ -40,4 +42,6 @@ public boolean canExtract() { public boolean canReceive() { return true; } + + } diff --git a/src/main/java/com/glodblock/github/appflux/common/caps/NetworkFEPowerL.java b/src/main/java/com/glodblock/github/appflux/common/caps/NetworkFEPowerL.java new file mode 100644 index 00000000..4a0b3766 --- /dev/null +++ b/src/main/java/com/glodblock/github/appflux/common/caps/NetworkFEPowerL.java @@ -0,0 +1,68 @@ +package com.glodblock.github.appflux.common.caps; + +import appeng.api.config.Actionable; +import appeng.api.networking.security.IActionSource; +import appeng.api.networking.storage.IStorageService; +import com.glodblock.github.appflux.common.me.key.FluxKey; +import com.glodblock.github.appflux.common.me.key.type.EnergyType; +import com.glodblock.github.appflux.util.AFUtil; +import net.minecraftforge.energy.IEnergyStorage; +import sonar.fluxnetworks.api.energy.IFNEnergyStorage; + + +public record NetworkFEPowerL(IStorageService storage, IActionSource source) implements IEnergyStorage,IFNEnergyStorage{ + + @Override + public int receiveEnergy(int maxReceive, boolean simulate) { + return (int) this.storage.getInventory().insert(FluxKey.of(EnergyType.FE), maxReceive, Actionable.ofSimulate(simulate), this.source); + } + + @Override + public int extractEnergy(int maxExtract, boolean simulate) { + return (int) this.storage.getInventory().extract(FluxKey.of(EnergyType.FE), maxExtract, Actionable.ofSimulate(simulate), this.source); + } + + @Override + public int getEnergyStored() { + return AFUtil.clampLong(this.storage.getCachedInventory().get(FluxKey.of(EnergyType.FE))); + } + + @Override + public int getMaxEnergyStored() { + var space = this.storage.getInventory().insert(FluxKey.of(EnergyType.FE), Long.MAX_VALUE - 1, Actionable.SIMULATE, this.source); + return AFUtil.clampLong(space + this.getEnergyStored()); + } + + + public long receiveEnergyL(long l, boolean b) { + return this.storage.getInventory().insert(FluxKey.of(EnergyType.FE), l, Actionable.ofSimulate(b), this.source); + } + + + public long extractEnergyL(long l, boolean b) { + return this.storage.getInventory().extract(FluxKey.of(EnergyType.FE), l, Actionable.ofSimulate(b), this.source); + } + + + public long getEnergyStoredL() { + return this.storage.getCachedInventory().get(FluxKey.of(EnergyType.FE)); + } + + public long getMaxEnergyStoredL() { + var space = this.storage.getInventory().insert(FluxKey.of(EnergyType.FE), Long.MAX_VALUE - 1, Actionable.SIMULATE, this.source); + return space + this.getEnergyStored(); + } + + + @Override + public boolean canExtract() { + return true; + } + + @Override + public boolean canReceive() { + return true; + } + + +} diff --git a/src/main/java/com/glodblock/github/appflux/common/tileentities/TileFluxAccessor.java b/src/main/java/com/glodblock/github/appflux/common/tileentities/TileFluxAccessor.java index 230d2d40..a23a7064 100644 --- a/src/main/java/com/glodblock/github/appflux/common/tileentities/TileFluxAccessor.java +++ b/src/main/java/com/glodblock/github/appflux/common/tileentities/TileFluxAccessor.java @@ -11,6 +11,7 @@ import appeng.blockentity.grid.AENetworkBlockEntity; import com.glodblock.github.appflux.common.AFItemAndBlock; import com.glodblock.github.appflux.common.caps.NetworkFEPower; +import com.glodblock.github.appflux.common.caps.NetworkFEPowerL; import com.glodblock.github.appflux.common.me.key.FluxKey; import com.glodblock.github.appflux.common.me.key.type.EnergyType; import com.glodblock.github.appflux.util.AFUtil; @@ -23,10 +24,16 @@ import net.minecraftforge.common.capabilities.ForgeCapabilities; import net.minecraftforge.common.util.LazyOptional; import net.minecraftforge.energy.EnergyStorage; +import net.minecraftforge.energy.IEnergyStorage; +import net.minecraftforge.fml.ModList; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import sonar.fluxnetworks.api.FluxCapabilities; +import appeng.api.config.PowerUnits; +import java.lang.reflect.InvocationTargetException; public class TileFluxAccessor extends AENetworkBlockEntity implements IGridTickable { + Boolean IsFnLoad = ModList.get().isLoaded("fluxnetworks"); public TileFluxAccessor(BlockPos pos, BlockState blockState) { super(GlodUtil.getTileType(TileFluxAccessor.class, TileFluxAccessor::new, AFItemAndBlock.FLUX_ACCESSOR), pos, blockState); @@ -36,9 +43,13 @@ public TileFluxAccessor(BlockPos pos, BlockState blockState) { @Override public @NotNull LazyOptional getCapability(@NotNull Capability cap, @Nullable Direction side) { - if (cap == ForgeCapabilities.ENERGY) { + if (cap == ForgeCapabilities.ENERGY || + (IsFnLoad && cap == FluxCapabilities.FN_ENERGY_STORAGE)) { return LazyOptional.of(() -> { if (this.getStorage() != null) { + if (ModList.get().isLoaded("fluxnetworks")) { + return new NetworkFEPowerL(this.getStorage(), this.getSource()); + } return new NetworkFEPower(this.getStorage(), this.getSource()); } else { return new EnergyStorage(0); @@ -80,24 +91,55 @@ public TickRateModulation tickingRequest(IGridNode node, int ticksSinceLastCall) var te = this.level.getBlockEntity(this.worldPosition.offset(d.getNormal())); var thatGrid = AFUtil.getGrid(te, d.getOpposite()); if (te != null && thatGrid != gird && !AFUtil.isBlackListTE(te, d.getOpposite())) { - var accepter = AFUtil.findCapability(te, d.getOpposite(), ForgeCapabilities.ENERGY); - if (accepter != null) { - var toAdd = accepter.receiveEnergy(Integer.MAX_VALUE, true); - if (toAdd > 0) { - var drained = storage.getInventory().extract(FluxKey.of(EnergyType.FE), toAdd, Actionable.MODULATE, this.getSource()); - if (drained > 0) { - var actuallyDrained = accepter.receiveEnergy((int) drained, false); - var differ = drained - actuallyDrained; - if (differ > 0) { - storage.getInventory().insert(FluxKey.of(EnergyType.FE), differ, Actionable.MODULATE, this.getSource()); - } + long canAdd = Long.MAX_VALUE; + var toAdd = 0L; + if (IsFnLoad) { + var accepterL = AFUtil.findCapability(te, d.getOpposite(), FluxCapabilities.FN_ENERGY_STORAGE); + if (accepterL != null) { + toAdd += accepterL.receiveEnergyL(canAdd, true); + } else { + var accepter = AFUtil.findCapability(te, d.getOpposite(), ForgeCapabilities.ENERGY); + if (accepter != null) { + toAdd += accepter.receiveEnergy(AFUtil.clampLong(canAdd), true); + } + } + } else { + var accepter = AFUtil.findCapability(te, d.getOpposite(), ForgeCapabilities.ENERGY); + if (accepter != null) { + toAdd += accepter.receiveEnergy(AFUtil.clampLong(canAdd), true); + } + } + canAdd=storage.getInventory().extract(FluxKey.of(EnergyType.FE), toAdd, Actionable.MODULATE, this.getSource()); + toAdd=0L; + if(IsFnLoad){ + var accepterL = AFUtil.findCapability(te, d.getOpposite(), FluxCapabilities.FN_ENERGY_STORAGE); + if(accepterL!=null){ + toAdd+=accepterL.receiveEnergyL(canAdd,false); + }else{ + var accepter = AFUtil.findCapability(te, d.getOpposite(), ForgeCapabilities.ENERGY); + if(accepter!=null){ + toAdd+=accepter.receiveEnergy(AFUtil.clampLong(canAdd),false); } } + }else{ + var accepter = AFUtil.findCapability(te, d.getOpposite(), ForgeCapabilities.ENERGY); + if(accepter!=null){ + toAdd+=accepter.receiveEnergy(AFUtil.clampLong(canAdd),false); + } } + storage.getInventory().insert(FluxKey.of(EnergyType.FE), canAdd-toAdd, Actionable.MODULATE, this.getSource()); } + + } + if (gird != null) { + var to_input = gird.getEnergyService().injectPower(9007199254740990L, Actionable.SIMULATE); + var can_input = storage.getInventory().extract(FluxKey.of(EnergyType.FE), Math.round(PowerUnits.AE.convertTo(PowerUnits.RF,9007199254740990L-to_input)), Actionable.MODULATE, this.getSource()); + gird.getEnergyService().injectPower(PowerUnits.RF.convertTo(PowerUnits.AE,can_input), Actionable.MODULATE); } + } return TickRateModulation.SAME; } + } diff --git a/src/main/java/com/glodblock/github/appflux/xmod/mek/MekEnergy.java b/src/main/java/com/glodblock/github/appflux/xmod/mek/MekEnergy.java index 17a2953d..869ec441 100644 --- a/src/main/java/com/glodblock/github/appflux/xmod/mek/MekEnergy.java +++ b/src/main/java/com/glodblock/github/appflux/xmod/mek/MekEnergy.java @@ -19,7 +19,6 @@ public interface MekEnergy { long output(long power, Actionable mode, Direction side); interface Factory { - MekEnergy create(ServerLevel level, BlockPos pos); }