Jump to content

Check if blocks is in MainHand and OffHand


NqwSqw

Recommended Posts

Hi,

I want to check if block is in MainHand or OffHand but i don't know how

 

package xyz.fusked.m0dules.mods.combat;
import java.lang.reflect.Method;
import java.util.Random;

import net.minecraft.block.Block;
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.init.Blocks;
import net.minecraft.item.ItemAxe;
import net.minecraft.item.ItemStack;
import net.minecraft.item.ItemSword;
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 NumberValue jitterstren;
private BooleanValue jitter;
private BooleanValue weapon;
private BooleanValue inv;
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("AutoClicker Droit", 0, Module.Category.COMBAT);
  this.maxcps = new NumberValue("MaxCPS", 12.0D, 1.0D, 20.0D);
  this.mincps = new NumberValue("MinCPS", 6.0D, 1.0D, 20.0D);
  this.jitterstren = new NumberValue("Jitter Strength", 0.5D, 0.1D, 2.0D);
  this.jitter = new BooleanValue("Jitter", false);
  this.blocks = new BooleanValue("Blocks", false);
  this.inv = new BooleanValue("Inventory fill", false);
  this.timer = new Timer();
  this.random = new Random();
  addValue(this.maxcps);
  addValue(this.mincps);
  addValue(this.jitterstren);
  addBoolean(this.jitter);
  addBoolean(this.weapon);
  addBoolean(this.inv);
  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() instanceof Block)) || ((playerSP.getHeldItemMainhand().getItem() instanceof ItemAxe))));
}

@SubscribeEvent
public void onTick(TickEvent.ClientTickEvent ev3nt)
  throws Exception
{
  if ((this.mc.currentScreen == null) && (check(this.mc.thePlayer)))
  {
    Mouse.poll();
    if (Mouse.isButtonDown(0))
    {
      if ((this.jitter.getState()) && (this.random.nextDouble() > 0.65D))
      {
        float jitterstrenght = (float)(this.jitterstren.getValue() * 0.5D);
        if (this.random.nextBoolean()) {
          this.mc.thePlayer.rotationYaw += this.random.nextFloat() * jitterstrenght;
        } else {
          this.mc.thePlayer.rotationYaw -= this.random.nextFloat() * jitterstrenght;
        }
        if (this.random.nextBoolean()) {
          this.mc.thePlayer.rotationPitch += (float)(this.random.nextFloat() * (jitterstrenght * 0.75D));
        } else {
          this.mc.thePlayer.rotationPitch -= (float)(this.random.nextFloat() * (jitterstrenght * 0.75D));
        }
      }
      if ((this.nextLeftDown > 0L) && (this.nextLeftUp > 0L))
      {
        if (System.currentTimeMillis() > this.nextLeftDown)
        {
          KeyBinding.setKeyBindState(this.mc.gameSettings.keyBindAttack.getKeyCode(), true);
          KeyBinding.onTick(this.mc.gameSettings.keyBindAttack.getKeyCode());
          MouseUtil.sendClick(0, true);
          generateLeftDelay();
        }
        else if (System.currentTimeMillis() > this.nextLeftUp)
        {
          KeyBinding.setKeyBindState(this.mc.gameSettings.keyBindAttack.getKeyCode(), false);
          MouseUtil.sendClick(0, false);
        }
      }
      else {
        generateLeftDelay();
      }
      if (!Mouse.isButtonDown(1))
      {
        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(0)) && ((Keyboard.isKeyDown(54)) || (Keyboard.isKeyDown(42))))
    {
      if (!this.inv.getState()) {
        return;
      }
      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

2 hours ago, NqwSqw said:

Hi,

I want to check if block is in MainHand or OffHand but i don't know how

 


package xyz.fusked.m0dules.mods.combat;
import java.lang.reflect.Method;
import java.util.Random;

import net.minecraft.block.Block;
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.init.Blocks;
import net.minecraft.item.ItemAxe;
import net.minecraft.item.ItemStack;
import net.minecraft.item.ItemSword;
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 NumberValue jitterstren;
private BooleanValue jitter;
private BooleanValue weapon;
private BooleanValue inv;
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("AutoClicker Droit", 0, Module.Category.COMBAT);
  this.maxcps = new NumberValue("MaxCPS", 12.0D, 1.0D, 20.0D);
  this.mincps = new NumberValue("MinCPS", 6.0D, 1.0D, 20.0D);
  this.jitterstren = new NumberValue("Jitter Strength", 0.5D, 0.1D, 2.0D);
  this.jitter = new BooleanValue("Jitter", false);
  this.blocks = new BooleanValue("Blocks", false);
  this.inv = new BooleanValue("Inventory fill", false);
  this.timer = new Timer();
  this.random = new Random();
  addValue(this.maxcps);
  addValue(this.mincps);
  addValue(this.jitterstren);
  addBoolean(this.jitter);
  addBoolean(this.weapon);
  addBoolean(this.inv);
  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() instanceof Block)) || ((playerSP.getHeldItemMainhand().getItem() instanceof ItemAxe))));
}

@SubscribeEvent
public void onTick(TickEvent.ClientTickEvent ev3nt)
  throws Exception
{
  if ((this.mc.currentScreen == null) && (check(this.mc.thePlayer)))
  {
    Mouse.poll();
    if (Mouse.isButtonDown(0))
    {
      if ((this.jitter.getState()) && (this.random.nextDouble() > 0.65D))
      {
        float jitterstrenght = (float)(this.jitterstren.getValue() * 0.5D);
        if (this.random.nextBoolean()) {
          this.mc.thePlayer.rotationYaw += this.random.nextFloat() * jitterstrenght;
        } else {
          this.mc.thePlayer.rotationYaw -= this.random.nextFloat() * jitterstrenght;
        }
        if (this.random.nextBoolean()) {
          this.mc.thePlayer.rotationPitch += (float)(this.random.nextFloat() * (jitterstrenght * 0.75D));
        } else {
          this.mc.thePlayer.rotationPitch -= (float)(this.random.nextFloat() * (jitterstrenght * 0.75D));
        }
      }
      if ((this.nextLeftDown > 0L) && (this.nextLeftUp > 0L))
      {
        if (System.currentTimeMillis() > this.nextLeftDown)
        {
          KeyBinding.setKeyBindState(this.mc.gameSettings.keyBindAttack.getKeyCode(), true);
          KeyBinding.onTick(this.mc.gameSettings.keyBindAttack.getKeyCode());
          MouseUtil.sendClick(0, true);
          generateLeftDelay();
        }
        else if (System.currentTimeMillis() > this.nextLeftUp)
        {
          KeyBinding.setKeyBindState(this.mc.gameSettings.keyBindAttack.getKeyCode(), false);
          MouseUtil.sendClick(0, false);
        }
      }
      else {
        generateLeftDelay();
      }
      if (!Mouse.isButtonDown(1))
      {
        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(0)) && ((Keyboard.isKeyDown(54)) || (Keyboard.isKeyDown(42))))
    {
      if (!this.inv.getState()) {
        return;
      }
      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();
  }
}
}

 

Check first one hand then the other. Player.getStackInHand(EnumHand) doing this from memory so the method might be named differently or you might have to do something like player.getHand(EnumHand).getActiveItemStack()

About Me

Spoiler

My Discord - Cadiboo#8887

My WebsiteCadiboo.github.io

My ModsCadiboo.github.io/projects

My TutorialsCadiboo.github.io/tutorials

Versions below 1.14.4 are no longer supported on this forum. Use the latest version to receive support.

When asking support remember to include all relevant log files (logs are found in .minecraft/logs/), code if applicable and screenshots if possible.

Only download mods from trusted sites like CurseForge (minecraft.curseforge.com). A list of bad sites can be found here, with more information available at stopmodreposts.org

Edit your own signature at www.minecraftforge.net/forum/settings/signature/ (Make sure to check its compatibility with the Dark Theme)

Link to comment
Share on other sites

2 hours ago, NqwSqw said:

I want to check if block is in MainHand or OffHand but i don't know how

 

 

Is that your own code? Because you are already checking the items in the hands in your code, so it seems you already know the right methods (getHeldItemOffHand and getHeldItemMainHand) and that code shows good knowledge of Java programming? So what exactly is your problem then?

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

Link to comment
Share on other sites

27 minutes ago, NqwSqw said:

Incompatible conditional operand types ItemStack and ItemBlock

ItemBlock extends from Item ItemStack is something that holds an item and all the various other information like stack size and metadata. ItemStack also has a method called getItem() which will return the item it is holding.

  • Thanks 1

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Link to comment
Share on other sites

1 hour ago, NqwSqw said:

This it's my problem

in


playerSP.getHeldItemOffhand() instanceof ItemBlock

 

The problem is that the "getHeldItem" methods actually return ItemStack not Item. The method should really be named getHeldItemStackOffHand() instead.

 

So you simply have to get the Item from the Itemstack, so add .getItem() at the end. like:

    playerSP.getHeldItemOffhand().getItem() instanceof ItemBlock

Edited by jabelar
  • Like 1

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

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



×
×
  • Create New...

Important Information

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