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

Commit

Permalink
Merge pull request #58 from NorthernOceanS/issue55
Browse files Browse the repository at this point in the history
Fix #55, remove using of tileData.
  • Loading branch information
callstackexceed authored May 7, 2021
2 parents 5207f7f + a31189b commit c6621a8
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 10,773 deletions.
2 changes: 1 addition & 1 deletion packs/behaviors/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"version": [
0,
13,
3
4
]
},
"modules": [
Expand Down
6 changes: 3 additions & 3 deletions packs/behaviors/scripts/client/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ const platform = {
y: undefined,
z: undefined,
blockIdentifier: undefined,
tileData: undefined,
blockState: undefined,
playerID: undefined
})

Expand Down Expand Up @@ -420,11 +420,11 @@ const platform = {
let blockType = await blockFetch.get(tickingArea, x, y, z)
return blockType
}
function setBlock(user, x, y, z, blockIdentifier, tileData) {
function setBlock(user, x, y, z, blockIdentifier, blockState) {
let logger = loggerFactory(user);
logger.log("verbose", "NZ is JULAO")
let setBlockEventData = clientSystem.createEventData("NZConstructor:setBlock")
setBlockEventData.data = { x: x, y: y, z: z, blockIdentifier: blockIdentifier, tileData: tileData, playerID: playerID }
setBlockEventData.data = { x: x, y: y, z: z, blockIdentifier: blockIdentifier, blockState: blockState, playerID: playerID }
clientSystem.broadcastEvent("NZConstructor:setBlock", setBlockEventData)
logger.logObject("verbose", setBlockEventData)
}
Expand Down
31 changes: 4 additions & 27 deletions packs/behaviors/scripts/server/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import system from '../system.js';
import '../plugin/index.js';
import { emptyPlatform, Coordinate, Position, BlockType, Direction, Block } from 'norma-core';

import { blockStateTranslator } from '../translator.js'
import { utils } from '../utils.js'

emptyPlatform.use(system);
Expand All @@ -20,8 +19,6 @@ const platform = {
scriptLoggerConfig.data.log_warnings = true;
serverSystem.broadcastEvent("minecraft:script_logger_config", scriptLoggerConfig);

let blockStateToTileDataTable = new Map()

let compiler = {
raw: function (blockArray) {
return blockArray
Expand Down Expand Up @@ -74,16 +71,6 @@ const platform = {
endCoordinate.z = temp
}

let tileData = undefined

if (blockStateToTileDataTable.has(JSON.stringify(blockType.blockState))) {
tileData = blockStateToTileDataTable.get(JSON.stringify(blockType.blockState))
}
else {
tileData = blockStateTranslator.getData(blockType.blockIdentifier, { "data": blockType.blockState })
blockStateToTileDataTable.set(JSON.stringify(blockType.blockState), tileData)
}

//Bypass the restriction of 32767 blocks
for (let x = startCoordinate.x; x <= endCoordinate.x; x += 32)
for (let y = startCoordinate.y; y <= endCoordinate.y; y += 32)
Expand All @@ -93,7 +80,7 @@ const platform = {
${Math.min(y + 31, endCoordinate.y)}
${Math.min(z + 31, endCoordinate.z)}
${blockType.blockIdentifier.slice(blockType.blockIdentifier.indexOf(":") + 1)}
${tileData} replace`, (commandResultData) => { }
[${blockType.blockState == null ? "" : JSON.stringify(blockType.blockState).slice(1, -1)}] replace`, (commandResultData) => { }
);

return []
Expand Down Expand Up @@ -218,8 +205,8 @@ const platform = {
serverSystem.broadcastEvent("NZConstructor:blockFetchResponse", blockFetchResponseEventData)
})
serverSystem.listenForEvent("NZConstructor:setBlock", (eventData) => {
let { x, y, z, blockIdentifier, tileData } = eventData.data
serverSystem.executeCommand(`/setblock ${x} ${y} ${z} ${blockIdentifier.slice(blockIdentifier.indexOf(":") + 1)} ${tileData} replace`, (commandResultData) => { })
let { x, y, z, blockIdentifier, blockState } = eventData.data
serverSystem.executeCommand(`/setblock ${x} ${y} ${z} ${blockIdentifier.slice(blockIdentifier.indexOf(":") + 1)} [${blockType.blockState == null ? "" : JSON.stringify(blockType.blockState).slice(1, -1)}] replace`, (commandResultData) => { })
})

//I suppose I have to make an explanation.
Expand Down Expand Up @@ -306,20 +293,10 @@ const platform = {
let coordinate = position.coordinate
//Thank you, WavePlayz!

let tileData = undefined

if (blockStateToTileDataTable.has(JSON.stringify(blockType.blockState))) {
tileData = blockStateToTileDataTable.get(JSON.stringify(blockType.blockState))
}
else {
tileData = blockStateTranslator.getData(blockType.blockIdentifier, { "data": blockType.blockState })
blockStateToTileDataTable.set(JSON.stringify(blockType.blockState), tileData)
}

//TODO:
//It currently use destroy mode to force replace the old block, but will leave tons of items.
//Might change to set air block first.
serverSystem.executeCommand(`/setblock ${coordinate.x} ${coordinate.y} ${coordinate.z} ${blockType.blockIdentifier.slice(blockType.blockIdentifier.indexOf(":") + 1)} ${tileData} replace`, (commandResultData) => {
serverSystem.executeCommand(`/setblock ${coordinate.x} ${coordinate.y} ${coordinate.z} ${blockType.blockIdentifier.slice(blockType.blockIdentifier.indexOf(":") + 1)} [${blockType.blockState == null ? "" : JSON.stringify(blockType.blockState).slice(1, -1)}] replace`, (commandResultData) => {

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

Expand Down
Loading

0 comments on commit c6621a8

Please sign in to comment.