Add DragonRod and Devourer's devour priority judgement 吞噬额外判断#3383
Add DragonRod and Devourer's devour priority judgement 吞噬额外判断#3383Chrise2024 wants to merge 11 commits intoAnvil-Dev:dev/1.21/1.6from
Conversation
There was a problem hiding this comment.
Pull request overview
This PR addresses issue #3382 by adding an attachment-aware “devour ordering” so blocks that would otherwise pop off (torches, redstone dust, etc.) can be handled before their supporting blocks are removed.
Changes:
- Added
DevouringLevelReader(a wrapperLevelReader) to simulate “to-be-devoured blocks are already air” when evaluatingBlockState#canSurvive. - Updated
DragonRodItemdevour logic to split blocks into “primary” vs “secondary” destruction passes using survivability checks. - Updated
BlockDevourerBlockdevour logic to use survivability checks (plus chain-devour handling) to influence devour order.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 7 comments.
| File | Description |
|---|---|
src/main/java/dev/dubhe/anvilcraft/util/DevouringLevelReader.java |
New fake LevelReader used to evaluate survivability as if devoured blocks were already removed. |
src/main/java/dev/dubhe/anvilcraft/item/DragonRodItem.java |
Uses the fake reader to reorder destruction and reduce attachment pop-off drops. |
src/main/java/dev/dubhe/anvilcraft/block/BlockDevourerBlock.java |
Applies survivability-based ordering to block devourer (including chain devouring). |
Comments suppressed due to low confidence (1)
src/main/java/dev/dubhe/anvilcraft/block/BlockDevourerBlock.java:33
import net.minecraft.world.level.block.Blocks;appears unused in this file (noBlocks.references). If your build enables unused-import checks, this will fail compilation; please remove the import.
import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.DirectionalBlock;
import net.minecraft.world.level.block.DoublePlantBlock;
import net.minecraft.world.level.block.Mirror;
import net.minecraft.world.level.block.RenderShape;
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| if (level.getBlockState(devourBlockPos).canSurvive(devouringLevelReader, devourBlockPos)) { | ||
| devourSingleBlockInternalLogic(level, anvil, devourBlockPos, filteredBlockPosList, itemHandlerList, center); | ||
| } else { | ||
| secondaryBlockPosList.add(devourBlockPos); | ||
| } | ||
| } | ||
| DevouringLevelReader chainDevouringLevelReader = new DevouringLevelReader(level, chainDevourBlockPosList); | ||
| for (BlockPos devourBlockPos : chainDevourBlockPosList) { | ||
| if (level.getBlockState(devourBlockPos).canSurvive(chainDevouringLevelReader, devourBlockPos)) { | ||
| devourSingleBlockInternalLogic(level, anvil, devourBlockPos, filteredBlockPosList, itemHandlerList, center); | ||
| } else { | ||
| secondaryBlockPosList.add(devourBlockPos); | ||
| } | ||
| } | ||
| for (BlockPos devourBlockPos : secondaryBlockPosList) { | ||
| devourSingleBlockInternalLogic(level, anvil, devourBlockPos, filteredBlockPosList, itemHandlerList, center); | ||
| } |
There was a problem hiding this comment.
The survivability-based ordering appears inverted. Blocks that cannot survive when other devoured blocks are treated as air are the ones that need to be devoured first (to avoid attachment blocks popping/dropping after their support is removed). Here, canSurvive(...) blocks are processed first and non-survivors are deferred to secondaryBlockPosList, which likely recreates the original drop problem. Swap the branches so non-survivors are devoured before survivors (apply similarly to the chain loop).
# Conflicts: # src/main/java/dev/dubhe/anvilcraft/util/DevouringLevelReader.java
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 3 out of 3 changed files in this pull request and generated 6 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 6 out of 6 changed files in this pull request and generated 8 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| @@ -207,7 +202,7 @@ public static int calculateDamage(ItemStack dragonRod) { | |||
| case 9 -> 4; | |||
| default -> 0; | |||
| }; | |||
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 6 out of 6 changed files in this pull request and generated 4 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
|
||
| for (BlockPos devourBlockPos : devourTargets) { | ||
| BlockState devourState = level.getBlockState(devourBlockPos); | ||
| if (!DevourUtil.shouldDevour(devourState)) continue; | ||
| BlockPos normalizedBlockPos = MultiPartBlockUtil.getChainableMainPartPos(level, devourBlockPos); | ||
| if (normalizedBlockPos.equals(devourBlockPos)) { | ||
| devourBlockPos = normalizedBlockPos; | ||
| devourState = level.getBlockState(normalizedBlockPos); | ||
| } |
| Set<BlockPos> devourTargets = Streams | ||
| .stream(BlockPos.betweenClosed(a, b)) | ||
| .flatMap(bottomPos -> { | ||
| // dh = 0 when DOWN, UP; above dh is chain range | ||
| int dh = devourDirection.getStepY() != 0 ? 0 : 2 * range; | ||
| int cy = bottomPos.getY() + dh; | ||
| return Streams | ||
| .stream(BlockPos.betweenClosed(bottomPos, bottomPos.atY(cy + chainCount))) | ||
| .map(BlockPos::immutable) | ||
| .takeWhile(pos -> pos.getY() <= cy || DevourUtil.shouldChainDevour(level.getBlockState(pos))); | ||
| // in common devour OR chain until unchainable | ||
| }) | ||
| .collect(Collectors.toSet()); |
| return; | ||
| } | ||
| boolean shouldDrop = !devouringState.is(ModBlockTags.BLOCK_DEVOURER_PROBABILITY_DROPPING) | ||
| || level.random.nextDouble() <= 0.05; |
| default -> 0; | ||
| }; | ||
| return Math.min(damage, Math.max(dragonRod.getMaxDamage() - dragonRod.getDamageValue(), 1)); | ||
| return Mth.clamp(dragonRod.getMaxDamage() - dragonRod.getDamageValue(), 1, damage); |
Uh oh!
There was an error while loading. Please reload this page.