From 9a9ecdbebb0a949df0ce79575593c4c9e72a1f38 Mon Sep 17 00:00:00 2001 From: bluefireoly Date: Sun, 13 Sep 2020 15:58:15 +0200 Subject: [PATCH] Structure rotation --- .../kspigot/structures/StructureBuilder.kt | 26 ++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/src/main/kotlin/net/axay/kspigot/structures/StructureBuilder.kt b/src/main/kotlin/net/axay/kspigot/structures/StructureBuilder.kt index ec6b7a4e..821239ae 100644 --- a/src/main/kotlin/net/axay/kspigot/structures/StructureBuilder.kt +++ b/src/main/kotlin/net/axay/kspigot/structures/StructureBuilder.kt @@ -1,8 +1,32 @@ package net.axay.kspigot.structures import net.axay.kspigot.extensions.geometry.plus +import net.axay.kspigot.extensions.geometry.toSimpleLoc +import net.axay.kspigot.extensions.geometry.toVector import org.bukkit.Location +import org.bukkit.util.Vector fun Structure.buildAt(loc: Location) { structureData.forEach { it.structureData.createAt(loc + it.location) } -} \ No newline at end of file +} + +fun Structure.rotateAroundX(angle: Number) + = rotate { it.rotateAroundX(angle.toDouble()) } + +fun Structure.rotateAroundY(angle: Number) + = rotate { it.rotateAroundY(angle.toDouble()) } + +fun Structure.rotateAroundZ(angle: Number) + = rotate { it.rotateAroundZ(angle.toDouble()) } + +inline fun Structure.rotate(vectorRotation: (Vector) -> Vector) + = Structure( + HashSet().apply { + structureData.forEach { + this += SingleStructureData( + vectorRotation.invoke(it.location.toVector()).toSimpleLoc(), + it.structureData + ) + } + } + ) \ No newline at end of file