blob: 6663b368a3b5efe58fed0f43ac10730c392bee2a (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
|
package me.xmrvizzy.skyblocker.skyblock.cooldown;
import com.google.common.collect.ImmutableList;
import me.xmrvizzy.skyblocker.config.SkyblockerConfig;
import me.xmrvizzy.skyblocker.events.ClientPlayerBlockBreakEvent;
import me.xmrvizzy.skyblocker.utils.ItemUtils;
import net.fabricmc.fabric.api.event.player.UseItemCallback;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.util.Hand;
import net.minecraft.util.TypedActionResult;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import java.util.HashMap;
import java.util.Map;
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 ImmutableList<String> BAT_ARMOR_IDS = ImmutableList.of("BAT_PERSON_HELMET", "BAT_PERSON_CHESTPLATE", "BAT_PERSON_LEGGINGS", "BAT_PERSON_BOOTS");
private static final Map<String, ItemCooldownEntry> itemCooldowns = new HashMap<>();
private static SkyblockerConfig.ItemCooldown config;
public static void init() {
ClientPlayerBlockBreakEvent.AFTER.register(ItemCooldowns::afterBlockBreak);
UseItemCallback.EVENT.register(ItemCooldowns::onItemInteract);
config = SkyblockerConfig.get().general.itemCooldown;
}
public static void afterBlockBreak(BlockPos pos, PlayerEntity player) {
if (!config.enableItemCooldowns) return;
String usedItemId = ItemUtils.getItemId(player.getMainHandStack());
if (usedItemId == null) return;
if (usedItemId.equals(JUNGLE_AXE_ID)) {
if (!isItemOnCooldown(JUNGLE_AXE_ID)) {
itemCooldowns.put(JUNGLE_AXE_ID, new ItemCooldownEntry(2000));
}
}
else if (usedItemId.equals(TREECAPITATOR_ID)) {
if (!isItemOnCooldown(TREECAPITATOR_ID)) {
itemCooldowns.put(TREECAPITATOR_ID, new ItemCooldownEntry(2000));
}
}
}
private static TypedActionResult<ItemStack> onItemInteract(PlayerEntity player, World world, Hand hand) {
if (!config.enableItemCooldowns) return TypedActionResult.pass(ItemStack.EMPTY);
String usedItemId = ItemUtils.getItemId(player.getMainHandStack());
if (usedItemId != null && usedItemId.equals(GRAPPLING_HOOK_ID) && player.fishHook != null) {
if (!isItemOnCooldown(GRAPPLING_HOOK_ID) && !isPlayerWearingBatArmor(player)) {
itemCooldowns.put(GRAPPLING_HOOK_ID, new ItemCooldownEntry(2000));
}
}
return TypedActionResult.pass(ItemStack.EMPTY);
}
public static boolean isItemOnCooldown(ItemStack itemStack) {
return isItemOnCooldown(ItemUtils.getItemId(itemStack));
}
private static boolean isItemOnCooldown(String itemId) {
if (itemCooldowns.containsKey(itemId)) {
ItemCooldownEntry cooldownEntry = itemCooldowns.get(itemId);
if (cooldownEntry.isOnCooldown()) {
return true;
}
else {
itemCooldowns.remove(cooldownEntry);
return false;
}
}
return false;
}
public static ItemCooldownEntry getItemCooldownEntry(ItemStack itemStack) {
return itemCooldowns.get(ItemUtils.getItemId(itemStack));
}
private static boolean isPlayerWearingBatArmor(PlayerEntity player) {
for (ItemStack stack : player.getArmorItems()) {
String itemId = ItemUtils.getItemId(stack);
if (!BAT_ARMOR_IDS.contains(itemId)) {
return false;
}
}
return true;
}
}
|