Skip to content

Commit

Permalink
Merge pull request #7 from Techlone/feature/oredict-support
Browse files Browse the repository at this point in the history
[WIP] Ore dict support
  • Loading branch information
Dream-Master committed Mar 7, 2016
2 parents bcf4934 + 19dcfba commit 0b338e2
Show file tree
Hide file tree
Showing 92 changed files with 2,168 additions and 5,594 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ eclipse/
out/
*.txt
.gradle/
.idea/
GTTweaker.iml
GTTweaker.ipr
GTTweaker.iws
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/gttweaker/GTTweaker.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.Mod.EventHandler;
import cpw.mods.fml.common.event.*;
import gttweaker.mods.gregtech.*;
import gttweaker.mods.gregtech.Fuels;
import gttweaker.mods.gregtech.machines.*;
import minetweaker.MineTweakerAPI;
import gregtech.api.*;

Expand Down
170 changes: 170 additions & 0 deletions src/main/java/gttweaker/mods/gregtech/AddMultipleRecipeAction.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,170 @@
package gttweaker.mods.gregtech;

import gttweaker.util.exception.AnyIngredientException;
import gttweaker.util.exception.EmptyIngredientException;
import gttweaker.util.exception.OutOfStackSizeException;
import minetweaker.MineTweakerAPI;
import minetweaker.OneWayAction;
import minetweaker.api.item.IIngredient;
import minetweaker.api.item.IItemStack;
import minetweaker.api.liquid.ILiquidStack;
import minetweaker.api.minecraft.MineTweakerMC;
import net.minecraft.item.ItemStack;
import net.minecraftforge.fluids.FluidStack;

import java.util.*;

/**
* Created by Techlone
*/
public abstract class AddMultipleRecipeAction extends OneWayAction {
private static void extendBySingle(Object singleArg, List<List<Object>> recipesData) {
for (List<Object> recipeData : recipesData) {
recipeData.add(singleArg);
}
}

private static void extendByMultiple(List args, List<List<Object>> recipesData) {
List<List<Object>> originData = fullCopy(recipesData);
recipesData.clear();
for (Object singleArg : args) {
List<List<Object>> tmp = fullCopy(originData);
extendBySingle(singleArg, tmp);
recipesData.addAll(tmp);
}
}

private static List<List<Object>> fullCopy(List<List<Object>> recipesData) {
List<List<Object>> result = new ArrayList<List<Object>>(recipesData.size());
for (List<Object> recipeData : recipesData) {
result.add(new ArrayList<Object>(recipeData));
}
return result;
}

private String description;
private List<List<Object>> recipesData;
private int aid; // argument index, equate to zero before applySingleRecipe call

private void addArgument(Object recipeArg) {
if (recipeArg instanceof ILiquidStack) {
extendBySingle(MineTweakerMC.getLiquidStack((ILiquidStack) recipeArg), recipesData);
} else if (recipeArg instanceof ILiquidStack[]) {
extendBySingle(MineTweakerMC.getLiquidStacks((ILiquidStack[]) recipeArg), recipesData);
} else if (recipeArg instanceof IItemStack) {
extendBySingle(MineTweakerMC.getItemStack((IItemStack) recipeArg), recipesData);
} else if (recipeArg instanceof IItemStack[]) {
extendBySingle(MineTweakerMC.getItemStacks((IItemStack[]) recipeArg), recipesData);
} else if (recipeArg instanceof IIngredient) {
extendByMultiple(getItemStacks((IIngredient) recipeArg), recipesData);
} else {
extendBySingle(recipeArg, recipesData);
}
}

private List<ItemStack> getItemStacks(IIngredient ingredientArg) {
List<IItemStack> items = ingredientArg.getItems();
if (items == null) {
throw new AnyIngredientException();
}
if (items.size() == 0) {
throw new EmptyIngredientException(ingredientArg);
}
List<ItemStack> itemStackList = Arrays.asList(MineTweakerMC.getItemStacks(items));
int amount = ingredientArg.getAmount();
if (amount < 0) {
throw new RuntimeException("Negative amount for ingredient " + ingredientArg);
}
for (ItemStack stack : itemStackList) {
if (amount > stack.getMaxStackSize()) {
throw new OutOfStackSizeException(ingredientArg, amount);
}
stack.stackSize = amount;
}
return itemStackList;
}

protected AddMultipleRecipeAction(String description, Object... recipeArgs) {
this.description = description;

recipesData = new ArrayList<List<Object>>(recipeArgs.length);
recipesData.add(new ArrayList<Object>());

try {
for (Object recipeArg : recipeArgs) {
addArgument(recipeArg);
}
} catch (Exception e) {
MineTweakerAPI.logError(e.toString());
}
}

protected abstract void applySingleRecipe(ArgIterator i);

protected static class ArgIterator {
private Iterator<Object> iterator;

public ArgIterator(List<Object> args) {
this.iterator = args.iterator();
}

public ItemStack nextItem() {
return (ItemStack) iterator.next();
}

public ItemStack[] nextItemArr() {
return (ItemStack[]) iterator.next();
}

public FluidStack nextFluid() {
return (FluidStack) iterator.next();
}

public FluidStack[] nextFluidArr() {
return (FluidStack[]) iterator.next();
}

public int nextInt() {
return (Integer) iterator.next();
}

public int[] nextIntArr() {
return (int[]) iterator.next();
}

public boolean nextBool() {
return (Boolean) iterator.next();
}
}

@Override
public void apply() {
for (List<Object> recipeData : recipesData) {
applySingleRecipe(new ArgIterator(recipeData));
}
}

@Override
public String describe() {
return this.description;
}

@Override
public Object getOverrideKey() {
return null;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;

AddMultipleRecipeAction that = (AddMultipleRecipeAction) o;
return recipesData != null ? recipesData.equals(that.recipesData) : that.recipesData == null;
}

@Override
public int hashCode() {
return recipesData != null ? recipesData.hashCode() : 0;
}
}
114 changes: 0 additions & 114 deletions src/main/java/gttweaker/mods/gregtech/AlloySmelter.java

This file was deleted.

Loading

0 comments on commit 0b338e2

Please sign in to comment.