Skip to content

Commit

Permalink
Merge pull request #1160 from P3pp3rF1y/1.21.x-dev
Browse files Browse the repository at this point in the history
fix: 🐛 Fixed backpack to just close gui instead of crashing out of wo…
  • Loading branch information
P3pp3rF1y authored Sep 28, 2024
2 parents 7ed2b9b + 1f1f90a commit 8488a1e
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ loader_version_range=[4,)
mod_id=sophisticatedbackpacks
mod_name=Sophisticated Backpacks
mod_license=GNU General Public License v3.0
mod_version=3.20.14
mod_version=3.20.15
mod_group_id=sophisticatedbackpacks
mod_authors=P3pp3rF1y, Ridanisaurus
mod_description=Fancy and functional backpacks.
Expand All @@ -34,7 +34,7 @@ chipped_cf_file_id=5506938
resourcefullib_cf_file_id=5483169
athena_cf_file_id=5431579
curios_cf_file_id=5546342
sc_version=[1.21,1.22)
sc_version=[1.21-0.6.39,1.22)

#publish
curseforge_id=422301
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package net.p3pp3rf1y.sophisticatedbackpacks.client.gui;

import com.mojang.blaze3d.platform.InputConstants;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.client.gui.screens.inventory.InventoryScreen;
import net.minecraft.network.chat.Component;
import net.minecraft.world.entity.player.Inventory;
Expand Down Expand Up @@ -52,4 +54,12 @@ private boolean mouseNotOverBackpack() {
protected String getStorageSettingsTabTooltip() {
return SBPTranslationHelper.INSTANCE.translGui("settings.tooltip");
}

@Override
public void render(GuiGraphics guiGraphics, int mouseX, int mouseY, float partialTicks) {
super.render(guiGraphics, mouseX, mouseY, partialTicks);
if (getMenu().getNumberOfStorageInventorySlots() == 0 && Minecraft.getInstance().player != null) {
Minecraft.getInstance().player.closeContainer();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,12 @@ public IBackpackWrapper getBackpackWrapper(Player player) {
SophisticatedBackpacks.LOGGER.error("Error getting backpack wrapper - Unable to find inventory handler for \"{}\"", handlerName);
return IBackpackWrapper.Noop.INSTANCE;
}
return BackpackWrapper.fromStack(inventoryHandler.get().getStackInSlot(player, identifier, backpackSlotIndex));
ItemStack backpackStack = inventoryHandler.get().getStackInSlot(player, identifier, backpackSlotIndex);
if (backpackStack.getItem() instanceof BackpackItem) {
return BackpackWrapper.fromStack(backpackStack);
}
SophisticatedBackpacks.LOGGER.error("Error getting backpack wrapper - Stack isn't a backpack");
return IBackpackWrapper.Noop.INSTANCE;
}

@Override
Expand Down

0 comments on commit 8488a1e

Please sign in to comment.