Skip to content

Commit

Permalink
merge some related materialtag properties
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed May 5, 2021
1 parent 79416f9 commit b26a466
Show file tree
Hide file tree
Showing 9 changed files with 83 additions and 76 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,10 @@ public static void registerTags() {
Deprecations.materialPropertyTags.warn(attribute.context);
return new ElementTag(MaterialWaterlogged.describes(object));
});
registerTag("is_switchable", (attribute, object) -> {
Deprecations.materialPropertyTags.warn(attribute.context);
return new ElementTag(MaterialSwitchable.describes(object));
});

// <--[tag]
// @attribute <MaterialTag.has_gravity>
Expand Down Expand Up @@ -420,16 +424,6 @@ public static void registerTags() {
return new ElementTag(object.material.isSolid());
});

// <--[tag]
// @attribute <MaterialTag.is_switchable>
// @returns ElementTag(Boolean)
// @description
// Returns whether the material is Openable, Powerable, or a Dispenser.
// -->
registerTag("is_switchable", (attribute, object) -> {
return new ElementTag(MaterialSwitchable.describes(object));
});

// <--[tag]
// @attribute <MaterialTag.is_transparent>
// @returns ElementTag(Boolean)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
import com.denizenscript.denizencore.objects.core.ElementTag;
import com.denizenscript.denizencore.objects.properties.Property;
import com.denizenscript.denizencore.objects.properties.PropertyParser;
import com.denizenscript.denizencore.utilities.CoreUtilities;
import org.bukkit.block.data.BlockData;
import org.bukkit.block.data.type.Campfire;
import org.bukkit.block.data.type.Slab;
import org.bukkit.block.data.type.TechnicalPiston;

Expand All @@ -22,7 +24,8 @@ public static boolean describes(ObjectTag material) {
}
BlockData data = mat.getModernData();
return data instanceof Slab
|| data instanceof TechnicalPiston;
|| data instanceof TechnicalPiston
|| data instanceof Campfire;
}

public static MaterialBlockType getFrom(ObjectTag _material) {
Expand Down Expand Up @@ -53,8 +56,9 @@ public static void registerTags() {
// @group properties
// @description
// Returns the current type of the block.
// For slabs, input is TOP, BOTTOM, or DOUBLE.
// For piston_heads, input is NORMAL or STICKY.
// For slabs, output is TOP, BOTTOM, or DOUBLE.
// For piston_heads, output is NORMAL or STICKY.
// For campfires, output is NORMAL or SIGNAL.
// -->
PropertyParser.<MaterialBlockType>registerTag("type", (attribute, material) -> {
return new ElementTag(material.getSlab().getType().name());
Expand All @@ -69,6 +73,10 @@ public boolean isPistonHead() {
return material.getModernData() instanceof TechnicalPiston;
}

public boolean isCampfire() {
return material.getModernData() instanceof Campfire;
}

public Slab getSlab() {
return (Slab) material.getModernData();
}
Expand All @@ -77,11 +85,18 @@ public TechnicalPiston getPistonHead() {
return (TechnicalPiston) material.getModernData();
}

public Campfire getCampfire() {
return (Campfire) material.getModernData();
}

@Override
public String getPropertyString() {
if (isSlab()) {
return String.valueOf(getSlab().getType());
}
else if (isCampfire()) {
return getCampfire().isSignalFire() ? "SIGNAL" : "NORMAL";
}
else {
return String.valueOf(getPistonHead().getType());
}
Expand All @@ -103,13 +118,17 @@ public void adjust(Mechanism mechanism) {
// Sets the current type of the block.
// For slabs, input is TOP, BOTTOM, or DOUBLE.
// For piston_heads, input is NORMAL or STICKY.
// For campfires, input is NORMAL or SIGNAL.
// @tags
// <MaterialTag.type>
// -->
if (mechanism.matches("type") || (mechanism.matches("slab_type"))) {
if (isSlab() && mechanism.requireEnum(false, Slab.Type.values())) {
getSlab().setType(Slab.Type.valueOf(mechanism.getValue().asString().toUpperCase()));
}
else if (isCampfire()) {
getCampfire().setSignalFire(CoreUtilities.equalsIgnoreCase(mechanism.getValue().asString(), "signal"));
}
else if (isPistonHead() && mechanism.requireEnum(false, TechnicalPiston.Type.values())) {
getPistonHead().setType(TechnicalPiston.Type.valueOf(mechanism.getValue().asString().toUpperCase()));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@
import com.denizenscript.denizencore.objects.core.ElementTag;
import com.denizenscript.denizencore.objects.properties.Property;
import com.denizenscript.denizencore.objects.properties.PropertyParser;
import com.denizenscript.denizencore.utilities.Deprecations;
import org.bukkit.block.data.type.Campfire;

@Deprecated
public class MaterialCampfire implements Property {

public static boolean describes(ObjectTag material) {
Expand Down Expand Up @@ -37,15 +39,8 @@ private MaterialCampfire(MaterialTag _material) {

public static void registerTags() {

// <--[tag]
// @attribute <MaterialTag.signal_fire>
// @returns ElementTag(Boolean)
// @mechanism MaterialTag.signal_fire
// @group properties
// @description
// Returns whether this campfire will produce longer smoke trails, or not.
// -->
PropertyParser.<MaterialCampfire>registerTag("signal_fire", (attribute, material) -> {
Deprecations.materialCampfire.warn(attribute.context);
return new ElementTag(material.getCampfire().isSignalFire());
});
}
Expand All @@ -67,16 +62,8 @@ public String getPropertyId() {
@Override
public void adjust(Mechanism mechanism) {

// <--[mechanism]
// @object MaterialTag
// @name signal_fire
// @input ElementTag(Boolean)
// @description
// Sets a campfire block to have longer smoke trails, or not.
// @tags
// <MaterialTag.signal_fire>
// -->
if (mechanism.matches("signal_fire") && mechanism.requireBoolean()) {
Deprecations.materialCampfire.warn(mechanism.context);
getCampfire().setSignalFire(mechanism.getValue().asBoolean());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@
import com.denizenscript.denizencore.objects.core.ElementTag;
import com.denizenscript.denizencore.objects.properties.Property;
import com.denizenscript.denizencore.objects.properties.PropertyParser;
import com.denizenscript.denizencore.utilities.Deprecations;
import org.bukkit.block.data.type.BubbleColumn;

@Deprecated
public class MaterialDrags implements Property {

public static boolean describes(ObjectTag material) {
Expand Down Expand Up @@ -37,15 +39,8 @@ private MaterialDrags(MaterialTag _material) {

public static void registerTags() {

// <--[tag]
// @attribute <MaterialTag.drags>
// @returns ElementTag(Boolean)
// @mechanism MaterialTag.drags
// @group properties
// @description
// Returns whether force is applied on entities moving through this BubbleColumn material.
// -->
PropertyParser.<MaterialDrags>registerTag("drags", (attribute, material) -> {
Deprecations.materialDrags.warn(attribute.context);
return new ElementTag(material.isDrag());
});
}
Expand All @@ -71,16 +66,8 @@ public String getPropertyId() {
@Override
public void adjust(Mechanism mechanism) {

// <--[mechanism]
// @object MaterialTag
// @name drags
// @input ElementTag(Boolean)
// @description
// Sets whether this material will apply force on entities moving through this BubbleColumn block.
// @tags
// <MaterialTag.drags>
// -->
if (mechanism.matches("drags") && mechanism.requireBoolean()) {
Deprecations.materialDrags.warn(mechanism.context);
getBubbleColumn().setDrag(mechanism.getValue().asBoolean());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@
import com.denizenscript.denizencore.objects.core.ElementTag;
import com.denizenscript.denizencore.objects.properties.Property;
import com.denizenscript.denizencore.objects.properties.PropertyParser;
import com.denizenscript.denizencore.utilities.Deprecations;
import org.bukkit.block.data.Lightable;

@Deprecated
public class MaterialLightable implements Property {

public static boolean describes(ObjectTag material) {
Expand Down Expand Up @@ -37,15 +39,8 @@ private MaterialLightable(MaterialTag _material) {

public static void registerTags() {

// <--[tag]
// @attribute <MaterialTag.lit>
// @returns ElementTag(Boolean)
// @mechanism MaterialTag.lit
// @group properties
// @description
// Returns whether a lightable material (such as a redstone torch) is lit currently.
// -->
PropertyParser.<MaterialLightable>registerTag("lit", (attribute, material) -> {
Deprecations.materialLit.warn(attribute.context);
return new ElementTag(material.getLightable().isLit());
});
}
Expand All @@ -56,7 +51,7 @@ public Lightable getLightable() {

@Override
public String getPropertyString() {
return String.valueOf(getLightable().isLit());
return null;
}

@Override
Expand All @@ -67,16 +62,8 @@ public String getPropertyId() {
@Override
public void adjust(Mechanism mechanism) {

// <--[mechanism]
// @object MaterialTag
// @name lit
// @input ElementTag(Boolean)
// @description
// Sets whether a lightable material (such as a redstone torch) is lit currently.
// @tags
// <MaterialTag.lit>
// -->
if (mechanism.matches("lit") && mechanism.requireBoolean()) {
Deprecations.materialLit.warn(mechanism.context);
getLightable().setLit(mechanism.getValue().asBoolean());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import com.denizenscript.denizencore.objects.properties.PropertyParser;
import com.denizenscript.denizencore.utilities.CoreUtilities;
import org.bukkit.block.data.BlockData;
import org.bukkit.block.data.type.BubbleColumn;
import org.bukkit.block.data.type.Comparator;
import org.bukkit.block.data.type.PistonHead;

Expand All @@ -23,7 +24,8 @@ public static boolean describes(ObjectTag material) {
}
BlockData data = mat.getModernData();
return data instanceof Comparator
|| data instanceof PistonHead;
|| data instanceof PistonHead
|| data instanceof BubbleColumn;
}

public static MaterialMode getFrom(ObjectTag _material) {
Expand Down Expand Up @@ -56,6 +58,7 @@ public static void registerTags() {
// Returns a block's mode.
// For comparators, output is COMPARE or SUBTRACT.
// For piston_heads, output is NORMAL or SHORT.
// For bubble-columns, output is NORMAL or DRAG.
// -->
PropertyParser.<MaterialMode>registerTag("mode", (attribute, material) -> {
return new ElementTag(material.getPropertyString());
Expand All @@ -70,6 +73,10 @@ public boolean isPistonHead() {
return material.getModernData() instanceof PistonHead;
}

public boolean isBubbleColumn() {
return material.getModernData() instanceof BubbleColumn;
}

public Comparator getComparator() {
return (Comparator) material.getModernData();
}
Expand All @@ -78,11 +85,18 @@ public PistonHead getPistonHead() {
return (PistonHead) material.getModernData();
}

public BubbleColumn getBubbleColumn() {
return (BubbleColumn) material.getModernData();
}

@Override
public String getPropertyString() {
if (isComparator()) {
return getComparator().getMode().name();
}
else if (isBubbleColumn()) {
return getBubbleColumn().isDrag() ? "DRAG" : "NORMAL";
}
else {
return getPistonHead().isShort() ? "SHORT" : "NORMAL";
}
Expand All @@ -104,13 +118,17 @@ public void adjust(Mechanism mechanism) {
// Set a block's mode.
// For comparators, input is COMPARE or SUBTRACT.
// For piston_heads, input is NORMAL or SHORT.
// For bubble-columns, input is NORMAL or DRAG.
// @tags
// <MaterialTag.mode>
// -->
if (mechanism.matches("mode") && mechanism.requireEnum(false, Comparator.Mode.values())) {
if (isComparator() && mechanism.requireEnum(false, Comparator.Mode.values())) {
getComparator().setMode(Comparator.Mode.valueOf(mechanism.getValue().asString().toUpperCase()));
}
else if (isBubbleColumn()) {
getBubbleColumn().setDrag(CoreUtilities.equalsIgnoreCase(mechanism.getValue().asString(), "drag"));
}
else if (isPistonHead()) {
getPistonHead().setShort(CoreUtilities.equalsIgnoreCase(mechanism.getValue().asString(), "short"));
}
Expand Down
Loading

0 comments on commit b26a466

Please sign in to comment.