-
Notifications
You must be signed in to change notification settings - Fork 2
Required Entity Interfaces
Entities using the builder system must implement IContainerEntity
to function properly.
Any entity that uses variants
in its builder must implement IVariantTypes
to function effectively.
These interfaces provide a large amounts of default methods to allow for ease of interaction with the EntityTypeContainer
system. There are default implementations of these interfaces that can be pasted into an entity class.
Better Animals Plus includes many implementations of these interfaces onto various LivingEntity
subclasses.
Here are the Forge implementations.
IContainerEntity requires the implementation of only two methods, but you must also override an additional method to add functionality.
First, removeWhenFarAway (MCP: despawn
) must call despawn
from IContainerEntity
in order to properly implement the despawn()
call.
@Override
public boolean removeWhenFarAway(double range) {
return despawn(range);
}
Second, getImplementation
must return this
. This is used to allow the interface to access methods and fields on the entity, since it doesn't extend Entity
.
@Override
public T getImplementation() {
return this;
}
Lastly, getContainer
must return the EntityTypeContainer
corresponding to your entity class.
@Override
public EntityTypeContainer<T> getContainer() {
return ExampleModEntities.EXAMPLE;
}
IVariantTypes must implement all methods from IContainerEntity, and the following.
@Override
protected void defineSynchedData() {
super.defineSynchedData();
this.registerTypeKey();
}
@Override
public void addAdditionalSaveData(CompoundTag compound) {
super.addAdditionalSaveData(compound);
this.writeType(compound);
}
@Override
public void readAdditionalSaveData(CompoundTag compound) {
super.readAdditionalSaveData(compound);
this.readType(compound);
}
@Override
public SpawnGroupData finalizeSpawn(ServerLevelAccessor world, DifficultyInstance difficulty, MobSpawnType reason, SpawnGroupData livingdata, CompoundTag compound) {
return this.initAgeableData(world, reason, super.finalizeSpawn(world, difficulty, reason, livingdata, compound));
}
@Override
public AgableMob getBreedOffspring(ServerLevel world, AgableMob ageable) {
if (!(ageable instanceof IVariantTypes))
return null;
IVariantTypes<?> child = getBaseChild();
if (child == null)
return null;
return (AgableMob) child.setType(this.getOffspringType(this, (IVariantTypes<?>) ageable));
}
protected abstract EntityAnimalWithTypes getBaseChild();