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
Okay, this is the extremest form of unfairness I’ve encountered yet with steady changes A mere 2 days after the post of ‘successful’ code… I’m getting stone blocks spawning whether used in an event or as a routine, using LITERALLY the exact code block posted, just changing the player object…
public void SpawnItems(Player p) {
ItemStack stack = this.game.getRegistry().createItemBuilder().itemType(ItemTypes.LAPIS_ORE).build();
Optional<Entity> optItem = p.getLocation().getExtent().createEntity(EntityTypes.ITEM, p.getLocation().getPosition());
if (optItem.isPresent()) {
Item item = (Item) optItem.get();
item.offer(Keys.REPRESENTED_ITEM, stack.createSnapshot());
p.getWorld().spawnEntity(item, Cause.of(p));
}
}
@Listener
public void tapBlock(InteractBlockEvent.Primary event) {
game.getServer().getBroadcastSink().sendMessage(Texts.of("Lets tap-test a block/location"));
if (event.getCause().last(Player.class).isPresent()) {
Player p = event.getCause().last(Player.class).get();
if (p.getItemInHand().isPresent()) {
if (p.getItemInHand().get().getItem() == ItemTypes.GOLDEN_PICKAXE) {
// do whatever test code here
SpawnItems(event.getCause().last(Player.class).get());
ItemStack stack = this.game.getRegistry().createItemBuilder().itemType(ItemTypes.GOLD_NUGGET).build();
Optional<Entity> optItem = p.getLocation().getExtent().createEntity(EntityTypes.ITEM, p.getLocation().getPosition());
if (optItem.isPresent()) {
Item item = (Item) optItem.get();
item.offer(Keys.REPRESENTED_ITEM, stack.createSnapshot());
p.getWorld().spawnEntity(item, Cause.of(p));
}
}
}
}
}
I tap a block with a golden-pickaxe, and all I get is two stone blocks spawned and picked up.
Forced-update of dependancies several times in the past few days and this morning. (How do I tell which specific version/build is being used?) Game is an injected object in main class definition (same as listener class)
@Inject
Game game;
–
What stupid thing am I overlooking/doing wrong? Or has there been changes recently that undid this code? Note I am testing from a player from an event, not a player from a command execution, but i cant see that being the cause of differences
Yeahp, that worked - purged the references from the pom.xml and used the shaded api file and its dropping both correctly.
This is good to see working, but definitely bad to not make sense. But as long as the api files are generated, I’ll stick with that approch - simpler project file to setup as well.