Search in sources :

Example 31 with NbtCompound

use of net.minecraft.nbt.NbtCompound in project FabricWaystones by LordDeatHunter.

the class WaystoneScrollItem method useOnBlock.

@Override
public ActionResult useOnBlock(ItemUsageContext context) {
    if (context.getWorld().getBlockState(context.getBlockPos()).getBlock() instanceof WaystoneBlock && context.getPlayer() != null) {
        HashSet<String> discovered = ((PlayerEntityMixinAccess) context.getPlayer()).getDiscoveredWaystones();
        ItemStack stack = context.getStack();
        if (discovered.isEmpty()) {
            return ActionResult.FAIL;
        }
        NbtCompound tag = new NbtCompound();
        NbtList list = new NbtList();
        for (String hash : discovered) {
            list.add(NbtString.of(hash));
        }
        tag.put("waystones", list);
        stack.setNbt(tag);
    }
    return super.useOnBlock(context);
}
Also used : PlayerEntityMixinAccess(wraith.waystones.access.PlayerEntityMixinAccess) NbtCompound(net.minecraft.nbt.NbtCompound) NbtList(net.minecraft.nbt.NbtList) WaystoneBlock(wraith.waystones.block.WaystoneBlock) NbtString(net.minecraft.nbt.NbtString) ItemStack(net.minecraft.item.ItemStack)

Example 32 with NbtCompound

use of net.minecraft.nbt.NbtCompound in project FabricWaystones by LordDeatHunter.

the class WaystoneScrollItem method appendTooltip.

@Override
public void appendTooltip(ItemStack stack, @Nullable World world, List<Text> tooltip, TooltipContext context) {
    super.appendTooltip(stack, world, tooltip, context);
    NbtCompound tag = stack.getNbt();
    if (tag == null || !tag.contains("waystones")) {
        return;
    }
    int size = tag.getList("waystones", 8).size();
    HashSet<String> waystones = null;
    if (Waystones.WAYSTONE_STORAGE != null) {
        waystones = Waystones.WAYSTONE_STORAGE.getAllHashes();
    } else if (world != null && world.isClient) {
        waystones = ClientStuff.getWaystoneHashes();
    }
    if (waystones != null) {
        tooltip.add(new TranslatableText("waystones.scroll.tooltip", new LiteralText(String.valueOf(size)).styled(style -> style.withColor(TextColor.parse(new TranslatableText("waystones.scroll.tooltip.arg_color").getString())))));
    }
}
Also used : TranslatableText(net.minecraft.text.TranslatableText) NbtCompound(net.minecraft.nbt.NbtCompound) NbtString(net.minecraft.nbt.NbtString) LiteralText(net.minecraft.text.LiteralText)

Example 33 with NbtCompound

use of net.minecraft.nbt.NbtCompound in project BleachHack by BleachDrinker420.

the class ItemContentUtils method getItemsInContainer.

public static List<ItemStack> getItemsInContainer(ItemStack item) {
    List<ItemStack> items = new ArrayList<>(Collections.nCopies(27, new ItemStack(Items.AIR)));
    NbtCompound nbt = item.getOrCreateNbt().contains("BlockEntityTag", 10) ? item.getNbt().getCompound("BlockEntityTag") : item.getNbt();
    if (nbt.contains("Items", 9)) {
        NbtList nbt2 = nbt.getList("Items", 10);
        for (int i = 0; i < nbt2.size(); i++) {
            int slot = nbt2.getCompound(i).contains("Slot", 99) ? nbt2.getCompound(i).getByte("Slot") : i;
            items.set(slot, ItemStack.fromNbt(nbt2.getCompound(i)));
        }
    }
    return items;
}
Also used : NbtCompound(net.minecraft.nbt.NbtCompound) ArrayList(java.util.ArrayList) NbtList(net.minecraft.nbt.NbtList) ItemStack(net.minecraft.item.ItemStack)

Example 34 with NbtCompound

use of net.minecraft.nbt.NbtCompound in project BleachHack by BleachDrinker420.

the class ItemContentUtils method getTextInBook.

public static List<List<String>> getTextInBook(ItemStack item) {
    List<String> pages = new ArrayList<>();
    NbtCompound nbt = item.getNbt();
    if (nbt != null && nbt.contains("pages")) {
        NbtList nbt2 = nbt.getList("pages", 8);
        for (int i = 0; i < nbt2.size(); i++) {
            if (item.getItem() == Items.WRITABLE_BOOK) {
                pages.add(nbt2.getString(i));
            } else {
                Text text = Text.Serializer.fromLenientJson(nbt2.getString(i));
                pages.add(text != null ? text.getString() : nbt2.getString(i));
            }
        }
    }
    List<List<String>> finalPages = new ArrayList<>();
    for (String s : pages) {
        String buffer = "";
        List<String> pageBuffer = new ArrayList<>();
        for (char c : s.toCharArray()) {
            if (MinecraftClient.getInstance().textRenderer.getWidth(buffer) > 114 || buffer.endsWith("\n")) {
                pageBuffer.add(buffer.replace("\n", ""));
                buffer = "";
            }
            buffer += c;
        }
        pageBuffer.add(buffer);
        finalPages.add(pageBuffer);
    }
    return finalPages;
}
Also used : NbtCompound(net.minecraft.nbt.NbtCompound) ArrayList(java.util.ArrayList) NbtList(net.minecraft.nbt.NbtList) Text(net.minecraft.text.Text) List(java.util.List) NbtList(net.minecraft.nbt.NbtList) ArrayList(java.util.ArrayList)

Example 35 with NbtCompound

use of net.minecraft.nbt.NbtCompound in project BleachHack by BleachDrinker420.

the class BookCrash method onTick.

@BleachSubscribe
public void onTick(EventTick event) {
    delay = (delay >= getSetting(2).asSlider().getValue() ? 0 : delay + 1);
    if (delay > 0)
        return;
    ItemStack bookObj = new ItemStack(Items.WRITABLE_BOOK);
    NbtList list = new NbtList();
    NbtCompound tag = new NbtCompound();
    String author = "Bleach";
    String title = "\n Bleachhack Owns All \n";
    String size = "";
    int pages = Math.min(getSetting(4).asSlider().getValueInt(), 100);
    int pageChars = 210;
    if (getSetting(3).asMode().getMode() == 2) {
        IntStream chars = new Random().ints(0x80, 0x10FFFF - 0x800).map(i -> i < 0xd800 ? i : i + 0x800);
        size = chars.limit(pageChars * pages).mapToObj(i -> String.valueOf((char) i)).collect(Collectors.joining());
    } else if (getSetting(3).asMode().getMode() == 1) {
        size = repeat(pages * pageChars, String.valueOf(0x10FFFF));
    } else if (getSetting(3).asMode().getMode() == 0) {
        IntStream chars = new Random().ints(0x20, 0x7E);
        size = chars.limit(pageChars * pages).mapToObj(i -> String.valueOf((char) i)).collect(Collectors.joining());
    } else if (getSetting(3).asMode().getMode() == 3) {
        size = "wveb54yn4y6y6hy6hb54yb5436by5346y3b4yb343yb453by45b34y5by34yb543yb54y5 h3y4h97,i567yb64t5vr2c43rc434v432tvt4tvybn4n6n57u6u57m6m6678mi68,867,79o,o97o,978iun7yb65453v4tyv34t4t3c2cc423rc334tcvtvt43tv45tvt5t5v43tv5345tv43tv5355vt5t3tv5t533v5t45tv43vt4355t54fwveb54yn4y6y6hy6hb54yb5436by5346y3b4yb343yb453by45b34y5by34yb543yb54y5 h3y4h97,i567yb64t5vr2c43rc434v432tvt4tvybn4n6n57u6u57m6m6678mi68,867,79o,o97o,978iun7yb65453v4tyv34t4t3c2cc423rc334tcvtvt43tv45tvt5t5v43tv5345tv43tv5355vt5t3tv5t533v5t45tv43vt4355t54fwveb54yn4y6y6hy6hb54yb5436by5346y3b4yb343yb453by45b34y5by34yb543yb54y5 h3y4h97,i567yb64t5";
    }
    if (getSetting(0).asMode().getMode() == 2) {
        String text = "bh ontop";
        Random rand = new Random();
        for (int i = 0; i < getSetting(1).asSlider().getValue(); i++) {
            mc.player.networkHandler.sendPacket(new UpdateSignC2SPacket(new BlockPos(rand.nextInt(29999999), rand.nextInt(29999999), rand.nextInt(29999999)), text, text, text, text));
        }
    } else {
        for (int i = 0; i < pages; i++) {
            NbtString tString = NbtString.of(size);
            list.add(tString);
        }
        tag.putString("author", author);
        tag.putString("title", title);
        tag.put("pages", list);
        bookObj.setSubNbt("pages", list);
        bookObj.setNbt(tag);
        for (int i = 0; i < getSetting(1).asSlider().getValue(); i++) {
            if (getSetting(0).asMode().getMode() == 0) {
                Int2ObjectMap<ItemStack> map = new Int2ObjectOpenHashMap<>(1);
                map.put(0, bookObj);
                mc.player.networkHandler.sendPacket(new ClickSlotC2SPacket(0, 0, 0, 0, SlotActionType.PICKUP, bookObj, map));
            } else {
                mc.player.networkHandler.sendPacket(new CreativeInventoryActionC2SPacket(0, bookObj));
            }
        }
    }
}
Also used : Int2ObjectOpenHashMap(it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap) NbtCompound(net.minecraft.nbt.NbtCompound) UpdateSignC2SPacket(net.minecraft.network.packet.c2s.play.UpdateSignC2SPacket) NbtString(net.minecraft.nbt.NbtString) NbtString(net.minecraft.nbt.NbtString) ClickSlotC2SPacket(net.minecraft.network.packet.c2s.play.ClickSlotC2SPacket) Random(java.util.Random) NbtList(net.minecraft.nbt.NbtList) BlockPos(net.minecraft.util.math.BlockPos) ItemStack(net.minecraft.item.ItemStack) IntStream(java.util.stream.IntStream) CreativeInventoryActionC2SPacket(net.minecraft.network.packet.c2s.play.CreativeInventoryActionC2SPacket) BleachSubscribe(org.bleachhack.eventbus.BleachSubscribe)

Aggregations

NbtCompound (net.minecraft.nbt.NbtCompound)318 NbtList (net.minecraft.nbt.NbtList)93 ItemStack (net.minecraft.item.ItemStack)69 NbtElement (net.minecraft.nbt.NbtElement)28 IOException (java.io.IOException)25 LiteralText (net.minecraft.text.LiteralText)24 Identifier (net.minecraft.util.Identifier)24 Inject (org.spongepowered.asm.mixin.injection.Inject)21 BlockPos (net.minecraft.util.math.BlockPos)20 NbtString (net.minecraft.nbt.NbtString)16 File (java.io.File)13 HashMap (java.util.HashMap)10 List (java.util.List)9 Text (net.minecraft.text.Text)9 Vec3d (net.minecraft.util.math.Vec3d)9 Map (java.util.Map)8 Items (net.minecraft.item.Items)8 TranslatableText (net.minecraft.text.TranslatableText)8 HashSet (java.util.HashSet)7 BlockEntity (net.minecraft.block.entity.BlockEntity)7