summaryrefslogtreecommitdiffstats
path: root/src/main
diff options
context:
space:
mode:
authorStefan <admin@fearthe1337.com>2014-12-14 17:22:59 +0100
committerThinkofdeath <thinkofdeath@spigotmc.org>2014-12-15 14:42:00 +0000
commite1070b9fbb5c50356338d9929bc318c3da8c57f2 (patch)
tree9ff9285a15038171d6ff770945472e1b7ceb37d6 /src/main
parent4207eeffe027b6231b3f4fd416fcf33a55a1c28e (diff)
downloadcraftbukkit-e1070b9fbb5c50356338d9929bc318c3da8c57f2.tar
craftbukkit-e1070b9fbb5c50356338d9929bc318c3da8c57f2.tar.gz
craftbukkit-e1070b9fbb5c50356338d9929bc318c3da8c57f2.tar.lz
craftbukkit-e1070b9fbb5c50356338d9929bc318c3da8c57f2.tar.xz
craftbukkit-e1070b9fbb5c50356338d9929bc318c3da8c57f2.zip
SPIGOT-206 Further checks and fixes for Hanging entities.
Adds an check for existing entities before selecting the location allowing for hanging entities to be spawned in blocks where there already is an hanging entity at the default rotation. Fixes the CraftHanging setRotation function to use the new 1.8 logic.
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/org/bukkit/craftbukkit/CraftWorld.java33
-rw-r--r--src/main/java/org/bukkit/craftbukkit/entity/CraftHanging.java4
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;
}