Search in sources :

Example 1 with CraftingMatrix

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);
}
Also used : CauseStack(org.lanternpowered.server.event.CauseStack) Entity(org.spongepowered.api.entity.Entity) CraftingMatrix(org.lanternpowered.server.item.recipe.crafting.CraftingMatrix) World(org.spongepowered.api.world.World) LanternWorld(org.lanternpowered.server.world.LanternWorld) SlotTransaction(org.spongepowered.api.item.inventory.transaction.SlotTransaction) SpawnEntityEvent(org.spongepowered.api.event.entity.SpawnEntityEvent) OutputSlot(org.spongepowered.api.item.inventory.slot.OutputSlot) AbstractSlot(org.lanternpowered.server.inventory.AbstractSlot) ClientSlot(org.lanternpowered.server.inventory.client.ClientSlot) AbstractInventorySlot(org.lanternpowered.server.inventory.AbstractInventorySlot) Slot(org.spongepowered.api.item.inventory.Slot) ItemStackSnapshot(org.spongepowered.api.item.inventory.ItemStackSnapshot) LanternItemStackSnapshot(org.lanternpowered.server.inventory.LanternItemStackSnapshot) ItemStack(org.spongepowered.api.item.inventory.ItemStack) LanternItemStack(org.lanternpowered.server.inventory.LanternItemStack) Transform(org.spongepowered.api.entity.Transform) CraftingGridInventory(org.spongepowered.api.item.inventory.crafting.CraftingGridInventory)

Aggregations

CauseStack (org.lanternpowered.server.event.CauseStack)1 AbstractInventorySlot (org.lanternpowered.server.inventory.AbstractInventorySlot)1 AbstractSlot (org.lanternpowered.server.inventory.AbstractSlot)1 LanternItemStack (org.lanternpowered.server.inventory.LanternItemStack)1 LanternItemStackSnapshot (org.lanternpowered.server.inventory.LanternItemStackSnapshot)1 ClientSlot (org.lanternpowered.server.inventory.client.ClientSlot)1 CraftingMatrix (org.lanternpowered.server.item.recipe.crafting.CraftingMatrix)1 LanternWorld (org.lanternpowered.server.world.LanternWorld)1 Entity (org.spongepowered.api.entity.Entity)1 Transform (org.spongepowered.api.entity.Transform)1 SpawnEntityEvent (org.spongepowered.api.event.entity.SpawnEntityEvent)1 ItemStack (org.spongepowered.api.item.inventory.ItemStack)1 ItemStackSnapshot (org.spongepowered.api.item.inventory.ItemStackSnapshot)1 Slot (org.spongepowered.api.item.inventory.Slot)1 CraftingGridInventory (org.spongepowered.api.item.inventory.crafting.CraftingGridInventory)1 OutputSlot (org.spongepowered.api.item.inventory.slot.OutputSlot)1 SlotTransaction (org.spongepowered.api.item.inventory.transaction.SlotTransaction)1 World (org.spongepowered.api.world.World)1