3232import net .minecraft .core .Direction .Axis ;
3333import net .minecraft .world .InteractionHand ;
3434import net .minecraft .world .ItemInteractionResult ;
35+ import net .minecraft .world .entity .Entity ;
3536import net .minecraft .world .entity .LivingEntity ;
37+ import net .minecraft .world .entity .item .ItemEntity ;
3638import net .minecraft .world .entity .player .Player ;
3739import net .minecraft .world .item .ItemStack ;
3840import net .minecraft .world .item .context .BlockPlaceContext ;
4648import net .minecraft .world .phys .HitResult ;
4749import net .minecraft .world .phys .shapes .CollisionContext ;
4850import net .minecraft .world .phys .shapes .VoxelShape ;
51+ import net .neoforged .neoforge .capabilities .Capabilities ;
52+ import net .neoforged .neoforge .items .IItemHandler ;
4953import org .jetbrains .annotations .Nullable ;
5054import plus .dragons .createdragonsplus .common .advancements .AdvancementBehaviour ;
5155import plus .dragons .createenchantmentindustry .common .registry .CEIBlockEntities ;
@@ -68,6 +72,33 @@ protected ItemInteractionResult useItemOn(ItemStack stack, BlockState state, Lev
6872 return super .useItemOn (stack , state , level , pos , player , hand , hitResult );
6973 }
7074
75+ @ Override
76+ public void updateEntityAfterFallOn (BlockGetter worldIn , Entity entityIn ) {
77+ super .updateEntityAfterFallOn (worldIn , entityIn );
78+
79+ if (entityIn .level ().isClientSide )
80+ return ;
81+ if (!(entityIn instanceof ItemEntity itemEntity ))
82+ return ;
83+ if (!entityIn .isAlive ())
84+ return ;
85+ GrindstoneDrainBlockEntity drain = getBlockEntity (worldIn , entityIn .blockPosition ());
86+ if (drain == null )
87+ return ;
88+
89+ IItemHandler capability = drain .getLevel ().getCapability (Capabilities .ItemHandler .BLOCK , drain .getBlockPos (), null );
90+ if (capability == null )
91+ return ;
92+
93+ ItemStack remainder = capability
94+ .insertItem (0 , itemEntity .getItem (), false );
95+ if (remainder .isEmpty ())
96+ itemEntity .discard ();
97+ if (remainder .getCount () < itemEntity .getItem ()
98+ .getCount ())
99+ itemEntity .setItem (remainder );
100+ }
101+
71102 @ Override
72103 protected VoxelShape getShape (BlockState state , BlockGetter level , BlockPos pos , CollisionContext context ) {
73104 return SHAPE ;
0 commit comments