Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@
import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap;
import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap;
import it.unimi.dsi.fastutil.objects.ObjectOpenHashSet;
import java.util.ArrayList;
import java.util.List;
import net.minecraft.client.resources.language.I18n;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.Identifier;
import java.util.ArrayList;
import java.util.List;

public class GeneralConfig {
public boolean enableTips = true;
Expand Down Expand Up @@ -203,8 +203,9 @@ public static class ItemProtection {
}

public enum SlotLockStyle {
CLASSIC(SkyblockerMod.id("textures/gui/slot_lock.png")),
FANCY(SkyblockerMod.id("textures/gui/fancy_slot_lock.png"));
NONE(SkyblockerMod.id("textures/gui/blank_item_protected")),
CLASSIC(SkyblockerMod.id("textures/gui/classic_item_protected.png")),
FANCY(SkyblockerMod.id("textures/gui/fancy_item_protected.png"));

public final Identifier tex;

Expand Down
49 changes: 36 additions & 13 deletions src/main/java/de/hysky/skyblocker/skyblock/item/ItemProtection.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@
import org.lwjgl.glfw.GLFW;

public class ItemProtection {
public static final Identifier ITEM_PROTECTION_TEX = SkyblockerMod.id("textures/gui/item_protection.png");

public static final Identifier ITEM_PROTECTION_TEX = SkyblockerConfigManager.get().general.itemProtection.slotLockStyle.tex;
public static KeyMapping itemProtection;

@Init
Expand All @@ -47,8 +48,14 @@ public static void init() {

public static boolean isItemProtected(ItemStack stack) {
if (stack == null) return false;
String itemUuid = stack.getUuid();
return SkyblockerConfigManager.get().general.protectedItems.contains(itemUuid);
else {
String itemUuid = stack.getUuid();
if (!itemUuid.isEmpty()) return SkyblockerConfigManager.get().general.protectedItems.contains(itemUuid);
else {
String SkyblockId = stack.getSkyblockId();
return SkyblockerConfigManager.get().general.protectedItems.contains(SkyblockId);
}
}
}

private static void registerCommand(CommandDispatcher<FabricClientCommandSource> dispatcher, CommandBuildContext registryAccess) {
Expand All @@ -59,20 +66,26 @@ private static void registerCommand(CommandDispatcher<FabricClientCommandSource>

private static int protectMyItem(FabricClientCommandSource source) {
ItemStack heldItem = source.getPlayer().getMainHandItem();
String itemUuid = heldItem.getUuid();
String skyblockId = heldItem.getSkyblockId();

if (Utils.isOnSkyblock()) {
String itemUuid = heldItem.getUuid();

if (!itemUuid.isEmpty()) {
if (!SkyblockerConfigManager.get().general.protectedItems.contains(itemUuid)) {
SkyblockerConfigManager.update(config -> config.general.protectedItems.add(itemUuid));
source.sendFeedback(Constants.PREFIX.get().append(Component.translatable("skyblocker.itemProtection.added", heldItem.getHoverName())));
source.sendFeedback(Constants.PREFIX.get().append(Component.translatable("skyblocker.itemProtection.uniqueAdded", heldItem.getHoverName())));
} else {
SkyblockerConfigManager.update(config -> config.general.protectedItems.remove(itemUuid));
source.sendFeedback(Constants.PREFIX.get().append(Component.translatable("skyblocker.itemProtection.removed", heldItem.getHoverName())));
source.sendFeedback(Constants.PREFIX.get().append(Component.translatable("skyblocker.itemProtection.uniqueRemoved", heldItem.getHoverName())));
}
} else {
source.sendFeedback(Constants.PREFIX.get().append(Component.translatable("skyblocker.itemProtection.noItemUuid")));
if (!SkyblockerConfigManager.get().general.protectedItems.contains(skyblockId)) {
SkyblockerConfigManager.update(config -> config.general.protectedItems.add(skyblockId));
source.sendFeedback(Constants.PREFIX.get().append(Component.translatable("skyblocker.itemProtection.genericAdded", heldItem.getHoverName())));
} else {
SkyblockerConfigManager.update(config -> config.general.protectedItems.remove(skyblockId));
source.sendFeedback(Constants.PREFIX.get().append(Component.translatable("skyblocker.itemProtection.genericRemoved", heldItem.getHoverName())));
}
}
} else {
source.sendFeedback(Constants.PREFIX.get().append(Component.translatable("skyblocker.itemProtection.unableToProtect")));
Expand All @@ -92,28 +105,37 @@ public static void handleKeyPressed(ItemStack heldItem) {
playerEntity.sendSystemMessage(Constants.PREFIX.get().append(Component.translatable("skyblocker.itemProtection.unableToProtect")));
return;
}

if (heldItem.isEmpty()) {
playerEntity.sendSystemMessage(Constants.PREFIX.get().append(Component.translatable("skyblocker.itemProtection.noItemUuid")));
return;
}

String itemUuid = heldItem.getUuid();
String skyblockId = heldItem.getSkyblockId();
if (!itemUuid.isEmpty()) {

if (!SkyblockerConfigManager.get().general.protectedItems.contains(itemUuid)) {
SkyblockerConfigManager.update(config -> config.general.protectedItems.add(itemUuid));
if (notifyConfiguration) {
playerEntity.sendSystemMessage(Constants.PREFIX.get().append(Component.translatable("skyblocker.itemProtection.added", heldItem.getHoverName())));
playerEntity.sendSystemMessage(Constants.PREFIX.get().append(Component.translatable("skyblocker.itemProtection.uniqueAdded", heldItem.getHoverName())));
}
} else {
SkyblockerConfigManager.update(config -> config.general.protectedItems.remove(itemUuid));
if (notifyConfiguration) {
playerEntity.sendSystemMessage(Constants.PREFIX.get().append(Component.translatable("skyblocker.itemProtection.removed", heldItem.getHoverName())));
playerEntity.sendSystemMessage(Constants.PREFIX.get().append(Component.translatable("skyblocker.itemProtection.uniqueRemoved", heldItem.getHoverName())));
}
}
} else {
playerEntity.sendSystemMessage(Constants.PREFIX.get().append(Component.translatable("skyblocker.itemProtection.noItemUuid")));
if (!SkyblockerConfigManager.get().general.protectedItems.contains(skyblockId)) {
SkyblockerConfigManager.update(config -> config.general.protectedItems.add(skyblockId));
if (notifyConfiguration) {
playerEntity.sendSystemMessage(Constants.PREFIX.get().append(Component.translatable("skyblocker.itemProtection.genericAdded", heldItem.getHoverName())));
}
} else {
SkyblockerConfigManager.update(config -> config.general.protectedItems.remove(skyblockId));
if (notifyConfiguration) {
playerEntity.sendSystemMessage(Constants.PREFIX.get().append(Component.translatable("skyblocker.itemProtection.genericRemoved", heldItem.getHoverName())));
}
}
}
}

Expand All @@ -133,6 +155,7 @@ private static InteractionResult onEntityInteract(Player playerEntity, Level wor
}
if (entity instanceof ItemFrame itemFrame && itemFrame.getItem().isEmpty()) {
if (isItemProtected(playerEntity.getItemInHand(hand)) || HotbarSlotLock.isLocked(playerEntity.getInventory().getSelectedSlot())) {
playerEntity.sendSystemMessage(Constants.PREFIX.get().append(Component.translatable("skyblocker.itemProtection.triggered")));
return InteractionResult.FAIL;
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
package de.hysky.skyblocker.skyblock.profileviewer.inventory;

import com.google.gson.JsonObject;

import de.hysky.skyblocker.skyblock.item.ItemProtection;
import de.hysky.skyblocker.skyblock.item.background.ItemBackgroundManager;
import de.hysky.skyblocker.skyblock.item.slottext.SlotTextManager;
import de.hysky.skyblocker.skyblock.profileviewer.ProfileViewerPage;
import de.hysky.skyblocker.skyblock.profileviewer.inventory.itemLoaders.InventoryItemLoader;
import it.unimi.dsi.fastutil.ints.IntIntPair;
import java.awt.Color;
import java.util.Collections;
import java.util.List;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.Font;
import net.minecraft.client.gui.GuiGraphicsExtractor;
Expand All @@ -22,6 +18,10 @@
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.TooltipFlag;

import java.awt.Color;
import java.util.Collections;
import java.util.List;

public class PlayerInventory implements ProfileViewerPage {
private static final Identifier TEXTURE = Identifier.parse("textures/gui/container/generic_54.png");
private static final Minecraft CLIENT = Minecraft.getInstance();
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.