generated from tilera/1710mod
feat: old crucible crafting registry
This commit is contained in:
parent
7c128b580f
commit
bf547b6f2b
85
src/main/java/dev/tilera/auracore/api/AuracoreRecipes.java
Normal file
85
src/main/java/dev/tilera/auracore/api/AuracoreRecipes.java
Normal file
|
@ -0,0 +1,85 @@
|
|||
package dev.tilera.auracore.api;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import dev.tilera.auracore.api.crafting.CrucibleRecipe;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import thaumcraft.api.aspects.AspectList;
|
||||
import thaumcraft.common.tiles.TileCrucible;
|
||||
|
||||
public class AuracoreRecipes {
|
||||
|
||||
private static List<CrucibleRecipe> crucibleRecipes = new ArrayList<CrucibleRecipe>();
|
||||
|
||||
public static void addCrucibleRecipe(String key, ItemStack result, int cost, AspectList tags) {
|
||||
crucibleRecipes.add(new CrucibleRecipe(key, result, tags, cost));
|
||||
}
|
||||
|
||||
public static void addCrucibleRecipe(String key, String recipeKey, ItemStack result, int cost, AspectList tags) {
|
||||
crucibleRecipes.add(new CrucibleRecipe(key, recipeKey, result, tags, cost));
|
||||
}
|
||||
|
||||
public static List<CrucibleRecipe> getCrucibleRecipes() {
|
||||
return crucibleRecipes;
|
||||
}
|
||||
|
||||
public static CrucibleRecipe getCrucibleRecipe(String key) {
|
||||
for (Object r : crucibleRecipes) {
|
||||
if (!(r instanceof CrucibleRecipe) || !((CrucibleRecipe)r).key.equals(key)) continue;
|
||||
return (CrucibleRecipe)r;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static CrucibleRecipe getCrucibleRecipe(ItemStack stack) {
|
||||
for (Object r : crucibleRecipes) {
|
||||
if (!(r instanceof CrucibleRecipe) || !((CrucibleRecipe)r).recipeOutput.isItemEqual(stack)) continue;
|
||||
return (CrucibleRecipe)r;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static CrucibleRecipe getCrucibleRecipe(AspectList tags, TileCrucible tile) {
|
||||
int highest = 0;
|
||||
int index = -1;
|
||||
for (int a = 0; a < AuracoreRecipes.getCrucibleRecipes().size(); ++a) {
|
||||
int result;
|
||||
CrucibleRecipe recipe;
|
||||
if (!(AuracoreRecipes.getCrucibleRecipes().get(a) instanceof CrucibleRecipe) || !(recipe = (CrucibleRecipe)AuracoreRecipes.getCrucibleRecipes().get(a)).matches(tags) || (result = recipe.aspects.size()) <= highest) continue;
|
||||
highest = result;
|
||||
index = a;
|
||||
}
|
||||
if (index < 0) {
|
||||
return null;
|
||||
} else {
|
||||
return crucibleRecipes.get(index);
|
||||
}
|
||||
}
|
||||
|
||||
public static int getCrucibleOutputCost(TileCrucible tile, CrucibleRecipe recipe) {
|
||||
int output = 0;
|
||||
AspectList tt = new AspectList();
|
||||
tt.aspects.putAll(tile.aspects.aspects);
|
||||
while (recipe.matches(tt)) {
|
||||
tt = recipe.removeMatching(tt);
|
||||
output += recipe.cost;
|
||||
}
|
||||
return output;
|
||||
}
|
||||
|
||||
public static ItemStack getCrucibleOutput(AspectList tags, TileCrucible tile, CrucibleRecipe recipe) {
|
||||
ItemStack output = recipe.recipeOutput.copy();
|
||||
int stackInc = output.stackSize;
|
||||
output.stackSize = 0;
|
||||
while (recipe.matches(tags)) {
|
||||
tags = recipe.removeMatching(tags);
|
||||
output.stackSize += stackInc;
|
||||
}
|
||||
if (!tile.getWorldObj().isRemote) {
|
||||
tile.aspects = tags;
|
||||
}
|
||||
return output;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,11 +1,18 @@
|
|||
package dev.tilera.auracore.crafting;
|
||||
|
||||
import dev.tilera.auracore.api.AuracoreRecipes;
|
||||
import dev.tilera.auracore.api.crafting.CrucibleRecipe;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.world.World;
|
||||
import thaumcraft.api.ThaumcraftApi;
|
||||
import thaumcraft.api.aspects.Aspect;
|
||||
import thaumcraft.api.aspects.AspectList;
|
||||
import thaumcraft.api.crafting.IArcaneRecipe;
|
||||
import thaumcraft.common.config.ConfigBlocks;
|
||||
import thaumcraft.common.lib.research.ResearchManager;
|
||||
import thaumcraft.common.tiles.TileCrucible;
|
||||
import thaumcraft.common.tiles.TileMagicWorkbench;
|
||||
|
||||
public class AuracoreCraftingManager {
|
||||
|
@ -40,4 +47,52 @@ public class AuracoreCraftingManager {
|
|||
return workbenchTile;
|
||||
}
|
||||
|
||||
public static boolean performCrucibleCrafting(EntityPlayer player, TileCrucible tile) {
|
||||
AspectList tags = new AspectList();
|
||||
for (Aspect tag : tile.aspects.getAspects()) {
|
||||
tags.add(tag, tile.aspects.getAmount(tag));
|
||||
}
|
||||
World world = tile.getWorldObj();
|
||||
CrucibleRecipe recipe = AuracoreRecipes.getCrucibleRecipe(tags, tile);
|
||||
ItemStack output = AuracoreRecipes.getCrucibleOutput(tags, tile, recipe);
|
||||
if (output != null && isCrucibleCreationSuccessful(world, output, player) && !world.isRemote) {
|
||||
tile.ejectItem(output);
|
||||
world.addBlockEvent(tile.xCoord, tile.yCoord, tile.zCoord, ConfigBlocks.blockMetalDevice, 1, -1);
|
||||
}
|
||||
if (!world.isRemote) {
|
||||
tile.spillRemnants();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static boolean isCrucibleCreationSuccessful(World world, ItemStack item, EntityPlayer player) {
|
||||
String key = AuracoreRecipes.getCrucibleRecipe((ItemStack)item).key;
|
||||
boolean completed = ResearchManager.isResearchComplete(player.getDisplayName(), key);
|
||||
float chance = 0.0f;
|
||||
if (completed) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
//TODO: research
|
||||
/*if (!ResearchManager.doesPlayerHaveRequisites(player.getDisplayName(), key)) {
|
||||
return false;
|
||||
}
|
||||
ItemStack note = ResearchManager.createResearchNoteForPlayer(world, player, key);
|
||||
if (note == null) {
|
||||
if (!world.isRemote) {
|
||||
player.func_70006_a("Your discover something, but you can't record your findings!");
|
||||
}
|
||||
} else if (ResearchManager.progressExperimentalResearch(world, key, note, Config.resExpChance + (int)Math.sqrt(item.stackSize * 8))) {
|
||||
chance = ResearchManager.getData(note).getTotalProgress();
|
||||
if (chance == 1.0f) {
|
||||
note.setItemDamage(note.getItemDamage() + 64);
|
||||
}
|
||||
player.inventoryContainer.detectAndSendChanges();
|
||||
if (!world.isRemote) {
|
||||
player.func_70006_a("You've learned something new!");
|
||||
}
|
||||
}
|
||||
return world.rand.nextFloat() < chance;*/
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue