diff --git a/core/src/mindustry/entities/comp/ChildComp.java b/core/src/mindustry/entities/comp/ChildComp.java index 03465fbf78..2ae553480f 100644 --- a/core/src/mindustry/entities/comp/ChildComp.java +++ b/core/src/mindustry/entities/comp/ChildComp.java @@ -4,7 +4,7 @@ import arc.math.*; import arc.util.*; import mindustry.annotations.Annotations.*; import mindustry.gen.*; -import mindustry.world.blocks.defense.turrets.BaseTurret.*; +import mindustry.world.blocks.*; @Component abstract class ChildComp implements Posc, Rotc{ @@ -23,9 +23,9 @@ abstract class ChildComp implements Posc, Rotc{ if(parent instanceof Rotc r){ offsetPos = -r.rotation(); offsetRot = rotation - r.rotation(); - }else if(parent instanceof BaseTurretBuild build){ - offsetPos = -build.rotation; - offsetRot = rotation - build.rotation; + }else if(parent instanceof RotBlock rot){ + offsetPos = -rot.buildRotation(); + offsetRot = rotation - rot.buildRotation(); } } } @@ -39,10 +39,10 @@ abstract class ChildComp implements Posc, Rotc{ x = parent.getX() + Angles.trnsx(r.rotation() + offsetPos, offsetX, offsetY); y = parent.getY() + Angles.trnsy(r.rotation() + offsetPos, offsetX, offsetY); rotation = r.rotation() + offsetRot; - }else if(parent instanceof BaseTurretBuild build){ - x = parent.getX() + Angles.trnsx(build.rotation + offsetPos, offsetX, offsetY); - y = parent.getY() + Angles.trnsy(build.rotation + offsetPos, offsetX, offsetY); - rotation = build.rotation + offsetRot; + }else if(parent instanceof RotBlock rot){ + x = parent.getX() + Angles.trnsx(rot.buildRotation() + offsetPos, offsetX, offsetY); + y = parent.getY() + Angles.trnsy(rot.buildRotation() + offsetPos, offsetX, offsetY); + rotation = rot.buildRotation() + offsetRot; } }else{ x = parent.getX() + offsetX; diff --git a/core/src/mindustry/type/UnitType.java b/core/src/mindustry/type/UnitType.java index d7dfcf16fe..b9f7ecd089 100644 --- a/core/src/mindustry/type/UnitType.java +++ b/core/src/mindustry/type/UnitType.java @@ -1270,6 +1270,7 @@ public class UnitType extends UnlockableContent implements Senseable{ DrawPart.params.life = s.fin(); } + applyColor(unit); part.draw(DrawPart.params); } } diff --git a/core/src/mindustry/type/Weapon.java b/core/src/mindustry/type/Weapon.java index 151a0f69ee..d67a1ca032 100644 --- a/core/src/mindustry/type/Weapon.java +++ b/core/src/mindustry/type/Weapon.java @@ -228,6 +228,7 @@ public class Weapon implements Cloneable{ var part = parts.get(i); DrawPart.params.setRecoil(part.recoilIndex >= 0 && mount.recoils != null ? mount.recoils[part.recoilIndex] : mount.recoil); if(part.under){ + unit.type.applyColor(unit); part.draw(DrawPart.params); } } @@ -262,6 +263,7 @@ public class Weapon implements Cloneable{ var part = parts.get(i); DrawPart.params.setRecoil(part.recoilIndex >= 0 && mount.recoils != null ? mount.recoils[part.recoilIndex] : mount.recoil); if(!part.under){ + unit.type.applyColor(unit); part.draw(DrawPart.params); } } diff --git a/core/src/mindustry/world/blocks/RotBlock.java b/core/src/mindustry/world/blocks/RotBlock.java new file mode 100644 index 0000000000..470b9dd43a --- /dev/null +++ b/core/src/mindustry/world/blocks/RotBlock.java @@ -0,0 +1,6 @@ +package mindustry.world.blocks; + +/** Any block that has 360-degree rotation */ +public interface RotBlock{ + float buildRotation(); +} diff --git a/core/src/mindustry/world/blocks/defense/BuildTurret.java b/core/src/mindustry/world/blocks/defense/BuildTurret.java index 9dfaca633f..10330650ac 100644 --- a/core/src/mindustry/world/blocks/defense/BuildTurret.java +++ b/core/src/mindustry/world/blocks/defense/BuildTurret.java @@ -77,7 +77,7 @@ public class BuildTurret extends BaseTurret{ return new TextureRegion[]{baseRegion, region}; } - public class BuildTurretBuild extends BaseTurretBuild implements ControlBlock{ + public class BuildTurretBuild extends BaseTurretBuild implements ControlBlock, RotBlock{ public BlockUnitc unit = (BlockUnitc)unitType.create(team); public @Nullable Unit following; public @Nullable BlockPlan lastPlan; @@ -92,6 +92,11 @@ public class BuildTurret extends BaseTurret{ return true; } + @Override + public float buildRotation(){ + return unit.rotation(); + } + @Override public Unit unit(){ //make sure stats are correct diff --git a/core/src/mindustry/world/blocks/defense/turrets/BaseTurret.java b/core/src/mindustry/world/blocks/defense/turrets/BaseTurret.java index a959c00ba2..dbe7794611 100644 --- a/core/src/mindustry/world/blocks/defense/turrets/BaseTurret.java +++ b/core/src/mindustry/world/blocks/defense/turrets/BaseTurret.java @@ -9,6 +9,7 @@ import mindustry.gen.*; import mindustry.graphics.*; import mindustry.logic.*; import mindustry.world.*; +import mindustry.world.blocks.*; import mindustry.world.consumers.*; import mindustry.world.meta.*; @@ -79,7 +80,7 @@ public class BaseTurret extends Block{ stats.add(Stat.shootRange, range / tilesize, StatUnit.blocks); } - public class BaseTurretBuild extends Building implements Ranged{ + public class BaseTurretBuild extends Building implements Ranged, RotBlock{ public float rotation = 90; @Override @@ -87,6 +88,11 @@ public class BaseTurret extends Block{ return range; } + @Override + public float buildRotation(){ + return rotation; + } + @Override public void drawSelect(){ Drawf.dashCircle(x, y, range(), team.color); diff --git a/core/src/mindustry/world/blocks/distribution/MassDriver.java b/core/src/mindustry/world/blocks/distribution/MassDriver.java index 6366419242..7fc0d5f0ec 100644 --- a/core/src/mindustry/world/blocks/distribution/MassDriver.java +++ b/core/src/mindustry/world/blocks/distribution/MassDriver.java @@ -18,6 +18,7 @@ import mindustry.graphics.*; import mindustry.logic.*; import mindustry.type.*; import mindustry.world.*; +import mindustry.world.blocks.*; import mindustry.world.meta.*; import static mindustry.Vars.*; @@ -104,7 +105,7 @@ public class MassDriver extends Block{ } } - public class MassDriverBuild extends Building{ + public class MassDriverBuild extends Building implements RotBlock{ public int link = -1; public float rotation = 90; public float reloadCounter = 0f; @@ -112,6 +113,11 @@ public class MassDriver extends Block{ //TODO use queue? this array usually holds about 3 shooters max anyway public OrderedSet waitingShooters = new OrderedSet<>(); + @Override + public float buildRotation(){ + return rotation; + } + public Building currentShooter(){ return waitingShooters.isEmpty() ? null : waitingShooters.first(); } diff --git a/core/src/mindustry/world/blocks/payloads/PayloadMassDriver.java b/core/src/mindustry/world/blocks/payloads/PayloadMassDriver.java index 314e77d5f7..0b3efc09c9 100644 --- a/core/src/mindustry/world/blocks/payloads/PayloadMassDriver.java +++ b/core/src/mindustry/world/blocks/payloads/PayloadMassDriver.java @@ -14,6 +14,7 @@ import mindustry.entities.units.*; import mindustry.gen.*; import mindustry.graphics.*; import mindustry.logic.*; +import mindustry.world.blocks.*; import mindustry.world.meta.*; import static mindustry.Vars.*; @@ -126,7 +127,7 @@ public class PayloadMassDriver extends PayloadBlock{ return new TextureRegion[]{leftRegion, rightRegion, capRegion}; } - public class PayloadDriverBuild extends PayloadBlockBuild{ + public class PayloadDriverBuild extends PayloadBlockBuild implements RotBlock{ public int link = -1; public float turretRotation = 90; public float reloadCounter = 0f, charge = 0f; @@ -143,6 +144,11 @@ public class PayloadMassDriver extends PayloadBlock{ return waitingShooters.isEmpty() ? null : waitingShooters.first(); } + @Override + public float buildRotation(){ + return rotation; + } + @Override public void updateTile(){ super.updateTile(); diff --git a/core/src/mindustry/world/blocks/units/RepairTurret.java b/core/src/mindustry/world/blocks/units/RepairTurret.java index 87624efb84..86b29c79a4 100644 --- a/core/src/mindustry/world/blocks/units/RepairTurret.java +++ b/core/src/mindustry/world/blocks/units/RepairTurret.java @@ -16,6 +16,7 @@ import mindustry.gen.*; import mindustry.graphics.*; import mindustry.logic.*; import mindustry.world.*; +import mindustry.world.blocks.*; import mindustry.world.consumers.*; import mindustry.world.meta.*; @@ -147,11 +148,16 @@ public class RepairTurret extends Block{ } } - public class RepairPointBuild extends Building implements Ranged{ + public class RepairPointBuild extends Building implements Ranged, RotBlock{ public Unit target; public Vec2 offset = new Vec2(), lastEnd = new Vec2(); public float strength, rotation = 90; + @Override + public float buildRotation(){ + return rotation; + } + @Override public void draw(){ Draw.rect(baseRegion, x, y);