HOW TO: Sell things for XP.

Started by Levi Kornelsen on Tue, 09/13/2016 - 04:05

Topic category: Advanced modding

Last seen on 14:36, 23. Sep 2017
Joined Mar 2016
User points:


  • Comments:
  • Forum topics:
  • Modifications:
  • Wiki pages:
HOW TO: Sell things for XP.
Tue, 09/13/2016 - 04:06 (edited)

If you have a block, item, or GUI where you want someone to get given an item for an XP cost, set it up so that when they right-click or press the button or do whatever, it then runs this custom code (edited to suit):


        if(entity.experienceLevel >= 2){
            entity.inventory.addItemStackToInventory(new ItemStack(Items.EXPERIENCE_BOTTLE, 1));


There are two main edits you'll want to make.

First, decide the answer to "How many XP levels should this cost?", and put that amount in the first line and last line, replacing the number "2" in the example.  The first line is there to make sure they have enough XP to do the transaction; the last line is there to take away the levels.

Second, decide what they get for those levels, and put that in place of "Items.EXPERIENCE_BOTTLE" in the example; make sure you're using the right name (there are lots of lists of the names out there).  Also, if they should get more than one of the item, just replace the "1" in that middle bit (which is actually all one line) with however many they should get.

If you're feeling advanced, you can replace the middle line entirely with another one that does whatever other thing you want to charge XP for.


Edited by Levi Kornelsen on Tue, 09/13/2016 - 04:06