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. By: Stefan <admin@fearthe1337.com>
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user