From a6da71e6a26ed1c3017301377d995bbe0b8562a2 Mon Sep 17 00:00:00 2001 From: Holly Date: Thu, 17 Oct 2024 21:20:47 +0100 Subject: [PATCH] make sugarcane break when no block under them --- server/blocks/Block.ts | 4 +++- server/blocks/BlockBehaviorSugarcane.ts | 17 +++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 server/blocks/BlockBehaviorSugarcane.ts diff --git a/server/blocks/Block.ts b/server/blocks/Block.ts index 3d43e91..9e30397 100644 --- a/server/blocks/Block.ts +++ b/server/blocks/Block.ts @@ -1,6 +1,7 @@ import AABB from "../AABB"; import { World } from "../World"; import { BlockBehaviourSapling } from "./BlockBehaviorSapling"; +import { BlockBehaviourSugarcane } from "./BlockBehaviorSugarcane"; import { BlockBehaviour } from "./BlockBehaviour"; import { BlockBehaviourClay } from "./BlockBehaviourClay"; import { BlockBehaviourFlower } from "./BlockBehaviourFlower"; @@ -25,6 +26,7 @@ abstract class Behaviour { public static redstoneOre = new BlockBehaviourRedstoneOre(); public static clay = new BlockBehaviourClay(); + public static sugarcane = new BlockBehaviourSugarcane(); } export class Block { @@ -236,7 +238,7 @@ export class Block { static readonly snowBlock = new Block(80).setHardness(0.2).setBlockName("Snow"); // TODO: Behavior script static readonly cactus = new Block(81).setHardness(0.4).setBlockName("Cactus"); // TODO: Behavior script static readonly clay = new Block(82).setHardness(0.6).setBehaviour(Behaviour.clay).setBlockName("Clay"); - static readonly sugarcane = new Block(83).setHardness(0).setLightPassage(255).setBlockName("Sugar Cane"); // TODO: Behavior script + static readonly sugarcane = new Block(83).setHardness(0).setLightPassage(255).setBehaviour(Behaviour.sugarcane).setBlockName("Sugar Cane"); // TODO: Behavior script static readonly jukebox = new Block(84).setHardness(2).setBlockName("Jukebox"); // TODO: Behavior script static readonly fence = new Block(85).setHardness(2).setBlockName("Fence"); // TODO: Behavior script static readonly pumpkin = new Block(86).setHardness(1).setBlockName("Pumpkin"); diff --git a/server/blocks/BlockBehaviorSugarcane.ts b/server/blocks/BlockBehaviorSugarcane.ts new file mode 100644 index 0000000..36b0b81 --- /dev/null +++ b/server/blocks/BlockBehaviorSugarcane.ts @@ -0,0 +1,17 @@ +import AABB from "../AABB"; +import { World } from "../World"; +import { Block } from "./Block"; +import { BlockBehaviour } from "./BlockBehaviour"; + +export class BlockBehaviourSugarcane extends BlockBehaviour { + public neighborBlockChange(world:World, x:number, y:number, z:number, blockId:number) { + const block = world.getBlockId(x, y - 1, z); + if (block === 0 || block !== Block.sugarcane.blockId) { + world.setBlockWithNotify(x, y, z, 0); + } + } + + public getBoundingBox() { + return AABB.getAABB(0, 0, 0, 0, 0, 0); + } +} \ No newline at end of file