Solved Remove certain trades from villagers

  • Welcome to skUnity!

    Welcome to skUnity! This is a forum where members of the Skript community can communicate and interact. Skript Resource Creators can post their Resources for all to see and use.

    If you haven't done so already, feel free to join our official Discord server to expand your level of interaction with the comminuty!

    Now, what are you waiting for? Join the community now!

  • LOOKING FOR A VERSION OF SKRIPT?

    You can always check out skUnity Downloads for downloads and any other information about Skript!

Status
Not open for further replies.

Radicc

Member
Oct 7, 2022
17
0
1
18
Hi. I made so you cant craft harming arrows but you can still get them with a villager trade. Is there a way to remove the trade and keep the other trades? Skript version: 2.6.2
 
Hi. I made so you cant craft harming arrows but you can still get them with a villager trade. Is there a way to remove the trade and keep the other trades? Skript version: 2.6.2
Anyway pure skript again cant make this thing, but Skript-reflect.
Code:
import:
    org.bukkit.event.inventory.InventoryType
    org.bukkit.inventory.MerchantRecipe
    java.util.ArrayList
on inventory open:
    if event.getView().getType() is InventoryType.MERCHANT:
        set {_merchant} to event.getInventory().getMerchant()
        set {_recipes} to new ArrayList()
        loop ...{_merchant}.getRecipes():
            if loop-value.getResult() is not emerald:
                {_recipes}.add(loop-value)
        {_merchant}.setRecipes({_recipes})
Some text for understand:

ArrayList
is like skript list, but its java type. Its needed because function '.setRecipes()' accepts types inherits from 'java.util.List', but in most cases Skript-reflect automatically convert skript types to java types.

Function '.getRecipes()' return immutable collection, so we cant edit this, but we can create our collection of recipes.

In this example I simply doesn't add to new list all recipes where result is emerald, but u can write what you want and much more.

After put all needed recipes we change current recipes of villager with function '.setRecipes(%java list%)'
You can also add your's recipes by create new recipes somethig like that:

Code:
set {_newrecipe} to new MerchantRecipe(%item%, %number uses%, %number max uses%, %boolean give exp?%, %number amount of villager exp?%, %number price multiplier%)
{_newrecipe}.addIngredient(%item%) #first ingredient
#{_newrecipe}.addIngredient(%item%) # second ingredient
{_recipes}.add({_newrecipe})

#example
set {_newrecipe} to new MerchantRecipe(dirt,0,5,true,10,2)
{_newrecipe}.addIngredient(sand)
{_recipes}.add({_newrecipe})
Again, read the docs, make your's ideas great. gl

[ArrayList docs]
[merchant docs]
[recipe docs]
 
Last edited:
Status
Not open for further replies.