Skip to content

Commit 42fab7b

Browse files
authored
Merge pull request #2622 from burin-ljx/multitool
Fix bug of multitool and magnet block 修复多用途工具和磁铁块的问题
2 parents 25750cb + 6b44d44 commit 42fab7b

File tree

3 files changed

+14
-16
lines changed

3 files changed

+14
-16
lines changed

src/main/java/dev/dubhe/anvilcraft/block/HollowMagnetBlock.java

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -133,13 +133,12 @@ protected void entityInside(BlockState state, Level level, BlockPos pos, Entity
133133

134134
@Override
135135
protected ItemInteractionResult useItemOn(ItemStack stack, BlockState state, Level level, BlockPos pos, Player player, InteractionHand hand, BlockHitResult hitResult) {
136-
if (level.isClientSide) {
137-
return ItemInteractionResult.sidedSuccess(true);
138-
}
139-
if (stack.is(Items.IRON_INGOT)) {
140-
stack.consume(1, player);
141-
level.setBlockAndUpdate(pos, ModBlocks.FERRITE_CORE_MAGNET_BLOCK.getDefaultState());
142-
return ItemInteractionResult.sidedSuccess(false);
136+
if (!level.isClientSide) {
137+
if (stack.is(Items.IRON_INGOT)) {
138+
stack.consume(1, player);
139+
level.setBlockAndUpdate(pos, ModBlocks.FERRITE_CORE_MAGNET_BLOCK.getDefaultState());
140+
return ItemInteractionResult.SUCCESS;
141+
}
143142
}
144143
return super.useItemOn(stack, state, level, pos, player, hand, hitResult);
145144
}

src/main/java/dev/dubhe/anvilcraft/block/MagnetBlock.java

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -166,14 +166,13 @@ public void tick(
166166

167167
@Override
168168
protected InteractionResult useWithoutItem(BlockState state, Level level, BlockPos pos, Player player, BlockHitResult hitResult) {
169-
if (level.isClientSide) {
170-
return InteractionResult.sidedSuccess(true);
171-
}
172-
if (state.is(ModBlocks.MAGNET_BLOCK)) {
173-
if (player.isShiftKeyDown()) {
174-
player.addItem(ModItems.MAGNET_INGOT.asStack());
175-
level.setBlockAndUpdate(pos, ModBlocks.HOLLOW_MAGNET_BLOCK.getDefaultState());
176-
return InteractionResult.sidedSuccess(false);
169+
if (!level.isClientSide) {
170+
if (state.is(ModBlocks.MAGNET_BLOCK)) {
171+
if (player.isShiftKeyDown()) {
172+
player.addItem(ModItems.MAGNET_INGOT.asStack());
173+
level.setBlockAndUpdate(pos, ModBlocks.HOLLOW_MAGNET_BLOCK.getDefaultState());
174+
return InteractionResult.SUCCESS;
175+
}
177176
}
178177
}
179178
return super.useWithoutItem(state, level, pos, player, hitResult);

src/main/java/dev/dubhe/anvilcraft/client/event/ClientEventListener.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ public static void onKeyPress(Key event) {
127127
}
128128

129129
if (event.getKey() == ModKeyMappings.SWITCH_RESONATE_MODE.get().getKey().getValue()) {
130-
if (event.getAction() == InputConstants.PRESS) {
130+
if (event.getAction() == InputConstants.PRESS && Minecraft.getInstance().screen == null) {
131131
LocalPlayer player = Minecraft.getInstance().player;
132132
if (player == null) {
133133
return;

0 commit comments

Comments
 (0)