diff options
Diffstat (limited to 'src/main/java')
-rw-r--r-- | src/main/java/org/bukkit/craftbukkit/CraftWorld.java | 33 | ||||
-rw-r--r-- | src/main/java/org/bukkit/craftbukkit/entity/CraftHanging.java | 4 |
2 files changed, 29 insertions, 8 deletions
diff --git a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java index 9d3be571..4ff9c1ae 100644 --- a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java +++ b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java @@ -5,6 +5,7 @@ import java.util.ArrayList; import java.util.Collection; import java.util.HashSet; import java.util.List; +import java.util.Iterator; import java.util.Random; import java.util.Set; import java.util.UUID; @@ -1023,12 +1024,36 @@ public class CraftWorld implements World { Block block = getBlockAt(location); BlockFace face = BlockFace.SELF; + int width = 16; // 1 full block, also painting smallest size. + int height = 16; // 1 full block, also painting smallest size. + + if (ItemFrame.class.isAssignableFrom(clazz)) { + width = 12; + height = 12; + } else if (LeashHitch.class.isAssignableFrom(clazz)) { + width = 9; + height = 9; + } + BlockFace[] faces = new BlockFace[]{BlockFace.EAST,BlockFace.NORTH,BlockFace.WEST,BlockFace.SOUTH}; - for(BlockFace dir : faces){ + final BlockPosition pos = new BlockPosition((int) x, (int) y, (int) z); + for (BlockFace dir : faces) { net.minecraft.server.Block nmsBlock = CraftMagicNumbers.getBlock(block.getRelative(dir)); - if(nmsBlock.getMaterial().isBuildable() || BlockDiodeAbstract.d(nmsBlock)) { - face = dir; - break; + if (nmsBlock.getMaterial().isBuildable() || BlockDiodeAbstract.d(nmsBlock)) { + boolean taken = false; + AxisAlignedBB bb = EntityHanging.calculateBoundingBox(pos,CraftBlock.blockFaceToNotch(dir).opposite(),width,height); + List<net.minecraft.server.Entity> list = (List<net.minecraft.server.Entity>) world.getEntities(null, bb); + for (Iterator<net.minecraft.server.Entity> it = list.iterator(); !taken && it.hasNext();) { + net.minecraft.server.Entity e = it.next(); + if (e instanceof EntityHanging) { + taken = true; // Hanging entities do not like hanging entities which intersect them. + } + } + + if (!taken) { + face = dir; + break; + } } } diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftHanging.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftHanging.java index 3bf83db1..f9ce5ad3 100644 --- a/src/main/java/org/bukkit/craftbukkit/entity/CraftHanging.java +++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftHanging.java @@ -23,11 +23,8 @@ public class CraftHanging extends CraftEntity implements Hanging { } public boolean setFacingDirection(BlockFace face, boolean force) { - Block block = getLocation().getBlock().getRelative(getAttachedFace()).getRelative(face.getOppositeFace()).getRelative(getFacing()); EntityHanging hanging = getHandle(); - BlockPosition old = hanging.getBlockPosition(); EnumDirection dir = hanging.direction; - hanging.blockPosition = new BlockPosition(block.getX(), block.getY(), block.getZ()); switch (face) { case SOUTH: default: @@ -45,7 +42,6 @@ public class CraftHanging extends CraftEntity implements Hanging { } if (!force && !hanging.survives()) { // Revert since it doesn't fit - hanging.blockPosition = old; hanging.setDirection(dir); return false; } |