33import com .gmail .sheepingtoninc .rainbowsheep .RainbowSheep ;
44import com .gmail .sheepingtoninc .rainbowsheep .api .IFlagSheep ;
55import net .minecraft .core .registries .Registries ;
6+ import net .minecraft .nbt .CompoundTag ;
67import net .minecraft .network .syncher .EntityDataAccessor ;
8+ import net .minecraft .network .syncher .EntityDataSerializers ;
79import net .minecraft .network .syncher .SynchedEntityData ;
810import net .minecraft .resources .ResourceKey ;
911import net .minecraft .resources .ResourceLocation ;
1315import org .spongepowered .asm .mixin .Final ;
1416import org .spongepowered .asm .mixin .Mixin ;
1517import org .spongepowered .asm .mixin .Shadow ;
18+ import org .spongepowered .asm .mixin .Unique ;
1619import org .spongepowered .asm .mixin .injection .At ;
1720import org .spongepowered .asm .mixin .injection .Inject ;
1821import org .spongepowered .asm .mixin .injection .ModifyArg ;
1922import org .spongepowered .asm .mixin .injection .callback .CallbackInfo ;
2023import org .spongepowered .asm .mixin .injection .callback .CallbackInfoReturnable ;
2124
22- import static com .gmail .sheepingtoninc .rainbowsheep .RainbowSheep .FLAG ;
23- import static com .gmail .sheepingtoninc .rainbowsheep .RainbowSheep .LOGGER ;
24-
2525
2626@ Mixin (Sheep .class )
2727public abstract class SheepMixin implements IFlagSheep {
2828 @ Shadow public abstract boolean isSheared ();
2929
3030 @ Shadow @ Final private static EntityDataAccessor <Byte > DATA_WOOL_ID ;
31+ private static final EntityDataAccessor <Integer > FLAG = SynchedEntityData .defineId (Sheep .class , EntityDataSerializers .INT );
3132
3233 private static final ResourceLocation RAINBOW_LOOT_LOCATION = ResourceLocation .fromNamespaceAndPath ("rainbowsheep" , "entities/sheep/rainbow" );
3334 private static final ResourceKey <LootTable > RAINBOW_LOOT_KEY = ResourceKey .create (Registries .LOOT_TABLE , RAINBOW_LOOT_LOCATION );
@@ -48,19 +49,35 @@ public abstract class SheepMixin implements IFlagSheep {
4849 private static final ResourceKey <LootTable > NONBINARY_LOOT_KEY = ResourceKey .create (Registries .LOOT_TABLE , NONBINARY_LOOT_LOCATION );
4950
5051
52+ @ Unique
53+ private SynchedEntityData rainbowSheep$getData () {
54+ return ((Sheep )(Object )this ).getEntityData ();
55+ }
56+
5157 @ Override
5258 public void rainbowSheep$setFlagWool (int flag ) {
53- SynchedEntityData data = (( Sheep )( Object ) this ). getEntityData ();
59+ SynchedEntityData data = this . rainbowSheep$getData ();
5460 byte woolByte = data .get (DATA_WOOL_ID );
5561 data .set (DATA_WOOL_ID , (byte )(woolByte & 240 ));
56- (( Sheep )( Object ) this ). setData (FLAG , flag );
62+ data . set (FLAG , flag );
5763 }
5864
5965 @ Override
6066 public int rainbowSheep$getFlagWool () {
61- return (( Sheep )( Object ) this ). getData (FLAG );
67+ return rainbowSheep$getData (). get (FLAG );
6268 }
6369
70+ @ Inject (method = "defineSynchedData(Lnet/minecraft/network/syncher/SynchedEntityData$Builder;)V" , at = @ At ("TAIL" ))
71+ private void defineFlagSynchedData (SynchedEntityData .Builder builder , CallbackInfo ci ) {
72+ builder .define (FLAG , 0 );
73+ }
74+
75+ @ Inject (method = "addAdditionalSaveData(Lnet/minecraft/nbt/CompoundTag;)V" , at = @ At ("TAIL" ))
76+ private void addFlagSaveData (CompoundTag compound , CallbackInfo ci ) { compound .putInt ("Flag" , rainbowSheep$getFlagWool ()); }
77+
78+ @ Inject (method = "readAdditionalSaveData(Lnet/minecraft/nbt/CompoundTag;)V" , at = @ At ("TAIL" ))
79+ private void readFlagSaveData (CompoundTag compound , CallbackInfo ci ) { rainbowSheep$setFlagWool (compound .getInt ("Flag" )); }
80+
6481 @ ModifyArg (method = "shear" , at = @ At (value = "INVOKE" , target = "Lnet/minecraft/world/entity/animal/Sheep;spawnAtLocation(Lnet/minecraft/world/level/ItemLike;I)Lnet/minecraft/world/entity/item/ItemEntity;" ))
6582 private ItemLike shearFlagWool (ItemLike original ) {
6683 return switch (rainbowSheep$getFlagWool ()) {
0 commit comments