Skip to content

Commit 22f185d

Browse files
authored
Merge pull request #235 from SaloEater/jewels-menu
Make it obvious in jewels menu how many jewels slots you have available
2 parents 321c773 + efeee82 commit 22f185d

4 files changed

Lines changed: 85 additions & 10 deletions

File tree

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
package com.robertx22.mine_and_slash.capability.player.container;
2+
3+
import com.robertx22.mine_and_slash.capability.player.helper.JewelInvHelper;
4+
import com.robertx22.mine_and_slash.uncommon.localization.Words;
5+
import net.minecraft.ChatFormatting;
6+
import net.minecraft.network.chat.Component;
7+
import net.minecraft.world.Container;
8+
import net.minecraft.world.entity.player.Inventory;
9+
import net.minecraft.world.entity.player.Player;
10+
import net.minecraft.world.inventory.ChestMenu;
11+
import net.minecraft.world.inventory.ClickType;
12+
import net.minecraft.world.inventory.MenuType;
13+
import net.minecraft.world.inventory.Slot;
14+
import net.minecraft.world.item.ItemStack;
15+
import net.minecraft.world.item.Items;
16+
17+
public class JewelsMenu extends ChestMenu {
18+
private Container container;
19+
private int maxJewels;
20+
private int firstPlayerInventoryIndex;
21+
22+
public JewelsMenu(MenuType<?> pType, int pContainerId, Inventory pPlayerInventory, Container pContainer, int pRows, int maxJewels) {
23+
super(pType, pContainerId, pPlayerInventory, pContainer, pRows);
24+
this.container = pContainer;
25+
this.maxJewels = maxJewels;
26+
this.firstPlayerInventoryIndex = pRows * 9;
27+
ItemStack itemStack = new ItemStack(JewelInvHelper.GetPlaceholder());
28+
itemStack.setHoverName(Component.literal(Words.JEWEL_SOCKET_NOT_AVAILABLE.translate()).withStyle(ChatFormatting.DARK_RED, ChatFormatting.BOLD));
29+
for (int i = 0; i < container.getContainerSize(); i++) {
30+
if (i >= maxJewels) {
31+
container.setItem(i, itemStack);
32+
} else if (JewelInvHelper.IsPlaceholder(itemStack)) {
33+
container.setItem(i, new ItemStack(Items.AIR));
34+
}
35+
}
36+
}
37+
38+
private boolean isJewelSlot(int pIndex) {
39+
return pIndex >= maxJewels && pIndex < firstPlayerInventoryIndex;
40+
}
41+
42+
@Override
43+
public ItemStack quickMoveStack(Player pPlayer, int pIndex) {
44+
if (isJewelSlot(pIndex)) {
45+
return ItemStack.EMPTY;
46+
}
47+
return super.quickMoveStack(pPlayer, pIndex);
48+
}
49+
50+
@Override
51+
public void clicked(int pSlotId, int pButton, ClickType pClickType, Player pPlayer) {
52+
if (isJewelSlot(pSlotId) || pClickType == ClickType.PICKUP_ALL) {
53+
return;
54+
}
55+
super.clicked(pSlotId, pButton, pClickType, pPlayer);
56+
}
57+
58+
@Override
59+
public boolean canTakeItemForPickAll(ItemStack pStack, Slot pSlot) {
60+
if (isJewelSlot(pSlot.index)) {
61+
return false;
62+
}
63+
return super.canTakeItemForPickAll(pStack, pSlot);
64+
}
65+
}

src/main/java/com/robertx22/mine_and_slash/capability/player/helper/JewelInvHelper.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@
1111
import com.robertx22.mine_and_slash.uncommon.utilityclasses.PlayerUtils;
1212
import net.minecraft.world.entity.LivingEntity;
1313
import net.minecraft.world.entity.player.Player;
14+
import net.minecraft.world.item.Item;
1415
import net.minecraft.world.item.ItemStack;
16+
import net.minecraft.world.item.Items;
1517

1618
import java.util.ArrayList;
1719
import java.util.List;
@@ -82,13 +84,21 @@ public void checkRemoveJewels(Player p) {
8284
ExplainedResultUtil.sendErrorMessage(p, Chats.EQUIP_JEWEL_ERROR, Chats.YOU_LACK_JEWEL_SLOTS);
8385
unequip(p, i);
8486
}
85-
} else {
87+
} else if (!IsPlaceholder(stack)) {
8688
unequip(p, i);
8789
}
8890
}
8991
}
9092

9193

94+
public static boolean IsPlaceholder(ItemStack stack) {
95+
return stack.getDescriptionId().equals(GetPlaceholder().getDescriptionId());
96+
}
97+
98+
public static Item GetPlaceholder() {
99+
return Items.BARRIER;
100+
}
101+
92102
public List<JewelItemData> getAllJewels() {
93103
List<JewelItemData> list = new ArrayList<>();
94104
for (int i = 0; i < inv.getTotalSlots(); i++) {

src/main/java/com/robertx22/mine_and_slash/uncommon/localization/Words.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,8 @@ public enum Words implements IAutoLocName {
364364
INCREASE_PERCENT_STAT("Extra ", "use for stat like \"(Extra) (attack speed)\", this is different with multiply stat prefix."),
365365
REDUCE_PERCENT_STAT("Lower "),
366366
EMPTY_BOX("Box"),
367-
LEVEL_UP_TYPE_PLAYER("Player");
367+
LEVEL_UP_TYPE_PLAYER("Player"),
368+
JEWEL_SOCKET_NOT_AVAILABLE("Unlock on talent tree");
368369

369370

370371
private String localization = "";

src/main/java/com/robertx22/mine_and_slash/vanilla_mc/packets/OpenJewelsPacket.java

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
import com.robertx22.library_of_exile.main.MyPacket;
44
import com.robertx22.library_of_exile.packets.ExilePacketContext;
5+
import com.robertx22.mine_and_slash.capability.player.container.JewelsMenu;
6+
import com.robertx22.mine_and_slash.capability.player.helper.JewelInvHelper;
57
import com.robertx22.mine_and_slash.mmorpg.SlashRef;
68
import com.robertx22.mine_and_slash.uncommon.datasaving.Load;
79
import net.minecraft.network.FriendlyByteBuf;
@@ -11,7 +13,6 @@
1113
import net.minecraft.world.SimpleMenuProvider;
1214
import net.minecraft.world.entity.player.Inventory;
1315
import net.minecraft.world.entity.player.Player;
14-
import net.minecraft.world.inventory.ChestMenu;
1516
import net.minecraft.world.inventory.MenuType;
1617

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

4041
@Override
4142
public void onReceived(ExilePacketContext ctx) {
42-
43-
var inv = Load.player(ctx.getPlayer()).getJewels().inv;
44-
43+
JewelInvHelper jewels = Load.player(ctx.getPlayer()).getJewels();
4544
Player p = ctx.getPlayer();
46-
45+
int maxJewels = jewels.getJewelSocketsMaxStat(p);
4746
p.openMenu(new SimpleMenuProvider((i, playerInventory, playerEntity) -> {
48-
return oneRow(i, playerInventory, inv); // todo why doesnt vanilla have this
47+
return oneRow(i, playerInventory, jewels.inv, maxJewels); // todo why doesnt vanilla have this
4948
}, Component.literal("")));
5049

5150
}
5251

53-
public static ChestMenu oneRow(int pContainerId, Inventory pPlayerInventory, Container pContainer) {
54-
return new ChestMenu(MenuType.GENERIC_9x1, pContainerId, pPlayerInventory, pContainer, 1);
52+
public static JewelsMenu oneRow(int pContainerId, Inventory pPlayerInventory, Container pContainer, int maxJewels) {
53+
return new JewelsMenu(MenuType.GENERIC_9x1, pContainerId, pPlayerInventory, pContainer, 1, maxJewels);
5554
}
5655

5756
@Override

0 commit comments

Comments
 (0)