diff --git a/src/main/java/ninety/megacells/init/InitCellModels.java b/src/main/java/ninety/megacells/init/client/InitCellModels.java similarity index 97% rename from src/main/java/ninety/megacells/init/InitCellModels.java rename to src/main/java/ninety/megacells/init/client/InitCellModels.java index 41cbadc7..942aaf6d 100644 --- a/src/main/java/ninety/megacells/init/InitCellModels.java +++ b/src/main/java/ninety/megacells/init/client/InitCellModels.java @@ -1,4 +1,4 @@ -package ninety.megacells.init; +package ninety.megacells.init.client; import java.util.stream.Stream; diff --git a/src/main/java/ninety/megacells/init/client/InitItemColors.java b/src/main/java/ninety/megacells/init/client/InitItemColors.java index 2c4d84c6..9e27ea03 100644 --- a/src/main/java/ninety/megacells/init/client/InitItemColors.java +++ b/src/main/java/ninety/megacells/init/client/InitItemColors.java @@ -6,6 +6,7 @@ import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext; import ninety.megacells.integration.appmek.AppMekCellType; +import ninety.megacells.item.MEGABulkCell; import ninety.megacells.item.MEGACellType; import ninety.megacells.item.MEGAItems; import ninety.megacells.item.MEGAPortableCell; @@ -24,7 +25,7 @@ private static void initItemColors(ColorHandlerEvent.Item event) { AppMekCellType.CHEMICAL.getCells().stream()).flatMap(s -> s).toList()) { event.getItemColors().register(MEGAStorageCell::getColor, cell); } - event.getItemColors().register(MEGAStorageCell::getColor, MEGAItems.BULK_ITEM_CELL.asItem()); + event.getItemColors().register(MEGABulkCell::getColor, MEGAItems.BULK_ITEM_CELL.asItem()); for (var cell : Stream.of( MEGACellType.ITEM.getPortableCells().stream(), diff --git a/src/main/java/ninety/megacells/item/MEGABulkCell.java b/src/main/java/ninety/megacells/item/MEGABulkCell.java index 450cada6..bdc9acf5 100644 --- a/src/main/java/ninety/megacells/item/MEGABulkCell.java +++ b/src/main/java/ninety/megacells/item/MEGABulkCell.java @@ -15,8 +15,10 @@ import appeng.api.storage.cells.IBasicCellItem; import appeng.api.upgrades.IUpgradeInventory; import appeng.api.upgrades.UpgradeInventories; +import appeng.core.localization.Tooltips; import appeng.items.AEBaseItem; import appeng.items.contents.CellConfig; +import appeng.me.cells.BasicCellHandler; import appeng.util.ConfigInventory; public class MEGABulkCell extends AEBaseItem implements IBasicCellItem { @@ -26,8 +28,22 @@ public MEGABulkCell(Properties properties) { @OnlyIn(Dist.CLIENT) @Override - public void appendHoverText(ItemStack stack, Level level, List lines, TooltipFlag advancedTooltips) { - addCellInformationToTooltip(stack, lines); + public void appendHoverText(ItemStack is, Level level, List lines, TooltipFlag advancedTooltips) { + var handler = BasicCellHandler.INSTANCE.getCellInventory(is, null); + if (handler == null) { + return; + } + + double used = handler.getUsedBytes(); + lines.add(used == 0 ? Tooltips.of("Empty") + : Tooltips.of(Tooltips.of("Capacity Used: "), + Tooltips.ofPercent(used / (double) Integer.MAX_VALUE, false))); + + var containedType = handler.getAvailableStacks().getFirstKey(); + if (containedType != null) { + var item = containedType.wrapForDisplayOrFilter(); + lines.add(Tooltips.of(Tooltips.of("Contains: "), Tooltips.of(item.getHoverName()))); + } } @Override @@ -36,17 +52,17 @@ public AEKeyType getKeyType() { } @Override - public int getBytes(ItemStack cellItem) { + public int getBytes(ItemStack is) { return Integer.MAX_VALUE; } @Override - public int getBytesPerType(ItemStack cellItem) { + public int getBytesPerType(ItemStack is) { return 1; } @Override - public int getTotalTypes(ItemStack cellItem) { + public int getTotalTypes(ItemStack is) { return 1; } @@ -76,5 +92,31 @@ public FuzzyMode getFuzzyMode(ItemStack is) { } @Override - public void setFuzzyMode(ItemStack is, FuzzyMode fzMode) {} + public void setFuzzyMode(ItemStack is, FuzzyMode fzMode) { + } + + public static int getColor(ItemStack is, int tintIndex) { + if (tintIndex == 1) { + // Determine LED color + + var handler = BasicCellHandler.INSTANCE.getCellInventory(is, null); + if (handler == null) { + return 0xFFFFFF; + } + + double used = handler.getUsedBytes(); + + if (used == 0) { + return 0xFFFFFF; + } else { + double p = 1 - used / (double) Integer.MAX_VALUE; + int r = (int) (255d * (Math.max(0, Math.min(2 - 2 * p, 1)))); + int g = (int) (255d * (Math.max(0, Math.min(2 * p, 1)))); + return 0xFF000000 + (r << 16) + (g << 8); + } + } else { + // White + return 0xFFFFFF; + } + } }