Search in sources :

Example 56 with CraftItemStack

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

the class CraftEventFactory method callEntityBreedEvent.

public static EntityBreedEvent callEntityBreedEvent(EntityLivingBase child, EntityLivingBase mother, EntityLivingBase father, EntityLivingBase breeder, ItemStack bredWith, int experience) {
    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.world.getServer().getPluginManager().callEvent(event);
    return event;
}
Also used : CraftLivingEntity(org.bukkit.craftbukkit.v1_12_R1.entity.CraftLivingEntity) CraftItemStack(org.bukkit.craftbukkit.v1_12_R1.inventory.CraftItemStack)

Example 57 with CraftItemStack

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

the class PerMaterialTest method maxStackSize.

@Test
public void maxStackSize() {
    if (INVALIDATED_MATERIALS.contains(material)) {
        return;
    }
    final ItemStack bukkit = new ItemStack(material);
    final CraftItemStack craft = CraftItemStack.asCraftCopy(bukkit);
    if (material == Material.AIR) {
        final int MAX_AIR_STACK = 0;
        assertThat(material.getMaxStackSize(), is(MAX_AIR_STACK));
        assertThat(bukkit.getMaxStackSize(), is(MAX_AIR_STACK));
        assertThat(craft.getMaxStackSize(), is(MAX_AIR_STACK));
    } else {
        assertThat(material.getMaxStackSize(), is(CraftMagicNumbers.getItem(material).getItemStackLimit()));
        assertThat(bukkit.getMaxStackSize(), is(material.getMaxStackSize()));
        assertThat(craft.getMaxStackSize(), is(material.getMaxStackSize()));
    }
}
Also used : CraftItemStack(org.bukkit.craftbukkit.v1_12_R1.inventory.CraftItemStack) CraftItemStack(org.bukkit.craftbukkit.v1_12_R1.inventory.CraftItemStack) ItemStack(org.bukkit.inventory.ItemStack) Test(org.junit.Test)

Example 58 with CraftItemStack

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

the class ItemMetaTest method testCrazyEquality.

@Test
public void testCrazyEquality() {
    CraftItemStack craft = CraftItemStack.asCraftCopy(new ItemStack(1));
    craft.setItemMeta(craft.getItemMeta());
    ItemStack bukkit = new ItemStack(craft);
    assertThat(craft, is(bukkit));
    assertThat(bukkit, is(craft));
}
Also used : CraftItemStack(org.bukkit.craftbukkit.v1_12_R1.inventory.CraftItemStack) CraftItemStack(org.bukkit.craftbukkit.v1_12_R1.inventory.CraftItemStack) ItemStack(org.bukkit.inventory.ItemStack) Test(org.junit.Test)

Example 59 with CraftItemStack

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

the class CraftEventFactory method callPlayerItemBreakEvent.

public static void callPlayerItemBreakEvent(PlayerEntity human, ItemStack brokenItem) {
    CraftItemStack item = CraftItemStack.asCraftMirror(brokenItem);
    PlayerItemBreakEvent event = new PlayerItemBreakEvent((Player) human.getBukkitEntity(), item);
    Bukkit.getPluginManager().callEvent(event);
}
Also used : CraftItemStack(org.bukkit.craftbukkit.v1_16_R3.inventory.CraftItemStack) PlayerItemBreakEvent(org.bukkit.event.player.PlayerItemBreakEvent)

Example 60 with CraftItemStack

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

the class CraftEventFactory method callEntityDeathEvent.

public static EntityDeathEvent callEntityDeathEvent(LivingEntity victim, List<org.bukkit.inventory.ItemStack> drops) {
    CraftLivingEntity entity = (CraftLivingEntity) victim.getBukkitEntity();
    EntityDeathEvent event = new EntityDeathEvent(entity, drops, victim.expToDrop);
    CraftWorld world = (CraftWorld) entity.getWorld();
    Bukkit.getServer().getPluginManager().callEvent(event);
    victim.expToDrop = event.getDroppedExp();
    for (org.bukkit.inventory.ItemStack stack : event.getDrops()) {
        if (stack == null || stack.getType() == Material.AIR || stack.getAmount() == 0)
            continue;
        // Paper - note: dropItem already clones due to this being bukkit -> NMS
        world.dropItem(entity.getLocation(), stack);
        if (stack instanceof CraftItemStack)
            // Paper - destroy this item - if this ever leaks due to game bugs, ensure it doesn't dupe, but don't nuke bukkit stacks of manually added items
            stack.setAmount(0);
    }
    victim.dropExperience();
    return event;
}
Also used : CraftItemStack(org.bukkit.craftbukkit.v1_16_R3.inventory.CraftItemStack) CraftLivingEntity(org.bukkit.craftbukkit.v1_16_R3.entity.CraftLivingEntity) CraftWorld(org.bukkit.craftbukkit.v1_16_R3.CraftWorld)

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