From 0bd3b346fc5871a33ed0156d6fc9dbee060641d0 Mon Sep 17 00:00:00 2001 From: zml2008 Date: Tue, 20 Mar 2012 17:53:48 -0700 Subject: [PATCH] Added support for features added to Spout (now depends on Vanilla) --- pom.xml | 7 ++- .../worldedit/spout/SpoutPlayerBlockBag.java | 45 ++++++-------- .../com/sk89q/worldedit/spout/SpoutWorld.java | 61 ++++++++++--------- 3 files changed, 57 insertions(+), 56 deletions(-) diff --git a/pom.xml b/pom.xml index 839bf9049..c7dc835b7 100644 --- a/pom.xml +++ b/pom.xml @@ -32,7 +32,7 @@ spout-repo - http://nexus.spout.org/content/groups/public/ + http://repo.spout.org/ @@ -90,6 +90,11 @@ spoutapi dev-SNAPSHOT + + org.spout + vanilla + dev-SNAPSHOT + diff --git a/src/main/java/com/sk89q/worldedit/spout/SpoutPlayerBlockBag.java b/src/main/java/com/sk89q/worldedit/spout/SpoutPlayerBlockBag.java index f861e933c..cc22f6a58 100644 --- a/src/main/java/com/sk89q/worldedit/spout/SpoutPlayerBlockBag.java +++ b/src/main/java/com/sk89q/worldedit/spout/SpoutPlayerBlockBag.java @@ -30,6 +30,7 @@ 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.Material; import org.spout.api.material.MaterialData; import org.spout.api.player.Player; @@ -45,7 +46,7 @@ public class SpoutPlayerBlockBag extends BlockBag { /** * Construct the object. - * + * * @param player */ public SpoutPlayerBlockBag(Player player) { @@ -63,7 +64,7 @@ public class SpoutPlayerBlockBag extends BlockBag { /** * Get the player. - * + * * @return */ public Player getPlayer() { @@ -77,11 +78,11 @@ public class SpoutPlayerBlockBag extends BlockBag { */ @Override public void fetchItem(BaseItem item) throws BlockBagException { - final int id = item.getType(); - final int damage = item.getDamage(); + final short id = (short)item.getType(); + final short damage = item.getDamage(); int amount = (item instanceof BaseItemStack) ? ((BaseItemStack) item).getAmount() : 1; assert(amount == 1); - boolean usesDamageValue = ItemType.usesDamageValue(id); + final Material mat = MaterialData.getMaterial(id, damage); if (id == BlockID.AIR) { throw new IllegalArgumentException("Can't fetch air block"); @@ -98,13 +99,8 @@ public class SpoutPlayerBlockBag extends BlockBag { continue; } - if (bukkitItem.getMaterial().getId() != id) { - // Type id doesn't fit - continue; - } - - if (usesDamageValue && bukkitItem.getDamage() != damage) { - // Damage value doesn't fit. + if (!bukkitItem.getMaterial().equals(mat)) { + // Type id or damage value doesn't fit continue; } @@ -132,16 +128,16 @@ public class SpoutPlayerBlockBag extends BlockBag { /** * Store a block. - * + * * @param item */ @Override public void storeItem(BaseItem item) throws BlockBagException { final int id = item.getType(); - final int damage = item.getDamage(); + final short damage = item.getDamage(); + final Material mat = MaterialData.getMaterial((short) id, damage); int amount = (item instanceof BaseItemStack) ? ((BaseItemStack) item).getAmount() : 1; - assert(amount <= 64); - boolean usesDamageValue = ItemType.usesDamageValue(id); + assert(amount <= mat.getMaxStackSize()); if (id == BlockID.AIR) { throw new IllegalArgumentException("Can't store air block"); @@ -164,13 +160,8 @@ public class SpoutPlayerBlockBag extends BlockBag { continue; } - if (bukkitItem.getMaterial().getId() != id) { - // Type id doesn't fit - continue; - } - - if (usesDamageValue && bukkitItem.getDamage() != damage) { - // Damage value doesn't fit. + if (!bukkitItem.getMaterial().equals(mat)) { + // Type id or damage value doesn't fit continue; } @@ -179,23 +170,23 @@ public class SpoutPlayerBlockBag extends BlockBag { // Unlimited return; } - if (currentAmount >= 64) { + if (currentAmount >= mat.getMaxStackSize()) { // Full stack continue; } - int spaceLeft = 64 - currentAmount; + int spaceLeft = mat.getMaxStackSize() - currentAmount; if (spaceLeft >= amount) { bukkitItem.setAmount(currentAmount + amount); return; } - bukkitItem.setAmount(64); + bukkitItem.setAmount(mat.getMaxStackSize()); amount -= spaceLeft; } if (freeSlot > -1) { - items[freeSlot] = new ItemStack(MaterialData.getMaterial((short)id), amount); + items[freeSlot] = new ItemStack(mat, amount); return; } diff --git a/src/main/java/com/sk89q/worldedit/spout/SpoutWorld.java b/src/main/java/com/sk89q/worldedit/spout/SpoutWorld.java index b1f3907f1..56563176d 100644 --- a/src/main/java/com/sk89q/worldedit/spout/SpoutWorld.java +++ b/src/main/java/com/sk89q/worldedit/spout/SpoutWorld.java @@ -30,8 +30,17 @@ import com.sk89q.worldedit.blocks.BaseItemStack; import com.sk89q.worldedit.regions.Region; import com.sk89q.worldedit.util.TreeGenerator; +import org.spout.api.entity.Entity; import org.spout.api.geo.World; +import org.spout.api.geo.cuboid.Chunk; +import org.spout.api.inventory.ItemStack; import org.spout.api.material.MaterialData; +import org.spout.api.math.Vector3; +import org.spout.vanilla.entity.object.Item; +import org.spout.vanilla.entity.object.falling.PrimedTnt; +import org.spout.vanilla.entity.object.projectile.Arrow; +import org.spout.vanilla.entity.object.vehicle.Boat; +import org.spout.vanilla.entity.object.vehicle.Minecart; public class SpoutWorld extends LocalWorld { private World world; @@ -381,10 +390,8 @@ public class SpoutWorld extends LocalWorld { */ @Override public void dropItem(Vector pt, BaseItemStack item) { - /*ItemStack bukkitItem = new ItemStack(item.getType(), item.getAmount(), - (byte) item.getDamage()); - world.dropItemNaturally(SpoutUtil.toLocation(world, pt), bukkitItem);*/ - + ItemStack bukkitItem = new ItemStack(MaterialData.getMaterial((short)item.getType(), item.getDamage()), item.getAmount(), item.getDamage()); + world.createAndSpawnEntity(SpoutUtil.toPoint(world, pt), new Item(bukkitItem, new Vector3(pt.getX(), pt.getY(), pt.getZ()))); } /** @@ -446,51 +453,51 @@ public class SpoutWorld extends LocalWorld { @Override public int removeEntities(EntityType type, Vector origin, int radius) { int num = 0; - /*double radiusSq = radius * radius; + double radiusSq = radius * radius; - for (Entity ent : world.getEntities()) { + for (Entity ent : world.getAll()) { if (radius != -1 - && origin.distanceSq(SpoutUtil.toVector(ent.getTransform().getPosition())) > radiusSq) { + && origin.distanceSq(SpoutUtil.toVector(ent.getPosition())) > radiusSq) { continue; } if (type == EntityType.ARROWS) { - if (ent instanceof Arrow) { - ent.remove(); + if (ent.getController() instanceof Arrow) { + ent.kill(); ++num; } } else if (type == EntityType.BOATS) { - if (ent instanceof Boat) { - ent.remove(); + if (ent.getController() instanceof Boat) { + ent.kill(); ++num; } } else if (type == EntityType.ITEMS) { - if (ent instanceof Item) { - ent.remove(); + if (ent.getController() instanceof Item) { + ent.kill(); ++num; } } else if (type == EntityType.MINECARTS) { - if (ent instanceof Minecart) { - ent.remove(); + if (ent.getController() instanceof Minecart) { + ent.kill(); ++num; } - } else if (type == EntityType.PAINTINGS) { - if (ent instanceof Painting) { - ent.remove(); + } /*else if (type == EntityType.PAINTINGS) { + if (ent.getController() instanceof Painting) { + ent.kill(); ++num; } - } else if (type == EntityType.TNT) { - if (ent instanceof TNTPrimed) { - ent.remove(); + }*/ else if (type == EntityType.TNT) { + if (ent.getController() instanceof PrimedTnt) { + ent.kill(); ++num; } - } else if (type == EntityType.XP_ORBS) { + } /*else if (type == EntityType.XP_ORBS) { if (ent instanceof ExperienceOrb) { - ent.remove(); + ent.kill(); ++num; } - } - }*/ + }*/ + } return num; } @@ -636,9 +643,7 @@ public class SpoutWorld extends LocalWorld { @Override public void checkLoadedChunk(Vector pt) { - /*if (!world.isChunkLoaded(pt.getBlockX() >> 4, pt.getBlockZ() >> 4)) { - world.loadChunk(pt.getBlockX() >> 4, pt.getBlockZ() >> 4); - }*/ + world.getChunk(pt.getBlockX() << Chunk.CHUNK_SIZE_BITS, pt.getBlockY() << Chunk.CHUNK_SIZE_BITS, pt.getBlockZ() << Chunk.CHUNK_SIZE_BITS); } @Override