@@ -46,43 +46,13 @@ public final String getOwner() throws LuaException {
4646 return getOwnerPlayer ().getName ().getString ();
4747 }
4848
49- /**
50- * @deprecated Switch to the function with the item filter object
51- */
52- @ Deprecated
53- @ LuaFunction (mainThread = true , value = {"pullItems" , "addItemToPlayer" })
54- public final MethodResult addItemToPlayer (String invDirection , int count , Optional <Integer > slot , Optional <String > item ) throws LuaException {
55- Pair <ItemFilter , String > filter ;
56- Map <Object , Object > filterMap = new HashMap <>();
57-
58- // Deprecated! Will be removed in the future. This exists to maintain compatibility within the same mc version
59- item .ifPresent (s -> filterMap .put ("name" , s ));
60- slot .ifPresent (integer -> filterMap .put ("toSlot" , integer ));
61- filterMap .put ("count" , count );
62-
63- filter = ItemFilter .parse (filterMap );
64- if (filter .rightPresent ())
65- return MethodResult .of (0 , filter .getRight ());
66- return MethodResult .of (addItemCommon (invDirection , filter .getLeft ()));
67-
68- }
6949
7050 //Add the specified item to the player
7151 //The item is specified the same as with the RS/ME bridge:
7252 //{name="minecraft:enchanted_book", count=1, nbt="ae70053c97f877de546b0248b9ddf525"}
73- //If a count is specified in the item it is silently IGNORED
7453 @ LuaFunction (mainThread = true )
75- public final MethodResult addItemToPlayerNBT (String invDirection , int count , Optional <Integer > slot , Optional <Map <?, ?>> item ) throws LuaException {
76- Pair <ItemFilter , String > filter ;
77- Map <Object , Object > filterMap = new HashMap <>();
78-
79- // Deprecated! Will be removed in the future. This exists to maintain compatibility within the same mc version
80- slot .ifPresent (integer -> filterMap .put ("toSlot" , integer ));
81- filterMap .put ("count" , count );
82-
83- item .ifPresent (filterMap ::putAll );
84-
85- filter = ItemFilter .parse (filterMap );
54+ public final MethodResult addItemToPlayer (String invDirection , Map <?, ?> item ) throws LuaException {
55+ Pair <ItemFilter , String > filter = ItemFilter .parse (item );
8656 if (filter .rightPresent ())
8757 return MethodResult .of (0 , filter .getRight ());
8858
@@ -104,34 +74,9 @@ private int addItemCommon(String invDirection, ItemFilter filter) throws LuaExce
10474 return InventoryUtil .moveItem (inventoryFrom , inventoryTo .getLeft (), filter );
10575 }
10676
107- @ LuaFunction (mainThread = true , value = {"pushItems" , "removeItemFromPlayer" })
108- public final MethodResult removeItemFromPlayer (String invDirection , int count , Optional <Integer > slot , Optional <String > item ) throws LuaException {
109- Pair <ItemFilter , String > filter ;
110- Map <Object , Object > filterMap = new HashMap <>();
111-
112- // Deprecated! Will be removed in the future. This exists to maintain compatibility within the same mc version
113- item .ifPresent (itemName -> filterMap .put ("name" , itemName ));
114- slot .ifPresent (toSlot -> filterMap .put ("toSlot" , toSlot ));
115- filterMap .put ("count" , count );
116-
117- filter = ItemFilter .parse (filterMap );
118- if (filter .rightPresent ())
119- return MethodResult .of (0 , filter .getRight ());
120- return removeItemCommon (invDirection , filter .getLeft ());
121- }
122-
12377 @ LuaFunction (mainThread = true )
124- public final MethodResult removeItemFromPlayerNBT (String invDirection , int count , Optional <Integer > slot , Optional <Map <?, ?>> item ) throws LuaException {
125- Pair <ItemFilter , String > filter ;
126- Map <Object , Object > filterMap = new HashMap <>();
127-
128- // Deprecated! Will be removed in the future. This exists to maintain compatibility within the same mc version
129- slot .ifPresent (toSlot -> filterMap .put ("toSlot" , toSlot ));
130- filterMap .put ("count" , count );
131-
132- item .ifPresent (filterMap ::putAll );
133-
134- filter = ItemFilter .parse (filterMap );
78+ public final MethodResult removeItemFromPlayer (String invDirection , Map <?, ?> item ) throws LuaException {
79+ Pair <ItemFilter , String > filter = ItemFilter .parse (item );
13580 if (filter .rightPresent ())
13681 return MethodResult .of (0 , filter .getRight ());
13782
@@ -145,7 +90,7 @@ private MethodResult removeItemCommon(String invDirection, ItemFilter filter) th
14590 Pair <IItemHandler , Integer > inventoryFrom = getHandlerFromSlot (filter .getFromSlot ());
14691 IItemHandler inventoryTo = targetEntity != null ? targetEntity .getCapability (ForgeCapabilities .ITEM_HANDLER , direction ).resolve ().orElse (null ) : null ;
14792
148- if (inventoryTo == null )
93+ if (inventoryTo == null )
14994 return MethodResult .of (0 , "INVENTORY_TO_INVALID" );
15095
15196 inventoryFrom .ifRightPresent (slot -> filter .fromSlot = slot );
@@ -173,7 +118,7 @@ public final MethodResult getItemsChest(String target) throws LuaException {
173118 BlockEntity targetEntity = owner .getLevel ().getBlockEntity (owner .getPos ().relative (direction ));
174119 IItemHandler inventoryTo = targetEntity != null ? targetEntity .getCapability (ForgeCapabilities .ITEM_HANDLER , direction ).resolve ().orElse (null ) : null ;
175120
176- if (inventoryTo == null )
121+ if (inventoryTo == null )
177122 return MethodResult .of (null , "INVENTORY_TO_INVALID" );
178123
179124 List <Object > items = new ArrayList <>();
@@ -257,12 +202,12 @@ private Player getOwnerPlayer() throws LuaException {
257202 @ NotNull
258203 private Pair <IItemHandler , Integer > getHandlerFromSlot (int slot ) throws LuaException {
259204 IItemHandler handler ;
260- if (slot >= 100 && slot <= 103 ) {
205+ if (slot >= 100 && slot <= 103 ) {
261206 handler = new PlayerArmorInvWrapper (getOwnerPlayer ().getInventory ());
262207 // If the slot is between 100 and 103, change the index to a normal index between 0 and 3.
263208 // This is necessary since the PlayerArmorInvWrapper does not work with these higher indexes
264209 slot = slot - 100 ;
265- } else if (slot == 36 ) {
210+ } else if (slot == 36 ) {
266211 handler = new PlayerOffhandInvWrapper (getOwnerPlayer ().getInventory ());
267212 // Set the "from slot" to zero so the offhand wrapper can work with that
268213 slot = 0 ;
0 commit comments