Search in sources :

Example 16 with NbtCompound

use of net.minecraft.nbt.NbtCompound in project Primeval by devs-immortal.

the class VesselItem method addToBundle.

private static int addToBundle(ItemStack bundle, ItemStack stack) {
    if (!stack.isEmpty() && stack.getItem().canBeNested() && canAddItem(bundle)) {
        NbtCompound nbtCompound = bundle.getOrCreateNbt();
        if (!nbtCompound.contains("Items")) {
            nbtCompound.put("Items", new NbtList());
        }
        int i = getBundleOccupancy(bundle);
        int j = getItemOccupancy(stack);
        int k = Math.min(stack.getCount(), (64 - i) / j);
        if (k == 0) {
            return 0;
        } else {
            NbtList nbtList = nbtCompound.getList("Items", 10);
            Optional<NbtCompound> optional = canMergeStack(stack, nbtList);
            if (optional.isPresent()) {
                NbtCompound nbtCompound2 = optional.get();
                ItemStack itemStack = ItemStack.fromNbt(nbtCompound2);
                itemStack.increment(k);
                itemStack.writeNbt(nbtCompound2);
                nbtList.remove(nbtCompound2);
                nbtList.add(0, nbtCompound2);
            } else {
                ItemStack nbtCompound2 = stack.copy();
                nbtCompound2.setCount(k);
                NbtCompound itemStack = new NbtCompound();
                nbtCompound2.writeNbt(itemStack);
                nbtList.add(0, itemStack);
            }
            return k;
        }
    } else {
        return 0;
    }
}
Also used : NbtCompound(net.minecraft.nbt.NbtCompound) NbtList(net.minecraft.nbt.NbtList) ItemStack(net.minecraft.item.ItemStack)

Example 17 with NbtCompound

use of net.minecraft.nbt.NbtCompound in project meteor-rejects by AntiCope.

the class ChatBot method fromTag.

@Override
public Module fromTag(NbtCompound tag) {
    commands.clear();
    if (tag.contains("commands")) {
        NbtCompound msgs = tag.getCompound("commands");
        msgs.getKeys().forEach((key) -> {
            commands.put(key, msgs.getString(key));
        });
    }
    return super.fromTag(tag);
}
Also used : NbtCompound(net.minecraft.nbt.NbtCompound)

Example 18 with NbtCompound

use of net.minecraft.nbt.NbtCompound in project meteor-rejects by AntiCope.

the class NewChunks method onReadPacket.

@EventHandler
private void onReadPacket(PacketEvent.Receive event) {
    if (event.packet instanceof ChunkDeltaUpdateS2CPacket) {
        ChunkDeltaUpdateS2CPacket packet = (ChunkDeltaUpdateS2CPacket) event.packet;
        packet.visitUpdates((pos, state) -> {
            if (!state.getFluidState().isEmpty() && !state.getFluidState().isStill()) {
                ChunkPos chunkPos = new ChunkPos(pos);
                for (Direction dir : searchDirs) {
                    if (mc.world.getBlockState(pos.offset(dir)).getFluidState().isStill() && !oldChunks.contains(chunkPos)) {
                        newChunks.add(chunkPos);
                        return;
                    }
                }
            }
        });
    } else if (event.packet instanceof BlockUpdateS2CPacket) {
        BlockUpdateS2CPacket packet = (BlockUpdateS2CPacket) event.packet;
        if (!packet.getState().getFluidState().isEmpty() && !packet.getState().getFluidState().isStill()) {
            ChunkPos chunkPos = new ChunkPos(packet.getPos());
            for (Direction dir : searchDirs) {
                if (mc.world.getBlockState(packet.getPos().offset(dir)).getFluidState().isStill() && !oldChunks.contains(chunkPos)) {
                    newChunks.add(chunkPos);
                    return;
                }
            }
        }
    } else if (event.packet instanceof ChunkDataS2CPacket && mc.world != null) {
        ChunkDataS2CPacket packet = (ChunkDataS2CPacket) event.packet;
        ChunkPos pos = new ChunkPos(packet.getX(), packet.getZ());
        if (!newChunks.contains(pos) && mc.world.getChunkManager().getChunk(packet.getX(), packet.getZ()) == null) {
            WorldChunk chunk = new WorldChunk(mc.world, pos);
            try {
                chunk.loadFromPacket(packet.getChunkData().getSectionsDataBuf(), new NbtCompound(), packet.getChunkData().getBlockEntities(packet.getX(), packet.getZ()));
            } catch (ArrayIndexOutOfBoundsException e) {
                return;
            }
            for (int x = 0; x < 16; x++) {
                for (int y = mc.world.getBottomY(); y < mc.world.getTopY(); y++) {
                    for (int z = 0; z < 16; z++) {
                        FluidState fluid = chunk.getFluidState(x, y, z);
                        if (!fluid.isEmpty() && !fluid.isStill()) {
                            oldChunks.add(pos);
                            return;
                        }
                    }
                }
            }
        }
    }
}
Also used : NbtCompound(net.minecraft.nbt.NbtCompound) WorldChunk(net.minecraft.world.chunk.WorldChunk) FluidState(net.minecraft.fluid.FluidState) EventHandler(meteordevelopment.orbit.EventHandler)

Example 19 with NbtCompound

use of net.minecraft.nbt.NbtCompound in project meteor-rejects by AntiCope.

the class HeadScreen method createHeadStack.

private ItemStack createHeadStack(String uuid, String value, String name) {
    ItemStack head = Items.PLAYER_HEAD.getDefaultStack();
    NbtCompound tag = new NbtCompound();
    NbtCompound skullOwner = new NbtCompound();
    skullOwner.putUuid("Id", UUID.fromString(uuid));
    NbtCompound properties = new NbtCompound();
    NbtList textures = new NbtList();
    NbtCompound Value = new NbtCompound();
    Value.putString("Value", value);
    textures.add(Value);
    properties.put("textures", textures);
    skullOwner.put("Properties", properties);
    tag.put("SkullOwner", skullOwner);
    head.setNbt(tag);
    head.setCustomName(new LiteralText(name));
    return head;
}
Also used : NbtCompound(net.minecraft.nbt.NbtCompound) NbtList(net.minecraft.nbt.NbtList) ItemStack(net.minecraft.item.ItemStack) LiteralText(net.minecraft.text.LiteralText)

Example 20 with NbtCompound

use of net.minecraft.nbt.NbtCompound in project meteor-rejects by AntiCope.

the class LocateCommand method build.

@Override
public void build(LiteralArgumentBuilder<CommandSource> builder) {
    builder.then(literal("lodestone").executes(ctx -> {
        ItemStack stack = mc.player.getInventory().getMainHandStack();
        if (stack.getItem() != Items.COMPASS) {
            error("You need to hold a lodestone compass");
            return SINGLE_SUCCESS;
        }
        NbtCompound tag = stack.getNbt();
        if (tag == null) {
            error("Couldn't get the NBT data. Are you holding a (highlight)lodestone(default) compass?");
            return SINGLE_SUCCESS;
        }
        NbtCompound nbt1 = tag.getCompound("LodestonePos");
        if (nbt1 == null) {
            error("Couldn't get the NBT data. Are you holding a (highlight)lodestone(default) compass?");
            return SINGLE_SUCCESS;
        }
        Vec3d coords = new Vec3d(nbt1.getDouble("X"), nbt1.getDouble("Y"), nbt1.getDouble("Z"));
        BaseText text = new LiteralText("Lodestone located at ");
        text.append(ChatUtils.formatCoords(coords));
        text.append(".");
        info(text);
        return SINGLE_SUCCESS;
    }));
    builder.then(argument("feature", EnumArgumentType.enumArgument(WorldGenUtils.Feature.stronghold)).executes(ctx -> {
        WorldGenUtils.Feature feature = EnumArgumentType.getEnum(ctx, "feature", WorldGenUtils.Feature.stronghold);
        BlockPos pos = WorldGenUtils.locateFeature(feature, mc.player.getBlockPos());
        if (pos != null) {
            BaseText text = new LiteralText(String.format("%s located at ", Utils.nameToTitle(feature.toString().replaceAll("_", "-"))));
            Vec3d coords = new Vec3d(pos.getX(), pos.getY(), pos.getZ());
            text.append(ChatUtils.formatCoords(coords));
            text.append(".");
            info(text);
            return SINGLE_SUCCESS;
        }
        if (feature == WorldGenUtils.Feature.stronghold) {
            FindItemResult eye = InvUtils.findInHotbar(Items.ENDER_EYE);
            if (eye.found()) {
                BaritoneAPI.getProvider().getPrimaryBaritone().getCommandManager().execute("follow entity minecraft:eye_of_ender");
                firstStart = null;
                firstEnd = null;
                secondStart = null;
                secondEnd = null;
                MeteorClient.EVENT_BUS.subscribe(this);
                info("Please throw the first Eye of Ender");
            }
        }
        throw NOT_FOUND.create(feature);
    }));
    builder.then(literal("cancel").executes(s -> {
        cancel();
        return SINGLE_SUCCESS;
    }));
}
Also used : EntityType(net.minecraft.entity.EntityType) LiteralText(net.minecraft.text.LiteralText) SINGLE_SUCCESS(com.mojang.brigadier.Command.SINGLE_SUCCESS) ItemStack(net.minecraft.item.ItemStack) PlaySoundS2CPacket(net.minecraft.network.packet.s2c.play.PlaySoundS2CPacket) BaseText(net.minecraft.text.BaseText) Command(meteordevelopment.meteorclient.systems.commands.Command) SoundEvents(net.minecraft.sound.SoundEvents) Vec3d(net.minecraft.util.math.Vec3d) EnumArgumentType(anticope.rejects.arguments.EnumArgumentType) FindItemResult(meteordevelopment.meteorclient.utils.player.FindItemResult) InvUtils(meteordevelopment.meteorclient.utils.player.InvUtils) ChatUtils(meteordevelopment.meteorclient.utils.player.ChatUtils) Utils(meteordevelopment.meteorclient.utils.Utils) EntitySpawnS2CPacket(net.minecraft.network.packet.s2c.play.EntitySpawnS2CPacket) BaritoneAPI(baritone.api.BaritoneAPI) BlockPos(net.minecraft.util.math.BlockPos) Items(net.minecraft.item.Items) PacketEvent(meteordevelopment.meteorclient.events.packets.PacketEvent) LiteralArgumentBuilder(com.mojang.brigadier.builder.LiteralArgumentBuilder) CommandSource(net.minecraft.command.CommandSource) NbtCompound(net.minecraft.nbt.NbtCompound) DynamicCommandExceptionType(com.mojang.brigadier.exceptions.DynamicCommandExceptionType) MeteorClient(meteordevelopment.meteorclient.MeteorClient) WorldGenUtils(anticope.rejects.utils.WorldGenUtils) EventHandler(meteordevelopment.orbit.EventHandler) BaseText(net.minecraft.text.BaseText) NbtCompound(net.minecraft.nbt.NbtCompound) FindItemResult(meteordevelopment.meteorclient.utils.player.FindItemResult) BlockPos(net.minecraft.util.math.BlockPos) ItemStack(net.minecraft.item.ItemStack) Vec3d(net.minecraft.util.math.Vec3d) LiteralText(net.minecraft.text.LiteralText)

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