use of icbm.classic.content.entity.EntityMissile in project ICBM-Classic by BuiltBrokenModding.
the class CommandICBM method processCommand.
@Override
public void processCommand(ICommandSender sender, String[] args) {
try {
EntityPlayer entityPlayer = (EntityPlayer) sender;
int dimension = entityPlayer.worldObj.provider.dimensionId;
if (args == null || args.length == 0 || args[0].equalsIgnoreCase("help")) {
((EntityPlayer) sender).addChatComponentMessage(new ChatComponentText("/icbmc help"));
((EntityPlayer) sender).addChatComponentMessage(new ChatComponentText("/icbmc lag <radius>"));
((EntityPlayer) sender).addChatComponentMessage(new ChatComponentText("/icbmc remove <All/Missile/Explosion> <radius>"));
((EntityPlayer) sender).addChatComponentMessage(new ChatComponentText("/icbmc emp <radius>"));
return;
} else if (args.length >= 2 && args[0].equalsIgnoreCase("lag")) {
int radius = parseInt(sender, args[1]);
if (radius > 0) {
AxisAlignedBB bounds = AxisAlignedBB.getBoundingBox(entityPlayer.posX - radius, entityPlayer.posY - radius, entityPlayer.posZ - radius, entityPlayer.posX + radius, entityPlayer.posY + radius, entityPlayer.posZ + radius);
List<Entity> entitiesNearby = entityPlayer.worldObj.getEntitiesWithinAABB(Entity.class, bounds);
for (Entity entity : entitiesNearby) {
if (entity instanceof EntityFlyingBlock) {
((EntityFlyingBlock) entity).setBlock();
} else if (entity instanceof EntityMissile) {
entity.setDead();
} else if (entity instanceof EntityExplosion) {
entity.setDead();
}
}
((EntityPlayer) sender).addChatComponentMessage(new ChatComponentText("Removed all ICBM lag sources within " + radius + " radius."));
return;
} else {
throw new WrongUsageException("Radius needs to be higher than zero");
}
} else if (args.length >= 3 && args[0].equalsIgnoreCase("remove")) {
int radius = parseInt(sender, args[2]);
boolean all = args[1].equalsIgnoreCase("all");
boolean missile = args[1].equalsIgnoreCase("missiles");
boolean explosion = args[1].equalsIgnoreCase("explosion");
String str = "entities";
if (missile) {
str = "missiles";
}
if (explosion) {
str = "explosions";
}
if (radius > 0) {
EntityPlayer player = (EntityPlayer) sender;
AxisAlignedBB bounds = AxisAlignedBB.getBoundingBox(player.posX - radius, player.posY - radius, player.posZ - radius, player.posX + radius, player.posY + radius, player.posZ + radius);
List<Entity> entitiesNearby = player.worldObj.getEntitiesWithinAABB(Entity.class, bounds);
for (Entity entity : entitiesNearby) {
if ((all || explosion) && entity instanceof EntityFlyingBlock) {
((EntityFlyingBlock) entity).setBlock();
} else if ((all || missile) && entity instanceof EntityMissile) {
entity.setDead();
} else if ((all || explosion) && entity instanceof EntityExplosion) {
entity.setDead();
}
}
((EntityPlayer) sender).addChatComponentMessage(new ChatComponentText("Removed all ICBM " + str + " within " + radius + " radius."));
return;
} else {
throw new WrongUsageException("Radius needs to be higher than zero");
}
} else if (args.length >= 2 && args[0].equalsIgnoreCase("emp")) {
int radius = parseInt(sender, args[1]);
if (radius > 0) {
new BlastEMP(entityPlayer.worldObj, null, entityPlayer.posX, entityPlayer.posY, entityPlayer.posZ, radius).setEffectBlocks().setEffectEntities().doExplode();
switch(entityPlayer.worldObj.rand.nextInt(20)) {
case 0:
((EntityPlayer) sender).addChatComponentMessage(new ChatComponentText("Did you pay the power bill?"));
return;
case 1:
((EntityPlayer) sender).addChatComponentMessage(new ChatComponentText("See them power their toys now!"));
return;
case 2:
((EntityPlayer) sender).addChatComponentMessage(new ChatComponentText("Hey who turned the lights out."));
return;
case 3:
((EntityPlayer) sender).addChatComponentMessage(new ChatComponentText("Ha! I run on steam power!"));
return;
case 4:
((EntityPlayer) sender).addChatComponentMessage(new ChatComponentText("The power of lighting at my finger tips!"));
return;
default:
((EntityPlayer) sender).addChatComponentMessage(new ChatComponentText("Zap!"));
return;
}
} else {
throw new WrongUsageException("Radius needs to be higher than zero");
}
}
} catch (Exception e) {
}
throw new WrongUsageException(this.getCommandUsage(sender));
}
use of icbm.classic.content.entity.EntityMissile in project ICBM-Classic by BuiltBrokenModding.
the class TileCruiseLauncher method launch.
/**
* Launches the missile
*/
@Override
public void launch() {
if (this.canLaunch()) {
this.extractEnergy();
EntityMissile entityMissile = new EntityMissile(world(), xi() + 0.5, yi() + 1.5, zi() + 0.5, -(float) currentAim.yaw() - 180, -(float) currentAim.pitch(), 2);
entityMissile.missileType = EntityMissile.MissileType.CruiseMissile;
entityMissile.explosiveID = Explosives.get(this.getStackInSlot(0).getItemDamage());
entityMissile.acceleration = 1;
entityMissile.launch(null);
world().spawnEntityInWorld(entityMissile);
//Clear slot last so we can still access data as needed or roll back changes if a crash happens
this.decrStackSize(0, 1);
}
}
use of icbm.classic.content.entity.EntityMissile in project ICBM-Classic by BuiltBrokenModding.
the class BlastSonic method doExplode.
@Override
public void doExplode() {
int r = this.callCount;
if (!this.world().isRemote) {
if (this.thread != null && this.thread.isComplete) {
Iterator<Pos> it = this.thread.results.iterator();
while (it.hasNext()) {
Pos targetPosition = it.next();
double distance = targetPosition.distance(position);
if (distance > r || distance < r - 3) {
continue;
}
Block blockID = this.world().getBlock(targetPosition.xi(), targetPosition.yi(), targetPosition.zi());
if (blockID == Blocks.air || blockID.blockHardness < 0) {
continue;
}
//if (block instanceof IForceFieldBlock)
//{
// continue;
//}
int metadata = this.world().getBlockMetadata(targetPosition.xi(), targetPosition.yi(), targetPosition.zi());
if (distance < r - 1 || this.world().rand.nextInt(3) > 0) {
if (blockID == ICBMClassic.blockExplosive) {
BlockExplosive.triggerExplosive(this.world(), targetPosition.xi(), targetPosition.yi(), targetPosition.zi(), ((TileEntityExplosive) this.world().getTileEntity(targetPosition.xi(), targetPosition.yi(), targetPosition.zi())).explosive, 1);
} else {
this.world().setBlockToAir(targetPosition.xi(), targetPosition.yi(), targetPosition.zi());
}
targetPosition = targetPosition.add(0.5D);
if (this.world().rand.nextFloat() < 0.3 * (this.getRadius() - r)) {
EntityFlyingBlock entity = new EntityFlyingBlock(this.world(), targetPosition, blockID, metadata);
this.world().spawnEntityInWorld(entity);
entity.yawChange = 50 * this.world().rand.nextFloat();
entity.pitchChange = 100 * this.world().rand.nextFloat();
}
it.remove();
}
}
}
}
int radius = 2 * this.callCount;
AxisAlignedBB bounds = AxisAlignedBB.getBoundingBox(position.x() - radius, position.y() - radius, position.z() - radius, position.x() + radius, position.y() + radius, position.z() + radius);
List<Entity> allEntities = this.world().getEntitiesWithinAABB(Entity.class, bounds);
synchronized (allEntities) {
for (Iterator it = allEntities.iterator(); it.hasNext(); ) {
Entity entity = (Entity) it.next();
if (entity instanceof EntityMissile) {
((EntityMissile) entity).setExplode();
break;
} else {
double xDifference = entity.posX - position.x();
double zDifference = entity.posZ - position.z();
r = (int) this.getRadius();
if (xDifference < 0) {
r = (int) -this.getRadius();
}
entity.motionX += (r - xDifference) * 0.02 * this.world().rand.nextFloat();
entity.motionY += 3 * this.world().rand.nextFloat();
r = (int) this.getRadius();
if (zDifference < 0) {
r = (int) -this.getRadius();
}
entity.motionZ += (r - zDifference) * 0.02 * this.world().rand.nextFloat();
}
}
}
if (this.callCount > this.getRadius()) {
this.controller.endExplosion();
}
}
use of icbm.classic.content.entity.EntityMissile in project ICBM-Classic by BuiltBrokenModding.
the class MissileAnti method update.
@Override
public void update(EntityMissile missileObj) {
if (missileObj.lockedTarget != null) {
Pos target = new Pos(missileObj.lockedTarget);
if (missileObj.lockedTarget.isDead) {
missileObj.explode();
return;
}
if (missileObj.lockedTarget instanceof EntityMissile) {
target = ((EntityMissile) missileObj.lockedTarget).getPredictedPosition(4);
}
missileObj.motionX = (target.x() - missileObj.posX) * (0.3F);
missileObj.motionY = (target.y() - missileObj.posY) * (0.3F);
missileObj.motionZ = (target.z() - missileObj.posZ) * (0.3F);
return;
}
AxisAlignedBB bounds = AxisAlignedBB.getBoundingBox(missileObj.posX - ABMRange, missileObj.posY - ABMRange, missileObj.posZ - ABMRange, missileObj.posX + ABMRange, missileObj.posY + ABMRange, missileObj.posZ + ABMRange);
// TODO: Check if this works.
Entity nearestEntity = missileObj.worldObj.findNearestEntityWithinAABB(EntityMissile.class, bounds, missileObj);
if (nearestEntity instanceof EntityMissile) {
// Lock target onto missileObj missile
missileObj.lockedTarget = nearestEntity;
missileObj.didTargetLockBefore = true;
missileObj.worldObj.playSoundAtEntity(missileObj, ICBMClassic.PREFIX + "targetlocked", 5F, 0.9F);
} else {
missileObj.motionX = missileObj.deltaPathX / missileObj.missileFlightTime;
missileObj.motionZ = missileObj.deltaPathZ / missileObj.missileFlightTime;
if (missileObj.didTargetLockBefore == true) {
missileObj.explode();
}
}
}
use of icbm.classic.content.entity.EntityMissile in project ICBM-Classic by BuiltBrokenModding.
the class MissileNuclearCluster method update.
@Override
public void update(EntityMissile missileObj) {
if (missileObj.motionY < -0.5) {
if (missileObj.missileCount < MAX_CLUSTER) {
if (!missileObj.worldObj.isRemote) {
Pos position = missileObj.toPos();
EntityMissile clusterMissile = new EntityMissile(missileObj.worldObj);
//TODO randomize spread to prevent collisions
clusterMissile.setPosition(position.x(), position.y(), position.z());
clusterMissile.explosiveID = Explosives.NUCLEAR;
missileObj.worldObj.spawnEntityInWorld(clusterMissile);
clusterMissile.missileType = MissileType.CruiseMissile;
clusterMissile.protectionTime = 20;
clusterMissile.launch(missileObj.targetVector.add(new Pos((missileObj.missileCount - MAX_CLUSTER / 2) * random() * 30, (missileObj.missileCount - MAX_CLUSTER / 2) * random() * 30, (missileObj.missileCount - MAX_CLUSTER / 2) * random() * 30)));
}
missileObj.protectionTime = 20;
missileObj.missileCount++;
} else {
missileObj.setDead();
}
}
}
Aggregations