Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"values": [
"#c:chests/trapped",
"#c:chests/wooden"
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public boolean handle(Level level, BlockPos hitBlockPos, BlockState hitBlockStat
);
if (
hitBlockState.getValue(BlockDevourerBlock.FACING) == Direction.DOWN
&& level.getBlockState(hitBlockPos.below()).getBlock().defaultDestroyTime() >= 0
&& BlockDevourerBlock.canDevour(level.getBlockState(hitBlockPos.below()))
) {
level.setBlockAndUpdate(hitBlockPos, Blocks.AIR.defaultBlockState());
level.setBlockAndUpdate(hitBlockPos.below(), hitBlockState.setValue(BlockDevourerBlock.TRIGGERED, true));
Expand Down
11 changes: 10 additions & 1 deletion src/main/java/dev/dubhe/anvilcraft/block/BlockDevourerBlock.java
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,15 @@ public void devourBlock(
}
}

/**
* 检查目标位置是否可以破坏
*
* @param devourBlockState 目标方块
* */
public static boolean canDevour(BlockState devourBlockState) {
return !devourBlockState.is(ModBlockTags.DEVOUR_BLACKLIST) && devourBlockState.getBlock().defaultDestroyTime() >= 0;
}

private static void devourSingleBlockInternalLogic(
ServerLevel level, @Nullable Block anvil, BlockPos devourBlockPos, List<BlockPos> filteredBlockPosList,
@Nullable List<IItemHandler> itemHandlerList, Vec3 center
Expand All @@ -265,7 +274,7 @@ private static void devourSingleBlockInternalLogic(
if (filteredBlockPosList.contains(devourBlockPos)) return;
BlockState devourBlockState = level.getBlockState(devourBlockPos);
if (devourBlockState.isAir()) return;
if (devourBlockState.getBlock().defaultDestroyTime() < 0) return;
if (!BlockDevourerBlock.canDevour(devourBlockState)) return;
if (
!(anvil instanceof FrostAnvilBlock)
&& devourBlockState.is(ModBlockTags.BLOCK_DEVOURER_PROBABILITY_DROPPING)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,10 @@ public static void init(RegistrumTagsProvider<Block> provider) {
.addTag(Tags.Blocks.CHESTS_ENDER)
.addTag(Tags.Blocks.CHESTS_TRAPPED)
.addTag(Tags.Blocks.CHESTS_WOODEN);
provider.addTag(ModBlockTags.DEVOUR_BLACKLIST)
.addTag(Tags.Blocks.CHESTS_TRAPPED)
.addTag(Tags.Blocks.CHESTS_WOODEN);

provider.addTag(ModBlockTags.FELLING_APPLICABLE)
.addTag(BlockTags.LOGS)
.addTag(BlockTags.WART_BLOCKS)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import dev.dubhe.anvilcraft.AnvilCraft;
import dev.dubhe.anvilcraft.api.amulet.AmuletManager;
import dev.dubhe.anvilcraft.api.power.PowerGrid;
import dev.dubhe.anvilcraft.block.BlockDevourerBlock;
import dev.dubhe.anvilcraft.block.item.ResinBlockItem;
import dev.dubhe.anvilcraft.entity.MagnetizedNodeEntity;
import dev.dubhe.anvilcraft.init.block.ModBlocks;
Expand Down Expand Up @@ -124,9 +125,12 @@ public static void handleDragonRod(PlayerInteractEvent.LeftClickBlock event) {
final Direction blockFace = event.getFace();

if (blockFace == null) return;
if (state.getDestroySpeed(level, pos) == 0.0F) return;
if (state.getDestroySpeed(level, pos) < 0.0F) return;
if (!stack.has(ModComponents.DEVOUR_RANGE)) return;
if (!DragonRodItem.canDevour(player, stack)) event.setCanceled(true);
if (!DragonRodItem.canDevour(player, stack) || !BlockDevourerBlock.canDevour(state)) {
event.setCanceled(true);
return;
}

if (event.getAction() == PlayerInteractEvent.LeftClickBlock.Action.START && !level.isClientSide) {
DragonRodItem.devourBlock((ServerLevel) level, player, hand, pos, state, blockFace);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ public class ModBlockTags {
public static final TagKey<Block> NEEDS_TRANSCENDIUM_TOOL = bind("needs_transcendium_tool");

public static final TagKey<Block> ANVIL_HAMMER_BLACKLIST = bind("anvil_hammer_blacklist");
public static final TagKey<Block> DEVOUR_BLACKLIST = bind("devour_blacklist");

public static final TagKey<Block> FELLING_APPLICABLE = bind("felling_applicable");
public static final TagKey<Block> CLEANING_APPLICABLE = bind("cleaning_applicable");
Expand Down
6 changes: 4 additions & 2 deletions src/main/java/dev/dubhe/anvilcraft/item/DragonRodItem.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package dev.dubhe.anvilcraft.item;

import com.google.common.collect.Streams;
import dev.dubhe.anvilcraft.block.BlockDevourerBlock;
import dev.dubhe.anvilcraft.init.block.ModBlockTags;
import dev.dubhe.anvilcraft.init.item.ModComponents;
import dev.dubhe.anvilcraft.init.item.ModItems;
Expand Down Expand Up @@ -98,7 +99,8 @@ public static void devourBlock(
ServerLevel level, Player player, InteractionHand hand,
BlockPos centerPos, BlockState centerState, Direction clickedSide
) {
if (centerState.getDestroySpeed(level, centerPos) == 0.0F) return;
if (centerState.is(ModBlockTags.DEVOUR_BLACKLIST)) return;
if (centerState.getDestroySpeed(level, centerPos) < 0.0F) return;
ItemStack dragonRod = player.getItemInHand(hand);
if (!canDevour(player, dragonRod)) return;
int range = dragonRod.getOrDefault(ModComponents.DEVOUR_RANGE, -1);
Expand All @@ -125,7 +127,7 @@ public static void devourBlock(
for (BlockPos devouringPos : devouringPoses) {
BlockState devouringState = level.getBlockState(devouringPos);
if (devouringState.isAir()) continue;
if (devouringState.getBlock().defaultDestroyTime() < 0) continue;
if (!BlockDevourerBlock.canDevour(devouringState)) continue;
if (devouringState.is(ModBlockTags.BLOCK_DEVOURER_PROBABILITY_DROPPING)
&& level.random.nextDouble() > 0.05) {
level.destroyBlock(devouringPos, false);
Expand Down
Loading