Jump to content

gettingRecipeList


Gnomorian

Recommended Posts

Hi, essentualy making a clone of Crafting Bench 2/3 as they both seem dead.

im having trouble with checking if the player has the right items in their inventory or not.

i have a function that runs during postinit to get the list of reciepes from CraftingManager and sort them into 2 lists, ShapedRecipe and ShapelessRecipe

 

public class GGURecipeManager 
{
/**
 * list of all shaped recipes found in the CraftingManager's Recipe List.
 */
private static List<ShapedRecipes> shapedRecipes = new ArrayList<ShapedRecipes>();
/**
 * list of all shapeless recipes found in the CraftingManager's Recipe List.
 */
private static List<ShapelessRecipes> shapelessRecipes = new ArrayList<ShapelessRecipes>();

/**
 * gets the list of recipes from the crafting manager and sorts them into multiple lists to 
 * reduse lookup time during the game.
 * @param recipeList list of recipes from CraftingManager
 */
public static void init(List recipeList) 
{
	for(int i = 0; i<recipeList.size();i++)
	{
		if(recipeList.get(i) instanceof ShapedRecipes) 
		{
			//if(((ShapedRecipes)recipeList.get(i)).getRecipeOutput() != null)
				shapedRecipes.add(((ShapedRecipes)recipeList.get(i)));
		}
		else if(recipeList.get(i) instanceof ShapelessRecipes) 
		{
			if(((ShapelessRecipes)recipeList.get(i)).getRecipeOutput() != null)
				shapelessRecipes.add(((ShapelessRecipes)recipeList.get(i)));
		}
	}
}
/**
 * returns the list of shaped recipes.
 */
public static List<ShapedRecipes> getShaped() 
{
	return shapedRecipes;

}
/**
 * returns the list of shaped recipes.
 */
public static List<ShapelessRecipes> getShapeless() 
{
	return shapelessRecipes;

}
}

 

i then have a block, which when you right click on it calls the method that loops through your inventory and checks if you have the items required for the stored ShapedRecipe and ShapelessReicpe stored in the lists

 

/*
* Copyright (c) 2014, William <[email protected]>
* 
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/

package nz.co.crookedhill.ggutils.util;

import java.util.ArrayList;
import java.util.List;

import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.ShapedRecipes;
import net.minecraft.item.crafting.ShapelessRecipes;

/**
*	recipe instances:
* 	net.minecraft.item.crafting.ShapedRecipes
*	net.minecraftforge.oredict.ShapedOreRecipe
*	net.minecraft.item.crafting.RecipesMapExtending
*	net.minecraft.item.crafting.RecipesArmorDyes
*	net.minecraft.item.crafting.RecipeFireworks
*	net.minecraft.item.crafting.RecipeBookCloning
*	net.minecraft.item.crafting.RecipesMapCloning
*	net.minecraft.item.crafting.ShapelessRecipes
*	net.minecraftforge.oredict.ShapelessOreRecipe
*	net.minecraft.item.crafting.ShapedRecipes
*/

/**
* new packet needs to be added that sends the itemstack 
* the player wants to make to the server. possibly as well
* as the itemstacks used to make it as the items used to
* make it to avoid the server looping through all the recipes.
* @author william-cameron1994
*
*/

public class GGURecipeFilter 
{
public static List filter(List<ItemStack> inventoryItems) 
{
	List avalableRecipes = new ArrayList();

	//for shaped recipes
	for(ShapedRecipes recipe : GGURecipeManager.getShaped()) 
	{
		/*
		 * if the player has an item required for the recipe, 
		 * incriment by one, if its the size of required items 
		 * at the end, player has all items
		 */
		int gotRequiredItems = 0;
		for(ItemStack requiredItem : recipe.recipeItems) 
		{
			if(requiredItem == null)
				continue;
			for(ItemStack invItem : inventoryItems) 
			{
				if(invItem == null)
					continue;
				if(requiredItem.getItem() == (invItem.getItem()) &&requiredItem.stackSize <= invItem.stackSize)
					gotRequiredItems++;
			}
		}
		if(recipe.recipeItems.length == gotRequiredItems)
			avalableRecipes.add(recipe);
	}

	//for shapeless recipes
	for(ShapelessRecipes recipe : GGURecipeManager.getShapeless()) 
	{
		/*
		 * if the player has an item required for the recipe, 
		 * incriment by one, if its the size of required items 
		 * at the end, player has all items
		 */
		int gotRequiredItems = 0;
		for(int i = 0; i < recipe.recipeItems.size(); i++) {
			ItemStack requiredItem = (ItemStack)recipe.recipeItems.get(i);
			if(requiredItem == null)
				continue;
			for(ItemStack invItem : inventoryItems) 
			{
				if(invItem == null)
					continue;
				if(requiredItem.getItem() == (invItem.getItem())&&requiredItem.stackSize <= invItem.stackSize)
					gotRequiredItems++;
			}
		}
		if(recipe.recipeItems.size() == gotRequiredItems)
			avalableRecipes.add(recipe);
	}
	System.out.println(avalableRecipes.size());
	return avalableRecipes;
}
}

 

the last method is called by the block, it then loops through the filtered out "valid" recipes and prints out what you can make.

 

public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int meta, float float1, float float2, float float3) 
{
	player.addStat(GGUAchievements.usedlazyCrafter, 1);
	//open the gui.
	//get the players inventory.
	//display the inventory and the items avalable 
	//to craft with current items.
	if(!world.isRemote)
	{
		IInventory inventory = player.inventory;
		List invItems = new ArrayList();
		//36-39=armour
		for(int i = 0; i < 35; i++) 
		{
			ItemStack items = inventory.getStackInSlot(i);
			if(items == null)
				continue;
			invItems.add(items);
		}
		List recipes = GGURecipeFilter.filter(invItems);
		for(int i = 0; i < recipes.size(); i++) 
		{
			if(recipes.get(i)instanceof ShapedRecipes) 
			{
				System.out.println(player.getDisplayName()+" can craft a shaped "+((ShapedRecipes)recipes.get(i)).getRecipeOutput().getDisplayName());
			}
			else if(recipes.get(i)instanceof ShapelessRecipes) {
				System.out.println(player.getDisplayName()+" can craft a shapeless "+((ShapelessRecipes)recipes.get(i)).getRecipeOutput().getDisplayName());
			}

		}

		return true;
	}
	return false;
}

}

 

 

it sort of seems to work, it finds some recipes, like it knows when you have 3+ planks, you can make slabs, but it doesn't recognize you can make sticks.

if anyone can make heads or tails of what im mucking up here, your help would be apreciated, thanks.

<iframe src="http://widget.mcf.li/mc-mods/minecraft/225523-gnomgnoms-utils" width="100%" style="border: none;"></iframe>

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • I am not using hardcoded recipes, I'm using Vanilla's already existing code for leather armor dying. (via extending and implementing DyeableArmorItem / DyeableLeatherItem respectively) I have actually figured out that it's something to do with registering item colors to the ItemColors instance, but I'm trying to figure out where exactly in my mod's code I would be placing a call to the required event handler. Unfortunately the tutorial is criminally undescriptive. The most I've found is that it has to be done during client initialization. I'm currently trying to do the necessary setup via hijacking the item registry since trying to modify the item classes directly (via using SubscribeEvent in the item's constructor didn't work. Class so far: // mrrp mrow - mcmod item painter v1.0 - catzrule ch package catzadvitems.init; import net.minecraft.client.color.item.ItemColors; import net.minecraft.world.item.Item; import net.minecraftforge.registries.ObjectHolder; import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent; import net.minecraftforge.fml.common.Mod; import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.client.event.ColorHandlerEvent; import catzadvitems.item.DyeableWoolArmorItem; @Mod.EventBusSubscriber(bus = Mod.EventBusSubscriber.Bus.MOD) public class Painter { @ObjectHolder("cai:dyeable_wool_chestplate") public static final Item W_CHEST = null; @ObjectHolder("cai:dyeable_wool_leggings") public static final Item W_LEGS = null; @ObjectHolder("cai:dyeable_wool_boots") public static final Item W_SOCKS = null; public Painter() { // left blank, idk if forge throws a fit if constructors are missing, not taking the chance of it happening. } @SubscribeEvent public static void init(FMLClientSetupEvent event) { new Painter(); } @Mod.EventBusSubscriber private static class ForgeBusEvents { @SubscribeEvent public static void registerItemColors(ColorHandlerEvent.Item event) { ItemColors col = event.getItemColors(); col.register(DyeableUnderArmorItem::getItemDyedColor, W_CHEST, W_LEGS, W_SOCKS); //placeholder for other dye-able items here later.. } } } (for those wondering, i couldn't think of a creative wool helmet name)
    • nvm found out it was because i had create h and not f
    • Maybe there's something happening in the 'leather armor + dye' recipe itself that would be updating the held item texture?
    • @SubscribeEvent public static void onRenderPlayer(RenderPlayerEvent.Pre e) { e.setCanceled(true); model.renderToBuffer(e.getPoseStack(), pBuffer, e.getPackedLight(), 0f, 0f, 0f, 0f, 0f); //ToaPlayerRenderer.render(); } Since getting the render method from a separate class is proving to be bit of a brick wall for me (but seems to be the solution in older versions of minecraft/forge) I've decided to try and pursue using the renderToBuffer method directly from the model itself. I've tried this route before but can't figure out what variables to feed it for the vertexConsumer and still can't seem to figure it out; if this is even a path to pursue.  The vanilla model files do not include any form of render methods, and seem to be fully constructed from their layer definitions? Their renderer files seem to take their layers which are used by the render method in the vanilla MobRenderer class. But for modded entities we @Override this function and don't have to feed the method variables because of that? I assume that the render method in the extended renderer takes the layer definitions from the renderer classes which take those from the model files. Or maybe instead of trying to use a render method I should be calling the super from the renderer like   new ToaPlayerRenderer(context, false); Except I'm not sure what I would provide for context? There's a context method in the vanilla EntityRendererProvider class which doesn't look especially helpful. I've been trying something like <e.getEntity(), model<e.getEntity()>> since that generally seems to be what is provided to the renderers for context, but I don't know if it's THE context I'm looking for? Especially since the method being called doesn't want to take this or variations of this.   In short; I feel like I'm super super close but I have to be missing something obvious? Maybe this insane inane ramble post will provide some insight into this puzzle?
  • Topics

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.