Search in sources :

Example 96 with CraftItemStack

use of org.bukkit.craftbukkit.v1_9_R2.inventory.CraftItemStack in project WLib by WizardlyBump17.

the class PacketListener method entityEquipment.

@SuppressWarnings("unchecked")
@SneakyThrows
private void entityEquipment(PacketPlayOutEntityEquipment handle) {
    final Field field = handle.getClass().getDeclaredField("c");
    field.setAccessible(true);
    List<Pair<EquipmentSlot, net.minecraft.world.item.ItemStack>> items = (List<Pair<EquipmentSlot, net.minecraft.world.item.ItemStack>>) field.get(handle);
    for (Pair<EquipmentSlot, net.minecraft.world.item.ItemStack> item : items) {
        final CraftItemStack stack = CraftItemStack.asCraftMirror(item.getSecond()).clone();
        if (!isValidItem(stack))
            continue;
        final Field second = item.getClass().getDeclaredField("second");
        second.setAccessible(true);
        second.set(item, CraftItemStack.asNMSCopy(fixItem(stack)));
    }
}
Also used : Field(java.lang.reflect.Field) CraftItemStack(org.bukkit.craftbukkit.v1_18_R2.inventory.CraftItemStack) EquipmentSlot(org.bukkit.inventory.EquipmentSlot) ArrayList(java.util.ArrayList) List(java.util.List) ItemStack(org.bukkit.inventory.ItemStack) CraftItemStack(org.bukkit.craftbukkit.v1_18_R2.inventory.CraftItemStack) Pair(com.mojang.datafixers.util.Pair) SneakyThrows(lombok.SneakyThrows)

Example 97 with CraftItemStack

use of org.bukkit.craftbukkit.v1_9_R2.inventory.CraftItemStack in project Magma-1.16.x by magmafoundation.

the class CraftEventFactory method callPlayerInteractEvent.

public static PlayerInteractEvent callPlayerInteractEvent(PlayerEntity who, Action action, BlockPos position, Direction direction, ItemStack itemstack, boolean cancelledBlock, Hand 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 == Hand.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_16_R3.inventory.CraftItemStack) Player(org.bukkit.entity.Player) CraftPlayer(org.bukkit.craftbukkit.v1_16_R3.entity.CraftPlayer) BlockFace(org.bukkit.block.BlockFace) PlayerInteractEvent(org.bukkit.event.player.PlayerInteractEvent) CraftBlock(org.bukkit.craftbukkit.v1_16_R3.block.CraftBlock) Block(org.bukkit.block.Block) CraftServer(org.bukkit.craftbukkit.v1_16_R3.CraftServer) CraftWorld(org.bukkit.craftbukkit.v1_16_R3.CraftWorld)

Example 98 with CraftItemStack

use of org.bukkit.craftbukkit.v1_9_R2.inventory.CraftItemStack in project Magma-1.16.x by magmafoundation.

the class CraftEventFactory method callEntityBreedEvent.

public static EntityBreedEvent callEntityBreedEvent(net.minecraft.entity.LivingEntity child, net.minecraft.entity.LivingEntity mother, net.minecraft.entity.LivingEntity father, net.minecraft.entity.LivingEntity breeder, ItemStack bredWith, int experience) {
    org.bukkit.entity.LivingEntity breederEntity = (LivingEntity) (breeder == null ? null : breeder.getBukkitEntity());
    CraftItemStack bredWithStack = bredWith == null ? null : CraftItemStack.asCraftMirror(bredWith).clone();
    EntityBreedEvent event = new EntityBreedEvent((LivingEntity) child.getBukkitEntity(), (LivingEntity) mother.getBukkitEntity(), (LivingEntity) father.getBukkitEntity(), breederEntity, bredWithStack, experience);
    child.level.getServerCB().getPluginManager().callEvent(event);
    return event;
}
Also used : LivingEntity(org.bukkit.entity.LivingEntity) CraftLivingEntity(org.bukkit.craftbukkit.v1_16_R3.entity.CraftLivingEntity) EntityBreedEvent(org.bukkit.event.entity.EntityBreedEvent) CraftItemStack(org.bukkit.craftbukkit.v1_16_R3.inventory.CraftItemStack) LivingEntity(org.bukkit.entity.LivingEntity)

Example 99 with CraftItemStack

use of org.bukkit.craftbukkit.v1_9_R2.inventory.CraftItemStack in project Magma-1.16.x by magmafoundation.

the class CraftEventFactory method getPlayerBucketEvent.

private static PlayerEvent getPlayerBucketEvent(boolean isFilling, World world, PlayerEntity who, BlockPos changed, BlockPos clicked, Direction clickedFace, ItemStack itemstack, net.minecraft.item.Item item) {
    Player player = (Player) who.getBukkitEntity();
    CraftItemStack itemInHand = CraftItemStack.asNewCraftStack(item);
    Material bucket = CraftMagicNumbers.getMaterial(itemstack.getItem());
    CraftServer craftServer = (CraftServer) player.getServer();
    Block block = CraftBlock.at(world, changed);
    Block blockClicked = CraftBlock.at(world, clicked);
    BlockFace blockFace = CraftBlock.notchToBlockFace(clickedFace);
    PlayerEvent event;
    if (isFilling) {
        event = new PlayerBucketFillEvent(player, block, blockClicked, blockFace, bucket, itemInHand);
        ((PlayerBucketFillEvent) event).setCancelled(!canBuild(world, player, changed.getX(), changed.getZ()));
    } else {
        event = new PlayerBucketEmptyEvent(player, block, blockClicked, blockFace, bucket, itemInHand);
        ((PlayerBucketEmptyEvent) event).setCancelled(!canBuild(world, player, changed.getX(), changed.getZ()));
    }
    craftServer.getPluginManager().callEvent(event);
    return event;
}
Also used : CraftItemStack(org.bukkit.craftbukkit.v1_16_R3.inventory.CraftItemStack) PlayerBucketFillEvent(org.bukkit.event.player.PlayerBucketFillEvent) Player(org.bukkit.entity.Player) CraftPlayer(org.bukkit.craftbukkit.v1_16_R3.entity.CraftPlayer) BlockFace(org.bukkit.block.BlockFace) PlayerEvent(org.bukkit.event.player.PlayerEvent) CraftBlock(org.bukkit.craftbukkit.v1_16_R3.block.CraftBlock) Block(org.bukkit.block.Block) Material(org.bukkit.Material) CraftServer(org.bukkit.craftbukkit.v1_16_R3.CraftServer) PlayerBucketEmptyEvent(org.bukkit.event.player.PlayerBucketEmptyEvent)

Example 100 with CraftItemStack

use of org.bukkit.craftbukkit.v1_9_R2.inventory.CraftItemStack in project Magma-1.16.x by magmafoundation.

the class CraftEventFactory method callEntityShootBowEvent.

/**
 * EntityShootBowEvent
 */
public static EntityShootBowEvent callEntityShootBowEvent(net.minecraft.entity.LivingEntity who, ItemStack bow, ItemStack consumableItem, Entity entityArrow, Hand hand, float force, boolean consumeItem) {
    LivingEntity shooter = (LivingEntity) who.getBukkitEntity();
    CraftItemStack itemInHand = CraftItemStack.asCraftMirror(bow);
    CraftItemStack itemConsumable = CraftItemStack.asCraftMirror(consumableItem);
    org.bukkit.entity.Entity arrow = entityArrow.getBukkitEntity();
    EquipmentSlot handSlot = (hand == Hand.MAIN_HAND) ? EquipmentSlot.HAND : EquipmentSlot.OFF_HAND;
    if (itemInHand != null && (itemInHand.getType() == Material.AIR || itemInHand.getAmount() == 0)) {
        itemInHand = null;
    }
    EntityShootBowEvent event = new EntityShootBowEvent(shooter, itemInHand, itemConsumable, arrow, handSlot, force, consumeItem);
    Bukkit.getPluginManager().callEvent(event);
    return event;
}
Also used : LivingEntity(org.bukkit.entity.LivingEntity) CraftLivingEntity(org.bukkit.craftbukkit.v1_16_R3.entity.CraftLivingEntity) CraftItemStack(org.bukkit.craftbukkit.v1_16_R3.inventory.CraftItemStack) EntityShootBowEvent(org.bukkit.event.entity.EntityShootBowEvent) EquipmentSlot(org.bukkit.inventory.EquipmentSlot)

Aggregations

ItemStack (org.bukkit.inventory.ItemStack)34 Nullable (javax.annotation.Nullable)27 CraftItemStack (org.bukkit.craftbukkit.v1_16_R3.inventory.CraftItemStack)27 CraftItemStack (org.bukkit.craftbukkit.v1_12_R1.inventory.CraftItemStack)22 CraftItemStack (org.bukkit.craftbukkit.v1_18_R2.inventory.CraftItemStack)18 CompoundTag (net.minecraft.nbt.CompoundTag)15 Material (org.bukkit.Material)14 Block (org.bukkit.block.Block)13 Field (java.lang.reflect.Field)12 SneakyThrows (lombok.SneakyThrows)11 ItemMeta (org.bukkit.inventory.meta.ItemMeta)10 CraftItemStack (org.bukkit.craftbukkit.v1_17_R1.inventory.CraftItemStack)9 CraftItemStack (org.bukkit.craftbukkit.v1_18_R1.inventory.CraftItemStack)9 Player (org.bukkit.entity.Player)9 BlockFace (org.bukkit.block.BlockFace)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 CraftItemStack (org.bukkit.craftbukkit.v1_16_R1.inventory.CraftItemStack)7 CraftWorld (org.bukkit.craftbukkit.v1_16_R3.CraftWorld)7