Fixed block construction / Added build version to crash
This commit is contained in:
@@ -2,7 +2,6 @@ package io.anuke.mindustry.io;
|
|||||||
|
|
||||||
import com.badlogic.gdx.files.FileHandle;
|
import com.badlogic.gdx.files.FileHandle;
|
||||||
import com.badlogic.gdx.utils.Array;
|
import com.badlogic.gdx.utils.Array;
|
||||||
import com.badlogic.gdx.utils.async.AsyncExecutor;
|
|
||||||
import io.anuke.mindustry.core.GameState.State;
|
import io.anuke.mindustry.core.GameState.State;
|
||||||
import io.anuke.mindustry.game.Difficulty;
|
import io.anuke.mindustry.game.Difficulty;
|
||||||
import io.anuke.mindustry.game.GameMode;
|
import io.anuke.mindustry.game.GameMode;
|
||||||
@@ -21,8 +20,6 @@ public class Saves {
|
|||||||
private boolean saving;
|
private boolean saving;
|
||||||
private float time;
|
private float time;
|
||||||
|
|
||||||
private AsyncExecutor exec = new AsyncExecutor(1);
|
|
||||||
|
|
||||||
public void load(){
|
public void load(){
|
||||||
saves.clear();
|
saves.clear();
|
||||||
for(int i = 0; i < saveSlots; i ++){
|
for(int i = 0; i < saveSlots; i ++){
|
||||||
|
|||||||
4
core/src/io/anuke/mindustry/world/Consumption.java
Normal file
4
core/src/io/anuke/mindustry/world/Consumption.java
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
package io.anuke.mindustry.world;
|
||||||
|
|
||||||
|
public class Consumption {
|
||||||
|
}
|
||||||
@@ -176,7 +176,6 @@ public class BuildBlock extends Block {
|
|||||||
public Recipe recipe;
|
public Recipe recipe;
|
||||||
|
|
||||||
public float progress = 0;
|
public float progress = 0;
|
||||||
public float lastProgress;
|
|
||||||
public float buildCost;
|
public float buildCost;
|
||||||
/**The block that used to be here.
|
/**The block that used to be here.
|
||||||
* If a non-recipe block is being deconstructed, this is the block that is being deconstructed.*/
|
* If a non-recipe block is being deconstructed, this is the block that is being deconstructed.*/
|
||||||
@@ -185,18 +184,16 @@ public class BuildBlock extends Block {
|
|||||||
private float[] accumulator;
|
private float[] accumulator;
|
||||||
|
|
||||||
public void construct(Unit builder, TileEntity core, float amount){
|
public void construct(Unit builder, TileEntity core, float amount){
|
||||||
float maxProgress = checkRequired(core.items, amount);
|
float maxProgress = checkRequired(core.items, amount, false);
|
||||||
|
|
||||||
for (int i = 0; i < recipe.requirements.length; i++) {
|
for (int i = 0; i < recipe.requirements.length; i++) {
|
||||||
accumulator[i] += recipe.requirements[i].amount*maxProgress; //add min amount progressed to the accumulator
|
accumulator[i] += recipe.requirements[i].amount*maxProgress; //add min amount progressed to the accumulator
|
||||||
}
|
}
|
||||||
|
|
||||||
maxProgress = checkRequired(core.items, maxProgress);
|
maxProgress = checkRequired(core.items, maxProgress, true);
|
||||||
|
|
||||||
progress = Mathf.clamp(progress + maxProgress);
|
progress = Mathf.clamp(progress + maxProgress);
|
||||||
|
|
||||||
lastProgress = maxProgress;
|
|
||||||
|
|
||||||
if(progress >= 1f){
|
if(progress >= 1f){
|
||||||
CallBlocks.onConstructFinish(tile, recipe.result, builder.getID(), tile.getRotation());
|
CallBlocks.onConstructFinish(tile, recipe.result, builder.getID(), tile.getRotation());
|
||||||
}
|
}
|
||||||
@@ -228,13 +225,15 @@ public class BuildBlock extends Block {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private float checkRequired(InventoryModule inventory, float amount){
|
private float checkRequired(InventoryModule inventory, float amount, boolean remove){
|
||||||
float maxProgress = amount;
|
float maxProgress = amount;
|
||||||
|
|
||||||
for(int i = 0; i < recipe.requirements.length; i ++){
|
for(int i = 0; i < recipe.requirements.length; i ++){
|
||||||
int required = (int)(accumulator[i]); //calculate items that are required now
|
int required = (int)(accumulator[i]); //calculate items that are required now
|
||||||
|
|
||||||
if(required > 0){ //if this amount is positive...
|
if(inventory.getItem(recipe.requirements[i].item) == 0){
|
||||||
|
maxProgress = 0f;
|
||||||
|
}else if(required > 0){ //if this amount is positive...
|
||||||
//calculate how many items it can actually use
|
//calculate how many items it can actually use
|
||||||
int maxUse = Math.min(required, inventory.getItem(recipe.requirements[i].item));
|
int maxUse = Math.min(required, inventory.getItem(recipe.requirements[i].item));
|
||||||
//get this as a fraction
|
//get this as a fraction
|
||||||
@@ -243,10 +242,13 @@ public class BuildBlock extends Block {
|
|||||||
//move max progress down if this fraction is less than 1
|
//move max progress down if this fraction is less than 1
|
||||||
maxProgress = Math.min(maxProgress, maxProgress*fraction);
|
maxProgress = Math.min(maxProgress, maxProgress*fraction);
|
||||||
|
|
||||||
//remove stuff that is actually used
|
|
||||||
accumulator[i] -= maxUse;
|
accumulator[i] -= maxUse;
|
||||||
|
|
||||||
|
//remove stuff that is actually used
|
||||||
|
if(remove) {
|
||||||
inventory.removeItem(recipe.requirements[i].item, maxUse);
|
inventory.removeItem(recipe.requirements[i].item, maxUse);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
//else, no items are required yet, so just keep going
|
//else, no items are required yet, so just keep going
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -254,7 +256,7 @@ public class BuildBlock extends Block {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public float progress(){
|
public float progress(){
|
||||||
return (float)progress;
|
return progress;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setConstruct(Block previous, Recipe recipe){
|
public void setConstruct(Block previous, Recipe recipe){
|
||||||
@@ -278,7 +280,7 @@ public class BuildBlock extends Block {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void write(DataOutputStream stream) throws IOException {
|
public void write(DataOutputStream stream) throws IOException {
|
||||||
stream.writeFloat((float)progress);
|
stream.writeFloat(progress);
|
||||||
stream.writeShort(previous == null ? -1 : previous.id);
|
stream.writeShort(previous == null ? -1 : previous.id);
|
||||||
stream.writeShort(recipe == null ? -1 : recipe.result.id);
|
stream.writeShort(recipe == null ? -1 : recipe.result.id);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user