Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Interaction entity support * use duration instead of time for interactions
- Loading branch information
Showing
6 changed files
with
162 additions
and
106 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
98 changes: 37 additions & 61 deletions
98
plugin/src/main/java/com/denizenscript/denizen/objects/properties/entity/EntityAware.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,86 +1,62 @@ | ||
package com.denizenscript.denizen.objects.properties.entity; | ||
|
||
import com.denizenscript.denizen.nms.NMSHandler; | ||
import com.denizenscript.denizen.nms.NMSVersion; | ||
import com.denizenscript.denizen.objects.EntityTag; | ||
import com.denizenscript.denizencore.objects.core.ElementTag; | ||
import com.denizenscript.denizencore.objects.Mechanism; | ||
import com.denizenscript.denizencore.objects.ObjectTag; | ||
import com.denizenscript.denizencore.objects.properties.Property; | ||
import com.denizenscript.denizencore.objects.properties.PropertyParser; | ||
import com.denizenscript.denizencore.objects.core.ElementTag; | ||
import org.bukkit.entity.Interaction; | ||
import org.bukkit.entity.Mob; | ||
|
||
public class EntityAware implements Property { | ||
public class EntityAware extends EntityProperty<ElementTag> { | ||
|
||
// <--[property] | ||
// @object EntityTag | ||
// @name is_aware | ||
// @input ElementTag(Boolean) | ||
// @description | ||
// For mobs (<@link tag EntityTag.is_mob>), this is whether the entity is aware of its surroundings. | ||
// Unaware entities will not perform any actions on their own, such as pathfinding or attacking. | ||
// Similar to <@link property EntityTag.has_ai>, except allows the entity to be moved by gravity, being pushed or attacked, etc. | ||
// For interaction entities, this is whether interacting with them should trigger a response (arm swings, sounds, etc.). | ||
// --> | ||
|
||
public static boolean describes(ObjectTag entity) { | ||
return entity instanceof EntityTag | ||
&& ((EntityTag) entity).isMobType(); | ||
public static boolean describes(EntityTag entity) { | ||
return entity.getBukkitEntity() instanceof Mob || (NMSHandler.getVersion().isAtLeast(NMSVersion.v1_19) && entity.getBukkitEntity() instanceof Interaction); | ||
} | ||
|
||
public static EntityAware getFrom(ObjectTag entity) { | ||
if (!describes(entity)) { | ||
return null; | ||
} | ||
else { | ||
return new EntityAware((EntityTag) entity); | ||
@Override | ||
public ElementTag getPropertyValue() { | ||
if (NMSHandler.getVersion().isAtLeast(NMSVersion.v1_19) && getEntity() instanceof Interaction interaction) { | ||
return new ElementTag(interaction.isResponsive()); | ||
} | ||
return new ElementTag(as(Mob.class).isAware()); | ||
} | ||
|
||
public static final String[] handledMechs = new String[] { | ||
"is_aware" | ||
}; | ||
|
||
public EntityAware(EntityTag entity) { | ||
this.entity = entity; | ||
@Override | ||
public boolean isDefaultValue(ElementTag value) { | ||
// Default value is true for mobs, false for interaction entities | ||
return value.asBoolean() == getEntity() instanceof Mob; | ||
} | ||
|
||
EntityTag entity; | ||
|
||
@Override | ||
public String getPropertyString() { | ||
return String.valueOf(getMob().isAware()); | ||
public void setPropertyValue(ElementTag value, Mechanism mechanism) { | ||
if (!mechanism.requireBoolean()) { | ||
return; | ||
} | ||
if (NMSHandler.getVersion().isAtLeast(NMSVersion.v1_19) && getEntity() instanceof Interaction interaction) { | ||
interaction.setResponsive(value.asBoolean()); | ||
return; | ||
} | ||
as(Mob.class).setAware(value.asBoolean()); | ||
} | ||
|
||
@Override | ||
public String getPropertyId() { | ||
return "is_aware"; | ||
} | ||
|
||
public Mob getMob() { | ||
return (Mob) entity.getBukkitEntity(); | ||
} | ||
|
||
public static void register() { | ||
|
||
// <--[tag] | ||
// @attribute <EntityTag.is_aware> | ||
// @returns ElementTag(Boolean) | ||
// @mechanism EntityTag.is_aware | ||
// @group attributes | ||
// @description | ||
// Returns whether the entity is aware of its surroundings. | ||
// Unaware entities will not perform any actions on their own, such as pathfinding or attacking. | ||
// Similar to <@link tag EntityTag.has_ai>, except allows the entity to be moved by gravity, being pushed or attacked, etc. | ||
// --> | ||
PropertyParser.registerTag(EntityAware.class, ElementTag.class, "is_aware", (attribute, entity) -> { | ||
return new ElementTag(entity.getMob().isAware()); | ||
}); | ||
} | ||
|
||
@Override | ||
public void adjust(Mechanism mechanism) { | ||
|
||
// <--[mechanism] | ||
// @object EntityTag | ||
// @name is_aware | ||
// @input ElementTag(Boolean) | ||
// @description | ||
// Sets whether the entity is aware of its surroundings. | ||
// Unaware entities will not perform any actions on their own, such as pathfinding or attacking. | ||
// Similar to <@link mechanism EntityTag.has_ai>, except allows the entity to be moved by gravity, being pushed or attacked, etc. | ||
// @tags | ||
// <EntityTag.is_aware> | ||
// --> | ||
if (mechanism.matches("is_aware") && mechanism.requireBoolean()) { | ||
getMob().setAware(mechanism.getValue().asBoolean()); | ||
} | ||
autoRegister("is_aware", EntityAware.class, ElementTag.class, false); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.