Search in sources :

Example 36 with IBlockState

use of net.minecraft.block.state.IBlockState in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.

the class NewExp2 method doExplosionB.

/**
     * Does the second part of the explosion (sound, particles, drop spawn)
     */
@Override
public void doExplosionB(boolean spawnParticles) {
    this.worldObj.playSound((EntityPlayer) null, this.explosionX, this.explosionY, this.explosionZ, SoundEvents.ENTITY_GENERIC_EXPLODE, SoundCategory.BLOCKS, 4.0F, (1.0F + (this.worldObj.rand.nextFloat() - this.worldObj.rand.nextFloat()) * 0.2F) * 0.7F);
    if (this.explosionSize >= 2.0F) {
        this.worldObj.spawnParticle(EnumParticleTypes.EXPLOSION_HUGE, this.explosionX, this.explosionY, this.explosionZ, 1.0D, 0.0D, 0.0D, new int[0]);
    } else {
        this.worldObj.spawnParticle(EnumParticleTypes.EXPLOSION_LARGE, this.explosionX, this.explosionY, this.explosionZ, 1.0D, 0.0D, 0.0D, new int[0]);
    }
    for (BlockPos blockpos : this.affectedBlockPositions) {
        IBlockState iblockstate = this.worldObj.getBlockState(blockpos);
        Block block = iblockstate.getBlock();
        if (spawnParticles) {
            double d0 = (double) ((float) blockpos.getX() + this.worldObj.rand.nextFloat());
            double d1 = (double) ((float) blockpos.getY() + this.worldObj.rand.nextFloat());
            double d2 = (double) ((float) blockpos.getZ() + this.worldObj.rand.nextFloat());
            double d3 = d0 - this.explosionX;
            double d4 = d1 - this.explosionY;
            double d5 = d2 - this.explosionZ;
            double d6 = (double) MathHelper.sqrt_double(d3 * d3 + d4 * d4 + d5 * d5);
            d3 = d3 / d6;
            d4 = d4 / d6;
            d5 = d5 / d6;
            double d7 = 0.5D / (d6 / (double) this.explosionSize + 0.1D);
            d7 = d7 * (double) (this.worldObj.rand.nextFloat() * this.worldObj.rand.nextFloat() + 0.3F);
            d3 = d3 * d7;
            d4 = d4 * d7;
            d5 = d5 * d7;
            this.worldObj.spawnParticle(EnumParticleTypes.EXPLOSION_NORMAL, (d0 + this.explosionX) / 2.0D, (d1 + this.explosionY) / 2.0D, (d2 + this.explosionZ) / 2.0D, d3, d4, d5, new int[0]);
            this.worldObj.spawnParticle(EnumParticleTypes.SMOKE_NORMAL, d0, d1, d2, d3, d4, d5, new int[0]);
        }
        if (iblockstate.getMaterial() != Material.AIR) {
            if (block.canDropFromExplosion(this)) {
                block.dropBlockAsItemWithChance(this.worldObj, blockpos, this.worldObj.getBlockState(blockpos), 1.0F / this.explosionSize, 0);
            }
            block.onBlockExploded(this.worldObj, blockpos, this);
        }
    }
    if (this.isFlaming) {
        for (BlockPos blockpos1 : this.affectedBlockPositions) {
            if (this.worldObj.getBlockState(blockpos1).getMaterial() == Material.AIR && this.worldObj.getBlockState(blockpos1.down()).isFullBlock() && this.explosionRNG.nextInt(3) == 0) {
                this.worldObj.setBlockState(blockpos1, Blocks.FIRE.getDefaultState());
            }
        }
    }
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) Block(net.minecraft.block.Block) BlockPos(net.minecraft.util.math.BlockPos)

Example 37 with IBlockState

use of net.minecraft.block.state.IBlockState in project Witchworks by Um-Mitternacht.

the class BlockKettle method getStateFromMeta.

@SuppressWarnings("deprecation")
@Override
public IBlockState getStateFromMeta(int meta) {
    IBlockState iblockstate = getDefaultState().withProperty(HALF, (meta & 4) > 0 ? BlockStairs.EnumHalf.TOP : BlockStairs.EnumHalf.BOTTOM);
    iblockstate = iblockstate.withProperty(FACING, EnumFacing.getFront(5 - (meta & 3)));
    return iblockstate;
}
Also used : IBlockState(net.minecraft.block.state.IBlockState)

Example 38 with IBlockState

use of net.minecraft.block.state.IBlockState in project Witchworks by Um-Mitternacht.

the class BlockKettle method getStateForPlacement.

@Override
public IBlockState getStateForPlacement(World world, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ, int meta, EntityLivingBase placer, EnumHand hand) {
    IBlockState iblockstate = super.getStateForPlacement(world, pos, facing, hitX, hitY, hitZ, meta, placer, hand);
    iblockstate = iblockstate.withProperty(FACING, placer.getHorizontalFacing());
    return facing != EnumFacing.DOWN && (facing == EnumFacing.UP || hitY <= 0.5F) ? iblockstate.withProperty(HALF, BlockStairs.EnumHalf.BOTTOM) : iblockstate.withProperty(HALF, BlockStairs.EnumHalf.TOP);
}
Also used : IBlockState(net.minecraft.block.state.IBlockState)

Example 39 with IBlockState

use of net.minecraft.block.state.IBlockState in project Witchworks by Um-Mitternacht.

the class ItemKelpSeed method onItemRightClick.

@Override
@SuppressWarnings("ConstantConditions")
public ActionResult<ItemStack> onItemRightClick(World worldIn, EntityPlayer playerIn, EnumHand hand) {
    final RayTraceResult raytraceresult = this.rayTrace(worldIn, playerIn, false);
    ItemStack stack = playerIn.getHeldItem(hand);
    if (raytraceresult == null) {
        return ActionResult.newResult(EnumActionResult.PASS, stack);
    } else {
        if (raytraceresult.typeOfHit == RayTraceResult.Type.BLOCK) {
            final BlockPos blockpos = raytraceresult.getBlockPos();
            if (!worldIn.isBlockModifiable(playerIn, blockpos) || !playerIn.canPlayerEdit(blockpos.offset(raytraceresult.sideHit), raytraceresult.sideHit, stack)) {
                return ActionResult.newResult(EnumActionResult.FAIL, stack);
            }
            final BlockPos up = blockpos.up();
            final IBlockState iblockstate = worldIn.getBlockState(blockpos);
            if (iblockstate.getMaterial().isSolid()) {
                // special case for handling block placement with water lilies
                BlockPos I = up.add(-1, 0, -1);
                BlockPos F = up.add(1, 1, 1);
                for (BlockPos blockPos : BlockPos.getAllInBox(I, F)) {
                    Block block = worldIn.getBlockState(blockPos).getBlock();
                    if (block != ModBlocks.CROP_KELP && block != Blocks.WATER) {
                        return ActionResult.newResult(EnumActionResult.FAIL, stack);
                    }
                }
                final net.minecraftforge.common.util.BlockSnapshot blocksnapshot = net.minecraftforge.common.util.BlockSnapshot.getBlockSnapshot(worldIn, up);
                if (net.minecraftforge.event.ForgeEventFactory.onPlayerBlockPlace(playerIn, blocksnapshot, net.minecraft.util.EnumFacing.UP, hand).isCanceled()) {
                    blocksnapshot.restore(true, false);
                    return ActionResult.newResult(EnumActionResult.FAIL, stack);
                }
                worldIn.setBlockState(up, this.crop.getDefaultState(), 11);
                if (!playerIn.capabilities.isCreativeMode) {
                    stack.shrink(1);
                }
                worldIn.playSound(playerIn, blockpos, SoundEvents.BLOCK_WATERLILY_PLACE, SoundCategory.BLOCKS, 1.0F, 1.0F);
                return ActionResult.newResult(EnumActionResult.SUCCESS, stack);
            }
        }
        return ActionResult.newResult(EnumActionResult.FAIL, stack);
    }
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) net.minecraft.util(net.minecraft.util) RayTraceResult(net.minecraft.util.math.RayTraceResult) Block(net.minecraft.block.Block) BlockPos(net.minecraft.util.math.BlockPos) ItemStack(net.minecraft.item.ItemStack)

Example 40 with IBlockState

use of net.minecraft.block.state.IBlockState in project Witchworks by Um-Mitternacht.

the class PacketHandler method updateToNearbyPlayers.

public static void updateToNearbyPlayers(World worldObj, BlockPos pos) {
    final IBlockState state = worldObj.getBlockState(pos);
    worldObj.notifyBlockUpdate(pos, state, state, 8);
}
Also used : IBlockState(net.minecraft.block.state.IBlockState)

Aggregations

IBlockState (net.minecraft.block.state.IBlockState)798 BlockPos (net.minecraft.util.math.BlockPos)325 Block (net.minecraft.block.Block)246 ItemStack (net.minecraft.item.ItemStack)118 TileEntity (net.minecraft.tileentity.TileEntity)84 EnumFacing (net.minecraft.util.EnumFacing)81 World (net.minecraft.world.World)66 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)42 EntityPlayer (net.minecraft.entity.player.EntityPlayer)34 Entity (net.minecraft.entity.Entity)30 Random (java.util.Random)28 AxisAlignedBB (net.minecraft.util.math.AxisAlignedBB)28 SideOnly (net.minecraftforge.fml.relauncher.SideOnly)28 IBakedModel (net.minecraft.client.renderer.block.model.IBakedModel)23 ArrayList (java.util.ArrayList)22 Vec3d (net.minecraft.util.math.Vec3d)22 SoundType (net.minecraft.block.SoundType)21 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)21 ResourceLocation (net.minecraft.util.ResourceLocation)21 RayTraceResult (net.minecraft.util.math.RayTraceResult)21