#Dropped item type?

1 messages · Page 1 of 1 (latest)

inner haven
#

I feel like this should be simple enough, but I literally just need to know if a dropped item is rotten flesh or not. I've tried to find the id and nametag of an item to get this, but it looks like ID isn't the name and neither is the nameTag (it's just blank). I've tried to get all item components, and it just gives me that it's an item. How do I find the type of item it is?

civic idol
#
const itemStack = Entity.getComponent('item').itemStack;
console.log(itemStack?.typeId);
inner haven
#

I have the component.

#

I need to ONLY remove() rotten flesh.

#

What item property has this?

civic idol
#

no dude, get the item itself.

inner haven
#

You mean

#

like construct a new itemstack out of the item entity component

#

and then get the name from that?

civic idol
#

Get the component first then get the itemStack

inner haven
#

So, I have this:

for (const entity of world.getDimension("overworld").getEntities()) {
        if (entity.typeId === "minecraft:item") {
    }
}
civic idol
#

the variable name can be anything but the component set-up should look exactly like that.

inner haven
#

If I have to make a new itemstack to check for the name out of every dropped item in the world

#

I feel like that might cause lag

civic idol
inner haven
#

Okay, so then

umbral idol
#

I'm sleepy

for (const entity of world.getDimension("overworld").getEntities()) {
        if (entity.typeId === "minecraft:item") {
    const itemStack = entity.getComponent('item').itemStack;
    if (itemStack.typeId == "minecraft:rotten_flesh")
    return entity.remove()
    }
}
civic idol
#
for (const entity of Dimension.getEntities()) {
  if (entity.hasComponent('item')) {
    const itemStack = entity.getComponent('item').itemStack;
    console.log(itemStack?.typeId);
  }
}```
#

As simple as that.

inner haven
#

typeId is the item type?

umbral idol
#

depend on where you access it

#

on entity its "minecraft:item"
on itemStack its "minecraft:rotten_flesh"

inner haven
#

Got it.

#

Now, I do have one more question. Is it possible to stop the loot table of a dead entity from spawning?

#

Like if I want a certain zombie to not spawn loot upon dying, is that possible?

umbral idol
#

"/gamerule doMobLoot false" or smt like that

inner haven
#

True, but I want other mobs to have droppable loot.

#

Any solution for just a specific zombie?

#

A component or something?

umbral idol
#

Meh, just remove the item entity after it spawns

inner haven
#

Yes, but how?

#

If it's a zombie, it can spawn carrots, iron ingots, rotten flesh, etc. after dying.

#

Is it really necessary to manually check for each of its possible loot items, or is there a simpler way?

umbral idol
#

Remove the item entities spawned on the same tick as when the zombie is killed. Limit it to the radius around the zombie's feet.

I've underlined to empathize something.

inner haven
#

Okay, but what if the zombie dies in a group of items?

#

If you kill it, and your inventory is full (thus you aren't picking up items), and it dies in a pool of items on the floor, then what?

umbral idol
#

Technically, Existing dropped items will have their "age" exceed the minimum for the check.

inner haven
#

?

#

So I can check for the age of the itemstack?

umbral idol
#

You know, it's like differentiating newborn and old ones.

Old ones get ignored.

New ones get killed.

Cus new ones have only recently appeared, their "age" would be less than a few ticks compared to old ones.

inner haven
#

Yes. How do I check for the age (in ticks) of an item?

umbral idol
#

I'll try to make one, ig

inner haven
#

I didn't know that was possible.

#

I'm understanding what you're suggesting, but I don't know how to check for item age.

umbral idol
inner haven
#

Oh, got it.

inner haven
umbral idol
#

its a property, not a method. So no ()

inner haven
#

got it.

inner haven
umbral idol
#

Loot spawns exactly when the entity died iirc.

You could use dynamicProperty to record what tick they got created. With entitySpawn event.

Then in the deadEntity event, get all the items around getEntities(), you can check for items that have their age:
system.currentTick - age <= 1

inner haven
#

Alright, I'll look into that.

umbral idol
#

made this in a few minutes

world.afterEvents.entityDie.subscribe(({deadEntity})=>{
    if (!deadEntity.isValid()) return;
    const deadtick = system.currentTick;
    if (deadEntity.typeId == "minecraft:zombie") {
        const loot = deadEntity.dimension.getEntities({
            location: deadEntity.location,
            maxDistance: 1,
            type: "minecraft:item"
        })
        .forEach((itemEntity)=>{
            if (deadtick - (itemEntity.getDynamicProperty("age")??0) < 1)
            itemEntity.remove();
        })
    }
})

world.afterEvents.entitySpawn.subscribe(({entity})=>{
    if (!entity.hasComponent("item")) return;
    entity.setDynamicProperty("age",system.currentTick)
})
#

Doesn't take account exp orbs ^

soft needle
umbral idol
#

im lazi- lazee- lazey- lazy

soft needle
#

ok