Skip to content
Merged
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
@@ -0,0 +1,65 @@
package com.robertx22.mine_and_slash.capability.player.container;

import com.robertx22.mine_and_slash.capability.player.helper.JewelInvHelper;
import com.robertx22.mine_and_slash.uncommon.localization.Words;
import net.minecraft.ChatFormatting;
import net.minecraft.network.chat.Component;
import net.minecraft.world.Container;
import net.minecraft.world.entity.player.Inventory;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.inventory.ChestMenu;
import net.minecraft.world.inventory.ClickType;
import net.minecraft.world.inventory.MenuType;
import net.minecraft.world.inventory.Slot;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.Items;

public class JewelsMenu extends ChestMenu {
private Container container;
private int maxJewels;
private int firstPlayerInventoryIndex;

public JewelsMenu(MenuType<?> pType, int pContainerId, Inventory pPlayerInventory, Container pContainer, int pRows, int maxJewels) {
super(pType, pContainerId, pPlayerInventory, pContainer, pRows);
this.container = pContainer;
this.maxJewels = maxJewels;
this.firstPlayerInventoryIndex = pRows * 9;
ItemStack itemStack = new ItemStack(JewelInvHelper.GetPlaceholder());
itemStack.setHoverName(Component.literal(Words.JEWEL_SOCKET_NOT_AVAILABLE.translate()).withStyle(ChatFormatting.DARK_RED, ChatFormatting.BOLD));
for (int i = 0; i < container.getContainerSize(); i++) {
if (i >= maxJewels) {
container.setItem(i, itemStack);
} else if (JewelInvHelper.IsPlaceholder(itemStack)) {
container.setItem(i, new ItemStack(Items.AIR));
}
}
}

private boolean isJewelSlot(int pIndex) {
return pIndex >= maxJewels && pIndex < firstPlayerInventoryIndex;
}

@Override
public ItemStack quickMoveStack(Player pPlayer, int pIndex) {
if (isJewelSlot(pIndex)) {
return ItemStack.EMPTY;
}
return super.quickMoveStack(pPlayer, pIndex);
}

@Override
public void clicked(int pSlotId, int pButton, ClickType pClickType, Player pPlayer) {
if (isJewelSlot(pSlotId) || pClickType == ClickType.PICKUP_ALL) {
return;
}
super.clicked(pSlotId, pButton, pClickType, pPlayer);
}

@Override
public boolean canTakeItemForPickAll(ItemStack pStack, Slot pSlot) {
if (isJewelSlot(pSlot.index)) {
return false;
}
return super.canTakeItemForPickAll(pStack, pSlot);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
import com.robertx22.mine_and_slash.uncommon.utilityclasses.PlayerUtils;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.Items;

import java.util.ArrayList;
import java.util.List;
Expand Down Expand Up @@ -82,13 +84,21 @@ public void checkRemoveJewels(Player p) {
ExplainedResultUtil.sendErrorMessage(p, Chats.EQUIP_JEWEL_ERROR, Chats.YOU_LACK_JEWEL_SLOTS);
unequip(p, i);
}
} else {
} else if (!IsPlaceholder(stack)) {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let me know if you want jewels cache be refactored into something different than a Container class

unequip(p, i);
}
}
}


public static boolean IsPlaceholder(ItemStack stack) {
return stack.getDescriptionId().equals(GetPlaceholder().getDescriptionId());
}

public static Item GetPlaceholder() {
return Items.BARRIER;
}

public List<JewelItemData> getAllJewels() {
List<JewelItemData> list = new ArrayList<>();
for (int i = 0; i < inv.getTotalSlots(); i++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,8 @@ public enum Words implements IAutoLocName {
INCREASE_PERCENT_STAT("Extra ", "use for stat like \"(Extra) (attack speed)\", this is different with multiply stat prefix."),
REDUCE_PERCENT_STAT("Lower "),
EMPTY_BOX("Box"),
LEVEL_UP_TYPE_PLAYER("Player");
LEVEL_UP_TYPE_PLAYER("Player"),
JEWEL_SOCKET_NOT_AVAILABLE("Unlock on talent tree");


private String localization = "";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import com.robertx22.library_of_exile.main.MyPacket;
import com.robertx22.library_of_exile.packets.ExilePacketContext;
import com.robertx22.mine_and_slash.capability.player.container.JewelsMenu;
import com.robertx22.mine_and_slash.capability.player.helper.JewelInvHelper;
import com.robertx22.mine_and_slash.mmorpg.SlashRef;
import com.robertx22.mine_and_slash.uncommon.datasaving.Load;
import net.minecraft.network.FriendlyByteBuf;
Expand All @@ -11,7 +13,6 @@
import net.minecraft.world.SimpleMenuProvider;
import net.minecraft.world.entity.player.Inventory;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.inventory.ChestMenu;
import net.minecraft.world.inventory.MenuType;

public class OpenJewelsPacket extends MyPacket<OpenJewelsPacket> {
Expand Down Expand Up @@ -39,19 +40,17 @@ public void saveToData(FriendlyByteBuf buf) {

@Override
public void onReceived(ExilePacketContext ctx) {

var inv = Load.player(ctx.getPlayer()).getJewels().inv;

JewelInvHelper jewels = Load.player(ctx.getPlayer()).getJewels();
Player p = ctx.getPlayer();

int maxJewels = jewels.getJewelSocketsMaxStat(p);
p.openMenu(new SimpleMenuProvider((i, playerInventory, playerEntity) -> {
return oneRow(i, playerInventory, inv); // todo why doesnt vanilla have this
return oneRow(i, playerInventory, jewels.inv, maxJewels); // todo why doesnt vanilla have this
}, Component.literal("")));

}

public static ChestMenu oneRow(int pContainerId, Inventory pPlayerInventory, Container pContainer) {
return new ChestMenu(MenuType.GENERIC_9x1, pContainerId, pPlayerInventory, pContainer, 1);
public static JewelsMenu oneRow(int pContainerId, Inventory pPlayerInventory, Container pContainer, int maxJewels) {
return new JewelsMenu(MenuType.GENERIC_9x1, pContainerId, pPlayerInventory, pContainer, 1, maxJewels);
}

@Override
Expand Down