Skip to content

Commit dcc8e0a

Browse files
authored
Improving quality of life when dealing with sealed drawers. (#48)
1 parent ac9fb71 commit dcc8e0a

File tree

8 files changed

+496
-51
lines changed

8 files changed

+496
-51
lines changed

src/main/java/com/jaquadro/minecraft/storagedrawers/integration/refinedrelocation/ItemSortingCompDrawers.java

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,28 +3,20 @@
33
import java.util.List;
44

55
import net.minecraft.block.Block;
6-
import net.minecraft.entity.player.EntityPlayer;
7-
import net.minecraft.item.ItemStack;
86
import net.minecraft.util.EnumChatFormatting;
97
import net.minecraft.util.StatCollector;
108

119
import com.jaquadro.minecraft.storagedrawers.item.ItemCompDrawers;
1210

13-
import cpw.mods.fml.relauncher.Side;
14-
import cpw.mods.fml.relauncher.SideOnly;
15-
1611
public class ItemSortingCompDrawers extends ItemCompDrawers {
1712

1813
public ItemSortingCompDrawers(Block block) {
1914
super(block);
2015
}
2116

2217
@Override
23-
@SideOnly(Side.CLIENT)
24-
public void addInformation(ItemStack itemStack, EntityPlayer player, List list, boolean par4) {
25-
super.addInformation(itemStack, player, list, par4);
26-
27-
Block block = Block.getBlockFromItem(itemStack.getItem());
18+
protected void addDescriptionInformation(int drawerCapacity, List list) {
19+
super.addDescriptionInformation(drawerCapacity, list);
2820
list.add(EnumChatFormatting.YELLOW + StatCollector.translateToLocalFormatted("storageDrawers.waila.sorting"));
2921
}
3022
}

src/main/java/com/jaquadro/minecraft/storagedrawers/integration/refinedrelocation/ItemSortingDrawers.java

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
import java.util.List;
44

55
import net.minecraft.block.Block;
6-
import net.minecraft.entity.player.EntityPlayer;
7-
import net.minecraft.item.ItemStack;
86
import net.minecraft.util.EnumChatFormatting;
97
import net.minecraft.util.StatCollector;
108

@@ -13,21 +11,15 @@
1311
import com.jaquadro.minecraft.storagedrawers.integration.RefinedRelocation;
1412
import com.jaquadro.minecraft.storagedrawers.item.ItemBasicDrawers;
1513

16-
import cpw.mods.fml.relauncher.Side;
17-
import cpw.mods.fml.relauncher.SideOnly;
18-
1914
public class ItemSortingDrawers extends ItemBasicDrawers {
2015

2116
public ItemSortingDrawers(Block block) {
2217
super(block);
2318
}
2419

2520
@Override
26-
@SideOnly(Side.CLIENT)
27-
public void addInformation(ItemStack itemStack, EntityPlayer player, List list, boolean par4) {
28-
super.addInformation(itemStack, player, list, par4);
29-
30-
Block block = Block.getBlockFromItem(itemStack.getItem());
21+
protected void addDescriptionInformation(int drawerCapacity, List list) {
22+
super.addDescriptionInformation(drawerCapacity, list);
3123
list.add(EnumChatFormatting.YELLOW + StatCollector.translateToLocalFormatted("storageDrawers.waila.sorting"));
3224
}
3325

src/main/java/com/jaquadro/minecraft/storagedrawers/item/ItemCompDrawers.java

Lines changed: 30 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,18 @@
44

55
import net.minecraft.block.Block;
66
import net.minecraft.entity.player.EntityPlayer;
7-
import net.minecraft.item.ItemBlock;
87
import net.minecraft.item.ItemStack;
8+
import net.minecraft.nbt.NBTTagCompound;
9+
import net.minecraft.nbt.NBTTagList;
910
import net.minecraft.util.EnumChatFormatting;
1011
import net.minecraft.util.StatCollector;
1112
import net.minecraft.world.World;
13+
import net.minecraftforge.common.util.Constants;
1214

1315
import com.jaquadro.minecraft.storagedrawers.StorageDrawers;
1416
import com.jaquadro.minecraft.storagedrawers.block.tile.TileEntityDrawers;
15-
import com.jaquadro.minecraft.storagedrawers.config.ConfigManager;
1617

17-
import cpw.mods.fml.relauncher.Side;
18-
import cpw.mods.fml.relauncher.SideOnly;
19-
20-
public class ItemCompDrawers extends ItemBlock {
18+
public class ItemCompDrawers extends ItemDrawers {
2119

2220
public ItemCompDrawers(Block block) {
2321
super(block);
@@ -45,17 +43,34 @@ public boolean placeBlockAt(ItemStack stack, EntityPlayer player, World world, i
4543
}
4644

4745
@Override
48-
@SideOnly(Side.CLIENT)
49-
public void addInformation(ItemStack itemStack, EntityPlayer player, List list, boolean par4) {
50-
ConfigManager config = StorageDrawers.config;
46+
protected void addDrawersInformation(NBTTagCompound tag, List list) {
47+
NBTTagList slots = tag.getTagList("Slots", Constants.NBT.TAG_COMPOUND);
48+
int totalCount = tag.getInteger("Count");
5149

52-
int count = config.getBlockBaseStorage("compdrawers");
53-
list.add(StatCollector.translateToLocalFormatted("storageDrawers.drawers.description", count));
50+
list.add(
51+
EnumChatFormatting.GRAY
52+
+ StatCollector.translateToLocal("storageDrawers.drawers.sealed.compDrawerList"));
5453

55-
if (itemStack.hasTagCompound() && itemStack.getTagCompound().hasKey("tile")) {
56-
list.add(
57-
EnumChatFormatting.YELLOW
58-
+ StatCollector.translateToLocalFormatted("storageDrawers.drawers.sealed"));
54+
for (int i = 0; i < slots.tagCount(); i++) {
55+
NBTTagCompound slot = slots.getCompoundTagAt(i);
56+
ItemStack stack = getItemStackFromDrawer(slot);
57+
String slotCounter = EnumChatFormatting.YELLOW + " #" + (i + 1) + ": ";
58+
if (stack != null && tag.hasKey("Conv" + i)) {
59+
// "Convi" is the conversion rate, for example in vanilla nugget = 1, ingot = 9, block = 81
60+
int itemCount = totalCount / tag.getByte("Conv" + i);
61+
// Example of show in tooltips (if we have vanilla minecraft):
62+
// #1: Gold Block [1] - totalCount / 81
63+
// #2: Gold Ingot [9] - totalCount / 9
64+
// #3: Gold Nugget [1x64 + 17] - totalCount / 1
65+
list.add(
66+
slotCounter + getGoodDisplayName(stack)
67+
+ " "
68+
+ getItemCountDisplay(stack.getMaxStackSize(), itemCount));
69+
} else {
70+
list.add(
71+
slotCounter + EnumChatFormatting.DARK_GRAY
72+
+ StatCollector.translateToLocal("storageDrawers.drawers.sealed.drawerEmpty"));
73+
}
5974
}
6075
}
6176
}

src/main/java/com/jaquadro/minecraft/storagedrawers/item/ItemCustomDrawers.java

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
package com.jaquadro.minecraft.storagedrawers.item;
22

3+
import java.util.List;
4+
35
import net.minecraft.block.Block;
46
import net.minecraft.entity.player.EntityPlayer;
57
import net.minecraft.item.Item;
68
import net.minecraft.item.ItemStack;
79
import net.minecraft.nbt.NBTTagCompound;
10+
import net.minecraft.util.EnumChatFormatting;
11+
import net.minecraft.util.StatCollector;
812
import net.minecraft.world.World;
913

1014
import com.jaquadro.minecraft.storagedrawers.block.tile.TileEntityDrawers;
@@ -52,6 +56,90 @@ public static ItemStack makeItemStack(Block block, int count, ItemStack matSide,
5256
return stack;
5357
}
5458

59+
@Override
60+
protected void addAlternativeTagInformation(ItemStack itemStack, EntityPlayer player, List list, boolean par4) {
61+
// Add materials information for not sealed framed drawers.
62+
Block block = Block.getBlockFromItem(itemStack.getItem());
63+
this.addDescriptionInformation(getCapacityForBlock(block), list);
64+
this.addMaterialsInformation(itemStack.getTagCompound(), list); // safe to use without tags.
65+
}
66+
67+
@Override
68+
protected void addNoneTagDescriptionInformation(int drawerCapacity, List list) {
69+
super.addNoneTagDescriptionInformation(drawerCapacity, list);
70+
list.add(
71+
EnumChatFormatting.GRAY + StatCollector.translateToLocal("storageDrawers.drawers.sealed.materialList"));
72+
list.add(
73+
" " + EnumChatFormatting.DARK_GRAY
74+
+ StatCollector.translateToLocal("storageDrawers.drawers.sealed.materialNone"));
75+
}
76+
77+
@Override
78+
protected void addSealedContentsInformation(NBTTagCompound tag, List list) {
79+
this.addMaterialsInformation(tag, list);
80+
}
81+
82+
/** Add to tooltip information about materials used in framed drawers */
83+
private void addMaterialsInformation(NBTTagCompound tag, List list) {
84+
ItemStack materialSide = null;
85+
ItemStack materialFront = null;
86+
ItemStack materialTrim = null;
87+
boolean hasMaterials = false;
88+
89+
// Logic copied from "readFromPortableNBT" method from "TileEntityDrawers".
90+
if (tag.hasKey("MatS")) {
91+
materialSide = ItemStack.loadItemStackFromNBT(tag.getCompoundTag("MatS"));
92+
hasMaterials = true;
93+
}
94+
if (tag.hasKey("MatF")) {
95+
materialFront = ItemStack.loadItemStackFromNBT(tag.getCompoundTag("MatF"));
96+
hasMaterials = true;
97+
}
98+
if (tag.hasKey("MatT")) {
99+
materialTrim = ItemStack.loadItemStackFromNBT(tag.getCompoundTag("MatT"));
100+
hasMaterials = true;
101+
}
102+
103+
list.add(
104+
EnumChatFormatting.GRAY + StatCollector.translateToLocal("storageDrawers.drawers.sealed.materialList"));
105+
106+
if (hasMaterials) {
107+
// Display side material
108+
list.add(
109+
" " + EnumChatFormatting.YELLOW
110+
+ StatCollector.translateToLocal("storageDrawers.drawers.sealed.materialSide")
111+
+ " "
112+
+ getMaterialDisplayName(materialSide));
113+
// Display trim material
114+
list.add(
115+
" " + EnumChatFormatting.YELLOW
116+
+ StatCollector.translateToLocal("storageDrawers.drawers.sealed.materialTrim")
117+
+ " "
118+
+ getMaterialDisplayName(materialTrim));
119+
// Display front material
120+
list.add(
121+
" " + EnumChatFormatting.YELLOW
122+
+ StatCollector.translateToLocal("storageDrawers.drawers.sealed.materialFront")
123+
+ " "
124+
+ getMaterialDisplayName(materialFront));
125+
} else {
126+
// Display <None> ...
127+
list.add(
128+
" " + EnumChatFormatting.DARK_GRAY
129+
+ StatCollector.translateToLocal("storageDrawers.drawers.sealed.materialNone"));
130+
}
131+
}
132+
133+
/** Returns good display name or in gray localised "sealed.materialNone". */
134+
private String getMaterialDisplayName(ItemStack stack) {
135+
if (stack != null) {
136+
return getGoodDisplayName(stack);
137+
} else {
138+
return EnumChatFormatting.DARK_GRAY
139+
+ StatCollector.translateToLocal("storageDrawers.drawers.sealed.materialNone");
140+
}
141+
}
142+
55143
private static NBTTagCompound getMaterialTag(ItemStack mat) {
56144
mat = mat.copy();
57145
mat.stackSize = 1;

src/main/java/com/jaquadro/minecraft/storagedrawers/item/ItemCustomTrim.java

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,22 @@
11
package com.jaquadro.minecraft.storagedrawers.item;
22

3+
import java.util.List;
4+
35
import net.minecraft.block.Block;
46
import net.minecraft.entity.player.EntityPlayer;
57
import net.minecraft.item.Item;
68
import net.minecraft.item.ItemBlock;
79
import net.minecraft.item.ItemStack;
810
import net.minecraft.nbt.NBTTagCompound;
11+
import net.minecraft.util.EnumChatFormatting;
12+
import net.minecraft.util.StatCollector;
913
import net.minecraft.world.World;
1014

1115
import com.jaquadro.minecraft.storagedrawers.block.tile.TileEntityTrim;
1216

17+
import cpw.mods.fml.relauncher.Side;
18+
import cpw.mods.fml.relauncher.SideOnly;
19+
1320
public class ItemCustomTrim extends ItemBlock {
1421

1522
public ItemCustomTrim(Block block) {
@@ -32,6 +39,90 @@ public boolean placeBlockAt(ItemStack stack, EntityPlayer player, World world, i
3239
return true;
3340
}
3441

42+
@Override
43+
@SideOnly(Side.CLIENT)
44+
public void addInformation(ItemStack itemStack, EntityPlayer player, List list, boolean par4) {
45+
if (itemStack.hasTagCompound()) {
46+
NBTTagCompound tag = itemStack.getTagCompound();
47+
this.addMaterialsInformation(tag, list);
48+
} else {
49+
list.add(StatCollector.translateToLocal("storageDrawers.drawers.sealed.materialList"));
50+
list.add(
51+
" " + EnumChatFormatting.DARK_GRAY
52+
+ StatCollector.translateToLocal("storageDrawers.drawers.sealed.materialNone"));
53+
}
54+
}
55+
56+
/**
57+
* Add to tooltip information about materials used in framed trim. Copied from ItemCustomDrawers method.
58+
*/
59+
private void addMaterialsInformation(NBTTagCompound tag, List list) {
60+
ItemStack materialSide = null;
61+
ItemStack materialFront = null;
62+
ItemStack materialTrim = null;
63+
boolean hasMaterials = false;
64+
65+
// Logic copied from "readFromPortableNBT" method from "TileEntityDrawers".
66+
if (tag.hasKey("MatS")) {
67+
materialSide = ItemStack.loadItemStackFromNBT(tag.getCompoundTag("MatS"));
68+
hasMaterials = true;
69+
}
70+
if (tag.hasKey("MatF")) {
71+
materialFront = ItemStack.loadItemStackFromNBT(tag.getCompoundTag("MatF"));
72+
hasMaterials = true;
73+
}
74+
if (tag.hasKey("MatT")) {
75+
materialTrim = ItemStack.loadItemStackFromNBT(tag.getCompoundTag("MatT"));
76+
hasMaterials = true;
77+
}
78+
79+
list.add(
80+
EnumChatFormatting.GRAY + StatCollector.translateToLocal("storageDrawers.drawers.sealed.materialList"));
81+
82+
if (hasMaterials) {
83+
// Display side material
84+
list.add(
85+
" " + EnumChatFormatting.YELLOW
86+
+ StatCollector.translateToLocal("storageDrawers.drawers.sealed.materialSide")
87+
+ " "
88+
+ getMaterialDisplayName(materialSide));
89+
// Display trim material
90+
list.add(
91+
" " + EnumChatFormatting.YELLOW
92+
+ StatCollector.translateToLocal("storageDrawers.drawers.sealed.materialTrim")
93+
+ " "
94+
+ getMaterialDisplayName(materialTrim));
95+
// Display front material
96+
list.add(
97+
" " + EnumChatFormatting.YELLOW
98+
+ StatCollector.translateToLocal("storageDrawers.drawers.sealed.materialFront")
99+
+ " "
100+
+ getMaterialDisplayName(materialFront));
101+
} else {
102+
// Display <None> ...
103+
list.add(
104+
" " + EnumChatFormatting.DARK_GRAY
105+
+ StatCollector.translateToLocal("storageDrawers.drawers.sealed.materialNone"));
106+
}
107+
}
108+
109+
/**
110+
* Returns good display name or in gray localised "sealed.materialNone". Copied from ItemDrawers and
111+
* ItemCustomDrawers methods.
112+
*/
113+
private String getMaterialDisplayName(ItemStack stack) {
114+
if (stack != null) {
115+
if (stack.hasDisplayName()) {
116+
return EnumChatFormatting.ITALIC.toString() + stack.getRarity().rarityColor + stack.getDisplayName();
117+
} else {
118+
return stack.getRarity().rarityColor.toString() + stack.getDisplayName();
119+
}
120+
} else {
121+
return EnumChatFormatting.DARK_GRAY
122+
+ StatCollector.translateToLocal("storageDrawers.drawers.sealed.materialNone");
123+
}
124+
}
125+
35126
public static ItemStack makeItemStack(Block block, int count, ItemStack matSide, ItemStack matTrim) {
36127
Item item = Item.getItemFromBlock(block);
37128
if (!(item instanceof ItemCustomTrim)) return null;

0 commit comments

Comments
 (0)