Skip to content

Commit

Permalink
New stuff related to leaves blocks: (#2014)
Browse files Browse the repository at this point in the history
* New stuff related to leaves blocks:
3 new tags: is_leaves, tree_distance, and persistent
1 new mechanism: persistent
1 additional fix (possible copypasta)

* Fix conflicts with upstream

* fixing the result of public school (grammar)

* removal of unnecessary import....

* updates to match proper denizen design

* readability improvement

* stability improvements

* further cleanup

* preferential fixes

* meta fixes
  • Loading branch information
Ph4i1ur3 authored and mcmonkey4eva committed Sep 6, 2019
1 parent 3abb4d1 commit e696128
Show file tree
Hide file tree
Showing 4 changed files with 136 additions and 0 deletions.
Expand Up @@ -2,6 +2,7 @@

import com.denizenscript.denizen.objects.notable.NotableManager;
import com.denizenscript.denizen.objects.properties.material.MaterialSwitchFace;
import com.denizenscript.denizen.objects.properties.material.MaterialLeaves;
import com.denizenscript.denizen.scripts.commands.world.SwitchCommand;
import com.denizenscript.denizen.utilities.MaterialCompat;
import com.denizenscript.denizen.utilities.PathFinder;
Expand Down Expand Up @@ -2620,6 +2621,23 @@ else if (this.getWorldName().equalsIgnoreCase(toLocation.getWorldName())) {
}
}

// <--[tag]
// @attribute <LocationTag.tree_distance>
// @returns ElementTag(Number)
// @group properties
// @description
// Returns a number of how many blocks away from a connected tree leaves are.
// Defaults to 7 if not connected to a tree.
// -->
if (attribute.startsWith("tree_distance")) {
MaterialTag material = new MaterialTag(getBlockForTag(attribute));
if (NMSHandler.getVersion().isAtLeast(NMSVersion.v1_13)
&& MaterialLeaves.describes(material)) {
return new ElementTag(MaterialLeaves.getFrom(material).getDistance())
.getAttribute(attribute.fulfill(1));
}
}

// <--[tag]
// @attribute <LocationTag.type>
// @returns ElementTag
Expand Down
Expand Up @@ -540,6 +540,24 @@ public String run(Attribute attribute, ObjectTag object) {
}
});

// <--[tag]
// @attribute <MaterialTag.is_leaves>
// @returns ElementTag(Boolean)
// @group properties
// @description
// Returns whether the material is a leaves material.
// When this returns true, <@link tag LocationTag.tree_distance>,
// <@link tag MaterialTag.persistent>, and
// <@link mechanism MaterialTag.persistent> are accessible.
// -->
registerTag("is_leaves", new TagRunnable() {
@Override
public String run(Attribute attribute, ObjectTag object) {
return new ElementTag(MaterialLeaves.describes(object))
.getAttribute(attribute.fulfill(1));
}
});

// <--[tag]
// @attribute <MaterialTag.is_slab>
// @returns ElementTag(Boolean)
Expand Down
Expand Up @@ -138,6 +138,7 @@ public static void registermainProperties() {
PropertyParser.registerProperty(MaterialDirectional.class, MaterialTag.class);
PropertyParser.registerProperty(MaterialHalf.class, MaterialTag.class);
PropertyParser.registerProperty(MaterialSlab.class, MaterialTag.class);
PropertyParser.registerProperty(MaterialLeaves.class, MaterialTag.class);
PropertyParser.registerProperty(MaterialLevel.class, MaterialTag.class);
PropertyParser.registerProperty(MaterialLightable.class, MaterialTag.class);
PropertyParser.registerProperty(MaterialSwitchFace.class, MaterialTag.class);
Expand Down
@@ -0,0 +1,99 @@
package com.denizenscript.denizen.objects.properties.material;

import com.denizenscript.denizen.objects.MaterialTag;
import com.denizenscript.denizen.utilities.debugging.Debug;
import com.denizenscript.denizencore.objects.Mechanism;
import com.denizenscript.denizencore.objects.ObjectTag;
import com.denizenscript.denizencore.objects.core.ElementTag;
import com.denizenscript.denizencore.objects.properties.Property;
import com.denizenscript.denizencore.tags.Attribute;
import org.bukkit.block.data.type.Leaves;

public class MaterialLeaves implements Property {

public static boolean describes(ObjectTag material) {
return material instanceof MaterialTag
&& ((MaterialTag) material).hasModernData()
&& ((MaterialTag) material).getModernData().data instanceof Leaves;
}

public static MaterialLeaves getFrom(ObjectTag _material) {
if (!describes(_material)) {
return null;
}
else {
return new MaterialLeaves((MaterialTag) _material);
}
}

public static final String[] handledTags = new String[] {
"persistent"
};

public static final String[] handledMechs = new String[] {
"persistent"
};


private MaterialLeaves(MaterialTag _material) {
material = _material;
}

MaterialTag material;

@Override
public String getAttribute(Attribute attribute) {

if (attribute == null) {
return null;
}

// <--[tag]
// @attribute <MaterialTag.persistent>
// @returns ElementTag(Boolean)
// @group properties
// @description
// Returns whether this block will decay from being too far away from a tree.
// -->
if (attribute.startsWith("persistent")) {
return new ElementTag(getLeaves().isPersistent()).getAttribute(attribute.fulfill(1));
}

return null;
}

public Leaves getLeaves() {
return (Leaves) material.getModernData().data;
}

public int getDistance() {
return getLeaves().getDistance();
}

@Override
public String getPropertyString() {
return String.valueOf(getLeaves().isPersistent());
}

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

@Override
public void adjust(Mechanism mechanism) {

// <--[mechanism]
// @object MaterialTag
// @name persistent
// @input Element(Boolean)
// @description
// Sets leaves blocks to ignore decay, or to obey it.
// @tags
// <MaterialTag.persistent>
// -->
if (mechanism.matches("persistent") && mechanism.requireBoolean()) {
getLeaves().setPersistent(mechanism.getValue().asBoolean());
}
}
}

0 comments on commit e696128

Please sign in to comment.