Search in sources :

Example 1 with MaterialColor

use of net.minecraft.block.material.MaterialColor in project MCMOD-Industria by M-Marvin.

the class ScreenMChunkLoader method mapChunk.

private void mapChunk(ChunkPos pos, World world, int chunkX, int chunkZ) {
    IChunk chunk = world.getChunk(pos.x, pos.z);
    for (int x = 0; x < 16; x++) {
        for (int z = 0; z < 16; z++) {
            int y = chunk.getHeight(Type.WORLD_SURFACE, (pos.x * 16) + x, (pos.z * 16) + z);
            BlockPos blockToMap = new BlockPos((pos.x * 16) + x, y, (pos.z * 16) + z);
            BlockState stateToMap = world.getBlockState(blockToMap);
            MaterialColor color = stateToMap.getMapColor(world, blockToMap);
            this.putColorOnMap(color, chunkX * 16 + x, chunkZ * 16 + z);
        }
    }
}
Also used : BlockState(net.minecraft.block.BlockState) IChunk(net.minecraft.world.chunk.IChunk) MaterialColor(net.minecraft.block.material.MaterialColor) BlockPos(net.minecraft.util.math.BlockPos)

Example 2 with MaterialColor

use of net.minecraft.block.material.MaterialColor in project ChocolateQuestRepoured by TeamChocoQuest.

the class GeneratableMapInfo method updateMapColorAt.

private static void updateMapColorAt(World world, int mapX, int mapZ, MapData data) {
    int i = 1 << data.scale;
    double d0 = 0.0D;
    int k2 = (data.x / i + mapX - 64) * i;
    int l2 = (data.z / i + mapZ - 64) * i;
    Multiset<MaterialColor> multiset = HashMultiset.create();
    Chunk chunk = world.getChunk(k2 >> 4, l2 >> 4);
    int i3 = k2 & 15;
    int j3 = l2 & 15;
    int k3 = 0;
    double d1 = 0.0D;
    if (world.dimension().equals(World.NETHER)) {
        int l3 = k2 + l2 * 231_871;
        l3 = l3 * l3 * 31_287_121 + l3 * 11;
        if ((l3 >> 20 & 1) == 0) {
            multiset.add(Blocks.DIRT.defaultBlockState().getMapColor(world, BlockPos.ZERO), 10);
        } else {
            multiset.add(Blocks.STONE.defaultBlockState().getMapColor(world, BlockPos.ZERO), 100);
        }
        d1 = 100.0D;
    } else {
        Mutable pos = new Mutable();
        for (int i4 = 0; i4 < i; ++i4) {
            for (int j4 = 0; j4 < i; ++j4) {
                // Correct replacement?
                int k4 = chunk.getHeight(Type.WORLD_SURFACE, i4 + i3, j4 + j3) + 1;
                BlockState state = Blocks.AIR.defaultBlockState();
                if (k4 <= 1) {
                    state = Blocks.BEDROCK.defaultBlockState();
                } else {
                    label175: {
                        while (true) {
                            --k4;
                            state = chunk.getBlockState(new BlockPos(i4 + i3, k4, j4 + j3));
                            pos.set((chunk.getPos().x << 4) + i4 + i3, k4, (chunk.getPos().z << 4) + j4 + j3);
                            if (state.getMapColor(world, pos) != MaterialColor.NONE || k4 <= 0) {
                                break;
                            }
                        }
                        if (k4 > 0 && state.getMaterial().isLiquid()) {
                            int l4 = k4 - 1;
                            while (true) {
                                BlockState iblockstate1 = chunk.getBlockState(new BlockPos(i4 + i3, l4--, j4 + j3));
                                ++k3;
                                if (l4 <= 0 || !iblockstate1.getMaterial().isLiquid()) {
                                    break label175;
                                }
                            }
                        }
                    }
                }
                d1 += (double) k4 / (double) (i * i);
                multiset.add(state.getMapColor(world, pos));
            }
        }
    }
    k3 = k3 / (i * i);
    double d2 = (d1 - d0) * 4.0D / (i + 4) + ((mapX + mapZ & 1) - 0.5D) * 0.4D;
    int i5 = 1;
    if (d2 > 0.6D) {
        i5 = 2;
    }
    if (d2 < -0.6D) {
        i5 = 0;
    }
    MaterialColor mapcolor = Iterables.getFirst(Multisets.copyHighestCountFirst(multiset), MaterialColor.NONE);
    if (mapcolor == MaterialColor.WATER) {
        d2 = k3 * 0.1D + (mapX + mapZ & 1) * 0.2D;
        i5 = 1;
        if (d2 < 0.5D) {
            i5 = 2;
        }
        if (d2 > 0.9D) {
            i5 = 0;
        }
    }
    byte b0 = data.colors[mapX + mapZ * 128];
    // Correct replacement?
    byte b1 = (byte) (mapcolor.col * 4 + i5);
    if (b0 != b1) {
        data.colors[mapX + mapZ * 128] = b1;
        data.setDirty(mapX, mapZ);
    }
}
Also used : Mutable(net.minecraft.util.math.BlockPos.Mutable) BlockState(net.minecraft.block.BlockState) MaterialColor(net.minecraft.block.material.MaterialColor) BlockPos(net.minecraft.util.math.BlockPos) Chunk(net.minecraft.world.chunk.Chunk)

Aggregations

BlockState (net.minecraft.block.BlockState)2 MaterialColor (net.minecraft.block.material.MaterialColor)2 BlockPos (net.minecraft.util.math.BlockPos)2 Mutable (net.minecraft.util.math.BlockPos.Mutable)1 Chunk (net.minecraft.world.chunk.Chunk)1 IChunk (net.minecraft.world.chunk.IChunk)1