Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

Player-based Crafting Recipes


Recommended Posts

Sure one can.

I phrased it wrong.

I was saying something like 'portable crafter' is surely in player's inventory, but I think it is impossible with this way.

EDIT: In IRecipe#getRemainingItems(InventoryCrafting crafting), one can use ForgeHooks#getCraftingPlayer().

But there are no general way on other cases.. So the way of tutorial would be best for the case.

I. Stellarium for Minecraft: Configurable Universe for Minecraft! (WIP)

II. Stellar Sky, Better Star Rendering&Sky Utility mod, had separated from Stellarium.

Link to post
Share on other sites
  • 1 year later...

Considering how you updated your post for 1.12, I thought you might want to do it for 1.14 as well:

 

In 1.14, the WorkbenchContainer also has a "player" field, so the detour over the slot is no longer needed.

 

Instead of using reflection, I used access transformers for the CraftingInventory's container field (called field_70465_c) as well as the PlayerContainer's and WorkbenchContainer's player field:

 

In accesstransformer.cfg:

public net.minecraft.inventory.CraftingInventory field_70465_c # container of CraftingInventory, used for conditional crafing recipes
public net.minecraft.inventory.container.PlayerContainer field_82862_h # player of PlayerContainer, used for conditional crafting recipes
public net.minecraft.inventory.container.WorkbenchContainer field_192390_i # player of WorkbenchContainer, used for conditional crafting recipes

 

The findPlayer method can then be changed as follows:

private static PlayerEntity findPlayer(CraftingInventory inv) 
{
	try 
	{
		Container container = inv.field_70465_c;
		if (container instanceof PlayerContainer) 
		{
			return ((PlayerContainer) container).player;
		} 
		else if (container instanceof WorkbenchContainer) 
		{
			return ((WorkbenchContainer) container).player;
		} 
		else 
		{
			// don't know the player
			return null;
		}
	} 
	catch (Exception e) 
	{
		throw Throwables.propagate(e);
	}
}

 

Link to post
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.

Guest
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.



×
×
  • Create New...

Important Information

By using this site, you agree to our Privacy Policy.