Search in sources :

Example 1 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 2 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.getId(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.isFullOpaque(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 3 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 4 with Material

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

the class SkyrootBucket method placeLiquid.

public boolean placeLiquid(PlayerEntity playerIn, World worldIn, BlockPos posIn, BlockHitResult hitResult) {
    if (!(this.containedBlock instanceof FlowableFluid)) {
        return false;
    } else {
        BlockState stateIn = worldIn.getBlockState(posIn);
        Material material = stateIn.getMaterial();
        boolean flag = !material.isSolid();
        boolean flag1 = material.isReplaceable();
        if (worldIn.isAir(posIn) || flag || flag1 || stateIn.getBlock() instanceof FluidFillable && ((FluidFillable) stateIn.getBlock()).canFillWithFluid(worldIn, posIn, stateIn, this.containedBlock)) {
            if (worldIn.getRegistryKey().equals(World.NETHER)) {
                int i = posIn.getX();
                int j = posIn.getY();
                int k = posIn.getZ();
                worldIn.playSound(playerIn, posIn, SoundEvents.BLOCK_FIRE_EXTINGUISH, SoundCategory.BLOCKS, 0.5F, 2.6F + (worldIn.random.nextFloat() - worldIn.random.nextFloat()) * 0.8F);
                for (int l = 0; l < 8; ++l) {
                    worldIn.addParticle(ParticleTypes.LARGE_SMOKE, (double) i + Math.random(), (double) j + Math.random(), (double) k + Math.random(), 0.0D, 0.0D, 0.0D);
                }
            } else if (stateIn.getBlock() instanceof FluidFillable) {
                if (((FluidFillable) stateIn.getBlock()).tryFillWithFluid(worldIn, posIn, stateIn, ((FlowableFluid) this.containedBlock).getStill(false))) {
                    this.playEmptySound(playerIn, worldIn, posIn);
                }
            } else {
                if (!worldIn.isClient && (flag || flag1) && !material.isLiquid()) {
                    worldIn.breakBlock(posIn, true);
                }
                this.playEmptySound(playerIn, worldIn, posIn);
                worldIn.setBlockState(posIn, this.containedBlock.getDefaultState().getBlockState(), 11);
            }
            return true;
        } else {
            return hitResult != null && this.placeLiquid(playerIn, worldIn, hitResult.getBlockPos().offset(hitResult.getSide()), null);
        }
    }
}
Also used : BlockState(net.minecraft.block.BlockState) FluidFillable(net.minecraft.block.FluidFillable) FlowableFluid(net.minecraft.fluid.FlowableFluid) Material(net.minecraft.block.Material)

Example 5 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.getId(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.isFullOpaque(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)

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