Search in sources :

Example 6 with EntityMissile

use of icbm.classic.content.entity.missile.EntityMissile in project ICBM-Classic by BuiltBrokenModding.

the class CommandLagTest method command_removeMissiles.

@Test
void command_removeMissiles() {
    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, 10, -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, new String[0]));
    // Validate output
    Assertions.assertEquals(1, dummyCommandSender.messages.size(), "Should have 1 chat message");
    Assertions.assertEquals(CommandLag.TRANSLATION_LAG_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(0, 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) FakeBlast(icbm.classic.command.FakeBlast) TestManager(com.builtbroken.mc.testing.junit.TestManager) 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) ExplosiveHandler(icbm.classic.lib.explosive.ExplosiveHandler) Vec3d(net.minecraft.util.math.Vec3d) Assertions(org.junit.jupiter.api.Assertions) TestUtils(icbm.classic.TestUtils) Entity(net.minecraft.entity.Entity) EntitySheep(net.minecraft.entity.passive.EntitySheep) Vec3d(net.minecraft.util.math.Vec3d) EntityMissile(icbm.classic.content.entity.missile.EntityMissile) Test(org.junit.jupiter.api.Test)

Example 7 with EntityMissile

use of icbm.classic.content.entity.missile.EntityMissile in project ICBM-Classic by BuiltBrokenModding.

the class TileLauncherBase method launchMissile.

/**
 * Launches the missile
 *
 * @param target     - The target in which the missile will land in
 * @param lockHeight - height to wait before curving the missile
 */
public boolean launchMissile(Pos target, int lockHeight) {
    // Allow canceling missile launches
    if (MinecraftForge.EVENT_BUS.post(new LauncherEvent.PreLaunch(missileLauncher, missileHolder))) {
        return false;
    }
    final ItemStack stack = getMissileStack();
    if (// TODO capability
    stack.getItem() == ItemReg.itemMissile) {
        IExplosiveData explosiveData = ICBMClassicHelpers.getExplosive(stack.getItemDamage(), true);
        if (explosiveData != null) {
            target = applyInaccuracy(target);
            if (isServer()) {
                // TODO generate entity from item using handler
                EntityMissile missile = new EntityMissile(getWorld());
                // Set data
                missile.explosiveID = explosiveData.getRegistryID();
                // TODO store our launcher instance or UUID
                missile.launcherPos = new Pos((TileEntity) this);
                // TODO store offset
                missile.setPosition(xi() + 0.5, yi() + 3, zi() + 0.5);
                // Trigger launch event
                missile.capabilityMissile.launch(target.x(), target.y(), target.z(), lockHeight);
                // Spawn entity
                ((WorldServer) getWorld()).addScheduledTask(() -> getWorld().spawnEntity(missile));
                // Grab rider
                if (// TODO add hook to disable riding some missiles
                seat != null && seat.getRidingEntity() != null) {
                    Entity entity = seat.getRidingEntity();
                    seat.getRidingEntity().startRiding(null);
                    entity.startRiding(missile);
                }
                // Remove item
                getInventory().decrStackSize(0, 1);
            }
            return true;
        }
    }
    return false;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) Entity(net.minecraft.entity.Entity) TileEntity(net.minecraft.tileentity.TileEntity) Pos(icbm.classic.lib.transform.vector.Pos) BlockPos(net.minecraft.util.math.BlockPos) LauncherEvent(icbm.classic.api.events.LauncherEvent) WorldServer(net.minecraft.world.WorldServer) ItemStack(net.minecraft.item.ItemStack) IExplosiveData(icbm.classic.api.reg.IExplosiveData) EntityMissile(icbm.classic.content.entity.missile.EntityMissile)

Example 8 with EntityMissile

use of icbm.classic.content.entity.missile.EntityMissile in project ICBM-Classic by BuiltBrokenModding.

the class TileRadarStation method getGUIPacket.

@Override
protected PacketTile getGUIPacket() {
    PacketTile packet = new PacketTile("gui", GUI_PACKET_ID, this);
    packet.write(alarmRange);
    packet.write(safetyRange);
    packet.write(getFrequency());
    packet.write(detectedEntities.size());
    if (detectedEntities.size() > 0) {
        for (Entity entity : detectedEntities) {
            if (entity != null && entity.isEntityAlive()) {
                packet.write(entity.getEntityId());
                int type = RadarObjectType.OTHER.ordinal();
                if (entity instanceof EntityMissile) {
                    type = isMissileGoingToHit((EntityMissile) entity) ? RadarObjectType.MISSILE_IMPACT.ordinal() : RadarObjectType.MISSILE.ordinal();
                }
                packet.write(type);
            } else {
                packet.write(-1);
                packet.write(0);
            }
        }
    }
    return packet;
}
Also used : Entity(net.minecraft.entity.Entity) TileEntity(net.minecraft.tileentity.TileEntity) PacketTile(icbm.classic.lib.network.packet.PacketTile) Point(icbm.classic.lib.transform.vector.Point) 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