use of org.lanternpowered.server.item.recipe.crafting.CraftingMatrix in project LanternServer by LanternPowered.
the class VanillaContainerInteractionBehavior method updateCraftingGrid.
private void updateCraftingGrid(Player player, CraftingInventory craftingInventory, MatrixResult matrixResult, List<SlotTransaction> transactions) {
final CraftingMatrix matrix = matrixResult.getCraftingMatrix();
final CraftingGridInventory grid = craftingInventory.getCraftingGrid();
for (int x = 0; x < matrix.width(); x++) {
for (int y = 0; y < matrix.height(); y++) {
final ItemStack itemStack = matrix.get(x, y);
final Slot slot = grid.getSlot(x, y).get();
transactions.add(new SlotTransaction(slot, slot.peek().map(LanternItemStackSnapshot::wrap).orElse(LanternItemStackSnapshot.none()), LanternItemStackSnapshot.wrap(itemStack)));
}
}
final CauseStack causeStack = CauseStack.current();
causeStack.addContext(EventContextKeys.SPAWN_TYPE, SpawnTypes.DROPPED_ITEM);
final Transform<World> transform = player.getTransform();
final List<Entity> entities = LanternEventHelper.handlePreDroppedItemSpawning(matrixResult.getRest().stream().map(itemStack -> new Tuple<ItemStackSnapshot, Transform<World>>(LanternItemStackSnapshot.wrap(itemStack), transform)).collect(Collectors.toList()));
final SpawnEntityEvent event = SpongeEventFactory.createDropItemEventDispense(causeStack.getCurrentCause(), entities);
Sponge.getEventManager().post(event);
// Spawn all the entities in the world if the event isn't cancelled
LanternWorld.finishSpawnEntityEvent(event);
}
Aggregations