Search in sources :

Example 6 with net.minecraft.server.v1_12_R1

use of net.minecraft.server.v1_12_R1 in project askyblock by tastybento.

the class NMSHandler method setBook.

@Override
public ItemStack setBook(Tag item) {
    ItemStack chestItem = new ItemStack(Material.WRITTEN_BOOK);
    // Bukkit.getLogger().info(item.toString());
    if (((CompoundTag) item).getValue().containsKey("tag")) {
        Map<String, Tag> contents = (Map<String, Tag>) ((CompoundTag) item).getValue().get("tag").getValue();
        // BookMeta bookMeta = (BookMeta) chestItem.getItemMeta();
        String author = "";
        if (contents.containsKey("author")) {
            author = ((StringTag) contents.get("author")).getValue();
        }
        // Bukkit.getLogger().info("Author: " + author);
        // bookMeta.setAuthor(author);
        String title = "";
        if (contents.containsKey("title")) {
            title = ((StringTag) contents.get("title")).getValue();
        }
        // Bukkit.getLogger().info("Title: " + title);
        // bookMeta.setTitle(title);
        List<String> lore = new ArrayList<String>();
        if (contents.containsKey("display")) {
            Map<String, Tag> display = (Map<String, Tag>) (contents.get("display")).getValue();
            List<Tag> loreTag = ((ListTag) display.get("Lore")).getValue();
            for (Tag s : loreTag) {
                lore.add(((StringTag) s).getValue());
            }
        }
        // Bukkit.getLogger().info("Lore: " + lore);
        net.minecraft.server.v1_12_R1.ItemStack stack = CraftItemStack.asNMSCopy(chestItem);
        // Pages
        // Create the NMS Stack's NBT (item data)
        NBTTagCompound tag = new NBTTagCompound();
        // Set the book's title
        tag.setString("title", title);
        tag.setString("author", author);
        if (contents.containsKey("pages")) {
            NBTTagList pages = new NBTTagList();
            List<Tag> pagesTag = ((ListTag) contents.get("pages")).getValue();
            for (Tag s : pagesTag) {
                pages.add(new NBTTagString(((StringTag) s).getValue()));
            }
            // Add the pages to the tag
            tag.set("pages", pages);
        }
        // Apply the tag to the item
        stack.setTag(tag);
        chestItem = CraftItemStack.asCraftMirror(stack);
        ItemMeta bookMeta = (ItemMeta) chestItem.getItemMeta();
        bookMeta.setLore(lore);
        chestItem.setItemMeta(bookMeta);
    }
    return chestItem;
}
Also used : StringTag(com.wasteofplastic.org.jnbt.StringTag) ArrayList(java.util.ArrayList) NBTTagCompound(net.minecraft.server.v1_12_R1.NBTTagCompound) NBTTagString(net.minecraft.server.v1_12_R1.NBTTagString) ListTag(com.wasteofplastic.org.jnbt.ListTag) NBTTagList(net.minecraft.server.v1_12_R1.NBTTagList) NBTTagString(net.minecraft.server.v1_12_R1.NBTTagString) ListTag(com.wasteofplastic.org.jnbt.ListTag) StringTag(com.wasteofplastic.org.jnbt.StringTag) CompoundTag(com.wasteofplastic.org.jnbt.CompoundTag) Tag(com.wasteofplastic.org.jnbt.Tag) CraftItemStack(org.bukkit.craftbukkit.v1_12_R1.inventory.CraftItemStack) ItemStack(org.bukkit.inventory.ItemStack) HashMap(java.util.HashMap) Map(java.util.Map) ItemMeta(org.bukkit.inventory.meta.ItemMeta)

Example 7 with net.minecraft.server.v1_12_R1

use of net.minecraft.server.v1_12_R1 in project askyblock by tastybento.

the class NMSHandler method isPotion.

/* (non-Javadoc)
     * @see com.wasteofplastic.askyblock.nms.NMSAbstraction#isPotion(org.bukkit.inventory.ItemStack)
     */
@Override
public boolean isPotion(ItemStack item) {
    // Bukkit.getLogger().info("DEBUG:item = " + item);
    if (item.getType().equals(Material.POTION)) {
        net.minecraft.server.v1_12_R1.ItemStack stack = CraftItemStack.asNMSCopy(item);
        NBTTagCompound tag = stack.getTag();
        /*
            for (String list : tag.c()) {
                Bukkit.getLogger().info("DEBUG: list = " + list);
            }*/
        if (tag != null && (!tag.getString("Potion").equalsIgnoreCase("minecraft:water") || tag.getString("Potion").isEmpty())) {
            return true;
        }
    }
    return false;
}
Also used : NBTTagCompound(net.minecraft.server.v1_12_R1.NBTTagCompound)

Example 8 with net.minecraft.server.v1_12_R1

use of net.minecraft.server.v1_12_R1 in project askyblock by tastybento.

the class NMSHandler method getSpawnEgg.

/**
 * Get spawn egg
 * @param type
 * @param amount
 * @return
 */
public ItemStack getSpawnEgg(EntityType type, int amount) {
    // Bukkit.getLogger().info("DEBUG: setting spawn egg " + type.toString());
    ItemStack item = new ItemStack(Material.MONSTER_EGG, amount);
    net.minecraft.server.v1_12_R1.ItemStack stack = CraftItemStack.asNMSCopy(item);
    NBTTagCompound tagCompound = stack.getTag();
    if (tagCompound == null) {
        tagCompound = new NBTTagCompound();
    }
    // Bukkit.getLogger().info("DEBUG: tag = " + tagCompound);
    NBTTagCompound id = new NBTTagCompound();
    if (!bToMConversion.containsKey(type)) {
        id.setString("id", "minecraft:" + type.toString().toLowerCase());
    } else {
        id.setString("id", "minecraft:" + bToMConversion.get(type));
    }
    tagCompound.set("EntityTag", id);
    stack.setTag(tagCompound);
    // Bukkit.getLogger().info("DEBUG: after tag = " + tagCompound);
    return CraftItemStack.asBukkitCopy(stack);
}
Also used : NBTTagCompound(net.minecraft.server.v1_12_R1.NBTTagCompound) CraftItemStack(org.bukkit.craftbukkit.v1_12_R1.inventory.CraftItemStack) ItemStack(org.bukkit.inventory.ItemStack)

Example 9 with net.minecraft.server.v1_12_R1

use of net.minecraft.server.v1_12_R1 in project solinia3-core by mixxit.

the class SoliniaItemFactory method CreateItem.

public static ISoliniaItem CreateItem(ItemStack itemStack, boolean operatorCreated) throws SoliniaItemException, CoreStateInitException {
    SoliniaItem item = new SoliniaItem();
    item.setOperatorCreated(operatorCreated);
    item.setId(StateManager.getInstance().getConfigurationManager().getNextItemId());
    item.setBasename(itemStack.getType().name());
    item.setDisplayname(itemStack.getType().name());
    if (itemStack.getData() != null) {
        try {
            item.setColor(itemStack.getData().getData());
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    if (itemStack.getType().name().equals("SKULL_ITEM")) {
        net.minecraft.server.v1_12_R1.ItemStack stack = CraftItemStack.asNMSCopy(itemStack);
        NBTTagCompound tag = stack.hasTag() ? stack.getTag() : new NBTTagCompound();
        tag.getCompound("SkullOwner").getString("Id");
        String texturevalue = tag.getCompound("SkullOwner").getCompound("Properties").getList("textures", 10).get(0).getString("Value");
        item.setTexturebase64(texturevalue);
    }
    StateManager.getInstance().getConfigurationManager().addItem(item);
    System.out.println("New Item Added: " + item.getId() + " - " + item.getDisplayname());
    return item;
}
Also used : NBTTagCompound(net.minecraft.server.v1_12_R1.NBTTagCompound) ISoliniaItem(com.solinia.solinia.Interfaces.ISoliniaItem) SoliniaItem(com.solinia.solinia.Models.SoliniaItem) CoreStateInitException(com.solinia.solinia.Exceptions.CoreStateInitException) SoliniaItemException(com.solinia.solinia.Exceptions.SoliniaItemException)

Example 10 with net.minecraft.server.v1_12_R1

use of net.minecraft.server.v1_12_R1 in project solinia3-core by mixxit.

the class SoliniaLivingEntity method targetSelector.

public void targetSelector() throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException {
    final net.minecraft.server.v1_12_R1.EntityInsentient e = (net.minecraft.server.v1_12_R1.EntityInsentient) ((org.bukkit.craftbukkit.v1_12_R1.entity.CraftLivingEntity) getBukkitLivingEntity()).getHandle();
    if (!(e instanceof net.minecraft.server.v1_12_R1.EntityCreature) && !(e instanceof net.minecraft.server.v1_12_R1.EntityTameableAnimal))
        return;
    final Field goalsField = net.minecraft.server.v1_12_R1.EntityInsentient.class.getDeclaredField("targetSelector");
    goalsField.setAccessible(true);
    final net.minecraft.server.v1_12_R1.PathfinderGoalSelector goals = (net.minecraft.server.v1_12_R1.PathfinderGoalSelector) goalsField.get(e);
    Field listField = net.minecraft.server.v1_12_R1.PathfinderGoalSelector.class.getDeclaredField("b");
    listField.setAccessible(true);
    Set list = (Set) listField.get(goals);
    list.clear();
    listField = net.minecraft.server.v1_12_R1.PathfinderGoalSelector.class.getDeclaredField("c");
    listField.setAccessible(true);
    list = (Set) listField.get(goals);
    list.clear();
    goals.a(1, (net.minecraft.server.v1_12_R1.PathfinderGoalLookAtPlayer) new net.minecraft.server.v1_12_R1.PathfinderGoalLookAtPlayer(e, (Class) net.minecraft.server.v1_12_R1.EntityHuman.class, 5.0f, 1.0f));
    goals.a(2, (net.minecraft.server.v1_12_R1.PathfinderGoalLookAtPlayer) new net.minecraft.server.v1_12_R1.PathfinderGoalLookAtPlayer(e, (Class) net.minecraft.server.v1_12_R1.EntityHuman.class, 5.0f, 1.0f));
    goals.a(10, (net.minecraft.server.v1_12_R1.PathfinderGoalLookAtPlayer) new net.minecraft.server.v1_12_R1.PathfinderGoalLookAtPlayer(e, (Class) net.minecraft.server.v1_12_R1.EntityHuman.class, 5.0f, 1.0f));
    goals.a(1, new PathfinderGoalOwnerHurtByTarget((EntityTameableAnimal) e));
    goals.a(2, new PathfinderGoalOwnerHurtTarget((EntityTameableAnimal) e));
    goals.a(3, new PathfinderGoalHurtByTarget((EntityCreature) e, true, new Class[0]));
}
Also used : Set(java.util.Set) EntityCreature(net.minecraft.server.v1_12_R1.EntityCreature) EntityTameableAnimal(net.minecraft.server.v1_12_R1.EntityTameableAnimal) Field(java.lang.reflect.Field) EntityTameableAnimal(net.minecraft.server.v1_12_R1.EntityTameableAnimal) PathfinderGoalOwnerHurtTarget(net.minecraft.server.v1_12_R1.PathfinderGoalOwnerHurtTarget) PathfinderGoalOwnerHurtByTarget(net.minecraft.server.v1_12_R1.PathfinderGoalOwnerHurtByTarget) PathfinderGoalHurtByTarget(net.minecraft.server.v1_12_R1.PathfinderGoalHurtByTarget) ISoliniaClass(com.solinia.solinia.Interfaces.ISoliniaClass) EntityCreature(net.minecraft.server.v1_12_R1.EntityCreature)

Aggregations

NBTTagCompound (net.minecraft.server.v1_12_R1.NBTTagCompound)13 CraftItemStack (org.bukkit.craftbukkit.v1_12_R1.inventory.CraftItemStack)6 BlockPosition (net.minecraft.server.v1_12_R1.BlockPosition)5 NBTTagString (net.minecraft.server.v1_12_R1.NBTTagString)5 ItemStack (org.bukkit.inventory.ItemStack)5 CompoundTag (com.wasteofplastic.org.jnbt.CompoundTag)4 ListTag (com.wasteofplastic.org.jnbt.ListTag)4 StringTag (com.wasteofplastic.org.jnbt.StringTag)4 Tag (com.wasteofplastic.org.jnbt.Tag)4 HashMap (java.util.HashMap)4 Map (java.util.Map)4 CraftWorld (org.bukkit.craftbukkit.v1_12_R1.CraftWorld)4 CraftEntity (org.bukkit.craftbukkit.v1_12_R1.entity.CraftEntity)4 ArrayList (java.util.ArrayList)3 AxisAlignedBB (net.minecraft.server.v1_12_R1.AxisAlignedBB)3 NBTTagList (net.minecraft.server.v1_12_R1.NBTTagList)3 ItemMeta (org.bukkit.inventory.meta.ItemMeta)3 CoreStateInitException (com.solinia.solinia.Exceptions.CoreStateInitException)2 IBlockData (net.minecraft.server.v1_12_R1.IBlockData)2 TileEntityFlowerPot (net.minecraft.server.v1_12_R1.TileEntityFlowerPot)2