Search in sources :

Example 1 with PointedDripstone

use of org.bukkit.block.data.type.PointedDripstone in project Denizen-For-Bukkit by DenizenScript.

the class MaterialDirectional method setFacing.

public void setFacing(BlockFace face) {
    if (isOrientable()) {
        Axis axis;
        Vector vec = face.getDirection();
        if (Math.abs(vec.getX()) >= 0.5) {
            axis = Axis.X;
        } else if (Math.abs(vec.getY()) >= 0.5) {
            axis = Axis.Y;
        } else {
            axis = Axis.Z;
        }
        getOrientable().setAxis(axis);
    } else if (isRotatable()) {
        getRotatable().setRotation(face);
    } else if (isRail()) {
        switch(face) {
            case EAST:
            case WEST:
                getRail().setShape(Rail.Shape.EAST_WEST);
            case NORTH:
            case SOUTH:
                getRail().setShape(Rail.Shape.NORTH_SOUTH);
            case NORTH_EAST:
                getRail().setShape(Rail.Shape.NORTH_EAST);
            case NORTH_WEST:
                getRail().setShape(Rail.Shape.NORTH_WEST);
            case SOUTH_EAST:
                getRail().setShape(Rail.Shape.SOUTH_EAST);
            case SOUTH_WEST:
                getRail().setShape(Rail.Shape.SOUTH_WEST);
            default:
                Debug.echoError("Unsupported rail direction '" + face + "'.");
        }
    } else if (isDirectional()) {
        getDirectional().setFacing(face);
    } else if (isDripstone()) {
        // TODO: 1.17
        ((PointedDripstone) material.getModernData()).setVerticalDirection(face);
    }
}
Also used : PointedDripstone(org.bukkit.block.data.type.PointedDripstone) Vector(org.bukkit.util.Vector) Axis(org.bukkit.Axis)

Example 2 with PointedDripstone

use of org.bukkit.block.data.type.PointedDripstone in project Denizen-For-Bukkit by DenizenScript.

the class MaterialDirectional method registerTags.

public static void registerTags() {
    // <--[tag]
    // @attribute <MaterialTag.valid_directions>
    // @returns ListTag
    // @mechanism MaterialTag.direction
    // @group properties
    // @description
    // Returns a list of directions that are valid for a directional material.
    // See also <@link tag MaterialTag.direction>
    // -->
    PropertyParser.<MaterialDirectional, ListTag>registerStaticTag(ListTag.class, "valid_directions", (attribute, material) -> {
        ListTag toReturn = new ListTag();
        if (material.isOrientable()) {
            for (Axis axis : material.getOrientable().getAxes()) {
                toReturn.add(axis.name());
            }
        } else if (material.isRail()) {
            for (Rail.Shape shape : material.getRail().getShapes()) {
                toReturn.add(shape.name());
            }
        } else if (material.isDirectional()) {
            for (BlockFace face : material.getDirectional().getFaces()) {
                toReturn.add(face.name());
            }
        } else if (material.isRotatable()) {
            for (BlockFace face : rotatableValidFaces) {
                toReturn.add(face.name());
            }
        } else if (material.isDripstone()) {
            for (BlockFace face : ((PointedDripstone) material.material.getModernData()).getVerticalDirections()) {
                // TODO: 1.17
                toReturn.add(face.name());
            }
        } else if (material.isJigsaw()) {
            for (Jigsaw.Orientation orientation : Jigsaw.Orientation.values()) {
                toReturn.add(orientation.name());
            }
        } else {
            // Unreachable
            return null;
        }
        return toReturn;
    });
    // <--[tag]
    // @attribute <MaterialTag.direction>
    // @returns ElementTag
    // @mechanism MaterialTag.direction
    // @group properties
    // @description
    // Returns the current facing direction for a directional material (like a door or a bed).
    // This includes materials that Spigot classifies as "directional", "orientable", or "rotatable", as well as rails, dripstone, and jigsaw blocks.
    // Output is a direction name like "NORTH", or an axis like "X", or a rail direction like "ASCENDING_NORTH".
    // -->
    PropertyParser.<MaterialDirectional, ElementTag>registerStaticTag(ElementTag.class, "direction", (attribute, material) -> {
        return new ElementTag(material.getDirectionName());
    });
}
Also used : PointedDripstone(org.bukkit.block.data.type.PointedDripstone) BlockFace(org.bukkit.block.BlockFace) ElementTag(com.denizenscript.denizencore.objects.core.ElementTag) ListTag(com.denizenscript.denizencore.objects.core.ListTag) Axis(org.bukkit.Axis)

Example 3 with PointedDripstone

use of org.bukkit.block.data.type.PointedDripstone in project Denizen-For-Bukkit by DenizenScript.

the class MaterialDirectional method describes.

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();
    return data instanceof Directional || data instanceof Orientable || data instanceof Rotatable || data instanceof Rail || data instanceof Jigsaw || (NMSHandler.getVersion().isAtLeast(NMSVersion.v1_17) && data instanceof PointedDripstone);
}
Also used : MaterialTag(com.denizenscript.denizen.objects.MaterialTag) PointedDripstone(org.bukkit.block.data.type.PointedDripstone) Jigsaw(org.bukkit.block.data.type.Jigsaw)

Aggregations

PointedDripstone (org.bukkit.block.data.type.PointedDripstone)3 Axis (org.bukkit.Axis)2 MaterialTag (com.denizenscript.denizen.objects.MaterialTag)1 ElementTag (com.denizenscript.denizencore.objects.core.ElementTag)1 ListTag (com.denizenscript.denizencore.objects.core.ListTag)1 BlockFace (org.bukkit.block.BlockFace)1 Jigsaw (org.bukkit.block.data.type.Jigsaw)1 Vector (org.bukkit.util.Vector)1