Fix /npc villager --profession error message, more sane boundingbox calculation

This commit is contained in:
fullwall 2021-11-27 12:19:19 +08:00
parent caff1e9ba4
commit 3da3cc2ae8
11 changed files with 12 additions and 27 deletions

View File

@ -79,7 +79,7 @@ public class NMS {
public static BoundingBox getCollisionBox(Block block) {
if (block.getType() == Material.AIR) {
return new BoundingBox(0, 0, 0, 0, 0, 0);
return BoundingBox.EMPTY;
}
return BRIDGE.getCollisionBox(block).add(block.getX(), block.getY(), block.getZ());
}

View File

@ -122,8 +122,8 @@ public class Util {
Location center = new Location(bloc.getWorld(), bloc.getBlockX() + 0.5, bloc.getBlockY(),
bloc.getBlockZ() + 0.5);
BoundingBox bb = NMS.getCollisionBox(block);
if (bb != null && bb.maxY < 0.6D) {
center.setY(center.getY() + bb.maxY);
if (bb != null && (bb.maxY - bb.minY) < 0.6D) {
center.setY(center.getY() + (bb.maxY - bb.minY));
}
return center;
}

View File

@ -388,10 +388,7 @@ public class NMSImpl implements NMSBridge {
public BoundingBox getCollisionBox(org.bukkit.block.Block block) {
WorldServer world = ((CraftWorld) block.getWorld()).getHandle();
VoxelShape shape = ((CraftBlock) block).getNMS().getCollisionShape(world, ((CraftBlock) block).getPosition());
AxisAlignedBB aabb = shape.isEmpty()
? ((CraftBlock) block).getNMS().getShape(world, ((CraftBlock) block).getPosition()).getBoundingBox()
: shape.getBoundingBox();
return aabb == null ? BoundingBox.convert(block.getBoundingBox()) : NMSBoundingBox.wrap(aabb);
return shape.isEmpty() ? new BoundingBox(0, 0, 0, 0, 0, 0) : NMSBoundingBox.wrap(shape.getBoundingBox());
}
private float getDragonYaw(Entity handle, double tX, double tZ) {

View File

@ -510,7 +510,7 @@ public class Commands {
if (args.hasValueFlag("profession")) {
Profession parsed = Util.matchEnum(Profession.values(), args.getFlag("profession"));
if (parsed == null) {
throw new CommandException(Messages.INVALID_PROFESSION, args.getString(1),
throw new CommandException(Messages.INVALID_PROFESSION, args.getFlag("profession"),
Joiner.on(',').join(Profession.values()));
}
npc.getOrAddTrait(VillagerProfession.class).setProfession(parsed);

View File

@ -424,10 +424,7 @@ public class NMSImpl implements NMSBridge {
public BoundingBox getCollisionBox(org.bukkit.block.Block block) {
WorldServer world = ((CraftWorld) block.getWorld()).getHandle();
VoxelShape shape = ((CraftBlock) block).getNMS().getCollisionShape(world, ((CraftBlock) block).getPosition());
AxisAlignedBB aabb = shape.isEmpty()
? ((CraftBlock) block).getNMS().getShape(world, ((CraftBlock) block).getPosition()).getBoundingBox()
: shape.getBoundingBox();
return aabb == null ? BoundingBox.convert(block.getBoundingBox()) : NMSBoundingBox.wrap(aabb);
return shape.isEmpty() ? new BoundingBox(0, 0, 0, 0, 0, 0) : NMSBoundingBox.wrap(shape.getBoundingBox());
}
private float getDragonYaw(Entity handle, double tX, double tZ) {

View File

@ -554,7 +554,7 @@ public class Commands {
if (args.hasValueFlag("profession")) {
Profession parsed = Util.matchEnum(Profession.values(), args.getFlag("profession"));
if (parsed == null) {
throw new CommandException(Messages.INVALID_PROFESSION, args.getString(1),
throw new CommandException(Messages.INVALID_PROFESSION, args.getFlag("profession"),
Joiner.on(',').join(Profession.values()));
}
npc.getOrAddTrait(VillagerProfession.class).setProfession(parsed);

View File

@ -432,10 +432,7 @@ public class NMSImpl implements NMSBridge {
public BoundingBox getCollisionBox(org.bukkit.block.Block block) {
WorldServer world = ((CraftWorld) block.getWorld()).getHandle();
VoxelShape shape = ((CraftBlock) block).getNMS().getCollisionShape(world, ((CraftBlock) block).getPosition());
AxisAlignedBB aabb = shape.isEmpty()
? ((CraftBlock) block).getNMS().getShape(world, ((CraftBlock) block).getPosition()).getBoundingBox()
: shape.getBoundingBox();
return aabb == null ? BoundingBox.convert(block.getBoundingBox()) : NMSBoundingBox.wrap(aabb);
return shape.isEmpty() ? new BoundingBox(0, 0, 0, 0, 0, 0) : NMSBoundingBox.wrap(shape.getBoundingBox());
}
private float getDragonYaw(Entity handle, double tX, double tZ) {

View File

@ -554,7 +554,7 @@ public class Commands {
if (args.hasValueFlag("profession")) {
Profession parsed = Util.matchEnum(Profession.values(), args.getFlag("profession"));
if (parsed == null) {
throw new CommandException(Messages.INVALID_PROFESSION, args.getString(1),
throw new CommandException(Messages.INVALID_PROFESSION, args.getFlag("profession"),
Joiner.on(',').join(Profession.values()));
}
npc.getOrAddTrait(VillagerProfession.class).setProfession(parsed);

View File

@ -438,10 +438,7 @@ public class NMSImpl implements NMSBridge {
public BoundingBox getCollisionBox(org.bukkit.block.Block block) {
WorldServer world = ((CraftWorld) block.getWorld()).getHandle();
VoxelShape shape = ((CraftBlock) block).getNMS().getCollisionShape(world, ((CraftBlock) block).getPosition());
AxisAlignedBB aabb = shape.isEmpty()
? ((CraftBlock) block).getNMS().getShape(world, ((CraftBlock) block).getPosition()).getBoundingBox()
: shape.getBoundingBox();
return aabb == null ? BoundingBox.convert(block.getBoundingBox()) : NMSBoundingBox.wrap(aabb);
return shape.isEmpty() ? new BoundingBox(0, 0, 0, 0, 0, 0) : NMSBoundingBox.wrap(shape.getBoundingBox());
}
private float getDragonYaw(Entity handle, double tX, double tZ) {

View File

@ -590,7 +590,7 @@ public class Commands {
if (args.hasValueFlag("profession")) {
Profession parsed = Util.matchEnum(Profession.values(), args.getFlag("profession"));
if (parsed == null) {
throw new CommandException(Messages.INVALID_PROFESSION, args.getString(1),
throw new CommandException(Messages.INVALID_PROFESSION, args.getFlag("profession"),
Joiner.on(',').join(Profession.values()));
}
npc.getOrAddTrait(VillagerProfession.class).setProfession(parsed);

View File

@ -448,10 +448,7 @@ public class NMSImpl implements NMSBridge {
public BoundingBox getCollisionBox(org.bukkit.block.Block block) {
ServerLevel world = ((CraftWorld) block.getWorld()).getHandle();
VoxelShape shape = ((CraftBlock) block).getNMS().getCollisionShape(world, ((CraftBlock) block).getPosition());
AABB aabb = shape.isEmpty()
? ((CraftBlock) block).getNMS().getShape(world, ((CraftBlock) block).getPosition()).bounds()
: shape.bounds();
return aabb == null ? BoundingBox.convert(block.getBoundingBox()) : NMSBoundingBox.wrap(aabb);
return shape.isEmpty() ? new BoundingBox(0, 0, 0, 0, 0, 0) : NMSBoundingBox.wrap(shape.bounds());
}
private float getDragonYaw(Entity handle, double tX, double tZ) {