use of net.minecraft.item.crafting.IRecipe in project LogisticsPipes by RS485.
the class PipeBlockRequestTable method cycleRecipe.
public void cycleRecipe(boolean down) {
cacheRecipe();
if (targetType == null) {
return;
}
cache = null;
AutoCraftingInventory craftInv = new AutoCraftingInventory(null);
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, getWorld())) {
list.add(r);
}
}
if (list.size() > 1) {
boolean found = false;
IRecipe prev = null;
for (IRecipe recipe : list) {
if (found) {
cache = recipe;
break;
}
craftInv = new AutoCraftingInventory(null);
for (int i = 0; i < 9; i++) {
craftInv.setInventorySlotContents(i, matrix.getStackInSlot(i));
}
if (targetType == ItemIdentifier.get(recipe.getCraftingResult(craftInv))) {
if (down) {
found = true;
} else {
if (prev == null) {
cache = list.get(list.size() - 1);
} else {
cache = prev;
}
break;
}
}
prev = recipe;
}
if (cache == null) {
cache = list.get(0);
}
craftInv = new AutoCraftingInventory(null);
for (int i = 0; i < 9; i++) {
craftInv.setInventorySlotContents(i, matrix.getStackInSlot(i));
}
targetType = ItemIdentifier.get(cache.getCraftingResult(craftInv));
}
if (!localGuiWatcher.isEmpty() && getWorld() != null && MainProxy.isServer(getWorld())) {
MainProxy.sendToPlayerList(PacketHandler.getPacket(CraftingSetType.class).setTargetType(targetType).setTilePos(container), localGuiWatcher);
}
cacheRecipe();
}
use of net.minecraft.item.crafting.IRecipe in project LogisticsPipes by RS485.
the class ImmibisCraftingTableMk2 method importRecipe.
@Override
public boolean importRecipe(TileEntity tile, ItemIdentifierInventory inventory) {
try {
if (tileAutoCraftingMk2.isInstance(tile)) {
// Import recipeInputs
ItemStack[][] recipe = (ItemStack[][]) tileAutoCraftingMk2.getField("recipeInputs").get(tile);
// Not really a AutoCraftingInventory, but same content
InventoryCrafting tempCraftingInv = new InventoryCrafting(new Container() {
@Override
public boolean canInteractWith(EntityPlayer entityplayer) {
return false;
}
@Override
public void onCraftMatrixChanged(IInventory par1iInventory) {
}
}, 3, 3);
for (int i = 0; i < 9; i++) {
if (recipe[i].length > 0) {
tempCraftingInv.setInventorySlotContents(i, recipe[i][0]);
inventory.setInventorySlotContents(i, recipe[i][0]);
} else {
inventory.clearInventorySlotContents(i);
}
}
// Compact
int slotCount = 0;
for (int i = 0; i < 9; i++) {
ItemStack slotStack = inventory.getStackInSlot(i);
inventory.clearInventorySlotContents(i);
if (slotStack != null && slotStack.getItem() != null) {
int count = 1;
for (int j = i + 1; j < 9; j++) {
ItemStack tempStack = inventory.getStackInSlot(j);
if (tempStack != null && ItemIdentifier.get(slotStack).equals(ItemIdentifier.get(tempStack))) {
inventory.clearInventorySlotContents(j);
count++;
}
}
slotStack.stackSize = count;
inventory.setInventorySlotContents(slotCount, slotStack);
slotCount++;
}
}
ItemStack result = null;
for (IRecipe r : CraftingUtil.getRecipeList()) {
if (r.matches(tempCraftingInv, tile.getWorldObj())) {
result = r.getCraftingResult(tempCraftingInv);
break;
}
}
inventory.setInventorySlotContents(9, result);
return true;
}
} catch (IllegalArgumentException | NoSuchFieldException e) {
LogisticsPipes.log.fatal("Error while importing recipe from Tubestuff's AutoCraftingMk2");
e.printStackTrace();
} catch (Exception e) {
LogisticsPipes.log.error("Got a problem on ImmibisCraftingTableMk2 CraftingRecipeProvider:");
LogisticsPipes.log.error(e.getMessage());
}
return false;
}
use of net.minecraft.item.crafting.IRecipe in project malmo by Microsoft.
the class CraftingHelper method dumpRecipes.
/** Little utility method for dumping out a list of all the recipes we understand.
* @param filename location to save the dumped list.
* @throws IOException
*/
public static void dumpRecipes(String filename) throws IOException {
FileOutputStream fos = new FileOutputStream(filename);
OutputStreamWriter osw = new OutputStreamWriter(fos, "utf-8");
BufferedWriter writer = new BufferedWriter(osw);
List<?> recipes = CraftingManager.getInstance().getRecipeList();
for (Object obj : recipes) {
if (obj == null)
continue;
if (obj instanceof IRecipe) {
ItemStack is = ((IRecipe) obj).getRecipeOutput();
if (is == null)
continue;
String s = is.stackSize + "x" + is.getUnlocalizedName() + " = ";
List<ItemStack> ingredients = getIngredients((IRecipe) obj);
boolean first = true;
for (ItemStack isIngredient : ingredients) {
if (!first)
s += ", ";
s += isIngredient.stackSize + "x" + isIngredient.getUnlocalizedName();
s += "(" + isIngredient.getDisplayName() + ")";
first = false;
}
s += "\n";
writer.write(s);
}
}
Iterator<?> furnaceIt = FurnaceRecipes.instance().getSmeltingList().keySet().iterator();
while (furnaceIt.hasNext()) {
ItemStack isInput = (ItemStack) furnaceIt.next();
ItemStack isOutput = (ItemStack) FurnaceRecipes.instance().getSmeltingList().get(isInput);
String s = isOutput.stackSize + "x" + isOutput.getUnlocalizedName() + " = FUEL + " + isInput.stackSize + "x" + isInput.getUnlocalizedName() + "\n";
writer.write(s);
}
writer.close();
}
use of net.minecraft.item.crafting.IRecipe in project MinecraftForge by MinecraftForge.
the class OreDictionary method initVanillaEntries.
private static void initVanillaEntries() {
if (!hasInit) {
// tree- and wood-related things
registerOre("logWood", new ItemStack(Blocks.LOG, 1, WILDCARD_VALUE));
registerOre("logWood", new ItemStack(Blocks.LOG2, 1, WILDCARD_VALUE));
registerOre("plankWood", new ItemStack(Blocks.PLANKS, 1, WILDCARD_VALUE));
registerOre("slabWood", new ItemStack(Blocks.WOODEN_SLAB, 1, WILDCARD_VALUE));
registerOre("stairWood", Blocks.OAK_STAIRS);
registerOre("stairWood", Blocks.SPRUCE_STAIRS);
registerOre("stairWood", Blocks.BIRCH_STAIRS);
registerOre("stairWood", Blocks.JUNGLE_STAIRS);
registerOre("stairWood", Blocks.ACACIA_STAIRS);
registerOre("stairWood", Blocks.DARK_OAK_STAIRS);
registerOre("stickWood", Items.STICK);
registerOre("treeSapling", new ItemStack(Blocks.SAPLING, 1, WILDCARD_VALUE));
registerOre("treeLeaves", new ItemStack(Blocks.LEAVES, 1, WILDCARD_VALUE));
registerOre("treeLeaves", new ItemStack(Blocks.LEAVES2, 1, WILDCARD_VALUE));
registerOre("vine", Blocks.VINE);
// Ores
registerOre("oreGold", Blocks.GOLD_ORE);
registerOre("oreIron", Blocks.IRON_ORE);
registerOre("oreLapis", Blocks.LAPIS_ORE);
registerOre("oreDiamond", Blocks.DIAMOND_ORE);
registerOre("oreRedstone", Blocks.REDSTONE_ORE);
registerOre("oreEmerald", Blocks.EMERALD_ORE);
registerOre("oreQuartz", Blocks.QUARTZ_ORE);
registerOre("oreCoal", Blocks.COAL_ORE);
// ingots/nuggets
registerOre("ingotIron", Items.IRON_INGOT);
registerOre("ingotGold", Items.GOLD_INGOT);
registerOre("ingotBrick", Items.BRICK);
registerOre("ingotBrickNether", Items.NETHERBRICK);
registerOre("nuggetGold", Items.GOLD_NUGGET);
registerOre("nuggetIron", Items.field_191525_da);
// gems and dusts
registerOre("gemDiamond", Items.DIAMOND);
registerOre("gemEmerald", Items.EMERALD);
registerOre("gemQuartz", Items.QUARTZ);
registerOre("gemPrismarine", Items.PRISMARINE_SHARD);
registerOre("dustPrismarine", Items.PRISMARINE_CRYSTALS);
registerOre("dustRedstone", Items.REDSTONE);
registerOre("dustGlowstone", Items.GLOWSTONE_DUST);
registerOre("gemLapis", new ItemStack(Items.DYE, 1, 4));
// storage blocks
registerOre("blockGold", Blocks.GOLD_BLOCK);
registerOre("blockIron", Blocks.IRON_BLOCK);
registerOre("blockLapis", Blocks.LAPIS_BLOCK);
registerOre("blockDiamond", Blocks.DIAMOND_BLOCK);
registerOre("blockRedstone", Blocks.REDSTONE_BLOCK);
registerOre("blockEmerald", Blocks.EMERALD_BLOCK);
registerOre("blockQuartz", Blocks.QUARTZ_BLOCK);
registerOre("blockCoal", Blocks.COAL_BLOCK);
// crops
registerOre("cropWheat", Items.WHEAT);
registerOre("cropPotato", Items.POTATO);
registerOre("cropCarrot", Items.CARROT);
registerOre("cropNetherWart", Items.NETHER_WART);
registerOre("sugarcane", Items.REEDS);
registerOre("blockCactus", Blocks.CACTUS);
// misc materials
registerOre("dye", new ItemStack(Items.DYE, 1, WILDCARD_VALUE));
registerOre("paper", new ItemStack(Items.PAPER));
// mob drops
registerOre("slimeball", Items.SLIME_BALL);
registerOre("enderpearl", Items.ENDER_PEARL);
registerOre("bone", Items.BONE);
registerOre("gunpowder", Items.GUNPOWDER);
registerOre("string", Items.STRING);
registerOre("netherStar", Items.NETHER_STAR);
registerOre("leather", Items.LEATHER);
registerOre("feather", Items.FEATHER);
registerOre("egg", Items.EGG);
// records
registerOre("record", Items.RECORD_13);
registerOre("record", Items.RECORD_CAT);
registerOre("record", Items.RECORD_BLOCKS);
registerOre("record", Items.RECORD_CHIRP);
registerOre("record", Items.RECORD_FAR);
registerOre("record", Items.RECORD_MALL);
registerOre("record", Items.RECORD_MELLOHI);
registerOre("record", Items.RECORD_STAL);
registerOre("record", Items.RECORD_STRAD);
registerOre("record", Items.RECORD_WARD);
registerOre("record", Items.RECORD_11);
registerOre("record", Items.RECORD_WAIT);
// blocks
registerOre("dirt", Blocks.DIRT);
registerOre("grass", Blocks.GRASS);
registerOre("stone", Blocks.STONE);
registerOre("cobblestone", Blocks.COBBLESTONE);
registerOre("gravel", Blocks.GRAVEL);
registerOre("sand", new ItemStack(Blocks.SAND, 1, WILDCARD_VALUE));
registerOre("sandstone", new ItemStack(Blocks.SANDSTONE, 1, WILDCARD_VALUE));
registerOre("sandstone", new ItemStack(Blocks.RED_SANDSTONE, 1, WILDCARD_VALUE));
registerOre("netherrack", Blocks.NETHERRACK);
registerOre("obsidian", Blocks.OBSIDIAN);
registerOre("glowstone", Blocks.GLOWSTONE);
registerOre("endstone", Blocks.END_STONE);
registerOre("torch", Blocks.TORCH);
registerOre("workbench", Blocks.CRAFTING_TABLE);
registerOre("blockSlime", Blocks.SLIME_BLOCK);
registerOre("blockPrismarine", new ItemStack(Blocks.PRISMARINE, 1, BlockPrismarine.EnumType.ROUGH.getMetadata()));
registerOre("blockPrismarineBrick", new ItemStack(Blocks.PRISMARINE, 1, BlockPrismarine.EnumType.BRICKS.getMetadata()));
registerOre("blockPrismarineDark", new ItemStack(Blocks.PRISMARINE, 1, BlockPrismarine.EnumType.DARK.getMetadata()));
registerOre("stoneGranite", new ItemStack(Blocks.STONE, 1, 1));
registerOre("stoneGranitePolished", new ItemStack(Blocks.STONE, 1, 2));
registerOre("stoneDiorite", new ItemStack(Blocks.STONE, 1, 3));
registerOre("stoneDioritePolished", new ItemStack(Blocks.STONE, 1, 4));
registerOre("stoneAndesite", new ItemStack(Blocks.STONE, 1, 5));
registerOre("stoneAndesitePolished", new ItemStack(Blocks.STONE, 1, 6));
registerOre("blockGlassColorless", Blocks.GLASS);
registerOre("blockGlass", Blocks.GLASS);
registerOre("blockGlass", new ItemStack(Blocks.STAINED_GLASS, 1, WILDCARD_VALUE));
//blockGlass{Color} is added below with dyes
registerOre("paneGlassColorless", Blocks.GLASS_PANE);
registerOre("paneGlass", Blocks.GLASS_PANE);
registerOre("paneGlass", new ItemStack(Blocks.STAINED_GLASS_PANE, 1, WILDCARD_VALUE));
//paneGlass{Color} is added below with dyes
// chests
registerOre("chest", Blocks.CHEST);
registerOre("chest", Blocks.ENDER_CHEST);
registerOre("chest", Blocks.TRAPPED_CHEST);
registerOre("chestWood", Blocks.CHEST);
registerOre("chestEnder", Blocks.ENDER_CHEST);
registerOre("chestTrapped", Blocks.TRAPPED_CHEST);
}
// Build our list of items to replace with ore tags
Map<ItemStack, String> replacements = new HashMap<ItemStack, String>();
// wood-related things
replacements.put(new ItemStack(Items.STICK), "stickWood");
replacements.put(new ItemStack(Blocks.PLANKS), "plankWood");
replacements.put(new ItemStack(Blocks.PLANKS, 1, WILDCARD_VALUE), "plankWood");
replacements.put(new ItemStack(Blocks.WOODEN_SLAB, 1, WILDCARD_VALUE), "slabWood");
// ingots/nuggets
replacements.put(new ItemStack(Items.GOLD_INGOT), "ingotGold");
replacements.put(new ItemStack(Items.IRON_INGOT), "ingotIron");
// gems and dusts
replacements.put(new ItemStack(Items.DIAMOND), "gemDiamond");
replacements.put(new ItemStack(Items.EMERALD), "gemEmerald");
replacements.put(new ItemStack(Items.PRISMARINE_SHARD), "gemPrismarine");
replacements.put(new ItemStack(Items.PRISMARINE_CRYSTALS), "dustPrismarine");
replacements.put(new ItemStack(Items.REDSTONE), "dustRedstone");
replacements.put(new ItemStack(Items.GLOWSTONE_DUST), "dustGlowstone");
// crops
replacements.put(new ItemStack(Items.REEDS), "sugarcane");
replacements.put(new ItemStack(Blocks.CACTUS), "blockCactus");
// misc materials
replacements.put(new ItemStack(Items.PAPER), "paper");
// mob drops
replacements.put(new ItemStack(Items.SLIME_BALL), "slimeball");
replacements.put(new ItemStack(Items.STRING), "string");
replacements.put(new ItemStack(Items.LEATHER), "leather");
replacements.put(new ItemStack(Items.ENDER_PEARL), "enderpearl");
replacements.put(new ItemStack(Items.GUNPOWDER), "gunpowder");
replacements.put(new ItemStack(Items.NETHER_STAR), "netherStar");
replacements.put(new ItemStack(Items.FEATHER), "feather");
replacements.put(new ItemStack(Items.BONE), "bone");
replacements.put(new ItemStack(Items.EGG), "egg");
// blocks
replacements.put(new ItemStack(Blocks.STONE), "stone");
replacements.put(new ItemStack(Blocks.COBBLESTONE), "cobblestone");
replacements.put(new ItemStack(Blocks.COBBLESTONE, 1, WILDCARD_VALUE), "cobblestone");
replacements.put(new ItemStack(Blocks.GLOWSTONE), "glowstone");
replacements.put(new ItemStack(Blocks.GLASS), "blockGlassColorless");
replacements.put(new ItemStack(Blocks.PRISMARINE), "prismarine");
replacements.put(new ItemStack(Blocks.STONE, 1, 1), "stoneGranite");
replacements.put(new ItemStack(Blocks.STONE, 1, 2), "stoneGranitePolished");
replacements.put(new ItemStack(Blocks.STONE, 1, 3), "stoneDiorite");
replacements.put(new ItemStack(Blocks.STONE, 1, 4), "stoneDioritePolished");
replacements.put(new ItemStack(Blocks.STONE, 1, 5), "stoneAndesite");
replacements.put(new ItemStack(Blocks.STONE, 1, 6), "stoneAndesitePolished");
// chests
replacements.put(new ItemStack(Blocks.CHEST), "chestWood");
replacements.put(new ItemStack(Blocks.ENDER_CHEST), "chestEnder");
replacements.put(new ItemStack(Blocks.TRAPPED_CHEST), "chestTrapped");
// Register dyes
String[] dyes = { "Black", "Red", "Green", "Brown", "Blue", "Purple", "Cyan", "LightGray", "Gray", "Pink", "Lime", "Yellow", "LightBlue", "Magenta", "Orange", "White" };
for (int i = 0; i < 16; i++) {
ItemStack dye = new ItemStack(Items.DYE, 1, i);
ItemStack block = new ItemStack(Blocks.STAINED_GLASS, 1, 15 - i);
ItemStack pane = new ItemStack(Blocks.STAINED_GLASS_PANE, 1, 15 - i);
if (!hasInit) {
registerOre("dye" + dyes[i], dye);
registerOre("blockGlass" + dyes[i], block);
registerOre("paneGlass" + dyes[i], pane);
}
replacements.put(dye, "dye" + dyes[i]);
replacements.put(block, "blockGlass" + dyes[i]);
replacements.put(pane, "paneGlass" + dyes[i]);
}
hasInit = true;
ItemStack[] replaceStacks = replacements.keySet().toArray(new ItemStack[replacements.keySet().size()]);
// Ignore recipes for the following items
ItemStack[] exclusions = new ItemStack[] { new ItemStack(Blocks.LAPIS_BLOCK), new ItemStack(Items.COOKIE), new ItemStack(Blocks.STONEBRICK), new ItemStack(Blocks.STONE_SLAB, 1, WILDCARD_VALUE), new ItemStack(Blocks.STONE_STAIRS), new ItemStack(Blocks.COBBLESTONE_WALL), new ItemStack(Blocks.OAK_FENCE), new ItemStack(Blocks.OAK_FENCE_GATE), new ItemStack(Blocks.OAK_STAIRS), new ItemStack(Blocks.SPRUCE_FENCE), new ItemStack(Blocks.SPRUCE_FENCE_GATE), new ItemStack(Blocks.SPRUCE_STAIRS), new ItemStack(Blocks.BIRCH_STAIRS), new ItemStack(Blocks.BIRCH_FENCE_GATE), new ItemStack(Blocks.BIRCH_STAIRS), new ItemStack(Blocks.JUNGLE_FENCE), new ItemStack(Blocks.JUNGLE_FENCE_GATE), new ItemStack(Blocks.JUNGLE_STAIRS), new ItemStack(Blocks.ACACIA_FENCE), new ItemStack(Blocks.ACACIA_FENCE_GATE), new ItemStack(Blocks.ACACIA_STAIRS), new ItemStack(Blocks.DARK_OAK_FENCE), new ItemStack(Blocks.DARK_OAK_FENCE_GATE), new ItemStack(Blocks.DARK_OAK_STAIRS), new ItemStack(Blocks.WOODEN_SLAB), new ItemStack(Blocks.GLASS_PANE), // Bone Block, to prevent conversion of dyes into bone meal.
new ItemStack(Blocks.BONE_BLOCK), new ItemStack(Items.BOAT), new ItemStack(Items.OAK_DOOR), //So the above can have a comma and we don't have to keep editing extra lines.
ItemStack.EMPTY };
List<IRecipe> recipes = CraftingManager.getInstance().getRecipeList();
List<IRecipe> recipesToRemove = new ArrayList<IRecipe>();
List<IRecipe> recipesToAdd = new ArrayList<IRecipe>();
// Search vanilla recipes for recipes to replace
for (Object obj : recipes) {
if (obj.getClass() == ShapedRecipes.class) {
ShapedRecipes recipe = (ShapedRecipes) obj;
ItemStack output = recipe.getRecipeOutput();
if (!output.isEmpty() && containsMatch(false, exclusions, output)) {
continue;
}
if (containsMatch(true, recipe.recipeItems, replaceStacks)) {
recipesToRemove.add(recipe);
recipesToAdd.add(new ShapedOreRecipe(recipe, replacements));
}
} else if (obj.getClass() == ShapelessRecipes.class) {
ShapelessRecipes recipe = (ShapelessRecipes) obj;
ItemStack output = recipe.getRecipeOutput();
if (!output.isEmpty() && containsMatch(false, exclusions, output)) {
continue;
}
if (containsMatch(true, recipe.recipeItems.toArray(new ItemStack[recipe.recipeItems.size()]), replaceStacks)) {
recipesToRemove.add((IRecipe) obj);
IRecipe newRecipe = new ShapelessOreRecipe(recipe, replacements);
recipesToAdd.add(newRecipe);
}
}
}
recipes.removeAll(recipesToRemove);
recipes.addAll(recipesToAdd);
if (recipesToRemove.size() > 0) {
FMLLog.info("Replaced %d ore recipes", recipesToRemove.size());
}
}
use of net.minecraft.item.crafting.IRecipe in project NetherEx by LogicTechCorp.
the class NetherExRecipes method removeRecipe.
private static void removeRecipe(Item output) {
List<IRecipe> recipes = CraftingManager.getInstance().getRecipeList();
Iterator<IRecipe> iter = recipes.iterator();
while (iter.hasNext()) {
ItemStack stack = iter.next().getRecipeOutput();
if (!stack.isEmpty() && stack.getItem() == output) {
iter.remove();
}
}
LOGGER.info("Removed original recipe for %s", output.getRegistryName());
}
Aggregations