Better builder detection for ConstructBlock

This commit is contained in:
Anuken 2020-10-11 14:20:53 -04:00
parent f1ec26f82b
commit 2f6f205dc7
2 changed files with 15 additions and 3 deletions

View File

@ -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);

View File

@ -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);
}
}