From 239aa499c402728400e3fa56ed4a49dbfc86fb41 Mon Sep 17 00:00:00 2001 From: Ellpeck Date: Mon, 24 Oct 2022 11:04:52 +0200 Subject: [PATCH] account for storage drawers' item handler behavior for over-sending prevention Should close #131 --- build.gradle | 3 +++ .../de/ellpeck/prettypipes/pipe/PipeBlockEntity.java | 9 +++++++++ 2 files changed, 12 insertions(+) diff --git a/build.gradle b/build.gradle index 7055cf4..3c41221 100644 --- a/build.gradle +++ b/build.gradle @@ -111,6 +111,9 @@ dependencies { compileOnly fg.deobf("mezz.jei:jei-1.19.2-common-api:11.3.0.260") runtimeOnly fg.deobf("mezz.jei:jei-1.19.2-forge:11.3.0.260") + // test storage drawers + runtimeOnly fg.deobf("curse.maven:storage-drawers-223852:3884263") + // to test the rf requiring and crafting stuff /* runtimeOnly fg.deobf("curse.maven:powah-352656:3057732") runtimeOnly fg.deobf("curse.maven:lollipop-347954:3057731") diff --git a/src/main/java/de/ellpeck/prettypipes/pipe/PipeBlockEntity.java b/src/main/java/de/ellpeck/prettypipes/pipe/PipeBlockEntity.java index 99393ec..b8bb360 100644 --- a/src/main/java/de/ellpeck/prettypipes/pipe/PipeBlockEntity.java +++ b/src/main/java/de/ellpeck/prettypipes/pipe/PipeBlockEntity.java @@ -236,12 +236,21 @@ public class PipeBlockEntity extends BlockEntity implements MenuProvider, IPipeC // have space for items of other types, but it'll be good enough for us var left = handler.insertItem(i, copy, true); totalSpace += maxStackSize - left.getCount(); + } // if the items on the way plus the items we're trying to move are too much, reduce if (onTheWay + toInsert.getCount() > totalSpace) toInsert.setCount(totalSpace - onTheWay); } } + + // the 0th slot of a storage drawer is a "catch-all" for any items that can be inserted into the drawer, and all + // subsequent slots are the actual slots for the items. this causes a problem because the drawer will seem to have + // space for twice the amount of items that it actually does. + // see https://github.com/Ellpeck/PrettyPipes/issues/131#issuecomment-1288653623 and Discord convo with Quinteger + if (handler.getClass().getName().equals("com.jaquadro.minecraft.storagedrawers.capabilities.DrawerItemHandler")) + toInsert.setCount(toInsert.getCount() / 2); + // we return the item that can actually be inserted, NOT the remainder! if (!toInsert.isEmpty()) return Pair.of(offset, toInsert);