java - 如何让它永远是一滴石头?
问题描述
我不知道怎么做才能总有一个石头物品有一定的机会,例如有一个物品池,总共是 100%。就在玩家破坏石头时,他总是从底池中掉出一些东西。
解决方案
I think I get what you are trying to say,
You want a stone block to drop different items randomly.
To do that you will have to make an event listener class, and listen for the BlockBreakEvent.
Next, check if the block type equals the stone material.
Then make all of the possible item drops and their probability into a map. Ex. 5 Stone, 4 Iron, 1 Diamond.
Use the random class to generate a number with the max being the sum of all the probabilities and the min being 0. Then iterate through the probabilities, and get the one that is the highest probability below the random number.
Then spawn in that ItemStack and cancel the event so Cobblestone won't spawn.
推荐阅读
- oracle - How to run Hang Analyze Report in Oracle database
- node.js - Download file from GCF function
- laravel - How to extend existing token expire time for Laravel JWT
- c++ - How to set cmake option with ninja without calling vcvarsall.bat to compile x86 and x64 each of parent and child project?
- asp.net - How to know what exactly who/where process run queries in SQL server
- python - Tensorflow how do I reshape array of images properly for model prediction input
- laravel - "GET method is not supported for this route" even though it's a POST route
- if-statement - 位操作的 Codesys IF 语句错误
- javascript - How To convert UTC into local time on the web with javascript? from http://openweathermap.org/
- java - 在 java 中,使用 Runtime Exception 作为函数调用的超级“突破”是不好的做法吗?