-
Notifications
You must be signed in to change notification settings - Fork 4
Adding Entities (Variant Loader)
Aram edited this page Nov 4, 2024
·
18 revisions
This variant loader has been designed with Geckolib in mind; therefore, using Geckolib is recommended.
-
Register Your Entity:
- Follow the instructions outlined in the Getting Started section to register your entity with the Variant Loader.
-
Create Your Entity Class:
- Develop the class for your entity. This class will define the behavior and properties of your entity within the game.
-
Add Resource Files:
- Place your resource files in the appropriate directories:
-
Textures: Add your texture files to the
assets/<modid>/textures/entity/
folder. -
JSON Files: Place your JSON configuration files in the
data/<modid>/variant/entity/
directory, refer to the example provided here. - For a detailed example of how to structure these files, refer to the example provided here.
- Note: If you are familiar with resource management in Minecraft, you may modify the resource paths to fit your preferences. Just ensure that your modifications are consistent and correctly referenced in your code.
-
Textures: Add your texture files to the
- Place your resource files in the appropriate directories:
To successfully add a new entity to the Variant Loader, you need to implement the following components in your entity class:
- A String variable declaring the entity name.
- A method to set the variant name. This allows for the dynamic assignment of the variant for each entity instance.
- A method to retrieve the variant name. This method enables you to access the currently set variant name.
-
finalizeSpawn
method. This method ensures that a variant is chosen during the spawning process.
Here’s an example of how to implement an entity class named EntityOne:
public class EntityOne extends PathfinderMob implements IVariantEntity {
protected final String entityName = "entityOne";
public DragonEntity(EntityType<? extends PathfinderMob> pEntityType, Level pLevel) {
super(pEntityType, pLevel);
}
public void setVariantName(String pVariantName) {
((IVariantAccessor) this).setEntityVariantName(pVariantName);
}
public String getVariantName() {
return ((IVariantAccessor) this).getEntityVariantName();
}
}
1.21.3+
@Override
public SpawnGroupData finalizeSpawn(@NotNull ServerLevelAccessor pLevel, @NotNull DifficultyInstance pDifficulty, @NotNull EntitySpawnReason pReason, @Nullable SpawnGroupData pSpawnData) {
if (getVariantName() == null || getVariantName().isEmpty()) {
setVariantName(getRandomVariant(getEntityVariants(entityName), "normal"));
}
return super.finalizeSpawn(pLevel, pDifficulty, pReason, pSpawnData);
}
Pre 1.21.3
@Override
public SpawnGroupData finalizeSpawn(@NotNull ServerLevelAccessor pLevel, @NotNull DifficultyInstance pDifficulty, @NotNull MobSpawnType pReason, @Nullable SpawnGroupData pSpawnData, @Nullable CompoundTag pSpawnTag) {
if (getVariantName() == null || getVariantName().isEmpty()) {
setVariantName(getRandomVariant(getEntityVariants(entityName), "normal"));
}
return super.finalizeSpawn(pLevel, pDifficulty, pReason, pSpawnData, pSpawnTag);
}
- Make sure to replace "normal" with the base entity texture you wish to return if the code does not function as expected.
- Remember to rename the class and update the variable to match the name of your entity.
After creating the entity class, you also need to return the texture path in the model or renderer class.
Geckolib
In the Model Class of your entity.
@Override
public ResourceLocation getTextureResource(<YourEntityClassName> pObject) {
return pObject.getTextureLocation(<modid>, "textures/entity/" + pObject.entityName + "/" + pObject.getVariantName() + ".png");
}
No Library
In the Renderer Class of your entity.
Fabric
@Override
public Identifier getTexture(<YourEntityClassName> pObject) {
return new Identifier(<modid>, "textures/entity/ + pObject.entityName + "/" + pObject.getVariantName() + ".png");
}
NeoForge
@Override
public ResourceLocation getTextureResource(<YourEntityClassName> pObject) {
return pObject.getTextureLocation(<modid>, "textures/entity/" + pObject.entityName + "/" + pObject.getVariantName() + ".png");
}
You may need to change the path if you modified it in your registry code.
- Consistency is Key: Make sure that all references to your entity name and variant names are consistent across your class and resource files.
By following these guidelines, you can successfully add entities to the Variant Loader, enriching your mod with unique creatures and characters. For further information and advanced customization options, refer to the official Discord or to our API Documentation.