use of icbm.classic.content.entity.missile.EntityMissile in project ICBM-Classic by BuiltBrokenModding.
the class ItemRocketLauncher method onPlayerStoppedUsing.
@Override
public void onPlayerStoppedUsing(ItemStack stack, World world, EntityLivingBase entityLiving, int timeLeft) {
if (entityLiving instanceof EntityPlayer) {
EntityPlayer player = (EntityPlayer) entityLiving;
if (this.getEnergy(stack) >= ENERGY || player.capabilities.isCreativeMode) {
// Check the player's inventory and look for missiles.
for (int slot = 0; slot < player.inventory.getSizeInventory(); slot++) {
ItemStack inventoryStack = player.inventory.getStackInSlot(slot);
if (inventoryStack != null) {
if (// TODO add capability
inventoryStack.getItem() instanceof ItemMissile) {
final int explosiveID = inventoryStack.getItemDamage();
final IExplosiveData exData = ICBMClassicHelpers.getExplosive(explosiveID, true);
if (exData != null) {
// TODO add hook to block firing some missiles from launcher
if (exData.getTier().ordinal() + 1 <= ConfigMain.ROCKET_LAUNCHER_TIER_FIRE_LIMIT || player.capabilities.isCreativeMode) {
if (!world.isRemote) {
EntityMissile entityMissile = new EntityMissile(player);
entityMissile.missileType = MissileFlightType.HAND_LAUNCHER;
entityMissile.explosiveID = explosiveID;
entityMissile.acceleration = 1;
entityMissile.capabilityMissile.launchNoTarget();
world.spawnEntity(entityMissile);
if (player.isSneaking()) {
player.startRiding(entityMissile);
player.setSneaking(false);
}
if (!player.capabilities.isCreativeMode) {
player.inventory.setInventorySlotContents(slot, ItemStack.EMPTY);
player.inventoryContainer.detectAndSendChanges();
this.discharge(stack, ENERGY, true);
}
}
// Store last time player launched a rocket
clickTimePlayer.put(player.getName(), System.currentTimeMillis());
return;
}
}
}
}
}
}
}
}
use of icbm.classic.content.entity.missile.EntityMissile in project ICBM-Classic by BuiltBrokenModding.
the class CommandRemoveTest method command_removeMissiles.
@ParameterizedTest
@MethodSource("provideArgsToTest")
void command_removeMissiles(String[] args, boolean removeMissile) {
dummyCommandSender.position = new Vec3d(100, 20, 100);
// Spawn some sheep to act as decoys
TestUtils.sheep(testManager.getWorld(), 100, 20, 100);
TestUtils.sheep(testManager.getWorld(), 100, 30, 100);
TestUtils.sheep(testManager.getWorld(), 100, 40, 100);
TestUtils.missile(testManager.getWorld(), 100, 10, 100);
TestUtils.missile(testManager.getWorld(), 100, 20, 100);
// Validate start condition
Assertions.assertEquals(3, testManager.getWorld().loadedEntityList.stream().filter(e -> e instanceof EntitySheep).count(), "Should start with 3 sheep");
Assertions.assertEquals(2, testManager.getWorld().loadedEntityList.stream().filter(e -> e instanceof EntityMissile).count(), "Should start with 2 missiles");
// Trigger command
Assertions.assertDoesNotThrow(() -> command.handleCommand(testManager.getServer(), dummyCommandSender, args));
// Validate output
Assertions.assertEquals(1, dummyCommandSender.messages.size(), "Should have 1 chat message");
Assertions.assertEquals(CommandRemove.TRANSLATION_REMOVE, dummyCommandSender.pollLastMessage(), "Should get translation");
// Should still have 3 sheep
Assertions.assertEquals(3, testManager.getWorld().loadedEntityList.stream().filter(e -> e instanceof EntitySheep).count(), "Should end with 3 sheep");
Assertions.assertEquals(removeMissile ? 0 : 2, testManager.getWorld().loadedEntityList.stream().filter(e -> e instanceof EntityMissile).filter(Entity::isEntityAlive).count(), "Should end with 0 missiles");
}
use of icbm.classic.content.entity.missile.EntityMissile in project ICBM-Classic by BuiltBrokenModding.
the class TileCruiseLauncher method launch.
/**
* Launches the missile
*
* @return true if launched, false if not
*/
// @Override
public boolean 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 = MissileFlightType.CRUISE_LAUNCHER;
// TODO encode entire itemstack
entityMissile.explosiveID = this.getInventory().getStackInSlot(0).getItemDamage();
entityMissile.acceleration = 1;
entityMissile.capabilityMissile.launchNoTarget();
world.spawnEntity(entityMissile);
// TODO we are missing the item NBT, this will prevent encoding data before using the missile
// Clear slot last so we can still access data as needed or roll back changes if a crash happens
this.getInventory().decrStackSize(0, 1);
return true;
}
return false;
}
use of icbm.classic.content.entity.missile.EntityMissile 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;
}
}
}
}
}
use of icbm.classic.content.entity.missile.EntityMissile in project ICBM-Classic by BuiltBrokenModding.
the class TestUtils method missile.
public static EntityMissile missile(World world, int x, int y, int z) {
final EntityMissile missile = new EntityMissile(world);
missile.forceSpawn = true;
missile.setPosition(x, y, z);
world.spawnEntity(missile);
return missile;
}
Aggregations