Search in sources :

Example 66 with CraftItemStack

use of org.bukkit.craftbukkit.v1_18_R2.inventory.CraftItemStack in project LoliServer by Loli-Server.

the class CraftEventFactory method callLootGenerateEvent.

public static LootGenerateEvent callLootGenerateEvent(IInventory inventory, LootTable lootTable, LootContext lootInfo, List<ItemStack> loot, boolean plugin) {
    CraftWorld world = lootInfo.getLevel().getWorld();
    Entity entity = lootInfo.getParamOrNull(LootParameters.THIS_ENTITY);
    // LoliServer
    NamespacedKey key = CraftNamespacedKey.fromMinecraft(world.getHandle().getServer().getLootTables().getKey(lootTable));
    CraftLootTable craftLootTable = new CraftLootTable(key, lootTable);
    List<org.bukkit.inventory.ItemStack> bukkitLoot = loot.stream().map(CraftItemStack::asCraftMirror).collect(Collectors.toCollection(ArrayList::new));
    LootGenerateEvent event = new LootGenerateEvent(world, (entity != null ? entity.getBukkitEntity() : null), InventoryOwner.get(inventory), craftLootTable, CraftLootTable.convertContext(lootInfo), bukkitLoot, plugin);
    Bukkit.getPluginManager().callEvent(event);
    return event;
}
Also used : StriderEntity(net.minecraft.entity.passive.StriderEntity) VillagerEntity(net.minecraft.entity.merchant.villager.VillagerEntity) WaterMobEntity(net.minecraft.entity.passive.WaterMobEntity) PotionEntity(net.minecraft.entity.projectile.PotionEntity) LivingEntity(net.minecraft.entity.LivingEntity) ProjectileEntity(net.minecraft.entity.projectile.ProjectileEntity) AnimalEntity(net.minecraft.entity.passive.AnimalEntity) EnderDragonEntity(net.minecraft.entity.boss.dragon.EnderDragonEntity) MonsterEntity(net.minecraft.entity.monster.MonsterEntity) GolemEntity(net.minecraft.entity.passive.GolemEntity) CraftEntity(org.bukkit.craftbukkit.v1_16_R3.entity.CraftEntity) AbstractRaiderEntity(net.minecraft.entity.monster.AbstractRaiderEntity) PlayerEntity(net.minecraft.entity.player.PlayerEntity) SlimeEntity(net.minecraft.entity.monster.SlimeEntity) SpellcastingIllagerEntity(net.minecraft.entity.monster.SpellcastingIllagerEntity) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) FireworkRocketEntity(net.minecraft.entity.projectile.FireworkRocketEntity) AbstractFishEntity(net.minecraft.entity.passive.fish.AbstractFishEntity) ExperienceOrbEntity(net.minecraft.entity.item.ExperienceOrbEntity) PiglinEntity(net.minecraft.entity.monster.piglin.PiglinEntity) MobEntity(net.minecraft.entity.MobEntity) AreaEffectCloudEntity(net.minecraft.entity.AreaEffectCloudEntity) Entity(net.minecraft.entity.Entity) GhastEntity(net.minecraft.entity.monster.GhastEntity) ItemEntity(net.minecraft.entity.item.ItemEntity) CraftLivingEntity(org.bukkit.craftbukkit.v1_16_R3.entity.CraftLivingEntity) CraftNamespacedKey(org.bukkit.craftbukkit.v1_16_R3.util.CraftNamespacedKey) NamespacedKey(org.bukkit.NamespacedKey) CraftLootTable(org.bukkit.craftbukkit.v1_16_R3.CraftLootTable) LootGenerateEvent(org.bukkit.event.world.LootGenerateEvent) ItemStack(net.minecraft.item.ItemStack) CraftItemStack(org.bukkit.craftbukkit.v1_16_R3.inventory.CraftItemStack) CraftWorld(org.bukkit.craftbukkit.v1_16_R3.CraftWorld)

Example 67 with CraftItemStack

use of org.bukkit.craftbukkit.v1_18_R2.inventory.CraftItemStack in project LoliServer by Loli-Server.

the class CraftEventFactory method callEntityShootBowEvent.

/**
 * EntityShootBowEvent
 */
public static EntityShootBowEvent callEntityShootBowEvent(LivingEntity who, ItemStack bow, ItemStack consumableItem, Entity entityArrow, Hand hand, float force, boolean consumeItem) {
    org.bukkit.entity.LivingEntity shooter = (org.bukkit.entity.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(net.minecraft.entity.LivingEntity) CraftLivingEntity(org.bukkit.craftbukkit.v1_16_R3.entity.CraftLivingEntity) CraftItemStack(org.bukkit.craftbukkit.v1_16_R3.inventory.CraftItemStack) EquipmentSlot(org.bukkit.inventory.EquipmentSlot) org.bukkit.event.entity(org.bukkit.event.entity) org.bukkit.entity(org.bukkit.entity)

Example 68 with CraftItemStack

use of org.bukkit.craftbukkit.v1_18_R2.inventory.CraftItemStack in project MyPet by MyPetORG.

the class CustomInventory method addItem.

public int addItem(org.bukkit.inventory.ItemStack itemAdd) {
    if (itemAdd == null) {
        return 0;
    }
    itemAdd = itemAdd.clone();
    for (int i = 0; i < this.getSize(); i++) {
        CraftItemStack craftItem = CraftItemStack.asCraftMirror(getItem(i));
        if (ItemStackComparator.compareItem(itemAdd, craftItem)) {
            if (craftItem.getAmount() >= craftItem.getMaxStackSize()) {
                continue;
            }
            while (craftItem.getAmount() < craftItem.getMaxStackSize() && itemAdd.getAmount() > 0) {
                craftItem.setAmount(craftItem.getAmount() + 1);
                itemAdd.setAmount(itemAdd.getAmount() - 1);
            }
            if (itemAdd.getAmount() == 0) {
                break;
            }
        }
    }
    if (itemAdd.getAmount() > 0) {
        for (int i = 0; i < this.getSize(); i++) {
            if (getItem(i) == null) {
                if (itemAdd.getAmount() <= itemAdd.getMaxStackSize()) {
                    setItem(i, CraftItemStack.asNMSCopy(itemAdd.clone()));
                    itemAdd.setAmount(0);
                    break;
                } else {
                    CraftItemStack itemStack = (CraftItemStack) itemAdd.clone();
                    itemStack.setAmount(itemStack.getMaxStackSize());
                    setItem(i, CraftItemStack.asNMSCopy(itemStack));
                    itemAdd.setAmount(itemAdd.getAmount() - itemStack.getMaxStackSize());
                }
                if (itemAdd.getAmount() == 0) {
                    break;
                }
            }
        }
    }
    return itemAdd.getAmount();
}
Also used : CraftItemStack(org.bukkit.craftbukkit.v1_9_R2.inventory.CraftItemStack)

Example 69 with CraftItemStack

use of org.bukkit.craftbukkit.v1_18_R2.inventory.CraftItemStack in project MyPet by MyPetORG.

the class CustomInventory method addItem.

@Override
public int addItem(org.bukkit.inventory.ItemStack itemAdd) {
    if (itemAdd == null) {
        return 0;
    }
    itemAdd = itemAdd.clone();
    for (int i = 0; i < this.getSize(); i++) {
        CraftItemStack craftItem = CraftItemStack.asCraftMirror(getItem(i));
        if (ItemStackComparator.compareItem(itemAdd, craftItem)) {
            if (craftItem.getAmount() >= craftItem.getMaxStackSize()) {
                continue;
            }
            while (craftItem.getAmount() < craftItem.getMaxStackSize() && itemAdd.getAmount() > 0) {
                craftItem.setAmount(craftItem.getAmount() + 1);
                itemAdd.setAmount(itemAdd.getAmount() - 1);
            }
            if (itemAdd.getAmount() == 0) {
                break;
            }
        }
    }
    if (itemAdd.getAmount() > 0) {
        for (int i = 0; i < this.getSize(); i++) {
            if (getItem(i) == ItemStack.b) {
                if (itemAdd.getAmount() <= itemAdd.getMaxStackSize()) {
                    setItem(i, CraftItemStack.asNMSCopy(itemAdd.clone()));
                    itemAdd.setAmount(0);
                    break;
                } else {
                    CraftItemStack itemStack = (CraftItemStack) itemAdd.clone();
                    itemStack.setAmount(itemStack.getMaxStackSize());
                    setItem(i, CraftItemStack.asNMSCopy(itemStack));
                    itemAdd.setAmount(itemAdd.getAmount() - itemStack.getMaxStackSize());
                }
                if (itemAdd.getAmount() == 0) {
                    break;
                }
            }
        }
    }
    return itemAdd.getAmount();
}
Also used : CraftItemStack(org.bukkit.craftbukkit.v1_16_R3.inventory.CraftItemStack)

Example 70 with CraftItemStack

use of org.bukkit.craftbukkit.v1_18_R2.inventory.CraftItemStack in project Essentials by drtshock.

the class v1_8_R2SpawnerProvider method getEntityType.

@Override
public EntityType getEntityType(ItemStack is) {
    net.minecraft.server.v1_8_R2.ItemStack itemStack;
    CraftItemStack craftStack = CraftItemStack.asCraftCopy(is);
    itemStack = CraftItemStack.asNMSCopy(craftStack);
    NBTTagCompound tag = itemStack.getTag();
    if (tag == null || !tag.hasKey("BlockEntityTag")) {
        throw new IllegalArgumentException();
    }
    String name = tag.getCompound("BlockEntityTag").getString("EntityId");
    return EntityType.fromName(name);
}
Also used : CraftItemStack(org.bukkit.craftbukkit.v1_8_R2.inventory.CraftItemStack) NBTTagCompound(net.minecraft.server.v1_8_R2.NBTTagCompound)

Aggregations

ItemStack (org.bukkit.inventory.ItemStack)35 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