SPIGOT-5732, SPIGOT-6387: Overhaul Hanging entities
- SPIGOT-5732: Fix issue with spawning leash hitches and painting, by using the right block faces - SPIGOT-6387: Allow hanging entities to be spawned mid air - Use randomize parameter to determine if a random painting should be chosen or not - Return BlockFace self by leash hitches entity - Throw a standardised exception when trying to set a BlockFace to a hanging entity which the entity does not support, instead of using BlockFace south or throwing a null pointer By: DerFrZocker <derrieple@gmail.com>
This commit is contained in:
@@ -29,7 +29,6 @@ public class CraftHanging extends CraftEntity implements Hanging {
|
||||
EnumDirection dir = hanging.getDirection();
|
||||
switch (face) {
|
||||
case SOUTH:
|
||||
default:
|
||||
getHandle().setDirection(EnumDirection.SOUTH);
|
||||
break;
|
||||
case WEST:
|
||||
@@ -41,6 +40,8 @@ public class CraftHanging extends CraftEntity implements Hanging {
|
||||
case EAST:
|
||||
getHandle().setDirection(EnumDirection.EAST);
|
||||
break;
|
||||
default:
|
||||
throw new IllegalArgumentException(String.format("%s is not a valid facing direction", face));
|
||||
}
|
||||
if (!force && !getHandle().generation && !hanging.survives()) {
|
||||
// Revert since it doesn't fit
|
||||
|
||||
@@ -26,6 +26,8 @@ public class CraftItemFrame extends CraftHanging implements ItemFrame {
|
||||
EnumDirection oldDir = hanging.getDirection();
|
||||
EnumDirection newDir = CraftBlock.blockFaceToNotch(face);
|
||||
|
||||
Preconditions.checkArgument(newDir != null, "%s is not a valid facing direction", face);
|
||||
|
||||
getHandle().setDirection(newDir);
|
||||
if (!force && !getHandle().generation && !hanging.survives()) {
|
||||
hanging.setDirection(oldDir);
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package org.bukkit.craftbukkit.entity;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import net.minecraft.world.entity.decoration.EntityLeash;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.craftbukkit.CraftServer;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.LeashHitch;
|
||||
@@ -10,6 +12,19 @@ public class CraftLeash extends CraftHanging implements LeashHitch {
|
||||
super(server, entity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean setFacingDirection(BlockFace face, boolean force) {
|
||||
Preconditions.checkArgument(face == BlockFace.SELF, "%s is not a valid facing direction", face);
|
||||
|
||||
return force || getHandle().generation || getHandle().survives();
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockFace getFacing() {
|
||||
// Leash hitch has no facing direction, so we return self
|
||||
return BlockFace.SELF;
|
||||
}
|
||||
|
||||
@Override
|
||||
public EntityLeash getHandle() {
|
||||
return (EntityLeash) entity;
|
||||
|
||||
Reference in New Issue
Block a user