Skip to content

Commit

Permalink
Merge pull request #253 from P3pp3rF1y/1.20.x-dev
Browse files Browse the repository at this point in the history
1.20.x dev
  • Loading branch information
P3pp3rF1y authored Aug 22, 2024
2 parents f10ed7e + 28c8741 commit ceff510
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 3 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.6.22
mod_version=0.6.25
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 @@ -7,7 +7,6 @@

public interface IStashStorageItem {
Optional<TooltipComponent> getInventoryTooltip(ItemStack stack);
ItemStack stash(ItemStack storageStack, ItemStack stack);
StashResult getItemStashable(ItemStack storageStack, ItemStack stack);

enum StashResult {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -670,7 +670,12 @@ private ItemStack insertIntoStoragesThatMatchStack(ItemStack remaining, ItemStac

private ItemStack insertIntoStoragesThatMatchItem(ItemStack remaining, boolean simulate) {
if (!emptySlotsStorages.isEmpty() && itemStackKeys.containsKey(remaining.getItem())) {
for (ItemStackKey key : itemStackKeys.get(remaining.getItem())) {
Set<ItemStackKey> matchingStackKeys = itemStackKeys.get(remaining.getItem());
if (remaining.getCount() > remaining.getMaxStackSize()) {
matchingStackKeys = new LinkedHashSet<>(matchingStackKeys); //to prevent CME when larger than maxStackSize stack causes new key to be added to set which then continues to be iterated on
}

for (ItemStackKey key : matchingStackKeys) {
if (stackStorages.containsKey(key)) {
Set<BlockPos> positions = stackStorages.get(key);
remaining = insertIntoStorages(positions, remaining, simulate, true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import net.minecraft.world.item.crafting.RecipeType;
import net.minecraft.world.level.Level;
import net.minecraftforge.items.ItemHandlerHelper;
import net.p3pp3rf1y.sophisticatedcore.SophisticatedCore;
import net.p3pp3rf1y.sophisticatedcore.common.gui.ICraftingContainer;
import net.p3pp3rf1y.sophisticatedcore.common.gui.SlotSuppliedHandler;
import net.p3pp3rf1y.sophisticatedcore.common.gui.UpgradeContainerBase;
Expand Down Expand Up @@ -66,6 +67,11 @@ public void onTake(Player thePlayer, ItemStack stack) {
}
net.minecraftforge.common.ForgeHooks.setCraftingPlayer(null);
for (int i = 0; i < items.size(); ++i) {
if (i >= 9) {
logErrorAndDropRemainingItems(i, items);
break;
}

ItemStack itemstack = craftMatrix.getItem(i);
ItemStack itemstack1 = items.get(i);
if (!itemstack.isEmpty()) {
Expand All @@ -90,6 +96,16 @@ public void onTake(Player thePlayer, ItemStack stack) {
}
}

private void logErrorAndDropRemainingItems(int i, List<ItemStack> items) {
for (int j = i; j < items.size(); j++) {
ItemStack remaining = items.get(j);
if (!remaining.isEmpty()) {
player.drop(remaining, false);
}
}
SophisticatedCore.LOGGER.error("Recipe " + (lastRecipe != null ? lastRecipe.getId() : "[unknown]") + " returned more than 9 remaining items, dropping the rest!");
}

@Override
public void setChanged() {
super.setChanged();
Expand Down

0 comments on commit ceff510

Please sign in to comment.