use of net.minecraft.nbt.NBTTagString in project SpongeCommon by SpongePowered.
the class BreakablePlaceableUtils method set.
public static boolean set(ItemStack stack, String nbtKey, Set<BlockType> value) {
NBTTagCompound stackTag = stack.getTagCompound();
if (value.isEmpty()) {
if (stackTag != null) {
stackTag.removeTag(nbtKey);
if (stackTag.hasNoTags()) {
stack.setTagCompound(null);
}
}
} else {
NBTTagList breakableIds = new NBTTagList();
for (BlockType breakable : value) {
String id = breakable.getId();
if (id.startsWith("minecraft:")) {
id = id.substring("minecraft:".length());
}
breakableIds.appendTag(new NBTTagString(id));
}
if (stackTag == null) {
stackTag = new NBTTagCompound();
stack.setTagCompound(stackTag);
}
stackTag.setTag(nbtKey, breakableIds);
}
return true;
}
use of net.minecraft.nbt.NBTTagString in project Geolosys by oitsjustjose.
the class ItemFieldManual method getBook.
@SideOnly(Side.CLIENT)
public ItemStack getBook(Book book) {
NBTTagCompound tags = new NBTTagCompound();
List<NBTTagString> pages = Lists.newArrayList();
FontRenderer fontRenderer = Minecraft.getMinecraft().fontRenderer;
TIntObjectHashMap<String> contents = new TIntObjectHashMap<>();
for (Page page : book.pages) {
StringBuilder sb = new StringBuilder();
String title = page.getTitle();
String text = page.getText();
if (title == null || text == null || title.isEmpty() || text.isEmpty()) {
System.out.println("Well you succ");
break;
}
contents.put(pages.size(), title);
sb.append(TextFormatting.UNDERLINE).append(title).append(TextFormatting.RESET).append("\n\n").append(text);
String formattedString = sb.toString();
List<String> splitStrings = fontRenderer.listFormattedStringToWidth(formattedString, 116);
StringBuilder sb2 = new StringBuilder();
int lineNumber = 0;
for (String s : splitStrings) {
sb2.append(s).append("\n");
lineNumber++;
if (lineNumber >= 13) {
pages.add(new NBTTagString(sb2.toString()));
sb2 = new StringBuilder();
lineNumber = 0;
}
}
if (lineNumber != 0) {
pages.add(new NBTTagString(sb2.toString()));
}
}
final NBTTagList pageList = new NBTTagList();
pageList.appendTag((NBTBase) new NBTTagString(TextFormatting.BOLD + "\n\n\n\n Geolosys\n Field Manual"));
final int offset = 3 + contents.size() / 13;
final int[] keys = contents.keys();
Arrays.sort(keys);
StringBuilder builder3 = new StringBuilder("Contents:\n\n");
int i = 2;
for (final int key : keys) {
String line;
int a;
for (line = contents.get(key), a = key + offset; fontRenderer.listFormattedStringToWidth(line + " " + a, 116).size() > 1; line = line.substring(0, line.length() - 1)) {
;
}
for (line += " "; fontRenderer.listFormattedStringToWidth(line + " " + a, 116).size() == 1; line += " ") {
;
}
line += a;
builder3.append(line).append('\n');
if (++i >= 13) {
i = 0;
pageList.appendTag(new NBTTagString(builder3.toString()));
builder3 = new StringBuilder();
}
}
if (i != 0) {
pageList.appendTag(new NBTTagString(builder3.toString()));
}
for (final NBTTagString page2 : pages) {
pageList.appendTag(page2);
}
tags.setTag("pages", pageList);
tags.setString("title", HelperFunctions.getTranslation("geolosys.field_manual.name"));
tags.setString("author", "oitsjustjose");
final ItemStack stack = new ItemStack(Items.WRITTEN_BOOK);
stack.setTagCompound(tags);
return stack;
}
use of net.minecraft.nbt.NBTTagString in project NyaSamaRailway by NSDN.
the class GuiNGTablet method func_146457_a.
private void func_146457_a(String p_146457_1_) {
if (this.ngtPages != null && this.currPage >= 0 && this.currPage < this.ngtPages.tagCount()) {
this.ngtPages.func_150304_a(this.currPage, new NBTTagString(p_146457_1_));
this.isNotEmpty = true;
}
}
use of net.minecraft.nbt.NBTTagString in project NyaSamaRailway by NSDN.
the class GuiNGTablet method addNewPage.
private void addNewPage() {
if (this.ngtPages != null && this.ngtPages.tagCount() < 50) {
this.ngtPages.appendTag(new NBTTagString(""));
++this.ngtTotalPages;
this.isNotEmpty = true;
}
}
use of net.minecraft.nbt.NBTTagString in project Charset by CharsetMC.
the class TileEntityDayBarrel method writeNBTData.
@Override
public NBTTagCompound writeNBTData(NBTTagCompound compound, boolean isClient) {
ItemUtils.writeToNBT(item, compound, "item");
compound.setInteger("count", item.getCount());
woodLog.writeToNBT(compound, "log");
woodSlab.writeToNBT(compound, "slab");
compound.setByte("dir", (byte) orientation.ordinal());
NBTTagList upgradeNBT = new NBTTagList();
for (BarrelUpgrade u : upgrades) {
upgradeNBT.appendTag(new NBTTagString(u.name()));
}
compound.setTag("upgrades", upgradeNBT);
if (!isClient) {
compound.setTag("lock", lockable.serializeNBT());
}
return compound;
}
Aggregations