Skip to content
This repository was archived by the owner on Jun 3, 2024. It is now read-only.

Commit e5f08e6

Browse files
authored
Merge pull request #86 from ZNixian/tracking-events
Add the PlayerEvent.StartTracking and StopTracking events
2 parents 55237bb + a33a6ec commit e5f08e6

File tree

3 files changed

+82
-2
lines changed

3 files changed

+82
-2
lines changed

patchwork-events-entity/src/main/java/net/minecraftforge/event/entity/player/PlayerEvent.java

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import net.minecraftforge.event.entity.living.LivingEvent;
2323

2424
import net.minecraft.entity.player.PlayerEntity;
25+
import net.minecraft.entity.Entity;
2526

2627
/**
2728
* PlayerEvent is fired whenever an event involving Living entities occurs.
@@ -66,13 +67,43 @@ public PlayerLoggedInEvent(PlayerEntity player) {
6667
}
6768
}
6869

70+
/**
71+
* Fired when an Entity is started to be "tracked" by this player (the player receives updates about this entity, e.g. motion).
72+
*/
73+
public static class StartTracking extends PlayerEvent {
74+
private final Entity target;
75+
76+
public StartTracking(PlayerEntity player, Entity target) {
77+
super(player);
78+
this.target = target;
79+
}
80+
81+
public Entity getTarget() {
82+
return target;
83+
}
84+
}
85+
86+
/**
87+
* Fired when an Entity is started to be "tracked" by this player (the player receives updates about this entity, e.g. motion).
88+
*/
89+
public static class StopTracking extends PlayerEvent {
90+
private final Entity target;
91+
92+
public StopTracking(PlayerEntity player, Entity target) {
93+
super(player);
94+
this.target = target;
95+
}
96+
97+
public Entity getTarget() {
98+
return target;
99+
}
100+
}
101+
69102
/*TODO Events:
70103
HarvestCheck
71104
BreakSpeed
72105
NameFormat
73106
Clone
74-
StartTracking
75-
StopTracking
76107
LoadFromFile
77108
SaveToFile
78109
Visibility
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*
2+
* Minecraft Forge, Patchwork Project
3+
* Copyright (c) 2016-2020, 2019-2020
4+
*
5+
* This library is free software; you can redistribute it and/or
6+
* modify it under the terms of the GNU Lesser General Public
7+
* License as published by the Free Software Foundation version 2.1
8+
* of the License.
9+
*
10+
* This library is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13+
* Lesser General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU Lesser General Public
16+
* License along with this library; if not, write to the Free Software
17+
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18+
*/
19+
20+
package net.patchworkmc.mixin.event.entity;
21+
22+
import net.minecraftforge.common.MinecraftForge;
23+
import net.minecraftforge.event.entity.player.PlayerEvent;
24+
import org.spongepowered.asm.mixin.Mixin;
25+
import org.spongepowered.asm.mixin.Shadow;
26+
import org.spongepowered.asm.mixin.injection.At;
27+
import org.spongepowered.asm.mixin.injection.Inject;
28+
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
29+
30+
import net.minecraft.entity.Entity;
31+
import net.minecraft.server.network.EntityTrackerEntry;
32+
import net.minecraft.server.network.ServerPlayerEntity;
33+
34+
@Mixin(EntityTrackerEntry.class)
35+
public class MixinEntityTrackerEntry {
36+
@Shadow
37+
private Entity entity;
38+
39+
@Inject(method = "startTracking", at = @At("TAIL"))
40+
private void hookEventStartTracking(ServerPlayerEntity player, CallbackInfo callback) {
41+
MinecraftForge.EVENT_BUS.post(new PlayerEvent.StartTracking(player, entity));
42+
}
43+
44+
@Inject(method = "stopTracking", at = @At("TAIL"))
45+
private void hookEventStopTracking(ServerPlayerEntity player, CallbackInfo callback) {
46+
MinecraftForge.EVENT_BUS.post(new PlayerEvent.StopTracking(player, entity));
47+
}
48+
}

patchwork-events-entity/src/main/resources/patchwork-events-entity.mixins.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"compatibilityLevel": "JAVA_8",
55
"mixins": [
66
"MixinEntity",
7+
"MixinEntityTrackerEntry",
78
"MixinEntityType",
89
"MixinLivingEntity",
910
"MixinMobEntity",

0 commit comments

Comments
 (0)