From d80c9382bd75fe35ffbdea540f8017ced5a5bf0e Mon Sep 17 00:00:00 2001 From: GrandPartyMask <16635607+MusicScore@users.noreply.github.com> Date: Sun, 7 Apr 2019 17:13:39 -0400 Subject: [PATCH] Expand arrow mecs, additional minor fixes (#1946) * Minor fix in item.potion_effects meta * Rename "plant_growth" dMaterial property to "age" * Fix potions erroring out below 1.11 * Expand existing arrow properties, add new arrow properties * Fix meta, replace "is_plant" with "is_ageable" * Fix arrow damage meta to be clearer * Revert "Minor fix in item.potion_effects meta" --- .../java/net/aufdemrand/denizen/Denizen.java | 8 +- .../aufdemrand/denizen/objects/dEntity.java | 32 +++++ .../aufdemrand/denizen/objects/dMaterial.java | 20 ++- .../properties/entity/EntityArrowDamage.java | 120 ++++++++++++++++++ .../properties/entity/EntityCritical.java | 7 +- .../properties/entity/EntityKnockback.java | 7 +- .../properties/entity/EntityPickupStatus.java | 103 +++++++++++++++ .../objects/properties/item/ItemColor.java | 24 ++-- ...erialPlantGrowth.java => MaterialAge.java} | 49 ++++--- 9 files changed, 320 insertions(+), 50 deletions(-) create mode 100644 plugin/src/main/java/net/aufdemrand/denizen/objects/properties/entity/EntityArrowDamage.java create mode 100644 plugin/src/main/java/net/aufdemrand/denizen/objects/properties/entity/EntityPickupStatus.java rename plugin/src/main/java/net/aufdemrand/denizen/objects/properties/material/{MaterialPlantGrowth.java => MaterialAge.java} (58%) diff --git a/plugin/src/main/java/net/aufdemrand/denizen/Denizen.java b/plugin/src/main/java/net/aufdemrand/denizen/Denizen.java index 50d3712841..a4af342ccb 100644 --- a/plugin/src/main/java/net/aufdemrand/denizen/Denizen.java +++ b/plugin/src/main/java/net/aufdemrand/denizen/Denizen.java @@ -31,7 +31,7 @@ import net.aufdemrand.denizen.objects.properties.inventory.InventorySize; import net.aufdemrand.denizen.objects.properties.inventory.InventoryTitle; import net.aufdemrand.denizen.objects.properties.item.*; -import net.aufdemrand.denizen.objects.properties.material.MaterialPlantGrowth; +import net.aufdemrand.denizen.objects.properties.material.MaterialAge; import net.aufdemrand.denizen.objects.properties.trade.*; import net.aufdemrand.denizen.scripts.commands.BukkitCommandRegistry; import net.aufdemrand.denizen.scripts.containers.core.*; @@ -809,6 +809,7 @@ public void onEnable() { PropertyParser.registerProperty(EntityAngry.class, dEntity.class); PropertyParser.registerProperty(EntityAreaEffectCloud.class, dEntity.class); PropertyParser.registerProperty(EntityArmorBonus.class, dEntity.class); + PropertyParser.registerProperty(EntityArrowDamage.class, dEntity.class); PropertyParser.registerProperty(EntityInvulnerable.class, dEntity.class); PropertyParser.registerProperty(EntityBoatType.class, dEntity.class); PropertyParser.registerProperty(EntityArmorPose.class, dEntity.class); @@ -838,6 +839,9 @@ public void onEnable() { PropertyParser.registerProperty(EntityMarker.class, dEntity.class); PropertyParser.registerProperty(EntityMaxFuseTicks.class, dEntity.class); PropertyParser.registerProperty(EntityPainting.class, dEntity.class); + if (NMSHandler.getVersion().isAtLeast(NMSVersion.v1_11_R1)) { + PropertyParser.registerProperty(EntityPickupStatus.class, dEntity.class); + } PropertyParser.registerProperty(EntityPotion.class, dEntity.class); PropertyParser.registerProperty(EntityPowered.class, dEntity.class); PropertyParser.registerProperty(EntityProfession.class, dEntity.class); @@ -896,7 +900,7 @@ public void onEnable() { if (NMSHandler.getVersion().isAtLeast(NMSVersion.v1_13_R2)) { // register core dMaterial properties - PropertyParser.registerProperty(MaterialPlantGrowth.class, dMaterial.class); + PropertyParser.registerProperty(MaterialAge.class, dMaterial.class); } if (NMSHandler.getVersion().isAtLeast(NMSVersion.v1_12_R1)) { diff --git a/plugin/src/main/java/net/aufdemrand/denizen/objects/dEntity.java b/plugin/src/main/java/net/aufdemrand/denizen/objects/dEntity.java index 47826a25a3..e9eeca555c 100644 --- a/plugin/src/main/java/net/aufdemrand/denizen/objects/dEntity.java +++ b/plugin/src/main/java/net/aufdemrand/denizen/objects/dEntity.java @@ -27,6 +27,7 @@ import net.citizensnpcs.api.CitizensAPI; import net.citizensnpcs.api.npc.NPC; import org.bukkit.*; +import org.bukkit.block.Block; import org.bukkit.block.BlockFace; import org.bukkit.entity.*; import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause; @@ -2263,6 +2264,37 @@ && getBukkitEntity() instanceof Item) { return new Duration(((Item) getBukkitEntity()).getPickupDelay() * 20).getAttribute(attribute.fulfill(1)); } + // <--[tag] + // @attribute + // @returns Element(Boolean) + // @group attributes + // @description + // Returns whether or not the arrow/trident entity is in a block. + // --> + if (NMSHandler.getVersion().isAtLeast(NMSVersion.v1_12_R1) && attribute.startsWith("is_in_block")) { + if (getBukkitEntity() instanceof Arrow) { + return new Element(((Arrow) getBukkitEntity()).isInBlock()).getAttribute(attribute.fulfill(1)); + } + return null; + } + + // <--[tag] + // @attribute + // @returns dLocation + // @group attributes + // @description + // Returns the location of the block that the arrow/trident entity is attached to. + // --> + if (NMSHandler.getVersion().isAtLeast(NMSVersion.v1_12_R1) && attribute.startsWith("attached_block")) { + if (getBukkitEntity() instanceof Arrow) { + Block attachedBlock = ((Arrow) getBukkitEntity()).getAttachedBlock(); + if (attachedBlock != null) { + return new dLocation(attachedBlock.getLocation()).getAttribute(attribute.fulfill(1)); + } + } + return null; + } + // <--[tag] // @attribute // @returns Element(Boolean) diff --git a/plugin/src/main/java/net/aufdemrand/denizen/objects/dMaterial.java b/plugin/src/main/java/net/aufdemrand/denizen/objects/dMaterial.java index e05ed78d31..8845b604a3 100644 --- a/plugin/src/main/java/net/aufdemrand/denizen/objects/dMaterial.java +++ b/plugin/src/main/java/net/aufdemrand/denizen/objects/dMaterial.java @@ -4,7 +4,7 @@ import net.aufdemrand.denizen.nms.NMSVersion; import net.aufdemrand.denizen.nms.abstracts.ModernBlockData; import net.aufdemrand.denizen.nms.interfaces.BlockData; -import net.aufdemrand.denizen.objects.properties.material.MaterialPlantGrowth; +import net.aufdemrand.denizen.objects.properties.material.MaterialAge; import net.aufdemrand.denizen.tags.BukkitTagContext; import net.aufdemrand.denizen.utilities.blocks.OldMaterialsHelper; import net.aufdemrand.denizen.utilities.debugging.dB; @@ -458,18 +458,26 @@ public String run(Attribute attribute, dObject object) { }); // <--[tag] - // @attribute + // @attribute // @returns Element(Boolean) // @group properties // @description - // Returns whether the material is a plant block material. - // When this returns true, <@link tag m@material.plant_growth>, <@link tag m@material.maximum_plant_growth>, - // and <@link mechanism dMaterial.plant_growth> are accessible. + // Returns whether the material is an ageable material. + // When this returns true, <@link tag m@material.age>, <@link tag m@material.maximum_age>, + // and <@link mechanism dMaterial.age> are accessible. // --> + registerTag("is_ageable", new TagRunnable() { + @Override + public String run(Attribute attribute, dObject object) { + return new Element(MaterialAge.describes(object)) + .getAttribute(attribute.fulfill(1)); + } + }); + registerTag("is_plant", new TagRunnable() { @Override public String run(Attribute attribute, dObject object) { - return new Element(MaterialPlantGrowth.describes(object)) + return new Element(MaterialAge.describes(object)) .getAttribute(attribute.fulfill(1)); } }); diff --git a/plugin/src/main/java/net/aufdemrand/denizen/objects/properties/entity/EntityArrowDamage.java b/plugin/src/main/java/net/aufdemrand/denizen/objects/properties/entity/EntityArrowDamage.java new file mode 100644 index 0000000000..677d064e6b --- /dev/null +++ b/plugin/src/main/java/net/aufdemrand/denizen/objects/properties/entity/EntityArrowDamage.java @@ -0,0 +1,120 @@ +package net.aufdemrand.denizen.objects.properties.entity; + +import net.aufdemrand.denizen.nms.NMSHandler; +import net.aufdemrand.denizen.nms.NMSVersion; +import net.aufdemrand.denizen.objects.dEntity; +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; +import org.bukkit.entity.Arrow; + +public class EntityArrowDamage implements Property { + + public static boolean describes(dObject entity) { + return entity instanceof dEntity && ((dEntity) entity).getBukkitEntity() instanceof Arrow; + } + + public static EntityArrowDamage getFrom(dObject entity) { + if (!describes(entity)) { + return null; + } + return new EntityArrowDamage((dEntity) entity); + } + + public static final String[] handledTags = { + "damage" + }; + + public static final String[] handledMechs = { + "damage" + }; + + + /////////////////// + // Instance Fields and Methods + ///////////// + + private EntityArrowDamage(dEntity entity) { + dentity = entity; + } + + dEntity dentity; + + ///////// + // Property Methods + /////// + + @Override + public String getPropertyString() { + if (NMSHandler.getVersion().isAtLeast(NMSVersion.v1_13_R2)) { + return String.valueOf(((Arrow) dentity.getBukkitEntity()).getDamage()); + } + else { + return String.valueOf(((Arrow) dentity.getBukkitEntity()).spigot().getDamage()); + } + } + + @Override + public String getPropertyId() { + return "damage"; + } + + /////////// + // dObject Attributes + //////// + + @Override + public String getAttribute(Attribute attribute) { + + if (attribute == null) { + return "null"; + } + + // <--[tag] + // @attribute + // @returns Element(Decimal) + // @mechanism dEntity.damage + // @group properties + // @description + // Returns the damage that the arrow/trident will inflict. + // NOTE: The actual damage dealt by the arrow/trident may be different depending on the projectile's flight speed. + // --> + if (attribute.startsWith("damage")) { + if (NMSHandler.getVersion().isAtLeast(NMSVersion.v1_13_R2)) { + return new Element(((Arrow) dentity.getBukkitEntity()).getDamage()) + .getAttribute(attribute.fulfill(1)); + } + else { + return new Element(((Arrow) dentity.getBukkitEntity()).spigot().getDamage()) + .getAttribute(attribute.fulfill(1)); + } + } + + return null; + } + + @Override + public void adjust(Mechanism mechanism) { + + // <--[mechanism] + // @object dEntity + // @name damage + // @input Element(Decimal) + // @description + // Changes how much damage an arrow/trident will inflict. + // @tags + // + // --> + + if (mechanism.matches("damage") && mechanism.requireDouble()) { + if (NMSHandler.getVersion().isAtLeast(NMSVersion.v1_13_R2)) { + ((Arrow) dentity.getBukkitEntity()).setDamage(mechanism.getValue().asDouble()); + } + else { + ((Arrow) dentity.getBukkitEntity()).spigot().setDamage(mechanism.getValue().asDouble()); + } + } + } +} diff --git a/plugin/src/main/java/net/aufdemrand/denizen/objects/properties/entity/EntityCritical.java b/plugin/src/main/java/net/aufdemrand/denizen/objects/properties/entity/EntityCritical.java index 80db7d758c..8577afb74e 100644 --- a/plugin/src/main/java/net/aufdemrand/denizen/objects/properties/entity/EntityCritical.java +++ b/plugin/src/main/java/net/aufdemrand/denizen/objects/properties/entity/EntityCritical.java @@ -7,12 +7,11 @@ import net.aufdemrand.denizencore.objects.properties.Property; import net.aufdemrand.denizencore.tags.Attribute; import org.bukkit.entity.Arrow; -import org.bukkit.entity.EntityType; public class EntityCritical implements Property { public static boolean describes(dObject entity) { - return entity instanceof dEntity && ((dEntity) entity).getBukkitEntityType() == EntityType.ARROW; + return entity instanceof dEntity && ((dEntity) entity).getBukkitEntity() instanceof Arrow; } public static EntityCritical getFrom(dObject entity) { @@ -79,7 +78,7 @@ public String getAttribute(Attribute attribute) { // @mechanism dEntity.critical // @group properties // @description - // If the entity is an arrow, returns whether the arrow is critical. + // If the entity is an arrow or trident, returns whether the arrow/trident is critical. // --> if (attribute.startsWith("critical")) { return new Element(((Arrow) critical.getBukkitEntity()).isCritical()) @@ -97,7 +96,7 @@ public void adjust(Mechanism mechanism) { // @name critical // @input Element(Boolean) // @description - // Changes whether an arrow is critical. + // Changes whether an arrow/trident is critical. // @tags // // --> diff --git a/plugin/src/main/java/net/aufdemrand/denizen/objects/properties/entity/EntityKnockback.java b/plugin/src/main/java/net/aufdemrand/denizen/objects/properties/entity/EntityKnockback.java index 5885337358..3dfa8c85b3 100644 --- a/plugin/src/main/java/net/aufdemrand/denizen/objects/properties/entity/EntityKnockback.java +++ b/plugin/src/main/java/net/aufdemrand/denizen/objects/properties/entity/EntityKnockback.java @@ -7,12 +7,11 @@ import net.aufdemrand.denizencore.objects.properties.Property; import net.aufdemrand.denizencore.tags.Attribute; import org.bukkit.entity.Arrow; -import org.bukkit.entity.EntityType; public class EntityKnockback implements Property { public static boolean describes(dObject entity) { - return entity instanceof dEntity && ((dEntity) entity).getBukkitEntityType() == EntityType.ARROW; + return entity instanceof dEntity && ((dEntity) entity).getBukkitEntity() instanceof Arrow; } public static EntityKnockback getFrom(dObject entity) { @@ -74,7 +73,7 @@ public String getAttribute(Attribute attribute) { // @mechanism dEntity.knockback // @group properties // @description - // If the entity is an arrow, returns the knockback strength of the arrow. + // If the entity is an arrow or trident, returns the knockback strength of the arrow/trident. // --> if (attribute.startsWith("knockback")) { return new Element(((Arrow) arrow.getBukkitEntity()).getKnockbackStrength()) @@ -92,7 +91,7 @@ public void adjust(Mechanism mechanism) { // @name knockback // @input Element(Number) // @description - // Changes an arrow's knockback strength. + // Changes an arrow's/trident's knockback strength. // @tags // // --> diff --git a/plugin/src/main/java/net/aufdemrand/denizen/objects/properties/entity/EntityPickupStatus.java b/plugin/src/main/java/net/aufdemrand/denizen/objects/properties/entity/EntityPickupStatus.java new file mode 100644 index 0000000000..55e92055a6 --- /dev/null +++ b/plugin/src/main/java/net/aufdemrand/denizen/objects/properties/entity/EntityPickupStatus.java @@ -0,0 +1,103 @@ +package net.aufdemrand.denizen.objects.properties.entity; + +import net.aufdemrand.denizen.objects.dEntity; +import net.aufdemrand.denizen.utilities.debugging.dB; +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; +import org.bukkit.entity.Arrow; + +public class EntityPickupStatus implements Property { + + public static boolean describes(dObject entity) { + return entity instanceof dEntity && ((dEntity) entity).getBukkitEntity() instanceof Arrow; + } + + public static EntityPickupStatus getFrom(dObject entity) { + if (!describes(entity)) { + return null; + } + return new EntityPickupStatus((dEntity) entity); + } + + public static final String[] handledTags = { + "pickup_status" + }; + + public static final String[] handledMechs = { + "pickup_status" + }; + + + /////////////////// + // Instance Fields and Methods + ///////////// + + private EntityPickupStatus(dEntity entity) { + dentity = entity; + } + + dEntity dentity; + + ///////// + // Property Methods + /////// + + @Override + public String getPropertyString() { + return ((Arrow) dentity.getBukkitEntity()).getPickupStatus().toString(); + } + + @Override + public String getPropertyId() { + return "pickup_status"; + } + + /////////// + // dObject Attributes + //////// + + @Override + public String getAttribute(Attribute attribute) { + + if (attribute == null) { + return "null"; + } + + // <--[tag] + // @attribute + // @returns Element + // @mechanism dEntity.pickup_status + // @group properties + // @description + // If the entity is an arrow or trident, returns the pickup status of the arrow/trident. + // --> + if (attribute.startsWith("pickup_status")) { + return new Element(((Arrow) dentity.getBukkitEntity()).getPickupStatus().toString()) + .getAttribute(attribute.fulfill(1)); + } + + return null; + } + + @Override + public void adjust(Mechanism mechanism) { + + // <--[mechanism] + // @object dEntity + // @name pickup_status + // @input Element + // @description + // Changes the pickup status of an arrow/trident. + // Available pickup statuses can be found here: <@link url https://hub.spigotmc.org/javadocs/spigot/org/bukkit/entity/Arrow.PickupStatus.html> + // @tags + // + // --> + + if (mechanism.matches("pickup_status") && mechanism.requireEnum(false, Arrow.PickupStatus.values())) { + ((Arrow) dentity.getBukkitEntity()).setPickupStatus(Arrow.PickupStatus.valueOf(mechanism.getValue().asString().toUpperCase())); + } + } +} diff --git a/plugin/src/main/java/net/aufdemrand/denizen/objects/properties/item/ItemColor.java b/plugin/src/main/java/net/aufdemrand/denizen/objects/properties/item/ItemColor.java index 83124ee2cd..7b9672d2c3 100644 --- a/plugin/src/main/java/net/aufdemrand/denizen/objects/properties/item/ItemColor.java +++ b/plugin/src/main/java/net/aufdemrand/denizen/objects/properties/item/ItemColor.java @@ -1,5 +1,7 @@ package net.aufdemrand.denizen.objects.properties.item; +import net.aufdemrand.denizen.nms.NMSHandler; +import net.aufdemrand.denizen.nms.NMSVersion; import net.aufdemrand.denizen.objects.dColor; import net.aufdemrand.denizen.objects.dItem; import net.aufdemrand.denizencore.objects.Mechanism; @@ -20,9 +22,10 @@ public static boolean describes(dObject item) { || ((dItem) item).getItemStack().getType() == Material.LEATHER_CHESTPLATE || ((dItem) item).getItemStack().getType() == Material.LEATHER_HELMET || ((dItem) item).getItemStack().getType() == Material.LEATHER_LEGGINGS - || ((dItem) item).getItemStack().getType() == Material.POTION - || ((dItem) item).getItemStack().getType() == Material.SPLASH_POTION - || ((dItem) item).getItemStack().getType() == Material.LINGERING_POTION); + || (NMSHandler.getVersion().isAtLeast(NMSVersion.v1_11_R1) + && (((dItem) item).getItemStack().getType() == Material.POTION + || ((dItem) item).getItemStack().getType() == Material.SPLASH_POTION + || ((dItem) item).getItemStack().getType() == Material.LINGERING_POTION))); } public static ItemColor getFrom(dObject _item) { @@ -66,9 +69,10 @@ public String getAttribute(Attribute attribute) { // --> if (attribute.startsWith("color") || attribute.startsWith("dye_color")) { Material mat = item.getItemStack().getType(); - if (mat == Material.POTION + if (NMSHandler.getVersion().isAtLeast(NMSVersion.v1_11_R1) + && (mat == Material.POTION || mat == Material.LINGERING_POTION - || mat == Material.SPLASH_POTION) { + || mat == Material.SPLASH_POTION)) { PotionMeta pm = (PotionMeta) item.getItemStack().getItemMeta(); if (!pm.hasColor()) { return new dColor(Color.WHITE).getAttribute(attribute.fulfill((1))); @@ -85,9 +89,10 @@ public String getAttribute(Attribute attribute) { @Override public String getPropertyString() { Material mat = item.getItemStack().getType(); - if (mat == Material.POTION + if (NMSHandler.getVersion().isAtLeast(NMSVersion.v1_11_R1) + && (mat == Material.POTION || mat == Material.LINGERING_POTION - || mat == Material.SPLASH_POTION) { + || mat == Material.SPLASH_POTION)) { PotionMeta pm = (PotionMeta) item.getItemStack().getItemMeta(); if (!pm.hasColor()) { return null; @@ -119,9 +124,10 @@ public void adjust(Mechanism mechanism) { || mechanism.matches("color")) && (mechanism.requireObject(dColor.class))) { dColor color = mechanism.valueAsType(dColor.class); Material mat = item.getItemStack().getType(); - if (mat == Material.POTION + if (NMSHandler.getVersion().isAtLeast(NMSVersion.v1_11_R1) + && (mat == Material.POTION || mat == Material.LINGERING_POTION - || mat == Material.SPLASH_POTION) { + || mat == Material.SPLASH_POTION)) { PotionMeta meta = (PotionMeta) item.getItemStack().getItemMeta(); meta.setColor(color.getColor()); item.getItemStack().setItemMeta(meta); diff --git a/plugin/src/main/java/net/aufdemrand/denizen/objects/properties/material/MaterialPlantGrowth.java b/plugin/src/main/java/net/aufdemrand/denizen/objects/properties/material/MaterialAge.java similarity index 58% rename from plugin/src/main/java/net/aufdemrand/denizen/objects/properties/material/MaterialPlantGrowth.java rename to plugin/src/main/java/net/aufdemrand/denizen/objects/properties/material/MaterialAge.java index 679be226e2..2dad586f04 100644 --- a/plugin/src/main/java/net/aufdemrand/denizen/objects/properties/material/MaterialPlantGrowth.java +++ b/plugin/src/main/java/net/aufdemrand/denizen/objects/properties/material/MaterialAge.java @@ -9,7 +9,7 @@ import net.aufdemrand.denizencore.tags.Attribute; import org.bukkit.block.data.Ageable; -public class MaterialPlantGrowth implements Property { +public class MaterialAge implements Property { public static boolean describes(dObject material) { return material instanceof dMaterial @@ -17,25 +17,25 @@ public static boolean describes(dObject material) { && ((dMaterial) material).getModernData().data instanceof Ageable; } - public static MaterialPlantGrowth getFrom(dObject _material) { + public static MaterialAge getFrom(dObject _material) { if (!describes(_material)) { return null; } else { - return new MaterialPlantGrowth((dMaterial) _material); + return new MaterialAge((dMaterial) _material); } } public static final String[] handledTags = new String[] { - "maximum_plant_growth", "plant_growth" + "maximum_age", "age", "maximum_plant_growth", "plant_growth" }; public static final String[] handledMechs = new String[] { - "plant_growth" + "age", "plant_growth" }; - private MaterialPlantGrowth(dMaterial _material) { + private MaterialAge(dMaterial _material) { material = _material; } @@ -49,27 +49,26 @@ public String getAttribute(Attribute attribute) { } // <--[tag] - // @attribute + // @attribute // @returns Element(Number) // @group properties // @description - // Returns the maximum plant growth stage for a plant material. + // Returns the maximum age for an ageable material. // --> - if (attribute.startsWith("maximum_plant_growth")) { + if (attribute.startsWith("maximum_age") || attribute.startsWith("maximum_plant_growth")) { return new Element(getMax()).getAttribute(attribute.fulfill(1)); } // <--[tag] - // @attribute + // @attribute // @returns Element(Number) - // @mechanism dMaterial.plant_growth + // @mechanism dMaterial.age // @group properties // @description - // Returns the current plant growth stage for a plant material. + // Returns the current age for an ageable material. // --> - if (attribute.startsWith("plant_growth")) { - return new Element(((Ageable) material.getModernData().data).getAge()) - .getAttribute(attribute.fulfill(1)); + if (attribute.startsWith("age") || attribute.startsWith("plant_growth")) { + return new Element(getCurrent()).getAttribute(attribute.fulfill(1)); } return null; @@ -94,7 +93,7 @@ public String getPropertyString() { @Override public String getPropertyId() { - return "plant_growth"; + return "age"; } @Override @@ -102,21 +101,21 @@ public void adjust(Mechanism mechanism) { // <--[mechanism] // @object dMaterial - // @name plant_growth + // @name age // @input Element(Number) // @description - // Sets a plant material's current growth level. + // Sets an ageable material's current age. // @tags - // - // + // + // // --> - if (mechanism.matches("plant_growth") && mechanism.requireInteger()) { - int growth = mechanism.getValue().asInt(); - if (growth < 0 || growth > getMax()) { - dB.echoError("Growth value '" + growth + "' is not valid. Must be between 0 and " + getAgeable() + " for material '" + material.realName() + "'."); + if ((mechanism.matches("age") || mechanism.matches("plant_growth")) && mechanism.requireInteger()) { + int age = mechanism.getValue().asInt(); + if (age < 0 || age > getMax()) { + dB.echoError("Age value '" + age + "' is not valid. Must be between 0 and " + getMax() + " for material '" + material.realName() + "'."); return; } - getAgeable().setAge(growth); + getAgeable().setAge(age); } } }