use of net.minecraft.nbt.NbtList in project Interdimensional by QuiltServerTools.
the class PortalLinkingStorage method writeNbt.
public NbtCompound writeNbt(NbtCompound tag) {
NbtList links = new NbtList();
portalLinks.keys().asIterator().forEachRemaining(dimKey -> {
portalLinks.get(dimKey).forEach((blockPos, dimensionalBlockPos) -> {
NbtCompound link = new NbtCompound();
link.putString("fromDimID", dimKey.toString());
link.putLong("fromPos", blockPos.asLong());
link.put("to", dimensionalBlockPos.toTag(new NbtCompound()));
links.add(link);
});
});
tag.put("portalLinks", links);
return tag;
}
use of net.minecraft.nbt.NbtList in project Interdimensional by QuiltServerTools.
the class PortalLinkingStorage method fromNbt.
public static PersistentState fromNbt(NbtCompound tag) {
PortalLinkingStorage cman = new PortalLinkingStorage();
NbtList links = (NbtList) tag.get("portalLinks");
for (int i = 0; i < links.size(); i++) {
NbtCompound link = links.getCompound(i);
DimensionalBlockPos toTag = DimensionalBlockPos.fromTag(link.getCompound("to"));
cman.addLink(BlockPos.fromLong(link.getLong("fromPos")), new Identifier(link.getString("fromDimID")), toTag.pos, toTag.dimensionType);
}
return cman;
}
use of net.minecraft.nbt.NbtList in project meteor-utils by kkllffaa.
the class BetterBookBot method writeBook.
private void writeBook(char[] chars) {
if (mc.player == null)
return;
ArrayList<String> pages = new ArrayList<>();
int booklenght = 0;
if (check(chars)) {
toggle();
info("complete");
return;
}
for (int pageI = 0; pageI < 100; pageI++) {
if (check(chars))
break;
if (!filltomax.get() && booklenght >= numberofcharacters.get())
break;
StringBuilder page = new StringBuilder();
for (int lineI = 0; lineI < 13; lineI++) {
if (check(chars))
break;
if (!filltomax.get() && booklenght >= numberofcharacters.get())
break;
double lineWidth = 0;
StringBuilder line = new StringBuilder();
while (true) {
if (check(chars))
break;
if (!filltomax.get() && booklenght >= numberofcharacters.get())
break;
char next = chars[iterator];
iterator++;
booklenght++;
if (next == '\r') {
if (chars.length > iterator && chars[iterator] == '\n')
continue;
break;
}
if (next == '\n')
break;
double charWidth = ((TextHandlerAccessor) mc.textRenderer.getTextHandler()).getWidthRetriever().getWidth(next, Style.EMPTY);
if (lineWidth + charWidth > 114)
break;
line.appendCodePoint(next);
lineWidth += charWidth;
}
page.append(line).append('\n');
}
pages.add(page.toString());
}
if (check(chars)) {
toggle();
info("complete");
}
// Write pages NBT
NbtList pageNbt = new NbtList();
pages.stream().map(NbtString::of).forEach(pageNbt::add);
if (!pages.isEmpty())
mc.player.getMainHandStack().setSubNbt("pages", pageNbt);
mc.player.networkHandler.sendPacket(new BookUpdateC2SPacket(mc.player.getInventory().selectedSlot, pages, sign.get() ? Optional.of(name.get() + (count.get() ? " #" + bookCount : "")) : Optional.empty()));
bookCount++;
if (showiterator.get()) {
MutableText message = new LiteralText("");
message.append(new LiteralText("iterator: ")).append(new LiteralText(String.valueOf(iterator)).setStyle(Style.EMPTY.withFormatting(Formatting.UNDERLINE, Formatting.RED).withClickEvent(new ClickEvent(ClickEvent.Action.COPY_TO_CLIPBOARD, String.valueOf(iterator))).withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new LiteralText("COPY")))));
message.append(new LiteralText(" "));
message.append(new LiteralText("bookcount: ")).append(new LiteralText(String.valueOf(bookCount)).setStyle(Style.EMPTY.withFormatting(Formatting.UNDERLINE, Formatting.RED).withClickEvent(new ClickEvent(ClickEvent.Action.COPY_TO_CLIPBOARD, String.valueOf(bookCount))).withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new LiteralText("COPY")))));
info(message);
}
}
use of net.minecraft.nbt.NbtList in project meteor-utils by kkllffaa.
the class EchestMemoryMixin method save.
@EventHandler
private static void save(GameLeftEvent event) {
if (mc.player == null)
return;
if (getSaveFile() == null)
return;
if (ITEMS.stream().allMatch(ItemStack::isEmpty)) {
getSaveFile().delete();
return;
}
NbtCompound tag = new NbtCompound();
NbtList list = new NbtList();
for (ItemStack stack : ITEMS) {
NbtCompound item = new NbtCompound();
list.add(stack.writeNbt(item));
}
tag.put("items", list);
try {
loc.mkdir();
getSaveFile().getParentFile().mkdir();
getSaveFile().createNewFile();
NbtIo.write(tag, getSaveFile());
} catch (IOException e) {
e.printStackTrace();
}
}
use of net.minecraft.nbt.NbtList in project HWG by cybercat-mods.
the class GrenadeLauncherItem method getProjectiles.
private static List<ItemStack> getProjectiles(ItemStack crossbow) {
List<ItemStack> list = Lists.newArrayList();
NbtCompound NbtCompound = crossbow.getNbt();
if (NbtCompound != null && NbtCompound.contains("ChargedProjectiles", 9)) {
NbtList NbtList = NbtCompound.getList("ChargedProjectiles", 10);
if (NbtList != null) {
for (int i = 0; i < NbtList.size(); ++i) {
NbtCompound NbtCompound2 = NbtList.getCompound(i);
list.add(ItemStack.fromNbt(NbtCompound2));
}
}
}
return list;
}
Aggregations