use of net.minecraft.potion.PotionEffect in project NetherEx by LogicTechCorp.
the class ExplosionSpore method doExplosionA.
@Override
public void doExplosionA() {
if (!world.isRemote) {
Set<BlockPos> set = Sets.newHashSet();
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 = explosionSize * (0.7F + world.rand.nextFloat() * 0.6F);
double d4 = explosionX;
double d6 = explosionY;
double d8 = explosionZ;
for (float f1 = 0.3F; f > 0.0F; f -= 0.22500001F) {
BlockPos blockpos = new BlockPos(d4, d6, d8);
IBlockState iblockstate = world.getBlockState(blockpos);
if (iblockstate.getMaterial() != Material.AIR) {
float f2 = exploder != null ? exploder.getExplosionResistance(this, world, blockpos, iblockstate) : iblockstate.getBlock().getExplosionResistance(world, blockpos, (Entity) null, this);
f -= (f2 + 0.3F) * 0.3F;
}
if (f > 0.0F && (exploder == null || exploder.verifyExplosion(this, world, blockpos, iblockstate, f))) {
set.add(blockpos);
}
d4 += d0 * 0.30000001192092896D;
d6 += d1 * 0.30000001192092896D;
d8 += d2 * 0.30000001192092896D;
}
}
}
}
}
affectedBlockPositions.addAll(set);
float f3 = explosionSize * 2.0F;
int k1 = MathHelper.floor(explosionX - (double) f3 - 1.0D);
int l1 = MathHelper.floor(explosionX + (double) f3 + 1.0D);
int i2 = MathHelper.floor(explosionY - (double) f3 - 1.0D);
int i1 = MathHelper.floor(explosionY + (double) f3 + 1.0D);
int j2 = MathHelper.floor(explosionZ - (double) f3 - 1.0D);
int j1 = MathHelper.floor(explosionZ + (double) f3 + 1.0D);
List<Entity> list = world.getEntitiesWithinAABBExcludingEntity(exploder, new AxisAlignedBB((double) k1, (double) i2, (double) j2, (double) l1, (double) i1, (double) j1));
ForgeEventFactory.onExplosionDetonate(world, this, list, f3);
Vec3d vec3d = new Vec3d(explosionX, explosionY, explosionZ);
for (Entity entity : list) {
if (!entity.isImmuneToExplosions()) {
double d12 = entity.getDistance(explosionX, explosionY, explosionZ) / (double) f3;
if (d12 <= 1.0D) {
double d5 = entity.posX - explosionX;
double d7 = entity.posY + (double) entity.getEyeHeight() - explosionY;
double d9 = entity.posZ - explosionZ;
double d13 = (double) MathHelper.sqrt(d5 * d5 + d7 * d7 + d9 * d9);
if (d13 != 0.0D) {
d5 = d5 / d13;
d7 = d7 / d13;
d9 = d9 / d13;
double d14 = (double) world.getBlockDensity(vec3d, entity.getEntityBoundingBox());
double d10 = (1.0D - d12) * d14;
if (!(entity instanceof EntitySporeCreeper) && !(entity instanceof EntitySpore)) {
entity.attackEntityFrom(DamageSource.causeExplosionDamage(this), (float) ((int) ((d10 * d10 + d10) / 2.0D * 7.0D * (double) f3 + 1.0D)));
}
if (entity instanceof EntityLivingBase) {
((EntityLivingBase) entity).addPotionEffect(new PotionEffect(NetherExEffects.SPORE, 2400, 0));
}
double d11 = d10;
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)) {
playerKnockbackMap.put(entityplayer, new Vec3d(d5 * d10, d7 * d10, d9 * d10));
}
}
}
}
}
}
}
}
use of net.minecraft.potion.PotionEffect in project ImmersiveEngineering by BluSunrize.
the class BlockIEFluidConcrete method updateTick.
@Override
public void updateTick(World world, BlockPos pos, IBlockState state, Random rand) {
if (!isSourceBlock(world, pos) && ForgeEventFactory.canCreateFluidSource(world, pos, state, false)) {
int adjacentSourceBlocks = (isSourceBlock(world, pos.north()) ? 1 : 0) + (isSourceBlock(world, pos.south()) ? 1 : 0) + (isSourceBlock(world, pos.east()) ? 1 : 0) + (isSourceBlock(world, pos.west()) ? 1 : 0);
if (adjacentSourceBlocks >= 2 && (world.getBlockState(pos.up(densityDir)).getMaterial().isSolid() || isSourceBlock(world, pos.up(densityDir))))
world.setBlockState(pos, state.withProperty(LEVEL, 0));
}
int level = state.getValue(LEVEL);
int timer = state.getValue(IEProperties.INT_16);
int quantaRemaining = quantaPerBlock - level;
int expQuanta = -101;
if (timer >= Math.min(14, quantaRemaining)) {
IBlockState solidState;
if (level >= 14)
solidState = IEContent.blockStoneDevice.getStateFromMeta(BlockTypes_StoneDevices.CONCRETE_SHEET.getMeta());
else if (level >= 10)
solidState = IEContent.blockStoneDevice.getStateFromMeta(BlockTypes_StoneDevices.CONCRETE_QUARTER.getMeta());
else if (level >= 6)
solidState = IEContent.blockStoneDecorationSlabs.getStateFromMeta(BlockTypes_StoneDecoration.CONCRETE.getMeta());
else if (level >= 2)
solidState = IEContent.blockStoneDevice.getStateFromMeta(BlockTypes_StoneDevices.CONCRETE_THREEQUARTER.getMeta());
else
solidState = IEContent.blockStoneDecoration.getStateFromMeta(BlockTypes_StoneDecoration.CONCRETE.getMeta());
world.setBlockState(pos, solidState);
for (EntityLivingBase living : world.getEntitiesWithinAABB(EntityLivingBase.class, new AxisAlignedBB(pos, pos.add(1, 1, 1)))) living.addPotionEffect(new PotionEffect(IEPotions.concreteFeet, Integer.MAX_VALUE));
return;
} else {
state = state.withProperty(IEProperties.INT_16, Math.min(15, timer + 1));
world.setBlockState(pos, state);
}
// check adjacent block levels if non-source
if (quantaRemaining < quantaPerBlock) {
if (world.getBlockState(pos.add(0, -densityDir, 0)).getBlock() == this || world.getBlockState(pos.add(-1, -densityDir, 0)).getBlock() == this || world.getBlockState(pos.add(1, -densityDir, 0)).getBlock() == this || world.getBlockState(pos.add(0, -densityDir, -1)).getBlock() == this || world.getBlockState(pos.add(0, -densityDir, 1)).getBlock() == this) {
expQuanta = quantaPerBlock - 1;
} else {
int maxQuanta = -100;
maxQuanta = getLargerQuanta(world, pos.add(-1, 0, 0), maxQuanta);
maxQuanta = getLargerQuanta(world, pos.add(1, 0, 0), maxQuanta);
maxQuanta = getLargerQuanta(world, pos.add(0, 0, -1), maxQuanta);
maxQuanta = getLargerQuanta(world, pos.add(0, 0, 1), maxQuanta);
expQuanta = maxQuanta - 1;
}
int total = level;
int blocks = 1;
for (EnumFacing f : EnumFacing.HORIZONTALS) {
IBlockState otherState = world.getBlockState(pos.offset(f));
if (otherState.getBlock() == this) {
blocks++;
total += otherState.getValue(LEVEL);
}
}
int newEvenQuanta = (int) Math.ceil(total / (float) blocks);
for (EnumFacing f : EnumFacing.HORIZONTALS) {
IBlockState otherState = world.getBlockState(pos.offset(f));
if (otherState.getBlock() == this)
world.setBlockState(pos.offset(f), otherState.withProperty(LEVEL, newEvenQuanta));
}
// decay calculation
if (expQuanta != quantaRemaining) {
quantaRemaining = expQuanta;
if (expQuanta <= 0)
world.setBlockToAir(pos);
else {
world.setBlockState(pos, state.withProperty(LEVEL, quantaPerBlock - expQuanta), 2);
world.scheduleUpdate(pos, this, tickRate);
world.notifyNeighborsOfStateChange(pos, this);
}
}
} else // This is a "source" block, set meta to zero, and send a server only update
if (quantaRemaining >= quantaPerBlock)
world.setBlockState(pos, this.getDefaultState(), 2);
// Flow vertically if possible
if (canDisplace(world, pos.up(densityDir))) {
flowIntoBlockRet(world, pos.up(densityDir), 1, timer);
return;
}
// Flow outward if possible
int flowMeta = quantaPerBlock - quantaRemaining + 1;
if (flowMeta >= quantaPerBlock) {
world.setBlockState(pos, state.withProperty(IEProperties.INT_16, Math.min(15, timer + 1)));
world.scheduleUpdate(pos, this, tickRate);
return;
}
if (isSourceBlock(world, pos) || !isFlowingVertically(world, pos)) {
if (world.getBlockState(pos.down(densityDir)).getBlock() == this)
flowMeta = 1;
boolean[] flowTo = getOptimalFlowDirections(world, pos);
boolean hasFlown = false;
if (flowTo[0])
hasFlown |= flowIntoBlockRet(world, pos.add(-1, 0, 0), flowMeta, timer);
if (flowTo[1])
hasFlown |= flowIntoBlockRet(world, pos.add(1, 0, 0), flowMeta, timer);
if (flowTo[2])
hasFlown |= flowIntoBlockRet(world, pos.add(0, 0, -1), flowMeta, timer);
if (flowTo[3])
hasFlown |= flowIntoBlockRet(world, pos.add(0, 0, 1), flowMeta, timer);
if (!hasFlown) {
world.setBlockState(pos, state.withProperty(IEProperties.INT_16, Math.min(15, timer + 1)));
world.scheduleUpdate(pos, this, tickRate);
}
}
}
use of net.minecraft.potion.PotionEffect in project NetherEx by LogicTechCorp.
the class BlockUrnOfSorrow method onBlockActivated.
@Override
public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
TileEntityUrnOfSorrow altar = (TileEntityUrnOfSorrow) world.getTileEntity(pos);
if (altar == null) {
return false;
}
ItemStackHandler inventory = altar.getInventory();
ItemStack inventoryStack = inventory.getStackInSlot(0);
ItemStack heldStack = player.getHeldItemMainhand();
if (!player.isSneaking()) {
if (heldStack.getItem() == Items.POTIONITEM && state.getValue(TYPE) == EnumType.EMPTY) {
for (PotionEffect effect : PotionUtils.getEffectsFromStack(heldStack)) {
if (effect.getPotion() == NetherExEffects.LOST) {
player.getHeldItemMainhand().shrink(1);
world.setBlockState(pos, state.withProperty(TYPE, EnumType.FULL));
}
}
} else {
if (inventoryStack.isEmpty() && !player.getHeldItemMainhand().isEmpty()) {
inventory.setStackInSlot(0, player.getHeldItemMainhand().splitStack(1));
}
}
} else {
if (!inventoryStack.isEmpty() && altar.getSummoningTime() == 0) {
if (!world.isRemote) {
altar.spawnItemStack(world, pos.up(), inventory.getStackInSlot(0));
}
inventory.setStackInSlot(0, ItemStack.EMPTY);
}
}
return super.onBlockActivated(world, pos, state, player, hand, facing, hitX, hitY, hitZ);
}
use of net.minecraft.potion.PotionEffect in project ImmersiveEngineering by BluSunrize.
the class EntityRevolvershot method secondaryImpact.
public void secondaryImpact(RayTraceResult mop) {
if (bulletElectro && mop.entityHit instanceof EntityLivingBase) {
IBullet bullet = BulletHandler.getBullet(bulletType);
float percentualDrain = .15f / (bullet == null ? 1 : bullet.getProjectileCount(shootingEntity instanceof EntityPlayer ? (EntityPlayer) this.shootingEntity : null));
((EntityLivingBase) mop.entityHit).addPotionEffect(new PotionEffect(MobEffects.SLOWNESS, 15, 4));
for (EntityEquipmentSlot slot : EntityEquipmentSlot.values()) {
ItemStack stack = ((EntityLivingBase) mop.entityHit).getItemStackFromSlot(slot);
if (EnergyHelper.isFluxItem(stack) && EnergyHelper.getEnergyStored(stack) > 0) {
int drain = (int) Math.max(EnergyHelper.getEnergyStored(stack), EnergyHelper.getMaxEnergyStored(stack) * percentualDrain);
int hasDrained = 0;
while (hasDrained < drain) {
int actualDrain = EnergyHelper.forceExtractFlux(stack, drain, false);
if (actualDrain <= 0)
break;
hasDrained += actualDrain;
}
}
}
}
// if(bulletType==6)
// {
// Vec3d v = new Vec3d(-motionX, -motionY, -motionZ);
// int split = 6;
// for(int i=0; i<split; i++)
// {
// float angle = i * (360f/split);
// Matrix4 matrix = new Matrix4();
// matrix.rotate(angle, v.xCoord,v.yCoord,v.zCoord);
// Vec3d vecDir = new Vec3d(0, 1, 0);
// vecDir = matrix.apply(vecDir);
//
// EntityWolfpackShot bullet = new EntityWolfpackShot(worldObj, this.shootingEntity, vecDir.xCoord*1.5,vecDir.yCoord*1.5,vecDir.zCoord*1.5, this.bulletType, null);
// if(mop.entityHit instanceof EntityLivingBase)
// bullet.targetOverride = (EntityLivingBase)mop.entityHit;
// bullet.setPosition(posX+vecDir.xCoord, posY+vecDir.yCoord, posZ+vecDir.zCoord);
// bullet.motionX = vecDir.xCoord*.375;
// bullet.motionY = vecDir.yCoord*.375;
// bullet.motionZ = vecDir.zCoord*.375;
// worldObj.spawnEntityInWorld(bullet);
// }
// }
// if(bulletType==8 && bulletPotion!=null && bulletPotion.getItem() instanceof ItemPotion)
// {
// PotionType potionType = PotionUtils.getPotionFromItem(bulletPotion);
// List<PotionEffect> effects = PotionUtils.getEffectsFromStack(bulletPotion);
// if(effects!=null)
// if(bulletPotion.getItem() instanceof ItemLingeringPotion)
// {
// EntityAreaEffectCloud entityareaeffectcloud = new EntityAreaEffectCloud(this.worldObj, this.posX, this.posY, this.posZ);
// entityareaeffectcloud.setOwner(shootingEntity);
// entityareaeffectcloud.setRadius(3.0F);
// entityareaeffectcloud.setRadiusOnUse(-0.5F);
// entityareaeffectcloud.setWaitTime(10);
// entityareaeffectcloud.setRadiusPerTick(-entityareaeffectcloud.getRadius() / (float)entityareaeffectcloud.getDuration());
// entityareaeffectcloud.setPotion(potionType);
// for(PotionEffect potioneffect : effects)
// entityareaeffectcloud.addEffect(new PotionEffect(potioneffect.getPotion(), potioneffect.getDuration(), potioneffect.getAmplifier()));
// this.worldObj.spawnEntityInWorld(entityareaeffectcloud);
// }
// else if(bulletPotion.getItem() instanceof ItemSplashPotion)
// {
// List<EntityLivingBase> livingEntities = this.worldObj.getEntitiesWithinAABB(EntityLivingBase.class, this.getEntityBoundingBox().expand(4.0D, 2.0D, 4.0D));
// if(livingEntities!=null && !livingEntities.isEmpty())
// for(EntityLivingBase living : livingEntities)
// if(living.canBeHitWithPotion())
// {
// double dist = this.getDistanceSqToEntity(living);
// if(dist<16D)
// {
// double dist2 = 1-Math.sqrt(dist)/4D;
// if(living == mop.entityHit)
// dist2 = 1D;
// for(PotionEffect p : effects)
// if(p.getPotion().isInstant())
// p.getPotion().affectEntity(this, this.shootingEntity, living, p.getAmplifier(), dist2);
// else
// {
// int j = (int)(dist2*p.getDuration()+.5D);
// if(j>20)
// living.addPotionEffect(new PotionEffect(p.getPotion(),j, p.getAmplifier()));
// }
// }
// }
//
// }
// else if(mop.entityHit instanceof EntityLivingBase)
// for(PotionEffect p : effects)
// {
// if(p.getDuration()<1)
// p = new PotionEffect(p.getPotion(),1);
// ((EntityLivingBase)mop.entityHit).addPotionEffect(p);
// }
// worldObj.playEvent(2002, new BlockPos(this), PotionType.getID(potionType));
// }
}
use of net.minecraft.potion.PotionEffect in project NetherEx by LogicTechCorp.
the class EntitySporeCreeper method spawnLingeringCloud.
private void spawnLingeringCloud() {
Collection<PotionEffect> collection = getActivePotionEffects();
if (!collection.isEmpty()) {
EntityAreaEffectCloud cloud = new EntityAreaEffectCloud(world, posX, posY, posZ);
cloud.setRadius(2.5F);
cloud.setRadiusOnUse(-0.5F);
cloud.setWaitTime(10);
cloud.setDuration(cloud.getDuration() / 2);
cloud.setRadiusPerTick(-cloud.getRadius() / (float) cloud.getDuration());
for (PotionEffect effect : collection) {
cloud.addEffect(new PotionEffect(effect));
}
world.spawnEntity(cloud);
}
}
Aggregations