-
-
Notifications
You must be signed in to change notification settings - Fork 119
/
ExpandPlayerInventory.java
177 lines (150 loc) · 5.5 KB
/
ExpandPlayerInventory.java
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
package com.blamejared.crafttweaker.impl_native.inventory;
import com.blamejared.crafttweaker.api.annotations.ZenRegister;
import com.blamejared.crafttweaker.api.item.IIngredient;
import com.blamejared.crafttweaker.api.item.IItemStack;
import com.blamejared.crafttweaker.impl.item.MCItemStack;
import com.blamejared.crafttweaker.impl.item.MCItemStackMutable;
import com.blamejared.crafttweaker_annotations.annotations.Document;
import com.blamejared.crafttweaker_annotations.annotations.NativeTypeRegistration;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.util.NonNullList;
import org.openzen.zencode.java.ZenCodeType;
@ZenRegister
@Document("vanilla/api/inventory/PlayerInventory")
@NativeTypeRegistration(value = PlayerInventory.class, zenCodeName = "crafttweaker.api.inventory.PlayerInventory")
public class ExpandPlayerInventory {
/**
* Gets the currently held item by the player.
*
* @return The currently held stack by the player.
*/
@ZenCodeType.Method
@ZenCodeType.Getter("currentItem")
public static IItemStack getCurrentItem(PlayerInventory internal) {
return new MCItemStack(internal.getCurrentItem());
}
/**
* Gets the first slot in the inventory that is empty.
*
* If no slot is found, it returns `-1`.
*
* @return The found slot or `-1` if no slot is found.
*/
@ZenCodeType.Method
@ZenCodeType.Getter("firstEmptyStack")
public static int getFirstEmptyStack(PlayerInventory internal) {
return internal.getFirstEmptyStack();
}
/**
* Checks if a stack can be stored in the player's inventory. It first tries to place it in the selected slot in the player's hotbar,
* then the offhand slot, then any available/empty slot in the player's inventory.
*
* @param stack The stack to store.
*
* @return The slot that the stack can be stored in, or `-1` if it can't be stored.
*
* @docParam stack <item:minecraft:diamond>
*/
@ZenCodeType.Method
public static int canStoreIItemStack(PlayerInventory internal, IItemStack stack) {
return internal.storeItemStack(stack.getInternal());
}
/**
* Adds the stack to the first empty slot in the player's inventory.
*
* @param stack The stack to add.
*
* @return True if the stack was added. False otherwise.
*
* @docParam stack <item:minecraft:diamond>
*/
@ZenCodeType.Method
public static boolean addIItemStackToInventory(PlayerInventory internal, IItemStack stack) {
return internal.addItemStackToInventory(stack.getInternal());
}
/**
* Adds the stack to the given slot in the player's inventory.
*
* @param slot The slot to put the stack.
* @param stack The stack to add.
*
* @return True if the stack was inserted. False otherwise.
*
* @docParam stack <item:minecraft:diamond>
*/
@ZenCodeType.Method
public static boolean add(PlayerInventory internal, int slot, IItemStack stack) {
return internal.add(slot, stack.getInternal());
}
/**
* Removes the first instance of the given stack from the inventory.
*
* @param stack The stack to remove.
*
* @docParam stack <item:minecraft:diamond>
*/
@ZenCodeType.Method
public static void deleteStack(PlayerInventory internal, IItemStack stack) {
internal.deleteStack(stack.getInternal());
}
/**
* Drop all items in the inventory..
*/
@ZenCodeType.Method
public static void dropAllItems(PlayerInventory internal) {
internal.dropAllItems();
}
/**
* Checks if the given IItemStack is in the inventory.
*
* @param stack The stack to look for.
*
* @return True if the stack is found. False otherwise.
*
* @docParam stack <item:minecraft:diamond>
*/
@ZenCodeType.Method
public static boolean hasIItemStack(PlayerInventory internal, IItemStack stack) {
return internal.hasItemStack(stack.getInternal());
}
/**
* Gets the IItemStack that is being held by the mouse in a Gui/Container.
*
* @return The held IItemStack
*/
@ZenCodeType.Method
@ZenCodeType.Getter("itemStack")
public static IItemStack getIItemStack(PlayerInventory internal) {
return new MCItemStack(internal.getItemStack());
}
/**
* Sets the IItemStack that is being held by the mouse in a Gui/Container.
*
* @param stack The stack to hold.
*
* @docParam stack <item:minecraft:dirt>
*/
@ZenCodeType.Method
@ZenCodeType.Setter("itemStack")
public static void setIItemStack(PlayerInventory internal, IItemStack stack) {
internal.setItemStack(stack.getInternal());
}
/**
* Removes all stacks that match the ingredient.
*
* @param ingredient The ingredient to match against.
*
* @docParam ingredient <item:minecraft:diamond>
*/
@ZenCodeType.Method
public static void remove(PlayerInventory internal, IIngredient ingredient) {
for(NonNullList<ItemStack> nonnulllist : internal.allInventories) {
for(int i = 0; i < nonnulllist.size(); ++i) {
if(ingredient.matches(new MCItemStackMutable(nonnulllist.get(i)))) {
nonnulllist.set(i, ItemStack.EMPTY);
}
}
}
}
}