Added IMC support for adding assembly and refinery recipes.

I think we shouldn't dismantle API adding, since if i do a complete addon it'll be easier to use, than IMC.

PS Is this just in NextGen buckets-machines behavior is broken? Or whole 1.7.2?
This commit is contained in:
Anton 2014-03-24 22:08:02 +02:00
parent ebebba3282
commit cb47a11853

View file

@ -8,12 +8,18 @@
*/
package buildcraft.core;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import buildcraft.core.recipes.AssemblyRecipeManager;
import buildcraft.core.recipes.RefineryRecipeManager;
import com.google.common.base.Strings;
import net.minecraft.block.Block;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.world.biome.BiomeGenBase;
import buildcraft.energy.worldgen.OilPopulate;
import buildcraft.transport.ItemFacade;
@ -24,23 +30,91 @@ import com.google.common.primitives.Ints;
import cpw.mods.fml.common.event.FMLInterModComms.IMCEvent;
import cpw.mods.fml.common.event.FMLInterModComms.IMCMessage;
import net.minecraftforge.fluids.FluidStack;
public class InterModComms {
public static void processIMC(IMCEvent event) {
for (IMCMessage m : event.getMessages()) {
if (m.key.equals("add-facade")) {
processAddFacadeIMC(event, m);
processAddFacadeIMC(event, m);
} else if (m.key.equals("blacklist-facade")) {
processBlacklistFacadeIMC(event, m);
} else if (m.key.equals("oil-lake-biome")) {
} else if (m.key.equals("oil-lake-biome")) {
processOilLakeBiomeIMC(event, m);
} else if (m.key.equals("oil-gen-exclude")) {
processOilGenExcludeIMC(event, m);
} else if (m.key.equals("add-assembly-recipe")){
processAssemblyRecipeIMC(event, m);
} else if (m.key.equals("add-refinery-recipe")){
processRefineryRecipeIMC(event, m);
} else if (m.key.equals("remove-assembly-recipe")){
//TODO
} else if (m.key.equals("remove-refinery-recipe")){
//TODO
} else {
Logger.getLogger("Buildcraft").log(Level.WARNING, "Received IMC message with unknown key('%s') from %s!", new Object[]{m.key, m.getSender()});
}
}
}
public static void processAssemblyRecipeIMC(IMCEvent event, IMCMessage msg){
boolean failed = false;
if (!msg.isNBTMessage()) {
failed = true;
} else {
NBTTagCompound recipe = msg.getNBTValue();
if (!recipe.hasKey("input", 9) || !recipe.hasKey("output", 10) || !recipe.hasKey("energy", 6)) { //Ints - NBTBase#NBTTypes
failed = true;
} else {
NBTTagList list = (NBTTagList) recipe.getTag("input");
List<ItemStack> input = new ArrayList<ItemStack>();
for (int i = 0; i < list.tagCount(); i++) {
ItemStack is = ItemStack.loadItemStackFromNBT(list.getCompoundTagAt(i));
if (is != null) {
input.add(is);
}
}
ItemStack is = ItemStack.loadItemStackFromNBT(recipe.getCompoundTag("output"));
if (is != null && !input.isEmpty()) {
AssemblyRecipeManager.INSTANCE.addRecipe(recipe.getDouble("energy"), is, input.toArray(new ItemStack[input.size()]));
} else {
failed = true;
}
}
}
if (failed) {
Logger.getLogger("Buildcraft").log(Level.WARNING, "Received invalid assembly recipe IMC message from %s!", msg.getSender());
}
}
public static void processRefineryRecipeIMC(IMCEvent event, IMCMessage msg){
boolean failed = false;
if (!msg.isNBTMessage()) {
failed = true;
} else {
NBTTagCompound recipe = msg.getNBTValue();
if (!recipe.hasKey("input", 10) || !recipe.hasKey("output", 10) || !recipe.hasKey("energy", 3) || !recipe.hasKey("delay", 3)) {
failed = true;
} else {
FluidStack output = FluidStack.loadFluidStackFromNBT(recipe.getCompoundTag("output"));
FluidStack input = FluidStack.loadFluidStackFromNBT(recipe.getCompoundTag("input"));
FluidStack input2 = null;
if (recipe.hasKey("input_2", 10)) {
input2 = FluidStack.loadFluidStackFromNBT(recipe.getCompoundTag("input_2"));
}
if (input != null && output != null) {
RefineryRecipeManager.INSTANCE.addRecipe(input, input2, output, recipe.getInteger("energy"), recipe.getInteger("delay"));
} else {
failed = true;
}
}
}
if (failed) {
Logger.getLogger("Buildcraft").log(Level.WARNING, "Received invalid refinery recipe IMC message from %s!", msg.getSender());
}
}
public static void processAddFacadeIMC(IMCEvent event, IMCMessage m) {
try {
if (m.isStringMessage()) {