Search in sources :

Example 1 with EntityMissile

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;
                            }
                        }
                    }
                }
            }
        }
    }
}
Also used : EntityPlayer(net.minecraft.entity.player.EntityPlayer) ItemStack(net.minecraft.item.ItemStack) IExplosiveData(icbm.classic.api.reg.IExplosiveData) EntityMissile(icbm.classic.content.entity.missile.EntityMissile)

Example 2 with EntityMissile

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");
}
Also used : Entity(net.minecraft.entity.Entity) TestManager(com.builtbroken.mc.testing.junit.TestManager) Arguments(org.junit.jupiter.params.provider.Arguments) EntityMissile(icbm.classic.content.entity.missile.EntityMissile) AfterAll(org.junit.jupiter.api.AfterAll) Test(org.junit.jupiter.api.Test) EntitySheep(net.minecraft.entity.passive.EntitySheep) DummyCommandSender(com.builtbroken.mc.testing.junit.testers.DummyCommandSender) AfterEach(org.junit.jupiter.api.AfterEach) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) Stream(java.util.stream.Stream) Vec3d(net.minecraft.util.math.Vec3d) WrongUsageException(net.minecraft.command.WrongUsageException) ICBMCommands(icbm.classic.command.ICBMCommands) Assertions(org.junit.jupiter.api.Assertions) TestUtils(icbm.classic.TestUtils) MethodSource(org.junit.jupiter.params.provider.MethodSource) Entity(net.minecraft.entity.Entity) EntitySheep(net.minecraft.entity.passive.EntitySheep) Vec3d(net.minecraft.util.math.Vec3d) EntityMissile(icbm.classic.content.entity.missile.EntityMissile) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 3 with EntityMissile

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;
}
Also used : EntityMissile(icbm.classic.content.entity.missile.EntityMissile)

Example 4 with EntityMissile

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;
                }
            }
        }
    }
}
Also used : EntityLiving(net.minecraft.entity.EntityLiving) EntityFlyingBlock(icbm.classic.content.entity.EntityFlyingBlock) IBlast(icbm.classic.api.explosion.IBlast) EntityPlayer(net.minecraft.entity.player.EntityPlayer) EntityExplosion(icbm.classic.content.entity.EntityExplosion) EntityExplosive(icbm.classic.content.entity.EntityExplosive) BlastAntimatter(icbm.classic.content.blast.threaded.BlastAntimatter) EntityMissile(icbm.classic.content.entity.missile.EntityMissile)

Example 5 with EntityMissile

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;
}
Also used : EntityMissile(icbm.classic.content.entity.missile.EntityMissile)

Aggregations

EntityMissile (icbm.classic.content.entity.missile.EntityMissile)8 Entity (net.minecraft.entity.Entity)4 TestManager (com.builtbroken.mc.testing.junit.TestManager)2 DummyCommandSender (com.builtbroken.mc.testing.junit.testers.DummyCommandSender)2 TestUtils (icbm.classic.TestUtils)2 IExplosiveData (icbm.classic.api.reg.IExplosiveData)2 EntitySheep (net.minecraft.entity.passive.EntitySheep)2 EntityPlayer (net.minecraft.entity.player.EntityPlayer)2 ItemStack (net.minecraft.item.ItemStack)2 TileEntity (net.minecraft.tileentity.TileEntity)2 Vec3d (net.minecraft.util.math.Vec3d)2 AfterAll (org.junit.jupiter.api.AfterAll)2 AfterEach (org.junit.jupiter.api.AfterEach)2 Assertions (org.junit.jupiter.api.Assertions)2 Test (org.junit.jupiter.api.Test)2 LauncherEvent (icbm.classic.api.events.LauncherEvent)1 IBlast (icbm.classic.api.explosion.IBlast)1 FakeBlast (icbm.classic.command.FakeBlast)1 ICBMCommands (icbm.classic.command.ICBMCommands)1 BlastAntimatter (icbm.classic.content.blast.threaded.BlastAntimatter)1