use of org.spongepowered.api.data.Transaction in project SpongeCommon by SpongePowered.
the class InventoryEventFactory method callUpdateAnvilEvent.
public static UpdateAnvilEvent callUpdateAnvilEvent(final AnvilMenu anvil, final ItemStack slot1, final ItemStack slot2, final ItemStack result, final String name, final int levelCost, final int materialCost) {
final Transaction<ItemStackSnapshot> transaction = new Transaction<>(ItemStackSnapshot.empty(), ItemStackUtil.snapshotOf(result));
final UpdateAnvilEventCost costs = new UpdateAnvilEventCost(levelCost, materialCost);
final UpdateAnvilEvent event = SpongeEventFactory.createUpdateAnvilEvent(PhaseTracker.getCauseStackManager().currentCause(), new Transaction<>(costs, costs), (Inventory) anvil, name, ItemStackUtil.snapshotOf(slot1), transaction, ItemStackUtil.snapshotOf(slot2));
SpongeCommon.post(event);
return event;
}
use of org.spongepowered.api.data.Transaction in project SpongeCommon by SpongePowered.
the class InventoryEventFactory method callEnchantEventEnchantmentList.
public static List<EnchantmentInstance> callEnchantEventEnchantmentList(EnchantmentMenu container, int seed, ItemStack itemStack, int option, int level, List<EnchantmentInstance> list) {
List<Enchantment> enchList = Collections.unmodifiableList(SpongeRandomEnchantmentListBuilder.fromNative(list));
org.spongepowered.api.item.inventory.Container enchantContainer = ContainerUtil.fromNative(container);
Player viewer = (Player) enchantContainer.viewer();
ItemStackSnapshot cursor = ItemStackUtil.snapshotOf(viewer.inventory.getCarried());
Transaction<ItemStackSnapshot> cursorTrans = new Transaction<>(cursor, cursor);
EnchantItemEvent.CalculateEnchantment event = SpongeEventFactory.createEnchantItemEventCalculateEnchantment(PhaseTracker.getCauseStackManager().currentCause(), enchList, enchList, enchantContainer, cursorTrans, ItemStackUtil.snapshotOf(itemStack), level, option, seed);
SpongeCommon.post(event);
if (event.enchantments() != event.originalEnchantments()) {
return SpongeRandomEnchantmentListBuilder.toNative(event.enchantments());
}
return list;
}
use of org.spongepowered.api.data.Transaction in project SpongeCommon by SpongePowered.
the class ClickCreativeMenuTransaction method createInventoryEvent.
@Override
Optional<ClickContainerEvent> createInventoryEvent(final List<SlotTransaction> slotTransactions, final List<Entity> entities, final PhaseContext<@NonNull ?> context, final Cause cause) {
if (slotTransactions.isEmpty() && this.slotNum >= 0 && this.slot != null) {
// No SlotTransaction was captured. So we add the clicked slot as a transaction with the creative stack
final ItemStackSnapshot item = this.slot.peek().createSnapshot();
slotTransactions.add(new SlotTransaction(this.slot, item, this.creativeStack));
}
// Creative doesn't inform server of cursor status so there is no way of knowing what the final stack is
final Transaction<ItemStackSnapshot> cursorTransaction = new Transaction<>(this.originalCursor, ItemStackSnapshot.empty());
if (entities.isEmpty()) {
return Optional.of(SpongeEventFactory.createClickContainerEventCreativeSet(cause, (Container) this.menu, cursorTransaction, Optional.ofNullable(this.slot), slotTransactions));
}
final Cause causeWithSpawnType = Cause.builder().from(cause).build(EventContext.builder().from(cause.context()).add(EventContextKeys.SPAWN_TYPE, SpawnTypes.DROPPED_ITEM.get()).build());
return Optional.of(SpongeEventFactory.createClickContainerEventCreativeDrop(causeWithSpawnType, (Container) this.menu, cursorTransaction, this.creativeStack, entities, Optional.ofNullable(this.slot), slotTransactions));
}
use of org.spongepowered.api.data.Transaction in project SpongeCommon by SpongePowered.
the class ClickMenuTransaction method createInventoryEvent.
@Override
Optional<ClickContainerEvent> createInventoryEvent(final List<SlotTransaction> slotTransactions, final List<Entity> entities, final PhaseContext<@NonNull ?> context, final Cause cause) {
final ItemStackSnapshot resultingCursor = ItemStackUtil.snapshotOf(this.player.inventory.getCarried());
final Transaction<ItemStackSnapshot> cursorTransaction = new Transaction<>(this.cursor, resultingCursor);
@Nullable final ClickContainerEvent event = context.createContainerEvent(cause, this.player, (Container) this.menu, cursorTransaction, slotTransactions, entities, this.buttonNum, this.slot);
return Optional.ofNullable(event);
}
use of org.spongepowered.api.data.Transaction in project SpongeCommon by SpongePowered.
the class CloseMenuTransaction method generateEvent.
@Override
public Optional<InteractContainerEvent> generateEvent(final PhaseContext<@NonNull ?> context, @Nullable final GameTransaction<@NonNull ?> parent, final ImmutableList<GameTransaction<InteractContainerEvent>> gameTransactions, final Cause currentCause) {
final ItemStackSnapshot resultingCursor = ItemStackUtil.snapshotOf(this.player.inventory.getCarried());
final Transaction<ItemStackSnapshot> cursorTransaction = new Transaction<>(this.cursor, resultingCursor);
final InteractContainerEvent.Close event = SpongeEventFactory.createInteractContainerEventClose(currentCause, (Container) this.menu, cursorTransaction, (Container) this.menu, this.slotTransactions == null ? Collections.emptyList() : this.slotTransactions);
return Optional.of(event);
}
Aggregations