mirror of
https://github.com/GTNewHorizons/ForestryMC.git
synced 2026-11-19 03:39:09 +00:00
Add better error checking to the Fabricator
This commit is contained in:
1 parent
9247ed1509
commit
e154d4e2c6
3 files changed
+46
-45
No files matched your search
@@ -242,14 +242,18 @@ public abstract class RecipeUtil {
|
||||
}
|
||||
|
||||
public static boolean matches(IDescriptiveRecipe recipe, IInventory inventoryCrafting) {
|
||||
ItemStack[][] resources = getResources(inventoryCrafting);
|
||||
Object[] recipeIngredients = recipe.getIngredients();
|
||||
int width = recipe.getWidth();
|
||||
int height = recipe.getHeight();
|
||||
return matches(recipeIngredients, width, height, inventoryCrafting);
|
||||
}
|
||||
|
||||
public static boolean matches(Object[] recipeIngredients, int width, int height, IInventory inventoryCrafting) {
|
||||
ItemStack[][] resources = getResources(inventoryCrafting);
|
||||
return matches(recipeIngredients, width, height, resources);
|
||||
}
|
||||
|
||||
private static ItemStack[][] getResources(IInventory inventoryCrafting) {
|
||||
public static ItemStack[][] getResources(IInventory inventoryCrafting) {
|
||||
ItemStack[][] resources = new ItemStack[3][3];
|
||||
for (int i = 0; i < 3; i++) {
|
||||
for (int j = 0; j < 3; j++) {
|
||||
|
||||
@@ -16,6 +16,7 @@ import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
@@ -42,23 +43,15 @@ public class FabricatorRecipeManager implements IFabricatorManager {
|
||||
RecipeManagers.fabricatorSmeltingManager.addSmelting(resource, molten, meltingPoint);
|
||||
}
|
||||
|
||||
public static IFabricatorRecipe findMatchingRecipe(ItemStack plan, FluidStack liquid, ItemStack[] resources) {
|
||||
ItemStack[][] gridResources = new ItemStack[3][3];
|
||||
for (int i = 0; i < 3; i++) {
|
||||
for (int j = 0; j < 3; j++) {
|
||||
gridResources[j][i] = resources[i * 3 + j];
|
||||
}
|
||||
}
|
||||
public static IFabricatorRecipe findMatchingRecipe(ItemStack plan, IInventory resources) {
|
||||
ItemStack[][] gridResources = RecipeUtil.getResources(resources);
|
||||
|
||||
for (IFabricatorRecipe recipe : recipes) {
|
||||
if (recipe.getPlan() != null && !ItemStackUtil.isCraftingEquivalent(recipe.getPlan(), plan)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (RecipeUtil.matches(recipe.getIngredients(), recipe.getWidth(), recipe.getHeight(), gridResources)) {
|
||||
if (liquid == null || liquid.containsFluid(recipe.getLiquid())) {
|
||||
return recipe;
|
||||
}
|
||||
return recipe;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -27,9 +27,11 @@ import net.minecraftforge.fluids.FluidStack;
|
||||
import net.minecraftforge.fluids.FluidTankInfo;
|
||||
import net.minecraftforge.fluids.IFluidHandler;
|
||||
|
||||
import forestry.api.core.IErrorLogic;
|
||||
import forestry.api.recipes.IFabricatorRecipe;
|
||||
import forestry.api.recipes.IFabricatorSmeltingRecipe;
|
||||
import forestry.core.config.Constants;
|
||||
import forestry.core.errors.EnumErrorCode;
|
||||
import forestry.core.fluids.Fluids;
|
||||
import forestry.core.fluids.TankManager;
|
||||
import forestry.core.fluids.tanks.FilteredTank;
|
||||
@@ -129,7 +131,11 @@ public class TileFabricator extends TilePowered implements ICrafter, ILiquidTank
|
||||
}
|
||||
}
|
||||
|
||||
this.dissipateHeat();
|
||||
if (heat > 2500) {
|
||||
this.heat -= 2;
|
||||
} else if (heat > 0) {
|
||||
this.heat--;
|
||||
}
|
||||
}
|
||||
|
||||
private void trySmelting() {
|
||||
@@ -155,36 +161,25 @@ public class TileFabricator extends TilePowered implements ICrafter, ILiquidTank
|
||||
|
||||
@Override
|
||||
public boolean workCycle() {
|
||||
craftResult(null);
|
||||
return addHeat(100);
|
||||
}
|
||||
|
||||
private boolean addHeat(int addition) {
|
||||
if (this.heat >= MAX_HEAT) {
|
||||
return false;
|
||||
}
|
||||
|
||||
this.heat += addition;
|
||||
this.heat += 100;
|
||||
if (this.heat > MAX_HEAT) {
|
||||
this.heat = MAX_HEAT;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
craftResult();
|
||||
|
||||
private void dissipateHeat() {
|
||||
if (heat > 2500) {
|
||||
this.heat -= 2;
|
||||
} else if (heat > 0) {
|
||||
this.heat--;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private IFabricatorRecipe getRecipe() {
|
||||
IInventoryAdapter inventory = getInternalInventory();
|
||||
ItemStack plan = inventory.getStackInSlot(InventoryFabricator.SLOT_PLAN);
|
||||
ItemStack[] crafting = InventoryUtil.getStacks(craftingInventory, InventoryFabricator.SLOT_CRAFTING_1, InventoryFabricator.SLOT_CRAFTING_COUNT);
|
||||
return FabricatorRecipeManager.findMatchingRecipe(plan, moltenTank.getFluid(), crafting);
|
||||
FluidStack liquid = moltenTank.getFluid();
|
||||
IFabricatorRecipe recipe = FabricatorRecipeManager.findMatchingRecipe(plan, craftingInventory);
|
||||
if (liquid != null && !liquid.containsFluid(recipe.getLiquid())) {
|
||||
return null;
|
||||
}
|
||||
return recipe;
|
||||
}
|
||||
|
||||
public ItemStack getResult() {
|
||||
@@ -207,7 +202,7 @@ public class TileFabricator extends TilePowered implements ICrafter, ILiquidTank
|
||||
return getInternalInventory().decrStackSize(InventoryFabricator.SLOT_RESULT, 1);
|
||||
}
|
||||
|
||||
private void craftResult(EntityPlayer player) {
|
||||
private void craftResult() {
|
||||
IFabricatorRecipe myRecipe = getRecipe();
|
||||
if (myRecipe == null) {
|
||||
return;
|
||||
@@ -228,7 +223,7 @@ public class TileFabricator extends TilePowered implements ICrafter, ILiquidTank
|
||||
|
||||
// Remove resources
|
||||
ItemStack[] crafting = InventoryUtil.getStacks(craftingInventory, InventoryFabricator.SLOT_CRAFTING_1, InventoryFabricator.SLOT_CRAFTING_COUNT);
|
||||
if (!removeFromInventory(crafting, player, false)) {
|
||||
if (!removeFromInventory(crafting, null, false)) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -236,7 +231,7 @@ public class TileFabricator extends TilePowered implements ICrafter, ILiquidTank
|
||||
return;
|
||||
}
|
||||
|
||||
removeFromInventory(crafting, player, true);
|
||||
removeFromInventory(crafting, null, true);
|
||||
moltenTank.drain(liquid.amount, true);
|
||||
|
||||
// Damage plan
|
||||
@@ -257,17 +252,26 @@ public class TileFabricator extends TilePowered implements ICrafter, ILiquidTank
|
||||
|
||||
@Override
|
||||
public boolean hasWork() {
|
||||
IInventoryAdapter inventory = getInternalInventory();
|
||||
ItemStack itemToMelt = inventory.getStackInSlot(InventoryFabricator.SLOT_METAL);
|
||||
IFabricatorSmeltingRecipe smelting = FabricatorSmeltingRecipeManager.findMatchingSmelting(itemToMelt);
|
||||
if (smelting != null && moltenTank.fill(smelting.getProduct(), false) > 0) {
|
||||
return true;
|
||||
boolean hasRecipe = true;
|
||||
boolean hasLiquidResources = true;
|
||||
boolean hasResources = true;
|
||||
|
||||
ItemStack plan = getStackInSlot(InventoryFabricator.SLOT_PLAN);
|
||||
IFabricatorRecipe recipe = FabricatorRecipeManager.findMatchingRecipe(plan, craftingInventory);
|
||||
if (recipe != null) {
|
||||
ItemStack[] crafting = InventoryUtil.getStacks(craftingInventory, InventoryFabricator.SLOT_CRAFTING_1, InventoryFabricator.SLOT_CRAFTING_COUNT);
|
||||
hasResources = removeFromInventory(crafting, null, false);
|
||||
hasLiquidResources = moltenTank.canDrain(recipe.getLiquid());
|
||||
} else {
|
||||
hasRecipe = false;
|
||||
}
|
||||
|
||||
ItemStack plan = inventory.getStackInSlot(InventoryFabricator.SLOT_PLAN);
|
||||
ItemStack[] resources = InventoryUtil.getStacks(craftingInventory, InventoryFabricator.SLOT_CRAFTING_1, InventoryFabricator.SLOT_CRAFTING_COUNT);
|
||||
IErrorLogic errorLogic = getErrorLogic();
|
||||
errorLogic.setCondition(!hasRecipe, EnumErrorCode.NO_RECIPE);
|
||||
errorLogic.setCondition(!hasLiquidResources, EnumErrorCode.NO_RESOURCE_LIQUID);
|
||||
errorLogic.setCondition(!hasResources, EnumErrorCode.NO_RESOURCE_INVENTORY);
|
||||
|
||||
return FabricatorRecipeManager.findMatchingRecipe(plan, moltenTank.getFluid(), resources) != null;
|
||||
return hasRecipe;
|
||||
}
|
||||
|
||||
public int getHeatScaled(int i) {
|
||||
|
||||
Reference in new issue
Block a user