Files
CatServer/patches/net/minecraft/entity/EntityTrackerEntry.java.patch

233 lines
11 KiB
Diff

--- ../src-base/minecraft/net/minecraft/entity/EntityTrackerEntry.java
+++ ../src-work/minecraft/net/minecraft/entity/EntityTrackerEntry.java
@@ -66,7 +66,11 @@
import net.minecraft.world.storage.MapData;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
+import org.bukkit.entity.Player;
+import org.bukkit.event.player.PlayerVelocityEvent;
+import javax.annotation.Nullable;
+
public class EntityTrackerEntry
{
private static final Logger LOGGER = LogManager.getLogger();
@@ -148,23 +152,23 @@
if (!list.equals(this.passengers))
{
this.passengers = list;
- this.sendPacketToTrackedPlayers(new SPacketSetPassengers(this.trackedEntity));
+ this.sendToTrackingAndSelf(new SPacketSetPassengers(this.trackedEntity));
}
- if (this.trackedEntity instanceof EntityItemFrame && this.updateCounter % 10 == 0)
+ if (this.trackedEntity instanceof EntityItemFrame /*&& this.updateCounter % 10 == 0*/) // CraftBukkit - Moved below, should always enter this block
{
EntityItemFrame entityitemframe = (EntityItemFrame)this.trackedEntity;
ItemStack itemstack = entityitemframe.getDisplayedItem();
- if (itemstack.getItem() instanceof ItemMap)
+ if (this.updateCounter % 10 == 0 && itemstack.getItem() instanceof ItemMap)// CraftBukkit - Moved this.updateCounter % 10 logic here so item frames do not enter the other blocks
{
- MapData mapdata = Items.FILLED_MAP.getMapData(itemstack, this.trackedEntity.world);
+ MapData mapdata = ((ItemMap) itemstack.getItem()).getMapData(itemstack, this.trackedEntity.world);
- for (EntityPlayer entityplayer : players)
+ for (EntityPlayer entityplayer : trackingPlayers)
{
EntityPlayerMP entityplayermp = (EntityPlayerMP)entityplayer;
mapdata.updateVisiblePlayers(entityplayermp, itemstack);
- Packet<?> packet = Items.FILLED_MAP.createMapDataPacket(itemstack, this.trackedEntity.world, entityplayermp);
+ Packet<?> packet = ((ItemMap) itemstack.getItem()).createMapDataPacket(itemstack, this.trackedEntity.world, entityplayermp);
if (packet != null)
{
@@ -211,7 +215,20 @@
Packet<?> packet1 = null;
boolean flag = j * j + k * k + l * l >= 128L || this.updateCounter % 60 == 0;
boolean flag1 = Math.abs(k2 - this.encodedRotationYaw) >= 1 || Math.abs(i - this.encodedRotationPitch) >= 1;
+ // CraftBukkit start - Code moved from below
+ if (flag)
+ {
+ this.encodedPosX = i1;
+ this.encodedPosY = i2;
+ this.encodedPosZ = j2;
+ }
+ if (flag1)
+ {
+ this.encodedRotationYaw = k2;
+ this.encodedRotationPitch = i;
+ }
+ // CraftBukkit end
if (this.updateCounter > 0 || this.trackedEntity instanceof EntityArrow)
{
if (j >= -32768L && j < 32768L && k >= -32768L && k < 32768L && l >= -32768L && l < 32768L && this.ticksSinceLastForcedTeleport <= 400 && !this.ridingEntity && this.onGround == this.trackedEntity.onGround)
@@ -236,6 +253,11 @@
{
this.onGround = this.trackedEntity.onGround;
this.ticksSinceLastForcedTeleport = 0;
+ // CraftBukkit start - Refresh list of who can see a player before sending teleport packet
+ if (this.trackedEntity instanceof EntityPlayer) {
+ this.updatePlayerEntities(new java.util.ArrayList<>(this.trackingPlayers));
+ }
+ // CraftBukkit end
this.resetPlayerVisibility();
packet1 = new SPacketEntityTeleport(this.trackedEntity);
}
@@ -272,6 +294,7 @@
this.sendMetadata();
+ /* CraftBukkit start - Code moved up
if (flag)
{
this.encodedPosX = i1;
@@ -284,7 +307,7 @@
this.encodedRotationYaw = k2;
this.encodedRotationPitch = i;
}
-
+ // CraftBukkit end */
this.ridingEntity = false;
}
@@ -303,7 +326,28 @@
if (this.trackedEntity.velocityChanged)
{
- this.sendToTrackingAndSelf(new SPacketEntityVelocity(this.trackedEntity));
+ // this.sendToTrackingAndSelf(new SPacketEntityVelocity(this.trackedEntity));
+ // CraftBukkit start - Create PlayerVelocity event
+ boolean cancelled = false;
+
+ if (this.trackedEntity instanceof EntityPlayer) {
+ Player player = (Player) this.trackedEntity.getBukkitEntity();
+ org.bukkit.util.Vector velocity = player.getVelocity();
+
+ PlayerVelocityEvent event = new PlayerVelocityEvent(player, velocity.clone());
+ this.trackedEntity.world.getServer().getPluginManager().callEvent(event);
+
+ if (event.isCancelled()) {
+ cancelled = true;
+ } else if (!velocity.equals(event.getVelocity())) {
+ player.setVelocity(event.getVelocity());
+ }
+ }
+
+ if (!cancelled) {
+ this.sendToTrackingAndSelf(new SPacketEntityVelocity(this.trackedEntity));
+ }
+ // CraftBukkit end
this.trackedEntity.velocityChanged = false;
}
}
@@ -324,6 +368,11 @@
if (!set.isEmpty())
{
+ // CraftBukkit start - Send scaled max health
+ if (this.trackedEntity instanceof EntityPlayerMP) {
+ ((EntityPlayerMP) this.trackedEntity).getBukkitEntity().injectScaledMaxHealth(set, false);
+ }
+ // CraftBukkit end
this.sendToTrackingAndSelf(new SPacketEntityProperties(this.trackedEntity.getEntityId(), set));
}
@@ -360,6 +409,7 @@
public void removeFromTrackedPlayers(EntityPlayerMP playerMP)
{
+ org.spigotmc.AsyncCatcher.catchOp("player tracker clear"); // Spigot
if (this.trackingPlayers.contains(playerMP))
{
this.trackedEntity.removeTrackingPlayer(playerMP);
@@ -370,12 +420,23 @@
public void updatePlayerEntity(EntityPlayerMP playerMP)
{
+ org.spigotmc.AsyncCatcher.catchOp("player tracker update"); // Spigot
if (playerMP != this.trackedEntity)
{
if (this.isVisibleTo(playerMP))
{
if (!this.trackingPlayers.contains(playerMP) && (this.isPlayerWatchingThisChunk(playerMP) || this.trackedEntity.forceSpawn))
{
+ // CraftBukkit start - respect vanish API
+ if (this.trackedEntity instanceof EntityPlayerMP) {
+ Player player = ((EntityPlayerMP) this.trackedEntity).getBukkitEntity();
+ if (!playerMP.getBukkitEntity().canSee(player)) {
+ return;
+ }
+ }
+
+ playerMP.entityRemoveQueue.remove(Integer.valueOf(this.trackedEntity.getEntityId()));
+ // CraftBukkit end
this.trackingPlayers.add(playerMP);
Packet<?> packet = this.createSpawnPacket();
playerMP.connection.sendPacket(packet);
@@ -392,6 +453,14 @@
AttributeMap attributemap = (AttributeMap)((EntityLivingBase)this.trackedEntity).getAttributeMap();
Collection<IAttributeInstance> collection = attributemap.getWatchedAttributes();
+ // CraftBukkit start - If sending own attributes send scaled health instead of current maximum health
+ if (this.trackedEntity.getEntityId() == playerMP.getEntityId()) {
+ // TODO: Maybe we should check for instanceof before casting to EntityPlayerMP?
+ ((EntityPlayerMP) this.trackedEntity).getBukkitEntity().injectScaledMaxHealth(collection, false);
+ }
+ // CraftBukkit end
+
+
if (!collection.isEmpty())
{
playerMP.connection.sendPacket(new SPacketEntityProperties(this.trackedEntity.getEntityId(), collection));
@@ -435,6 +504,11 @@
}
}
+ // CraftBukkit start - Fix for nonsensical head yaw
+ this.lastHeadMotion = MathHelper.floor(this.trackedEntity.getRotationYawHead() * 256.0F / 360.0F);
+ this.sendPacketToTrackedPlayers(new SPacketEntityHeadLook(this.trackedEntity, (byte) lastHeadMotion));
+ // CraftBukkit end
+
if (this.trackedEntity instanceof EntityLivingBase)
{
EntityLivingBase entitylivingbase = (EntityLivingBase)this.trackedEntity;
@@ -457,6 +531,7 @@
this.trackedEntity.addTrackingPlayer(playerMP);
playerMP.addEntity(this.trackedEntity);
+ net.minecraftforge.event.ForgeEventFactory.onStartEntityTracking(trackedEntity, playerMP);
}
}
else if (this.trackingPlayers.contains(playerMP))
@@ -464,6 +539,7 @@
this.trackingPlayers.remove(playerMP);
this.trackedEntity.removeTrackingPlayer(playerMP);
playerMP.removeEntity(this.trackedEntity);
+ net.minecraftforge.event.ForgeEventFactory.onStopEntityTracking(trackedEntity, playerMP);
}
}
}
@@ -489,13 +565,19 @@
}
}
+ @Nullable
private Packet<?> createSpawnPacket()
{
if (this.trackedEntity.isDead)
{
- LOGGER.warn("Fetching addPacket for removed entity");
+ // CraftBukkit start - Remove useless error spam, just return
+ // LOGGER.warn("Fetching addPacket for removed entity");
+ return null;
}
+ Packet pkt = net.minecraftforge.fml.common.network.internal.FMLNetworkHandler.getEntitySpawningPacket(this.trackedEntity);
+ if (pkt != null) return pkt;
+
if (this.trackedEntity instanceof EntityPlayerMP)
{
return new SPacketSpawnPlayer((EntityPlayer)this.trackedEntity);