|
240 | 240 | + // Paper start |
241 | 241 | + // This method should only be used if the data of an entity could have become desynced |
242 | 242 | + // due to interactions on the client. |
243 | | -+ public void resendPossiblyDesyncedEntityData(net.minecraft.server.level.ServerPlayer player) { |
| 243 | ++ public void resendPossiblyDesyncedEntityData(ServerPlayer player) { |
244 | 244 | + if (player.getBukkitEntity().canSee(this.getBukkitEntity())) { |
245 | | -+ ServerLevel world = (net.minecraft.server.level.ServerLevel)this.level(); |
246 | | -+ net.minecraft.server.level.ChunkMap.TrackedEntity tracker = world == null ? null : world.getChunkSource().chunkMap.entityMap.get(this.getId()); |
| 245 | ++ ServerLevel level = (net.minecraft.server.level.ServerLevel) this.level(); |
| 246 | ++ net.minecraft.server.level.ChunkMap.TrackedEntity tracker = level == null ? null : level.getChunkSource().chunkMap.entityMap.get(this.getId()); |
247 | 247 | + if (tracker == null) { |
248 | 248 | + return; |
249 | 249 | + } |
|
254 | 254 | + } |
255 | 255 | + } |
256 | 256 | + |
257 | | -+ // This method allows you to specifically resend certain data accessor keys to the client |
258 | | -+ public void resendPossiblyDesyncedDataValues(List<EntityDataAccessor<?>> keys, ServerPlayer to) { |
| 257 | ++ // This method allows you to specifically resend certain data accessors to the client |
| 258 | ++ public void resendPossiblyDesyncedDataValues(List<EntityDataAccessor<?>> accessors, ServerPlayer to) { |
259 | 259 | + if (!to.getBukkitEntity().canSee(this.getBukkitEntity())) { |
260 | 260 | + return; |
261 | 261 | + } |
262 | 262 | + |
263 | | -+ final List<SynchedEntityData.DataValue<?>> values = new java.util.ArrayList<>(keys.size()); |
264 | | -+ for (final EntityDataAccessor<?> key : keys) { |
265 | | -+ final SynchedEntityData.DataItem<?> synchedValue = this.entityData.getItem(key); |
266 | | -+ values.add(synchedValue.value()); |
| 263 | ++ final List<SynchedEntityData.DataValue<?>> values = new ArrayList<>(accessors.size()); |
| 264 | ++ for (final EntityDataAccessor<?> accessor : accessors) { |
| 265 | ++ final SynchedEntityData.DataItem<?> item = this.entityData.getItem(accessor); |
| 266 | ++ values.add(item.value()); |
267 | 267 | + } |
268 | 268 | + |
269 | 269 | + to.connection.send(new net.minecraft.network.protocol.game.ClientboundSetEntityDataPacket(this.id, values)); |
|
1329 | 1329 | } |
1330 | 1330 |
|
1331 | 1331 | public int getAirSupply() { |
1332 | | -@@ -2732,10 +_,22 @@ |
| 1332 | +@@ -2732,10 +_,24 @@ |
1333 | 1333 | } |
1334 | 1334 |
|
1335 | 1335 | public void setAirSupply(final int supply) { |
|
1341 | 1341 | + event.getEntity().getServer().getPluginManager().callEvent(event); |
1342 | 1342 | + } |
1343 | 1343 | + if (event.isCancelled() && this.getAirSupply() != supply) { |
1344 | | -+ this.entityData.markDirty(DATA_AIR_SUPPLY_ID); |
| 1344 | ++ if (this instanceof ServerPlayer player) { |
| 1345 | ++ this.resendPossiblyDesyncedDataValues(java.util.List.of(DATA_AIR_SUPPLY_ID), player); // todo is that even needed? |
| 1346 | ++ } |
1345 | 1347 | + return; |
1346 | 1348 | + } |
1347 | 1349 | + this.entityData.set(DATA_AIR_SUPPLY_ID, event.getAmount()); |
|
0 commit comments