Skip to content
This repository has been archived by the owner on Feb 6, 2022. It is now read-only.

Commit

Permalink
Fix a bug that cause wrong reading of tileData.
Browse files Browse the repository at this point in the history
  • Loading branch information
dzx-dzx committed Mar 23, 2020
1 parent cd6925c commit 0b41fcb
Show file tree
Hide file tree
Showing 3 changed files with 176 additions and 6 deletions.
175 changes: 173 additions & 2 deletions packs/behaviors/scripts/client/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ var blockQuery = []

import { Coordinate, Position, BlockType, Block, Direction, Usage, Description, Generator } from '../utils'
let generatorArray = [];

(function () {
generatorArray.push(
new Generator(
Expand Down Expand Up @@ -116,7 +117,9 @@ let generatorArray = [];
}
)
)
}());

(function () {
generatorArray.push(
new Generator(
new Description("Clone, ignoring direction.",
Expand Down Expand Up @@ -195,7 +198,9 @@ let generatorArray = [];
}
)
)
}());

(function () {
generatorArray.push(
new Generator(
new Description("Test.",
Expand Down Expand Up @@ -264,8 +269,174 @@ let generatorArray = [];
}
)
)
}())
}());

(function () {
generatorArray.push(
new Generator(
new Description("Create a line with given interval.",
new Usage(
["Start point"],
["BlockType"],
["Direction"],
[
{
viewtype: "edittext",
text: "Length:",
key: "length",
},
{
viewtype: "edittext",
text: "Interval:",
key: "interval",
}
])
),

[undefined],
[undefined],
[undefined],
{
"positionArrayLengthRequired": 1,
"blockTypeArrayLengthRequired": 1,
"directionArrayLengthRequired": 1,
"length": 0,
"interval": 0
},

function (position) {
displayObject(position)
let indexOfVacancy = this.positionArray.indexOf(undefined)
if (indexOfVacancy == -1) displayChat("Too many positions!New one is ignored")
else this.positionArray[indexOfVacancy] = position
},
function (blockType) {
displayObject(blockType)
let indexOfVacancy = this.blockTypeArray.indexOf(undefined)
if (indexOfVacancy == -1) displayChat("Too many blockTypes!New one is ignored")
else this.blockTypeArray[indexOfVacancy] = blockType
},
function (direction) {
displayObject(direction)
let indexOfVacancy = this.directionArray.indexOf(undefined)
if (indexOfVacancy == -1) displayChat("Too many directions!New one is ignored")
else this.directionArray[indexOfVacancy] = direction
},
function (index) {
if (index === undefined)
for (index = this.positionArray.length - 1; index >= 0 && this.positionArray[index] == undefined; index--);
if (index >= 0) this.positionArray[index] = undefined
displayObject(this.positionArray)
},
function (index) {
if (index === undefined)
for (index = this.blockTypeArray.length - 1; index >= 0 && this.blockTypeArray[index] == undefined; index--);
if (index >= 0) this.blockTypeArray[index] = undefined
displayObject(this.blockTypeArray)
},
function (index) {
if (index === undefined)
for (index = this.directionArray.length - 1; index >= 0 && this.directionArray[index] == undefined; index--);
if (index >= 0) this.directionArray[index] = undefined
displayObject(this.directionArray)
},

function () {
let result = new String()
if (this.blockTypeArray.indexOf(undefined) != -1)
result += "Too few blockTypes!Refusing to execute.\n"
if (this.positionArray.indexOf(undefined) != -1)
result += "Too few positions!Refusing to execute."
if (this.directionArray.indexOf(undefined) != -1)
result += "Too few directions!Refusing to execute."
if (result == "") result = "success"

return result;
},
function () {
let blockArray = []

displayChat("§b NZ is JULAO!")

let positionArray = this.positionArray
let blockTypeArray = this.blockTypeArray
let directionArray = this.directionArray

displayChat("§b Yes, NZ is JULAO!")


let direction = (function () {
if (-45 <= directionArray[0].y && directionArray[0].y <= 45) return "+z"
else if (-135 <= directionArray[0].y && directionArray[0].y <= -45) return "+x"
else if (45 <= directionArray[0].y && directionArray[0].y <= 135) return "-x"
else return "-z"
}());

switch (direction) {
case "+z": {
let x = positionArray[0].coordinate.x
let y = positionArray[0].coordinate.y
for (let z = positionArray[0].coordinate.z; z < this.option.length + positionArray[0].coordinate.z; z += (this.option.interval + 1))
blockArray.push(new Block(
new Position(
new Coordinate(x, y, z),
positionArray[0].tickingArea
),
blockTypeArray[0])
)
break;
}
case "-z": {
let x = positionArray[0].coordinate.x
let y = positionArray[0].coordinate.y
for (let z = positionArray[0].coordinate.z; z > -this.option.length + positionArray[0].coordinate.z; z -= (this.option.interval + 1))
blockArray.push(new Block(
new Position(
new Coordinate(x, y, z),
positionArray[0].tickingArea
),
blockTypeArray[0])
)
break;
}
case "+x": {
let z = positionArray[0].coordinate.z
let y = positionArray[0].coordinate.y
for (let x = positionArray[0].coordinate.x; x < this.option.length + positionArray[0].coordinate.x; x += (this.option.interval + 1))
blockArray.push(new Block(
new Position(
new Coordinate(x, y, z),
positionArray[0].tickingArea
),
blockTypeArray[0])
)
break;
}
case "-x": {
let z = positionArray[0].coordinate.z
let y = positionArray[0].coordinate.y
for (let x = positionArray[0].coordinate.x; x > -this.option.length + positionArray[0].coordinate.z; x -= (this.option.interval + 1))
blockArray.push(new Block(
new Position(
new Coordinate(x, y, z),
positionArray[0].tickingArea
),
blockTypeArray[0])
)
break;
}
}

return blockArray
},
function () {
this.positionArray = [undefined]
this.blockTypeArray = [undefined]
this.directionArray = [undefined]
}
)
)
}());

clientSystem.initialize = function () {

Expand Down Expand Up @@ -427,7 +598,7 @@ clientSystem.initialize = function () {
break;
}
case "chooseLastGenerator": {
generatorIndex = (generatorIndex - 1) % generatorArray.length
generatorIndex = (generatorIndex - 1 + generatorArray.length) % generatorArray.length
}
}
break;
Expand Down
3 changes: 1 addition & 2 deletions packs/behaviors/scripts/server/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,6 @@ serverSystem.initialize = function () {
break;
}
case "minecraft:iron_sword": {
displayChat("AAAAAAAAAAAAAAAAAA")
sendCommand("showMenu",playerID)
break;
}
Expand Down Expand Up @@ -237,7 +236,7 @@ function setBlock(block) {
let coordinate = position.coordinate
//Thank you, WavePlayz!

serverSystem.executeCommand(`/setblock ${coordinate.x} ${coordinate.y} ${coordinate.z} ${blockType.blockIdentifier.slice(blockType.blockIdentifier.indexOf(":") + 1)} ${blockStateTranslator.getID(blockType.blockIdentifier,blockType.blockState)}`, (commandResultData) => {
serverSystem.executeCommand(`/setblock ${coordinate.x} ${coordinate.y} ${coordinate.z} ${blockType.blockIdentifier.slice(blockType.blockIdentifier.indexOf(":") + 1)} ${blockStateTranslator.getData(blockType.blockIdentifier,{"data":blockType.blockState})}`, (commandResultData) => {

// var targerBlock = serverSystem.getBlock(position.tickingArea, coordinate.x, coordinate.y, coordinate.z)

Expand Down
4 changes: 2 additions & 2 deletions packs/resources/experimental_ui/menu/menu.html
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@
}
function handleEditTextInput(character) {
if (character == 'd')
if (editTextInput > 0) editTextInput = editTextInput.slice(0, editTextInput.length - 1)
if (editTextInput.length > 0) editTextInput = editTextInput.slice(0, editTextInput.length - 1)
else;
else editTextInput += character
inputDisplay.textContent = editTextInput
Expand Down Expand Up @@ -235,7 +235,7 @@
`<div style="display: flex;flex-direction: row;">
<div style="width: 90%;">${optionUsage[i].text}</div>
<input id=${i} type="text" style="width: 10%;text-align: center;" value=${defaultNumber}
onclick="idOfEditTextOnFocus = ${i};inputDisplay.textContent = editTextInput = ${defaultNumber}">
onclick="idOfEditTextOnFocus = ${i};inputDisplay.textContent = editTextInput = '0';">
</div>`)
break;
}
Expand Down

0 comments on commit 0b41fcb

Please sign in to comment.