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());
}
}
}
}
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));
}
}
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;
}
}
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);
}
}
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);
}
Aggregations