7
7
import net .minecraft .nbt .NBTTagList ;
8
8
9
9
/**
10
- *
11
10
* @author Michael DeRuscio<https://github.com/Michael-073>
12
11
*/
13
- public class InventoryVoidSatchel implements IInventory {
12
+ public class InventoryVoidSatchel implements IInventory {
14
13
15
14
private ItemStack [] inventory ;
16
15
private final int INVENTORY_SIZE = 13 * 3 ;
17
16
18
-
19
17
public InventoryVoidSatchel (ItemStack stack ) {
20
- if (stack .getItem () != ModItems .voidSatchel ) return ;
21
-
22
-
23
-
18
+ if (stack .getItem () != ModItems .voidSatchel ){
19
+ return ;
20
+ }
21
+
24
22
boolean success = readFromNBT (stack .getTagCompound ());
25
- if (!success )
23
+ if (!success ){
26
24
inventory = new ItemStack [INVENTORY_SIZE ];
25
+ }
27
26
}
28
27
29
28
@ Override
@@ -33,18 +32,21 @@ public int getSizeInventory() {
33
32
34
33
@ Override
35
34
public ItemStack getStackInSlot (int slot ) {
36
- return inventory [slot ];
35
+ return inventory [slot ];
37
36
}
38
37
39
38
@ Override
40
39
public ItemStack decrStackSize (int slot , int num ) {
41
40
ItemStack stack = getStackInSlot (slot ), s ;
42
- if (stack == null ) return null ;
43
- if (stack .stackSize > num ) {
41
+ if (stack == null ){
42
+ return null ;
43
+ }
44
+ if (stack .stackSize > num ){
44
45
s = stack .splitStack (num );
45
- if (stack .stackSize <= 0 )
46
+ if (stack .stackSize <= 0 ){
46
47
setInventorySlotContents (slot , null );
47
- } else {
48
+ }
49
+ }else {
48
50
s = stack ;
49
51
setInventorySlotContents (slot , null );
50
52
@@ -53,16 +55,15 @@ public ItemStack decrStackSize(int slot, int num) {
53
55
return s ;
54
56
}
55
57
56
-
57
-
58
58
@ Override
59
- public ItemStack getStackInSlotOnClosing (int slot ) {
60
- if (inventory [slot ] != null ) {
59
+ public ItemStack getStackInSlotOnClosing (int slot ) {
60
+ if (inventory [slot ] != null ){
61
61
ItemStack itemstack = inventory [slot ];
62
62
this .inventory [slot ] = null ;
63
63
return itemstack ;
64
- } else
64
+ }else {
65
65
return null ;
66
+ }
66
67
}
67
68
68
69
@ Override
@@ -109,55 +110,62 @@ public boolean isStackValidForSlot(int i, ItemStack itemstack) {
109
110
private static final String NBT_VOID_SATCHEL_INVENTORY = "voidSatchelInventory" ;
110
111
111
112
private boolean readFromNBT (NBTTagCompound tag ) {
112
- if (tag == null || !tag .hasKey (NBT_VOID_SATCHEL_INVENTORY )) return false ;
113
+ if ((tag == null ) || !tag .hasKey (NBT_VOID_SATCHEL_INVENTORY )){
114
+ return false ;
115
+ }
113
116
NBTTagList tagList = tag .getTagList (NBT_VOID_SATCHEL_INVENTORY );
114
117
inventory = new ItemStack [getSizeInventory ()];
115
118
116
- for (int i = 0 ; i < tagList .tagCount (); i ++){
119
+ for (int i = 0 ; i < tagList .tagCount (); i ++){
117
120
NBTTagCompound t = (NBTTagCompound ) tagList .tagAt (i );
118
121
int slot = t .getByte ("Slot" );
119
- if ( slot >= 0 && slot < inventory .length )
122
+ if (( slot >= 0 ) && ( slot < inventory .length )){
120
123
inventory [slot ] = ItemStack .loadItemStackFromNBT (t );
124
+ }
121
125
}
122
126
return true ;
123
127
}
124
128
125
129
public void writeBagContents (ItemStack item ) {
126
130
NBTTagCompound tag = item .getTagCompound ();
127
- if (tag == null ){
131
+ if (tag == null ){
128
132
tag = new NBTTagCompound ();
129
133
item .setTagCompound (tag );
130
134
}
131
135
NBTTagList list = new NBTTagList ();
132
136
NBTTagCompound tagComp ;
133
137
ItemStack stack ;
134
- for (int i = 0 ; i < inventory .length ; i ++) {
138
+ for (int i = 0 ; i < inventory .length ; i ++){
135
139
stack = inventory [i ];
136
- if (stack == null ) continue ;
140
+ if (stack == null ){
141
+ continue ;
142
+ }
137
143
tagComp = new NBTTagCompound ();
138
- tagComp .setByte ("Slot" , (byte )i );
144
+ tagComp .setByte ("Slot" , (byte ) i );
139
145
stack .writeToNBT (tagComp );
140
- list .appendTag ( tagComp );
146
+ list .appendTag (tagComp );
141
147
}
142
148
tag .setTag (NBT_VOID_SATCHEL_INVENTORY , list );
143
149
}
144
-
145
- public void clearInventoryNBT (ItemStack item ) {
150
+
151
+ public void clearInventoryNBT (ItemStack item ) {
146
152
NBTTagCompound tag = item .getTagCompound ();
147
- if (tag == null ){
153
+ if (tag == null ){
148
154
tag = new NBTTagCompound ();
149
155
item .setTagCompound (tag );
150
156
}
151
157
NBTTagList list = new NBTTagList ();
152
158
NBTTagCompound tagComp ;
153
159
ItemStack stack ;
154
- for (int i = 0 ; i < inventory .length ; i ++) {
160
+ for (int i = 0 ; i < inventory .length ; i ++){
155
161
stack = inventory [i ];
156
- if (stack == null ) continue ;
162
+ if (stack == null ){
163
+ continue ;
164
+ }
157
165
tagComp = new NBTTagCompound ();
158
- tagComp .setByte ("Slot" , (byte )i );
166
+ tagComp .setByte ("Slot" , (byte ) i );
159
167
stack .writeToNBT (tagComp );
160
- list .appendTag ( tagComp );
168
+ list .appendTag (tagComp );
161
169
}
162
170
tag .setTag (NBT_VOID_SATCHEL_INVENTORY , list );
163
171
}
0 commit comments