Added some values for copper and tin, added support for ic2 machines and crafting

This commit is contained in:
modmuss50 2015-06-27 09:03:09 +01:00
parent 10837c46ff
commit 6f08a56df2
2 changed files with 125 additions and 3 deletions

View file

@ -58,6 +58,7 @@ public class CommandRegen extends CommandBase {
commandSender.addChatMessage(new ChatComponentText("Regening EMC Values"));
DynamicEnergyValueInitThread.initEnergyValueRegistry();
EnergyValueRegistry.getInstance().setShouldRegenNextRestart(false);
EnergyValueRegistry.getInstance().save();
commandSender.addChatMessage(new ChatComponentText("Syncing all EMC Values"));
new CommandSyncEnergyValues().processCommand(commandSender, args);
}

View file

@ -1,21 +1,130 @@
package techreborn.compat.ee3;
import com.pahimar.ee3.api.exchange.EnergyValue;
import com.pahimar.ee3.api.exchange.EnergyValueRegistryProxy;
import com.pahimar.ee3.api.exchange.RecipeRegistryProxy;
import com.pahimar.ee3.exchange.EnergyValueRegistry;
import com.pahimar.ee3.exchange.OreStack;
import com.pahimar.ee3.exchange.WrappedStack;
import cpw.mods.fml.common.event.FMLInitializationEvent;
import cpw.mods.fml.common.event.FMLPostInitializationEvent;
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
import cpw.mods.fml.common.event.FMLServerStartingEvent;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import cpw.mods.fml.common.gameevent.TickEvent;
import ic2.api.recipe.IRecipeInput;
import ic2.api.recipe.RecipeInputFluidContainer;
import ic2.api.recipe.RecipeInputItemStack;
import ic2.api.recipe.RecipeInputOreDict;
import ic2.api.recipe.RecipeOutput;
import ic2.api.recipe.Recipes;
import ic2.core.AdvRecipe;
import ic2.core.AdvShapelessRecipe;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.CraftingManager;
import net.minecraft.item.crafting.IRecipe;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.fluids.FluidStack;
import techreborn.api.recipe.IBaseRecipeType;
import techreborn.api.recipe.RecipeHandler;
import techreborn.command.TechRebornDevCommand;
import techreborn.compat.ICompatModule;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
public class EmcValues implements ICompatModule {
public static void addIC2Handlers() {
for (Map.Entry<IRecipeInput, RecipeOutput> entry : Recipes.macerator.getRecipes().entrySet())
sendRecipeEntry(entry);
for (Map.Entry<IRecipeInput, RecipeOutput> entry : Recipes.compressor.getRecipes().entrySet())
sendRecipeEntry(entry);
for (Map.Entry<IRecipeInput, RecipeOutput> entry : Recipes.extractor.getRecipes().entrySet())
sendRecipeEntry(entry);
for (Map.Entry<IRecipeInput, RecipeOutput> entry : Recipes.metalformerCutting.getRecipes().entrySet())
sendRecipeEntry(entry);
for (Map.Entry<IRecipeInput, RecipeOutput> entry : Recipes.metalformerExtruding.getRecipes().entrySet())
sendRecipeEntry(entry);
for (Map.Entry<IRecipeInput, RecipeOutput> entry : Recipes.metalformerRolling.getRecipes().entrySet())
sendRecipeEntry(entry);
for (Map.Entry<IRecipeInput, RecipeOutput> entry : Recipes.oreWashing.getRecipes().entrySet())
sendRecipeEntry(entry);
for (Map.Entry<IRecipeInput, RecipeOutput> entry : Recipes.centrifuge.getRecipes().entrySet())
sendRecipeEntry(entry);
for (Map.Entry<IRecipeInput, RecipeOutput> entry : Recipes.blockcutter.getRecipes().entrySet())
sendRecipeEntry(entry);
for (Map.Entry<IRecipeInput, RecipeOutput> entry : Recipes.blastfurance.getRecipes().entrySet())
sendRecipeEntry(entry);
for (Object recipeObject : CraftingManager.getInstance().getRecipeList()) {
if (recipeObject instanceof AdvRecipe || recipeObject instanceof AdvShapelessRecipe) {
IRecipe recipe = (IRecipe) recipeObject;
if (recipe.getRecipeOutput() != null) {
List<Object> recipeInputs = getRecipeInputs(recipe);
if (recipeInputs != null && !recipeInputs.isEmpty()) {
RecipeRegistryProxy.addRecipe(recipe.getRecipeOutput(), recipeInputs);
}
}
}
}
}
private static void sendRecipeEntry(Map.Entry<IRecipeInput, RecipeOutput> entry) {
List<ItemStack> recipeStackOutputs = entry.getValue().items;
if (recipeStackOutputs.size() == 1) {
ItemStack recipeOutput = recipeStackOutputs.get(0);
if (recipeOutput != null) {
recipeOutput = recipeOutput.copy();
recipeOutput.setTagCompound(entry.getValue().metadata);
for (ItemStack recipeInput : entry.getKey().getInputs()) {
if (recipeInput != null) {
recipeInput = recipeInput.copy();
recipeInput.stackSize = entry.getKey().getAmount();
RecipeRegistryProxy.addRecipe(recipeOutput, Arrays.asList(recipeInput));
}
}
}
}
}
private static List<Object> getRecipeInputs(IRecipe recipe) {
List<Object> recipeInputs = new ArrayList<Object>();
if (recipe instanceof AdvRecipe) {
for (Object object : ((AdvRecipe) recipe).input) {
addInputToList(recipeInputs, object);
}
} else if (recipe instanceof AdvShapelessRecipe) {
for (Object object : ((AdvShapelessRecipe) recipe).input) {
addInputToList(recipeInputs, object);
}
}
return recipeInputs;
}
public static void addInputToList(List<Object> recipeInputs, Object object) {
if (object instanceof ItemStack) {
ItemStack itemStack = ((ItemStack) object).copy();
recipeInputs.add(itemStack);
} else if (object instanceof String) {
OreStack stack = new OreStack((String) object);
recipeInputs.add(stack);
} else if (object instanceof IRecipeInput) {
if (object instanceof RecipeInputItemStack)
recipeInputs.add(((RecipeInputItemStack) object).input);
else if (object instanceof RecipeInputOreDict)
recipeInputs.add(new OreStack(((RecipeInputOreDict) object).input));
else if (object instanceof RecipeInputFluidContainer)
recipeInputs.add(new FluidStack(((RecipeInputFluidContainer) object).fluid, ((RecipeInputFluidContainer) object).amount));
}
}
@Override
public void preInit(FMLPreInitializationEvent event) {
@ -33,6 +142,11 @@ public class EmcValues implements ICompatModule {
@Override
public void postInit(FMLPostInitializationEvent event) {
MinecraftForge.EVENT_BUS.register(this);
addOre("ingotCopper", 128);
addOre("ingotSilver", 1024);
addOre("ingotTin", 256);
addOre("ingotLead", 256);
addIC2Handlers();
}
@Override
@ -41,10 +155,17 @@ public class EmcValues implements ICompatModule {
event.registerServerCommand(new CommandReload());
}
@SubscribeEvent
public void serverTick(TickEvent.ServerTickEvent event){
public void serverTick(TickEvent.ServerTickEvent event) {
//This should be a fix for the things not saving
EnergyValueRegistry.getInstance().setShouldRegenNextRestart(false);
}
private void addOre(String name, float value) {
WrappedStack stack = WrappedStack.wrap(new OreStack(name));
EnergyValue energyValue = new EnergyValue(value);
EnergyValueRegistryProxy.addPreAssignedEnergyValue(stack, energyValue);
}
}