Skip to content

Commit 9c19664

Browse files
fix: Unify conduit placement logic
1 parent 939c998 commit 9c19664

File tree

2 files changed

+19
-23
lines changed

2 files changed

+19
-23
lines changed

src/conduits/java/com/enderio/conduits/common/conduit/ConduitBlockItem.java

Lines changed: 6 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import com.enderio.api.conduit.ConduitType;
44
import com.enderio.base.client.tooltip.TooltipHandler;
5+
import com.enderio.conduits.common.conduit.block.ConduitBlock;
56
import com.enderio.conduits.common.conduit.block.ConduitBlockEntity;
67
import com.enderio.conduits.common.init.ConduitLang;
78
import com.enderio.core.common.util.TooltipUtil;
@@ -22,6 +23,7 @@
2223
import org.jetbrains.annotations.Nullable;
2324

2425
import java.util.List;
26+
import java.util.Optional;
2527
import java.util.function.Supplier;
2628

2729
public 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);

src/conduits/java/com/enderio/conduits/common/conduit/block/ConduitBlock.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,19 @@ private Optional<InteractionResult> addConduit(ConduitBlockEntity conduit, Playe
237237
return Optional.of(result);
238238
}
239239

240+
public Optional<InteractionResult> handleBlockPlace(BlockPlaceContext context) {
241+
Level level = context.getLevel();
242+
@Nullable
243+
Player player = context.getPlayer();
244+
BlockPos blockpos = context.getClickedPos();
245+
ItemStack itemstack = context.getItemInHand();
246+
247+
if (player != null && level.getBlockEntity(blockpos) instanceof ConduitBlockEntity conduit) {
248+
return addConduit(conduit, player, itemstack, level.isClientSide);
249+
}
250+
return Optional.empty();
251+
}
252+
240253
private Optional<InteractionResult> handleYeta(ConduitBlockEntity conduit, Player player, ItemStack stack, BlockHitResult hit, boolean isClientSide) {
241254
if (stack.is(EIOTags.Items.WRENCH)) {
242255
@Nullable ConduitType<?> type = conduit.getShape().getConduit(hit.getBlockPos(), hit);

0 commit comments

Comments
 (0)