Java Code Examples for org.bukkit.craftbukkit.inventory.CraftItemStack#asNMSCopy()

The following examples show how to use org.bukkit.craftbukkit.inventory.CraftItemStack#asNMSCopy() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CraftEventFactory.java    From Kettle with GNU General Public License v3.0 6 votes vote down vote up
public static EntityDeathEvent callEntityDeathEvent(EntityLivingBase victim, List<org.bukkit.inventory.ItemStack> drops) {
    CraftLivingEntity entity = (CraftLivingEntity) victim.getBukkitEntity();
    EntityDeathEvent event = new EntityDeathEvent(entity, drops, victim.getExpReward());
    // CraftWorld world = (CraftWorld) entity.getWorld();
    Bukkit.getServer().getPluginManager().callEvent(event);

    victim.expToDrop = event.getDroppedExp();
    // Kettle start - clear captured drops to allow plugins make changes to them
    victim.capturedDrops.clear();
    for (org.bukkit.inventory.ItemStack stack : event.getDrops()) {
        if (stack == null || stack.getType() == Material.AIR || stack.getAmount() == 0) continue;
        net.minecraft.entity.item.EntityItem entityitem = new net.minecraft.entity.item.EntityItem(victim.world, entity.getLocation().getX(), entity.getLocation().getY(), entity.getLocation().getZ(), CraftItemStack.asNMSCopy(stack));
        // world.dropItemNaturally(entity.getLocation(), stack); we don't want this, spawn items in EntityLivingBase.onDeath() (cauldron stuff)
        victim.capturedDrops.add(entityitem);
    }
    // Kettle end
    return event;
}
 
Example 2
Source File: NMSHacks.java    From ProjectAres with GNU Affero General Public License v3.0 6 votes vote down vote up
public static void showFakeItems(Plugin plugin, Player viewer, Location location, org.bukkit.inventory.ItemStack item, int count, Duration duration) {
    if(count <= 0) return;

    final EntityPlayer nmsPlayer = ((CraftPlayer) viewer).getHandle();
    final int[] entityIds = new int[count];

    for(int i = 0; i < count; i++) {
        final EntityItem entity = new EntityItem(nmsPlayer.getWorld(), location.getX(), location.getY(), location.getZ(), CraftItemStack.asNMSCopy(item));

        entity.motX = randomEntityVelocity();
        entity.motY = randomEntityVelocity();
        entity.motZ = randomEntityVelocity();

        sendPacket(viewer, new PacketPlayOutSpawnEntity(entity, ENTITY_TYPE_IDS.get(org.bukkit.entity.Item.class)));
        sendPacket(viewer, new PacketPlayOutEntityMetadata(entity.getId(), entity.getDataWatcher(), true));

        entityIds[i] = entity.getId();
    }

    scheduleEntityDestroy(plugin, viewer.getUniqueId(), duration, entityIds);
}
 
Example 3
Source File: CraftMagicNumbers.java    From Thermos with GNU General Public License v3.0 6 votes vote down vote up
@Override
public ItemStack modifyItemStack(ItemStack stack, String arguments) {
    net.minecraft.item.ItemStack nmsStack = CraftItemStack.asNMSCopy(stack);

    try
    {
        nmsStack.setTagCompound((net.minecraft.nbt.NBTTagCompound) net.minecraft.nbt.JsonToNBT.func_150315_a(arguments));
    }
    catch (net.minecraft.nbt.NBTException e)
    {
        e.printStackTrace();
    }

    stack.setItemMeta(CraftItemStack.getItemMeta(nmsStack));

    return stack;
}
 
Example 4
Source File: CraftWorld.java    From Kettle with GNU General Public License v3.0 5 votes vote down vote up
public Item dropItem(Location loc, ItemStack item) {
    Validate.notNull(item, "Cannot drop a Null item.");
    Validate.isTrue(item.getTypeId() != 0, "Cannot drop AIR.");
    EntityItem entity = new EntityItem(world, loc.getX(), loc.getY(), loc.getZ(), CraftItemStack.asNMSCopy(item));
    entity.pickupDelay = 10;
    world.spawnEntity(entity, SpawnReason.CUSTOM);
    // TODO this is inconsistent with how Entity.getBukkitEntity() works.
    // However, this entity is not at the moment backed by a server entity class so it may be left.
    return new CraftItem(world.getServer(), entity);
}
 
Example 5
Source File: CraftEventFactory.java    From Kettle with GNU General Public License v3.0 5 votes vote down vote up
public static ItemStack callPreCraftEvent(InventoryCrafting matrix, ItemStack result, InventoryView lastCraftView, boolean isRepair) {
    CraftInventoryCrafting inventory = new CraftInventoryCrafting(matrix, matrix.resultInventory);
    inventory.setResult(CraftItemStack.asCraftMirror(result));

    PrepareItemCraftEvent event = new PrepareItemCraftEvent(inventory, lastCraftView, isRepair);
    Bukkit.getPluginManager().callEvent(event);

    org.bukkit.inventory.ItemStack bitem = event.getInventory().getResult();

    return CraftItemStack.asNMSCopy(bitem);
}
 
Example 6
Source File: CraftMagicNumbers.java    From Kettle with GNU General Public License v3.0 5 votes vote down vote up
@Override
public ItemStack modifyItemStack(ItemStack stack, String arguments) {
    net.minecraft.item.ItemStack nmsStack = CraftItemStack.asNMSCopy(stack);

    try {
        nmsStack.setTagCompound((NBTTagCompound) JsonToNBT.getTagFromJson(arguments));
    } catch (NBTException ex) {
        Logger.getLogger(CraftMagicNumbers.class.getName()).log(Level.SEVERE, null, ex);
    }

    stack.setItemMeta(CraftItemStack.getItemMeta(nmsStack));

    return stack;
}
 
Example 7
Source File: NMSHacks.java    From ProjectAres with GNU Affero General Public License v3.0 5 votes vote down vote up
static ItemStack asNMS(org.bukkit.inventory.ItemStack bukkit) {
    if(bukkit instanceof CraftItemStack) {
        return ((CraftItemStack) bukkit).getHandle();
    } else {
        return CraftItemStack.asNMSCopy(bukkit);
    }
}
 
Example 8
Source File: CraftHumanEntity.java    From Thermos with GNU General Public License v3.0 5 votes vote down vote up
public void setItemOnCursor(ItemStack item) {
    net.minecraft.item.ItemStack stack = CraftItemStack.asNMSCopy(item);
    getHandle().inventory.setItemStack(stack);
    if (this instanceof CraftPlayer) {
        ((net.minecraft.entity.player.EntityPlayerMP) getHandle()).updateHeldItem(); // Send set slot for cursor
    }
}
 
Example 9
Source File: CraftThrownPotion.java    From Thermos with GNU General Public License v3.0 5 votes vote down vote up
public void setItem(ItemStack item) {
    // The ItemStack must not be null.
    Validate.notNull(item, "ItemStack cannot be null.");

    // The ItemStack must be a potion.
    Validate.isTrue(item.getType() == Material.POTION, "ItemStack must be a potion. This item stack was " + item.getType() + ".");

    getHandle().potionDamage = CraftItemStack.asNMSCopy(item);
}
 
Example 10
Source File: NMSHacks.java    From ProjectAres with GNU Affero General Public License v3.0 4 votes vote down vote up
public static Packet entityHelmetPacket(int entityId, org.bukkit.inventory.ItemStack helmet) {
    return new PacketPlayOutEntityEquipment(entityId, EnumItemSlot.HEAD, CraftItemStack.asNMSCopy(helmet));
}
 
Example 11
Source File: CraftLivingEntity.java    From Thermos with GNU General Public License v3.0 4 votes vote down vote up
@SuppressWarnings("unchecked")
public <T extends Projectile> T launchProjectile(Class<? extends T> projectile, Vector velocity) {
    net.minecraft.world.World world = ((CraftWorld) getWorld()).getHandle();
    net.minecraft.entity.Entity launch = null;

    if (Snowball.class.isAssignableFrom(projectile)) {
        launch = new net.minecraft.entity.projectile.EntitySnowball(world, getHandle());
    } else if (Egg.class.isAssignableFrom(projectile)) {
        launch = new net.minecraft.entity.projectile.EntityEgg(world, getHandle());
    } else if (EnderPearl.class.isAssignableFrom(projectile)) {
        launch = new net.minecraft.entity.item.EntityEnderPearl(world, getHandle());
    } else if (Arrow.class.isAssignableFrom(projectile)) {
        launch = new net.minecraft.entity.projectile.EntityArrow(world, getHandle(), 1);
    } else if (ThrownPotion.class.isAssignableFrom(projectile)) {
        launch = new net.minecraft.entity.projectile.EntityPotion(world, getHandle(), CraftItemStack.asNMSCopy(new ItemStack(Material.POTION, 1)));
    } else if (ThrownExpBottle.class.isAssignableFrom(projectile)) {
        launch = new net.minecraft.entity.item.EntityExpBottle(world, getHandle());
    } else if (Fish.class.isAssignableFrom(projectile) && getHandle() instanceof net.minecraft.entity.player.EntityPlayer) {
        launch = new net.minecraft.entity.projectile.EntityFishHook(world, (net.minecraft.entity.player.EntityPlayer) getHandle());
    } else if (Fireball.class.isAssignableFrom(projectile)) {
        Location location = getEyeLocation();
        Vector direction = location.getDirection().multiply(10);

        if (SmallFireball.class.isAssignableFrom(projectile)) {
            launch = new net.minecraft.entity.projectile.EntitySmallFireball(world, getHandle(), direction.getX(), direction.getY(), direction.getZ());
        } else if (WitherSkull.class.isAssignableFrom(projectile)) {
            launch = new net.minecraft.entity.projectile.EntityWitherSkull(world, getHandle(), direction.getX(), direction.getY(), direction.getZ());
        } else {
            launch = new net.minecraft.entity.projectile.EntityLargeFireball(world, getHandle(), direction.getX(), direction.getY(), direction.getZ());
        }

        ((net.minecraft.entity.projectile.EntityFireball) launch).projectileSource = this;
        launch.setLocationAndAngles(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch());
    }

    Validate.notNull(launch, "Projectile not supported");

    if (velocity != null) {
        ((T) launch.getBukkitEntity()).setVelocity(velocity);
    }

    world.spawnEntityInWorld(launch);
    return (T) launch.getBukkitEntity();
}