Added support for features added to Spout (now depends on Vanilla)

This commit is contained in:
zml2008 2012-03-20 17:53:48 -07:00
parent 86011a0d0d
commit 0bd3b346fc
3 changed files with 57 additions and 56 deletions

View File

@ -32,7 +32,7 @@
</repository> </repository>
<repository> <repository>
<id>spout-repo</id> <id>spout-repo</id>
<url>http://nexus.spout.org/content/groups/public/</url> <url>http://repo.spout.org/</url>
</repository> </repository>
</repositories> </repositories>
@ -90,6 +90,11 @@
<artifactId>spoutapi</artifactId> <artifactId>spoutapi</artifactId>
<version>dev-SNAPSHOT</version> <version>dev-SNAPSHOT</version>
</dependency> </dependency>
<dependency>
<groupId>org.spout</groupId>
<artifactId>vanilla</artifactId>
<version>dev-SNAPSHOT</version>
</dependency>
</dependencies> </dependencies>
<build> <build>

View File

@ -30,6 +30,7 @@ import com.sk89q.worldedit.blocks.BlockID;
import com.sk89q.worldedit.blocks.ItemType; import com.sk89q.worldedit.blocks.ItemType;
import org.spout.api.inventory.Inventory; import org.spout.api.inventory.Inventory;
import org.spout.api.inventory.ItemStack; import org.spout.api.inventory.ItemStack;
import org.spout.api.material.Material;
import org.spout.api.material.MaterialData; import org.spout.api.material.MaterialData;
import org.spout.api.player.Player; import org.spout.api.player.Player;
@ -77,11 +78,11 @@ public class SpoutPlayerBlockBag extends BlockBag {
*/ */
@Override @Override
public void fetchItem(BaseItem item) throws BlockBagException { public void fetchItem(BaseItem item) throws BlockBagException {
final int id = item.getType(); final short id = (short)item.getType();
final int damage = item.getDamage(); final short damage = item.getDamage();
int amount = (item instanceof BaseItemStack) ? ((BaseItemStack) item).getAmount() : 1; int amount = (item instanceof BaseItemStack) ? ((BaseItemStack) item).getAmount() : 1;
assert(amount == 1); assert(amount == 1);
boolean usesDamageValue = ItemType.usesDamageValue(id); final Material mat = MaterialData.getMaterial(id, damage);
if (id == BlockID.AIR) { if (id == BlockID.AIR) {
throw new IllegalArgumentException("Can't fetch air block"); throw new IllegalArgumentException("Can't fetch air block");
@ -98,13 +99,8 @@ public class SpoutPlayerBlockBag extends BlockBag {
continue; continue;
} }
if (bukkitItem.getMaterial().getId() != id) { if (!bukkitItem.getMaterial().equals(mat)) {
// Type id doesn't fit // Type id or damage value doesn't fit
continue;
}
if (usesDamageValue && bukkitItem.getDamage() != damage) {
// Damage value doesn't fit.
continue; continue;
} }
@ -138,10 +134,10 @@ public class SpoutPlayerBlockBag extends BlockBag {
@Override @Override
public void storeItem(BaseItem item) throws BlockBagException { public void storeItem(BaseItem item) throws BlockBagException {
final int id = item.getType(); 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; int amount = (item instanceof BaseItemStack) ? ((BaseItemStack) item).getAmount() : 1;
assert(amount <= 64); assert(amount <= mat.getMaxStackSize());
boolean usesDamageValue = ItemType.usesDamageValue(id);
if (id == BlockID.AIR) { if (id == BlockID.AIR) {
throw new IllegalArgumentException("Can't store air block"); throw new IllegalArgumentException("Can't store air block");
@ -164,13 +160,8 @@ public class SpoutPlayerBlockBag extends BlockBag {
continue; continue;
} }
if (bukkitItem.getMaterial().getId() != id) { if (!bukkitItem.getMaterial().equals(mat)) {
// Type id doesn't fit // Type id or damage value doesn't fit
continue;
}
if (usesDamageValue && bukkitItem.getDamage() != damage) {
// Damage value doesn't fit.
continue; continue;
} }
@ -179,23 +170,23 @@ public class SpoutPlayerBlockBag extends BlockBag {
// Unlimited // Unlimited
return; return;
} }
if (currentAmount >= 64) { if (currentAmount >= mat.getMaxStackSize()) {
// Full stack // Full stack
continue; continue;
} }
int spaceLeft = 64 - currentAmount; int spaceLeft = mat.getMaxStackSize() - currentAmount;
if (spaceLeft >= amount) { if (spaceLeft >= amount) {
bukkitItem.setAmount(currentAmount + amount); bukkitItem.setAmount(currentAmount + amount);
return; return;
} }
bukkitItem.setAmount(64); bukkitItem.setAmount(mat.getMaxStackSize());
amount -= spaceLeft; amount -= spaceLeft;
} }
if (freeSlot > -1) { if (freeSlot > -1) {
items[freeSlot] = new ItemStack(MaterialData.getMaterial((short)id), amount); items[freeSlot] = new ItemStack(mat, amount);
return; return;
} }

View File

@ -30,8 +30,17 @@ import com.sk89q.worldedit.blocks.BaseItemStack;
import com.sk89q.worldedit.regions.Region; import com.sk89q.worldedit.regions.Region;
import com.sk89q.worldedit.util.TreeGenerator; import com.sk89q.worldedit.util.TreeGenerator;
import org.spout.api.entity.Entity;
import org.spout.api.geo.World; 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.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 { public class SpoutWorld extends LocalWorld {
private World world; private World world;
@ -381,10 +390,8 @@ public class SpoutWorld extends LocalWorld {
*/ */
@Override @Override
public void dropItem(Vector pt, BaseItemStack item) { public void dropItem(Vector pt, BaseItemStack item) {
/*ItemStack bukkitItem = new ItemStack(item.getType(), item.getAmount(), ItemStack bukkitItem = new ItemStack(MaterialData.getMaterial((short)item.getType(), item.getDamage()), item.getAmount(), item.getDamage());
(byte) item.getDamage()); world.createAndSpawnEntity(SpoutUtil.toPoint(world, pt), new Item(bukkitItem, new Vector3(pt.getX(), pt.getY(), pt.getZ())));
world.dropItemNaturally(SpoutUtil.toLocation(world, pt), bukkitItem);*/
} }
/** /**
@ -446,51 +453,51 @@ public class SpoutWorld extends LocalWorld {
@Override @Override
public int removeEntities(EntityType type, Vector origin, int radius) { public int removeEntities(EntityType type, Vector origin, int radius) {
int num = 0; int num = 0;
/*double radiusSq = radius * radius; double radiusSq = radius * radius;
for (Entity ent : world.getEntities()) { for (Entity ent : world.getAll()) {
if (radius != -1 if (radius != -1
&& origin.distanceSq(SpoutUtil.toVector(ent.getTransform().getPosition())) > radiusSq) { && origin.distanceSq(SpoutUtil.toVector(ent.getPosition())) > radiusSq) {
continue; continue;
} }
if (type == EntityType.ARROWS) { if (type == EntityType.ARROWS) {
if (ent instanceof Arrow) { if (ent.getController() instanceof Arrow) {
ent.remove(); ent.kill();
++num; ++num;
} }
} else if (type == EntityType.BOATS) { } else if (type == EntityType.BOATS) {
if (ent instanceof Boat) { if (ent.getController() instanceof Boat) {
ent.remove(); ent.kill();
++num; ++num;
} }
} else if (type == EntityType.ITEMS) { } else if (type == EntityType.ITEMS) {
if (ent instanceof Item) { if (ent.getController() instanceof Item) {
ent.remove(); ent.kill();
++num; ++num;
} }
} else if (type == EntityType.MINECARTS) { } else if (type == EntityType.MINECARTS) {
if (ent instanceof Minecart) { if (ent.getController() instanceof Minecart) {
ent.remove(); ent.kill();
++num; ++num;
} }
} else if (type == EntityType.PAINTINGS) { } /*else if (type == EntityType.PAINTINGS) {
if (ent instanceof Painting) { if (ent.getController() instanceof Painting) {
ent.remove(); ent.kill();
++num; ++num;
} }
} else if (type == EntityType.TNT) { }*/ else if (type == EntityType.TNT) {
if (ent instanceof TNTPrimed) { if (ent.getController() instanceof PrimedTnt) {
ent.remove(); ent.kill();
++num; ++num;
} }
} else if (type == EntityType.XP_ORBS) { } /*else if (type == EntityType.XP_ORBS) {
if (ent instanceof ExperienceOrb) { if (ent instanceof ExperienceOrb) {
ent.remove(); ent.kill();
++num; ++num;
} }
} }*/
}*/ }
return num; return num;
} }
@ -636,9 +643,7 @@ public class SpoutWorld extends LocalWorld {
@Override @Override
public void checkLoadedChunk(Vector pt) { public void checkLoadedChunk(Vector pt) {
/*if (!world.isChunkLoaded(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);
world.loadChunk(pt.getBlockX() >> 4, pt.getBlockZ() >> 4);
}*/
} }
@Override @Override