2021-03-15 23:00:00 +01:00
--- a/net/minecraft/server/level/EntityTrackerEntry.java
+++ b/net/minecraft/server/level/EntityTrackerEntry.java
2024-04-23 17:15:00 +02:00
@@ -46,6 +46,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();
2024-04-23 17:15:00 +02:00
@@ -70,8 +76,12 @@
2021-06-11 07:00:00 +02:00
private boolean wasOnGround;
2022-12-07 17:00:00 +01:00
@Nullable
2024-04-23 17:15:00 +02:00
private List<DataWatcher.c<?>> trackedDataValues;
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.level = worldserver;
2024-06-13 17:05:00 +02:00
this.broadcast = consumer;
this.entity = entity;
@@ -90,7 +100,7 @@
2023-03-14 17:30:00 +01:00
List<Entity> list = this.entity.getPassengers();
2022-06-10 02:39:19 +02:00
if (!list.equals(this.lastPassengers)) {
- this.broadcast.accept(new PacketPlayOutMount(this.entity));
+ this.broadcastAndSend(new PacketPlayOutMount(this.entity)); // CraftBukkit
2023-06-07 17:30:00 +02:00
removedPassengers(list, this.lastPassengers).forEach((entity) -> {
2024-04-23 17:15:00 +02:00
if (entity instanceof EntityPlayer entityplayer) {
entityplayer.connection.teleport(entityplayer.getX(), entityplayer.getY(), entityplayer.getZ(), entityplayer.getYRot(), entityplayer.getXRot());
2024-06-13 17:05:00 +02:00
@@ -103,18 +113,18 @@
2024-04-23 17:15:00 +02:00
Entity entity = this.entity;
2021-06-11 07:00:00 +02:00
2024-04-23 17:15:00 +02:00
if (entity instanceof EntityItemFrame entityitemframe) {
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
2024-04-23 17:15:00 +02:00
MapId mapid = (MapId) itemstack.get(DataComponents.MAP_ID);
WorldMap worldmap = ItemWorldMap.getSavedData(mapid, this.level);
2022-06-07 18:00:00 +02:00
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);
2024-04-23 17:15:00 +02:00
Packet<?> packet = worldmap.getUpdatePacket(mapid, entityplayer);
2024-06-13 17:05:00 +02:00
@@ -232,6 +242,27 @@
2014-11-25 22:32:16 +01:00
2021-06-11 07:00:00 +02:00
++this.tickCount;
if (this.entity.hurtMarked) {
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());
2023-06-07 17:30:00 +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
+ }
+ }
+
2024-06-13 17:05:00 +02:00
+ if (cancelled) {
+ return;
2014-11-25 22:32:16 +01:00
+ }
+ // CraftBukkit end
2024-06-13 17:05:00 +02:00
this.entity.hurtMarked = false;
this.broadcastAndSend(new PacketPlayOutEntityVelocity(this.entity));
}
@@ -260,7 +291,10 @@
2019-04-23 04:00:00 +02:00
2023-06-07 17:30:00 +02:00
public void sendPairingData(EntityPlayer entityplayer, Consumer<Packet<PacketListenerPlayOut>> consumer) {
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
}
2024-06-13 17:05:00 +02:00
Packet<PacketListenerPlayOut> packet = this.entity.getAddEntityPacket(this);
@@ -275,6 +309,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
}
2024-06-13 17:05:00 +02:00
@@ -305,6 +345,7 @@
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
}
2023-09-24 23:47:22 +02:00
+ ((EntityLiving) this.entity).detectEquipmentUpdatesPublic(); // CraftBukkit - SPIGOT-3789: sync again immediately after sending
2023-09-21 18:57:13 +02:00
}
2023-06-07 17:30:00 +02:00
if (!this.entity.getPassengers().isEmpty()) {
2024-06-13 17:05:00 +02:00
@@ -358,6 +399,11 @@
Set<AttributeModifiable> set = ((EntityLiving) this.entity).getAttributes().getAttributesToSync();
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
}