Move effects into the modding api
This commit is contained in:
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"format_version": 1,
|
||||
"effect": {
|
||||
"id": "bworld:instant_health",
|
||||
"category": "beneficial",
|
||||
"instant": true,
|
||||
"components": { "bworld:heal": { "amount": 4 } }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"format_version": 1,
|
||||
"effect": {
|
||||
"id": "bworld:poison",
|
||||
"category": "harmful",
|
||||
"components": { "bworld:poison": { "every": 25 } }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"format_version": 1,
|
||||
"effect": {
|
||||
"id": "bworld:regeneration",
|
||||
"category": "beneficial",
|
||||
"components": { "bworld:heal_over_time": { "every": 50 } }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"format_version": 1,
|
||||
"effect": {
|
||||
"id": "bworld:resistance",
|
||||
"category": "beneficial"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"format_version": 1,
|
||||
"effect": {
|
||||
"id": "bworld:slowness",
|
||||
"category": "harmful",
|
||||
"modifiers": [{ "attribute": "bworld:movement_speed", "amount": -0.15, "operation": "add_multiplied_total" }]
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"format_version": 1,
|
||||
"effect": {
|
||||
"id": "bworld:speed",
|
||||
"category": "beneficial",
|
||||
"modifiers": [{ "attribute": "bworld:movement_speed", "amount": 0.2, "operation": "add_multiplied_total" }]
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"format_version": 1,
|
||||
"effect": {
|
||||
"id": "bworld:water_breathing",
|
||||
"category": "beneficial"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
// what the base game's effects do over time, see mods/bworld/effects. speed and slowness are only attribute
|
||||
// modifiers, and resistance and water breathing work where damage and air happen, like minecraft's
|
||||
import type { ServerContext } from "bworld/server";
|
||||
|
||||
// every n ticks, n halving with each level: minecraft's regeneration and poison
|
||||
function every(ticks: number, amplifier: number, n: number) {
|
||||
const interval = n >> amplifier;
|
||||
return interval > 0 ? ticks % interval === 0 : true;
|
||||
}
|
||||
|
||||
export function register_effects(ctx: ServerContext) {
|
||||
ctx.components.register_effect<{ every: number }>("bworld:heal_over_time", {
|
||||
should_tick: (ticks, amplifier, params) => every(ticks, amplifier, params.every),
|
||||
on_tick(entity) {
|
||||
if (entity.health < entity.max_health) entity.heal(1);
|
||||
},
|
||||
});
|
||||
ctx.components.register_effect<{ every: number }>("bworld:poison", {
|
||||
should_tick: (ticks, amplifier, params) => every(ticks, amplifier, params.every),
|
||||
on_tick(entity) {
|
||||
// never kills
|
||||
if (entity.health > 1) entity.damage(1, "magic");
|
||||
},
|
||||
});
|
||||
// instant: amount for level 1, doubling with each level
|
||||
ctx.components.register_effect<{ amount: number }>("bworld:heal", {
|
||||
on_tick(entity, amplifier, params) {
|
||||
entity.heal(Math.max(params.amount << amplifier, 0));
|
||||
},
|
||||
});
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
// the base game's block and item behavior, written against the same api as any other mod
|
||||
import type { BlockRef, Container, EntityRef, Player, ServerContext } from "bworld/server";
|
||||
import { register_curios } from "./curios.ts";
|
||||
import { register_effects } from "./effects.ts";
|
||||
|
||||
export function setup(ctx: ServerContext) {
|
||||
register_hoeable(ctx);
|
||||
@@ -10,6 +11,7 @@ export function setup(ctx: ServerContext) {
|
||||
register_farming(ctx);
|
||||
register_fishing(ctx);
|
||||
register_curios(ctx);
|
||||
register_effects(ctx);
|
||||
}
|
||||
|
||||
// right clicking with a type of tool turns the block into another, like any hoe on grass
|
||||
|
||||
Reference in New Issue
Block a user