Skip to content

Commit

Permalink
apply uniqueness to tabs, fix up item tabs
Browse files Browse the repository at this point in the history
  • Loading branch information
sisby-folk committed Dec 5, 2023
1 parent 75c89fd commit 8a854a2
Show file tree
Hide file tree
Showing 14 changed files with 217 additions and 47 deletions.
21 changes: 0 additions & 21 deletions LICENSE

This file was deleted.

165 changes: 165 additions & 0 deletions LICENSE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
GNU LESSER GENERAL PUBLIC LICENSE
Version 3, 29 June 2007

Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.


This version of the GNU Lesser General Public License incorporates
the terms and conditions of version 3 of the GNU General Public
License, supplemented by the additional permissions listed below.

0. Additional Definitions.

As used herein, "this License" refers to version 3 of the GNU Lesser
General Public License, and the "GNU GPL" refers to version 3 of the GNU
General Public License.

"The Library" refers to a covered work governed by this License,
other than an Application or a Combined Work as defined below.

An "Application" is any work that makes use of an interface provided
by the Library, but which is not otherwise based on the Library.
Defining a subclass of a class defined by the Library is deemed a mode
of using an interface provided by the Library.

A "Combined Work" is a work produced by combining or linking an
Application with the Library. The particular version of the Library
with which the Combined Work was made is also called the "Linked
Version".

The "Minimal Corresponding Source" for a Combined Work means the
Corresponding Source for the Combined Work, excluding any source code
for portions of the Combined Work that, considered in isolation, are
based on the Application, and not on the Linked Version.

The "Corresponding Application Code" for a Combined Work means the
object code and/or source code for the Application, including any data
and utility programs needed for reproducing the Combined Work from the
Application, but excluding the System Libraries of the Combined Work.

1. Exception to Section 3 of the GNU GPL.

You may convey a covered work under sections 3 and 4 of this License
without being bound by section 3 of the GNU GPL.

2. Conveying Modified Versions.

If you modify a copy of the Library, and, in your modifications, a
facility refers to a function or data to be supplied by an Application
that uses the facility (other than as an argument passed when the
facility is invoked), then you may convey a copy of the modified
version:

a) under this License, provided that you make a good faith effort to
ensure that, in the event an Application does not supply the
function or data, the facility still operates, and performs
whatever part of its purpose remains meaningful, or

b) under the GNU GPL, with none of the additional permissions of
this License applicable to that copy.

3. Object Code Incorporating Material from Library Header Files.

The object code form of an Application may incorporate material from
a header file that is part of the Library. You may convey such object
code under terms of your choice, provided that, if the incorporated
material is not limited to numerical parameters, data structure
layouts and accessors, or small macros, inline functions and templates
(ten or fewer lines in length), you do both of the following:

a) Give prominent notice with each copy of the object code that the
Library is used in it and that the Library and its use are
covered by this License.

b) Accompany the object code with a copy of the GNU GPL and this license
document.

4. Combined Works.

You may convey a Combined Work under terms of your choice that,
taken together, effectively do not restrict modification of the
portions of the Library contained in the Combined Work and reverse
engineering for debugging such modifications, if you also do each of
the following:

a) Give prominent notice with each copy of the Combined Work that
the Library is used in it and that the Library and its use are
covered by this License.

b) Accompany the Combined Work with a copy of the GNU GPL and this license
document.

c) For a Combined Work that displays copyright notices during
execution, include the copyright notice for the Library among
these notices, as well as a reference directing the user to the
copies of the GNU GPL and this license document.

d) Do one of the following:

0) Convey the Minimal Corresponding Source under the terms of this
License, and the Corresponding Application Code in a form
suitable for, and under terms that permit, the user to
recombine or relink the Application with a modified version of
the Linked Version to produce a modified Combined Work, in the
manner specified by section 6 of the GNU GPL for conveying
Corresponding Source.

1) Use a suitable shared library mechanism for linking with the
Library. A suitable mechanism is one that (a) uses at run time
a copy of the Library already present on the user's computer
system, and (b) will operate properly with a modified version
of the Library that is interface-compatible with the Linked
Version.

e) Provide Installation Information, but only if you would otherwise
be required to provide such information under section 6 of the
GNU GPL, and only to the extent that such information is
necessary to install and execute a modified version of the
Combined Work produced by recombining or relinking the
Application with a modified version of the Linked Version. (If
you use option 4d0, the Installation Information must accompany
the Minimal Corresponding Source and Corresponding Application
Code. If you use option 4d1, you must provide the Installation
Information in the manner specified by section 6 of the GNU GPL
for conveying Corresponding Source.)

5. Combined Libraries.

You may place library facilities that are a work based on the
Library side by side in a single library together with other library
facilities that are not Applications and are not covered by this
License, and convey such a combined library under terms of your
choice, if you do both of the following:

a) Accompany the combined library with a copy of the same work based
on the Library, uncombined with any other library facilities,
conveyed under the terms of this License.

b) Give prominent notice with the combined library that part of it
is a work based on the Library, and explaining where to find the
accompanying uncombined form of the same work.

6. Revised Versions of the GNU Lesser General Public License.

The Free Software Foundation may publish revised and/or new versions
of the GNU Lesser General Public License from time to time. Such new
versions will be similar in spirit to the present version, but may
differ in detail to address new problems or concerns.

Each version is given a distinguishing version number. If the
Library as you received it specifies that a certain numbered version
of the GNU Lesser General Public License "or any later version"
applies to it, you have the option of following the terms and
conditions either of that published version or of any later version
published by the Free Software Foundation. If the Library as you
received it does not specify a version number of the GNU Lesser
General Public License, you may choose any version of the GNU Lesser
General Public License ever published by the Free Software Foundation.

If the Library as you received it specifies that a proxy can decide
whether future versions of the GNU Lesser General Public License shall
apply, that proxy's public statement of acceptance of any version is
permanent authorization for you to choose that version for the
Library.
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,9 @@ Blocks, Entity Types, and Items can be manually assigned to specific concrete ta

Provider IDs can be set to `""` to prevent tabs being provided for that object.

Provider IDs are automatically populated further down in the config, where you can disable the default matching logic for each provider (e.g. the Chest provider matching all AbstractChestBlocks).</br>
This is effectively a more fine-tuned whitelisting mode.
All present provider IDs are automatically populated under `[registryProviderDefaults]`, where you can disable the default matching logic for each provider (e.g. the chest provider matching all AbstractChestBlocks).

If a handled screen shouldn't display tabs, or should display tabs but isn't, its ID can be added to the `allow` and `deny` lists in `tabDisplayFilter`. Read the config for more information.
If a handled screen shouldn't display tabs, or should display tabs but isn't, its handler ID can be added to the `allow` and `deny` lists in `[tabDisplayFilter]`.

### Addons

Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ org.gradle.configureondemand=true
# Enable advanced multi-module optimizations (share tiny-remaper instance between projects)
fabric.loom.multiProjectOptimisation=true
# Mod Properties
baseVersion = 1.0.0
baseVersion = 1.0.1
defaultBranch = 1.20
branch = 1.20
15 changes: 7 additions & 8 deletions src/main/java/folk/sisby/inventory_tabs/TabManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import folk.sisby.inventory_tabs.tabs.ItemTab;
import folk.sisby.inventory_tabs.tabs.Tab;
import folk.sisby.inventory_tabs.tabs.VehicleInventoryTab;
import folk.sisby.inventory_tabs.util.CursorStackUtil;
import folk.sisby.inventory_tabs.util.HandlerSlotUtil;
import folk.sisby.inventory_tabs.util.MouseUtil;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.client.MinecraftClient;
Expand All @@ -17,7 +17,7 @@
import net.minecraft.client.sound.PositionedSoundInstance;
import net.minecraft.client.util.math.Rect2i;
import net.minecraft.entity.Entity;
import net.minecraft.item.ItemStack;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.network.packet.c2s.play.HandledScreenCloseC2SPacket;
import net.minecraft.sound.SoundEvents;
import net.minecraft.text.Text;
Expand Down Expand Up @@ -53,7 +53,7 @@ public static void initScreen(MinecraftClient client, HandledScreen<?> screen) {
if (!tabOpenedRecently) onOpenTab(guessOpenedTab(client, screen));
tabOpenedRecently = false;
if (!skipRestore) {
CursorStackUtil.tryPop(MinecraftClient.getInstance().player, MinecraftClient.getInstance().interactionManager, currentScreen.getScreenHandler());
HandlerSlotUtil.tryPop(MinecraftClient.getInstance().player, MinecraftClient.getInstance().interactionManager, currentScreen.getScreenHandler());
MouseUtil.tryPop();
} else {
skipRestore = false;
Expand Down Expand Up @@ -93,11 +93,10 @@ public static Tab guessOpenedTab(MinecraftClient client, HandledScreen<?> screen
}
}
// Hand Guesses
for (ItemStack stack : client.player.getItemsHand()) {
if (stack.isEmpty()) continue;
for (int slot : List.of(client.player.getInventory().selectedSlot, PlayerInventory.OFF_HAND_SLOT)) {
for (Tab tab : tabs) {
if (tab instanceof ItemTab it) {
if (stack.equals(it.stack)) {
if (slot == it.slot) {
return tab;
}
}
Expand Down Expand Up @@ -190,14 +189,14 @@ public static boolean keyPressed(int keyCode, int scanCode, int modifiers) {

public static void onTabClick(Tab tab) {
MouseUtil.push();
CursorStackUtil.push(MinecraftClient.getInstance().player, MinecraftClient.getInstance().interactionManager, currentScreen.getScreenHandler());
HandlerSlotUtil.push(MinecraftClient.getInstance().player, MinecraftClient.getInstance().interactionManager, currentScreen.getScreenHandler());
skipRestore = true;
tabOpenedRecently = true;
MinecraftClient.getInstance().getNetworkHandler().sendPacket(new HandledScreenCloseC2SPacket(currentScreen.getScreenHandler().syncId));
if (tab.open()) {
onOpenTab(tab);
if (!skipRestore) {
CursorStackUtil.tryPop(MinecraftClient.getInstance().player, MinecraftClient.getInstance().interactionManager, currentScreen.getScreenHandler());
HandlerSlotUtil.tryPop(MinecraftClient.getInstance().player, MinecraftClient.getInstance().interactionManager, currentScreen.getScreenHandler());
MouseUtil.tryPop();
}
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,6 @@ public void addAvailableTabs(ClientPlayerEntity player, Consumer<Tab> addTab) {
}

public Tab createTab(World world, BlockPos pos) {
return new BlockTab(0, world, pos);
return new BlockTab(0, world, pos, isUnique());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public EnderChestTabProvider() {

@Override
public Tab createTab(World world, BlockPos pos) {
return new BlockTab(-5, world, pos);
return new BlockTab(-5, world, pos, isUnique());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@ public void addAvailableTabs(ClientPlayerEntity player, Consumer<Tab> addTab) {
}

public Tab createTab(ItemStack stack, int slot) {
return new ItemTab(stack, slot);
return new ItemTab(stack, slot, isUnique());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public SimpleBlockTabProvider() {

@Override
public Tab createTab(World world, BlockPos pos) {
return new BlockTab(30, world, pos);
return new BlockTab(30, world, pos, isUnique());
}

@Override
Expand Down
12 changes: 10 additions & 2 deletions src/main/java/folk/sisby/inventory_tabs/tabs/BlockTab.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,13 @@ public class BlockTab implements Tab {
public final int priority;
public final Block block;
public final BlockPos pos;
public final boolean unique;
public ItemStack itemStack;
public Text hoverText;

public BlockTab(int priority, World world, BlockPos pos) {
public BlockTab(int priority, World world, BlockPos pos, boolean unique) {
this.priority = priority;
this.unique = unique;
this.block = world.getBlockState(pos).getBlock();
this.pos = pos;
refreshPreview(world);
Expand Down Expand Up @@ -96,6 +98,12 @@ public int getPriority() {

@Override
public boolean equals(Object other) {
return other != null && getClass() == other.getClass() && Objects.equals(pos, ((BlockTab) other).pos);
if (other == null) return false;
if (unique) {
return other instanceof ItemTab it && Objects.equals(block.asItem(), it.stack.getItem()) ||
other instanceof BlockTab bt && Objects.equals(block, bt.block);
} else {
return other instanceof BlockTab bt && Objects.equals(pos, bt.pos);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class ChestBlockTab extends BlockTab {
public BlockPos leftPos;

public ChestBlockTab(int priority, World world, BlockPos pos) {
super(priority, world, pos);
super(priority, world, pos, false);
shouldBeRemoved(world, false);
}

Expand Down
19 changes: 14 additions & 5 deletions src/main/java/folk/sisby/inventory_tabs/tabs/ItemTab.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package folk.sisby.inventory_tabs.tabs;

import folk.sisby.inventory_tabs.util.HandlerSlotUtil;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.gui.screen.ingame.HandledScreen;
Expand All @@ -18,10 +19,12 @@
public class ItemTab implements Tab {
public final ItemStack stack;
public final int slot;
public final boolean unique;

public ItemTab(ItemStack stack, int slot) {
public ItemTab(ItemStack stack, int slot, boolean unique) {
this.stack = stack;
this.slot = slot;
this.unique = unique;
}

@Override
Expand All @@ -32,9 +35,9 @@ public boolean open() {
ScreenHandler handler = hs.getScreenHandler();
OptionalInt slotIndex = handler.getSlotIndex(player.getInventory(), slot);
if (slotIndex.isPresent()) {
MinecraftClient.getInstance().interactionManager.clickSlot(handler.syncId, slotIndex.getAsInt(), 40, SlotActionType.SWAP, player);
stack.use(MinecraftClient.getInstance().world, player, Hand.OFF_HAND);
MinecraftClient.getInstance().interactionManager.clickSlot(handler.syncId, slotIndex.getAsInt(), 40, SlotActionType.SWAP, player);
MinecraftClient.getInstance().interactionManager.clickSlot(handler.syncId, slotIndex.getAsInt(), player.getInventory().selectedSlot, SlotActionType.SWAP, player);
MinecraftClient.getInstance().interactionManager.interactItem(player, Hand.MAIN_HAND);
HandlerSlotUtil.mainHandSwapSlot = slot;
return true;
}
}
Expand All @@ -60,6 +63,12 @@ public ItemStack getTabIcon() {

@Override
public boolean equals(Object other) {
return other != null && getClass() == other.getClass() && Objects.equals(slot, ((ItemTab) other).slot);
if (other == null) return false;
if (unique) {
return other instanceof ItemTab it && Objects.equals(stack.getItem(), it.stack.getItem()) ||
other instanceof BlockTab bt && Objects.equals(stack.getItem(), bt.block.asItem());
} else {
return other instanceof ItemTab it && Objects.equals(slot, it.slot);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

public class ShulkerBoxBlockTab extends BlockTab {
public ShulkerBoxBlockTab(World world, BlockPos pos) {
super(-50, world, pos);
super(-50, world, pos, false);
}

@Override
Expand Down
Loading

0 comments on commit 8a854a2

Please sign in to comment.