|
1 | 1 | package org.scbrm.fidelity.mixin; |
2 | 2 |
|
| 3 | +import net.minecraft.nbt.CompoundTag; |
| 4 | +import net.minecraft.server.ServerConfigHandler; |
3 | 5 | import org.scbrm.fidelity.bridge.IHorseBaseEntity; |
4 | 6 | import org.scbrm.fidelity.entity.ai.goal.ObeyMasterGoal; |
5 | 7 | import net.minecraft.entity.EntityType; |
|
23 | 25 | @Mixin(HorseBaseEntity.class) |
24 | 26 | public abstract class HorseBaseEntityMixin extends AnimalEntity implements IHorseBaseEntity { |
25 | 27 |
|
26 | | - private static final TrackedData<Optional<UUID>> MASTER_UUID; |
| 28 | + private static final TrackedData<Optional<UUID>> MASTER_UUID = DataTracker.registerData(HorseBaseEntity.class, TrackedDataHandlerRegistry.OPTIONAL_UUID); |
27 | 29 | private State state = State.ROAMING_FREE; |
28 | 30 |
|
29 | 31 | /*@Shadow protected abstract void spawnPlayerReactionParticles(boolean positive);*/ |
@@ -70,7 +72,29 @@ public void setState(@NotNull State state) { |
70 | 72 | this.state = state; |
71 | 73 | } |
72 | 74 |
|
73 | | - static { |
74 | | - MASTER_UUID = DataTracker.registerData(HorseBaseEntity.class, TrackedDataHandlerRegistry.OPTIONAL_UUID); |
| 75 | + @Inject(at = @At("TAIL"), method = "writeCustomDataToTag(Lnet/minecraft/nbt/CompoundTag;)V") |
| 76 | + public void _writeCustomDataToTag(CompoundTag tag, CallbackInfo info) { |
| 77 | + if (this.getMasterUuid() != null) { |
| 78 | + tag.putUuid("Master", this.getMasterUuid()); |
| 79 | + } |
| 80 | + |
| 81 | + tag.putByte("FidelityState", (byte)this.state.ordinal()); |
75 | 82 | } |
| 83 | + |
| 84 | + @Inject(at = @At("TAIL"), method = "readCustomDataFromTag(Lnet/minecraft/nbt/CompoundTag;)V") |
| 85 | + public void _readCustomDataFromTag(CompoundTag tag, CallbackInfo info) { |
| 86 | + final UUID uuid = tag.containsUuid("Master") ? |
| 87 | + tag.getUuid("Master") : |
| 88 | + ServerConfigHandler.getPlayerUuidByName(this.getServer(), tag.getString("Master")); |
| 89 | + |
| 90 | + if (uuid != null) { |
| 91 | + try { |
| 92 | + this.setMasterUuid(uuid); |
| 93 | + this.state = State.values()[tag.getByte("FidelityState")]; |
| 94 | + } catch (Throwable e) { |
| 95 | + this.state = State.ROAMING_FREE; |
| 96 | + } |
| 97 | + } |
| 98 | + } |
| 99 | + |
76 | 100 | } |
0 commit comments