Optimized Weighted Random Dungeon Selection
Optimized the selection of random dungeons with weights applied. We now have a class called WeightedContainer for taping into Minecraft's weighted selection code without having to extend the WeightedRandomItem class. Using that, we no longer need to keep a list with duplicate dungeons to achieve weighted selection, so I removed that variable.
This commit is contained in:
27
StevenDimDoors/mod_pocketDim/util/WeightedContainer.java
Normal file
27
StevenDimDoors/mod_pocketDim/util/WeightedContainer.java
Normal file
@@ -0,0 +1,27 @@
|
||||
package StevenDimDoors.mod_pocketDim.util;
|
||||
|
||||
import net.minecraft.util.WeightedRandomItem;
|
||||
|
||||
/*.
|
||||
* Implements a simple generic item for using net.minecraft.util.WeightedRandom with objects of type T.
|
||||
*
|
||||
* This is generally useful for cases in which we already extend an existing class, which prevents us from also
|
||||
* extending WeightedRandomItem or cases in which we would have to break compatibility with previous serialized
|
||||
* instances to add support for WeightedRandomItem.
|
||||
*/
|
||||
public class WeightedContainer<T> extends WeightedRandomItem {
|
||||
|
||||
private T data;
|
||||
|
||||
public WeightedContainer(T data, int weight)
|
||||
{
|
||||
super(weight);
|
||||
this.data = data;
|
||||
super.itemWeight = weight;
|
||||
}
|
||||
|
||||
public T getData()
|
||||
{
|
||||
return data;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user