Search in sources :

Example 1 with Direction

use of net.minecraft.util.math.Direction in project MasaGadget by plusls.

the class MixinWorldUtils method fixDoEasyPlaceAction0.

// 修复 漏斗,原木放置问题
// 核心思路是修改玩家看的位置以及 side
@Inject(method = "doEasyPlaceAction", at = @At(value = "INVOKE", target = "Lfi/dy/masa/litematica/util/WorldUtils;cacheEasyPlacePosition(Lnet/minecraft/util/math/BlockPos;)V", ordinal = 0, remap = true), locals = LocalCapture.CAPTURE_FAILHARD)
private static void fixDoEasyPlaceAction0(MinecraftClient mc, CallbackInfoReturnable<ActionResult> cir, RayTraceUtils.RayTraceWrapper traceWrapper) {
    if (!Configs.Litematica.FIX_ACCURATE_PROTOCOL.getBooleanValue()) {
        return;
    }
    BlockHitResult trace = Objects.requireNonNull(traceWrapper).getBlockHitResult();
    BlockPos pos = Objects.requireNonNull(trace).getBlockPos();
    World world = Objects.requireNonNull(SchematicWorldHandler.getSchematicWorld());
    BlockState stateSchematic = world.getBlockState(pos);
    ItemStack stack = MaterialCache.getInstance().getRequiredBuildItemForState(stateSchematic);
    Hand hand = EntityUtils.getUsedHandForItem(Objects.requireNonNull(mc.player), stack);
    Vec3d hitPos = trace.getPos();
    Direction newSide = BlockUtils.getFirstPropertyFacingValue(stateSchematic);
    easyPlaceActionNewSide.set(newSide);
    easyPlaceActionOldYaw.set(mc.player.getYaw());
    if (newSide == null && stateSchematic.contains(Properties.AXIS)) {
        // 原木之类的
        newSide = Direction.from(stateSchematic.get(Properties.AXIS), Direction.AxisDirection.POSITIVE);
        easyPlaceActionNewSide.set(newSide);
    }
    if (newSide != null && !(stateSchematic.getBlock() instanceof SlabBlock)) {
        // fuck mojang
        // 有时候放的东西是反向的,需要特判
        mc.player.setYaw(newSide.asRotation());
        ItemStack itemStack = new ItemStack(stateSchematic.getBlock().asItem());
        ItemPlacementContext itemPlacementContext = new ItemPlacementContext(mc.player, hand, itemStack, new BlockHitResult(hitPos, newSide, pos, false));
        BlockState testState = stateSchematic.getBlock().getPlacementState(itemPlacementContext);
        if (testState != null) {
            Direction testDirection = BlockUtils.getFirstPropertyFacingValue(testState);
            if (testDirection != null && testDirection != newSide) {
                newSide = newSide.getOpposite();
                easyPlaceActionNewSide.set(newSide);
                mc.player.setYaw(newSide.asRotation());
            }
        }
        mc.player.networkHandler.sendPacket(new PlayerMoveC2SPacket.LookAndOnGround(mc.player.getYaw(), mc.player.getPitch(), mc.player.isOnGround()));
    }
    if (stateSchematic.getBlock() instanceof FenceGateBlock && stateSchematic.get(Properties.OPEN)) {
        interactBlockCount.set(1);
    }
}
Also used : PlayerMoveC2SPacket(net.minecraft.network.packet.c2s.play.PlayerMoveC2SPacket) World(net.minecraft.world.World) ClientWorld(net.minecraft.client.world.ClientWorld) Hand(net.minecraft.util.Hand) Direction(net.minecraft.util.math.Direction) Vec3d(net.minecraft.util.math.Vec3d) BlockPos(net.minecraft.util.math.BlockPos) ItemPlacementContext(net.minecraft.item.ItemPlacementContext) BlockHitResult(net.minecraft.util.hit.BlockHitResult) ItemStack(net.minecraft.item.ItemStack) Inject(org.spongepowered.asm.mixin.injection.Inject)

Example 2 with Direction

use of net.minecraft.util.math.Direction in project MasaGadget by plusls.

the class MixinWorldUtils method preApplyCarpetProtocolHitVec.

@Inject(method = "applyCarpetProtocolHitVec", at = @At(value = "HEAD"), cancellable = true)
private static void preApplyCarpetProtocolHitVec(BlockPos pos, BlockState state, Vec3d hitVecIn, CallbackInfoReturnable<Vec3d> cir) {
    if (!Configs.Litematica.FIX_ACCURATE_PROTOCOL.getBooleanValue()) {
        return;
    }
    double x = hitVecIn.x;
    double y = hitVecIn.y;
    double z = hitVecIn.z;
    Block block = state.getBlock();
    Direction facing = fi.dy.masa.malilib.util.BlockUtils.getFirstPropertyFacingValue(state);
    // 应该是 32 而不是 16
    final int propertyIncrement = 32;
    double relX = hitVecIn.x - pos.getX();
    if (facing != null) {
        x = pos.getX() + relX + 2 + (facing.getId() * 2);
    }
    if (block instanceof RepeaterBlock) {
        // 这里也实现错了,不应该是 DELAY - 1
        x += ((state.get(RepeaterBlock.DELAY))) * propertyIncrement;
    } else if (block instanceof TrapdoorBlock && state.get(TrapdoorBlock.HALF) == BlockHalf.TOP) {
        x += propertyIncrement;
    } else if (block instanceof ComparatorBlock && state.get(ComparatorBlock.MODE) == ComparatorMode.SUBTRACT) {
        x += propertyIncrement;
    } else if (block instanceof StairsBlock && state.get(StairsBlock.HALF) == BlockHalf.TOP) {
        x += propertyIncrement;
    } else if (block instanceof SlabBlock && state.get(SlabBlock.TYPE) != SlabType.DOUBLE) {
        // Do it via vanilla
        if (state.get(SlabBlock.TYPE) == SlabType.TOP) {
            y = pos.getY() + 0.9;
        } else {
            y = pos.getY();
        }
    }
    ModInfo.LOGGER.debug("applyCarpetProtocolHitVec: {} -> {}", hitVecIn, new Vec3d(x, y, z).toString());
    cir.setReturnValue(new Vec3d(x, y, z));
}
Also used : Direction(net.minecraft.util.math.Direction) Vec3d(net.minecraft.util.math.Vec3d) Inject(org.spongepowered.asm.mixin.injection.Inject)

Example 3 with Direction

use of net.minecraft.util.math.Direction in project Blockus by Brandcraf06.

the class Barrier method method_24423.

private BlockState method_24423(WorldView worldView, BlockPos blockPos, BlockState blockState, BlockPos blockPos2, BlockState blockState2, Direction direction) {
    Direction direction2 = direction.getOpposite();
    boolean bl = direction == Direction.NORTH ? this.shouldConnectTo(blockState2, blockState2.isSideSolidFullSquare(worldView, blockPos2, direction2), direction2) : method_24424(blockState, NORTH_SHAPE);
    boolean bl2 = direction == Direction.EAST ? this.shouldConnectTo(blockState2, blockState2.isSideSolidFullSquare(worldView, blockPos2, direction2), direction2) : method_24424(blockState, EAST_SHAPE);
    boolean bl3 = direction == Direction.SOUTH ? this.shouldConnectTo(blockState2, blockState2.isSideSolidFullSquare(worldView, blockPos2, direction2), direction2) : method_24424(blockState, SOUTH_SHAPE);
    boolean bl4 = direction == Direction.WEST ? this.shouldConnectTo(blockState2, blockState2.isSideSolidFullSquare(worldView, blockPos2, direction2), direction2) : method_24424(blockState, WEST_SHAPE);
    BlockPos blockPos3 = blockPos.up();
    BlockState blockState3 = worldView.getBlockState(blockPos3);
    return this.method_24422(worldView, blockState, blockPos3, blockState3, bl, bl2, bl3, bl4);
}
Also used : BlockPos(net.minecraft.util.math.BlockPos) Direction(net.minecraft.util.math.Direction)

Example 4 with Direction

use of net.minecraft.util.math.Direction in project Primeval by devs-immortal.

the class SemiSupportedBlock method supported.

protected boolean supported(World world, BlockPos pos, Random random) {
    float fallPercent = 1.0f;
    for (Direction sideDirection : Arrays.asList(Direction.UP, Direction.DOWN, Direction.NORTH, Direction.EAST, Direction.SOUTH, Direction.WEST)) {
        if (world.getBlockState(pos.offset(sideDirection)).isSideSolidFullSquare(world, pos.offset(sideDirection), sideDirection.getOpposite())) {
            fallPercent -= percentPerSide;
        }
    }
    float rand = random.nextFloat();
    return rand > fallPercent || super.supported(world, pos, random);
}
Also used : Direction(net.minecraft.util.math.Direction)

Example 5 with Direction

use of net.minecraft.util.math.Direction in project meteor-rejects by AntiCope.

the class AutoWither method onTick.

@EventHandler
private void onTick(TickEvent.Pre event) {
    if (wither == null) {
        // Delay
        if (witherTicksWaited < witherDelay.get() - 1) {
            return;
        }
        // Clear pool and list
        for (Wither wither : withers) witherPool.free(wither);
        withers.clear();
        // Register
        BlockIterator.register(horizontalRadius.get(), verticalRadius.get(), (blockPos, blockState) -> {
            Direction dir = Direction.fromRotation(Rotations.getYaw(blockPos)).getOpposite();
            if (isValidSpawn(blockPos, dir))
                withers.add(witherPool.get().set(blockPos, dir));
        });
    }
}
Also used : Direction(net.minecraft.util.math.Direction) EventHandler(meteordevelopment.orbit.EventHandler)

Aggregations

Direction (net.minecraft.util.math.Direction)184 BlockPos (net.minecraft.util.math.BlockPos)89 BlockState (net.minecraft.block.BlockState)46 Vec3d (net.minecraft.util.math.Vec3d)19 Block (net.minecraft.block.Block)14 BlockHitResult (net.minecraft.util.hit.BlockHitResult)13 Box (net.minecraft.util.math.Box)11 VoxelShape (net.minecraft.util.shape.VoxelShape)8 SculkVeinBlock (frozenblock.wild.mod.blocks.SculkVeinBlock)7 Inject (org.spongepowered.asm.mixin.injection.Inject)7 ArrayList (java.util.ArrayList)6 World (net.minecraft.world.World)6 Random (java.util.Random)5 Environment (net.fabricmc.api.Environment)5 BakedQuad (net.minecraft.client.render.model.BakedQuad)5 Nullable (org.jetbrains.annotations.Nullable)5 List (java.util.List)4 Set (java.util.Set)4 Collectors (java.util.stream.Collectors)4 EventHandler (meteordevelopment.orbit.EventHandler)4