Search in sources :

Example 51 with CraftItemStack

use of org.bukkit.craftbukkit.v1_18_R2.inventory.CraftItemStack in project SilkSpawners by timbru31.

the class NMSHandler method getVanillaNBTEntityID.

@Override
@Nullable
public String getVanillaNBTEntityID(final ItemStack item) {
    net.minecraft.server.v1_11_R1.ItemStack itemStack = null;
    final CraftItemStack craftStack = CraftItemStack.asCraftCopy(item);
    itemStack = CraftItemStack.asNMSCopy(craftStack);
    NBTTagCompound tag = itemStack.getTag();
    if (tag == null || !tag.hasKey("BlockEntityTag")) {
        return null;
    }
    tag = tag.getCompound("BlockEntityTag");
    if (tag.hasKey("EntityId")) {
        return tag.getString("EntityId");
    } else if (tag.hasKey("SpawnData") && tag.getCompound("SpawnData").hasKey("id")) {
        return tag.getCompound("SpawnData").getString("id");
    } else if (tag.hasKey("SpawnPotentials") && !tag.getList("SpawnPotentials", 8).isEmpty()) {
        return tag.getList("SpawnPotentials", 8).get(0).getCompound("Entity").getString("id");
    } else {
        return null;
    }
}
Also used : CraftItemStack(org.bukkit.craftbukkit.v1_11_R1.inventory.CraftItemStack) NBTTagCompound(net.minecraft.server.v1_11_R1.NBTTagCompound) Nullable(javax.annotation.Nullable)

Example 52 with CraftItemStack

use of org.bukkit.craftbukkit.v1_18_R2.inventory.CraftItemStack in project Mohist by MohistMC.

the class CraftItemStack method asNMSCopy.

public static net.minecraft.world.item.ItemStack asNMSCopy(ItemStack original) {
    if (original instanceof CraftItemStack) {
        CraftItemStack stack = (CraftItemStack) original;
        return stack.handle == null ? net.minecraft.world.item.ItemStack.EMPTY : stack.handle.copy();
    }
    if (original == null || original.getType() == Material.AIR) {
        return net.minecraft.world.item.ItemStack.EMPTY;
    }
    Item item = CraftMagicNumbers.getItem(original.getType(), original.getDurability());
    if (item == null) {
        return net.minecraft.world.item.ItemStack.EMPTY;
    }
    net.minecraft.world.item.ItemStack stack = new net.minecraft.world.item.ItemStack(item, original.getAmount());
    if (original.hasItemMeta()) {
        setItemMeta(stack, original.getItemMeta());
    }
    return stack;
}
Also used : Item(net.minecraft.world.item.Item) CraftMetaItem(org.bukkit.craftbukkit.v1_18_R2.inventory.CraftMetaItem) ItemStack(org.bukkit.inventory.ItemStack)

Example 53 with CraftItemStack

use of org.bukkit.craftbukkit.v1_18_R2.inventory.CraftItemStack in project Mohist by MohistMC.

the class CraftEventFactory method callPlayerInteractEvent.

public static PlayerInteractEvent callPlayerInteractEvent(net.minecraft.world.entity.player.Player who, Action action, BlockPos position, Direction direction, ItemStack itemstack, boolean cancelledBlock, InteractionHand hand) {
    Player player = (who == null) ? null : (Player) who.getBukkitEntity();
    CraftItemStack itemInHand = CraftItemStack.asCraftMirror(itemstack);
    CraftWorld craftWorld = (CraftWorld) player.getWorld();
    CraftServer craftServer = (CraftServer) player.getServer();
    Block blockClicked = null;
    if (position != null) {
        blockClicked = craftWorld.getBlockAt(position.getX(), position.getY(), position.getZ());
    } else {
        switch(action) {
            case LEFT_CLICK_BLOCK:
                action = Action.LEFT_CLICK_AIR;
                break;
            case RIGHT_CLICK_BLOCK:
                action = Action.RIGHT_CLICK_AIR;
                break;
        }
    }
    BlockFace blockFace = CraftBlock.notchToBlockFace(direction);
    if (itemInHand.getType() == Material.AIR || itemInHand.getAmount() == 0) {
        itemInHand = null;
    }
    PlayerInteractEvent event = new PlayerInteractEvent(player, action, itemInHand, blockClicked, blockFace, (hand == null) ? null : ((hand == InteractionHand.OFF_HAND) ? EquipmentSlot.OFF_HAND : EquipmentSlot.HAND));
    if (cancelledBlock) {
        event.setUseInteractedBlock(Event.Result.DENY);
    }
    craftServer.getPluginManager().callEvent(event);
    return event;
}
Also used : CraftItemStack(org.bukkit.craftbukkit.v1_18_R2.inventory.CraftItemStack) ServerPlayer(net.minecraft.server.level.ServerPlayer) CraftPlayer(org.bukkit.craftbukkit.v1_18_R2.entity.CraftPlayer) Player(org.bukkit.entity.Player) BlockFace(org.bukkit.block.BlockFace) PlayerInteractEvent(org.bukkit.event.player.PlayerInteractEvent) Block(org.bukkit.block.Block) CraftBlock(org.bukkit.craftbukkit.v1_18_R2.block.CraftBlock)

Example 54 with CraftItemStack

use of org.bukkit.craftbukkit.v1_18_R2.inventory.CraftItemStack in project Mohist by MohistMC.

the class CraftEventFactory method callBlockDamageAbortEvent.

public static BlockDamageAbortEvent callBlockDamageAbortEvent(ServerPlayer who, BlockPos pos, ItemStack itemstack) {
    Player player = who.getBukkitEntity();
    CraftItemStack itemInHand = CraftItemStack.asCraftMirror(itemstack);
    Block blockClicked = CraftBlock.at(who.getLevel(), pos);
    BlockDamageAbortEvent event = new BlockDamageAbortEvent(player, blockClicked, itemInHand);
    player.getServer().getPluginManager().callEvent(event);
    return event;
}
Also used : CraftItemStack(org.bukkit.craftbukkit.v1_18_R2.inventory.CraftItemStack) ServerPlayer(net.minecraft.server.level.ServerPlayer) CraftPlayer(org.bukkit.craftbukkit.v1_18_R2.entity.CraftPlayer) Player(org.bukkit.entity.Player) BlockDamageAbortEvent(org.bukkit.event.block.BlockDamageAbortEvent) Block(org.bukkit.block.Block) CraftBlock(org.bukkit.craftbukkit.v1_18_R2.block.CraftBlock)

Example 55 with CraftItemStack

use of org.bukkit.craftbukkit.v1_18_R2.inventory.CraftItemStack in project Mohist by MohistMC.

the class CraftEventFactory method callPlayerHarvestBlockEvent.

/**
 * Player Harvest Block Event
 */
public static PlayerHarvestBlockEvent callPlayerHarvestBlockEvent(Level world, BlockPos blockposition, net.minecraft.world.entity.player.Player who, List<ItemStack> itemsToHarvest) {
    List<org.bukkit.inventory.ItemStack> bukkitItemsToHarvest = new ArrayList<>(itemsToHarvest.stream().map(CraftItemStack::asBukkitCopy).collect(Collectors.toList()));
    Player player = (Player) who.getBukkitEntity();
    PlayerHarvestBlockEvent playerHarvestBlockEvent = new PlayerHarvestBlockEvent(player, CraftBlock.at(world, blockposition), bukkitItemsToHarvest);
    Bukkit.getPluginManager().callEvent(playerHarvestBlockEvent);
    return playerHarvestBlockEvent;
}
Also used : CraftItemStack(org.bukkit.craftbukkit.v1_18_R2.inventory.CraftItemStack) ServerPlayer(net.minecraft.server.level.ServerPlayer) CraftPlayer(org.bukkit.craftbukkit.v1_18_R2.entity.CraftPlayer) Player(org.bukkit.entity.Player) ArrayList(java.util.ArrayList) PlayerHarvestBlockEvent(org.bukkit.event.player.PlayerHarvestBlockEvent) ItemStack(net.minecraft.world.item.ItemStack) CraftItemStack(org.bukkit.craftbukkit.v1_18_R2.inventory.CraftItemStack)

Aggregations

ItemStack (org.bukkit.inventory.ItemStack)35 Nullable (javax.annotation.Nullable)27 CraftItemStack (org.bukkit.craftbukkit.v1_16_R3.inventory.CraftItemStack)25 CraftItemStack (org.bukkit.craftbukkit.v1_12_R1.inventory.CraftItemStack)20 CraftItemStack (org.bukkit.craftbukkit.v1_18_R2.inventory.CraftItemStack)17 CompoundTag (net.minecraft.nbt.CompoundTag)15 Material (org.bukkit.Material)14 Block (org.bukkit.block.Block)13 Field (java.lang.reflect.Field)11 SneakyThrows (lombok.SneakyThrows)11 ItemMeta (org.bukkit.inventory.meta.ItemMeta)10 Player (org.bukkit.entity.Player)9 BlockFace (org.bukkit.block.BlockFace)8 CraftItemStack (org.bukkit.craftbukkit.v1_18_R1.inventory.CraftItemStack)8 CraftItemStack (org.bukkit.craftbukkit.v1_8_R1.inventory.CraftItemStack)8 ArrayList (java.util.ArrayList)7 NBTTagCompound (net.minecraft.server.v1_8_R1.NBTTagCompound)7 CraftWorld (org.bukkit.craftbukkit.v1_16_R3.CraftWorld)7 CraftLivingEntity (org.bukkit.craftbukkit.v1_16_R3.entity.CraftLivingEntity)7 CraftItemStack (org.bukkit.craftbukkit.v1_13_R2.inventory.CraftItemStack)6