1
0
Fork 0
mirror of https://github.com/haselkern/Minecraft-ArmorStand.git synced 2025-05-18 05:55:35 +00:00

Convert rotations correctly

This commit is contained in:
Lars Martens 2021-08-20 22:01:21 +02:00
parent 8ccd87ae45
commit f05e8a383c
2 changed files with 18 additions and 12 deletions

View file

@ -108,6 +108,7 @@ import RotationSliderRow from "./RotationSliderRow.vue"
import {generateIntArray, generateUUID, isXYZZero, xyzToTextArray} from "./util.js" import {generateIntArray, generateUUID, isXYZZero, xyzToTextArray} from "./util.js"
// The Armorstand will hold all attributes for an armor stand. // The Armorstand will hold all attributes for an armor stand.
// TODO Move this to a different file
class Armorstand { class Armorstand {
constructor() { constructor() {
// Rotation values for the body parts // Rotation values for the body parts
@ -231,7 +232,7 @@ class Armorstand {
armor.push(this.getShoesItem()) armor.push(this.getShoesItem())
armor.push(this.getLeggingsItem()) armor.push(this.getLeggingsItem())
armor.push(this.getChestplateItem()) armor.push(this.getChestplateItem())
armor.push(this.getHeadItem()) armor.push(this.getHeadItem(mcVersion))
tags.push("Equipment:["+armor.join(",")+"]") tags.push("Equipment:["+armor.join(",")+"]")
} else { } else {
@ -241,7 +242,7 @@ class Armorstand {
armor.push(this.getShoesItem()) armor.push(this.getShoesItem())
armor.push(this.getLeggingsItem()) armor.push(this.getLeggingsItem())
armor.push(this.getChestplateItem()) armor.push(this.getChestplateItem())
armor.push(this.getHeadItem()); armor.push(this.getHeadItem(mcVersion))
tags.push("ArmorItems:["+armor.join(",")+"]") tags.push("ArmorItems:["+armor.join(",")+"]")
@ -362,7 +363,7 @@ class Armorstand {
+"}" +"}"
} }
getHeadItem() { getHeadItem(mcVersion) {
if (this.equipHelmet == "") return "{}" if (this.equipHelmet == "") return "{}"
// Use input as item // Use input as item
@ -373,7 +374,7 @@ class Armorstand {
} }
// Use input as player name // Use input as player name
else if (this.helmetMode == "player") { else if (this.helmetMode == "name") {
if (mcVersion == "1.8" || mcVersion == "1.10" || mcVersion == "1.11") { if (mcVersion == "1.8" || mcVersion == "1.10" || mcVersion == "1.11") {
return "{id:\"skull\",Count:1b,Damage:3b,tag:{SkullOwner:\""+this.equipHelmet+"\"}}" return "{id:\"skull\",Count:1b,Damage:3b,tag:{SkullOwner:\""+this.equipHelmet+"\"}}"
} else { } else {

View file

@ -108,7 +108,8 @@
<script> <script>
import { Box, Camera, LambertMaterial, AmbientLight, Renderer, Scene, Object3D } from "troisjs"; import { Box, Camera, LambertMaterial, AmbientLight, Renderer, Scene, Object3D } from "troisjs"
import {Vector3, Matrix4, Euler} from "three"
export default { export default {
props: ["armorstand"], props: ["armorstand"],
@ -120,13 +121,17 @@ export default {
// }) // })
}, },
methods: { methods: {
convertRotation: function (rot) { // Convert the given rotation in Minecraft-space to ThreeJS-space
// TODO Convert Minecraft to ThreeJS rotation here convertRotation(mcRotation) {
return { const DEG2RAD = Math.PI / 180
x: rot.x / 180 * Math.PI,
y: rot.y / 180 * Math.PI, let matX = new Matrix4().makeRotationAxis(new Vector3(1, 0, 0), mcRotation.x * DEG2RAD)
z: rot.z / 180 * Math.PI, let matY = new Matrix4().makeRotationAxis(new Vector3(0, 1, 0), -mcRotation.y * DEG2RAD)
} matY.multiply(matX)
let matZ = new Matrix4().makeRotationAxis(new Vector3(0, 0, 1), -mcRotation.z * DEG2RAD)
matZ.multiply(matY)
return new Euler().setFromRotationMatrix(matZ).toVector3()
} }
}, },
components: { Box, Camera, LambertMaterial, Renderer, Scene, Object3D }, components: { Box, Camera, LambertMaterial, Renderer, Scene, Object3D },