Search in sources :

Example 1 with ListTag

use of net.minecraft.util.io.ListTag in project StationAPI by ModificationStation.

the class MixinLevelManager method saveBlockStates.

@Inject(method = "method_1480(Lnet/minecraft/level/chunk/Chunk;Lnet/minecraft/level/Level;Lnet/minecraft/util/io/CompoundTag;)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/util/io/CompoundTag;put(Ljava/lang/String;[B)V", ordinal = 0, shift = At.Shift.AFTER))
private static void saveBlockStates(Chunk chunk, Level level, CompoundTag tag, CallbackInfo ci) {
    ChunkSection[] sections = ((ChunkSectionsAccessor) chunk).getSections();
    ListTag listTag = new ListTag();
    for (int i = 0; i < sections.length; ++i) {
        ChunkSection section = sections[i];
        if (section != ChunkSection.EMPTY_SECTION) {
            CompoundTag compoundTag7 = new CompoundTag();
            compoundTag7.put("Y", (byte) (i & 255));
            section.getContainer().write(compoundTag7, "Palette", "BlockStates");
            listTag.add(compoundTag7);
        }
    }
    tag.put(SECTIONS_TAG, listTag);
}
Also used : ChunkSectionsAccessor(net.modificationstation.stationapi.impl.level.chunk.ChunkSectionsAccessor) ChunkSection(net.modificationstation.stationapi.impl.level.chunk.ChunkSection) ListTag(net.minecraft.util.io.ListTag) CompoundTag(net.minecraft.util.io.CompoundTag) Inject(org.spongepowered.asm.mixin.injection.Inject)

Example 2 with ListTag

use of net.minecraft.util.io.ListTag in project StationAPI by ModificationStation.

the class MixinLevelManager method loadBlockState.

@Inject(method = "method_1479(Lnet/minecraft/level/Level;Lnet/minecraft/util/io/CompoundTag;)Lnet/minecraft/level/chunk/Chunk;", at = @At(value = "FIELD", target = "Lnet/minecraft/level/chunk/Chunk;tiles:[B", opcode = Opcodes.PUTFIELD, shift = At.Shift.AFTER), locals = LocalCapture.CAPTURE_FAILHARD)
private static void loadBlockState(Level arg, CompoundTag arg1, CallbackInfoReturnable<Chunk> cir, int var2, int var3, Chunk var4) {
    ChunkSection[] sections = ((ChunkSectionsAccessor) var4).getSections();
    if (arg1.containsKey(SECTIONS_TAG)) {
        ListTag listTag = arg1.getListTag(SECTIONS_TAG);
        for (int i = 0; i < listTag.size(); i++) {
            CompoundTag section = (CompoundTag) listTag.get(i);
            int k = section.getByte("Y");
            if (section.containsKey("Palette") && section.containsKey("BlockStates")) {
                ChunkSection chunkSection = new ChunkSection(k << 4);
                chunkSection.getContainer().read(section.getListTag("Palette"), ((LongArrayCompound) section).getLongArray("BlockStates"));
                chunkSection.calculateCounts();
                if (!chunkSection.isEmpty()) {
                    sections[k] = chunkSection;
                }
            // poiStorage.initForPalette(pos, chunkSection);
            }
        }
    }
}
Also used : ChunkSectionsAccessor(net.modificationstation.stationapi.impl.level.chunk.ChunkSectionsAccessor) ChunkSection(net.modificationstation.stationapi.impl.level.chunk.ChunkSection) ListTag(net.minecraft.util.io.ListTag) CompoundTag(net.minecraft.util.io.CompoundTag) Inject(org.spongepowered.asm.mixin.injection.Inject)

Example 3 with ListTag

use of net.minecraft.util.io.ListTag in project StationAPI by ModificationStation.

the class PalettedContainer method write.

public void write(CompoundTag compoundTag, String string, String string2) {
    this.lock();
    BiMapPalette<T> biMapPalette = new BiMapPalette<>(this.idList, this.paletteSize, this.noOpPaletteResizeHandler, this.elementDeserializer, this.elementSerializer);
    T object = this.defaultValue;
    int i = biMapPalette.getIndex(this.defaultValue);
    int[] is = new int[4096];
    for (int j = 0; j < 4096; ++j) {
        T object2 = this.get(j);
        if (object2 != object) {
            object = object2;
            i = biMapPalette.getIndex(object2);
        }
        is[j] = i;
    }
    ListTag listTag = new ListTag();
    biMapPalette.toTag(listTag);
    compoundTag.put(string, listTag);
    int k = Math.max(4, MathHelper.log2DeBruijn(listTag.size()));
    PackedIntegerArray packedIntegerArray = new PackedIntegerArray(k, 4096);
    for (int l = 0; l < is.length; ++l) {
        packedIntegerArray.set(l, is[l]);
    }
    ((LongArrayCompound) compoundTag).put(string2, packedIntegerArray.getStorage());
    this.unlock();
}
Also used : PackedIntegerArray(net.modificationstation.stationapi.api.util.collection.PackedIntegerArray) ListTag(net.minecraft.util.io.ListTag) LongArrayCompound(net.modificationstation.stationapi.impl.nbt.LongArrayCompound)

Example 4 with ListTag

use of net.minecraft.util.io.ListTag in project StationAPI by ModificationStation.

the class TileEntityFreezer method readIdentifyingData.

@Override
public void readIdentifyingData(CompoundTag nbttagcompound) {
    super.readIdentifyingData(nbttagcompound);
    ListTag nbttaglist = nbttagcompound.getListTag("Items");
    frozenItemStacks = new ItemInstance[getInventorySize()];
    for (int i = 0; i < nbttaglist.size(); i++) {
        CompoundTag nbttagcompound1 = (CompoundTag) nbttaglist.get(i);
        byte byte0 = nbttagcompound1.getByte("Slot");
        if (byte0 >= 0 && byte0 < frozenItemStacks.length) {
            frozenItemStacks[byte0] = new ItemInstance(nbttagcompound1);
        }
    }
    frozenProgress = nbttagcompound.getShort("BurnTime");
    frozenTimeForItem = nbttagcompound.getShort("CookTime");
}
Also used : ListTag(net.minecraft.util.io.ListTag) CompoundTag(net.minecraft.util.io.CompoundTag) ItemInstance(net.minecraft.item.ItemInstance)

Example 5 with ListTag

use of net.minecraft.util.io.ListTag in project StationAPI by ModificationStation.

the class TileEntityFreezer method writeIdentifyingData.

@Override
public void writeIdentifyingData(CompoundTag nbttagcompound) {
    super.writeIdentifyingData(nbttagcompound);
    nbttagcompound.put("BurnTime", (short) frozenProgress);
    nbttagcompound.put("CookTime", (short) frozenTimeForItem);
    ListTag nbttaglist = new ListTag();
    for (int i = 0; i < frozenItemStacks.length; i++) {
        if (frozenItemStacks[i] != null) {
            CompoundTag nbttagcompound1 = new CompoundTag();
            nbttagcompound1.put("Slot", (byte) i);
            frozenItemStacks[i].toTag(nbttagcompound1);
            nbttaglist.add(nbttagcompound1);
        }
    }
    nbttagcompound.put("Items", nbttaglist);
}
Also used : ListTag(net.minecraft.util.io.ListTag) CompoundTag(net.minecraft.util.io.CompoundTag)

Aggregations

ListTag (net.minecraft.util.io.ListTag)5 CompoundTag (net.minecraft.util.io.CompoundTag)4 ChunkSection (net.modificationstation.stationapi.impl.level.chunk.ChunkSection)2 ChunkSectionsAccessor (net.modificationstation.stationapi.impl.level.chunk.ChunkSectionsAccessor)2 Inject (org.spongepowered.asm.mixin.injection.Inject)2 ItemInstance (net.minecraft.item.ItemInstance)1 PackedIntegerArray (net.modificationstation.stationapi.api.util.collection.PackedIntegerArray)1 LongArrayCompound (net.modificationstation.stationapi.impl.nbt.LongArrayCompound)1