2013-08-23 16:59:50 +02:00
|
|
|
package com.pahimar.ee3.emc;
|
|
|
|
|
2013-10-20 08:32:32 +02:00
|
|
|
import java.util.ArrayList;
|
2013-10-07 03:50:43 +02:00
|
|
|
import java.util.Arrays;
|
2013-10-06 04:46:29 +02:00
|
|
|
import java.util.HashMap;
|
2013-10-18 07:23:11 +02:00
|
|
|
import java.util.List;
|
2013-10-06 04:46:29 +02:00
|
|
|
import java.util.Map;
|
2013-08-23 16:59:50 +02:00
|
|
|
|
2013-10-07 03:50:43 +02:00
|
|
|
import net.minecraft.block.Block;
|
2013-10-18 07:23:11 +02:00
|
|
|
import net.minecraft.item.ItemStack;
|
2013-10-07 03:50:43 +02:00
|
|
|
|
2013-08-23 16:59:50 +02:00
|
|
|
import com.pahimar.ee3.item.CustomWrappedStack;
|
2013-10-18 07:23:11 +02:00
|
|
|
import com.pahimar.ee3.item.crafting.RecipeRegistry;
|
2013-08-23 16:59:50 +02:00
|
|
|
|
|
|
|
public class EmcDefaultValues {
|
2013-10-07 03:50:43 +02:00
|
|
|
|
2013-10-17 04:27:07 +02:00
|
|
|
private static EmcDefaultValues emcDefaultValues = null;
|
|
|
|
private Map<CustomWrappedStack, EmcValue> valueMap;
|
2013-08-23 16:59:50 +02:00
|
|
|
|
2013-09-10 03:48:34 +02:00
|
|
|
private EmcDefaultValues() {
|
2013-10-07 03:50:43 +02:00
|
|
|
|
2013-10-17 04:27:07 +02:00
|
|
|
valueMap = new HashMap<CustomWrappedStack, EmcValue>();
|
2013-09-10 03:48:34 +02:00
|
|
|
}
|
2013-10-07 03:50:43 +02:00
|
|
|
|
2013-10-17 04:27:07 +02:00
|
|
|
private static void lazyInit() {
|
2013-10-07 03:50:43 +02:00
|
|
|
|
2013-10-17 04:27:07 +02:00
|
|
|
if (emcDefaultValues == null) {
|
|
|
|
emcDefaultValues = new EmcDefaultValues();
|
|
|
|
emcDefaultValues.init();
|
2013-09-10 03:48:34 +02:00
|
|
|
}
|
|
|
|
}
|
2013-10-07 03:50:43 +02:00
|
|
|
|
2013-09-10 03:48:34 +02:00
|
|
|
private void init() {
|
2013-10-07 03:50:43 +02:00
|
|
|
|
2013-10-18 07:23:11 +02:00
|
|
|
valueMap.put(new CustomWrappedStack(Block.stone), new EmcValue(1, EmcComponent.CORPOREAL_UNIT_COMPONENT));
|
|
|
|
valueMap.put(new CustomWrappedStack(Block.grass), new EmcValue(1, Arrays.asList(new EmcComponent(EmcType.CORPOREAL, 9), EmcComponent.ESSENTIA_UNIT_COMPONENT)));
|
|
|
|
valueMap.put(new CustomWrappedStack(Block.dirt), new EmcValue(1, EmcComponent.CORPOREAL_UNIT_COMPONENT));
|
2013-10-17 04:27:07 +02:00
|
|
|
valueMap.put(new CustomWrappedStack(Block.cobblestone), new EmcValue(1, EmcComponent.CORPOREAL_UNIT_COMPONENT));
|
2013-10-18 07:23:11 +02:00
|
|
|
valueMap.put(new CustomWrappedStack(Block.sand), new EmcValue(1, Arrays.asList(new EmcComponent(EmcType.CORPOREAL, 9), EmcComponent.AMORPHOUS_UNIT_COMPONENT)));
|
2013-10-20 08:32:32 +02:00
|
|
|
valueMap.put(new CustomWrappedStack(Block.leaves), new EmcValue(1, Arrays.asList(new EmcComponent(EmcType.CORPOREAL, 9), EmcComponent.ESSENTIA_UNIT_COMPONENT)));
|
2013-10-18 07:23:11 +02:00
|
|
|
valueMap.put(new CustomWrappedStack(Block.glass), new EmcValue(1, EmcComponent.CORPOREAL_UNIT_COMPONENT));
|
2013-10-20 08:32:32 +02:00
|
|
|
valueMap.put(new CustomWrappedStack(Block.tallGrass), new EmcValue(1, Arrays.asList(new EmcComponent(EmcType.CORPOREAL, 9), EmcComponent.ESSENTIA_UNIT_COMPONENT)));
|
|
|
|
for (int meta = 0; meta < 16; meta++) {
|
|
|
|
valueMap.put(new CustomWrappedStack(new ItemStack(Block.tallGrass.blockID, 1, meta)), new EmcValue(1, Arrays.asList(new EmcComponent(EmcType.CORPOREAL, 9), EmcComponent.ESSENTIA_UNIT_COMPONENT)));
|
2013-10-18 07:23:11 +02:00
|
|
|
}
|
|
|
|
valueMap.put(new CustomWrappedStack(Block.deadBush), new EmcValue(1, EmcComponent.CORPOREAL_UNIT_COMPONENT));
|
|
|
|
valueMap.put(new CustomWrappedStack(Block.ice), new EmcValue(1, EmcComponent.CORPOREAL_UNIT_COMPONENT));
|
2013-10-20 08:32:32 +02:00
|
|
|
|
2013-10-18 07:23:11 +02:00
|
|
|
valueMap.put(new CustomWrappedStack(Block.wood), new EmcValue(32, Arrays.asList(new EmcComponent(EmcType.CORPOREAL, 4), EmcComponent.ESSENTIA_UNIT_COMPONENT)));
|
2013-10-17 04:27:07 +02:00
|
|
|
valueMap.put(new CustomWrappedStack(Block.oreIron), new EmcValue(256, EmcComponent.CORPOREAL_UNIT_COMPONENT));
|
|
|
|
valueMap.put(new CustomWrappedStack(Block.oreGold), new EmcValue(2048, EmcComponent.CORPOREAL_UNIT_COMPONENT));
|
|
|
|
valueMap.put(new CustomWrappedStack(Block.oreDiamond), new EmcValue(8192, EmcComponent.CORPOREAL_UNIT_COMPONENT));
|
|
|
|
valueMap.put(new CustomWrappedStack(Block.oreCoal), new EmcValue(32, Arrays.asList(new EmcComponent(EmcType.CORPOREAL, 4), new EmcComponent(EmcType.KINETIC, 1))));
|
2013-10-07 03:50:43 +02:00
|
|
|
|
2013-10-20 08:32:32 +02:00
|
|
|
// TODO Multiple passes for value computation
|
|
|
|
attemptValueAssignment();
|
2013-10-18 07:23:11 +02:00
|
|
|
}
|
2013-10-20 08:32:32 +02:00
|
|
|
|
|
|
|
private List<CustomWrappedStack> attemptValueAssignment() {
|
|
|
|
|
|
|
|
List<CustomWrappedStack> computedStacks = new ArrayList<CustomWrappedStack>();
|
|
|
|
|
2013-10-18 07:23:11 +02:00
|
|
|
for (CustomWrappedStack stack : RecipeRegistry.getDiscoveredStacks()) {
|
2013-10-20 08:32:32 +02:00
|
|
|
|
2013-10-18 07:23:11 +02:00
|
|
|
if (!valueMap.containsKey(stack)) {
|
2013-10-20 08:32:32 +02:00
|
|
|
|
2013-10-18 07:23:11 +02:00
|
|
|
for (CustomWrappedStack recipeOutput : RecipeRegistry.getRecipeMappings().keySet()) {
|
2013-10-20 08:32:32 +02:00
|
|
|
|
2013-10-18 07:23:11 +02:00
|
|
|
if (recipeOutput.getWrappedStack().equals(stack.getWrappedStack())) {
|
2013-10-20 08:32:32 +02:00
|
|
|
|
|
|
|
for (List<CustomWrappedStack> recipeInputs : RecipeRegistry.getRecipeMappings().get(recipeOutput)) {
|
|
|
|
|
|
|
|
EmcValue computedValue = computeEmcValueFromList(recipeOutput.getStackSize(), recipeInputs);
|
|
|
|
|
|
|
|
if (computedValue instanceof EmcValue) {
|
|
|
|
valueMap.put(stack, computedValue);
|
|
|
|
computedStacks.add(stack);
|
2013-10-18 07:23:11 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-10-20 08:32:32 +02:00
|
|
|
return computedStacks;
|
|
|
|
}
|
|
|
|
|
|
|
|
private EmcValue computeEmcValueFromList(int recipeOutputSize, List<CustomWrappedStack> recipeInputs) {
|
|
|
|
|
|
|
|
float[] computedSubValues = new float[EmcType.TYPES.length];
|
|
|
|
|
|
|
|
for (CustomWrappedStack stack : recipeInputs) {
|
|
|
|
|
|
|
|
EmcValue stackValue = valueMap.get(new CustomWrappedStack(stack.getWrappedStack()));
|
|
|
|
|
|
|
|
if (stackValue != null) {
|
|
|
|
for (EmcType emcType : EmcType.TYPES) {
|
|
|
|
computedSubValues[emcType.ordinal()] += stackValue.components[emcType.ordinal()] * stack.getStackSize() * stackValue.recoveryPercent / recipeOutputSize;
|
2013-10-18 07:23:11 +02:00
|
|
|
}
|
|
|
|
}
|
2013-10-20 08:32:32 +02:00
|
|
|
else {
|
|
|
|
return null;
|
2013-10-18 07:23:11 +02:00
|
|
|
}
|
|
|
|
}
|
2013-10-20 08:32:32 +02:00
|
|
|
|
|
|
|
return new EmcValue(computedSubValues);
|
2013-09-10 03:48:34 +02:00
|
|
|
}
|
2013-10-07 03:50:43 +02:00
|
|
|
|
2013-10-17 04:27:07 +02:00
|
|
|
public static Map<CustomWrappedStack, EmcValue> getDefaultValueMap() {
|
2013-10-07 03:50:43 +02:00
|
|
|
|
2013-10-17 04:27:07 +02:00
|
|
|
lazyInit();
|
|
|
|
return emcDefaultValues.valueMap;
|
2013-08-23 16:59:50 +02:00
|
|
|
}
|
|
|
|
}
|