Add a bunch of crops and farmer's delight crops
This commit is contained in:
+19
-20
@@ -27,7 +27,7 @@ import {
|
||||
import type { ModListing, RecipeBook } from "$/common/mod_loader.ts";
|
||||
import type { WorldgenSetup } from "$/common/generation.ts";
|
||||
import { CYCLE_TICKS, format_clock, time_of_day, TIMES_OF_DAY } from "$/common/time.ts";
|
||||
import { can_stand_on } from "$/common/utils.ts";
|
||||
import { can_place, can_stand_on, placement_target } from "$/common/utils.ts";
|
||||
import { EXHAUSTION, MAX_HEALTH } from "./vitals.ts";
|
||||
import { ModRuntime, run_guarded } from "./mod_runtime.ts";
|
||||
import type { GameLoop } from "./game_loop.ts";
|
||||
@@ -705,15 +705,17 @@ export class GameServer {
|
||||
}
|
||||
}
|
||||
|
||||
// the held item's on_use handlers, returns whether it has any
|
||||
// right click at nothing: eating, or the item's on_use
|
||||
#use_item(player: ServerPlayer): boolean {
|
||||
return this.#eat(player) || this.#use_item_components(player);
|
||||
}
|
||||
|
||||
// the held item's on_use handlers, returns whether it has any
|
||||
#use_item_components(player: ServerPlayer): boolean {
|
||||
const held = player.held_item;
|
||||
if (!held) {
|
||||
return false;
|
||||
}
|
||||
if (this.#eat(player)) {
|
||||
return true;
|
||||
}
|
||||
const components = this.mods.item_components_of(held.type_id).filter(({ component }) => component.on_use);
|
||||
if (components.length === 0) {
|
||||
return false;
|
||||
@@ -727,10 +729,10 @@ export class GameServer {
|
||||
}
|
||||
|
||||
#use_block(player: ServerPlayer, x: number, y: number, z: number, face: Faces) {
|
||||
const offset = FACE_OFFSETS[face];
|
||||
const [tx, ty, tz] = [x + offset.x, y + offset.y, z + offset.z];
|
||||
|
||||
const info = this.world.get_block_info(x, y, z);
|
||||
const target = placement_target(x, y, z, FACE_OFFSETS[face], info);
|
||||
const [tx, ty, tz] = [target.x, target.y, target.z];
|
||||
|
||||
if (!info || !this.#in_reach(player, x, y, z)) {
|
||||
this.#correct(player, x, y, z);
|
||||
this.#correct(player, tx, ty, tz);
|
||||
@@ -763,21 +765,23 @@ export class GameServer {
|
||||
}
|
||||
|
||||
// an item that does something when used does that instead of being placed
|
||||
if (this.#use_item(player)) {
|
||||
if (this.#use_item_components(player)) {
|
||||
this.#correct(player, tx, ty, tz);
|
||||
return;
|
||||
}
|
||||
|
||||
// place the held block against the face
|
||||
// place the held block against the face, or into the clicked block if it's replaceable. food that can be planted,
|
||||
// like a potato on farmland, is planted, and eaten when it can't be
|
||||
const held_slot = player.inventory.get_slot(player.selected_slot);
|
||||
const held = EverythingRegistry.get<ItemRegistry>("items", held_slot.type_id ?? "");
|
||||
if (
|
||||
!held?.block_id || ty < 0 || ty >= CHUNK_HEIGHT || !this.#replaceable(tx, ty, tz) ||
|
||||
!can_stand_on(
|
||||
const placeable = held?.block_id !== undefined && ty >= 0 && ty < CHUNK_HEIGHT &&
|
||||
can_place(
|
||||
EverythingRegistry.get<BlockRegistry>("blocks", held.block_id),
|
||||
this.world.get_block_info(tx, ty, tz),
|
||||
this.world.get_block_id(tx, ty - 1, tz),
|
||||
)
|
||||
) {
|
||||
);
|
||||
if (!placeable || !held?.block_id) {
|
||||
this.#eat(player);
|
||||
this.#correct(player, tx, ty, tz);
|
||||
return;
|
||||
}
|
||||
@@ -1282,11 +1286,6 @@ export class GameServer {
|
||||
this.#send(player, { type: "set_block", x, y, z, id: this.world.get_block_id(x, y, z) });
|
||||
}
|
||||
|
||||
#replaceable(x: number, y: number, z: number) {
|
||||
const nid = this.world.get_block_nid(x, y, z);
|
||||
return nid === AIR || (EverythingRegistry.get_by_id<BlockRegistry>("blocks", nid)?.replaceable ?? false);
|
||||
}
|
||||
|
||||
#in_reach(player: ServerPlayer, x: number, y: number, z: number) {
|
||||
const dx = x + 0.5 - player.x;
|
||||
const dy = y + 0.5 - (player.y + PLAYER_EYE_HEIGHT);
|
||||
|
||||
@@ -345,6 +345,11 @@ export class ModRuntime {
|
||||
game().set_block(x, y, z, id);
|
||||
return true;
|
||||
},
|
||||
break_block: (x, y, z) => {
|
||||
if (game().world.get_block_id(x, y, z) === AIR_ID) return false;
|
||||
game().destroy_block(x, y, z);
|
||||
return true;
|
||||
},
|
||||
get_state: (x, y, z, name) => {
|
||||
const id = game().world.get_block_id(x, y, z);
|
||||
if (id === AIR_ID) return undefined;
|
||||
|
||||
Reference in New Issue
Block a user