Server authority
This commit is contained in:
@@ -0,0 +1,16 @@
|
||||
import { BlockRegistry, EverythingRegistry } from "$/common/everything_registry.ts";
|
||||
import { register_block_item } from "$/common/utils.ts";
|
||||
|
||||
// behavior lives in server/game/blocks.ts
|
||||
const block = EverythingRegistry.register<BlockRegistry>("blocks", "bworld:chest", {
|
||||
id: "bworld:chest",
|
||||
textures: "bworld:planks",
|
||||
toughness: 8,
|
||||
requires_tool: false,
|
||||
tool_to_break: "axe",
|
||||
drop_table: "bworld:chest",
|
||||
has_collision: false,
|
||||
interactive: true,
|
||||
});
|
||||
|
||||
register_block_item(block);
|
||||
@@ -0,0 +1,14 @@
|
||||
import { BlockRegistry, EverythingRegistry } from "$/common/everything_registry.ts";
|
||||
import { register_block_item } from "$/common/utils.ts";
|
||||
|
||||
const block = EverythingRegistry.register<BlockRegistry>("blocks", "bworld:coal_ore", {
|
||||
id: "bworld:coal_ore",
|
||||
textures: "bworld:stone_coal",
|
||||
has_collision: true,
|
||||
drop_table: "bworld:coal_ore",
|
||||
toughness: 5,
|
||||
requires_tool: true,
|
||||
tool_to_break: "pickaxe",
|
||||
});
|
||||
|
||||
register_block_item(block);
|
||||
@@ -0,0 +1,14 @@
|
||||
import { BlockRegistry, EverythingRegistry } from "$/common/everything_registry.ts";
|
||||
import { register_block_item } from "$/common/utils.ts";
|
||||
|
||||
const block = EverythingRegistry.register<BlockRegistry>("blocks", "bworld:copper_ore", {
|
||||
id: "bworld:copper_ore",
|
||||
textures: "bworld:stone_copper",
|
||||
has_collision: true,
|
||||
drop_table: "bworld:copper_ore",
|
||||
toughness: 5,
|
||||
requires_tool: true,
|
||||
tool_to_break: "pickaxe",
|
||||
});
|
||||
|
||||
register_block_item(block);
|
||||
@@ -0,0 +1,145 @@
|
||||
import { EverythingRegistry } from "$/common/everything_registry.ts";
|
||||
|
||||
interface CropsRegistry {
|
||||
total_stages: number;
|
||||
time_to_grow: number[];
|
||||
item_drop: string;
|
||||
sprite_ids: string[];
|
||||
regrowable: boolean;
|
||||
}
|
||||
|
||||
EverythingRegistry.register<CropsRegistry>("crops", "bworld:carrot", {
|
||||
total_stages: 5,
|
||||
time_to_grow: [60, 60 * 3, 60 * 3, 60 * 3],
|
||||
sprite_ids: [
|
||||
"bworld:carrot_seeds",
|
||||
"bworld:carrot_stage_1",
|
||||
"bworld:carrot_stage_2",
|
||||
"bworld:carrot_stage_3",
|
||||
"bworld:carrot_stage_4",
|
||||
],
|
||||
item_drop: "bworld:carrot",
|
||||
regrowable: false,
|
||||
});
|
||||
EverythingRegistry.register<CropsRegistry>("crops", "bworld:potato", {
|
||||
total_stages: 5,
|
||||
time_to_grow: [45, 60 * 2, 60 * 2, 60 * 2],
|
||||
sprite_ids: [
|
||||
"bworld:potato_seeds",
|
||||
"bworld:potato_stage_1",
|
||||
"bworld:potato_stage_2",
|
||||
"bworld:potato_stage_3",
|
||||
"bworld:potato_stage_4",
|
||||
],
|
||||
item_drop: "bworld:potato",
|
||||
regrowable: false,
|
||||
});
|
||||
EverythingRegistry.register<CropsRegistry>("crops", "bworld:tomato", {
|
||||
total_stages: 5,
|
||||
time_to_grow: [90, 60 * 2, 60 * 2, 60 * 3],
|
||||
sprite_ids: [
|
||||
"bworld:tomato_seeds",
|
||||
"bworld:tomato_stage_1",
|
||||
"bworld:tomato_stage_2",
|
||||
"bworld:tomato_stage_3",
|
||||
"bworld:tomato_stage_4",
|
||||
],
|
||||
item_drop: "bworld:tomato",
|
||||
regrowable: true,
|
||||
});
|
||||
EverythingRegistry.register<CropsRegistry>("crops", "bworld:pumpkin", {
|
||||
total_stages: 5,
|
||||
time_to_grow: [60 * 2, 60 * 4, 60 * 4, 60 * 4],
|
||||
sprite_ids: [
|
||||
"bworld:pumpkin_seeds",
|
||||
"bworld:pumpkin_stage_1",
|
||||
"bworld:pumpkin_stage_2",
|
||||
"bworld:pumpkin_stage_3",
|
||||
"bworld:pumpkin_stage_4",
|
||||
],
|
||||
item_drop: "bworld:pumpkin",
|
||||
regrowable: false,
|
||||
});
|
||||
|
||||
interface TileCropData {
|
||||
current_stage: number;
|
||||
growth_time: number;
|
||||
}
|
||||
/*
|
||||
function create_crop_tile(crop_id: string) {
|
||||
const crop_info = EverythingRegistry.get<CropsRegistry>("crops", crop_id);
|
||||
|
||||
return {
|
||||
has_collision: false,
|
||||
on_create(_, tile) {
|
||||
tile.data = {
|
||||
current_stage: 0,
|
||||
growth_time: 0,
|
||||
};
|
||||
},
|
||||
texture_id(tile) {
|
||||
return crop_info.sprite_ids[tile.data!.current_stage];
|
||||
},
|
||||
on_click(world, tile) {
|
||||
const [player] = world.get_tag("player")!;
|
||||
const player_inventory = player.get(PlayerComponent)!.player_inventory;
|
||||
const item = player_inventory.container.get_item(player_inventory.hotbar_selected);
|
||||
if (!item) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (item.type_id === "bworld:pickaxe") {
|
||||
world.dimension.delete_tile(world, tile);
|
||||
}
|
||||
},
|
||||
on_interact(world, tile) {
|
||||
if (tile.data!.current_stage + 1 !== crop_info.total_stages) {
|
||||
return;
|
||||
}
|
||||
const [player] = world.get_tag("player")!;
|
||||
const player_inventory = player.get(PlayerComponent)!.player_inventory;
|
||||
player_inventory.container.add_item(new ItemStack(crop_info.item_drop));
|
||||
if (crop_info.regrowable) {
|
||||
tile.data!.current_stage -= 1;
|
||||
} else {
|
||||
world.dimension.delete_tile(world, tile);
|
||||
}
|
||||
},
|
||||
on_second(_, tile, delta) {
|
||||
const crop = tile.data!;
|
||||
// finished growing
|
||||
if (crop.current_stage + 1 === crop_info.total_stages) {
|
||||
return;
|
||||
}
|
||||
|
||||
// grow !
|
||||
crop.growth_time += delta;
|
||||
if (crop.growth_time >= crop_info.time_to_grow[crop.current_stage]) {
|
||||
crop.current_stage += 1;
|
||||
crop.growth_time = 0;
|
||||
}
|
||||
},
|
||||
} as BlockRegistry<TileCropData>;
|
||||
}
|
||||
|
||||
EverythingRegistry.register<BlockRegistry<TileCropData>>(
|
||||
"blocks",
|
||||
"bworld:tomato_crop",
|
||||
create_crop_tile("bworld:tomato"),
|
||||
);
|
||||
EverythingRegistry.register<BlockRegistry<TileCropData>>(
|
||||
"blocks",
|
||||
"bworld:carrot_crop",
|
||||
create_crop_tile("bworld:carrot"),
|
||||
);
|
||||
EverythingRegistry.register<BlockRegistry<TileCropData>>(
|
||||
"blocks",
|
||||
"bworld:potato_crop",
|
||||
create_crop_tile("bworld:potato"),
|
||||
);
|
||||
EverythingRegistry.register<BlockRegistry<TileCropData>>(
|
||||
"blocks",
|
||||
"bworld:pumpkin_crop",
|
||||
create_crop_tile("bworld:pumpkin"),
|
||||
);
|
||||
*/
|
||||
@@ -0,0 +1,15 @@
|
||||
import { BlockRegistry, EverythingRegistry } from "$/common/everything_registry.ts";
|
||||
import { register_block_item } from "$/common/utils.ts";
|
||||
|
||||
// hoeing it is handled in server/game/blocks.ts
|
||||
const block = EverythingRegistry.register<BlockRegistry>("blocks", "bworld:dirt", {
|
||||
id: "bworld:dirt",
|
||||
textures: "bworld:dirt",
|
||||
has_collision: false,
|
||||
drop_table: "bworld:dirt",
|
||||
toughness: 2,
|
||||
requires_tool: false,
|
||||
tool_to_break: "shovel",
|
||||
});
|
||||
|
||||
register_block_item(block);
|
||||
@@ -0,0 +1,16 @@
|
||||
import { BlockRegistry, EverythingRegistry } from "$/common/everything_registry.ts";
|
||||
import { register_block_item } from "$/common/utils.ts";
|
||||
|
||||
// behavior lives in server/game/blocks.ts
|
||||
const block = EverythingRegistry.register<BlockRegistry>("blocks", "bworld:furnace", {
|
||||
id: "bworld:furnace",
|
||||
textures: { front: "bworld:furnace", side: "bworld:stone" },
|
||||
has_collision: true,
|
||||
drop_table: "bworld:furnace",
|
||||
toughness: 5,
|
||||
requires_tool: true,
|
||||
tool_to_break: "pickaxe",
|
||||
interactive: true,
|
||||
});
|
||||
|
||||
register_block_item(block);
|
||||
@@ -0,0 +1,14 @@
|
||||
import { BlockRegistry, EverythingRegistry } from "$/common/everything_registry.ts";
|
||||
import { register_block_item } from "$/common/utils.ts";
|
||||
|
||||
const block = EverythingRegistry.register<BlockRegistry>("blocks", "bworld:glass", {
|
||||
id: "bworld:glass",
|
||||
textures: "bworld:glass",
|
||||
has_collision: true,
|
||||
transparent: true,
|
||||
toughness: 3,
|
||||
requires_tool: false,
|
||||
tool_to_break: "pickaxe",
|
||||
});
|
||||
|
||||
register_block_item(block);
|
||||
@@ -0,0 +1,14 @@
|
||||
import { BlockRegistry, EverythingRegistry } from "$/common/everything_registry.ts";
|
||||
import { register_block_item } from "$/common/utils.ts";
|
||||
|
||||
const block = EverythingRegistry.register<BlockRegistry>("blocks", "bworld:gold_ore", {
|
||||
id: "bworld:gold_ore",
|
||||
textures: "bworld:stone_gold",
|
||||
has_collision: true,
|
||||
drop_table: "bworld:gold_ore",
|
||||
toughness: 5,
|
||||
requires_tool: true,
|
||||
tool_to_break: "pickaxe",
|
||||
});
|
||||
|
||||
register_block_item(block);
|
||||
@@ -0,0 +1,12 @@
|
||||
import { BlockRegistry, EverythingRegistry } from "$/common/everything_registry.ts";
|
||||
|
||||
// hoeing it is handled in server/game/blocks.ts
|
||||
EverythingRegistry.register<BlockRegistry>("blocks", "bworld:grass", {
|
||||
id: "bworld:grass",
|
||||
textures: { top: "bworld:grass_top", bottom: "bworld:dirt", "side": "bworld:grass_side" },
|
||||
has_collision: false,
|
||||
drop_table: "bworld:dirt",
|
||||
toughness: 2,
|
||||
requires_tool: false,
|
||||
tool_to_break: "shovel",
|
||||
});
|
||||
@@ -0,0 +1,18 @@
|
||||
import { BlockRegistry, EverythingRegistry } from "$/common/everything_registry.ts";
|
||||
import { register_block_item } from "$/common/utils.ts";
|
||||
|
||||
// TODO: watered state
|
||||
const block = EverythingRegistry.register<BlockRegistry>("blocks", "bworld:hoed_dirt", {
|
||||
id: "bworld:hoed_dirt",
|
||||
textures: { side: "bworld:dirt", top: "bworld:hoed_dirt", bottom: "bworld:dirt" },
|
||||
has_collision: false,
|
||||
drop_table: "bworld:dirt",
|
||||
toughness: 5,
|
||||
requires_tool: false,
|
||||
tool_to_break: "shovel",
|
||||
states: [
|
||||
{ name: "watered", bits: 1, default: 0 },
|
||||
],
|
||||
});
|
||||
|
||||
register_block_item(block);
|
||||
@@ -0,0 +1,14 @@
|
||||
import { BlockRegistry, EverythingRegistry } from "$/common/everything_registry.ts";
|
||||
import { register_block_item } from "$/common/utils.ts";
|
||||
|
||||
const block = EverythingRegistry.register<BlockRegistry>("blocks", "bworld:iron_ore", {
|
||||
id: "bworld:iron_ore",
|
||||
textures: "bworld:stone_iron",
|
||||
has_collision: true,
|
||||
drop_table: "bworld:iron_ore",
|
||||
toughness: 5,
|
||||
requires_tool: true,
|
||||
tool_to_break: "pickaxe",
|
||||
});
|
||||
|
||||
register_block_item(block);
|
||||
@@ -0,0 +1,14 @@
|
||||
import { BlockRegistry, EverythingRegistry } from "$/common/everything_registry.ts";
|
||||
import { register_block_item } from "$/common/utils.ts";
|
||||
|
||||
const block = EverythingRegistry.register<BlockRegistry>("blocks", "bworld:leaves", {
|
||||
id: "bworld:leaves",
|
||||
textures: "bworld:leaves",
|
||||
has_collision: true,
|
||||
transparent: true,
|
||||
toughness: 3,
|
||||
requires_tool: false,
|
||||
tool_to_break: "hoe",
|
||||
});
|
||||
|
||||
register_block_item(block);
|
||||
@@ -0,0 +1,14 @@
|
||||
import { BlockRegistry, EverythingRegistry } from "$/common/everything_registry.ts";
|
||||
import { register_block_item } from "$/common/utils.ts";
|
||||
|
||||
const block = EverythingRegistry.register<BlockRegistry>("blocks", "bworld:log", {
|
||||
id: "bworld:log",
|
||||
textures: { side: "bworld:log_side", top: "bworld:log_top", bottom: "bworld:log_top" },
|
||||
has_collision: true,
|
||||
drop_table: "bworld:log",
|
||||
toughness: 3,
|
||||
requires_tool: false,
|
||||
tool_to_break: "axe",
|
||||
});
|
||||
|
||||
register_block_item(block);
|
||||
@@ -0,0 +1,19 @@
|
||||
import "./grass.ts";
|
||||
import "./dirt.ts";
|
||||
import "./crops.ts";
|
||||
import "./water.ts";
|
||||
import "./chest.ts";
|
||||
import "./furnace.ts";
|
||||
import "./stone.ts";
|
||||
import "./log.ts";
|
||||
import "./sand.ts";
|
||||
import "./snow.ts";
|
||||
import "./glass.ts";
|
||||
import "./hoed_dirt.ts";
|
||||
import "./leaves.ts";
|
||||
import "./coal_ore.ts";
|
||||
import "./copper_ore.ts";
|
||||
import "./iron_ore.ts";
|
||||
import "./tin_ore.ts";
|
||||
import "./gold_ore.ts";
|
||||
import "./planks.ts";
|
||||
@@ -0,0 +1,14 @@
|
||||
import { BlockRegistry, EverythingRegistry } from "$/common/everything_registry.ts";
|
||||
import { register_block_item } from "$/common/utils.ts";
|
||||
|
||||
const block = EverythingRegistry.register<BlockRegistry>("blocks", "bworld:planks", {
|
||||
id: "bworld:planks",
|
||||
textures: "bworld:planks",
|
||||
has_collision: true,
|
||||
drop_table: "bworld:log",
|
||||
toughness: 3,
|
||||
requires_tool: false,
|
||||
tool_to_break: "axe",
|
||||
});
|
||||
|
||||
register_block_item(block);
|
||||
@@ -0,0 +1,14 @@
|
||||
import { BlockRegistry, EverythingRegistry } from "$/common/everything_registry.ts";
|
||||
import { register_block_item } from "$/common/utils.ts";
|
||||
|
||||
const block = EverythingRegistry.register<BlockRegistry>("blocks", "bworld:sand", {
|
||||
id: "bworld:sand",
|
||||
textures: "bworld:sand",
|
||||
has_collision: true,
|
||||
drop_table: "bworld:sand",
|
||||
toughness: 3,
|
||||
requires_tool: false,
|
||||
tool_to_break: "shovel",
|
||||
});
|
||||
|
||||
register_block_item(block);
|
||||
@@ -0,0 +1,13 @@
|
||||
import { BlockRegistry, EverythingRegistry } from "$/common/everything_registry.ts";
|
||||
import { register_block_item } from "$/common/utils.ts";
|
||||
|
||||
const block = EverythingRegistry.register<BlockRegistry>("blocks", "bworld:snow", {
|
||||
id: "bworld:snow",
|
||||
textures: "bworld:snow",
|
||||
has_collision: true,
|
||||
toughness: 2,
|
||||
requires_tool: true,
|
||||
tool_to_break: "shovel",
|
||||
});
|
||||
|
||||
register_block_item(block);
|
||||
@@ -0,0 +1,14 @@
|
||||
import { BlockRegistry, EverythingRegistry } from "$/common/everything_registry.ts";
|
||||
import { register_block_item } from "$/common/utils.ts";
|
||||
|
||||
const block = EverythingRegistry.register<BlockRegistry>("blocks", "bworld:stone", {
|
||||
id: "bworld:stone",
|
||||
textures: "bworld:stone",
|
||||
has_collision: true,
|
||||
drop_table: "bworld:stone",
|
||||
toughness: 3,
|
||||
requires_tool: true,
|
||||
tool_to_break: "pickaxe",
|
||||
});
|
||||
|
||||
register_block_item(block);
|
||||
@@ -0,0 +1,14 @@
|
||||
import { BlockRegistry, EverythingRegistry } from "$/common/everything_registry.ts";
|
||||
import { register_block_item } from "$/common/utils.ts";
|
||||
|
||||
const block = EverythingRegistry.register<BlockRegistry>("blocks", "bworld:tin_ore", {
|
||||
id: "bworld:tin_ore",
|
||||
textures: "bworld:stone_tin",
|
||||
has_collision: true,
|
||||
drop_table: "bworld:tin_ore",
|
||||
toughness: 5,
|
||||
requires_tool: true,
|
||||
tool_to_break: "pickaxe",
|
||||
});
|
||||
|
||||
register_block_item(block);
|
||||
@@ -0,0 +1,9 @@
|
||||
import { BlockRegistry, EverythingRegistry } from "$/common/everything_registry.ts";
|
||||
|
||||
EverythingRegistry.register<BlockRegistry>("blocks", "bworld:water", {
|
||||
id: "bworld:water",
|
||||
textures: "bworld:water",
|
||||
has_collision: false,
|
||||
transparent: true,
|
||||
alpha: 0.8,
|
||||
});
|
||||
Reference in New Issue
Block a user