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"
// The Armorstand will hold all attributes for an armor stand.
// TODO Move this to a different file
class Armorstand {
constructor() {
// Rotation values for the body parts
@ -231,7 +232,7 @@ class Armorstand {
armor.push(this.getShoesItem())
armor.push(this.getLeggingsItem())
armor.push(this.getChestplateItem())
armor.push(this.getHeadItem())
armor.push(this.getHeadItem(mcVersion))
tags.push("Equipment:["+armor.join(",")+"]")
} else {
@ -241,7 +242,7 @@ class Armorstand {
armor.push(this.getShoesItem())
armor.push(this.getLeggingsItem())
armor.push(this.getChestplateItem())
armor.push(this.getHeadItem());
armor.push(this.getHeadItem(mcVersion))
tags.push("ArmorItems:["+armor.join(",")+"]")
@ -362,7 +363,7 @@ class Armorstand {
+"}"
}
getHeadItem() {
getHeadItem(mcVersion) {
if (this.equipHelmet == "") return "{}"
// Use input as item
@ -373,7 +374,7 @@ class Armorstand {
}
// 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") {
return "{id:\"skull\",Count:1b,Damage:3b,tag:{SkullOwner:\""+this.equipHelmet+"\"}}"
} else {

View file

@ -108,7 +108,8 @@
<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 {
props: ["armorstand"],
@ -120,13 +121,17 @@ export default {
// })
},
methods: {
convertRotation: function (rot) {
// TODO Convert Minecraft to ThreeJS rotation here
return {
x: rot.x / 180 * Math.PI,
y: rot.y / 180 * Math.PI,
z: rot.z / 180 * Math.PI,
}
// Convert the given rotation in Minecraft-space to ThreeJS-space
convertRotation(mcRotation) {
const DEG2RAD = Math.PI / 180
let matX = new Matrix4().makeRotationAxis(new Vector3(1, 0, 0), mcRotation.x * DEG2RAD)
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 },