Skip to content

Commit

Permalink
added 2 items to ItemCooldowns (#1018)
Browse files Browse the repository at this point in the history
* added 3 items to ItemCooldowns

* added more items to ItemCooldowns

* methods? best way i could think of doing it

* changes
  • Loading branch information
VeritasDL authored Oct 21, 2024
1 parent 135125f commit 2e82772
Showing 1 changed file with 52 additions and 9 deletions.
61 changes: 52 additions & 9 deletions src/main/java/de/hysky/skyblocker/skyblock/item/ItemCooldowns.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,16 @@ public class ItemCooldowns {
private static final String JUNGLE_AXE_ID = "JUNGLE_AXE";
private static final String TREECAPITATOR_ID = "TREECAPITATOR_AXE";
private static final String GRAPPLING_HOOK_ID = "GRAPPLING_HOOK";
private static final String ROGUE_SWORD_ID = "ROGUE_SWORD";
private static final String LEAPING_SWORD_ID = "LEAPING_SWORD";
private static final String SILK_EDGE_SWORD_ID = "SILK_EDGE_SWORD";
private static final String GREAT_SPOOK_STAFF_ID = "GREAT_SPOOK_STAFF";
private static final String SPIRIT_LEAP_ID = "SPIRIT_LEAP";
private static final String GIANTS_SWORD_ID = "GIANTS_SWORD";
private static final String SHADOW_FURY_ID = "SHADOW_FURY";
private static final String LIVID_DAGGER_ID = "LIVID_DAGGER";
private static final String INK_WAND_ID = "INK_WAND";

private static final List<String> BAT_ARMOR_IDS = List.of("BAT_PERSON_HELMET", "BAT_PERSON_CHESTPLATE", "BAT_PERSON_LEGGINGS", "BAT_PERSON_BOOTS");
private static final Map<String, CooldownEntry> ITEM_COOLDOWNS = new HashMap<>();
private static final int[] EXPERIENCE_LEVELS = {
Expand Down Expand Up @@ -85,18 +95,51 @@ public static void afterBlockBreak(World world, PlayerEntity player, BlockPos po
}

private static TypedActionResult<ItemStack> onItemInteract(PlayerEntity player, World world, Hand hand) {
if (!SkyblockerConfigManager.get().uiAndVisuals.itemCooldown.enableItemCooldowns)
return TypedActionResult.pass(ItemStack.EMPTY);
String usedItemId = ItemUtils.getItemId(player.getMainHandStack());
if (usedItemId.equals(GRAPPLING_HOOK_ID) && player.fishHook != null) {
if (!isOnCooldown(GRAPPLING_HOOK_ID) && !isWearingBatArmor(player)) {
ITEM_COOLDOWNS.put(GRAPPLING_HOOK_ID, new CooldownEntry(2000));
}
}

if (!SkyblockerConfigManager.get().uiAndVisuals.itemCooldown.enableItemCooldowns)
return TypedActionResult.pass(ItemStack.EMPTY);
String usedItemId = ItemUtils.getItemId(player.getMainHandStack());
switch (usedItemId) {
case SILK_EDGE_SWORD_ID:
case LEAPING_SWORD_ID:
handleItemCooldown(usedItemId, 1000);
break;
case GRAPPLING_HOOK_ID:
handleItemCooldown(GRAPPLING_HOOK_ID, 2000, player.fishHook != null && !isWearingBatArmor(player));
break;
case ROGUE_SWORD_ID:
case SPIRIT_LEAP_ID:
case LIVID_DAGGER_ID:
handleItemCooldown(usedItemId, 5000);
break;
case SHADOW_FURY_ID:
handleItemCooldown(SHADOW_FURY_ID, 15000);
break;
case INK_WAND_ID:
case GIANTS_SWORD_ID:
handleItemCooldown(usedItemId, 30000);
break;
case GREAT_SPOOK_STAFF_ID:
handleItemCooldown(GREAT_SPOOK_STAFF_ID, 60000);
break;
default:
// Handle any unlisted items if necessary
break;
}
return TypedActionResult.pass(ItemStack.EMPTY);
}

// Method to handle item cooldowns with optional condition
private static void handleItemCooldown(String itemId, int cooldownTime, boolean additionalCondition) {
if (!isOnCooldown(itemId) && additionalCondition) {
ITEM_COOLDOWNS.put(itemId, new CooldownEntry(cooldownTime));
}
}

// Overloaded method for cases without additional conditions
private static void handleItemCooldown(String itemId, int cooldownTime) {
handleItemCooldown(itemId, cooldownTime, true);
}

public static boolean isOnCooldown(ItemStack itemStack) {
return isOnCooldown(ItemUtils.getItemId(itemStack));
}
Expand Down

0 comments on commit 2e82772

Please sign in to comment.