Java Code Examples for net.minecraft.nbt.NBTTagString

The following examples show how to use net.minecraft.nbt.NBTTagString. These examples are extracted from open source projects. 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 Project: Kettle   Source File: CraftMetaMap.java    License: GNU General Public License v3.0 6 votes vote down vote up
@Override
void applyToItem(NBTTagCompound tag) {
    super.applyToItem(tag);

    if (hasScaling()) {
        tag.setBoolean(MAP_SCALING.NBT, isScaling());
    }

    if (hasLocationName()) {
        setDisplayTag(tag, MAP_LOC_NAME.NBT, new NBTTagString(getLocationName()));
    }

    if (hasColor()) {
        setDisplayTag(tag, MAP_COLOR.NBT, new NBTTagInt(color.asRGB()));
    }
}
 
Example 2
Source Project: Minecoprocessors   Source File: BookCreator.java    License: GNU General Public License v3.0 6 votes vote down vote up
private static ItemStack loadBook(String name) throws IOException {
  ItemStack book = new ItemStack(Items.WRITTEN_BOOK);
  String line;
  int lineNumber = 1;
  StringBuilder page = newPage();
  try (BufferedReader reader = openBookReader(name)) {
    while ((line = reader.readLine()) != null) {
      if (lineNumber == 1) {
        book.setTagInfo("title", new NBTTagString(line));
      } else if (lineNumber == 2) {
        book.setTagInfo("author", new NBTTagString(line));
      } else if (PAGE_DELIMITER.equals(line)) {
        writePage(book, page);
        page = newPage();
      } else {
        page.append(line).append("\n");
      }
      lineNumber++;
    }
  }
  writePage(book, page);
  return book;
}
 
Example 3
/**
 * Store the data to the specified NBT tag.
 *
 * @param nbt the tag to save the data to.
 */
public void writeToNBT(final NBTTagCompound nbt) {
  final NBTTagList pagesNbt = new NBTTagList();
  int removed = 0;
  for (int index = 0; index < pages.size(); index++) {
    final List<String> program = pages.get(index);
    if (program.size() > 1 || program.get(0).length() > 0) {
      pagesNbt.appendTag(new NBTTagString(String.join("\n", program)));
    } else if (index < selectedPage) {
      removed++;
    }
  }
  nbt.setTag(TAG_PAGES, pagesNbt);

  nbt.setInteger(TAG_SELECTED, selectedPage - removed);
}
 
Example 4
Source Project: ForgeHax   Source File: BookBot.java    License: MIT License 6 votes vote down vote up
private void sendBook(ItemStack stack) {
  NBTTagList pages = new NBTTagList(); // page tag list
  
  // copy pages into NBT
  for (int i = 0; i < MAX_PAGES && parser.hasNext(); i++) {
    pages.appendTag(new NBTTagString(parser.next().trim()));
    page++;
  }
  
  // set our client side book
  if (stack.hasTagCompound()) {
    stack.getTagCompound().setTag("pages", pages);
  } else {
    stack.setTagInfo("pages", pages);
  }
  
  // publish the book
  stack.setTagInfo("author", new NBTTagString(getLocalPlayer().getName()));
  stack.setTagInfo(
      "title",
      new NBTTagString(parent.name.get().replaceAll(NUMBER_TOKEN, "" + getBook()).trim()));
  
  PacketBuffer buff = new PacketBuffer(Unpooled.buffer());
  buff.writeItemStack(stack);
  MC.getConnection().sendPacket(new CPacketCustomPayload("MC|BSign", buff));
}
 
Example 5
Source Project: Wizardry   Source File: SpellUtils.java    License: GNU Lesser General Public License v3.0 6 votes vote down vote up
public static List<List<ModuleInstance>> deserializeModuleList(@Nonnull NBTTagList list) {
	List<List<ModuleInstance>> modules = new ArrayList<>();
	List<ModuleInstance> moduleList = new ArrayList<>();
	for (int i = 0; i < list.tagCount(); i++) {
		NBTBase base = list.get(i);
		if (!(base instanceof NBTTagString)) continue;
		NBTTagString string = (NBTTagString) base;
		if (string.isEmpty()) {
			if (!moduleList.isEmpty())
				modules.add(moduleList);
			moduleList = new ArrayList<>();
		}
		ModuleInstance module = ModuleInstance.deserialize(string);
		if (module == null) continue;
		moduleList.add(module);
	}
	if (!moduleList.isEmpty())
		modules.add(moduleList);
	return modules;
}
 
Example 6
Source Project: pycode-minecraft   Source File: GuiPythonBook.java    License: MIT License 6 votes vote down vote up
private void sendBookToServer() throws IOException {
    if (!this.bookIsModified || this.bookPages == null) {
        return;
    }
    while (this.bookPages.tagCount() > 1) {
        String s = this.bookPages.getStringTagAt(this.bookPages.tagCount() - 1);
        if (!s.trim().isEmpty()) {
            break;
        }
        this.bookPages.removeTag(this.bookPages.tagCount() - 1);
    }
    this.bookObj.setTagInfo("pages", this.bookPages);
    String title = this.bookTitle;
    if (title.equals(TITLE_PLACEHOLDER)) title = "";
    this.bookObj.setTagInfo("title", new NBTTagString(title));

    PacketBuffer packetbuffer = new PacketBuffer(Unpooled.buffer());
    packetbuffer.writeItemStackToBuffer(this.bookObj);
    this.mc.getConnection().sendPacket(new CPacketCustomPayload("MC|BEdit", packetbuffer));
}
 
Example 7
Source Project: Framez   Source File: TileMotor.java    License: GNU General Public License v3.0 6 votes vote down vote up
@Override
public void writeToNBT(NBTTagCompound tag) {

    super.writeToNBT(tag);

    tag.setBoolean("redstoneInput", redstoneInput);

    tag.setInteger("face", getFace().ordinal());

    NBTTagCompound movement = new NBTTagCompound();
    getMovement().writeToNBT(movement);
    tag.setTag("movement", movement);

    NBTTagList l = new NBTTagList();
    for (MotorSetting s : settings)
        l.appendTag(new NBTTagString(s.ordinal() + ""));
    tag.setTag("settings", l);

    tag.setDouble("power", getEnergyBuffer());
}
 
Example 8
Source Project: Framez   Source File: TileMotor.java    License: GNU General Public License v3.0 6 votes vote down vote up
protected void readFromPacketNBT(NBTTagCompound tag) {

        face = ForgeDirection.getOrientation(tag.getInteger("face"));

        getMovement().readFromNBT(tag.getCompoundTag("movement"));

        settings.clear();
        NBTTagList l = tag.getTagList("settings", new NBTTagString().getId());
        for (int i = 0; i < l.tagCount(); i++)
            settings.add(MotorSetting.values()[Integer.parseInt(l.getStringTagAt(i))]);

        blocking = new ArrayList<Vec3i>();
        if (tag.hasKey("blocking")) {
            NBTTagList blocking = tag.getTagList("blocking", new NBTTagCompound().getId());
            for (int i = 0; i < blocking.tagCount(); i++) {
                NBTTagCompound t = blocking.getCompoundTagAt(i);
                this.blocking.add(new Vec3i(t.getInteger("x"), t.getInteger("y"), t.getInteger("z")));
            }
        }

        storedPower = tag.getDouble("power");

        markForRenderUpdate();
    }
 
Example 9
Source Project: Framez   Source File: PartFrame.java    License: GNU General Public License v3.0 6 votes vote down vote up
@Override
public void save(NBTTagCompound tag) {

    if (hidden == null)
        hidden = new boolean[6];

    super.save(tag);

    for (int i = 0; i < 6; i++) {
        tag.setBoolean("hidden_" + i, hidden[i]);
        NBTTagList l = new NBTTagList();
        for (IFrameSideModifier m : getSideModifiers(ForgeDirection.getOrientation(i)))
            l.appendTag(new NBTTagString(m.getType()));
        tag.setTag("sidemods_" + i, l);
    }
}
 
Example 10
Source Project: Framez   Source File: PartFrame.java    License: GNU General Public License v3.0 6 votes vote down vote up
@Override
public void load(NBTTagCompound tag) {

    if (hidden == null)
        hidden = new boolean[6];

    super.load(tag);

    for (int i = 0; i < 6; i++) {
        hidden[i] = tag.getBoolean("hidden_" + i);
        NBTTagList l = tag.getTagList("sidemods_" + i, new NBTTagString().getId());
        Collection<IFrameSideModifier> c = getSideModifiers(ForgeDirection.getOrientation(i));
        c.clear();
        for (int j = 0; j < l.tagCount(); j++)
            c.add((IFrameSideModifier) FrameModifierRegistry.instance().findModifier(l.getStringTagAt(j)));
    }
}
 
Example 11
Source Project: Framez   Source File: ItemPartFrame.java    License: GNU General Public License v3.0 6 votes vote down vote up
@Override
public TMultiPart newPart(ItemStack item, EntityPlayer player, World world, BlockCoord loc, int side, Vector3 hit) {

    NBTTagCompound tag = item.getTagCompound();

    if (tag == null)
        return null;
    if (!tag.hasKey("modifiers"))
        return null;

    NBTTagList l = tag.getTagList("modifiers", new NBTTagString().getId());
    List<IFrameModifier> mods = new ArrayList<IFrameModifier>();
    for (int i = 0; i < l.tagCount(); i++) {
        IFrameModifier mod = FrameModifierRegistry.instance().findModifier(l.getStringTagAt(i));
        if (mod != null)
            mods.add(mod);
    }

    return FrameFactory.createFrame(PartFrame.class, mods);
}
 
Example 12
Source Project: Framez   Source File: ItemPartFrame.java    License: GNU General Public License v3.0 6 votes vote down vote up
@SuppressWarnings({ "rawtypes", "unchecked" })
@Override
public void getSubItems(Item i, CreativeTabs t, List l) {

    for (List<IFrameModifier> mods : FrameModifierRegistry.instance().getAllCombinations(PartFrame.class)) {
        NBTTagList tagList = new NBTTagList();
        for (IFrameModifier mod : mods)
            tagList.appendTag(new NBTTagString(mod.getType()));

        NBTTagCompound tag = new NBTTagCompound();
        tag.setTag("modifiers", tagList);

        ItemStack is = new ItemStack(this);
        is.setTagCompound(tag);
        l.add(is);
    }
}
 
Example 13
Source Project: Framez   Source File: ItemPartFrame.java    License: GNU General Public License v3.0 6 votes vote down vote up
@SuppressWarnings({ "rawtypes", "unchecked" })
@Override
public void addInformation(ItemStack stack, EntityPlayer player, List tip, boolean shift) {

    NBTTagCompound tag = stack.getTagCompound();

    if (tag == null)
        return;
    if (!tag.hasKey("modifiers"))
        return;

    tip.add(I18n.format("tooltip." + ModInfo.MODID + ":modifiers") + ":");

    NBTTagList l = tag.getTagList("modifiers", new NBTTagString().getId());
    for (int i = 0; i < l.tagCount(); i++) {
        String type = l.getStringTagAt(i);
        IFrameModifier mod = FrameModifierRegistry.instance().findModifier(type);
        boolean found = mod != null;

        tip.add((!found ? EnumChatFormatting.RED : "")
                + " - "
                + I18n.format("tooltip." + ModInfo.MODID + ":modifier." + type + ".name")
                + (mod != null && mod instanceof IFrameModifierMaterial ? " ["
                        + I18n.format("tooltip." + ModInfo.MODID + ":modifier.material") + "]" : ""));
    }
}
 
Example 14
Source Project: Framez   Source File: ItemPartFrame.java    License: GNU General Public License v3.0 6 votes vote down vote up
@Override
public String getUnlocalizedName(ItemStack stack) {

    NBTTagCompound tag = stack.getTagCompound();

    if (tag == null)
        return super.getUnlocalizedName(stack);
    if (!tag.hasKey("modifiers"))
        return super.getUnlocalizedName(stack);

    NBTTagList l = tag.getTagList("modifiers", new NBTTagString().getId());
    for (int i = 0; i < l.tagCount(); i++) {
        String type = l.getStringTagAt(i);
        IFrameModifier mod = FrameModifierRegistry.instance().findModifier(type);
        if (mod != null && mod instanceof IFrameModifierMaterial)
            return super.getUnlocalizedName(stack) + "." + type;
    }

    return super.getUnlocalizedName(stack);
}
 
Example 15
Source Project: NBTEdit   Source File: GuiEditNBT.java    License: GNU General Public License v3.0 6 votes vote down vote up
private static void setValidValue(Node<NamedNBT> node, String value){
	NamedNBT named = node.getObject();
	NBTBase base = named.getNBT();
	
	if (base instanceof NBTTagByte)
		named.setNBT(new NBTTagByte(ParseHelper.parseByte(value)));
	if (base instanceof NBTTagShort)
		named.setNBT(new NBTTagShort(ParseHelper.parseShort(value)));
	if (base instanceof NBTTagInt)
		named.setNBT(new NBTTagInt(ParseHelper.parseInt(value)));
	if (base instanceof NBTTagLong)
		named.setNBT(new NBTTagLong(ParseHelper.parseLong(value)));
	if(base instanceof NBTTagFloat)
		named.setNBT(new NBTTagFloat(ParseHelper.parseFloat(value)));
	if(base instanceof NBTTagDouble)
		named.setNBT(new NBTTagDouble(ParseHelper.parseDouble(value)));
	if(base instanceof NBTTagByteArray)
		named.setNBT(new NBTTagByteArray(ParseHelper.parseByteArray(value)));
	if(base instanceof NBTTagIntArray)
		named.setNBT(new NBTTagIntArray(ParseHelper.parseIntArray(value)));
	if (base instanceof NBTTagString)
		named.setNBT(new NBTTagString(value));
}
 
Example 16
public void addOutputsBook(String title, String text, ICommandSender command, String[] astring) {
    ItemStack book = new ItemStack(Items.written_book);
    book.setTagInfo("author", new NBTTagString("Tombenpotter"));
    book.setTagInfo("title", new NBTTagString(title));
    NBTTagCompound nbttagcompound = book.getTagCompound();
    NBTTagList bookPages = new NBTTagList();

    bookPages.appendTag(new NBTTagString(text.substring(0, 237)));
    bookPages.appendTag(new NBTTagString(text.substring(237, 476)));
    bookPages.appendTag(new NBTTagString(text.substring(476, 709)));
    bookPages.appendTag(new NBTTagString(text.substring(709)));

    nbttagcompound.setTag("pages", bookPages);

    System.out.println(text.length());

    if (!command.getEntityWorld().getPlayerEntityByName(command.getCommandSenderName()).inventory.addItemStackToInventory(book))
        command.getEntityWorld().getPlayerEntityByName(command.getCommandSenderName()).entityDropItem(book, 0);
}
 
Example 17
Source Project: minecraft-roguelike   Source File: BookBase.java    License: GNU General Public License v3.0 6 votes vote down vote up
@Override
public ItemStack get(){
	ItemStack book = new ItemStack(Items.WRITTEN_BOOK, 1);
	
	NBTTagList nbtPages = new NBTTagList();
	
	for(String page : this.pages){
		ITextComponent text = new TextComponentString(page);
		String json = ITextComponent.Serializer.componentToJson(text);
		NBTTagString nbtPage = new NBTTagString(json);
		nbtPages.appendTag(nbtPage);
	}
	
	book.setTagInfo("pages", nbtPages);
	book.setTagInfo("author", new NBTTagString(this.author == null ? "Anonymous" : this.author));
	book.setTagInfo("title", new NBTTagString(this.title == null ? "Book" : this.title));
	
	
	return book;
}
 
Example 18
Source Project: seppuku   Source File: SignBookCommand.java    License: GNU General Public License v3.0 5 votes vote down vote up
@Override
public void exec(String input) {
    if (!this.clamp(input, 2, 2)) {
        this.printUsage();
        return;
    }

    final Minecraft mc = Minecraft.getMinecraft();

    if (!mc.player.isCreative()) {
        Seppuku.INSTANCE.errorChat("Creative mode is required to use this command.");
        return;
    }

    final ItemStack itemStack = mc.player.inventory.getCurrentItem();

    final String[] split = input.split(" ");

    if(itemStack.getItem() instanceof ItemWrittenBook) {
        final NBTTagCompound tagCompound = (itemStack.hasTagCompound()) ? itemStack.getTagCompound() : new NBTTagCompound();
        tagCompound.setTag("author", new NBTTagString(split[1]));
        mc.player.connection.sendPacket(new CPacketCreativeInventoryAction(36 + mc.player.inventory.currentItem, itemStack));
        Seppuku.INSTANCE.logChat("Signed book with username " + split[1]);
    }else{
        Seppuku.INSTANCE.errorChat("Please hold a signed book");
    }
}
 
Example 19
@Override
public void readFromNBT(NBTTagCompound compound) {
    super.readFromNBT(compound);
    Material material = Material.MATERIAL_REGISTRY.getObject(compound.getString("Material"));
    this.material = material == null ? Materials.Aluminium : material;

    for (NBTBase undergroundMaterialNBTBase : compound.getTagList("UndergroundMaterials", NBT.TAG_STRING)) {
        undergroundMaterials.add(Material.MATERIAL_REGISTRY.getObject(((NBTTagString) undergroundMaterialNBTBase).getString()));
    }
}
 
Example 20
@Override
public NBTTagCompound writeToNBT(NBTTagCompound compound) {
    super.writeToNBT(compound);
    compound.setString("Material", Material.MATERIAL_REGISTRY.getNameForObject(material));
    NBTTagList tagList = new NBTTagList();
    this.undergroundMaterials.forEach(it ->
        tagList.appendTag(new NBTTagString(Material.MATERIAL_REGISTRY.getNameForObject(it))));
    compound.setTag("UndergroundMaterials", tagList);
    return compound;
}
 
Example 21
Source Project: Kettle   Source File: CraftMetaBookSigned.java    License: GNU General Public License v3.0 5 votes vote down vote up
@Override
void applyToItem(NBTTagCompound itemData) {
    super.applyToItem(itemData, false);

    if (hasTitle()) {
        itemData.setString(BOOK_TITLE.NBT, this.title);
    } else {
        itemData.setString(BOOK_TITLE.NBT, " ");
    }

    if (hasAuthor()) {
        itemData.setString(BOOK_AUTHOR.NBT, this.author);
    } else {
        itemData.setString(BOOK_AUTHOR.NBT, " ");
    }

    if (hasPages()) {
        NBTTagList list = new NBTTagList();
        for (ITextComponent page : pages) {
            list.appendTag(new NBTTagString(
                    ITextComponent.Serializer.componentToJson(page)
            ));
        }
        itemData.setTag(BOOK_PAGES.NBT, list);
    }
    itemData.setBoolean(RESOLVED.NBT, true);

    if (generation != null) {
        itemData.setInteger(GENERATION.NBT, generation);
    } else {
        itemData.setInteger(GENERATION.NBT, 0);
    }
}
 
Example 22
void applyToItem(NBTTagCompound itemData) {
    super.applyToItem(itemData);

    if (hasRecipes()) {
        NBTTagList list = new NBTTagList();
        for (NamespacedKey recipe : this.recipes) {
            list.appendTag(new NBTTagString(recipe.toString()));
        }
        itemData.setTag(BOOK_RECIPES.NBT, list);
    }
}
 
Example 23
Source Project: Kettle   Source File: CraftMetaBook.java    License: GNU General Public License v3.0 5 votes vote down vote up
void applyToItem(NBTTagCompound itemData, boolean handlePages) {
    super.applyToItem(itemData);

    if (hasTitle()) {
        itemData.setString(BOOK_TITLE.NBT, this.title);
    }

    if (hasAuthor()) {
        itemData.setString(BOOK_AUTHOR.NBT, this.author);
    }

    if (handlePages) {
        if (hasPages()) {
            NBTTagList list = new NBTTagList();
            for (ITextComponent page : pages) {
                list.appendTag(new NBTTagString(CraftChatMessage.fromComponent(page)));
            }
            itemData.setTag(BOOK_PAGES.NBT, list);
        }

        itemData.removeTag(RESOLVED.NBT);
    }

    if (generation != null) {
        itemData.setInteger(GENERATION.NBT, generation);
    }
}
 
Example 24
Source Project: ehacks-pro   Source File: NBTStringHelper.java    License: GNU General Public License v3.0 5 votes vote down vote up
public static NBTBase newTag(byte type) {
    switch (type) {
        case 1: {
            return new NBTTagCompound();
        }
        case 2: {
            return new NBTTagByte((byte) 0);
        }
        case 3: {
            return new NBTTagShort();
        }
        case 4: {
            return new NBTTagInt(0);
        }
        case 5: {
            return new NBTTagLong(0L);
        }
        case 6: {
            return new NBTTagFloat(0.0f);
        }
        case 7: {
            return new NBTTagDouble(0.0);
        }
        case 8: {
            return new NBTTagString("");
        }
        case 9: {
            return new NBTTagList();
        }
        case 10: {
            return new NBTTagByteArray(new byte[0]);
        }
        case 11: {
            return new NBTTagIntArray(new int[0]);
        }
    }
    return null;
}
 
Example 25
Source Project: ehacks-pro   Source File: NBTStringHelper.java    License: GNU General Public License v3.0 5 votes vote down vote up
public static String toString(NBTBase base) {
    switch (GuiNBTNode.NBT_ICON_MAPPING[base.getId() - 1]) {
        case 0: {
            return "(TagCompound)";
        }
        case 1: {
            return "" + ((NBTTagByte) base).func_150290_f();
        }
        case 2: {
            return "" + ((NBTTagShort) base).func_150289_e();
        }
        case 3: {
            return "" + ((NBTTagInt) base).func_150287_d();
        }
        case 4: {
            return "" + ((NBTTagLong) base).func_150291_c();
        }
        case 5: {
            return "" + ((NBTTagFloat) base).func_150288_h();
        }
        case 6: {
            return "" + ((NBTTagDouble) base).func_150286_g();
        }
        case 7: {
            return ((NBTTagString) base).func_150285_a_();
        }
        case 8: {
            return "(TagList)";
        }
        case 9: {
            return base.toString();
        }
        case 10: {
            return base.toString();
        }
    }
    return "?";
}
 
Example 26
Source Project: ehacks-pro   Source File: GuiEditSingleNBT.java    License: GNU General Public License v3.0 5 votes vote down vote up
private static void setValidValue(Node<NamedNBT> node, String value) {
    NamedNBT named = node.getObject();
    NBTBase base = named.getNBT();
    if (base instanceof NBTTagByte) {
        named.setNBT(new NBTTagByte(ParseHelper.parseByte(value)));
    }
    if (base instanceof NBTTagShort) {
        named.setNBT(new NBTTagShort(ParseHelper.parseShort(value)));
    }
    if (base instanceof NBTTagInt) {
        named.setNBT(new NBTTagInt(ParseHelper.parseInt(value)));
    }
    if (base instanceof NBTTagLong) {
        named.setNBT(new NBTTagLong(ParseHelper.parseLong(value)));
    }
    if (base instanceof NBTTagFloat) {
        named.setNBT(new NBTTagFloat(ParseHelper.parseFloat(value)));
    }
    if (base instanceof NBTTagDouble) {
        named.setNBT(new NBTTagDouble(ParseHelper.parseDouble(value)));
    }
    if (base instanceof NBTTagByteArray) {
        named.setNBT(new NBTTagByteArray(ParseHelper.parseByteArray(value)));
    }
    if (base instanceof NBTTagIntArray) {
        named.setNBT(new NBTTagIntArray(ParseHelper.parseIntArray(value)));
    }
    if (base instanceof NBTTagString) {
        named.setNBT(new NBTTagString(value));
    }
}
 
Example 27
Source Project: litematica   Source File: ItemUtils.java    License: GNU Lesser General Public License v3.0 5 votes vote down vote up
public static ItemStack storeTEInStack(ItemStack stack, TileEntity te)
{
    NBTTagCompound nbt = te.writeToNBT(new NBTTagCompound());

    if (stack.getItem() == Items.SKULL && nbt.hasKey("Owner"))
    {
        NBTTagCompound tagOwner = nbt.getCompoundTag("Owner");
        NBTTagCompound tagSkull = new NBTTagCompound();

        tagSkull.setTag("SkullOwner", tagOwner);
        stack.setTagCompound(tagSkull);

        return stack;
    }
    else
    {
        NBTTagCompound tagLore = new NBTTagCompound();
        NBTTagList tagList = new NBTTagList();

        tagList.appendTag(new NBTTagString("(+NBT)"));
        tagLore.setTag("Lore", tagList);
        stack.setTagInfo("display", tagLore);
        stack.setTagInfo("BlockEntityTag", nbt);

        return stack;
    }
}
 
Example 28
@Override
public boolean matches(@Nonnull InventoryCrafting inv, @Nonnull World worldIn) {
	ItemStack foundHalo = ItemStack.EMPTY;
	boolean foundGlueStick = false;

	int availableItems = 0;
	for (int i = 0; i < inv.getSizeInventory(); i++) {
		ItemStack stack = inv.getStackInSlot(i);
		if (stack.getItem() == Items.SLIME_BALL) {
			if (foundGlueStick) return false;
			foundGlueStick = true;
		} else if (stack.getItem() == ModItems.FAKE_HALO) {
			if (!foundHalo.isEmpty()) return false;
			foundHalo = stack;
		} else if (HaloInfusionItemRegistry.isHaloInfusionItem(stack))
			availableItems++;
		else if (!stack.isEmpty()) {
			return false;
		}
	}

	if (!foundGlueStick || foundHalo.isEmpty() || availableItems <= 0) return false;

	NBTTagList slots = NBTHelper.getList(foundHalo, "slots", NBTTagString.class);
	if (slots == null) return availableItems <= 7;

	int freeSlots = 0;
	for (int j = 0; j < slots.tagCount(); j++) {
		if (freeSlots >= 7) break;
		String string = slots.getStringTagAt(j);
		HaloInfusionItem infusionItem = HaloInfusionItemRegistry.getItemFromName(string);
		if (infusionItem == HaloInfusionItemRegistry.EMPTY) freeSlots++;
	}

	return freeSlots >= availableItems;
}
 
Example 29
private void setEnemyType(QuestData data, List<String> enemies) {
	NBTTagCompound c = getCustomNbtTag(data);
	NBTTagList list = new NBTTagList();
	for (String enemy : enemies) {
		list.appendTag(new NBTTagString(enemy));
	}
	c.setTag("enemies", list);
}
 
Example 30
Source Project: ToroQuest   Source File: QuestCourier.java    License: GNU General Public License v3.0 5 votes vote down vote up
@Override
public List<ItemStack> accept(QuestData data, List<ItemStack> in) {
	Province deliverToProvince = getDeliverToProvince(data);
	ItemStack note = new ItemStack(Items.PAPER);
	note.setStackDisplayName("Deliver to the Lord of " + deliverToProvince.name);
	note.setTagInfo("toProvince", new NBTTagString(deliverToProvince.id.toString()));
	note.setTagInfo("questId", new NBTTagString(data.getQuestId().toString()));
	in.add(note);
	return in;
}