Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adjust when the EntityTrackingEvents are fired. #4369

Merged
merged 3 commits into from
Jan 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import net.minecraft.util.Identifier;

import net.fabricmc.api.ModInitializer;
import net.fabricmc.fabric.api.networking.v1.EntityTrackingEvents;
import net.fabricmc.fabric.api.networking.v1.PayloadTypeRegistry;
import net.fabricmc.fabric.api.networking.v1.ServerConfigurationConnectionEvents;
import net.fabricmc.fabric.api.networking.v1.ServerConfigurationNetworking;
Expand Down Expand Up @@ -113,7 +114,14 @@ public void onInitialize() {
}
});

// entity tracking handled in EntityTrackerEntryMixin instead, see comment
EntityTrackingEvents.START_TRACKING.register((trackedEntity, player) -> {
List<AttachmentChange> changes = new ArrayList<>();
((AttachmentTargetImpl) trackedEntity).fabric_computeInitialSyncChanges(player, changes::add);

if (!changes.isEmpty()) {
AttachmentChange.partitionAndSendPackets(changes, player);
}
});
}

private record AttachmentSyncTask() implements ServerPlayerConfigurationTask {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
"ClientConnectionMixin",
"CustomPayloadS2CPacketAccessor",
"EntityMixin",
"EntityTrackerEntryMixin",
"SerializedChunkMixin",
"ServerWorldMixin",
"VarIntsAccessor",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@
*/
public final class EntityTrackingEvents {
/**
* An event that is called before player starts tracking an entity.
* An event that is called after a player has started tracking an entity.
* Typically, this occurs when an entity enters a client's view distance.
* This event is called before the player's client is sent the entity's {@linkplain Entity#createSpawnPacket spawn packet}.
* This event is called after the entity's {@linkplain Entity#createSpawnPacket spawn packet} is sent to the player.
*/
public static final Event<StartTracking> START_TRACKING = EventFactory.createArrayBacked(StartTracking.class, callbacks -> (trackedEntity, player) -> {
for (StartTracking callback : callbacks) {
Expand All @@ -38,9 +38,8 @@ public final class EntityTrackingEvents {
});

/**
* An event that is called after a player has stopped tracking an entity.
* The client at this point was sent a packet to {@link net.minecraft.network.packet.s2c.play.EntitiesDestroyS2CPacket destroy} the entity on the client.
* The entity still exists on the server.
* An event that is called before a player stops tracking an entity.
* The entity still exists on the server and on the player's client.
*/
public static final Event<StopTracking> STOP_TRACKING = EventFactory.createArrayBacked(StopTracking.class, callbacks -> (trackedEntity, player) -> {
for (StopTracking callback : callbacks) {
Expand All @@ -51,7 +50,7 @@ public final class EntityTrackingEvents {
@FunctionalInterface
public interface StartTracking {
/**
* Called before an entity starts getting tracked by a player.
* Called after a player has started tracking an entity.
*
* @param trackedEntity the entity that will be tracked
* @param player the player that will track the entity
Expand All @@ -62,10 +61,10 @@ public interface StartTracking {
@FunctionalInterface
public interface StopTracking {
/**
* Called after an entity stops getting tracked by a player.
* Called before an entity stops getting tracked by a player.
*
* @param trackedEntity the entity that is no longer being tracked
* @param player the player that is no longer tracking the entity
* @param trackedEntity the entity that is about to stop being tracked
* @param player the player that is about to stop tracking the entity
*/
void onStopTracking(Entity trackedEntity, ServerPlayerEntity player);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@ abstract class EntityTrackerEntryMixin {
@Final
private Entity entity;

@Inject(method = "startTracking", at = @At("HEAD"))
@Inject(method = "startTracking", at = @At("TAIL"))
private void onStartTracking(ServerPlayerEntity player, CallbackInfo ci) {
EntityTrackingEvents.START_TRACKING.invoker().onStartTracking(this.entity, player);
}

@Inject(method = "stopTracking", at = @At("TAIL"))
@Inject(method = "stopTracking", at = @At("HEAD"))
private void onStopTracking(ServerPlayerEntity player, CallbackInfo ci) {
EntityTrackingEvents.STOP_TRACKING.invoker().onStopTracking(this.entity, player);
}
Expand Down