Search in sources :

Example 41 with ClientPlayerEntity

use of net.minecraft.client.network.ClientPlayerEntity in project AutoHUD by Crendgrim.

the class Hud method tick.

public static void tick() {
    ClientPlayerEntity player = MinecraftClient.getInstance().player;
    if (player != null) {
        if (state == null) {
            state = new State(player);
            wasPeeking = false;
        }
        state.tick(player);
    } else {
        state = null;
    }
}
Also used : ClientPlayerEntity(net.minecraft.client.network.ClientPlayerEntity)

Example 42 with ClientPlayerEntity

use of net.minecraft.client.network.ClientPlayerEntity in project libr-getter by gXLg.

the class Worker method tick.

public static void tick() {
    if (state == State.STANDBY)
        return;
    if (block == null || villager == null) {
        state = State.STANDBY;
        return;
    }
    if (state == State.START) {
        counter++;
        MinecraftClient client = MinecraftClient.getInstance();
        ClientPlayerEntity player = client.player;
        if (player == null) {
            source.sendFeedback(new LiteralText("InternalError: player == null").formatted(Formatting.RED));
            state = State.STANDBY;
            return;
        }
        PlayerInventory inventory = player.inventory;
        if (inventory == null) {
            source.sendFeedback(new LiteralText("InternalError: inventory == null").formatted(Formatting.RED));
            state = State.STANDBY;
            return;
        }
        int slot = -1;
        float max = -1;
        for (int i = 0; i < inventory.main.size(); i++) {
            ItemStack stack = inventory.getStack(i);
            float f = stack.getMiningSpeedMultiplier(Blocks.LECTERN.getDefaultState());
            int ef = EnchantmentHelper.getLevel(Enchantments.EFFICIENCY, stack);
            f += (float) (ef * ef + 1);
            if (f > max) {
                max = f;
                slot = i;
            }
        }
        ClientPlayerInteractionManager manager = client.interactionManager;
        if (manager == null) {
            source.sendFeedback(new LiteralText("InternalError: manager == null").formatted(Formatting.RED));
            state = State.STANDBY;
            return;
        }
        ClientPlayNetworkHandler handler = client.getNetworkHandler();
        if (handler == null) {
            source.sendFeedback(new LiteralText("InternalError: handler == null").formatted(Formatting.RED));
            state = State.STANDBY;
            return;
        }
        if (slot != -1) {
            if (PlayerInventory.isValidHotbarIndex(slot))
                inventory.selectedSlot = slot;
            else
                manager.pickFromInventory(slot);
            UpdateSelectedSlotC2SPacket packetSelect = new UpdateSelectedSlotC2SPacket(inventory.selectedSlot);
            handler.sendPacket(packetSelect);
        }
        state = State.BREAK;
    } else if (state == State.BREAK) {
        MinecraftClient client = MinecraftClient.getInstance();
        ClientWorld world = client.world;
        if (world == null) {
            source.sendFeedback(new LiteralText("InternalError: world == null").formatted(Formatting.RED));
            state = State.STANDBY;
            return;
        }
        BlockState targetBlock = world.getBlockState(block);
        if (targetBlock.isAir()) {
            state = State.PLACE;
            return;
        }
        ClientPlayerInteractionManager manager = client.interactionManager;
        if (manager == null) {
            source.sendFeedback(new LiteralText("InternalError: manager == null").formatted(Formatting.RED));
            state = State.STANDBY;
            return;
        }
        manager.updateBlockBreakingProgress(block, Direction.UP);
    } else if (state == State.PLACE) {
        MinecraftClient client = MinecraftClient.getInstance();
        ClientPlayerEntity player = client.player;
        if (player == null) {
            source.sendFeedback(new LiteralText("InternalError: player == null").formatted(Formatting.RED));
            state = State.STANDBY;
            return;
        }
        PlayerInventory inventory = player.inventory;
        if (inventory == null) {
            source.sendFeedback(new LiteralText("InternalError: inventory == null").formatted(Formatting.RED));
            state = State.STANDBY;
            return;
        }
        int slot = inventory.getSlotWithStack(new ItemStack(Items.LECTERN));
        if (slot == -1)
            return;
        ClientPlayerInteractionManager manager = client.interactionManager;
        if (manager == null) {
            source.sendFeedback(new LiteralText("InternalError: manager == null").formatted(Formatting.RED));
            state = State.STANDBY;
            return;
        }
        ClientPlayNetworkHandler handler = client.getNetworkHandler();
        if (handler == null) {
            source.sendFeedback(new LiteralText("InternalError: handler == null").formatted(Formatting.RED));
            state = State.STANDBY;
            return;
        }
        if (PlayerInventory.isValidHotbarIndex(slot))
            inventory.selectedSlot = slot;
        else
            manager.pickFromInventory(slot);
        UpdateSelectedSlotC2SPacket packetSelect = new UpdateSelectedSlotC2SPacket(inventory.selectedSlot);
        handler.sendPacket(packetSelect);
        Vec3d lowBlockPos = new Vec3d(block.getX(), block.getY() - 1, block.getZ());
        BlockHitResult lowBlock = new BlockHitResult(lowBlockPos, Direction.UP, block, false);
        PlayerInteractBlockC2SPacket packetSet = new PlayerInteractBlockC2SPacket(Hand.MAIN_HAND, lowBlock);
        handler.sendPacket(packetSet);
        state = State.GET;
    } else if (state == State.GET) {
        if (villager.getVillagerData().getProfession() == VillagerProfession.NONE)
            return;
        MinecraftClient client = MinecraftClient.getInstance();
        ClientPlayNetworkHandler handler = client.getNetworkHandler();
        if (handler == null) {
            source.sendFeedback(new LiteralText("InternalError: handler == null").formatted(Formatting.RED));
            state = State.STANDBY;
            return;
        }
        PlayerInteractEntityC2SPacket packet = new PlayerInteractEntityC2SPacket(villager, Hand.MAIN_HAND, false);
        handler.sendPacket(packet);
        trades = null;
        state = State.GETTING;
    } else if (state == State.GETTING) {
        if (trades == null)
            return;
        int trade;
        if (trades.get(0).getSellItem().getItem() == Items.ENCHANTED_BOOK)
            trade = 0;
        else if (trades.get(1).getSellItem().getItem() == Items.ENCHANTED_BOOK)
            trade = 1;
        else
            trade = -1;
        String enchant;
        if (trade != -1) {
            NbtCompound tag = trades.get(trade).getSellItem().getTag();
            if (tag == null) {
                source.sendFeedback(new LiteralText("InternalError: tag == null").formatted(Formatting.RED));
                state = State.STANDBY;
                return;
            }
            NbtCompound element = (NbtCompound) tag.getList("StoredEnchantments", 10).get(0);
            NbtElement id = element.get("id");
            NbtElement lvl = element.get("lvl");
            if (id == null || lvl == null) {
                source.sendFeedback(new LiteralText("InternalError: tag == null").formatted(Formatting.RED));
                state = State.STANDBY;
                return;
            }
            enchant = id.asString() + "_" + lvl.asString();
        } else
            enchant = "none";
        source.sendFeedback(new LiteralText("Enchantment offered: " + enchant));
        if (looking.equals(enchant)) {
            source.sendFeedback(new LiteralText("Successfully found after: " + counter + " tries").formatted(Formatting.GREEN));
            state = State.STANDBY;
        } else
            state = State.START;
    }
}
Also used : ClientPlayerInteractionManager(net.minecraft.client.network.ClientPlayerInteractionManager) NbtCompound(net.minecraft.nbt.NbtCompound) PlayerInventory(net.minecraft.entity.player.PlayerInventory) NbtElement(net.minecraft.nbt.NbtElement) PlayerInteractEntityC2SPacket(net.minecraft.network.packet.c2s.play.PlayerInteractEntityC2SPacket) Vec3d(net.minecraft.util.math.Vec3d) BlockState(net.minecraft.block.BlockState) MinecraftClient(net.minecraft.client.MinecraftClient) UpdateSelectedSlotC2SPacket(net.minecraft.network.packet.c2s.play.UpdateSelectedSlotC2SPacket) ClientWorld(net.minecraft.client.world.ClientWorld) ClientPlayerEntity(net.minecraft.client.network.ClientPlayerEntity) ItemStack(net.minecraft.item.ItemStack) BlockHitResult(net.minecraft.util.hit.BlockHitResult) ClientPlayNetworkHandler(net.minecraft.client.network.ClientPlayNetworkHandler) LiteralText(net.minecraft.text.LiteralText) PlayerInteractBlockC2SPacket(net.minecraft.network.packet.c2s.play.PlayerInteractBlockC2SPacket)

Example 43 with ClientPlayerEntity

use of net.minecraft.client.network.ClientPlayerEntity in project libr-getter by gXLg.

the class LibrGetCommand method runSelector.

private static int runSelector(CommandContext<FabricClientCommandSource> context) {
    if (Worker.getState() != Worker.State.STANDBY) {
        context.getSource().sendFeedback(new LiteralText("LibrGetter is running!").formatted(Formatting.RED));
        return 1;
    }
    MinecraftClient client = MinecraftClient.getInstance();
    ClientWorld world = client.world;
    if (world == null) {
        context.getSource().sendFeedback(new LiteralText("InternalError: world == null").formatted(Formatting.RED));
        return 1;
    }
    ClientPlayerEntity player = client.player;
    if (player == null) {
        context.getSource().sendFeedback(new LiteralText("InternalError: player == null").formatted(Formatting.RED));
        return 1;
    }
    HitResult hit = client.crosshairTarget;
    if (hit == null) {
        context.getSource().sendFeedback(new LiteralText("InternalError: hit == null").formatted(Formatting.RED));
        return 1;
    }
    HitResult.Type hitType = hit.getType();
    if (hitType == HitResult.Type.MISS) {
        context.getSource().sendFeedback(new LiteralText("You are not targeting anything!").formatted(Formatting.RED));
        return 1;
    }
    if (hitType == HitResult.Type.BLOCK) {
        BlockPos blockPos = ((BlockHitResult) hit).getBlockPos();
        if (!world.getBlockState(blockPos).isOf(Blocks.LECTERN)) {
            context.getSource().sendFeedback(new LiteralText("Block is not a lectern!").formatted(Formatting.RED));
            return 1;
        }
        Worker.setBlock(blockPos);
        context.getSource().sendFeedback(new LiteralText("Block selected"));
    } else if (hitType == HitResult.Type.ENTITY) {
        EntityHitResult entityHitResult = (EntityHitResult) hit;
        Entity entity = entityHitResult.getEntity();
        if (!(entity instanceof MerchantEntity)) {
            context.getSource().sendFeedback(new LiteralText("Entity is not a villager!").formatted(Formatting.RED));
            return 1;
        }
        VillagerEntity villager = (VillagerEntity) entity;
        if (villager.getVillagerData().getProfession() != VillagerProfession.LIBRARIAN) {
            context.getSource().sendFeedback(new LiteralText("Villager is not a librarian!").formatted(Formatting.RED));
            return 1;
        }
        context.getSource().sendFeedback(new LiteralText("Villager selected"));
        Worker.setVillager(villager);
    }
    return 0;
}
Also used : BlockHitResult(net.minecraft.util.hit.BlockHitResult) HitResult(net.minecraft.util.hit.HitResult) EntityHitResult(net.minecraft.util.hit.EntityHitResult) VillagerEntity(net.minecraft.entity.passive.VillagerEntity) MerchantEntity(net.minecraft.entity.passive.MerchantEntity) Entity(net.minecraft.entity.Entity) VillagerEntity(net.minecraft.entity.passive.VillagerEntity) ClientPlayerEntity(net.minecraft.client.network.ClientPlayerEntity) MerchantEntity(net.minecraft.entity.passive.MerchantEntity) MinecraftClient(net.minecraft.client.MinecraftClient) BlockPos(net.minecraft.util.math.BlockPos) ClientWorld(net.minecraft.client.world.ClientWorld) ClientPlayerEntity(net.minecraft.client.network.ClientPlayerEntity) BlockHitResult(net.minecraft.util.hit.BlockHitResult) EntityHitResult(net.minecraft.util.hit.EntityHitResult) LiteralText(net.minecraft.text.LiteralText)

Example 44 with ClientPlayerEntity

use of net.minecraft.client.network.ClientPlayerEntity in project thorium by PotassiumMC.

the class MinecraftClientMixin method handleInputEventsOnInventoryOpened.

@Redirect(method = "handleInputEvents()V", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/tutorial/TutorialManager;onInventoryOpened()V"))
private void handleInputEventsOnInventoryOpened(TutorialManager instance) {
    ClientPlayerEntity me = ((MinecraftClient) (Object) this).player;
    // Don't call the 'event' if we're in a nether portal.
    if (((EntityAccessor) me).inNetherPortal())
        return;
    instance.onInventoryOpened();
}
Also used : EntityAccessor(io.github.potassiummc.thorium.mixin.access.EntityAccessor) MinecraftClient(net.minecraft.client.MinecraftClient) ClientPlayerEntity(net.minecraft.client.network.ClientPlayerEntity) Redirect(org.spongepowered.asm.mixin.injection.Redirect)

Example 45 with ClientPlayerEntity

use of net.minecraft.client.network.ClientPlayerEntity in project BigRat by ZimnyCat.

the class MixinNoToolCooldown method beginRenderTick.

@Inject(at = @At("HEAD"), method = "beginRenderTick", cancellable = true)
public void beginRenderTick(long timeMillis, CallbackInfoReturnable<Integer> ci) {
    Module ntc = ModuleManager.getModule(NoToolCooldown.class);
    MinecraftClient mc = MinecraftClient.getInstance();
    ClientPlayerEntity player = mc == null ? null : mc.player;
    if (player != null && player.handSwinging && ntc != null && ntc.isToggled()) {
        this.lastFrameDuration = (float) (((timeMillis - this.prevTimeMillis) / this.tickTime) * ModuleManager.getModule(NoToolCooldown.class).getSetting(0).asSlider().getValue());
        this.prevTimeMillis = timeMillis;
        this.tickDelta += this.lastFrameDuration;
        int i = (int) this.tickDelta;
        this.tickDelta -= i;
        ci.setReturnValue(i);
        ci.cancel();
    }
}
Also used : MinecraftClient(net.minecraft.client.MinecraftClient) Module(bleach.hack.module.Module) ClientPlayerEntity(net.minecraft.client.network.ClientPlayerEntity) NoToolCooldown(bleach.hack.module.mods.NoToolCooldown) Inject(org.spongepowered.asm.mixin.injection.Inject)

Aggregations

ClientPlayerEntity (net.minecraft.client.network.ClientPlayerEntity)134 ItemStack (net.minecraft.item.ItemStack)20 Vec3d (net.minecraft.util.math.Vec3d)20 MinecraftClient (net.minecraft.client.MinecraftClient)16 Entity (net.minecraft.entity.Entity)16 BlockPos (net.minecraft.util.math.BlockPos)14 Inject (org.spongepowered.asm.mixin.injection.Inject)14 ClientWorld (net.minecraft.client.world.ClientWorld)13 LivingEntity (net.minecraft.entity.LivingEntity)13 PlayerEntity (net.minecraft.entity.player.PlayerEntity)11 Stream (java.util.stream.Stream)10 Identifier (net.minecraft.util.Identifier)10 AnimalEntity (net.minecraft.entity.passive.AnimalEntity)9 PlayerInventory (net.minecraft.entity.player.PlayerInventory)9 LiteralArgumentBuilder (com.mojang.brigadier.builder.LiteralArgumentBuilder)8 ArrayList (java.util.ArrayList)8 AmbientEntity (net.minecraft.entity.mob.AmbientEntity)8 WaterCreatureEntity (net.minecraft.entity.mob.WaterCreatureEntity)8 PlayerUtils (at.haha007.edenclient.utils.PlayerUtils)7 ConfigSubscriber (at.haha007.edenclient.utils.config.ConfigSubscriber)7