From 8436599c79636d4b83bf3c71f9d57297f19cdc8f Mon Sep 17 00:00:00 2001 From: Anuken Date: Tue, 20 Jul 2021 14:12:48 -0400 Subject: [PATCH] #5050 --- .../mindustry/entities/bullet/BulletType.java | 2 +- .../mindustry/entities/comp/BulletComp.java | 22 +++++++++++-------- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/core/src/mindustry/entities/bullet/BulletType.java b/core/src/mindustry/entities/bullet/BulletType.java index 4a1df75e62..3640299921 100644 --- a/core/src/mindustry/entities/bullet/BulletType.java +++ b/core/src/mindustry/entities/bullet/BulletType.java @@ -371,7 +371,7 @@ public class BulletType extends Content implements Cloneable{ e -> e.checkTarget(collidesAir, collidesGround) && e.team != b.team, t -> collidesGround && (t.team != b.team || t.damaged())); }else{ - target = Units.closestTarget(b.team, b.x, b.y, homingRange, e -> e.checkTarget(collidesAir, collidesGround), t -> collidesGround); + target = Units.closestTarget(b.team, b.x, b.y, homingRange, e -> e.checkTarget(collidesAir, collidesGround) && !b.hasCollided(e.id), t -> collidesGround && !b.hasCollided(t.id)); } if(target != null){ diff --git a/core/src/mindustry/entities/comp/BulletComp.java b/core/src/mindustry/entities/comp/BulletComp.java index e1254670f0..839e0b0c44 100644 --- a/core/src/mindustry/entities/comp/BulletComp.java +++ b/core/src/mindustry/entities/comp/BulletComp.java @@ -80,6 +80,10 @@ abstract class BulletComp implements Timedc, Damagec, Hitboxc, Teamc, Posc, Draw remove(); } + public boolean hasCollided(int id){ + return collided.size != 0 && !collided.contains(id); + } + @Replace public float clipSize(){ return type.drawSize; @@ -90,7 +94,7 @@ abstract class BulletComp implements Timedc, Damagec, Hitboxc, Teamc, Posc, Draw public boolean collides(Hitboxc other){ return type.collides && (other instanceof Teamc t && t.team() != team) && !(other instanceof Flyingc f && !f.checkTarget(type.collidesAir, type.collidesGround)) - && !(type.pierce && collided.contains(other.id())); //prevent multiple collisions + && !(type.pierce && hasCollided(other.id())); //prevent multiple collisions } @MethodPriority(100) @@ -116,16 +120,16 @@ abstract class BulletComp implements Timedc, Damagec, Hitboxc, Teamc, Posc, Draw if(type.collidesTiles && type.collides && type.collidesGround){ world.raycastEach(World.toTile(lastX()), World.toTile(lastY()), tileX(), tileY(), (x, y) -> { - Building tile = world.build(x, y); - if(tile == null || !isAdded()) return false; + Building build = world.build(x, y); + if(build == null || !isAdded()) return false; - if(tile.collide(self()) && type.testCollision(self(), tile) && !tile.dead() && (type.collidesTeam || tile.team != team) && !(type.pierceBuilding && collided.contains(tile.id))){ + if(build.collide(self()) && type.testCollision(self(), build) && !build.dead() && (type.collidesTeam || build.team != team) && !(type.pierceBuilding && hasCollided(build.id))){ boolean remove = false; - float health = tile.health; + float health = build.health; - if(tile.team != team){ - remove = tile.collision(self()); + if(build.team != team){ + remove = build.collision(self()); } if(remove || type.collidesTeam){ @@ -133,11 +137,11 @@ abstract class BulletComp implements Timedc, Damagec, Hitboxc, Teamc, Posc, Draw hit = true; remove(); }else{ - collided.add(tile.id); + collided.add(build.id); } } - type.hitTile(self(), tile, health, true); + type.hitTile(self(), build, health, true); return !type.pierceBuilding; }