-
-
Notifications
You must be signed in to change notification settings - Fork 115
Added MossyCarpet to MaterialSides #2808
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: dev
Are you sure you want to change the base?
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,174 +1,139 @@ | ||
| 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.denizen.utilities.Utilities; | ||
| import com.denizenscript.denizencore.objects.Mechanism; | ||
| import com.denizenscript.denizencore.objects.ObjectTag; | ||
| import com.denizenscript.denizencore.objects.core.ElementTag; | ||
| import com.denizenscript.denizencore.objects.core.ListTag; | ||
| import com.denizenscript.denizencore.objects.properties.Property; | ||
| import com.denizenscript.denizencore.objects.properties.PropertyParser; | ||
| import com.denizenscript.denizencore.utilities.CoreUtilities; | ||
| import com.denizenscript.denizencore.utilities.debugging.DebugInternals; | ||
| import org.bukkit.block.BlockFace; | ||
| import org.bukkit.block.data.*; | ||
| import org.bukkit.block.data.BlockData; | ||
| import org.bukkit.block.data.type.MossyCarpet; | ||
| import org.bukkit.block.data.type.RedstoneWire; | ||
| import org.bukkit.block.data.type.Wall; | ||
|
|
||
| public class MaterialSides implements Property { | ||
|
|
||
| public static boolean describes(ObjectTag material) { | ||
| if (!(material instanceof MaterialTag)) { | ||
| return false; | ||
| } | ||
| MaterialTag mat = (MaterialTag) material; | ||
| if (!mat.hasModernData()) { | ||
| return false; | ||
| } | ||
| BlockData data = mat.getModernData(); | ||
| if (!(data instanceof Wall) && !(data instanceof RedstoneWire)) { | ||
| return false; | ||
| } | ||
| return true; | ||
| } | ||
|
|
||
| public static MaterialSides getFrom(ObjectTag _material) { | ||
| if (!describes(_material)) { | ||
| return null; | ||
| } | ||
| else { | ||
| return new MaterialSides((MaterialTag) _material); | ||
| } | ||
| } | ||
|
|
||
| public static final String[] handledMechs = new String[] { | ||
| "sides", "heights" | ||
| }; | ||
|
|
||
| public MaterialSides(MaterialTag _material) { | ||
| material = _material; | ||
| } | ||
|
|
||
| MaterialTag material; | ||
|
|
||
| public static void register() { | ||
|
|
||
| // <--[tag] | ||
| // @attribute <MaterialTag.heights> | ||
| // @returns ListTag | ||
| // @mechanism MaterialTag.heights | ||
| // @group properties | ||
| // @deprecated Use 'sides' | ||
| // @description | ||
| // Deprecated in favor of <@link tag MaterialTag.sides> | ||
| // --> | ||
| // <--[tag] | ||
| // @attribute <MaterialTag.sides> | ||
| // @returns ListTag | ||
| // @mechanism MaterialTag.sides | ||
| // @group properties | ||
| // @description | ||
| // Returns the list of heights for a wall block, or connections for a redstone wire, in order North|East|South|West|Vertical. | ||
| // For wall blocks: For n/e/s/w, can be "tall", "low", or "none". For vertical, can be "tall" or "none". | ||
| // For redstone wires: For n/e/s/w, can be "none", "side", or "up". No vertical. | ||
| // --> | ||
| PropertyParser.registerStaticTag(MaterialSides.class, ListTag.class, "sides", (attribute, material) -> { | ||
| return material.getSidesList(); | ||
| }, "heights"); | ||
| } | ||
|
|
||
| public boolean isWall() { | ||
| return material.getModernData() instanceof Wall; | ||
| } | ||
|
|
||
| public Wall getWall() { | ||
| return (Wall) material.getModernData(); | ||
| import java.util.function.BiConsumer; | ||
|
|
||
| public class MaterialSides extends MaterialProperty<ListTag> { | ||
|
|
||
| // <--[property] | ||
| // @object MaterialTag | ||
| // @name sides | ||
| // @input ListTag | ||
| // @description | ||
| // Controls the heights for a wall block or mossy carpet, or connections for a redstone wire, in order North|East|South|West|Vertical. | ||
| // For wall blocks: For n/e/s/w, can be "tall", "low", or "none". For vertical, can be "tall" or "none". | ||
| // For redstone wires: For n/e/s/w, can be "none", "side", or "up". No vertical. | ||
| // For mossy carpets: For n/e/s/w, can be "tall", "low", or "none". Vertical controls the bottom, and can either be "bottom" or "none". | ||
| // --> | ||
|
|
||
| public static boolean describes(MaterialTag material) { | ||
| BlockData data = material.getModernData(); | ||
| return data instanceof Wall | ||
| || data instanceof RedstoneWire | ||
| || (NMSHandler.getVersion().isAtLeast(NMSVersion.v1_21) && data instanceof MossyCarpet); | ||
| } | ||
|
|
||
| public boolean isWire() { | ||
| return material.getModernData() instanceof RedstoneWire; | ||
| } | ||
|
|
||
| public RedstoneWire getWire() { | ||
| return (RedstoneWire) material.getModernData(); | ||
| } | ||
|
|
||
| public ListTag getSidesList() { | ||
| @Override | ||
| public ListTag getPropertyValue() { | ||
| ListTag list = new ListTag(5); | ||
| if (isWall()) { | ||
| Wall wall = getWall(); | ||
| if (getBlockData() instanceof Wall wall) { | ||
| list.add(wall.getHeight(BlockFace.NORTH).name()); | ||
| list.add(wall.getHeight(BlockFace.EAST).name()); | ||
| list.add(wall.getHeight(BlockFace.SOUTH).name()); | ||
| list.add(wall.getHeight(BlockFace.WEST).name()); | ||
| list.add(wall.isUp() ? "TALL" : "NONE"); | ||
| } | ||
| else if (isWire()) { | ||
| RedstoneWire wire = getWire(); | ||
| else if (getBlockData() instanceof RedstoneWire wire) { | ||
| list.add(wire.getFace(BlockFace.NORTH).name()); | ||
| list.add(wire.getFace(BlockFace.EAST).name()); | ||
| list.add(wire.getFace(BlockFace.SOUTH).name()); | ||
| list.add(wire.getFace(BlockFace.WEST).name()); | ||
| } | ||
| else if (NMSHandler.getVersion().isAtLeast(NMSVersion.v1_21) && getBlockData() instanceof MossyCarpet carpet) { | ||
| list.add(carpet.getHeight(BlockFace.NORTH).name()); | ||
| list.add(carpet.getHeight(BlockFace.EAST).name()); | ||
| list.add(carpet.getHeight(BlockFace.SOUTH).name()); | ||
| list.add(carpet.getHeight(BlockFace.WEST).name()); | ||
| list.add(carpet.isBottom() ? "BOTTOM" : "NONE"); | ||
| } | ||
| return list; | ||
| } | ||
|
|
||
| @Override | ||
| public String getPropertyString() { | ||
| return getSidesList().identify(); | ||
| public void setPropertyValue(ListTag list, Mechanism mechanism) { | ||
| if (getBlockData() instanceof Wall wall) { | ||
| if (list.size() != 5) { | ||
| mechanism.echoError("Invalid sides list, size must be 5."); | ||
| return; | ||
| } | ||
| setSide(wall::setHeight, Wall.Height.class, BlockFace.NORTH, list, 0, mechanism); | ||
| setSide(wall::setHeight, Wall.Height.class, BlockFace.EAST, list, 1, mechanism); | ||
| setSide(wall::setHeight, Wall.Height.class, BlockFace.SOUTH, list, 2, mechanism); | ||
| setSide(wall::setHeight, Wall.Height.class, BlockFace.WEST, list, 3, mechanism); | ||
| wall.setUp(list.get(4).equalsIgnoreCase("tall")); | ||
| } | ||
| else if (getBlockData() instanceof RedstoneWire wire) { | ||
| if (list.size() != 4) { | ||
| mechanism.echoError("Invalid sides list, size must be 4."); | ||
| return; | ||
| } | ||
| setSide(wire::setFace, RedstoneWire.Connection.class, BlockFace.NORTH, list, 0, mechanism); | ||
| setSide(wire::setFace, RedstoneWire.Connection.class, BlockFace.EAST, list, 1, mechanism); | ||
| setSide(wire::setFace, RedstoneWire.Connection.class, BlockFace.SOUTH, list, 2, mechanism); | ||
| setSide(wire::setFace, RedstoneWire.Connection.class, BlockFace.WEST, list, 3, mechanism); | ||
| } | ||
| else if (NMSHandler.getVersion().isAtLeast(NMSVersion.v1_21) && getBlockData() instanceof MossyCarpet carpet) { | ||
| if (list.size() != 5) { | ||
| mechanism.echoError("Invalid sides list, size must be 5."); | ||
| return; | ||
| } | ||
| setSide(carpet::setHeight, MossyCarpet.Height.class, BlockFace.NORTH, list, 0, mechanism); | ||
| setSide(carpet::setHeight, MossyCarpet.Height.class, BlockFace.EAST, list, 1, mechanism); | ||
| setSide(carpet::setHeight, MossyCarpet.Height.class, BlockFace.SOUTH, list, 2, mechanism); | ||
| setSide(carpet::setHeight, MossyCarpet.Height.class, BlockFace.WEST, list, 3, mechanism); | ||
| carpet.setBottom(list.get(4).equalsIgnoreCase("bottom")); | ||
| } | ||
| } | ||
|
|
||
| public static <T> void setSide(BiConsumer<BlockFace, T> consumer, Class<T> type, BlockFace face, ListTag list, int index, Mechanism mechanism) { | ||
| T value = Utilities.elementToEnumlike(new ElementTag(list.get(index)), type); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks good overall, but you'd want |
||
| if (value == null) { | ||
| mechanism.echoError("'"+ list.get(index) + "' is not a valid " + DebugInternals.getClassNameOpti(type) + "."); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing space before the |
||
| return; | ||
| } | ||
| consumer.accept(face, value); | ||
| } | ||
|
|
||
| @Override | ||
| public String getPropertyId() { | ||
| return "sides"; | ||
| } | ||
|
|
||
| @Override | ||
| public void adjust(Mechanism mechanism) { | ||
| // <--[tag] | ||
| // @attribute <MaterialTag.heights> | ||
| // @returns ListTag | ||
| // @mechanism MaterialTag.heights | ||
| // @group properties | ||
| // @deprecated Use 'sides' | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Start lowercase on these |
||
| // @description | ||
| // Deprecated in favor of <@link property MaterialTag.sides> | ||
| // --> | ||
|
|
||
| // <--[mechanism] | ||
| // @object MaterialTag | ||
| // @name heights | ||
| // @input ElementTag | ||
| // @deprecated Use 'sides' | ||
| // @description | ||
| // Deprecated in favor of <@link property MaterialTag.sides> | ||
| // @tags | ||
| // <MaterialTag.heights> | ||
| // --> | ||
|
|
||
| // <--[mechanism] | ||
| // @object MaterialTag | ||
| // @name heights | ||
| // @input ElementTag | ||
| // @deprecated Use 'sides' | ||
| // @description | ||
| // Deprecated in favor of <@link mechanism MaterialTag.sides> | ||
| // @tags | ||
| // <MaterialTag.heights> | ||
| // --> | ||
| // <--[mechanism] | ||
| // @object MaterialTag | ||
| // @name sides | ||
| // @input ElementTag | ||
| // @description | ||
| // Sets the list of heights for a wall block, or connections for a redstone wire, in order North|East|South|West|Vertical. | ||
| // For wall blocks: For n/e/s/w, can be "tall", "low", or "none". For vertical, can be "tall" or "none". | ||
| // For redstone wires: For n/e/s/w, can be "none", "side", or "up". No vertical. | ||
| // @tags | ||
| // <MaterialTag.sides> | ||
| // --> | ||
| if ((mechanism.matches("sides") || mechanism.matches("heights")) && mechanism.requireObject(ListTag.class)) { | ||
| ListTag list = mechanism.valueAsType(ListTag.class); | ||
| if (isWall()) { | ||
| if (list.size() != 5) { | ||
| mechanism.echoError("Invalid sides list, size must be 5."); | ||
| return; | ||
| } | ||
| Wall wall = getWall(); | ||
| wall.setHeight(BlockFace.NORTH, Wall.Height.valueOf(list.get(0).toUpperCase())); | ||
| wall.setHeight(BlockFace.EAST, Wall.Height.valueOf(list.get(1).toUpperCase())); | ||
| wall.setHeight(BlockFace.SOUTH, Wall.Height.valueOf(list.get(2).toUpperCase())); | ||
| wall.setHeight(BlockFace.WEST, Wall.Height.valueOf(list.get(3).toUpperCase())); | ||
| wall.setUp(CoreUtilities.toLowerCase(list.get(4)).equals("tall")); | ||
| } | ||
| else if (isWire()) { | ||
| if (list.size() != 4) { | ||
| mechanism.echoError("Invalid sides list, size must be 4."); | ||
| return; | ||
| } | ||
| RedstoneWire wire = getWire(); | ||
| wire.setFace(BlockFace.NORTH, RedstoneWire.Connection.valueOf(list.get(0).toUpperCase())); | ||
| wire.setFace(BlockFace.EAST, RedstoneWire.Connection.valueOf(list.get(1).toUpperCase())); | ||
| wire.setFace(BlockFace.SOUTH, RedstoneWire.Connection.valueOf(list.get(2).toUpperCase())); | ||
| wire.setFace(BlockFace.WEST, RedstoneWire.Connection.valueOf(list.get(3).toUpperCase())); | ||
| } | ||
| } | ||
| public static void register() { | ||
| autoRegister("sides", MaterialSides.class, ListTag.class, false, "heights"); | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nitpick, but these can be
CoreUtilities#equalsIgnoreCase/#toLowerCaseon the list value + a normal equals