Search in sources :

Example 16 with Material

use of net.minecraft.block.material.Material in project MinecraftForge by MinecraftForge.

the class BlockFluidBase method canDisplace.

/**
     * Returns true if the block at (pos) is displaceable. Does not displace the block.
     */
public boolean canDisplace(IBlockAccess world, BlockPos pos) {
    if (world.isAirBlock(pos))
        return true;
    IBlockState state = world.getBlockState(pos);
    if (state.getBlock() == this) {
        return false;
    }
    if (displacements.containsKey(state.getBlock())) {
        return displacements.get(state.getBlock());
    }
    Material material = state.getMaterial();
    if (material.blocksMovement() || material == Material.PORTAL) {
        return false;
    }
    int density = getDensity(world, pos);
    if (density == Integer.MAX_VALUE) {
        return true;
    }
    if (this.density > density) {
        return true;
    } else {
        return false;
    }
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) Material(net.minecraft.block.material.Material)

Example 17 with Material

use of net.minecraft.block.material.Material in project MineFactoryReloaded by powercrystals.

the class BlockVanillaIce method harvestBlock.

@Override
public void harvestBlock(World world, EntityPlayer player, int x, int y, int z, int meta) {
    player.addStat(StatList.mineBlockStatArray[this.blockID], 1);
    player.addExhaustion(0.025F);
    if (this.canSilkHarvest() && EnchantmentHelper.getSilkTouchModifier(player)) {
        ItemStack droppedStack = this.createStackedBlock(meta);
        if (droppedStack != null) {
            this.dropBlockAsItem_do(world, x, y, z, droppedStack);
        }
    } else {
        if (world.provider.isHellWorld) {
            return;
        }
        int fortune = EnchantmentHelper.getFortuneModifier(player);
        this.dropBlockAsItem(world, x, y, z, meta, fortune);
        Material var8 = world.getBlockMaterial(x, y - 1, z);
        if ((var8.blocksMovement() || var8.isLiquid()) && meta == 0) {
            world.setBlock(x, y, z, Block.waterMoving.blockID);
        }
    }
}
Also used : Material(net.minecraft.block.material.Material) ItemStack(net.minecraft.item.ItemStack)

Example 18 with Material

use of net.minecraft.block.material.Material in project Overloaded by CJ-MC-Mods.

the class CompressedBlockHandler method CreateCompressedBlocks.

public static Map<Integer, Block> CreateCompressedBlocks(@Nonnull Block toCompress, int depth, boolean recipeEnabled) {
    Map<Integer, Block> compressedBlocks = new HashMap<>();
    Material material = toCompress.getDefaultState().getMaterial();
    String registryName = toCompress.getRegistryName().getResourcePath();
    String unlocalizedName = toCompress.getUnlocalizedName();
    float baseHardness = toCompress.getDefaultState().getBlockHardness(null, null);
    String harvestTool = toCompress.getHarvestTool(toCompress.getDefaultState());
    int harvestLevel = toCompress.getHarvestLevel(toCompress.getDefaultState());
    compressedBlocks.put(0, toCompress);
    Block previousLevel = toCompress;
    float currentHardness = baseHardness;
    for (int i = 1; i <= depth; i++) {
        String compRegistryName = String.format("compressed%s%d", registryName, i);
        String compUnlocalizedName = String.format("%dxCompressed:%s", i, unlocalizedName);
        currentHardness *= 9;
        if (currentHardness < 0) {
            currentHardness = Float.MAX_VALUE;
        }
        BlockCompressed block = new BlockCompressed(toCompress, previousLevel, i, material, compRegistryName, compUnlocalizedName, currentHardness, harvestTool, harvestLevel, recipeEnabled);
        previousLevel = block;
        compressedBlocks.put(i, block);
    }
    return compressedBlocks;
}
Also used : HashMap(java.util.HashMap) Block(net.minecraft.block.Block) Material(net.minecraft.block.material.Material)

Example 19 with Material

use of net.minecraft.block.material.Material in project ImmersiveEngineering by BluSunrize.

the class Utils method getFlowVector.

public static Vec3d getFlowVector(World world, BlockPos pos) {
    IBlockState state = world.getBlockState(pos);
    if (state.getBlock() instanceof BlockFluidBase)
        return ((BlockFluidBase) state.getBlock()).getFlowVector(world, pos);
    else if (!(state.getBlock() instanceof BlockLiquid))
        return new Vec3d(0, 0, 0);
    BlockLiquid block = (BlockLiquid) state.getBlock();
    Vec3d vec3 = new Vec3d(0.0D, 0.0D, 0.0D);
    Material mat = state.getMaterial();
    int i = getEffectiveFlowDecay(world, pos, mat);
    for (EnumFacing enumfacing : EnumFacing.Plane.HORIZONTAL) {
        BlockPos blockpos = pos.offset(enumfacing);
        int j = getEffectiveFlowDecay(world, blockpos, mat);
        if (j < 0) {
            if (!world.getBlockState(blockpos).getMaterial().blocksMovement()) {
                j = getEffectiveFlowDecay(world, blockpos.down(), mat);
                if (j >= 0) {
                    int k = j - (i - 8);
                    vec3 = vec3.addVector((double) ((blockpos.getX() - pos.getX()) * k), (double) ((blockpos.getY() - pos.getY()) * k), (double) ((blockpos.getZ() - pos.getZ()) * k));
                }
            }
        } else if (j >= 0) {
            int l = j - i;
            vec3 = vec3.addVector((double) ((blockpos.getX() - pos.getX()) * l), (double) ((blockpos.getY() - pos.getY()) * l), (double) ((blockpos.getZ() - pos.getZ()) * l));
        }
    }
    if (state.getValue(BlockLiquid.LEVEL).intValue() >= 8) {
        for (EnumFacing enumfacing1 : EnumFacing.Plane.HORIZONTAL) {
            BlockPos blockpos1 = pos.offset(enumfacing1);
            if (block.isBlockSolid(world, blockpos1, enumfacing1) || block.isBlockSolid(world, blockpos1.up(), enumfacing1)) {
                vec3 = vec3.normalize().addVector(0.0D, -6.0D, 0.0D);
                break;
            }
        }
    }
    return vec3.normalize();
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) BlockLiquid(net.minecraft.block.BlockLiquid) EnumFacing(net.minecraft.util.EnumFacing) Material(net.minecraft.block.material.Material) DirectionalBlockPos(blusunrize.immersiveengineering.api.DirectionalBlockPos) BlockPos(net.minecraft.util.math.BlockPos) Vec3d(net.minecraft.util.math.Vec3d)

Example 20 with Material

use of net.minecraft.block.material.Material in project NetherEx by LogicTechCorp.

the class WorldGenPit method generate.

@Override
public boolean generate(World world, Random rand, BlockPos pos) {
    for (pos = pos.add(-8, 0, -8); pos.getY() > 33 && (world.isAirBlock(pos) || world.getBlockState(pos) == blockToIgnore); pos = pos.down()) {
    }
    if (pos.getY() < 33) {
        return false;
    } else {
        boolean[] hasSpace = new boolean[2048];
        int i = rand.nextInt(4) + 4;
        pos = pos.down(4);
        for (int j = 0; j < i; ++j) {
            double d0 = rand.nextDouble() * 6.0D + 3.0D;
            double d1 = rand.nextDouble() * 4.0D + 2.0D;
            double d2 = rand.nextDouble() * 6.0D + 3.0D;
            double d3 = rand.nextDouble() * (16.0D - d0 - 2.0D) + 1.0D + d0 / 2.0D;
            double d4 = rand.nextDouble() * (8.0D - d1 - 4.0D) + 2.0D + d1 / 2.0D;
            double d5 = rand.nextDouble() * (16.0D - d2 - 2.0D) + 1.0D + d2 / 2.0D;
            for (int l = 1; l < 15; ++l) {
                for (int i1 = 1; i1 < 15; ++i1) {
                    for (int j1 = 1; j1 < 7; ++j1) {
                        double d6 = ((double) l - d3) / (d0 / 2.0D);
                        double d7 = ((double) j1 - d4) / (d1 / 2.0D);
                        double d8 = ((double) i1 - d5) / (d2 / 2.0D);
                        double d9 = d6 * d6 + d7 * d7 + d8 * d8;
                        if (d9 < 1.0D) {
                            hasSpace[(l * 16 + i1) * 8 + j1] = true;
                        }
                    }
                }
            }
        }
        for (int k1 = 0; k1 < 16; ++k1) {
            for (int l2 = 0; l2 < 16; ++l2) {
                for (int k = 0; k < 8; ++k) {
                    boolean flag = !hasSpace[(k1 * 16 + l2) * 8 + k] && (k1 < 15 && hasSpace[((k1 + 1) * 16 + l2) * 8 + k] || k1 > 0 && hasSpace[((k1 - 1) * 16 + l2) * 8 + k] || l2 < 15 && hasSpace[(k1 * 16 + l2 + 1) * 8 + k] || l2 > 0 && hasSpace[(k1 * 16 + (l2 - 1)) * 8 + k] || k < 7 && hasSpace[(k1 * 16 + l2) * 8 + k + 1] || k > 0 && hasSpace[(k1 * 16 + l2) * 8 + (k - 1)]);
                    if (flag) {
                        Material material = world.getBlockState(pos.add(k1, k, l2)).getMaterial();
                        if (k >= 4 && material.isLiquid()) {
                            return false;
                        }
                        if (k < 4 && !material.isSolid() && world.getBlockState(pos.add(k1, k, l2)).getBlock() != block) {
                            return false;
                        }
                    }
                }
            }
        }
        for (int l1 = 0; l1 < 16; ++l1) {
            for (int i3 = 0; i3 < 16; ++i3) {
                for (int i4 = 0; i4 < 8; ++i4) {
                    if (hasSpace[(l1 * 16 + i3) * 8 + i4]) {
                        world.setBlockState(pos.add(l1, i4, i3), i4 >= 4 ? Blocks.AIR.getDefaultState() : block.getDefaultState(), 2);
                    }
                }
            }
        }
        for (int j2 = 0; j2 < 16; ++j2) {
            for (int k3 = 0; k3 < 16; ++k3) {
                for (int k4 = 0; k4 < 8; ++k4) {
                    boolean flag1 = !hasSpace[(j2 * 16 + k3) * 8 + k4] && (j2 < 15 && hasSpace[((j2 + 1) * 16 + k3) * 8 + k4] || j2 > 0 && hasSpace[((j2 - 1) * 16 + k3) * 8 + k4] || k3 < 15 && hasSpace[(j2 * 16 + k3 + 1) * 8 + k4] || k3 > 0 && hasSpace[(j2 * 16 + (k3 - 1)) * 8 + k4] || k4 < 7 && hasSpace[(j2 * 16 + k3) * 8 + k4 + 1] || k4 > 0 && hasSpace[(j2 * 16 + k3) * 8 + (k4 - 1)]);
                    if (flag1 && (k4 < 4 || rand.nextInt(2) != 0) && world.getBlockState(pos.add(j2, k4, k3)).getMaterial().isSolid()) {
                        world.setBlockState(pos.add(j2, k4, k3), surroundingBlock, 2);
                    }
                }
            }
        }
        return true;
    }
}
Also used : Material(net.minecraft.block.material.Material)

Aggregations

Material (net.minecraft.block.material.Material)31 IBlockState (net.minecraft.block.state.IBlockState)11 Block (net.minecraft.block.Block)9 BlockPos (net.minecraft.util.math.BlockPos)9 BlockLiquid (net.minecraft.block.BlockLiquid)6 ItemStack (net.minecraft.item.ItemStack)6 World (net.minecraft.world.World)3 EntityPlayer (net.minecraft.entity.player.EntityPlayer)2 MovingObjectPosition (net.minecraft.util.MovingObjectPosition)2 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)2 DirectionalBlockPos (blusunrize.immersiveengineering.api.DirectionalBlockPos)1 IPos3D (com.builtbroken.jlib.data.vector.IPos3D)1 Location (com.builtbroken.mc.imp.transform.vector.Location)1 Pos (com.builtbroken.mc.imp.transform.vector.Pos)1 PlacementData (com.builtbroken.mc.lib.world.edit.PlacementData)1 FMLControlledNamespacedRegistry (cpw.mods.fml.common.registry.FMLControlledNamespacedRegistry)1 EntityFlyingBlock (icbm.classic.content.entity.EntityFlyingBlock)1 ThreadLargeExplosion (icbm.classic.content.explosive.thread.ThreadLargeExplosion)1 IThreadCallBack (icbm.classic.content.explosive.thread.ThreadLargeExplosion.IThreadCallBack)1 MaterialNegativeSpace (ivorius.reccomplex.block.materials.MaterialNegativeSpace)1