aboutsummaryrefslogtreecommitdiff
path: root/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/gregtech/api/util/GT_ModHandler.java31
-rw-r--r--src/main/java/gregtech/common/tileentities/storage/GT_MetaTileEntity_Locker.java78
-rw-r--r--src/main/resources/assets/gregtech/lang/en_US.lang4
3 files changed, 113 insertions, 0 deletions
diff --git a/src/main/java/gregtech/api/util/GT_ModHandler.java b/src/main/java/gregtech/api/util/GT_ModHandler.java
index 68f1bd9b97..5201cc6876 100644
--- a/src/main/java/gregtech/api/util/GT_ModHandler.java
+++ b/src/main/java/gregtech/api/util/GT_ModHandler.java
@@ -22,6 +22,7 @@ import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Objects;
+import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;
@@ -63,6 +64,7 @@ import gregtech.api.enums.ToolDictNames;
import gregtech.api.interfaces.IDamagableItem;
import gregtech.api.interfaces.IItemContainer;
import gregtech.api.interfaces.internal.IGT_CraftingRecipe;
+import gregtech.api.items.GT_MetaBase_Item;
import gregtech.api.objects.GT_HashSet;
import gregtech.api.objects.GT_ItemStack;
import gregtech.api.objects.ItemData;
@@ -2328,6 +2330,35 @@ public class GT_ModHandler {
}
/**
+ * Returns the current charge and maximum charge of an ItemStack.
+ *
+ * @param aStack Any ItemStack.
+ * @return Optional.empty() if the stack is null or not an electric item, or an Optional containing a payload of an
+ * array containing [ current_charge, maximum_charge ] on success.
+ */
+ public static Optional<Long[]> getElectricItemCharge(ItemStack aStack) {
+ if (aStack == null || !isElectricItem(aStack)) {
+ return Optional.empty();
+ }
+
+ final Item item = aStack.getItem();
+
+ if (item instanceof final GT_MetaBase_Item metaBaseItem) {
+ final Long[] stats = metaBaseItem.getElectricStats(aStack);
+ if (stats != null && stats.length > 0) {
+ return Optional.of(new Long[] { metaBaseItem.getRealCharge(aStack), stats[0] });
+ }
+
+ } else if (item instanceof final IElectricItem ic2ElectricItem) {
+ return Optional.of(
+ new Long[] { (long) ic2.api.item.ElectricItem.manager.getCharge(aStack),
+ (long) ic2ElectricItem.getMaxCharge(aStack) });
+ }
+
+ return Optional.empty();
+ }
+
+ /**
* Allow item to be inserted into ic2 toolbox
*/
public static void registerBoxableItemToToolBox(ItemStack aStack) {
diff --git a/src/main/java/gregtech/common/tileentities/storage/GT_MetaTileEntity_Locker.java b/src/main/java/gregtech/common/tileentities/storage/GT_MetaTileEntity_Locker.java
index a36ed7fe40..abce9514de 100644
--- a/src/main/java/gregtech/common/tileentities/storage/GT_MetaTileEntity_Locker.java
+++ b/src/main/java/gregtech/common/tileentities/storage/GT_MetaTileEntity_Locker.java
@@ -5,9 +5,16 @@ import static gregtech.api.enums.Textures.BlockIcons.MACHINE_CASINGS;
import static gregtech.api.enums.Textures.BlockIcons.OVERLAYS_ENERGY_IN;
import static gregtech.api.enums.Textures.BlockIcons.OVERLAY_LOCKER;
+import java.util.List;
+
import net.minecraft.entity.player.EntityPlayer;
+import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
+import net.minecraft.tileentity.TileEntity;
+import net.minecraft.util.EnumChatFormatting;
+import net.minecraft.util.StatCollector;
+import net.minecraft.world.World;
import net.minecraftforge.common.util.ForgeDirection;
import gregtech.api.enums.SoundResource;
@@ -17,10 +24,14 @@ import gregtech.api.interfaces.tileentity.IGregTechTileEntity;
import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_TieredMachineBlock;
import gregtech.api.objects.GT_ItemStack;
import gregtech.api.render.TextureFactory;
+import gregtech.api.util.GT_ModHandler;
import gregtech.api.util.GT_Utility;
+import mcp.mobius.waila.api.IWailaConfigHandler;
+import mcp.mobius.waila.api.IWailaDataAccessor;
public class GT_MetaTileEntity_Locker extends GT_MetaTileEntity_TieredMachineBlock {
+ private static final String CHARGE_SLOT_WAILA_TAG = "charge_slot_";
public byte mType = 0;
public GT_MetaTileEntity_Locker(int aID, String aName, String aNameRegional, int aTier) {
@@ -202,4 +213,71 @@ public class GT_MetaTileEntity_Locker extends GT_MetaTileEntity_TieredMachineBlo
ItemStack aStack) {
return false;
}
+
+ @Override
+ public void getWailaNBTData(EntityPlayerMP player, TileEntity tile, NBTTagCompound tag, World world, int x, int y,
+ int z) {
+ super.getWailaNBTData(player, tile, tag, world, x, y, z);
+ for (int i = 0; i < 4; i++) {
+ final ItemStack itemStack = this.mInventory[3 - i];
+
+ if (itemStack != null) {
+ tag.setTag(CHARGE_SLOT_WAILA_TAG + i, itemStack.writeToNBT(new NBTTagCompound()));
+ }
+ }
+ }
+
+ @Override
+ public void getWailaBody(ItemStack itemStack, List<String> currentTip, IWailaDataAccessor accessor,
+ IWailaConfigHandler config) {
+ super.getWailaBody(itemStack, currentTip, accessor, config);
+
+ final NBTTagCompound tag = accessor.getNBTData();
+
+ for (int i = 0; i < 4; i++) {
+ final String index = GT_Utility.formatNumbers(i + 1);
+
+ if (tag.hasKey(CHARGE_SLOT_WAILA_TAG + i)) {
+ final ItemStack slotItem = ItemStack
+ .loadItemStackFromNBT(tag.getCompoundTag(CHARGE_SLOT_WAILA_TAG + i));
+ assert slotItem != null;
+
+ currentTip.add(
+ GT_ModHandler.getElectricItemCharge(slotItem)
+ .map(chargeInfo -> {
+ final float ratio = (float) chargeInfo[0] / (float) chargeInfo[1];
+ final EnumChatFormatting chargeFormat;
+
+ if (ratio == 0L) {
+ chargeFormat = EnumChatFormatting.GRAY;
+ } else if (ratio < 0.25) {
+ chargeFormat = EnumChatFormatting.RED;
+ } else if (ratio < 0.5) {
+ chargeFormat = EnumChatFormatting.GOLD;
+ } else if (ratio < 0.75) {
+ chargeFormat = EnumChatFormatting.YELLOW;
+ } else if (ratio < 1L) {
+ chargeFormat = EnumChatFormatting.GREEN;
+ } else {
+ chargeFormat = EnumChatFormatting.AQUA;
+ }
+
+ return StatCollector.translateToLocalFormatted(
+ "gt.locker.waila_armor_slot_charged",
+ index,
+ slotItem.getDisplayName(),
+ chargeFormat,
+ GT_Utility.formatNumbers(ratio * 100));
+ })
+ .orElseGet(
+ // Lazy initialization
+ () -> StatCollector.translateToLocalFormatted(
+ "gt.locker.waila_armor_slot_generic",
+ index,
+ slotItem.getDisplayName())));
+ } else {
+ currentTip.add(StatCollector.translateToLocalFormatted("gt.locker.waila_armor_slot_none", index));
+ }
+ }
+ }
}
diff --git a/src/main/resources/assets/gregtech/lang/en_US.lang b/src/main/resources/assets/gregtech/lang/en_US.lang
index 0c3853f808..ff1952aae5 100644
--- a/src/main/resources/assets/gregtech/lang/en_US.lang
+++ b/src/main/resources/assets/gregtech/lang/en_US.lang
@@ -1324,3 +1324,7 @@ gt.solar.system.phobos=Phobos
gt.specialvalue.stages=Stages:
gt.multiBlock.controller.cokeOven=Coke Oven
+
+gt.locker.waila_armor_slot_none=Slot %s: §7None
+gt.locker.waila_armor_slot_generic=Slot %s: §e%s
+gt.locker.waila_armor_slot_charged=Slot %s: §e%s§r (%s%s%%§r)