Jump to content

Check if MainHand is null to use autoclick right


NqwSqw

Recommended Posts

Hi,

I want to when I have blocks in OffHand and item can be eating in MainHand, the autoclick doesn't work and when in offHand there are blocks and MainHand have other things except foods it works

package xyz.fusked.m0dules.mods.combat;

import java.lang.reflect.Method;
import java.util.Random;
import net.minecraft.client.Minecraft;
import net.minecraft.client.entity.EntityPlayerSP;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.client.gui.inventory.GuiInventory;
import net.minecraft.client.settings.GameSettings;
import net.minecraft.client.settings.KeyBinding;
import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemStack;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.common.gameevent.TickEvent;
import net.minecraftforge.fml.common.gameevent.TickEvent.ClientTickEvent;
import org.lwjgl.input.Keyboard;
import org.lwjgl.input.Mouse;
import xyz.fusked.m0dules.Module;
import xyz.fusked.m0dules.Module.Category;
import xyz.fusked.m0dules.Module.Modules;
import xyz.fusked.utils.MouseUtil;
import xyz.fusked.utils.Timer;
import xyz.fusked.values.BooleanValue;
import xyz.fusked.values.NumberValue;

public class AutoclickDroit extends Module
{
  private NumberValue maxcps;
  private NumberValue mincps;
  private BooleanValue blocks;
  private long nextLeftUp;
  private long nextLeftDown;
  private long nextRightUp;
  private long nextRightDown;
  private long nextDrop;
  private long nextExhaust;
  private Timer timer;
  private Random random;
  private double dr0pR4t3;
  private boolean dr0pp1ng;
  private Method guiScreenMethod;
  
  public AutoclickDroit()
  {
    super("AutoClickDroit", 0, Module.Category.COMBAT);
    this.maxcps = new NumberValue("MaxCPS", 12.0D, 1.0D, 50.0D);
    this.mincps = new NumberValue("MinCPS", 6.0D, 1.0D, 50.0D);
    this.blocks = new BooleanValue("Blocks", false);
    this.timer = new Timer();
    this.random = new Random();
    addValue(this.maxcps);
    addValue(this.mincps);
    addBoolean(this.blocks);
    try
    {
      this.guiScreenMethod = GuiScreen.class.getDeclaredMethod("mouseClicked", new Class[] { Integer.TYPE, Integer.TYPE, Integer.TYPE });
    }
    catch (NoSuchMethodException e)
    {
      e.printStackTrace();
    }
  }
  
  public boolean check(EntityPlayerSP playerSP)
  {
    return (!this.blocks.getState()) || ((playerSP.getHeldItemOffhand() != null) && (playerSP.getHeldItemOffhand().getItem() instanceof ItemBlock));
  }
  
  @SubscribeEvent
  public void onTick(TickEvent.ClientTickEvent ev3nt, EntityPlayerSP playerSP)
    throws Exception
  {
    if ((this.mc.currentScreen == null) && (check(this.mc.thePlayer)))
    {
      Mouse.poll();
      if (Mouse.isButtonDown(1))
      {
        if ((this.nextLeftDown > 0L) && (this.nextLeftUp > 0L))
        {
          if (System.currentTimeMillis() > this.nextLeftDown)
          {
        		  KeyBinding.setKeyBindState(this.mc.gameSettings.keyBindUseItem.getKeyCode(), true);
                  KeyBinding.onTick(this.mc.gameSettings.keyBindUseItem.getKeyCode());
                  MouseUtil.sendClick(0, true);
                  generateLeftDelay();  
          }
          else if (System.currentTimeMillis() > this.nextLeftUp)
          {
        	KeyBinding.setKeyBindState(this.mc.gameSettings.keyBindUseItem.getKeyCode(), false);
            MouseUtil.sendClick(0, false);
          }
        }
        else {
          generateLeftDelay();
        }
        if (!Mouse.isButtonDown(0))
        {
          long n = 0L;
          this.nextRightUp = 0L;
          this.nextRightDown = 0L;
        }
      }
      else
      {
        long n2 = 0L;
        this.nextRightUp = 0L;
        this.nextRightDown = 0L;
        this.nextLeftUp = 0L;
        this.nextLeftDown = 0L;
      }
    }
    else if ((this.mc.currentScreen instanceof GuiInventory))
    {
      if ((Mouse.isButtonDown(1)) && ((Keyboard.isKeyDown(54)) || (Keyboard.isKeyDown(42))))
      {
        if ((this.nextLeftUp == 0L) || (this.nextLeftDown == 0L))
        {
          generateLeftDelay();
          return;
        }
        if (System.currentTimeMillis() > this.nextLeftDown)
        {
          generateLeftDelay();
          clickInventory(this.mc.currentScreen);
        }
      }
      else
      {
        long n3 = 0L;
        this.nextRightUp = 0L;
        this.nextRightDown = 0L;
        this.nextLeftUp = 0L;
        this.nextLeftDown = 0L;
      }
    }
  }
  
  private void generateLeftDelay()
  {
    if (this.mincps.getValue() > this.maxcps.getValue()) {
      return;
    }
    long d3l4y = (int)Math.round(900.0D / this.mincps.getValue() + this.random.nextDouble() * (this.maxcps.getValue() - this.mincps.getValue()));
    if (System.currentTimeMillis() > this.nextDrop)
    {
      if ((!this.dr0pp1ng) && (this.random.nextInt(100) >= 85))
      {
        this.dr0pp1ng = true;
        this.dr0pR4t3 = (1.1D + this.random.nextDouble() * 0.15D);
      }
      else
      {
        this.dr0pp1ng = false;
      }
      this.nextDrop = (System.currentTimeMillis() + 500L + this.random.nextInt(1500));
    }
    if (this.dr0pp1ng) {
      d3l4y *= this.dr0pR4t3;
    }
    if (System.currentTimeMillis() > this.nextExhaust)
    {
      if (this.random.nextInt(100) >= 80) {
        d3l4y += 50L + this.random.nextInt(150);
      }
      this.nextExhaust = (System.currentTimeMillis() + 500L + this.random.nextInt(1500));
    }
    this.nextLeftDown = (System.currentTimeMillis() + d3l4y);
    this.nextLeftUp = (System.currentTimeMillis() + d3l4y / 2L - this.random.nextInt(10));
  }
  private void clickInventory(GuiScreen screen)
  {
    int v4r1 = Mouse.getX() * screen.width / this.mc.displayWidth;
    int v4r2 = screen.height - Mouse.getY() * screen.height / this.mc.displayHeight - 1;
    int v4r3 = 0;
    try
    {
      this.guiScreenMethod.setAccessible(true);
      this.guiScreenMethod.invoke(screen, new Object[] { Integer.valueOf(v4r1), Integer.valueOf(v4r2), Integer.valueOf(0) });
      this.guiScreenMethod.setAccessible(false);
    }
    catch (Exception e)
    {
      e.printStackTrace();
    }
  }

 

Link to comment
Share on other sites

Try checking getHeldItem(MainHand).isEmpty()

Also

12 hours ago, NqwSqw said:

playerSP.getHeldItemOffhand() != null

Is always true. Look at Problematic code 12#

My Projects:

Cruelars Triforcemod (1.12 release; 1.14 alpha soon coming)

 

Important:

As my mod is on at least 10 different third party sites without my permission, I want to warn you about that with a link to StopModReposts

Link to comment
Share on other sites

But why this doesn't work

package xyz.fusked.m0dules.mods.combat;

import java.lang.reflect.Method;
import java.util.Random;
import net.minecraft.client.Minecraft;
import net.minecraft.client.entity.EntityPlayerSP;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.client.gui.inventory.GuiInventory;
import net.minecraft.client.settings.GameSettings;
import net.minecraft.client.settings.KeyBinding;
import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemFood;
import net.minecraft.item.ItemStack;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.common.gameevent.TickEvent;
import net.minecraftforge.fml.common.gameevent.TickEvent.ClientTickEvent;
import org.lwjgl.input.Keyboard;
import org.lwjgl.input.Mouse;
import xyz.fusked.m0dules.Module;
import xyz.fusked.m0dules.Module.Category;
import xyz.fusked.m0dules.Module.Modules;
import xyz.fusked.utils.MouseUtil;
import xyz.fusked.utils.Timer;
import xyz.fusked.values.BooleanValue;
import xyz.fusked.values.NumberValue;

public class AutoclickDroit extends Module
{
  private NumberValue maxcps;
  private NumberValue mincps;
  private BooleanValue blocks;
  private long nextLeftUp;
  private long nextLeftDown;
  private long nextRightUp;
  private long nextRightDown;
  private long nextDrop;
  private long nextExhaust;
  private Timer timer;
  private Random random;
  private double dr0pR4t3;
  private boolean dr0pp1ng;
  private Method guiScreenMethod;
  
  public AutoclickDroit()
  {
    super("AutoClickDroit", 0, Module.Category.COMBAT);
    this.maxcps = new NumberValue("MaxCPS", 12.7D, 1.0D, 20.0D);
    this.mincps = new NumberValue("MinCPS", 12.0D, 1.0D, 20.0D);
    this.blocks = new BooleanValue("Blocks", false);
    this.timer = new Timer();
    this.random = new Random();
    addValue(this.maxcps);
    addValue(this.mincps);
    addBoolean(this.blocks);
    try
    {
      this.guiScreenMethod = GuiScreen.class.getDeclaredMethod("mouseClicked", new Class[] { Integer.TYPE, Integer.TYPE, Integer.TYPE });
    }
    catch (NoSuchMethodException e)
    {
      e.printStackTrace();
    }
  }
  
  public boolean check(EntityPlayerSP playerSP)
  {
	  if ((playerSP.getHeldItemMainhand() != null) && (playerSP.getHeldItemMainhand().getItem() instanceof ItemBlock)){
	      return true;
	  }
	  else if ((playerSP.getHeldItemOffhand() != null) && (playerSP.getHeldItemOffhand().getItem() instanceof ItemBlock)){
	      return true;
	  }
	  else if((playerSP.getHeldItemOffhand() != null) && (playerSP.getHeldItemOffhand().getItem() instanceof ItemBlock ) && (playerSP.getHeldItemMainhand().getItem() instanceof ItemFood )){
		  return false;
	  }
	  else {
		  return false;
	  }
  }
  
  @SubscribeEvent
  public void onTick(TickEvent.ClientTickEvent ev3nt)
    throws Exception
  {
    if ((this.mc.currentScreen == null) && (check(this.mc.thePlayer)))
    {
      Mouse.poll();
      if (Mouse.isButtonDown(1))
      {
        if ((this.nextLeftDown > 0L) && (this.nextLeftUp > 0L))
        {
          if (System.currentTimeMillis() > this.nextLeftDown)
          {
        		  KeyBinding.setKeyBindState(this.mc.gameSettings.keyBindUseItem.getKeyCode(), true);
                  KeyBinding.onTick(this.mc.gameSettings.keyBindUseItem.getKeyCode());
                  MouseUtil.sendClick(0, true);
                  generateLeftDelay();  
          }
          else if (System.currentTimeMillis() > this.nextLeftUp)
          {
        	KeyBinding.setKeyBindState(this.mc.gameSettings.keyBindUseItem.getKeyCode(), false);
            MouseUtil.sendClick(0, false);
          }
        }
        else {
          generateLeftDelay();
        }
        if (!Mouse.isButtonDown(0))
        {
          long n = 0L;
          this.nextRightUp = 0L;
          this.nextRightDown = 0L;
        }
      }
      else
      {
        long n2 = 0L;
        this.nextRightUp = 0L;
        this.nextRightDown = 0L;
        this.nextLeftUp = 0L;
        this.nextLeftDown = 0L;
      }
    }
    else if ((this.mc.currentScreen instanceof GuiInventory))
    {
      if ((Mouse.isButtonDown(1)) && ((Keyboard.isKeyDown(54)) || (Keyboard.isKeyDown(42))))
      {
        if ((this.nextLeftUp == 0L) || (this.nextLeftDown == 0L))
        {
          generateLeftDelay();
          return;
        }
        if (System.currentTimeMillis() > this.nextLeftDown)
        {
          generateLeftDelay();
          clickInventory(this.mc.currentScreen);
        }
      }
      else
      {
        long n3 = 0L;
        this.nextRightUp = 0L;
        this.nextRightDown = 0L;
        this.nextLeftUp = 0L;
        this.nextLeftDown = 0L;
      }
    }
  }
  
  private void generateLeftDelay()
  {
    if (this.mincps.getValue() > this.maxcps.getValue()) {
      return;
    }
    long d3l4y = (int)Math.round(900.0D / this.mincps.getValue() + this.random.nextDouble() * (this.maxcps.getValue() - this.mincps.getValue()));
    if (System.currentTimeMillis() > this.nextDrop)
    {
      if ((!this.dr0pp1ng) && (this.random.nextInt(100) >= 85))
      {
        this.dr0pp1ng = true;
        this.dr0pR4t3 = (1.1D + this.random.nextDouble() * 0.15D);
      }
      else
      {
        this.dr0pp1ng = false;
      }
      this.nextDrop = (System.currentTimeMillis() + 500L + this.random.nextInt(1500));
    }
    if (this.dr0pp1ng) {
      d3l4y *= this.dr0pR4t3;
    }
    if (System.currentTimeMillis() > this.nextExhaust)
    {
      if (this.random.nextInt(100) >= 80) {
        d3l4y += 50L + this.random.nextInt(150);
      }
      this.nextExhaust = (System.currentTimeMillis() + 500L + this.random.nextInt(1500));
    }
    this.nextLeftDown = (System.currentTimeMillis() + d3l4y);
    this.nextLeftUp = (System.currentTimeMillis() + d3l4y / 2L - this.random.nextInt(10));
  }
  private void clickInventory(GuiScreen screen)
  {
    int v4r1 = Mouse.getX() * screen.width / this.mc.displayWidth;
    int v4r2 = screen.height - Mouse.getY() * screen.height / this.mc.displayHeight - 1;
    int v4r3 = 0;
    try
    {
      this.guiScreenMethod.setAccessible(true);
      this.guiScreenMethod.invoke(screen, new Object[] { Integer.valueOf(v4r1), Integer.valueOf(v4r2), Integer.valueOf(0) });
      this.guiScreenMethod.setAccessible(false);
    }
    catch (Exception e)
    {
      e.printStackTrace();
    }
  }
}

 

at

 

public boolean check(EntityPlayerSP playerSP)
  {
	  if ((playerSP.getHeldItemMainhand() != null) && (playerSP.getHeldItemMainhand().getItem() instanceof ItemBlock)){
	      return true;
	  }
	  else if ((playerSP.getHeldItemOffhand() != null) && (playerSP.getHeldItemOffhand().getItem() instanceof ItemBlock)){
	      return true;
	  }
	  else if((playerSP.getHeldItemOffhand() != null) && (playerSP.getHeldItemOffhand().getItem() instanceof ItemBlock ) && (playerSP.getHeldItemMainhand().getItem() instanceof ItemFood )){
		  return false;
	  }
	  else {
		  return false;
	  }
  }

 

if I want to when I have blocks in OffHand and item can be eating in MainHand, the autoclick doesn't work and when in offHand there are blocks and MainHand have other things except foods it works ?

 

 

Link to comment
Share on other sites

Quote

public boolean check(EntityPlayerSP playerSP)
  {
	  if ((playerSP.getHeldItemMainhand() != null) && (playerSP.getHeldItemMainhand().getItem() instanceof ItemBlock)){
	      return true;
	  }
	  else if ((playerSP.getHeldItemOffhand() != null) && (playerSP.getHeldItemOffhand().getItem() instanceof ItemBlock)){
	      return true;
	  }
	  else if((playerSP.getHeldItemOffhand() != null) && (playerSP.getHeldItemOffhand().getItem() instanceof ItemBlock ) && (playerSP.getHeldItemMainhand().getItem() instanceof ItemFood )){
		  return false;
	  }
	  else {
		  return false;
	  }
  }

Have you even looked at the info in the link? Both Vanilla and Forge code expect ItemStacks to be not null so they use Itemstack.EMPTY use ItemStack.isEmpty() to check for that.

My Projects:

Cruelars Triforcemod (1.12 release; 1.14 alpha soon coming)

 

Important:

As my mod is on at least 10 different third party sites without my permission, I want to warn you about that with a link to StopModReposts

Link to comment
Share on other sites

3 hours ago, _Cruelar_ said:

Have you even looked at the info in the link? Both Vanilla and Forge code expect ItemStacks to be not null so they use Itemstack.EMPTY use ItemStack.isEmpty() to check for that.

I try it but it give unexpected method for ItemStack

Link to comment
Share on other sites

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • Sometimes, tweaking load order or specific configs can also help ease those conflicts.
    • I have recently tired downloading forge so i can run mods for hypixel skyblock but whenever i download forge and do it the same way as videos and tutorials forge keeps downloading as log file and doesnt download the .jar file any help will be aprecciated.
    • So I have created a Create Mod Server with my friends and i to play everyone can join play except one of my friends because when he tries to launch the game from the CurseForge Launcher it will load but never open or give him a crash report, we have tried everything from deleting CF and reinstalling it to Updating his drivers, IDK what to do if anyone can help I would be very Grateful
    • I get this error when trying to start the server for forged mods. In the code below it mentions distant horizons but no matter what mod I put in (deleting distant horizons) it still gives an error and doesn't launch Crash Report UUID: 3e91d5c7-18a7-43c2-a935-a8d28de560d1 FML: 47.3 Forge: net.minecraftforge:47.3.10[23:33:47] [main/ERROR] [minecraft/Main]: Failed to start the minecraft server net.minecraftforge.fml.LoadingFailedException: Loading errors encountered: [    Distant Horizons (distanthorizons) encountered an error during the sided_setup event phase§7java.lang.ExceptionInInitializerError: null]     at net.minecraftforge.fml.ModLoader.waitForTransition(ModLoader.java:246) ~[fmlcore-1.20.1-47.3.10.jar%23104!/:?] {}     at net.minecraftforge.fml.ModLoader.lambda$dispatchAndHandleError$20(ModLoader.java:210) ~[fmlcore-1.20.1-47.3.10.jar%23104!/:?] {}     at java.util.Optional.ifPresent(Optional.java:178) ~[?:?] {}     at net.minecraftforge.fml.ModLoader.dispatchAndHandleError(ModLoader.java:210) ~[fmlcore-1.20.1-47.3.10.jar%23104!/:?] {}     at net.minecraftforge.fml.ModLoader.lambda$loadMods$15(ModLoader.java:190) ~[fmlcore-1.20.1-47.3.10.jar%23104!/:?] {}     at java.lang.Iterable.forEach(Iterable.java:75) ~[?:?] {}     at net.minecraftforge.fml.ModLoader.loadMods(ModLoader.java:190) ~[fmlcore-1.20.1-47.3.10.jar%23104!/:?] {}     at net.minecraft.server.loading.ServerModLoader.load(ServerModLoader.java:31) ~[forge-1.20.1-47.3.10-universal.jar%23108!/:?] {re:classloading}     at net.minecraft.server.Main.main(Main.java:125) ~[server-1.20.1-20230612.114412-srg.jar%23103!/:?] {re:classloading}     at jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103) ~[?:?] {}     at java.lang.reflect.Method.invoke(Method.java:580) ~[?:?] {}     at net.minecraftforge.fml.loading.targets.CommonLaunchHandler.runTarget(CommonLaunchHandler.java:111) ~[fmlloader-1.20.1-47.3.10.jar%2369!/:?] {}     at net.minecraftforge.fml.loading.targets.CommonLaunchHandler.lambda$run$1(CommonLaunchHandler.java:103) ~[fmlloader-1.20.1-47.3.10.jar%2369!/:?] {}     at net.minecraftforge.fml.loading.targets.CommonServerLaunchHandler.lambda$makeService$0(CommonServerLaunchHandler.java:27) ~[fmlloader-1.20.1-47.3.10.jar%2369!/:?] {}     at cpw.mods.modlauncher.LaunchServiceHandlerDecorator.launch(LaunchServiceHandlerDecorator.java:30) ~[modlauncher-10.0.9.jar%2355!/:?] {}     at cpw.mods.modlauncher.LaunchServiceHandler.launch(LaunchServiceHandler.java:53) ~[modlauncher-10.0.9.jar%2355!/:?] {}     at cpw.mods.modlauncher.LaunchServiceHandler.launch(LaunchServiceHandler.java:71) ~[modlauncher-10.0.9.jar%2355!/:?] {}     at cpw.mods.modlauncher.Launcher.run(Launcher.java:108) ~[modlauncher-10.0.9.jar%2355!/:?] {}     at cpw.mods.modlauncher.Launcher.main(Launcher.java:78) ~[modlauncher-10.0.9.jar%2355!/:?] {}     at cpw.mods.bootstraplauncher.BootstrapLauncher.main(BootstrapLauncher.java:141) ~[bootstraplauncher-1.1.2.jar:?] {}  
    • This error keeps coming up after player tries to join server, doesn't happen to anyone else.  Error: Internal Exception: io.netty.handler.codec.DecoderException: java.lang.ArrayIndexOutOfBoundsException: Index 17196645 out of bounds for length 13 Heres the latest.log https://pastebin.com/uaw3KC0K  Heres the debug.log https://drive.google.com/file/d/1QzqtCMUf7ps1Iz85AOsMM7W8QhbHjBeU/view?usp=sharing
  • Topics

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.