Thread: AutoSword

Results 1 to 4 of 4
  1. #1
    Caezer99's Avatar
    Join Date
    Dec 2011
    Gender
    male
    Location
    127.0.0.1
    Posts
    577
    Reputation
    10
    Thanks
    1,243

    AutoSword

    Ok, since I don't know how to use getDamageVsEntity in Minecraft.
    I came up with this for my autosword.

    Code:
    	private void getSword() {
    		boolean isSwordFound = false;
    		for (int slot = 44; slot >= 9; slot--) {
    			ItemStack is = getPlayer().inventoryContainer.getSlot(slot)
    					.getStack();
    			if (is != null) {
    				if (!isSwordFound) {
    					if (slot >= 36 && slot <= 44) {
    						if (is.getItem() == this.diamondSword) {
    							getPlayer().inventory.currentItem = slot - 36;
    							getMinecraft().playerController.updateController();
    							isSwordFound = true;
    							break;
    						} else if (is.getItem() == this.diamondSword) {
    							getMinecraft().playerController.windowClick(0,
    									slot, 0, 0, getPlayer());
    							getMinecraft().playerController.windowClick(0, 37,
    									0, 0, getPlayer());
    						} else {
    							if (is.getItem() == this.goldenSword) {
    								getPlayer().inventory.currentItem = slot - 36;
    								getMinecraft().playerController
    										.updateController();
    								isSwordFound = true;
    								break;
    							} else if (is.getItem() == this.goldenSword) {
    								getMinecraft().playerController.windowClick(0,
    										slot, 0, 0, getPlayer());
    								getMinecraft().playerController.windowClick(0,
    										37, 0, 0, getPlayer());
    							} else {
    								if (is.getItem() == this.ironSword) {
    									getPlayer().inventory.currentItem = slot - 36;
    									getMinecraft().playerController
    											.updateController();
    									isSwordFound = true;
    									break;
    								} else if (is.getItem() == this.ironSword) {
    									getMinecraft().playerController
    											.windowClick(0, slot, 0, 0,
    													getPlayer());
    									getMinecraft().playerController
    											.windowClick(0, 37, 0, 0,
    													getPlayer());
    								} else {
    									if (is.getItem() == this.stoneSword) {
    										getPlayer().inventory.currentItem = slot - 36;
    										getMinecraft().playerController
    												.updateController();
    										isSwordFound = true;
    										break;
    									} else if (is.getItem() == this.stoneSword) {
    										getMinecraft().playerController
    												.windowClick(0, slot, 0, 0,
    														getPlayer());
    										getMinecraft().playerController
    												.windowClick(0, 37, 0, 0,
    														getPlayer());
    									} else {
    										if (is.getItem() == this.woodenSword) {
    											getPlayer().inventory.currentItem = slot - 36;
    											getMinecraft().playerController
    													.updateController();
    											isSwordFound = true;
    											break;
    										} else if (is.getItem() == this.woodenSword) {
    											getMinecraft().playerController
    													.windowClick(0, slot, 0, 0,
    															getPlayer());
    											getMinecraft().playerController
    													.windowClick(0, 37, 0, 0,
    															getPlayer());
    										}
    									}
    								}
    							}
    						}
    					}
    				} else {
    
    				}
    			}
    		}
    	}
    Is there a better way for AutoSword ?
    Please help me

    Also, I know this is a bad way to do it.
    And this also gets the first sword in the hotbar from the right to left. Regarding whether it's a wooden sword or iron sword.
    I've tried doing a nest but it still gets the first sword.
    Last edited by Caezer99; 03-08-2014 at 01:53 AM.


    Mess with the best, die like the rest.


  2. #2
    godshawk's Avatar
    Join Date
    Mar 2013
    Gender
    female
    Location
    root@google ~#
    Posts
    90
    Reputation
    14
    Thanks
    134
    My Mood
    Crappy
    Code:
    isSwordFound = true;
    break;
    Now what could THIS possibly be...?

    PM me if you need something.

    DOGE: DLunanNyoE7wmiiKQMVXpSxcQag3eN7kB5

  3. #3
    RandomAmazingGuy's Avatar
    Join Date
    Aug 2012
    Gender
    male
    Posts
    113
    Reputation
    14
    Thanks
    4,737
    My Mood
    Amused
    Two main things:

    The new getDamageVsEntity is
    Code:
    ItemSword.func_150931_i();
    You need an ItemSword for this, so just cast to it.

    Second, use instanceof ItemSword instead of looking at every type of sword.

    It should be something like this:
    Code:
    		 float curItemDamage = 1;
    		 int newItemSlot = Base.getPlayer().inventory.currentItem;
    		 
    		 //Loop through all slots
    		 for (int slot = 0; slot < 9; slot++) 
    		 {
    			 ItemStack currentStack = Base.getPlayer().inventory.mainInventory[slot];
    			 
    			 //Skip empty slots
    			 if(currentStack == null){
    				 continue;
    			 }
    
    			 if(currentStack.getItem() instanceof ItemSword){
    				 ItemSword is = (ItemSword) currentStack.getItem();
    				 
    				 //The new getDamageVsEntity(), check it's declaration
    				 float newItemDamage = is.func_150931_i();
    				 
    				 if(newItemDamage > curItemDamage){
    					 newItemSlot = slot;
    					 curItemDamage = newItemDamage;
    				 }
    			 }
    		 }
    		 switchToSlot(newItemSlot);

  4. #4
    Caezer99's Avatar
    Join Date
    Dec 2011
    Gender
    male
    Location
    127.0.0.1
    Posts
    577
    Reputation
    10
    Thanks
    1,243
    Quote Originally Posted by RandomAmazingGuy View Post
    Two main things:

    The new getDamageVsEntity is
    Code:
    ItemSword.func_150931_i();
    You need an ItemSword for this, so just cast to it.

    Second, use instanceof ItemSword instead of looking at every type of sword.

    It should be something like this:
    Code:
    		 float curItemDamage = 1;
    		 int newItemSlot = Base.getPlayer().inventory.currentItem;
    		 
    		 //Loop through all slots
    		 for (int slot = 0; slot < 9; slot++) 
    		 {
    			 ItemStack currentStack = Base.getPlayer().inventory.mainInventory[slot];
    			 
    			 //Skip empty slots
    			 if(currentStack == null){
    				 continue;
    			 }
    
    			 if(currentStack.getItem() instanceof ItemSword){
    				 ItemSword is = (ItemSword) currentStack.getItem();
    				 
    				 //The new getDamageVsEntity(), check it's declaration
    				 float newItemDamage = is.func_150931_i();
    				 
    				 if(newItemDamage > curItemDamage){
    					 newItemSlot = slot;
    					 curItemDamage = newItemDamage;
    				 }
    			 }
    		 }
    		 switchToSlot(newItemSlot);
    Thank you so much. Let me try this. Previously when I used this, it doesn't seem to get Stone or Wooden swords.

    TESTED:
    YES it does not seem to work for wooden or stone swords.
    Last edited by Caezer99; 03-08-2014 at 04:44 PM.


    Mess with the best, die like the rest.