6
6
7
7
import dan200 .computercraft .shared .ModRegistry ;
8
8
import dan200 .computercraft .shared .common .HorizontalContainerBlock ;
9
- import dan200 .computercraft .shared .platform .PlatformHelper ;
10
9
import net .minecraft .core .BlockPos ;
11
10
import net .minecraft .core .Direction ;
12
- import net .minecraft .world .InteractionHand ;
13
11
import net .minecraft .world .InteractionResult ;
14
- import net .minecraft .world .entity .player .Player ;
12
+ import net .minecraft .world .item .Item ;
13
+ import net .minecraft .world .item .context .UseOnContext ;
15
14
import net .minecraft .world .level .Level ;
16
15
import net .minecraft .world .level .block .BaseEntityBlock ;
17
16
import net .minecraft .world .level .block .Block ;
21
20
import net .minecraft .world .level .block .state .BlockState ;
22
21
import net .minecraft .world .level .block .state .StateDefinition ;
23
22
import net .minecraft .world .level .block .state .properties .EnumProperty ;
24
- import net .minecraft .world .phys .BlockHitResult ;
25
23
import org .jspecify .annotations .Nullable ;
26
24
27
25
public class DiskDriveBlock extends HorizontalContainerBlock {
@@ -42,21 +40,26 @@ protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockSt
42
40
properties .add (FACING , STATE );
43
41
}
44
42
45
- @ Override
46
- @ Deprecated
47
- public InteractionResult use (BlockState state , Level level , BlockPos pos , Player player , InteractionHand hand , BlockHitResult hit ) {
48
- if (player .isCrouching () && level .getBlockEntity (pos ) instanceof DiskDriveBlockEntity drive ) {
49
- // Try to put a disk into the drive
50
- var disk = player .getItemInHand (hand );
51
- if (disk .isEmpty ()) return InteractionResult .PASS ;
43
+ /**
44
+ * A default implementation of {@link Item#useOn(UseOnContext)} for items that can be placed into a drive.
45
+ *
46
+ * @param context The context of this item usage action.
47
+ * @return Whether the item was placed or not.
48
+ */
49
+ public static InteractionResult defaultUseItemOn (UseOnContext context ) {
50
+ if (context .getPlayer () == null || !context .getPlayer ().isSecondaryUseActive ()) return InteractionResult .PASS ;
52
51
53
- if (!level .isClientSide && drive .getDiskStack ().isEmpty () && PlatformHelper .get ().getMedia (disk ) != null ) {
54
- drive .setDiskStack (disk .split (1 ));
52
+ var level = context .getLevel ();
53
+ var blockPos = context .getClickedPos ();
54
+ var blockState = level .getBlockState (blockPos );
55
+ if (blockState .is (ModRegistry .Blocks .DISK_DRIVE .get ()) && blockState .getValue (STATE ) == DiskDriveState .EMPTY ) {
56
+ if (!level .isClientSide && level .getBlockEntity (blockPos ) instanceof DiskDriveBlockEntity drive && drive .getDiskStack ().isEmpty ()) {
57
+ drive .setDiskStack (context .getItemInHand ().split (1 ));
55
58
}
56
59
return InteractionResult .sidedSuccess (level .isClientSide );
57
60
}
58
61
59
- return super . use ( state , level , pos , player , hand , hit ) ;
62
+ return InteractionResult . PASS ;
60
63
}
61
64
62
65
@ Nullable
0 commit comments