From 73cf129db763024cb7506d8a7d509bebadb54555 Mon Sep 17 00:00:00 2001 From: CraftBukkit/Spigot Date: Mon, 13 Aug 2012 22:21:10 -0500 Subject: [PATCH] Implement methods for spawning FallingBlocks and add various FallingBlock methods. Adds BUKKIT-2282 By: feildmaster --- .../org/bukkit/craftbukkit/CraftWorld.java | 31 +++++++++++++++++-- .../craftbukkit/entity/CraftFallingSand.java | 22 ++++++++++++- 2 files changed, 49 insertions(+), 4 deletions(-) diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/CraftWorld.java b/paper-server/src/main/java/org/bukkit/craftbukkit/CraftWorld.java index c68767f58e..3208e1c49a 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/CraftWorld.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/CraftWorld.java @@ -785,6 +785,26 @@ public class CraftWorld implements World { return spawn(location, clazz, SpawnReason.CUSTOM); } + public FallingBlock spawnFallingBlock(Location location, org.bukkit.Material material, byte data) throws IllegalArgumentException { + Validate.notNull(location, "Location cannot be null"); + Validate.notNull(material, "Material cannot be null"); + Validate.isTrue(material.isBlock(), "Material must be a block"); + + double x = location.getBlockX() + 0.5; + double y = location.getBlockY() + 0.5; + double z = location.getBlockZ() + 0.5; + + EntityFallingBlock entity = new EntityFallingBlock(world, x, y, z, material.getId(), data); + entity.c = 1; // ticksLived + + world.addEntity(entity, SpawnReason.CUSTOM); + return (FallingBlock) entity.getBukkitEntity(); + } + + public FallingBlock spawnFallingBlock(Location location, int blockId, byte blockData) throws IllegalArgumentException { + return spawnFallingBlock(location, org.bukkit.Material.getMaterial(blockId), blockData); + } + @SuppressWarnings("unchecked") public T spawn(Location location, Class clazz, SpawnReason reason) throws IllegalArgumentException { if (location == null || clazz == null) { @@ -802,8 +822,14 @@ public class CraftWorld implements World { // order is important for some of these if (Boat.class.isAssignableFrom(clazz)) { entity = new EntityBoat(world, x, y, z); - } else if (FallingSand.class.isAssignableFrom(clazz)) { - entity = new EntityFallingBlock(world, x, y, z, 0, 0); + } else if (FallingBlock.class.isAssignableFrom(clazz)) { + x = location.getBlockX(); + y = location.getBlockY(); + z = location.getBlockZ(); + int type = world.getTypeId((int) x, (int) y, (int) z); + int data = world.getData((int) x, (int) y, (int) z); + + entity = new EntityFallingBlock(world, x + 0.5, y + 0.5, z + 0.5, type, data); } else if (Projectile.class.isAssignableFrom(clazz)) { if (Snowball.class.isAssignableFrom(clazz)) { entity = new EntitySnowball(world, x, y, z); @@ -934,7 +960,6 @@ public class CraftWorld implements World { break; case SOUTH: dir = 3; - ; break; } entity = new EntityPainting(world, (int) x, (int) y, (int) z, dir); diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftFallingSand.java b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftFallingSand.java index f6a954553a..b384c77fc3 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftFallingSand.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftFallingSand.java @@ -2,8 +2,8 @@ package org.bukkit.craftbukkit.entity; import net.minecraft.server.EntityFallingBlock; +import org.bukkit.Material; import org.bukkit.craftbukkit.CraftServer; -import org.bukkit.craftbukkit.entity.CraftEntity; import org.bukkit.entity.EntityType; import org.bukkit.entity.FallingSand; @@ -26,4 +26,24 @@ public class CraftFallingSand extends CraftEntity implements FallingSand { public EntityType getType() { return EntityType.FALLING_BLOCK; } + + public Material getMaterial() { + return Material.getMaterial(getBlockId()); + } + + public int getBlockId() { + return getHandle().id; + } + + public byte getBlockData() { + return (byte) getHandle().data; + } + + public boolean getDropItem() { + return getHandle().dropItem; + } + + public void setDropItem(boolean drop) { + getHandle().dropItem = drop; + } }