[ Tutorial ] Mobs with custom trades!

Started by AidenR0 on

Topic category: User side tutorials

Last seen on 11:52, 29. Sep 2021
Joined Apr 2020
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
[ Tutorial ] Mobs with custom trades!

Hello everyone! I've recently released Yggdrasil, a mod that adds quite a bit of content to the game. (You can view it here)

I thought I might make a quick tutorial on how to make mobs that you can trade with! Same way to how I made the Gnome mob in Yggdrasil. Here it goes:

1) First off, make your mob, give it all the parameters you want, custom model, textures, and all that. 

2) Create a custom GUI, you can mess around with how you want the GUI to look like, but I made it look like so:
 

gui

Slot number 00, 01, and 02 are normal GUI slots, make sure to set it to drop items if the inventory is closed

gui

Slot number 04 and 03 are the same, except that you need to disable the interaction with them. 

gui

(The arrow is just an image I imported into the GUI) 

Now create two buttons, Next and Trade. 

  • Trade Button: Create a new procedure when the button is clicked, call it whatever you want. Then add these blocks into the procedure:procedure

    An If and Do statement is added, then in the If statement, add an item = item block, from the Logic tab. Then in the first parameter, add a "Get item from slot" procedure block. This will check for the item in slot 0 in the GUI we just made. Then on the second parameter, add an item block from Minecraft Components, and add your item of trade. For me, it is coins, so I added a bronze coin. Basically, this will check for whether the required trade item is available in the slot. 
    To check for more a number of items, it will be like so:
    procedure

    You need to add an And statement to the If parameter. In the second block of the AND statement, add a comparation block, with the first parameter set to [Get number of items from slot..], Make sure that it's set to > or bigger, not just > in it. In the second parameter, add a number block with your desired amount of trade. (5 coins here, to buy something for example.)

    Then in the DO area, add a block that removes the same amount of time we just chose earlier, from the same slot as well. Then add another block that sets the product we just bought with the amount of coins. Add a "SET" procedure block, move away the [1] from after the "SET" , and add a maths (+) block, in the first parameter, "Get number of items in: Get item from slot [2]..etc" And in the second parameter, add a number block with the amount of how much you want the player to get for the price. In the first example, it's one coin for one Glenola, in the second, it's 5 coins for 5 Leprons (Both are custom elements in my mod). It doesn't have to be equal, you can set 4 coins for, well, 64 diamonds if you wish so. 

    The reason why we set the SET block like so is because if the player clicks Trade more than one time, the items in the 02 slot will build up to how much he paid. Instead of just being stuck at whatever the amount we set.
     

  • Next Button: The Next button simply opens up the second trade GUI, which you will create and do the same thing we did all over again in the previous GUI. Make a procedure that opens up the second GUI for this. It's easy and simple.

  • Back Button: Now when you go to the second page, I added a "Back" button that goes back to the previous page, same as the Next button, simply a procedure upon clicking that opens up the previous GUI. (Found in the GUI tab in the procedure window)
     

Important: Now that we got the trading set up, how do we show the players what they are trading for? Surely we don't want them to trade blindly. Here slots number 04 and 03 come into play. 

  • What these slots do is show us what will we trade for. Saving us the hassle of importing images into MCreator and adding a number and all that. What you need to do is first create 2 procedures, one on while this GUI is open tick, and one when the GUI closes.
    - For the first procedure, the Open Tick one, here's how it looks like:procedure

    Add in two procedure blocks here, both are to set elements in slots 03 and 04. You can decide how many items are also present for example. (In the example above, 3 coins for 1 Glenola)

  • In the second procedure, the GUI closes one, do this. VERY IMPORTANT:
    Add in these blocks to clear the slots of what they have, this is important as to prevent the view items from going into the player's inventory when they close the GUI. 
     

    procedure

 

 

Now that we've got everything set up nice and working, we need to assign the trade GUI to the mob, simply add this procedure block when the player is right clicked:
 

procedure

Maker sure that you change the "Open screen for Event/Target Entity" to "Source Entity." Otherwise this won't work.

 

And that should be it! You can add randomizers for this to make the trade less static, but personally there aren't that many trades yet for my mob so it wasn't needed.

If you have any questions, feel free to let me know! I'll try my best to reply.

 

Last seen on 14:11, 17. Oct 2021
Joined Oct 2021
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
where is the and statement
Tue, 10/12/2021 - 23:05

where is the and statement

Last seen on 14:48, 21. Jan 2023
Joined Mar 2021
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
whenever i try to make the…
Sat, 01/21/2023 - 14:10

whenever i try to make the next button, it says i need a world dependency. any help?