Search in sources :

Example 61 with NbtCompound

use of net.minecraft.nbt.NbtCompound in project EdenClient by HahaOO7.

the class StringStringMapLoader method parse.

public NbtCompound parse(String s) {
    NbtCompound tag = new NbtCompound();
    if (s.isEmpty())
        return tag;
    String[] a = s.split(";");
    for (int i = 0; i < a.length; i++) {
        String k = a[i];
        i++;
        tag.putString(k, a[i]);
    }
    return tag;
}
Also used : NbtCompound(net.minecraft.nbt.NbtCompound)

Example 62 with NbtCompound

use of net.minecraft.nbt.NbtCompound in project Industrious by Pbone3.

the class MachineBlockEntity method readNbt.

@Override
public void readNbt(NbtCompound tag) {
    super.readNbt(tag);
    NbtCompound components = tag.getCompound("components");
    for (String key : machineComponents.keySet()) {
        if (!components.contains(key, 10))
            continue;
        NbtCompound componentData = components.getCompound(key);
        BaseComponent component = machineComponents.getOrDefault(key, null);
        if (component != null) {
            component.readNbt(componentData);
        }
    }
}
Also used : NbtCompound(net.minecraft.nbt.NbtCompound)

Example 63 with NbtCompound

use of net.minecraft.nbt.NbtCompound in project Liminal-Library by LudoCrypt.

the class NbtPlacerUtil method spawnEntities.

public NbtPlacerUtil spawnEntities(ChunkRegion region, BlockPos pos, BlockRotation rotation) {
    this.entities.forEach((nbtElement) -> {
        NbtCompound entityCompound = (NbtCompound) nbtElement;
        NbtList nbtPos = entityCompound.getList("blockPos", 3);
        Vec3d realPosition = rotate(new Vec3d(nbtPos.getInt(0), nbtPos.getInt(1), nbtPos.getInt(2)), rotation).subtract(Vec3d.of(lowestPos)).add(pos.getX(), pos.getY(), pos.getZ());
        NbtCompound nbt = entityCompound.getCompound("nbt").copy();
        nbt.remove("Pos");
        nbt.remove("UUID");
        NbtList posList = new NbtList();
        posList.add(NbtDouble.of(realPosition.x));
        posList.add(NbtDouble.of(realPosition.y));
        posList.add(NbtDouble.of(realPosition.z));
        nbt.put("Pos", posList);
        NbtList rotationList = new NbtList();
        NbtList entityRotationList = nbt.getList("Rotation", 5);
        float yawRotation = applyRotation(entityRotationList.getFloat(0), rotation);
        rotationList.add(NbtFloat.of(yawRotation));
        rotationList.add(NbtFloat.of(entityRotationList.getFloat(1)));
        nbt.remove("Rotation");
        nbt.put("Rotation", rotationList);
        if (nbt.contains("Facing")) {
            Direction dir = rotation.rotate(Direction.fromHorizontal(nbt.getByte("Facing")));
            nbt.remove("Facing");
            nbt.putByte("Facing", (byte) dir.getHorizontal());
        }
        getEntity(region, nbt).ifPresent((entity) -> {
            entity.refreshPositionAndAngles(realPosition.x, realPosition.y, realPosition.z, yawRotation, entity.getPitch());
            region.spawnEntity(entity);
        });
    });
    return this;
}
Also used : NbtCompound(net.minecraft.nbt.NbtCompound) NbtList(net.minecraft.nbt.NbtList) Direction(net.minecraft.util.math.Direction) Vec3d(net.minecraft.util.math.Vec3d)

Example 64 with NbtCompound

use of net.minecraft.nbt.NbtCompound in project frame-fabric by moddingplayground.

the class FrameBannerPatternConversions method makeData.

/**
 * Parses the given NBT data into a list of {@link FrameBannerPatternData} objects.
 *
 * @param nbt a nullable {@link NbtList} with Frame banner pattern data
 */
public static List<FrameBannerPatternData> makeData(NbtList nbt) {
    List<FrameBannerPatternData> res = new ArrayList<>();
    if (nbt != null) {
        for (NbtElement t : nbt) {
            NbtCompound patternNbt = (NbtCompound) t;
            FrameBannerPattern pattern = FrameBannerPatterns.REGISTRY.get(new Identifier(patternNbt.getString("Pattern")));
            if (pattern != null) {
                DyeColor color = DyeColor.byId(patternNbt.getInt("Color"));
                int index = patternNbt.getInt("Index");
                res.add(new FrameBannerPatternData(pattern, color, index));
            }
        }
    }
    return res;
}
Also used : Identifier(net.minecraft.util.Identifier) NbtCompound(net.minecraft.nbt.NbtCompound) ArrayList(java.util.ArrayList) NbtElement(net.minecraft.nbt.NbtElement) FrameBannerPattern(net.moddingplayground.frame.api.bannerpatterns.v0.FrameBannerPattern) DyeColor(net.minecraft.util.DyeColor)

Example 65 with NbtCompound

use of net.minecraft.nbt.NbtCompound in project frame-fabric by moddingplayground.

the class BannerBlockEntityMixin method cleanFrameBannerPattern.

/**
 * Handles removing Frame banner patterns instead of vanilla banner patterns
 * when a banner is cleaned in a cauldron. Yes, this is an "inject-and-cancel"
 * callback. Let me know if there are incompatibilities.
 */
@Inject(method = "loadFromItemStack", at = @At("HEAD"), cancellable = true)
private static void cleanFrameBannerPattern(ItemStack stack, CallbackInfo info) {
    NbtCompound beTag = stack.getSubNbt("BlockEntityTag");
    if (beTag != null) {
        NbtList framePatterns = beTag.getList(FrameBannerPatternAccess.NBT_KEY, 10);
        NbtList patterns = beTag.getList("Patterns", 10);
        boolean cleaned = false;
        if (!framePatterns.isEmpty()) {
            // determine if the last banner pattern is the topmost
            int lastIndex = framePatterns.getCompound(framePatterns.size() - 1).getInt("Index");
            if (lastIndex >= patterns.size()) {
                framePatterns.remove(framePatterns.size() - 1);
                cleaned = true;
            }
        }
        if (!cleaned && !patterns.isEmpty()) {
            patterns.remove(patterns.size() - 1);
        }
        if (framePatterns.isEmpty()) {
            if (patterns.isEmpty()) {
                stack.removeSubNbt("BlockEntityTag");
            } else {
                beTag.remove(FrameBannerPatternAccess.NBT_KEY);
            }
        } else if (patterns.isEmpty()) {
            beTag.remove("Patterns");
        }
    }
    info.cancel();
}
Also used : NbtCompound(net.minecraft.nbt.NbtCompound) NbtList(net.minecraft.nbt.NbtList) Inject(org.spongepowered.asm.mixin.injection.Inject)

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