mirror of
https://github.com/PaperMC/Paper.git
synced 2025-01-09 19:49:35 +01:00
40076782ed
By: md_5 <git@md-5.net>
151 lines
7.3 KiB
Diff
151 lines
7.3 KiB
Diff
--- a/net/minecraft/server/level/EntityTrackerEntry.java
|
|
+++ b/net/minecraft/server/level/EntityTrackerEntry.java
|
|
@@ -44,6 +44,12 @@
|
|
import net.minecraft.world.phys.Vec3D;
|
|
import org.slf4j.Logger;
|
|
|
|
+// CraftBukkit start
|
|
+import net.minecraft.server.network.ServerPlayerConnection;
|
|
+import org.bukkit.entity.Player;
|
|
+import org.bukkit.event.player.PlayerVelocityEvent;
|
|
+// CraftBukkit end
|
|
+
|
|
public class EntityTrackerEntry {
|
|
|
|
private static final Logger LOGGER = LogUtils.getLogger();
|
|
@@ -65,8 +71,12 @@
|
|
private boolean wasOnGround;
|
|
@Nullable
|
|
private List<DataWatcher.b<?>> trackedDataValues;
|
|
+ // CraftBukkit start
|
|
+ private final Set<ServerPlayerConnection> trackedPlayers;
|
|
|
|
- public EntityTrackerEntry(WorldServer worldserver, Entity entity, int i, boolean flag, Consumer<Packet<?>> consumer) {
|
|
+ public EntityTrackerEntry(WorldServer worldserver, Entity entity, int i, boolean flag, Consumer<Packet<?>> consumer, Set<ServerPlayerConnection> trackedPlayers) {
|
|
+ this.trackedPlayers = trackedPlayers;
|
|
+ // CraftBukkit end
|
|
this.ap = Vec3D.ZERO;
|
|
this.lastPassengers = Collections.emptyList();
|
|
this.level = worldserver;
|
|
@@ -86,7 +96,7 @@
|
|
List<Entity> list = this.entity.getPassengers();
|
|
|
|
if (!list.equals(this.lastPassengers)) {
|
|
- this.broadcast.accept(new PacketPlayOutMount(this.entity));
|
|
+ this.broadcastAndSend(new PacketPlayOutMount(this.entity)); // CraftBukkit
|
|
this.changedPassengers(list, this.lastPassengers).forEach((entity) -> {
|
|
if (entity instanceof EntityPlayer) {
|
|
EntityPlayer entityplayer = (EntityPlayer) entity;
|
|
@@ -105,18 +115,18 @@
|
|
if (entity instanceof EntityItemFrame) {
|
|
EntityItemFrame entityitemframe = (EntityItemFrame) entity;
|
|
|
|
- if (this.tickCount % 10 == 0) {
|
|
+ if (true || this.tickCount % 10 == 0) { // CraftBukkit - Moved below, should always enter this block
|
|
ItemStack itemstack = entityitemframe.getItem();
|
|
|
|
- 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);
|
|
@@ -229,7 +239,27 @@
|
|
|
|
++this.tickCount;
|
|
if (this.entity.hurtMarked) {
|
|
- this.broadcastAndSend(new PacketPlayOutEntityVelocity(this.entity));
|
|
+ // CraftBukkit start - Create PlayerVelocity event
|
|
+ boolean cancelled = false;
|
|
+
|
|
+ if (this.entity instanceof EntityPlayer) {
|
|
+ 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 PacketPlayOutEntityVelocity(this.entity));
|
|
+ }
|
|
+ // CraftBukkit end
|
|
this.entity.hurtMarked = false;
|
|
}
|
|
|
|
@@ -252,14 +282,17 @@
|
|
List<Packet<PacketListenerPlayOut>> list = new ArrayList();
|
|
|
|
Objects.requireNonNull(list);
|
|
- this.sendPairingData(list::add);
|
|
+ this.sendPairingData(list::add, entityplayer); // CraftBukkit - add player
|
|
entityplayer.connection.send(new ClientboundBundlePacket(list));
|
|
this.entity.startSeenByPlayer(entityplayer);
|
|
}
|
|
|
|
- public void sendPairingData(Consumer<Packet<PacketListenerPlayOut>> consumer) {
|
|
+ public void sendPairingData(Consumer<Packet<PacketListenerPlayOut>> consumer, EntityPlayer entityplayer) { // CraftBukkit - add player
|
|
if (this.entity.isRemoved()) {
|
|
- EntityTrackerEntry.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<PacketListenerPlayOut> packet = this.entity.getAddEntityPacket();
|
|
@@ -275,6 +308,12 @@
|
|
if (this.entity instanceof EntityLiving) {
|
|
Collection<AttributeModifiable> collection = ((EntityLiving) this.entity).getAttributes().getSyncableAttributes();
|
|
|
|
+ // CraftBukkit start - If sending own attributes send scaled health instead of current maximum health
|
|
+ if (this.entity.getId() == entityplayer.getId()) {
|
|
+ ((EntityPlayer) this.entity).getBukkitEntity().injectScaledMaxHealth(collection, false);
|
|
+ }
|
|
+ // CraftBukkit end
|
|
+
|
|
if (!collection.isEmpty()) {
|
|
consumer.accept(new PacketPlayOutUpdateAttributes(this.entity.getId(), collection));
|
|
}
|
|
@@ -306,8 +345,14 @@
|
|
if (!list.isEmpty()) {
|
|
consumer.accept(new PacketPlayOutEntityEquipment(this.entity.getId(), list));
|
|
}
|
|
+ ((EntityLiving) this.entity).detectEquipmentUpdates(); // CraftBukkit - SPIGOT-3789: sync again immediately after sending
|
|
}
|
|
|
|
+ // CraftBukkit start - Fix for nonsensical head yaw
|
|
+ this.yHeadRotp = MathHelper.floor(this.entity.getYHeadRot() * 256.0F / 360.0F);
|
|
+ consumer.accept(new PacketPlayOutEntityHeadRotation(this.entity, (byte) yHeadRotp));
|
|
+ // CraftBukkit end
|
|
+
|
|
if (this.entity instanceof EntityLiving) {
|
|
EntityLiving entityliving = (EntityLiving) this.entity;
|
|
Iterator iterator = entityliving.getActiveEffects().iterator();
|
|
@@ -350,6 +395,11 @@
|
|
Set<AttributeModifiable> set = ((EntityLiving) this.entity).getAttributes().getDirtyAttributes();
|
|
|
|
if (!set.isEmpty()) {
|
|
+ // CraftBukkit start - Send scaled max health
|
|
+ if (this.entity instanceof EntityPlayer) {
|
|
+ ((EntityPlayer) this.entity).getBukkitEntity().injectScaledMaxHealth(set, false);
|
|
+ }
|
|
+ // CraftBukkit end
|
|
this.broadcastAndSend(new PacketPlayOutUpdateAttributes(this.entity.getId(), set));
|
|
}
|
|
|