[Suggestion] [1.19]: Support for custom usage/craft triggers
Speiger opened this issue ยท 2 comments
Suggestion
o/
I have a gui that doesn't have traditional slots, because it is way to modular to achieve normal slots...
(Crashes would happen way to likely)
So would there be a way to add a "callback" where you can provide objects when the usage/craft request comes from the player?
If not that would be a feature request.
Found a way to do it.
For everyone who wants to do it.
Just manually trying to find JEIs Keybindings and comparing them to the keys being pressed (no mouse support but who cares)
And then I just call these 2 functions
@Override
public boolean triggerRecipe(ItemStack stack)
{
JeiRuntime time = Internal.getRuntime().orElse(null);
if(time == null) return false;
time.getRecipesGui().show(time.getJeiHelpers().getFocusFactory().createFocus(RecipeIngredientRole.OUTPUT, VanillaTypes.ITEM_STACK, stack));
return true;
}
@Override
public boolean triggerUsage(ItemStack stack)
{
JeiRuntime time = Internal.getRuntime().orElse(null);
if(time == null) return false;
time.getRecipesGui().show(time.getJeiHelpers().getFocusFactory().createFocus(RecipeIngredientRole.INPUT, VanillaTypes.ITEM_STACK, stack));
return true;
}
Gui Code
@OnlyIn(Dist.CLIENT)
public KeyMapping getKey(String name)
{
for(KeyMapping binding : Minecraft.getInstance().options.keyMappings)
{
if(binding.getName().equals(name)) return binding;
}
return null;
}
@Override
@OnlyIn(Dist.CLIENT)
public boolean onKeyTyped(int keyCode)
{
KeyMapping mapping = getKey("key.jei.showRecipe");
if(mapping != null && mapping.getKey().getValue() == keyCode)
{
ItemStack result = create(lastMouseX, lastMouseY);
if(!result.isEmpty() && JEI_PLUGIN.triggerRecipe(result)) return true;
}
mapping = getKey("key.jei.showUses");
if(mapping != null && mapping.getKey().getValue() == keyCode)
{
ItemStack result = create(lastMouseX, lastMouseY);
if(!result.isEmpty() && JEI_PLUGIN.triggerUsage(result)) return true;
}
return false;
}