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
Expand Up @@ -182,7 +182,7 @@ private boolean couldOpenScreen() {
ItemList entries = itemGroupManager.getList(itemInHand);

if (entries != null) {
if (configManager.getConfig().listsAsPalette) {
if (configManager.getConfig().listsAsPalette || entries.isPaletteList()) {
openPage(new ItemGroupManager.ListPage(entries));
} else {
openScreen(new ItemListOverlay(entries));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public void reset() {
listMapping.clear();
groupMapping.clear();
paletteMapping.clear();
lastPicked.clear();
}

public void registerItemGroup(ItemGroup group) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ public void onResourceManagerReload(ResourceManager resourceManager) {
itemGroupModifiers.clear();
itemListModifiers.clear();
itemLists.clear();
ItemSwapperSharedMod.instance.getItemGroupManager().reset();
resourceManager.listResources("itemgroups", id -> id.getPath().endsWith(".json")).forEach((id, resourceRef) -> {
try {
InputStream stream = resourceRef.open();
Expand Down Expand Up @@ -216,6 +217,11 @@ private void processList(/*? >= 1.21.11 {*/ Identifier /*?} else {*//* ResourceL
if (ignoreItems != null && ignoreItems.length > 0) {
group.withIgnoreItems(new HashSet<>(Arrays.asList(ignoreItems)));
}
group.withShortcuts(processShortcuts(jsonLocation, json.get("shortcuts")));
if (json.has("paletteList") && json.get("paletteList").isJsonPrimitive()
&& json.get("paletteList").getAsBoolean()) {
group.withPaletteList(true);
}
if (json.has("icon") && json.get("icon").isJsonPrimitive()) {
group.withIcon(
dev.tr7zw.transition.mc.ItemUtil.getItem(getResourceLocation(json.get("icon").getAsString())));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package dev.tr7zw.itemswapper.manager.itemgroups;

import java.util.Collections;
import java.util.Set;
import java.util.*;

import net.minecraft.network.chat.Component;
import net.minecraft.resources.*;
Expand All @@ -17,6 +16,8 @@ public class ItemList {
private final Set<Item> ignoreItems;
private final boolean disableAutoLink;
private final/*? >= 1.21.11 {*/ Identifier /*?} else {*//* ResourceLocation *//*?}*/ link;
private final List<Shortcut> shortcuts;
private boolean paletteList = false;

private ItemList(Builder builder) {
this.id = builder.id;
Expand All @@ -27,6 +28,8 @@ private ItemList(Builder builder) {
this.ignoreItems = builder.ignoreItems;
this.disableAutoLink = builder.disableAutoLink;
this.link = builder.link;
this.shortcuts = builder.shortcuts;
this.paletteList = builder.paletteList;
}

public/*? >= 1.21.11 {*/ Identifier /*?} else {*//* ResourceLocation *//*?}*/ getId() {
Expand Down Expand Up @@ -61,6 +64,14 @@ public Set<Item> getIgnoreItems() {
return link;
}

public List<Shortcut> getShortcuts() {
return shortcuts;
}

public boolean isPaletteList() {
return paletteList;
}

public static Builder builder() {
return new Builder();
}
Expand All @@ -74,6 +85,8 @@ public static final class Builder {
private Set<Item> ignoreItems = Collections.emptySet();
private boolean disableAutoLink;
private/*? >= 1.21.11 {*/ Identifier /*?} else {*//* ResourceLocation *//*?}*/ link;
private List<Shortcut> shortcuts = Collections.emptyList();
private boolean paletteList = false;

private Builder() {
}
Expand Down Expand Up @@ -118,6 +131,16 @@ public Builder withLink(/*? >= 1.21.11 {*/ Identifier /*?} else {*//* ResourceLo
return this;
}

public Builder withShortcuts(List<Shortcut> shortcuts) {
this.shortcuts = shortcuts;
return this;
}

public Builder withPaletteList(boolean paletteList) {
this.paletteList = paletteList;
return this;
}

public/*? >= 1.21.11 {*/ Identifier /*?} else {*//* ResourceLocation *//*?}*/ getId() {
return id;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,8 @@ public void openItemList(ItemList items) {
selectionHandler.addWidget(mainWidget);
selectionHandler.addWidget(new ShortcutListWidget(items.getId(), shortcutList,
mainWidget.getWidgetArea().getMouseBoundsX() + ItemSwapperUI.slotSize, 1));
selectionHandler.addWidget(new ShortcutListWidget(items.getId(), items.getShortcuts(),
-mainWidget.getWidgetArea().getMouseBoundsX() - ItemSwapperUI.slotSize, 1));
}

public boolean openPage(Page page) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,21 @@
import java.util.List;
import java.util.concurrent.atomic.AtomicBoolean;

import dev.tr7zw.itemswapper.*;
import dev.tr7zw.itemswapper.api.AvailableSlot;
import dev.tr7zw.itemswapper.api.client.ItemSwapperClientAPI.OnSwap;
import dev.tr7zw.itemswapper.api.client.ItemSwapperClientAPI.SwapSent;
import dev.tr7zw.itemswapper.manager.itemgroups.ItemList;
import dev.tr7zw.itemswapper.overlay.SwitchItemOverlay;
import dev.tr7zw.transition.mc.InventoryUtil;
import dev.tr7zw.transition.mc.*;
import dev.tr7zw.itemswapper.util.ItemUtil;
import dev.tr7zw.itemswapper.util.NetworkUtil;
import dev.tr7zw.itemswapper.util.RenderHelper;
import dev.tr7zw.itemswapper.util.RenderHelper.SlotEffect;
import dev.tr7zw.itemswapper.util.WidgetUtil;
import dev.tr7zw.trender.gui.client.RenderContext;
import net.minecraft.world.inventory.ClickType;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.*;

public class ListContentWidget extends ItemGridWidget {

Expand All @@ -34,6 +35,17 @@ public ListContentWidget(ItemList items, int x, int y) {

private void refreshList() {
entries.clear();
if (itemSelection.isPaletteList()) {
for (int i = 0; i < itemSelection.getItems().length; i++) {
List<AvailableSlot> availableSlots = resolveItem(i);
if (availableSlots.isEmpty() || !dev.tr7zw.transition.mc.ItemUtil.isSame(availableSlots.get(0).item(),
itemSelection.getItems()[i].getDefaultInstance())) {
entries.add(null);
} else {
entries.add(availableSlots.get(0));
}
}
}
for (Item item : itemSelection.getItems()) {
List<AvailableSlot> ids = providerManager.findSlotsMatchingItem(item, false, false);
for (AvailableSlot id : ids) {
Expand All @@ -44,21 +56,33 @@ private void refreshList() {
}
}

private List<AvailableSlot> getItem(int id) {
return id > entries.size() - 1 ? Collections.emptyList() : Collections.singletonList(entries.get(id));
private List<AvailableSlot> resolveItem(int id) {
return id > itemSelection.getItems().length - 1 ? Collections.emptyList()
: providerManager.findSlotsMatchingItem(itemSelection.getItems()[id], false, false);
}

@Override
protected void renderSlot(RenderContext graphics, int x, int y, List<Runnable> itemRenderList, GuiSlot guiSlot,
boolean overwrideAvailable) {
List<AvailableSlot> slots = getItem(guiSlot.id());
if (!slots.isEmpty() && !overwrideAvailable) {
itemRenderList.add(() -> RenderHelper.renderSlot(graphics, x + 3, y + 4, minecraft.player,
slots.get(0).item(), 1, SlotEffect.NONE, slots.get(0).amount().get()));
AvailableSlot slot = guiSlot.id() < entries.size() ? entries.get(guiSlot.id()) : null;
if (slot != null && !overwrideAvailable) {
SlotEffect effect = itemSelection.isPaletteList() && guiSlot.id() >= itemSelection.getItems().length
? SlotEffect.YELLOW
: SlotEffect.NONE;
itemRenderList.add(() -> RenderHelper.renderSlot(graphics, x + 3, y + 4, minecraft.player, slot.item(), 1,
effect, slot.amount().get()));

} else if (guiSlot.id() <= entries.size() - 1) {
itemRenderList.add(() -> RenderHelper.renderSlot(graphics, x + 3, y + 4, minecraft.player,
entries.get(guiSlot.id()).item(), 1, !overwrideAvailable ? SlotEffect.RED : SlotEffect.NONE, 1));
if (entries.get(guiSlot.id()) == null) {
itemRenderList.add(() -> RenderHelper.renderSlot(graphics, x + 3, y + 4, minecraft.player,
itemSelection.getItems()[guiSlot.id()].getDefaultInstance(), 1,
!overwrideAvailable ? SlotEffect.RED : SlotEffect.NONE, 0));
} else {
itemRenderList.add(() -> RenderHelper.renderSlot(graphics, x + 3, y + 4, minecraft.player,
entries.get(guiSlot.id()).item(), 1,
guiSlot.id() < itemSelection.getItems().length ? SlotEffect.NONE : SlotEffect.YELLOW,
entries.get(guiSlot.id()).amount().get()));
}
}
}

Expand Down Expand Up @@ -89,6 +113,22 @@ public boolean onPrimaryClick(SwitchItemOverlay overlay, GuiSlot guiSlot, int xO
}
clientAPI.itemSwapSentEvent.callEvent(new SwapSent(entry));
return false;
} else if (guiSlot.id() < itemSelection.getItems().length && minecraft.player.isCreative()
&& configManager.getConfig().creativeCheatMode) {
// stash away current item, if its not a default item to prevent item loss
ItemStack itemInHand = GeneralUtil.getPlayer().getMainHandItem();
if (!itemInHand.isEmpty() && !dev.tr7zw.transition.mc.ItemUtil.isSame(itemInHand,
itemInHand.getItem().getDefaultInstance())) {
ItemUtil.grabItem(Items.AIR, true);
}
minecraft.gameMode.handleCreativeModeItemAdd(
itemSelection.getItems()[guiSlot.id()].getDefaultInstance().copy(),
36 + InventoryUtil.getSelectedId(minecraft.player.getInventory()));
minecraft.player.getInventory().setItem(InventoryUtil.getSelectedId(minecraft.player.getInventory()),
itemSelection.getItems()[guiSlot.id()].getDefaultInstance().copy());
ItemSwapperSharedMod.instance.setLastItem(itemSelection.getItems()[guiSlot.id()]);
ItemSwapperSharedMod.instance.setLastPage(overlay.getLastPages().get(overlay.getLastPages().size() - 1));
return false;
}
return true;
}
Expand All @@ -101,6 +141,12 @@ public void renderSelectedSlotName(GuiSlot selected, int yOffset, int maxWidth,
}
AvailableSlot slot = entries.get(selected.id());
if (slot == null) {
if (itemSelection.isPaletteList()) {
RenderHelper.renderSelectedItemName(
ItemUtil.getDisplayname(itemSelection.getItems()[selected.id()].getDefaultInstance()),
itemSelection.getItems()[selected.id()].getDefaultInstance(), false, yOffset, maxWidth,
graphics);
}
return;
}
RenderHelper.renderSelectedItemName(ItemUtil.getDisplayname(slot.item()), slot.item(), false, yOffset, maxWidth,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public PaletteWidget(ItemGroup itemGroup, int x, int y) {
super(x, y);
this.itemGroup = itemGroup;
WidgetUtil.setupDynamicSlots(widgetArea, slots, itemGroup.getItems().length);
for(int i = 0; i < itemGroup.getItems().length; i++) {
for (int i = 0; i < itemGroup.getItems().length; i++) {
availableSlots.add(resolveItem(i));
}
}
Expand All @@ -37,8 +37,7 @@ private List<AvailableSlot> resolveItem(int id) {
}

private List<AvailableSlot> getItem(int id) {
return id > itemGroup.getItems().length - 1 ? Collections.emptyList()
: availableSlots.get(id);
return id > itemGroup.getItems().length - 1 ? Collections.emptyList() : availableSlots.get(id);
}

@Override
Expand Down
14 changes: 9 additions & 5 deletions src/main/java/dev/tr7zw/itemswapper/util/RenderHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,8 @@ public static void renderUnavailableItem(RenderContext graphics, LivingEntity li
int l = i;
int m = j;
int color = 0;
if (effect == SlotEffect.RED) {
color = 822018048;
} else if (effect == SlotEffect.GRAY) {
color = -1879048192;
if (effect != SlotEffect.NONE) {
color = effect.color;
}
// these values need to be fixed when the texture size gets fixed.
graphics.fill(l - 1, m - 1, l + 17, m + 17, color);
Expand Down Expand Up @@ -94,7 +92,13 @@ public static void renderGuiItemText(Font font, String text, int i, int j, int c
}

public enum SlotEffect {
NONE, RED, GRAY
NONE(0), RED(822018048), GRAY(-1879048192), YELLOW(687865610);

public int color;

SlotEffect(int color) {
this.color = color;
}
}

public static void renderSlot(RenderContext graphics, int x, int y, Player arg, ItemStack arg2, int k,
Expand Down
18 changes: 10 additions & 8 deletions src/main/java/dev/tr7zw/itemswapper/util/WidgetUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -144,21 +144,22 @@ public static void setupDynamicSlots(WidgetArea widgetArea, List<GuiSlot> slots,
} else if (length <= 25) {
setupSlots(widgetArea, slots, 5, 5, false, BACKGROUND_25_LOCATION);
} else if (length <= 28) {
setupSlots(widgetArea, slots, new int[]{3, 7, 8, 7, 3}, BACKGROUND_28_LOCATION);
setupSlots(widgetArea, slots, new int[] { 3, 7, 8, 7, 3 }, BACKGROUND_28_LOCATION);
} else if (length <= 30) {
setupSlots(widgetArea, slots, new int[]{6, 6, 6, 6, 6, 6}, BACKGROUND_30_LOCATION);
setupSlots(widgetArea, slots, new int[] { 6, 6, 6, 6, 6, 6 }, BACKGROUND_30_LOCATION);
} else if (length <= 33) {
setupSlots(widgetArea, slots, new int[]{6, 7, 7, 7, 6}, BACKGROUND_33_LOCATION);
setupSlots(widgetArea, slots, new int[] { 6, 7, 7, 7, 6 }, BACKGROUND_33_LOCATION);
} else if (length <= 35) {
setupSlots(widgetArea, slots, new int[]{6, 7, 9, 7, 6}, BACKGROUND_35_LOCATION);
setupSlots(widgetArea, slots, new int[] { 6, 7, 9, 7, 6 }, BACKGROUND_35_LOCATION);
} else if (length <= 38) {
setupSlots(widgetArea, slots, new int[]{6, 8, 10, 8, 6}, BACKGROUND_38_LOCATION);
setupSlots(widgetArea, slots, new int[] { 6, 8, 10, 8, 6 }, BACKGROUND_38_LOCATION);
} else {
setupSlots(widgetArea, slots, new int[]{8, 8, 8, 8, 8}, BACKGROUND_40_LOCATION);
setupSlots(widgetArea, slots, new int[] { 8, 8, 8, 8, 8 }, BACKGROUND_40_LOCATION);
}
}

public static void setupSlots(WidgetArea widgetArea, List<GuiSlot> slots, int[] lines, /*? >= 1.21.11 {*/ Identifier /*?} else {*//* ResourceLocation *//*?}*/ texture) {
public static void setupSlots(WidgetArea widgetArea, List<GuiSlot> slots, int[] lines,
/*? >= 1.21.11 {*/ Identifier /*?} else {*//* ResourceLocation *//*?}*/ texture) {
int maxWidth = 0;
for (int line : lines) {
if (line > maxWidth) {
Expand All @@ -179,7 +180,8 @@ public static void setupSlots(WidgetArea widgetArea, List<GuiSlot> slots, int[]
for (int y = 0; y < lines.length; y++) {
int xOffset = (maxWidth - lines[y]) % 2 == 1 ? sz / 2 : 0;
for (int x = 0; x < lines[y]; x++) {
slots.add(new GuiSlot(originX + xOffset + ((maxWidth - lines[y]) / 2 + x) * sz, originY + y * sz, slotId, ItemSwapperUI.tinySlotSize));
slots.add(new GuiSlot(originX + xOffset + ((maxWidth - lines[y]) / 2 + x) * sz, originY + y * sz,
slotId, ItemSwapperUI.tinySlotSize));
slotId++;
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"type": "list",
"priority": 20,
"displayName": "text.itemswapper.list.armor",
"priority": 50,
"displayName": "text.itemswapper.directory.armor",
"link": "itemswapper:v2/tools",
"items": [
"minecraft:netherite_helmet",
Expand Down Expand Up @@ -31,6 +31,7 @@
"minecraft:leather_helmet",
"minecraft:leather_chestplate",
"minecraft:leather_leggings",
"minecraft:leather_boots"
"minecraft:leather_boots",
"minecraft:elytra"
]
}
Loading
Loading