package com.example; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.GuiScreen; import net.minecraft.client.gui.inventory.GuiChest; import net.minecraft.inventory.ContainerChest; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTBase; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagList; import net.minecraft.nbt.NBTTagString; import net.minecraftforge.client.ClientCommandHandler; import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.fml.common.Mod; import net.minecraftforge.fml.common.event.FMLInitializationEvent; import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; import net.minecraftforge.fml.common.gameevent.TickEvent; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import java.util.ArrayList; import java.util.List; import java.util.function.Function; @Mod(modid = "examplemod", useMetadata = true) public class ExampleMod { @Mod.EventHandler public void init(FMLInitializationEvent event) { MinecraftForge.EVENT_BUS.register(this); ClientCommandHandler.instance.registerCommand(new CrashCommand()); } public static GuiScreen screenToOpenNextTick = null; public static final int MOUSE_LEFT = 0; public static final int MOUSE_RIGHT = 1; public static final int MOUSE_MIDDLE = 2; public static final int MOUSE_BACKWARD = 3; public static final int MOUSE_FORWARD = 4; public static List listFromNBT(NBTTagList nbtList, Function reader) { List ts = new ArrayList<>(nbtList.tagCount()); for (int i = 0; i < nbtList.tagCount(); i++) { //noinspection unchecked ts.add(reader.apply((U) nbtList.get(i))); } return ts; } @SubscribeEvent public void onTick(TickEvent.ClientTickEvent event) { if (event.phase != TickEvent.Phase.END) return; GuiScreen currentScreen = Minecraft.getMinecraft().currentScreen; if (!(currentScreen instanceof GuiChest)) return; ContainerChest container = (ContainerChest) ((GuiChest) currentScreen).inventorySlots; LogManager.getLogger("ExampleMod").info("Container Name: " + container.getLowerChestInventory().getDisplayName().getFormattedText()); Logger logger = LogManager.getLogger("ExampleMod"); for (int i = 0; i < container.getLowerChestInventory().getSizeInventory(); i++) { ItemStack stack = container.getLowerChestInventory().getStackInSlot(i); if (stack == null) continue; logger.info("Slot " + i + ":"); byte STRING_NBT_TAG = new NBTTagString().getId(); NBTTagCompound tagCompound = stack.getTagCompound(); if (tagCompound == null) continue; String displayName = tagCompound.getCompoundTag("display").getString("Name"); NBTTagList loreList = tagCompound.getCompoundTag("display").getTagList("Lore", STRING_NBT_TAG); List loreStrings = listFromNBT(loreList, NBTTagString::getString); for (int i1 = 0; i1 < loreList.tagCount(); i1++) { String loreLine = loreList.getStringTagAt(i1); } } } }