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

[1.20.4] Alter StartTracking with Before and After Variants #3696

Open
wants to merge 2 commits into
base: 1.20.4
Choose a base branch
from
Open
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 @@ -25,15 +25,26 @@
/**
* Events related to a tracking entities within a player's view distance.
*/
public final class EntityTrackingEvents {

Check failure on line 28 in fabric-networking-api-v1/src/main/java/net/fabricmc/fabric/api/networking/v1/EntityTrackingEvents.java

View workflow job for this annotation

GitHub Actions / build (17-ubuntu)

blank line after {

/**
* An event that is called before player starts 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 {@link Entity#createSpawnPacket() spawn packet}.
* This event is called <strong>before</strong> the player's client is sent the entity's {@link Entity#createSpawnPacket() spawn packet}.
*/
public static final Event<StartTracking> START_TRACKING = EventFactory.createArrayBacked(StartTracking.class, callbacks -> (trackedEntity, player) -> {
for (StartTracking callback : callbacks) {
callback.onStartTracking(trackedEntity, player);
public static final Event<BeforeStartTracking> BEFORE_START_TRACKING = EventFactory.createArrayBacked(BeforeStartTracking.class, callbacks -> (trackedEntity, player) -> {
for (BeforeStartTracking callback : callbacks) {
callback.beforeStartTracking(trackedEntity, player);
}
});

/**
* An event that is called after player starts tracking an entity.
* This event is called <strong>after</strong> the player's client is sent the entity's {@link Entity#createSpawnPacket() spawn packet}.
*/
public static final Event<AfterStartTracking> AFTER_START_TRACKING = EventFactory.createArrayBacked(AfterStartTracking.class, callbacks -> (trackedEntity, player) -> {
for (AfterStartTracking callback : callbacks) {
callback.afterStartTracking(trackedEntity, player);
}
});

Expand All @@ -49,14 +60,24 @@
});

@FunctionalInterface
public interface StartTracking {
public interface BeforeStartTracking {
/**
* Called before an entity starts getting tracked by a player.
*
* @param trackedEntity the entity that will be tracked
* @param player the player that will track the entity
*/
void onStartTracking(Entity trackedEntity, ServerPlayerEntity player);
void beforeStartTracking(Entity trackedEntity, ServerPlayerEntity player);
}

public interface AfterStartTracking {
/**
* Called after an entity starts getting tracked by a player.
*
* @param trackedEntity the entity that will be tracked
* @param player the player that will track the entity
*/
void afterStartTracking(Entity trackedEntity, ServerPlayerEntity player);
}

@FunctionalInterface
Expand All @@ -72,4 +93,22 @@

private EntityTrackingEvents() {
}

//--

/**
* @deprecated Use {#BEFORE_START_TRACKING} or {@link #AFTER_START_TRACKING} instead
*/
@Deprecated()
public static final Event<StartTracking> START_TRACKING = EventFactory.createArrayBacked(StartTracking.class, callbacks -> (trackedEntity, player) -> {
for (StartTracking callback : callbacks) {
callback.onStartTracking(trackedEntity, player);
}
});

@Deprecated()
@FunctionalInterface
public interface StartTracking {
void onStartTracking(Entity trackedEntity, ServerPlayerEntity player);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,14 @@ abstract class EntityTrackerEntryMixin {
private Entity entity;

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

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

@Inject(method = "stopTracking", at = @At("TAIL"))
Expand Down
Loading