API Surface (1) ItemStack execute(final BlockSource source, final ItemStack dispensed)
Code Graph: Dependencies (8) Edges (calls / imports / inherits / references) resolved by graphify from the AST. Every chip opens the class source.
Full Source
ShulkerBoxDispenseBehavior.java 33 lines · Minecraft 26.3 · verbatim Copy
1 package net.minecraft.core.dispenser;
2
3 import com.mojang.logging.LogUtils;
4 import net.minecraft.core.BlockPos;
5 import net.minecraft.core.Direction;
6 import net.minecraft.world.item.BlockItem;
7 import net.minecraft.world.item.ItemStack;
8 import net.minecraft.world.item.context.DirectionalPlaceContext;
9 import net.minecraft.world.level.block.DispenserBlock;
10 import org.slf4j.Logger;
11
12 public class ShulkerBoxDispenseBehavior extends OptionalDispenseItemBehavior {
13 private static final Logger LOGGER = LogUtils.getLogger();
14
15 @Override
16 protected ItemStack execute(final BlockSource source, final ItemStack dispensed) {
17 this.setSuccess(false);
18 if (dispensed.getItem() instanceof BlockItem blockItem) {
19 Direction facing = source.state().getValue(DispenserBlock.FACING);
20 BlockPos relativePos = source.pos().relative(facing);
21 Direction clickedFace = source.level().isEmptyBlock(relativePos.below()) ? facing : Direction.UP;
22
23 try {
24 this.setSuccess(blockItem.place(new DirectionalPlaceContext(source.level(), relativePos, facing, dispensed, clickedFace)).consumesAction());
25 } catch (Exception e) {
26 LOGGER.error("Error trying to place shulker box at {}", relativePos, e);
27 }
28 }
29
30 return dispensed;
31 }
32 }
33
Decompiled Minecraft 26.3 source of ShulkerBoxDispenseBehavior (net/minecraft/core/dispenser/ShulkerBoxDispenseBehavior.java) with Mojang official mappings, stored verbatim on the site.