Skip to content

Commit 5c09d0b

Browse files
committed
fix(forge16/19): make ConfigRewardPool use ConfigRandomWeightedSet
skip-ci
1 parent 16ea388 commit 5c09d0b

2 files changed

Lines changed: 88 additions & 6 deletions

File tree

forge16/src/main/java/com/envyful/api/forge/config/ConfigRewardPool.java

Lines changed: 44 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package com.envyful.api.forge.config;
22

3+
import com.envyful.api.config.type.ConfigRandomWeightedSet;
34
import com.envyful.api.gui.Transformer;
4-
import com.envyful.api.math.RandomWeightedSet;
55
import com.envyful.api.math.UtilRandom;
66
import com.google.common.collect.Lists;
77
import net.minecraft.entity.player.ServerPlayerEntity;
@@ -15,9 +15,9 @@ public class ConfigRewardPool {
1515
private ConfigReward guaranteedReward;
1616
private int rewardRollsMin;
1717
private int rewardRollsMax;
18-
private RandomWeightedSet<ConfigReward> rewards;
18+
private ConfigRandomWeightedSet<ConfigReward> rewards;
1919

20-
public ConfigRewardPool(ConfigReward guaranteedReward, int rewardRollsMin, int rewardRollsMax, RandomWeightedSet<ConfigReward> rewards) {
20+
private ConfigRewardPool(ConfigReward guaranteedReward, int rewardRollsMin, int rewardRollsMax, ConfigRandomWeightedSet<ConfigReward> rewards) {
2121
this.guaranteedReward = guaranteedReward;
2222
this.rewardRollsMin = rewardRollsMin;
2323
this.rewardRollsMax = rewardRollsMax;
@@ -46,4 +46,45 @@ public void give(ServerPlayerEntity player, Transformer... transformers) {
4646
randomReward.execute(player, transformers);
4747
}
4848
}
49+
50+
public static Builder builder() {
51+
return new Builder();
52+
}
53+
54+
public static class Builder {
55+
56+
private ConfigReward guaranteedReward;
57+
private int rewardRollsMin;
58+
private int rewardRollsMax;
59+
private ConfigRandomWeightedSet<ConfigReward> rewards;
60+
61+
private Builder() {}
62+
63+
public Builder guranteedReward(ConfigReward reward) {
64+
this.guaranteedReward = reward;
65+
return this;
66+
}
67+
68+
public Builder minRolls(int minRolls) {
69+
this.rewardRollsMin = minRolls;
70+
return this;
71+
}
72+
73+
public Builder maxRolls(int maxRolls) {
74+
this.rewardRollsMax = maxRolls;
75+
return this;
76+
}
77+
78+
public Builder rewards(ConfigRandomWeightedSet<ConfigReward> rewards) {
79+
this.rewards = rewards;
80+
return this;
81+
}
82+
83+
public ConfigRewardPool build() {
84+
return new ConfigRewardPool(
85+
this.guaranteedReward, this.rewardRollsMin, this.rewardRollsMax,
86+
this.rewards
87+
);
88+
}
89+
}
4990
}

forge19/src/main/java/com/envyful/api/forge/config/ConfigRewardPool.java

Lines changed: 44 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package com.envyful.api.forge.config;
22

3+
import com.envyful.api.config.type.ConfigRandomWeightedSet;
34
import com.envyful.api.gui.Transformer;
4-
import com.envyful.api.math.RandomWeightedSet;
55
import com.envyful.api.math.UtilRandom;
66
import com.google.common.collect.Lists;
77
import net.minecraft.server.level.ServerPlayer;
@@ -15,9 +15,9 @@ public class ConfigRewardPool {
1515
private ConfigReward guaranteedReward;
1616
private int rewardRollsMin;
1717
private int rewardRollsMax;
18-
private RandomWeightedSet<ConfigReward> rewards;
18+
private ConfigRandomWeightedSet<ConfigReward> rewards;
1919

20-
public ConfigRewardPool(ConfigReward guaranteedReward, int rewardRollsMin, int rewardRollsMax, RandomWeightedSet<ConfigReward> rewards) {
20+
private ConfigRewardPool(ConfigReward guaranteedReward, int rewardRollsMin, int rewardRollsMax, ConfigRandomWeightedSet<ConfigReward> rewards) {
2121
this.guaranteedReward = guaranteedReward;
2222
this.rewardRollsMin = rewardRollsMin;
2323
this.rewardRollsMax = rewardRollsMax;
@@ -46,4 +46,45 @@ public void give(ServerPlayer player, Transformer... transformers) {
4646
randomReward.execute(player, transformers);
4747
}
4848
}
49+
50+
public static Builder builder() {
51+
return new Builder();
52+
}
53+
54+
public static class Builder {
55+
56+
private ConfigReward guaranteedReward;
57+
private int rewardRollsMin;
58+
private int rewardRollsMax;
59+
private ConfigRandomWeightedSet<ConfigReward> rewards;
60+
61+
private Builder() {}
62+
63+
public Builder guranteedReward(ConfigReward reward) {
64+
this.guaranteedReward = reward;
65+
return this;
66+
}
67+
68+
public Builder minRolls(int minRolls) {
69+
this.rewardRollsMin = minRolls;
70+
return this;
71+
}
72+
73+
public Builder maxRolls(int maxRolls) {
74+
this.rewardRollsMax = maxRolls;
75+
return this;
76+
}
77+
78+
public Builder rewards(ConfigRandomWeightedSet<ConfigReward> rewards) {
79+
this.rewards = rewards;
80+
return this;
81+
}
82+
83+
public ConfigRewardPool build() {
84+
return new ConfigRewardPool(
85+
this.guaranteedReward, this.rewardRollsMin, this.rewardRollsMax,
86+
this.rewards
87+
);
88+
}
89+
}
4990
}

0 commit comments

Comments
 (0)