Skip to content

Commit

Permalink
resolve #12 and #11
Browse files Browse the repository at this point in the history
  • Loading branch information
FN-FAL113 committed Aug 7, 2023
1 parent dfe76ab commit 5a7cbe8
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>ne.fnfal113</groupId>
<artifactId>RelicsOfCthonia</artifactId>
<version>Unofficial-1.6</version>
<version>Unofficial-1.7</version>
<packaging>jar</packaging>

<name>RelicsOfCthonia</name>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public class MiningListener implements Listener {
@Getter
private final Map<AbstractRelic, List<Material>> whereToDropMaterialMap = RelicsOfCthonia.getInstance().getRelicsRegistry().getWhereToDropMaterialMap();

@EventHandler(priority = EventPriority.LOWEST)
@EventHandler(priority = EventPriority.MONITOR)
public void onBlockBreak(BlockBreakEvent event) {
if(event.isCancelled()){
return;
Expand All @@ -48,6 +48,7 @@ public void onBlockBreak(BlockBreakEvent event) {

World world = event.getPlayer().getWorld();
AtomicInteger itemDroppedCounter = new AtomicInteger(0);
ThreadLocalRandom currentRandomThread = ThreadLocalRandom.current();

Utils.createAsyncTask(asyncTask -> {
Iterator<Map.Entry<AbstractRelic, List<Material>>> dropIterator = getWhereToDropMaterialMap().entrySet().iterator();
Expand All @@ -63,7 +64,9 @@ public void onBlockBreak(BlockBreakEvent event) {
}

if(pair.getValue().contains(blockBrokeType)) {
double randomNum = ThreadLocalRandom.current().nextDouble(0.0, 100);
// biased probability to lower the chance of repeated values from the current random thread which utilizes same seed
double randomOrigin = currentRandomThread.nextDouble(0.0, 60);
double randomNum = currentRandomThread.nextDouble(randomOrigin, 100);

if(randomNum < abstractRelic.getDropChance()) {
ItemStack drop = abstractRelic.setRelicConditionAndGet(true, 0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ public void onMobKill(EntityDeathEvent event) {
String entityType = livingEntity.getType().name().toLowerCase();
World world = livingEntity.getWorld();
AtomicInteger itemDroppedCounter = new AtomicInteger(0);
ThreadLocalRandom currentRandomThread = ThreadLocalRandom.current();

Utils.createAsyncTask(asyncTask -> {
Iterator<Map.Entry<AbstractRelic, List<String>>> dropIterator = getWhereToDropMobMap().entrySet().iterator();
Expand All @@ -81,7 +82,9 @@ public void onMobKill(EntityDeathEvent event) {

// check if relic mob list contains killed mob type
if(pair.getValue().contains(entityType)) {
double randomNum = ThreadLocalRandom.current().nextDouble(0.0, 100);
// biased probability to lower the chance of repeated values from the current random thread which utilizes same seed
double randomOrigin = currentRandomThread.nextDouble(0.0, 60);
double randomNum = ThreadLocalRandom.current().nextDouble(randomOrigin, 100);

if(randomNum < abstractRelic.getDropChance()) {
ItemStack drop = abstractRelic.setRelicConditionAndGet(true, 0);
Expand Down

0 comments on commit 5a7cbe8

Please sign in to comment.