Skip to content

Commit

Permalink
Option to restrict fluid cell (#263)
Browse files Browse the repository at this point in the history
Co-authored-by: Martin Robertz <[email protected]>
Co-authored-by: Maya <[email protected]>
  • Loading branch information
3 people authored Jan 25, 2025
1 parent 3ff5324 commit 0908e90
Show file tree
Hide file tree
Showing 4 changed files with 95 additions and 17 deletions.
14 changes: 7 additions & 7 deletions dependencies.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -34,22 +34,22 @@
* For more details, see https://docs.gradle.org/8.0.1/userguide/java_library_plugin.html#sec:java_library_configurations_graph
*/
dependencies {
api('com.github.GTNewHorizons:NotEnoughItems:2.7.25-GTNH:dev')
api('com.github.GTNewHorizons:Applied-Energistics-2-Unofficial:rv3-beta-527-GTNH:dev')
api('com.github.GTNewHorizons:NotEnoughItems:2.7.27-GTNH:dev')
api('com.github.GTNewHorizons:Applied-Energistics-2-Unofficial:rv3-beta-532-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.3:dev")
api("com.github.GTNewHorizons:GTNHLib:0.6.5:dev")

implementation("com.github.GTNewHorizons:WirelessCraftingTerminal:1.11.7:dev") {
exclude group: 'com.github.GTNewHorizons', module: 'Applied-Energistics-2-Unofficial'
}

compileOnly("com.github.GTNewHorizons:GTNHLib:0.6.3:dev") { transitive = false }
compileOnly("com.github.GTNewHorizons:GTNHLib:0.6.5:dev") { transitive = false }
compileOnly('com.github.GTNewHorizons:Baubles-Expanded:2.0.3:dev')
compileOnly('com.github.GTNewHorizons:ExtraCells2:2.5.35:dev') { transitive = false }
compileOnly('com.github.GTNewHorizons:ForestryMC:4.10.1:dev')
compileOnly('com.github.GTNewHorizons:EnderIO:2.9.2:dev')
compileOnly('com.github.GTNewHorizons:GT5-Unofficial:5.09.51.93:dev') {
compileOnly('com.github.GTNewHorizons:GT5-Unofficial:5.09.51.97:dev') {
exclude group: 'com.github.GTNewHorizons', module: 'AE2FluidCraft-Rework'
exclude group: 'com.github.GTNewHorizons', module: 'Applied-Energistics-2-Unofficial'
}
Expand All @@ -58,8 +58,8 @@ dependencies {
compileOnly('com.gregoriust.gregtech:gregtech_1.7.10:6.14.23:dev') { transitive = false }
compileOnly('com.github.GTNewHorizons:OpenComputers:1.11.4-GTNH:dev') { transitive = false }
compileOnly('com.github.GTNewHorizons:ThaumicEnergistics:1.7.5-GTNH:dev') { transitive = false }
compileOnly("com.github.GTNewHorizons:Hodgepodge:2.6.20:dev") { transitive = false }
compileOnly("com.github.GTNewHorizons:Hodgepodge:2.6.22:dev") { transitive = false }

runtimeOnlyNonPublishable("com.github.GTNewHorizons:DuraDisplay:1.3.4:dev")
runtimeOnlyNonPublishable("com.github.GTNewHorizons:GTNHLib:0.6.3:dev")
runtimeOnlyNonPublishable("com.github.GTNewHorizons:GTNHLib:0.6.5:dev")
}
50 changes: 43 additions & 7 deletions src/main/java/com/glodblock/github/common/item/FCBaseItemCell.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.glodblock.github.common.item;

import java.text.NumberFormat;
import java.util.Arrays;
import java.util.EnumSet;
import java.util.List;

Expand All @@ -16,8 +17,8 @@

import com.glodblock.github.api.FluidCraftAPI;
import com.glodblock.github.common.storage.CellType;
import com.glodblock.github.common.storage.FluidCellInventory;
import com.glodblock.github.common.storage.FluidCellInventoryHandler;
import com.glodblock.github.common.storage.IFluidCellInventory;
import com.glodblock.github.common.storage.IStorageFluidCell;
import com.glodblock.github.loader.ItemAndBlockHolder;
import com.glodblock.github.util.NameConst;
Expand All @@ -33,6 +34,7 @@
import appeng.api.storage.data.IItemList;
import appeng.core.features.AEFeature;
import appeng.core.localization.GuiText;
import appeng.helpers.ICellRestriction;
import appeng.items.AEBaseItem;
import appeng.items.contents.CellConfig;
import appeng.items.contents.CellUpgrades;
Expand All @@ -41,7 +43,7 @@
import appeng.util.Platform;
import appeng.util.ReadableNumberConverter;

public abstract class FCBaseItemCell extends AEBaseItem implements IStorageFluidCell {
public abstract class FCBaseItemCell extends AEBaseItem implements IStorageFluidCell, ICellRestriction {

protected CellType component;
protected long totalBytes;
Expand Down Expand Up @@ -92,12 +94,12 @@ public boolean isBlackListed(ItemStack cellItem, IAEFluidStack requestedAddition

@Override
public void addCheckedInformation(final ItemStack stack, final EntityPlayer player, final List<String> lines,
final boolean displayMoreInfo) {
final boolean displayMoreInfo) {
final IMEInventoryHandler<?> inventory = AEApi.instance().registries().cell()
.getCellInventory(stack, null, StorageChannel.FLUIDS);
.getCellInventory(stack, null, StorageChannel.FLUIDS);

if (inventory instanceof final FluidCellInventoryHandler handler) {
final IFluidCellInventory cellInventory = handler.getCellInv();
final FluidCellInventory cellInventory = (FluidCellInventory) handler.getCellInv();

if (cellInventory != null) {
lines.add(
Expand All @@ -118,7 +120,7 @@ public void addCheckedInformation(final ItemStack stack, final EntityPlayer play
+ GuiText.Of.getLocal()
+ " "
+ EnumChatFormatting.DARK_GREEN
+ cellInventory.getTotalFluidTypes()
+ cellInventory.getMaxFluidTypes()
+ " "
+ EnumChatFormatting.GRAY
+ GuiText.Types.getLocal());
Expand All @@ -144,7 +146,7 @@ public void addCheckedInformation(final ItemStack stack, final EntityPlayer play

if (handler.isPreformatted()) {
final String list = (handler.getIncludeExcludeMode() == IncludeExclude.WHITELIST ? GuiText.Included
: GuiText.Excluded).getLocal();
: GuiText.Excluded).getLocal();
lines.add(GuiText.Partitioned.getLocal() + " - " + list + ' ' + GuiText.Precise.getLocal());

if (GuiScreen.isShiftKeyDown()) {
Expand All @@ -159,6 +161,17 @@ public void addCheckedInformation(final ItemStack stack, final EntityPlayer play
lines.add(GuiText.Sticky.getLocal());
}
}
List<Object> restricted = handler.getRestricted();
if (restricted != null && ((long) restricted.get(0) != 0 || (byte) restricted.get(1) != 0)) {
lines.add(GuiText.Restricted.getLocal());
if (GuiScreen.isShiftKeyDown()) {
NumberFormat nf = NumberFormat.getNumberInstance();
if ((long) restricted.get(0) != 0)
lines.add(GuiText.MaxFluid.getLocal() + " " + nf.format((long) restricted.get(0)) + " mB");
if ((byte) restricted.get(1) != 0)
lines.add(GuiText.MaxTypes.getLocal() + " " + restricted.get(1));
}
}
}
}
}
Expand Down Expand Up @@ -213,6 +226,29 @@ public void setFuzzyMode(ItemStack is, FuzzyMode fzMode) {
Platform.openNbtData(is).setString("FuzzyMode", fzMode.name());
}

@Override
public String getCellData(ItemStack is) {
return totalBytes + ","
+ this.getTotalTypes(null)
+ ","
+ this.getBytesPerType(null)
+ ","
+ 256 * 8
+ ","
+ Platform.openNbtData(is).getByte("cellRestrictionTypes")
+ ","
+ Platform.openNbtData(is).getLong("cellRestrictionAmount")
+ ","
+ "fluid";
}

@Override
public void setCellRestriction(ItemStack is, String newData) {
List<String> data = Arrays.asList(newData.split(",", 2));
Platform.openNbtData(is).setByte("cellRestrictionTypes", Byte.parseByte(data.get(0)));
Platform.openNbtData(is).setLong("cellRestrictionAmount", Long.parseLong(data.get(1)));
}

@SuppressWarnings("unchecked")
protected boolean disassembleDrive(final ItemStack stack, final World world, final EntityPlayer player) {
if (player.isSneaking()) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.glodblock.github.common.storage;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import javax.annotation.Nonnull;
Expand Down Expand Up @@ -50,6 +51,8 @@ public class FluidCellInventory implements IFluidCellInventory {
public static final int singleByteAmount = 256 * 8;
private boolean cardVoidOverflow = false;
private boolean cardDistribution = false;
private byte restrictionTypes = 0;
private long restrictionLong = 0;

public FluidCellInventory(final ItemStack o, final ISaveProvider container) throws AppEngException {
if (o == null) {
Expand Down Expand Up @@ -97,6 +100,8 @@ public FluidCellInventory(final ItemStack o, final ISaveProvider container) thro
this.tagCompound = Platform.openNbtData(o);
this.storedFluids = this.tagCompound.getShort(FLUID_TYPE_TAG);
this.storedFluidCount = this.tagCompound.getLong(FLUID_COUNT_TAG);
this.restrictionTypes = this.tagCompound.getByte("cellRestrictionTypes");
this.restrictionLong = this.tagCompound.getLong("cellRestrictionAmount");
this.cellFluids = null;
}

Expand Down Expand Up @@ -173,6 +178,11 @@ public long getUsedBytes() {

@Override
public long getTotalFluidTypes() {
if (restrictionTypes > 0) return restrictionTypes;
return this.cellType.getTotalTypes(this.cellItem);
}

public long getMaxFluidTypes() {
return this.cellType.getTotalTypes(this.cellItem);
}

Expand All @@ -195,6 +205,11 @@ public long getRemainingFluidTypes() {

@Override
public long getRemainingFluidCount() {
if (restrictionLong > 0) {
return Math.min(
restrictionLong - this.getStoredFluidCount(),
this.getFreeBytes() * singleByteAmount + this.getUnusedFluidCount());
}
final long remaining = this.getFreeBytes() * singleByteAmount + this.getUnusedFluidCount();
return remaining > 0 ? remaining : 0;
}
Expand All @@ -210,10 +225,22 @@ public long getRemainingFluidCountDist(IAEFluidStack l) {
}
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);
if (restrictionLong > 0) {
remaining = Math.min((restrictionLong / types) - l.getStackSize(), this.getUnusedFluidCount());
} else {
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;
if (restrictionLong > 0) {
remaining = Math.min(
restrictionLong / types,
((this.getTotalBytes() / types) - this.getBytesPerType()) * singleByteAmount);
} else {
remaining = ((this.getTotalBytes() / types) - this.getBytesPerType()) * singleByteAmount;
}
}
return remaining > 0 ? remaining : 0;
}
Expand Down Expand Up @@ -467,4 +494,8 @@ public IInventory getUpgradesInventory() {
public StorageChannel getChannel() {
return StorageChannel.FLUIDS;
}

public List<Object> getRestriction() {
return Arrays.asList(restrictionLong, restrictionTypes);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.glodblock.github.common.storage;

import java.util.List;

import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import net.minecraftforge.fluids.FluidStack;
Expand Down Expand Up @@ -148,4 +150,13 @@ public int getCellStatus() {
public TYPE getCellType() {
return TYPE.FLUID;
}

public List<Object> getRestricted() {
IFluidCellInventory cellInventory = this.getCellInv();
if (cellInventory instanceof FluidCellInventory ci) {
return ci.getRestriction();

}
return null;
}
}

0 comments on commit 0908e90

Please sign in to comment.