Spawn / Drop item

Hey,

do I spawn / drop (not in inventory) an item with spawnEntity?
Because of getting the Type ItemStack to Entity is pretty weird.

Cheers

Try this:

ItemStack rose = event.getGame().getRegistry().createItemBuilder().itemType(ItemTypes.DOUBLE_PLANT).quantity(1).build();
rose.offer(Keys.DOUBLE_PLANT_TYPE, DoublePlantTypes.ROSE);
Optional<Entity> optional = player.getLocation().getExtent().createEntity(EntityTypes.DROPPED_ITEM, player.getLocation().getPosition());
  if(optional.isPresent()) {
    Item item = (Item) optional.get();
    item.offer(Keys.REPRESENTED_ITEM, rose.createSnapshot());
    player.getLocation().getExtent().spawnEntity(item, Cause.of(player));
  }

It’s not the best example but I hope it’s understandable!

1 Like

It is - I’m already on this way. Thanks, dude.

This is giving me an error: Could not pass LivingDeathEvent to SpongePlugin.
Without this line a stone will be dropped without any problems.

So I cant attach the ItemStack Data to the Item.

-KAISER

I just updated the Sponge Version.
Is there no EntityTypes.DROPPED_ITEM anymore?

-KAISER

@simon816

It changed to EntityTypes.ITEM 6 hours ago

It gives me:

Could not pass LivingDeathEvent to SpongePlugin
NoSuchFieldError: ITEM

Is it already in 630?

-KAISER

@simon816

The implementation has not updated for the recent change.
You can see that it still references the old field name

You will either have to wait for Sponge to update, or backdate your SpongeAPI version to something like 2.1-20150913.204424-7

@simon816
I need the version number after the Destruct Event Implementation (Commits on Sep 17, 2015).
Or is a new update already planned?

Sorry for my late answer - I just installed Win10 :smiley:

-KAISER

You can use the latest versions again now, I have updated SpongeCommon and Sponge

1 Like

@simon816
Thank you very much, my dear <3

Do you or the others may have an idea why

item.offer(Keys.REPRESENTED_ITEM, itemstack.createSnapshot());

throws an error:

Could not pass LivingDeathEvent to SpongePlugin (NullPointerException)

itemstack Output: 1xtile.oreLapis@0 - That should be correct.
Without the “REPRESENTED_ITEM” Line a default stone block is spawning.

-KAISER

1 Like

RepresentedItemData is not yet implemented unfortunately

1 Like

Hmm … not even planned at the moment.

Can I request it for those RPG Plugin plans?
Or any workarounds on your mind?

-KAISER

So the DataProcessor is added - Thanks for those quick reactions.

But:

ItemStack stack = game.getRegistry().createItemBuilder()
		.itemType(ItemTypes.LAPIS_ORE)
		.quantity(1)
		.build();


  item.offer(Keys.REPRESENTED_ITEM, stack.createSnapshot());
  extent.spawnEntity(item, null);

is still spawning a stoneblock. Is something wrong on my offer?

-KAISER

I just tested it and get a stone block.
When I do System.out.println(item.offer(Keys.REPRESENTED_ITEM, stack.createSnapshot()).getType());
it shows FAILURE, so it’s definitely not completely implemented. It could be just a small thing that’s missing. I’ll take a look

Edit:
This file is just a stub, that would explain it
https://github.com/SpongePowered/SpongeCommon/blob/master/src/main/java/org/spongepowered/common/data/processor/value/RepresentedItemValueProcessor.java

@simon816 Any news?

Yeah, see this commit, gabizou has completed the rest of the implementation

Hey,

still dropping just a stone :confused:

-KAISER

@gabizou

I saw you answering questions on that on GitHub

@simon816

It’s still dropping stones with the latest versions and updates.
Any ideas?