Skip to content

Commit

Permalink
Refactor old code
Browse files Browse the repository at this point in the history
  • Loading branch information
Intybyte committed Sep 26, 2024
1 parent 0a7fea8 commit 730cbc0
Showing 1 changed file with 22 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -82,31 +82,32 @@ public static boolean useFlintAndSteel(Player p, Block smelteryBlock) {
}

// Check if the chamber contains a Flint and Steel
if (inv.contains(Material.FLINT_AND_STEEL)) {
ItemStack item = inv.getItem(inv.first(Material.FLINT_AND_STEEL));
ItemMeta meta = item.getItemMeta();

// Only damage the Flint and Steel if it isn't unbreakable.
if (!meta.isUnbreakable()) {
// Update the damage value
((Damageable) meta).setDamage(((Damageable) meta).getDamage() + 1);

if (((Damageable) meta).getDamage() >= item.getType().getMaxDurability()) {
// The Flint and Steel broke
item.setAmount(0);
SoundEffect.IGNITION_CHAMBER_USE_FLINT_AND_STEEL_SOUND.playAt(smelteryBlock);
} else {
item.setItemMeta(meta);
}
}

SoundEffect.IGNITION_CHAMBER_USE_FLINT_AND_STEEL_SOUND.playAt(smelteryBlock);
return true;
} else {
if (!inv.contains(Material.FLINT_AND_STEEL)) {
// Notify the Player there is a chamber but without any Flint and Steel
Slimefun.getLocalization().sendMessage(p, "machines.ignition-chamber-no-flint", true);
return false;
}

ItemStack item = inv.getItem(inv.first(Material.FLINT_AND_STEEL));
ItemMeta meta = item.getItemMeta();

// Only damage the Flint and Steel if it isn't unbreakable.
if (!meta.isUnbreakable()) {
Damageable damageable = (Damageable) meta;
// Update the damage value
damageable.setDamage(damageable.getDamage() + 1);

if (damageable.getDamage() >= item.getType().getMaxDurability()) {
// The Flint and Steel broke
item.setAmount(0);
SoundEffect.IGNITION_CHAMBER_USE_FLINT_AND_STEEL_SOUND.playAt(smelteryBlock);
} else {
item.setItemMeta(meta);
}
}

SoundEffect.IGNITION_CHAMBER_USE_FLINT_AND_STEEL_SOUND.playAt(smelteryBlock);
return true;
}

private static @Nullable Inventory findIgnitionChamber(@Nonnull Block b) {
Expand Down

0 comments on commit 730cbc0

Please sign in to comment.