Skip to content
Open
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
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ license=LGPL-3.0-or-later
# Mod Version
baseVersion=1.4.0
# Branch Metadata
branch=1.21
branch=1.21.3
tagBranch=1.20
compatibleVersions=1.21, 1.21.1
compatibleVersions=1.21.3, 1.21.4
compatibleLoaders=fabric, quilt, neoforge
8 changes: 4 additions & 4 deletions libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ minotaur = "2.+"

kaleidoConfig = "0.3.1+1.3.2"

mc = "1.21"
fl = "0.15.11"
yarn = "1.21+build.9"
fapi = "0.101.2+1.21"
mc = "1.21.3"
fl = "0.16.9"
yarn = "1.21.3+build.2"
fapi = "0.114.0+1.21.3"

[plugins]
loom = { id = "fabric-loom", version.ref = "loom" }
Expand Down
28 changes: 19 additions & 9 deletions src/main/java/folk/sisby/inventory_tabs/ControlHintToast.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package folk.sisby.inventory_tabs;

import net.minecraft.client.MinecraftClient;
import net.minecraft.client.font.TextRenderer;
import net.minecraft.client.gui.DrawContext;
import net.minecraft.client.option.KeyBinding;
import net.minecraft.client.render.RenderLayer;
import net.minecraft.client.toast.Toast;
import net.minecraft.client.toast.ToastManager;
import net.minecraft.text.Text;
Expand All @@ -16,6 +18,7 @@ public class ControlHintToast implements Toast {
protected KeyBinding keyBinding;
protected int titleWidth;
protected int hintWidth;
private Toast.Visibility visibility = Toast.Visibility.HIDE;

public ControlHintToast(Text title, KeyBinding keybinding) {
this.title = title;
Expand All @@ -25,19 +28,26 @@ public ControlHintToast(Text title, KeyBinding keybinding) {
hintWidth = MinecraftClient.getInstance().textRenderer.getWidth(keyHint);
}

@Override
public Visibility getVisibility() {
return this.visibility;
}

@Override
public Visibility draw(DrawContext context, ToastManager manager, long elapsedTime) {
context.drawGuiTexture(TEXTURE, 0, 0, getWidth(), getHeight());
context.drawText(manager.getClient().textRenderer, title, (getWidth() - titleWidth) / 2, 7, 0xFFFFFF, false);
context.drawText(manager.getClient().textRenderer, keyHint, (getWidth() - hintWidth) / 2, 18, 0xFFFFFF, false);
@Override
public void update(ToastManager manager, long elapsedTime) {
double time = 2000 * manager.getNotificationDisplayTimeMultiplier();

double time = 2000 * manager.getNotificationDisplayTimeMultiplier();
this.visibility = elapsedTime >= time ? Visibility.HIDE : Visibility.SHOW;
}

return elapsedTime >= time ? Visibility.HIDE : Visibility.SHOW;
}
@Override
public void draw(DrawContext context, TextRenderer textRenderer, long startTime) {
context.drawGuiTexture(RenderLayer::getGuiTextured, TEXTURE, 0, 0, getWidth(), getHeight());
context.drawText(textRenderer, title, (getWidth() - titleWidth) / 2, 7, 0xFFFFFF, false);
context.drawText(textRenderer, keyHint, (getWidth() - hintWidth) / 2, 18, 0xFFFFFF, false);
}

@Override
@Override
public int getWidth() {
return Math.max(titleWidth, hintWidth) + 24;
}
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/folk/sisby/inventory_tabs/TabManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import net.minecraft.client.network.ClientPlayNetworkHandler;
import net.minecraft.client.network.ClientPlayerEntity;
import net.minecraft.client.network.ClientPlayerInteractionManager;
import net.minecraft.client.render.RenderLayer;
import net.minecraft.client.sound.PositionedSoundInstance;
import net.minecraft.client.util.math.Rect2i;
import net.minecraft.client.world.ClientWorld;
Expand Down Expand Up @@ -303,7 +304,7 @@ public static void drawButton(DrawContext drawContext, double mouseX, double mou
boolean active = left ? currentPage > 0 : currentPage < getMaximumPage();
int u = BUTTON_WIDTH * (left ? 0 : 1);
int v = BUTTON_HEIGHT * (active ? hovered ? 2 : 1 : 0);
drawContext.drawTexture(BUTTONS_TEXTURE, rect.getX(), rect.getY(), u, v, rect.getWidth(), rect.getHeight());
drawContext.drawTexture(RenderLayer::getGuiTextured, BUTTONS_TEXTURE, rect.getX(), rect.getY(), u, v, rect.getWidth(), rect.getHeight(), 256, 256);
if (hovered) drawContext.drawTooltip(MinecraftClient.getInstance().textRenderer, Text.literal((currentPage + 1) + "/" + (getMaximumPage() + 1)), (int) mouseX, (int) mouseY);
}

Expand Down
8 changes: 4 additions & 4 deletions src/main/java/folk/sisby/inventory_tabs/TabProviders.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public static void reload(DynamicRegistryManager manager) {
InventoryTabs.LOGGER.info("[InventoryTabs] Reloading tab providers.");
refreshConfigPlaceholders();
if (InventoryTabs.CONFIG.configLogging) {
Map<String, List<RegistryKey<ScreenHandlerType<?>>>> types = manager.get(RegistryKeys.SCREEN_HANDLER).getKeys().stream().filter(k -> ScreenSupport.allowTabs(k) == null && InventoryTabs.CONFIG.allowScreensByDefault).collect(Collectors.groupingBy(k -> k.getValue().getNamespace()));
Map<String, List<RegistryKey<ScreenHandlerType<?>>>> types = manager.getOrThrow(RegistryKeys.SCREEN_HANDLER).getKeys().stream().filter(k -> ScreenSupport.allowTabs(k) == null && InventoryTabs.CONFIG.allowScreensByDefault).collect(Collectors.groupingBy(k -> k.getValue().getNamespace()));
if (!types.isEmpty()) {
InventoryTabs.LOGGER.warn("[Inventory Tabs] {} Automatically tabbed screen handlers:", types.values().stream().mapToInt(Collection::size).sum());
types.forEach((namespace, ids) -> InventoryTabs.LOGGER.info(" | {}: {}", namespace, ids.stream().map(RegistryKey::getValue).map(Identifier::getPath).collect(Collectors.joining(", "))));
Expand Down Expand Up @@ -122,8 +122,8 @@ public static <T> Set<T> reloadRegistryProviders(DynamicRegistryManager manager,
unsortedOverrides.entrySet().stream().sorted(Comparator.comparingInt(e -> e.getKey().priority())).forEach(e -> overrides.put(e.getKey(), e.getValue()));

// Add values to providers
for (Map.Entry<RegistryKey<T>, T> entry : manager.get(registryKey).getEntrySet()) {
RegistryEntry<T> holder = manager.createRegistryLookup().getOptional(registryKey).orElseThrow().getOrThrow(entry.getKey());
for (Map.Entry<RegistryKey<T>, T> entry : manager.getOrThrow(registryKey).getEntrySet()) {
RegistryEntry<T> holder = manager.getOptional(registryKey).orElseThrow().getOrThrow(entry.getKey());

Optional<Map.Entry<RegistryMatcher<T>, RegistryTabProvider<T>>> override = overrides.entrySet().stream().filter(e -> e.getKey().is(holder)).findFirst();
if (override.isPresent()) {
Expand Down Expand Up @@ -209,4 +209,4 @@ public static <T extends TabProvider> T register(Identifier id, T tabProvider) {
REGISTRY.put(id, tabProvider);
return tabProvider;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import net.minecraft.client.gui.DrawContext;
import net.minecraft.client.gui.screen.ingame.GenericContainerScreen;
import net.minecraft.client.gui.screen.ingame.HandledScreen;
import net.minecraft.client.render.RenderLayer;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.screen.GenericContainerScreenHandler;
import net.minecraft.text.Text;
Expand Down Expand Up @@ -46,39 +47,39 @@ public void containerTextHeight(GenericContainerScreenHandler handler, PlayerInv

@Inject(method = "drawBackground", at = @At("TAIL"))
public void containerHeader(DrawContext drawContext, float delta, int mouseX, int mouseY, CallbackInfo ci) {
drawContext.drawTexture(TEXTURE, (this.width - this.backgroundWidth) / 2, (this.height - this.backgroundHeight) / 2, 0, 0, this.backgroundWidth, 7);
drawContext.drawTexture(RenderLayer::getGuiTextured, TEXTURE, (this.width - this.backgroundWidth) / 2, (this.height - this.backgroundHeight) / 2, 0, 0, this.backgroundWidth, 7, 256, 256);
}

@ModifyArg(method = "drawBackground", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/DrawContext;drawTexture(Lnet/minecraft/util/Identifier;IIIIII)V", ordinal = 0), index = 2)
@ModifyArg(method = "drawBackground", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/DrawContext;drawTexture(Ljava/util/function/Function;Lnet/minecraft/util/Identifier;IIFFIIII)V", ordinal = 0), index = 3)
public int containerY(int original) {
return original + 7;
}

@ModifyArg(method = "drawBackground", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/DrawContext;drawTexture(Lnet/minecraft/util/Identifier;IIIIII)V", ordinal = 0), index = 4)
public int containerV(int original) {
@ModifyArg(method = "drawBackground", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/DrawContext;drawTexture(Ljava/util/function/Function;Lnet/minecraft/util/Identifier;IIFFIIII)V", ordinal = 0), index = 5)
public float containerV(float original) {
if (rows == 6 && InventoryTabs.CONFIG.compactLargeContainers) return original + 17;
return original + 8;
}

@ModifyArg(method = "drawBackground", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/DrawContext;drawTexture(Lnet/minecraft/util/Identifier;IIIIII)V", ordinal = 0), index = 6)
@ModifyArg(method = "drawBackground", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/DrawContext;drawTexture(Ljava/util/function/Function;Lnet/minecraft/util/Identifier;IIFFIIII)V", ordinal = 0), index = 7)
public int containerHeight(int original) {
if (rows == 6 && InventoryTabs.CONFIG.compactLargeContainers) return original - 17;
return original - 8;
}

@ModifyArg(method = "drawBackground", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/DrawContext;drawTexture(Lnet/minecraft/util/Identifier;IIIIII)V", ordinal = 1), index = 2)
@ModifyArg(method = "drawBackground", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/DrawContext;drawTexture(Ljava/util/function/Function;Lnet/minecraft/util/Identifier;IIFFIIII)V", ordinal = 1), index = 3)
public int inventoryY(int original) {
if (rows == 6 && InventoryTabs.CONFIG.compactLargeContainers) return original - 10;
return original - 1;
}

@ModifyArg(method = "drawBackground", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/DrawContext;drawTexture(Lnet/minecraft/util/Identifier;IIIIII)V", ordinal = 1), index = 4)
public int inventoryV(int original) {
@ModifyArg(method = "drawBackground", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/DrawContext;drawTexture(Ljava/util/function/Function;Lnet/minecraft/util/Identifier;IIFFIIII)V", ordinal = 1), index = 5)
public float inventoryV(float original) {
if (rows == 6 && InventoryTabs.CONFIG.compactLargeContainers) return original + 9;
return original;
}

@ModifyArg(method = "drawBackground", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/DrawContext;drawTexture(Lnet/minecraft/util/Identifier;IIIIII)V", ordinal = 1), index = 6)
@ModifyArg(method = "drawBackground", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/DrawContext;drawTexture(Ljava/util/function/Function;Lnet/minecraft/util/Identifier;IIFFIIII)V", ordinal = 1), index = 7)
public int inventoryHeight(int original) {
if (rows == 6 && InventoryTabs.CONFIG.compactLargeContainers) return original - 9;
return original;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,14 @@
public abstract class MixinGenericContainerScreenHandler {
@Shadow @Final private int rows;

@ModifyArg(method = "<init>(Lnet/minecraft/screen/ScreenHandlerType;ILnet/minecraft/entity/player/PlayerInventory;Lnet/minecraft/inventory/Inventory;I)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/screen/slot/Slot;<init>(Lnet/minecraft/inventory/Inventory;III)V", ordinal = 0), index = 3)
@ModifyArg(method = "addInventorySlots", at = @At(value = "INVOKE", target = "Lnet/minecraft/screen/slot/Slot;<init>(Lnet/minecraft/inventory/Inventory;III)V", ordinal = 0), index = 3)
public int raiseContainerSlotY(int original) {
if (rows == 6 && InventoryTabs.CONFIG.compactLargeContainers) return original - 10;
return original - 1;
}

@ModifyArg(method = "<init>(Lnet/minecraft/screen/ScreenHandlerType;ILnet/minecraft/entity/player/PlayerInventory;Lnet/minecraft/inventory/Inventory;I)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/screen/slot/Slot;<init>(Lnet/minecraft/inventory/Inventory;III)V", ordinal = 1), index = 3)
public int raiseInventorySlotY(int original) {
if (rows == 6 && InventoryTabs.CONFIG.compactLargeContainers) return original - 19;
return original - 1;
}

@ModifyArg(method = "<init>(Lnet/minecraft/screen/ScreenHandlerType;ILnet/minecraft/entity/player/PlayerInventory;Lnet/minecraft/inventory/Inventory;I)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/screen/slot/Slot;<init>(Lnet/minecraft/inventory/Inventory;III)V", ordinal = 2), index = 3)
public int raiseHotbarSlotY(int original) {
@ModifyArg(method = "<init>(Lnet/minecraft/screen/ScreenHandlerType;ILnet/minecraft/entity/player/PlayerInventory;Lnet/minecraft/inventory/Inventory;I)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/screen/GenericContainerScreenHandler;addPlayerSlots(Lnet/minecraft/inventory/Inventory;II)V", ordinal = 0), index = 2)
public int raiseHotbarAndInventorySlotY(int original) {
if (rows == 6 && InventoryTabs.CONFIG.compactLargeContainers) return original - 19;
return original - 1;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import net.minecraft.client.gui.DrawContext;
import net.minecraft.client.gui.screen.ingame.HandledScreen;
import net.minecraft.client.gui.screen.ingame.ShulkerBoxScreen;
import net.minecraft.client.render.RenderLayer;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.screen.GenericContainerScreenHandler;
import net.minecraft.screen.ShulkerBoxScreenHandler;
Expand Down Expand Up @@ -32,26 +33,26 @@ public void containerTextHeight(ShulkerBoxScreenHandler handler, PlayerInventory

@Inject(method = "drawBackground", at = @At("TAIL"))
public void containerHeader(DrawContext drawContext, float delta, int mouseX, int mouseY, CallbackInfo ci) {
drawContext.drawTexture(TEXTURE, (this.width - this.backgroundWidth) / 2, (this.height - this.backgroundHeight) / 2, 0, 0, this.backgroundWidth, 7);
drawContext.drawTexture(RenderLayer::getGuiTextured, TEXTURE, (this.width - this.backgroundWidth) / 2, (this.height - this.backgroundHeight) / 2, 0, 0, this.backgroundWidth, 7, 256, 256);
}

@ModifyArg(method = "drawBackground", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/DrawContext;drawTexture(Lnet/minecraft/util/Identifier;IIIIII)V", ordinal = 0), index = 2)
@ModifyArg(method = "drawBackground", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/DrawContext;drawTexture(Ljava/util/function/Function;Lnet/minecraft/util/Identifier;IIFFIIII)V", ordinal = 0), index = 3)
public int containerY(int original) {
return original + 7;
}

@ModifyArg(method = "drawBackground", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/DrawContext;drawTexture(Lnet/minecraft/util/Identifier;IIIIII)V", ordinal = 0), index = 4)
public int containerV(int original) {
@ModifyArg(method = "drawBackground", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/DrawContext;drawTexture(Ljava/util/function/Function;Lnet/minecraft/util/Identifier;IIFFIIII)V", ordinal = 0), index = 5)
public float containerV(float original) {
return original + 8;
}

@ModifyArg(method = "drawBackground", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/DrawContext;drawTexture(Lnet/minecraft/util/Identifier;IIIIII)V", ordinal = 0), index = 6)
@ModifyArg(method = "drawBackground", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/DrawContext;drawTexture(Ljava/util/function/Function;Lnet/minecraft/util/Identifier;IIFFIIII)V", ordinal = 0), index = 7)
public int containerHeight(int original) {
return 64;
}

@Inject(method = "drawBackground", at = @At("TAIL"))
public void containerInventory(DrawContext drawContext, float delta, int mouseX, int mouseY, CallbackInfo ci) {
drawContext.drawTexture(TEXTURE, (this.width - this.backgroundWidth) / 2, (this.height - this.backgroundHeight) / 2 + 71, 0, 71, this.backgroundWidth, 96);
drawContext.drawTexture(RenderLayer::getGuiTextured, TEXTURE, (this.width - this.backgroundWidth) / 2, (this.height - this.backgroundHeight) / 2 + 71, 0, 71, this.backgroundWidth, 96, 256, 256);
}
}
9 changes: 5 additions & 4 deletions src/main/java/folk/sisby/inventory_tabs/util/DrawUtil.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package folk.sisby.inventory_tabs.util;

import net.minecraft.client.gui.DrawContext;
import net.minecraft.client.render.RenderLayer;
import net.minecraft.util.Identifier;

public class DrawUtil {
Expand All @@ -10,9 +11,9 @@ public static void drawCrunched(DrawContext context, Identifier texture, int x,
int rightWidth = width - leftWidth;
int bottomHeight = height - topHeight;

context.drawTexture(texture, x, y, u, v, leftWidth, topHeight, texWidth, texHeight); // Top Left
context.drawTexture(texture, x + leftWidth, y, u + regionWidth - rightWidth, v, rightWidth, topHeight, texWidth, texHeight); // Top Right
context.drawTexture(texture, x, y + topHeight, u, v + regionHeight - bottomHeight, leftWidth, bottomHeight, texWidth, texHeight); // Bottom Left
context.drawTexture(texture, x + leftWidth, y + topHeight, u + regionWidth - rightWidth, v + regionHeight - bottomHeight, rightWidth, bottomHeight, texWidth, texHeight); // Bottom Right
context.drawTexture(RenderLayer::getGuiTextured, texture, x, y, u, v, leftWidth, topHeight, texWidth, texHeight); // Top Left
context.drawTexture(RenderLayer::getGuiTextured, texture, x + leftWidth, y, u + regionWidth - rightWidth, v, rightWidth, topHeight, texWidth, texHeight); // Top Right
context.drawTexture(RenderLayer::getGuiTextured, texture, x, y + topHeight, u, v + regionHeight - bottomHeight, leftWidth, bottomHeight, texWidth, texHeight); // Bottom Left
context.drawTexture(RenderLayer::getGuiTextured, texture, x + leftWidth, y + topHeight, u + regionWidth - rightWidth, v + regionHeight - bottomHeight, rightWidth, bottomHeight, texWidth, texHeight); // Bottom Right
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public int priority() {
} else {
Identifier id = Identifier.tryParse(value);
if (id == null) return null;
return manager.createRegistryLookup().getOptional(registry).orElseThrow().getOptional(RegistryKey.of(registry, id)).map(h -> new RegistryMatcher<>(Either.left(Either.left(h)))).orElse(null);
return manager.getOptional(registry).orElseThrow().getOptional(RegistryKey.of(registry, id)).map(h -> new RegistryMatcher<>(Either.left(Either.left(h)))).orElse(null);
}
}

Expand Down