Water wheel and creative motor

This commit is contained in:
2026-10-28 21:40:39 -03:00
parent 507e9aab24
commit 872db88066
9 changed files with 325 additions and 35 deletions
+33 -10
View File
@@ -62,10 +62,18 @@ export function setup(ctx: SharedContext) {
return other.cog === "small" && cog === "small";
});
// a block with a facing faces away from the axle beside it, or toward the player, or away from them while
// sneaking, like DirectionalKineticBlock. one with its axle only in front faces the axle instead, like
// CreativeMotorBlock
const facing_for = (placement: BlockPlacement, shaft: KineticParams["shaft"]): Face => {
const side = axle_beside(placement.x, placement.y, placement.z);
if (side && !placement.sneaking) return shaft === "front" ? side : OPPOSITE[side];
return placement.sneaking ? placement.looking : OPPOSITE[placement.looking];
};
// a block with an axis lines up with the axle it's placed against, or sneaking, with the face it's clicked onto.
// otherwise it points the way the player looks, like RotatedPillarKineticBlock. a block with a facing faces away
// from the axle, or toward the player, or away from them while sneaking, like DirectionalKineticBlock. cogs are
// placed their own way, see cog_axis
// otherwise it points the way the player looks, like RotatedPillarKineticBlock. a block with a facing faces as
// facing_for says. cogs are placed their own way, see cog_axis
ctx.components.register_block<KineticParams>("create:kinetic", {
state_for_placement(placement, params) {
if (params.cog) {
@@ -78,15 +86,10 @@ export function setup(ctx: SharedContext) {
const side = axle_beside(placement.x, placement.y, placement.z, FACINGS.slice(0, 4));
return { [params.facing]: FACINGS.indexOf(side ?? OPPOSITE[placement.facing]) };
}
const side = axle_beside(placement.x, placement.y, placement.z);
if (params.facing !== undefined) {
const facing = side && !placement.sneaking
? OPPOSITE[side]
: placement.sneaking
? placement.looking
: OPPOSITE[placement.looking];
return { [params.facing]: FACINGS.indexOf(facing) };
return { [params.facing]: FACINGS.indexOf(facing_for(placement, params.shaft)) };
}
const side = axle_beside(placement.x, placement.y, placement.z);
const axis = side && !placement.sneaking
? face_axis(side)
: side
@@ -96,6 +99,26 @@ export function setup(ctx: SharedContext) {
},
});
// a wheel's paddles would cut into a wheel beside it, unless that one is on the same axis and beside it along that
// axis, like WaterWheelBlock.canSurvive
const wheel_at = (x: number, y: number, z: number) => {
const id = ctx.world.get_block(x, y, z);
return id !== undefined && ctx.blocks.exists(id) &&
ctx.blocks.components(id)["create:water_wheel"] !== undefined;
};
ctx.components.register_block("create:water_wheel", {
state_for_placement(placement) {
const { x, y, z } = placement;
const axis = face_axis(facing_for(placement, "both"));
const fits = FACINGS.every((side) => {
const [dx, dy, dz] = FACE_OFFSETS[side];
if (!wheel_at(x + dx, y + dy, z + dz)) return true;
return face_axis(side) === axis && beside(x, y, z, side)?.axis === axis;
});
if (!fits) return false;
},
});
// a crank faces away from what it's placed on, unless there's an axle beside it to turn, like HandCrankBlock
ctx.components.register_block("create:hand_crank", {
state_for_placement(placement) {