use of icbm.classic.content.entity.EntityExplosive in project ICBM-Classic by BuiltBrokenModding.
the class RenderEntityExplosive method doRender.
@Override
public void doRender(Entity par1Entity, double x, double y, double z, float par8, float par9) {
EntityExplosive entityExplosive = (EntityExplosive) par1Entity;
GL11.glPushMatrix();
GL11.glTranslatef((float) x, (float) y, (float) z);
float f2;
if (entityExplosive.fuse - par9 + 1.0F < 10.0F) {
f2 = 1.0F - (entityExplosive.fuse - par9 + 1.0F) / 10.0F;
if (f2 < 0.0F) {
f2 = 0.0F;
}
if (f2 > 1.0F) {
f2 = 1.0F;
}
f2 *= f2;
f2 *= f2;
float f3 = 1.0F + f2 * 0.3F;
GL11.glScalef(f3, f3, f3);
}
f2 = (1.0F - (entityExplosive.fuse - par9 + 1.0F) / 100.0F) * 0.8F;
RenderUtility.setTerrainTexture();
this.blockRenderer.renderBlockAsItem(ICBMClassic.blockExplosive, entityExplosive.explosiveID.ordinal(), entityExplosive.getBrightness(par9));
if (entityExplosive.fuse / 5 % 2 == 0) {
GL11.glDisable(GL11.GL_TEXTURE_2D);
GL11.glDisable(GL11.GL_LIGHTING);
GL11.glEnable(GL11.GL_BLEND);
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_DST_ALPHA);
GL11.glColor4f(1.0F, 1.0F, 1.0F, f2);
this.blockRenderer.renderBlockAsItem(ICBMClassic.blockExplosive, entityExplosive.explosiveID.ordinal(), 1.0F);
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
GL11.glDisable(GL11.GL_BLEND);
GL11.glEnable(GL11.GL_LIGHTING);
GL11.glEnable(GL11.GL_TEXTURE_2D);
}
GL11.glPopMatrix();
}
use of icbm.classic.content.entity.EntityExplosive in project ICBM-Classic by BuiltBrokenModding.
the class BlastEMP method doExplode.
@Override
public void doExplode() {
if (!world().isRemote) {
if (this.effectBlocks) {
for (int x = (int) -this.getRadius(); x < (int) this.getRadius(); x++) {
for (int y = (int) -this.getRadius(); y < (int) this.getRadius(); y++) {
for (int z = (int) -this.getRadius(); z < (int) this.getRadius(); z++) {
double dist = MathHelper.sqrt_double((x * x + y * y + z * z));
Pos searchPosition = new Pos(x, y, z).add(position);
if (dist > this.getRadius()) {
continue;
}
if (Math.round(position.x() + y) == position.yi()) {
world().spawnParticle("largesmoke", searchPosition.x(), searchPosition.y(), searchPosition.z(), 0, 0, 0);
}
Block block = searchPosition.getBlock(world());
TileEntity tileEntity = searchPosition.getTileEntity(world());
//TODO more EMP effect to UniversalEnergySystem to better support cross mod support
if (block != null) {
//}
if (block instanceof IEMPBlock) {
((IEMPBlock) block).onEMP(world(), searchPosition.xi(), searchPosition.yi(), searchPosition.zi(), this);
}
}
if (tileEntity != null) {
//if (tileEntity instanceof IFortronStorage)
//{
// ((IFortronStorage) tileEntity).provideFortron((int) world().rand.nextFloat() * ((IFortronStorage) tileEntity).getFortronCapacity(), true);
//}
UniversalEnergySystem.clearEnergy(tileEntity, true);
}
}
}
}
}
if (this.effectEntities) {
// Drop all missiles
List<Entity> entitiesNearby = RadarRegistry.getAllLivingObjectsWithin(world(), new Cube(position.sub(getRadius()), position.add(getRadius())), null);
for (Entity entity : entitiesNearby) {
if (entity instanceof IMissile && !entity.isEntityEqual(this.controller)) {
if (((IMissile) entity).getTicksInAir() > -1) {
((IMissile) entity).dropMissileAsItem();
}
}
}
int maxFx = 10;
AxisAlignedBB bounds = AxisAlignedBB.getBoundingBox(position.x() - this.getRadius(), position.y() - this.getRadius(), position.z() - this.getRadius(), position.x() + this.getRadius(), position.y() + this.getRadius(), position.z() + this.getRadius());
List<Entity> entities = world().getEntitiesWithinAABB(Entity.class, bounds);
for (Entity entity : entities) {
if (entity instanceof EntityLivingBase) {
if (this.world().isRemote && maxFx > 0) {
ICBMClassic.proxy.spawnShock(this.world(), this.position, new Pos(entity), 20);
maxFx--;
}
if (entity instanceof EntityCreeper) {
if (!this.world().isRemote) {
try {
((EntityCreeper) entity).getDataWatcher().updateObject(17, (byte) 1);
} catch (Exception e) {
e.printStackTrace();
}
}
}
if (entity instanceof EntityPlayer) {
IInventory inventory = ((EntityPlayer) entity).inventory;
for (int i = 0; i < inventory.getSizeInventory(); i++) {
ItemStack itemStack = inventory.getStackInSlot(i);
if (itemStack != null) {
if (itemStack.getItem() instanceof IEMPItem) {
((IEMPItem) itemStack.getItem()).onEMP(itemStack, entity, this);
}
UniversalEnergySystem.clearEnergy(itemStack, true);
}
}
}
} else if (entity instanceof EntityExplosive) {
entity.setDead();
}
}
}
VEProviderShockWave.spawnEffect(world(), position.x(), position.y(), position.z(), 0, 0, 0, 0, 0, 255, 1, 3);
VEProviderShockWave.spawnEffect(world(), position.x(), position.y(), position.z(), 0, 0, 0, 0, 0, 255, 3, 3);
VEProviderShockWave.spawnEffect(world(), position.x(), position.y(), position.z(), 0, 0, 0, 0, 0, 255, 5, 3);
this.world().playSoundEffect(position.x(), position.y(), position.z(), ICBMClassic.PREFIX + "emp", 4.0F, (1.0F + (world().rand.nextFloat() - world().rand.nextFloat()) * 0.2F) * 0.7F);
}
}
use of icbm.classic.content.entity.EntityExplosive in project ICBM-Classic by BuiltBrokenModding.
the class BlastRedmatter method affectEntity.
/**
* Makes an entity get affected by Red Matter.
*
* @Return True if explosion happened
*/
public boolean affectEntity(float radius, Entity entity, boolean doExplosion) {
//Ignore players that are in creative mode or can't be harmed
if (entity instanceof EntityPlayer && (((EntityPlayer) entity).capabilities.isCreativeMode || ((EntityPlayer) entity).capabilities.disableDamage)) {
return false;
}
//Ignore self
if (entity == this.controller) {
return false;
}
//Ignore entities that mark themselves are ignorable
if (entity instanceof IExplosiveIgnore) {
if (((IExplosiveIgnore) entity).canIgnore(this)) {
return false;
}
}
//Calculate different from center
double xDifference = entity.posX - position.xi() + 0.5;
double yDifference = entity.posY - position.yi() + 0.5;
double zDifference = entity.posZ - position.zi() + 0.5;
/** The percentage of the closeness of the entity. */
double xPercentage = 1 - (xDifference / radius);
double yPercentage = 1 - (yDifference / radius);
double zPercentage = 1 - (zDifference / radius);
double distancePercentage = this.position.distance(entity) / radius;
Pos entityPosition = new Pos(entity);
Pos centeredPosition = entityPosition.subtract(this.position);
centeredPosition = (Pos) centeredPosition.transform(new EulerAngle(1.5 * distancePercentage * Math.random(), 1.5 * distancePercentage * Math.random(), 1.5 * distancePercentage * Math.random()));
Location newPosition = this.position.add(centeredPosition);
// Orbit Velocity
entity.addVelocity(newPosition.x() - entityPosition.x(), 0, newPosition.z() - entityPosition.z());
// Gravity Velocity (0.015 is barely enough to overcome y gravity so do not lower)
entity.addVelocity(-xDifference * 0.015 * xPercentage, -yDifference * 0.015 * yPercentage, -zDifference * 0.015 * zPercentage);
boolean explosionCreated = false;
if (new Pos(entity.posX, entity.posY, entity.posZ).distance(position) < (ENTITY_DESTROY_RADIUS * (getRadius() / NORMAL_RADIUS))) {
if (entity instanceof EntityExplosion) {
if (((EntityExplosion) entity).getBlast() instanceof BlastAntimatter) {
if (doAudio) {
this.world().playSoundEffect(position.x(), position.y(), position.z(), ICBMClassic.PREFIX + "explosion", 7.0F, (1.0F + (this.world().rand.nextFloat() - this.world().rand.nextFloat()) * 0.2F) * 0.7F);
}
if (this.world().rand.nextFloat() > 0.85 && !this.world().isRemote) {
entity.setDead();
return explosionCreated;
}
} else if (((EntityExplosion) entity).getBlast() instanceof BlastRedmatter) {
//https://www.wolframalpha.com/input/?i=(4%2F3)pi+*+r%5E3+%3D+(4%2F3)pi+*+a%5E3+%2B+(4%2F3)pi+*+b%5E3
//We are going to merge both blasts together
double sizeA = this.getRadius();
sizeA = sizeA * sizeA * sizeA;
double sizeB = ((EntityExplosion) entity).getBlast().getRadius();
sizeB = sizeB * sizeB * sizeB;
float radiusNew = (float) Math.cbrt(sizeA + sizeB);
//Average out timer
this.callCount = (callCount + ((EntityExplosion) entity).getBlast().callCount) / 2;
//Destroy current instance
this.isAlive = false;
this.controller.setDead();
//Create new to avoid doing packet syncing
new BlastRedmatter(world(), entity, position.x(), position.y(), position.z(), radiusNew).explode();
}
//Kill explosion entity
((EntityExplosion) entity).getBlast().isAlive = false;
//Kill entity in the center of the ball
entity.setDead();
} else if (entity instanceof EntityExplosive) {
((EntityExplosive) entity).explode();
} else if (entity instanceof EntityLiving) {
((EntityLiving) entity).attackEntityFrom(DamageSource.outOfWorld, 99999999);
} else {
//Kill entity in the center of the ball
entity.setDead();
}
}
return explosionCreated;
}
use of icbm.classic.content.entity.EntityExplosive in project ICBM-Classic by BuiltBrokenModding.
the class TileEntityExplosive method trigger.
public void trigger(boolean setFire) {
if (!hasBeenTriggered) {
hasBeenTriggered = true;
EntityExplosive entityExplosive = new EntityExplosive(world, new Pos(pos).add(0.5), getDirection(), capabilityExplosive.toStack());
if (setFire) {
entityExplosive.setFire(100);
}
world.spawnEntity(entityExplosive);
world.setBlockToAir(pos);
ICBMClassic.logger().info("TileEntityExplosive: Triggered ITEM{" + capabilityExplosive.toStack() + "] " + capabilityExplosive.getExplosiveData().getRegistryName() + " at location " + getPos());
}
}
use of icbm.classic.content.entity.EntityExplosive in project ICBM-Classic by BuiltBrokenModding.
the class BlastRedmatter method attackEntity.
private void attackEntity(Entity entity, double distance) {
// Handle eating logic
if (// TODO make config driven, break section out into its own method
distance < (ConfigBlast.REDMATTER.ENTITY_DESTROY_RADIUS * getScaleFactor())) {
if (entity instanceof EntityExplosion) {
final IBlast blast = ((EntityExplosion) entity).getBlast();
if (// TODO move to capability
blast instanceof BlastAntimatter) {
if (ConfigBlast.REDMATTER.ENABLE_AUDIO) {
ICBMSounds.EXPLOSION.play(world, location.x(), location.y(), location.z(), 7.0F, CalculationHelpers.randFloatRange(world().rand, -0.6F, 0.9F), true);
}
if (this.world().rand.nextFloat() > 0.85 && !this.world().isRemote) {
// Destroy self
clearBlast();
}
} else if (// TODO move to capability, also why isAlive checks?
blast instanceof BlastRedmatter && ((BlastRedmatter) blast).isAlive && this.isAlive) {
// https://www.wolframalpha.com/input/?i=(4%2F3)pi+*+r%5E3+%3D+(4%2F3)pi+*+a%5E3+%2B+(4%2F3)pi+*+b%5E3
// We are going to merge both blasts together
final double selfRad = Math.pow(this.getBlastRadius(), 3);
final double targetRad = Math.pow(((EntityExplosion) entity).getBlast().getBlastRadius(), 3);
// TODO why cube?
final float newRad = (float) Math.cbrt(selfRad + targetRad);
// Average out timer
this.callCount = (callCount + ((BlastRedmatter) blast).callCount) / 2;
this.size = newRad;
// TODO combine the vectors
this.controller.setVelocity(0, 0, 0);
// TODO fire an event when combined (non-cancelable to allow acting on combined result)
}
// Kill the blast
blast.clearBlast();
} else if (// TODO move to capability
entity instanceof EntityMissile) {
// TODO should trigger the explosive capability
((EntityMissile) entity).doExplosion();
} else if (// TODO move to capability
entity instanceof EntityExplosive) {
// TODO should trigger the explosive capability
((EntityExplosive) entity).explode();
} else if (entity instanceof EntityLiving || entity instanceof EntityPlayer) {
entity.attackEntityFrom(new DamageSourceRedmatter(this), 2000);
} else {
// Kill entity in the center of the ball
entity.setDead();
if (entity instanceof EntityFlyingBlock) {
if (this.size < 120) {
this.size += 0.05;
}
}
}
}
}
Aggregations