From 278c90f5f969261345ca513f77223d601292b697 Mon Sep 17 00:00:00 2001 From: Holly Date: Sat, 11 Nov 2023 00:14:27 +0000 Subject: [PATCH] Make tall grass not drop --- server/MPClient.ts | 9 ++++++--- server/blocks/Block.ts | 8 +++++--- server/blocks/BlockBehaviourTallGrass.ts | 21 +++++++++++++++++++++ 3 files changed, 32 insertions(+), 6 deletions(-) create mode 100644 server/blocks/BlockBehaviourTallGrass.ts diff --git a/server/MPClient.ts b/server/MPClient.ts index 92e8ca7..80ccebf 100644 --- a/server/MPClient.ts +++ b/server/MPClient.ts @@ -161,9 +161,12 @@ export class MPClient { this.entity.world.setBlockWithNotify(this.diggingAt.x, this.diggingAt.y, this.diggingAt.z, 0); this.inventory.addItemStack(new ItemStack(Block.blockBehaviours[brokenBlockId].droppedItem(brokenBlockId), 1, metadata)); this.send(new PacketWindowItems(0, this.inventory.getInventorySize(), this.inventory.constructInventoryPayload()).writeData()); - /*const itemEntity = new EntityItem(this.entity.world, new ItemStack(Block.blockBehaviours[brokenBlockId].droppedItem(brokenBlockId), 1, metadata)); - itemEntity.position.set(x + 0.5, y + 0.5, z + 0.5); - this.entity.world.addEntity(itemEntity);*/ + /*const itemId = Block.blockBehaviours[brokenBlockId].droppedItem(brokenBlockId); + if (itemId !== -1) { + const itemEntity = new EntityItem(this.entity.world, new ItemStack(itemId, 1, metadata)); + itemEntity.position.set(x + 0.5, y + 0.5, z + 0.5); + this.entity.world.addEntity(itemEntity); + }*/ } // TODO: Cap how far away a player is able to break blocks diff --git a/server/blocks/Block.ts b/server/blocks/Block.ts index 34787fb..656a2e4 100644 --- a/server/blocks/Block.ts +++ b/server/blocks/Block.ts @@ -4,6 +4,7 @@ import { BlockBehaviour } from "./BlockBehaviour"; import { BlockBehaviourFlower } from "./BlockBehaviourFlower"; import { BlockBehaviourGrass } from "./BlockBehaviourGrass"; import { BlockBehaviourStone } from "./BlockBehaviourStone"; +import { BlockBehaviourTallGrass } from "./BlockBehaviourTallGrass"; import { IBlockBehaviour } from "./IBlockBehaviour"; abstract class Behaviour { @@ -12,6 +13,7 @@ abstract class Behaviour { public static stone = new BlockBehaviourStone(); public static grass = new BlockBehaviourGrass(); + public static tallGrass = new BlockBehaviourTallGrass(); public static flower = new BlockBehaviourFlower(); } @@ -142,10 +144,10 @@ export class Block { static readonly glass = new Block(20).setHardness(0.3).setLightPassage(255).setBlockName("Glass"); - static readonly tallGrass = new Block(31).setHardness(0).setLightPassage(255).setBehaviour(Behaviour.flower).setBlockName("Tall Grass"); + static readonly tallGrass = new Block(31).setHardness(0).setLightPassage(255).setBehaviour(Behaviour.tallGrass).setBlockName("Tall Grass"); - static readonly flowerDandelion = new Block(37).setHardness(0).setLightPassage(255).setBlockName("Dandelion"); - static readonly flowerRose = new Block(38).setHardness(0).setLightPassage(255).setBlockName("Rose"); + static readonly flowerDandelion = new Block(37).setHardness(0).setLightPassage(255).setBehaviour(Behaviour.flower).setBlockName("Dandelion"); + static readonly flowerRose = new Block(38).setHardness(0).setLightPassage(255).setBehaviour(Behaviour.flower).setBlockName("Rose"); static readonly clay = new Block(82).setHardness(0.6).setBlockName("Clay"); diff --git a/server/blocks/BlockBehaviourTallGrass.ts b/server/blocks/BlockBehaviourTallGrass.ts new file mode 100644 index 0000000..4c0d6c5 --- /dev/null +++ b/server/blocks/BlockBehaviourTallGrass.ts @@ -0,0 +1,21 @@ +import AABB from "../AABB"; +import { World } from "../World"; +import { Block } from "./Block"; +import { BlockBehaviour } from "./BlockBehaviour"; + +export class BlockBehaviourTallGrass extends BlockBehaviour { + public neighborBlockChange(world:World, x:number, y:number, z:number, blockId:number) { + const block = world.getBlockId(x, y - 1, z); + if (block !== Block.grass.blockId && block !== Block.dirt.blockId) { + world.setBlockWithNotify(x, y, z, 0); + } + } + + public droppedItem(blockId:number) { + return -1; + } + + public getBoundingBox() { + return AABB.getAABB(0, 0, 0, 0, 0, 0); + } +} \ No newline at end of file