Better builder detection for ConstructBlock
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user