Skip to content

Commit

Permalink
Make some items have a durability range
Browse files Browse the repository at this point in the history
  • Loading branch information
ellieisjelly committed Jun 12, 2024
1 parent d57e37e commit e26207a
Showing 1 changed file with 17 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,19 @@ public class SabotageChest extends ChestBlock implements BlockEntityProvider, Po
entry(Items.GOLDEN_APPLE, 1),
entry(Items.BOW, 4),
entry(Items.CROSSBOW, 4),
// to-do: make firework explosive
entry(Items.FIREWORK_ROCKET, 10),
entry(Items.ARROW, 20)
);
private static final Map<Item, Integer> durabilities = Map.ofEntries(
entry(Items.GOLDEN_AXE, 5),
entry(Items.IRON_SWORD, 250),
entry(Items.WOODEN_AXE, 10),
entry(Items.IRON_CHESTPLATE, 100),
entry(Items.IRON_LEGGINGS, 150),
entry(Items.BOW, 100),
entry(Items.CROSSBOW, 30)
);
@FunctionalInterface
private interface ThreadLocalRandomWrapper {
ThreadLocalRandom current();
Expand All @@ -75,7 +85,13 @@ private static <T> T getFromWeightedMap(Map<T, ? extends Number> weights) {
}
private static ItemStack getItemDrop() {
Item item = getFromWeightedMap(items);
return new ItemStack(item);
ItemStack stack = new ItemStack(item);
if (durabilities.get(item) != null) {
int range = durabilities.get(item);
int durability = (int) Math.floor(Math.random() * range);
stack.setDamage(stack.getMaxDamage() - durability);
}
return stack;
}
public SabotageChest(Settings settings, Block virtualBlock) {
super(settings, () -> SABOTAGE_CHEST_ENTITY);
Expand Down

0 comments on commit e26207a

Please sign in to comment.