Register items for blocks
This commit is contained in:
@@ -8,11 +8,12 @@ interface TileChestData {
|
||||
}
|
||||
|
||||
EverythingRegistry.register<BlockRegistry<TileChestData>>("blocks", "bworld:chest", {
|
||||
id: "bworld:chest",
|
||||
textures: "bworld:chest",
|
||||
has_collision: false,
|
||||
|
||||
on_interact(world, tile) {
|
||||
const [player] = world.get_tag("player")!;
|
||||
on_interact(dimension, tile) {
|
||||
const [player] = dimension.world.get_tag("player")!;
|
||||
const player_component = player.get(PlayerComponent)!;
|
||||
if (tile.data && tile.data.inventory) {
|
||||
player_component.screens.push(new GuiChest(tile.data.inventory, player_component.player_inventory));
|
||||
|
||||
+4
-81
@@ -1,8 +1,9 @@
|
||||
import { BlockRegistry, EverythingRegistry } from "$/common/everything_registry.ts";
|
||||
import { WateringCanData } from "../items/watering_can.ts";
|
||||
import { register_block_item } from "$/common/utils.ts";
|
||||
import { PlayerComponent } from "../player.ts";
|
||||
|
||||
EverythingRegistry.register<BlockRegistry>("blocks", "bworld:dirt", {
|
||||
const block = EverythingRegistry.register<BlockRegistry>("blocks", "bworld:dirt", {
|
||||
id: "bworld:dirt",
|
||||
textures: "bworld:dirt",
|
||||
has_collision: false,
|
||||
drop_table: "bworld:dirt",
|
||||
@@ -17,82 +18,4 @@ EverythingRegistry.register<BlockRegistry>("blocks", "bworld:dirt", {
|
||||
},
|
||||
});
|
||||
|
||||
EverythingRegistry.register<BlockRegistry>("blocks", "bworld:hoed_dirt", {
|
||||
textures: { side: "bworld:dirt", top: "bworld:hoed_dirt", bottom: "bworld:dirt" },
|
||||
has_collision: false,
|
||||
drop_table: "bworld:dirt",
|
||||
|
||||
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") {
|
||||
tile.id = "bworld:dirt";
|
||||
}
|
||||
},
|
||||
on_interact(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:watering_can") {
|
||||
const data = item.data as WateringCanData;
|
||||
if (data.water > 0) {
|
||||
tile.id = "bworld:hoed_watered_dirt";
|
||||
data.water -= 1;
|
||||
}
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
EverythingRegistry.register<BlockRegistry>("blocks", "bworld:hoed_watered_dirt", {
|
||||
textures: "bworld:hoed_watered_dirt",
|
||||
has_collision: false,
|
||||
drop_table: "bworld:dirt",
|
||||
|
||||
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") {
|
||||
tile.id = "bworld:dirt";
|
||||
}
|
||||
},
|
||||
on_interact(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:tomato_seeds") {
|
||||
world.dimension.add_block(world, { x: tile.x, y: tile.y, id: "bworld:tomato_crop", tickable: true });
|
||||
item.amount -= 1;
|
||||
player_inventory.container.set_item(player_inventory.hotbar_selected, item);
|
||||
} else if (item.type_id === "bworld:potato_seeds") {
|
||||
world.dimension.add_block(world, { x: tile.x, y: tile.y, id: "bworld:potato_crop", tickable: true });
|
||||
item.amount -= 1;
|
||||
player_inventory.container.set_item(player_inventory.hotbar_selected, item);
|
||||
} else if (item.type_id === "bworld:pumpkin_seeds") {
|
||||
world.dimension.add_block(world, { x: tile.x, y: tile.y, id: "bworld:pumpkin_crop", tickable: true });
|
||||
item.amount -= 1;
|
||||
player_inventory.container.set_item(player_inventory.hotbar_selected, item);
|
||||
} else if (item.type_id === "bworld:carrot_seeds") {
|
||||
world.dimension.add_block(world, { x: tile.x, y: tile.y, id: "bworld:carrot_crop", tickable: true });
|
||||
item.amount -= 1;
|
||||
player_inventory.container.set_item(player_inventory.hotbar_selected, item);
|
||||
}
|
||||
},
|
||||
});
|
||||
register_block_item(block);
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
import { BlockRegistry, EverythingRegistry } from "$/common/everything_registry.ts";
|
||||
import { register_block_item } from "$/common/utils.ts";
|
||||
|
||||
EverythingRegistry.register<BlockRegistry>("blocks", "bworld:glass", {
|
||||
const block = EverythingRegistry.register<BlockRegistry>("blocks", "bworld:glass", {
|
||||
textures: "bworld:glass",
|
||||
has_collision: true,
|
||||
transparent: true,
|
||||
});
|
||||
|
||||
register_block_item(block);
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
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",
|
||||
});
|
||||
|
||||
register_block_item(block);
|
||||
@@ -0,0 +1,11 @@
|
||||
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,
|
||||
});
|
||||
|
||||
register_block_item(block);
|
||||
@@ -1,13 +1,11 @@
|
||||
import { BlockRegistry, EverythingRegistry } from "$/common/everything_registry.ts";
|
||||
import { register_block_item } from "$/common/utils.ts";
|
||||
|
||||
EverythingRegistry.register<BlockRegistry>("blocks", "bworld:log", {
|
||||
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",
|
||||
});
|
||||
|
||||
EverythingRegistry.register<BlockRegistry>("blocks", "bworld:leaves", {
|
||||
textures: "bworld:leaves",
|
||||
has_collision: true,
|
||||
transparent: true,
|
||||
});
|
||||
register_block_item(block);
|
||||
|
||||
@@ -9,3 +9,5 @@ import "./log.ts";
|
||||
import "./sand.ts";
|
||||
import "./snow.ts";
|
||||
import "./glass.ts";
|
||||
import "./hoed_dirt.ts";
|
||||
import "./leaves.ts";
|
||||
|
||||
@@ -1,7 +1,11 @@
|
||||
import { BlockRegistry, EverythingRegistry } from "$/common/everything_registry.ts";
|
||||
import { register_block_item } from "../../common/utils.ts";
|
||||
|
||||
EverythingRegistry.register<BlockRegistry>("blocks", "bworld:sand", {
|
||||
const block = EverythingRegistry.register<BlockRegistry>("blocks", "bworld:sand", {
|
||||
id: "bworld:sand",
|
||||
textures: "bworld:sand",
|
||||
has_collision: true,
|
||||
drop_table: "bworld:sand",
|
||||
});
|
||||
|
||||
register_block_item(block);
|
||||
|
||||
@@ -1,6 +1,10 @@
|
||||
import { BlockRegistry, EverythingRegistry } from "$/common/everything_registry.ts";
|
||||
import { register_block_item } from "$/common/utils.ts";
|
||||
|
||||
EverythingRegistry.register<BlockRegistry>("blocks", "bworld:snow", {
|
||||
const block = EverythingRegistry.register<BlockRegistry>("blocks", "bworld:snow", {
|
||||
id: "bworld:snow",
|
||||
textures: "bworld:snow",
|
||||
has_collision: true,
|
||||
});
|
||||
|
||||
register_block_item(block);
|
||||
|
||||
@@ -1,7 +1,11 @@
|
||||
import { BlockRegistry, EverythingRegistry } from "$/common/everything_registry.ts";
|
||||
import { register_block_item } from "$/common/utils.ts";
|
||||
|
||||
EverythingRegistry.register<BlockRegistry>("blocks", "bworld:stone", {
|
||||
const block = EverythingRegistry.register<BlockRegistry>("blocks", "bworld:stone", {
|
||||
id: "bworld:stone",
|
||||
textures: "bworld:stone",
|
||||
has_collision: true,
|
||||
drop_table: "bworld:stone",
|
||||
});
|
||||
|
||||
register_block_item(block);
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
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,
|
||||
|
||||
@@ -1,5 +0,0 @@
|
||||
import { EverythingRegistry, ItemRegistry } from "$/common/everything_registry.ts";
|
||||
|
||||
EverythingRegistry.register<ItemRegistry>("items", "bworld:dirt", {
|
||||
texture_id: "bworld:dirt",
|
||||
});
|
||||
@@ -1,2 +1 @@
|
||||
import "./watering_can.ts";
|
||||
import "./dirt.ts";
|
||||
|
||||
Reference in New Issue
Block a user