GabrielSnow Posted February 25, 2023 Posted February 25, 2023 So I've been making a Minecraft bot because I want to get into AI and because I'm a bored student and I can't figure out how to make the player hold down left click, I've seen many people use KeyBind or minecraft.player.gameSettings but I figured that that doesn't work anymore because it's only in older versions(I think), I can't make the imports work (net.minecraft.client.settings). So far I figured out how to do it with the Baritone API using a loop but it's very CPU intensive, adding a delay makes it not work. while(true) { BaritoneAPI.getProvider().getPrimaryBaritone().getInputOverrideHandler().setInputForceState(baritone.api.utils.input.Input.CLICK_LEFT, true); } Quote
perromercenary00 Posted February 26, 2023 Posted February 26, 2023 yeah that something im also interested but will try to avoid packages and complex things let say make a capability whit some values like int action = 0; long start = 0L; Reveal hidden contents package merctool.item.tool; import net.minecraft.core.NonNullList; import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.ListTag; import net.minecraft.nbt.Tag; import net.minecraft.world.item.ItemStack; import net.minecraftforge.common.capabilities.ForgeCapabilities; import net.minecraftforge.items.ItemStackHandler; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; /* helditem.getCapability(ForgeCapabilities.ITEM_HANDLER).ifPresent(handler00 -> { item_handler ih = (item_handler)handler00; System.out.println(warudo.isClientSide + " ih.fuel => " + ih.fuel ); }); */ public class item_handler extends ItemStackHandler { public ItemStack container = null; public float fuel = 0; public int munition = 0; public int type = 0; public long start = 0; public int action = 0; public int tick = 0; public int limit = 1200; public item_handler(ItemStack container) { super(0); this.container = container; } public void print(String mensaje) { System.out.println("\n" + mensaje); System.out.println("this.fuel = " + this.fuel); System.out.println("this.munition = " + this.munition); System.out.println("this.type = " + this.type); System.out.println("this.start = " + this.start); System.out.println("this.action = " + this.action); System.out.println("this.tick = " + this.tick); System.out.println("this.limit = " + this.limit); System.out.println("\n"); } @Override public int getSlotLimit(int slot) { return 64; } @Override public boolean isItemValid(int slot, @NotNull ItemStack stack) { if (stack == null || stack.isEmpty()) // || stack.getItem() instanceof BasketBlockItem { return false; } else { return super.isItemValid(slot, stack); } } @Override public void setStackInSlot(int slot, @NotNull ItemStack stack) { //// System.out.println("setStackInSlot(" + slot + ")"); validateSlotIndex(slot); this.stacks.set(slot, stack); onContentsChanged(slot); if (this.container != null) { // write_item_to_slot(this.container, slot, stack); } } // ########## ########## ########## ########## // @Override public static NonNullList<ItemStack> read_items_from(ItemStack itemstack) { NonNullList<ItemStack> contained_items = NonNullList.withSize(9, ItemStack.EMPTY);// this.getContainerSize() if (itemstack.hasTag()) { CompoundTag compoundtag = itemstack.getTag(); ListTag listtag = null; int size = 0; if (compoundtag.contains("Items")) { // ListTag listtag = new ListTag(); listtag = compoundtag.getList("Items", 10); size = listtag.size(); // contained_items = NonNullList.withSize(size, ItemStack.EMPTY); for (int i = 0; i < listtag.size(); ++i) { CompoundTag itemstacktag = listtag.getCompound(i); int j = compoundtag.getByte("Slot") & 255; if (j >= 0 && j < contained_items.size()) { contained_items.set(j, ItemStack.of(itemstacktag)); } } } } return contained_items; } // ########## ########## ########## ########## // @Override public void write_item_to_slot(ItemStack container, int slot, @NotNull ItemStack stack) { // , NonNullList<ItemStack> contained_items CompoundTag compoundtag = null; if (container.hasTag()) { compoundtag = container.getTag(); } else { compoundtag = new CompoundTag(); } ListTag listtag = null; if (compoundtag.contains("Items")) { listtag = compoundtag.getList("Items", 10); } else { listtag = new ListTag(); } CompoundTag itemstacktag = null; if (slot < listtag.size()) { itemstacktag = listtag.getCompound(slot); } else { itemstacktag = new CompoundTag(); } itemstacktag.putByte("Slot", (byte) slot); stack.save(itemstacktag); listtag.add(itemstacktag); // aqui tengi una duda, se sobreescrive o crea otra ?? compoundtag.put("Items", listtag); container.setTag(compoundtag); } @Override public CompoundTag serializeNBT() { ListTag nbtTagList = new ListTag(); for (int i = 0; i < stacks.size(); i++) { if (!stacks.get(i).isEmpty()) { CompoundTag itemTag = new CompoundTag(); itemTag.putInt("Slot", i); stacks.get(i).save(itemTag); nbtTagList.add(itemTag); } } CompoundTag nbt = new CompoundTag(); nbt.put("Items", nbtTagList); nbt.putInt("Size", stacks.size()); nbt.putInt("munition", this.munition); nbt.putInt("type", this.type); nbt.putFloat("fuel", this.fuel); nbt.putLong("start", this.start); nbt.putShort("action", (short) this.action); nbt.putShort("limit", (short) this.limit); this.tick = 0; //print("serializeNBT()"); onSave(); return nbt; } @Override public void deserializeNBT(CompoundTag nbt) { setSize(nbt.contains("Size", Tag.TAG_INT) ? nbt.getInt("Size") : stacks.size()); ListTag tagList = nbt.getList("Items", Tag.TAG_COMPOUND); for (int i = 0; i < tagList.size(); i++) { CompoundTag itemTags = tagList.getCompound(i); int slot = itemTags.getInt("Slot"); if (slot >= 0 && slot < stacks.size()) { stacks.set(slot, ItemStack.of(itemTags)); } } this.munition = nbt.getInt("munition"); this.fuel = nbt.getFloat("fuel"); this.type = nbt.getInt("type"); this.limit = nbt.getShort("limit"); this.start = nbt.getLong("start"); this.action = nbt.getShort("action"); //System.out.println( "DeserializeNBT()" ); //print("DeserializeNBT()"); onLoad(); } //@Override protected void onSave() { //System.out.println("item_handler __ onSave() "); if(this.action > 0) { //this.tick = get_tick(); if( this.action > 0) { if( this.start > 0L ) { //System.out.println( "Calcular_tick()\n" ); this.tick = (int) ((System.currentTimeMillis() - this.start) / 50); // 50 this.tick = (this.tick > this.limit)? this.limit : this.tick; } } } //System.out.println("item_handler __ onSave() " + this.tick ); } @Override protected void onLoad() { //System.out.println("item_handler __ onLoad() "); if(this.action > 0) { //this.tick = get_tick(); if( this.action > 0) { if( this.start > 0L ) { //System.out.println( "Calcular_tick()\n" ); this.tick = (int) ((System.currentTimeMillis() - this.start) / 50); // 50 this.tick = (this.tick > this.limit)? this.limit : this.tick; } } } //System.out.println("item_handler __ onLoad() " + this.tick ); } public void start(int action) { if ( this.action != action ) { this.action = action; this.start = System.currentTimeMillis(); // 50 this.tick = 0; } } public void stop() { this.action = 0; this.start = 0; // 50 this.tick = 0; this.limit = 1200; } public int get_tick() { /* if( this.tick > 0) { } else if( this.action > 0) { if( this.start > 0L ) { //System.out.println( "Calcular_tick()\n" ); this.tick = (int) ((System.currentTimeMillis() - this.start) / 50); // 50 this.tick = (this.tick > this.limit)? this.limit : this.tick; } } */ return this.tick; } } in the item on swing make action to lets say 5 and start equal to actual time in milli seconds public boolean onEntitySwing(ItemStack helditem, LivingEntity le) { System.out.println("onEntitySwing"); item_handler ih = get_itemhandler(helditem); ih.start = System.currentTimeMillis(); ih.action = 5; then on inventoryTick check the action set // ########## ########## ########## ########## @Override public void inventoryTick(ItemStack helditem, Level warudo, Entity entity, int slot, boolean p_41408_) { System.out.println("inventoryTick " + slot); if (!warudo.isClientSide && slot < 9) { item_handler ih = get_itemhandler(helditem); if (ih.action == 5) { int tick = ih.get_tick(); // hot do i check if the player entity is presing left click ????? // if is presing keep counting and call onUseTick // if its not stop and call releaseUsing } } } ############################################# then i get stuck coze i dont know how from server side ask what mouse keis is the player presing Minecraft.getMouseEvent or pe.isShiftKeyDown() or something Quote
perromercenary00 Posted February 26, 2023 Posted February 26, 2023 package merctool.item.stick; import org.jetbrains.annotations.Nullable; import merctool.item.ItemInit; import merctool.item.tool.item_c_provider; import merctool.item.tool.item_handler; import merctool.util.Postate; import merctool.util.Target; import net.minecraft.core.BlockPos; import net.minecraft.core.Vec3i; import net.minecraft.core.particles.ParticleTypes; import net.minecraft.nbt.CompoundTag; import net.minecraft.sounds.SoundEvents; import net.minecraft.world.InteractionHand; import net.minecraft.world.InteractionResult; import net.minecraft.world.InteractionResultHolder; import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.LivingEntity; import net.minecraft.world.entity.item.ItemEntity; import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.Item; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.context.UseOnContext; import net.minecraft.world.level.Level; import net.minecraft.world.level.block.AbstractCauldronBlock; import net.minecraft.world.level.block.Blocks; import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.block.state.properties.BlockStateProperties; import net.minecraft.world.level.block.state.properties.DirectionProperty; import net.minecraft.world.level.material.Material; import net.minecraft.world.phys.Vec3; import net.minecraftforge.common.ToolAction; import net.minecraftforge.common.capabilities.ForgeCapabilities; import net.minecraftforge.common.capabilities.ICapabilityProvider; public class stick_lefclick extends Item { public static final DirectionProperty FACING = BlockStateProperties.FACING; // ########## ########## ########## ########## public stick_lefclick(Properties propiedad) { super(propiedad); // TODO Auto-generated constructor stub // ahora las propiedades se declaran en el client side dela clase pricipal // esto va a ser un arco por ahora } // ########## ########## ########## ########## @Nullable @Override public ICapabilityProvider initCapabilities(ItemStack csaw, @Nullable CompoundTag nbt) { return new item_c_provider(csaw); } // ########## ########## ########## ########## public static item_handler get_itemhandler(ItemStack csaw) { // item_handler ih = get_itemhandler(helditem); item_handler ih = ((item_handler) csaw.getCapability(ForgeCapabilities.ITEM_HANDLER) .orElseThrow(() -> new RuntimeException("O_O"))); return ih; } // ########## ########## ########## ########## @Override public InteractionResultHolder<ItemStack> use(Level warudo, Player pe, InteractionHand hand) { ItemStack itemstack = pe.getItemInHand(hand); Target target = new Target(warudo, pe, 10); Vec3 vh = target.calcular_vh(); if (vh != null) { BlockPos pos = new BlockPos(vh);// .x, vh.y ,vh.z System.out.println(((warudo.isClientSide) ? "local : " : "remote: ") + pos); Vec3i vo = new Vec3i(pos.getX(), pos.getY() + 1, pos.getZ()); particle(warudo, Vec3.atCenterOf(vo)); } return InteractionResultHolder.pass(pe.getItemInHand(hand)); } // ########## ########## ########## ########## @Override public boolean onEntitySwing(ItemStack helditem, LivingEntity le) { System.out.println("onEntitySwing"); Level warudo = le.level; if (!warudo.isClientSide) { item_handler ih = get_itemhandler(helditem); ih.start(5); } // ItemStack itemstack = le.getItemInHand(hand); Target target = new Target(warudo, le, 10); Vec3 vh = target.calcular_vh(); if (vh != null) { BlockPos pos = new BlockPos(vh);// .x, vh.y ,vh.z System.out.println(((warudo.isClientSide) ? "local : " : "remote: ") + vh); Vec3i vo = new Vec3i(pos.getX(), pos.getY() + 1, pos.getZ()); particle(warudo, Vec3.atCenterOf(vo)); } // le.startUsingItem(InteractionHand.MAIN_HAND); // le.stopUsingItem(); le.setItemInHand(InteractionHand.MAIN_HAND, helditem); // le.swing(InteractionHand.MAIN_HAND); return false; } // ########## ########## ########## ########## @Override public void inventoryTick(ItemStack helditem, Level warudo, Entity entity, int slot, boolean p_41408_) { System.out.println("inventoryTick " + slot); if (!warudo.isClientSide) { item_handler ih = get_itemhandler(helditem); if (ih.action == 5) { // hot do i check if the player entity is presing left click ????? // if is presing keep counting and call onUseTick // if its not stop and call releaseUsing } } } // ########## ########## ########## ########## @Override public InteractionResult useOn(UseOnContext p_41427_) { System.out.println("useOn"); return InteractionResult.PASS; } // ########## ########## ########## ########## @Override public boolean onLeftClickEntity(ItemStack stack, Player player, Entity entity) { System.out.println("onLeftClickEntity"); return false; } // ########## ########## ########## ########## @Override public boolean onEntityItemUpdate(ItemStack stack, ItemEntity entity) { // System.out.println("onEntityItemUpdate"); return false; } // ########## ########## ########## ########## @Override public boolean canPerformAction(ItemStack stack, ToolAction toolAction) { System.out.println("canPerformAction"); return false; } // ########## ########## ########## ########## public void particle(Level warudo, Vec3 vh) { warudo.addAlwaysVisibleParticle(ParticleTypes.FLAME, vh.x, vh.y, vh.z, 0.0D, 0.0D, 0.0D); warudo.addParticle(ParticleTypes.SMOKE, vh.x, vh.y, vh.z, 0.0D, 0.0D, 0.0D); // pe.playSound(SoundEvents.FIRE_EXTINGUISH, 1.0F, 1.0F); } // ########## ########## ########## ########## public static boolean if_is_wet_drop(Postate relative_postate) { boolean drop = false; if (relative_postate != null) { // relative_postate.print(); if (relative_postate.getMaterial() == Material.WATER) { drop = true; // System.out.println("\nWATER BLOCK "); relative_postate.setBlockState(Blocks.AIR.defaultBlockState()); } else if (relative_postate.is_WATERLOGGED()) { drop = true; // System.out.println("\nWATERlogged "); relative_postate.set_WATERLOGGED(false); } else if (relative_postate.getBlock() instanceof AbstractCauldronBlock) { int level = relative_postate.getBlockState().getValue(BlockStateProperties.LEVEL_CAULDRON); // System.out.println("\nCAULDRUM LEVEL = " + level); if (level > 0) { drop = true; level = level - 1; if (level < 1) { relative_postate.setBlockState(Blocks.CAULDRON.defaultBlockState()); } else { relative_postate.setBlockState( relative_postate.getBlockState().setValue(BlockStateProperties.LEVEL_CAULDRON, level)); } } } } if (drop == true) { // System.out.println("\nSAVING BLOCK AS "); // relative_postate.print(); relative_postate.setBlock(2); Level warudo = relative_postate.level(); Vec3 center = relative_postate.get_center(); ItemStack dropstack = new ItemStack(ItemInit.INGOT_STEEL.get(), 1); // itemstack.shrink(1); if (warudo.isClientSide) { // System.out.println("FLAME " + warudo.isClientSide); warudo.addParticle(ParticleTypes.FLAME, (center.x), (center.y + 0.5F), (center.z), 0.0D, 0.0D, 0.0D); // le.playSound(SoundEvents.FIRE_EXTINGUISH, 1.0F, 1.0F); } if (!warudo.isClientSide) { ItemEntity pdrop = new ItemEntity(warudo, (center.x), (center.y + 0.5F), (center.z), dropstack); warudo.addFreshEntity(pdrop); } } return drop; } // ########## ########## ########## ########## public static void drop(Level warudo, LivingEntity le, BlockPos pos, ItemStack itemstack) { if (warudo.isClientSide) { warudo.addParticle(ParticleTypes.FLAME, (double) (pos.getX() + 0.5F), (double) (pos.getY() + 1.0F), (double) (pos.getZ() + 0.5F), 0.0D, 0.0D, 0.0D); le.playSound(SoundEvents.FIRE_EXTINGUISH, 1.0F, 1.0F); } if (!warudo.isClientSide) { ItemEntity drop = new ItemEntity(warudo, (double) (pos.getX() + 0.5F), (double) (pos.getY() + 1.0F), (double) (pos.getZ() + 0.5F), itemstack); warudo.addFreshEntity(drop); } } // ########## ########## ########## ########## } Quote
GabrielSnow Posted February 26, 2023 Author Posted February 26, 2023 On 2/26/2023 at 1:20 AM, perromercenary00 said: yeah that something im also interested but will try to avoid packages and complex things let say make a capability whit some values like int action = 0; long start = 0L; Reveal hidden contents package merctool.item.tool; import net.minecraft.core.NonNullList; import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.ListTag; import net.minecraft.nbt.Tag; import net.minecraft.world.item.ItemStack; import net.minecraftforge.common.capabilities.ForgeCapabilities; import net.minecraftforge.items.ItemStackHandler; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; /* helditem.getCapability(ForgeCapabilities.ITEM_HANDLER).ifPresent(handler00 -> { item_handler ih = (item_handler)handler00; System.out.println(warudo.isClientSide + " ih.fuel => " + ih.fuel ); }); */ public class item_handler extends ItemStackHandler { public ItemStack container = null; public float fuel = 0; public int munition = 0; public int type = 0; public long start = 0; public int action = 0; public int tick = 0; public int limit = 1200; public item_handler(ItemStack container) { super(0); this.container = container; } public void print(String mensaje) { System.out.println("\n" + mensaje); System.out.println("this.fuel = " + this.fuel); System.out.println("this.munition = " + this.munition); System.out.println("this.type = " + this.type); System.out.println("this.start = " + this.start); System.out.println("this.action = " + this.action); System.out.println("this.tick = " + this.tick); System.out.println("this.limit = " + this.limit); System.out.println("\n"); } @Override public int getSlotLimit(int slot) { return 64; } @Override public boolean isItemValid(int slot, @NotNull ItemStack stack) { if (stack == null || stack.isEmpty()) // || stack.getItem() instanceof BasketBlockItem { return false; } else { return super.isItemValid(slot, stack); } } @Override public void setStackInSlot(int slot, @NotNull ItemStack stack) { //// System.out.println("setStackInSlot(" + slot + ")"); validateSlotIndex(slot); this.stacks.set(slot, stack); onContentsChanged(slot); if (this.container != null) { // write_item_to_slot(this.container, slot, stack); } } // ########## ########## ########## ########## // @Override public static NonNullList<ItemStack> read_items_from(ItemStack itemstack) { NonNullList<ItemStack> contained_items = NonNullList.withSize(9, ItemStack.EMPTY);// this.getContainerSize() if (itemstack.hasTag()) { CompoundTag compoundtag = itemstack.getTag(); ListTag listtag = null; int size = 0; if (compoundtag.contains("Items")) { // ListTag listtag = new ListTag(); listtag = compoundtag.getList("Items", 10); size = listtag.size(); // contained_items = NonNullList.withSize(size, ItemStack.EMPTY); for (int i = 0; i < listtag.size(); ++i) { CompoundTag itemstacktag = listtag.getCompound(i); int j = compoundtag.getByte("Slot") & 255; if (j >= 0 && j < contained_items.size()) { contained_items.set(j, ItemStack.of(itemstacktag)); } } } } return contained_items; } // ########## ########## ########## ########## // @Override public void write_item_to_slot(ItemStack container, int slot, @NotNull ItemStack stack) { // , NonNullList<ItemStack> contained_items CompoundTag compoundtag = null; if (container.hasTag()) { compoundtag = container.getTag(); } else { compoundtag = new CompoundTag(); } ListTag listtag = null; if (compoundtag.contains("Items")) { listtag = compoundtag.getList("Items", 10); } else { listtag = new ListTag(); } CompoundTag itemstacktag = null; if (slot < listtag.size()) { itemstacktag = listtag.getCompound(slot); } else { itemstacktag = new CompoundTag(); } itemstacktag.putByte("Slot", (byte) slot); stack.save(itemstacktag); listtag.add(itemstacktag); // aqui tengi una duda, se sobreescrive o crea otra ?? compoundtag.put("Items", listtag); container.setTag(compoundtag); } @Override public CompoundTag serializeNBT() { ListTag nbtTagList = new ListTag(); for (int i = 0; i < stacks.size(); i++) { if (!stacks.get(i).isEmpty()) { CompoundTag itemTag = new CompoundTag(); itemTag.putInt("Slot", i); stacks.get(i).save(itemTag); nbtTagList.add(itemTag); } } CompoundTag nbt = new CompoundTag(); nbt.put("Items", nbtTagList); nbt.putInt("Size", stacks.size()); nbt.putInt("munition", this.munition); nbt.putInt("type", this.type); nbt.putFloat("fuel", this.fuel); nbt.putLong("start", this.start); nbt.putShort("action", (short) this.action); nbt.putShort("limit", (short) this.limit); this.tick = 0; //print("serializeNBT()"); onSave(); return nbt; } @Override public void deserializeNBT(CompoundTag nbt) { setSize(nbt.contains("Size", Tag.TAG_INT) ? nbt.getInt("Size") : stacks.size()); ListTag tagList = nbt.getList("Items", Tag.TAG_COMPOUND); for (int i = 0; i < tagList.size(); i++) { CompoundTag itemTags = tagList.getCompound(i); int slot = itemTags.getInt("Slot"); if (slot >= 0 && slot < stacks.size()) { stacks.set(slot, ItemStack.of(itemTags)); } } this.munition = nbt.getInt("munition"); this.fuel = nbt.getFloat("fuel"); this.type = nbt.getInt("type"); this.limit = nbt.getShort("limit"); this.start = nbt.getLong("start"); this.action = nbt.getShort("action"); //System.out.println( "DeserializeNBT()" ); //print("DeserializeNBT()"); onLoad(); } //@Override protected void onSave() { //System.out.println("item_handler __ onSave() "); if(this.action > 0) { //this.tick = get_tick(); if( this.action > 0) { if( this.start > 0L ) { //System.out.println( "Calcular_tick()\n" ); this.tick = (int) ((System.currentTimeMillis() - this.start) / 50); // 50 this.tick = (this.tick > this.limit)? this.limit : this.tick; } } } //System.out.println("item_handler __ onSave() " + this.tick ); } @Override protected void onLoad() { //System.out.println("item_handler __ onLoad() "); if(this.action > 0) { //this.tick = get_tick(); if( this.action > 0) { if( this.start > 0L ) { //System.out.println( "Calcular_tick()\n" ); this.tick = (int) ((System.currentTimeMillis() - this.start) / 50); // 50 this.tick = (this.tick > this.limit)? this.limit : this.tick; } } } //System.out.println("item_handler __ onLoad() " + this.tick ); } public void start(int action) { if ( this.action != action ) { this.action = action; this.start = System.currentTimeMillis(); // 50 this.tick = 0; } } public void stop() { this.action = 0; this.start = 0; // 50 this.tick = 0; this.limit = 1200; } public int get_tick() { /* if( this.tick > 0) { } else if( this.action > 0) { if( this.start > 0L ) { //System.out.println( "Calcular_tick()\n" ); this.tick = (int) ((System.currentTimeMillis() - this.start) / 50); // 50 this.tick = (this.tick > this.limit)? this.limit : this.tick; } } */ return this.tick; } } in the item on swing make action to lets say 5 and start equal to actual time in milli seconds public boolean onEntitySwing(ItemStack helditem, LivingEntity le) { System.out.println("onEntitySwing"); item_handler ih = get_itemhandler(helditem); ih.start = System.currentTimeMillis(); ih.action = 5; then on inventoryTick check the action set // ########## ########## ########## ########## @Override public void inventoryTick(ItemStack helditem, Level warudo, Entity entity, int slot, boolean p_41408_) { System.out.println("inventoryTick " + slot); if (!warudo.isClientSide && slot < 9) { item_handler ih = get_itemhandler(helditem); if (ih.action == 5) { int tick = ih.get_tick(); // hot do i check if the player entity is presing left click ????? // if is presing keep counting and call onUseTick // if its not stop and call releaseUsing } } } ############################################# then i get stuck coze i dont know how from server side ask what mouse keis is the player presing Minecraft.getMouseEvent or pe.isShiftKeyDown() or something Expand I think that you are trying to find out the opposite of me, how to detect left click. I'm trying to make the player left click, or mine. I know there is a way to detect the thing that you want using Minecraft.getInstance().player.getAttack() or something like that, I know it has .attack something at the end of it, hope it helps. But still, how do I make the player LEFT CLICK, and how do I make the player HOLD LEFT CLICK? If you know thanks ahead. Quote
GabrielSnow Posted February 26, 2023 Author Posted February 26, 2023 On 2/25/2023 at 11:57 PM, GabrielSnow said: So I've been making a Minecraft bot because I want to get into AI and because I'm a bored student and I can't figure out how to make the player hold down left click, I've seen many people use KeyBind or minecraft.player.gameSettings but I figured that that doesn't work anymore because it's only in older versions(I think), I can't make the imports work (net.minecraft.client.settings). So far I figured out how to do it with the Baritone API using a loop but it's very CPU intensive, adding a delay makes it not work. while(true) { BaritoneAPI.getProvider().getPrimaryBaritone().getInputOverrideHandler().setInputForceState(baritone.api.utils.input.Input.CLICK_LEFT, true); } Expand To add to this, I do not want to make a Minecraft bot like mineFlayer, that was not what I meant. I want to connect to the client side of the client using the mod and help them out like Baritone does, I want to help them farm or mine etc. I know that Baritone has those functions and accessing them would be great but making my own lets say #mine carrot command would be better. Maybe even at the end goal I could make a command to end the game by killing the ender dragon, but for that I need to create player inputs which I cannot seem to find even in the forge documentary, I asked ChatGPT but he only knows everything at and below 1.12.2 which is not what I want. A solution using external APIs would also be a good solution but I would prefer a solution without external APIs. Quote
perromercenary00 Posted February 26, 2023 Posted February 26, 2023 i found something old //import org.lwjgl.input.Mouse; int button_presed = Mouse.getButton(); but dont works in java 17 i fond something similar but dont get it to work //import java.awt.event.MouseEvent; MouseEvent.getButton() look like you must first create MouseEvent object to use it but dont find a working exaple could it be an minecraft event trigered on left click we could capture and use ? Quote
GabrielSnow Posted February 26, 2023 Author Posted February 26, 2023 On 2/26/2023 at 1:47 PM, perromercenary00 said: i found something old //import org.lwjgl.input.Mouse; int button_presed = Mouse.getButton(); but dont works in java 17 i fond something similar but dont get it to work //import java.awt.event.MouseEvent; MouseEvent.getButton() look like you must first create MouseEvent object to use it but dont find a working exaple could it be an minecraft event trigered on left click we could capture and use ? Expand It doesn't seem like it would work, it doesn't reference the Minecraft instance. If it were to exist it would probably use Minecraft.getInstance() for the input, otherwise I don't think it would make sense, I went over the docs for Minecraft.getInstance().player but I couldn't find anything useful, only setting the rotation and getting the position, I can't find anything for inputs, maybe the only thing I could find is the keys for the player's set controls, but even with that there isn't a way that I know of that could use those keys to make an input onto the client, or register an input. Quote
GabrielSnow Posted February 26, 2023 Author Posted February 26, 2023 On 2/26/2023 at 1:47 PM, perromercenary00 said: i found something old //import org.lwjgl.input.Mouse; int button_presed = Mouse.getButton(); but dont works in java 17 i fond something similar but dont get it to work //import java.awt.event.MouseEvent; MouseEvent.getButton() look like you must first create MouseEvent object to use it but dont find a working exaple could it be an minecraft event trigered on left click we could capture and use ? Expand As for listening if the mouse is pressed I found something for you: int pressed = java.awt.event.MouseEvent.BUTTON1; hope it helps, it might not be the exact thing you need but I think the library has listeners. Quote
perromercenary00 Posted February 26, 2023 Posted February 26, 2023 On 2/26/2023 at 2:05 PM, GabrielSnow said: As for listening if the mouse is pressed I found something for you: int pressed = java.awt.event.MouseEvent.BUTTON1; hope it helps, it might not be the exact thing you need but I think the library has listeners. Expand no that dont works allwais says 1 no mather what i press // ########## ########## ########## ########## @Override public void inventoryTick(ItemStack helditem, Level warudo, Entity entity, int slot, boolean p_41408_) { int pressed = java.awt.event.MouseEvent.BUTTON1; System.out.println("inventoryTick [" + slot + "], " + ((warudo.isClientSide)? "Local World":"Server World") + ", b1=" + pressed ); } inventoryTick [2], Local World, b1=1 inventoryTick [2], Server World, b1=1 inventoryTick [2], Local World, b1=1 inventoryTick [2], Server World, b1=1 inventoryTick [2], Local World, b1=1 inventoryTick [2], Server World, b1=1 inventoryTick [2], Local World, b1=1 inventoryTick [2], Local World, b1=1 Quote
GabrielSnow Posted February 26, 2023 Author Posted February 26, 2023 I found some Baritone commands that make a click but I cant seems to figure out how it works, can you help? public void Tester() { new Thread(() -> { if(StartTester) { Minecraft minecraft = Minecraft.getInstance(); minecraft.player.sendMessage(new TextComponent("Tester started"), minecraft.player.getUUID()); BaritoneAPI.getSettings().allowSprint.value = true; BaritoneAPI.getSettings().primaryTimeoutMS.value = 2000L; ICustomGoalProcess customGoalProcess = BaritoneAPI.getProvider().getPrimaryBaritone().getCustomGoalProcess(); IPlayerController playerController = BaritoneAPI.getProvider().getPrimaryBaritone().getPlayerContext().playerController(); customGoalProcess.setGoalAndPath(new GoalXZ(1000, 0)); while(StartTester) { playerController.clickBlock(null, Direction.fromNormal(0,0,0)); try { Thread.sleep(50); } catch (InterruptedException e) { minecraft.player.sendMessage(new TextComponent("Thread sleep error"), minecraft.player.getUUID()); Thread.currentThread().interrupt(); } } } }).start(); } playerController.clickBlock(); seems to be the thing I need but I dont know how to make it work. Quote
perromercenary00 Posted February 26, 2023 Posted February 26, 2023 On 2/26/2023 at 2:53 PM, GabrielSnow said: I found some Baritone commands that make a click but I cant seems to figure out how it works, can you help? public void Tester() { new Thread(() -> { if(StartTester) { Minecraft minecraft = Minecraft.getInstance(); minecraft.player.sendMessage(new TextComponent("Tester started"), minecraft.player.getUUID()); BaritoneAPI.getSettings().allowSprint.value = true; BaritoneAPI.getSettings().primaryTimeoutMS.value = 2000L; ICustomGoalProcess customGoalProcess = BaritoneAPI.getProvider().getPrimaryBaritone().getCustomGoalProcess(); IPlayerController playerController = BaritoneAPI.getProvider().getPrimaryBaritone().getPlayerContext().playerController(); customGoalProcess.setGoalAndPath(new GoalXZ(1000, 0)); while(StartTester) { playerController.clickBlock(null, Direction.fromNormal(0,0,0)); try { Thread.sleep(50); } catch (InterruptedException e) { minecraft.player.sendMessage(new TextComponent("Thread sleep error"), minecraft.player.getUUID()); Thread.currentThread().interrupt(); } } } }).start(); } playerController.clickBlock(); seems to be the thing I need but I dont know how to make it work. Expand i dont think that gonna work the name suggest it only works when click a block is like useOn() Quote
perromercenary00 Posted February 26, 2023 Posted February 26, 2023 a frack MouseEvent is an event who could guess such a thing //########## ########## ########## ########## @SubscribeEvent public static void on_mouse_something(MouseButton event) { //Entity entity = event.; //Level warudo = event. //ItemStack itemstack = event.?; Minecraft mc = Minecraft.getInstance(); //Level warudo = mc.level;//it return null System.out.println("on_mouse_something [" + event.getButton() + "], " ); } on_mouse_something [0], on_mouse_something [0], on_mouse_something [0], on_mouse_something [0], on_mouse_something [1], on_mouse_something [1], on_mouse_something [1], on_mouse_something [1], on_mouse_something [2], on_mouse_something [2], on_mouse_something [2], on_mouse_something [2], on_mouse_something [3], on_mouse_something [3], on_mouse_something [3], ######## but is there a misssing string i need to get the player and itemstack his holding to know how to proced on left click Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.