Skip to content

Commit

Permalink
Consumable Protection (#1090)
Browse files Browse the repository at this point in the history
  • Loading branch information
AzureAaron authored Dec 22, 2024
1 parent ce45803 commit f9a6f61
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,14 @@ public static ConfigCategory create(SkyblockerConfig defaults, SkyblockerConfig
newValue -> config.general.itemProtection.slotLockStyle = newValue)
.controller(ConfigUtils::createEnumCyclingListController)
.build())
.option(Option.<Boolean>createBuilder()
.name(Text.translatable("skyblocker.config.general.itemProtection.protectValuableConsumables"))
.description(OptionDescription.of(Text.translatable("skyblocker.config.general.itemProtection.protectValuableConsumables.@Tooltip")))
.binding(defaults.general.itemProtection.protectValuableConsumables,
() -> config.general.itemProtection.protectValuableConsumables,
newValue -> config.general.itemProtection.protectValuableConsumables = newValue)
.controller(ConfigUtils::createBooleanController)
.build())
.build())

//Wiki Lookup
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,9 @@ public String toString() {
public static class ItemProtection {
@SerialEntry
public SlotLockStyle slotLockStyle = SlotLockStyle.FANCY;

@SerialEntry
public boolean protectValuableConsumables = true;
}

public enum SlotLockStyle {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package de.hysky.skyblocker.skyblock.item;

import java.util.Set;

import de.hysky.skyblocker.annotations.Init;
import de.hysky.skyblocker.config.SkyblockerConfigManager;
import de.hysky.skyblocker.utils.Utils;
import net.fabricmc.fabric.api.event.player.UseBlockCallback;
import net.fabricmc.fabric.api.event.player.UseItemCallback;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ActionResult;
import net.minecraft.util.Hand;
import net.minecraft.world.World;

public class ConsumableProtection {
private static final Set<String> PROTECTED_CONSUMABLES = Set.of("NEW_BOTTLE_OF_JYRRE", "DARK_CACAO_TRUFFLE", "DISCRITE");

@Init
public static void init() {
UseItemCallback.EVENT.register(ConsumableProtection::onInteract);
//Prevents placing the items when they are player heads (counts for consuming them)
UseBlockCallback.EVENT.register((player, world, hand, hitResult) -> onInteract(player, world, hand));
}

private static ActionResult onInteract(PlayerEntity player, World world, Hand hand) {
if (world.isClient() && SkyblockerConfigManager.get().general.itemProtection.protectValuableConsumables && Utils.isOnSkyblock()) {
ItemStack stack = player.getStackInHand(hand);
String skyblockId = stack.getSkyblockId();

if (!skyblockId.isEmpty() && PROTECTED_CONSUMABLES.contains(skyblockId)) {
return ActionResult.FAIL;
}
}

return ActionResult.PASS;
}
}
2 changes: 2 additions & 0 deletions src/main/resources/assets/skyblocker/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,8 @@
"skyblocker.config.general.itemList.enableItemList": "Enable Item List",

"skyblocker.config.general.itemProtection": "Item Protection",
"skyblocker.config.general.itemProtection.protectValuableConsumables": "Protect Valuable Consumables",
"skyblocker.config.general.itemProtection.protectValuableConsumables.@Tooltip": "Prevents consuming items such as Bottles of Jyrre, Dark Cacao Truffles, and Discrite before they have evolved.",
"skyblocker.config.general.itemProtection.slotLockStyle": "Slot Lock Icon Style",
"skyblocker.config.general.itemProtection.slotLockStyle.@Tooltip": "Choose between the fancy or the classic slot lock icon.",
"skyblocker.config.general.itemProtection.slotLockStyle.style.CLASSIC": "Classic",
Expand Down

0 comments on commit f9a6f61

Please sign in to comment.