mirror of
https://github.com/Anuken/Mindustry.git
synced 2025-02-22 04:28:27 +07:00
Fixed block construction / Added build version to crash
This commit is contained in:
parent
b6531efe08
commit
c2c837329c
@ -2,7 +2,6 @@ package io.anuke.mindustry.io;
|
||||
|
||||
import com.badlogic.gdx.files.FileHandle;
|
||||
import com.badlogic.gdx.utils.Array;
|
||||
import com.badlogic.gdx.utils.async.AsyncExecutor;
|
||||
import io.anuke.mindustry.core.GameState.State;
|
||||
import io.anuke.mindustry.game.Difficulty;
|
||||
import io.anuke.mindustry.game.GameMode;
|
||||
@ -21,8 +20,6 @@ public class Saves {
|
||||
private boolean saving;
|
||||
private float time;
|
||||
|
||||
private AsyncExecutor exec = new AsyncExecutor(1);
|
||||
|
||||
public void load(){
|
||||
saves.clear();
|
||||
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 float progress = 0;
|
||||
public float lastProgress;
|
||||
public float buildCost;
|
||||
/**The block that used to be here.
|
||||
* 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;
|
||||
|
||||
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++) {
|
||||
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);
|
||||
|
||||
lastProgress = maxProgress;
|
||||
|
||||
if(progress >= 1f){
|
||||
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;
|
||||
|
||||
for(int i = 0; i < recipe.requirements.length; i ++){
|
||||
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
|
||||
int maxUse = Math.min(required, inventory.getItem(recipe.requirements[i].item));
|
||||
//get this as a fraction
|
||||
@ -243,9 +242,12 @@ public class BuildBlock extends Block {
|
||||
//move max progress down if this fraction is less than 1
|
||||
maxProgress = Math.min(maxProgress, maxProgress*fraction);
|
||||
|
||||
//remove stuff that is actually used
|
||||
accumulator[i] -= maxUse;
|
||||
inventory.removeItem(recipe.requirements[i].item, maxUse);
|
||||
|
||||
//remove stuff that is actually used
|
||||
if(remove) {
|
||||
inventory.removeItem(recipe.requirements[i].item, maxUse);
|
||||
}
|
||||
}
|
||||
//else, no items are required yet, so just keep going
|
||||
}
|
||||
@ -254,7 +256,7 @@ public class BuildBlock extends Block {
|
||||
}
|
||||
|
||||
public float progress(){
|
||||
return (float)progress;
|
||||
return progress;
|
||||
}
|
||||
|
||||
public void setConstruct(Block previous, Recipe recipe){
|
||||
@ -278,7 +280,7 @@ public class BuildBlock extends Block {
|
||||
|
||||
@Override
|
||||
public void write(DataOutputStream stream) throws IOException {
|
||||
stream.writeFloat((float)progress);
|
||||
stream.writeFloat(progress);
|
||||
stream.writeShort(previous == null ? -1 : previous.id);
|
||||
stream.writeShort(recipe == null ? -1 : recipe.result.id);
|
||||
|
||||
|
@ -34,7 +34,7 @@ public class CrashHandler {
|
||||
String header = "--CRASH REPORT--\n";
|
||||
|
||||
try{
|
||||
header += "--GAME INFO-- \n";
|
||||
header += "--GAME INFO--\n";
|
||||
header += "Build: " + Version.build + "\n";
|
||||
header += "Net Active: " + netActive + "\n";
|
||||
header += "Net Server: " + netServer + "\n";
|
||||
|
Loading…
Reference in New Issue
Block a user