Skip to content

Commit

Permalink
Implement attachable tripwire mechanism and tags (#2443)
Browse files Browse the repository at this point in the history
* Implement attachable tripwire mechanism and tags

* Remove unused imports

* Update meta for consistency

* Update meta to include hanging signs

* Avoid splitting a line in the middle of a sentance
  • Loading branch information
SXRWahrheit committed Mar 17, 2023
1 parent e737d95 commit 337dcbd
Showing 1 changed file with 26 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@
import com.denizenscript.denizen.nms.NMSHandler;
import com.denizenscript.denizen.nms.NMSVersion;
import com.denizenscript.denizen.objects.MaterialTag;
import com.denizenscript.denizencore.objects.core.ElementTag;
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.objects.properties.PropertyParser;
import org.bukkit.block.data.Attachable;
import org.bukkit.block.data.Hangable;
import org.bukkit.block.data.type.Gate;
import org.bukkit.block.data.type.Lantern;
Expand All @@ -19,6 +20,7 @@ public static boolean describes(ObjectTag material) {
&& ((MaterialTag) material).hasModernData()
&& (((MaterialTag) material).getModernData() instanceof Gate
|| ((MaterialTag) material).getModernData() instanceof Lantern
|| ((MaterialTag) material).getModernData() instanceof Attachable
|| (NMSHandler.getVersion().isAtLeast(NMSVersion.v1_19) && ((MaterialTag) material).getModernData() instanceof Hangable));
}

Expand Down Expand Up @@ -53,6 +55,8 @@ public static void register() {
// For a lantern, this returns whether it is hanging from the ceiling.
// For a gate, this returns whether it is lowered to attach to a wall block.
// For a mangrove_propagule, this returns whether it is hanging from the block above it.
// For a tripwire, this returns whether a tripwire hook or string forms a complete tripwire circuit and is ready to trigger.
// For a hanging sign, this returns whether it is hanging from the block above it.
// -->
PropertyParser.registerStaticTag(MaterialAttached.class, ElementTag.class, "attached", (attribute, material) -> {
if (material.isGate()) {
Expand All @@ -61,6 +65,9 @@ public static void register() {
else if (material.isLantern()) {
return new ElementTag(material.getLantern().isHanging());
}
else if (material.isAttachable()) {
return new ElementTag(material.getAttachable().isAttached());
}
else if (material.isHangable()) {
return new ElementTag(((Hangable) material.material.getModernData()).isHanging());
}
Expand Down Expand Up @@ -90,6 +97,14 @@ public Lantern getLantern() { // TODO: remove once 1.19 is the minimum - Lantern
return (Lantern) material.getModernData();
}

public Attachable getAttachable() {
return (Attachable) material.getModernData();
}

public boolean isAttachable() {
return material.getModernData() instanceof Attachable;
}

/*public Hangable getHangable() { // TODO: 1.19
return (Hangable) material.getModernData();
}*/
Expand All @@ -101,6 +116,9 @@ public boolean isAttached() {
else if (isLantern()) {
return getLantern().isHanging();
}
else if (isAttachable()) {
return getAttachable().isAttached();
}
else if (isHangable()) {
return ((Hangable) material.getModernData()).isHanging(); // TODO: 1.19
}
Expand Down Expand Up @@ -129,6 +147,10 @@ public void adjust(Mechanism mechanism) {
// For a lantern, this sets whether it is hanging from the ceiling.
// For a gate, this sets whether it is lowered to attach to a wall block.
// For a mangrove_propagule, this sets whether it is hanging from the block above it.
// For a tripwire, this sets whether a tripwire hook or string forms a complete tripwire circuit and is ready to trigger.
// Updating the property on a tripwire hook will change the texture to indicate a connected string, but will not have any effect when used on the tripwire string itself.
// It may however still be used to check whether the string forms a circuit.
// For hanging signs, this affects signs hanging below a block and changes whether the chains are vertical (false) or diagonal (true).
// @tags
// <MaterialTag.attached>
// -->
Expand All @@ -139,6 +161,9 @@ public void adjust(Mechanism mechanism) {
else if (isLantern()) {
getLantern().setHanging(mechanism.getValue().asBoolean());
}
else if (isAttachable()) {
getAttachable().setAttached(mechanism.getValue().asBoolean());
}
else if (isHangable()) {
((Hangable) material.getModernData()).setHanging(mechanism.getValue().asBoolean()); // TODO: 1.19
}
Expand Down

0 comments on commit 337dcbd

Please sign in to comment.