use of it.unimi.dsi.fastutil.io.FastByteArrayOutputStream in project DynamicSurroundings by OreCruncher.
the class ConfigData method load.
public static ConfigData load() {
final FastByteArrayOutputStream bits = new FastByteArrayOutputStream(16 * 1024);
try (final OutputStreamWriter output = new OutputStreamWriter(new GZIPOutputStream(bits))) {
// We are writing a Json array of objects so start with the open
output.write("[");
boolean prependComma = false;
// Collect the locations where DS data is configured
final List<IMyResourcePack> packs = ResourcePacks.findResourcePacks();
final List<ModContainer> activeMods = Loader.instance().getActiveModList();
// files from the dsurround jar.
for (final ModContainer mod : activeMods) {
final ResourceLocation rl = new ResourceLocation(ModInfo.MOD_ID, "data/" + mod.getModId().toLowerCase() + ".json");
for (final IMyResourcePack p : packs) {
if (p.resourceExists(rl))
prependComma = copy(p, rl, output, "[" + rl.toString() + "] from [" + p.getModName() + "]", prependComma);
}
}
// Get config data from our JAR.
final ResourceLocation rl = ResourcePacks.CONFIGURE_RESOURCE;
for (final IMyResourcePack p : packs) {
if (p.resourceExists(rl))
prependComma = copy(p, rl, output, "[" + rl.toString() + "] from [" + p.getModName() + "]", prependComma);
}
// Built in toggle profiles for turning feature sets on/off
final List<ProfileScript> resources = Profiles.getProfileStreams();
for (final ProfileScript script : resources) {
try (final InputStreamReader reader = new InputStreamReader(script.stream)) {
prependComma = copy(reader, output, script.packName, prependComma);
} catch (@Nonnull final Throwable t) {
ModBase.log().error("Error reading profile script", t);
}
}
// by players or pack makers.
for (final String cfg : ModOptions.general.externalScriptFiles) {
final File file = getFileReference(cfg);
if (file.exists()) {
ModBase.log().info("Loading external configuration script '%s'", cfg);
try (final InputStream stream = new FileInputStream(file)) {
try (final InputStreamReader input = new InputStreamReader(stream)) {
prependComma = copy(input, output, cfg, prependComma);
} catch (final Throwable t) {
ModBase.log().error(String.format("Unable to load configuration script '%s'", cfg), t);
}
} catch (final Throwable t) {
ModBase.log().error(String.format("Unable to load configuration script '%s'", cfg), t);
}
}
}
// The tap - need to close out the json array and flush
// the stream to make sure.
output.write("]");
output.flush();
} catch (@Nonnull final Throwable t) {
ModBase.log().error("Something went horribly wrong", t);
}
// dump(bits.toByteArray());
bits.trim();
return new ConfigData(bits.array);
}
use of it.unimi.dsi.fastutil.io.FastByteArrayOutputStream in project meteor-client by MeteorDevelopment.
the class BookScreenMixin method onInit.
@Inject(method = "init", at = @At("TAIL"))
private void onInit(CallbackInfo info) {
addDrawableChild(new ButtonWidget(4, 4, 120, 20, new LiteralText("Copy"), button -> {
NbtList listTag = new NbtList();
for (int i = 0; i < contents.getPageCount(); i++) listTag.add(NbtString.of(contents.getPage(i).getString()));
NbtCompound tag = new NbtCompound();
tag.put("pages", listTag);
tag.putInt("currentPage", pageIndex);
FastByteArrayOutputStream bytes = new FastByteArrayOutputStream();
DataOutputStream out = new DataOutputStream(bytes);
try {
NbtIo.write(tag, out);
} catch (IOException e) {
e.printStackTrace();
}
GLFW.glfwSetClipboardString(mc.getWindow().getHandle(), Base64.getEncoder().encodeToString(bytes.array));
}));
// Edit title & author
ItemStack itemStack = mc.player.getMainHandStack();
Hand hand = Hand.MAIN_HAND;
if (itemStack.getItem() != Items.WRITTEN_BOOK) {
itemStack = mc.player.getOffHandStack();
hand = Hand.OFF_HAND;
}
if (itemStack.getItem() != Items.WRITTEN_BOOK)
return;
// Fuck you Java
ItemStack book = itemStack;
// Honestly
Hand hand2 = hand;
addDrawableChild(new ButtonWidget(4, 4 + 20 + 2, 120, 20, new LiteralText("Edit title & author"), button -> {
mc.setScreen(new EditBookTitleAndAuthorScreen(GuiThemes.get(), book, hand2));
}));
}
use of it.unimi.dsi.fastutil.io.FastByteArrayOutputStream in project Client by MatHax.
the class BookEditScreenMixin method onInit.
@Inject(method = "init", at = @At("TAIL"))
private void onInit(CallbackInfo info) {
addDrawableChild(new ButtonWidget(4, 4, 120, 20, new LiteralText("Copy"), button -> {
NbtList listTag = new NbtList();
pages.stream().map(NbtString::of).forEach(listTag::add);
NbtCompound tag = new NbtCompound();
tag.put("pages", listTag);
tag.putInt("currentPage", currentPage);
FastByteArrayOutputStream bytes = new FastByteArrayOutputStream();
DataOutputStream out = new DataOutputStream(bytes);
try {
NbtIo.write(tag, out);
} catch (IOException e) {
e.printStackTrace();
}
try {
GLFW.glfwSetClipboardString(mc.getWindow().getHandle(), Base64.getEncoder().encodeToString(bytes.array));
} catch (OutOfMemoryError exception) {
GLFW.glfwSetClipboardString(mc.getWindow().getHandle(), exception.toString());
}
}));
addDrawableChild(new ButtonWidget(4, 4 + 20 + 2, 120, 20, new LiteralText("Paste"), button -> {
String clipboard = GLFW.glfwGetClipboardString(mc.getWindow().getHandle());
if (clipboard == null)
return;
byte[] bytes;
try {
bytes = Base64.getDecoder().decode(clipboard);
} catch (IllegalArgumentException ignored) {
return;
}
DataInputStream in = new DataInputStream(new ByteArrayInputStream(bytes));
try {
NbtCompound tag = NbtIo.read(in);
NbtList listTag = tag.getList("pages", 8).copy();
pages.clear();
for (int i = 0; i < listTag.size(); ++i) {
pages.add(listTag.getString(i));
}
if (pages.isEmpty())
pages.add("");
currentPage = tag.getInt("currentPage");
dirty = true;
updateButtons();
} catch (IOException e) {
e.printStackTrace();
}
}));
}
use of it.unimi.dsi.fastutil.io.FastByteArrayOutputStream in project Client by MatHax.
the class BookScreenMixin method onInit.
@Inject(method = "init", at = @At("TAIL"))
private void onInit(CallbackInfo info) {
addDrawableChild(new ButtonWidget(4, 4, 120, 20, new LiteralText("Copy"), button -> {
NbtList listTag = new NbtList();
for (int i = 0; i < contents.getPageCount(); i++) listTag.add(NbtString.of(contents.getPage(i).getString()));
NbtCompound tag = new NbtCompound();
tag.put("pages", listTag);
tag.putInt("currentPage", pageIndex);
FastByteArrayOutputStream bytes = new FastByteArrayOutputStream();
DataOutputStream out = new DataOutputStream(bytes);
try {
NbtIo.write(tag, out);
} catch (IOException e) {
e.printStackTrace();
}
GLFW.glfwSetClipboardString(mc.getWindow().getHandle(), Base64.getEncoder().encodeToString(bytes.array));
}));
// Edit title & author
ItemStack itemStack = mc.player.getMainHandStack();
Hand hand = Hand.MAIN_HAND;
if (itemStack.getItem() != Items.WRITTEN_BOOK) {
itemStack = mc.player.getOffHandStack();
hand = Hand.OFF_HAND;
}
if (itemStack.getItem() != Items.WRITTEN_BOOK)
return;
// Fuck you Java
ItemStack book = itemStack;
// Honestly
Hand hand2 = hand;
addDrawableChild(new ButtonWidget(4, 4 + 20 + 2, 120, 20, new LiteralText("Edit title & author"), button -> mc.setScreen(new EditBookTitleAndAuthorScreen(GuiThemes.get(), book, hand2))));
}
use of it.unimi.dsi.fastutil.io.FastByteArrayOutputStream in project meteor-client by MeteorDevelopment.
the class BookEditScreenMixin method onInit.
@Inject(method = "init", at = @At("TAIL"))
private void onInit(CallbackInfo info) {
addDrawableChild(new ButtonWidget(4, 4, 120, 20, new LiteralText("Copy"), button -> {
NbtList listTag = new NbtList();
pages.stream().map(NbtString::of).forEach(listTag::add);
NbtCompound tag = new NbtCompound();
tag.put("pages", listTag);
tag.putInt("currentPage", currentPage);
FastByteArrayOutputStream bytes = new FastByteArrayOutputStream();
DataOutputStream out = new DataOutputStream(bytes);
try {
NbtIo.write(tag, out);
} catch (IOException e) {
e.printStackTrace();
}
try {
GLFW.glfwSetClipboardString(mc.getWindow().getHandle(), Base64.getEncoder().encodeToString(bytes.array));
} catch (OutOfMemoryError exception) {
GLFW.glfwSetClipboardString(mc.getWindow().getHandle(), exception.toString());
}
}));
addDrawableChild(new ButtonWidget(4, 4 + 20 + 2, 120, 20, new LiteralText("Paste"), button -> {
String clipboard = GLFW.glfwGetClipboardString(mc.getWindow().getHandle());
if (clipboard == null)
return;
byte[] bytes;
try {
bytes = Base64.getDecoder().decode(clipboard);
} catch (IllegalArgumentException ignored) {
return;
}
DataInputStream in = new DataInputStream(new ByteArrayInputStream(bytes));
try {
NbtCompound tag = NbtIo.read(in);
NbtList listTag = tag.getList("pages", 8).copy();
pages.clear();
for (int i = 0; i < listTag.size(); ++i) {
pages.add(listTag.getString(i));
}
if (pages.isEmpty()) {
pages.add("");
}
currentPage = tag.getInt("currentPage");
dirty = true;
updateButtons();
} catch (IOException e) {
e.printStackTrace();
}
}));
}
Aggregations