Kajetan Johannes Hammerle 3 years ago
parent
commit
353eecdb4d
1 changed files with 11 additions and 12 deletions
  1. 11 12
      src/main/java/me/km/snuviscript/commands/InventoryCommands.java

+ 11 - 12
src/main/java/me/km/snuviscript/commands/InventoryCommands.java

@@ -14,7 +14,8 @@ import net.minecraft.util.NonNullList;
 public class InventoryCommands {
     public static void registerFunctions(ScriptManager sm) {
         sm.registerFunction("inv.new", (sc, in) -> new ModInventory(in[0].getString(sc)));
-        sm.registerFunction("inv.getid", (sc, in) -> (double) ((ModInventory) in[0].get(sc)).getModId());
+        sm.registerFunction("inv.getid",
+                (sc, in) -> (double) ((ModInventory) in[0].get(sc)).getModId());
         sm.registerFunction("inv.loadchest", (sc, in) -> {
             Location l = (Location) in[0].get(sc);
             ChestTileEntity chest = (ChestTileEntity) l.getWorld().getTileEntity(l.getBlockPos());
@@ -31,25 +32,23 @@ public class InventoryCommands {
             return inv;
         });
         sm.registerConsumer("inv.setitem", (sc, in) -> {
-            ((IInventory) in[0].get(sc)).setInventorySlotContents(in[1].getInt(sc), (ItemStack) in[2].get(sc));
+            ((IInventory) in[0].get(sc)).setInventorySlotContents(in[1].getInt(sc),
+                    (ItemStack) in[2].get(sc));
         });
-        sm.registerFunction("inv.getitem", (sc, in) -> ((IInventory) in[0].get(sc)).getStackInSlot(in[1].getInt(sc)));
-        sm.registerFunction("inv.getsize", (sc, in) -> (double) ((IInventory) in[0].get(sc)).getSizeInventory());
+        sm.registerFunction("inv.getitem",
+                (sc, in) -> ((IInventory) in[0].get(sc)).getStackInSlot(in[1].getInt(sc)));
+        sm.registerFunction("inv.getsize",
+                (sc, in) -> (double) ((IInventory) in[0].get(sc)).getSizeInventory());
         sm.registerConsumer("inv.open", (sc, in) -> {
-            CustomContainer.openForPlayer((ServerPlayerEntity) in[1].get(sc), (ModInventory) in[0].get(sc), in[2].getString(sc), sc);
+            CustomContainer.openForPlayer((ServerPlayerEntity) in[1].get(sc),
+                    (ModInventory) in[0].get(sc), in[2].getString(sc), sc);
         });
         sm.registerConsumer("inv.close", (sc, in) -> {
             ((PlayerEntity) in[0].get(sc)).closeScreen();
         });
         sm.registerConsumer("inv.update", (sc, in) -> {
             ServerPlayerEntity p = (ServerPlayerEntity) in[0].get(sc);
-            NonNullList<ItemStack> list = NonNullList.<ItemStack>create();
-            int size = p.openContainer.inventorySlots.size();
-            for(int j = 0; j < size; j++) {
-                ItemStack itemstack = p.openContainer.inventorySlots.get(j).getStack();
-                list.add(itemstack.isEmpty() ? ItemStack.EMPTY : itemstack);
-            }
-            p.sendAllContents(p.openContainer, list);
+            p.sendAllContents(p.openContainer, p.openContainer.getInventory());
         });
     }
 }