首页 > 解决方案 > 如何让它永远是一滴石头?

问题描述

我不知道怎么做才能总有一个石头物品有一定的机会,例如有一个物品池,总共是 100%。就在玩家破坏石头时,他总是从底池中掉出一些东西。

标签: javabukkit

解决方案


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.


推荐阅读