aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/com/example/ExampleMod.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/com/example/ExampleMod.java')
-rw-r--r--src/main/java/com/example/ExampleMod.java46
1 files changed, 43 insertions, 3 deletions
diff --git a/src/main/java/com/example/ExampleMod.java b/src/main/java/com/example/ExampleMod.java
index 166c371..6a386e1 100644
--- a/src/main/java/com/example/ExampleMod.java
+++ b/src/main/java/com/example/ExampleMod.java
@@ -2,12 +2,25 @@ 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 {
@@ -24,11 +37,38 @@ public class ExampleMod {
public static final int MOUSE_MIDDLE = 2;
public static final int MOUSE_BACKWARD = 3;
public static final int MOUSE_FORWARD = 4;
+
+ public static <U extends NBTBase, T> List<T> listFromNBT(NBTTagList nbtList, Function<U, T> reader) {
+ List<T> 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 (screenToOpenNextTick != null) {
- Minecraft.getMinecraft().displayGuiScreen(screenToOpenNextTick);
- screenToOpenNextTick = null;
+ 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<String> loreStrings = listFromNBT(loreList, NBTTagString::getString);
+ for (int i1 = 0; i1 < loreList.tagCount(); i1++) {
+ String loreLine = loreList.getStringTagAt(i1);
+ }
}
}
}