Search in sources :

Example 6 with BaseItemStack

use of com.sk89q.worldedit.blocks.BaseItemStack in project FastAsyncWorldEdit by IntellectualSites.

the class SelectionCommands method wand.

@Command(name = "/wand", desc = "Get the wand object")
@CommandPermissions("worldedit.wand")
public void wand(Player player, LocalSession session, @Switch(name = 'n', desc = "Get a navigation wand") boolean navWand) throws WorldEditException {
    // FAWE start
    session.loadDefaults(player, true);
    // FAWE end
    String wandId = navWand ? session.getNavWandItem() : session.getWandItem();
    if (wandId == null) {
        wandId = navWand ? we.getConfiguration().navigationWand : we.getConfiguration().wandItem;
    }
    ItemType itemType = ItemTypes.parse(wandId);
    if (itemType == null) {
        player.print(Caption.of("worldedit.wand.invalid"));
        return;
    }
    player.giveItem(new BaseItemStack(itemType, 1));
    // FAWE start - instance-iate session
    if (navWand) {
        session.setTool(itemType, NavigationWand.INSTANCE);
        player.print(Caption.of("worldedit.wand.navwand.info"));
    } else {
        session.setTool(itemType, SelectionWand.INSTANCE);
        player.print(Caption.of("worldedit.wand.selwand.info"));
    // FAWE end
    }
}
Also used : BaseItemStack(com.sk89q.worldedit.blocks.BaseItemStack) ItemType(com.sk89q.worldedit.world.item.ItemType) Command(org.enginehub.piston.annotation.Command) CommandPermissions(com.sk89q.worldedit.command.util.CommandPermissions)

Example 7 with BaseItemStack

use of com.sk89q.worldedit.blocks.BaseItemStack in project FastAsyncWorldEdit by IntellectualSites.

the class PaperweightAdapter method adapt.

@Override
public BaseItemStack adapt(org.bukkit.inventory.ItemStack itemStack) {
    final ItemStack nmsStack = CraftItemStack.asNMSCopy(itemStack);
    final BaseItemStack weStack = new BaseItemStack(BukkitAdapter.asItemType(itemStack.getType()), itemStack.getAmount());
    weStack.setNbt(((CompoundBinaryTag) toNativeBinary(nmsStack.getTag())));
    return weStack;
}
Also used : BaseItemStack(com.sk89q.worldedit.blocks.BaseItemStack) CraftItemStack(org.bukkit.craftbukkit.v1_18_R1.inventory.CraftItemStack) BaseItemStack(com.sk89q.worldedit.blocks.BaseItemStack) ItemStack(net.minecraft.world.item.ItemStack) CompoundBinaryTag(com.sk89q.worldedit.util.nbt.CompoundBinaryTag)

Example 8 with BaseItemStack

use of com.sk89q.worldedit.blocks.BaseItemStack in project FastAsyncWorldEdit by IntellectualSites.

the class BukkitPlayerBlockBag method setItem.

@Override
public void setItem(int slot, BaseItem block) {
    loadInventory();
    BaseItemStack stack = block instanceof BaseItemStack ? (BaseItemStack) block : new BaseItemStack(block.getType(), block.getNbtData(), 1);
    items[slot] = BukkitAdapter.adapt(stack);
}
Also used : BaseItemStack(com.sk89q.worldedit.blocks.BaseItemStack)

Example 9 with BaseItemStack

use of com.sk89q.worldedit.blocks.BaseItemStack in project FastAsyncWorldEdit by IntellectualSites.

the class BukkitPlayerBlockBag method storeBlock.

@Override
public void storeBlock(BlockState blockState, int amount) throws BlockBagException {
    if (blockState.getBlockType().getMaterial().isAir()) {
        throw new IllegalArgumentException("Can't store air block");
    }
    if (!blockState.getBlockType().hasItemType()) {
        throw new IllegalArgumentException("This block cannot be stored");
    }
    loadInventory();
    int freeSlot = -1;
    for (int slot = 0; slot < items.length; ++slot) {
        ItemStack bukkitItem = items[slot];
        if (bukkitItem == null) {
            if (freeSlot == -1) {
                freeSlot = slot;
            }
            continue;
        }
        if (!BukkitAdapter.equals(blockState.getBlockType(), bukkitItem.getType())) {
            // Type id doesn't fit
            continue;
        }
        int currentAmount = bukkitItem.getAmount();
        if (currentAmount < 0) {
            // Unlimited
            return;
        }
        if (currentAmount >= 64) {
            // Full stack
            continue;
        }
        int spaceLeft = 64 - currentAmount;
        if (spaceLeft >= amount) {
            bukkitItem.setAmount(currentAmount + amount);
            return;
        }
        bukkitItem.setAmount(64);
        amount -= spaceLeft;
    }
    if (freeSlot > -1) {
        items[freeSlot] = BukkitAdapter.adapt(new BaseItemStack(blockState.getBlockType().getItemType(), amount));
        return;
    }
    throw new OutOfSpaceException(blockState.getBlockType());
}
Also used : BaseItemStack(com.sk89q.worldedit.blocks.BaseItemStack) BaseItemStack(com.sk89q.worldedit.blocks.BaseItemStack) ItemStack(org.bukkit.inventory.ItemStack) OutOfSpaceException(com.sk89q.worldedit.extent.inventory.OutOfSpaceException)

Example 10 with BaseItemStack

use of com.sk89q.worldedit.blocks.BaseItemStack in project FastAsyncWorldEdit by IntellectualSites.

the class BukkitPlayer method giveItem.

// FAWE start
@Override
public void giveItem(BaseItemStack itemStack) {
    final PlayerInventory inv = player.getInventory();
    ItemStack newItem = BukkitAdapter.adapt(itemStack);
    if (itemStack.getType().getId().equalsIgnoreCase(WorldEdit.getInstance().getConfiguration().wandItem)) {
        inv.remove(newItem);
    }
    final ItemStack item = player.getInventory().getItemInMainHand();
    player.getInventory().setItemInMainHand(newItem);
    HashMap<Integer, ItemStack> overflow = inv.addItem(item);
    if (!overflow.isEmpty()) {
        TaskManager.taskManager().sync(new RunnableVal<>() {

            @Override
            public void run(Object value) {
                for (Map.Entry<Integer, ItemStack> entry : overflow.entrySet()) {
                    ItemStack stack = entry.getValue();
                    if (stack.getType() != Material.AIR && stack.getAmount() > 0) {
                        Item dropped = player.getWorld().dropItem(player.getLocation(), stack);
                        PlayerDropItemEvent event = new PlayerDropItemEvent(player, dropped);
                        Bukkit.getPluginManager().callEvent(event);
                        if (event.isCancelled()) {
                            dropped.remove();
                        }
                    }
                }
            }
        });
    }
    player.updateInventory();
}
Also used : PlayerDropItemEvent(org.bukkit.event.player.PlayerDropItemEvent) Item(org.bukkit.entity.Item) PlayerInventory(org.bukkit.inventory.PlayerInventory) BaseItemStack(com.sk89q.worldedit.blocks.BaseItemStack) ItemStack(org.bukkit.inventory.ItemStack)

Aggregations

BaseItemStack (com.sk89q.worldedit.blocks.BaseItemStack)13 ItemStack (net.minecraft.item.ItemStack)4 ExecutionException (java.util.concurrent.ExecutionException)3 ItemStack (net.minecraft.world.item.ItemStack)3 CraftItemStack (org.bukkit.craftbukkit.v1_18_R1.inventory.CraftItemStack)3 CompoundBinaryTag (com.sk89q.worldedit.util.nbt.CompoundBinaryTag)2 ItemType (com.sk89q.worldedit.world.item.ItemType)2 BlockPos (net.minecraft.util.math.BlockPos)2 ItemStack (org.bukkit.inventory.ItemStack)2 BaseItem (com.sk89q.worldedit.blocks.BaseItem)1 CommandPermissions (com.sk89q.worldedit.command.util.CommandPermissions)1 InputParseException (com.sk89q.worldedit.extension.input.InputParseException)1 NoMatchException (com.sk89q.worldedit.extension.input.NoMatchException)1 OutOfSpaceException (com.sk89q.worldedit.extent.inventory.OutOfSpaceException)1 IOException (java.io.IOException)1 BlockPos (net.minecraft.core.BlockPos)1 ItemUsageContext (net.minecraft.item.ItemUsageContext)1 ItemUseContext (net.minecraft.item.ItemUseContext)1 CompoundNBT (net.minecraft.nbt.CompoundNBT)1 ServerLevel (net.minecraft.server.level.ServerLevel)1