2021-03-15 23:00:00 +01:00
--- a/net/minecraft/server/level/EntityTrackerEntry.java
+++ b/net/minecraft/server/level/EntityTrackerEntry.java
2021-11-21 23:00:00 +01:00
@@ -40,6 +40,12 @@
2022-02-28 16:00:00 +01:00
import net.minecraft.world.phys.Vec3D;
import org.slf4j.Logger;
2019-04-23 06:00:30 +02:00
2014-11-25 22:32:16 +01:00
+// CraftBukkit start
2021-06-11 07:00:00 +02:00
+import net.minecraft.server.network.ServerPlayerConnection;
2014-11-25 22:32:16 +01:00
+import org.bukkit.entity.Player;
+import org.bukkit.event.player.PlayerVelocityEvent;
+// CraftBukkit end
2019-04-23 06:00:30 +02:00
+
2019-04-23 04:00:00 +02:00
public class EntityTrackerEntry {
2017-01-04 00:50:02 +01:00
2022-02-28 16:00:00 +01:00
private static final Logger LOGGER = LogUtils.getLogger();
2022-06-07 18:00:00 +02:00
@@ -59,8 +65,12 @@
2021-06-11 07:00:00 +02:00
private List<Entity> lastPassengers;
private boolean wasRiding;
private boolean wasOnGround;
2019-04-23 04:00:00 +02:00
+ // CraftBukkit start
2021-06-11 07:00:00 +02:00
+ private final Set<ServerPlayerConnection> trackedPlayers;
2019-04-23 04:00:00 +02:00
- public EntityTrackerEntry(WorldServer worldserver, Entity entity, int i, boolean flag, Consumer<Packet<?>> consumer) {
2021-06-11 07:00:00 +02:00
+ public EntityTrackerEntry(WorldServer worldserver, Entity entity, int i, boolean flag, Consumer<Packet<?>> consumer, Set<ServerPlayerConnection> trackedPlayers) {
2019-04-23 04:00:00 +02:00
+ this.trackedPlayers = trackedPlayers;
+ // CraftBukkit end
2021-06-11 07:00:00 +02:00
this.ap = Vec3D.ZERO;
this.lastPassengers = Collections.emptyList();
this.level = worldserver;
2022-06-10 02:39:19 +02:00
@@ -80,7 +90,7 @@
if (!list.equals(this.lastPassengers)) {
this.lastPassengers = list;
- this.broadcast.accept(new PacketPlayOutMount(this.entity));
+ this.broadcastAndSend(new PacketPlayOutMount(this.entity)); // CraftBukkit
}
Entity entity = this.entity;
2022-06-07 18:00:00 +02:00
@@ -88,18 +98,18 @@
if (entity instanceof EntityItemFrame) {
EntityItemFrame entityitemframe = (EntityItemFrame) entity;
2021-06-11 07:00:00 +02:00
2022-06-07 18:00:00 +02:00
- if (this.tickCount % 10 == 0) {
+ if (true || this.tickCount % 10 == 0) { // CraftBukkit - Moved below, should always enter this block
ItemStack itemstack = entityitemframe.getItem();
2014-11-25 22:32:16 +01:00
2022-06-07 18:00:00 +02:00
- if (itemstack.getItem() instanceof ItemWorldMap) {
+ if (this.tickCount % 10 == 0 && itemstack.getItem() instanceof ItemWorldMap) { // CraftBukkit - Moved this.tickCounter % 10 logic here so item frames do not enter the other blocks
Integer integer = ItemWorldMap.getMapId(itemstack);
WorldMap worldmap = ItemWorldMap.getSavedData(integer, this.level);
if (worldmap != null) {
- Iterator iterator = this.level.players().iterator();
+ Iterator<ServerPlayerConnection> iterator = this.trackedPlayers.iterator(); // CraftBukkit
while (iterator.hasNext()) {
- EntityPlayer entityplayer = (EntityPlayer) iterator.next();
+ EntityPlayer entityplayer = iterator.next().getPlayer(); // CraftBukkit
worldmap.tickCarriedBy(entityplayer, itemstack);
Packet<?> packet = worldmap.getUpdatePacket(integer, entityplayer);
@@ -204,7 +214,27 @@
2014-11-25 22:32:16 +01:00
2021-06-11 07:00:00 +02:00
++this.tickCount;
if (this.entity.hurtMarked) {
2021-11-21 23:00:00 +01:00
- this.broadcastAndSend(new PacketPlayOutEntityVelocity(this.entity));
2014-11-25 22:32:16 +01:00
+ // CraftBukkit start - Create PlayerVelocity event
+ boolean cancelled = false;
+
2021-06-11 07:00:00 +02:00
+ if (this.entity instanceof EntityPlayer) {
+ Player player = (Player) this.entity.getBukkitEntity();
2014-11-25 22:32:16 +01:00
+ org.bukkit.util.Vector velocity = player.getVelocity();
+
2015-07-20 21:42:30 +02:00
+ PlayerVelocityEvent event = new PlayerVelocityEvent(player, velocity.clone());
2021-06-11 13:33:49 +02:00
+ this.entity.level.getCraftServer().getPluginManager().callEvent(event);
2014-11-25 22:32:16 +01:00
+
+ if (event.isCancelled()) {
+ cancelled = true;
+ } else if (!velocity.equals(event.getVelocity())) {
2015-07-20 21:42:30 +02:00
+ player.setVelocity(event.getVelocity());
2014-11-25 22:32:16 +01:00
+ }
+ }
+
+ if (!cancelled) {
2021-11-21 23:00:00 +01:00
+ this.broadcastAndSend(new PacketPlayOutEntityVelocity(this.entity));
2014-11-25 22:32:16 +01:00
+ }
+ // CraftBukkit end
2021-06-11 07:00:00 +02:00
this.entity.hurtMarked = false;
2014-11-25 22:32:16 +01:00
}
2022-06-07 18:00:00 +02:00
@@ -219,13 +249,16 @@
2021-06-11 07:00:00 +02:00
PlayerConnection playerconnection = entityplayer.connection;
2019-04-23 04:00:00 +02:00
2021-06-11 07:00:00 +02:00
Objects.requireNonNull(entityplayer.connection);
2021-11-21 23:00:00 +01:00
- this.sendPairingData(playerconnection::send);
+ this.sendPairingData(playerconnection::send, entityplayer); // CraftBukkit - add player
this.entity.startSeenByPlayer(entityplayer);
2019-04-23 04:00:00 +02:00
}
2021-11-21 23:00:00 +01:00
- public void sendPairingData(Consumer<Packet<?>> consumer) {
+ public void sendPairingData(Consumer<Packet<?>> consumer, EntityPlayer entityplayer) { // CraftBukkit - add player
2021-06-11 07:00:00 +02:00
if (this.entity.isRemoved()) {
- EntityTrackerEntry.LOGGER.warn("Fetching packet for removed entity {}", this.entity);
2019-04-23 04:00:00 +02:00
+ // CraftBukkit start - Remove useless error spam, just return
2021-06-11 07:00:00 +02:00
+ // EntityTrackerEntry.LOGGER.warn("Fetching packet for removed entity {}", this.entity);
2019-04-23 04:00:00 +02:00
+ return;
+ // CraftBukkit end
}
2021-11-21 23:00:00 +01:00
Packet<?> packet = this.entity.getAddEntityPacket();
2022-06-07 18:00:00 +02:00
@@ -241,6 +274,12 @@
2021-06-11 07:00:00 +02:00
if (this.entity instanceof EntityLiving) {
2021-11-21 23:00:00 +01:00
Collection<AttributeModifiable> collection = ((EntityLiving) this.entity).getAttributes().getSyncableAttributes();
2019-04-23 04:00:00 +02:00
+ // CraftBukkit start - If sending own attributes send scaled health instead of current maximum health
2021-06-11 07:00:00 +02:00
+ if (this.entity.getId() == entityplayer.getId()) {
+ ((EntityPlayer) this.entity).getBukkitEntity().injectScaledMaxHealth(collection, false);
2019-04-23 04:00:00 +02:00
+ }
+ // CraftBukkit end
+
if (!collection.isEmpty()) {
2021-06-11 07:00:00 +02:00
consumer.accept(new PacketPlayOutUpdateAttributes(this.entity.getId(), collection));
2019-04-23 04:00:00 +02:00
}
2022-06-07 18:00:00 +02:00
@@ -272,8 +311,14 @@
2021-01-27 04:24:20 +01:00
if (!list.isEmpty()) {
2021-06-11 07:00:00 +02:00
consumer.accept(new PacketPlayOutEntityEquipment(this.entity.getId(), list));
2019-04-23 04:00:00 +02:00
}
2021-11-21 23:00:00 +01:00
+ ((EntityLiving) this.entity).detectEquipmentUpdates(); // CraftBukkit - SPIGOT-3789: sync again immediately after sending
2019-04-23 04:00:00 +02:00
}
+ // CraftBukkit start - Fix for nonsensical head yaw
2021-11-21 23:00:00 +01:00
+ this.yHeadRotp = MathHelper.floor(this.entity.getYHeadRot() * 256.0F / 360.0F);
2021-06-11 07:00:00 +02:00
+ consumer.accept(new PacketPlayOutEntityHeadRotation(this.entity, (byte) yHeadRotp));
2019-04-23 04:00:00 +02:00
+ // CraftBukkit end
+
2021-06-11 07:00:00 +02:00
if (this.entity instanceof EntityLiving) {
EntityLiving entityliving = (EntityLiving) this.entity;
2021-11-21 23:00:00 +01:00
Iterator iterator = entityliving.getActiveEffects().iterator();
2022-06-07 18:00:00 +02:00
@@ -314,6 +359,11 @@
2021-11-21 23:00:00 +01:00
Set<AttributeModifiable> set = ((EntityLiving) this.entity).getAttributes().getDirtyAttributes();
2014-11-25 22:32:16 +01:00
if (!set.isEmpty()) {
+ // CraftBukkit start - Send scaled max health
2021-06-11 07:00:00 +02:00
+ if (this.entity instanceof EntityPlayer) {
+ ((EntityPlayer) this.entity).getBukkitEntity().injectScaledMaxHealth(set, false);
2014-11-25 22:32:16 +01:00
+ }
+ // CraftBukkit end
2021-11-21 23:00:00 +01:00
this.broadcastAndSend(new PacketPlayOutUpdateAttributes(this.entity.getId(), set));
2014-11-25 22:32:16 +01:00
}