Skip to content

Commit a8025ff

Browse files
committed
GameBlockData - change how random bonus chests are chosen
- use min/max instead of random percent
1 parent 2c1b5cd commit a8025ff

File tree

3 files changed

+20
-10
lines changed

3 files changed

+20
-10
lines changed

src/main/java/com/shanebeestudios/hg/api/game/GameBlockData.java

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -183,16 +183,21 @@ public int logBlocksForRollback() {
183183

184184
@SuppressWarnings("UnstableApiUsage")
185185
public void setupRandomizedBonusChests() {
186+
if (!Config.CHESTS_BONUS_RANDOMIZE_ENABLED) return;
187+
186188
Optional<BlockType> first = BlockUtils.getBonusBlockTypes().stream().findFirst();
187189
if (first.isEmpty()) return;
190+
188191
BlockData blockData = first.get().createBlockData();
192+
int bonusChestAmount = this.random.nextInt(Config.CHESTS_BONUS_RANDOMIZE_MIN, Config.CHESTS_BONUS_RANDOMIZE_MAX + 1);
193+
List<Block> randoms = new ArrayList<>(this.randomBonusChests);
194+
for (int i = 0; i < bonusChestAmount; i++) {
195+
if (randoms.isEmpty()) return;
189196

190-
if (Config.CHESTS_BONUS_RANDOMIZE_ENABLED) {
191-
this.randomBonusChests.forEach(bonusChest -> {
192-
if (this.random.nextInt(100) < Config.CHESTS_BONUS_RANDOMIZE_CHANCE) {
193-
bonusChest.setBlockData(blockData);
194-
}
195-
});
197+
Collections.shuffle(randoms);
198+
Block bonusChest = randoms.getFirst();
199+
randoms.remove(bonusChest);
200+
bonusChest.setBlockData(blockData);
196201
}
197202
}
198203

src/main/java/com/shanebeestudios/hg/plugin/configs/Config.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,8 @@ public class Config {
7474
public static List<String> CHESTS_BONUS_BLOCK_TYPES;
7575
// Chests - Bonus - Randomize
7676
public static boolean CHESTS_BONUS_RANDOMIZE_ENABLED;
77-
public static int CHESTS_BONUS_RANDOMIZE_CHANCE;
77+
public static int CHESTS_BONUS_RANDOMIZE_MIN;
78+
public static int CHESTS_BONUS_RANDOMIZE_MAX;
7879
public static String CHESTS_BONUS_RANDOMIZE_BLOCK;
7980

8081
// Chests - Drops
@@ -177,7 +178,8 @@ private void loadConfig() {
177178
CHESTS_BONUS_MAX_CONTENT = config.getInt("chests.bonus.max-content");
178179
CHESTS_BONUS_BLOCK_TYPES = config.getStringList("chests.bonus.block-types");
179180
CHESTS_BONUS_RANDOMIZE_ENABLED = config.getBoolean("chests.bonus.randomize.enabled");
180-
CHESTS_BONUS_RANDOMIZE_CHANCE = config.getInt("chests.bonus.randomize.chance");
181+
CHESTS_BONUS_RANDOMIZE_MIN = config.getInt("chests.bonus.randomize.min");
182+
CHESTS_BONUS_RANDOMIZE_MAX = config.getInt("chests.bonus.randomize.max");
181183
CHESTS_BONUS_RANDOMIZE_BLOCK = config.getString("chests.bonus.randomize.block");
182184
CHESTS_CHEST_DROP_ENABLED = config.getBoolean("chests.chest-drop.enabled");
183185
CHESTS_CHEST_DROP_INTERVAL = config.getInt("chests.chest-drop.interval");

src/main/resources/config.yml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,9 +124,12 @@ chests:
124124
# The blocks will be replaced with the first element of 'chests.bonus.block-types' from above
125125
enabled: true
126126
# Place this block randomly around your arena to be replaced when a game starts
127+
# Place as many as you'd like
127128
block: 'minecraft:pink_wool'
128-
# Chance a block will be replaced (out of 100)
129-
chance: 50
129+
# How many random bonus chests to place (randomly selected between min/max)
130+
# If there aren't enough blocks placed it will just stop (make sure to place plenty more than your max)
131+
min: 2
132+
max: 5
130133
# Chest drops
131134
chest-drop:
132135
# Whether to enable chest drops

0 commit comments

Comments
 (0)