Skip to content

Commit

Permalink
IMC to allow adding a material + liquid to all the standard metal too…
Browse files Browse the repository at this point in the history
…l part casting stuff.
  • Loading branch information
bonii-xx committed Sep 22, 2014
1 parent ff79f7d commit e7a2fb5
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 1 deletion.
Expand Up @@ -16,7 +16,7 @@ public class PatternBuilder
public static PatternBuilder instance = new PatternBuilder();
// Map items to their parts with a hashmap
public List<ItemKey> materials = new ArrayList<ItemKey>();
public HashMap materialSets = new HashMap<String, MaterialSet>();
public HashMap<String, MaterialSet> materialSets = new HashMap<String, MaterialSet>();

// We could use IRecipe if it wasn't tied to InventoryCrafting
public List<IPattern> toolPatterns = new ArrayList<IPattern>();
Expand Down
67 changes: 67 additions & 0 deletions src/main/java/tconstruct/util/IMCHandler.java
@@ -1,11 +1,20 @@
package tconstruct.util;

import cpw.mods.fml.common.event.FMLInterModComms;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraftforge.fluids.FluidStack;
import tconstruct.TConstruct;
import tconstruct.library.TConstructRegistry;
import tconstruct.library.crafting.CastingRecipe;
import tconstruct.library.crafting.PatternBuilder;
import tconstruct.library.tools.DynamicToolPart;
import tconstruct.library.tools.ToolMaterial;
import tconstruct.library.util.IPattern;
import tconstruct.library.util.IToolPart;
import tconstruct.smeltery.TinkerSmeltery;

import java.util.LinkedList;
import java.util.List;

public final class IMCHandler {
Expand Down Expand Up @@ -35,6 +44,64 @@ public static void processIMC(List<FMLInterModComms.IMCMessage> messages)
TConstruct.logger.info("IMC: Added material " + mat.materialName);
}
}
else if(type.equals("addPartBuilderMaterial"))
{
if(!message.isNBTMessage())
{
logInvalidMessage(message);
continue;
}
// PatternBuilder.instance.registerMaterial();
}
else if(type.equals("addPartCastingMaterial"))
{
if(!message.isNBTMessage())
{
logInvalidMessage(message);
continue;
}

NBTTagCompound tag = message.getNBTValue();

if(!tag.hasKey("MaterialId"))
{
TConstruct.logger.error("Casting IMC: Not material ID for the result present");
continue;
}

int matID = tag.getInteger("MaterialId");
FluidStack liquid = FluidStack.loadFluidStackFromNBT(tag);
if(liquid == null) {
TConstruct.logger.error("Casting IMC: No fluid found");
continue;
}

// we add the toolpart to all smeltery recipies that use iron and create a toolpart
List<CastingRecipe> newRecipies = new LinkedList<CastingRecipe>();
for(CastingRecipe recipe : TConstructRegistry.getTableCasting().getCastingRecipes())
{
if(recipe.castingMetal.getFluid() != TinkerSmeltery.moltenIronFluid)
continue;
if(recipe.cast == null || !(recipe.cast.getItem() instanceof IPattern))
continue;
if(!(recipe.getResult().getItem() instanceof DynamicToolPart)) // has to be dynamic toolpart to support automatic addition
continue;

newRecipies.add(recipe);
}

// has to be done separately so we have all checks and no concurrent modification exception
for(CastingRecipe recipe : newRecipies)
{
ItemStack output = recipe.getResult().copy();
output.setItemDamage(matID);

FluidStack liquid2 = new FluidStack(liquid, recipe.castingMetal.amount);

// ok, this recipe creates a toolpart and uses iron for it. add a new one for the IMC stuff!
TConstructRegistry.getTableCasting().addCastingRecipe(output, liquid2, recipe.cast, recipe.consumeCast, recipe.coolTime);
}
}
}
}

Expand Down

0 comments on commit e7a2fb5

Please sign in to comment.