Skip to content

Commit

Permalink
Merge pull request #74 from Th3Shadowbroker/fix/drops
Browse files Browse the repository at this point in the history
Fix/drops
  • Loading branch information
Th3Shadowbroker authored Mar 20, 2021
2 parents 46beccd + 54a77d0 commit 5eb5f7c
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 13 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<groupId>dev.th3shadowbroker.spigot</groupId>
<artifactId>OuroborosMines</artifactId>
<version>1.10.1-SNAPSHOT</version>
<version>1.10.2-SNAPSHOT</version>

<properties>
<plugin.name>${project.artifactId}</plugin.name>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
package dev.th3shadowbroker.ouroboros.mines.drops;

import dev.th3shadowbroker.ouroboros.mines.drops.types.AbstractDrop;
import dev.th3shadowbroker.ouroboros.mines.drops.types.ItemDrop;
import org.bukkit.Location;
import org.bukkit.entity.Player;

Expand Down Expand Up @@ -57,7 +58,8 @@ public AbstractDrop[] drawMultidrop() {
drops.add(drop);
} else {
Random rnd = new Random();
boolean shallDrop = ((double) rnd.nextInt(100) / 100) <= drop.getChance();
double drawn = ((double) rnd.nextInt(100) / 100);
boolean shallDrop = drawn <= drop.getChance();
if (shallDrop) drops.add(drop);
}
});
Expand All @@ -73,7 +75,7 @@ public AbstractDrop drawSingledrop() {
double offset = 0;

for (AbstractDrop pDrop : drops) {
boolean shallDrop = pDrop.getChance() <= drawn + offset;
boolean shallDrop = pDrop.getChance() >= 1 || pDrop.getChance() <= drawn + offset;
if (shallDrop) {
drop = pDrop;
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,16 +149,18 @@ private void breakBlock(BlockBreakEvent event, MineableMaterial mineableMaterial
}

private void breakNaturally(BlockBreakEvent event, boolean dropNaturalItems, boolean autoPickup) {
if (autoPickup) {
event.setDropItems(dropNaturalItems);
Collection<ItemStack> drops = event.getBlock().getDrops();

Player player = event.getPlayer();
Location blockLocation = event.getBlock().getLocation();
Map<Integer, ItemStack> overflow = player.getInventory().addItem(drops.stream().toArray(ItemStack[]::new));
overflow.values().forEach(i -> blockLocation.getWorld().dropItem(blockLocation, i));
} else {
event.getBlock().breakNaturally(event.getPlayer().getInventory().getItemInMainHand());
if (dropNaturalItems) {
if (autoPickup) {
event.setDropItems(false);
Collection<ItemStack> drops = event.getBlock().getDrops();

Player player = event.getPlayer();
Location blockLocation = event.getBlock().getLocation();
Map<Integer, ItemStack> overflow = player.getInventory().addItem(drops.stream().toArray(ItemStack[]::new));
overflow.values().forEach(i -> blockLocation.getWorld().dropItem(blockLocation, i));
} else {
event.getBlock().breakNaturally(event.getPlayer().getInventory().getItemInMainHand());
}
}
}

Expand Down

0 comments on commit 5eb5f7c

Please sign in to comment.