mirror of
https://github.com/GTNewHorizons/ForestryMC.git
synced 2026-11-27 23:33:00 +00:00
Fix carpenter and thermionic fabricator recipes
This commit is contained in:
1 parent
6a00a65aac
commit
3d932700cd
12 files changed
+169
-8
No files matched your search
@@ -30,6 +30,8 @@ public interface IDescriptiveRecipe {
|
||||
* Each inner list represents one slot's accepted ItemStacks
|
||||
*/
|
||||
NonNullList<NonNullList<ItemStack>> getIngredients();
|
||||
|
||||
NonNullList<String> getOreDicts();
|
||||
|
||||
ItemStack getRecipeOutput();
|
||||
}
|
||||
@@ -21,6 +21,8 @@ public interface IFabricatorRecipe extends IForestryRecipe {
|
||||
* Each inner list represents one slot's accepted ItemStacks
|
||||
*/
|
||||
NonNullList<NonNullList<ItemStack>> getIngredients();
|
||||
|
||||
NonNullList<String> getOreDicts();
|
||||
|
||||
/**
|
||||
* @return the width of ingredients in the crafting grid to create this recipe.
|
||||
|
||||
@@ -455,7 +455,7 @@ public class PluginArboriculture extends BlankForestryPlugin {
|
||||
RecipeUtil.addShapelessRecipe(new ItemStack(blocks.woodPile), OreDictUtil.LOG_WOOD, OreDictUtil.LOG_WOOD, OreDictUtil.LOG_WOOD, OreDictUtil.LOG_WOOD);
|
||||
|
||||
//Dirt Pile Block
|
||||
RecipeUtil.addShapelessRecipe(new ItemStack(blocks.loam), Items.CLAY_BALL, coreItems.fertilizerBio, Items.CLAY_BALL, OreDictUtil.SAND, Items.CLAY_BALL, OreDictUtil.SAND, Items.CLAY_BALL, coreItems.fertilizerBio, Items.CLAY_BALL);
|
||||
RecipeUtil.addShapelessRecipe(new ItemStack(blocks.loam, 4), Items.CLAY_BALL, coreItems.fertilizerBio, Items.CLAY_BALL, OreDictUtil.SAND, Items.CLAY_BALL, OreDictUtil.SAND, Items.CLAY_BALL, coreItems.fertilizerBio, Items.CLAY_BALL);
|
||||
}
|
||||
|
||||
private static void registerAlleles() {
|
||||
|
||||
@@ -7,8 +7,8 @@ import forestry.api.arboriculture.TreeManager;
|
||||
import forestry.api.core.IItemModelRegister;
|
||||
import forestry.api.core.IModelManager;
|
||||
import forestry.api.core.IStateMapperRegister;
|
||||
import forestry.api.core.Tabs;
|
||||
import forestry.arboriculture.PluginArboriculture;
|
||||
import forestry.core.CreativeTabForestry;
|
||||
import forestry.core.proxy.Proxies;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.SoundType;
|
||||
@@ -40,7 +40,7 @@ public class BlockWoodPile extends Block implements IItemModelRegister, IStateMa
|
||||
super(Material.WOOD);
|
||||
setHardness(1.5f);
|
||||
setTickRandomly(true);
|
||||
setCreativeTab(CreativeTabForestry.tabForestry);
|
||||
setCreativeTab(Tabs.tabArboriculture);
|
||||
setSoundType(SoundType.WOOD);
|
||||
}
|
||||
|
||||
|
||||
@@ -266,6 +266,9 @@ public abstract class RecipeUtil {
|
||||
return resource.isEmpty();
|
||||
}
|
||||
for (ItemStack item : recipeIngredient) {
|
||||
if(item.isEmpty() && resource.isEmpty()){
|
||||
return true;
|
||||
}
|
||||
if (ItemStackUtil.isCraftingEquivalent(item, resource)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -30,6 +30,7 @@ public class ShapedRecipeCustom extends ShapedOreRecipe implements IDescriptiveR
|
||||
private static final int MAX_CRAFT_GRID_HEIGHT = 3;
|
||||
|
||||
private NonNullList<NonNullList<ItemStack>> input;
|
||||
private NonNullList<String> oreDicts;
|
||||
private int width;
|
||||
private int height;
|
||||
private boolean mirrored = true;
|
||||
@@ -78,6 +79,7 @@ public class ShapedRecipeCustom extends ShapedOreRecipe implements IDescriptiveR
|
||||
}
|
||||
|
||||
HashMap<Character, NonNullList<ItemStack>> itemMap = new HashMap<>();
|
||||
HashMap<Character, String> oreMap = new HashMap<>();
|
||||
|
||||
for (; idx < recipe.length; idx += 2) {
|
||||
Character chr = (Character) recipe[idx];
|
||||
@@ -100,6 +102,7 @@ public class ShapedRecipeCustom extends ShapedOreRecipe implements IDescriptiveR
|
||||
itemMap.put(chr, ingredient);
|
||||
} else if (in instanceof String) {
|
||||
itemMap.put(chr, OreDictionary.getOres((String) in));
|
||||
oreMap.put(chr, (String) in);
|
||||
} else {
|
||||
String ret = "Invalid shaped ore recipe: ";
|
||||
for (Object tmp : recipe) {
|
||||
@@ -111,11 +114,17 @@ public class ShapedRecipeCustom extends ShapedOreRecipe implements IDescriptiveR
|
||||
}
|
||||
|
||||
input = NonNullList.withSize(9, NonNullList.create());
|
||||
oreDicts = NonNullList.withSize(9, "");
|
||||
int x = 0;
|
||||
for (char chr : shape.toCharArray()) {
|
||||
NonNullList<ItemStack> stacks = itemMap.get(chr);
|
||||
if (stacks != null) {
|
||||
input.set(x++, stacks);
|
||||
if(oreMap.get(chr) != null){
|
||||
oreDicts.set(x-1, oreMap.get(chr));
|
||||
}
|
||||
}else{
|
||||
input.set(x++, NonNullList.withSize(1, ItemStack.EMPTY));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -134,6 +143,11 @@ public class ShapedRecipeCustom extends ShapedOreRecipe implements IDescriptiveR
|
||||
public NonNullList<NonNullList<ItemStack>> getIngredients() {
|
||||
return input;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NonNullList<String> getOreDicts() {
|
||||
return oreDicts;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matches(InventoryCrafting inv, World world) {
|
||||
|
||||
@@ -207,6 +207,17 @@ public abstract class InventoryUtil {
|
||||
return ItemStackUtil.containsSets(set, stock, oreDictionary, craftingTools) >= count;
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean removeSets(IInventory inventory, int count, NonNullList<ItemStack> set, NonNullList<String> oreDicts, @Nullable EntityPlayer player, boolean stowContainer, boolean craftingTools, boolean doRemove) {
|
||||
NonNullList<ItemStack> stock = getStacks(inventory);
|
||||
|
||||
if (doRemove) {
|
||||
NonNullList<ItemStack> removed = removeSets(inventory, count, set, oreDicts, player, stowContainer, craftingTools);
|
||||
return removed != null && removed.size() >= count;
|
||||
} else {
|
||||
return ItemStackUtil.containsSets(set, stock, oreDicts, craftingTools) >= count;
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static NonNullList<ItemStack> removeSets(IInventory inventory, int count, NonNullList<ItemStack> set, @Nullable EntityPlayer player, boolean stowContainer, boolean oreDictionary, boolean craftingTools) {
|
||||
@@ -235,6 +246,34 @@ public abstract class InventoryUtil {
|
||||
}
|
||||
return removed;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static NonNullList<ItemStack> removeSets(IInventory inventory, int count, NonNullList<ItemStack> set, NonNullList<String> oreDicts, @Nullable EntityPlayer player, boolean stowContainer, boolean craftingTools) {
|
||||
NonNullList<ItemStack> removed = NonNullList.withSize(set.size(), ItemStack.EMPTY);
|
||||
NonNullList<ItemStack> stock = getStacks(inventory);
|
||||
|
||||
if (ItemStackUtil.containsSets(set, stock, oreDicts, craftingTools) < count) {
|
||||
return null;
|
||||
}
|
||||
|
||||
for (int i = 0; i < set.size(); i++) {
|
||||
ItemStack itemStack = set.get(i);
|
||||
if (!itemStack.isEmpty()) {
|
||||
ItemStack stackToRemove = itemStack.copy();
|
||||
stackToRemove.setCount(stackToRemove.getCount() * count);
|
||||
|
||||
// try to remove the exact stack first
|
||||
ItemStack removedStack = removeStack(inventory, stackToRemove, player, stowContainer, false, false);
|
||||
if (removedStack.isEmpty()) {
|
||||
// remove crafting equivalents next
|
||||
removedStack = removeStack(inventory, stackToRemove, oreDicts.get(i), player, stowContainer, craftingTools);
|
||||
}
|
||||
|
||||
removed.set(i, removedStack);
|
||||
}
|
||||
}
|
||||
return removed;
|
||||
}
|
||||
|
||||
/**
|
||||
* Private Helper for removeSetsFromInventory. Assumes removal is possible.
|
||||
@@ -259,6 +298,27 @@ public abstract class InventoryUtil {
|
||||
}
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
|
||||
private static ItemStack removeStack(IInventory inventory, ItemStack stackToRemove, String oreDictOfStack, @Nullable EntityPlayer player, boolean stowContainer, boolean craftingTools) {
|
||||
for (int j = 0; j < inventory.getSizeInventory(); j++) {
|
||||
ItemStack stackInSlot = inventory.getStackInSlot(j);
|
||||
if (!stackInSlot.isEmpty()) {
|
||||
if (ItemStackUtil.isCraftingEquivalent(stackToRemove, stackInSlot, oreDictOfStack, craftingTools)) {
|
||||
ItemStack removed = inventory.decrStackSize(j, stackToRemove.getCount());
|
||||
stackToRemove.shrink(removed.getCount());
|
||||
|
||||
if (stowContainer && stackToRemove.getItem().hasContainerItem(stackToRemove)) {
|
||||
stowContainerItem(removed, inventory, j, player);
|
||||
}
|
||||
|
||||
if (stackToRemove.isEmpty()) {
|
||||
return removed;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
|
||||
/* CONTAINS */
|
||||
|
||||
|
||||
@@ -254,6 +254,38 @@ public abstract class ItemStackUtil {
|
||||
|
||||
return totalSets;
|
||||
}
|
||||
|
||||
/**
|
||||
* Counts how many full sets are contained in the passed stock
|
||||
*/
|
||||
public static int containsSets(NonNullList<ItemStack> set, NonNullList<ItemStack> stock, NonNullList<String> oreDicts, boolean craftingTools) {
|
||||
int totalSets = 0;
|
||||
|
||||
NonNullList<ItemStack> condensedRequired = ItemStackUtil.condenseStacks(set);
|
||||
NonNullList<ItemStack> condensedOffered = ItemStackUtil.condenseStacks(stock);
|
||||
|
||||
for (ItemStack req : condensedRequired) {
|
||||
|
||||
int reqCount = 0;
|
||||
for (int i = 0;i < condensedOffered.size();i++) {
|
||||
ItemStack offer = condensedOffered.get(i);
|
||||
if (isCraftingEquivalent(req, offer, oreDicts.get(i), craftingTools)) {
|
||||
int stackCount = (int) Math.floor(offer.getCount() / req.getCount());
|
||||
reqCount = Math.max(reqCount, stackCount);
|
||||
}
|
||||
}
|
||||
|
||||
if (reqCount == 0) {
|
||||
return 0;
|
||||
} else if (totalSets == 0) {
|
||||
totalSets = reqCount;
|
||||
} else if (totalSets > reqCount) {
|
||||
totalSets = reqCount;
|
||||
}
|
||||
}
|
||||
|
||||
return totalSets;
|
||||
}
|
||||
|
||||
public static boolean equalSets(NonNullList<ItemStack> set1, NonNullList<ItemStack> set2) {
|
||||
if (set1 == set2) {
|
||||
@@ -298,6 +330,46 @@ public abstract class ItemStackUtil {
|
||||
return ItemStack.areItemStackTagsEqual(base, comparison);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Compare two item stacks for crafting equivalency.
|
||||
*/
|
||||
public static boolean isCraftingEquivalent(ItemStack base, ItemStack comparison, String oreDict, boolean craftingTools) {
|
||||
if (base.isEmpty() || comparison.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (craftingTools && isCraftingToolEquivalent(base, comparison)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (isCraftingEquivalent(base, comparison)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (base.getTagCompound() != null && !base.getTagCompound().hasNoTags()) {
|
||||
if (!ItemStack.areItemStacksEqual(base, comparison)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (!oreDict.isEmpty()) {
|
||||
int[] idsBase = OreDictionary.getOreIDs(base);
|
||||
Arrays.sort(idsBase);
|
||||
int idComp = OreDictionary.getOreID(oreDict);
|
||||
|
||||
int iBase = 0;
|
||||
while (iBase < idsBase.length) {
|
||||
if (idsBase[iBase] == idComp) {
|
||||
iBase++;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Compare two item stacks for crafting equivalency.
|
||||
|
||||
@@ -20,18 +20,21 @@ public class FabricatorRecipe implements IFabricatorRecipe {
|
||||
private final ItemStack plan;
|
||||
private final FluidStack molten;
|
||||
private final NonNullList<NonNullList<ItemStack>> ingredients;
|
||||
private final NonNullList<String> oreDicts;
|
||||
private final ItemStack result;
|
||||
|
||||
public FabricatorRecipe(ItemStack plan, FluidStack molten, ItemStack result, NonNullList<NonNullList<ItemStack>> ingredients) {
|
||||
public FabricatorRecipe(ItemStack plan, FluidStack molten, ItemStack result, NonNullList<NonNullList<ItemStack>> ingredients, NonNullList<String> oreDicts) {
|
||||
Preconditions.checkNotNull(plan);
|
||||
Preconditions.checkNotNull(molten);
|
||||
Preconditions.checkNotNull(result);
|
||||
Preconditions.checkArgument(!result.isEmpty());
|
||||
Preconditions.checkNotNull(ingredients);
|
||||
Preconditions.checkNotNull(oreDicts);
|
||||
this.plan = plan;
|
||||
this.molten = molten;
|
||||
this.result = result;
|
||||
this.ingredients = ingredients;
|
||||
this.oreDicts = oreDicts;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -39,6 +42,11 @@ public class FabricatorRecipe implements IFabricatorRecipe {
|
||||
return ingredients;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NonNullList<String> getOreDicts() {
|
||||
return oreDicts;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getWidth() {
|
||||
return 3;
|
||||
|
||||
@@ -34,7 +34,7 @@ public class FabricatorRecipeManager implements IFabricatorManager {
|
||||
ShapedRecipeCustom patternRecipe = new ShapedRecipeCustom(result, pattern);
|
||||
NonNullList<NonNullList<ItemStack>> ingredients = patternRecipe.getIngredients();
|
||||
|
||||
IFabricatorRecipe recipe = new FabricatorRecipe(plan, molten, result, ingredients);
|
||||
IFabricatorRecipe recipe = new FabricatorRecipe(plan, molten, result, ingredients, patternRecipe.getOreDicts());
|
||||
addRecipe(recipe);
|
||||
}
|
||||
|
||||
|
||||
@@ -186,7 +186,7 @@ public class TileCarpenter extends TilePowered implements ISidedInventory, ILiqu
|
||||
|
||||
NonNullList<ItemStack> craftingSets = InventoryUtil.getStacks(craftingInventory, InventoryGhostCrafting.SLOT_CRAFTING_1, InventoryGhostCrafting.SLOT_CRAFTING_COUNT);
|
||||
IInventory inventory = new InventoryMapper(getInternalInventory(), InventoryCarpenter.SLOT_INVENTORY_1, InventoryCarpenter.SLOT_INVENTORY_COUNT);
|
||||
return InventoryUtil.removeSets(inventory, 1, craftingSets, null, true, true, false, doRemove);
|
||||
return InventoryUtil.removeSets(inventory, 1, craftingSets, currentRecipe.getCraftingGridRecipe().getOreDicts(), null, true, false, doRemove);
|
||||
}
|
||||
|
||||
/* STATE INFORMATION */
|
||||
|
||||
@@ -221,7 +221,7 @@ public class TileFabricator extends TilePowered implements ISlotPickupWatcher, I
|
||||
|
||||
private boolean removeFromInventory(NonNullList<ItemStack> set, boolean doRemove) {
|
||||
IInventory inventory = new InventoryMapper(this, InventoryFabricator.SLOT_INVENTORY_1, InventoryFabricator.SLOT_INVENTORY_COUNT);
|
||||
return InventoryUtil.removeSets(inventory, 1, set, null, true, true, false, doRemove);
|
||||
return InventoryUtil.removeSets(inventory, 1, set, getRecipe().getOreDicts(), null, true, false, doRemove);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -237,7 +237,7 @@ public class TileFabricator extends TilePowered implements ISlotPickupWatcher, I
|
||||
hasResources = removeFromInventory(crafting, false);
|
||||
FluidStack toDrain = recipe.getLiquid();
|
||||
FluidStack drained = moltenTank.drainInternal(toDrain, false);
|
||||
hasLiquidResources = drained.isFluidStackIdentical(toDrain);
|
||||
hasLiquidResources = drained != null && drained.isFluidStackIdentical(toDrain);
|
||||
} else {
|
||||
hasRecipe = false;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user