Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Bell `attachment` mechanism beginnings * It worked the whole time! I was using the wrong `adjust` command :P Thanks for letting me know Aya. * Add `attachment` logic to `switch_face` Also updates `MaterialSwitchFace` to new Property system * Update mech to `attachment_face` and more optimizations * Update meta and add value for `DOUBLE_WALL`
- Loading branch information
1 parent
ff0f280
commit 7341333
Showing
5 changed files
with
96 additions
and
106 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
91 changes: 91 additions & 0 deletions
91
...in/java/com/denizenscript/denizen/objects/properties/material/MaterialAttachmentFace.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
package com.denizenscript.denizen.objects.properties.material; | ||
|
||
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 org.bukkit.block.BlockFace; | ||
import org.bukkit.block.data.BlockData; | ||
import org.bukkit.block.data.Directional; | ||
import org.bukkit.block.data.FaceAttachable; | ||
import org.bukkit.block.data.type.Bell; | ||
|
||
public class MaterialAttachmentFace extends MaterialProperty<ElementTag> { | ||
|
||
// <--[property] | ||
// @object MaterialTag | ||
// @name attachment_face | ||
// @input ElementTag | ||
// @description | ||
// Controls the current attach direction for attachable materials such as switches, grindstones, and bells. | ||
// For bell values, see <@link url https://hub.spigotmc.org/javadocs/spigot/org/bukkit/block/data/type/Bell.Attachment.html> | ||
// For all other supported type values, see <@link url https://hub.spigotmc.org/javadocs/spigot/org/bukkit/block/data/FaceAttachable.AttachedFace.html> | ||
// --> | ||
|
||
public static boolean describes(MaterialTag material) { | ||
BlockData data = material.getModernData(); | ||
return data instanceof FaceAttachable || data instanceof Bell; | ||
} | ||
|
||
public MaterialAttachmentFace(MaterialTag material) { | ||
super(material); | ||
} | ||
|
||
@Override | ||
public ElementTag getPropertyValue() { | ||
if (getBlockData() instanceof FaceAttachable attachable) { | ||
return new ElementTag(attachable.getAttachedFace()); | ||
} | ||
else if (getBlockData() instanceof Bell bell) { | ||
return new ElementTag(bell.getAttachment()); | ||
} | ||
return null; | ||
} | ||
|
||
@Override | ||
public String getPropertyId() { | ||
return "attachment_face"; | ||
} | ||
|
||
@Override | ||
public void setPropertyValue(ElementTag attachment, Mechanism mechanism) { | ||
if (getBlockData() instanceof FaceAttachable attachable) { | ||
if (mechanism.requireEnum(FaceAttachable.AttachedFace.class)) { | ||
attachable.setAttachedFace(FaceAttachable.AttachedFace.valueOf(attachment.asString().toUpperCase())); | ||
} | ||
} | ||
else if (getBlockData() instanceof Bell bell) { | ||
if (mechanism.requireEnum(Bell.Attachment.class)) { | ||
bell.setAttachment(Bell.Attachment.valueOf(attachment.asString().toUpperCase())); | ||
} | ||
} | ||
} | ||
|
||
public BlockFace getAttachedTo() { | ||
if (getBlockData() instanceof FaceAttachable attachable) { | ||
return switch (attachable.getAttachedFace()) { | ||
case WALL -> { | ||
if (getBlockData() instanceof Directional) { | ||
yield ((Directional) getBlockData()).getFacing().getOppositeFace(); | ||
} | ||
yield BlockFace.SELF; | ||
} | ||
case FLOOR -> BlockFace.DOWN; | ||
case CEILING -> BlockFace.UP; | ||
}; | ||
} | ||
else if (getBlockData() instanceof Bell bell) { | ||
return switch (bell.getAttachment()) { | ||
case SINGLE_WALL, DOUBLE_WALL -> ((Directional) getBlockData()).getFacing(); | ||
case FLOOR -> BlockFace.DOWN; | ||
case CEILING -> BlockFace.UP; | ||
}; | ||
} | ||
return null; | ||
} | ||
|
||
public static void register() { | ||
autoRegister("attachment_face", MaterialAttachmentFace.class, ElementTag.class, false, "switch_face"); | ||
} | ||
} |
101 changes: 0 additions & 101 deletions
101
...c/main/java/com/denizenscript/denizen/objects/properties/material/MaterialSwitchFace.java
This file was deleted.
Oops, something went wrong.