Skip to content

Commit

Permalink
feat: Update to Minecraft 1.21.2
Browse files Browse the repository at this point in the history
  • Loading branch information
BlayTheNinth committed Oct 10, 2024
1 parent 34b9e06 commit 5726431
Show file tree
Hide file tree
Showing 6 changed files with 92 additions and 68 deletions.
3 changes: 1 addition & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
- Updated to Minecraft 1.21.1
- Changed the way key mappings are handled to avoid conflicts with vanilla key mappings
- Updated to Minecraft 1.21.2
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,19 @@
import net.minecraft.client.gui.screens.inventory.CreativeModeInventoryScreen;
import net.minecraft.client.gui.screens.inventory.InventoryScreen;
import net.minecraft.client.player.LocalPlayer;
import net.minecraft.client.renderer.RenderType;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.MutableComponent;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.inventory.Slot;
import net.minecraft.world.item.ItemStack;

public class TrashSlotGuiHandler {

private static final ResourceLocation SLOT_HIGHLIGHT_BACK_SPRITE = ResourceLocation.withDefaultNamespace("container/slot_highlight_back");
private static final ResourceLocation SLOT_HIGHLIGHT_FRONT_SPRITE = ResourceLocation.withDefaultNamespace("container/slot_highlight_front");

private static final TrashSlotSlot trashSlot = new TrashSlotSlot();
private static TrashSlotComponent trashSlotComponent;
private static ContainerSettings currentContainerSettings = ContainerSettings.NONE;
Expand All @@ -43,7 +48,6 @@ public static void initialize() {
Balm.getEvents().onEvent(ScreenMouseEvent.Click.Pre.class, TrashSlotGuiHandler::onMouseClick);
Balm.getEvents().onEvent(ScreenKeyEvent.Press.Post.class, TrashSlotGuiHandler::onKeyPress);
Balm.getEvents().onEvent(ContainerScreenDrawEvent.Background.class, TrashSlotGuiHandler::onBackgroundDrawn);
Balm.getEvents().onEvent(ContainerScreenDrawEvent.Background.class, TrashSlotGuiHandler::onScreenDrawn);
}

private static void onScreenInit(ScreenInitEvent.Post event) {
Expand Down Expand Up @@ -274,17 +278,38 @@ public static void onBackgroundDrawn(ContainerScreenDrawEvent.Background event)
trashSlotComponent.update(event.getMouseX(), event.getMouseY());
trashSlotComponent.drawBackground(event.getGuiGraphics());

if (((AbstractContainerScreenAccessor) screen).callIsHovering(trashSlot, event.getMouseX(), event.getMouseY())) {
var poseStack = event.getGuiGraphics().pose();
final var poseStack = event.getGuiGraphics().pose();
final var screenAccessor = (AbstractContainerScreenAccessor) screen;
final var hovering = screenAccessor.callIsHovering(trashSlot, event.getMouseX(), event.getMouseY());
if (hovering) {
poseStack.pushPose();
poseStack.translate(((AbstractContainerScreenAccessor) screen).getLeftPos(), ((AbstractContainerScreenAccessor) screen).getTopPos(), 0);
AbstractContainerScreen.renderSlotHighlight(event.getGuiGraphics(), trashSlot.x, trashSlot.y, 0);
poseStack.translate(screenAccessor.getLeftPos(), screenAccessor.getTopPos(), 1);
event.getGuiGraphics().blitSprite(RenderType::guiTextured, SLOT_HIGHLIGHT_BACK_SPRITE, trashSlot.x - 4, trashSlot.y - 4, 24, 24);
poseStack.popPose();
}

// TODO bit ugly for now since renderSlot ignores the pose stack translation
TrashSlotSlot trashSlot = TrashSlotGuiHandler.trashSlot;
SlotAccessor slotAccessor = (SlotAccessor) trashSlot;
slotAccessor.setX(trashSlot.x + screenAccessor.getLeftPos());
slotAccessor.setY(trashSlot.y + screenAccessor.getTopPos());
screenAccessor.callRenderSlot(event.getGuiGraphics(), trashSlot);
slotAccessor.setX(trashSlot.x - screenAccessor.getLeftPos());
slotAccessor.setY(trashSlot.y - screenAccessor.getTopPos());

if (hovering) {
poseStack.pushPose();
poseStack.translate(screenAccessor.getLeftPos(), screenAccessor.getTopPos(), 300);
event.getGuiGraphics().blitSprite(RenderType::guiTextured, SLOT_HIGHLIGHT_FRONT_SPRITE, trashSlot.x - 4, trashSlot.y - 4, 24, 24);
poseStack.popPose();
}

boolean isMouseSlot = screenAccessor.callIsHovering(trashSlot, event.getMouseX(), event.getMouseY());
if (isMouseSlot && screen.getMenu().getCarried().isEmpty() && trashSlot.hasItem()) {
event.getGuiGraphics().renderTooltip(Minecraft.getInstance().font, trashSlot.getItem(), event.getMouseX(), event.getMouseY());
}
}
}

public static void onScreenDrawn(ContainerScreenDrawEvent.Background event) {
if (currentHint != null) {
currentHint.render(event.getScreen(), event.getGuiGraphics());
if (currentHint.isComplete()) {
Expand All @@ -294,25 +319,8 @@ public static void onScreenDrawn(ContainerScreenDrawEvent.Background event) {
}
}

DeletionProvider deletionProvider = TrashSlotConfig.getDeletionProvider();
if (deletionProvider == null || !currentContainerSettings.isEnabled()) {
return;
}

if (event.getScreen() instanceof AbstractContainerScreen<?> screen && trashSlotComponent != null) {
// TODO bit ugly for now since renderSlot ignores the pose stack translation
TrashSlotSlot trashSlot = TrashSlotGuiHandler.trashSlot;
SlotAccessor slotAccessor = (SlotAccessor) trashSlot;
slotAccessor.setX(trashSlot.x + ((AbstractContainerScreenAccessor) screen).getLeftPos());
slotAccessor.setY(trashSlot.y + ((AbstractContainerScreenAccessor) screen).getTopPos());
((AbstractContainerScreenAccessor) screen).callRenderSlot(event.getGuiGraphics(), trashSlot);
slotAccessor.setX(trashSlot.x - ((AbstractContainerScreenAccessor) screen).getLeftPos());
slotAccessor.setY(trashSlot.y - ((AbstractContainerScreenAccessor) screen).getTopPos());

boolean isMouseSlot = ((AbstractContainerScreenAccessor) screen).callIsHovering(trashSlot, event.getMouseX(), event.getMouseY());
if (isMouseSlot && screen.getMenu().getCarried().isEmpty() && trashSlot.hasItem()) {
event.getGuiGraphics().renderTooltip(Minecraft.getInstance().font, trashSlot.getItem(), event.getMouseX(), event.getMouseY());
}
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package net.blay09.mods.trashslot.client.gui;

import com.mojang.blaze3d.systems.RenderSystem;
import com.mojang.blaze3d.vertex.PoseStack;
import net.blay09.mods.balm.mixin.AbstractContainerScreenAccessor;
import net.blay09.mods.balm.mixin.SlotAccessor;
import net.blay09.mods.trashslot.TrashSlot;
Expand All @@ -19,6 +17,7 @@
import net.minecraft.client.gui.screens.Screen;
import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen;
import net.minecraft.client.renderer.Rect2i;
import net.minecraft.client.renderer.RenderType;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.util.Mth;

Expand Down Expand Up @@ -145,7 +144,6 @@ public void drawBackground(GuiGraphics guiGraphics) {
poseStack.pushPose();
poseStack.translate(0, 0, 1);

guiGraphics.setColor(1f, 1f, 1f, 1f);
renderX += renderStyle.getRenderOffsetX() + layout.getSlotOffsetX(screen, renderStyle);
renderY += renderStyle.getRenderOffsetY() + layout.getSlotOffsetY(screen, renderStyle);
DeletionProvider deletionProvider = TrashSlotConfig.getDeletionProvider();
Expand All @@ -154,58 +152,58 @@ public void drawBackground(GuiGraphics guiGraphics) {
texOffsetX = 64;
}
switch (renderStyle) {
case LONE -> guiGraphics.blit(texture, renderX, renderY, texOffsetX, 56, renderStyle.getRenderWidth(), renderStyle.getRenderHeight());
case LONE -> guiGraphics.blit(RenderType::guiTextured, texture, renderX, renderY, texOffsetX, 56, renderStyle.getRenderWidth(), renderStyle.getRenderHeight(), 256, 256);
case ATTACH_BOTTOM_CENTER -> {
guiGraphics.blit(texture, renderX, renderY, texOffsetX, 0, renderStyle.getRenderWidth(), renderStyle.getRenderHeight());
guiGraphics.blit(texture, renderX, renderY, texOffsetX + 50, 29, 4, 4);
guiGraphics.blit(texture, renderX + renderStyle.getRenderWidth() - 4, renderY, texOffsetX + 54, 29, 4, 4);
guiGraphics.blit(RenderType::guiTextured, texture, renderX, renderY, texOffsetX, 0, renderStyle.getRenderWidth(), renderStyle.getRenderHeight(), 256, 256);
guiGraphics.blit(RenderType::guiTextured, texture, renderX, renderY, texOffsetX + 50, 29, 4, 4, 256, 256);
guiGraphics.blit(RenderType::guiTextured, texture, renderX + renderStyle.getRenderWidth() - 4, renderY, texOffsetX + 54, 29, 4, 4, 256, 256);
}
case ATTACH_BOTTOM_LEFT -> {
guiGraphics.blit(texture, renderX, renderY, texOffsetX, 0, renderStyle.getRenderWidth(), renderStyle.getRenderHeight());
guiGraphics.blit(texture, renderX + renderStyle.getRenderWidth() - 4, renderY, texOffsetX + 54, 29, 4, 4);
guiGraphics.blit(RenderType::guiTextured, texture, renderX, renderY, texOffsetX, 0, renderStyle.getRenderWidth(), renderStyle.getRenderHeight(), 256, 256);
guiGraphics.blit(RenderType::guiTextured, texture, renderX + renderStyle.getRenderWidth() - 4, renderY, texOffsetX + 54, 29, 4, 4, 256, 256);
}
case ATTACH_BOTTOM_RIGHT -> {
guiGraphics.blit(texture, renderX, renderY, texOffsetX, 0, renderStyle.getRenderWidth(), renderStyle.getRenderHeight());
guiGraphics.blit(texture, renderX, renderY, texOffsetX + 50, 29, 4, 4);
guiGraphics.blit(RenderType::guiTextured, texture, renderX, renderY, texOffsetX, 0, renderStyle.getRenderWidth(), renderStyle.getRenderHeight(), 256, 256);
guiGraphics.blit(RenderType::guiTextured, texture, renderX, renderY, texOffsetX + 50, 29, 4, 4, 256, 256);
}
case ATTACH_TOP_CENTER -> {
guiGraphics.blit(texture, renderX, renderY, texOffsetX + 32, 0, renderStyle.getRenderWidth(), renderStyle.getRenderHeight());
guiGraphics.blit(texture, renderX, renderY + renderStyle.getRenderHeight() - 4, texOffsetX + 50, 25, 4, 4);
guiGraphics.blit(texture, renderX + renderStyle.getRenderWidth() - 4, renderY + renderStyle.getRenderHeight() - 4, texOffsetX + 54, 25, 4, 4);
guiGraphics.blit(RenderType::guiTextured, texture, renderX, renderY, texOffsetX + 32, 0, renderStyle.getRenderWidth(), renderStyle.getRenderHeight(), 256, 256);
guiGraphics.blit(RenderType::guiTextured, texture, renderX, renderY + renderStyle.getRenderHeight() - 4, texOffsetX + 50, 25, 4, 4, 256, 256);
guiGraphics.blit(RenderType::guiTextured, texture, renderX + renderStyle.getRenderWidth() - 4, renderY + renderStyle.getRenderHeight() - 4, texOffsetX + 54, 25, 4, 4, 256, 256);
}
case ATTACH_TOP_LEFT -> {
guiGraphics.blit(texture, renderX, renderY, texOffsetX + 32, 0, renderStyle.getRenderWidth(), renderStyle.getRenderHeight());
guiGraphics.blit(texture, renderX + renderStyle.getRenderWidth() - 4, renderY + renderStyle.getRenderHeight() - 4, texOffsetX + 54, 25, 4, 4);
guiGraphics.blit(RenderType::guiTextured, texture, renderX, renderY, texOffsetX + 32, 0, renderStyle.getRenderWidth(), renderStyle.getRenderHeight(), 256, 256);
guiGraphics.blit(RenderType::guiTextured, texture, renderX + renderStyle.getRenderWidth() - 4, renderY + renderStyle.getRenderHeight() - 4, texOffsetX + 54, 25, 4, 4, 256, 256);
}
case ATTACH_TOP_RIGHT -> {
guiGraphics.blit(texture, renderX, renderY, texOffsetX + 32, 0, renderStyle.getRenderWidth(), renderStyle.getRenderHeight());
guiGraphics.blit(texture, renderX, renderY + renderStyle.getRenderHeight() - 4, texOffsetX + 50, 25, 4, 4);
guiGraphics.blit(RenderType::guiTextured, texture, renderX, renderY, texOffsetX + 32, 0, renderStyle.getRenderWidth(), renderStyle.getRenderHeight(), 256, 256);
guiGraphics.blit(RenderType::guiTextured, texture, renderX, renderY + renderStyle.getRenderHeight() - 4, texOffsetX + 50, 25, 4, 4, 256, 256);
}
case ATTACH_LEFT_CENTER -> {
guiGraphics.blit(texture, renderX, renderY, texOffsetX + 25, 25, renderStyle.getRenderWidth(), renderStyle.getRenderHeight());
guiGraphics.blit(texture, renderX + renderStyle.getRenderWidth() - 4, renderY, texOffsetX + 50, 33, 4, 4);
guiGraphics.blit(texture, renderX + renderStyle.getRenderWidth() - 4, renderY + renderStyle.getRenderHeight() - 4, texOffsetX + 50, 37, 4, 4);
guiGraphics.blit(RenderType::guiTextured, texture, renderX, renderY, texOffsetX + 25, 25, renderStyle.getRenderWidth(), renderStyle.getRenderHeight(), 256, 256);
guiGraphics.blit(RenderType::guiTextured, texture, renderX + renderStyle.getRenderWidth() - 4, renderY, texOffsetX + 50, 33, 4, 4, 256, 256);
guiGraphics.blit(RenderType::guiTextured, texture, renderX + renderStyle.getRenderWidth() - 4, renderY + renderStyle.getRenderHeight() - 4, texOffsetX + 50, 37, 4, 4, 256, 256);
}
case ATTACH_LEFT_TOP -> {
guiGraphics.blit(texture, renderX, renderY, texOffsetX + 25, 25, renderStyle.getRenderWidth(), renderStyle.getRenderHeight());
guiGraphics.blit(texture, renderX + renderStyle.getRenderWidth() - 4, renderY + renderStyle.getRenderHeight() - 4, texOffsetX + 50, 37, 4, 4);
guiGraphics.blit(RenderType::guiTextured, texture, renderX, renderY, texOffsetX + 25, 25, renderStyle.getRenderWidth(), renderStyle.getRenderHeight(), 256, 256);
guiGraphics.blit(RenderType::guiTextured, texture, renderX + renderStyle.getRenderWidth() - 4, renderY + renderStyle.getRenderHeight() - 4, texOffsetX + 50, 37, 4, 4, 256, 256);
}
case ATTACH_LEFT_BOTTOM -> {
guiGraphics.blit(texture, renderX, renderY, texOffsetX + 25, 25, renderStyle.getRenderWidth(), renderStyle.getRenderHeight());
guiGraphics.blit(texture, renderX + renderStyle.getRenderWidth() - 4, renderY, texOffsetX + 50, 33, 4, 4);
guiGraphics.blit(RenderType::guiTextured, texture, renderX, renderY, texOffsetX + 25, 25, renderStyle.getRenderWidth(), renderStyle.getRenderHeight(), 256, 256);
guiGraphics.blit(RenderType::guiTextured, texture, renderX + renderStyle.getRenderWidth() - 4, renderY, texOffsetX + 50, 33, 4, 4, 256, 256);
}
case ATTACH_RIGHT_CENTER -> {
guiGraphics.blit(texture, renderX, renderY, texOffsetX, 25, renderStyle.getRenderWidth(), renderStyle.getRenderHeight());
guiGraphics.blit(texture, renderX, renderY, texOffsetX + 54, 33, 4, 4);
guiGraphics.blit(texture, renderX, renderY + renderStyle.getRenderHeight() - 4, texOffsetX + 54, 37, 4, 4);
guiGraphics.blit(RenderType::guiTextured, texture, renderX, renderY, texOffsetX, 25, renderStyle.getRenderWidth(), renderStyle.getRenderHeight(), 256, 256);
guiGraphics.blit(RenderType::guiTextured, texture, renderX, renderY, texOffsetX + 54, 33, 4, 4, 256, 256);
guiGraphics.blit(RenderType::guiTextured, texture, renderX, renderY + renderStyle.getRenderHeight() - 4, texOffsetX + 54, 37, 4, 4, 256, 256);
}
case ATTACH_RIGHT_TOP -> {
guiGraphics.blit(texture, renderX, renderY, texOffsetX, 25, renderStyle.getRenderWidth(), renderStyle.getRenderHeight());
guiGraphics.blit(texture, renderX, renderY + renderStyle.getRenderHeight() - 4, texOffsetX + 54, 37, 4, 4);
guiGraphics.blit(RenderType::guiTextured, texture, renderX, renderY, texOffsetX, 25, renderStyle.getRenderWidth(), renderStyle.getRenderHeight(), 256, 256);
guiGraphics.blit(RenderType::guiTextured, texture, renderX, renderY + renderStyle.getRenderHeight() - 4, texOffsetX + 54, 37, 4, 4, 256, 256);
}
case ATTACH_RIGHT_BOTTOM -> {
guiGraphics.blit(texture, renderX, renderY, texOffsetX, 25, renderStyle.getRenderWidth(), renderStyle.getRenderHeight());
guiGraphics.blit(texture, renderX, renderY, texOffsetX + 54, 33, 4, 4);
guiGraphics.blit(RenderType::guiTextured, texture, renderX, renderY, texOffsetX, 25, renderStyle.getRenderWidth(), renderStyle.getRenderHeight(), 256, 256);
guiGraphics.blit(RenderType::guiTextured, texture, renderX, renderY, texOffsetX + 54, 33, 4, 4, 256, 256);
}
}

Expand Down
16 changes: 8 additions & 8 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ mod_id = trashslot
mod_name = TrashSlot
mod_main=TrashSlot
description=Adds a trash slot to the inventory screen that allows deletion of unwanted items.
version = 21.1.1
version = 21.2.0
group = net.blay09.mods
homepage=https://mods.twelveiterations.com/mc/trashslot
sources=https://github.com/TwelveIterationMods/TrashSlot
Expand All @@ -18,16 +18,16 @@ modrinth_release_type = release
modrinth_project_id = vRYk0bv7

# Minecraft
minecraft_version = 1.21.1
minecraft_version = 1.21.2-pre1
minimum_minecraft_version = 1.21
minecraft_versions = 1.21,1.21.1
minecraft_versions = 1.21,1.21.1,1.21.2-pre1
minecraft_version_range = [1.21,)
pack_format_number = 18
java_version = 21

# Balm
balm_version = 21.0.14-SNAPSHOT
balm_version_range = [21.0.0,)
balm_version = 21.2.1-SNAPSHOT
balm_version_range = [21.2.0,)

# Forge
forge_version = 52.0.2
Expand All @@ -40,8 +40,8 @@ neoforge_version_range = [21-beta,)
neoforge_loader_version_range = [1,)

# Fabric
fabric_version = 0.102.1+1.21.1
fabric_loader_version = 0.15.11
fabric_version = 0.105.3+1.21.2
fabric_loader_version = 0.16.5

# Dependencies
jei_minecraft_version=1.19.2
Expand All @@ -56,6 +56,6 @@ org.gradle.daemon=false
mod_author = BlayTheNinth
credits = BlayTheNinth
kuma_version = [21.0,22)
neo_form_version = 1.21.1-20240808.144430
neo_form_version = 1.21.2-pre1-20241008.174159
parchment_minecraft = 1.21
parchment_version = 2024.06.23
19 changes: 19 additions & 0 deletions repositories.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ repositories {
url = 'https://jitpack.io'
content {
includeGroup "com.github.BlueMap-Minecraft"
includeGroup "com.github.mattidragon"
}
}

Expand All @@ -65,4 +66,22 @@ repositories {
includeGroup "de.siphalor"
}
}

maven {
url = "https://dl.cloudsmith.io/public/novamachina-mods/release/maven/"
content {
includeGroup "novamachina.novacore"
includeGroup "novamachina.exnihilosequentia"
}
}

exclusiveContent {
forRepository {
maven {
name = 'Minecraft'
url = 'https://libraries.minecraft.net/'
}
}
filter { includeGroupAndSubgroups("com.mojang") }
}
}
4 changes: 2 additions & 2 deletions settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,5 @@ plugins {

include("common")
include("fabric")
include("neoforge")
include("forge")
//include("neoforge")
//include("forge")

0 comments on commit 5726431

Please sign in to comment.