Skip to content

Commit

Permalink
Merge pull request #1003 from dmzz-yyhyy/placer_fix
Browse files Browse the repository at this point in the history
修复放置器逻辑
  • Loading branch information
Gu-ZT authored Jul 4, 2024
2 parents c4315a0 + 9d0387f commit 615fbc1
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -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<String> BLOCK_PLACER_BLACKLIST = new HashSet<>();
public static IAnvilCraftBlockPlacer anvilCraftBlockPlacer = null;
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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(),
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -23,5 +25,6 @@ public void apply() {
}
return null;
}));
AnvilCraftBlockPlacer.BLOCK_PLACER_BLACKLIST.add(AllBlocks.BELT.getId().toString());
}
}
3 changes: 2 additions & 1 deletion common/src/main/resources/anvilcraft.accesswidener
Original file line number Diff line number Diff line change
Expand Up @@ -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;
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
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 615fbc1

Please sign in to comment.