use of net.minecraft.item.crafting.IRecipe in project BetterStorage by copygirl.
the class Recipes method addTileRecipes.
private static void addTileRecipes() {
// Crate recipe
if (BetterStorageTiles.crate != null)
GameRegistry.addRecipe(new ShapedOreRecipe(new ItemStack(BetterStorageTiles.crate), "o/o", "/ /", "o/o", 'o', "plankWood", '/', "stickWood"));
// Reinforced chest recipes
if (BetterStorageTiles.reinforcedChest != null)
for (ContainerMaterial material : ContainerMaterial.getMaterials()) {
IRecipe recipe = material.getReinforcedRecipe(Blocks.chest, BetterStorageTiles.reinforcedChest);
if (recipe != null)
GameRegistry.addRecipe(recipe);
}
// Locker recipe
if (BetterStorageTiles.locker != null) {
GameRegistry.addRecipe(new ShapedOreRecipe(new ItemStack(BetterStorageTiles.locker), "ooo", "o |", "ooo", 'o', "plankWood", '|', Blocks.trapdoor));
GameRegistry.addRecipe(new ShapedOreRecipe(new ItemStack(BetterStorageTiles.locker), "ooo", "| o", "ooo", 'o', "plankWood", '|', Blocks.trapdoor));
// Reinforced locker recipes
if (BetterStorageTiles.reinforcedLocker != null)
for (ContainerMaterial material : ContainerMaterial.getMaterials()) {
IRecipe recipe = material.getReinforcedRecipe(BetterStorageTiles.locker, BetterStorageTiles.reinforcedLocker);
if (recipe != null)
GameRegistry.addRecipe(recipe);
}
}
// Armor stand recipe
if (BetterStorageTiles.armorStand != null)
GameRegistry.addShapedRecipe(new ItemStack(BetterStorageTiles.armorStand), " i ", "/i/", " s ", 's', new ItemStack(Blocks.stone_slab, 1, 0), 'i', Items.iron_ingot, '/', Items.stick);
// Backpack recipe
if (BetterStorageTiles.backpack != null)
GameRegistry.addShapedRecipe(new ItemStack(BetterStorageItems.itemBackpack), "#i#", "#O#", "###", '#', Items.leather, 'O', Blocks.wool, 'i', Items.gold_ingot);
// Cardboard box recipe
if ((BetterStorageTiles.cardboardBox != null) && (BetterStorageItems.cardboardSheet != null))
GameRegistry.addRecipe(new ShapedOreRecipe(new ItemStack(BetterStorageTiles.cardboardBox), "ooo", "o o", "ooo", 'o', "sheetCardboard"));
// Crafting Station recipe
if (BetterStorageTiles.craftingStation != null)
GameRegistry.addRecipe(new ShapedOreRecipe(new ItemStack(BetterStorageTiles.craftingStation), "B-B", "PTP", "WCW", 'B', Blocks.stonebrick, '-', Blocks.light_weighted_pressure_plate, 'P', Blocks.piston, 'T', Blocks.crafting_table, 'W', "plankWood", 'C', ((BetterStorageTiles.crate != null) ? BetterStorageTiles.crate : Blocks.chest)));
// Present recipe
if ((BetterStorageTiles.present != null) && (BetterStorageTiles.cardboardBox != null)) {
GameRegistry.addRecipe(new PresentRecipe());
BetterStorageCrafting.addStationRecipe(new PresentRemoveNametagRecipe());
}
// Flint Block recipe
if (BetterStorageTiles.flintBlock != null) {
GameRegistry.addShapedRecipe(new ItemStack(BetterStorageTiles.flintBlock), "ooo", "ooo", "ooo", 'o', Items.flint);
GameRegistry.addShapelessRecipe(new ItemStack(Items.flint, 9), BetterStorageTiles.flintBlock);
}
}
use of net.minecraft.item.crafting.IRecipe in project BluePower by Qmunity.
the class SlotCircuitTableCrafting method getCraftingComponents.
private static List<ItemStack> getCraftingComponents(ItemStack gate) {
List<ItemStack> requiredItems = new ArrayList<ItemStack>();
List recipeList = CraftingManager.getInstance().getRecipeList();
for (IRecipe r : (List<IRecipe>) recipeList) {
ItemStack result = r.getRecipeOutput();
if (result != null && result.isItemEqual(gate)) {
if (r instanceof ShapedOreRecipe) {
ShapedOreRecipe recipe = (ShapedOreRecipe) r;
for (Object o : recipe.getInput()) {
if (o != null) {
ItemStack stack;
if (o instanceof ItemStack) {
stack = (ItemStack) o;
} else {
List<ItemStack> list = (List<ItemStack>) o;
stack = list.size() > 0 ? list.get(0) : null;
}
if (stack != null) {
boolean needsAdding = true;
for (ItemStack listStack : requiredItems) {
if (listStack.isItemEqual(stack)) {
listStack.stackSize++;
needsAdding = false;
break;
}
}
if (needsAdding)
requiredItems.add(stack.copy());
}
}
}
return requiredItems;
} else if (r instanceof ShapedRecipes) {
ShapedRecipes recipe = (ShapedRecipes) r;
for (ItemStack stack : recipe.recipeItems) {
if (stack != null) {
boolean needsAdding = true;
for (ItemStack listStack : requiredItems) {
if (listStack.isItemEqual(stack)) {
listStack.stackSize++;
needsAdding = false;
break;
}
}
if (needsAdding)
requiredItems.add(stack.copy());
}
}
return requiredItems;
}
}
}
return new ArrayList<ItemStack>();
}
use of net.minecraft.item.crafting.IRecipe in project BluePower by Qmunity.
the class AlloyFurnaceRegistry method generateRecyclingRecipes.
@SuppressWarnings("unchecked")
public void generateRecyclingRecipes() {
Collections.addAll(blacklist, Config.alloyFurnaceBlacklist);
List<Item> blacklist = new ArrayList<Item>();
for (String configString : this.blacklist) {
Item item = GameData.getItemRegistry().getObject(configString);
if (item != null) {
blacklist.add(item);
} else {
BluePower.log.info("Config entry \"" + configString + "\" not an existing item/block name! Will not be added to the blacklist");
}
}
List<ItemStack> registeredRecycledItems = new ArrayList<ItemStack>();
List<ItemStack> registeredResultItems = new ArrayList<ItemStack>();
List<IRecipe> recipes = CraftingManager.getInstance().getRecipeList();
for (IRecipe recipe : recipes) {
int recyclingAmount = 0;
ItemStack currentlyRecycledInto = null;
for (ItemStack recyclingItem : bufferedRecyclingItems) {
try {
if (recipe instanceof ShapedRecipes) {
ShapedRecipes shaped = (ShapedRecipes) recipe;
if (shaped.recipeItems != null) {
for (ItemStack input : shaped.recipeItems) {
if (input != null && ItemStackUtils.isItemFuzzyEqual(input, recyclingItem)) {
ItemStack moltenDownItem = getRecyclingStack(recyclingItem);
if (currentlyRecycledInto == null || ItemStackUtils.isItemFuzzyEqual(currentlyRecycledInto, moltenDownItem)) {
currentlyRecycledInto = moltenDownItem;
recyclingAmount += moltenDownItem.stackSize;
}
}
}
}
} else if (recipe instanceof ShapelessRecipes) {
ShapelessRecipes shapeless = (ShapelessRecipes) recipe;
if (shapeless.recipeItems != null) {
for (ItemStack input : (List<ItemStack>) shapeless.recipeItems) {
if (input != null && ItemStackUtils.isItemFuzzyEqual(input, recyclingItem)) {
ItemStack moltenDownItem = getRecyclingStack(recyclingItem);
if (currentlyRecycledInto == null || ItemStackUtils.isItemFuzzyEqual(currentlyRecycledInto, moltenDownItem)) {
currentlyRecycledInto = moltenDownItem;
recyclingAmount += moltenDownItem.stackSize;
}
}
}
}
} else if (recipe instanceof ShapedOreRecipe) {
ShapedOreRecipe shapedOreRecipe = (ShapedOreRecipe) recipe;
if (shapedOreRecipe.getInput() != null) {
for (Object input : shapedOreRecipe.getInput()) {
if (input != null) {
List<ItemStack> itemList;
if (input instanceof ItemStack) {
itemList = new ArrayList<ItemStack>();
itemList.add((ItemStack) input);
} else {
itemList = (List<ItemStack>) input;
}
for (ItemStack item : itemList) {
if (item != null && ItemStackUtils.isItemFuzzyEqual(item, recyclingItem)) {
ItemStack moltenDownItem = getRecyclingStack(recyclingItem);
if (currentlyRecycledInto == null || ItemStackUtils.isItemFuzzyEqual(currentlyRecycledInto, moltenDownItem)) {
currentlyRecycledInto = moltenDownItem;
recyclingAmount += moltenDownItem.stackSize;
}
break;
}
}
}
}
}
} else if (recipe instanceof ShapelessOreRecipe) {
ShapelessOreRecipe shapeless = (ShapelessOreRecipe) recipe;
for (Object input : shapeless.getInput()) {
if (input != null) {
List<ItemStack> itemList;
if (input instanceof ItemStack) {
itemList = new ArrayList<ItemStack>();
itemList.add((ItemStack) input);
} else {
itemList = (List<ItemStack>) input;
}
for (ItemStack item : itemList) {
if (item != null && ItemStackUtils.isItemFuzzyEqual(item, recyclingItem)) {
ItemStack moltenDownItem = getRecyclingStack(recyclingItem);
if (currentlyRecycledInto == null || ItemStackUtils.isItemFuzzyEqual(currentlyRecycledInto, moltenDownItem)) {
currentlyRecycledInto = moltenDownItem;
recyclingAmount += moltenDownItem.stackSize;
}
break;
}
}
}
}
}
} catch (Throwable e) {
BluePower.log.error("Error when generating an Alloy Furnace recipe for item " + recyclingItem.getDisplayName() + ", recipe output: " + recipe.getRecipeOutput().getDisplayName());
e.printStackTrace();
}
}
if (recyclingAmount > 0 && recipe.getRecipeOutput().stackSize > 0) {
boolean shouldAdd = true;
for (int i = 0; i < registeredRecycledItems.size(); i++) {
if (ItemStackUtils.isItemFuzzyEqual(registeredRecycledItems.get(i), recipe.getRecipeOutput())) {
if (registeredResultItems.get(i).stackSize < recyclingAmount) {
shouldAdd = false;
break;
} else {
registeredResultItems.remove(i);
registeredRecycledItems.remove(i);
i--;
}
}
}
if (shouldAdd) {
if (blacklist.contains(recipe.getRecipeOutput().getItem())) {
BluePower.log.info("Skipped adding item/block " + recipe.getRecipeOutput().getDisplayName() + " to the Alloy Furnace recipes.");
continue;
}
ItemStack resultItem = new ItemStack(currentlyRecycledInto.getItem(), Math.min(64, recyclingAmount), currentlyRecycledInto.getItemDamage());
registeredResultItems.add(resultItem);
registeredRecycledItems.add(recipe.getRecipeOutput());
}
}
}
for (int i = 0; i < registeredResultItems.size(); i++) {
addRecipe(registeredResultItems.get(i), registeredRecycledItems.get(i));
}
}
use of net.minecraft.item.crafting.IRecipe in project LogisticsPipes by RS485.
the class LogisticsCraftingTableTileEntity method getOutput.
public ItemStack getOutput(IResource wanted, IRoutedPowerProvider power) {
boolean isFuzzy = isFuzzy();
if (cache == null) {
cacheRecipe();
if (cache == null) {
return null;
}
}
int[] toUse = new int[9];
int[] used = new int[inv.getSizeInventory()];
outer: for (int i = 0; i < 9; i++) {
ItemIdentifierStack item = matrix.getIDStackInSlot(i);
if (item == null) {
toUse[i] = -1;
continue;
}
ItemIdentifier ident = item.getItem();
for (int j = 0; j < inv.getSizeInventory(); j++) {
item = inv.getIDStackInSlot(j);
if (item == null) {
continue;
}
if (isFuzzy ? (testFuzzy(ident, item, i)) : ident.equalsForCrafting(item.getItem())) {
if (item.getStackSize() > used[j]) {
used[j]++;
toUse[i] = j;
continue outer;
}
}
}
//Not enough material
return null;
}
AutoCraftingInventory crafter = new AutoCraftingInventory(placedBy);
for (int i = 0; i < 9; i++) {
int j = toUse[i];
if (j != -1) {
crafter.setInventorySlotContents(i, inv.getStackInSlot(j));
}
}
IRecipe recipe = cache;
outputFuzzyFlags.stack = resultInv.getIDStackInSlot(0);
if (!recipe.matches(crafter, getWorldObj())) {
if (isFuzzy && outputFuzzyFlags.getBitSet().nextSetBit(0) != -1) {
recipe = null;
for (IRecipe r : CraftingUtil.getRecipeList()) {
if (r.matches(crafter, getWorldObj()) && outputFuzzyFlags.matches(ItemIdentifier.get(r.getRecipeOutput()), IResource.MatchSettings.NORMAL)) {
recipe = r;
break;
}
}
if (recipe == null) {
return null;
}
} else {
//Fix MystCraft
return null;
}
}
ItemStack result = recipe.getCraftingResult(crafter);
if (result == null) {
return null;
}
if (isFuzzy && outputFuzzyFlags.getBitSet().nextSetBit(0) != -1) {
if (!outputFuzzyFlags.matches(ItemIdentifier.get(result), IResource.MatchSettings.NORMAL)) {
return null;
}
if (!outputFuzzyFlags.matches(wanted.getAsItem(), IResource.MatchSettings.NORMAL)) {
return null;
}
} else {
if (!resultInv.getIDStackInSlot(0).getItem().equalsWithoutNBT(ItemIdentifier.get(result))) {
return null;
}
if (!wanted.matches(resultInv.getIDStackInSlot(0).getItem(), IResource.MatchSettings.WITHOUT_NBT)) {
return null;
}
}
if (!power.useEnergy(Configs.LOGISTICS_CRAFTING_TABLE_POWER_USAGE)) {
return null;
}
crafter = new AutoCraftingInventory(placedBy);
for (int i = 0; i < 9; i++) {
int j = toUse[i];
if (j != -1) {
crafter.setInventorySlotContents(i, inv.decrStackSize(j, 1));
}
}
result = recipe.getCraftingResult(crafter);
if (fake == null) {
fake = MainProxy.getFakePlayer(this);
}
result = result.copy();
SlotCrafting craftingSlot = new SlotCrafting(fake, crafter, resultInv, 0, 0, 0);
craftingSlot.onPickupFromSlot(fake, result);
for (int i = 0; i < 9; i++) {
ItemStack left = crafter.getStackInSlot(i);
crafter.setInventorySlotContents(i, null);
if (left != null) {
left.stackSize = inv.addCompressed(left, false);
if (left.stackSize > 0) {
ItemIdentifierInventory.dropItems(worldObj, left, xCoord, yCoord, zCoord);
}
}
}
for (int i = 0; i < fake.inventory.getSizeInventory(); i++) {
ItemStack left = fake.inventory.getStackInSlot(i);
fake.inventory.setInventorySlotContents(i, null);
if (left != null) {
left.stackSize = inv.addCompressed(left, false);
if (left.stackSize > 0) {
ItemIdentifierInventory.dropItems(worldObj, left, xCoord, yCoord, zCoord);
}
}
}
return result;
}
use of net.minecraft.item.crafting.IRecipe in project LogisticsPipes by RS485.
the class LogisticsCraftingTableTileEntity method cacheRecipe.
public void cacheRecipe() {
ItemIdentifier oldTargetType = targetType;
cache = null;
resultInv.clearInventorySlotContents(0);
AutoCraftingInventory craftInv = new AutoCraftingInventory(placedBy);
for (int i = 0; i < 9; i++) {
craftInv.setInventorySlotContents(i, matrix.getStackInSlot(i));
}
List<IRecipe> list = new ArrayList<>();
for (IRecipe r : CraftingUtil.getRecipeList()) {
if (r.matches(craftInv, getWorldObj())) {
list.add(r);
}
}
if (list.size() == 1) {
cache = list.get(0);
resultInv.setInventorySlotContents(0, cache.getCraftingResult(craftInv));
targetType = null;
} else if (list.size() > 1) {
if (targetType != null) {
for (IRecipe recipe : list) {
craftInv = new AutoCraftingInventory(placedBy);
for (int i = 0; i < 9; i++) {
craftInv.setInventorySlotContents(i, matrix.getStackInSlot(i));
}
ItemStack result = recipe.getCraftingResult(craftInv);
if (result != null && targetType.equals(ItemIdentifier.get(result))) {
resultInv.setInventorySlotContents(0, result);
cache = recipe;
break;
}
}
}
if (cache == null) {
for (IRecipe r : list) {
ItemStack result = r.getCraftingResult(craftInv);
if (result != null) {
cache = r;
resultInv.setInventorySlotContents(0, result);
targetType = ItemIdentifier.get(result);
break;
}
}
}
} else {
targetType = null;
}
outputFuzzyFlags.stack = resultInv.getIDStackInSlot(0);
if (((targetType == null && oldTargetType != null) || (targetType != null && !targetType.equals(oldTargetType))) && !guiWatcher.isEmpty() && getWorldObj() != null && MainProxy.isServer(getWorldObj())) {
MainProxy.sendToPlayerList(PacketHandler.getPacket(CraftingSetType.class).setTargetType(targetType).setTilePos(this), guiWatcher);
}
}
Aggregations