Make tall grass not drop

This commit is contained in:
Holly Stubbs 2023-11-11 00:14:27 +00:00
parent 604bec9e89
commit 278c90f5f9
Signed by: tgpholly
GPG key ID: B8583C4B7D18119E
3 changed files with 32 additions and 6 deletions

View file

@ -161,9 +161,12 @@ export class MPClient {
this.entity.world.setBlockWithNotify(this.diggingAt.x, this.diggingAt.y, this.diggingAt.z, 0); 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.inventory.addItemStack(new ItemStack(Block.blockBehaviours[brokenBlockId].droppedItem(brokenBlockId), 1, metadata));
this.send(new PacketWindowItems(0, this.inventory.getInventorySize(), this.inventory.constructInventoryPayload()).writeData()); 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)); /*const itemId = Block.blockBehaviours[brokenBlockId].droppedItem(brokenBlockId);
itemEntity.position.set(x + 0.5, y + 0.5, z + 0.5); if (itemId !== -1) {
this.entity.world.addEntity(itemEntity);*/ 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 // TODO: Cap how far away a player is able to break blocks

View file

@ -4,6 +4,7 @@ import { BlockBehaviour } from "./BlockBehaviour";
import { BlockBehaviourFlower } from "./BlockBehaviourFlower"; import { BlockBehaviourFlower } from "./BlockBehaviourFlower";
import { BlockBehaviourGrass } from "./BlockBehaviourGrass"; import { BlockBehaviourGrass } from "./BlockBehaviourGrass";
import { BlockBehaviourStone } from "./BlockBehaviourStone"; import { BlockBehaviourStone } from "./BlockBehaviourStone";
import { BlockBehaviourTallGrass } from "./BlockBehaviourTallGrass";
import { IBlockBehaviour } from "./IBlockBehaviour"; import { IBlockBehaviour } from "./IBlockBehaviour";
abstract class Behaviour { abstract class Behaviour {
@ -12,6 +13,7 @@ abstract class Behaviour {
public static stone = new BlockBehaviourStone(); public static stone = new BlockBehaviourStone();
public static grass = new BlockBehaviourGrass(); public static grass = new BlockBehaviourGrass();
public static tallGrass = new BlockBehaviourTallGrass();
public static flower = new BlockBehaviourFlower(); 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 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 flowerDandelion = new Block(37).setHardness(0).setLightPassage(255).setBehaviour(Behaviour.flower).setBlockName("Dandelion");
static readonly flowerRose = new Block(38).setHardness(0).setLightPassage(255).setBlockName("Rose"); 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"); static readonly clay = new Block(82).setHardness(0.6).setBlockName("Clay");

View file

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