generated from tilera/1710mod
feat: implement old aspect calculation
This commit is contained in:
parent
0e909e82de
commit
49c41c1ef4
|
@ -24,7 +24,7 @@ apply from: './gradle/scripts/mixins.gradle'
|
|||
sourceCompatibility = JavaVersion.VERSION_1_8
|
||||
targetCompatibility = JavaVersion.VERSION_1_8
|
||||
|
||||
version = "1.6.1"
|
||||
version = "1.7.0"
|
||||
group= "dev.tilera"
|
||||
archivesBaseName = "auracore"
|
||||
|
||||
|
|
|
@ -0,0 +1,194 @@
|
|||
package dev.tilera.auracore.crafting;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
import dev.tilera.auracore.api.AuracoreRecipes;
|
||||
import dev.tilera.auracore.api.crafting.CrucibleRecipe;
|
||||
import dev.tilera.auracore.api.crafting.IInfusionRecipe;
|
||||
import dev.tilera.auracore.api.crafting.ShapedInfusionCraftingRecipe;
|
||||
import dev.tilera.auracore.api.crafting.ShapelessInfusionCraftingRecipe;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import thaumcraft.api.ThaumcraftApi;
|
||||
import thaumcraft.api.aspects.Aspect;
|
||||
import thaumcraft.api.aspects.AspectList;
|
||||
import thaumcraft.api.crafting.IArcaneRecipe;
|
||||
import thaumcraft.api.crafting.ShapedArcaneRecipe;
|
||||
import thaumcraft.api.crafting.ShapelessArcaneRecipe;
|
||||
import thaumcraft.common.lib.crafting.ThaumcraftCraftingManager;
|
||||
|
||||
public class AspectCalculation {
|
||||
|
||||
public static AspectList generateTagsFromInfusionRecipes(Item item, int meta, ArrayList<List> history) {
|
||||
AspectList ret = null;
|
||||
int value = 0;
|
||||
List<IInfusionRecipe> recipeList = AuracoreRecipes.getInfusionRecipes();
|
||||
for (int q = 0; q < recipeList.size(); ++q) {
|
||||
int idS;
|
||||
IInfusionRecipe recipe = recipeList.get(q);
|
||||
int idR = recipe.getRecipeOutput().getItemDamage() < 0 ? 0 : recipe.getRecipeOutput().getItemDamage();
|
||||
int n = idS = meta < 0 ? 0 : meta;
|
||||
if (recipe.getRecipeOutput().getItem() != item || idR != idS) continue;
|
||||
HashMap<List<Integer>, ItemStack> ingredients = new HashMap<List<Integer>, ItemStack>();
|
||||
AspectList ph = new AspectList();
|
||||
int cval = 0;
|
||||
try {
|
||||
if (recipe instanceof ShapedInfusionCraftingRecipe) {
|
||||
int width = ((ShapedInfusionCraftingRecipe)recipe).recipeWidth;
|
||||
int height = ((ShapedInfusionCraftingRecipe)recipe).recipeHeight;
|
||||
ItemStack[] items = ((ShapedInfusionCraftingRecipe)recipe).recipeItems;
|
||||
for (int i = 0; i < width && i < 3; ++i) {
|
||||
for (int j = 0; j < height && j < 3; ++j) {
|
||||
if (items[i + j * width] == null) continue;
|
||||
items[i + j * width].stackSize = 1;
|
||||
if (ingredients.containsKey(Arrays.asList(Item.getIdFromItem(items[i + j * width].getItem()), items[i + j * width].getItemDamage()))) {
|
||||
ItemStack is = (ItemStack)ingredients.get(Arrays.asList(items[i + j * width].getItem(), items[i + j * width].getItemDamage()));
|
||||
++is.stackSize;
|
||||
ingredients.put(Arrays.asList(Item.getIdFromItem(items[i + j * width].getItem()), items[i + j * width].getItemDamage()), is);
|
||||
continue;
|
||||
}
|
||||
ingredients.put(Arrays.asList(Item.getIdFromItem(items[i + j * width].getItem()), items[i + j * width].getItemDamage()), items[i + j * width]);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
List<ItemStack> items = ((ShapelessInfusionCraftingRecipe)recipe).recipeItems;
|
||||
for (int i = 0; i < items.size() && i < 9; ++i) {
|
||||
if (items.get(i) == null) continue;
|
||||
((ItemStack)items.get((int)i)).stackSize = 1;
|
||||
if (ingredients.containsKey(Arrays.asList(((ItemStack)items.get((int)i)).getItem(), ((ItemStack)items.get(i)).getItemDamage()))) {
|
||||
ItemStack is = (ItemStack)ingredients.get(Arrays.asList(Item.getIdFromItem(((ItemStack)items.get((int)i)).getItem()), ((ItemStack)items.get(i)).getItemDamage()));
|
||||
++is.stackSize;
|
||||
ingredients.put(Arrays.asList(Item.getIdFromItem(((ItemStack)items.get((int)i)).getItem()), ((ItemStack)items.get(i)).getItemDamage()), is);
|
||||
continue;
|
||||
}
|
||||
ingredients.put(Arrays.asList(Item.getIdFromItem(((ItemStack)items.get((int)i)).getItem()), ((ItemStack)items.get(i)).getItemDamage()), items.get(i));
|
||||
}
|
||||
}
|
||||
Collection<ItemStack> ings = ingredients.values();
|
||||
for (ItemStack is : ings) {
|
||||
AspectList obj = ThaumcraftCraftingManager.generateTags(is.getItem(), is.getItemDamage(), history);
|
||||
AspectList objC = null;
|
||||
if (is.getItem().getContainerItem() != null) {
|
||||
objC = ThaumcraftCraftingManager.generateTags(is.getItem().getContainerItem(), -1, history);
|
||||
}
|
||||
if (obj == null) continue;
|
||||
for (Aspect as : obj.getAspects()) {
|
||||
float amnt;
|
||||
if (objC != null && objC.getAmount(as) > 0 || !((amnt = (float)(obj.getAmount(as) * is.stackSize) / (float)recipe.getRecipeOutput().stackSize) > 0.5f)) continue;
|
||||
float tmod = 0.8f;
|
||||
ph.add(as, Math.max(Math.round(amnt * tmod), 1));
|
||||
cval += Math.max(Math.round(amnt * tmod), 1);
|
||||
}
|
||||
}
|
||||
ph.add(Aspect.MAGIC, Math.round((float)recipe.getCost() / 10.0f / (float)recipe.getRecipeOutput().stackSize));
|
||||
for (Aspect tag : recipe.getAspects().getAspects()) {
|
||||
ph.add(tag, Math.round((float)recipe.getAspects().getAmount(tag) / (float)recipe.getRecipeOutput().stackSize));
|
||||
}
|
||||
if (cval < value) continue;
|
||||
ret = ph;
|
||||
value = cval;
|
||||
continue;
|
||||
}
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
public static AspectList generateTagsFromCrucibleRecipes(Item item, int meta, ArrayList<List> history) {
|
||||
CrucibleRecipe cr = AuracoreRecipes.getCrucibleRecipe(new ItemStack(item, 1, meta));
|
||||
if (cr != null) {
|
||||
AspectList ot = new AspectList();
|
||||
int ss = cr.recipeOutput.stackSize;
|
||||
ot.add(Aspect.MAGIC, Math.round((float)cr.cost / 10.0f));
|
||||
for (Aspect tt : cr.aspects.getAspects()) {
|
||||
int amt = cr.aspects.getAmount(tt) / ss;
|
||||
ot.add(tt, amt);
|
||||
}
|
||||
return ot;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static AspectList generateTagsFromArcaneRecipes(Item item, int meta, ArrayList<List> history) {
|
||||
AspectList ret = null;
|
||||
int value = 0;
|
||||
List recipeList = ThaumcraftApi.getCraftingRecipes();
|
||||
for (int q = 0; q < recipeList.size(); ++q) {
|
||||
int idS;
|
||||
if (!(recipeList.get(q) instanceof IArcaneRecipe)) continue;
|
||||
IArcaneRecipe recipe = (IArcaneRecipe)recipeList.get(q);
|
||||
if (!(recipe instanceof ShapedArcaneRecipe || recipe instanceof ShapelessArcaneRecipe)) continue;
|
||||
int idR = recipe.getRecipeOutput().getItemDamage() < 0 ? 0 : recipe.getRecipeOutput().getItemDamage();
|
||||
int n = idS = meta < 0 ? 0 : meta;
|
||||
if (recipe.getRecipeOutput().getItem() != item || idR != idS) continue;
|
||||
HashMap<List<Integer>, ItemStack> ingredients = new HashMap<List<Integer>, ItemStack>();
|
||||
AspectList ph = new AspectList();
|
||||
int cval = 0;
|
||||
try {
|
||||
if (recipe instanceof ShapedArcaneRecipe) {
|
||||
int width = ((ShapedArcaneRecipe)recipe).width;
|
||||
int height = ((ShapedArcaneRecipe)recipe).width;
|
||||
ItemStack[] items = (ItemStack[]) ((ShapedArcaneRecipe)recipe).input;
|
||||
for (int i = 0; i < width && i < 3; ++i) {
|
||||
for (int j = 0; j < height && j < 3; ++j) {
|
||||
if (items[i + j * width] == null) continue;
|
||||
items[i + j * width].stackSize = 1;
|
||||
if (ingredients.containsKey(Arrays.asList(Item.getIdFromItem(items[i + j * width].getItem()), items[i + j * width].getItemDamage()))) {
|
||||
ItemStack is = (ItemStack)ingredients.get(Arrays.asList(Item.getIdFromItem(items[i + j * width].getItem()), items[i + j * width].getItemDamage()));
|
||||
++is.stackSize;
|
||||
ingredients.put(Arrays.asList(Item.getIdFromItem(items[i + j * width].getItem()), items[i + j * width].getItemDamage()), is);
|
||||
continue;
|
||||
}
|
||||
ingredients.put(Arrays.asList(Item.getIdFromItem(items[i + j * width].getItem()), items[i + j * width].getItemDamage()), items[i + j * width]);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
List<ItemStack> items = ((ShapelessArcaneRecipe)recipe).getInput();
|
||||
for (int i = 0; i < items.size() && i < 9; ++i) {
|
||||
if (items.get(i) == null) continue;
|
||||
((ItemStack)items.get((int)i)).stackSize = 1;
|
||||
if (ingredients.containsKey(Arrays.asList(Item.getIdFromItem(((ItemStack)items.get((int)i)).getItem()), ((ItemStack)items.get(i)).getItemDamage()))) {
|
||||
ItemStack is = (ItemStack)ingredients.get(Arrays.asList(Item.getIdFromItem(((ItemStack)items.get((int)i)).getItem()), ((ItemStack)items.get(i)).getItemDamage()));
|
||||
++is.stackSize;
|
||||
ingredients.put(Arrays.asList(Item.getIdFromItem(((ItemStack)items.get((int)i)).getItem()), ((ItemStack)items.get(i)).getItemDamage()), is);
|
||||
continue;
|
||||
}
|
||||
ingredients.put(Arrays.asList(Item.getIdFromItem(((ItemStack)items.get((int)i)).getItem()), ((ItemStack)items.get(i)).getItemDamage()), items.get(i));
|
||||
}
|
||||
}
|
||||
Collection<ItemStack> ings = ingredients.values();
|
||||
for (ItemStack is : ings) {
|
||||
AspectList obj = ThaumcraftCraftingManager.generateTags(is.getItem(), is.getItemDamage(), history);
|
||||
AspectList objC = null;
|
||||
if (is.getItem().getContainerItem() != null) {
|
||||
objC = ThaumcraftCraftingManager.generateTags(is.getItem().getContainerItem(), -1, history);
|
||||
}
|
||||
if (obj == null) continue;
|
||||
for (Aspect as : obj.getAspects()) {
|
||||
float amnt;
|
||||
if (objC != null && objC.getAmount(as) > 0 || !((amnt = (float)(obj.getAmount(as) * is.stackSize) / (float)recipe.getRecipeOutput().stackSize) > 0.5f)) continue;
|
||||
float tmod = 0.8f;
|
||||
ph.add(as, Math.max(Math.round(amnt * tmod), 1));
|
||||
cval += Math.max(Math.round(amnt * tmod), 1);
|
||||
}
|
||||
}
|
||||
ph.add(Aspect.MAGIC, Math.round((float)AuracoreCraftingManager.getArcaneRecipeVisCost(recipe, null) / 10.0f / (float)recipe.getRecipeOutput().stackSize));
|
||||
if (cval < value) continue;
|
||||
ret = ph;
|
||||
value = cval;
|
||||
continue;
|
||||
}
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
}
|
|
@ -41,7 +41,13 @@ public class AuracoreCraftingManager {
|
|||
public static int getArcaneRecipeVisCost(IArcaneRecipe recipe, TileMagicWorkbench awb) {
|
||||
if (recipe == null) return 0;
|
||||
int sum = 0;
|
||||
AspectList aspects = recipe.getAspects(awb);
|
||||
AspectList aspects = recipe.getAspects();
|
||||
if (awb != null) {
|
||||
aspects = recipe.getAspects(awb);
|
||||
}
|
||||
if (aspects == null) {
|
||||
aspects = new AspectList();
|
||||
}
|
||||
for (Aspect aspect : aspects.getAspects()) {
|
||||
if (aspect != null) sum += aspects.getAmount(aspect);
|
||||
}
|
||||
|
|
|
@ -0,0 +1,85 @@
|
|||
package dev.tilera.auracore.mixins;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Overwrite;
|
||||
import org.spongepowered.asm.mixin.gen.Invoker;
|
||||
|
||||
import dev.tilera.auracore.api.Aspects;
|
||||
import dev.tilera.auracore.crafting.AspectCalculation;
|
||||
import net.minecraft.item.Item;
|
||||
import thaumcraft.api.aspects.Aspect;
|
||||
import thaumcraft.api.aspects.AspectList;
|
||||
import thaumcraft.common.lib.crafting.ThaumcraftCraftingManager;
|
||||
|
||||
@Mixin(ThaumcraftCraftingManager.class)
|
||||
public abstract class MixinThaumcraftCraftingManager {
|
||||
|
||||
@Invoker("generateTagsFromCrucibleRecipes")
|
||||
public static AspectList invokeGenerateTagsFromCrucibleRecipes(Item item, int meta, ArrayList<List> history) {
|
||||
throw new RuntimeException();
|
||||
}
|
||||
|
||||
@Invoker("generateTagsFromArcaneRecipes")
|
||||
public static AspectList invokeGenerateTagsFromArcaneRecipes(Item item, int meta, ArrayList<List> history) {
|
||||
throw new RuntimeException();
|
||||
}
|
||||
|
||||
@Invoker("generateTagsFromInfusionRecipes")
|
||||
public static AspectList invokeGenerateTagsFromInfusionRecipes(Item item, int meta, ArrayList<List> history) {
|
||||
throw new RuntimeException();
|
||||
}
|
||||
|
||||
@Invoker("generateTagsFromCraftingRecipes")
|
||||
public static AspectList invokeGenerateTagsFromCraftingRecipes(Item item, int meta, ArrayList<List> history) {
|
||||
throw new RuntimeException();
|
||||
}
|
||||
|
||||
/**
|
||||
* @author tilera
|
||||
* @reason recipe tag generation
|
||||
*/
|
||||
@Overwrite(remap = false)
|
||||
private static AspectList generateTagsFromRecipes(Item item, int meta, ArrayList<List> history) {
|
||||
AspectList ret = null;
|
||||
ret = AspectCalculation.generateTagsFromCrucibleRecipes(item, meta, history);
|
||||
if (ret != null) {
|
||||
return ret;
|
||||
}
|
||||
ret = invokeGenerateTagsFromCrucibleRecipes(item, meta, history);
|
||||
if (ret != null) {
|
||||
return ret;
|
||||
}
|
||||
ret = AspectCalculation.generateTagsFromArcaneRecipes(item, meta, history);
|
||||
if (ret != null) {
|
||||
return ret;
|
||||
}
|
||||
ret = invokeGenerateTagsFromArcaneRecipes(item, meta, history);
|
||||
if (ret != null) {
|
||||
return ret;
|
||||
}
|
||||
ret = AspectCalculation.generateTagsFromInfusionRecipes(item, meta, history);
|
||||
if (ret != null) {
|
||||
return ret;
|
||||
}
|
||||
ret = invokeGenerateTagsFromInfusionRecipes(item, meta, history);
|
||||
if (ret != null) {
|
||||
return ret;
|
||||
}
|
||||
ret = invokeGenerateTagsFromCraftingRecipes(item, meta, history);
|
||||
|
||||
if (ret != null) {
|
||||
int vis = ret.getAmount(Aspects.VIS);
|
||||
if (vis > 0) {
|
||||
ret.remove(Aspects.VIS);
|
||||
int magic = Math.round((float)vis / 10.0f);
|
||||
ret.add(Aspect.MAGIC, magic);
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
}
|
|
@ -20,7 +20,8 @@
|
|||
"MixinEventHandlerEntity",
|
||||
"MixinThaumcraftWorldGenerator",
|
||||
"MixinPlayerKnowledge",
|
||||
"MixinConfigAspects"
|
||||
"MixinConfigAspects",
|
||||
"MixinThaumcraftCraftingManager"
|
||||
],
|
||||
"client": [
|
||||
"MixinBlockCustomOreRenderer",
|
||||
|
|
Loading…
Reference in New Issue