22
33import com .enderio .api .conduit .ConduitType ;
44import com .enderio .base .client .tooltip .TooltipHandler ;
5+ import com .enderio .conduits .common .conduit .block .ConduitBlock ;
56import com .enderio .conduits .common .conduit .block .ConduitBlockEntity ;
67import com .enderio .conduits .common .init .ConduitLang ;
78import com .enderio .core .common .util .TooltipUtil ;
2223import org .jetbrains .annotations .Nullable ;
2324
2425import java .util .List ;
26+ import java .util .Optional ;
2527import java .util .function .Supplier ;
2628
2729public class ConduitBlockItem extends BlockItem {
@@ -45,32 +47,13 @@ public String getDescriptionId() {
4547 @ Override
4648 public InteractionResult place (BlockPlaceContext context ) {
4749 Level level = context .getLevel ();
48- @ Nullable
49- Player player = context .getPlayer ();
50- BlockPos blockpos = context .getClickedPos ();
51- ItemStack itemstack = context .getItemInHand ();
5250
5351 // Handle placing into an existing block
54- if (level .getBlockEntity ( blockpos ) instanceof ConduitBlockEntity conduit ) {
55- if ( conduit . hasType ( type . get ())) {
56- // Pass through to block
57- return level . getBlockState ( blockpos ). use ( level , player , context . getHand (), context . getHitResult () );
52+ if (level .getBlockState ( context . getClickedPos ()). getBlock () instanceof ConduitBlock conduitBlock ) {
53+ Optional < InteractionResult > result = conduitBlock . handleBlockPlace ( context );
54+ if ( result . isPresent ()) {
55+ return result . get ( );
5856 }
59-
60- conduit .addType (type .get (), player );
61- if (level .isClientSide ()) {
62- conduit .updateClient ();
63- }
64-
65- BlockState blockState = level .getBlockState (blockpos );
66- SoundType soundtype = blockState .getSoundType (level , blockpos , context .getPlayer ());
67- level .playSound (player , blockpos , this .getPlaceSound (blockState , level , blockpos , context .getPlayer ()), SoundSource .BLOCKS , (soundtype .getVolume () + 1.0F ) / 2.0F , soundtype .getPitch () * 0.8F );
68- level .gameEvent (GameEvent .BLOCK_PLACE , blockpos , GameEvent .Context .of (player , blockState ));
69-
70- if (!player .getAbilities ().instabuild ) {
71- itemstack .shrink (1 );
72- }
73- return InteractionResult .sidedSuccess (level .isClientSide ());
7457 }
7558
7659 return super .place (context );
0 commit comments