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
bestium_init()
in the constructor. - Override
getType()
and returnbestium_backingType()
. - Override
addAdditionalSaveData(ValueOutput)
to call bothsuper.addAdditionalSaveData(ValueOutput)
andbestium_addAdditionalSaveData(ValueOutput)
.
public abstract class CustomSkeleton extends Skeleton implements Injectable {
public CustomSkeleton(EntityType<? extends CustomSkeleton> type, Level level) {
super(type, level);
bestium_init();
}
@Override
public EntityType<?> getType() {
return bestium_backingType();
}
@Override
protected void addAdditionalSaveData(ValueOutput output) {
super.addAdditionalSaveData(output);
bestium_addAdditionalSaveData(output);
}
}
This abstract class can then be extended further to implement specific custom behavior.
Note: Calls to bestium_key()
, bestium_backingType()
, and bestium_realType()
are relatively expensive
and should be cached if accessed frequently.
-
Method Summary
Modifier and TypeMethodDescriptiondefault void
bestium_addAdditionalSaveData
(net.minecraft.world.level.storage.ValueOutput output) Writes entity data to persistent storage.default <T extends net.minecraft.world.entity.Entity & Injectable>
TReturns this object cast as aEntity
.default net.minecraft.world.entity.EntityType
<?> Returns the vanillaEntityType
that backs this custom entity.default void
Initializes this Bestium entity.default net.kyori.adventure.key.Key
Returns the uniqueKey
associated with this injectable entity.default net.minecraft.world.entity.EntityType
<?> Returns the syntheticEntityType
used internally.
-
Method Details
-
bestium_asEntity
@NonExtendable @NotNull default <T extends net.minecraft.world.entity.Entity & Injectable> T bestium_asEntity()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
-
bestium_key
@NonExtendable default net.kyori.adventure.key.Key bestium_key()Returns the uniqueKey
associated with this injectable entity.- Returns:
- the registered entity key
- Throws:
NullPointerException
- if the entity was not properly registered
-
bestium_backingType
@NonExtendable default net.minecraft.world.entity.EntityType<?> bestium_backingType()Returns the vanillaEntityType
that 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:
-
bestium_realType
@NonExtendable default net.minecraft.world.entity.EntityType<?> bestium_realType()Returns the syntheticEntityType
used 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
-
bestium_addAdditionalSaveData
@NonExtendable default void bestium_addAdditionalSaveData(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
-
bestium_init
@NonExtendable default void bestium_init()Initializes this Bestium entity.This method sets up persistent tracking data (e.g., for models), and should be called from the constructor of your custom entity class.
-