Opened 4 years ago

Last modified 4 years ago

#58 accepted enhancement

Villager Economy System

Reported by: jonathan Owned by: jonathan
Priority: major Component: Blocks and Items
Version: 9.0.x-Orange Keywords:
Cc: indianwells, kevin

Description (last modified by jonathan)

Preamble

The purpose of this ticket is to introduce an economy system or manager that alters supply and cost of goods offered by villagers given certain market drivers most typically being demand and sale frequency.

Please discuss this idea here using the comments on this ticket. Think about some of the issues raised by this idea and post your thoughts and ideas about how to handle these here using this ticket.

Supply and Demand Controls

It seems to be agreed that villager offers should be influenced / driven by the frequency an item is bought or sold:

  1. If an item is bought from a villager the cost of that item increases
  2. If an item is sold to a villager the offer amount should decrease

Issues to Consider

  1. When the buy/sell price is altered due to these drivers, should that buy/sell price change for the...
    1. Villager?
    2. Region?
    3. Globally?
  2. What happens when the price gets too high or too low?
  3. What is the definition of too high or too low?

Currency Used

Presently the villagers accept items in exchange for other items, they have no concept of currency.

Issues to Consider

  1. The concept of currency exchange to be abolished, and should villagers just accept whatever coins you have so long as they add-up to the amount desired / needed?
  2. Currency be treated as an entity separate from trading items?

New Trader Entity

Rather than modify the villagers, introduce a new entity type exclusively designed for buying/selling goods using currency instead of in-game items.

Issues to Consider

  1. What do we do with all the villagers then? are they to become technical debt?
  2. What would the new entity look like? should it have any resemblance to villagers?
  3. Isn't this still too redundant? wouldn't it be more sensible to modify the existing villagers?

Rarity

Not all items are created equal, dirt is literally dirt cheap and diamonds or rhenium ingots are extremely expensive. This implies two things for each item based on its rarity:

  1. A starting / initial cost
  2. The rate of increase / decrease for each item

Issues to Consider

  1. Is the rate of increase / decrease related to the initial cost? or is there any reason they could be independent?
  2. Does the rate of increase / decrease change? or is it fixed based upon rarity?
  3. How are initial values for each item going to be calculated?

Price Point

How should the initial prices be calculated? it seems there are different categories of items and price pointing everything may be unnecessary:

  1. Refuse - Dirt and netherrack probably fall into this category, generally things that have very little use and are abundant
  2. Quest - Items that pertain to quests and should probably never be sold or even exchanged between players
  3. Adventure - Blocks and items that are very focused and specific to mini-games and side-quests such as the construction materials used by towers in the Twilight Forest.
  4. Ingredients - Anything that is an important ingredient for some recipe
  5. Valuable - Anything that can be considered valuable such as gold bars or gem stones
  6. Food - Edible items for sustenance
  7. Tools - Tools for mining or digging etc.
  8. Armaments - Weapons and armor

Issues to Consider

  1. Should everything have a price point?
  2. How is it possible to price point absolutely every item?
  3. Is it possible to price point entire categories instead of price pointing a bazillion items individually?
  4. Should only an initial and small subset of items be made available for sale?

Attachments (1)

villager-currency-exchange.png (46.0 KB) - added by jonathan 4 years ago.
Preview of Villager Built-in Currency Exchange

Download all attachments as: .zip

Change History (12)

comment:1 Changed 4 years ago by jonathan

  • Cc indianwells kevin added

comment:2 Changed 4 years ago by indianwells

Does this mean that if you are the first person to buy everything, it will make everything more expensive for the next person? Say something that is technically really cheap like dirt, if I buy a ton of dirt, I feel like that price should not necessarily go up since its "dirt".

comment:3 Changed 4 years ago by jonathan

  • Description modified (diff)

Even the price of dirt can increase / decrease, but it can happen slowly. For example, if dirt costs one copper each, consider that it can double to two copper each after someone has bought 100 stacks of dirt or something.

So this implies that each item should increase / decrease by different rates depending on rarity. In fact, I forgot to introduce that concept.

comment:4 Changed 4 years ago by indianwells

Just thinking now, so we would have to price point every single item?

comment:5 Changed 4 years ago by jonathan

  • Description modified (diff)

I don't think we should price point everything, some items don't even make sense for sale IMO. I'm going to update the description again. This will be a living document.

comment:6 Changed 4 years ago by indianwells

I am going to make a list of items that I am pretty sure are not at the trading port already and start there. It would be good to have a document/spreadsheet that we can all have access to and view/edit together.

comment:7 Changed 4 years ago by kevin

I am going to spitball all my ideas just to get them out so we can evaluate them. Keep the good and dich the impractical and bad ones.
Part one: Data collection
The first most important question is to ask what info can be easily pulled from the game? I have thought about this a lot over the years and wondered in great detail on how to make this work as automated as passable, yet still be functional and dynamic.

  • Does the game give total number of entities, items and blocks in the world?

o How is this info distributed? Such as can we know it based on chunks or is a flat number for the word.
o To get this info do you have to calculate it each time or it is it already actively kept in the word file just waiting to be referenced?
o Can we know what is in a player’s inventory? I know there is a json file with all this data ripe for the picking.
o Do we get to know what items are kept in chests?
o Does it keep track of entities that are dropped, but not de-spawned?
o Do we have records such as what regen the item comes from (World, nether, end, etc..¬)
 Has anyone activate that world yet. If no one has been to the end then perhaps end items are unavailable for sale.
Next we need to need to know different stats about every entity, item and block that the game will give us. This is mostly an addition look to the section Jonathan has under Price Point, but from the perspective of getting the data.

  • Is the item craftable
  • Is it a quest item
  • Does the item have to be mined, farmed or found?
  • Is this only available via creative mode or commands.
  • Is the item a high consumable thing like food and arrows?

Part two: Practical application of data for use in auto item base value
Each attribute listed below would crease a score that would then be weighted against the other attributes to create a total value that would then be used as the Baseline value for the price of the item. The best part is, once setup very little to no effort would need to be collected by a person as most of this would be pulled from existing data within the game. This data does change slowly over time so the base price would be organic keeping things interesting.

  • Finding the Base value of an item

o For example, a single chunk contains the potential for 65,536 blocks. Let’s say there is 25,000 blocks of dirt, but only 25 blocks of Clay. Sure, the Clay is worth more than dirt, but is worth 1,000 times more? I would pay 1,000 times more for clay then dirt. So this metric is very useful for a starting value point.
o How many of the item are found in the world as placed item?
 A comparison between the world and the local area would be useful as we can use this to create a reginal offset.
 Is the item a dropped entity?
 Does the item fall from a mob/critter

  • If so then how many of them are found in the world. Use that number in stead.
  • If it is a Mob that can de-spawn then it would not even use the number of mobs found, instead reference to spawn chance number found in the code.

o How many are found in chests and on players
 This has a higher weighed value then untouched item in the world
o If an item is only craftable or available via commands then it comes with fixed weighted offset so account for its false rarity A good way to do this would be to average out the value of its base components instead of counting its value.
 Then give it an offset based on the crafting difficulty

  • Scale from lowest bonus to highest Person crafting, crafting table, Quern, Furnace, Refractory furnace, etc.
  • This could also further be offset by the availability of crafting tools found in the regen. Such that if no Refractory furnaces exist then the cost would be much higher then if lots of them are found close by and that is what is needed to make the item.

o Apply the items intrinsic value to it
 This would be a manual added attribute such as (Refuse, Generic, Useful, Needed, Great, Epic, Uncategorised)

  • All items in a category would have their values averaged and that would create benchmark that can be used to override a value of an item that does not have enough meaningful data to create a useful base value with
  • A use case example where this could help is when we make an item that can only be found at a vendor. So, it comes with no meaningful base data. We would then use one of the listed categories to decide its base and then later provide a slight offset to give its unique price point.
  • It will also be used later on for the default Min/Max? values calculation.

o Consumability and usability rate
 All items have a use for something, even if it is wasting your time as you look for some lava to toss it into. This would be a value given to the items to determine how mush a person will need of it and how quickly they will go through it. This would be simplest to do in the form of creating a number range such as 1 high and 0.01 being low. The higher the number for consumability the cheaper it would be.

  • Food for example would have a very high consumability making its value less, where as a Rudameter never breaks so you only ever need one of them, so its value would be quite high. Brick buildings last a long time so it would also have a lower consumability number making its value greater. Gravel roads always need repair for some odd reason so it would have a moderate value level.
  • How to use the numbers. After all each of the values collected above will come out to wildly different numbers and values for each category. The next challenge will be to find a way to apply context to each value in an automated way.

o This is hard to estimate without seeing some of the raw outputs. Once we have the raw outputs, we can then use them to decide how they will compare to one another in a weighted way. It’s the fine art of taking an apple, orange and donkey then making meaningful comparisons between them to get a usable number to work with.
o Lets make up an item and see how the process works for it by gestemate what the data would look like and imagine how this might work for bringing it into one meaningful number.
 Lets call the pretend example item moderite. In the world it is plentiful (250K total, but average of 12 per chunk), in the local regen (surrounding local area averaged out for a single chunk comparison) it has 134 blocks placed, 12 in chests and 2 on players. It does not drop from mobs, so that value is Null and not counted. It is both craftable by hand and findable in the world. Its intrinsic value is Needed and its Consumability rating is moderate.

  • We then take all this info and find some way to collate it.
  • World Number = 12
  • Local Number = 134
  • Local chests = 12
  • Players = 2
  • The numbers above would then combine using various weighting to produce a world availability value of say 17.
  • It is also craftable so it would have its base crafting items values taken into consideration. Lets say that value is 25.

o It can be crafted by hand so only one point subtracted from it for the inconvenientnes of making it. Something like needed a refractory furnace might reduce between 20 and 200 to an item depending on how many of them are found in the area.
o The lower the number for this the rare an item is so the more valuable it becomes.
 This number will be inverted from low to high. To do that we check the min/max by finding the highest and lowest numbers for all the items in the world then use an items inverse value for the price.

  • So, its overall world availability after inverse comes to say 52 silver.
  • Because its intrinsic value is needed and the average values for needed items comes to 1 gold. This gets a re-adjustment offset of some arbitrary percentage we decide when seeing the numbers. This brings its value up to 57 silver.
  • Its Consumability is moderate and that has 0% price adjustment.
  • Therefor, our pretend item has the base value of 57 silver.

o I don’t think the base value numbers should auto recalculate dynamically to prevent extra strain on the server. Perhaps once a real day. The base numbers would not realistically change much anyways perhaps a few coppers a day on a valuable item.
 Well unless Tanya is involved, after all when she crafts, she does it in bulk!

comment:8 Changed 4 years ago by jonathan

Part one: Data collection

Has anyone activate that world yet. If no one has been to the end then perhaps end items are unavailable for sale.

Yeah this is good, we should definitely respect the tech-tree as much as possible.

  • Is the item craftable
  • Is it a quest item

I think quest items should be excluded from the economy and probably made player-bound too

  • Does the item have to be mined, farmed or found?

See below

  • Is this only available via creative mode or commands.

These items should be excluded from the economy since it implies they are not meant for survival mode and I think a villager economy makes no sense in creative mode since you have everything for free anyway.

  • Is the item a high consumable thing like food and arrows?

Every item that is consumable (to some degree, whether high or low) could be tracked using a numeric rating.

I see this as being broken down into three flags:

  • Reagent - is an ingredient of some recipe
  • Product - is a product of some recipe
  • Consunable - can be consumed or used as is (without crafting)

Some items will have just one of these flags, some will have a combination of all three and some will have all three of these flags. Here are some examples I can think of:

Name Description Reagent Product Consumable
Cat Whisker Detectorinterim crafting ingredient for redstone devicesXX
Top Grain Leatherused for making backpacksXX
Leather X
Rotten Fleshthere's a silly Biomes 'o Plenty recipe that lets you craft rotten flesh from regular flesh and a vial of poison extract, useless otherwise X
Arrows XX
Dirtmaybe consumable, it has some use X
Tower BlockThe materials that make-up the fortresses in Twilight Forest, only available in creative mode and not meant to be used by players
Sandnot really useful until you craft something from itX
Tomatoes X X
Quest itemdepends on the quest, but usually these items should not be craftable nor be reagents in a crafting recipe X
Burnt foodwhat happens if you leave food to cook in a dry cooking cauldron? X
Slagresult of using the alloying kiln incorrectly X
Hasha meal of carrots and potatoes, can also be used to make LatkesXXX

Additionally I would argue that most blocks that are only available in creative mode are going to have none of these flags since they are not meant to be used in survival mode or they are part of procedurallly generated constructs (e.g. end portal)

Part two: Practical application of data for use in auto item base value

These algorithms are potentially very expensive, so it will require a lot of creativity to figure-out how to pull them off without bringing the server to its knees. I think some of these variables can be static (pre-computed and delivered as fixed values with the mod) and some can be dynamic (continuously re-computed during gameplay)

  • How many of the item are found in the world as placed item?

These might be called Natural items.

  • A comparison between the world and the local area would be useful as we can use this to create a reginal offset.

Let's call this Locality, this should be measured on a chunk-by-chunk basis rather than block-by-block.

  • Is the item a dropped entity?
  • Does the item fall from a mob/critter
    • If so then how many of them are found in the world. Use that number in stead.
    • If it is a Mob that can de-spawn then it would not even use the number of mobs found, instead reference to spawn chance number found in the code.

We can call all of the above Drops but there is indeed a distinction between mobs that can despawn and mobs that cannot. Generally mobs that can despawn are infinite (Zombies, Jakkers, slime blobs) and those that cannot despawn are finite (sheep, cows, chickens). Drops from mobs that can despawn should be considered abundant and common whereas drops from mobs that do not despawn normally should be considered scarce and/or limited.

  • How many are found in chests and on players

This could be fun to implement, this would denote items that are considered Gathered whether harvested or crafted.

  • This has a higher weighed value then untouched item in the world

Yes

If an item is only craftable or available via commands then it comes with fixed weighted offset so account for its false rarity. A good way to do this would be to average out the value of its base components instead of counting its value.

Determining valuation from crafting recipes could prove to be quite useful, but the implementation would be tricky. We would have to be careful not to get stuck in infinite loops because some recipes are cyclic. Additionally, there are so many recipes that we would want to make sure that this is only done once during start-up. If the scan takes more than a few seconds then we should re-evaluate whether this approach is worth it (when waiting for Minecraft to load, 5 seconds is a small eternity).

As mentioned before I would also argue that items only available in creative mode or via commands should be excluded from the economy system altogether presupposing that the economy system is a survival-mode-only system. If anyone can think of an example or reason otherwise then we should document those reasons. For example, if you want to create your own end portal then you would do that in creative mode. Doing that in survival mode by making it purchasable makes the overall gameplay mechanics held hostage to the economy system, which is a lot of burden on the economy system to maintain global balance. Generally, placing something as significant as an end portal might require operator / moderator approval, and they will have access to creative mode anyway.

Then give it an offset based on the crafting difficulty.

  • Scale from lowest bonus to highest Person crafting, crafting table, Quern, Furnace, Refractory furnace, etc.
  • This could also further be offset by the availability of crafting tools found in the regen. Such that if no Refractory furnaces exist then the cost would be much higher then if lots of them are found close by and that is what is needed to make the item.

It would be nice to make the economy system mod-independent so that it doesn't have to be aware of things such as querns and refractory furnaces. Additionally, looking around the world for crafting stations is a computationally-intensive task. Now, we could leverage the clients to do a lot of this work for us, but that doesn't solve the problem of making the economy system mod-independent. The other problem is that every crafting station is different and has different code for processing recipes, so there's no reliable way to determine how things are crafted (and what ingredients are involved) at a crafting station.

Sometimes it's not really possible to make things truly mod-independent, so what we do then is export a configuration file that allows a mod-packer to customize the mod a little bit and make explicit exceptions without being a mod developer. Olivine works this way now, go ahead and take a look at the default Olivine configuration file, it's already huge. Actually don't even bother, I can link to it right here and now

  • Apply the items intrinsic value to it
    • This would be a manual added attribute such as (Refuse, Generic, Useful, Needed, Great, Epic, Uncategorised)

These categories are great, in fact we don't even need to get these perfect, they just have to be good enough to accurately describe 90% of the items with valuations. The hard part is assigning items to these categories.

All items in a category would have their values averaged and that would create benchmark that can be used to override a value of an item that does not have enough meaningful data to create a useful base value with

That could be very powerful and time-saving

A use case example where this could help is when we make an item that can only be found at a vendor. So, it comes with no meaningful base data. We would then use one of the listed categories to decide its base and then later provide a slight offset to give its unique price point. It will also be used later on for the default Min/Max?? values calculation.

  • Consumability and usability rate
    • All items have a use for something, even if it is wasting your time as you look for some lava to toss it into. This would be a value given to the items to determine how mush a person will need of it and how quickly they will go through it. This would be simplest to do in the form of creating a number range such as 1 high and 0.01 being low. The higher the number for consumability the cheaper it would be.

Alternatively we might want to consider having coarse categories to describe this, it depends on what makes the code easier to follow / implement when we cross that bridge, it could also make the code more complex, it's hard to know until we get closer to implementation. If we do determine that coarse categories are more appropriate then I would propose the following:

Name Description Examples
refuseGarbage, you typically just toss it into lavadirt, rotten flesh
essentialsFood, weapons and armor, bare essentials that concerns your bodyvegetables, meat, iron swords, leather armor
constructionThis can be essential, but it does not involve your body. Digging a hole in the ground and burying yourself during the night does not fall into this category, but building a house from stone and wood does fall into this categorycobblestone, wooden planks
boostThings that boost the performance / efficiency / appearance of existing items, generally these items are only available post-early gamestone brick, polished diorite, speed potion, enchanted pickaxe, horse armors, orb staff
luxuriesGenerally end-game equipment and items and completely unnecessary for survival other than to make something aestheticpolished malachite, gold blocks, ruby blocks, galactic radio tuner

Food for example would have a very high consumability making its value less, where as a Rudameter never breaks so you only ever need one of them, so its value would be quite high. Brick buildings last a long time so it would also have a lower consumability number making its value greater. Gravel roads always need repair for some odd reason so it would have a moderate value level.

Some of these justifications are based on our own gameplay and not how others would play. For example, people on another server might insist on using sandstone for their lengthy roads and think gravel is junk. For use cases like these we would have to find a way to gauge player demand in real-time. The Ruddimeter is an excellent example of an item that you only typically need one of, in fact you could argue it is not consumable at all other than the fact you could lose it and need to craft a new one.

Lets make up an item and see how the process works for it by gestemate what the data would look like...

So to summarize, you have the following variables you want to account for:

  • Global / world item count
  • Item count restricted to locality or according to locality
  • Stored item count (chests) also according to locality
  • Carried by players

And additionally there is a flag to determine if an item is craftable from other items.

Something like needed a refractory furnace might reduce between 20 and 200 to an item depending on how many of them are found in the area.

I like this algorithm, it's a challenge to implement efficiently without being computationally expensive, will need to brainstorm the actual implementation more. As I mentioned before it is not easy to determine what is a crafting station and what isn't if you're trying to be mod-independent. The simplest way to work-around this is to require that mod packers explicitly declare these things in a configuration file.

I don’t think the base value numbers should auto recalculate dynamically to prevent extra strain on the server. Perhaps once a real day. The base numbers would not realistically change much anyways perhaps a few coppers a day on a valuable item.

A one-shot update would probably stall the server until it completes, this would annoy players who are currently online playing. This might not be an issue if it's done at 4am but 4am is 1pm in France when a lot of people would be playing. It's much more complicated and harder to pull off but it would be more efficient to incrementally recompute these values bit by bit throughout the day. Since you understand your algorithms best right now, can you think of a way this might be done? to partially update and recompute base values? perhaps compute one base value for one particular item at a time?

comment:9 Changed 4 years ago by jonathan

Incidentally I just discovered something really cool, we can import textures from the mod directly here, here's the Ruddimeter: source:/Primary/src/main/resources/assets/mmm/textures/items/ruddimeter.png

Source: [[Image(source:/Primary/src/main/resources/assets/mmm/textures/items/ruddimeter.png)]]

Changed 4 years ago by jonathan

Preview of Villager Built-in Currency Exchange

comment:10 Changed 4 years ago by jonathan

I made some improvements slated for 9.1.9-Orange that will bring us one step closer to this, it's a built-in currency exchange model for each and every villager trade. Here is a sneak peek:

Preview of Villager Built-in Currency Exchange

The up/down and page-up/page-down buttons basically make the trading system convert your coins automatically prior to placing the coins in (or taking them out of) the trade slots.

Last edited 4 years ago by jonathan (previous) (diff)

comment:11 Changed 4 years ago by jonathan

  • Status changed from new to accepted

I've started work on this, for now I will implement a timeout for trades. Villager trades are capped at 37 right now, that will timeout and refresh after a predefined time limit. We can improve on this as the Economy System grows.

Note: See TracTickets for help on using tickets.