mirror of
https://github.com/GTNewHorizons/ForestryMC.git
synced 2026-11-28 15:36:18 +00:00
Merge branch 'mc-1.11' of https://github.com/ForestryMC/ForestryMC into Greenhouse
This commit is contained in:
commit
35f7ba6153
26 files changed
+547
-373
No files matched your search
@@ -49,4 +49,33 @@ public interface IFermenterManager extends ICraftingProvider<IFermenterRecipe> {
|
||||
* @throws NullPointerException if resource, output or liquid is null
|
||||
*/
|
||||
void addRecipe(ItemStack resource, int fermentationValue, float modifier, FluidStack output);
|
||||
|
||||
/**
|
||||
* Add a recipe to the fermenter
|
||||
*
|
||||
* @param resource String representing the resource as a {@link net.minecraftforge.oredict.OreDictionary} name.
|
||||
* @param fermentationValue Value of the given resource, i.e. how much needs
|
||||
* to be fermented for the output to be deposited into the product tank.
|
||||
* @param modifier Modifies the amount of liquid output per work cycle.
|
||||
* (water = 1.0f, honey = 1.5f)
|
||||
* @param output LiquidStack representing output liquid. Amount is
|
||||
* determined by fermentationValue*modifier.
|
||||
* @param liquid LiquidStack representing resource liquid and amount.
|
||||
* @throws NullPointerException if resource, output or liquid is null
|
||||
*/
|
||||
void addRecipe(String resource, int fermentationValue, float modifier, FluidStack output, FluidStack liquid);
|
||||
|
||||
/**
|
||||
* Add a recipe to the fermenter. Defaults to water as input liquid.
|
||||
*
|
||||
* @param resource String representing the resource as a {@link net.minecraftforge.oredict.OreDictionary} name.
|
||||
* @param modifier Modifies the amount of liquid output per work cycle.
|
||||
* (water = 1.0f, honey = 1.5f)
|
||||
* @param fermentationValue Value of the given resource, i.e. how much needs
|
||||
* to be fermented for the output to be deposited into the product tank.
|
||||
* @param output LiquidStack representing output liquid. Amount is
|
||||
* determined by fermentationValue*modifier.
|
||||
* @throws NullPointerException if resource, output or liquid is null
|
||||
*/
|
||||
void addRecipe(String resource, int fermentationValue, float modifier, FluidStack output);
|
||||
}
|
||||
@@ -5,16 +5,26 @@
|
||||
******************************************************************************/
|
||||
package forestry.api.recipes;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import net.minecraftforge.fluids.Fluid;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
|
||||
public interface IFermenterRecipe extends IForestryRecipe {
|
||||
public interface IFermenterRecipe extends IForestryRecipe, Comparable<IFermenterRecipe> {
|
||||
|
||||
/**
|
||||
* @return ItemStack representing the input resource.
|
||||
*/
|
||||
ItemStack getResource();
|
||||
|
||||
/**
|
||||
* @return String representing the input resource as a {@link net.minecraftforge.oredict.OreDictionary} name.
|
||||
*/
|
||||
@Nullable
|
||||
String getResourceOreName();
|
||||
|
||||
/**
|
||||
* @return FluidStack representing the input fluid resource.
|
||||
*/
|
||||
|
||||
@@ -10,34 +10,15 @@
|
||||
******************************************************************************/
|
||||
package forestry.core;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import net.minecraft.command.ICommand;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.init.Items;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.world.storage.loot.functions.LootFunctionManager;
|
||||
|
||||
import net.minecraftforge.client.event.ModelBakeEvent;
|
||||
import net.minecraftforge.client.event.TextureStitchEvent;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.fluids.FluidRegistry;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
import net.minecraftforge.oredict.OreDictionary;
|
||||
import net.minecraftforge.oredict.RecipeSorter;
|
||||
|
||||
import net.minecraftforge.fml.common.IFuelHandler;
|
||||
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import forestry.api.circuits.ChipsetManager;
|
||||
import forestry.api.core.CamouflageManager;
|
||||
import forestry.api.core.ForestryAPI;
|
||||
import forestry.api.genetics.AlleleManager;
|
||||
import forestry.api.multiblock.MultiblockManager;
|
||||
@@ -63,6 +44,8 @@ import forestry.core.items.EnumContainerType;
|
||||
import forestry.core.items.ItemRegistryCore;
|
||||
import forestry.core.items.ItemRegistryFluids;
|
||||
import forestry.core.loot.SetSpeciesNBT;
|
||||
import forestry.core.models.ModelCamouflageSprayCan;
|
||||
import forestry.core.models.ModelEntry;
|
||||
import forestry.core.models.ModelManager;
|
||||
import forestry.core.multiblock.MultiblockLogicFactory;
|
||||
import forestry.core.network.IPacketRegistry;
|
||||
@@ -79,6 +62,23 @@ import forestry.core.utils.World2ObjectMap;
|
||||
import forestry.plugins.BlankForestryPlugin;
|
||||
import forestry.plugins.ForestryPlugin;
|
||||
import forestry.plugins.ForestryPluginUids;
|
||||
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
|
||||
import net.minecraft.command.ICommand;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.init.Items;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.world.storage.loot.functions.LootFunctionManager;
|
||||
import net.minecraftforge.client.event.ModelBakeEvent;
|
||||
import net.minecraftforge.client.event.TextureStitchEvent;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.fluids.FluidRegistry;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
import net.minecraftforge.fml.common.IFuelHandler;
|
||||
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
import net.minecraftforge.oredict.OreDictionary;
|
||||
import net.minecraftforge.oredict.RecipeSorter;
|
||||
|
||||
@ForestryPlugin(pluginID = ForestryPluginUids.CORE, name = "Core", author = "SirSengir", url = Constants.URL, unlocalizedDescription = "for.plugin.core.description")
|
||||
public class PluginCore extends BlankForestryPlugin {
|
||||
@@ -292,6 +292,9 @@ public class PluginCore extends BlankForestryPlugin {
|
||||
|
||||
// / WRENCH
|
||||
RecipeUtil.addRecipe(items.wrench, "# #", " # ", " # ", '#', OreDictUtil.INGOT_BRONZE);
|
||||
|
||||
// / CAMOUFLAGE SPRAY CAN
|
||||
RecipeUtil.addRecipe(items.camouflageSprayCan, "TTT", "TCT", "TCT", 'T', OreDictUtil.INGOT_TIN, 'C', items.craftingMaterial.getCamouflagedPaneling());
|
||||
|
||||
// / WEB
|
||||
RecipeUtil.addRecipe(new ItemStack(Blocks.WEB, 4), "# #", " # ", "# #", '#', items.craftingMaterial.getSilkWisp());
|
||||
|
||||
@@ -12,7 +12,6 @@ package forestry.core.fluids;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import forestry.core.utils.InventoryUtil;
|
||||
import forestry.core.utils.ItemStackUtil;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
@@ -107,7 +106,7 @@ public final class FluidHelper {
|
||||
|
||||
boolean moveToOutput = fluidInContainer.amount >= containerCapacity;
|
||||
if (moveToOutput) {
|
||||
if (!output.isEmpty() && (output.getCount() >= output.getMaxStackSize() || !InventoryUtil.isItemEqual(filled, output))) {
|
||||
if (!output.isEmpty() && (output.getCount() >= output.getMaxStackSize() || !ItemStackUtil.areItemStacksEqualIgnoreCount(filled, output))) {
|
||||
return FillStatus.NO_SPACE;
|
||||
}
|
||||
} else {
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
******************************************************************************/
|
||||
package forestry.core.gui.slots;
|
||||
|
||||
import forestry.factory.inventory.InventoryCraftingForestry;
|
||||
import forestry.factory.tiles.ICrafterWorktable;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.init.Blocks;
|
||||
@@ -29,7 +30,7 @@ public class SlotCrafter extends Slot {
|
||||
/**
|
||||
* The craft matrix inventory linked to this result slot.
|
||||
*/
|
||||
private final IInventory craftMatrix;
|
||||
private final InventoryCraftingForestry craftMatrix;
|
||||
private final ICrafterWorktable crafter;
|
||||
|
||||
/**
|
||||
@@ -40,9 +41,9 @@ public class SlotCrafter extends Slot {
|
||||
* The number of items that have been crafted so far. Gets passed to ItemStack.onCrafting before being reset.
|
||||
*/
|
||||
private int amountCrafted;
|
||||
|
||||
public SlotCrafter(EntityPlayer player, IInventory craftMatrix, ICrafterWorktable crafter, int slot, int xPos, int yPos) {
|
||||
super(craftMatrix, slot, xPos, yPos);
|
||||
|
||||
public SlotCrafter(EntityPlayer player, InventoryCraftingForestry craftMatrix, IInventory craftingDisplay, ICrafterWorktable crafter, int slot, int xPos, int yPos) {
|
||||
super(craftingDisplay, slot, xPos, yPos);
|
||||
this.craftMatrix = craftMatrix;
|
||||
this.crafter = crafter;
|
||||
this.player = player;
|
||||
@@ -136,7 +137,7 @@ public class SlotCrafter extends Slot {
|
||||
|
||||
@Override
|
||||
public ItemStack getStack() {
|
||||
return crafter.getResult();
|
||||
return crafter.getResult(craftMatrix, player.world);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -13,11 +13,6 @@ package forestry.core.recipes;
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.List;
|
||||
|
||||
import forestry.api.recipes.IDescriptiveRecipe;
|
||||
import forestry.api.recipes.RecipeManagers;
|
||||
import forestry.core.fluids.Fluids;
|
||||
import forestry.core.utils.ItemStackUtil;
|
||||
import forestry.factory.inventory.InventoryCraftingForestry;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.inventory.InventoryCrafting;
|
||||
@@ -27,11 +22,19 @@ import net.minecraft.item.crafting.CraftingManager;
|
||||
import net.minecraft.item.crafting.IRecipe;
|
||||
import net.minecraft.util.NonNullList;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import net.minecraftforge.fluids.FluidRegistry;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
import net.minecraftforge.fml.common.registry.GameRegistry;
|
||||
import net.minecraftforge.oredict.ShapelessOreRecipe;
|
||||
|
||||
import net.minecraftforge.fml.common.registry.GameRegistry;
|
||||
|
||||
import forestry.api.recipes.IDescriptiveRecipe;
|
||||
import forestry.api.recipes.RecipeManagers;
|
||||
import forestry.core.fluids.Fluids;
|
||||
import forestry.core.utils.ItemStackUtil;
|
||||
import forestry.factory.inventory.InventoryCraftingForestry;
|
||||
|
||||
public abstract class RecipeUtil {
|
||||
|
||||
public static void addFermenterRecipes(ItemStack resource, int fermentationValue, Fluids output) {
|
||||
@@ -50,120 +53,93 @@ public abstract class RecipeUtil {
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static InventoryCraftingForestry getCraftRecipe(NonNullList<ItemStack> recipeItems, NonNullList<ItemStack> availableItems, World world, ItemStack recipeOutput) {
|
||||
// Need at least one matched set
|
||||
if (ItemStackUtil.containsSets(recipeItems, availableItems, true, true) == 0) {
|
||||
return null;
|
||||
public static void addFermenterRecipes(String resource, int fermentationValue, Fluids output) {
|
||||
if (RecipeManagers.fermenterManager == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Check that it doesn't make a different recipe.
|
||||
// For example:
|
||||
// Wood Logs are all ore dictionary equivalent with each other,
|
||||
// but an Oak Log shouldn't be able to make Ebony Wood Planks
|
||||
// because it makes Oak Wood Planks using the same recipe.
|
||||
// Strategy:
|
||||
// Create a fake crafting inventory using items we have in availableItems
|
||||
// in place of the ones in the saved crafting inventory.
|
||||
// Check that the recipe it makes is the same as the currentRecipe.
|
||||
RecipeManagers.fermenterManager.addRecipe(resource, fermentationValue, 1.0f, output.getFluid(1), new FluidStack(FluidRegistry.WATER, 1));
|
||||
|
||||
if (FluidRegistry.isFluidRegistered(Fluids.JUICE.getFluid())) {
|
||||
RecipeManagers.fermenterManager.addRecipe(resource, fermentationValue, 1.5f, output.getFluid(1), Fluids.JUICE.getFluid(1));
|
||||
}
|
||||
|
||||
if (FluidRegistry.isFluidRegistered(Fluids.FOR_HONEY.getFluid())) {
|
||||
RecipeManagers.fermenterManager.addRecipe(resource, fermentationValue, 1.5f, output.getFluid(1), Fluids.FOR_HONEY.getFluid(1));
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static InventoryCraftingForestry getCraftRecipe(InventoryCrafting originalCrafting, NonNullList<ItemStack> availableItems, World world, IRecipe recipe) {
|
||||
if (!recipe.matches(originalCrafting, world)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
ItemStack expectedOutput = recipe.getCraftingResult(originalCrafting);
|
||||
if (expectedOutput.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
InventoryCraftingForestry crafting = new InventoryCraftingForestry();
|
||||
NonNullList<ItemStack> stockCopy = ItemStackUtil.condenseStacks(availableItems);
|
||||
|
||||
for (int slot = 0; slot < recipeItems.size(); slot++) {
|
||||
ItemStack recipeStack = recipeItems.get(slot);
|
||||
if (recipeStack.isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Use crafting equivalent (not oredict) items first
|
||||
for (ItemStack stockStack : stockCopy) {
|
||||
if (stockStack.getCount() > 0 && ItemStackUtil.isCraftingEquivalent(recipeStack, stockStack, false, false)) {
|
||||
ItemStack stack = ItemStackUtil.createCopyWithCount(stockStack, 1);
|
||||
stockStack.shrink(1);
|
||||
crafting.setInventorySlotContents(slot, stack);
|
||||
break;
|
||||
for (int slot = 0; slot < originalCrafting.getSizeInventory(); slot++) {
|
||||
ItemStack stackInSlot = originalCrafting.getStackInSlot(slot);
|
||||
if (!stackInSlot.isEmpty()) {
|
||||
ItemStack equivalent = getCraftingEquivalent(stockCopy, originalCrafting, slot, world, recipe, expectedOutput);
|
||||
if (equivalent.isEmpty()) {
|
||||
return null;
|
||||
} else {
|
||||
crafting.setInventorySlotContents(slot, equivalent);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (recipe.matches(crafting, world)) {
|
||||
ItemStack output = recipe.getCraftingResult(crafting);
|
||||
if (ItemStack.areItemStacksEqual(output, expectedOutput)) {
|
||||
return crafting;
|
||||
}
|
||||
}
|
||||
|
||||
// Use oredict items if crafting equivalent items aren't available
|
||||
if (crafting.getStackInSlot(slot).isEmpty()) {
|
||||
for (ItemStack stockStack : stockCopy) {
|
||||
if (stockStack.getCount() > 0 && ItemStackUtil.isCraftingEquivalent(recipeStack, stockStack, true, true)) {
|
||||
ItemStack stack = ItemStackUtil.createCopyWithCount(stockStack, 1);
|
||||
stockStack.shrink(1);
|
||||
crafting.setInventorySlotContents(slot, stack);
|
||||
break;
|
||||
return null;
|
||||
}
|
||||
|
||||
private static ItemStack getCraftingEquivalent(NonNullList<ItemStack> stockCopy, InventoryCrafting crafting, int slot, World world, IRecipe recipe, ItemStack expectedOutput)
|
||||
{
|
||||
ItemStack originalStack = crafting.getStackInSlot(slot);
|
||||
for (ItemStack stockStack : stockCopy)
|
||||
{
|
||||
if (!stockStack.isEmpty())
|
||||
{
|
||||
ItemStack singleStockStack = ItemStackUtil.createCopyWithCount(stockStack, 1);
|
||||
crafting.setInventorySlotContents(slot, singleStockStack);
|
||||
if (recipe.matches(crafting, world))
|
||||
{
|
||||
ItemStack output = recipe.getCraftingResult(crafting);
|
||||
if (ItemStack.areItemStacksEqual(output, expectedOutput))
|
||||
{
|
||||
crafting.setInventorySlotContents(slot, originalStack);
|
||||
return stockStack.splitStack(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
List<ItemStack> outputs = findMatchingRecipes(crafting, world);
|
||||
if (!ItemStackUtil.containsItemStack(outputs, recipeOutput)) {
|
||||
return null;
|
||||
}
|
||||
return crafting;
|
||||
crafting.setInventorySlotContents(slot, originalStack);
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
|
||||
public static NonNullList<ItemStack> findMatchingRecipes(InventoryCrafting inventory, World world) {
|
||||
NonNullList<ItemStack> matchingRecipes = NonNullList.create();
|
||||
ItemStack repairRecipe = findRepairRecipe(inventory);
|
||||
if (!repairRecipe.isEmpty()) {
|
||||
matchingRecipes.add(repairRecipe);
|
||||
return matchingRecipes;
|
||||
}
|
||||
|
||||
for (Object recipe : CraftingManager.getInstance().getRecipeList()) {
|
||||
IRecipe irecipe = (IRecipe) recipe;
|
||||
|
||||
if (irecipe.matches(inventory, world)) {
|
||||
ItemStack result = irecipe.getCraftingResult(inventory);
|
||||
if (!ItemStackUtil.containsItemStack(matchingRecipes, result)) {
|
||||
matchingRecipes.add(result);
|
||||
}
|
||||
public static NonNullList<IRecipe> findMatchingRecipes(InventoryCrafting inventory, World world) {
|
||||
NonNullList<IRecipe> matchingRecipes = NonNullList.create();
|
||||
for (IRecipe recipe : CraftingManager.getInstance().getRecipeList()) {
|
||||
if (recipe.matches(inventory, world)) {
|
||||
matchingRecipes.add(recipe);
|
||||
}
|
||||
}
|
||||
|
||||
return matchingRecipes;
|
||||
}
|
||||
|
||||
private static ItemStack findRepairRecipe(InventoryCrafting inventory) {
|
||||
int craftIngredientCount = 0;
|
||||
ItemStack itemstack0 = ItemStack.EMPTY;
|
||||
ItemStack itemstack1 = ItemStack.EMPTY;
|
||||
|
||||
for (int j = 0; j < inventory.getSizeInventory(); j++) {
|
||||
ItemStack itemstack = inventory.getStackInSlot(j);
|
||||
|
||||
if (!itemstack.isEmpty()) {
|
||||
if (craftIngredientCount == 0) {
|
||||
itemstack0 = itemstack;
|
||||
}
|
||||
|
||||
if (craftIngredientCount == 1) {
|
||||
itemstack1 = itemstack;
|
||||
}
|
||||
|
||||
++craftIngredientCount;
|
||||
}
|
||||
}
|
||||
|
||||
if (craftIngredientCount == 2 && itemstack0.getItem() == itemstack1.getItem() && itemstack0.getCount() == 1 && itemstack1.getCount() == 1 && itemstack0.getItem().isRepairable()) {
|
||||
int damage0 = itemstack0.getMaxDamage() - itemstack0.getItemDamage();
|
||||
int damage1 = itemstack0.getMaxDamage() - itemstack1.getItemDamage();
|
||||
int repairAmount = damage0 + damage1 + itemstack0.getMaxDamage() * 5 / 100;
|
||||
int repairedDamage = itemstack0.getMaxDamage() - repairAmount;
|
||||
|
||||
if (repairedDamage < 0) {
|
||||
repairedDamage = 0;
|
||||
}
|
||||
|
||||
return new ItemStack(itemstack0.getItem(), 1, repairedDamage);
|
||||
}
|
||||
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
|
||||
public static void addRecipe(Block block, Object... obj) {
|
||||
addRecipe(new ItemStack(block), obj);
|
||||
}
|
||||
@@ -196,6 +172,7 @@ public abstract class RecipeUtil {
|
||||
GameRegistry.addSmelting(res, prod, xp);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static String[][] matches(IDescriptiveRecipe recipe, IInventory inventoryCrafting) {
|
||||
NonNullList<NonNullList<ItemStack>> recipeIngredients = recipe.getIngredients();
|
||||
NonNullList<String> oreDicts = recipe.getOreDicts();
|
||||
@@ -204,6 +181,7 @@ public abstract class RecipeUtil {
|
||||
return matches(recipeIngredients, oreDicts, width, height, inventoryCrafting);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static String[][] matches(NonNullList<NonNullList<ItemStack>> recipeIngredients, NonNullList<String> oreDicts, int width, int height, IInventory inventoryCrafting) {
|
||||
ItemStack[][] resources = getResources(inventoryCrafting);
|
||||
return matches(recipeIngredients, oreDicts, width, height, resources);
|
||||
|
||||
@@ -11,7 +11,6 @@
|
||||
package forestry.core.utils;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.Collection;
|
||||
|
||||
import forestry.api.core.ForestryAPI;
|
||||
import forestry.core.circuits.ISocketable;
|
||||
@@ -32,75 +31,8 @@ import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.ForgeHooks;
|
||||
import net.minecraftforge.fml.common.Optional;
|
||||
import net.minecraftforge.items.IItemHandler;
|
||||
import net.minecraftforge.oredict.OreDictionary;
|
||||
|
||||
public abstract class InventoryUtil {
|
||||
|
||||
public static boolean isWildcard(ItemStack stack) {
|
||||
return stack.getItemDamage() == OreDictionary.WILDCARD_VALUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* A more robust item comparison function. Supports items with damage = -1
|
||||
* matching any sub-type.
|
||||
*
|
||||
* @param a An ItemStack
|
||||
* @param b An ItemStack
|
||||
* @return True if equal
|
||||
*/
|
||||
public static boolean isItemEqual(ItemStack a, ItemStack b) {
|
||||
return isItemEqual(a, b, true, true);
|
||||
}
|
||||
|
||||
public static boolean isItemEqual(final ItemStack a, final ItemStack b, final boolean matchDamage, final boolean matchNBT) {
|
||||
if (a.isEmpty() || b.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
if (a.getItem() != b.getItem()) {
|
||||
return false;
|
||||
}
|
||||
if (matchNBT && !ItemStack.areItemStackTagsEqual(a, b)) {
|
||||
return false;
|
||||
}
|
||||
if (matchDamage && a.getHasSubtypes()) {
|
||||
if (isWildcard(a) || isWildcard(b)) {
|
||||
return true;
|
||||
}
|
||||
if (a.getItemDamage() != b.getItemDamage()) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the item is equal to any one of several possible matches.
|
||||
*/
|
||||
public static boolean isItemEqual(ItemStack stack, ItemStack... matches) {
|
||||
for (ItemStack match : matches) {
|
||||
if (isItemEqual(stack, match)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the item is equal to any one of several possible matches.
|
||||
*
|
||||
* @param stack the ItemStack to test
|
||||
* @param matches the ItemStacks to test against
|
||||
* @return true if a match is found
|
||||
*/
|
||||
public static boolean isItemEqual(ItemStack stack, Collection<ItemStack> matches) {
|
||||
for (ItemStack match : matches) {
|
||||
if (isItemEqual(stack, match)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Attempts to move an ItemStack from one inventory to another.
|
||||
*
|
||||
@@ -218,6 +150,48 @@ public abstract class InventoryUtil {
|
||||
return ItemStackUtil.containsSets(set, stock, oreDicts, craftingTools) >= count;
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean deleteExactSet(IInventory inventory, NonNullList<ItemStack> required) {
|
||||
NonNullList<ItemStack> offered = getStacks(inventory);
|
||||
NonNullList<ItemStack> condensedRequired = ItemStackUtil.condenseStacks(required);
|
||||
NonNullList<ItemStack> condensedOffered = ItemStackUtil.condenseStacks(offered);
|
||||
|
||||
for (ItemStack req : condensedRequired) {
|
||||
if (!containsExactStack(req, condensedOffered)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
for (ItemStack itemStack : condensedRequired) {
|
||||
deleteExactStack(inventory, itemStack);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private static boolean containsExactStack(ItemStack req, NonNullList<ItemStack> condensedOffered) {
|
||||
for (ItemStack offer : condensedOffered) {
|
||||
if (offer.getCount() >= req.getCount() && ItemStackUtil.areItemStacksEqualIgnoreCount(req, offer)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private static void deleteExactStack(IInventory inventory, ItemStack itemStack) {
|
||||
int count = itemStack.getCount();
|
||||
for (int j = 0; j < inventory.getSizeInventory(); j++) {
|
||||
ItemStack stackInSlot = inventory.getStackInSlot(j);
|
||||
if (!stackInSlot.isEmpty()) {
|
||||
if (ItemStackUtil.areItemStacksEqualIgnoreCount(itemStack, stackInSlot)) {
|
||||
ItemStack removed = inventory.decrStackSize(j, count);
|
||||
count -= removed.getCount();
|
||||
if (count == 0) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static NonNullList<ItemStack> removeSets(IInventory inventory, int count, NonNullList<ItemStack> set, @Nullable EntityPlayer player, boolean stowContainer, boolean oreDictionary, boolean craftingTools) {
|
||||
@@ -394,7 +368,7 @@ public abstract class InventoryUtil {
|
||||
public static boolean tryAddStacksCopy(IInventory inventory, NonNullList<ItemStack> stacks, int startSlot, int slots, boolean all) {
|
||||
|
||||
for (ItemStack stack : stacks) {
|
||||
if (stack == null) {
|
||||
if (stack == null || stack.isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
@@ -594,5 +594,24 @@ public abstract class ItemStackUtil {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Checks like {@link ItemStack#areItemStacksEqual(ItemStack, ItemStack)}
|
||||
* but ignores stack size (count).
|
||||
*/
|
||||
public static boolean areItemStacksEqualIgnoreCount(ItemStack a, ItemStack b) {
|
||||
if (a.isEmpty() && b.isEmpty()) {
|
||||
return true;
|
||||
} else if (a.isEmpty() || b.isEmpty()) {
|
||||
return false;
|
||||
} else if (a.getItem() != b.getItem()) {
|
||||
return false;
|
||||
} else if (a.getItemDamage() != b.getItemDamage()) {
|
||||
return false;
|
||||
} else if (a.getTagCompound() == null && b.getTagCompound() != null) {
|
||||
return false;
|
||||
} else {
|
||||
return (a.getTagCompound() == null || a.getTagCompound().equals(b.getTagCompound())) && a.areCapsCompatible(b);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -53,9 +53,13 @@ public class OreDictUtil {
|
||||
public static final String CROP_DATE = "cropDate";
|
||||
public static final String CROP_PAPAYA = "cropPapaya";
|
||||
|
||||
public static final String CROP_WHEAT = "cropWheat";
|
||||
public static final String CROP_POTATO = "cropPotato";
|
||||
public static final String CROP_CARROT = "cropCarrot";
|
||||
public static final String SUGARCANE = "sugarcane";
|
||||
|
||||
public static final String PANE_GLASS = "paneGlass";
|
||||
public static final String SAND = "sand";
|
||||
public static final String CROP_WHEAT = "cropWheat";
|
||||
public static final String DUST_REDSTONE = "dustRedstone";
|
||||
public static final String GEM_DIAMOND = "gemDiamond";
|
||||
public static final String STICK_WOOD = "stickWood";
|
||||
@@ -67,6 +71,7 @@ public class OreDictUtil {
|
||||
public static final String GEM_QUARTZ = "gemQuartz";
|
||||
public static final String CHEST_WOOD = "chestWood";
|
||||
public static final String LEATHER = "leather";
|
||||
public static final String BLOCK_CACTUS = "blockCactus";
|
||||
|
||||
public static final String DYE_YELLOW = "dyeYellow";
|
||||
public static final String DYE_BLUE = "dyeBlue";
|
||||
|
||||
@@ -12,6 +12,7 @@ package forestry.core.utils;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import forestry.core.gui.slots.SlotCrafter;
|
||||
import forestry.core.gui.slots.SlotForestry;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.InventoryPlayer;
|
||||
@@ -70,7 +71,7 @@ public abstract class SlotUtil {
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
|
||||
boolean fromCraftingSlot = slot instanceof SlotCrafting;
|
||||
boolean fromCraftingSlot = slot instanceof SlotCrafting || slot instanceof SlotCrafter;
|
||||
|
||||
int numSlots = inventorySlots.size();
|
||||
ItemStack stackInSlot = slot.getStack();
|
||||
@@ -82,7 +83,7 @@ public abstract class SlotUtil {
|
||||
|
||||
slot.onSlotChange(stackInSlot, originalStack);
|
||||
if (stackInSlot.isEmpty()) {
|
||||
slot.putStack(stackInSlot);
|
||||
slot.putStack(ItemStack.EMPTY);
|
||||
} else {
|
||||
slot.onSlotChanged();
|
||||
}
|
||||
|
||||
@@ -10,11 +10,17 @@
|
||||
******************************************************************************/
|
||||
package forestry.factory;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.NonNullList;
|
||||
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
|
||||
import forestry.api.recipes.ICarpenterManager;
|
||||
import forestry.api.recipes.ICarpenterRecipe;
|
||||
import forestry.api.recipes.ICentrifugeManager;
|
||||
@@ -33,9 +39,6 @@ import forestry.api.recipes.ISqueezerManager;
|
||||
import forestry.api.recipes.ISqueezerRecipe;
|
||||
import forestry.api.recipes.IStillManager;
|
||||
import forestry.api.recipes.IStillRecipe;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.NonNullList;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
|
||||
public class DummyManagers {
|
||||
|
||||
@@ -110,6 +113,16 @@ public class DummyManagers {
|
||||
public void addRecipe(ItemStack resource, int fermentationValue, float modifier, FluidStack output) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addRecipe(String resource, int fermentationValue, float modifier, FluidStack output, FluidStack liquid) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addRecipe(String resource, int fermentationValue, float modifier, FluidStack output) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public static class DummyMoistenerManager extends DummyCraftingProvider<IMoistenerRecipe> implements IMoistenerManager {
|
||||
|
||||
@@ -10,10 +10,22 @@
|
||||
******************************************************************************/
|
||||
package forestry.factory;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.Set;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import net.minecraft.block.BlockDirt.DirtType;
|
||||
import net.minecraft.block.BlockPlanks.EnumType;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.init.Items;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.NonNullList;
|
||||
|
||||
import net.minecraftforge.fluids.Fluid;
|
||||
import net.minecraftforge.fluids.FluidRegistry;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
|
||||
import forestry.api.circuits.ChipsetManager;
|
||||
import forestry.api.circuits.CircuitSocketType;
|
||||
import forestry.api.circuits.ICircuit;
|
||||
@@ -44,6 +56,7 @@ import forestry.core.items.ItemRegistryCore;
|
||||
import forestry.core.items.ItemRegistryFluids;
|
||||
import forestry.core.network.IPacketRegistry;
|
||||
import forestry.core.recipes.RecipeUtil;
|
||||
import forestry.core.utils.OreDictUtil;
|
||||
import forestry.core.utils.datastructures.FluidMap;
|
||||
import forestry.core.utils.datastructures.ItemStackMap;
|
||||
import forestry.factory.blocks.BlockRegistryFactory;
|
||||
@@ -61,15 +74,6 @@ import forestry.plugins.BlankForestryPlugin;
|
||||
import forestry.plugins.ForestryPlugin;
|
||||
import forestry.plugins.ForestryPluginUids;
|
||||
import forestry.storage.PluginStorage;
|
||||
import net.minecraft.block.BlockDirt.DirtType;
|
||||
import net.minecraft.block.BlockPlanks.EnumType;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.init.Items;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.NonNullList;
|
||||
import net.minecraftforge.fluids.Fluid;
|
||||
import net.minecraftforge.fluids.FluidRegistry;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
|
||||
@ForestryPlugin(pluginID = ForestryPluginUids.FACTORY, name = "Factory", author = "SirSengir", url = Constants.URL, unlocalizedDescription = "for.plugin.factory.description")
|
||||
public class PluginFactory extends BlankForestryPlugin {
|
||||
@@ -380,14 +384,12 @@ public class PluginFactory extends BlankForestryPlugin {
|
||||
RecipeManagers.moistenerManager.addRecipe(new ItemStack(Blocks.LEAVES, 1, EnumType.SPRUCE.ordinal()), new ItemStack(Blocks.DIRT, 1, DirtType.PODZOL.ordinal()), 5000);
|
||||
|
||||
// FERMENTER
|
||||
for (int i = 0; i < 6; i++) {
|
||||
RecipeUtil.addFermenterRecipes(new ItemStack(Blocks.SAPLING, 1, i), ForestryAPI.activeMode.getIntegerSetting("fermenter.yield.sapling"), Fluids.BIOMASS);
|
||||
}
|
||||
RecipeUtil.addFermenterRecipes(OreDictUtil.TREE_SAPLING, ForestryAPI.activeMode.getIntegerSetting("fermenter.yield.sapling"), Fluids.BIOMASS);
|
||||
|
||||
RecipeUtil.addFermenterRecipes(new ItemStack(Blocks.CACTUS), ForestryAPI.activeMode.getIntegerSetting("fermenter.yield.cactus"), Fluids.BIOMASS);
|
||||
RecipeUtil.addFermenterRecipes(new ItemStack(Items.WHEAT), ForestryAPI.activeMode.getIntegerSetting("fermenter.yield.wheat"), Fluids.BIOMASS);
|
||||
RecipeUtil.addFermenterRecipes(new ItemStack(Items.POTATO), 2 * ForestryAPI.activeMode.getIntegerSetting("fermenter.yield.wheat"), Fluids.BIOMASS);
|
||||
RecipeUtil.addFermenterRecipes(new ItemStack(Items.REEDS), ForestryAPI.activeMode.getIntegerSetting("fermenter.yield.cane"), Fluids.BIOMASS);
|
||||
RecipeUtil.addFermenterRecipes(OreDictUtil.BLOCK_CACTUS, ForestryAPI.activeMode.getIntegerSetting("fermenter.yield.cactus"), Fluids.BIOMASS);
|
||||
RecipeUtil.addFermenterRecipes(OreDictUtil.CROP_WHEAT, ForestryAPI.activeMode.getIntegerSetting("fermenter.yield.wheat"), Fluids.BIOMASS);
|
||||
RecipeUtil.addFermenterRecipes(OreDictUtil.CROP_POTATO, 2 * ForestryAPI.activeMode.getIntegerSetting("fermenter.yield.wheat"), Fluids.BIOMASS);
|
||||
RecipeUtil.addFermenterRecipes(OreDictUtil.SUGARCANE, ForestryAPI.activeMode.getIntegerSetting("fermenter.yield.cane"), Fluids.BIOMASS);
|
||||
RecipeUtil.addFermenterRecipes(new ItemStack(Blocks.BROWN_MUSHROOM), ForestryAPI.activeMode.getIntegerSetting("fermenter.yield.mushroom"), Fluids.BIOMASS);
|
||||
RecipeUtil.addFermenterRecipes(new ItemStack(Blocks.RED_MUSHROOM), ForestryAPI.activeMode.getIntegerSetting("fermenter.yield.mushroom"), Fluids.BIOMASS);
|
||||
|
||||
|
||||
@@ -61,7 +61,7 @@ public class ContainerWorktable extends ContainerTile<TileWorktable> implements
|
||||
}
|
||||
|
||||
// CraftResult display
|
||||
addSlotToContainer(new SlotCrafter(player, craftingDisplay, tile, InventoryGhostCrafting.SLOT_CRAFTING_RESULT, 77, 38));
|
||||
addSlotToContainer(new SlotCrafter(player, craftMatrix, craftingDisplay, tile, InventoryGhostCrafting.SLOT_CRAFTING_RESULT, 77, 38));
|
||||
|
||||
for (int i = 0; i < craftMatrix.getSizeInventory(); i++) {
|
||||
onCraftMatrixChanged(tile.getCraftingDisplay(), i);
|
||||
|
||||
@@ -12,14 +12,31 @@ package forestry.factory.inventory;
|
||||
|
||||
import forestry.core.gui.ContainerDummy;
|
||||
import forestry.factory.gui.ContainerWorktable;
|
||||
|
||||
import net.minecraft.inventory.Container;
|
||||
import net.minecraft.inventory.InventoryCrafting;
|
||||
|
||||
public class InventoryCraftingForestry extends InventoryCrafting {
|
||||
private final Container eventHandlerIn;
|
||||
|
||||
public InventoryCraftingForestry(ContainerWorktable containerWorktable) {
|
||||
super(containerWorktable, 3, 3);
|
||||
this(containerWorktable, 3, 3);
|
||||
}
|
||||
|
||||
public InventoryCraftingForestry() {
|
||||
super(ContainerDummy.instance, 3, 3);
|
||||
this(ContainerDummy.instance, 3, 3);
|
||||
}
|
||||
|
||||
private InventoryCraftingForestry(Container eventHandlerIn, int width, int height) {
|
||||
super(eventHandlerIn, width, height);
|
||||
this.eventHandlerIn = eventHandlerIn;
|
||||
}
|
||||
|
||||
public InventoryCraftingForestry copy() {
|
||||
InventoryCraftingForestry copy = new InventoryCraftingForestry(this.eventHandlerIn, getWidth(), getHeight());
|
||||
for (int slot = 0; slot < getSizeInventory(); slot++) {
|
||||
copy.setInventorySlotContents(slot, getStackInSlot(slot).copy());
|
||||
}
|
||||
return copy;
|
||||
}
|
||||
}
|
||||
@@ -53,7 +53,7 @@ public class PacketWorktableRecipeRequest extends ForestryPacket implements IFor
|
||||
@Override
|
||||
public void onPacketData(PacketBufferForestry data, EntityPlayerMP player) throws IOException {
|
||||
BlockPos pos = data.readBlockPos();
|
||||
MemorizedRecipe recipe = new MemorizedRecipe(data);
|
||||
MemorizedRecipe recipe = new MemorizedRecipe(data, player.world);
|
||||
|
||||
TileUtil.actOnTile(player.world, pos, TileWorktable.class, worktable -> {
|
||||
worktable.setCurrentRecipe(recipe);
|
||||
|
||||
@@ -55,7 +55,7 @@ public class PacketWorktableRecipeUpdate extends ForestryPacket implements IFore
|
||||
@Override
|
||||
public void onPacketData(PacketBufferForestry data, EntityPlayer player) throws IOException {
|
||||
BlockPos pos = data.readBlockPos();
|
||||
MemorizedRecipe recipe = data.readStreamable(MemorizedRecipe::new);
|
||||
MemorizedRecipe recipe = data.readStreamable(data1 -> new MemorizedRecipe(data1, player.world));
|
||||
|
||||
TileUtil.actOnTile(player.world, pos, TileWorktable.class, tile -> tile.setCurrentRecipe(recipe));
|
||||
}
|
||||
|
||||
@@ -11,14 +11,20 @@
|
||||
package forestry.factory.recipes;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import forestry.api.recipes.IFermenterRecipe;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import net.minecraftforge.fluids.Fluid;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
|
||||
import forestry.api.recipes.IFermenterRecipe;
|
||||
|
||||
public class FermenterRecipe implements IFermenterRecipe {
|
||||
|
||||
private final ItemStack resource;
|
||||
private final String resourceOreName;
|
||||
private final int fermentationValue;
|
||||
private final float modifier;
|
||||
private final Fluid output;
|
||||
@@ -31,17 +37,39 @@ public class FermenterRecipe implements IFermenterRecipe {
|
||||
Preconditions.checkNotNull(fluidResource, "Fermenter Liquid cannot be null!");
|
||||
|
||||
this.resource = resource;
|
||||
this.resourceOreName = null;
|
||||
this.fermentationValue = fermentationValue;
|
||||
this.modifier = modifier;
|
||||
this.output = output;
|
||||
this.fluidResource = fluidResource;
|
||||
}
|
||||
|
||||
public FermenterRecipe(String resourceOreName, int fermentationValue, float modifier, Fluid output, FluidStack fluidResource) {
|
||||
Preconditions.checkNotNull(resourceOreName, "Fermenter Resource cannot be null!");
|
||||
Preconditions.checkArgument(!resourceOreName.isEmpty(), "Fermenter Resource ore name cannot be empty!");
|
||||
Preconditions.checkNotNull(output, "Fermenter Output cannot be null!");
|
||||
Preconditions.checkNotNull(fluidResource, "Fermenter Liquid cannot be null!");
|
||||
|
||||
this.resource = ItemStack.EMPTY;
|
||||
this.resourceOreName = resourceOreName;
|
||||
this.fermentationValue = fermentationValue;
|
||||
this.modifier = modifier;
|
||||
this.output = output;
|
||||
this.fluidResource = fluidResource;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public ItemStack getResource() {
|
||||
return resource;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public String getResourceOreName() {
|
||||
return resourceOreName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FluidStack getFluidResource() {
|
||||
return fluidResource;
|
||||
@@ -61,4 +89,9 @@ public class FermenterRecipe implements IFermenterRecipe {
|
||||
public Fluid getOutput() {
|
||||
return output;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(IFermenterRecipe o) {
|
||||
return resource.isEmpty() ? 1 : 0;
|
||||
}
|
||||
}
|
||||
@@ -14,6 +14,7 @@ import javax.annotation.Nullable;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.TreeSet;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
@@ -27,7 +28,7 @@ import forestry.core.utils.ItemStackUtil;
|
||||
|
||||
public class FermenterRecipeManager implements IFermenterManager {
|
||||
|
||||
private static final Set<IFermenterRecipe> recipes = new HashSet<>();
|
||||
private static final Set<IFermenterRecipe> recipes = new TreeSet<>();
|
||||
public static final Set<Fluid> recipeFluidInputs = new HashSet<>();
|
||||
public static final Set<Fluid> recipeFluidOutputs = new HashSet<>();
|
||||
|
||||
@@ -42,6 +43,17 @@ public class FermenterRecipeManager implements IFermenterManager {
|
||||
addRecipe(resource, fermentationValue, modifier, output, new FluidStack(FluidRegistry.WATER, Fluid.BUCKET_VOLUME));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addRecipe(String resourceOreName, int fermentationValue, float modifier, FluidStack output, FluidStack liquid) {
|
||||
IFermenterRecipe recipe = new FermenterRecipe(resourceOreName, fermentationValue, modifier, output.getFluid(), liquid);
|
||||
addRecipe(recipe);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addRecipe(String resourceOreName, int fermentationValue, float modifier, FluidStack output) {
|
||||
addRecipe(resourceOreName, fermentationValue, modifier, output, new FluidStack(FluidRegistry.WATER, Fluid.BUCKET_VOLUME));
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static IFermenterRecipe findMatchingRecipe(ItemStack res, FluidStack liqu) {
|
||||
if(res.isEmpty()){
|
||||
@@ -57,7 +69,7 @@ public class FermenterRecipeManager implements IFermenterManager {
|
||||
|
||||
public static boolean matches(IFermenterRecipe recipe, ItemStack res, FluidStack liqu) {
|
||||
ItemStack resource = recipe.getResource();
|
||||
if (!ItemStackUtil.isCraftingEquivalent(resource, res)) {
|
||||
if (!ItemStackUtil.isCraftingEquivalent(resource, res, recipe.getResourceOreName(), false)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -71,7 +83,7 @@ public class FermenterRecipeManager implements IFermenterManager {
|
||||
}
|
||||
|
||||
for (IFermenterRecipe recipe : recipes) {
|
||||
if (ItemStackUtil.isCraftingEquivalent(recipe.getResource(), resource)) {
|
||||
if (ItemStackUtil.isCraftingEquivalent(recipe.getResource(), resource, recipe.getResourceOreName(), false)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,7 +10,20 @@
|
||||
******************************************************************************/
|
||||
package forestry.factory.recipes;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.inventory.InventoryCrafting;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.crafting.IRecipe;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.NonNullList;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
import forestry.api.core.INbtReadable;
|
||||
import forestry.api.core.INbtWritable;
|
||||
@@ -18,112 +31,133 @@ import forestry.core.network.IStreamable;
|
||||
import forestry.core.network.PacketBufferForestry;
|
||||
import forestry.core.recipes.RecipeUtil;
|
||||
import forestry.core.utils.InventoryUtil;
|
||||
import forestry.core.utils.ItemStackUtil;
|
||||
import forestry.factory.inventory.InventoryCraftingForestry;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.NonNullList;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public final class MemorizedRecipe implements INbtWritable, INbtReadable, IStreamable {
|
||||
private final InventoryCraftingForestry craftMatrix = new InventoryCraftingForestry();
|
||||
private NonNullList<ItemStack> recipeOutputs = NonNullList.create();
|
||||
private InventoryCraftingForestry craftMatrix = new InventoryCraftingForestry();
|
||||
private List<IRecipe> recipes = NonNullList.create();
|
||||
private int selectedRecipe;
|
||||
private long lastUsed;
|
||||
private boolean locked;
|
||||
|
||||
public MemorizedRecipe(PacketBufferForestry data) throws IOException {
|
||||
readData(data);
|
||||
|
||||
public MemorizedRecipe(PacketBufferForestry data, World world) throws IOException {
|
||||
readData(data, world);
|
||||
}
|
||||
|
||||
|
||||
public MemorizedRecipe(NBTTagCompound nbt) {
|
||||
readFromNBT(nbt);
|
||||
}
|
||||
|
||||
public MemorizedRecipe(InventoryCraftingForestry craftMatrix, NonNullList<ItemStack> recipeOutputs) {
|
||||
|
||||
public MemorizedRecipe(InventoryCraftingForestry craftMatrix, List<IRecipe> recipes) {
|
||||
InventoryUtil.deepCopyInventoryContents(craftMatrix, this.craftMatrix);
|
||||
this.recipeOutputs = recipeOutputs;
|
||||
this.recipes = recipes;
|
||||
}
|
||||
|
||||
|
||||
public InventoryCraftingForestry getCraftMatrix() {
|
||||
return craftMatrix;
|
||||
}
|
||||
|
||||
public void calculateRecipeOutput(World world) {
|
||||
recipeOutputs = RecipeUtil.findMatchingRecipes(craftMatrix, world);
|
||||
if (selectedRecipe >= recipeOutputs.size()) {
|
||||
|
||||
public void setCraftMatrix(InventoryCraftingForestry craftMatrix) {
|
||||
this.craftMatrix = craftMatrix;
|
||||
}
|
||||
|
||||
public void validate(World world) {
|
||||
recipes = RecipeUtil.findMatchingRecipes(craftMatrix, world);
|
||||
if (selectedRecipe > recipes.size()) {
|
||||
selectedRecipe = 0;
|
||||
}
|
||||
if (hasRecipeConflict()) {
|
||||
removeRecipeConflicts();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void incrementRecipe() {
|
||||
selectedRecipe++;
|
||||
if (selectedRecipe >= recipeOutputs.size()) {
|
||||
if (selectedRecipe >= recipes.size()) {
|
||||
selectedRecipe = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void decrementRecipe() {
|
||||
selectedRecipe--;
|
||||
if (selectedRecipe < 0) {
|
||||
selectedRecipe = recipeOutputs.size() - 1;
|
||||
selectedRecipe = recipes.size() - 1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public boolean hasRecipeConflict() {
|
||||
return recipeOutputs.size() > 1;
|
||||
return recipes.size() > 1;
|
||||
}
|
||||
|
||||
|
||||
public void removeRecipeConflicts() {
|
||||
ItemStack recipeOutput = getRecipeOutput();
|
||||
recipeOutputs.clear();
|
||||
recipeOutputs.add(recipeOutput);
|
||||
IRecipe recipe = getSelectedRecipe();
|
||||
recipes.clear();
|
||||
recipes.add(recipe);
|
||||
selectedRecipe = 0;
|
||||
}
|
||||
|
||||
public ItemStack getRecipeOutput() {
|
||||
if (recipeOutputs.isEmpty()) {
|
||||
return ItemStack.EMPTY;
|
||||
|
||||
public ItemStack getOutputIcon() {
|
||||
IRecipe selectedRecipe = getSelectedRecipe();
|
||||
if (selectedRecipe != null) {
|
||||
ItemStack recipeOutput = selectedRecipe.getCraftingResult(craftMatrix);
|
||||
if (!recipeOutput.isEmpty()) {
|
||||
return recipeOutput;
|
||||
}
|
||||
}
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
|
||||
public ItemStack getCraftingResult(InventoryCrafting inventoryCrafting, World world) {
|
||||
IRecipe selectedRecipe = getSelectedRecipe();
|
||||
if (selectedRecipe != null && selectedRecipe.matches(inventoryCrafting, world)) {
|
||||
ItemStack recipeOutput = selectedRecipe.getCraftingResult(inventoryCrafting);
|
||||
if (!recipeOutput.isEmpty()) {
|
||||
return recipeOutput;
|
||||
}
|
||||
}
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public IRecipe getSelectedRecipe() {
|
||||
if (recipes.isEmpty()) {
|
||||
return null;
|
||||
} else {
|
||||
return recipeOutputs.get(selectedRecipe);
|
||||
return recipes.get(selectedRecipe);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean hasRecipeOutput(ItemStack output) {
|
||||
return ItemStackUtil.containsItemStack(recipeOutputs, output);
|
||||
|
||||
public boolean hasRecipe(@Nullable IRecipe recipe) {
|
||||
return this.recipes.contains(recipe);
|
||||
}
|
||||
|
||||
|
||||
public void updateLastUse(long lastUsed) {
|
||||
this.lastUsed = lastUsed;
|
||||
}
|
||||
|
||||
|
||||
public long getLastUsed() {
|
||||
return lastUsed;
|
||||
}
|
||||
|
||||
|
||||
public void toggleLock() {
|
||||
locked = !locked;
|
||||
}
|
||||
|
||||
|
||||
public boolean isLocked() {
|
||||
return locked;
|
||||
}
|
||||
|
||||
|
||||
/* INbtWritable */
|
||||
@Override
|
||||
public final void readFromNBT(NBTTagCompound nbttagcompound) {
|
||||
InventoryUtil.readFromNBT(craftMatrix, nbttagcompound);
|
||||
lastUsed = nbttagcompound.getLong("LastUsed");
|
||||
locked = nbttagcompound.getBoolean("Locked");
|
||||
|
||||
|
||||
if (nbttagcompound.hasKey("SelectedRecipe")) {
|
||||
selectedRecipe = nbttagcompound.getInteger("SelectedRecipe");
|
||||
}
|
||||
|
||||
recipes.clear();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public NBTTagCompound writeToNBT(NBTTagCompound nbttagcompound) {
|
||||
InventoryUtil.writeToNBT(craftMatrix, nbttagcompound);
|
||||
@@ -138,15 +172,21 @@ public final class MemorizedRecipe implements INbtWritable, INbtReadable, IStrea
|
||||
public void writeData(PacketBufferForestry data) {
|
||||
data.writeInventory(craftMatrix);
|
||||
data.writeBoolean(locked);
|
||||
data.writeItemStacks(recipeOutputs);
|
||||
data.writeVarInt(selectedRecipe);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void readData(PacketBufferForestry data) throws IOException {
|
||||
readData(data, Minecraft.getMinecraft().world);
|
||||
}
|
||||
|
||||
public void readData(PacketBufferForestry data, World world) throws IOException {
|
||||
data.readInventory(craftMatrix);
|
||||
locked = data.readBoolean();
|
||||
recipeOutputs = data.readItemStacks();
|
||||
selectedRecipe = data.readVarInt();
|
||||
|
||||
recipes.clear();
|
||||
validate(world);
|
||||
}
|
||||
}
|
||||
@@ -17,26 +17,32 @@ import java.util.Iterator;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import forestry.api.core.INbtWritable;
|
||||
import forestry.core.network.IStreamable;
|
||||
import forestry.core.network.PacketBufferForestry;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemMap;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.crafting.IRecipe;
|
||||
import net.minecraft.item.crafting.RecipesMapCloning;
|
||||
import net.minecraft.item.crafting.RecipesMapExtending;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
import forestry.api.core.INbtWritable;
|
||||
import forestry.core.network.IStreamable;
|
||||
import forestry.core.network.PacketBufferForestry;
|
||||
|
||||
public class RecipeMemory implements INbtWritable, IStreamable {
|
||||
|
||||
private static final int capacity = 9;
|
||||
|
||||
private static final List<Class<? extends Item>> memoryBlacklist = new ArrayList<>();
|
||||
|
||||
private static final List<Class<? extends IRecipe>> memoryBlacklist = new ArrayList<>();
|
||||
|
||||
static {
|
||||
memoryBlacklist.add(ItemMap.class); // almost every ItemMap is unique
|
||||
// almost every ItemMap is unique
|
||||
memoryBlacklist.add(RecipesMapCloning.class);
|
||||
memoryBlacklist.add(RecipesMapExtending.class);
|
||||
}
|
||||
|
||||
private final LinkedList<MemorizedRecipe> memorizedRecipes;
|
||||
@@ -64,12 +70,8 @@ public class RecipeMemory implements INbtWritable, IStreamable {
|
||||
if (recipe == null) {
|
||||
return false;
|
||||
}
|
||||
ItemStack recipeOutput = recipe.getRecipeOutput();
|
||||
if (recipeOutput.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
Item item = recipeOutput.getItem();
|
||||
return !memoryBlacklist.contains(item.getClass());
|
||||
IRecipe recipeOutput = recipe.getSelectedRecipe();
|
||||
return recipeOutput != null && !memoryBlacklist.contains(recipeOutput.getClass());
|
||||
}
|
||||
|
||||
public void validate(World world) {
|
||||
@@ -77,7 +79,7 @@ public class RecipeMemory implements INbtWritable, IStreamable {
|
||||
while (iterator.hasNext()) {
|
||||
MemorizedRecipe recipe = iterator.next();
|
||||
if (recipe != null) {
|
||||
recipe.calculateRecipeOutput(world);
|
||||
recipe.validate(world);
|
||||
if (!isValid(recipe)) {
|
||||
iterator.remove();
|
||||
}
|
||||
@@ -88,26 +90,26 @@ public class RecipeMemory implements INbtWritable, IStreamable {
|
||||
public long getLastUpdate() {
|
||||
return lastUpdate;
|
||||
}
|
||||
|
||||
|
||||
public void memorizeRecipe(long worldTime, MemorizedRecipe recipe) {
|
||||
if (!isValid(recipe)) {
|
||||
if (recipe.getSelectedRecipe() == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
lastUpdate = worldTime;
|
||||
recipe.updateLastUse(lastUpdate);
|
||||
|
||||
|
||||
if (recipe.hasRecipeConflict()) {
|
||||
recipe.removeRecipeConflicts();
|
||||
}
|
||||
|
||||
|
||||
// update existing matching recipes
|
||||
MemorizedRecipe memory = getExistingMemorizedRecipe(recipe.getRecipeOutput());
|
||||
MemorizedRecipe memory = getExistingMemorizedRecipe(recipe.getSelectedRecipe());
|
||||
if (memory != null) {
|
||||
updateExistingRecipe(memory, recipe);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
// add a new recipe
|
||||
if (memorizedRecipes.size() < capacity) {
|
||||
memorizedRecipes.add(recipe);
|
||||
@@ -150,13 +152,13 @@ public class RecipeMemory implements INbtWritable, IStreamable {
|
||||
}
|
||||
return memorizedRecipes.get(recipeIndex);
|
||||
}
|
||||
|
||||
|
||||
public ItemStack getRecipeDisplayOutput(int recipeIndex) {
|
||||
MemorizedRecipe recipe = getRecipe(recipeIndex);
|
||||
if (recipe == null) {
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
return recipe.getRecipeOutput();
|
||||
return recipe.getOutputIcon();
|
||||
}
|
||||
|
||||
public boolean isLocked(int recipeIndex) {
|
||||
@@ -170,15 +172,17 @@ public class RecipeMemory implements INbtWritable, IStreamable {
|
||||
memorizedRecipes.get(recipeIndex).toggleLock();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Nullable
|
||||
private MemorizedRecipe getExistingMemorizedRecipe(ItemStack craftingRecipeOutput) {
|
||||
for (MemorizedRecipe memorizedRecipe : memorizedRecipes) {
|
||||
if (memorizedRecipe.hasRecipeOutput(craftingRecipeOutput)) {
|
||||
return memorizedRecipe;
|
||||
private MemorizedRecipe getExistingMemorizedRecipe(@Nullable IRecipe recipe) {
|
||||
if (recipe != null) {
|
||||
for (MemorizedRecipe memorizedRecipe : memorizedRecipes) {
|
||||
if (memorizedRecipe.hasRecipe(recipe)) {
|
||||
return memorizedRecipe;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -204,6 +208,6 @@ public class RecipeMemory implements INbtWritable, IStreamable {
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void readData(PacketBufferForestry data) throws IOException {
|
||||
data.readStreamables(memorizedRecipes, MemorizedRecipe::new);
|
||||
data.readStreamables(memorizedRecipes, data1 -> new MemorizedRecipe(data1, Minecraft.getMinecraft().world));
|
||||
}
|
||||
}
|
||||
@@ -4,6 +4,7 @@ import javax.annotation.Nullable;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import forestry.core.recipes.RecipeUtil;
|
||||
import forestry.factory.gui.ContainerWorktable;
|
||||
import forestry.factory.inventory.InventoryCraftingForestry;
|
||||
import forestry.factory.recipes.MemorizedRecipe;
|
||||
@@ -13,6 +14,7 @@ import mezz.jei.api.recipe.transfer.IRecipeTransferError;
|
||||
import mezz.jei.api.recipe.transfer.IRecipeTransferHandler;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.crafting.IRecipe;
|
||||
import net.minecraft.util.NonNullList;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
@@ -27,27 +29,30 @@ class WorktableRecipeTransferHandler implements IRecipeTransferHandler<Container
|
||||
@Nullable
|
||||
@Override
|
||||
public IRecipeTransferError transferRecipe(ContainerWorktable container, IRecipeLayout recipeLayout, EntityPlayer player, boolean maxTransfer, boolean doTransfer) {
|
||||
Map<Integer, ? extends IGuiIngredient<ItemStack>> guiIngredients = recipeLayout.getItemStacks().getGuiIngredients();
|
||||
if (doTransfer) {
|
||||
Map<Integer, ? extends IGuiIngredient<ItemStack>> guiIngredients = recipeLayout.getItemStacks().getGuiIngredients();
|
||||
|
||||
InventoryCraftingForestry inventory = new InventoryCraftingForestry(container);
|
||||
InventoryCraftingForestry inventory = new InventoryCraftingForestry(container);
|
||||
|
||||
NonNullList<ItemStack> recipeOutputs = NonNullList.create();
|
||||
for (Map.Entry<Integer, ? extends IGuiIngredient<ItemStack>> entry : guiIngredients.entrySet()) {
|
||||
int recipeSlot = entry.getKey();
|
||||
List<ItemStack> allIngredients = entry.getValue().getAllIngredients();
|
||||
if (!allIngredients.isEmpty()) {
|
||||
if (recipeSlot == 0) {
|
||||
recipeOutputs.addAll(allIngredients);
|
||||
} else {
|
||||
ItemStack firstIngredient = allIngredients.get(0);
|
||||
inventory.setInventorySlotContents(recipeSlot - 1, firstIngredient);
|
||||
NonNullList<ItemStack> recipeOutputs = NonNullList.create();
|
||||
for (Map.Entry<Integer, ? extends IGuiIngredient<ItemStack>> entry : guiIngredients.entrySet()) {
|
||||
int recipeSlot = entry.getKey();
|
||||
List<ItemStack> allIngredients = entry.getValue().getAllIngredients();
|
||||
if (!allIngredients.isEmpty()) {
|
||||
if (recipeSlot == 0) {
|
||||
recipeOutputs.addAll(allIngredients);
|
||||
} else {
|
||||
ItemStack firstIngredient = allIngredients.get(0);
|
||||
inventory.setInventorySlotContents(recipeSlot - 1, firstIngredient);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!recipeOutputs.isEmpty() && doTransfer) {
|
||||
MemorizedRecipe recipe = new MemorizedRecipe(inventory, recipeOutputs);
|
||||
container.sendWorktableRecipeRequest(recipe);
|
||||
|
||||
List<IRecipe> matchingRecipes = RecipeUtil.findMatchingRecipes(inventory, player.world);
|
||||
if (!matchingRecipes.isEmpty()) {
|
||||
MemorizedRecipe recipe = new MemorizedRecipe(inventory, matchingRecipes);
|
||||
container.sendWorktableRecipeRequest(recipe);
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
|
||||
@@ -3,12 +3,17 @@ package forestry.factory.recipes.jei.fermenter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.NonNullList;
|
||||
|
||||
import net.minecraftforge.oredict.OreDictionary;
|
||||
|
||||
import forestry.api.recipes.IFermenterRecipe;
|
||||
import forestry.api.recipes.IVariableFermentable;
|
||||
import forestry.api.recipes.RecipeManagers;
|
||||
import forestry.core.utils.Log;
|
||||
|
||||
import mezz.jei.api.recipe.IStackHelper;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
public class FermenterRecipeMaker {
|
||||
|
||||
@@ -19,12 +24,13 @@ public class FermenterRecipeMaker {
|
||||
List<FermenterRecipeWrapper> recipes = new ArrayList<>();
|
||||
for (IFermenterRecipe recipe : RecipeManagers.fermenterManager.recipes()) {
|
||||
if (!recipe.getResource().isEmpty()) {
|
||||
if (recipe.getResource().getItem() instanceof IVariableFermentable) {
|
||||
for (ItemStack stack : stackHelper.getSubtypes(recipe.getResource())) {
|
||||
recipes.add(new FermenterRecipeWrapper(recipe, stack));
|
||||
addWrapperToList(stackHelper, recipe, recipe.getResource(), recipes);
|
||||
}else if(recipe.getResourceOreName() != null){
|
||||
NonNullList<ItemStack> itemStacks = OreDictionary.getOres(recipe.getResourceOreName());
|
||||
if(!itemStacks.isEmpty()){
|
||||
for(ItemStack resource : itemStacks){
|
||||
addWrapperToList(stackHelper, recipe, resource, recipes);
|
||||
}
|
||||
} else {
|
||||
recipes.add(new FermenterRecipeWrapper(recipe, recipe.getResource()));
|
||||
}
|
||||
} else {
|
||||
Log.error("Empty resource for recipe");
|
||||
@@ -33,4 +39,14 @@ public class FermenterRecipeMaker {
|
||||
return recipes;
|
||||
}
|
||||
|
||||
private static void addWrapperToList(IStackHelper stackHelper, IFermenterRecipe recipe, ItemStack resource, List<FermenterRecipeWrapper> recipes){
|
||||
if (resource.getItem() instanceof IVariableFermentable) {
|
||||
for (ItemStack stack : stackHelper.getSubtypes(resource)) {
|
||||
recipes.add(new FermenterRecipeWrapper(recipe, stack));
|
||||
}
|
||||
} else {
|
||||
recipes.add(new FermenterRecipeWrapper(recipe, resource));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,10 +1,12 @@
|
||||
package forestry.factory.tiles;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.InventoryCrafting;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public interface ICrafterWorktable {
|
||||
ItemStack getResult();
|
||||
ItemStack getResult(InventoryCrafting inventoryCrafting, World world);
|
||||
|
||||
boolean canTakeStack(int slotIndex);
|
||||
|
||||
|
||||
@@ -12,6 +12,7 @@ package forestry.factory.tiles;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import forestry.core.inventory.InventoryAdapterTile;
|
||||
@@ -33,10 +34,13 @@ import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.Container;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.inventory.InventoryBasic;
|
||||
import net.minecraft.inventory.InventoryCrafting;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.crafting.CraftingManager;
|
||||
import net.minecraft.item.crafting.IRecipe;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.NonNullList;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import net.minecraftforge.common.ForgeHooks;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
@@ -134,15 +138,18 @@ public class TileWorktable extends TileBase implements ICrafterWorktable {
|
||||
if (currentRecipe == null) {
|
||||
return false;
|
||||
}
|
||||
IRecipe selectedRecipe = currentRecipe.getSelectedRecipe();
|
||||
if (selectedRecipe == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
NonNullList<ItemStack> recipeItems = InventoryUtil.getStacks(currentRecipe.getCraftMatrix());
|
||||
NonNullList<ItemStack> inventoryStacks = InventoryUtil.getStacks(this);
|
||||
InventoryCraftingForestry crafting = RecipeUtil.getCraftRecipe(recipeItems, inventoryStacks, world, currentRecipe.getRecipeOutput());
|
||||
InventoryCraftingForestry crafting = RecipeUtil.getCraftRecipe(currentRecipe.getCraftMatrix(), inventoryStacks, world, selectedRecipe);
|
||||
if (crafting == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
recipeItems = InventoryUtil.getStacks(crafting);
|
||||
NonNullList<ItemStack> recipeItems = InventoryUtil.getStacks(crafting);
|
||||
|
||||
IInventory inventory;
|
||||
if (simulate) {
|
||||
@@ -152,15 +159,16 @@ public class TileWorktable extends TileBase implements ICrafterWorktable {
|
||||
inventory = this;
|
||||
}
|
||||
|
||||
// craft recipe should exactly match ingredients here, so no oreDict or tool matching
|
||||
NonNullList<ItemStack> removed = InventoryUtil.removeSets(inventory, 1, recipeItems, null, false, false, false);
|
||||
if (removed == null) {
|
||||
if (!InventoryUtil.deleteExactSet(inventory, recipeItems))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!simulate) {
|
||||
if (!simulate)
|
||||
{
|
||||
// update crafting display to match the ingredients that were actually used
|
||||
setCraftingDisplay(crafting);
|
||||
currentRecipe.setCraftMatrix(crafting);
|
||||
setCurrentRecipe(currentRecipe);
|
||||
}
|
||||
|
||||
return true;
|
||||
@@ -169,13 +177,17 @@ public class TileWorktable extends TileBase implements ICrafterWorktable {
|
||||
@Override
|
||||
public void onCraftingComplete(EntityPlayer player) {
|
||||
Preconditions.checkState(currentRecipe != null);
|
||||
|
||||
IRecipe selectedRecipe = currentRecipe.getSelectedRecipe();
|
||||
Preconditions.checkState(selectedRecipe != null);
|
||||
|
||||
ForgeHooks.setCraftingPlayer(player);
|
||||
NonNullList<ItemStack> remainingItems = CraftingManager.getInstance().getRemainingItems(currentRecipe.getCraftMatrix(), player.world);
|
||||
InventoryCraftingForestry craftMatrix = currentRecipe.getCraftMatrix();
|
||||
NonNullList<ItemStack> remainingItems = selectedRecipe.getRemainingItems(craftMatrix.copy());
|
||||
ForgeHooks.setCraftingPlayer(null);
|
||||
|
||||
for (ItemStack remainingItem : remainingItems) {
|
||||
if (remainingItem != null) {
|
||||
if (remainingItem != null && !remainingItem.isEmpty())
|
||||
{
|
||||
if (!InventoryUtil.tryAddStack(this, remainingItem, true)) {
|
||||
player.dropItem(remainingItem, false);
|
||||
}
|
||||
@@ -186,18 +198,13 @@ public class TileWorktable extends TileBase implements ICrafterWorktable {
|
||||
recipeMemory.memorizeRecipe(world.getTotalWorldTime(), currentRecipe);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public ItemStack getResult() {
|
||||
if (currentRecipe == null) {
|
||||
return ItemStack.EMPTY;
|
||||
public ItemStack getResult(InventoryCrafting inventoryCrafting, World world) {
|
||||
if (currentRecipe != null) {
|
||||
return currentRecipe.getCraftingResult(inventoryCrafting, world);
|
||||
}
|
||||
|
||||
ItemStack result = currentRecipe.getRecipeOutput();
|
||||
if (!result.isEmpty()) {
|
||||
result = result.copy();
|
||||
}
|
||||
return result;
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
|
||||
/* Crafting Container methods */
|
||||
@@ -225,13 +232,13 @@ public class TileWorktable extends TileBase implements ICrafterWorktable {
|
||||
craftingDisplay.setInventorySlotContents(slot, ItemStack.EMPTY);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void setCurrentRecipe(InventoryCraftingForestry crafting) {
|
||||
NonNullList<ItemStack> recipeOutputs = RecipeUtil.findMatchingRecipes(crafting, world);
|
||||
MemorizedRecipe recipe = recipeOutputs.isEmpty() ? null : new MemorizedRecipe(crafting, recipeOutputs);
|
||||
|
||||
List<IRecipe> recipes = RecipeUtil.findMatchingRecipes(crafting, world);
|
||||
MemorizedRecipe recipe = recipes.isEmpty() ? null : new MemorizedRecipe(crafting, recipes);
|
||||
|
||||
if (currentRecipe != null && recipe != null) {
|
||||
if (recipe.hasRecipeOutput(currentRecipe.getRecipeOutput())) {
|
||||
if (recipe.hasRecipe(currentRecipe.getSelectedRecipe())) {
|
||||
NonNullList<ItemStack> stacks = InventoryUtil.getStacks(crafting);
|
||||
NonNullList<ItemStack> currentStacks = InventoryUtil.getStacks(currentRecipe.getCraftMatrix());
|
||||
if (ItemStackUtil.equalSets(stacks, currentStacks)) {
|
||||
@@ -239,7 +246,7 @@ public class TileWorktable extends TileBase implements ICrafterWorktable {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
setCurrentRecipe(recipe);
|
||||
}
|
||||
|
||||
|
||||
@@ -87,7 +87,11 @@ public final class FarmRegistry implements IFarmRegistry {
|
||||
try {
|
||||
String fertilizer = fertilizerList[i];
|
||||
String[] fertilizers = fertilizer.split(";");
|
||||
ItemStack fertilizerItem = ItemStackUtil.parseItemStackString(fertilizers[0], OreDictionary.WILDCARD_VALUE);
|
||||
String itemName = fertilizers[0];
|
||||
if(itemName.equals("forestry:fertilizerCompound")){
|
||||
itemName = "forestry:fertilizer_compound";
|
||||
}
|
||||
ItemStack fertilizerItem = ItemStackUtil.parseItemStackString(itemName, OreDictionary.WILDCARD_VALUE);
|
||||
int fertilizerValue = Integer.parseInt(fertilizers[1]);
|
||||
registerFertilizer(fertilizerItem, fertilizerValue);
|
||||
} catch (Exception e) {
|
||||
|
||||
Reference in new issue
Block a user