Avoid setting NPC.COLLIDABLE_METADATA on Player NPCs

This commit is contained in:
fullwall 2022-01-20 17:10:52 +08:00
parent b5a2c30476
commit 7683516d62
14 changed files with 42 additions and 14 deletions

View File

@ -1197,6 +1197,7 @@ public class NPCCommands {
key = NPC.Metadata.valueOf(key.toUpperCase()).getKey();
} catch (IllegalArgumentException e) {
}
if (command.equals("set")) {
if (args.argsLength() != 4)
throw new CommandException();

View File

@ -275,6 +275,7 @@ public class Controllable extends Trait implements Toggleable, CommandConfigurab
vel = vel.setX(dXcos * speed * speedMod).setZ(dXsin * speed * speedMod);
}
vel = vel.add(new Vector(
passenger.getVelocity().getX() * speedMod * Setting.CONTROLLABLE_GROUND_DIRECTION_MODIFIER.asDouble(),
0D,
@ -317,9 +318,8 @@ public class Controllable extends Trait implements Toggleable, CommandConfigurab
boolean onGround = NMS.isOnGround(npc.getEntity());
float speedMod = npc.getNavigator().getDefaultParameters()
.modifiedSpeed((onGround ? GROUND_SPEED : AIR_SPEED));
if (!Util.isHorse(npc.getEntity().getType()) || npc.getEntity().getType().name().equals("LLAMA")
|| npc.getEntity().getType().name().equals("TRADER_LLAMA")) {
// just use minecraft horse physics
if (!Util.isHorse(npc.getEntity().getType())) {
// use minecraft horse physics
speed = updateHorizontalSpeed(npc.getEntity(), rider, speed, speedMod);
}

View File

@ -52,7 +52,7 @@ public class Util {
return new Vector(x, y, z);
}
boolean allowed = !npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true)
|| (npc.data().has(NPC.COLLIDABLE_METADATA) && npc.data().get(NPC.COLLIDABLE_METADATA, true));
|| (npc.data().has(NPC.COLLIDABLE_METADATA) && npc.data().<Boolean> get(NPC.COLLIDABLE_METADATA));
if (NPCPushEvent.getHandlerList().getRegisteredListeners().length == 0) {
return allowed ? new Vector(x, y, z) : null;
}

View File

@ -266,7 +266,9 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder, Skinnable
@Override
public boolean isCollidable() {
return npc == null ? super.isCollidable() : npc.data().get(NPC.COLLIDABLE_METADATA, true);
return npc == null ? super.isCollidable()
: npc.data().has(NPC.COLLIDABLE_METADATA) ? npc.data().<Boolean> get(NPC.COLLIDABLE_METADATA)
: !npc.isProtected();
}
public boolean isNavigating() {

View File

@ -293,7 +293,9 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder, Skinnable
@Override
public boolean isCollidable() {
return npc == null ? super.isCollidable() : npc.data().get(NPC.COLLIDABLE_METADATA, true);
return npc == null ? super.isCollidable()
: npc.data().has(NPC.COLLIDABLE_METADATA) ? npc.data().<Boolean> get(NPC.COLLIDABLE_METADATA)
: !npc.isProtected();
}
public boolean isNavigating() {

View File

@ -320,7 +320,9 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder, Skinnable
@Override
public boolean isCollidable() {
return npc == null ? super.isCollidable() : npc.data().get(NPC.COLLIDABLE_METADATA, true);
return npc == null ? super.isCollidable()
: npc.data().has(NPC.COLLIDABLE_METADATA) ? npc.data().<Boolean> get(NPC.COLLIDABLE_METADATA)
: !npc.isProtected();
}
public boolean isNavigating() {

View File

@ -303,7 +303,9 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder, Skinnable
@Override
public boolean isCollidable() {
return npc == null ? super.isCollidable() : npc.data().get(NPC.COLLIDABLE_METADATA, true);
return npc == null ? super.isCollidable()
: npc.data().has(NPC.COLLIDABLE_METADATA) ? npc.data().<Boolean> get(NPC.COLLIDABLE_METADATA)
: !npc.isProtected();
}
public boolean isNavigating() {

View File

@ -299,7 +299,9 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder, Skinnable
@Override
public boolean isCollidable() {
return npc == null ? super.isCollidable() : npc.data().get(NPC.COLLIDABLE_METADATA, true);
return npc == null ? super.isCollidable()
: npc.data().has(NPC.COLLIDABLE_METADATA) ? npc.data().<Boolean> get(NPC.COLLIDABLE_METADATA)
: !npc.isProtected();
}
public boolean isNavigating() {

View File

@ -300,7 +300,9 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder, Skinnable
@Override
public boolean isCollidable() {
return npc == null ? super.isCollidable() : npc.data().get(NPC.COLLIDABLE_METADATA, true);
return npc == null ? super.isCollidable()
: npc.data().has(NPC.COLLIDABLE_METADATA) ? npc.data().<Boolean> get(NPC.COLLIDABLE_METADATA)
: !npc.isProtected();
}
public boolean isNavigating() {

View File

@ -330,7 +330,9 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder, Skinnable
@Override
public boolean isCollidable() {
return npc == null ? super.isCollidable() : npc.data().get(NPC.COLLIDABLE_METADATA, true);
return npc == null ? super.isCollidable()
: npc.data().has(NPC.COLLIDABLE_METADATA) ? npc.data().<Boolean> get(NPC.COLLIDABLE_METADATA)
: !npc.isProtected();
}
public boolean isNavigating() {

View File

@ -371,7 +371,9 @@ public class EntityHumanNPC extends ServerPlayer implements NPCHolder, Skinnable
@Override
public boolean isPushable() {
return npc == null ? super.isPushable() : npc.data().get(NPC.COLLIDABLE_METADATA, true);
return npc == null ? super.isPushable()
: npc.data().has(NPC.COLLIDABLE_METADATA) ? npc.data().<Boolean> get(NPC.COLLIDABLE_METADATA)
: !npc.isProtected();
}
private void moveOnCurrentHeading() {

View File

@ -375,7 +375,9 @@ public class EntityHumanNPC extends ServerPlayer implements NPCHolder, Skinnable
@Override
public boolean isPushable() {
return npc == null ? super.isPushable() : npc.data().get(NPC.COLLIDABLE_METADATA, true);
return npc == null ? super.isPushable()
: npc.data().has(NPC.COLLIDABLE_METADATA) ? npc.data().<Boolean> get(NPC.COLLIDABLE_METADATA)
: !npc.isProtected();
}
private void moveOnCurrentHeading() {

View File

@ -54,6 +54,13 @@ public class RavagerController extends MobEntityController {
}
}
@Override
public boolean canBeControlledByRider() {
return (npc == null || npc.data().<Boolean> get(NPC.Metadata.USE_MINECRAFT_AI, false))
? super.canBeControlledByRider()
: false;
}
@Override
protected boolean canRide(Entity entity) {
if (npc != null && (entity instanceof Boat || entity instanceof AbstractMinecart)) {

View File

@ -101,7 +101,9 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder, Skinnable
@Override
public boolean ae() {
return npc == null ? super.ae() : npc.data().get(NPC.COLLIDABLE_METADATA, true);
return npc == null ? super.ae()
: npc.data().has(NPC.COLLIDABLE_METADATA) ? npc.data().<Boolean> get(NPC.COLLIDABLE_METADATA)
: !npc.isProtected();
}
@Override