From 8ccd87ae45280529d616f56ad5c362e2907592ee Mon Sep 17 00:00:00 2001 From: Lars Martens Date: Fri, 20 Aug 2021 20:43:29 +0200 Subject: [PATCH] Add code generation --- README.md | 2 + src/App.vue | 280 +++++++++++++++++++++++++++++++++++++++++++++++++++- src/util.js | 39 ++++++++ 3 files changed, 318 insertions(+), 3 deletions(-) create mode 100644 src/util.js diff --git a/README.md b/README.md index 9a01f9e..378a9d4 100644 --- a/README.md +++ b/README.md @@ -7,12 +7,14 @@ The following things still have to be done. Possibly in this order. - [ ] Equipment - [ ] Equipment locking - [ ] Can we scrape the MC wiki for a searchable dropdown list? https://minecraft.fandom.com/api.php ? + * Only items that are available in a given minecraft version should show up - [ ] Colors for leather pieces - [ ] Helmet: player name - [ ] Helmet: Image URL - [ ] Helmet: https://minecraft-heads.com -> but use Minecraft-URL or Player name and skip the give code thing, that was confusing anyways. Have a help popup that explains this functionality with a few screenshots. - [ ] Custom name with styling options - [ ] Code generation +- [ ] Hide controls that are not relevant for the chosen minecraft version - [ ] **Proper rotation conversion between Minecraft and ThreeJS** - [ ] /summon or /give - [ ] Hint for command block diff --git a/src/App.vue b/src/App.vue index 830f70d..5d1f6e0 100644 --- a/src/App.vue +++ b/src/App.vue @@ -50,7 +50,7 @@
- + @@ -93,6 +93,10 @@
+

{{currentCode}}

+ +
+
@@ -101,6 +105,7 @@ diff --git a/src/util.js b/src/util.js new file mode 100644 index 0000000..5d06c5c --- /dev/null +++ b/src/util.js @@ -0,0 +1,39 @@ +// This file contains small helper methods + +// From here: http://stackoverflow.com/a/8809472/1456971 +export function generateUUID(){ + var d = new Date().getTime() + var uuid = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) { + var r = (d + Math.random()*16)%16 | 0 + d = Math.floor(d/16) + return (c=='x' ? r : (r&0x3|0x8)).toString(16) + }) + return uuid +} + +export function generateIntArray() { + const buffer = new Uint32Array(4) + const UUID = new DataView(buffer.buffer) + const paddings = [8, 4, 4, 4, 12] + + let hexUUID = generateUUID().split("-").map((val, i) => val.padStart(paddings[i], "0")).join("") + let ints = [] + + for (let i = 0; i < 4; i++) { + num = Number("0x" + hexUUID.substring(i*8, (i+1)*8)) + UUID.setInt32(i*4, num) + ints.push(UUID.getInt32(i*4)) + } + + return '[I;' + ints.join(",") + ']' +} + +// Check if the x, y, z attributes of the given thing are all zero. +export function isXYZZero(thing) { + return thing.x == 0 && thing.y == 0 && thing.z == 0 +} + +// Returns a string with a JSON array from the x, y, z attributes of the given thing. +export function xyzToTextArray(thing) { + return "["+thing.x+"f,"+thing.y+"f,"+thing.z+"f]"; +} \ No newline at end of file