Search in sources :

Example 76 with NbtList

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

the class NbtPlacerUtil method load.

public static Optional<NbtPlacerUtil> load(ResourceManager manager, Identifier id) {
    try {
        Optional<NbtCompound> nbtOptional = loadNbtFromFile(manager, id);
        if (nbtOptional.isPresent()) {
            NbtCompound nbt = nbtOptional.get();
            NbtList paletteList = nbt.getList("palette", 10);
            HashMap<Integer, BlockState> palette = new HashMap<Integer, BlockState>(paletteList.size());
            List<NbtCompound> paletteCompoundList = paletteList.stream().filter(nbtElement -> nbtElement instanceof NbtCompound).map(element -> (NbtCompound) element).toList();
            for (int i = 0; i < paletteCompoundList.size(); i++) {
                palette.put(i, NbtHelper.toBlockState(paletteCompoundList.get(i)));
            }
            NbtList sizeList = nbt.getList("size", 3);
            BlockPos sizeVectorRotated = new BlockPos(sizeList.getInt(0), sizeList.getInt(1), sizeList.getInt(2));
            BlockPos sizeVector = new BlockPos(Math.abs(sizeVectorRotated.getX()), Math.abs(sizeVectorRotated.getY()), Math.abs(sizeVectorRotated.getZ()));
            NbtList positionsList = nbt.getList("blocks", 10);
            HashMap<BlockPos, Pair<BlockState, NbtCompound>> positions = new HashMap<BlockPos, Pair<BlockState, NbtCompound>>(positionsList.size());
            List<Pair<BlockPos, Pair<BlockState, NbtCompound>>> positionsPairList = positionsList.stream().filter(nbtElement -> nbtElement instanceof NbtCompound).map(element -> (NbtCompound) element).map((nbtCompound) -> Pair.of(new BlockPos(nbtCompound.getList("pos", 3).getInt(0), nbtCompound.getList("pos", 3).getInt(1), nbtCompound.getList("pos", 3).getInt(2)), Pair.of(palette.get(nbtCompound.getInt("state")), nbtCompound.getCompound("nbt")))).sorted(Comparator.comparing((pair) -> pair.getFirst().getX())).sorted(Comparator.comparing((pair) -> pair.getFirst().getY())).sorted(Comparator.comparing((pair) -> pair.getFirst().getZ())).toList();
            positionsPairList.forEach((pair) -> positions.put(pair.getFirst().subtract(positionsPairList.get(0).getFirst()), pair.getSecond()));
            return Optional.of(new NbtPlacerUtil(nbt, positions, nbt.getList("entities", 10), positionsPairList.get(0).getFirst(), sizeVector));
        }
        throw new NullPointerException();
    } catch (Exception e) {
        e.printStackTrace();
        return Optional.empty();
    }
}
Also used : EntityType(net.minecraft.entity.EntityType) NbtIo(net.minecraft.nbt.NbtIo) NbtList(net.minecraft.nbt.NbtList) ChunkRegion(net.minecraft.world.ChunkRegion) HashMap(java.util.HashMap) Resource(net.minecraft.resource.Resource) Direction(net.minecraft.util.math.Direction) NbtDouble(net.minecraft.nbt.NbtDouble) Vec3d(net.minecraft.util.math.Vec3d) BlockState(net.minecraft.block.BlockState) Entity(net.minecraft.entity.Entity) TriConsumer(org.apache.logging.log4j.util.TriConsumer) BlockRotation(net.minecraft.util.BlockRotation) NbtFloat(net.minecraft.nbt.NbtFloat) IOException(java.io.IOException) BlockPos(net.minecraft.util.math.BlockPos) NbtHelper(net.minecraft.nbt.NbtHelper) ResourceManager(net.minecraft.resource.ResourceManager) Pair(com.mojang.datafixers.util.Pair) Blocks(net.minecraft.block.Blocks) NbtInt(net.minecraft.nbt.NbtInt) NbtCompound(net.minecraft.nbt.NbtCompound) List(java.util.List) MathHelper(net.minecraft.util.math.MathHelper) Optional(java.util.Optional) Identifier(net.minecraft.util.Identifier) Comparator(java.util.Comparator) NbtCompound(net.minecraft.nbt.NbtCompound) HashMap(java.util.HashMap) IOException(java.io.IOException) BlockState(net.minecraft.block.BlockState) NbtList(net.minecraft.nbt.NbtList) BlockPos(net.minecraft.util.math.BlockPos) Pair(com.mojang.datafixers.util.Pair)

Example 77 with NbtList

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

the class NbtPlacerUtil method rotate.

public NbtPlacerUtil rotate(BlockRotation rotation) {
    NbtList paletteList = storedNbt.getList("palette", 10);
    HashMap<Integer, BlockState> palette = new HashMap<Integer, BlockState>(paletteList.size());
    List<NbtCompound> paletteCompoundList = paletteList.stream().filter(nbtElement -> nbtElement instanceof NbtCompound).map(element -> (NbtCompound) element).toList();
    for (int i = 0; i < paletteCompoundList.size(); i++) {
        palette.put(i, NbtHelper.toBlockState(paletteCompoundList.get(i)).rotate(rotation));
    }
    NbtList sizeList = storedNbt.getList("size", 3);
    BlockPos sizeVectorRotated = new BlockPos(sizeList.getInt(0), sizeList.getInt(1), sizeList.getInt(2)).rotate(rotation);
    BlockPos sizeVector = new BlockPos(Math.abs(sizeVectorRotated.getX()), Math.abs(sizeVectorRotated.getY()), Math.abs(sizeVectorRotated.getZ()));
    NbtList positionsList = storedNbt.getList("blocks", 10);
    HashMap<BlockPos, Pair<BlockState, NbtCompound>> positions = new HashMap<BlockPos, Pair<BlockState, NbtCompound>>(positionsList.size());
    List<Pair<BlockPos, Pair<BlockState, NbtCompound>>> positionsPairList = positionsList.stream().filter(nbtElement -> nbtElement instanceof NbtCompound).map(element -> (NbtCompound) element).map((nbtCompound) -> Pair.of(new BlockPos(nbtCompound.getList("pos", 3).getInt(0), nbtCompound.getList("pos", 3).getInt(1), nbtCompound.getList("pos", 3).getInt(2)).rotate(rotation), Pair.of(palette.get(nbtCompound.getInt("state")), nbtCompound.getCompound("nbt")))).sorted(Comparator.comparing((pair) -> pair.getFirst().getX())).sorted(Comparator.comparing((pair) -> pair.getFirst().getY())).sorted(Comparator.comparing((pair) -> pair.getFirst().getZ())).toList();
    positionsPairList.forEach((pair) -> positions.put(pair.getFirst().subtract(positionsPairList.get(0).getFirst()), pair.getSecond()));
    return new NbtPlacerUtil(storedNbt, positions, storedNbt.getList("entities", 10), positionsPairList.get(0).getFirst(), sizeVector);
}
Also used : EntityType(net.minecraft.entity.EntityType) NbtIo(net.minecraft.nbt.NbtIo) NbtList(net.minecraft.nbt.NbtList) ChunkRegion(net.minecraft.world.ChunkRegion) HashMap(java.util.HashMap) Resource(net.minecraft.resource.Resource) Direction(net.minecraft.util.math.Direction) NbtDouble(net.minecraft.nbt.NbtDouble) Vec3d(net.minecraft.util.math.Vec3d) BlockState(net.minecraft.block.BlockState) Entity(net.minecraft.entity.Entity) TriConsumer(org.apache.logging.log4j.util.TriConsumer) BlockRotation(net.minecraft.util.BlockRotation) NbtFloat(net.minecraft.nbt.NbtFloat) IOException(java.io.IOException) BlockPos(net.minecraft.util.math.BlockPos) NbtHelper(net.minecraft.nbt.NbtHelper) ResourceManager(net.minecraft.resource.ResourceManager) Pair(com.mojang.datafixers.util.Pair) Blocks(net.minecraft.block.Blocks) NbtInt(net.minecraft.nbt.NbtInt) NbtCompound(net.minecraft.nbt.NbtCompound) List(java.util.List) MathHelper(net.minecraft.util.math.MathHelper) Optional(java.util.Optional) Identifier(net.minecraft.util.Identifier) Comparator(java.util.Comparator) NbtCompound(net.minecraft.nbt.NbtCompound) HashMap(java.util.HashMap) BlockState(net.minecraft.block.BlockState) NbtList(net.minecraft.nbt.NbtList) BlockPos(net.minecraft.util.math.BlockPos) Pair(com.mojang.datafixers.util.Pair)

Example 78 with NbtList

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

the class NbtPlacerUtil method createNbtIntList.

public static NbtList createNbtIntList(int... ints) {
    NbtList nbtList = new NbtList();
    int[] var3 = ints;
    int var4 = ints.length;
    for (int var5 = 0; var5 < var4; ++var5) {
        int i = var3[var5];
        nbtList.add(NbtInt.of(i));
    }
    return nbtList;
}
Also used : NbtList(net.minecraft.nbt.NbtList)

Example 79 with NbtList

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

the class LoomScreenMixin method saveFrameBannerPatterns.

@Inject(method = "onInventoryChanged", at = @At("RETURN"))
private void saveFrameBannerPatterns(CallbackInfo ci) {
    if (this.bannerPatterns != null) {
        ItemStack banner = (this.handler).getOutputSlot().getStack();
        NbtList ls = FrameBannerPatternConversions.getNbt(banner);
        frame_bannerPatterns = FrameBannerPatternConversions.makeData(ls);
    } else
        frame_bannerPatterns = Collections.emptyList();
}
Also used : NbtList(net.minecraft.nbt.NbtList) ItemStack(net.minecraft.item.ItemStack) Inject(org.spongepowered.asm.mixin.injection.Inject)

Example 80 with NbtList

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

the class LoomScreenMixin method proxyPutPatterns.

/**
 * If the pattern index indicates a Frame pattern, put the Frame
 * pattern in the item NBT instead of a vanilla pattern.
 */
@Redirect(method = "drawBanner", at = @At(value = "INVOKE", target = "Lnet/minecraft/nbt/NbtCompound;put(Ljava/lang/String;Lnet/minecraft/nbt/NbtElement;)Lnet/minecraft/nbt/NbtElement;", ordinal = 0))
private NbtElement proxyPutPatterns(NbtCompound nbt, String key, NbtElement patterns) {
    frame_singlePattern.clear();
    if (frame_bannerPatternIndex < 0) {
        int frameBannerPatternIdx = -frame_bannerPatternIndex - (1 + BannerPattern.LOOM_APPLICABLE_COUNT);
        FrameBannerPattern pattern = FrameBannerPatternsInternal.get(frameBannerPatternIdx);
        NbtList framePatterns = new NbtList();
        NbtCompound patternNbtElement = new NbtCompound();
        patternNbtElement.putString("Pattern", pattern.getId().toString());
        patternNbtElement.putInt("Color", 0);
        patternNbtElement.putInt("Index", 1);
        framePatterns.add(patternNbtElement);
        // pop dummy vanilla banner pattern
        NbtList vanillaPatterns = (NbtList) patterns;
        assert vanillaPatterns.size() == 2 : vanillaPatterns.size();
        vanillaPatterns.remove(1);
        nbt.put(FrameBannerPatternAccess.NBT_KEY, framePatterns);
        frame_singlePattern.add(new FrameBannerPatternData(pattern, DyeColor.WHITE, 1));
    }
    FrameBannerPatternRenderContext.setFrameBannerPatterns(frame_singlePattern);
    return nbt.put(key, patterns);
}
Also used : NbtCompound(net.minecraft.nbt.NbtCompound) NbtList(net.minecraft.nbt.NbtList) FrameBannerPattern(net.moddingplayground.frame.api.bannerpatterns.v0.FrameBannerPattern) FrameBannerPatternData(net.moddingplayground.frame.impl.bannerpatterns.FrameBannerPatternData) Redirect(org.spongepowered.asm.mixin.injection.Redirect)

Aggregations

NbtList (net.minecraft.nbt.NbtList)161 NbtCompound (net.minecraft.nbt.NbtCompound)92 NbtElement (net.minecraft.nbt.NbtElement)46 Identifier (net.minecraft.util.Identifier)38 ItemStack (net.minecraft.item.ItemStack)28 NbtString (net.minecraft.nbt.NbtString)17 LiteralText (net.minecraft.text.LiteralText)12 BlockPos (net.minecraft.util.math.BlockPos)11 Block (net.minecraft.block.Block)9 IOException (java.io.IOException)8 List (java.util.List)8 Item (net.minecraft.item.Item)7 Inject (org.spongepowered.asm.mixin.injection.Inject)7 Items (net.minecraft.item.Items)6 NbtIo (net.minecraft.nbt.NbtIo)6 StatusEffect (net.minecraft.entity.effect.StatusEffect)5 Text (net.minecraft.text.Text)5 ArrayList (java.util.ArrayList)4 Comparator (java.util.Comparator)4 Blocks (net.minecraft.block.Blocks)4