use of org.spongepowered.api.item.inventory.BlockCarrier in project modules-extra by CubeEngine.
the class ChangeInventoryReport method listen.
@Listener
public void listen(ClickInventoryEvent event) {
List<SlotTransaction> upperTransactions = new ArrayList<>();
int upperSize = event.getTargetInventory().iterator().next().capacity();
for (SlotTransaction transaction : event.getTransactions()) {
Integer affectedSlot = transaction.getSlot().getInventoryProperty(SlotIndex.class).map(SlotIndex::getValue).orElse(-1);
boolean upper = affectedSlot != -1 && affectedSlot < upperSize;
if (upper) {
upperTransactions.add(transaction);
}
}
Inventory te = event.getTargetInventory().query(QueryOperationTypes.TYPE.of(BlockCarrier.class));
if (!(te instanceof BlockCarrier)) {
te = te.first();
}
if (te instanceof BlockCarrier) {
Action action = this.observe(event);
action.addData(INVENTORY_CHANGES, Observe.transactions(upperTransactions));
action.addData(Report.LOCATION, Observe.location(((BlockCarrier) te).getLocation()));
this.report(action);
}
}
use of org.spongepowered.api.item.inventory.BlockCarrier in project AdamantineShield by Karanum.
the class InventoryChangeListener method onInventoryTransfer.
@Listener
public void onInventoryTransfer(AffectSlotEvent e, @First Player p) {
if (e.getTransactions().isEmpty())
return;
if (!(e.getTransactions().get(0).getSlot().parent() instanceof CarriedInventory))
return;
BlockCarrier carrier = null;
CarriedInventory<?> c = (CarriedInventory<?>) e.getTransactions().get(0).getSlot().parent();
if (c.getCarrier().get() instanceof BlockCarrier) {
carrier = (BlockCarrier) c.getCarrier().get();
}
if (carrier == null)
return;
if (!logContainers && !(carrier instanceof Chest))
return;
long timestamp = new Date().getTime();
int containerSize = c.iterator().next().capacity();
for (SlotTransaction transaction : e.getTransactions()) {
int slotId = transaction.getSlot().getProperty(SlotIndex.class, "slotindex").map(SlotIndex::getValue).orElse(-1);
if (slotId >= containerSize)
continue;
ItemStackSnapshot origItem = transaction.getOriginal();
ItemStackSnapshot finalItem = transaction.getFinal();
if (origItem == finalItem)
continue;
if (origItem.createGameDictionaryEntry().matches(finalItem.createStack()) && ItemStackComparators.ITEM_DATA.compare(origItem.createStack(), finalItem.createStack()) == 0) {
if (origItem.getQuantity() > finalItem.getQuantity()) {
ItemStackSnapshot stack = ItemStack.builder().itemType(origItem.getType()).quantity(origItem.getQuantity() - finalItem.getQuantity()).build().createSnapshot();
db.addToQueue(new InventoryQueueEntry(carrier, slotId, stack, ActionType.CONTAINER_REMOVE, p, timestamp));
} else if (origItem.getQuantity() < finalItem.getQuantity()) {
ItemStackSnapshot stack = ItemStack.builder().itemType(origItem.getType()).quantity(finalItem.getQuantity() - origItem.getQuantity()).build().createSnapshot();
db.addToQueue(new InventoryQueueEntry(carrier, slotId, stack, ActionType.CONTAINER_ADD, p, timestamp));
}
} else {
if (origItem.getType() != ItemTypes.NONE) {
db.addToQueue(new InventoryQueueEntry(carrier, slotId, origItem, ActionType.CONTAINER_REMOVE, p, timestamp));
}
if (finalItem.getType() != ItemTypes.NONE) {
db.addToQueue(new InventoryQueueEntry(carrier, slotId, finalItem, ActionType.CONTAINER_ADD, p, timestamp));
}
}
}
}
use of org.spongepowered.api.item.inventory.BlockCarrier in project LanternServer by LanternPowered.
the class LanternMultiBlockCarrier method getInventory.
@Override
public Optional<Inventory> getInventory(Location<World> at, Direction from) {
checkNotNull(at, "at");
checkNotNull(from, "from");
final BlockCarrier carrier = this.carriers.get(at);
return carrier == null ? Optional.empty() : Optional.of(carrier.getInventory(from));
}
use of org.spongepowered.api.item.inventory.BlockCarrier in project LanternServer by LanternPowered.
the class LanternMultiBlockCarrier method getInventory.
@Override
public Optional<Inventory> getInventory(Location<World> at) {
checkNotNull(at, "at");
final BlockCarrier carrier = this.carriers.get(at);
return carrier == null ? Optional.empty() : Optional.of(carrier.getInventory());
}
Aggregations