Search in sources :

Example 11 with BaseItemStack

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

the class ToolCommands method setTool.

private static void setTool(Player player, LocalSession session, Tool tool, String translationKey) throws InvalidToolBindException {
    BaseItemStack itemStack = player.getItemInHand(HandSide.MAIN_HAND);
    session.setTool(itemStack.getType(), tool);
    player.print(Caption.of(translationKey, itemStack.getRichName()));
    sendUnbindInstruction(player, UNBIND_COMMAND_COMPONENT);
}
Also used : BaseItemStack(com.sk89q.worldedit.blocks.BaseItemStack)

Example 12 with BaseItemStack

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

the class FabricWorld method useItem.

@Override
public boolean useItem(BlockVector3 position, BaseItem item, Direction face) {
    ItemStack stack = FabricAdapter.adapt(new BaseItemStack(item.getType(), item.getNbtData(), 1));
    ServerWorld world = (ServerWorld) getWorld();
    final WorldEditFakePlayer fakePlayer;
    try {
        fakePlayer = fakePlayers.get(world);
    } catch (ExecutionException ignored) {
        return false;
    }
    fakePlayer.setStackInHand(Hand.MAIN_HAND, stack);
    fakePlayer.setPositionAndAngles(position.getBlockX(), position.getBlockY(), position.getBlockZ(), (float) face.toVector().toYaw(), (float) face.toVector().toPitch());
    final BlockPos blockPos = FabricAdapter.toBlockPos(position);
    final BlockHitResult rayTraceResult = new BlockHitResult(FabricAdapter.toVec3(position), FabricAdapter.adapt(face), blockPos, false);
    ItemUsageContext itemUseContext = new ItemUsageContext(fakePlayer, Hand.MAIN_HAND, rayTraceResult);
    ActionResult used = stack.useOnBlock(itemUseContext);
    if (used != ActionResult.SUCCESS) {
        // try activating the block
        if (getWorld().getBlockState(blockPos).activate(world, fakePlayer, Hand.MAIN_HAND, rayTraceResult)) {
            used = ActionResult.SUCCESS;
        } else {
            used = stack.getItem().use(world, fakePlayer, Hand.MAIN_HAND).getResult();
        }
    }
    return used == ActionResult.SUCCESS;
}
Also used : ServerWorld(net.minecraft.server.world.ServerWorld) BaseItemStack(com.sk89q.worldedit.blocks.BaseItemStack) ActionResult(net.minecraft.util.ActionResult) ItemUsageContext(net.minecraft.item.ItemUsageContext) BlockPos(net.minecraft.util.math.BlockPos) BaseItemStack(com.sk89q.worldedit.blocks.BaseItemStack) ItemStack(net.minecraft.item.ItemStack) ExecutionException(java.util.concurrent.ExecutionException) BlockHitResult(net.minecraft.util.hit.BlockHitResult)

Example 13 with BaseItemStack

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

the class FabricAdapter method adapt.

public static ItemStack adapt(BaseItemStack baseItemStack) {
    net.minecraft.nbt.CompoundTag fabricCompound = null;
    if (baseItemStack.getNbtData() != null) {
        fabricCompound = NBTConverter.toNative(baseItemStack.getNbtData());
    }
    final ItemStack itemStack = new ItemStack(adapt(baseItemStack.getType()), baseItemStack.getAmount());
    itemStack.setTag(fabricCompound);
    return itemStack;
}
Also used : BaseItemStack(com.sk89q.worldedit.blocks.BaseItemStack) ItemStack(net.minecraft.item.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