Skip to content

Commit 3e503d3

Browse files
authored
Fix #1082: Make steam drill work with Sophisticated Backpacks pickup upgrade (#1088)
1 parent c2f6c80 commit 3e503d3

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

src/main/java/aztech/modern_industrialization/items/SteamDrillItem.java

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
import net.minecraft.world.entity.ExperienceOrb;
5454
import net.minecraft.world.entity.LivingEntity;
5555
import net.minecraft.world.entity.SlotAccess;
56+
import net.minecraft.world.entity.item.ItemEntity;
5657
import net.minecraft.world.entity.player.Player;
5758
import net.minecraft.world.inventory.ClickAction;
5859
import net.minecraft.world.inventory.Slot;
@@ -79,6 +80,7 @@
7980
import net.neoforged.bus.api.EventPriority;
8081
import net.neoforged.neoforge.capabilities.Capabilities;
8182
import net.neoforged.neoforge.common.NeoForge;
83+
import net.neoforged.neoforge.event.entity.player.ItemEntityPickupEvent;
8284
import net.neoforged.neoforge.event.entity.player.PlayerInteractEvent;
8385
import net.neoforged.neoforge.event.level.BlockDropsEvent;
8486
import net.neoforged.neoforge.fluids.FluidType;
@@ -339,7 +341,20 @@ public boolean mineBlock(ItemStack stack, Level world, BlockState state, BlockPo
339341
recursiveMineBlock.set(false);
340342
}
341343
totalDrops.forEach(itemStack -> {
342-
ItemHandlerHelper.giveItemToPlayer(p, itemStack);
344+
// Create an ItemEntity for the stack, and fire the pickup event.
345+
// This lets Sophisticated Backpacks (SB) and similar mods try to intercept the stack.
346+
// The stacks can have more than the max stack size, let's hope it won't cause issues.
347+
var itemEntity = new ItemEntity(world, p.getX(), p.getY(), p.getZ(), itemStack);
348+
// Set delay to 0 since we will pick up the item immediately. Otherwise, SB won't process the entity.
349+
itemEntity.setNoPickUpDelay();
350+
var pickupEvent = new ItemEntityPickupEvent.Pre(p, itemEntity);
351+
NeoForge.EVENT_BUS.post(pickupEvent);
352+
353+
// Ignore canPickup and assume that mods correctly updated the item entity.
354+
// Let's at least check isRemoved() just in case, but I am not sure if it's needed.
355+
if (!itemEntity.isRemoved()) {
356+
ItemHandlerHelper.giveItemToPlayer(p, itemEntity.getItem());
357+
}
343358
});
344359
totalDrops = null;
345360
world.getEntitiesOfClass(ExperienceOrb.class,

0 commit comments

Comments
 (0)