Skip to content

Commit 5bae498

Browse files
Fix custom data not copying upon player death
1 parent d919e35 commit 5bae498

File tree

5 files changed

+30
-3
lines changed

5 files changed

+30
-3
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
- Updated to 1.21.10.
1+
- Fix custom data not copying upon player death.

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ yarn_mappings=1.21.10+build.1
77
loader_version=0.17.2
88

99
# Mod Properties
10-
mod_version=0.3.1-1.21.10
10+
mod_version=0.3.2-1.21.10
1111
supported_versions=>=1.21.9 <=1.21.10
1212
maven_group=xyz.eclipseisoffline
1313
archives_base_name=modifyplayerdata
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package xyz.eclipseisoffline.modifyplayerdata.mixin;
2+
3+
import net.minecraft.component.type.NbtComponent;
4+
import net.minecraft.entity.Entity;
5+
import org.spongepowered.asm.mixin.Mixin;
6+
import org.spongepowered.asm.mixin.gen.Accessor;
7+
8+
@Mixin(Entity.class)
9+
public interface EntityAccessor {
10+
11+
@Accessor
12+
NbtComponent getCustomData();
13+
}

src/main/java/xyz/eclipseisoffline/modifyplayerdata/mixin/ServerPlayerEntityMixin.java

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,24 @@
11
package xyz.eclipseisoffline.modifyplayerdata.mixin;
22

3+
import com.mojang.authlib.GameProfile;
4+
import net.minecraft.component.DataComponentTypes;
5+
import net.minecraft.entity.player.PlayerEntity;
36
import net.minecraft.server.network.ServerPlayerEntity;
47
import net.minecraft.storage.ReadView;
58
import net.minecraft.storage.WriteView;
9+
import net.minecraft.world.World;
610
import org.spongepowered.asm.mixin.Mixin;
711
import org.spongepowered.asm.mixin.injection.At;
812
import org.spongepowered.asm.mixin.injection.Inject;
913
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
1014
import xyz.eclipseisoffline.modifyplayerdata.PlayerData;
1115

1216
@Mixin(ServerPlayerEntity.class)
13-
public class ServerPlayerEntityMixin {
17+
public abstract class ServerPlayerEntityMixin extends PlayerEntity {
18+
19+
public ServerPlayerEntityMixin(World world, GameProfile profile) {
20+
super(world, profile);
21+
}
1422

1523
@Inject(method = "readCustomData", at = @At("TAIL"))
1624
public void readExtraCustomData(ReadView view, CallbackInfo callbackInfo) {
@@ -21,4 +29,9 @@ public void readExtraCustomData(ReadView view, CallbackInfo callbackInfo) {
2129
public void writeExtraCustomData(WriteView view, CallbackInfo callbackInfo) {
2230
PlayerData.write((ServerPlayerEntity) (Object) this, view);
2331
}
32+
33+
@Inject(method = "copyFrom", at = @At("TAIL"))
34+
public void copyCustomData(ServerPlayerEntity oldPlayer, boolean alive, CallbackInfo callbackInfo) {
35+
setComponent(DataComponentTypes.CUSTOM_DATA, ((EntityAccessor) oldPlayer).getCustomData());
36+
}
2437
}

src/main/resources/modifyplayerdata.mixins.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"package": "xyz.eclipseisoffline.modifyplayerdata.mixin",
55
"compatibilityLevel": "JAVA_17",
66
"mixins": [
7+
"EntityAccessor",
78
"EntityDataObjectMixin",
89
"EntityMixin",
910
"HungerManagerAccessor",

0 commit comments

Comments
 (0)