Skip to content
This repository has been archived by the owner on May 25, 2024. It is now read-only.

Commit

Permalink
fix bunch of yottank issues (#94)
Browse files Browse the repository at this point in the history
* yot tank/hatch fix

* dep
  • Loading branch information
GlodBlock authored Oct 17, 2022
1 parent 153f6ff commit 8ceb408
Show file tree
Hide file tree
Showing 3 changed files with 112 additions and 40 deletions.
4 changes: 2 additions & 2 deletions dependencies.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ dependencies {
compile('net.industrial-craft:industrialcraft-2:2.2.828-experimental:dev')

compileOnly('com.github.GTNewHorizons:EnderCore:0.2.6:dev') {transitive = false}
compileOnly('com.github.GTNewHorizons:Applied-Energistics-2-Unofficial:rv3-beta-97-GTNH:dev') {transitive = false}
compileOnly('com.github.GTNewHorizons:Applied-Energistics-2-Unofficial:rv3-beta-97-GTNH:dev') {transitive = false}
compileOnly('com.github.GTNewHorizons:GTplusplus:1.7.76:dev') {transitive = false}
compileOnly('com.github.GTNewHorizons:AppleCore:3.1.9:dev') {transitive = false}
compileOnly('com.github.GTNewHorizons:ForestryMC:4.4.12:dev') {transitive = false}
compileOnly('com.github.GTNewHorizons:Railcraft:9.13.9:dev') {transitive = false}
compileOnly('com.github.GTNewHorizons:EnderIO:2.3.1.43:dev') {transitive = false}
compileOnly('com.github.GTNewHorizons:ExtraCells2:2.5.19:dev') {transitive = false}
compileOnly('com.github.GTNewHorizons:ExtraCells2:2.5.19:dev') {transitive = false}
compileOnly('com.github.GTNewHorizons:BuildCraft:7.1.27:dev') {transitive = false}
compileOnly('com.github.GTNewHorizons:ThaumicEnergistics:1.3.19-GTNH:dev') {transitive = false}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@
import appeng.api.networking.security.BaseActionSource;
import appeng.api.networking.security.IActionHost;
import appeng.api.networking.storage.IStorageGrid;
import appeng.api.storage.*;
import appeng.api.storage.ICellContainer;
import appeng.api.storage.IMEInventory;
import appeng.api.storage.IMEInventoryHandler;
import appeng.api.storage.StorageChannel;
import appeng.api.storage.data.IAEFluidStack;
import appeng.api.storage.data.IItemList;
import appeng.api.util.AECableType;
Expand Down Expand Up @@ -75,7 +78,9 @@ public class YOTTAHatch extends GT_MetaTileEntity_Hatch
private YottaFluidTank host;
private AENetworkProxy gridProxy = null;
private int priority;
private byte ticksSinceUpdate;
private byte tickRate = 20;
private String lastFluid = "";
private BigInteger lastAmt = BigInteger.ZERO;
private AccessRestriction readMode = AccessRestriction.READ_WRITE;
private final AccessRestriction[] AEModes = new AccessRestriction[] {
AccessRestriction.NO_ACCESS, AccessRestriction.READ, AccessRestriction.WRITE, AccessRestriction.READ_WRITE
Expand Down Expand Up @@ -181,21 +186,20 @@ public IItemList<IAEFluidStack> getAvailableItems(IItemList<IAEFluidStack> out)
if (host.mFluidName == null
|| host.mFluidName.equals("")
|| host.mStorageCurrent.compareTo(BigInteger.ZERO) <= 0) return out;
int ready;
if (host.mStorageCurrent.compareTo(BigInteger.valueOf(Integer.MAX_VALUE)) > 0) {
ready = Integer.MAX_VALUE;
} else ready = host.mStorageCurrent.intValue();
long ready;
if (host.mStorageCurrent.compareTo(BigInteger.valueOf(Long.MAX_VALUE)) > 0) {
ready = Long.MAX_VALUE;
} else ready = host.mStorageCurrent.longValue();
out.add(FluidUtil.createAEFluidStack(FluidRegistry.getFluid(host.mFluidName), ready));
return out;
}

@Override
@Optional.Method(modid = "appliedenergistics2")
public IAEFluidStack injectItems(IAEFluidStack input, Actionable type, BaseActionSource src) {
FluidStack rInput = input.getFluidStack();
int amt = fill(null, rInput, false);
if (amt == rInput.amount) {
if (type.equals(Actionable.MODULATE)) fill(null, rInput, true);
long amt = fill(null, input, false);
if (amt == input.getStackSize()) {
if (type.equals(Actionable.MODULATE)) fill(null, input, true);
return null;
}
return input;
Expand All @@ -204,10 +208,10 @@ public IAEFluidStack injectItems(IAEFluidStack input, Actionable type, BaseActio
@Override
@Optional.Method(modid = "appliedenergistics2")
public IAEFluidStack extractItems(IAEFluidStack request, Actionable mode, BaseActionSource src) {
FluidStack ready = drain(null, request.getFluidStack(), false);
IAEFluidStack ready = drain(null, request, false);
if (ready != null) {
if (mode.equals(Actionable.MODULATE)) drain(null, request.getFluidStack(), true);
return FluidUtil.createAEFluidStack(ready.getFluid(), ready.amount);
return ready;
} else return null;
}

Expand All @@ -225,25 +229,29 @@ public void onFirstTick(IGregTechTileEntity aBaseMetaTileEntity) {

@Override
public void onPostTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) {
ticksSinceUpdate++;
if (ticksSinceUpdate > 20) {
IGridNode node = getGridNode(null);
if (node != null) {
IGrid grid = node.getGrid();
if (grid != null) {
grid.postEvent(new MENetworkCellArrayUpdate());
IStorageGrid storageGrid = grid.getCache(IStorageGrid.class);
if (storageGrid == null) {
node.getGrid().postEvent(new MENetworkStorageEvent(null, StorageChannel.FLUIDS));
} else {
node.getGrid()
.postEvent(new MENetworkStorageEvent(
storageGrid.getFluidInventory(), StorageChannel.FLUIDS));
if (shouldTick(aTick)) {
if (isChanged()) {
IGridNode node = getGridNode(null);
if (node != null) {
IGrid grid = node.getGrid();
if (grid != null) {
grid.postEvent(new MENetworkCellArrayUpdate());
IStorageGrid storageGrid = grid.getCache(IStorageGrid.class);
if (storageGrid == null) {
node.getGrid().postEvent(new MENetworkStorageEvent(null, StorageChannel.FLUIDS));
} else {
node.getGrid()
.postEvent(new MENetworkStorageEvent(
storageGrid.getFluidInventory(), StorageChannel.FLUIDS));
}
node.getGrid().postEvent(new MENetworkCellArrayUpdate());
}
node.getGrid().postEvent(new MENetworkCellArrayUpdate());
}
faster();
update();
} else {
slower();
}
ticksSinceUpdate = 0;
}
super.onPostTick(aBaseMetaTileEntity, aTick);
}
Expand Down Expand Up @@ -279,6 +287,27 @@ public int fill(ForgeDirection from, FluidStack resource, boolean doFill) {
return 0;
}

public long fill(ForgeDirection from, IAEFluidStack resource, boolean doFill) {
if (host == null
|| host.getBaseMetaTileEntity() == null
|| !host.getBaseMetaTileEntity().isActive()) return 0;
if (host.mFluidName == null
|| host.mFluidName.equals("")
|| host.mFluidName.equals(resource.getFluid().getName())) {
host.mFluidName = resource.getFluid().getName();
if (host.mStorage.subtract(host.mStorageCurrent).compareTo(BigInteger.valueOf(resource.getStackSize()))
>= 0) {
if (doFill) host.addFluid(resource.getStackSize());
return resource.getStackSize();
} else {
long added = host.mStorage.subtract(host.mStorageCurrent).longValue();
if (doFill) host.addFluid(added);
return added;
}
}
return 0;
}

@Override
public FluidStack drain(ForgeDirection from, FluidStack resource, boolean doDrain) {
if (host == null
Expand All @@ -298,6 +327,26 @@ public FluidStack drain(ForgeDirection from, FluidStack resource, boolean doDrai
return new FluidStack(resource.getFluid(), ready);
}

public IAEFluidStack drain(ForgeDirection from, IAEFluidStack resource, boolean doDrain) {
if (host == null
|| host.getBaseMetaTileEntity() == null
|| !host.getBaseMetaTileEntity().isActive()) return null;
if (host.mFluidName == null
|| host.mFluidName.equals("")
|| !host.mFluidName.equals(resource.getFluid().getName())) return null;
long ready;
if (host.mStorageCurrent.compareTo(BigInteger.valueOf(Long.MAX_VALUE)) > 0) {
ready = Long.MAX_VALUE;
} else ready = host.mStorageCurrent.longValue();
ready = Math.min(ready, resource.getStackSize());
if (doDrain) {
host.reduceFluid(ready);
}
IAEFluidStack copy = resource.copy();
copy.setStackSize(ready);
return copy;
}

@Override
public FluidStack drain(ForgeDirection from, int maxDrain, boolean doDrain) {
if (host == null
Expand Down Expand Up @@ -416,4 +465,32 @@ public void blinkCell(int slot) {}
public void saveChanges(IMEInventory cellInventory) {
// This is handled by host itself.
}

private boolean isChanged() {
if (this.host == null) return false;
return !this.lastAmt.equals(this.host.mStorageCurrent) || !this.lastFluid.equals(this.host.mFluidName);
}

private void update() {
if (this.host == null) return;
this.lastAmt = this.host.mStorageCurrent;
this.lastFluid = this.host.mFluidName;
}

private void faster() {
if (this.tickRate > 15) {
this.tickRate -= 5;
}
}

private void slower() {
if (this.tickRate < 100) {
this.tickRate += 5;
}
}

private boolean shouldTick(long tick) {
if (this.host == null) return false;
return tick % this.tickRate == 0;
}
}
15 changes: 5 additions & 10 deletions src/main/java/goodgenerator/blocks/tileEntity/YottaFluidTank.java
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ public boolean checkRecipe_EM(ItemStack aStack) {
return true;
}

public boolean reduceFluid(int amount) {
public boolean reduceFluid(long amount) {
BigInteger tmp = new BigInteger(amount + "");
if (mStorageCurrent.compareTo(tmp) < 0) {
return false;
Expand All @@ -128,7 +128,7 @@ public boolean reduceFluid(int amount) {
}
}

public boolean addFluid(int amount) {
public boolean addFluid(long amount) {
BigInteger tmp = new BigInteger(amount + "");
if (mStorage.subtract(mStorageCurrent).compareTo(tmp) < 0) {
return false;
Expand All @@ -138,16 +138,11 @@ public boolean addFluid(int amount) {
}
}

private int calGlassTier(int meta) {
if (meta >= 1 && meta <= 6) return meta; // returns correct meta for Tiers 1-6, 7-12 is colour variations of HV
if (meta >= 7 && meta <= 12) return 1; // For all the HV Glass colour variations
return meta; // returns the rest
}

@Override
public boolean checkMachine_EM(IGregTechTileEntity aBaseMetaTileEntity, ItemStack aStack) {
mStorage = BigInteger.ZERO;
glassMeta = 0;
maxCell = 0;
mYottaHatch.clear();
if (!structureCheck_EM(YOTTANK_BOTTOM, 2, 0, 0)) return false;
int cnt = 0;
Expand All @@ -156,8 +151,8 @@ public boolean checkMachine_EM(IGregTechTileEntity aBaseMetaTileEntity, ItemStac
}
if (cnt > 15 || cnt < 1) return false;
if (!structureCheck_EM(YOTTANK_TOP, 2, cnt + 2, 0)) return false;
// maxCell+1 = Tier of highest Cell. maxCell itself just return Tier-1
if (mMaintenanceHatches.size() == 1 && maxCell + 1 <= calGlassTier(glassMeta)) {
// maxCell+1 = Tier of highest Cell. glassMeta is the glass voltage tier
if (mMaintenanceHatches.size() == 1 && maxCell + 3 <= glassMeta) {
if (mStorage.compareTo(mStorageCurrent) < 0) mStorageCurrent = mStorage;
if (FluidRegistry.getFluidStack(mFluidName, 1) == null) {
mStorageCurrent = BigInteger.ZERO;
Expand Down

0 comments on commit 8ceb408

Please sign in to comment.