Repository navigation
Targeting System
This page explains which entities a turret is allowed to shoot, how it picks one of them and how it aims at it.
A turret looks at all living entities around it (refreshed every 10 ticks, turrets.turretTargetSearchTicks) and drops every entity that
- is dead, or on the config block list
general.mobBlackList(armor stands by default), - is out of range: the range is checked per axis (a cube around the turret), up to the range set in the base GUI,
- cannot be seen from the turret (line of sight to its eyes), or would need the turret to aim into its own base,
- is the owner, a trusted player or a scoreboard team member of the owner (see Ownership and Trusted Players),
- is a pet of the owner or a trusted player, or a tamed horse without owner,
- already has slowness (Slowing Turret only).
Each remaining entity is classified:
- on
general.neutralForceList→ neutral (cows by default) - on
general.mobForceList→ hostile (creepers by default) - otherwise monsters are hostile, animals and bats are neutral, everything else (players, golems, villagers, water creatures…) is neither.
An entity on both force lists is ignored on both and an error is logged.
It is a valid target if
- it is hostile and the base attacks mobs, or
- it is neutral and the base attacks neutrals, or
- it is a player and the base attacks players.
The server can switch each category off for all bases with turrets.globalCanTargetMobs, globalCanTargetNeutrals and globalCanTargetPlayers.
With multi targeting enabled on the base, entities that another turret of the same base is already shooting at are skipped.
Every turret type has five priority weights. For each valid target the turret computes a score, and the target with the highest score wins (on ties, the first one found):
score = MAX_HP × current health
+ HP_REMAINING × missing health (max health − current health)
+ DISTANCE × distance to the turret in blocks
+ ARMOR × (armor points + 1)
+ PLAYER × (100 if the target is a player, else 0)
A positive weight prefers targets with a high value of that factor, a negative weight prefers a low value, and 0 ignores it. The score only decides the order; a target with a negative score is still shot when it is the best one left.
The weights are fixed per turret type:
| Turret | MAX_HP | HP_REMAINING | DISTANCE | ARMOR | PLAYER |
|---|---|---|---|---|---|
| Disposable Item | 5 | 5 | −5 | 1 | 10 |
| Potato Cannon | −5 | −5 | −5 | 1 | 10 |
| Crossbow | −5 | −5 | −5 | 1 | 10 |
| Melee | 1 | 1 | 0 | 10 | 10 |
| Gun | 1 | 10 | −5 | −5 | 10 |
| Incendiary | 10 | −5 | −2 | 10 | 10 |
| Grenade Launcher | 10 | 10 | 20 | 1 | 10 |
| Slowing | 1 | 1 | 0 | 10 | 10 |
| Rocket Launcher | 10 | 10 | 20 | 1 | 10 |
| Teleporter | 1 | −10 | 0 | 10 | 10 |
| Arc | 5 | 10 | 2 | −10 | 10 |
| Laser | 5 | 10 | 2 | −10 | 10 |
| Rail Gun | 10 | 10 | 20 | 40 | 10 |
| Plasma Launcher | 10 | 10 | 20 | 1 | 10 |
So, for example, the Rail Gun prefers far away, heavily armored targets, the Laser avoids armored targets, and the small projectile turrets go for close, weak targets. Every turret prefers players over mobs a bit, if it is allowed to target players at all.
Turrets added by other mods set their own weights (see Turret API).
Changed in 4.0: in 3.x (1.12.2) the factors were multiplied and non-players got −100 for PLAYER, which made a single zero factor zero the whole score and inverted the ranking of mobs. In 4.x the factors are added up, and distance is the real distance (3.x used a cube root by mistake).
Coming with the next release of Open Modular Turrets for 1.12.2, 1.20.1, 1.21.1 and 1.21.11 (#539); in the released 4.0 versions every turret turns instantly.
Once a turret has a target, it turns towards the target's eyes at its turn rate (turnRate in its section of the Configuration): at most that many degrees per tick, on the yaw and on the pitch each.
A turn rate of 0 turns instantly.
The defaults per turret are in Turret Heads; the tooltips show them in degrees per second.
- A turret with a turn rate fires only once its aim is at most
turrets.aimTolerancedegrees (default 5) off the direction to the target. - While it is still turning it uses nothing: no energy, no ammo, and its cooldown is not reset. The cooldown keeps running, so it fires on the first tick its aim is within the tolerance.
- The shot itself is aimed as before: projectiles go along the lead (the predicted position of a moving target), rays towards the target's eyes, not along the turret's current aim.
- The turn rate does not change which target is picked: a turret keeps turning after its target, also one it cannot catch up with (for example a mob circling close around a slow turret), and does not fire at it until its aim is within the tolerance.
- A turret keeps its aim when the world is saved and goes on turning from there.
- Turrets from other mods turn instantly unless their mod gives them a turn rate (see Turret API).
Computer control (OpenComputers and ComputerCraft on 1.12.2, OpenComputers: Rebooted on NeoForge 1.21.1): a yaw and pitch set by a computer is taken at once, without the turn rate. Forced shots and auto fire are not held back by the aim tolerance, but they still deal less damage with distance (range falloff, see Turret Heads). See OC CC Functions.
Contraptions (Sable on 1.21.1): when a contraption rotates, a turret on it turns against the rotation at its turn rate, so a fast turning contraption can keep a slow turret from lining up. The range falloff is measured in world space.