diff --git a/gradle.properties b/gradle.properties index b5f43ca2..e3ce65a2 100644 --- a/gradle.properties +++ b/gradle.properties @@ -3,7 +3,7 @@ org.gradle.daemon=false mod_id=sophisticatedcore mod_group_id=sophisticatedcore -mod_version=0.5.108 +mod_version=0.5.111 sonar_project_key=sophisticatedcore:SophisticatedCore github_package_url=https://maven.pkg.github.com/P3pp3rF1y/SophisticatedCore diff --git a/src/main/java/net/p3pp3rf1y/sophisticatedcore/client/gui/StorageScreenBase.java b/src/main/java/net/p3pp3rf1y/sophisticatedcore/client/gui/StorageScreenBase.java index 327cc2cc..03dc621c 100644 --- a/src/main/java/net/p3pp3rf1y/sophisticatedcore/client/gui/StorageScreenBase.java +++ b/src/main/java/net/p3pp3rf1y/sophisticatedcore/client/gui/StorageScreenBase.java @@ -96,7 +96,7 @@ public abstract class StorageScreenBase> e private static ICraftingUIPart craftingUIPart = ICraftingUIPart.NOOP; private static ISlotDecorationRenderer slotDecorationRenderer = (guiGraphics, slot) -> {}; - private StorageBackgroundProperties storageBackgroundProperties; + protected StorageBackgroundProperties storageBackgroundProperties; public static void setCraftingUIPart(ICraftingUIPart part) { craftingUIPart = part; @@ -155,7 +155,7 @@ public Slot getSlot(int slotIndex) { return getMenu().getSlot(slotIndex); } - private void updateUpgradeSlotsPositions() { + protected void updateUpgradeSlotsPositions() { int yPosition = 6; for (int slotIndex = 0; slotIndex < numberOfUpgradeSlots; slotIndex++) { Slot slot = getMenu().getSlot(getMenu().getFirstUpgradeSlot() + slotIndex); @@ -637,7 +637,7 @@ protected void renderTooltip(GuiGraphics guiGraphics, int x, int y) { inventoryParts.values().forEach(part -> part.renderTooltip(this, guiGraphics, x, y)); if (getMenu().getCarried().isEmpty() && hoveredSlot != null) { if (hoveredSlot.hasItem()) { - guiGraphics.renderTooltip(font, hoveredSlot.getItem(), x, y); + super.renderTooltip(guiGraphics, x, y); } else if (hoveredSlot instanceof INameableEmptySlot emptySlot && emptySlot.hasEmptyTooltip()) { guiGraphics.renderComponentTooltip(font, Collections.singletonList(emptySlot.getEmptyTooltip()), x, y); } @@ -652,10 +652,12 @@ protected void renderTooltip(GuiGraphics guiGraphics, int x, int y) { @Override protected List getTooltipFromContainerItem(ItemStack itemStack) { - List ret = super.getTooltipFromContainerItem(itemStack); - if (itemStack.getCount() > 999) { + List ret = getTooltipFromItem(minecraft, itemStack); + if (hoveredSlot != null && hoveredSlot.getMaxStackSize() > 64) { ret.add(Component.translatable("gui.sophisticatedcore.tooltip.stack_count", - Component.literal(NumberFormat.getNumberInstance().format(itemStack.getCount())).withStyle(ChatFormatting.DARK_AQUA)) + Component.literal(NumberFormat.getNumberInstance().format(itemStack.getCount())).withStyle(ChatFormatting.DARK_AQUA) + .append(Component.literal(" / ").withStyle(ChatFormatting.GRAY)) + .append(Component.literal(NumberFormat.getNumberInstance().format(hoveredSlot.getMaxStackSize(itemStack))).withStyle(ChatFormatting.DARK_AQUA))) .withStyle(ChatFormatting.GRAY) ); } diff --git a/src/main/java/net/p3pp3rf1y/sophisticatedcore/inventory/CachedFailedInsertInventoryHandler.java b/src/main/java/net/p3pp3rf1y/sophisticatedcore/inventory/CachedFailedInsertInventoryHandler.java index 3d79d85e..3e4ab90d 100644 --- a/src/main/java/net/p3pp3rf1y/sophisticatedcore/inventory/CachedFailedInsertInventoryHandler.java +++ b/src/main/java/net/p3pp3rf1y/sophisticatedcore/inventory/CachedFailedInsertInventoryHandler.java @@ -12,7 +12,7 @@ public class CachedFailedInsertInventoryHandler implements IItemHandlerModifiabl private final IItemHandlerModifiable wrapped; private final LongSupplier timeSupplier; private long currentCacheTime = 0; - private final Set failedInsertStackHashes = new HashSet<>(); + private final Set failedInsertStacks = new HashSet<>(); public CachedFailedInsertInventoryHandler(IItemHandlerModifiable wrapped, LongSupplier timeSupplier) { this.wrapped = wrapped; @@ -39,27 +39,18 @@ public ItemStack getStackInSlot(int slot) { @Override public ItemStack insertItem(int slot, @NotNull ItemStack stack, boolean simulate) { if (currentCacheTime != timeSupplier.getAsLong()) { - failedInsertStackHashes.clear(); + failedInsertStacks.clear(); currentCacheTime = timeSupplier.getAsLong(); } - boolean hashCalculated = false; - int stackHash = 0; - if (!failedInsertStackHashes.isEmpty()) { - stackHash = ItemStackKey.getHashCode(stack); - hashCalculated = true; - if (failedInsertStackHashes.contains(stackHash)) { - return stack; - } + if (failedInsertStacks.contains(stack)) { + return stack; } ItemStack result = wrapped.insertItem(slot, stack, simulate); if (result == stack) { - if (!hashCalculated) { - stackHash = ItemStackKey.getHashCode(stack); - } - failedInsertStackHashes.add(stackHash); + failedInsertStacks.add(stack); //only working with stack references because this logic is meant to handle the case where something tries to insert the same stack number of slots times } return result; diff --git a/src/main/java/net/p3pp3rf1y/sophisticatedcore/inventory/InventoryHandler.java b/src/main/java/net/p3pp3rf1y/sophisticatedcore/inventory/InventoryHandler.java index d040bf0f..4bf03b6f 100644 --- a/src/main/java/net/p3pp3rf1y/sophisticatedcore/inventory/InventoryHandler.java +++ b/src/main/java/net/p3pp3rf1y/sophisticatedcore/inventory/InventoryHandler.java @@ -236,7 +236,9 @@ public ItemStack extractItemInternal(int slot, int amount, boolean simulate) { return ItemStack.EMPTY; } - if (existing.getCount() <= amount) { + int toExtract = Math.min(amount, existing.getMaxStackSize()); + + if (existing.getCount() <= toExtract) { if (!simulate) { setSlotStack(slot, ItemStack.EMPTY); return existing; @@ -245,10 +247,10 @@ public ItemStack extractItemInternal(int slot, int amount, boolean simulate) { } } else { if (!simulate) { - setSlotStack(slot, ItemHandlerHelper.copyStackWithSize(existing, existing.getCount() - amount)); + setSlotStack(slot, ItemHandlerHelper.copyStackWithSize(existing, existing.getCount() - toExtract)); } - return ItemHandlerHelper.copyStackWithSize(existing, amount); + return ItemHandlerHelper.copyStackWithSize(existing, toExtract); } } diff --git a/src/main/resources/assets/sophisticatedcore/lang/en_us.json b/src/main/resources/assets/sophisticatedcore/lang/en_us.json index 9e1d229a..736bd74f 100644 --- a/src/main/resources/assets/sophisticatedcore/lang/en_us.json +++ b/src/main/resources/assets/sophisticatedcore/lang/en_us.json @@ -205,5 +205,6 @@ "gui.sophisticatedcore.narrate.context_button": "Context toggle set to: %s", "gui.sophisticatedcore.narrate.context_button.usage": "Click to toggle context", "fluid_type.sophisticatedcore.experience": "Experience", - "gui.sophisticatedcore.tooltip.stack_count": "Count: %s" + "gui.sophisticatedcore.tooltip.stack_count": "Count: %s", + "gui.sophisticatedcore.tooltip.stack_limit": "Limit: %s" } \ No newline at end of file