implement torch on wall

This commit is contained in:
LabyStudio
2022-02-13 04:17:03 +01:00
parent 9078d34ab0
commit bcdbe4240b
9 changed files with 215 additions and 40 deletions
@@ -64,6 +64,14 @@ window.Block = class {
return this.boundingBox;
}
onBlockAdded(world, x, y, z) {
}
onBlockPlaced(world, x, y, z, face) {
}
collisionRayTrace(x, y, z, start, end) {
start = start.addVector(-x, -y, -z);
end = end.addVector(-x, -y, -z);
@@ -4,6 +4,14 @@ window.BlockTorch = class extends Block {
super(id, textureSlotId);
this.boundingBox = new BoundingBox(0.4, 0.0, 0.4, 0.6, 0.6, 0.6);
this.dataFaces = [
EnumBlockFace.WEST,
EnumBlockFace.EAST,
EnumBlockFace.NORTH,
EnumBlockFace.SOUTH,
EnumBlockFace.BOTTOM,
]
}
getLightValue() {
@@ -17,4 +25,30 @@ window.BlockTorch = class extends Block {
getRenderType() {
return BlockRenderType.TORCH;
}
onBlockAdded(world, x, y, z) {
for (let i = this.dataFaces.length - 1; i >= 0; i--) {
let dataFace = this.dataFaces[i];
if (world.isSolidBlockAt(x + dataFace.x, y + dataFace.y, z + dataFace.z)) {
world.setBlockDataAt(x, y, z, i + 1);
break;
}
}
}
onBlockPlaced(world, x, y, z, face) {
let meta = world.getBlockDataAt(x, y, z);
for (let i in this.dataFaces) {
let dataFace = this.dataFaces[i];
if (face === dataFace.opposite() && world.isSolidBlockAt(x + dataFace.x, y + dataFace.y, z + dataFace.z)) {
meta = parseInt(i) + 1;
break;
}
}
world.getChunkSectionAt(x >> 4, y >> 4, z >> 4).setBlockDataAt(x & 15, y & 15, z & 15, meta);
}
}