From e719508698bc3cb4d6cae69bdd50ce37a0e9d623 Mon Sep 17 00:00:00 2001 From: zml2008 Date: Sat, 14 Jan 2012 17:29:55 -0800 Subject: [PATCH] Implemented inventory handling for SpoutAPI --- src/main/java/com/sk89q/worldedit/spout/SpoutPlayer.java | 6 ++++-- .../com/sk89q/worldedit/spout/SpoutPlayerBlockBag.java | 9 ++++++--- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/sk89q/worldedit/spout/SpoutPlayer.java b/src/main/java/com/sk89q/worldedit/spout/SpoutPlayer.java index 4400f9e04..4221db193 100644 --- a/src/main/java/com/sk89q/worldedit/spout/SpoutPlayer.java +++ b/src/main/java/com/sk89q/worldedit/spout/SpoutPlayer.java @@ -27,9 +27,11 @@ import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.WorldVector; import com.sk89q.worldedit.bags.BlockBag; import com.sk89q.worldedit.cui.CUIEvent; +import org.hibernate.type.MaterializedClobType; import org.spout.api.geo.discrete.Point; import org.spout.api.geo.discrete.Transform; import org.spout.api.inventory.ItemStack; +import org.spout.api.material.MaterialData; import org.spout.api.math.Quaternion; import org.spout.api.math.Vector3; import org.spout.api.player.Player; @@ -47,7 +49,7 @@ public class SpoutPlayer extends LocalPlayer { @Override public int getItemInHand() { - ItemStack itemStack = null;//player.getItemInHand(); + ItemStack itemStack = player.getEntity().getInventory().getCurrentItem(); return itemStack != null ? itemStack.getMaterial().getId() : 0; } @@ -75,7 +77,7 @@ public class SpoutPlayer extends LocalPlayer { @Override public void giveItem(int type, int amt) { - //player.getInventory().addItem(new ItemStack(type, amt)); + player.getEntity().getInventory().addItem(new ItemStack(MaterialData.getMaterial((short)type), amt)); } @Override diff --git a/src/main/java/com/sk89q/worldedit/spout/SpoutPlayerBlockBag.java b/src/main/java/com/sk89q/worldedit/spout/SpoutPlayerBlockBag.java index 5848ff564..9eb1947a8 100644 --- a/src/main/java/com/sk89q/worldedit/spout/SpoutPlayerBlockBag.java +++ b/src/main/java/com/sk89q/worldedit/spout/SpoutPlayerBlockBag.java @@ -28,6 +28,7 @@ import com.sk89q.worldedit.blocks.BaseItem; import com.sk89q.worldedit.blocks.BaseItemStack; import com.sk89q.worldedit.blocks.BlockID; import com.sk89q.worldedit.blocks.ItemType; +import org.spout.api.inventory.Inventory; import org.spout.api.inventory.ItemStack; import org.spout.api.material.MaterialData; import org.spout.api.player.Player; @@ -56,8 +57,7 @@ public class SpoutPlayerBlockBag extends BlockBag { */ private void loadInventory() { if (items == null) { - items = new ItemStack[0]; - //items = player.getInventory().getContents(); + items = player.getEntity().getInventory().getContents(); } } @@ -208,7 +208,10 @@ public class SpoutPlayerBlockBag extends BlockBag { @Override public void flushChanges() { if (items != null) { - //player.getInventory().setContents(items); + Inventory inv = player.getEntity().getInventory(); + for (int i = 0; i < items.length && i < player.getEntity().getInventorySize(); ++i) { + inv.setItem(items[i], i); + } items = null; } }