Single module modding
This commit is contained in:
@@ -48,8 +48,8 @@ a tank.
|
||||
|
||||
## Rules
|
||||
|
||||
A fluid's name, color and value can depend on its data. The mod's [shared script](../concepts/sides.md#shared-scripts)
|
||||
gives one of its fluids rules for that, like NeoForge's `FluidType.getDescription` and `FluidTintSource.colorAsStack`:
|
||||
A fluid's name, color and value can depend on its data. The mod's [shared phase](../concepts/sides.md#shared) gives one
|
||||
of its fluids rules for that, like NeoForge's `FluidType.getDescription` and `FluidTintSource.colorAsStack`:
|
||||
|
||||
```ts
|
||||
import type { SharedContext } from "cubi/shared";
|
||||
@@ -58,7 +58,7 @@ interface SyrupData {
|
||||
tree?: string;
|
||||
}
|
||||
|
||||
export function setup(ctx: SharedContext) {
|
||||
export function shared(ctx: SharedContext) {
|
||||
ctx.fluids.register("copper_tools:syrup", {
|
||||
name(data) {
|
||||
const { tree } = (data ?? {}) as SyrupData;
|
||||
@@ -86,15 +86,15 @@ export function setup(ctx: SharedContext) {
|
||||
|
||||
`data` is the variant's, `undefined` when it has none, and mustn't be changed. A rule that throws, or returns something
|
||||
that isn't a name, a color or a value, is logged and the JSON's is used. A fluid has one set of rules, from its own mod,
|
||||
and they can only be registered during `setup`.
|
||||
and they can only be registered while the shared phase runs.
|
||||
|
||||
The rules are in the shared script because both sides need them: the server for tooltips, and clients to draw the fluid.
|
||||
Shared scripts have `ctx.items.exists(id)`, `ctx.items.name(id)`, `ctx.items.components(id)` and
|
||||
The rules are in the shared phase because both sides need them: the server for tooltips, and clients to draw the fluid.
|
||||
The shared phase has `ctx.items.exists(id)`, `ctx.items.name(id)`, `ctx.items.components(id)` and
|
||||
`ctx.items.sell_value(id, data?)` for rules that read an item, like syrup named after its tree.
|
||||
|
||||
## Using Fluids
|
||||
|
||||
Server and client scripts have `ctx.fluids`, which goes through the rules:
|
||||
Server and client phases have `ctx.fluids`, which goes through the rules:
|
||||
|
||||
```ts
|
||||
const birch = { id: "copper_tools:syrup", data: { tree: "bworld:birch_log" } };
|
||||
@@ -106,10 +106,10 @@ ctx.fluids.same(birch, { id: "copper_tools:syrup" }); // false, the data is diff
|
||||
```
|
||||
|
||||
`ids` gives each fluid once, without data, so a fluid that's many things by its data, like syrup from each tree, is only
|
||||
there as plain `copper_tools:syrup`. Client scripts also have `ctx.fluids.mod(id)`, the name of the mod that added it,
|
||||
there as plain `copper_tools:syrup`. The client phase also has `ctx.fluids.mod(id)`, the name of the mod that added it,
|
||||
like `ctx.items.mod`.
|
||||
|
||||
Shared scripts have `ctx.fluids.exists` and `ctx.fluids.same` too, which don't depend on rules, like a
|
||||
The shared phase has `ctx.fluids.exists` and `ctx.fluids.same` too, which don't depend on rules, like a
|
||||
[recipe type](recipes.md#custom-recipe-types) that's found by a fluid.
|
||||
|
||||
## Containers
|
||||
@@ -146,11 +146,11 @@ tooltip says what's in it and how much, like "Birch Log Syrup, 250 mB".
|
||||
|
||||
A full one sells for its own `base_sell_value` and what its fluid is worth on top: the fluid's value for 1000 mB times
|
||||
how much it holds, rounded up to a whole number. A jar of maple syrup worth 40 a bucket sells for 10, and the jar's own
|
||||
value when it has one. It can't be sold if neither has a value. Server scripts get this from
|
||||
`ctx.items.sell_value(id, data)`, which the base game's shipping bin sells by. Client and shared scripts have it too,
|
||||
and the base game shows it in [tooltips](../gui/index.md#item-tooltips).
|
||||
value when it has one. It can't be sold if neither has a value. The server phase gets this from
|
||||
`ctx.items.sell_value(id, data)`, which the base game's shipping bin sells by. Client and shared phases have it too, and
|
||||
the base game shows it in [tooltips](../gui/index.md#item-tooltips).
|
||||
|
||||
A server script fills and empties one through its [fluid handler](#fluid-handlers), and `ctx.items.fluid_capacity(id)`
|
||||
The server phase fills and empties one through its [fluid handler](#fluid-handlers), and `ctx.items.fluid_capacity(id)`
|
||||
says how much one holds.
|
||||
|
||||
## Fluid Handlers
|
||||
|
||||
Reference in New Issue
Block a user