1. 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!

  2. LOOKING FOR A VERSION OF SKRIPT?

    You can always check out our Wiki for downloads and any other information about Skript!

Dismiss Notice
This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Solved Remove certain trades from villagers

Discussion in 'Skript' started by Radicc, Oct 7, 2022.

Tags:
  1. Radicc

    Radicc New Member

    Joined:
    Oct 7, 2022
    Messages:
    6
    Likes Received:
    0
    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
     
  2. Pierrelasse

    Pierrelasse Active Member

    Joined:
    Apr 20, 2022
    Messages:
    114
    Likes Received:
    4
    Idk
     
    • Agree Agree x 1
  3. Radicc

    Radicc New Member

    Joined:
    Oct 7, 2022
    Messages:
    6
    Likes Received:
    0
    please only answear if you know how to fix it i got so hyped when i saw there was a answear
     
  4. lotzy

    lotzy Active Member

    Joined:
    Mar 15, 2022
    Messages:
    138
    Likes Received:
    22
    Anyway pure skript again cant make this thing, but Skript-reflect.
    Code (Text):
    1. import:
    2.     org.bukkit.event.inventory.InventoryType
    3.     org.bukkit.inventory.MerchantRecipe
    4.     java.util.ArrayList
    5. on inventory open:
    6.     if event.getView().getType() is InventoryType.MERCHANT:
    7.         set {_merchant} to event.getInventory().getMerchant()
    8.         set {_recipes} to new ArrayList()
    9.         loop ...{_merchant}.getRecipes():
    10.             if loop-value.getResult() is not emerald:
    11.                 {_recipes}.add(loop-value)
    12.         {_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 (Text):
    1. set {_newrecipe} to new MerchantRecipe(%item%, %number uses%, %number max uses%, %boolean give exp?%, %number amount of villager exp?%, %number price multiplier%)
    2. {_newrecipe}.addIngredient(%item%) #first ingredient
    3. #{_newrecipe}.addIngredient(%item%) # second ingredient
    4. {_recipes}.add({_newrecipe})
    5.  
    6. #example
    7. set {_newrecipe} to new MerchantRecipe(dirt,0,5,true,10,2)
    8. {_newrecipe}.addIngredient(sand)
    9. {_recipes}.add({_newrecipe})
    Again, read the docs, make your's ideas great. gl

    [ArrayList docs]
    [merchant docs]
    [recipe docs]
     
    #4 lotzy, Oct 13, 2022
    Last edited: Oct 13, 2022
    • Friendly Friendly x 1

Share This Page

Loading...