Spigot Timings

Overhauls the Timings System adding performance tracking all around the Minecraft Server

By: Aikar <aikar@aikar.co>
This commit is contained in:
CraftBukkit/Spigot
2013-01-10 00:18:11 -05:00
parent 127d8c1595
commit 78524cb95e
16 changed files with 924 additions and 387 deletions

View File

@@ -18,7 +18,7 @@
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.FenceGateBlock;
@@ -138,9 +138,67 @@
@@ -138,9 +138,68 @@
import net.minecraft.world.scores.ScoreHolder;
import net.minecraft.world.scores.Team;
import org.slf4j.Logger;
@@ -33,6 +33,7 @@
+import org.bukkit.entity.Hanging;
+import org.bukkit.entity.LivingEntity;
+import org.bukkit.entity.Vehicle;
+import org.spigotmc.CustomTimingsHandler; // Spigot
+import org.bukkit.event.entity.EntityCombustByEntityEvent;
+import org.bukkit.event.hanging.HangingBreakByEntityEvent;
+import org.bukkit.event.vehicle.VehicleBlockCollisionEvent;
@@ -61,13 +62,13 @@
+// CraftBukkit end
public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess, ScoreHolder {
+
+ // CraftBukkit start
+ private static final int CURRENT_LEVEL = 2;
+ static boolean isLevelAtLeast(CompoundTag tag, int level) {
+ return tag.contains("Bukkit.updateLevel") && tag.getInt("Bukkit.updateLevel") >= level;
+ }
+
+ private CraftEntity bukkitEntity;
+
+ public CraftEntity getBukkitEntity() {
@@ -86,7 +87,7 @@
private static final Logger LOGGER = LogUtils.getLogger();
public static final String ID_TAG = "id";
public static final String PASSENGERS_TAG = "Passengers";
@@ -224,7 +282,7 @@
@@ -224,7 +283,7 @@
private static final EntityDataAccessor<Boolean> DATA_CUSTOM_NAME_VISIBLE = SynchedEntityData.defineId(Entity.class, EntityDataSerializers.BOOLEAN);
private static final EntityDataAccessor<Boolean> DATA_SILENT = SynchedEntityData.defineId(Entity.class, EntityDataSerializers.BOOLEAN);
private static final EntityDataAccessor<Boolean> DATA_NO_GRAVITY = SynchedEntityData.defineId(Entity.class, EntityDataSerializers.BOOLEAN);
@@ -95,7 +96,7 @@
private static final EntityDataAccessor<Integer> DATA_TICKS_FROZEN = SynchedEntityData.defineId(Entity.class, EntityDataSerializers.INT);
private EntityInLevelCallback levelCallback;
private final VecDeltaCodec packetPositionCodec;
@@ -253,7 +311,31 @@
@@ -253,7 +312,32 @@
private final List<Entity.Movement> movementThisTick;
private final Set<BlockState> blocksInside;
private final LongSet visitedBlocks;
@@ -114,6 +115,7 @@
+ // Marks an entity, that it was removed by a plugin via Entity#remove
+ // Main use case currently is for SPIGOT-7487, preventing dropping of leash when leash is removed
+ public boolean pluginRemoved = false;
+ public CustomTimingsHandler tickTimer = org.bukkit.craftbukkit.SpigotTimings.getEntityTimings(this); // Spigot
+ public float getBukkitYaw() {
+ return this.yRot;
@@ -127,7 +129,7 @@
public Entity(EntityType<?> type, Level world) {
this.id = Entity.ENTITY_COUNTER.incrementAndGet();
this.passengers = ImmutableList.of();
@@ -292,7 +374,7 @@
@@ -292,7 +376,7 @@
datawatcher_a.define(Entity.DATA_CUSTOM_NAME, Optional.empty());
datawatcher_a.define(Entity.DATA_SILENT, false);
datawatcher_a.define(Entity.DATA_NO_GRAVITY, false);
@@ -136,7 +138,7 @@
datawatcher_a.define(Entity.DATA_TICKS_FROZEN, 0);
this.defineSynchedData(datawatcher_a);
this.entityData = datawatcher_a.build();
@@ -362,20 +444,36 @@
@@ -362,20 +446,36 @@
}
public void kill(ServerLevel world) {
@@ -175,7 +177,7 @@
public boolean equals(Object object) {
return object instanceof Entity ? ((Entity) object).id == this.id : false;
}
@@ -385,22 +483,34 @@
@@ -385,22 +485,34 @@
}
public void remove(Entity.RemovalReason reason) {
@@ -215,7 +217,7 @@
return this.getPose() == pose;
}
@@ -417,6 +527,33 @@
@@ -417,6 +529,33 @@
}
public void setRot(float yaw, float pitch) {
@@ -249,7 +251,7 @@
this.setYRot(yaw % 360.0F);
this.setXRot(pitch % 360.0F);
}
@@ -462,6 +599,15 @@
@@ -462,6 +601,15 @@
this.baseTick();
}
@@ -265,7 +267,7 @@
public void baseTick() {
ProfilerFiller gameprofilerfiller = Profiler.get();
@@ -475,7 +621,7 @@
@@ -475,7 +623,7 @@
--this.boardingCooldown;
}
@@ -274,7 +276,7 @@
if (this.canSpawnSprintParticle()) {
this.spawnSprintParticle();
}
@@ -514,6 +660,10 @@
@@ -514,6 +662,10 @@
if (this.isInLava()) {
this.lavaHurt();
this.fallDistance *= 0.5F;
@@ -285,7 +287,7 @@
}
this.checkBelowWorld();
@@ -525,7 +675,7 @@
@@ -525,7 +677,7 @@
world = this.level();
if (world instanceof ServerLevel worldserver) {
if (this instanceof Leashable) {
@@ -294,7 +296,7 @@
}
}
@@ -568,15 +718,32 @@
@@ -568,15 +720,32 @@
public void lavaHurt() {
if (!this.fireImmune()) {
@@ -329,7 +331,7 @@
}
}
@@ -587,9 +754,25 @@
@@ -587,9 +756,25 @@
}
public final void igniteForSeconds(float seconds) {
@@ -356,7 +358,7 @@
public void igniteForTicks(int ticks) {
if (this.remainingFireTicks < ticks) {
this.setRemainingFireTicks(ticks);
@@ -610,7 +793,7 @@
@@ -610,7 +795,7 @@
}
protected void onBelowWorld() {
@@ -365,13 +367,18 @@
}
public boolean isFree(double offsetX, double offsetY, double offsetZ) {
@@ -747,8 +930,30 @@
@@ -672,6 +857,7 @@
}
public void move(MoverType type, Vec3 movement) {
+ org.bukkit.craftbukkit.SpigotTimings.entityMoveTimer.startTiming(); // Spigot
if (this.noPhysics) {
this.setPos(this.getX() + movement.x, this.getY() + movement.y, this.getZ() + movement.z);
} else {
@@ -750,6 +936,28 @@
}
}
if (movement.y != vec3d1.y) {
block.updateEntityMovementAfterFallOn(this.level(), this);
+ }
+ }
+
+ // CraftBukkit start
+ if (this.horizontalCollision && this.getBukkitEntity() instanceof Vehicle) {
+ Vehicle vehicle = (Vehicle) this.getBukkitEntity();
@@ -385,22 +392,30 @@
+ bl = bl.getRelative(BlockFace.SOUTH);
+ } else if (movement.z < vec3d1.z) {
+ bl = bl.getRelative(BlockFace.NORTH);
}
+ }
+
+ if (!bl.getType().isAir()) {
+ VehicleBlockCollisionEvent event = new VehicleBlockCollisionEvent(vehicle, bl);
+ this.level.getCraftServer().getPluginManager().callEvent(event);
+ }
}
+ }
+ // CraftBukkit end
+
if (!this.level().isClientSide() || this.isControlledByLocalInstance()) {
Entity.MovementEmission entity_movementemission = this.getMovementEmission();
@@ -1131,7 +1336,21 @@
@@ -764,6 +972,7 @@
gameprofilerfiller.pop();
}
}
+ org.bukkit.craftbukkit.SpigotTimings.entityMoveTimer.stopTiming(); // Spigot
}
private void applyMovementEmissionAndPlaySound(Entity.MovementEmission moveEffect, Vec3 movement, BlockPos landingPos, BlockState landingState) {
@@ -1132,6 +1341,20 @@
protected SoundEvent getSwimHighSpeedSplashSound() {
return SoundEvents.GENERIC_SPLASH;
+ }
}
+
+ // CraftBukkit start - Add delegate methods
+ public SoundEvent getSwimSound0() {
@@ -413,12 +428,12 @@
+
+ public SoundEvent getSwimHighSpeedSplashSound0() {
+ return this.getSwimHighSpeedSplashSound();
}
+ }
+ // CraftBukkit end
public void recordMovementThroughBlocks(Vec3 oldPos, Vec3 newPos) {
this.movementThisTick.add(new Entity.Movement(oldPos, newPos));
@@ -1609,6 +1828,7 @@
@@ -1609,6 +1832,7 @@
this.yo = y;
this.zo = d4;
this.setPos(d3, y, d4);
@@ -426,7 +441,7 @@
}
public void moveTo(Vec3 pos) {
@@ -1861,6 +2081,12 @@
@@ -1861,6 +2085,12 @@
return false;
}
@@ -439,7 +454,7 @@
public void awardKillScore(Entity entityKilled, DamageSource damageSource) {
if (entityKilled instanceof ServerPlayer) {
CriteriaTriggers.ENTITY_KILLED_PLAYER.trigger((ServerPlayer) entityKilled, this, damageSource);
@@ -1889,16 +2115,22 @@
@@ -1889,16 +2119,22 @@
}
public boolean saveAsPassenger(CompoundTag nbt) {
@@ -465,22 +480,21 @@
return true;
}
}
@@ -1909,54 +2141,97 @@
@@ -1909,54 +2145,97 @@
}
public CompoundTag saveWithoutId(CompoundTag nbt) {
- try {
- if (this.vehicle != null) {
- nbt.put("Pos", this.newDoubleList(this.vehicle.getX(), this.getY(), this.vehicle.getZ()));
- } else {
- nbt.put("Pos", this.newDoubleList(this.getX(), this.getY(), this.getZ()));
+ // CraftBukkit start - allow excluding certain data when saving
+ return this.saveWithoutId(nbt, true);
+ }
+
+ public CompoundTag saveWithoutId(CompoundTag nbttagcompound, boolean includeAll) {
+ // CraftBukkit end
+ try {
try {
- if (this.vehicle != null) {
- nbt.put("Pos", this.newDoubleList(this.vehicle.getX(), this.getY(), this.vehicle.getZ()));
- } else {
- nbt.put("Pos", this.newDoubleList(this.getX(), this.getY(), this.getZ()));
+ // CraftBukkit start - selectively save position
+ if (includeAll) {
+ if (this.vehicle != null) {
@@ -584,7 +598,7 @@
}
ListTag nbttaglist;
@@ -1972,10 +2247,10 @@
@@ -1972,10 +2251,10 @@
nbttaglist.add(StringTag.valueOf(s));
}
@@ -597,7 +611,7 @@
if (this.isVehicle()) {
nbttaglist = new ListTag();
iterator = this.getPassengers().iterator();
@@ -1984,17 +2259,22 @@
@@ -1984,17 +2263,22 @@
Entity entity = (Entity) iterator.next();
CompoundTag nbttagcompound1 = new CompoundTag();
@@ -623,7 +637,7 @@
} catch (Throwable throwable) {
CrashReport crashreport = CrashReport.forThrowable(throwable, "Saving entity NBT");
CrashReportCategory crashreportsystemdetails = crashreport.addCategory("Entity being saved");
@@ -2080,6 +2360,45 @@
@@ -2080,6 +2364,45 @@
} else {
throw new IllegalStateException("Entity has invalid position");
}
@@ -669,7 +683,7 @@
} catch (Throwable throwable) {
CrashReport crashreport = CrashReport.forThrowable(throwable, "Loading entity NBT");
CrashReportCategory crashreportsystemdetails = crashreport.addCategory("Entity being loaded");
@@ -2101,6 +2420,12 @@
@@ -2101,6 +2424,12 @@
return entitytypes.canSerialize() && minecraftkey != null ? minecraftkey.toString() : null;
}
@@ -682,7 +696,7 @@
protected abstract void readAdditionalSaveData(CompoundTag nbt);
protected abstract void addAdditionalSaveData(CompoundTag nbt);
@@ -2153,9 +2478,22 @@
@@ -2153,9 +2482,22 @@
if (stack.isEmpty()) {
return null;
} else {
@@ -705,7 +719,7 @@
world.addFreshEntity(entityitem);
return entityitem;
}
@@ -2184,6 +2522,12 @@
@@ -2184,6 +2526,12 @@
if (this.isAlive() && this instanceof Leashable leashable) {
if (leashable.getLeashHolder() == player) {
if (!this.level().isClientSide()) {
@@ -718,7 +732,7 @@
if (player.hasInfiniteMaterials()) {
leashable.removeLeash();
} else {
@@ -2200,6 +2544,13 @@
@@ -2200,6 +2548,13 @@
if (itemstack.is(Items.LEAD) && leashable.canHaveALeashAttachedToIt()) {
if (!this.level().isClientSide()) {
@@ -732,7 +746,7 @@
leashable.setLeashedTo(player, true);
}
@@ -2265,7 +2616,7 @@
@@ -2265,7 +2620,7 @@
}
public boolean showVehicleHealth() {
@@ -741,7 +755,7 @@
}
public boolean startRiding(Entity entity, boolean force) {
@@ -2273,7 +2624,7 @@
@@ -2273,7 +2628,7 @@
return false;
} else if (!entity.couldAcceptPassenger()) {
return false;
@@ -750,7 +764,7 @@
return false;
} else {
for (Entity entity1 = entity; entity1.vehicle != null; entity1 = entity1.vehicle) {
@@ -2285,11 +2636,32 @@
@@ -2285,11 +2640,32 @@
if (!force && (!this.canRide(entity) || !entity.canAddPassenger(this))) {
return false;
} else {
@@ -784,7 +798,7 @@
this.vehicle = entity;
this.vehicle.addPassenger(this);
entity.getIndirectPassengersStream().filter((entity2) -> {
@@ -2318,7 +2690,7 @@
@@ -2318,7 +2694,7 @@
Entity entity = this.vehicle;
this.vehicle = null;
@@ -793,7 +807,7 @@
}
}
@@ -2349,21 +2721,50 @@
@@ -2349,21 +2725,50 @@
}
}
@@ -850,7 +864,7 @@
}
protected boolean canAddPassenger(Entity passenger) {
@@ -2464,7 +2865,7 @@
@@ -2464,7 +2869,7 @@
if (teleporttransition != null) {
ServerLevel worldserver1 = teleporttransition.newLevel();
@@ -859,7 +873,7 @@
this.teleport(teleporttransition);
}
}
@@ -2547,7 +2948,7 @@
@@ -2547,7 +2952,7 @@
}
public boolean isCrouching() {
@@ -868,7 +882,7 @@
}
public boolean isSprinting() {
@@ -2563,7 +2964,7 @@
@@ -2563,7 +2968,7 @@
}
public boolean isVisuallySwimming() {
@@ -877,7 +891,7 @@
}
public boolean isVisuallyCrawling() {
@@ -2571,6 +2972,13 @@
@@ -2571,6 +2976,13 @@
}
public void setSwimming(boolean swimming) {
@@ -891,7 +905,7 @@
this.setSharedFlag(4, swimming);
}
@@ -2624,8 +3032,12 @@
@@ -2624,8 +3036,12 @@
return this.getTeam() != null ? this.getTeam().isAlliedTo(team) : false;
}
@@ -905,7 +919,7 @@
}
public boolean getSharedFlag(int index) {
@@ -2644,7 +3056,7 @@
@@ -2644,7 +3060,7 @@
}
public int getMaxAirSupply() {
@@ -914,7 +928,7 @@
}
public int getAirSupply() {
@@ -2652,7 +3064,18 @@
@@ -2652,7 +3068,18 @@
}
public void setAirSupply(int air) {
@@ -934,7 +948,7 @@
}
public int getTicksFrozen() {
@@ -2679,11 +3102,40 @@
@@ -2679,11 +3106,40 @@
public void thunderHit(ServerLevel world, LightningBolt lightning) {
this.setRemainingFireTicks(this.remainingFireTicks + 1);
@@ -977,7 +991,7 @@
}
public void onAboveBubbleCol(boolean drag) {
@@ -2713,7 +3165,7 @@
@@ -2713,7 +3169,7 @@
this.resetFallDistance();
}
@@ -986,7 +1000,7 @@
return true;
}
@@ -2852,6 +3304,18 @@
@@ -2852,6 +3308,18 @@
if (world instanceof ServerLevel worldserver) {
if (!this.isRemoved()) {
@@ -1005,7 +1019,7 @@
ServerLevel worldserver1 = teleportTarget.newLevel();
boolean flag = worldserver1.dimension() != worldserver.dimension();
@@ -2920,8 +3384,12 @@
@@ -2920,8 +3388,12 @@
} else {
entity.restoreFrom(this);
this.removeAfterChangingDimensions();
@@ -1019,7 +1033,7 @@
Iterator iterator1 = list1.iterator();
while (iterator1.hasNext()) {
@@ -2947,7 +3415,7 @@
@@ -2947,7 +3419,7 @@
}
private void sendTeleportTransitionToRidingPlayers(TeleportTransition teleportTarget) {
@@ -1028,7 +1042,7 @@
Iterator iterator = this.getIndirectPassengers().iterator();
while (iterator.hasNext()) {
@@ -2995,8 +3463,9 @@
@@ -2995,8 +3467,9 @@
}
protected void removeAfterChangingDimensions() {
@@ -1039,7 +1053,7 @@
leashable.removeLeash();
}
@@ -3004,7 +3473,21 @@
@@ -3004,7 +3477,21 @@
public Vec3 getRelativePortalPosition(Direction.Axis portalAxis, BlockUtil.FoundRectangle portalRect) {
return PortalShape.getRelativePosition(portalRect, portalAxis, this.position(), this.getDimensions(this.getPose()));
@@ -1061,7 +1075,7 @@
public boolean canUsePortal(boolean allowVehicles) {
return (allowVehicles || !this.isPassenger()) && this.isAlive();
@@ -3134,10 +3617,16 @@
@@ -3134,10 +3621,16 @@
return (Boolean) this.entityData.get(Entity.DATA_CUSTOM_NAME_VISIBLE);
}
@@ -1081,7 +1095,7 @@
return entity != null;
}
@@ -3187,7 +3676,7 @@
@@ -3187,7 +3680,7 @@
/** @deprecated */
@Deprecated
protected void fixupDimensions() {
@@ -1090,7 +1104,7 @@
EntityDimensions entitysize = this.getDimensions(entitypose);
this.dimensions = entitysize;
@@ -3196,7 +3685,7 @@
@@ -3196,7 +3689,7 @@
public void refreshDimensions() {
EntityDimensions entitysize = this.dimensions;
@@ -1099,7 +1113,7 @@
EntityDimensions entitysize1 = this.getDimensions(entitypose);
this.dimensions = entitysize1;
@@ -3258,10 +3747,29 @@
@@ -3258,10 +3751,29 @@
}
public final void setBoundingBox(AABB boundingBox) {
@@ -1131,7 +1145,7 @@
return this.getDimensions(pose).eyeHeight();
}
@@ -3335,7 +3843,7 @@
@@ -3335,7 +3847,7 @@
}
@Nullable
@@ -1140,7 +1154,7 @@
return null;
}
@@ -3435,7 +3943,7 @@
@@ -3435,7 +3947,7 @@
}
public boolean isControlledByLocalInstance() {
@@ -1149,7 +1163,7 @@
if (entityliving instanceof Player entityhuman) {
return entityhuman.isLocalPlayer();
@@ -3445,7 +3953,7 @@
@@ -3445,7 +3957,7 @@
}
public boolean isControlledByClient() {
@@ -1158,7 +1172,7 @@
return entityliving != null && entityliving.isControlledByClient();
}
@@ -3463,7 +3971,7 @@
@@ -3463,7 +3975,7 @@
return new Vec3((double) f1 * d2 / (double) f3, 0.0D, (double) f2 * d2 / (double) f3);
}
@@ -1167,7 +1181,7 @@
return new Vec3(this.getX(), this.getBoundingBox().maxY, this.getZ());
}
@@ -3489,8 +3997,37 @@
@@ -3489,8 +4001,37 @@
return 1;
}
@@ -1206,7 +1220,7 @@
}
public void lookAt(EntityAnchorArgument.Anchor anchorPoint, Vec3 target) {
@@ -3551,6 +4088,11 @@
@@ -3551,6 +4092,11 @@
vec3d = vec3d.add(vec3d1);
++k1;
}
@@ -1218,7 +1232,7 @@
}
}
}
@@ -3613,7 +4155,7 @@
@@ -3613,7 +4159,7 @@
return new ClientboundAddEntityPacket(this, entityTrackerEntry);
}
@@ -1227,7 +1241,7 @@
return this.type.getDimensions();
}
@@ -3818,8 +4360,16 @@
@@ -3818,8 +4364,16 @@
@Override
public final void setRemoved(Entity.RemovalReason reason) {
@@ -1245,7 +1259,7 @@
}
if (this.removalReason.shouldDestroy()) {
@@ -3827,8 +4377,8 @@
@@ -3827,8 +4381,8 @@
}
this.getPassengers().forEach(Entity::stopRiding);
@@ -1256,7 +1270,7 @@
}
public void unsetRemoved() {
@@ -3887,7 +4437,7 @@
@@ -3887,7 +4441,7 @@
}
public Vec3 getKnownMovement() {

View File

@@ -17,11 +17,10 @@
import net.minecraft.world.entity.projectile.AbstractArrow;
import net.minecraft.world.entity.projectile.Projectile;
import net.minecraft.world.item.AxeItem;
@@ -135,6 +136,30 @@
import net.minecraft.world.scores.PlayerTeam;
@@ -136,6 +137,32 @@
import net.minecraft.world.scores.Scoreboard;
import org.slf4j.Logger;
+
+// CraftBukkit start
+import java.util.ArrayList;
+import java.util.HashSet;
@@ -45,10 +44,13 @@
+import org.bukkit.event.entity.EntityTeleportEvent;
+import org.bukkit.event.player.PlayerItemConsumeEvent;
+// CraftBukkit end
+
+import org.bukkit.craftbukkit.SpigotTimings; // Spigot
+
public abstract class LivingEntity extends Entity implements Attackable {
@@ -174,7 +199,7 @@
private static final Logger LOGGER = LogUtils.getLogger();
@@ -174,7 +201,7 @@
public static final float DEFAULT_BABY_SCALE = 0.5F;
public static final String ATTRIBUTES_FIELD = "attributes";
public static final Predicate<LivingEntity> PLAYER_NOT_WEARING_DISGUISE_ITEM = (entityliving) -> {
@@ -57,7 +59,7 @@
ItemStack itemstack = entityhuman.getItemBySlot(EquipmentSlot.HEAD);
return !itemstack.is(ItemTags.GAZE_DISGUISE_EQUIPMENT);
@@ -210,7 +235,7 @@
@@ -210,7 +237,7 @@
public float yHeadRotO;
public final ElytraAnimationState elytraAnimationState;
@Nullable
@@ -66,7 +68,7 @@
public int lastHurtByPlayerTime;
protected boolean dead;
protected int noActionTime;
@@ -260,7 +285,20 @@
@@ -260,7 +287,20 @@
protected boolean skipDropExperience;
private final EnumMap<EquipmentSlot, Reference2ObjectMap<Enchantment, Set<EnchantmentLocationBasedEffect>>> activeLocationDependentEnchantments;
protected float appliedScale;
@@ -87,7 +89,7 @@
protected LivingEntity(EntityType<? extends LivingEntity> type, Level world) {
super(type, world);
this.lastHandItemStacks = NonNullList.withSize(2, ItemStack.EMPTY);
@@ -276,7 +314,9 @@
@@ -276,7 +316,9 @@
this.activeLocationDependentEnchantments = new EnumMap(EquipmentSlot.class);
this.appliedScale = 1.0F;
this.attributes = new AttributeMap(DefaultAttributes.getSupplier(type));
@@ -98,7 +100,7 @@
this.blocksBuilding = true;
this.rotA = (float) ((Math.random() + 1.0D) * 0.009999999776482582D);
this.reapplyPosition();
@@ -356,7 +396,13 @@
@@ -356,7 +398,13 @@
double d8 = Math.min((double) (0.2F + f / 15.0F), 2.5D);
int i = (int) (150.0D * d8);
@@ -113,7 +115,7 @@
}
}
}
@@ -402,7 +448,7 @@
@@ -402,7 +450,7 @@
}
if (this.isAlive()) {
@@ -122,7 +124,7 @@
Level world1 = this.level();
ServerLevel worldserver1;
double d0;
@@ -424,7 +470,7 @@
@@ -424,7 +472,7 @@
}
if (this.isEyeInFluid(FluidTags.WATER) && !this.level().getBlockState(BlockPos.containing(this.getX(), this.getEyeY(), this.getZ())).is(Blocks.BUBBLE_COLUMN)) {
@@ -131,7 +133,7 @@
if (flag1) {
this.setAirSupply(this.decreaseAirSupply(this.getAirSupply()));
@@ -573,7 +619,7 @@
@@ -573,7 +621,7 @@
++this.deathTime;
if (this.deathTime >= 20 && !this.level().isClientSide() && !this.isRemoved()) {
this.level().broadcastEntityEvent(this, (byte) 60);
@@ -140,7 +142,7 @@
}
}
@@ -629,7 +675,7 @@
@@ -629,7 +677,7 @@
return this.lastHurtByMobTimestamp;
}
@@ -149,28 +151,27 @@
this.lastHurtByPlayer = attacking;
this.lastHurtByPlayerTime = this.tickCount;
}
@@ -679,17 +725,23 @@
@@ -679,17 +727,23 @@
}
public void onEquipItem(EquipmentSlot slot, ItemStack oldStack, ItemStack newStack) {
- if (!this.level().isClientSide() && !this.isSpectator()) {
- boolean flag = newStack.isEmpty() && oldStack.isEmpty();
+ // CraftBukkit start
+ this.onEquipItem(slot, oldStack, newStack, false);
+ }
+
+ public void onEquipItem(EquipmentSlot enumitemslot, ItemStack itemstack, ItemStack itemstack1, boolean silent) {
+ // CraftBukkit end
if (!this.level().isClientSide() && !this.isSpectator()) {
- boolean flag = newStack.isEmpty() && oldStack.isEmpty();
+ boolean flag = itemstack1.isEmpty() && itemstack.isEmpty();
- if (!flag && !ItemStack.isSameItemSameComponents(oldStack, newStack) && !this.firstTick) {
- Equippable equippable = (Equippable) newStack.get(DataComponents.EQUIPPABLE);
+ public void onEquipItem(EquipmentSlot enumitemslot, ItemStack itemstack, ItemStack itemstack1, boolean silent) {
+ // CraftBukkit end
+ if (!this.level().isClientSide() && !this.isSpectator()) {
+ boolean flag = itemstack1.isEmpty() && itemstack.isEmpty();
+ if (!flag && !ItemStack.isSameItemSameComponents(itemstack, itemstack1) && !this.firstTick) {
+ Equippable equippable = (Equippable) itemstack1.get(DataComponents.EQUIPPABLE);
- if (!this.isSilent() && equippable != null && slot == equippable.slot()) {
- this.level().playSeededSound((Player) null, this.getX(), this.getY(), this.getZ(), equippable.equipSound(), this.getSoundSource(), 1.0F, 1.0F, this.random.nextLong());
+ if (!flag && !ItemStack.isSameItemSameComponents(itemstack, itemstack1) && !this.firstTick) {
+ Equippable equippable = (Equippable) itemstack1.get(DataComponents.EQUIPPABLE);
+
+ if (!this.isSilent() && equippable != null && enumitemslot == equippable.slot() && !silent) { // CraftBukkit
+ this.level().playSeededSound((net.minecraft.world.entity.player.Player) null, this.getX(), this.getY(), this.getZ(), equippable.equipSound(), this.getSoundSource(), 1.0F, 1.0F, this.random.nextLong());
}
@@ -180,7 +181,7 @@
this.gameEvent(equippable != null ? GameEvent.EQUIP : GameEvent.UNEQUIP);
}
@@ -699,17 +751,24 @@
@@ -699,17 +753,24 @@
@Override
public void remove(Entity.RemovalReason reason) {
@@ -208,7 +209,7 @@
this.brain.clearMemories();
}
@@ -722,6 +781,7 @@
@@ -722,6 +783,7 @@
mobeffect.onMobRemoved(world, this, reason);
}
@@ -216,13 +217,10 @@
this.activeEffects.clear();
}
@@ -778,8 +838,19 @@
if (mobeffect != null) {
this.activeEffects.put(mobeffect.getEffect(), mobeffect);
}
+ }
+ }
+
@@ -781,6 +843,17 @@
}
}
+ // CraftBukkit start
+ if (nbt.contains("Bukkit.MaxHealth")) {
+ Tag nbtbase = nbt.get("Bukkit.MaxHealth");
@@ -230,13 +228,14 @@
+ this.getAttribute(Attributes.MAX_HEALTH).setBaseValue(((FloatTag) nbtbase).getAsDouble());
+ } else if (nbtbase.getId() == 3) {
+ this.getAttribute(Attributes.MAX_HEALTH).setBaseValue(((IntTag) nbtbase).getAsDouble());
}
}
+ }
+ }
+ // CraftBukkit end
+
if (nbt.contains("Health", 99)) {
this.setHealth(nbt.getFloat("Health"));
@@ -819,9 +890,32 @@
}
@@ -819,9 +892,32 @@
}
@@ -269,7 +268,7 @@
try {
while (iterator.hasNext()) {
Holder<MobEffect> holder = (Holder) iterator.next();
@@ -831,6 +925,12 @@
@@ -831,6 +927,12 @@
this.onEffectUpdated(mobeffect, true, (Entity) null);
})) {
if (!this.level().isClientSide) {
@@ -282,7 +281,7 @@
iterator.remove();
this.onEffectsRemoved(List.of(mobeffect));
}
@@ -841,6 +941,17 @@
@@ -841,6 +943,17 @@
} catch (ConcurrentModificationException concurrentmodificationexception) {
;
}
@@ -300,7 +299,7 @@
if (this.effectsDirty) {
if (!this.level().isClientSide) {
@@ -921,7 +1032,7 @@
@@ -921,7 +1034,7 @@
}
public boolean canAttack(LivingEntity target) {
@@ -309,7 +308,7 @@
}
public boolean canBeSeenAsEnemy() {
@@ -952,17 +1063,36 @@
@@ -952,17 +1065,36 @@
this.entityData.set(LivingEntity.DATA_EFFECT_PARTICLES, List.of());
}
@@ -350,7 +349,7 @@
}
}
@@ -987,24 +1117,55 @@
@@ -987,24 +1119,55 @@
return this.addEffect(effect, (Entity) null);
}
@@ -415,7 +414,7 @@
return flag;
}
}
@@ -1031,14 +1192,40 @@
@@ -1031,14 +1194,40 @@
return this.getType().is(EntityTypeTags.INVERTED_HEALING_AND_HARM);
}
@@ -458,7 +457,7 @@
if (mobeffect != null) {
this.onEffectsRemoved(List.of(mobeffect));
return true;
@@ -1142,20 +1329,55 @@
@@ -1142,20 +1331,55 @@
}
@@ -515,7 +514,7 @@
this.entityData.set(LivingEntity.DATA_HEALTH_ID, Mth.clamp(health, 0.0F, this.getMaxHealth()));
}
@@ -1167,7 +1389,7 @@
@@ -1167,7 +1391,7 @@
public boolean hurtServer(ServerLevel world, DamageSource source, float amount) {
if (this.isInvulnerableTo(world, source)) {
return false;
@@ -524,7 +523,7 @@
return false;
} else if (source.is(DamageTypeTags.IS_FIRE) && this.hasEffect(MobEffects.FIRE_RESISTANCE)) {
return false;
@@ -1182,10 +1404,11 @@
@@ -1182,10 +1406,11 @@
}
float f1 = amount;
@@ -538,7 +537,7 @@
this.hurtCurrentlyUsedShield(amount);
f2 = amount;
amount = 0.0F;
@@ -1202,15 +1425,26 @@
@@ -1202,15 +1427,26 @@
flag = true;
}
@@ -567,7 +566,7 @@
this.walkAnimation.setSpeed(1.5F);
if (Float.isNaN(amount) || Float.isInfinite(amount)) {
amount = Float.MAX_VALUE;
@@ -1218,18 +1452,27 @@
@@ -1218,18 +1454,27 @@
boolean flag1 = true;
@@ -599,7 +598,7 @@
this.hurtDuration = 10;
this.hurtTime = this.hurtDuration;
}
@@ -1243,7 +1486,7 @@
@@ -1243,7 +1488,7 @@
world.broadcastDamageEvent(this, source);
}
@@ -608,7 +607,7 @@
this.markHurt();
}
@@ -1263,7 +1506,7 @@
@@ -1263,7 +1508,7 @@
d1 = source.getSourcePosition().z() - this.getZ();
}
@@ -617,7 +616,7 @@
if (!flag) {
this.indicateDamage(d0, d1);
}
@@ -1282,7 +1525,7 @@
@@ -1282,7 +1527,7 @@
this.playHurtSound(source);
}
@@ -626,7 +625,7 @@
if (flag2) {
this.lastDamageSource = source;
@@ -1329,10 +1572,10 @@
@@ -1329,10 +1574,10 @@
}
@Nullable
@@ -639,7 +638,7 @@
this.lastHurtByPlayerTime = 100;
this.lastHurtByPlayer = entityhuman;
return entityhuman;
@@ -1342,8 +1585,8 @@
@@ -1342,8 +1587,8 @@
this.lastHurtByPlayerTime = 100;
LivingEntity entityliving = entitywolf.getOwner();
@@ -650,7 +649,7 @@
this.lastHurtByPlayer = entityhuman1;
} else {
@@ -1363,7 +1606,7 @@
@@ -1363,7 +1608,7 @@
}
protected void blockedByShield(LivingEntity target) {
@@ -659,7 +658,7 @@
}
private boolean checkTotemDeathProtection(DamageSource source) {
@@ -1375,20 +1618,33 @@
@@ -1375,20 +1620,33 @@
InteractionHand[] aenumhand = InteractionHand.values();
int i = aenumhand.length;
@@ -697,7 +696,7 @@
ServerPlayer entityplayer = (ServerPlayer) this;
entityplayer.awardStat(Stats.ITEM_USED.get(itemstack.getItem()));
@@ -1512,14 +1768,22 @@
@@ -1512,14 +1770,22 @@
BlockState iblockdata = Blocks.WITHER_ROSE.defaultBlockState();
if (this.level().getBlockState(blockposition).isAir() && iblockdata.canSurvive(this.level(), blockposition)) {
@@ -722,7 +721,7 @@
this.level().addFreshEntity(entityitem);
}
}
@@ -1530,22 +1794,37 @@
@@ -1530,22 +1796,37 @@
protected void dropAllDeathLoot(ServerLevel world, DamageSource damageSource) {
boolean flag = this.lastHurtByPlayerTime > 0;
@@ -764,7 +763,7 @@
}
protected void dropCustomDeathLoot(ServerLevel world, DamageSource source, boolean causedByPlayer) {}
@@ -1612,19 +1891,31 @@
@@ -1612,19 +1893,31 @@
}
public void knockback(double strength, double x, double z) {
@@ -803,7 +802,7 @@
}
}
@@ -1683,6 +1974,20 @@
@@ -1683,6 +1976,20 @@
return new LivingEntity.Fallsounds(SoundEvents.GENERIC_SMALL_FALL, SoundEvents.GENERIC_BIG_FALL);
}
@@ -824,7 +823,7 @@
public Optional<BlockPos> getLastClimbablePos() {
return this.lastClimbablePos;
}
@@ -1757,9 +2062,14 @@
@@ -1757,9 +2064,14 @@
int i = this.calculateFallDamage(fallDistance, damageMultiplier);
if (i > 0) {
@@ -840,7 +839,7 @@
return true;
} else {
return flag;
@@ -1830,7 +2140,7 @@
@@ -1830,7 +2142,7 @@
protected float getDamageAfterArmorAbsorb(DamageSource source, float amount) {
if (!source.is(DamageTypeTags.BYPASSES_ARMOR)) {
@@ -849,7 +848,7 @@
amount = CombatRules.getDamageAfterAbsorb(this, amount, source, (float) this.getArmorValue(), (float) this.getAttributeValue(Attributes.ARMOR_TOUGHNESS));
}
@@ -1841,7 +2151,8 @@
@@ -1841,7 +2153,8 @@
if (source.is(DamageTypeTags.BYPASSES_EFFECTS)) {
return amount;
} else {
@@ -859,7 +858,7 @@
int i = (this.getEffect(MobEffects.DAMAGE_RESISTANCE).getAmplifier() + 1) * 5;
int j = 25 - i;
float f1 = amount * (float) j;
@@ -1884,18 +2195,144 @@
@@ -1884,18 +2197,144 @@
}
}
@@ -886,7 +885,7 @@
+ };
+ float freezingModifier = freezing.apply((double) f).floatValue();
+ f += freezingModifier;
+
+ com.google.common.base.Function<Double, Double> hardHat = new com.google.common.base.Function<Double, Double>() {
+ @Override
+ public Double apply(Double f) {
@@ -916,7 +915,7 @@
+ };
+ float armorModifier = armor.apply((double) f).floatValue();
+ f += armorModifier;
+
+ com.google.common.base.Function<Double, Double> resistance = new com.google.common.base.Function<Double, Double>() {
+ @Override
+ public Double apply(Double f) {
@@ -1013,7 +1012,7 @@
if (entity instanceof ServerPlayer) {
ServerPlayer entityplayer = (ServerPlayer) entity;
@@ -1904,13 +2341,48 @@
@@ -1904,13 +2343,48 @@
}
}
@@ -1066,28 +1065,27 @@
}
public CombatTracker getCombatTracker() {
@@ -1935,9 +2407,19 @@
@@ -1935,8 +2409,18 @@
}
public final void setArrowCount(int stuckArrowCount) {
- this.entityData.set(LivingEntity.DATA_ARROW_COUNT_ID, stuckArrowCount);
+ // CraftBukkit start
+ this.setArrowCount(stuckArrowCount, false);
}
+ }
+
+ public final void setArrowCount(int i, boolean flag) {
+ ArrowBodyCountChangeEvent event = CraftEventFactory.callArrowBodyCountChangeEvent(this, this.getArrowCount(), i, flag);
+ if (event.isCancelled()) {
+ return;
+ }
+ this.entityData.set(LivingEntity.DATA_ARROW_COUNT_ID, event.getNewAmount());
+ }
}
+ // CraftBukkit end
+
public final int getStingerCount() {
return (Integer) this.entityData.get(LivingEntity.DATA_STINGER_COUNT_ID);
}
@@ -1999,7 +2481,7 @@
@@ -1999,7 +2483,7 @@
this.playSound(soundeffect, this.getSoundVolume(), (this.random.nextFloat() - this.random.nextFloat()) * 0.2F + 1.0F);
}
@@ -1096,7 +1094,7 @@
this.setHealth(0.0F);
this.die(this.damageSources().generic());
}
@@ -2182,6 +2664,12 @@
@@ -2182,6 +2666,12 @@
public abstract ItemStack getItemBySlot(EquipmentSlot slot);
@@ -1109,7 +1107,7 @@
public abstract void setItemSlot(EquipmentSlot slot, ItemStack stack);
public Iterable<ItemStack> getHandSlots() {
@@ -2494,7 +2982,7 @@
@@ -2494,7 +2984,7 @@
}
@@ -1118,7 +1116,7 @@
Vec3 vec3d1 = this.getRiddenInput(controllingPlayer, movementInput);
this.tickRidden(controllingPlayer, vec3d1);
@@ -2507,13 +2995,13 @@
@@ -2507,13 +2997,13 @@
}
@@ -1135,7 +1133,7 @@
return this.getSpeed();
}
@@ -2571,7 +3059,7 @@
@@ -2571,7 +3061,7 @@
double d1 = Mth.clamp(motion.z, -0.15000000596046448D, 0.15000000596046448D);
double d2 = Math.max(motion.y, -0.15000000596046448D);
@@ -1144,7 +1142,7 @@
d2 = 0.0D;
}
@@ -2586,7 +3074,7 @@
@@ -2586,7 +3076,7 @@
}
protected float getFlyingSpeed() {
@@ -1153,7 +1151,15 @@
}
public float getSpeed() {
@@ -2634,7 +3122,7 @@
@@ -2604,6 +3094,7 @@
@Override
public void tick() {
+ SpigotTimings.timerEntityBaseTick.startTiming(); // Spigot
super.tick();
this.updatingUsingItem();
this.updateSwimAmount();
@@ -2634,7 +3125,7 @@
}
}
@@ -1162,8 +1168,21 @@
if (this.tickCount % 20 == 0) {
this.getCombatTracker().recheckStatus();
}
@@ -2741,7 +3229,7 @@
@@ -2645,7 +3136,9 @@
}
if (!this.isRemoved()) {
+ SpigotTimings.timerEntityBaseTick.stopTiming(); // Spigot
this.aiStep();
+ SpigotTimings.timerEntityTickRest.startTiming(); // Spigot
}
double d0 = this.getX() - this.xo;
@@ -2739,9 +3232,10 @@
}
this.elytraAnimationState.tick();
+ SpigotTimings.timerEntityTickRest.stopTiming(); // Spigot
}
- public void detectEquipmentUpdates() {
@@ -1171,7 +1190,28 @@
Map<EquipmentSlot, ItemStack> map = this.collectEquipmentChanges();
if (map != null) {
@@ -3000,7 +3488,7 @@
@@ -2945,6 +3439,7 @@
ProfilerFiller gameprofilerfiller = Profiler.get();
gameprofilerfiller.push("ai");
+ SpigotTimings.timerEntityAI.startTiming(); // Spigot
if (this.isImmobile()) {
this.jumping = false;
this.xxa = 0.0F;
@@ -2954,6 +3449,7 @@
this.serverAiStep();
gameprofilerfiller.pop();
}
+ SpigotTimings.timerEntityAI.stopTiming(); // Spigot
gameprofilerfiller.pop();
gameprofilerfiller.push("jump");
@@ -2996,11 +3492,12 @@
this.resetFallDistance();
}
+ SpigotTimings.timerEntityAIMove.startTiming(); // Spigot
label112:
{
LivingEntity entityliving = this.getControllingPassenger();
@@ -1180,7 +1220,25 @@
if (this.isAlive()) {
this.travelRidden(entityhuman, vec3d1);
break label112;
@@ -3063,6 +3551,7 @@
@@ -3009,6 +3506,7 @@
this.travel(vec3d1);
}
+ SpigotTimings.timerEntityAIMove.stopTiming(); // Spigot
if (!this.level().isClientSide() || this.isControlledByLocalInstance()) {
this.applyEffectsFromBlocks();
@@ -3044,7 +3542,9 @@
this.checkAutoSpinAttack(axisalignedbb, this.getBoundingBox());
}
+ SpigotTimings.timerEntityAICollision.startTiming(); // Spigot
this.pushEntities();
+ SpigotTimings.timerEntityAICollision.stopTiming(); // Spigot
gameprofilerfiller.pop();
world = this.level();
if (world instanceof ServerLevel worldserver) {
@@ -3063,6 +3563,7 @@
this.checkSlowFallDistance();
if (!this.level().isClientSide) {
if (!this.canGlide()) {
@@ -1188,7 +1246,7 @@
this.setSharedFlag(7, false);
return;
}
@@ -3113,7 +3602,7 @@
@@ -3113,7 +3614,7 @@
Level world = this.level();
if (!(world instanceof ServerLevel worldserver)) {
@@ -1197,7 +1255,7 @@
} else {
List list = this.level().getEntities((Entity) this, this.getBoundingBox(), EntitySelector.pushableBy(this));
@@ -3305,15 +3794,22 @@
@@ -3305,15 +3806,22 @@
@Override
public boolean isPickable() {
@@ -1222,7 +1280,7 @@
public float getYHeadRot() {
return this.yHeadRot;
}
@@ -3483,8 +3979,31 @@
@@ -3483,8 +3991,31 @@
this.releaseUsingItem();
} else {
if (!this.useItem.isEmpty() && this.isUsingItem()) {
@@ -1255,7 +1313,7 @@
if (itemstack != this.useItem) {
this.setItemInHand(enumhand, itemstack);
}
@@ -3568,12 +4087,18 @@
@@ -3568,12 +4099,18 @@
}
public boolean randomTeleport(double x, double y, double z, boolean particleEffects) {
@@ -1276,7 +1334,7 @@
Level world = this.level();
if (world.hasChunkAt(blockposition)) {
@@ -3592,18 +4117,43 @@
@@ -3592,18 +4129,43 @@
}
if (flag2) {
@@ -1324,7 +1382,7 @@
world.broadcastEntityEvent(this, (byte) 46);
}
@@ -3613,7 +4163,7 @@
@@ -3613,7 +4175,7 @@
entitycreature.getNavigation().stop();
}
@@ -1333,7 +1391,7 @@
}
}
@@ -3706,7 +4256,7 @@
@@ -3706,7 +4268,7 @@
}
public void stopSleeping() {
@@ -1342,7 +1400,7 @@
Level world = this.level();
java.util.Objects.requireNonNull(world);
@@ -3718,9 +4268,9 @@
@@ -3718,9 +4280,9 @@
this.level().setBlock(blockposition, (BlockState) iblockdata.setValue(BedBlock.OCCUPIED, false), 3);
Vec3 vec3d = (Vec3) BedBlock.findStandUpPosition(this.getType(), this.level(), blockposition, enumdirection, this.getYRot()).orElseGet(() -> {
@@ -1354,7 +1412,7 @@
});
Vec3 vec3d1 = Vec3.atBottomCenterOf(blockposition).subtract(vec3d).normalize();
float f = (float) Mth.wrapDegrees(Mth.atan2(vec3d1.z, vec3d1.x) * 57.2957763671875D - 90.0D);
@@ -3740,7 +4290,7 @@
@@ -3740,7 +4302,7 @@
@Nullable
public Direction getBedOrientation() {
@@ -1363,7 +1421,7 @@
return blockposition != null ? BedBlock.getBedOrientation(this.level(), blockposition) : null;
}
@@ -3905,7 +4455,7 @@
@@ -3905,7 +4467,7 @@
public float maxUpStep() {
float f = (float) this.getAttributeValue(Attributes.STEP_HEIGHT);