Skip to content

Commit

Permalink
Add MaterialTag.has_eye property (#2291)
Browse files Browse the repository at this point in the history
* Add MaterialHasEye MaterialTag property.

* Remove `MaterialHasEye` and add end portal frame support to `MaterialTag.switched`

* Formatting fix
  • Loading branch information
tal5 committed Jan 17, 2022
1 parent 6a441b2 commit cbcf3bf
Showing 1 changed file with 24 additions and 6 deletions.
Expand Up @@ -13,8 +13,9 @@
import org.bukkit.block.data.type.DaylightDetector;
import org.bukkit.block.data.type.Dispenser;
import org.bukkit.block.data.type.Piston;
import org.bukkit.block.data.type.EndPortalFrame;

public class MaterialSwitchable implements Property {
public class MaterialSwitchable implements Property {

public static boolean describes(ObjectTag material) {
if (!(material instanceof MaterialTag)) {
Expand All @@ -30,7 +31,8 @@ public static boolean describes(ObjectTag material) {
|| data instanceof Dispenser
|| data instanceof DaylightDetector
|| data instanceof Piston
|| data instanceof Lightable;
|| data instanceof Lightable
|| data instanceof EndPortalFrame;
}

public static MaterialSwitchable getFrom(ObjectTag _material) {
Expand Down Expand Up @@ -61,7 +63,8 @@ public static void registerTags() {
// @synonyms MaterialTag.lit, MaterialTag.open, MaterialTag.active
// @group properties
// @description
// Returns whether a Powerable material (like pressure plates) an Openable material (like doors), a dispenser, a daylight sensor, a lightable block, or a piston is switched.
// Returns whether a Powerable material (like pressure plates) an Openable material (like doors), a dispenser, a daylight sensor, a lightable block, or a piston is switched,
// Or whether an end portal frame has an ender eye.
// -->
PropertyParser.<MaterialSwitchable, ElementTag>registerStaticTag(ElementTag.class, "switched", (attribute, material) -> {
return new ElementTag(material.getState());
Expand Down Expand Up @@ -92,6 +95,10 @@ public boolean isLightable() {
return material.getModernData() instanceof Lightable;
}

public boolean isPiston() {
return material.getModernData() instanceof Piston;
}

public Openable getOpenable() {
return (Openable) material.getModernData();
}
Expand All @@ -112,6 +119,10 @@ public Lightable getLightable() {
return (Lightable) material.getModernData();
}

public EndPortalFrame getEndFrame() {
return (EndPortalFrame) material.getModernData();
}

public boolean getState() {
if (isOpenable()) {
return getOpenable().isOpen();
Expand All @@ -128,9 +139,12 @@ else if (isDaylightDetector()) {
else if (isLightable()) {
return getLightable().isLit();
}
else {
else if (isPiston()) {
return getPiston().isExtended();
}
else {
return getEndFrame().hasEye();
}
}

public void setState(boolean state) {
Expand All @@ -149,9 +163,12 @@ else if (isDaylightDetector()) {
else if (isLightable()) {
getLightable().setLit(state);
}
else {
else if (isPiston()) {
getPiston().setExtended(state);
}
else {
getEndFrame().setEye(state);
}
}

@Override
Expand All @@ -172,7 +189,8 @@ public void adjust(Mechanism mechanism) {
// @name switched
// @input ElementTag(Boolean)
// @description
// Sets whether a Powerable material (like pressure plates) an Openable material (like doors), a dispenser, a daylight sensor, a lightable block, or a piston is switched.
// Sets whether a Powerable material (like pressure plates) an Openable material (like doors), a dispenser, a daylight sensor, a lightable block, or a piston is switched,
// Or whether an end portal frame has an ender eye.
// @tags
// <MaterialTag.switched>
// -->
Expand Down

0 comments on commit cbcf3bf

Please sign in to comment.