clean up code and close #253

This commit is contained in:
Bella 2020-01-15 09:41:44 -05:00
parent aa87a288bf
commit 9111966a40
1 changed files with 80 additions and 104 deletions

View File

@ -12,7 +12,6 @@ import net.minecraft.block.BlockObsidian;
import net.minecraft.block.state.IBlockState;
import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemStack;
import net.minecraft.network.Packet;
import net.minecraft.network.play.client.CPacketAnimation;
import net.minecraft.network.play.client.CPacketEntityAction;
import net.minecraft.network.play.client.CPacketEntityAction.Action;
@ -33,23 +32,21 @@ import net.minecraft.util.math.Vec3d;
*/
@Module.Info(name = "Surround", category = Module.Category.COMBAT, description = "Surrounds you with obsidian")
public class Surround extends Module {
//private final Vec3d[] surroundTargetsCritical = new Vec3d[]{new Vec3d(0.0D, 0.0D, 0.0D), new Vec3d(1.0D, 1.0D, 0.0D), new Vec3d(0.0D, 1.0D, 1.0D), new Vec3d(-1.0D, 1.0D, 0.0D), new Vec3d(0.0D, 1.0D, -1.0D)};
private Setting toggleable = this.register(Settings.b("Toggleable", true));
private Setting spoofRotations = this.register(Settings.b("Spoof Rotations", true));
private Setting spoofHotbar = this.register(Settings.b("Spoof Hotbar", true));
private Setting<Double> blockPerTick = this.register(Settings.doubleBuilder("Blocks per Tick").withMinimum(1.0).withValue(4.0).withMaximum(10.0).build());
private Setting<Boolean> autoDisable = register(Settings.b("Auto Disable", false));
private Setting<Boolean> spoofRotations = register(Settings.b("Spoof Rotations", true));
private Setting<Boolean> spoofHotbar = register(Settings.b("Spoof Hotbar", true));
private Setting<Double> blockPerTick = register(Settings.doubleBuilder("Blocks per Tick").withMinimum(1.0).withValue(4.0).withMaximum(10.0).build());
private Setting<DebugMsgs> debugMsgs = register(Settings.e("Debug Messages", DebugMsgs.IMPORTANT));
private Setting<AutoCenter> autoCenter = register(Settings.e("Auto Center", AutoCenter.TP));
private final Vec3d[] surroundTargets = new Vec3d[]{new Vec3d(0.0D, 0.0D, 0.0D), new Vec3d(1.0D, 1.0D, 0.0D), new Vec3d(0.0D, 1.0D, 1.0D), new Vec3d(-1.0D, 1.0D, 0.0D), new Vec3d(0.0D, 1.0D, -1.0D), new Vec3d(1.0D, 0.0D, 0.0D), new Vec3d(0.0D, 0.0D, 1.0D), new Vec3d(-1.0D, 0.0D, 0.0D), new Vec3d(0.0D, 0.0D, -1.0D), new Vec3d(1.0D, 1.0D, 0.0D), new Vec3d(0.0D, 1.0D, 1.0D), new Vec3d(-1.0D, 1.0D, 0.0D), new Vec3d(0.0D, 1.0D, -1.0D)};
private final Vec3d[] surroundTargetsFull = new Vec3d[]{new Vec3d(0.0D, 0.0D, 0.0D), new Vec3d(1.0D, 1.0D, 0.0D), new Vec3d(0.0D, 1.0D, 1.0D), new Vec3d(-1.0D, 1.0D, 0.0D), new Vec3d(0.0D, 1.0D, -1.0D), new Vec3d(1.0D, 0.0D, 0.0D), new Vec3d(0.0D, 0.0D, 1.0D), new Vec3d(-1.0D, 0.0D, 0.0D), new Vec3d(0.0D, 0.0D, -1.0D), new Vec3d(1.0D, 1.0D, 0.0D), new Vec3d(0.0D, 1.0D, 1.0D), new Vec3d(-1.0D, 1.0D, 0.0D), new Vec3d(0.0D, 1.0D, -1.0D)};
private Vec3d playerPos;
private BlockPos basePos;
private int offsetStep = 0;
private int playerHotbarSlot = -1;
private int lastHotbarSlot = -1;
private Vec3d playerPos;
private enum DebugMsgs {
NONE, IMPORTANT, ALL
}
@ -58,32 +55,32 @@ public class Surround extends Module {
}
public void onUpdate() {
if (!this.isDisabled() && mc.player != null && !ModuleManager.isModuleEnabled("Freecam")) {
if (this.offsetStep == 0) {
this.basePos = (new BlockPos(mc.player.getPositionVector())).down();
this.playerHotbarSlot = Wrapper.getPlayer().inventory.currentItem;
if (!isDisabled() && mc.player != null && !ModuleManager.isModuleEnabled("Freecam")) {
if (offsetStep == 0) {
basePos = (new BlockPos(mc.player.getPositionVector())).down();
playerHotbarSlot = Wrapper.getPlayer().inventory.currentItem;
if (debugMsgs.getValue().equals(DebugMsgs.ALL)) {
Command.sendChatMessage("[Surround] Starting Loop, current Player Slot: " + this.playerHotbarSlot);
Command.sendChatMessage("[Surround] Starting Loop, current Player Slot: " + playerHotbarSlot);
}
if (!(Boolean) this.spoofHotbar.getValue()) {
this.lastHotbarSlot = mc.player.inventory.currentItem;
if (!spoofHotbar.getValue()) {
lastHotbarSlot = mc.player.inventory.currentItem;
}
}
for (int i = 0; i < (int) Math.floor(this.blockPerTick.getValue()); ++i) {
for (int i = 0; i < (int) Math.floor(blockPerTick.getValue()); ++i) {
if (debugMsgs.getValue().equals(DebugMsgs.ALL)) {
Command.sendChatMessage("[Surround] Loop iteration: " + this.offsetStep);
Command.sendChatMessage("[Surround] Loop iteration: " + offsetStep);
}
if (this.offsetStep >= this.surroundTargets.length) {
this.endLoop();
if (offsetStep >= surroundTargets.length) {
endLoop();
return;
}
Vec3d offset = this.surroundTargets[this.offsetStep];
this.placeBlock(new BlockPos(this.basePos.add(offset.x, offset.y, offset.z)));
++this.offsetStep;
Vec3d offset = surroundTargets[offsetStep];
placeBlock(new BlockPos(basePos.add(offset.x, offset.y, offset.z)));
++offsetStep;
}
}
@ -103,50 +100,51 @@ public class Surround extends Module {
double getDst(Vec3d vec) {
return playerPos.distanceTo(vec);
}
/* End of Autocenter */
public void onEnable() {
if (mc.player == null) this.disable();
if (mc.player == null) return;
else if (debugMsgs.getValue().equals(DebugMsgs.ALL)) Command.sendChatMessage("[Surround] Enabling");
/* Autocenter */
BlockPos centerPos = mc.player.getPosition();
playerPos = mc.player.getPositionVector();
if (mc.player != null) {
BlockPos centerPos = mc.player.getPosition();
playerPos = mc.player.getPositionVector();
double y = centerPos.getY();
double x = centerPos.getX();
double z = centerPos.getZ();
double y = centerPos.getY(); double x = centerPos.getX(); double z = centerPos.getZ();
final Vec3d plusPlus = new Vec3d(x + 0.5, y, z + 0.5);
final Vec3d plusMinus = new Vec3d(x + 0.5, y, z - 0.5);
final Vec3d minusMinus = new Vec3d(x - 0.5, y, z - 0.5);
final Vec3d minusPlus = new Vec3d(x - 0.5, y, z + 0.5);
final Vec3d plusPlus = new Vec3d(x + 0.5, y, z + 0.5);
final Vec3d plusMinus = new Vec3d(x + 0.5, y, z - 0.5);
final Vec3d minusMinus = new Vec3d(x-0.5, y, z-0.5);
final Vec3d minusPlus = new Vec3d(x-0.5, y, z+0.5);
if (autoCenter.getValue().equals(AutoCenter.TP)) {
if (getDst(plusPlus) < getDst(plusMinus) && getDst(plusPlus) < getDst(minusMinus) && getDst(plusPlus) < getDst(minusPlus)) {
x = centerPos.getX() + 0.5;
z = centerPos.getZ() + 0.5;
centerPlayer(x, y, z);
} if (getDst(plusMinus) < getDst(plusPlus) && getDst(plusMinus) < getDst(minusMinus) && getDst(plusMinus) < getDst(minusPlus)) {
x = centerPos.getX() + 0.5;
z = centerPos.getZ() - 0.5;
centerPlayer(x, y, z);
} if (getDst(minusMinus) < getDst(plusPlus) && getDst(minusMinus) < getDst(plusMinus) && getDst(minusMinus) < getDst(minusPlus)) {
x = centerPos.getX() - 0.5;
z = centerPos.getZ() - 0.5;
centerPlayer(x, y, z);
} if (getDst(minusPlus) < getDst(plusPlus) && getDst(minusPlus) < getDst(plusMinus) && getDst(minusPlus) < getDst(minusMinus)) {
x = centerPos.getX() - 0.5;
z = centerPos.getZ() + 0.5;
centerPlayer(x, y, z);
}
}
/* End of Autocenter*/
if (autoCenter.getValue().equals(AutoCenter.TP)) {
if (getDst(plusPlus) < getDst(plusMinus) && getDst(plusPlus) < getDst(minusMinus) && getDst(plusPlus) < getDst(minusPlus) ) {
x = centerPos.getX()+0.5;
z = centerPos.getZ()+0.5;
centerPlayer(x,y,z);
playerHotbarSlot = Wrapper.getPlayer().inventory.currentItem;
lastHotbarSlot = -1;
if (debugMsgs.getValue().equals(DebugMsgs.ALL)) {
Command.sendChatMessage("[Surround] Saving initial Slot = " + playerHotbarSlot);
}
if (getDst(plusMinus) < getDst(plusPlus) && getDst(plusMinus) < getDst(minusMinus) && getDst(plusMinus) < getDst(minusPlus) ) {
x = centerPos.getX()+0.5;
z = centerPos.getZ()-0.5;
centerPlayer(x,y,z);
}
if (getDst(minusMinus) < getDst(plusPlus) && getDst(minusMinus) < getDst(plusMinus) && getDst(minusMinus) < getDst(minusPlus) ) {
x = centerPos.getX()-0.5;
z = centerPos.getZ()-0.5;
centerPlayer(x,y,z);
}
if (getDst(minusPlus) < getDst(plusPlus) && getDst(minusPlus) < getDst(plusMinus) && getDst(minusPlus) < getDst(minusMinus) ) {
x = centerPos.getX()-0.5;
z = centerPos.getZ()+0.5;
centerPlayer(x,y,z);
}
}
/* End of Autocenter*/
this.playerHotbarSlot = Wrapper.getPlayer().inventory.currentItem;
this.lastHotbarSlot = -1;
if (debugMsgs.getValue().equals(DebugMsgs.ALL)) {
Command.sendChatMessage("[Surround] Saving initial Slot = " + this.playerHotbarSlot);
}
}
@ -156,45 +154,39 @@ public class Surround extends Module {
Command.sendChatMessage("[Surround] Disabling");
}
if (this.lastHotbarSlot != this.playerHotbarSlot && this.playerHotbarSlot != -1) {
if (debugMsgs.getValue().equals(DebugMsgs.ALL)) {
//Command.sendChatMessage("[Surround] Setting Slot to = " + this.playerHotbarSlot);
}
if ((Boolean) this.spoofHotbar.getValue()) {
mc.player.connection.sendPacket(new CPacketHeldItemChange(this.playerHotbarSlot));
if (lastHotbarSlot != playerHotbarSlot && playerHotbarSlot != -1) {
if (spoofHotbar.getValue()) {
mc.player.connection.sendPacket(new CPacketHeldItemChange(playerHotbarSlot));
} else {
Wrapper.getPlayer().inventory.currentItem = this.playerHotbarSlot;
Wrapper.getPlayer().inventory.currentItem = playerHotbarSlot;
}
}
this.playerHotbarSlot = -1;
this.lastHotbarSlot = -1;
playerHotbarSlot = -1;
lastHotbarSlot = -1;
}
}
private void endLoop() {
this.offsetStep = 0;
offsetStep = 0;
if (debugMsgs.getValue().equals(DebugMsgs.ALL)) {
Command.sendChatMessage("[Surround] Ending Loop");
}
if (this.lastHotbarSlot != this.playerHotbarSlot && this.playerHotbarSlot != -1) {
if (lastHotbarSlot != playerHotbarSlot && playerHotbarSlot != -1) {
if (debugMsgs.getValue().equals(DebugMsgs.ALL)) {
Command.sendChatMessage("[Surround] Setting Slot back to = " + this.playerHotbarSlot);
Command.sendChatMessage("[Surround] Setting Slot back to = " + playerHotbarSlot);
}
if ((Boolean) this.spoofHotbar.getValue()) {
mc.player.connection.sendPacket(new CPacketHeldItemChange(this.playerHotbarSlot));
if (spoofHotbar.getValue()) {
mc.player.connection.sendPacket(new CPacketHeldItemChange(playerHotbarSlot));
} else {
Wrapper.getPlayer().inventory.currentItem = this.playerHotbarSlot;
Wrapper.getPlayer().inventory.currentItem = playerHotbarSlot;
}
this.lastHotbarSlot = this.playerHotbarSlot;
lastHotbarSlot = playerHotbarSlot;
}
if (!(Boolean) this.toggleable.getValue()) {
this.disable();
if (autoDisable.getValue()) {
disable();
}
}
@ -204,20 +196,15 @@ public class Surround extends Module {
if (debugMsgs.getValue().equals(DebugMsgs.ALL)) {
Command.sendChatMessage("[Surround] Block is already placed, skipping");
}
} else if (!BlockInteractionHelper.checkForNeighbours(blockPos)) {
if (debugMsgs.getValue().equals(DebugMsgs.ALL)) {
Command.sendChatMessage("[Surround] !checkForNeighbours(blockPos), disabling! ");
}
} else if (!BlockInteractionHelper.checkForNeighbours(blockPos) && debugMsgs.getValue().equals(DebugMsgs.ALL)) {
Command.sendChatMessage("[Surround] !checkForNeighbours(blockPos), disabling! ");
} else {
this.placeBlockExecute(blockPos);
placeBlockExecute(blockPos);
}
}
private int findObiInHotbar() {
int slot = -1;
for (int i = 0; i < 9; ++i) {
ItemStack stack = Wrapper.getPlayer().inventory.getStackInSlot(i);
if (stack != ItemStack.EMPTY && stack.getItem() instanceof ItemBlock) {
@ -228,17 +215,14 @@ public class Surround extends Module {
}
}
}
return slot;
}
public void placeBlockExecute(BlockPos pos) {
Vec3d eyesPos = new Vec3d(Wrapper.getPlayer().posX, Wrapper.getPlayer().posY + (double) Wrapper.getPlayer().getEyeHeight(), Wrapper.getPlayer().posZ);
EnumFacing[] var3 = EnumFacing.values();
int var4 = var3.length;
for (int var5 = 0; var5 < var4; ++var5) {
EnumFacing side = var3[var5];
for (EnumFacing side : var3) {
BlockPos neighbor = pos.offset(side);
EnumFacing side2 = side.getOpposite();
if (!canBeClicked(neighbor)) {
@ -248,46 +232,40 @@ public class Surround extends Module {
} else {
Vec3d hitVec = (new Vec3d(neighbor)).add(0.5D, 0.5D, 0.5D).add((new Vec3d(side2.getDirectionVec())).scale(0.5D));
if (eyesPos.squareDistanceTo(hitVec) <= 18.0625D) {
if ((Boolean) this.spoofRotations.getValue()) {
if (spoofRotations.getValue()) {
faceVectorPacketInstant(hitVec);
}
boolean needSneak = false;
Block blockBelow = mc.world.getBlockState(neighbor).getBlock();
if (BlockInteractionHelper.blackList.contains(blockBelow) || BlockInteractionHelper.shulkerList.contains(blockBelow)) {
if (debugMsgs.getValue().equals(DebugMsgs.IMPORTANT)) {
Command.sendChatMessage("[Surround] Sneak enabled!");
}
needSneak = true;
}
if (needSneak) {
mc.player.connection.sendPacket(new CPacketEntityAction(mc.player, Action.START_SNEAKING));
}
int obiSlot = this.findObiInHotbar();
int obiSlot = findObiInHotbar();
if (obiSlot == -1) {
if (debugMsgs.getValue().equals(DebugMsgs.IMPORTANT)) {
Command.sendChatMessage("[Surround] No Obi in Hotbar, disabling!");
}
this.disable();
disable();
return;
}
if (this.lastHotbarSlot != obiSlot) {
if (lastHotbarSlot != obiSlot) {
if (debugMsgs.getValue().equals(DebugMsgs.ALL)) {
Command.sendChatMessage("[Surround] Setting Slot to Obi at = " + obiSlot);
}
if ((Boolean) this.spoofHotbar.getValue()) {
if (spoofHotbar.getValue()) {
mc.player.connection.sendPacket(new CPacketHeldItemChange(obiSlot));
} else {
Wrapper.getPlayer().inventory.currentItem = obiSlot;
}
this.lastHotbarSlot = obiSlot;
lastHotbarSlot = obiSlot;
}
mc.playerController.processRightClickBlock(Wrapper.getPlayer(), mc.world, neighbor, side2, hitVec, EnumHand.MAIN_HAND);
@ -296,10 +274,8 @@ public class Surround extends Module {
if (debugMsgs.getValue().equals(DebugMsgs.IMPORTANT)) {
Command.sendChatMessage("[Surround] Sneak disabled!");
}
mc.player.connection.sendPacket(new CPacketEntityAction(mc.player, Action.STOP_SNEAKING));
}
return;
}