forked from RedServer/Hwyla
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHUDHandlerCache.java
More file actions
98 lines (78 loc) · 3.46 KB
/
HUDHandlerCache.java
File metadata and controls
98 lines (78 loc) · 3.46 KB
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
package mcp.mobius.waila.addons.thermalexpansion;
import mcp.mobius.waila.api.IWailaConfigHandler;
import mcp.mobius.waila.api.IWailaDataAccessor;
import mcp.mobius.waila.api.IWailaDataProvider;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.math.BlockPos;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
import java.lang.reflect.InvocationTargetException;
import java.util.List;
import javax.annotation.Nonnull;
public class HUDHandlerCache implements IWailaDataProvider {
static final IWailaDataProvider INSTANCE = new HUDHandlerCache();
@Nonnull
@Override
public List<String> getWailaHead(ItemStack itemStack, List<String> currenttip, IWailaDataAccessor accessor,
IWailaConfigHandler config) {
if (!config.getConfig("thermalexpansion.cache")) return currenttip;
try {
ItemStack storedItem = null;
if (accessor.getNBTData().hasKey("Item"))
storedItem = readItemStack(accessor.getNBTData().getCompoundTag("Item"));
String name = currenttip.get(0);
String color = "";
if (name.startsWith("\u00a7")) color = name.substring(0, 2);
if (storedItem != null) {;
name += String.format(color + " < %s >", storedItem.getDisplayName());
} else name += " " + "EMPTY";
currenttip.set(0, name);
} catch (Exception e) {
throw new RuntimeException(e);
}
return currenttip;
}
@Nonnull
@Override
public List<String> getWailaBody(ItemStack itemStack, List<String> currenttip, IWailaDataAccessor accessor, IWailaConfigHandler config) {
if (!config.getConfig("thermalexpansion.cache")) return currenttip;
NBTTagCompound tag = accessor.getNBTData();
ItemStack storedItem = null;
if (tag.hasKey("Item")) storedItem = readItemStack(tag.getCompoundTag("Item"));
int stored = 0;
int maxStored = 0;
if (tag.hasKey("Stored")) stored = tag.getInteger("Stored");
if (tag.hasKey("MaxStored")) maxStored = tag.getInteger("MaxStored");
if (storedItem != null) {
currenttip.add("Stored: " + stored);
// currenttip.add("Stored: " + stored + "/" + maxStored); //TODO: maxStored
} else currenttip.add("Capacity: " + maxStored);
return currenttip;
}
@Nonnull
@Override
public NBTTagCompound getNBTData(EntityPlayerMP player, TileEntity te, NBTTagCompound tag, World world, BlockPos pos) {
TileEntity tile = world.getTileEntity(pos);
if (te != null) te.writeToNBT(tag);
try {
tag.setInteger("MaxStored", 0); //TODO: maxStored
tag.setInteger("Stored", (Integer) ThermalExpansionModule.TileCache_getStored.invoke(te));
} catch (InvocationTargetException | IllegalAccessException e) {
e.printStackTrace();
}
return tag;
}
public ItemStack readItemStack(NBTTagCompound tag) {
ItemStack is = new ItemStack(Item.getByNameOrId(tag.getString("id")));
// TODO: WIP
// is.splitStack(tag.getInteger("Count"));
// is.setItemDamage(Math.max(0, tag.getShort("Damage")));
// if (tag.hasKey("tag", 10)) {
// is.setTagCompound(tag.getCompoundTag("tag"));
// }
return is;
}
}