Add food ticking for players if /npc ai is enabled, update player pose and xp ticks

This commit is contained in:
fullwall 2024-03-05 10:47:37 +08:00
parent b6e6a66eb3
commit 4bfededf7a
12 changed files with 86 additions and 18 deletions

View File

@ -278,7 +278,13 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder, Skinnable
}
updateAI();
cs();
if (npc.useMinecraftAI()) {
foodData.a(this);
}
if (npc.data().get(NPC.Metadata.PICKUP_ITEMS, false)) {
if (this.bA > 0) {
--this.bA;
}
AxisAlignedBB axisalignedbb;
if (this.isPassenger() && !this.getVehicle().dead) {
axisalignedbb = this.getBoundingBox().a(this.getVehicle().getBoundingBox()).grow(1.0, 0.0, 1.0);
@ -291,6 +297,7 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder, Skinnable
}
}
}
cJ();
}
@Override

View File

@ -63,7 +63,6 @@ import net.minecraft.server.v1_11_R1.SoundEffect;
import net.minecraft.server.v1_11_R1.WorldServer;
public class EntityHumanNPC extends EntityPlayer implements NPCHolder, SkinnableEntity {
private final Map<PathType, Float> bz = Maps.newEnumMap(PathType.class);
private PlayerControllerJump controllerJump;
private PlayerControllerMove controllerMove;
private final Map<EnumItemSlot, ItemStack> equipmentCache = Maps.newEnumMap(EnumItemSlot.class);
@ -72,6 +71,7 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder, Skinnable
private PlayerNavigation navigation;
private final CitizensNPC npc;
private final Location packetLocationCache = new Location(null, 0, 0, 0);
private final Map<PathType, Float> pathtypes = Maps.newEnumMap(PathType.class);
private final SkinPacketTracker skinTracker;
public EntityHumanNPC(MinecraftServer minecraftServer, WorldServer world, GameProfile gameProfile,
@ -103,11 +103,11 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder, Skinnable
}
public float a(PathType pathtype) {
return this.bz.containsKey(pathtype) ? this.bz.get(pathtype) : pathtype.a();
return this.pathtypes.containsKey(pathtype) ? this.pathtypes.get(pathtype) : pathtype.a();
}
public void a(PathType pathtype, float f) {
this.bz.put(pathtype, f);
this.pathtypes.put(pathtype, f);
}
@Override
@ -340,7 +340,13 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder, Skinnable
}
updateAI();
ct();
if (npc.useMinecraftAI()) {
foodData.a(this);
}
if (npc.data().get(NPC.Metadata.PICKUP_ITEMS, false)) {
if (this.bz > 0) {
--this.bz;
}
AxisAlignedBB axisalignedbb;
if (this.isPassenger() && !this.getVehicle().dead) {
axisalignedbb = this.getBoundingBox().b(this.getVehicle().getBoundingBox()).grow(1.0, 0.0, 1.0);
@ -353,6 +359,7 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder, Skinnable
}
}
}
cL();
}
public void setMoveDestination(double x, double y, double z, double speed) {

View File

@ -357,7 +357,13 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder, Skinnable
}
updateAI();
cB();
if (npc.useMinecraftAI()) {
foodData.a(this);
}
if (npc.data().get(NPC.Metadata.PICKUP_ITEMS, false)) {
if (this.bD > 0) {
--this.bD;
}
AxisAlignedBB axisalignedbb;
if (this.isPassenger() && !this.getVehicle().dead) {
axisalignedbb = this.getBoundingBox().b(this.getVehicle().getBoundingBox()).grow(1.0, 0.0, 1.0);
@ -370,6 +376,7 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder, Skinnable
}
}
}
cT();
}
public void setMoveDestination(double x, double y, double z, double speed) {

View File

@ -333,7 +333,13 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder, Skinnable
}
updateAI();
cN();
if (npc.useMinecraftAI()) {
foodData.a(this);
}
if (npc.data().get(NPC.Metadata.PICKUP_ITEMS, false)) {
if (this.bJ > 0) {
--this.bJ;
}
AxisAlignedBB axisalignedbb;
if (this.isPassenger() && !this.getVehicle().dead) {
axisalignedbb = this.getBoundingBox().b(this.getVehicle().getBoundingBox()).grow(1.0, 0.0, 1.0);
@ -346,6 +352,7 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder, Skinnable
}
}
}
dh();
}
public void setMoveDestination(double x, double y, double z, double speed) {

View File

@ -338,7 +338,13 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder, Skinnable
}
updateAI();
collideNearby();
if (npc.useMinecraftAI()) {
foodData.a(this);
}
if (npc.data().get(NPC.Metadata.PICKUP_ITEMS, false)) {
if (this.bF > 0) {
--this.bF;
}
AxisAlignedBB axisalignedbb;
if (this.isPassenger() && !this.getVehicle().dead) {
axisalignedbb = this.getBoundingBox().b(this.getVehicle().getBoundingBox()).grow(1.0, 0.0, 1.0);
@ -351,6 +357,7 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder, Skinnable
}
}
}
dB();
}
public void setMoveDestination(double x, double y, double z, double speed) {

View File

@ -384,8 +384,13 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder, Skinnable
boolean navigating = npc.getNavigator().isNavigating();
updatePackets(navigating);
npc.update();
if (npc.useMinecraftAI()) {
foodData.a(this);
}
if (npc.data().get(NPC.Metadata.PICKUP_ITEMS, false)) {
if (this.bC > 0) {
--this.bC;
}
AxisAlignedBB axisalignedbb;
if (this.isPassenger() && !this.getVehicle().dead) {
axisalignedbb = this.getBoundingBox().b(this.getVehicle().getBoundingBox()).grow(1.0, 0.0, 1.0);
@ -398,6 +403,7 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder, Skinnable
}
}
}
dX();
}
public void updateAI() {

View File

@ -349,7 +349,13 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder, Skinnable
boolean navigating = npc.getNavigator().isNavigating();
updatePackets(navigating);
npc.update();
if (npc.useMinecraftAI()) {
foodData.a(this);
}
if (npc.data().get(NPC.Metadata.PICKUP_ITEMS, false)) {
if (this.bu > 0) {
--this.bu;
}
AxisAlignedBB axisalignedbb;
if (this.isPassenger() && !this.getVehicle().dead) {
axisalignedbb = this.getBoundingBox().b(this.getVehicle().getBoundingBox()).grow(1.0, 0.0, 1.0);
@ -362,16 +368,7 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder, Skinnable
}
}
}
/*
double diff = this.yaw - this.aK;
if (diff != 40 && diff != -40) {
++this.yawUpdateRequiredTicks;
}
if (this.yawUpdateRequiredTicks > 5) {
this.yaw = (diff > -40 && diff < 0) || (diff > 0 && diff > 40) ? this.aK - 40 : this.aK + 40;
this.yawUpdateRequiredTicks = 0;
}
*/
eu();
}
private void updatePackets(boolean navigating) {

View File

@ -144,8 +144,13 @@ public class EntityHumanNPC extends ServerPlayer implements NPCHolder, Skinnable
this.onGround = false;
}
pushEntities();
if (npc.useMinecraftAI()) {
foodData.tick(this);
}
if (npc.data().get(NPC.Metadata.PICKUP_ITEMS, false)) {
if (this.takeXpDelay > 0) {
--this.takeXpDelay;
}
AABB axisalignedbb;
if (this.isPassenger() && !this.getVehicle().isRemoved()) {
axisalignedbb = this.getBoundingBox().minmax(this.getVehicle().getBoundingBox()).inflate(1.0, 0.0, 1.0);
@ -156,6 +161,7 @@ public class EntityHumanNPC extends ServerPlayer implements NPCHolder, Skinnable
entity.playerTouch(this);
}
}
updatePlayerPose();
}
@Override

View File

@ -145,8 +145,13 @@ public class EntityHumanNPC extends ServerPlayer implements NPCHolder, Skinnable
this.onGround = false;
}
pushEntities();
if (npc.useMinecraftAI()) {
foodData.tick(this);
}
if (npc.data().get(NPC.Metadata.PICKUP_ITEMS, false)) {
if (this.takeXpDelay > 0) {
--this.takeXpDelay;
}
AABB axisalignedbb;
if (this.isPassenger() && !this.getVehicle().isRemoved()) {
axisalignedbb = this.getBoundingBox().minmax(this.getVehicle().getBoundingBox()).inflate(1.0, 0.0, 1.0);
@ -157,6 +162,7 @@ public class EntityHumanNPC extends ServerPlayer implements NPCHolder, Skinnable
entity.playerTouch(this);
}
}
updatePlayerPose();
}
@Override

View File

@ -138,8 +138,13 @@ public class EntityHumanNPC extends ServerPlayer implements NPCHolder, Skinnable
this.onGround = false;
}
pushEntities();
if (npc.useMinecraftAI()) {
foodData.tick(this);
}
if (npc.data().get(NPC.Metadata.PICKUP_ITEMS, false)) {
if (this.takeXpDelay > 0) {
--this.takeXpDelay;
}
AABB axisalignedbb;
if (this.isPassenger() && !this.getVehicle().isRemoved()) {
axisalignedbb = this.getBoundingBox().minmax(this.getVehicle().getBoundingBox()).inflate(1.0, 0.0, 1.0);
@ -150,6 +155,7 @@ public class EntityHumanNPC extends ServerPlayer implements NPCHolder, Skinnable
entity.playerTouch(this);
}
}
updatePlayerPose();
}
@Override

View File

@ -141,8 +141,13 @@ public class EntityHumanNPC extends ServerPlayer implements NPCHolder, Skinnable
this.onGround = false;
}
pushEntities();
if (npc.useMinecraftAI()) {
foodData.tick(this);
}
if (npc.data().get(NPC.Metadata.PICKUP_ITEMS, false)) {
if (this.takeXpDelay > 0) {
--this.takeXpDelay;
}
AABB axisalignedbb;
if (this.isPassenger() && !this.getVehicle().isRemoved()) {
axisalignedbb = this.getBoundingBox().minmax(this.getVehicle().getBoundingBox()).inflate(1.0, 0.0, 1.0);
@ -153,6 +158,7 @@ public class EntityHumanNPC extends ServerPlayer implements NPCHolder, Skinnable
entity.playerTouch(this);
}
}
updatePlayerPose();
}
@Override

View File

@ -280,7 +280,13 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder, Skinnable
}
updateAI();
bL();
if (npc.useMinecraftAI()) {
foodData.a(this);
}
if (npc.data().get(NPC.Metadata.PICKUP_ITEMS, false)) {
if (this.bp > 0) {
--this.bp;
}
AxisAlignedBB axisalignedbb = null;
if (this.vehicle != null && !this.vehicle.dead) {
axisalignedbb = this.getBoundingBox().a(this.vehicle.getBoundingBox()).grow(1.0, 0.0, 1.0);