@@ -118,7 +118,7 @@ public static void serverTick(World world, BlockPos pos, BlockState state, Custo
118118 blockEntity .lastTickTime = world .getTime ();
119119 if (!blockEntity .needsCooldown ()) {
120120 blockEntity .setTransferCooldown (0 );
121- insertAndExtract (world , pos , state , blockEntity , () -> extract ((World )world , (CustomHopperBlockEntity )blockEntity ), blockEntity .itemRate );
121+ insertAndExtract (world , pos , state , blockEntity , () -> extract ((World )world , (CustomHopperBlockEntity )blockEntity , blockEntity . itemRate ), blockEntity .itemRate );
122122 }
123123
124124 }
@@ -202,14 +202,14 @@ private static boolean isInventoryEmpty(Inventory inv, Direction facing) {
202202 return getAvailableSlots (inv , facing ).allMatch ((slot ) -> inv .getStack (slot ).isEmpty ());
203203 }
204204
205- public static boolean extract (World world , CustomHopperBlockEntity hopper ) {
205+ public static boolean extract (World world , CustomHopperBlockEntity hopper , int itemRate ) {
206206 Inventory inventory = getInputInventory (world , hopper );
207207 if (inventory != null ) {
208208 Direction direction = Direction .DOWN ;
209- return isInventoryEmpty (inventory , direction ) ? false : getAvailableSlots (inventory , direction ).anyMatch ((slot ) -> extract (hopper , inventory , slot , direction ));
209+ return isInventoryEmpty (inventory , direction ) ? false : getAvailableSlots (inventory , direction ).anyMatch ((slot ) -> extract (hopper , inventory , slot , direction , hopper . itemRate ));
210210 } else {
211211 for (ItemEntity itemEntity : getInputItemEntities (world , hopper )) {
212- if (extract ((Inventory )hopper , (ItemEntity )itemEntity )) {
212+ if (extract ((Inventory )hopper , (ItemEntity )itemEntity , hopper . itemRate )) {
213213 return true ;
214214 }
215215 }
@@ -218,31 +218,37 @@ public static boolean extract(World world, CustomHopperBlockEntity hopper) {
218218 }
219219 }
220220
221- private static boolean extract (Hopper hopper , Inventory inventory , int slot , Direction side ) {
221+ private static boolean extract (Hopper hopper , Inventory inventory , int slot , Direction side , int itemRate ) {
222222 ItemStack itemStack = inventory .getStack (slot );
223- if (!itemStack .isEmpty () && canExtract (inventory , itemStack , slot , side )) {
224- ItemStack itemStack2 = itemStack .copy ();
225- ItemStack itemStack3 = transfer (inventory , hopper , inventory .removeStack (slot , 1 ), (Direction )null );
226- if (itemStack3 .isEmpty ()) {
227- inventory .markDirty ();
228- return true ;
229- }
230223
231- inventory .setStack (slot , itemStack2 );
224+ for (var i = 0 ; i < itemRate ; i ++) {
225+ if (!itemStack .isEmpty () && canExtract (inventory , itemStack , slot , side )) {
226+ ItemStack itemStack2 = itemStack .copy ();
227+ ItemStack itemStack3 = transfer (inventory , hopper , inventory .removeStack (slot , 1 ), (Direction ) null );
228+ if (itemStack3 .isEmpty ()) {
229+ inventory .markDirty ();
230+ return true ;
231+ }
232+
233+ inventory .setStack (slot , itemStack2 );
234+ }
232235 }
233236
234237 return false ;
235238 }
236239
237- public static boolean extract (Inventory inventory , ItemEntity itemEntity ) {
240+ public static boolean extract (Inventory inventory , ItemEntity itemEntity , int itemRate ) {
238241 boolean bl = false ;
239- ItemStack itemStack = itemEntity .getStack ().copy ();
240- ItemStack itemStack2 = transfer ((Inventory )null , inventory , itemStack , (Direction )null );
241- if (itemStack2 .isEmpty ()) {
242- bl = true ;
243- itemEntity .discard ();
244- } else {
245- itemEntity .setStack (itemStack2 );
242+
243+ for (var i = 0 ; i < itemRate ; i ++) {
244+ ItemStack itemStack = itemEntity .getStack ().copy ();
245+ ItemStack itemStack2 = transfer ((Inventory ) null , inventory , itemStack , (Direction ) null );
246+ if (itemStack2 .isEmpty ()) {
247+ bl = true ;
248+ itemEntity .discard ();
249+ } else {
250+ itemEntity .setStack (itemStack2 );
251+ }
246252 }
247253
248254 return bl ;
@@ -416,7 +422,7 @@ protected void setInvStackList(DefaultedList<ItemStack> list) {
416422
417423 public static void onEntityCollided (World world , BlockPos pos , BlockState state , Entity entity , CustomHopperBlockEntity blockEntity ) {
418424 if (entity instanceof ItemEntity && VoxelShapes .matchesAnywhere (VoxelShapes .cuboid (entity .getBoundingBox ().offset ((double )(-pos .getX ()), (double )(-pos .getY ()), (double )(-pos .getZ ()))), blockEntity .getInputAreaShape (), BooleanBiFunction .AND )) {
419- insertAndExtract (world , pos , state , blockEntity , () -> extract ((Inventory )blockEntity , (ItemEntity )((ItemEntity )entity )), blockEntity .itemRate );
425+ insertAndExtract (world , pos , state , blockEntity , () -> extract ((Inventory )blockEntity , (ItemEntity )((ItemEntity )entity ), blockEntity . itemRate ), blockEntity .itemRate );
420426 }
421427
422428 }
0 commit comments