From 2f6f205dc77b402d1c5d4056f2ec2c8ef8734edd Mon Sep 17 00:00:00 2001 From: Anuken Date: Sun, 11 Oct 2020 14:20:53 -0400 Subject: [PATCH] Better builder detection for ConstructBlock --- .../src/mindustry/graphics/OverlayRenderer.java | 1 - .../mindustry/world/blocks/ConstructBlock.java | 17 +++++++++++++++-- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/core/src/mindustry/graphics/OverlayRenderer.java b/core/src/mindustry/graphics/OverlayRenderer.java index e796b0b168..19569ed1a3 100644 --- a/core/src/mindustry/graphics/OverlayRenderer.java +++ b/core/src/mindustry/graphics/OverlayRenderer.java @@ -153,7 +153,6 @@ public class OverlayRenderer{ input.drawOverSelect(); if(ui.hudfrag.blockfrag.hover() instanceof Unit unit && unit.controller() instanceof LogicAI ai && ai.controller instanceof Building build){ - Draw.z(Layer.overlayUI); Drawf.square(build.x, build.y, build.block.size * tilesize/2f + 2f); if(!unit.within(build, unit.hitSize * 2f)){ Drawf.arrow(unit.x, unit.y, build.x, build.y, unit.hitSize *2f, 4f); diff --git a/core/src/mindustry/world/blocks/ConstructBlock.java b/core/src/mindustry/world/blocks/ConstructBlock.java index 304ef07afa..c228397a32 100644 --- a/core/src/mindustry/world/blocks/ConstructBlock.java +++ b/core/src/mindustry/world/blocks/ConstructBlock.java @@ -146,6 +146,9 @@ public class ConstructBlock extends Block{ public Block previous; public Object lastConfig; + @Nullable + public Unit lastBuilder; + private float[] accumulator; private float[] totalAccumulator; @@ -218,6 +221,10 @@ public class ConstructBlock extends Block{ return; } + if(builder.isPlayer()){ + lastBuilder = builder; + } + lastConfig = config; if(cblock.requirements.length != accumulator.length || totalAccumulator.length != cblock.requirements.length){ @@ -237,13 +244,18 @@ public class ConstructBlock extends Block{ progress = Mathf.clamp(progress + maxProgress); if(progress >= 1f || state.rules.infiniteResources){ - constructed(tile, cblock, builder, (byte)rotation, builder.team, config); + if(lastBuilder == null) lastBuilder = builder; + constructed(tile, cblock, lastBuilder, (byte)rotation, builder.team, config); } } public void deconstruct(Unit builder, @Nullable Building core, float amount){ float deconstructMultiplier = state.rules.deconstructRefundMultiplier; + if(builder.isPlayer()){ + lastBuilder = builder; + } + if(cblock != null){ ItemStack[] requirements = cblock.requirements; if(requirements.length != accumulator.length || totalAccumulator.length != requirements.length){ @@ -275,7 +287,8 @@ public class ConstructBlock extends Block{ progress = Mathf.clamp(progress - amount); if(progress <= 0 || state.rules.infiniteResources){ - Call.deconstructFinish(tile, this.cblock == null ? previous : this.cblock, builder); + if(lastBuilder == null) lastBuilder = builder; + Call.deconstructFinish(tile, this.cblock == null ? previous : this.cblock, lastBuilder); } }