Skip to content

Commit

Permalink
Add Dense & Void Gas Cells (MekEng) (AE2-UEL#76)
Browse files Browse the repository at this point in the history
  • Loading branch information
NotMyWing authored and ChromaPIE committed Nov 18, 2024
1 parent 64ae6e0 commit b35632e
Show file tree
Hide file tree
Showing 34 changed files with 419 additions and 68 deletions.
6 changes: 6 additions & 0 deletions src/main/java/co/neeve/nae2/common/features/Features.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ public boolean isEnabled() {
}
},
DENSE_CELLS(EnumSet.allOf(DenseCellFeatures.class)),
DENSE_GAS_CELLS() {
@Override
public boolean isEnabled() {
return Platform.isModLoaded("mekeng") && super.isEnabled();
}
},
DENSE_CPU_COPROCESSORS("dense.coprocessor"),
DENSE_FLUID_CELLS(),
EXPOSER(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@
import org.jetbrains.annotations.Nullable;

public enum VoidCellFeatures implements ISubFeature {
CONDENSER_POWER("Enable Matter Condenser power", "void.condenser");
CONDENSER_POWER("Enable Matter Condenser power", "void.condenser"),
CONVERSION_RECIPES(
"""
Enable conversion recipes. Useful if you want to add custom recipes.
HOWEVER, disassembling the Cells will still pop out a Void Component and a Housing!
You might want to disable disassembling as a feature in the AE2 config, which Void Cells respect.""");

private final String description;
private final String mixins;
Expand All @@ -14,6 +19,10 @@ public enum VoidCellFeatures implements ISubFeature {
this.mixins = mixins;
}

VoidCellFeatures(String description) {
this(description, null);
}

public String getDescription() {
return this.description;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,12 @@
import appeng.api.storage.data.IItemList;
import appeng.client.render.StackSizeRenderer;
import appeng.fluids.client.render.FluidStackSizeRenderer;
import appeng.util.Platform;
import appeng.util.item.AEItemStack;
import co.neeve.nae2.Tags;
import com.github.bsideup.jabel.Desugar;
import com.google.common.collect.ImmutableList;
import com.mekeng.github.common.me.storage.IGasStorageChannel;
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
import mezz.jei.Internal;
Expand Down Expand Up @@ -81,6 +83,8 @@ private static String getStorageChannelUnits(IStorageChannel<?> storageChannel)
return "items";
} else if (storageChannel instanceof IFluidStorageChannel) {
return "buckets";
} else if (Platform.isModLoaded("mekeng") && storageChannel instanceof IGasStorageChannel) {
return "buckets";
} else {
return "units";
}
Expand Down Expand Up @@ -187,7 +191,8 @@ public void drawExtras(@NotNull Minecraft minecraft) {
var format = NumberFormat.getInstance();

var storedItemCount = this.cellInfo.cellInv.getStoredItemCount();
var transferFactor = this.cellInfo.channel().transferFactor();
var transferFactor = this.getTransferFactor();

var capacity = (this.cellInfo.cellInv.getRemainingItemCount() + storedItemCount) / transferFactor;
var byteLoss = this.cellInfo.cellInv.getBytesPerType() * this.cellInfo.cellInv.getStoredItemTypes();
var capacityLoss = byteLoss * this.cellInfo.channel.getUnitsPerByte() / transferFactor;
Expand All @@ -211,6 +216,16 @@ public void drawExtras(@NotNull Minecraft minecraft) {
}
}

private int getTransferFactor() {
final int transferFactor;
if (Platform.isModLoaded("mekeng") && this.cellInfo.channel instanceof IGasStorageChannel) {
transferFactor = 1000;
} else {
transferFactor = this.cellInfo.channel().transferFactor();
}
return transferFactor;
}

@Override
public @NotNull List<String> getTooltipStrings(int mouseX, int mouseY) {
if (this.cellInfo != null && mouseX > 0 && mouseY > 0 && mouseX < WIDTH && mouseY < TOTAL_HEIGHT - GRID_HEIGHT - 2) {
Expand Down Expand Up @@ -243,7 +258,7 @@ private <T> ITooltipCallback<T> getCallBack(CellInfo<? extends IAEStack<?>> cell
var unitName = I18n.format("nae2.jei.cellview." + getStorageChannelUnits(cellInfo.channel()));

tooltip.add(I18n.format("nae2.jei.cellview.hover.stored",
format.format(stackSize / (double) this.cellInfo.channel.transferFactor()), unitName));
format.format(stackSize / (double) this.getTransferFactor()), unitName));
tooltip.add(I18n.format("nae2.jei.cellview.used",
format.format(cellInfo.cellInv().getBytesPerType() + Math.ceil(stackSize / (double) cellInfo.channel().getUnitsPerByte()))));
}
Expand Down
25 changes: 25 additions & 0 deletions src/main/java/co/neeve/nae2/common/items/cells/DenseGasCell.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package co.neeve.nae2.common.items.cells;

import appeng.core.Api;
import co.neeve.nae2.common.registration.definitions.Materials;
import com.mekeng.github.common.me.data.IAEGasStack;
import com.mekeng.github.common.me.storage.IGasStorageChannel;
import net.minecraft.item.ItemStack;
import org.jetbrains.annotations.NotNull;

public class DenseGasCell extends DenseCell<IAEGasStack> {
public DenseGasCell(Materials.MaterialType whichCell, int kilobytes) {
super(whichCell, kilobytes);
}

@NotNull
@Override
public IGasStorageChannel getChannel() {
return Api.INSTANCE.storage().getStorageChannel(IGasStorageChannel.class);
}

@Override
public int getTotalTypes(@NotNull ItemStack cellItem) {
return 15;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,10 @@
import appeng.api.storage.ICellInventoryHandler;
import appeng.api.storage.ISaveProvider;
import appeng.api.storage.IStorageChannel;
import appeng.api.storage.channels.IFluidStorageChannel;
import appeng.api.storage.channels.IItemStorageChannel;
import appeng.api.storage.data.IAEStack;
import co.neeve.nae2.common.interfaces.IVoidingCellHandler;
import co.neeve.nae2.common.items.cells.vc.VoidCell;
import co.neeve.nae2.common.items.cells.vc.VoidCellInventory;
import co.neeve.nae2.common.items.cells.vc.VoidFluidCell;
import co.neeve.nae2.common.items.cells.vc.VoidItemCell;
import net.minecraft.item.ItemStack;

public final class VoidCellHandler implements IVoidingCellHandler {
Expand All @@ -26,11 +22,8 @@ public boolean isCell(ItemStack is) {
public <T extends IAEStack<T>> ICellInventoryHandler<T> getCellInventory(ItemStack itemStack,
ISaveProvider iSaveProvider,
IStorageChannel<T> iStorageChannel) {
return !itemStack.isEmpty()
&& (
(itemStack.getItem() instanceof VoidItemCell && iStorageChannel instanceof IItemStorageChannel)
|| (itemStack.getItem() instanceof VoidFluidCell && iStorageChannel instanceof IFluidStorageChannel)
) ? new VoidCellInventory<>(itemStack, iSaveProvider) : null;
return this.isCell(itemStack) && ((VoidCell<?>) itemStack.getItem()).getStorageChannel() == iStorageChannel
? new VoidCellInventory<>(itemStack, iSaveProvider) : null;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import net.minecraftforge.fml.relauncher.SideOnly;
import net.minecraftforge.items.IItemHandler;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.text.NumberFormat;
import java.util.List;
Expand All @@ -53,7 +54,7 @@ public CellUpgrades getUpgradesInventory(ItemStack is) {

@Override
public IItemHandler getConfigInventory(ItemStack is) {
return this.getCellInventory(is).getCellConfig();
return this.getCellConfig(is);
}

public VoidCellInventory<T> getCellInventory(ItemStack stack) {
Expand Down Expand Up @@ -208,4 +209,9 @@ protected IncludeExclude getIncludeExcludeMode(ItemStack itemStack) {
protected boolean isFuzzy(ItemStack itemStack) {
return this.getCellInventory(itemStack).isFuzzy();
}

public abstract CellConfig getCellConfig(ItemStack o);

@Nullable
public abstract T handleConfigStack(ItemStack stack);
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,8 @@
import appeng.api.storage.IStorageChannel;
import appeng.api.storage.data.IAEStack;
import appeng.api.storage.data.IItemList;
import appeng.fluids.helper.FluidCellConfig;
import appeng.fluids.items.FluidDummyItem;
import appeng.fluids.util.AEFluidStack;
import appeng.items.contents.CellConfig;
import appeng.util.Platform;
import appeng.util.item.AEItemStack;
import co.neeve.nae2.common.features.subfeatures.VoidCellFeatures;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
Expand All @@ -40,13 +36,12 @@ public VoidCellInventory(ItemStack o, ISaveProvider iSaveProvider) {
this.itemListCache = this.getChannel().createList();
this.saveProvider = iSaveProvider;

this.cellConfig = this.isFluid() ? new FluidCellConfig(o) : new CellConfig(o);
this.cellConfig = this.item.getCellConfig(o);
for (final var is : this.cellConfig) {
if (!is.isEmpty()) {
if (this.isFluid() && is.getItem() instanceof FluidDummyItem fdi) {
this.itemListCache.add((T) AEFluidStack.fromFluidStack(fdi.getFluidStack(is)));
} else if (!this.isFluid()) {
this.itemListCache.add((T) AEItemStack.fromItemStack(is));
var aeStack = this.item.handleConfigStack(is);
if (aeStack != null) {
this.itemListCache.add(aeStack);
}
}
}
Expand All @@ -70,10 +65,6 @@ public VoidCellInventory(ItemStack o, ISaveProvider iSaveProvider) {
}
}

public CellConfig getCellConfig() {
return this.cellConfig;
}

@Override
public T injectItems(T input, Actionable mode, IActionSource src) {
if (!this.isValidInput(input)) return input;
Expand Down Expand Up @@ -112,10 +103,6 @@ public IStorageChannel<T> getChannel() {
return this.channel;
}

private boolean isFluid() {
return this.itemStack.getItem() instanceof VoidFluidCell;
}

@Override
public AccessRestriction getAccess() {
return AccessRestriction.WRITE;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,31 @@
import appeng.api.storage.IStorageChannel;
import appeng.api.storage.channels.IFluidStorageChannel;
import appeng.api.storage.data.IAEFluidStack;
import appeng.fluids.helper.FluidCellConfig;
import appeng.fluids.items.FluidDummyItem;
import appeng.fluids.util.AEFluidStack;
import appeng.items.contents.CellConfig;
import net.minecraft.item.ItemStack;
import org.jetbrains.annotations.Nullable;

public class VoidFluidCell extends VoidCell<IAEFluidStack> {
@Override
public IStorageChannel<IAEFluidStack> getStorageChannel() {
return AEApi.instance().storage().getStorageChannel(IFluidStorageChannel.class);
}

@Override
public CellConfig getCellConfig(ItemStack o) {
return new FluidCellConfig(o);
}

@Override
@Nullable
public IAEFluidStack handleConfigStack(ItemStack stack) {
if (stack.getItem() instanceof FluidDummyItem fdi) {
return AEFluidStack.fromFluidStack(fdi.getFluidStack(stack));
}

return null;
}
}
34 changes: 34 additions & 0 deletions src/main/java/co/neeve/nae2/common/items/cells/vc/VoidGasCell.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package co.neeve.nae2.common.items.cells.vc;

import appeng.api.AEApi;
import appeng.api.storage.IStorageChannel;
import appeng.items.contents.CellConfig;
import com.mekeng.github.common.item.ItemDummyGas;
import com.mekeng.github.common.me.data.IAEGasStack;
import com.mekeng.github.common.me.data.impl.AEGasStack;
import com.mekeng.github.common.me.storage.IGasStorageChannel;
import com.mekeng.github.util.helpers.GasCellConfig;
import net.minecraft.item.ItemStack;

import javax.annotation.Nullable;

public class VoidGasCell extends VoidCell<IAEGasStack> {
@Override
public IStorageChannel<IAEGasStack> getStorageChannel() {
return AEApi.instance().storage().getStorageChannel(IGasStorageChannel.class);
}

@Override
public CellConfig getCellConfig(ItemStack o) {
return new GasCellConfig(o);
}

@Override
@Nullable
public IAEGasStack handleConfigStack(ItemStack stack) {
if (stack.getItem() instanceof ItemDummyGas gasItem) {
return AEGasStack.of(gasItem.getGasStack(stack));
}
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,23 @@
import appeng.api.storage.IStorageChannel;
import appeng.api.storage.channels.IItemStorageChannel;
import appeng.api.storage.data.IAEItemStack;
import appeng.items.contents.CellConfig;
import appeng.util.item.AEItemStack;
import net.minecraft.item.ItemStack;

public class VoidItemCell extends VoidCell<IAEItemStack> {
@Override
public IStorageChannel<IAEItemStack> getStorageChannel() {
return AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class);
}

@Override
public CellConfig getCellConfig(ItemStack o) {
return new CellConfig(o);
}

@Override
public IAEItemStack handleConfigStack(ItemStack stack) {
return AEItemStack.fromItemStack(stack);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

import appeng.api.AEApi;
import appeng.api.definitions.IItemDefinition;
import appeng.api.storage.IMEInventory;
import appeng.api.storage.channels.IItemStorageChannel;
import appeng.api.storage.data.IAEItemStack;
import appeng.api.storage.data.IAEStack;
import appeng.api.storage.data.IItemList;
import co.neeve.nae2.NAE2;
import co.neeve.nae2.common.items.cells.vc.VoidCell;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.InventoryCrafting;
import net.minecraft.item.ItemStack;
Expand Down Expand Up @@ -33,8 +33,6 @@ public DisassembleRecipe() {
this.cellMappings = new HashMap<>(6);
this.nonCellMappings = new HashMap<>(4);

this.cellMappings.put(items.storageCellVoid(), mats.cellPartVoid());
this.cellMappings.put(items.fluidStorageCellVoid(), mats.cellPartVoid());
this.cellMappings.put(items.storageCell256K(), mats.cellPart256K());
this.cellMappings.put(items.storageCell1024K(), mats.cellPart1024K());
this.cellMappings.put(items.storageCell4096K(), mats.cellPart4096K());
Expand All @@ -49,6 +47,21 @@ public DisassembleRecipe() {
this.nonCellMappings.put(blocks.storageCrafting4096K(), mats.cellPart4096K());
this.nonCellMappings.put(blocks.storageCrafting16384K(), mats.cellPart16384K());
}

@SuppressWarnings("unchecked")
private static <T extends IAEStack<T>> IItemList<T> getStorageList(final ItemStack stack) {
var item = (VoidCell<T>) stack.getItem();
var channel = item.getStorageChannel();

// make sure the storage cell is empty...
var cellInv = AEApi.instance()
.registries()
.cell()
.getCellInventory(stack, null, channel);

assert cellInv != null;
return cellInv.getAvailableItems(channel.createList());
}

@Override
public boolean matches(final @NotNull InventoryCrafting inv, final @NotNull World w) {
Expand All @@ -73,18 +86,9 @@ private ItemStack getOutput(final IInventory inventory) {
var maybeCellOutput = this.getCellOutput(stackInSlot);
if (maybeCellOutput.isPresent()) {
var storageCellStack = maybeCellOutput.get();
// make sure the storage cell stackInSlot empty...
final IMEInventory<IAEItemStack> cellInv = AEApi.instance()
.registries()
.cell()
.getCellInventory(stackInSlot, null,
AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class));
if (cellInv != null) {
final var list = cellInv
.getAvailableItems(AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class).createList());
if (!list.isEmpty()) {
return ItemStack.EMPTY;
}
var storageList = getStorageList(storageCellStack);
if (storageList.isEmpty()) {
return MISMATCHED_STACK;
}

output = storageCellStack;
Expand Down
Loading

0 comments on commit b35632e

Please sign in to comment.