From fbb40aac669b002a5f4bc221d6ac82eedbb8806b Mon Sep 17 00:00:00 2001 From: Alex 'mcmonkey' Goodwin Date: Sat, 15 Feb 2020 00:22:26 -0800 Subject: [PATCH] add tags Location.rotate_yaw/pitch --- .../denizen/objects/LocationTag.java | 28 +++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/plugin/src/main/java/com/denizenscript/denizen/objects/LocationTag.java b/plugin/src/main/java/com/denizenscript/denizen/objects/LocationTag.java index f3101a4493..ffc1644388 100644 --- a/plugin/src/main/java/com/denizenscript/denizen/objects/LocationTag.java +++ b/plugin/src/main/java/com/denizenscript/denizen/objects/LocationTag.java @@ -1671,6 +1671,30 @@ else if (object.getBlockTypeForTag(attribute) == Material.FLOWER_POT) { } }); + // <--[tag] + // @attribute ]> + // @returns LocationTag + // @description + // Returns the location with the yaw rotated the specified amount (eg 180 to face the location backwards). + // --> + registerTag("rotate_yaw", (attribute, object) -> { + LocationTag loc = LocationTag.valueOf(object.identify()); + loc.setYaw(loc.getYaw() + (float) attribute.getDoubleContext(1)); + return loc; + }); + + // <--[tag] + // @attribute ]> + // @returns LocationTag + // @description + // Returns the location with the pitch rotated the specified amount. Note that this is capped to +/- 90. + // --> + registerTag("rotate_pitch", (attribute, object) -> { + LocationTag loc = LocationTag.valueOf(object.identify()); + loc.setPitch(Math.max(-90, Math.min(90, loc.getPitch() + (float) attribute.getDoubleContext(1)))); + return loc; + }); + // <--[tag] // @attribute ]> // @returns LocationTag @@ -1699,7 +1723,7 @@ else if (object.getBlockTypeForTag(attribute) == Material.FLOWER_POT) { int degrees = 45; LocationTag facingLoc; if (LocationTag.matches(attribute.getContext(1))) { - facingLoc = LocationTag.valueOf(attribute.getContext(1)); + facingLoc = object.clone(); } else if (EntityTag.matches(attribute.getContext(1))) { facingLoc = EntityTag.valueOf(attribute.getContext(1)).getLocation(); @@ -1771,7 +1795,7 @@ else if (context.split(",").length == 2) { pitch = Float.parseFloat(split[0]); yaw = Float.parseFloat(split[1]); } - LocationTag loc = LocationTag.valueOf(object.identify()); + LocationTag loc = object.clone(); loc.setPitch(pitch); loc.setYaw(yaw); return loc;