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

Commit d853a3d

Browse files
authored
Implement the PlayerEvent.Clone event (#88)
Implement the PlayerEvent.Clone event
1 parent e5f08e6 commit d853a3d

File tree

3 files changed

+42
-2
lines changed

3 files changed

+42
-2
lines changed

patchwork-events-entity/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
archivesBaseName = "patchwork-events-entity"
2-
version = getSubprojectVersion(project, "0.2.0")
2+
version = getSubprojectVersion(project, "0.3.0")
33

44
dependencies {
55
compile project(path: ':patchwork-fml', configuration: 'dev')

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
@@ -99,11 +99,42 @@ public Entity getTarget() {
9999
}
100100
}
101101

102+
/*
103+
* Fired when the EntityPlayer is cloned, typically caused by the network sending a RESPAWN_PLAYER event.
104+
* Either caused by death, or by traveling from the End to the overworld.
105+
*/
106+
public static class Clone extends PlayerEvent {
107+
private final PlayerEntity original;
108+
private final boolean wasDeath;
109+
110+
public Clone(PlayerEntity newPlayer, PlayerEntity oldPlayer, boolean wasDeath) {
111+
super(newPlayer);
112+
this.original = oldPlayer;
113+
this.wasDeath = wasDeath;
114+
}
115+
116+
/**
117+
* @return The old EntityPlayer that this new entity is a clone of.
118+
*/
119+
public PlayerEntity getOriginal() {
120+
return original;
121+
}
122+
123+
/**
124+
* True if this event was fired because the player died.
125+
* False if it was fired because the entity switched dimensions.
126+
*
127+
* @return Whether this event was caused by the player dying.
128+
*/
129+
public boolean isWasDeath() {
130+
return wasDeath;
131+
}
132+
}
133+
102134
/*TODO Events:
103135
HarvestCheck
104136
BreakSpeed
105137
NameFormat
106-
Clone
107138
LoadFromFile
108139
SaveToFile
109140
Visibility

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)