本文整理汇总了Java中net.minecraft.nbt.NBTTagString类的典型用法代码示例。如果您正苦于以下问题:Java NBTTagString类的具体用法?Java NBTTagString怎么用?Java NBTTagString使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
NBTTagString类属于net.minecraft.nbt包,在下文中一共展示了NBTTagString类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: loadBook
import net.minecraft.nbt.NBTTagString; //导入依赖的package包/类
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;
}
示例2: writeToNBT
import net.minecraft.nbt.NBTTagString; //导入依赖的package包/类
/**
* 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);
}
示例3: playerJoin
import net.minecraft.nbt.NBTTagString; //导入依赖的package包/类
@SubscribeEvent
public void playerJoin(PlayerEvent.PlayerLoggedInEvent event) {
ItemStack guideBookStack = new ItemStack(Items.WRITTEN_BOOK, 1);
NBTTagCompound nbt = new NBTTagCompound();
nbt.setString("title", new TextComponentTranslation("book.title.guide").getFormattedText());
nbt.setString("author", new TextComponentTranslation("book.author.guide").getFormattedText());
nbt.setInteger("generation", 2);
NBTTagList nbtList = new NBTTagList();
for (int index = 0; index <= 15; index++)
nbtList.appendTag(new NBTTagString(String.format("{\"text\": \"%s\"}", new TextComponentTranslation(String.format("book.pages.guide.%d", index)).getFormattedText())));
nbt.setTag("pages", nbtList);
guideBookStack.setTagCompound(nbt);
if (!event.player.getEntityData().getBoolean("genera.joined_before")) {
event.player.getEntityData().setBoolean("genera.joined_before", true);
event.player.getEntityData().setInteger("genera.sacrifices_made", 0);
event.player.addItemStackToInventory(guideBookStack);
}
}
示例4: readDataNBT
import net.minecraft.nbt.NBTTagString; //导入依赖的package包/类
@Override
protected void readDataNBT(NBTTagCompound tag) {
cooldown = tag.getInteger("cooldown");
if (tag.hasKey("ritual"))
ritual = Ritual.REGISTRY.getValue(new ResourceLocation(tag.getString("ritual")));
if (tag.hasKey("player"))
entityPlayer = UUID.fromString(tag.getString("player"));
if (tag.hasKey("data"))
ritualData = tag.getCompoundTag("data");
if (tag.hasKey("entityList")) {
entityList = new ArrayList<Tuple<String, String>>();
tag.getTagList("entityList", NBT.TAG_STRING).forEach(nbts -> {
String[] names = ((NBTTagString) nbts).getString().split("!");
if (names.length == 2)
entityList.add(new Tuple<String, String>(names[0], names[1]));
});
}
}
示例5: writeDataNBT
import net.minecraft.nbt.NBTTagString; //导入依赖的package包/类
@Override
protected void writeDataNBT(NBTTagCompound tag) {
tag.setInteger("cooldown", cooldown);
if (ritual != null)
tag.setString("ritual", ritual.getRegistryName().toString());
if (entityPlayer != null)
tag.setString("player", entityPlayer.toString());
if (ritualData != null)
tag.setTag("data", ritualData);
NBTTagList list = new NBTTagList();
for (int i = 0; i < entityList.size(); i++) {
Tuple<String, String> t = entityList.get(i);
list.appendTag(new NBTTagString(t.getFirst() + "!" + t.getSecond()));
}
tag.setTag("entityList", list);
}
示例6: getActionsSaveData
import net.minecraft.nbt.NBTTagString; //导入依赖的package包/类
private NBTTagList getActionsSaveData()
{
NBTTagList actionList = new NBTTagList();
for (Map.Entry<Integer, Set<String>> entry : actionPoints.entrySet())
{
int time = entry.getKey();
NBTTagList nameList = new NBTTagList();
for (String name : entry.getValue())
{
nameList.appendTag(new NBTTagString(name));
}
NBTTagCompound timeCompound = new NBTTagCompound();
timeCompound.setInteger("Time", time);
timeCompound.setTag("Names", nameList);
actionList.appendTag(timeCompound);
}
return actionList;
}
示例7: sendBook
import net.minecraft.nbt.NBTTagString; //导入依赖的package包/类
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));
}
示例8: func_181036_a
import net.minecraft.nbt.NBTTagString; //导入依赖的package包/类
private ItemStack func_181036_a(Item p_181036_1_, int p_181036_2_, TileEntity p_181036_3_)
{
ItemStack itemstack = new ItemStack(p_181036_1_, 1, p_181036_2_);
NBTTagCompound nbttagcompound = new NBTTagCompound();
p_181036_3_.writeToNBT(nbttagcompound);
if (p_181036_1_ == Items.skull && nbttagcompound.hasKey("Owner"))
{
NBTTagCompound nbttagcompound2 = nbttagcompound.getCompoundTag("Owner");
NBTTagCompound nbttagcompound3 = new NBTTagCompound();
nbttagcompound3.setTag("SkullOwner", nbttagcompound2);
itemstack.setTagCompound(nbttagcompound3);
return itemstack;
}
else
{
itemstack.setTagInfo("BlockEntityTag", nbttagcompound);
NBTTagCompound nbttagcompound1 = new NBTTagCompound();
NBTTagList nbttaglist = new NBTTagList();
nbttaglist.appendTag(new NBTTagString("(+NBT)"));
nbttagcompound1.setTag("Lore", nbttaglist);
itemstack.setTagInfo("display", nbttagcompound1);
return itemstack;
}
}
示例9: call
import net.minecraft.nbt.NBTTagString; //导入依赖的package包/类
@Override
public void call(String[] args) throws CmdException
{
if(args.length == 0)
throw new CmdSyntaxError();
if(!WMinecraft.getPlayer().capabilities.isCreativeMode)
throw new CmdError("Creative mode only.");
ItemStack item = WMinecraft.getPlayer().inventory.getCurrentItem();
if(item == null || Item.getIdFromItem(item.getItem()) != 387)
throw new CmdError(
"You are not holding a written book in your hand.");
String author = args[0];
for(int i = 1; i < args.length; i++)
author += " " + args[i];
item.setTagInfo("author", new NBTTagString(author));
}
示例10: func_181036_a
import net.minecraft.nbt.NBTTagString; //导入依赖的package包/类
private ItemStack func_181036_a(Item p_181036_1_, int p_181036_2_, TileEntity p_181036_3_) {
ItemStack itemstack = new ItemStack(p_181036_1_, 1, p_181036_2_);
NBTTagCompound nbttagcompound = new NBTTagCompound();
p_181036_3_.writeToNBT(nbttagcompound);
if (p_181036_1_ == Items.skull && nbttagcompound.hasKey("Owner")) {
NBTTagCompound nbttagcompound2 = nbttagcompound.getCompoundTag("Owner");
NBTTagCompound nbttagcompound3 = new NBTTagCompound();
nbttagcompound3.setTag("SkullOwner", nbttagcompound2);
itemstack.setTagCompound(nbttagcompound3);
return itemstack;
} else {
itemstack.setTagInfo("BlockEntityTag", nbttagcompound);
NBTTagCompound nbttagcompound1 = new NBTTagCompound();
NBTTagList nbttaglist = new NBTTagList();
nbttaglist.appendTag(new NBTTagString("(+NBT)"));
nbttagcompound1.setTag("Lore", nbttaglist);
itemstack.setTagInfo("display", nbttagcompound1);
return itemstack;
}
}
示例11: storeTEInStack
import net.minecraft.nbt.NBTTagString; //导入依赖的package包/类
private ItemStack storeTEInStack(ItemStack stack, TileEntity te)
{
NBTTagCompound nbttagcompound = te.writeToNBT(new NBTTagCompound());
if (stack.getItem() == Items.SKULL && nbttagcompound.hasKey("Owner"))
{
NBTTagCompound nbttagcompound2 = nbttagcompound.getCompoundTag("Owner");
NBTTagCompound nbttagcompound3 = new NBTTagCompound();
nbttagcompound3.setTag("SkullOwner", nbttagcompound2);
stack.setTagCompound(nbttagcompound3);
return stack;
}
else
{
stack.setTagInfo("BlockEntityTag", nbttagcompound);
NBTTagCompound nbttagcompound1 = new NBTTagCompound();
NBTTagList nbttaglist = new NBTTagList();
nbttaglist.appendTag(new NBTTagString("(+NBT)"));
nbttagcompound1.setTag("Lore", nbttaglist);
stack.setTagInfo("display", nbttagcompound1);
return stack;
}
}
示例12: GuiScreenBook
import net.minecraft.nbt.NBTTagString; //导入依赖的package包/类
public GuiScreenBook(EntityPlayer player, ItemStack book, boolean isUnsigned)
{
this.editingPlayer = player;
this.bookObj = book;
this.bookIsUnsigned = isUnsigned;
if (book.hasTagCompound())
{
NBTTagCompound nbttagcompound = book.getTagCompound();
this.bookPages = nbttagcompound.getTagList("pages", 8).copy();
this.bookTotalPages = this.bookPages.tagCount();
if (this.bookTotalPages < 1)
{
this.bookTotalPages = 1;
}
}
if (this.bookPages == null && isUnsigned)
{
this.bookPages = new NBTTagList();
this.bookPages.appendTag(new NBTTagString(""));
this.bookTotalPages = 1;
}
}
示例13: storeTEInStack
import net.minecraft.nbt.NBTTagString; //导入依赖的package包/类
public ItemStack storeTEInStack(ItemStack stack, TileEntity te)
{
NBTTagCompound nbttagcompound = te.writeToNBT(new NBTTagCompound());
if (stack.getItem() == Items.SKULL && nbttagcompound.hasKey("Owner"))
{
NBTTagCompound nbttagcompound2 = nbttagcompound.getCompoundTag("Owner");
NBTTagCompound nbttagcompound3 = new NBTTagCompound();
nbttagcompound3.setTag("SkullOwner", nbttagcompound2);
stack.setTagCompound(nbttagcompound3);
return stack;
}
else
{
stack.setTagInfo("BlockEntityTag", nbttagcompound);
NBTTagCompound nbttagcompound1 = new NBTTagCompound();
NBTTagList nbttaglist = new NBTTagList();
nbttaglist.appendTag(new NBTTagString("(+NBT)"));
nbttagcompound1.setTag("Lore", nbttaglist);
stack.setTagInfo("display", nbttagcompound1);
return stack;
}
}
示例14: addLore
import net.minecraft.nbt.NBTTagString; //导入依赖的package包/类
public static ItemStack addLore(final ItemStack a, final String... lore) {
NBTTagCompound tag = a.getTagCompound();
if (tag == null) {
tag = new NBTTagCompound();
}
if (!tag.hasKey("display", 10)) {
tag.setTag("display", (NBTBase)new NBTTagCompound());
}
final NBTTagList l = new NBTTagList();
for (final String s : lore) {
l.appendTag((NBTBase)new NBTTagString(s));
}
tag.getCompoundTag("display").setTag("Lore", (NBTBase)l);
a.setTagCompound(tag);
return a;
}
示例15: storeTEInStack
import net.minecraft.nbt.NBTTagString; //导入依赖的package包/类
/**
* Originally copied from {@link Minecraft#storeTEInStack(ItemStack, TileEntity)}
*
*/
private static ItemStack storeTEInStack(ItemStack stack, NBTTagCompound nbttagcompound) {
if (stack.getItem() == Items.SKULL && nbttagcompound.hasKey("Owner")) {
NBTTagCompound nbttagcompound2 = nbttagcompound.getCompoundTag("Owner");
NBTTagCompound nbttagcompound3 = new NBTTagCompound();
nbttagcompound3.setTag("SkullOwner", nbttagcompound2);
stack.setTagCompound(nbttagcompound3);
return stack;
} else {
stack.setTagInfo("BlockEntityTag", nbttagcompound);
if (stack.isStackable()) {
NBTTagCompound nbttagcompound1 = new NBTTagCompound();
NBTTagList nbttaglist = new NBTTagList();
nbttaglist.appendTag(new NBTTagString("(+NBT)"));
nbttagcompound1.setTag("Lore", nbttaglist);
stack.setTagInfo("display", nbttagcompound1);
}
return stack;
}
}