Search in sources :

Example 1 with ChunkSection

use of net.modificationstation.stationapi.impl.level.chunk.ChunkSection 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 ChunkSection

use of net.modificationstation.stationapi.impl.level.chunk.ChunkSection 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 ChunkSection

use of net.modificationstation.stationapi.impl.level.chunk.ChunkSection in project StationAPI by ModificationStation.

the class MixinChunk method setTileWithMetadata.

/**
 * @reason early version
 * @author mine_diver
 */
@Overwrite
public boolean setTileWithMetadata(int x, int y, int z, int blockId, int meta) {
    BlockState state = ((BlockStateHolder) BlockBase.BY_ID[blockId]).getDefaultState();
    int yOffset = y >> 4;
    ChunkSection section = sections[yOffset];
    boolean sameMeta = this.field_957.method_1703(x, y, z) == meta;
    if (section == ChunkSection.EMPTY_SECTION) {
        if (state.isAir() && sameMeta)
            return false;
        section = new ChunkSection(yOffset << 4);
        this.sections[yOffset] = section;
    }
    int var6 = this.heightmap[(z << 4) | x] & 255;
    BlockState oldState = section.getBlockState(x, y & 15, z);
    if (oldState == state && sameMeta)
        return false;
    else {
        int levelX = this.x * 16 + x;
        int levelZ = this.z * 16 + z;
        section.setBlockState(x, y & 15, z, state);
        oldState.getBlock().onBlockRemoved(this.level, levelX, y, levelZ);
        this.field_957.method_1704(x, y, z, meta);
        if (!this.level.dimension.halvesMapping) {
            if (BlockBase.LIGHT_OPACITY[state.getBlock().id] != 0) {
                if (y >= var6)
                    this.method_889(x, y + 1, z);
            } else if (y == var6 - 1)
                this.method_889(x, y, z);
            this.level.method_166(LightType.SKY, levelX, y, levelZ, levelX, y, levelZ);
        }
        this.level.method_166(LightType.BLOCK, levelX, y, levelZ, levelX, y, levelZ);
        this.method_887(x, z);
        this.field_957.method_1704(x, y, z, meta);
        state.getBlock().onBlockPlaced(this.level, levelX, y, levelZ);
        this.field_967 = true;
        return true;
    }
}
Also used : BlockState(net.modificationstation.stationapi.api.block.BlockState) BlockStateHolder(net.modificationstation.stationapi.api.block.BlockStateHolder) ChunkSection(net.modificationstation.stationapi.impl.level.chunk.ChunkSection) Overwrite(org.spongepowered.asm.mixin.Overwrite)

Example 4 with ChunkSection

use of net.modificationstation.stationapi.impl.level.chunk.ChunkSection in project StationAPI by ModificationStation.

the class MixinChunk method setBlockState.

@Override
@Unique
public BlockState setBlockState(int x, int y, int z, BlockState state) {
    int yOffset = y >> 4;
    ChunkSection section = sections[yOffset];
    if (section == ChunkSection.EMPTY_SECTION) {
        if (state.isAir())
            return null;
        section = new ChunkSection(yOffset << 4);
        this.sections[yOffset] = section;
    }
    int topY = this.heightmap[(z << 4) | x] & 255;
    BlockState oldState = section.getBlockState(x, y & 15, z);
    if (oldState == state)
        return null;
    else {
        int levelX = this.x * 16 + x;
        int levelZ = this.z * 16 + z;
        oldState.getBlock().onBlockRemoved(this.level, levelX, y, levelZ);
        // moving this to after onBlockRemoved because some blocks may want to get their blockstate before being removed
        section.setBlockState(x, y & 15, z, state);
        this.field_957.method_1704(x, y, z, 0);
        if (!this.level.dimension.halvesMapping) {
            if (BlockBase.LIGHT_OPACITY[state.getBlock().id] != 0) {
                if (y >= topY)
                    this.method_889(x, y + 1, z);
            } else if (y == topY - 1)
                this.method_889(x, y, z);
            this.level.method_166(LightType.SKY, levelX, y, levelZ, levelX, y, levelZ);
        }
        this.level.method_166(LightType.BLOCK, levelX, y, levelZ, levelX, y, levelZ);
        this.method_887(x, z);
        if (!this.level.isClient) {
            state.getBlock().onBlockPlaced(this.level, levelX, y, levelZ);
        }
        this.field_967 = true;
        return oldState;
    }
}
Also used : BlockState(net.modificationstation.stationapi.api.block.BlockState) ChunkSection(net.modificationstation.stationapi.impl.level.chunk.ChunkSection) Unique(org.spongepowered.asm.mixin.Unique)

Aggregations

ChunkSection (net.modificationstation.stationapi.impl.level.chunk.ChunkSection)4 CompoundTag (net.minecraft.util.io.CompoundTag)2 ListTag (net.minecraft.util.io.ListTag)2 BlockState (net.modificationstation.stationapi.api.block.BlockState)2 ChunkSectionsAccessor (net.modificationstation.stationapi.impl.level.chunk.ChunkSectionsAccessor)2 Inject (org.spongepowered.asm.mixin.injection.Inject)2 BlockStateHolder (net.modificationstation.stationapi.api.block.BlockStateHolder)1 Overwrite (org.spongepowered.asm.mixin.Overwrite)1 Unique (org.spongepowered.asm.mixin.Unique)1