Skip to content

Commit

Permalink
Add dEntity.has_ai property
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed Apr 5, 2015
1 parent 500a42c commit 0e7f1e2
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 26 deletions.
1 change: 1 addition & 0 deletions src/main/java/net/aufdemrand/denizen/Denizen.java
Expand Up @@ -636,6 +636,7 @@ public void onEnable() {

// register core dEntity properties
propertyParser.registerProperty(EntityAge.class, dEntity.class);
propertyParser.registerProperty(EntityAI.class, dEntity.class);
propertyParser.registerProperty(EntityAngry.class, dEntity.class);
propertyParser.registerProperty(EntityColor.class, dEntity.class);
propertyParser.registerProperty(EntityCritical.class, dEntity.class);
Expand Down
26 changes: 0 additions & 26 deletions src/main/java/net/aufdemrand/denizen/objects/dEntity.java
Expand Up @@ -1877,19 +1877,6 @@ else return new Element("null")
return new Duration(entity.getTicksLived() / 20)
.getAttribute(attribute.fulfill(1));

// <--[tag]
// @attribute <e@entity.has_ai>
// @returns Element(Boolean)
// @group attributes
// @description
// Returns whether the entity uses the default Minecraft
// AI to roam and look around.
// -->
if (attribute.startsWith("has_ai"))
return new Element(!EntityMovement.isAIDisabled(getBukkitEntity()))
.getAttribute(attribute.fulfill(1));


/////////////////////
// TYPE ATTRIBUTES
/////////////////
Expand Down Expand Up @@ -2273,19 +2260,6 @@ public void adjust(Mechanism mechanism) {
getLivingEntity().playEffect(EntityEffect.DEATH);
}

// <--[mechanism]
// @object dEntity
// @name toggle_ai
// @input Element(Boolean)
// @description
// Sets whether this entity will use the default
// Minecraft AI to roam and look around.
// @tags
// <e@entity.has_ai>
// -->
if (mechanism.matches("toggle_ai") && mechanism.requireBoolean()) {
EntityMovement.toggleAI(getBukkitEntity(), value.asBoolean());
}

// Iterate through this object's properties' mechanisms
for (Property property : PropertyParser.getProperties(this)) {
Expand Down
@@ -0,0 +1,92 @@
package net.aufdemrand.denizen.objects.properties.entity;

import net.aufdemrand.denizen.objects.dEntity;
import net.aufdemrand.denizen.utilities.entity.EntityMovement;
import net.aufdemrand.denizencore.objects.Element;
import net.aufdemrand.denizencore.objects.Mechanism;
import net.aufdemrand.denizencore.objects.dObject;
import net.aufdemrand.denizencore.objects.properties.Property;
import net.aufdemrand.denizencore.tags.Attribute;

public class EntityAI implements Property {

public static boolean describes(dObject entity) {
return entity instanceof dEntity
&& ((dEntity) entity).isLivingEntity();
}

public static EntityAI getFrom(dObject entity) {
if (!describes(entity)) return null;

else return new EntityAI((dEntity) entity);
}


///////////////////
// Instance Fields and Methods
/////////////

private EntityAI(dEntity ent) {
entity = ent;
}

dEntity entity;

/////////
// Property Methods
///////

@Override
public String getPropertyString() {
return String.valueOf(!EntityMovement.isAIDisabled(entity.getBukkitEntity()));
}

@Override
public String getPropertyId() {
return "has_ai";
}


///////////
// dObject Attributes
////////

@Override
public String getAttribute(Attribute attribute) {

if (attribute == null) return "null";

// <--[tag]
// @attribute <e@entity.has_ai>
// @returns Element(Boolean)
// @group attributes
// @description
// Returns whether the entity uses the default Minecraft
// AI to roam and look around.
// -->
if (attribute.startsWith("has_ai"))
return new Element(!EntityMovement.isAIDisabled(entity.getBukkitEntity()))
.getAttribute(attribute.fulfill(1));


return null;
}

@Override
public void adjust(Mechanism mechanism) {

// <--[mechanism]
// @object dEntity
// @name has_ai
// @input Element(Boolean)
// @description
// Sets whether this entity will use the default
// Minecraft AI to roam and look around.
// @tags
// <e@entity.has_ai>
// -->
if ((mechanism.matches("has_ai") || mechanism.matches("toggle_ai")) && mechanism.requireBoolean()) {
EntityMovement.toggleAI(entity.getBukkitEntity(), mechanism.getValue().asBoolean());
}
}
}

0 comments on commit 0e7f1e2

Please sign in to comment.