Skip to content

Commit

Permalink
Add Support Void and Distribution card for cells and increase card li…
Browse files Browse the repository at this point in the history
…mit for cells (#262)
  • Loading branch information
lordIcocain authored Jan 17, 2025
1 parent d184c30 commit 31a5dec
Show file tree
Hide file tree
Showing 5 changed files with 89 additions and 6 deletions.
2 changes: 1 addition & 1 deletion dependencies.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
*/
dependencies {
api('com.github.GTNewHorizons:NotEnoughItems:2.7.18-GTNH:dev')
api('com.github.GTNewHorizons:Applied-Energistics-2-Unofficial:rv3-beta-521-GTNH:dev')
api('com.github.GTNewHorizons:Applied-Energistics-2-Unofficial:rv3-beta-523-GTNH:dev')
api('curse.maven:cofh-core-69162:2388751')
api('com.github.GTNewHorizons:waila:1.8.2:dev')
api("com.github.GTNewHorizons:GTNHLib:0.6.1:dev")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ public boolean isEditable(ItemStack is) {

@Override
public IInventory getUpgradesInventory(ItemStack is) {
return new CellUpgrades(is, 2);
return new CellUpgrades(is, 5);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@

import appeng.api.AEApi;
import appeng.api.config.Actionable;
import appeng.api.config.Upgrades;
import appeng.api.exceptions.AppEngException;
import appeng.api.implementations.items.IUpgradeModule;
import appeng.api.networking.security.BaseActionSource;
import appeng.api.storage.IMEInventoryHandler;
import appeng.api.storage.ISaveProvider;
Expand All @@ -46,6 +48,8 @@ public class FluidCellInventory implements IFluidCellInventory {
protected IItemList<IAEFluidStack> cellFluids;
protected final NBTTagCompound tagCompound;
public static final int singleByteAmount = 256 * 8;
private boolean cardVoidOverflow = false;
private boolean cardDistribution = false;

public FluidCellInventory(final ItemStack o, final ISaveProvider container) throws AppEngException {
if (o == null) {
Expand Down Expand Up @@ -74,6 +78,21 @@ public FluidCellInventory(final ItemStack o, final ISaveProvider container) thro
}
}

final IInventory upgrades = this.getUpgradesInventory();
for (int x = 0; x < upgrades.getSizeInventory(); x++) {
final ItemStack is = upgrades.getStackInSlot(x);
if (is != null && is.getItem() instanceof IUpgradeModule) {
final Upgrades u = ((IUpgradeModule) is.getItem()).getType(is);
if (u != null) {
switch (u) {
case VOID_OVERFLOW -> cardVoidOverflow = true;
case DISTRIBUTION -> cardDistribution = true;
default -> {}
}
}
}
}

this.container = container;
this.tagCompound = Platform.openNbtData(o);
this.storedFluids = this.tagCompound.getShort(FLUID_TYPE_TAG);
Expand Down Expand Up @@ -180,6 +199,25 @@ public long getRemainingFluidCount() {
return remaining > 0 ? remaining : 0;
}

@Override
public long getRemainingFluidCountDist(IAEFluidStack l) {
long remaining;
long types = 0;
for (int i = 0; i < this.getTotalFluidTypes(); i++) {
if (this.getConfigInventory().getStackInSlot(i) != null) {
types++;
}
}
if (types == 0) types = this.getTotalFluidTypes();
if (l != null) {
remaining = (((this.getTotalBytes() / types) - (int) Math.ceil((double) l.getStackSize() / singleByteAmount)
- getBytesPerType()) * singleByteAmount) + (singleByteAmount - l.getStackSize() % singleByteAmount);
} else {
remaining = ((this.getTotalBytes() / types) - this.getBytesPerType()) * singleByteAmount;
}
return remaining > 0 ? remaining : 0;
}

@Override
public int getUnusedFluidCount() {
final int div = (int) (this.getStoredFluidCount() % singleByteAmount);
Expand Down Expand Up @@ -293,9 +331,17 @@ public IAEFluidStack injectItems(IAEFluidStack input, Actionable mode, BaseActio
final IAEFluidStack l = this.getCellFluids().findPrecise(input);

if (l != null) {
final long remainingFluidSlots = this.getRemainingFluidCount();
long remainingFluidSlots;
if (cardDistribution) {
remainingFluidSlots = this.getRemainingFluidCountDist(l);
} else {
remainingFluidSlots = this.getRemainingFluidCount();
}

if (remainingFluidSlots < 0) {
if (remainingFluidSlots <= 0) {
if (cardVoidOverflow) {
return null;
}
return input;
}

Expand All @@ -320,8 +366,13 @@ public IAEFluidStack injectItems(IAEFluidStack input, Actionable mode, BaseActio

if (this.canHoldNewFluid()) // room for new type, and for at least one item!
{
final long remainingFluidCount = this.getRemainingFluidCount()
- ((long) this.getBytesPerType() * singleByteAmount);
long remainingFluidCount;
if (cardDistribution) {
remainingFluidCount = this.getRemainingFluidCountDist(null);
} else {
remainingFluidCount = this.getRemainingFluidCount()
- ((long) this.getBytesPerType() * singleByteAmount);
}

if (remainingFluidCount > 0) {
if (input.getStackSize() > remainingFluidCount) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@ public interface IFluidCellInventory extends IMEInventory<IAEFluidStack> {
*/
long getRemainingFluidCount();

/**
* @return how many more fluids can be stored with Distribution card.
*/
long getRemainingFluidCountDist(IAEFluidStack l);

/**
* @return how many fluid types remain.
*/
Expand Down
27 changes: 27 additions & 0 deletions src/main/java/com/glodblock/github/proxy/CommonProxy.java
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,15 @@ public void postInit(FMLPostInitializationEvent event) {
Upgrades.STICKY.registerItem(new ItemStack(ItemAndBlockHolder.CELL4096K), 1);
Upgrades.STICKY.registerItem(new ItemStack(ItemAndBlockHolder.CELL16384K), 1);

Upgrades.VOID_OVERFLOW.registerItem(new ItemStack(ItemAndBlockHolder.CELL1K), 1);
Upgrades.VOID_OVERFLOW.registerItem(new ItemStack(ItemAndBlockHolder.CELL4K), 1);
Upgrades.VOID_OVERFLOW.registerItem(new ItemStack(ItemAndBlockHolder.CELL16K), 1);
Upgrades.VOID_OVERFLOW.registerItem(new ItemStack(ItemAndBlockHolder.CELL64K), 1);
Upgrades.VOID_OVERFLOW.registerItem(new ItemStack(ItemAndBlockHolder.CELL256K), 1);
Upgrades.VOID_OVERFLOW.registerItem(new ItemStack(ItemAndBlockHolder.CELL1024K), 1);
Upgrades.VOID_OVERFLOW.registerItem(new ItemStack(ItemAndBlockHolder.CELL4096K), 1);
Upgrades.VOID_OVERFLOW.registerItem(new ItemStack(ItemAndBlockHolder.CELL16384K), 1);

Upgrades.STICKY.registerItem(new ItemStack(ItemAndBlockHolder.CELL1KM), 1);
Upgrades.STICKY.registerItem(new ItemStack(ItemAndBlockHolder.CELL4KM), 1);
Upgrades.STICKY.registerItem(new ItemStack(ItemAndBlockHolder.CELL16KM), 1);
Expand All @@ -85,6 +94,24 @@ public void postInit(FMLPostInitializationEvent event) {
Upgrades.STICKY.registerItem(new ItemStack(ItemAndBlockHolder.CELL4096KM), 1);
Upgrades.STICKY.registerItem(new ItemStack(ItemAndBlockHolder.CELL16384KM), 1);

Upgrades.VOID_OVERFLOW.registerItem(new ItemStack(ItemAndBlockHolder.CELL1KM), 1);
Upgrades.VOID_OVERFLOW.registerItem(new ItemStack(ItemAndBlockHolder.CELL4KM), 1);
Upgrades.VOID_OVERFLOW.registerItem(new ItemStack(ItemAndBlockHolder.CELL16KM), 1);
Upgrades.VOID_OVERFLOW.registerItem(new ItemStack(ItemAndBlockHolder.CELL64KM), 1);
Upgrades.VOID_OVERFLOW.registerItem(new ItemStack(ItemAndBlockHolder.CELL256KM), 1);
Upgrades.VOID_OVERFLOW.registerItem(new ItemStack(ItemAndBlockHolder.CELL1024KM), 1);
Upgrades.VOID_OVERFLOW.registerItem(new ItemStack(ItemAndBlockHolder.CELL4096KM), 1);
Upgrades.VOID_OVERFLOW.registerItem(new ItemStack(ItemAndBlockHolder.CELL16384KM), 1);

Upgrades.DISTRIBUTION.registerItem(new ItemStack(ItemAndBlockHolder.CELL1KM), 1);
Upgrades.DISTRIBUTION.registerItem(new ItemStack(ItemAndBlockHolder.CELL4KM), 1);
Upgrades.DISTRIBUTION.registerItem(new ItemStack(ItemAndBlockHolder.CELL16KM), 1);
Upgrades.DISTRIBUTION.registerItem(new ItemStack(ItemAndBlockHolder.CELL64KM), 1);
Upgrades.DISTRIBUTION.registerItem(new ItemStack(ItemAndBlockHolder.CELL256KM), 1);
Upgrades.DISTRIBUTION.registerItem(new ItemStack(ItemAndBlockHolder.CELL1024KM), 1);
Upgrades.DISTRIBUTION.registerItem(new ItemStack(ItemAndBlockHolder.CELL4096KM), 1);
Upgrades.DISTRIBUTION.registerItem(new ItemStack(ItemAndBlockHolder.CELL16384KM), 1);

Upgrades.FAKE_CRAFTING.registerItem(new ItemStack(ItemAndBlockHolder.FLUID_INTERFACE), 1);
Upgrades.FAKE_CRAFTING.registerItem(new ItemStack(ItemAndBlockHolder.INTERFACE), 1);
Upgrades.FAKE_CRAFTING.registerItem(new ItemStack(ItemAndBlockHolder.FLUID_INTERFACE_P2P), 1);
Expand Down

0 comments on commit 31a5dec

Please sign in to comment.