Re-added resource harvesting from blocks
This commit is contained in:
@@ -56,8 +56,27 @@ public interface BlockBuilder {
|
||||
if(unit.distanceTo(tile) > placeDistance) { //out of range, skip it.
|
||||
getPlaceQueue().removeFirst();
|
||||
}else if(current.remove){
|
||||
if(Build.validBreak(unit.team, current.x, current.y)){ //if it's valid, break it
|
||||
current.removeProgress += 1f / tile.getBreakTime();
|
||||
if(Build.validBreak(unit.team, current.x, current.y) && current.recipe == Recipe.getByResult(tile.block())){ //if it's valid, break it
|
||||
|
||||
float progress = 1f / tile.getBreakTime();
|
||||
TileEntity core = unit.getClosestCore();
|
||||
|
||||
//update accumulation of resources to add
|
||||
if(current.recipe != null && core != null){
|
||||
for(int i = 0; i < current.recipe.requirements.length; i ++){
|
||||
current.removeAccumulator[i] += current.recipe.requirements[i].amount*progress / 2f; //add scaled amount progressed to the accumulator
|
||||
int amount = (int)(current.removeAccumulator[i]); //get amount
|
||||
|
||||
if(amount > 0){ //if it's positive, add it to the core
|
||||
int accepting = core.tile.block().acceptStack(getCurrentRequest().recipe.requirements[i].item, amount, core.tile, unit);
|
||||
core.tile.block().handleStack(getCurrentRequest().recipe.requirements[i].item, amount, core.tile, unit);
|
||||
|
||||
current.removeAccumulator[i] -= accepting;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
current.removeProgress += progress;
|
||||
|
||||
if(current.removeProgress >= 1f){
|
||||
Build.breakBlock(unit.team, current.x, current.y, true, true);
|
||||
@@ -139,6 +158,7 @@ public interface BlockBuilder {
|
||||
public final boolean remove;
|
||||
|
||||
float removeProgress;
|
||||
float[] removeAccumulator;
|
||||
|
||||
/**This creates a build request.*/
|
||||
public BuildRequest(int x, int y, int rotation, Recipe recipe) {
|
||||
@@ -154,8 +174,12 @@ public interface BlockBuilder {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.rotation = -1;
|
||||
this.recipe = null;
|
||||
this.recipe = Recipe.getByResult(world.tile(x, y).block());
|
||||
this.remove = true;
|
||||
|
||||
if(this.recipe != null){
|
||||
this.removeAccumulator = new float[recipe.requirements.length];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user