Skip to content

Commit

Permalink
Merge pull request #190 from P3pp3rF1y/1.20.x-dev
Browse files Browse the repository at this point in the history
Release merge
  • Loading branch information
P3pp3rF1y authored Dec 11, 2023
2 parents eacda82 + 7a0383c commit 1f9bd29
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 25 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public abstract class StorageScreenBase<S extends StorageContainerMenuBase<?>> 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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}
Expand All @@ -652,10 +652,12 @@ protected void renderTooltip(GuiGraphics guiGraphics, int x, int y) {

@Override
protected List<Component> getTooltipFromContainerItem(ItemStack itemStack) {
List<Component> ret = super.getTooltipFromContainerItem(itemStack);
if (itemStack.getCount() > 999) {
List<Component> 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)
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public class CachedFailedInsertInventoryHandler implements IItemHandlerModifiabl
private final IItemHandlerModifiable wrapped;
private final LongSupplier timeSupplier;
private long currentCacheTime = 0;
private final Set<Integer> failedInsertStackHashes = new HashSet<>();
private final Set<ItemStack> failedInsertStacks = new HashSet<>();

public CachedFailedInsertInventoryHandler(IItemHandlerModifiable wrapped, LongSupplier timeSupplier) {
this.wrapped = wrapped;
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
}
}

Expand Down
3 changes: 2 additions & 1 deletion src/main/resources/assets/sophisticatedcore/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}

0 comments on commit 1f9bd29

Please sign in to comment.