From 60b3796cf792f40e0ea3c62f225b505ab3a10b7f Mon Sep 17 00:00:00 2001 From: WenXin2 Date: Sat, 4 Jan 2025 18:24:54 -0600 Subject: [PATCH] Fix invisible question block --- .../blocks/InvisibleQuestionBlock.java | 22 +++++-------------- .../marioverse/blocks/QuestionBlock.java | 4 ++-- 2 files changed, 7 insertions(+), 19 deletions(-) diff --git a/src/main/java/com/wenxin2/marioverse/blocks/InvisibleQuestionBlock.java b/src/main/java/com/wenxin2/marioverse/blocks/InvisibleQuestionBlock.java index fd11c768..665ddb06 100644 --- a/src/main/java/com/wenxin2/marioverse/blocks/InvisibleQuestionBlock.java +++ b/src/main/java/com/wenxin2/marioverse/blocks/InvisibleQuestionBlock.java @@ -5,7 +5,6 @@ import com.wenxin2.marioverse.init.ConfigRegistry; import com.wenxin2.marioverse.init.ParticleRegistry; import com.wenxin2.marioverse.init.TagRegistry; -import com.wenxin2.marioverse.items.BasePowerUpItem; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; import net.minecraft.tags.FluidTags; @@ -13,20 +12,10 @@ import net.minecraft.world.InteractionHand; import net.minecraft.world.ItemInteractionResult; import net.minecraft.world.entity.player.Player; -import net.minecraft.world.item.ArmorStandItem; import net.minecraft.world.item.BlockItem; -import net.minecraft.world.item.BoatItem; import net.minecraft.world.item.BucketItem; import net.minecraft.world.item.DebugStickItem; -import net.minecraft.world.item.EggItem; -import net.minecraft.world.item.ExperienceBottleItem; -import net.minecraft.world.item.FireChargeItem; import net.minecraft.world.item.ItemStack; -import net.minecraft.world.item.LingeringPotionItem; -import net.minecraft.world.item.MinecartItem; -import net.minecraft.world.item.PotionItem; -import net.minecraft.world.item.SpawnEggItem; -import net.minecraft.world.item.WindChargeItem; import net.minecraft.world.item.context.BlockPlaceContext; import net.minecraft.world.level.BlockGetter; import net.minecraft.world.level.Level; @@ -34,7 +23,6 @@ import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.RenderShape; import net.minecraft.world.level.block.SimpleWaterloggedBlock; -import net.minecraft.world.level.block.TntBlock; import net.minecraft.world.level.block.entity.BlockEntity; import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.block.state.StateDefinition; @@ -165,6 +153,10 @@ protected ItemInteractionResult useItemOn(ItemStack stack, BlockState state, Lev && !state.getValue(EMPTY)) { ItemStack storedItem = questionBlockEntity.getItems().getFirst(); + // Keep above "if (!storedItem.isEmpty())" + if (state.getValue(InvisibleQuestionBlock.INVISIBLE)) + world.setBlock(pos, state.setValue(INVISIBLE, Boolean.FALSE), 3); + if (!storedItem.isEmpty()) { if (!world.isClientSide) this.spawnFromQuestionBlock(world, pos, storedItem, null, Boolean.FALSE, Boolean.TRUE); @@ -174,13 +166,9 @@ protected ItemInteractionResult useItemOn(ItemStack stack, BlockState state, Lev questionBlockEntity.setChanged(); } - if (storedItem.isEmpty()) { + if (storedItem.isEmpty()) world.setBlock(pos, state.setValue(QuestionBlock.EMPTY, Boolean.TRUE), 3); - } - if (state.getValue(InvisibleQuestionBlock.INVISIBLE)) { - world.setBlock(pos, state.setValue(INVISIBLE, Boolean.FALSE), 3); - } return ItemInteractionResult.SUCCESS; } else return ItemInteractionResult.PASS_TO_DEFAULT_BLOCK_INTERACTION; } diff --git a/src/main/java/com/wenxin2/marioverse/blocks/QuestionBlock.java b/src/main/java/com/wenxin2/marioverse/blocks/QuestionBlock.java index 16a8fb17..80524aeb 100644 --- a/src/main/java/com/wenxin2/marioverse/blocks/QuestionBlock.java +++ b/src/main/java/com/wenxin2/marioverse/blocks/QuestionBlock.java @@ -184,9 +184,9 @@ protected ItemInteractionResult useItemOn(ItemStack stack, BlockState state, Lev questionBlockEntity.setChanged(); } - if (storedItem.isEmpty()) { + if (storedItem.isEmpty()) world.setBlock(pos, state.setValue(QuestionBlock.EMPTY, Boolean.TRUE), 3); - } + return ItemInteractionResult.SUCCESS; } else return ItemInteractionResult.PASS_TO_DEFAULT_BLOCK_INTERACTION; }