Search in sources :

Example 11 with Material

use of net.minecraft.block.material.Material in project ICBM-Classic by BuiltBrokenModding.

the class BlastSonic method doPreExplode.

@Override
public void doPreExplode() {
    if (!this.world().isRemote) {
        if (this.hasShockWave) {
            for (int x = (int) (-this.getRadius() * 2); x < this.getRadius() * 2; ++x) {
                for (int y = (int) (-this.getRadius() * 2); y < this.getRadius() * 2; ++y) {
                    for (int z = (int) (-this.getRadius() * 2); z < this.getRadius() * 2; ++z) {
                        Location targetPosition = position.add(new Pos(x, y, z));
                        Block blockID = world().getBlock(targetPosition.xi(), targetPosition.yi(), targetPosition.zi());
                        if (blockID != Blocks.air) {
                            Material material = blockID.getMaterial();
                            if (blockID != Blocks.bedrock && !(material.isLiquid()) && (blockID.getExplosionResistance(this.exploder, world(), targetPosition.xi(), targetPosition.yi(), targetPosition.zi(), position.xi(), position.yi(), position.zi()) > this.nengLiang || material == Material.glass)) {
                                targetPosition.setBlock(world(), Blocks.air);
                            }
                        }
                    }
                }
            }
        }
        this.thread = new ThreadLargeExplosion(this.position, (int) this.getRadius(), this.nengLiang, this.exploder, new IThreadCallBack() {

            @Override
            public float getResistance(World world, IPos3D explosionPosition, IPos3D targetPosition, Entity source, Block block) {
                float resistance = 0;
                if (block instanceof BlockLiquid || block instanceof IFluidBlock) {
                    resistance = 1f;
                } else {
                    resistance = block.getExplosionResistance(source, world, (int) targetPosition.x(), (int) targetPosition.y(), (int) targetPosition.z(), explosionPosition.x(), explosionPosition.y(), explosionPosition.z());
                }
                return resistance;
            }
        });
        this.thread.start();
    }
    if (this.hasShockWave) {
        this.world().playSoundEffect(position.x(), position.y(), position.z(), ICBMClassic.PREFIX + "hypersonic", 4.0F, (1.0F + (this.world().rand.nextFloat() - this.world().rand.nextFloat()) * 0.2F) * 0.7F);
    } else {
        this.world().playSoundEffect(position.x(), position.y(), position.z(), ICBMClassic.PREFIX + "sonicwave", 4.0F, (1.0F + (this.world().rand.nextFloat() - this.world().rand.nextFloat()) * 0.2F) * 0.7F);
    }
}
Also used : Entity(net.minecraft.entity.Entity) IThreadCallBack(icbm.classic.content.explosive.thread.ThreadLargeExplosion.IThreadCallBack) Material(net.minecraft.block.material.Material) World(net.minecraft.world.World) ThreadLargeExplosion(icbm.classic.content.explosive.thread.ThreadLargeExplosion) IPos3D(com.builtbroken.jlib.data.vector.IPos3D) BlockLiquid(net.minecraft.block.BlockLiquid) Pos(com.builtbroken.mc.imp.transform.vector.Pos) IFluidBlock(net.minecraftforge.fluids.IFluidBlock) EntityFlyingBlock(icbm.classic.content.entity.EntityFlyingBlock) IFluidBlock(net.minecraftforge.fluids.IFluidBlock) Block(net.minecraft.block.Block) Location(com.builtbroken.mc.imp.transform.vector.Location)

Example 12 with Material

use of net.minecraft.block.material.Material in project SecurityCraft by Geforce132.

the class ItemModifiedBucket method onItemRightClick.

/**
     * Called whenever this item is equipped and the right mouse button is pressed. Args: itemStack, world, entityPlayer
     */
public ItemStack onItemRightClick(ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer) {
    boolean flag = this.isFull == Blocks.air;
    MovingObjectPosition movingobjectposition = this.getMovingObjectPositionFromPlayer(par2World, par3EntityPlayer, flag);
    if (movingobjectposition == null) {
        return par1ItemStack;
    } else {
        FillBucketEvent event = new FillBucketEvent(par3EntityPlayer, par1ItemStack, par2World, movingobjectposition);
        if (MinecraftForge.EVENT_BUS.post(event)) {
            return par1ItemStack;
        }
        if (event.getResult() == Event.Result.ALLOW) {
            if (par3EntityPlayer.capabilities.isCreativeMode) {
                return par1ItemStack;
            }
            if (--par1ItemStack.stackSize <= 0) {
                return event.result;
            }
            if (!par3EntityPlayer.inventory.addItemStackToInventory(event.result)) {
                par3EntityPlayer.dropPlayerItemWithRandomChoice(event.result, false);
            }
            return par1ItemStack;
        }
        if (movingobjectposition.typeOfHit == MovingObjectPosition.MovingObjectType.BLOCK) {
            int i = movingobjectposition.blockX;
            int j = movingobjectposition.blockY;
            int k = movingobjectposition.blockZ;
            if (!par2World.canMineBlock(par3EntityPlayer, i, j, k)) {
                return par1ItemStack;
            }
            if (flag) {
                if (!par3EntityPlayer.canPlayerEdit(i, j, k, movingobjectposition.sideHit, par1ItemStack)) {
                    return par1ItemStack;
                }
                Material material = par2World.getBlock(i, j, k).getMaterial();
                int l = par2World.getBlockMetadata(i, j, k);
                //if (material == Material.water && l == 0)
                if (material == Material.water && l == 0) {
                    par2World.setBlockToAir(i, j, k);
                    // return this.func_150910_a(par1ItemStack, par3EntityPlayer, mod_SecurityCraft.fWaterBucket);
                    return new ItemStack(mod_SecurityCraft.fWaterBucket, 1, 0);
                }
                if (material == Material.lava && l == 0) {
                    par2World.setBlockToAir(i, j, k);
                    //return this.func_150910_a(par1ItemStack, par3EntityPlayer, mod_SecurityCraft.fLavaBucket);
                    return new ItemStack(mod_SecurityCraft.fLavaBucket, 1, 0);
                }
            } else {
                if (this.isFull == Blocks.air) {
                    return new ItemStack(Items.bucket);
                }
                if (movingobjectposition.sideHit == 0) {
                    --j;
                }
                if (movingobjectposition.sideHit == 1) {
                    ++j;
                }
                if (movingobjectposition.sideHit == 2) {
                    --k;
                }
                if (movingobjectposition.sideHit == 3) {
                    ++k;
                }
                if (movingobjectposition.sideHit == 4) {
                    --i;
                }
                if (movingobjectposition.sideHit == 5) {
                    ++i;
                }
                if (!par3EntityPlayer.canPlayerEdit(i, j, k, movingobjectposition.sideHit, par1ItemStack)) {
                    return par1ItemStack;
                }
                if (this.tryPlaceContainedLiquid(par2World, i, j, k) && !par3EntityPlayer.capabilities.isCreativeMode) {
                    return new ItemStack(Items.bucket);
                }
            }
        }
        return par1ItemStack;
    }
}
Also used : MovingObjectPosition(net.minecraft.util.MovingObjectPosition) FillBucketEvent(net.minecraftforge.event.entity.player.FillBucketEvent) Material(net.minecraft.block.material.Material) ItemStack(net.minecraft.item.ItemStack)

Example 13 with Material

use of net.minecraft.block.material.Material in project SecurityCraft by Geforce132.

the class ItemModifiedBucket method onItemRightClick.

public ItemStack onItemRightClick(ItemStack itemStackIn, World worldIn, EntityPlayer playerIn) {
    boolean flag = this.containedBlock == Blocks.air;
    MovingObjectPosition movingobjectposition = this.getMovingObjectPositionFromPlayer(worldIn, playerIn, flag);
    if (movingobjectposition == null) {
        return itemStackIn;
    } else {
        ItemStack ret = net.minecraftforge.event.ForgeEventFactory.onBucketUse(playerIn, worldIn, itemStackIn, movingobjectposition);
        if (ret != null)
            return ret;
        if (movingobjectposition.typeOfHit == MovingObjectPosition.MovingObjectType.BLOCK) {
            BlockPos blockpos = movingobjectposition.getBlockPos();
            if (!worldIn.isBlockModifiable(playerIn, blockpos)) {
                return itemStackIn;
            }
            if (flag) {
                if (!playerIn.canPlayerEdit(blockpos.offset(movingobjectposition.sideHit), movingobjectposition.sideHit, itemStackIn)) {
                    return itemStackIn;
                }
                IBlockState iblockstate = worldIn.getBlockState(blockpos);
                Material material = iblockstate.getBlock().getMaterial();
                if (material == Material.water && ((Integer) iblockstate.getValue(BlockLiquid.LEVEL)).intValue() == 0) {
                    worldIn.setBlockToAir(blockpos);
                    playerIn.triggerAchievement(StatList.objectUseStats[Item.getIdFromItem(this)]);
                    return this.fillBucket(itemStackIn, playerIn, mod_SecurityCraft.fWaterBucket);
                }
                if (material == Material.lava && ((Integer) iblockstate.getValue(BlockLiquid.LEVEL)).intValue() == 0) {
                    worldIn.setBlockToAir(blockpos);
                    playerIn.triggerAchievement(StatList.objectUseStats[Item.getIdFromItem(this)]);
                    return this.fillBucket(itemStackIn, playerIn, mod_SecurityCraft.fLavaBucket);
                }
            } else {
                if (this.containedBlock == Blocks.air) {
                    return new ItemStack(Items.bucket);
                }
                BlockPos blockpos1 = blockpos.offset(movingobjectposition.sideHit);
                if (!playerIn.canPlayerEdit(blockpos1, movingobjectposition.sideHit, itemStackIn)) {
                    return itemStackIn;
                }
                if (this.tryPlaceContainedLiquid(worldIn, blockpos1) && !playerIn.capabilities.isCreativeMode) {
                    playerIn.triggerAchievement(StatList.objectUseStats[Item.getIdFromItem(this)]);
                    return new ItemStack(Items.bucket);
                }
            }
        }
        return itemStackIn;
    }
}
Also used : MovingObjectPosition(net.minecraft.util.MovingObjectPosition) IBlockState(net.minecraft.block.state.IBlockState) BlockPos(net.minecraft.util.BlockPos) Material(net.minecraft.block.material.Material) ItemStack(net.minecraft.item.ItemStack)

Example 14 with Material

use of net.minecraft.block.material.Material in project SecurityCraft by Geforce132.

the class ItemModifiedBucket method onItemRightClick.

@Override
public ActionResult<ItemStack> onItemRightClick(ItemStack itemStackIn, World worldIn, EntityPlayer playerIn, EnumHand hand) {
    boolean flag = this.containedBlock == Blocks.AIR;
    RayTraceResult rayTraceResult = this.rayTrace(worldIn, playerIn, flag);
    if (rayTraceResult == null) {
        return ActionResult.newResult(EnumActionResult.PASS, itemStackIn);
    } else {
        ActionResult<ItemStack> result = ForgeEventFactory.onBucketUse(playerIn, worldIn, itemStackIn, rayTraceResult);
        if (result.getType() != EnumActionResult.FAIL)
            return ActionResult.newResult(EnumActionResult.PASS, result.getResult());
        if (rayTraceResult.typeOfHit == Type.BLOCK) {
            BlockPos blockpos = rayTraceResult.getBlockPos();
            if (!worldIn.isBlockModifiable(playerIn, blockpos)) {
                return ActionResult.newResult(EnumActionResult.PASS, itemStackIn);
            }
            if (flag) {
                if (!playerIn.canPlayerEdit(blockpos.offset(rayTraceResult.sideHit), rayTraceResult.sideHit, itemStackIn)) {
                    return ActionResult.newResult(EnumActionResult.PASS, itemStackIn);
                }
                IBlockState iblockstate = worldIn.getBlockState(blockpos);
                Material material = iblockstate.getBlock().getMaterial(iblockstate);
                //StatList.OBJECT_USE_STATS no longer accessible TODO check for 1.10.2 and 1.11.2
                if (material == Material.WATER && iblockstate.getValue(BlockLiquid.LEVEL).intValue() == 0) {
                    worldIn.setBlockToAir(blockpos);
                    //TODO StatList.OBJECT_USE_STATS
                    return ActionResult.newResult(EnumActionResult.PASS, fillBucket(itemStackIn, playerIn, mod_SecurityCraft.fWaterBucket));
                }
                if (material == Material.LAVA && iblockstate.getValue(BlockLiquid.LEVEL).intValue() == 0) {
                    worldIn.setBlockToAir(blockpos);
                    //TODO StatList.OBJECT_USE_STATS
                    return ActionResult.newResult(EnumActionResult.PASS, fillBucket(itemStackIn, playerIn, mod_SecurityCraft.fLavaBucket));
                }
            } else {
                if (this.containedBlock == Blocks.AIR) {
                    return ActionResult.newResult(EnumActionResult.PASS, new ItemStack(Items.BUCKET));
                }
                BlockPos blockpos1 = blockpos.offset(rayTraceResult.sideHit);
                if (!playerIn.canPlayerEdit(blockpos1, rayTraceResult.sideHit, itemStackIn)) {
                    return ActionResult.newResult(EnumActionResult.PASS, itemStackIn);
                }
                if (this.tryPlaceContainedLiquid(worldIn, blockpos1) && !playerIn.capabilities.isCreativeMode) {
                    //TODO StatList.OBJECT_USE_STATS
                    return ActionResult.newResult(EnumActionResult.PASS, new ItemStack(Items.BUCKET));
                }
            }
        }
        return ActionResult.newResult(EnumActionResult.PASS, itemStackIn);
    }
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) RayTraceResult(net.minecraft.util.math.RayTraceResult) BlockPos(net.minecraft.util.math.BlockPos) Material(net.minecraft.block.material.Material) ItemStack(net.minecraft.item.ItemStack)

Example 15 with Material

use of net.minecraft.block.material.Material in project BluePower by Qmunity.

the class WorldGenVolcano method canReplace.

private boolean canReplace(World world, int x, int y, int z) {
    if (world.isAirBlock(x, y, z))
        return true;
    Block block = world.getBlock(x, y, z);
    Material material = block.getMaterial();
    return material == Material.wood || material == Material.cactus || material == Material.leaves || material == Material.plants || material == Material.vine || block == Blocks.water || block == Blocks.flowing_water;
}
Also used : Block(net.minecraft.block.Block) 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