Interface Injectable

All Known Implementing Classes:
CustomAbstractFish, CustomAbstractGolem, CustomAbstractSchoolingFish, CustomAbstractVillager, CustomAgeableMob, CustomAgeableWaterCreature, CustomAmbientCreature, CustomAnimal, CustomEntity, CustomLivingEntity, CustomMob, CustomMonster, CustomPathfinderMob, CustomShoulderRidingEntity, CustomTamableAnimal, CustomWaterAnimal

@NullMarked public interface Injectable
Represents a Bestium entity that can be injected into the Minecraft runtime.

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:

  1. Create an abstract class that extends a vanilla Minecraft entity (e.g. Skeleton).
  2. Implement Injectable.
  3. Call bestium_init() in the constructor.
  4. Override getType() and return bestium_backingType().
  5. Override addAdditionalSaveData(ValueOutput) to call both super.addAdditionalSaveData(ValueOutput) and bestium_addAdditionalSaveData(ValueOutput).
For example:

 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 Type
    Method
    Description
    default 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>
    T
    Returns this object cast as a Entity.
    default net.minecraft.world.entity.EntityType<?>
    Returns the vanilla EntityType that backs this custom entity.
    default void
    Initializes this Bestium entity.
    default net.kyori.adventure.key.Key
    Returns the unique Key associated with this injectable entity.
    default net.minecraft.world.entity.EntityType<?>
    Returns the synthetic EntityType 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 a Entity.

      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 extend Entity
    • bestium_key

      @NonExtendable default net.kyori.adventure.key.Key bestium_key()
      Returns the unique Key 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 vanilla EntityType 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 synthetic EntityType 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 of addAdditionalSaveData(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.