use of net.minecraft.nbt.NbtList in project HWG by cybercat-mods.
the class FlareGunItem method clearProjectiles.
private static void clearProjectiles(ItemStack crossbow) {
NbtCompound NbtCompound = crossbow.getNbt();
if (NbtCompound != null) {
NbtList NbtList = NbtCompound.getList("ChargedProjectiles", 9);
NbtList.clear();
NbtCompound.put("ChargedProjectiles", NbtList);
}
}
use of net.minecraft.nbt.NbtList in project HWG by cybercat-mods.
the class FlareGunItem 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;
}
use of net.minecraft.nbt.NbtList in project alaskanativecraft by Platymemo.
the class AkutaqRecipe method addEffectToAkutaq.
// Can't use SuspiciousStewItem.addEffectToStew because it overwrites the list tag each time
public static void addEffectToAkutaq(@NotNull ItemStack stew, StatusEffect effect, int duration) {
NbtCompound compoundTag = stew.getOrCreateNbt();
NbtList listTag = compoundTag.getList("Effects", 10);
boolean effectExists = false;
byte effectId = (byte) StatusEffect.getRawId(effect);
int actualDuration = duration;
for (int i = 0; i < listTag.size(); ++i) {
NbtCompound previousEffect = listTag.getCompound(i);
if (previousEffect.contains("EffectDuration", 3) && effectId == previousEffect.getByte("EffectId")) {
actualDuration += previousEffect.getInt("EffectDuration");
previousEffect.putInt("EffectDuration", actualDuration);
effectExists = true;
}
}
if (!effectExists) {
NbtCompound newEffect = new NbtCompound();
newEffect.putByte("EffectId", effectId);
newEffect.putInt("EffectDuration", actualDuration);
listTag.add(newEffect);
}
compoundTag.put("Effects", listTag);
}
use of net.minecraft.nbt.NbtList 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 net.minecraft.nbt.NbtList 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))));
}
Aggregations