Search in sources :

Example 1 with BlockHitResult

use of net.minecraft.util.hit.BlockHitResult 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 BlockHitResult

use of net.minecraft.util.hit.BlockHitResult in project MasaGadget by plusls.

the class MixinWorldUtils method checkInventory.

@Inject(method = "handleEasyPlace", at = @At(value = "INVOKE", target = "Lfi/dy/masa/malilib/util/InfoUtils;showGuiOrInGameMessage(Lfi/dy/masa/malilib/gui/Message$MessageType;Ljava/lang/String;[Ljava/lang/Object;)V", ordinal = 0), cancellable = true)
private static void checkInventory(MinecraftClient mc, CallbackInfoReturnable<Boolean> cir) {
    if (!Configs.Litematica.BETTER_EASY_PLACE_MODE.getBooleanValue() || mc.world == null) {
        return;
    }
    HitResult trace = mc.crosshairTarget;
    if (trace != null && trace.getType() == HitResult.Type.BLOCK) {
        BlockHitResult blockHitResult = (BlockHitResult) trace;
        BlockPos pos = blockHitResult.getBlockPos();
        Block block = mc.world.getBlockState(pos).getBlock();
        if (block == Blocks.BEACON || mc.world.getBlockEntity(pos) instanceof Inventory) {
            cir.setReturnValue(false);
        }
    }
}
Also used : BlockHitResult(net.minecraft.util.hit.BlockHitResult) HitResult(net.minecraft.util.hit.HitResult) Block(net.minecraft.block.Block) BlockPos(net.minecraft.util.math.BlockPos) BlockHitResult(net.minecraft.util.hit.BlockHitResult) Inventory(net.minecraft.inventory.Inventory) Inject(org.spongepowered.asm.mixin.injection.Inject)

Example 3 with BlockHitResult

use of net.minecraft.util.hit.BlockHitResult in project meteor-rejects by AntiCope.

the class Confuse method onTick.

@EventHandler
private void onTick(TickEvent.Pre event) {
    // Delay
    delayWaited++;
    if (delayWaited < delay.get())
        return;
    delayWaited = 0;
    // Targetting
    target = TargetUtils.getPlayerTarget(range.get(), priority.get());
    if (target == null)
        return;
    Vec3d entityPos = target.getPos();
    Vec3d playerPos = mc.player.getPos();
    Random r = new Random();
    BlockHitResult hit;
    int halfRange = range.get() / 2;
    switch(mode.get()) {
        case RandomTP:
            double x = r.nextDouble() * range.get() - halfRange;
            double y = 0;
            double z = r.nextDouble() * range.get() - halfRange;
            Vec3d addend = new Vec3d(x, y, z);
            Vec3d goal = entityPos.add(addend);
            if (mc.world.getBlockState(new BlockPos(goal.x, goal.y, goal.z)).getBlock() != Blocks.AIR) {
                goal = new Vec3d(x, playerPos.y, z);
            }
            if (mc.world.getBlockState(new BlockPos(goal.x, goal.y, goal.z)).getBlock() == Blocks.AIR) {
                hit = mc.world.raycast(new RaycastContext(mc.player.getPos(), goal, RaycastContext.ShapeType.COLLIDER, RaycastContext.FluidHandling.ANY, mc.player));
                if (!moveThroughBlocks.get() && hit.isInsideBlock()) {
                    delayWaited = (int) (delay.get() - 1);
                    break;
                }
                mc.player.updatePosition(goal.x, goal.y, goal.z);
            } else {
                delayWaited = (int) (delay.get() - 1);
            }
            break;
        case Switch:
            Vec3d diff = entityPos.subtract(playerPos);
            Vec3d diff1 = new Vec3d(Utils.clamp(diff.x, -halfRange, halfRange), Utils.clamp(diff.y, -halfRange, halfRange), Utils.clamp(diff.z, -halfRange, halfRange));
            Vec3d goal2 = entityPos.add(diff1);
            hit = mc.world.raycast(new RaycastContext(mc.player.getPos(), goal2, RaycastContext.ShapeType.COLLIDER, RaycastContext.FluidHandling.ANY, mc.player));
            if (!moveThroughBlocks.get() && hit.isInsideBlock()) {
                delayWaited = (int) (delay.get() - 1);
                break;
            }
            mc.player.updatePosition(goal2.x, goal2.y, goal2.z);
            break;
        case Circle:
            delay.set(0);
            circleProgress += circleSpeed.get();
            if (circleProgress > 360)
                circleProgress -= 360;
            double rad = Math.toRadians(circleProgress);
            double sin = Math.sin(rad) * 3;
            double cos = Math.cos(rad) * 3;
            Vec3d current = new Vec3d(entityPos.x + sin, playerPos.y, entityPos.z + cos);
            hit = mc.world.raycast(new RaycastContext(mc.player.getPos(), current, RaycastContext.ShapeType.COLLIDER, RaycastContext.FluidHandling.ANY, mc.player));
            if (!moveThroughBlocks.get() && hit.isInsideBlock())
                break;
            mc.player.updatePosition(current.x, current.y, current.z);
            break;
    }
}
Also used : Random(java.util.Random) RaycastContext(net.minecraft.world.RaycastContext) BlockPos(net.minecraft.util.math.BlockPos) BlockHitResult(net.minecraft.util.hit.BlockHitResult) Vec3d(net.minecraft.util.math.Vec3d) EventHandler(meteordevelopment.orbit.EventHandler)

Example 4 with BlockHitResult

use of net.minecraft.util.hit.BlockHitResult in project meteor-rejects by AntiCope.

the class AutoTNT method ignite.

private void ignite(BlockPos pos, FindItemResult item) {
    InvUtils.swap(item.slot(), true);
    mc.interactionManager.interactBlock(mc.player, mc.world, Hand.MAIN_HAND, new BlockHitResult(new Vec3d(pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5), Direction.UP, pos, true));
    InvUtils.swapBack();
}
Also used : BlockHitResult(net.minecraft.util.hit.BlockHitResult) Vec3d(net.minecraft.util.math.Vec3d)

Example 5 with BlockHitResult

use of net.minecraft.util.hit.BlockHitResult in project BlockMeter by ModProg.

the class BlockMeterClient method onInitializeClient.

@Override
public void onInitializeClient() {
    final KeyBinding keyBinding = new KeyBinding("key.blockmeter.assign", InputUtil.Type.KEYSYM, GLFW.GLFW_KEY_M, "category.blockmeter.key");
    final KeyBinding keyBindingMenu = new KeyBinding("key.blockmeter.menu", InputUtil.Type.KEYSYM, GLFW.GLFW_KEY_LEFT_ALT, "category.blockmeter.key");
    KeyBindingHelper.registerKeyBinding(keyBinding);
    KeyBindingHelper.registerKeyBinding(keyBindingMenu);
    // This is ugly I know, but I did not find something better
    // (Issue in AutoConfig https://github.com/shedaniel/AutoConfig/issues/13)
    confMgr = (ConfigManager<ModConfig>) AutoConfig.register(ModConfig.class, Toml4jConfigSerializer::new);
    ClientTickEvents.START_CLIENT_TICK.register(e -> {
        if (keyBinding.wasPressed()) {
            if (Screen.hasShiftDown()) {
                if (undo())
                    e.player.sendMessage(new TranslatableText("blockmeter.clearLast"), true);
            } else if (Screen.hasControlDown()) {
                if (clear())
                    e.player.sendMessage(new TranslatableText("blockmeter.clearAll"), true);
            } else if (this.active) {
                disable();
                e.player.sendMessage(new TranslatableText("blockmeter.toggle.off", new Object[0]), true);
            } else {
                active = true;
                ItemStack itemStack = e.player.getMainHandStack();
                currentItem = itemStack.getItem();
                e.player.sendMessage(new TranslatableText("blockmeter.toggle.on", new Object[] { new TranslatableText(itemStack.getTranslationKey(), new Object[0]) }), true);
            }
        }
        if (keyBindingMenu.wasPressed() && active && MinecraftClient.getInstance().player.getMainHandStack().getItem() == this.currentItem) {
            MinecraftClient.getInstance().setScreen((Screen) this.quickMenu);
        }
        // Updates Selection preview
        if (this.active && this.boxes.size() > 0) {
            final ClientMeasureBox currentBox = getCurrentBox();
            if (currentBox != null) {
                final HitResult rayHit = e.player.raycast((double) e.interactionManager.getReachDistance(), 1.0f, false);
                if (rayHit.getType() == HitResult.Type.BLOCK) {
                    final BlockHitResult blockHitResult = (BlockHitResult) rayHit;
                    currentBox.setBlockEnd(new BlockPos(blockHitResult.getBlockPos()));
                }
            }
        }
    });
    UseBlockCallback.EVENT.register((playerEntity, world, hand, hitResult) -> this.onBlockMeterClick(playerEntity, hitResult));
}
Also used : Toml4jConfigSerializer(me.shedaniel.autoconfig.serializer.Toml4jConfigSerializer) TranslatableText(net.minecraft.text.TranslatableText) BlockHitResult(net.minecraft.util.hit.BlockHitResult) HitResult(net.minecraft.util.hit.HitResult) KeyBinding(net.minecraft.client.option.KeyBinding) ClientMeasureBox(win.baruna.blockmeter.measurebox.ClientMeasureBox) BlockPos(net.minecraft.util.math.BlockPos) ItemStack(net.minecraft.item.ItemStack) BlockHitResult(net.minecraft.util.hit.BlockHitResult)

Aggregations

BlockHitResult (net.minecraft.util.hit.BlockHitResult)83 BlockPos (net.minecraft.util.math.BlockPos)45 Vec3d (net.minecraft.util.math.Vec3d)36 Direction (net.minecraft.util.math.Direction)20 Hand (net.minecraft.util.Hand)17 BlockState (net.minecraft.block.BlockState)15 HitResult (net.minecraft.util.hit.HitResult)14 RaycastContext (net.minecraft.world.RaycastContext)13 BlockEntity (net.minecraft.block.entity.BlockEntity)12 ItemStack (net.minecraft.item.ItemStack)11 PlayerInteractBlockC2SPacket (net.minecraft.network.packet.c2s.play.PlayerInteractBlockC2SPacket)11 PlayerEntity (net.minecraft.entity.player.PlayerEntity)10 Box (net.minecraft.util.math.Box)10 PlayerMoveC2SPacket (net.minecraft.network.packet.c2s.play.PlayerMoveC2SPacket)9 BleachSubscribe (org.bleachhack.eventbus.BleachSubscribe)9 List (java.util.List)8 EventHandler (meteordevelopment.orbit.EventHandler)8 Entity (net.minecraft.entity.Entity)8 World (net.minecraft.world.World)6 ArrayList (java.util.ArrayList)5