implement creative inventory, implement bedrock, glass and gravel, version 1.0.4
This commit is contained in:
@@ -49,7 +49,7 @@ export default class Block {
|
||||
|
||||
shouldRenderFace(world, x, y, z, face) {
|
||||
let typeId = world.getBlockAtFace(x, y, z, face);
|
||||
return typeId === 0 || !Block.getById(typeId).isSolid();
|
||||
return typeId === 0 || Block.getById(typeId).isTranslucent();
|
||||
}
|
||||
|
||||
getColor(world, x, y, z, face) {
|
||||
|
||||
@@ -9,6 +9,10 @@ import BlockTorch from "./type/BlockTorch.js";
|
||||
import Sound from "./sound/Sound.js";
|
||||
import Block from "./Block.js";
|
||||
import BlockWood from "./type/BlockWood.js";
|
||||
import BlockBedrock from "./type/BlockBedrock.js";
|
||||
import BlockGlass from "./type/BlockGlass.js";
|
||||
import SoundGlass from "./sound/SoundGlass.js";
|
||||
import BlockGravel from "./type/BlockGravel.js";
|
||||
|
||||
export class BlockRegistry {
|
||||
|
||||
@@ -20,14 +24,18 @@ export class BlockRegistry {
|
||||
Block.sounds.grass = new Sound("grass", 1.0);
|
||||
Block.sounds.cloth = new Sound("cloth", 1.0);
|
||||
Block.sounds.sand = new Sound("sand", 1.0);
|
||||
Block.sounds.glass = new SoundGlass("stone", 1.0);
|
||||
|
||||
// Blocks
|
||||
BlockRegistry.STONE = new BlockStone(1, 0);
|
||||
BlockRegistry.GRASS = new BlockGrass(2, 1);
|
||||
BlockRegistry.DIRT = new BlockDirt(3, 2);
|
||||
BlockRegistry.WOOD = new BlockWood(5, 10);
|
||||
BlockRegistry.BEDROCK = new BlockBedrock(7, 11);
|
||||
BlockRegistry.GRAVEL = new BlockGravel(13, 13);
|
||||
BlockRegistry.LOG = new BlockLog(17, 4);
|
||||
BlockRegistry.LEAVE = new BlockLeave(18, 6);
|
||||
BlockRegistry.GLASS = new BlockGlass(20, 12);
|
||||
BlockRegistry.WATER = new BlockWater(9, 7);
|
||||
BlockRegistry.SAND = new BlockSand(12, 8)
|
||||
BlockRegistry.TORCH = new BlockTorch(50, 9)
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
import Sound from "./Sound.js";
|
||||
|
||||
export default class SoundGlass extends Sound {
|
||||
|
||||
constructor(name, pitch) {
|
||||
super(name, pitch);
|
||||
}
|
||||
|
||||
getBreakSound() {
|
||||
return "random.glass";
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
import Block from "../Block.js";
|
||||
|
||||
export default class BlockBedrock extends Block {
|
||||
|
||||
constructor(id, textureSlotId) {
|
||||
super(id, textureSlotId);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
import Block from "../Block.js";
|
||||
|
||||
export default class BlockGlass extends Block {
|
||||
|
||||
constructor(id, textureSlotId) {
|
||||
super(id, textureSlotId);
|
||||
|
||||
// Sound
|
||||
this.sound = Block.sounds.glass;
|
||||
}
|
||||
|
||||
isTranslucent() {
|
||||
return true;
|
||||
}
|
||||
|
||||
shouldRenderFace(world, x, y, z, face) {
|
||||
let typeId = world.getBlockAtFace(x, y, z, face);
|
||||
return typeId === 0 || typeId !== this.id;
|
||||
}
|
||||
|
||||
getOpacity() {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
import Block from "../Block.js";
|
||||
|
||||
export default class BlockGravel extends Block {
|
||||
|
||||
constructor(id, textureSlotId) {
|
||||
super(id, textureSlotId);
|
||||
|
||||
// Sound
|
||||
this.sound = Block.sounds.gravel;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -9,6 +9,11 @@ export default class BlockLeave extends Block {
|
||||
this.sound = Block.sounds.grass;
|
||||
}
|
||||
|
||||
// TODO fix transparency of leaves
|
||||
/*isTranslucent() {
|
||||
return true;
|
||||
}*/
|
||||
|
||||
getColor(world, x, y, z, face) {
|
||||
// Inventory items have a default color
|
||||
if (world === null) {
|
||||
@@ -20,6 +25,12 @@ export default class BlockLeave extends Block {
|
||||
return world.minecraft.grassColorizer.getColor(temperature, humidity);
|
||||
}
|
||||
|
||||
// TODO fix transparency of leaves
|
||||
/*shouldRenderFace(world, x, y, z, face) {
|
||||
let typeId = world.getBlockAtFace(x, y, z, face);
|
||||
return typeId === 0 || typeId === this.id;
|
||||
}*/
|
||||
|
||||
getOpacity() {
|
||||
return 0.3;
|
||||
}
|
||||
|
||||
@@ -31,6 +31,10 @@ export default class BlockTorch extends Block {
|
||||
return false;
|
||||
}
|
||||
|
||||
isTranslucent() {
|
||||
return true;
|
||||
}
|
||||
|
||||
getRenderType() {
|
||||
return BlockRenderType.TORCH;
|
||||
}
|
||||
|
||||
@@ -34,7 +34,7 @@ export default class BlockWater extends Block {
|
||||
|
||||
getBoundingBox(world, x, y, z) {
|
||||
let box = this.boundingBox.clone();
|
||||
if (world.getBlockAt(x, y + 1, z) !== this.id) {
|
||||
if (world !== null && world.getBlockAt(x, y + 1, z) !== this.id) {
|
||||
box.maxY = 1.0 - 0.12;
|
||||
}
|
||||
return box;
|
||||
|
||||
@@ -205,8 +205,8 @@ export default class WorldGenerator extends Generator {
|
||||
// For the entire height of the chunk
|
||||
for (let y = 127; y >= 0; y--) {
|
||||
// Set bedrock on floor level
|
||||
if (y <= (this.random.nextInt(6)) - 1) {
|
||||
primer.set(x, y, z, BlockRegistry.STONE.getId()); // TODO add bedrock block
|
||||
if (y <= (this.random.nextInt(6)) - 1 || y === 0) {
|
||||
primer.set(x, y, z, BlockRegistry.BEDROCK.getId());
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -238,7 +238,7 @@ export default class WorldGenerator extends Generator {
|
||||
// Add gravel patches
|
||||
if (gravelPatchNoise) {
|
||||
topLayerTypeId = 0;
|
||||
innerLayerTypeId = BlockRegistry.STONE.getId(); // TODO add gravel block
|
||||
innerLayerTypeId = BlockRegistry.GRAVEL.getId();
|
||||
}
|
||||
|
||||
// Add sand patches
|
||||
|
||||
Reference in New Issue
Block a user