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

Commit 496c8d0

Browse files
committed
Implement the PlayerEvent.Clone event
1 parent 55237bb commit 496c8d0

File tree

2 files changed

+41
-1
lines changed

2 files changed

+41
-1
lines changed

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

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,42 @@ public PlayerLoggedInEvent(PlayerEntity player) {
6666
}
6767
}
6868

69+
/**
70+
* Fired when the EntityPlayer is cloned, typically caused by the network sending a RESPAWN_PLAYER event.
71+
* Either caused by death, or by traveling from the End to the overworld.
72+
*/
73+
public static class Clone extends PlayerEvent {
74+
private final PlayerEntity original;
75+
private final boolean wasDeath;
76+
77+
public Clone(PlayerEntity _new, PlayerEntity oldPlayer, boolean wasDeath) {
78+
super(_new);
79+
this.original = oldPlayer;
80+
this.wasDeath = wasDeath;
81+
}
82+
83+
/**
84+
* @return The old EntityPlayer that this new entity is a clone of.
85+
*/
86+
public PlayerEntity getOriginal() {
87+
return original;
88+
}
89+
90+
/**
91+
* True if this event was fired because the player died.
92+
* False if it was fired because the entity switched dimensions.
93+
*
94+
* @return Whether this event was caused by the player dying.
95+
*/
96+
public boolean isWasDeath() {
97+
return wasDeath;
98+
}
99+
}
100+
69101
/*TODO Events:
70102
HarvestCheck
71103
BreakSpeed
72104
NameFormat
73-
Clone
74105
StartTracking
75106
StopTracking
76107
LoadFromFile

patchwork-events-entity/src/main/java/net/patchworkmc/mixin/event/entity/MixinServerPlayerEntity.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919

2020
package net.patchworkmc.mixin.event.entity;
2121

22+
import net.minecraftforge.common.MinecraftForge;
23+
import net.minecraftforge.event.entity.player.PlayerEvent;
2224
import org.spongepowered.asm.mixin.Mixin;
2325
import org.spongepowered.asm.mixin.injection.At;
2426
import org.spongepowered.asm.mixin.injection.Inject;
@@ -40,4 +42,11 @@ private void hookDeath(DamageSource source, CallbackInfo callback) {
4042
callback.cancel();
4143
}
4244
}
45+
46+
@Inject(method = "copyFrom", at = @At("TAIL"))
47+
private void hookCopyFromForCloneEvent(ServerPlayerEntity oldPlayer, boolean alive, CallbackInfo info) {
48+
@SuppressWarnings("ConstantConditions")
49+
ServerPlayerEntity speThis = (ServerPlayerEntity) (Object) this;
50+
MinecraftForge.EVENT_BUS.post(new PlayerEvent.Clone(speThis, oldPlayer, !alive));
51+
}
4352
}

0 commit comments

Comments
 (0)