use of net.minecraft.util.math.BlockPos in project Witchworks by Um-Mitternacht.
the class CropKelp method neighborChanged.
@Override
public void neighborChanged(IBlockState state, World worldIn, BlockPos pos, Block blockIn, BlockPos fromPos) {
BlockPos I = pos.add(-1, 0, -1);
BlockPos F = pos.add(1, 1, 1);
for (BlockPos blockPos : BlockPos.getAllInBox(I, F)) {
Block block = worldIn.getBlockState(blockPos).getBlock();
if (block != this && block != Blocks.WATER && block != Blocks.FLOWING_WATER) {
checkAndDropBlock(worldIn, pos, state);
break;
}
}
if (!canBlockStay(worldIn, pos, state) || !canSustainBush(worldIn.getBlockState(pos.down()))) {
checkAndDropBlock(worldIn, pos, state);
}
}
use of net.minecraft.util.math.BlockPos in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.
the class BlockEtheriumOre method tryFallingUp.
private void tryFallingUp(World worldIn, BlockPos pos) {
BlockPos downPos = pos.up();
if ((worldIn.isAirBlock(downPos) || canFallThrough(worldIn.getBlockState(downPos))) && pos.getY() >= 0) {
int i = 32;
if (!BlockFalling.fallInstantly && worldIn.isAreaLoaded(pos.add(-32, -32, -32), pos.add(32, 32, 32))) {
if (!worldIn.isRemote) {
// Start falling up
EntityFallingUpBlock entityfallingblock = new EntityFallingUpBlock(worldIn, (double) pos.getX() + 0.5D, (double) pos.getY(), (double) pos.getZ() + 0.5D, worldIn.getBlockState(pos));
worldIn.spawnEntityInWorld(entityfallingblock);
}
} else {
IBlockState state = worldIn.getBlockState(pos);
worldIn.setBlockToAir(pos);
BlockPos blockpos;
for (blockpos = pos.up(); (worldIn.isAirBlock(blockpos) || canFallThrough(worldIn.getBlockState(blockpos))) && blockpos.getY() < 255; blockpos = blockpos.up()) {
;
}
if (blockpos.getY() < 255) {
worldIn.setBlockState(blockpos.down(), state, 3);
}
}
}
}
use of net.minecraft.util.math.BlockPos in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.
the class EntityFallingUpBlock method onUpdate.
@Override
public void onUpdate() {
Block block = this.fallTile.getBlock();
if (this.fallTile.getMaterial() == Material.AIR) {
this.setDead();
} else {
this.prevPosX = this.posX;
this.prevPosY = this.posY;
this.prevPosZ = this.posZ;
if (this.fallTime++ == 0) {
BlockPos blockpos = new BlockPos(this);
if (this.worldObj.getBlockState(blockpos).getBlock() == block) {
this.worldObj.setBlockToAir(blockpos);
} else if (!this.worldObj.isRemote) {
this.setDead();
return;
}
}
if (!this.hasNoGravity()) {
this.motionY += 0.03999999910593033D;
}
CallRunner.onEntityMove(this, this.motionX, this.motionY, this.motionZ);
this.motionX *= 0.9800000190734863D;
this.motionY *= 0.9800000190734863D;
this.motionZ *= 0.9800000190734863D;
if (!this.worldObj.isRemote) {
BlockPos blockpos1 = new BlockPos(this);
if (!onGround && isCollidedVertically) {
IBlockState iblockstate = this.worldObj.getBlockState(blockpos1);
if (// Forge: Don't indent below.
this.worldObj.isAirBlock(new BlockPos(this.posX, this.posY + 1.009999999776482582D, this.posZ)))
if (BlockFalling.canFallThrough(this.worldObj.getBlockState(new BlockPos(this.posX, this.posY + 1.009999999776482582D, this.posZ)))) {
this.isCollidedVertically = false;
return;
}
this.motionX *= 0.699999988079071D;
this.motionZ *= 0.699999988079071D;
this.motionY *= -0.5D;
if (iblockstate.getBlock() != Blocks.PISTON_EXTENSION) {
this.setDead();
if (!this.canSetAsBlock) {
if (this.worldObj.canBlockBePlaced(block, blockpos1, true, EnumFacing.UP, (Entity) null, (ItemStack) null) && !BlockFalling.canFallThrough(this.worldObj.getBlockState(blockpos1.up())) && worldObj.setBlockState(blockpos1, this.fallTile, 3)) {
if (block instanceof BlockFalling) {
((BlockFalling) block).onEndFalling(this.worldObj, blockpos1);
}
if (this.tileEntityData != null && block instanceof ITileEntityProvider) {
TileEntity tileentity = this.worldObj.getTileEntity(blockpos1);
if (tileentity != null) {
NBTTagCompound nbttagcompound = tileentity.writeToNBT(new NBTTagCompound());
for (String s : this.tileEntityData.getKeySet()) {
NBTBase nbtbase = this.tileEntityData.getTag(s);
if (!"x".equals(s) && !"y".equals(s) && !"z".equals(s)) {
nbttagcompound.setTag(s, nbtbase.copy());
}
}
tileentity.readFromNBT(nbttagcompound);
tileentity.markDirty();
}
}
} else if (this.shouldDropItem && this.worldObj.getGameRules().getBoolean("doEntityDrops")) {
this.entityDropItem(new ItemStack(block, 1, block.damageDropped(this.fallTile)), 0.0F);
}
}
}
} else if (this.fallTime > 100 && !this.worldObj.isRemote && (blockpos1.getY() < 1 || blockpos1.getY() > 256) || this.fallTime > 600) {
if (this.shouldDropItem && this.worldObj.getGameRules().getBoolean("doEntityDrops")) {
this.entityDropItem(new ItemStack(block, 1, block.damageDropped(this.fallTile)), 0.0F);
}
this.setDead();
}
}
}
}
use of net.minecraft.util.math.BlockPos in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.
the class NewExp method doExplosionA.
/**
* Does the first part of the explosion (destroy blocks)
*/
public void doExplosionA() {
Set<BlockPos> set = Sets.<BlockPos>newHashSet();
int i = 16;
for (int j = 0; j < 16; ++j) {
for (int k = 0; k < 16; ++k) {
for (int l = 0; l < 16; ++l) {
if (j == 0 || j == 15 || k == 0 || k == 15 || l == 0 || l == 15) {
double d0 = (double) ((float) j / 15.0F * 2.0F - 1.0F);
double d1 = (double) ((float) k / 15.0F * 2.0F - 1.0F);
double d2 = (double) ((float) l / 15.0F * 2.0F - 1.0F);
double d3 = Math.sqrt(d0 * d0 + d1 * d1 + d2 * d2);
d0 = d0 / d3;
d1 = d1 / d3;
d2 = d2 / d3;
float f = this.explosionSize * (0.3F + this.worldObj.rand.nextFloat() * 0.3F);
double d4 = this.explosionX;
double d6 = this.explosionY;
double d8 = this.explosionZ;
for (float f1 = 0.3F; f > 0.0F; f -= 0.22500001F) {
BlockPos blockpos = new BlockPos(d4, d6, d8);
IBlockState iblockstate = this.worldObj.getBlockState(blockpos);
if (iblockstate.getMaterial() != Material.AIR) {
float f2 = this.exploder != null ? this.exploder.getExplosionResistance(this, this.worldObj, blockpos, iblockstate) : iblockstate.getBlock().getExplosionResistance(worldObj, blockpos, (Entity) null, this);
// f -= ((f2 + 0.3F) * 0.3F) / this.explosionPower ;
f -= (f2 * this.explosionBlast) + this.explosionPower;
}
if (f > 0.0F && (this.exploder == null || this.exploder.verifyExplosion(this, this.worldObj, blockpos, iblockstate, f))) {
set.add(blockpos);
}
d4 += d0 * 0.30000001192092896D;
d6 += d1 * 0.30000001192092896D;
d8 += d2 * 0.30000001192092896D;
}
}
}
}
}
this.affectedBlockPositions.addAll(set);
float f3 = this.explosionSize * 2.0F;
int k1 = MathHelper.floor_double(this.explosionX - (double) f3 - 1.0D);
int l1 = MathHelper.floor_double(this.explosionX + (double) f3 + 1.0D);
int i2 = MathHelper.floor_double(this.explosionY - (double) f3 - 1.0D);
int i1 = MathHelper.floor_double(this.explosionY + (double) f3 + 1.0D);
int j2 = MathHelper.floor_double(this.explosionZ - (double) f3 - 1.0D);
int j1 = MathHelper.floor_double(this.explosionZ + (double) f3 + 1.0D);
List<Entity> list = this.worldObj.getEntitiesWithinAABBExcludingEntity(this.exploder, new AxisAlignedBB((double) k1, (double) i2, (double) j2, (double) l1, (double) i1, (double) j1));
net.minecraftforge.event.ForgeEventFactory.onExplosionDetonate(this.worldObj, this, list, f3);
Vec3d vec3d = new Vec3d(this.explosionX, this.explosionY, this.explosionZ);
for (int k2 = 0; k2 < list.size(); ++k2) {
Entity entity = (Entity) list.get(k2);
if (!entity.isImmuneToExplosions()) {
double d12 = entity.getDistance(this.explosionX, this.explosionY, this.explosionZ) / f3;
if (d12 <= 1.0D) {
double d5 = entity.posX - this.explosionX;
double d7 = entity.posY + (double) entity.getEyeHeight() - this.explosionY;
double d9 = entity.posZ - this.explosionZ;
double d13 = (double) MathHelper.sqrt_double(d5 * d5 + d7 * d7 + d9 * d9);
if (d13 != 0.0D) {
d5 = d5 / d13;
d7 = d7 / d13;
d9 = d9 / d13;
double d14 = (double) this.worldObj.getBlockDensity(vec3d, entity.getEntityBoundingBox());
double d10 = (1.0D - d12) * d14;
entity.attackEntityFrom(DamageSource.causeExplosionDamage(this), (float) ((int) ((d10 * d10 + d10) + this.explosionDamage / 2.0D)));
double d11 = 1.0D;
if (entity instanceof EntityLivingBase) {
d11 = EnchantmentProtection.getBlastDamageReduction((EntityLivingBase) entity, d10);
}
entity.motionX += d5 * d11;
entity.motionY += d7 * d11;
entity.motionZ += d9 * d11;
if (entity instanceof EntityPlayer) {
EntityPlayer entityplayer = (EntityPlayer) entity;
if (!entityplayer.isSpectator() && (!entityplayer.isCreative() || !entityplayer.capabilities.isFlying)) {
this.playerKnockbackMap.put(entityplayer, new Vec3d(d5 * d10, d7 * d10, d9 * d10));
}
}
}
}
}
}
}
use of net.minecraft.util.math.BlockPos in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.
the class NewExp2 method doExplosionA.
/**
* Does the first part of the explosion (destroy blocks)
*/
public void doExplosionA() {
Set<BlockPos> set = Sets.<BlockPos>newHashSet();
int i = 16;
for (int j = 0; j < 16; ++j) {
for (int k = 0; k < 16; ++k) {
for (int l = 0; l < 16; ++l) {
if (j == 0 || j == 15 || k == 0 || k == 15 || l == 0 || l == 15) {
double d0 = (double) ((float) j / 15.0F * 2.0F - 1.0F);
double d1 = (double) ((float) k / 15.0F * 2.0F - 1.0F);
double d2 = (double) ((float) l / 15.0F * 2.0F - 1.0F);
double d3 = Math.sqrt(d0 * d0 + d1 * d1 + d2 * d2);
d0 = d0 / d3;
d1 = d1 / d3;
d2 = d2 / d3;
float f = this.explosionSize * (0.3F + this.worldObj.rand.nextFloat() * 0.3F);
double d4 = this.explosionX;
double d6 = this.explosionY;
double d8 = this.explosionZ;
for (float f1 = 0.3F; f > 0.0F; f -= 0.22500001F) {
BlockPos blockpos = new BlockPos(d4, d6, d8);
IBlockState iblockstate = this.worldObj.getBlockState(blockpos);
if (iblockstate.getMaterial() != Material.AIR) {
float f2 = this.exploder != null ? this.exploder.getExplosionResistance(this, this.worldObj, blockpos, iblockstate) : iblockstate.getBlock().getExplosionResistance(worldObj, blockpos, (Entity) null, this);
// f -= ((f2 + 0.3F) * 0.3F) / this.explosionPower ;
f -= (f2 * this.explosionBlast) + this.explosionPower;
}
if (f > 0.0F && (this.exploder == null || this.exploder.verifyExplosion(this, this.worldObj, blockpos, iblockstate, f))) {
set.add(blockpos);
}
d4 += d0 * 0.30000001192092896D;
d6 += d1 * 0.30000001192092896D;
d8 += d2 * 0.30000001192092896D;
}
}
}
}
}
this.affectedBlockPositions.addAll(set);
float f3 = this.explosionSize * 2;
int k1 = MathHelper.floor_double(this.explosionX - (double) f3 - 1.0D);
int l1 = MathHelper.floor_double(this.explosionX + (double) f3 + 1.0D);
int i2 = MathHelper.floor_double(this.explosionY - (double) f3 - 1.0D);
int i1 = MathHelper.floor_double(this.explosionY + (double) f3 + 1.0D);
int j2 = MathHelper.floor_double(this.explosionZ - (double) f3 - 1.0D);
int j1 = MathHelper.floor_double(this.explosionZ + (double) f3 + 1.0D);
List<Entity> list = this.worldObj.getEntitiesWithinAABBExcludingEntity(this.exploder, new AxisAlignedBB((double) k1, (double) i2, (double) j2, (double) l1, (double) i1, (double) j1));
net.minecraftforge.event.ForgeEventFactory.onExplosionDetonate(this.worldObj, this, list, f3);
Vec3d vec3d = new Vec3d(this.explosionX, this.explosionY, this.explosionZ);
for (int k2 = 0; k2 < list.size(); ++k2) {
Entity entity = (Entity) list.get(k2);
if (!entity.isImmuneToExplosions()) {
double d12 = entity.getDistance(this.explosionX, this.explosionY, this.explosionZ) / f3;
if (d12 <= 1.0D) {
double d5 = entity.posX - this.explosionX;
double d7 = entity.posY + (double) entity.getEyeHeight() - this.explosionY;
double d9 = entity.posZ - this.explosionZ;
double d13 = (double) MathHelper.sqrt_double(d5 * d5 + d7 * d7 + d9 * d9);
if (d13 != 0.0D) {
d5 = d5 / d13;
d7 = d7 / d13;
d9 = d9 / d13;
double d14 = (double) this.worldObj.getBlockDensity(vec3d, entity.getEntityBoundingBox());
double d10 = (1.0D - d12) * d14;
entity.attackEntityFrom(DamageSource.causeExplosionDamage(this), (float) ((int) ((d10 * d10 + d10) + this.explosionDamage / 2.0D)));
double d11 = 1.0D;
if (entity instanceof EntityLivingBase) {
d11 = EnchantmentProtection.getBlastDamageReduction((EntityLivingBase) entity, d10);
}
entity.motionX += d5 * d11;
entity.motionY += d7 * d11;
entity.motionZ += d9 * d11;
if (entity instanceof EntityPlayer) {
EntityPlayer entityplayer = (EntityPlayer) entity;
if (!entityplayer.isSpectator() && (!entityplayer.isCreative() || !entityplayer.capabilities.isFlying)) {
this.playerKnockbackMap.put(entityplayer, new Vec3d(d5 * d10, d7 * d10, d9 * d10));
}
}
}
}
}
}
}
Aggregations