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.