blob: 6a386e1233b2e6cb35609c7ea12dde51cdc58f38 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
|
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 <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 (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);
}
}
}
}
|