-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from Techlone/feature/oredict-support
[WIP] Ore dict support
- Loading branch information
Showing
92 changed files
with
2,168 additions
and
5,594 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ eclipse/ | |
out/ | ||
*.txt | ||
.gradle/ | ||
.idea/ | ||
GTTweaker.iml | ||
GTTweaker.ipr | ||
GTTweaker.iws | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
170 changes: 170 additions & 0 deletions
170
src/main/java/gttweaker/mods/gregtech/AddMultipleRecipeAction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
114
src/main/java/gttweaker/mods/gregtech/AlloySmelter.java
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.