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

Commit

Permalink
Implement the PlayerEvent.Clone event
Browse files Browse the repository at this point in the history
  • Loading branch information
ZNixian committed Jun 19, 2020
1 parent 708b620 commit 9d2902e
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,42 @@ public Entity getTarget() {
}
}

/*
* Fired when the EntityPlayer is cloned, typically caused by the network sending a RESPAWN_PLAYER event.
* Either caused by death, or by traveling from the End to the overworld.
*/
public static class Clone extends PlayerEvent {
private final PlayerEntity original;
private final boolean wasDeath;

public Clone(PlayerEntity newPlayer, PlayerEntity oldPlayer, boolean wasDeath) {
super(newPlayer);
this.original = oldPlayer;
this.wasDeath = wasDeath;
}

/**
* @return The old EntityPlayer that this new entity is a clone of.
*/
public PlayerEntity getOriginal() {
return original;
}

/**
* True if this event was fired because the player died.
* False if it was fired because the entity switched dimensions.
*
* @return Whether this event was caused by the player dying.
*/
public boolean isWasDeath() {
return wasDeath;
}
}

/*TODO Events:
HarvestCheck
BreakSpeed
NameFormat
Clone
LoadFromFile
SaveToFile
Visibility
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@

package net.patchworkmc.mixin.event.entity;

import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.entity.player.PlayerEvent;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
Expand All @@ -40,4 +42,11 @@ private void hookDeath(DamageSource source, CallbackInfo callback) {
callback.cancel();
}
}

@Inject(method = "copyFrom", at = @At("TAIL"))
private void hookCopyFromForCloneEvent(ServerPlayerEntity oldPlayer, boolean alive, CallbackInfo info) {
@SuppressWarnings("ConstantConditions")
ServerPlayerEntity speThis = (ServerPlayerEntity) (Object) this;
MinecraftForge.EVENT_BUS.post(new PlayerEvent.Clone(speThis, oldPlayer, !alive));
}
}

0 comments on commit 9d2902e

Please sign in to comment.