-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Lowered the Files the Mod Owners need to use to create the Variant Loader
- Loading branch information
Showing
7 changed files
with
101 additions
and
162 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
NeoForge/src/main/java/software/bluelib/interfaces/variant/IVariantAccessor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package software.bluelib.interfaces.variant; | ||
|
||
public interface IVariantAccessor { | ||
void setEntityVariantName(String pVariantName); | ||
String getEntityVariantName(); | ||
} | ||
|
59 changes: 59 additions & 0 deletions
59
NeoForge/src/main/java/software/bluelib/mixin/variant/LivingEntityMixin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package software.bluelib.mixin.variant; | ||
|
||
import net.minecraft.nbt.CompoundTag; | ||
import net.minecraft.world.entity.Entity; | ||
import net.minecraft.world.entity.LivingEntity; | ||
import net.minecraft.network.syncher.EntityDataAccessor; | ||
import net.minecraft.network.syncher.EntityDataSerializers; | ||
import net.minecraft.network.syncher.SynchedEntityData; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.Unique; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.Inject; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; | ||
import software.bluelib.interfaces.variant.IVariantAccessor; | ||
|
||
@Mixin(LivingEntity.class) | ||
public class LivingEntityMixin implements IVariantAccessor { | ||
|
||
@Unique | ||
private static final EntityDataAccessor<String> bluelib$VARIANT = | ||
SynchedEntityData.defineId(LivingEntity.class, EntityDataSerializers.STRING); | ||
|
||
@Inject(method = "defineSynchedData", at = @At("HEAD")) | ||
protected void defineSynchedData(SynchedEntityData.@NotNull Builder pBuilder, CallbackInfo pCi) { | ||
pBuilder.define(bluelib$VARIANT, "normal"); | ||
} | ||
|
||
@Inject(method = "addAdditionalSaveData", at = @At("HEAD")) | ||
public void addAdditionalSaveData(@NotNull CompoundTag pCompound, CallbackInfo pCi) { | ||
pCompound.putString("Variant", bluelib$getVariantName()); | ||
} | ||
|
||
@Inject(method = "readAdditionalSaveData", at = @At("HEAD")) | ||
public void readAdditionalSaveData(@NotNull CompoundTag pCompound, CallbackInfo pCi) { | ||
bluelib$setVariantName(pCompound.getString("Variant")); | ||
} | ||
|
||
@Unique | ||
public void bluelib$setVariantName(String pName) { | ||
((Entity) (Object) this).getEntityData().set(bluelib$VARIANT, pName); | ||
} | ||
|
||
@Unique | ||
public String bluelib$getVariantName() { | ||
return ((Entity) (Object) this).getEntityData().get(bluelib$VARIANT); | ||
} | ||
|
||
@Override | ||
public void setEntityVariantName(String pVariantName) { | ||
bluelib$setVariantName(pVariantName); | ||
} | ||
|
||
@Override | ||
public String getEntityVariantName() { | ||
return bluelib$getVariantName(); | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{ | ||
"required": true, | ||
"minVersion": "0.8.0", | ||
"package": "software.bluelib.mixin", | ||
"refmap": "bluelib.refmap.json", | ||
"mixins": [ | ||
"variant.LivingEntityMixin" | ||
], | ||
"client": [], | ||
"server": [], | ||
"injectors": { | ||
"defaultRequire": 1 | ||
} | ||
} |