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 initBestium() in the constructor.
  4. Override getType() and return getBestiumBackingType().
  5. Override addAdditionalSaveData(ValueOutput) to call both super.addAdditionalSaveData(ValueOutput) and addBestiumAdditionalSaveData(ValueOutput).
For example:

 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

    Fields
    Modifier and Type
    Field
    Description
    static final org.bukkit.NamespacedKey
    The persistent data key used to identify injected entities.
  • Method Summary

    Modifier and Type
    Method
    Description
    default void
    addBestiumAdditionalSaveData(net.minecraft.world.level.storage.ValueOutput output)
    Writes entity data to persistent storage.
    default <T extends net.minecraft.world.entity.Entity>
    T
    Returns this object cast as a Entity.
    default net.minecraft.world.entity.EntityType<?>
    Returns the vanilla EntityType that backs this custom 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.
    default void
    Initializes this Bestium entity.
  • Field Details

  • Method Details

    • asBestiumEntity

      @NonExtendable @NotNull default <T extends net.minecraft.world.entity.Entity> T asBestiumEntity()
      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
    • getBestiumKey

      @NonExtendable default net.kyori.adventure.key.Key getBestiumKey()
      Returns the unique Key associated 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 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:
    • getBestiumRealType

      @NonExtendable default net.minecraft.world.entity.EntityType<?> getBestiumRealType()
      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
    • 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 of addAdditionalSaveData(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.