Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

通量访问点支持到Long #133

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -31,6 +32,7 @@ public int getMaxEnergyStored() {
return AFUtil.clampLong(space + this.getEnergyStored());
}


@Override
public boolean canExtract() {
return true;
Expand All @@ -40,4 +42,6 @@ public boolean canExtract() {
public boolean canReceive() {
return true;
}


}
Original file line number Diff line number Diff line change
@@ -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;
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand All @@ -36,9 +43,13 @@ public TileFluxAccessor(BlockPos pos, BlockState blockState) {

@Override
public <T> @NotNull LazyOptional<T> getCapability(@NotNull Capability<T> 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);
Expand Down Expand Up @@ -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;
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ public interface MekEnergy {
long output(long power, Actionable mode, Direction side);

interface Factory {

MekEnergy create(ServerLevel level, BlockPos pos);

}
Expand Down