Search in sources :

Example 26 with BlockPos

use of net.minecraft.util.math.BlockPos 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 27 with BlockPos

use of net.minecraft.util.math.BlockPos in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.

the class ValkyrienWarfareWorldGen method runGenerator.

private void runGenerator(WorldGenerator generator, World world, Random rand, int chunk_X, int chunk_Z, int chancesToSpawn, int minHeight, int maxHeight) {
    if (minHeight < 0 || maxHeight > 256 || minHeight > maxHeight) {
        throw new IllegalArgumentException("Illegal Height Arguments for WorldGenerator");
    }
    int heightDiff = maxHeight - minHeight + 1;
    for (int i = 0; i < chancesToSpawn; i++) {
        int x = chunk_X * 16 + rand.nextInt(16);
        int y = minHeight + rand.nextInt(heightDiff);
        int z = chunk_Z * 16 + rand.nextInt(16);
        generator.generate(world, rand, new BlockPos(x, y, z));
    }
}
Also used : BlockPos(net.minecraft.util.math.BlockPos)

Example 28 with BlockPos

use of net.minecraft.util.math.BlockPos in project Witchworks by Um-Mitternacht.

the class ItemSalt method onItemUse.

@Override
public EnumActionResult onItemUse(EntityPlayer playerIn, World worldIn, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
    final boolean flag = worldIn.getBlockState(pos).getBlock().isReplaceable(worldIn, pos);
    final BlockPos blockpos = flag ? pos : pos.offset(facing);
    ItemStack stack = playerIn.getHeldItem(hand);
    if (playerIn.canPlayerEdit(blockpos, facing, stack) && worldIn.mayPlace(worldIn.getBlockState(blockpos).getBlock(), blockpos, false, facing, playerIn) && ModBlocks.SALT_BARRIER.canPlaceBlockAt(worldIn, blockpos)) {
        stack.shrink(1);
        worldIn.setBlockState(blockpos, ModBlocks.SALT_BARRIER.getDefaultState());
        return EnumActionResult.SUCCESS;
    } else {
        return EnumActionResult.FAIL;
    }
}
Also used : BlockPos(net.minecraft.util.math.BlockPos) ItemStack(net.minecraft.item.ItemStack)

Example 29 with BlockPos

use of net.minecraft.util.math.BlockPos 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 30 with BlockPos

use of net.minecraft.util.math.BlockPos in project Witchworks by Um-Mitternacht.

the class TileApiary method getArea.

private Iterable<BlockPos> getArea() {
    final BlockPos posI = getPos().add(-5, -5, -5);
    final BlockPos posF = getPos().add(5, 5, 5);
    return BlockPos.getAllInBox(posI, posF);
}
Also used : BlockPos(net.minecraft.util.math.BlockPos)

Aggregations

BlockPos (net.minecraft.util.math.BlockPos)4488 IBlockState (net.minecraft.block.state.IBlockState)1202 TileEntity (net.minecraft.tileentity.TileEntity)675 ItemStack (net.minecraft.item.ItemStack)577 World (net.minecraft.world.World)550 Block (net.minecraft.block.Block)545 EnumFacing (net.minecraft.util.EnumFacing)517 EntityPlayer (net.minecraft.entity.player.EntityPlayer)257 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)249 AxisAlignedBB (net.minecraft.util.math.AxisAlignedBB)216 Vec3d (net.minecraft.util.math.Vec3d)216 ArrayList (java.util.ArrayList)211 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)182 Entity (net.minecraft.entity.Entity)176 NBTTagList (net.minecraft.nbt.NBTTagList)139 Random (java.util.Random)130 Biome (net.minecraft.world.biome.Biome)129 Nullable (javax.annotation.Nullable)126 SideOnly (net.minecraftforge.fml.relauncher.SideOnly)126 RayTraceResult (net.minecraft.util.math.RayTraceResult)112