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");
}
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;
}
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;
}
Aggregations