From 792a7b57559e13ae876b0293bd4fb5d0e48e6ff3 Mon Sep 17 00:00:00 2001 From: Anuken Date: Sat, 7 May 2022 11:44:36 -0400 Subject: [PATCH] Laser crash fix --- .../blocks/defense/turrets/LaserTurret.java | 31 ++++++++++++++----- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/core/src/mindustry/world/blocks/defense/turrets/LaserTurret.java b/core/src/mindustry/world/blocks/defense/turrets/LaserTurret.java index a2887944b0..21a0a4ac21 100644 --- a/core/src/mindustry/world/blocks/defense/turrets/LaserTurret.java +++ b/core/src/mindustry/world/blocks/defense/turrets/LaserTurret.java @@ -6,6 +6,7 @@ import arc.util.*; import mindustry.entities.bullet.*; import mindustry.gen.*; import mindustry.type.*; +import mindustry.world.consumers.*; import mindustry.world.meta.*; import static mindustry.Vars.*; @@ -29,6 +30,15 @@ public class LaserTurret extends PowerTurret{ stats.add(Stat.input, StatValues.boosters(reload, coolant.amount, coolantMultiplier, false, this::consumesLiquid)); } + @Override + public void init(){ + super.init(); + + if(coolant == null){ + coolant = findConsumer(c -> c instanceof ConsumeLiquidBase); + } + } + public class LaserTurretBuild extends PowerTurretBuild{ public Seq bullets = new Seq<>(); @@ -69,15 +79,20 @@ public class LaserTurret extends PowerTurret{ recoil = recoilAmount; }else if(reloadCounter > 0){ wasShooting = true; - //TODO does not handle multi liquid req? - Liquid liquid = liquids.current(); - float maxUsed = coolant.amount; - float used = (cheating() ? maxUsed : Math.min(liquids.get(liquid), maxUsed)) * delta(); - reloadCounter -= used * liquid.heatCapacity * coolantMultiplier; - liquids.remove(liquid, used); - if(Mathf.chance(0.06 * used)){ - coolEffect.at(x + Mathf.range(size * tilesize / 2f), y + Mathf.range(size * tilesize / 2f)); + if(coolant != null){ + //TODO does not handle multi liquid req? + Liquid liquid = liquids.current(); + float maxUsed = coolant.amount; + float used = (cheating() ? maxUsed : Math.min(liquids.get(liquid), maxUsed)) * delta(); + reloadCounter -= used * liquid.heatCapacity * coolantMultiplier; + liquids.remove(liquid, used); + + if(Mathf.chance(0.06 * used)){ + coolEffect.at(x + Mathf.range(size * tilesize / 2f), y + Mathf.range(size * tilesize / 2f)); + } + }else{ + reloadCounter -= edelta(); } } }