Interface Injectable
- All Known Implementing Classes:
CustomAbstractFish,CustomAbstractGolem,CustomAbstractSchoolingFish,CustomAbstractVillager,CustomAgeableMob,CustomAgeableWaterCreature,CustomAmbientCreature,CustomAnimal,CustomEntity,CustomLivingEntity,CustomMob,CustomMonster,CustomPathfinderMob,CustomShoulderRidingEntity,CustomTamableAnimal,CustomWaterAnimal
This is an interface because Java does not support multiple class inheritance, and Bestium entities cannot be directly injected into the official vanilla entity hierarchy. While this is technically an interface, its methods are not intended to be overridden — they provide essential infrastructure logic for Bestium entity injection.
Before you start implementing this interface to create your custom abstract class, you should first check the
cz.jeme.bestium.api.entity package. It may already contain a suitable implementation, such as CustomMonster
or CustomAnimal.
If it does not, consider opening an issue or pull request on the official GitHub page
to propose the addition.
To create an injectable custom entity, you should:
- Create an abstract class that extends a vanilla Minecraft entity (e.g.
Skeleton). - Implement
Injectable. - Call
initBestium()in the constructor. - Override
getType()and returngetBestiumBackingType(). - Override
addAdditionalSaveData(ValueOutput)to call bothsuper.addAdditionalSaveData(ValueOutput)andaddBestiumAdditionalSaveData(ValueOutput).
public abstract class CustomSkeleton extends Skeleton implements Injectable {
public CustomSkeleton(EntityType<? extends CustomSkeleton> type, Level level) {
super(type, level);
initBestium();
}
@Override
public EntityType<?> getType() {
return getBestiumBackingType();
}
@Override
protected void addAdditionalSaveData(ValueOutput output) {
super.addAdditionalSaveData(output);
addBestiumAdditionalSaveData(output);
}
}
This abstract class can then be extended further to implement specific custom behavior.
Note: Calls to getBestiumKey(), getBestiumBackingType(), and getBestiumRealType() are relatively expensive
and should be cached if accessed frequently.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final org.bukkit.NamespacedKeyThe persistent data key used to identify injected entities. -
Method Summary
Modifier and TypeMethodDescriptiondefault voidaddBestiumAdditionalSaveData(net.minecraft.world.level.storage.ValueOutput output) Writes entity data to persistent storage.default <T extends net.minecraft.world.entity.Entity>
TReturns this object cast as aEntity.default net.minecraft.world.entity.EntityType<?> Returns the vanillaEntityTypethat backs this custom entity.default net.kyori.adventure.key.KeyReturns the uniqueKeyassociated with this injectable entity.default net.minecraft.world.entity.EntityType<?> Returns the syntheticEntityTypeused internally.default voidInitializes this Bestium entity.
-
Field Details
-
BESTIUM_ID_KEY
@Internal static final org.bukkit.NamespacedKey BESTIUM_ID_KEYThe persistent data key used to identify injected entities.This key is stored in an entity's
PersistentDataContainerand holds aPersistentDataType.STRINGrepresenting the injected entity'sKey.Presence of this key signifies that the entity was spawned via the Bestium injection system.
- See Also:
-
-
Method Details
-
asBestiumEntity
@NonExtendable @NotNull default <T extends net.minecraft.world.entity.Entity> T asBestiumEntity()Returns this object cast as aEntity.This is safe by contract, as all implementations of this interface must extend
Entity.- Type Parameters:
T- the specific type extending both Entity and Injectable- Returns:
- this object cast as an
Entity - Throws:
IllegalStateException- if the implementing class does not extendEntity
-
getBestiumKey
@NonExtendable default net.kyori.adventure.key.Key getBestiumKey()Returns the uniqueKeyassociated with this injectable entity.- Returns:
- the registered entity key
- Throws:
NullPointerException- if the entity was not properly registered
-
getBestiumBackingType
@NonExtendable default net.minecraft.world.entity.EntityType<?> getBestiumBackingType()Returns the vanillaEntityTypethat backs this custom entity. This is the type used for interaction with vanilla systems such as spawning or serialization.- Returns:
- the vanilla backing type
- See Also:
-
getBestiumRealType
@NonExtendable default net.minecraft.world.entity.EntityType<?> getBestiumRealType()Returns the syntheticEntityTypeused internally.Warning: This type is not safe to send to the client, as it is not recognized by vanilla clients and may cause packet errors or disconnections.
- Returns:
- the internal Bestium entity type
-
addBestiumAdditionalSaveData
@NonExtendable default void addBestiumAdditionalSaveData(net.minecraft.world.level.storage.ValueOutput output) Writes entity data to persistent storage. Should be called from the overriding implementation ofaddAdditionalSaveData(ValueOutput).- Parameters:
output- the save target to write to
-
initBestium
@NonExtendable default void initBestium()Initializes this Bestium entity.This method should be called from the constructor of your custom entity base class.
-