Search in sources :

Example 6 with Material

use of net.minecraft.block.Material in project dynmap by webbukkit.

the class DynmapPlugin method initializeBlockStates.

/**
 * Initialize block states (org.dynmap.blockstate.DynmapBlockState)
 */
public void initializeBlockStates() {
    // Simple map - scale as needed
    stateByID = new DynmapBlockState[512 * 32];
    // Default to air
    Arrays.fill(stateByID, DynmapBlockState.AIR);
    IdList<BlockState> bsids = Block.STATE_IDS;
    DynmapBlockState basebs = null;
    Block baseb = null;
    int baseidx = 0;
    Iterator<BlockState> iter = bsids.iterator();
    DynmapBlockState.Builder bld = new DynmapBlockState.Builder();
    while (iter.hasNext()) {
        BlockState bs = iter.next();
        int idx = bsids.getRawId(bs);
        if (idx >= stateByID.length) {
            int plen = stateByID.length;
            // grow array by 10%
            stateByID = Arrays.copyOf(stateByID, idx * 11 / 10);
            Arrays.fill(stateByID, plen, stateByID.length, DynmapBlockState.AIR);
        }
        Block b = bs.getBlock();
        // If this is new block vs last, it's the base block state
        if (b != baseb) {
            basebs = null;
            baseidx = idx;
            baseb = b;
        }
        Identifier ui = Registry.BLOCK.getId(b);
        if (ui == null) {
            continue;
        }
        String bn = ui.getNamespace() + ":" + ui.getPath();
        // Only do defined names, and not "air"
        if (!bn.equals(DynmapBlockState.AIR_BLOCK)) {
            Material mat = bs.getMaterial();
            String statename = "";
            for (net.minecraft.state.property.Property<?> p : bs.getProperties()) {
                if (statename.length() > 0) {
                    statename += ",";
                }
                statename += p.getName() + "=" + bs.get(p).toString();
            }
            int lightAtten = bs.isOpaqueFullCube(EmptyBlockView.INSTANCE, BlockPos.ORIGIN) ? 15 : (bs.isTranslucent(EmptyBlockView.INSTANCE, BlockPos.ORIGIN) ? 0 : 1);
            // Log.info("statename=" + bn + "[" + statename + "], lightAtten=" + lightAtten);
            // Fill in base attributes
            bld.setBaseState(basebs).setStateIndex(idx - baseidx).setBlockName(bn).setStateName(statename).setMaterial(mat.toString()).setLegacyBlockID(idx).setAttenuatesLight(lightAtten);
            if (mat.isSolid()) {
                bld.setSolid();
            }
            if (mat == Material.AIR) {
                bld.setAir();
            }
            if (mat == Material.WOOD) {
                bld.setLog();
            }
            if (mat == Material.LEAVES) {
                bld.setLeaves();
            }
            if ((!bs.getFluidState().isEmpty()) && !(bs.getBlock() instanceof FluidBlock)) {
                bld.setWaterlogged();
            }
            // Build state
            DynmapBlockState dbs = bld.build();
            stateByID[idx] = dbs;
            if (basebs == null) {
                basebs = dbs;
            }
        }
    }
// for (int gidx = 0; gidx < DynmapBlockState.getGlobalIndexMax(); gidx++) {
// DynmapBlockState bs = DynmapBlockState.getStateByGlobalIndex(gidx);
// Log.info(gidx + ":" + bs.toString() + ", gidx=" + bs.globalStateIndex + ", sidx=" + bs.stateIndex);
// }
}
Also used : FluidBlock(net.minecraft.block.FluidBlock) DynmapBlockState(org.dynmap.renderer.DynmapBlockState) Material(net.minecraft.block.Material) BlockState(net.minecraft.block.BlockState) DynmapBlockState(org.dynmap.renderer.DynmapBlockState) Identifier(net.minecraft.util.Identifier) FluidBlock(net.minecraft.block.FluidBlock) Block(net.minecraft.block.Block)

Example 7 with Material

use of net.minecraft.block.Material in project dynmap by webbukkit.

the class DynmapPlugin method initializeBlockStates.

/**
 * Initialize block states (org.dynmap.blockstate.DynmapBlockState)
 */
public void initializeBlockStates() {
    // Simple map - scale as needed
    stateByID = new DynmapBlockState[512 * 32];
    // Default to air
    Arrays.fill(stateByID, DynmapBlockState.AIR);
    IdList<BlockState> bsids = Block.STATE_IDS;
    DynmapBlockState basebs = null;
    Block baseb = null;
    int baseidx = 0;
    Iterator<BlockState> iter = bsids.iterator();
    DynmapBlockState.Builder bld = new DynmapBlockState.Builder();
    while (iter.hasNext()) {
        BlockState bs = iter.next();
        int idx = bsids.getRawId(bs);
        if (idx >= stateByID.length) {
            int plen = stateByID.length;
            // grow array by 10%
            stateByID = Arrays.copyOf(stateByID, idx * 11 / 10);
            Arrays.fill(stateByID, plen, stateByID.length, DynmapBlockState.AIR);
        }
        Block b = bs.getBlock();
        // If this is new block vs last, it's the base block state
        if (b != baseb) {
            basebs = null;
            baseidx = idx;
            baseb = b;
        }
        Identifier ui = Registry.BLOCK.getId(b);
        if (ui == null) {
            continue;
        }
        String bn = ui.getNamespace() + ":" + ui.getPath();
        // Only do defined names, and not "air"
        if (!bn.equals(DynmapBlockState.AIR_BLOCK)) {
            Material mat = bs.getMaterial();
            String statename = "";
            for (net.minecraft.state.property.Property<?> p : bs.getProperties()) {
                if (statename.length() > 0) {
                    statename += ",";
                }
                statename += p.getName() + "=" + bs.get(p).toString();
            }
            int lightAtten = bs.isOpaqueFullCube(EmptyBlockView.INSTANCE, BlockPos.ORIGIN) ? 15 : (bs.isTranslucent(EmptyBlockView.INSTANCE, BlockPos.ORIGIN) ? 0 : 1);
            // Log.info("statename=" + bn + "[" + statename + "], lightAtten=" + lightAtten);
            // Fill in base attributes
            bld.setBaseState(basebs).setStateIndex(idx - baseidx).setBlockName(bn).setStateName(statename).setMaterial(mat.toString()).setLegacyBlockID(idx).setAttenuatesLight(lightAtten);
            if (mat.isSolid()) {
                bld.setSolid();
            }
            if (mat == Material.AIR) {
                bld.setAir();
            }
            if (mat == Material.WOOD) {
                bld.setLog();
            }
            if (mat == Material.LEAVES) {
                bld.setLeaves();
            }
            if ((!bs.getFluidState().isEmpty()) && !(bs.getBlock() instanceof FluidBlock)) {
                bld.setWaterlogged();
            }
            // Build state
            DynmapBlockState dbs = bld.build();
            stateByID[idx] = dbs;
            if (basebs == null) {
                basebs = dbs;
            }
        }
    }
// for (int gidx = 0; gidx < DynmapBlockState.getGlobalIndexMax(); gidx++) {
// DynmapBlockState bs = DynmapBlockState.getStateByGlobalIndex(gidx);
// Log.info(gidx + ":" + bs.toString() + ", gidx=" + bs.globalStateIndex + ", sidx=" + bs.stateIndex);
// }
}
Also used : FluidBlock(net.minecraft.block.FluidBlock) DynmapBlockState(org.dynmap.renderer.DynmapBlockState) Material(net.minecraft.block.Material) BlockState(net.minecraft.block.BlockState) DynmapBlockState(org.dynmap.renderer.DynmapBlockState) Identifier(net.minecraft.util.Identifier) FluidBlock(net.minecraft.block.FluidBlock) Block(net.minecraft.block.Block)

Example 8 with Material

use of net.minecraft.block.Material in project MCDoom by AzureDoom.

the class ArgentPaxel method isSuitableFor.

@Override
public boolean isSuitableFor(BlockState state) {
    Block block = state.getBlock();
    if (block == Blocks.SNOW || block == Blocks.SNOW_BLOCK) {
        return true;
    }
    Material material = state.getMaterial();
    return material == Material.STONE || material == Material.METAL;
}
Also used : PillarBlock(net.minecraft.block.PillarBlock) Block(net.minecraft.block.Block) CampfireBlock(net.minecraft.block.CampfireBlock) Material(net.minecraft.block.Material)

Example 9 with Material

use of net.minecraft.block.Material in project Paradise-Lost by devs-immortal.

the class AetherLakeFeature method generate.

public boolean generate(StructureWorldAccess structureWorldAccess, ChunkGenerator chunkGenerator, Random random, BlockPos blockPos, SingleStateFeatureConfig singleStateFeatureConfig) {
    while (blockPos.getY() > 60 && structureWorldAccess.isAir(blockPos)) {
        blockPos = blockPos.down();
    }
    if (blockPos.getY() <= 59) {
        return false;
    } else {
        blockPos = blockPos.down(4);
        if (structureWorldAccess.getStructures(ChunkSectionPos.from(blockPos), StructureFeature.VILLAGE).findAny().isPresent()) {
            return false;
        } else {
            boolean[] bls = new boolean[2048];
            int i = random.nextInt(4) + 4;
            int ab;
            for (ab = 0; ab < i; ++ab) {
                double d = random.nextDouble() * 6.0D + 3.0D;
                double e = random.nextDouble() * 4.0D + 2.0D;
                double f = random.nextDouble() * 6.0D + 3.0D;
                double g = random.nextDouble() * (16.0D - d - 2.0D) + 1.0D + d / 2.0D;
                double h = random.nextDouble() * (8.0D - e - 4.0D) + 2.0D + e / 2.0D;
                double k = random.nextDouble() * (16.0D - f - 2.0D) + 1.0D + f / 2.0D;
                for (int l = 1; l < 15; ++l) {
                    for (int m = 1; m < 15; ++m) {
                        for (int n = 1; n < 7; ++n) {
                            double o = ((double) l - g) / (d / 2.0D);
                            double p = ((double) n - h) / (e / 2.0D);
                            double q = ((double) m - k) / (f / 2.0D);
                            double r = o * o + p * p + q * q;
                            if (r < 1.0D) {
                                bls[(l * 16 + m) * 8 + n] = true;
                            }
                        }
                    }
                }
            }
            int ad;
            int ac;
            boolean bl2;
            for (ab = 0; ab < 16; ++ab) {
                for (ac = 0; ac < 16; ++ac) {
                    for (ad = 0; ad < 8; ++ad) {
                        bl2 = !bls[(ab * 16 + ac) * 8 + ad] && (ab < 15 && bls[((ab + 1) * 16 + ac) * 8 + ad] || ab > 0 && bls[((ab - 1) * 16 + ac) * 8 + ad] || ac < 15 && bls[(ab * 16 + ac + 1) * 8 + ad] || ac > 0 && bls[(ab * 16 + (ac - 1)) * 8 + ad] || ad < 7 && bls[(ab * 16 + ac) * 8 + ad + 1] || ad > 0 && bls[(ab * 16 + ac) * 8 + (ad - 1)]);
                        if (bl2) {
                            Material material = structureWorldAccess.getBlockState(blockPos.add(ab, ad, ac)).getMaterial();
                            if (ad >= 4 && material.isLiquid()) {
                                return false;
                            }
                            if (ad < 4 && !material.isSolid() && structureWorldAccess.getBlockState(blockPos.add(ab, ad, ac)) != singleStateFeatureConfig.state) {
                                return false;
                            }
                        }
                    }
                }
            }
            for (ab = 0; ab < 16; ++ab) {
                for (ac = 0; ac < 16; ++ac) {
                    for (ad = 0; ad < 8; ++ad) {
                        if (bls[(ab * 16 + ac) * 8 + ad]) {
                            structureWorldAccess.setBlockState(blockPos.add(ab, ad, ac), ad >= 4 ? CAVE_AIR : singleStateFeatureConfig.state, 2);
                        }
                    }
                }
            }
            BlockPos blockPos3;
            for (ab = 0; ab < 16; ++ab) {
                for (ac = 0; ac < 16; ++ac) {
                    for (ad = 4; ad < 8; ++ad) {
                        if (bls[(ab * 16 + ac) * 8 + ad]) {
                            blockPos3 = blockPos.add(ab, ad - 1, ac);
                            if (isSoil(structureWorldAccess.getBlockState(blockPos3).getBlock()) && structureWorldAccess.getLightLevel(LightType.SKY, blockPos.add(ab, ad, ac)) > 0) {
                                structureWorldAccess.setBlockState(blockPos3, AetherBlocks.AETHER_GRASS_BLOCK.getDefaultState(), 2);
                            }
                        }
                    }
                }
            }
            if (singleStateFeatureConfig.state.getMaterial() == Material.LAVA) {
                for (ab = 0; ab < 16; ++ab) {
                    for (ac = 0; ac < 16; ++ac) {
                        for (ad = 0; ad < 8; ++ad) {
                            bl2 = !bls[(ab * 16 + ac) * 8 + ad] && (ab < 15 && bls[((ab + 1) * 16 + ac) * 8 + ad] || ab > 0 && bls[((ab - 1) * 16 + ac) * 8 + ad] || ac < 15 && bls[(ab * 16 + ac + 1) * 8 + ad] || ac > 0 && bls[(ab * 16 + (ac - 1)) * 8 + ad] || ad < 7 && bls[(ab * 16 + ac) * 8 + ad + 1] || ad > 0 && bls[(ab * 16 + ac) * 8 + (ad - 1)]);
                            if (bl2 && (ad < 4 || random.nextInt(2) != 0) && structureWorldAccess.getBlockState(blockPos.add(ab, ad, ac)).getMaterial().isSolid()) {
                                structureWorldAccess.setBlockState(blockPos.add(ab, ad, ac), AetherBlocks.HOLYSTONE.getDefaultState(), 2);
                            }
                        }
                    }
                }
            }
            if (singleStateFeatureConfig.state.getMaterial() == Material.WATER) {
                for (ab = 0; ab < 16; ++ab) {
                    for (ac = 0; ac < 16; ++ac) {
                        blockPos3 = blockPos.add(ab, 4, ac);
                        if (structureWorldAccess.getBiome(blockPos3).canSetIce(structureWorldAccess, blockPos3, false)) {
                            structureWorldAccess.setBlockState(blockPos3, Blocks.ICE.getDefaultState(), 2);
                        }
                    }
                }
            }
            return true;
        }
    }
}
Also used : Material(net.minecraft.block.Material) BlockPos(net.minecraft.util.math.BlockPos)

Aggregations

Material (net.minecraft.block.Material)9 Block (net.minecraft.block.Block)7 BlockState (net.minecraft.block.BlockState)7 FluidBlock (net.minecraft.block.FluidBlock)6 Identifier (net.minecraft.util.Identifier)6 DynmapBlockState (org.dynmap.renderer.DynmapBlockState)6 CampfireBlock (net.minecraft.block.CampfireBlock)1 FluidFillable (net.minecraft.block.FluidFillable)1 PillarBlock (net.minecraft.block.PillarBlock)1 FlowableFluid (net.minecraft.fluid.FlowableFluid)1 BlockPos (net.minecraft.util.math.BlockPos)1