diff options
Diffstat (limited to 'patch-remap/mache-spigotflower/net/minecraft/server/level/ServerEntity.java.patch')
-rw-r--r-- | patch-remap/mache-spigotflower/net/minecraft/server/level/ServerEntity.java.patch | 306 |
1 files changed, 306 insertions, 0 deletions
diff --git a/patch-remap/mache-spigotflower/net/minecraft/server/level/ServerEntity.java.patch b/patch-remap/mache-spigotflower/net/minecraft/server/level/ServerEntity.java.patch new file mode 100644 index 0000000000..7af7213a79 --- /dev/null +++ b/patch-remap/mache-spigotflower/net/minecraft/server/level/ServerEntity.java.patch @@ -0,0 +1,306 @@ +--- a/net/minecraft/server/level/ServerEntity.java ++++ b/net/minecraft/server/level/ServerEntity.java +@@ -28,7 +28,6 @@ + import net.minecraft.network.protocol.game.ClientboundUpdateAttributesPacket; + import net.minecraft.network.protocol.game.VecDeltaCodec; + import net.minecraft.network.syncher.SynchedEntityData; +-import net.minecraft.util.Mth; + import net.minecraft.world.entity.Entity; + import net.minecraft.world.entity.EquipmentSlot; + import net.minecraft.world.entity.LivingEntity; +@@ -42,6 +41,13 @@ + import net.minecraft.world.phys.Vec3; + import org.slf4j.Logger; + ++// CraftBukkit start ++import net.minecraft.server.network.ServerPlayerConnection; ++import net.minecraft.util.Mth; ++import org.bukkit.entity.Player; ++import org.bukkit.event.player.PlayerVelocityEvent; ++// CraftBukkit end ++ + public class ServerEntity { + + private static final Logger LOGGER = LogUtils.getLogger(); +@@ -66,11 +72,15 @@ + private boolean wasOnGround; + @Nullable + private List<SynchedEntityData.DataValue<?>> trackedDataValues; ++ // CraftBukkit start ++ private final Set<ServerPlayerConnection> trackedPlayers; + +- public ServerEntity(ServerLevel serverlevel, Entity entity, int i, boolean flag, Consumer<Packet<?>> consumer) { ++ public ServerEntity(ServerLevel worldserver, Entity entity, int i, boolean flag, Consumer<Packet<?>> consumer, Set<ServerPlayerConnection> trackedPlayers) { ++ this.trackedPlayers = trackedPlayers; ++ // CraftBukkit end + this.ap = Vec3.ZERO; + this.lastPassengers = Collections.emptyList(); +- this.level = serverlevel; ++ this.level = worldserver; + this.broadcast = consumer; + this.entity = entity; + this.updateInterval = i; +@@ -87,12 +97,12 @@ + List<Entity> list = this.entity.getPassengers(); + + if (!list.equals(this.lastPassengers)) { +- this.broadcast.accept(new ClientboundSetPassengersPacket(this.entity)); ++ this.broadcastAndSend(new ClientboundSetPassengersPacket(this.entity)); // CraftBukkit + removedPassengers(list, this.lastPassengers).forEach((entity) -> { + if (entity instanceof ServerPlayer) { +- ServerPlayer serverplayer = (ServerPlayer) entity; ++ ServerPlayer entityplayer = (ServerPlayer) entity; + +- serverplayer.connection.teleport(serverplayer.getX(), serverplayer.getY(), serverplayer.getZ(), serverplayer.getYRot(), serverplayer.getXRot()); ++ entityplayer.connection.teleport(entityplayer.getX(), entityplayer.getY(), entityplayer.getZ(), entityplayer.getYRot(), entityplayer.getXRot()); + } + + }); +@@ -102,26 +112,26 @@ + Entity entity = this.entity; + + if (entity instanceof ItemFrame) { +- ItemFrame itemframe = (ItemFrame) entity; ++ ItemFrame entityitemframe = (ItemFrame) entity; + +- if (this.tickCount % 10 == 0) { +- ItemStack itemstack = itemframe.getItem(); ++ if (true || this.tickCount % 10 == 0) { // CraftBukkit - Moved below, should always enter this block ++ ItemStack itemstack = entityitemframe.getItem(); + +- if (itemstack.getItem() instanceof MapItem) { ++ if (this.tickCount % 10 == 0 && itemstack.getItem() instanceof MapItem) { // CraftBukkit - Moved this.tickCounter % 10 logic here so item frames do not enter the other blocks + Integer integer = MapItem.getMapId(itemstack); +- MapItemSavedData mapitemsaveddata = MapItem.getSavedData(integer, this.level); ++ MapItemSavedData worldmap = MapItem.getSavedData(integer, this.level); + +- if (mapitemsaveddata != null) { +- Iterator iterator = this.level.players().iterator(); ++ if (worldmap != null) { ++ Iterator<ServerPlayerConnection> iterator = this.trackedPlayers.iterator(); // CraftBukkit + + while (iterator.hasNext()) { +- ServerPlayer serverplayer = (ServerPlayer) iterator.next(); ++ ServerPlayer entityplayer = iterator.next().getPlayer(); // CraftBukkit + +- mapitemsaveddata.tickCarriedBy(serverplayer, itemstack); +- Packet<?> packet = mapitemsaveddata.getUpdatePacket(integer, serverplayer); ++ worldmap.tickCarriedBy(entityplayer, itemstack); ++ Packet<?> packet = worldmap.getUpdatePacket(integer, entityplayer); + + if (packet != null) { +- serverplayer.connection.send(packet); ++ entityplayer.connection.send(packet); + } + } + } +@@ -153,8 +163,8 @@ + ++this.teleportDelay; + i = Mth.floor(this.entity.getYRot() * 256.0F / 360.0F); + j = Mth.floor(this.entity.getXRot() * 256.0F / 360.0F); +- Vec3 vec3 = this.entity.trackingPosition(); +- boolean flag1 = this.positionCodec.delta(vec3).lengthSqr() >= 7.62939453125E-6D; ++ Vec3 vec3d = this.entity.trackingPosition(); ++ boolean flag1 = this.positionCodec.delta(vec3d).lengthSqr() >= 7.62939453125E-6D; + Packet<?> packet1 = null; + boolean flag2 = flag1 || this.tickCount % 60 == 0; + boolean flag3 = Math.abs(i - this.yRotp) >= 1 || Math.abs(j - this.xRotp) >= 1; +@@ -162,9 +172,9 @@ + boolean flag5 = false; + + if (this.tickCount > 0 || this.entity instanceof AbstractArrow) { +- long k = this.positionCodec.encodeX(vec3); +- long l = this.positionCodec.encodeY(vec3); +- long i1 = this.positionCodec.encodeZ(vec3); ++ long k = this.positionCodec.encodeX(vec3d); ++ long l = this.positionCodec.encodeY(vec3d); ++ long i1 = this.positionCodec.encodeZ(vec3d); + boolean flag6 = k < -32768L || k > 32767L || l < -32768L || l > 32767L || i1 < -32768L || i1 > 32767L; + + if (!flag6 && this.teleportDelay <= 400 && !this.wasRiding && this.wasOnGround == this.entity.onGround()) { +@@ -191,11 +201,11 @@ + } + + if ((this.trackDelta || this.entity.hasImpulse || this.entity instanceof LivingEntity && ((LivingEntity) this.entity).isFallFlying()) && this.tickCount > 0) { +- Vec3 vec31 = this.entity.getDeltaMovement(); +- double d0 = vec31.distanceToSqr(this.ap); ++ Vec3 vec3d1 = this.entity.getDeltaMovement(); ++ double d0 = vec3d1.distanceToSqr(this.ap); + +- if (d0 > 1.0E-7D || d0 > 0.0D && vec31.lengthSqr() == 0.0D) { +- this.ap = vec31; ++ if (d0 > 1.0E-7D || d0 > 0.0D && vec3d1.lengthSqr() == 0.0D) { ++ this.ap = vec3d1; + this.broadcast.accept(new ClientboundSetEntityMotionPacket(this.entity.getId(), this.ap)); + } + } +@@ -206,7 +216,7 @@ + + this.sendDirtyEntityData(); + if (flag4) { +- this.positionCodec.setBase(vec3); ++ this.positionCodec.setBase(vec3d); + } + + if (flag5) { +@@ -228,35 +238,58 @@ + + ++this.tickCount; + if (this.entity.hurtMarked) { +- this.broadcastAndSend(new ClientboundSetEntityMotionPacket(this.entity)); ++ // CraftBukkit start - Create PlayerVelocity event ++ boolean cancelled = false; ++ ++ if (this.entity instanceof ServerPlayer) { ++ Player player = (Player) this.entity.getBukkitEntity(); ++ org.bukkit.util.Vector velocity = player.getVelocity(); ++ ++ PlayerVelocityEvent event = new PlayerVelocityEvent(player, velocity.clone()); ++ this.entity.level().getCraftServer().getPluginManager().callEvent(event); ++ ++ if (event.isCancelled()) { ++ cancelled = true; ++ } else if (!velocity.equals(event.getVelocity())) { ++ player.setVelocity(event.getVelocity()); ++ } ++ } ++ ++ if (!cancelled) { ++ this.broadcastAndSend(new ClientboundSetEntityMotionPacket(this.entity)); ++ } ++ // CraftBukkit end + this.entity.hurtMarked = false; + } + + } + +- private static Stream<Entity> removedPassengers(List<Entity> list, List<Entity> list1) { +- return list1.stream().filter((entity) -> { +- return !list.contains(entity); ++ private static Stream<Entity> removedPassengers(List<Entity> initialPassengers, List<Entity> currentPassengers) { ++ return currentPassengers.stream().filter((entity) -> { ++ return !initialPassengers.contains(entity); + }); + } + +- public void removePairing(ServerPlayer serverplayer) { +- this.entity.stopSeenByPlayer(serverplayer); +- serverplayer.connection.send(new ClientboundRemoveEntitiesPacket(new int[]{this.entity.getId()})); ++ public void removePairing(ServerPlayer player) { ++ this.entity.stopSeenByPlayer(player); ++ player.connection.send(new ClientboundRemoveEntitiesPacket(new int[]{this.entity.getId()})); + } + +- public void addPairing(ServerPlayer serverplayer) { ++ public void addPairing(ServerPlayer player) { + List<Packet<ClientGamePacketListener>> list = new ArrayList(); + + Objects.requireNonNull(list); +- this.sendPairingData(serverplayer, list::add); +- serverplayer.connection.send(new ClientboundBundlePacket(list)); +- this.entity.startSeenByPlayer(serverplayer); ++ this.sendPairingData(player, list::add); ++ player.connection.send(new ClientboundBundlePacket(list)); ++ this.entity.startSeenByPlayer(player); + } + +- public void sendPairingData(ServerPlayer serverplayer, Consumer<Packet<ClientGamePacketListener>> consumer) { ++ public void sendPairingData(ServerPlayer player, Consumer<Packet<ClientGamePacketListener>> consumer) { + if (this.entity.isRemoved()) { +- ServerEntity.LOGGER.warn("Fetching packet for removed entity {}", this.entity); ++ // CraftBukkit start - Remove useless error spam, just return ++ // EntityTrackerEntry.LOGGER.warn("Fetching packet for removed entity {}", this.entity); ++ return; ++ // CraftBukkit end + } + + Packet<ClientGamePacketListener> packet = this.entity.getAddEntityPacket(); +@@ -272,6 +305,12 @@ + if (this.entity instanceof LivingEntity) { + Collection<AttributeInstance> collection = ((LivingEntity) this.entity).getAttributes().getSyncableAttributes(); + ++ // CraftBukkit start - If sending own attributes send scaled health instead of current maximum health ++ if (this.entity.getId() == player.getId()) { ++ ((ServerPlayer) this.entity).getBukkitEntity().injectScaledMaxHealth(collection, false); ++ } ++ // CraftBukkit end ++ + if (!collection.isEmpty()) { + consumer.accept(new ClientboundUpdateAttributesPacket(this.entity.getId(), collection)); + } +@@ -288,23 +327,30 @@ + + if (this.entity instanceof LivingEntity) { + List<Pair<EquipmentSlot, ItemStack>> list = Lists.newArrayList(); +- EquipmentSlot[] aequipmentslot = EquipmentSlot.values(); +- int i = aequipmentslot.length; ++ EquipmentSlot[] aenumitemslot = EquipmentSlot.values(); ++ int i = aenumitemslot.length; + + for (int j = 0; j < i; ++j) { +- EquipmentSlot equipmentslot = aequipmentslot[j]; +- ItemStack itemstack = ((LivingEntity) this.entity).getItemBySlot(equipmentslot); ++ EquipmentSlot enumitemslot = aenumitemslot[j]; ++ ItemStack itemstack = ((LivingEntity) this.entity).getItemBySlot(enumitemslot); + + if (!itemstack.isEmpty()) { +- list.add(Pair.of(equipmentslot, itemstack.copy())); ++ list.add(Pair.of(enumitemslot, itemstack.copy())); + } + } + + if (!list.isEmpty()) { + consumer.accept(new ClientboundSetEquipmentPacket(this.entity.getId(), list)); + } ++ ((LivingEntity) this.entity).detectEquipmentUpdatesPublic(); // CraftBukkit - SPIGOT-3789: sync again immediately after sending + } + ++ // CraftBukkit start - MC-109346: Fix for nonsensical head yaw ++ if (this.entity instanceof ServerPlayer) { ++ consumer.accept(new ClientboundRotateHeadPacket(this.entity, (byte) Mth.floor(this.entity.getYHeadRot() * 256.0F / 360.0F))); ++ } ++ // CraftBukkit end ++ + if (!this.entity.getPassengers().isEmpty()) { + consumer.accept(new ClientboundSetPassengersPacket(this.entity)); + } +@@ -316,21 +362,21 @@ + Entity entity = this.entity; + + if (entity instanceof Mob) { +- Mob mob = (Mob) entity; ++ Mob entityinsentient = (Mob) entity; + +- if (mob.isLeashed()) { +- consumer.accept(new ClientboundSetEntityLinkPacket(mob, mob.getLeashHolder())); ++ if (entityinsentient.isLeashed()) { ++ consumer.accept(new ClientboundSetEntityLinkPacket(entityinsentient, entityinsentient.getLeashHolder())); + } + } + + } + + private void sendDirtyEntityData() { +- SynchedEntityData synchedentitydata = this.entity.getEntityData(); +- List<SynchedEntityData.DataValue<?>> list = synchedentitydata.packDirty(); ++ SynchedEntityData datawatcher = this.entity.getEntityData(); ++ List<SynchedEntityData.DataValue<?>> list = datawatcher.packDirty(); + + if (list != null) { +- this.trackedDataValues = synchedentitydata.getNonDefaultValues(); ++ this.trackedDataValues = datawatcher.getNonDefaultValues(); + this.broadcastAndSend(new ClientboundSetEntityDataPacket(this.entity.getId(), list)); + } + +@@ -338,6 +384,11 @@ + Set<AttributeInstance> set = ((LivingEntity) this.entity).getAttributes().getDirtyAttributes(); + + if (!set.isEmpty()) { ++ // CraftBukkit start - Send scaled max health ++ if (this.entity instanceof ServerPlayer) { ++ ((ServerPlayer) this.entity).getBukkitEntity().injectScaledMaxHealth(set, false); ++ } ++ // CraftBukkit end + this.broadcastAndSend(new ClientboundUpdateAttributesPacket(this.entity.getId(), set)); + } + |