Search in sources :

Example 1 with HitResult

use of net.minecraft.util.hit.HitResult 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 2 with HitResult

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

Example 3 with HitResult

use of net.minecraft.util.hit.HitResult in project FallingAttackFabric by hamusuke0323.

the class FallingAttackShockWave method getEntitiesStruckByShockWave.

public List<LivingEntity> getEntitiesStruckByShockWave() {
    return this.world.getEntitiesByClass(LivingEntity.class, this.box, livingEntity -> {
        double d = distanceTo2D(livingEntity.getPos(), this.pos);
        boolean flag = !this.exceptEntities.contains(livingEntity) && !livingEntity.isSpectator() && livingEntity != this.owner && d >= this.secondary.getRadius() && this.primary.getRadius() >= d;
        for (int i = 0; i < 2 && flag; i++) {
            Vec3d vec3d = new Vec3d(livingEntity.getX(), livingEntity.getBodyY(0.5D * (double) i), livingEntity.getZ());
            HitResult hitResult = this.world.raycast(new RaycastContext(this.pos, vec3d, RaycastContext.ShapeType.COLLIDER, RaycastContext.FluidHandling.NONE, this.owner));
            if (hitResult.getType() == HitResult.Type.MISS) {
                return true;
            }
        }
        return false;
    });
}
Also used : HitResult(net.minecraft.util.hit.HitResult) RaycastContext(net.minecraft.world.RaycastContext) Vec3d(net.minecraft.util.math.Vec3d)

Example 4 with HitResult

use of net.minecraft.util.hit.HitResult in project CustomHUD by Minenash.

the class ComplexData method update.

@SuppressWarnings("ConstantConditions")
public static void update(Profile profile) {
    if (profile.enabled.serverWorld) {
        IntegratedServer integratedServer = client.getServer();
        serverWorld = integratedServer != null ? integratedServer.getWorld(client.world.getRegistryKey()) : null;
    }
    if (profile.enabled.clientChunk) {
        ChunkPos newPos = new ChunkPos(client.getCameraEntity().getBlockPos());
        if (!Objects.equals(ComplexData.pos, newPos)) {
            pos = newPos;
            chunkFuture = null;
            clientChunk = null;
        }
        if (clientChunk == null)
            clientChunk = client.world.getChunk(pos.x, pos.z);
    }
    if (profile.enabled.serverChunk) {
        if (chunkFuture == null) {
            if (serverWorld != null)
                chunkFuture = serverWorld.getChunkManager().getChunkFutureSyncOnMainThread(pos.x, pos.z, ChunkStatus.FULL, false).thenApply((either) -> either.map((chunk) -> (WorldChunk) chunk, (unloaded) -> null));
            if (chunkFuture == null)
                chunkFuture = CompletableFuture.completedFuture(clientChunk);
        }
        serverChunk = chunkFuture.getNow(null);
    }
    if (profile.enabled.targetBlock) {
        HitResult hit = client.cameraEntity.raycast(profile.targetDistance, 0.0F, false);
        targetBlockPos = hit.getType() == HitResult.Type.BLOCK ? ((BlockHitResult) hit).getBlockPos() : null;
    }
    if (profile.enabled.world)
        world = DataFixUtils.orElse(Optional.ofNullable(client.getServer()).flatMap((integratedServer) -> Optional.ofNullable(integratedServer.getWorld(client.world.getRegistryKey()))), client.world);
    if (profile.enabled.localDifficulty)
        localDifficulty = new LocalDifficulty(world.getDifficulty(), world.getTimeOfDay(), serverChunk == null ? 0 : serverChunk.getInhabitedTime(), world.getMoonSize());
    if (profile.enabled.sound)
        sounds = client.getSoundManager().getDebugString().substring(8).replace(" + ", "/").split("/");
    if (profile.enabled.clientChunkCache)
        clientChunkCache = client.worldRenderer.getChunksDebugString().substring(20).split(", ");
    if (profile.enabled.time) {
        timeOfDay = (int) ((client.world.getTimeOfDay() + 6000) % 24000);
    }
    if (profile.enabled.velocity) {
        if (velocityWaitCounter > 0) {
            velocityWaitCounter--;
            return;
        }
        velocityWaitCounter = 4;
        ClientPlayerEntity p = client.player;
        final double changeXZ = Math.sqrt(Math.pow(Math.abs(p.getX() - x1), 2) + Math.pow(Math.abs(p.getZ() - z1), 2));
        final double changeY = Math.abs(p.getY() - y1);
        final double changeXYZ = Math.sqrt(changeXZ * changeXZ + changeY * changeY);
        x1 = p.getX();
        y1 = p.getY();
        z1 = p.getZ();
        velocityXZ = ((int) (changeXZ * 40)) / 10.0;
        velocityY = ((int) (changeY * 40)) / 10.0;
        velocityXYZ = ((int) (changeXYZ * 40)) / 10.0;
    }
}
Also used : World(net.minecraft.world.World) ServerWorld(net.minecraft.server.world.ServerWorld) BlockHitResult(net.minecraft.util.hit.BlockHitResult) ChunkPos(net.minecraft.util.math.ChunkPos) BlockPos(net.minecraft.util.math.BlockPos) CompletableFuture(java.util.concurrent.CompletableFuture) DataFixUtils(com.mojang.datafixers.DataFixUtils) WorldChunk(net.minecraft.world.chunk.WorldChunk) HitResult(net.minecraft.util.hit.HitResult) Objects(java.util.Objects) IntegratedServer(net.minecraft.server.integrated.IntegratedServer) ChunkStatus(net.minecraft.world.chunk.ChunkStatus) Optional(java.util.Optional) MinecraftClient(net.minecraft.client.MinecraftClient) ClientPlayerEntity(net.minecraft.client.network.ClientPlayerEntity) LocalDifficulty(net.minecraft.world.LocalDifficulty) BlockHitResult(net.minecraft.util.hit.BlockHitResult) HitResult(net.minecraft.util.hit.HitResult) IntegratedServer(net.minecraft.server.integrated.IntegratedServer) LocalDifficulty(net.minecraft.world.LocalDifficulty) WorldChunk(net.minecraft.world.chunk.WorldChunk) ChunkPos(net.minecraft.util.math.ChunkPos) BlockHitResult(net.minecraft.util.hit.BlockHitResult) ClientPlayerEntity(net.minecraft.client.network.ClientPlayerEntity)

Example 5 with HitResult

use of net.minecraft.util.hit.HitResult in project BleachHack by BleachDrinker420.

the class CmdNBT method getNbt.

private NbtCompound getNbt(String arg) {
    if (arg.equalsIgnoreCase("hand")) {
        return mc.player.getMainHandStack().getOrCreateNbt();
    } else if (arg.equalsIgnoreCase("block")) {
        HitResult target = mc.crosshairTarget;
        if (target.getType() == HitResult.Type.BLOCK) {
            BlockPos pos = ((BlockHitResult) target).getBlockPos();
            BlockEntity be = mc.world.getBlockEntity(pos);
            if (be != null) {
                return be.writeNbt(new NbtCompound());
            } else {
                return new NbtCompound();
            }
        }
        BleachLogger.error("Not looking at a block.");
        return null;
    } else if (arg.equalsIgnoreCase("entity")) {
        HitResult target = mc.crosshairTarget;
        if (target.getType() == HitResult.Type.ENTITY) {
            return ((EntityHitResult) target).getEntity().writeNbt(new NbtCompound());
        }
        BleachLogger.error("Not looking at an entity.");
        return null;
    }
    throw new CmdSyntaxException();
}
Also used : BlockHitResult(net.minecraft.util.hit.BlockHitResult) HitResult(net.minecraft.util.hit.HitResult) EntityHitResult(net.minecraft.util.hit.EntityHitResult) NbtCompound(net.minecraft.nbt.NbtCompound) CmdSyntaxException(org.bleachhack.command.exception.CmdSyntaxException) BlockPos(net.minecraft.util.math.BlockPos) BlockEntity(net.minecraft.block.entity.BlockEntity)

Aggregations

HitResult (net.minecraft.util.hit.HitResult)15 BlockPos (net.minecraft.util.math.BlockPos)10 BlockHitResult (net.minecraft.util.hit.BlockHitResult)9 PlayerEntity (net.minecraft.entity.player.PlayerEntity)5 ItemStack (net.minecraft.item.ItemStack)5 EntityHitResult (net.minecraft.util.hit.EntityHitResult)5 Entity (net.minecraft.entity.Entity)4 Vec3d (net.minecraft.util.math.Vec3d)4 BlockState (net.minecraft.block.BlockState)3 MinecraftClient (net.minecraft.client.MinecraftClient)3 Box (net.minecraft.util.math.Box)3 EventTarget (dev.hypnotic.event.EventTarget)2 Iterator (java.util.Iterator)2 BlockEntity (net.minecraft.block.entity.BlockEntity)2 LiteralText (net.minecraft.text.LiteralText)2 Direction (net.minecraft.util.math.Direction)2 VoxelShape (net.minecraft.util.shape.VoxelShape)2 World (net.minecraft.world.World)2 IOffhandAttack (chronosacaria.mcdw.api.interfaces.IOffhandAttack)1 DataFixUtils (com.mojang.datafixers.DataFixUtils)1