Re-added resource harvesting from blocks

This commit is contained in:
Anuken
2018-05-20 20:51:56 -04:00
parent 26e1ad51ff
commit 75f01099ee
2 changed files with 32 additions and 10 deletions

View File

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

View File

@ -56,12 +56,12 @@ public class BuildBlock extends Block {
Shaders.blockbuild.color = Colors.get("accent");
for(TextureRegion region : entity.result.getBlockIcon()){
for(TextureRegion region : entity.recipe.result.getBlockIcon()){
Shaders.blockbuild.region = region;
Shaders.blockbuild.progress = (float)entity.progress;
Shaders.blockbuild.apply();
Draw.rect(region, tile.drawx(), tile.drawy(), entity.result.rotate ? tile.getRotation() * 90 : 0);
Draw.rect(region, tile.drawx(), tile.drawy(), entity.recipe.result.rotate ? tile.getRotation() * 90 : 0);
Graphics.flush();
}
@ -71,7 +71,7 @@ public class BuildBlock extends Block {
public void drawShadow(Tile tile) {
BuildEntity entity = tile.entity();
entity.result.drawShadow(tile);
entity.recipe.result.drawShadow(tile);
}
@Override
@ -80,7 +80,7 @@ public class BuildBlock extends Block {
if(entity.progress >= 1f){
Team team = tile.getTeam();
tile.setBlock(entity.result);
tile.setBlock(entity.recipe.result);
tile.setTeam(team);
Effects.effect(Fx.placeBlock, tile.drawx(), tile.drawy(), 0f, (float)size);
}else if(entity.progress < 0f){
@ -88,7 +88,7 @@ public class BuildBlock extends Block {
}
if(!entity.updated){
entity.progress -= 1f/entity.result.health/decaySpeedScl;
entity.progress -= 1f/entity.recipe.cost/decaySpeedScl;
}
entity.updated = false;
@ -104,7 +104,6 @@ public class BuildBlock extends Block {
private double progress = 0;
private double[] accumulator;
private Block result;
private boolean updated;
public void addProgress(InventoryModule inventory, double amount){
@ -136,7 +135,6 @@ public class BuildBlock extends Block {
public void set(Recipe recipe){
updated = true;
this.result = recipe.result;
this.recipe = recipe;
this.accumulator = new double[recipe.requirements.length];
}