diff --git a/src/main/java/com/wenxin2/marioverse/blocks/QuestionBlock.java b/src/main/java/com/wenxin2/marioverse/blocks/QuestionBlock.java index efc09178..15838c6f 100644 --- a/src/main/java/com/wenxin2/marioverse/blocks/QuestionBlock.java +++ b/src/main/java/com/wenxin2/marioverse/blocks/QuestionBlock.java @@ -7,7 +7,6 @@ import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; import net.minecraft.server.level.ServerLevel; -import net.minecraft.sounds.SoundEvents; import net.minecraft.sounds.SoundSource; import net.minecraft.world.Containers; import net.minecraft.world.InteractionHand; @@ -66,39 +65,6 @@ public BlockState getStateForPlacement(BlockPlaceContext placeContext) { return this.defaultBlockState().setValue(EMPTY, Boolean.TRUE); } - @Override - public void onPlace(BlockState state, Level world, BlockPos pos, BlockState oldState, boolean isMoving) { - super.onPlace(state, world, pos, oldState, isMoving); - if (world.getBlockEntity(pos) instanceof QuestionBlockEntity questionBlockEntity) { - boolean hasUnprocessedLoot = questionBlockEntity.getLootTable() != null && !questionBlockEntity.hasLootTableBeenProcessed(); - if (hasUnprocessedLoot || !questionBlockEntity.hasItems()) - state.setValue(QuestionBlock.EMPTY, Boolean.FALSE); - else state.setValue(QuestionBlock.EMPTY, Boolean.TRUE); - } - } - - @Override - public void neighborChanged(BlockState state, Level world, BlockPos pos, Block block, BlockPos neighborPos, boolean moved) { - super.neighborChanged(state, world, pos, block, neighborPos, moved); - if (world.getBlockEntity(pos) instanceof QuestionBlockEntity questionBlockEntity) { - boolean hasUnprocessedLoot = questionBlockEntity.getLootTable() != null && !questionBlockEntity.hasLootTableBeenProcessed(); - if (hasUnprocessedLoot || !questionBlockEntity.hasItems()) - state.setValue(QuestionBlock.EMPTY, Boolean.FALSE); - else state.setValue(QuestionBlock.EMPTY, Boolean.TRUE); - } - } - - @Override - public BlockState updateShape(BlockState state, Direction direction, BlockState neighborState, - LevelAccessor worldAccessor, BlockPos pos, BlockPos posNeighbor) { - QuestionBlockEntity questionBlockEntity = (QuestionBlockEntity) worldAccessor.getBlockEntity(pos); - - if (questionBlockEntity != null && (questionBlockEntity.getLootTable() != null || questionBlockEntity.hasItems())) { - return state.setValue(EMPTY, Boolean.FALSE); - } - else return state.setValue(EMPTY, Boolean.TRUE); - } - @Override protected boolean hasAnalogOutputSignal(BlockState state) { return true; @@ -116,14 +82,13 @@ protected ItemInteractionResult useItemOn(ItemStack stack, BlockState state, Lev ItemStack heldItem = player.getItemInHand(hand); BlockEntity blockEntity = world.getBlockEntity(pos); - if (blockEntity instanceof QuestionBlockEntity questionBlockEntity) { + if (blockEntity instanceof QuestionBlockEntity questionBlockEntity && !heldItem.is(TagRegistry.QUESTION_BLOCK_ITEM_BLACKLIST)) { ItemStack blockStack = questionBlockEntity.getStackInSlot(); - if (questionBlockEntity.getLootTable() != null) { + if (questionBlockEntity.getLootTable() != null) this.unpackLootTable(player, questionBlockEntity); - world.setBlock(pos, state.setValue(QuestionBlock.EMPTY, Boolean.TRUE), 3); - } - if (!heldItem.isEmpty() && (ConfigRegistry.QUESTION_ADD_ITEMS.get() || player.isCreative()) + if (!heldItem.isEmpty() && questionBlockEntity.getLootTable() == null/* && !heldItem.is(TagRegistry.QUESTION_BLOCK_ITEM_BLACKLIST)*/ + && (ConfigRegistry.QUESTION_ADD_ITEMS.get() || player.isCreative()) && (blockStack.isEmpty() || ItemStack.isSameItemSameComponents(heldItem, blockStack))) { world.setBlock(pos, state.setValue(QuestionBlock.EMPTY, Boolean.FALSE), 3); questionBlockEntity.addItem(heldItem); @@ -132,7 +97,7 @@ protected ItemInteractionResult useItemOn(ItemStack stack, BlockState state, Lev stack.shrink(heldItem.getCount()); return ItemInteractionResult.SUCCESS; } else if (heldItem.isEmpty() && (ConfigRegistry.QUESTION_REMOVE_ITEMS.get() || player.isCreative()) - && (!state.getValue(EMPTY) || !questionBlockEntity.hasLootTableBeenProcessed())) { + && !state.getValue(EMPTY)) { ItemStack storedItem = questionBlockEntity.getItems().getFirst(); if (!storedItem.isEmpty()) { @@ -153,16 +118,16 @@ else if (storedItem.getItem() instanceof SpawnEggItem) world.setBlock(pos, state.setValue(QuestionBlock.EMPTY, Boolean.TRUE), 3); } return ItemInteractionResult.SUCCESS; - } else return ItemInteractionResult.CONSUME; + } else return ItemInteractionResult.PASS_TO_DEFAULT_BLOCK_INTERACTION; } - return ItemInteractionResult.CONSUME; + return ItemInteractionResult.PASS_TO_DEFAULT_BLOCK_INTERACTION; } public void spawnEntity(Level world, BlockPos pos, ItemStack stack) { if (stack.getItem() instanceof SpawnEggItem spawnEgg && ConfigRegistry.QUESTION_SPAWNS_MOBS.get()) { EntityType entityType = spawnEgg.getType(stack); - if (world instanceof ServerLevel serverWorld && !entityType.is(TagRegistry.QUESTION_BLOCK_BLACKLIST)) { + if (world instanceof ServerLevel serverWorld && !entityType.is(TagRegistry.QUESTION_BLOCK_ENTITY_BLACKLIST)) { if (world.getBlockState(pos.above()).isAir()) entityType.spawn(serverWorld, stack, null, pos.above(2), MobSpawnType.SPAWN_EGG, true, true); else entityType.spawn(serverWorld, stack, null, pos.below(Math.round(entityType.getHeight())), MobSpawnType.SPAWN_EGG, true, true); diff --git a/src/main/java/com/wenxin2/marioverse/blocks/entities/QuestionBlockEntity.java b/src/main/java/com/wenxin2/marioverse/blocks/entities/QuestionBlockEntity.java index 5a819c13..873424e9 100644 --- a/src/main/java/com/wenxin2/marioverse/blocks/entities/QuestionBlockEntity.java +++ b/src/main/java/com/wenxin2/marioverse/blocks/entities/QuestionBlockEntity.java @@ -63,18 +63,16 @@ public static void serverTick(Level p_155014_, BlockPos p_155015_, BlockState p_ } -// @Override -// public void setChanged() { -// boolean hasUnprocessedLoot = this.getLootTable() != null && !this.hasLootTableBeenProcessed(); -// -// if (this.level != null && this.level.getBlockState(this.getBlockPos()).getBlock() instanceof QuestionBlock) { -// if (hasUnprocessedLoot || !this.items.isEmpty()) -// this.level.setBlock(this.getBlockPos(), this.getBlockState().setValue(QuestionBlock.EMPTY, Boolean.FALSE), 3); -// else -// this.level.setBlock(this.getBlockPos(), this.getBlockState().setValue(QuestionBlock.EMPTY, Boolean.TRUE), 3); -// } -// super.setChanged(); -// } + @Override + public void setChanged() { + if (this.level != null && this.level.getBlockState(this.getBlockPos()).getBlock() instanceof QuestionBlock) { + if (this.getLootTable() != null || !this.items.getFirst().isEmpty()) + this.level.setBlock(this.getBlockPos(), this.getBlockState().setValue(QuestionBlock.EMPTY, Boolean.FALSE), 3); + else + this.level.setBlock(this.getBlockPos(), this.getBlockState().setValue(QuestionBlock.EMPTY, Boolean.TRUE), 3); + } + super.setChanged(); + } @Override protected void saveAdditional(CompoundTag tag, HolderLookup.Provider provider) { diff --git a/src/main/java/com/wenxin2/marioverse/init/TagRegistry.java b/src/main/java/com/wenxin2/marioverse/init/TagRegistry.java index f1e2a0ba..2fc38eb4 100644 --- a/src/main/java/com/wenxin2/marioverse/init/TagRegistry.java +++ b/src/main/java/com/wenxin2/marioverse/init/TagRegistry.java @@ -11,14 +11,15 @@ public class TagRegistry { public static final TagKey BONKABLE_BLOCKS = blockTags(Marioverse.MOD_ID, "bonkable_blocks"); public static final TagKey DYEABLE_WARP_PIPE_BLOCKS = blockTags(Marioverse.MOD_ID, "dyeable_warp_pipes"); - public static final TagKey WARP_PIPE_BLOCKS = blockTags(Marioverse.MOD_ID, "warp_pipes"); public static final TagKey QUESTION_BLOCK_BLOCKS = blockTags(Marioverse.MOD_ID, "question_blocks"); - public static final TagKey QUESTION_BLOCK_ITEMS = itemTags(Marioverse.MOD_ID, "question_blocks"); + public static final TagKey WARP_PIPE_BLOCKS = blockTags(Marioverse.MOD_ID, "warp_pipes"); public static final TagKey WRENCH_EFFICIENT = blockTags(Marioverse.MOD_ID, "wrench_efficient"); public static final TagKey DYEABLE_WARP_PIPE_ITEMS = itemTags(Marioverse.MOD_ID, "dyeable_warp_pipes"); + public static final TagKey QUESTION_BLOCK_ITEM_BLACKLIST = itemTags(Marioverse.MOD_ID, "question_block_blacklist"); + public static final TagKey QUESTION_BLOCK_ITEMS = itemTags(Marioverse.MOD_ID, "question_blocks"); public static final TagKey WARP_PIPE_ITEMS = itemTags(Marioverse.MOD_ID, "warp_pipes"); public static final TagKey> WARP_BLACKLIST = entityTypeTags(Marioverse.MOD_ID, "warp_blacklist"); - public static final TagKey> QUESTION_BLOCK_BLACKLIST = entityTypeTags(Marioverse.MOD_ID, "question_block_blacklist"); + public static final TagKey> QUESTION_BLOCK_ENTITY_BLACKLIST = entityTypeTags(Marioverse.MOD_ID, "question_block_blacklist"); public static final TagKey> QUICK_TRAVEL_BLACKLIST = entityTypeTags(Marioverse.MOD_ID, "quick_travel_blacklist"); public static TagKey blockTags(String id, String name) { diff --git a/src/main/java/com/wenxin2/marioverse/mixin/PlayerMixin.java b/src/main/java/com/wenxin2/marioverse/mixin/PlayerMixin.java index 768383f2..b3a4c996 100644 --- a/src/main/java/com/wenxin2/marioverse/mixin/PlayerMixin.java +++ b/src/main/java/com/wenxin2/marioverse/mixin/PlayerMixin.java @@ -116,10 +116,8 @@ public void baseTick() { if (world.getBlockState(pos).getBlock() instanceof QuestionBlock questionBlock) { - if (questionBlockEntity.getLootTable() != null) { + if (questionBlockEntity.getLootTable() != null) questionBlock.unpackLootTable(this, questionBlockEntity); - world.setBlock(pos, world.getBlockState(pos).setValue(QuestionBlock.EMPTY, Boolean.TRUE), 3); - } ItemStack storedItem = questionBlockEntity.getItems().getFirst(); if (!storedItem.isEmpty() && !world.getBlockState(pos).getValue(QuestionBlock.EMPTY)) {