2014-07-03 21:44:44 +02:00
|
|
|
|
package com.pahimar.ee3.util;
|
|
|
|
|
|
2015-05-07 19:45:06 +02:00
|
|
|
|
import com.pahimar.ee3.api.exchange.EnergyValue;
|
2015-11-25 22:00:25 +01:00
|
|
|
|
import com.pahimar.ee3.api.exchange.EnergyValueRegistryProxy;
|
2014-07-03 21:44:44 +02:00
|
|
|
|
import com.pahimar.ee3.init.ModItems;
|
|
|
|
|
import net.minecraft.item.ItemStack;
|
|
|
|
|
|
2015-11-25 22:00:25 +01:00
|
|
|
|
import java.util.Random;
|
2014-07-03 21:44:44 +02:00
|
|
|
|
|
2014-07-04 21:18:10 +02:00
|
|
|
|
public class CalcinationHelper
|
|
|
|
|
{
|
2015-11-25 22:00:25 +01:00
|
|
|
|
private static Random random = new Random();
|
2014-07-03 21:44:44 +02:00
|
|
|
|
|
2015-11-25 22:00:25 +01:00
|
|
|
|
public static ItemStack getCalcinationResult(ItemStack itemStack) {
|
|
|
|
|
EnergyValue dustEnergyValue = EnergyValueRegistryProxy.getEnergyValue(new ItemStack(ModItems.alchemicalDust, 1, 3));
|
|
|
|
|
EnergyValue itemStackEnergyValue = EnergyValueRegistryProxy.getEnergyValue(itemStack);
|
2014-07-03 21:44:44 +02:00
|
|
|
|
|
2015-11-25 22:00:25 +01:00
|
|
|
|
if (dustEnergyValue != null && itemStackEnergyValue != null) {
|
|
|
|
|
int dustAmount = (int) Math.floor(itemStackEnergyValue.getValue() / dustEnergyValue.getValue());
|
|
|
|
|
float residualEMC = itemStackEnergyValue.getValue() - (dustAmount * dustEnergyValue.getValue());
|
|
|
|
|
|
|
|
|
|
double u = (double) residualEMC / dustEnergyValue.getValue(); // expected value (µ)
|
|
|
|
|
double s = u / 2; // deviation (σ)
|
|
|
|
|
u *= 1 - 0.0043451773677092; // negative cut-off correction factor
|
|
|
|
|
dustAmount += (int) (Math.max(0, random.nextGaussian() * s + u) + random.nextDouble());
|
|
|
|
|
|
|
|
|
|
if (dustAmount > 0) {
|
|
|
|
|
return new ItemStack(ModItems.alchemicalDust, dustAmount, 3);
|
2014-07-03 21:44:44 +02:00
|
|
|
|
}
|
2014-07-04 21:18:10 +02:00
|
|
|
|
}
|
2015-11-25 22:00:25 +01:00
|
|
|
|
|
|
|
|
|
return new ItemStack(ModItems.alchemicalDust, 1, 0);
|
2014-07-03 21:44:44 +02:00
|
|
|
|
}
|
|
|
|
|
}
|