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;
}
}
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;
}
}
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;
}
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();
}
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();
}
}
Aggregations