make sugarcane break when no block under them

This commit is contained in:
Holly Stubbs 2024-10-17 21:20:47 +01:00
parent db9847634e
commit a6da71e6a2
Signed by: tgpholly
GPG key ID: B8583C4B7D18119E
2 changed files with 20 additions and 1 deletions

View file

@ -1,6 +1,7 @@
import AABB from "../AABB"; import AABB from "../AABB";
import { World } from "../World"; import { World } from "../World";
import { BlockBehaviourSapling } from "./BlockBehaviorSapling"; import { BlockBehaviourSapling } from "./BlockBehaviorSapling";
import { BlockBehaviourSugarcane } from "./BlockBehaviorSugarcane";
import { BlockBehaviour } from "./BlockBehaviour"; import { BlockBehaviour } from "./BlockBehaviour";
import { BlockBehaviourClay } from "./BlockBehaviourClay"; import { BlockBehaviourClay } from "./BlockBehaviourClay";
import { BlockBehaviourFlower } from "./BlockBehaviourFlower"; import { BlockBehaviourFlower } from "./BlockBehaviourFlower";
@ -25,6 +26,7 @@ abstract class Behaviour {
public static redstoneOre = new BlockBehaviourRedstoneOre(); public static redstoneOre = new BlockBehaviourRedstoneOre();
public static clay = new BlockBehaviourClay(); public static clay = new BlockBehaviourClay();
public static sugarcane = new BlockBehaviourSugarcane();
} }
export class Block { 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 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 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 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 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 fence = new Block(85).setHardness(2).setBlockName("Fence"); // TODO: Behavior script
static readonly pumpkin = new Block(86).setHardness(1).setBlockName("Pumpkin"); static readonly pumpkin = new Block(86).setHardness(1).setBlockName("Pumpkin");

View file

@ -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);
}
}