4jcraft/targets/minecraft/util/WeighedRandom.h
Tropical dd93cfe91e
Some checks are pending
Build (Linux, x86-64) / build-linux (push) Waiting to run
Format Check / clang-format (push) Waiting to run
format everything
2026-04-01 13:48:29 -05:00

36 lines
1.1 KiB
C++

#pragma once
#include <vector>
#include "java/Random.h"
// 4J - this WeighedRandomItem class was a nested static class within
// WeighedRandom, but we need to be able to refer to it externally
class WeighedRandomItem {
friend class WeighedRandom;
protected:
int randomWeight;
public:
WeighedRandomItem(int randomWeight) { this->randomWeight = randomWeight; }
};
class WeighedRandom {
public:
// 4J - vectors here were Collection<? extends WeighedRandomItem>
static int getTotalWeight(std::vector<WeighedRandomItem*>* items);
static WeighedRandomItem* getRandomItem(
Random* random, std::vector<WeighedRandomItem*>* items,
int totalWeight);
static WeighedRandomItem* getRandomItem(
Random* random, std::vector<WeighedRandomItem*>* items);
static int getTotalWeight(const std::vector<WeighedRandomItem*>& items);
static WeighedRandomItem* getRandomItem(
Random* random, const std::vector<WeighedRandomItem*>& items,
int totalWeight);
static WeighedRandomItem* getRandomItem(
Random* random, const std::vector<WeighedRandomItem*>& items);
};