-
-
Notifications
You must be signed in to change notification settings - Fork 100
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ce45803
commit f9a6f61
Showing
4 changed files
with
51 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
src/main/java/de/hysky/skyblocker/skyblock/item/ConsumableProtection.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters