Class EntityBuilder
java.lang.Object
de.eldoria.eldoutilities.entities.EntityBuilder
A class to build entities with a builder pattern.
- Since:
- 1.1.0
-
Method Summary
Modifier and TypeMethodDescriptionasInvulnerable
(boolean flag) Sets whether the entity is invulnerable or not.asPersistent
(boolean persistent) Sets whether or not the entity gets persisted.asSilent
(boolean flag) Sets whether the entity is silent or not.<T extends LivingEntity>
Tbuild()
Returns the builded entity and casts it to the requested type.static EntityBuilder
of
(EntityType entity, Location location) Returns a new EntityBuilder with an entity at the requested position.static EntityBuilder
of
(LivingEntity entity) Returns a new EntityBuilder with an entity at the requested position.setCollidable
(boolean collidable) Set if this entity will be subject to collisions with other entities.setInvisible
(boolean invisible) Sets whether the entity is invisible or not.<T extends LivingEntity>
EntityBuilderApplies a consumer on this entity after casting it to the requested type.with
(Consumer<LivingEntity> entityConsumer) Applies a consumer on this entitywithAbsorptionAmount
(double amount) Sets the entity's absorption amount.withAI
(boolean ai) Sets whether an entity will have AI.withAttribute
(Attribute attribute, double value) Sets theAttributeInstance.getBaseValue()
to the value which is required to get the target value onAttributeInstance.getValue()
for the requestedAttribute
withCustomName
(@Nullable String name) Sets a custom name on a mob or block.withFallDistance
(float distance) Sets the fall distance for this entitywithFireTicks
(int ticks) Sets the entity's current fire ticks (ticks before the entity stops being on fire).withGlowing
(boolean flag) Sets whether the entity has a team colored (default: white) glow.withGravity
(boolean gravity) Sets whether gravity applies to this entity.withHealth
(double health) Sets the entity's health from 0 toDamageable.getMaxHealth()
, where 0 is dead.withMetadata
(@NotNull String metadataKey, @NotNull MetadataValue newMetadataValue) Sets a metadata value in the implementing object's metadata store.withNBT
(Consumer<PersistentDataContainer> change) Applies changes to the persistent data container of the entitywithPassenger
(@NotNull Entity... passengers) Add a passenger to the vehicle.withPotionEffect
(@NotNull PotionEffect effect) Adds the givenPotionEffect
to the living entity.withRotation
(float yaw, float pitch) Sets the entity's rotation.Add a tag to this entity.withTicksLived
(int value) Sets the amount of ticks this entity has lived for.withVelocity
(@NotNull Vector velocity) Sets this entity's velocitywithVisibleCustomName
(boolean flag) Sets whether or not to display the mob's custom name client side.
-
Method Details
-
of
Returns a new EntityBuilder with an entity at the requested position.- Parameters:
entity
- entity to wrap- Returns:
- new EntityBuilder instance with entity
-
of
Returns a new EntityBuilder with an entity at the requested position.- Parameters:
entity
- entity type to spawnlocation
- location to spawn- Returns:
- new EntityBuilder instance with spawned entity
-
withPassenger
Add a passenger to the vehicle.- Parameters:
passengers
- One or more passengers to add- Returns:
- builder instance
- Since:
- 1.1.0
-
withScoreboardTag
Add a tag to this entity.
Entities can have no more than 1024 tags.- Parameters:
tag
- the tag to add- Returns:
- builder instance
- Since:
- 1.1.0
-
withVelocity
Sets this entity's velocity- Parameters:
velocity
- New velocity to travel with- Returns:
- builder instance
- Since:
- 1.1.0
-
withRotation
Sets the entity's rotation.Note that if the entity is affected by AI, it may override this rotation.
- Parameters:
yaw
- the yawpitch
- the pitch- Returns:
- builder instance
- Throws:
UnsupportedOperationException
- if used for players- Since:
- 1.1.0
-
withFireTicks
Sets the entity's current fire ticks (ticks before the entity stops being on fire).- Parameters:
ticks
- Current ticks remaining- Returns:
- builder instance
-
asPersistent
Sets whether or not the entity gets persisted.- Parameters:
persistent
- the persistence status- Returns:
- builder instance
- See Also:
-
withFallDistance
Sets the fall distance for this entity- Parameters:
distance
- The new distance.- Returns:
- builder instance
-
withTicksLived
Sets the amount of ticks this entity has lived for.This is the equivalent to "age" in entities. May not be less than one tick.
- Parameters:
value
- Age of entity- Returns:
- builder instance
-
withVisibleCustomName
Sets whether or not to display the mob's custom name client side. The name will be displayed above the mob similarly to a player.This value has no effect on players, they will always display their name.
- Parameters:
flag
- custom name or not- Returns:
- builder instance
-
withGlowing
Sets whether the entity has a team colored (default: white) glow. nb: this refers to the 'Glowing' entity property, not whether a glowing potion effect is applied- Parameters:
flag
- if the entity is glowing- Returns:
- builder instance
-
asInvulnerable
Sets whether the entity is invulnerable or not.When an entity is invulnerable it can only be damaged by players in creative mode.
- Parameters:
flag
- if the entity is invulnerable- Returns:
- builder instance
-
asSilent
Sets whether the entity is silent or not.When an entity is silent it will not produce any sound.
- Parameters:
flag
- if the entity is silent- Returns:
- builder instance
-
withGravity
Sets whether gravity applies to this entity.- Parameters:
gravity
- whether gravity should apply- Returns:
- builder instance
-
withMetadata
public EntityBuilder withMetadata(@NotNull @NotNull String metadataKey, @NotNull @NotNull MetadataValue newMetadataValue) Sets a metadata value in the implementing object's metadata store.- Parameters:
metadataKey
- A unique key to identify this metadata.newMetadataValue
- The metadata value to apply.- Returns:
- builder instance
- Throws:
IllegalArgumentException
- If value is null, or the owning plugin is null
-
withCustomName
Sets a custom name on a mob or block. This name will be used in death messages and can be sent to the client as a nameplate over the mob.Setting the name to null or an empty string will clear it.
This value has no effect on players, they will always use their real name.
- Parameters:
name
- the name to set- Returns:
- builder instance
-
withNBT
Applies changes to the persistent data container of the entity- Parameters:
change
- conumer for data container- Returns:
- builder instance
-
withAttribute
Sets theAttributeInstance.getBaseValue()
to the value which is required to get the target value onAttributeInstance.getValue()
for the requestedAttribute
- Parameters:
attribute
- attribute type to set if presentvalue
- target value which should be retrieved viaAttributeInstance.getValue()
- Returns:
- builder instance
-
withPotionEffect
Adds the givenPotionEffect
to the living entity.- Parameters:
effect
- PotionEffect to be added- Returns:
- builder instance
-
withAI
Sets whether an entity will have AI.The entity will be completely unable to move if it has no AI.
- Parameters:
ai
- whether the mob will have AI or not.- Returns:
- builder instance
-
with
Applies a consumer on this entity- Parameters:
entityConsumer
- consumer- Returns:
- builder instance
-
with
Applies a consumer on this entity after casting it to the requested type.- Type Parameters:
T
- type of entity- Parameters:
clazz
- class of entityentityConsumer
- consumer- Returns:
- builder instance
-
setCollidable
Set if this entity will be subject to collisions with other entities.Exemptions to this rule can be managed with
LivingEntity.getCollidableExemptions()
- Parameters:
collidable
- collision status- Returns:
- builder instance
-
setInvisible
Sets whether the entity is invisible or not.- Parameters:
invisible
- If the entity is invisible- Returns:
- builder instance
-
withHealth
Sets the entity's health from 0 toDamageable.getMaxHealth()
, where 0 is dead.- Parameters:
health
- New health represented from 0 to max- Returns:
- builder instance
-
withAbsorptionAmount
Sets the entity's absorption amount.- Parameters:
amount
- new absorption amount from 0- Returns:
- builder instance
- Throws:
IllegalArgumentException
- thrown if health is < 0 or non-finite.
-
build
Returns the builded entity and casts it to the requested type.- Type Parameters:
T
- type of entity- Returns:
- entity instance
-