#what do i need to remove the drop of a vanilla block?

1 messages · Page 1 of 1 (latest)

crude hollow
#

import { system, world, } from '@minecraft/server'
import { ItemStack } from '@minecraft/server'

world.beforeEvents.playerBreakBlock.subscribe(event => {
console.warn("dirt broken")
const { block, player } = event
const pdim = player.dimension
if (block?.typeId === "minecraft:dirt") {
system.run(() => {
pdim.spawnItem(new ItemStack("minecraft:stone", 1), { x: block.x, y: block.y, z: block.z });

    })
}

})

honest pollen
#
import { system, world, ItemStack } from '@minecraft/server';
#

just a recomendation

#

use 1 import

#

any log?

#

oh nvm

#

u should getEntities

#

and if there's an entity (drop), u remove it, and after removing, u spawn the new drop

#

another one could be canceling

#
import { system, world, ItemStack } from "@minecraft/server";
world.beforeEvents.playerBreakBlock.subscribe((event) => {
  console.warn("dirt broken");
  const { block, player } = event;
  const pdim = player.dimension;
  if (block?.typeId === "minecraft:dirt") {
    event.cancel = true;
    system.run(() => {
      block.runCommand("setblock air ~ ~ ~");
      pdim.spawnItem(new ItemStack("minecraft:stone", 1), {
        x: block.x,
        y: block.y,
        z: block.z,
      });
    });
  }
});
#

fillBlocks it's not stable, so i used runCommand, u can change it if u want

crude hollow
#

ok thanks

crude hollow
honest pollen
crude hollow
honest pollen
#

try again, i edited rn

crude hollow
#

it fails then cancel the block breaking

crude hollow
crude hollow
crude hollow
honest pollen
crude hollow
#

9

crude hollow
honest pollen
#

add dimension property to the line

crude hollow
honest pollen
crude hollow
#

it wont give stone

crude hollow
honest pollen
# crude hollow how do i make the dirt item disappear after breaking?
import { system, world, ItemStack } from "@minecraft/server";
world.beforeEvents.playerBreakBlock.subscribe((event) => {
  
  const { block, player } = event;
  const pdim = player.dimension;
  const loc = block.location;
  if (block?.typeId === "minecraft:dirt") {
    event.cancel = true;
    system.run(() => {
      pdim.spawnItem(new ItemStack("minecraft:stone", 1), {
        x: block.x,
        y: block.y,
        z: block.z,
      });
      player.dimension.fillBlocks(loc, loc, 'minecraft:air')
    });
  }
});
#

try this

#

also u have to use beta apis bc typeId of Block class it's not stable yet

#

it works for me

crude hollow
honest pollen
crude hollow
#

if (block?.typeId === "minecraft:dirt", "minecraft:grass") {

honest pollen
#

if there's a lot of blocks maybe that's not the best option

#
import { system, world, ItemStack } from "@minecraft/server";

const blocksList = [
  "minecraft:dirt",
  "minecraf:grass"
];

world.beforeEvents.playerBreakBlock.subscribe((event) => {
  
  const { block, player } = event;
  const pdim = player.dimension;
  const loc = block.location;
  for (block_ of blocksList) {
    if (block?.typeId === block_) {
    event.cancel = true;
    system.run(() => {
      pdim.spawnItem(new ItemStack("minecraft:stone", 1), {
        x: block.x,
        y: block.y,
        z: block.z,
      });
      player.dimension.fillBlocks(loc, loc, 'minecraft:air')
    });
  }
}
});
crude hollow
honest pollen
#

ok so

#

u can do that

#
world.beforeEvents.playerBreakBlock.subscribe((event) => {
  
  const { block, player } = event;
  const pdim = player.dimension;
  const loc = block.location;
  if (block) {
    event.cancel = true;
    system.run(() => {
      pdim.spawnItem(new ItemStack("minecraft:stone", 1), {
        x: block.x,
        y: block.y,
        z: block.z,
      });
      player.dimension.fillBlocks(loc, loc, 'minecraft:air')
    });
  }
});