diff --git a/common/src/main/java/dev/dubhe/anvilcraft/api/entity/player/AnvilCraftBlockPlacer.java b/common/src/main/java/dev/dubhe/anvilcraft/api/entity/player/AnvilCraftBlockPlacer.java index c5e379eb1..fa04df9d1 100644 --- a/common/src/main/java/dev/dubhe/anvilcraft/api/entity/player/AnvilCraftBlockPlacer.java +++ b/common/src/main/java/dev/dubhe/anvilcraft/api/entity/player/AnvilCraftBlockPlacer.java @@ -1,5 +1,9 @@ package dev.dubhe.anvilcraft.api.entity.player; +import java.util.HashSet; +import java.util.Set; + public class AnvilCraftBlockPlacer { + public static Set BLOCK_PLACER_BLACKLIST = new HashSet<>(); public static IAnvilCraftBlockPlacer anvilCraftBlockPlacer = null; } diff --git a/common/src/main/java/dev/dubhe/anvilcraft/api/entity/player/IAnvilCraftBlockPlacer.java b/common/src/main/java/dev/dubhe/anvilcraft/api/entity/player/IAnvilCraftBlockPlacer.java index 0493a8340..c2e1bf6b7 100644 --- a/common/src/main/java/dev/dubhe/anvilcraft/api/entity/player/IAnvilCraftBlockPlacer.java +++ b/common/src/main/java/dev/dubhe/anvilcraft/api/entity/player/IAnvilCraftBlockPlacer.java @@ -4,6 +4,8 @@ import dev.dubhe.anvilcraft.mixin.BlockItemInvoker; import net.minecraft.commands.arguments.EntityAnchorArgument.Anchor; import net.minecraft.core.BlockPos; +import net.minecraft.core.registries.BuiltInRegistries; +import net.minecraft.server.level.ServerLevel; import net.minecraft.server.level.ServerPlayer; import net.minecraft.sounds.SoundSource; import net.minecraft.world.InteractionResult; @@ -33,12 +35,20 @@ public interface IAnvilCraftBlockPlacer { */ default InteractionResult placeBlock(Level level, BlockPos pos, Orientation orientation, BlockItem blockItem, ItemStack itemStack) { + if (AnvilCraftBlockPlacer.BLOCK_PLACER_BLACKLIST + .contains(BuiltInRegistries.BLOCK.getKey(blockItem.getBlock()).toString())) + return InteractionResult.FAIL; + if (level instanceof ServerLevel serverLevel) + getPlayer().setServerLevel(serverLevel); + getPlayer().moveTo( + pos.relative(orientation.getDirection().getOpposite()).getX(), + pos.relative(orientation.getDirection().getOpposite()).getY() - 1, + pos.relative(orientation.getDirection().getOpposite()).getZ()); + getPlayer().lookAt(Anchor.EYES, new Vec3(pos.getX(), pos.getY(), pos.getZ())); Vec3 clickClickLocation = getPosFromOrientation(orientation); double x = clickClickLocation.x; double y = clickClickLocation.y; double z = clickClickLocation.z; - getPlayer().teleportTo(0.5, -1, 0.5); - getPlayer().lookAt(Anchor.EYES, new Vec3(x, 1 - y, z)); BlockHitResult blockHitResult = new BlockHitResult( pos.getCenter().add(-0.5, -0.5, -0.5).add(x, 1 - y, z), orientation.getDirection().getOpposite(), @@ -51,6 +61,8 @@ default InteractionResult placeBlock(Level level, BlockPos pos, Orientation orie if (blockState == null) { return InteractionResult.FAIL; } + if (!blockItem.canPlace(blockPlaceContext, blockState) || !blockState.canSurvive(level, pos)) + return InteractionResult.FAIL; level.setBlockAndUpdate(pos, blockState); blockItem.getBlock().setPlacedBy(level, pos, blockState, getPlayer(), itemStack); // 使放置的方块实体有NBT diff --git a/common/src/main/java/dev/dubhe/anvilcraft/integration/create/BoilerIntegration.java b/common/src/main/java/dev/dubhe/anvilcraft/integration/create/BoilerIntegration.java index a8d6de25a..985c454d3 100644 --- a/common/src/main/java/dev/dubhe/anvilcraft/integration/create/BoilerIntegration.java +++ b/common/src/main/java/dev/dubhe/anvilcraft/integration/create/BoilerIntegration.java @@ -1,8 +1,10 @@ package dev.dubhe.anvilcraft.integration.create; +import com.simibubi.create.AllBlocks; import com.simibubi.create.content.fluids.tank.BoilerHeaters; import dev.anvilcraft.lib.integration.Integration; import dev.dubhe.anvilcraft.AnvilCraft; +import dev.dubhe.anvilcraft.api.entity.player.AnvilCraftBlockPlacer; import dev.dubhe.anvilcraft.block.HeaterBlock; import dev.dubhe.anvilcraft.init.ModBlocks; @@ -23,5 +25,6 @@ public void apply() { } return null; })); + AnvilCraftBlockPlacer.BLOCK_PLACER_BLACKLIST.add(AllBlocks.BELT.getId().toString()); } } diff --git a/common/src/main/resources/anvilcraft.accesswidener b/common/src/main/resources/anvilcraft.accesswidener index 141752f2c..bb98f82fd 100644 --- a/common/src/main/resources/anvilcraft.accesswidener +++ b/common/src/main/resources/anvilcraft.accesswidener @@ -26,4 +26,5 @@ accessible method net/minecraft/world/level/block/Blocks never (Lnet/minecraft/w accessible method net/minecraft/world/level/block/Blocks never (Lnet/minecraft/world/level/block/state/BlockState;Lnet/minecraft/world/level/BlockGetter;Lnet/minecraft/core/BlockPos;)Z accessible method net/minecraft/util/SortedArraySet findIndex (Ljava/lang/Object;)I accessible method net/minecraft/util/SortedArraySet getInternal (I)Ljava/lang/Object; -accessible field net/minecraft/world/entity/item/FallingBlockEntity blockState Lnet/minecraft/world/level/block/state/BlockState; \ No newline at end of file +accessible field net/minecraft/world/entity/item/FallingBlockEntity blockState Lnet/minecraft/world/level/block/state/BlockState; +accessible method net/minecraft/world/item/BlockItem canPlace (Lnet/minecraft/world/item/context/BlockPlaceContext;Lnet/minecraft/world/level/block/state/BlockState;)Z \ No newline at end of file diff --git a/gradle.properties b/gradle.properties index 20dbff940..08a80ba7c 100644 --- a/gradle.properties +++ b/gradle.properties @@ -27,7 +27,7 @@ jei_version=15.3.0.4 rei_version=12.0.648 emi_version=1.1.4+1.20.1 kjs_version=2001.6.3-build.37 -anvil_lib_version=1.0.0+build.6 +anvil_lib_version=1.0.0+build.7 ## Fabric fabric_loader_version=0.15.7 fabric_api_version=0.92.0