Skip to content

Commit

Permalink
Add contained item and upgrade tooltip to bulk cells
Browse files Browse the repository at this point in the history
  • Loading branch information
62832 committed Jul 24, 2023
1 parent b061409 commit 23624fc
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 4 deletions.
37 changes: 35 additions & 2 deletions common/src/main/java/gripe/_90/megacells/item/MEGABulkCell.java
Original file line number Diff line number Diff line change
@@ -1,29 +1,36 @@
package gripe._90.megacells.item;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.Optional;

import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import net.minecraft.ChatFormatting;
import net.minecraft.network.chat.Component;
import net.minecraft.world.inventory.tooltip.TooltipComponent;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.TooltipFlag;
import net.minecraft.world.level.Level;

import appeng.api.config.FuzzyMode;
import appeng.api.stacks.AEItemKey;
import appeng.api.stacks.GenericStack;
import appeng.api.storage.cells.ICellHandler;
import appeng.api.storage.cells.ICellWorkbenchItem;
import appeng.api.storage.cells.ISaveProvider;
import appeng.api.upgrades.IUpgradeInventory;
import appeng.api.upgrades.UpgradeInventories;
import appeng.core.AEConfig;
import appeng.core.localization.Tooltips;
import appeng.items.AEBaseItem;
import appeng.items.contents.CellConfig;
import appeng.items.storage.StorageCellTooltipComponent;
import appeng.util.ConfigInventory;

import gripe._90.megacells.definition.MEGAItems;
import gripe._90.megacells.definition.MEGATranslations;
import gripe._90.megacells.item.cell.BulkCellInventory;

Expand Down Expand Up @@ -73,12 +80,38 @@ public void appendHoverText(ItemStack is, Level level, @NotNull List<Component>
}
}

lines.add(Tooltips.of(MEGATranslations.Compression.text(inv.compressionEnabled
lines.add(Tooltips.of(MEGATranslations.Compression.text(inv.isCompressionEnabled()
? MEGATranslations.Enabled.text().withStyle(ChatFormatting.GREEN)
: MEGATranslations.Disabled.text().withStyle(ChatFormatting.RED))));
}
}

@NotNull
@Override
public Optional<TooltipComponent> getTooltipImage(ItemStack is) {
var inv = HANDLER.getCellInventory(is, null);

if (inv == null) {
return Optional.empty();
}

var upgrades = new ArrayList<ItemStack>();
if (AEConfig.instance().isTooltipShowCellUpgrades()) {
if (inv.isCompressionEnabled()) {
upgrades.add(MEGAItems.COMPRESSION_CARD.stack());
}
}

var content = new ArrayList<GenericStack>();
if (AEConfig.instance().isTooltipShowCellContent()) {
if (inv.getStoredItem() != null) {
content.add(new GenericStack(inv.getStoredItem(), inv.getStoredQuantity()));
}
}

return Optional.of(new StorageCellTooltipComponent(upgrades, content, false, true));
}

@Override
public IUpgradeInventory getUpgrades(ItemStack is) {
return UpgradeInventories.forItem(is, 1);
Expand All @@ -93,7 +126,7 @@ public FuzzyMode getFuzzyMode(ItemStack itemStack) {
public void setFuzzyMode(ItemStack itemStack, FuzzyMode fuzzyMode) {
}

public static class Handler implements ICellHandler {
private static class Handler implements ICellHandler {
private Handler() {
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public class BulkCellInventory implements StorageCell {
private BigInteger unitCount;
private AEItemKey highestCompressed;
private final long unitFactor;
public final boolean compressionEnabled;
private final boolean compressionEnabled;

private boolean isPersisted = true;

Expand Down Expand Up @@ -110,6 +110,10 @@ public AEItemKey getFilterItem() {
return filterItem;
}

public boolean isCompressionEnabled() {
return compressionEnabled;
}

@Override
public double getIdleDrain() {
return 10.0f;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ private StorageCell getCellByDriveSlot(DriveBlockEntity drive, int slot) throws
}

private Object2IntMap<AEItemKey> getChain(BulkCellInventory cell) {
if (cell.compressionEnabled) {
if (cell.isCompressionEnabled()) {
return CompressionService.INSTANCE.getChain(cell.getStoredItem()).map(c -> {
var keys = new ObjectArrayList<>(c.keySet());
Collections.reverse(keys);
Expand Down

0 comments on commit 23624fc

Please sign in to comment.