Java Code Examples for org.spongepowered.api.item.ItemTypes#AIR

The following examples show how to use org.spongepowered.api.item.ItemTypes#AIR . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ElementRegistry.java    From HuskyUI-Plugin with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Convert an ItemStack into an ElementID
 *
 * @param stack ItemStack to pull ElementID from
 * @return ElementID, if it exists. This ID may not actually be associated with an Element, so please verify that before use with {@link #elementExists(int)}.
 */
public Optional<Integer> getElementIDFromItemStack(ItemStack stack){
    if(stack.getType() == ItemTypes.AIR || stack.getType() == ItemTypes.NONE) return Optional.empty();
    Optional<Object> optRegID = stack.toContainer().get(DataQuery.of("UnsafeData", "regid"));
    if(optRegID.isPresent()){
        return Optional.of((int)optRegID.get());
    }
    return Optional.empty();
}
 
Example 2
Source File: HuskyUI.java    From HuskyUI-Plugin with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Handle inventory clicks
 * @param event clickinvevent
 */
@Listener(order = Order.PRE)
public void onItemClick(ClickInventoryEvent event){
    try {
        if (event instanceof ClickInventoryEvent.Primary ||
                event instanceof ClickInventoryEvent.Secondary ||
                event instanceof ClickInventoryEvent.Shift ||
                event instanceof ClickInventoryEvent.Creative) {

            ItemStack affected;
            affected = event.getTransactions().get(0).getOriginal().createStack();
            if (event instanceof ClickInventoryEvent.Shift && (affected.getType() == ItemTypes.AIR || affected.getType() == ItemTypes.NONE)) {
                affected = event.getTransactions().get(0).getDefault().createStack();
            }
            Optional<Integer> potentialID = registry.getElementIDFromItemStack(affected);
            if (potentialID.isPresent()) {
                if (registry.elementExists(potentialID.get())) {
                    if (registry.isElementAuto(potentialID.get())) {
                        if (event.getTransactions().get(0).getSlot().parent().getArchetype().equals(InventoryArchetypes.PLAYER)) {
                            if (registry.isElementFixedAuto(potentialID.get())) {
                                event.setCancelled(true);
                            }
                        } else {
                            event.setCancelled(true);
                        }
                    }
                }
            }
        }
    }catch(Exception ignored){}
}
 
Example 3
Source File: SpongeDeathListener.java    From Plan with GNU Lesser General Public License v3.0 5 votes vote down vote up
private Runnable handlePlayerKill(long time, UUID victimUUID, Player killer) {

        Optional<ItemStack> inMainHand = killer.getItemInHand(HandTypes.MAIN_HAND);
        ItemStack inHand = inMainHand.orElse(killer.getItemInHand(HandTypes.OFF_HAND).orElse(ItemStack.empty()));
        ItemType type = inHand.isEmpty() ? ItemTypes.AIR : inHand.getType();

        return victimUUID != null
                ? new PlayerKillProcessor(killer.getUniqueId(), time, victimUUID, new ItemNameFormatter().apply(type.getName()))
                : new MobKillProcessor(killer.getUniqueId());
    }