Skip to content

Commit

Permalink
Fix smeltery gui crashing when hovering over the tank in an empty sme…
Browse files Browse the repository at this point in the history
…ltery
  • Loading branch information
bonii-xx committed Mar 15, 2016
1 parent 984bc58 commit fcd93d7
Showing 1 changed file with 28 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -139,40 +139,39 @@ public static int[] calcLiquidHeights (List<FluidStack> liquids, int capacity, i
{
int fluidHeights[] = new int[liquids.size()];

for (int i = 0; i < liquids.size(); i++)
{
FluidStack liquid = liquids.get(i);
if(liquids.size() > 0) {

float h = (float) liquid.amount / (float) capacity;
fluidHeights[i] = Math.max(min, (int) Math.ceil(h * (float)height));
}
for(int i = 0; i < liquids.size(); i++) {
FluidStack liquid = liquids.get(i);

// check if we have enough height to render everything
int sum = 0;
do
{
sum = 0;
int biggest = -1;
int m = 0;
for (int i = 0; i < fluidHeights.length; i++)
{
sum += fluidHeights[i];
if (liquids.get(i).amount > biggest)
{
biggest = liquids.get(i).amount;
m = i;
}
float h = (float) liquid.amount / (float) capacity;
fluidHeights[i] = Math.max(min, (int) Math.ceil(h * (float) height));
}

// we can't get a result without going negative
if(fluidHeights[m] == 0) {
break;
}
// check if we have enough height to render everything
int sum = 0;
do {
sum = 0;
int biggest = -1;
int m = 0;
for(int i = 0; i < fluidHeights.length; i++) {
sum += fluidHeights[i];
if(liquids.get(i).amount > biggest) {
biggest = liquids.get(i).amount;
m = i;
}
}

// remove a pixel from the biggest one
if (sum > height)
fluidHeights[m]--;
} while (sum > height);
// we can't get a result without going negative
if(fluidHeights[m] == 0) {
break;
}

// remove a pixel from the biggest one
if(sum > height)
fluidHeights[m]--;
} while(sum > height);
}

return fluidHeights;
}
Expand Down

0 comments on commit fcd93d7

Please sign in to comment.