forked from RepoMirrors/kami-blue
AutoFeetPlace
This commit is contained in:
parent
6546cf9fe0
commit
ac9e373fed
|
@ -1,13 +1,17 @@
|
||||||
package me.zeroeightsix.kami.module.modules.combat;
|
package me.zeroeightsix.kami.module.modules.combat;
|
||||||
|
|
||||||
|
import com.mojang.realmsclient.gui.ChatFormatting;
|
||||||
|
import me.zeroeightsix.kami.command.Command;
|
||||||
import me.zeroeightsix.kami.module.Module;
|
import me.zeroeightsix.kami.module.Module;
|
||||||
import me.zeroeightsix.kami.module.ModuleManager;
|
import me.zeroeightsix.kami.module.ModuleManager;
|
||||||
import me.zeroeightsix.kami.setting.Setting;
|
import me.zeroeightsix.kami.setting.Setting;
|
||||||
import me.zeroeightsix.kami.setting.Settings;
|
import me.zeroeightsix.kami.setting.Settings;
|
||||||
import me.zeroeightsix.kami.util.BlockInteractionHelper;
|
import me.zeroeightsix.kami.util.BlockInteractionHelper;
|
||||||
import me.zeroeightsix.kami.util.Wrapper;
|
|
||||||
import net.minecraft.block.Block;
|
import net.minecraft.block.Block;
|
||||||
|
import net.minecraft.block.BlockAir;
|
||||||
|
import net.minecraft.block.BlockLiquid;
|
||||||
import net.minecraft.block.BlockObsidian;
|
import net.minecraft.block.BlockObsidian;
|
||||||
|
import net.minecraft.block.state.IBlockState;
|
||||||
import net.minecraft.entity.Entity;
|
import net.minecraft.entity.Entity;
|
||||||
import net.minecraft.entity.item.EntityItem;
|
import net.minecraft.entity.item.EntityItem;
|
||||||
import net.minecraft.entity.item.EntityXPOrb;
|
import net.minecraft.entity.item.EntityXPOrb;
|
||||||
|
@ -20,40 +24,56 @@ import net.minecraft.util.math.AxisAlignedBB;
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
import net.minecraft.util.math.Vec3d;
|
import net.minecraft.util.math.Vec3d;
|
||||||
|
|
||||||
import static me.zeroeightsix.kami.util.BlockInteractionHelper.*;
|
import static me.zeroeightsix.kami.util.BlockInteractionHelper.canBeClicked;
|
||||||
|
import static me.zeroeightsix.kami.util.BlockInteractionHelper.faceVectorPacketInstant;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created 13 August 2019 by hub
|
* @author hub
|
||||||
* Updated 24 November 2019 by hub
|
* @since 2019-8-13
|
||||||
*/
|
*/
|
||||||
@Module.Info(name = "AutoFeetPlace", category = Module.Category.COMBAT)
|
@Module.Info(name = "AutoFeetPlace", category = Module.Category.COMBAT)
|
||||||
public class AutoFeetPlace extends Module {
|
public class AutoFeetPlace extends Module {
|
||||||
|
|
||||||
private final Vec3d[] surroundTargets = {
|
private Setting<Mode> mode = register(Settings.e("Mode", Mode.FULL));
|
||||||
new Vec3d(1, 0, 0),
|
|
||||||
new Vec3d(0, 0, 1),
|
|
||||||
new Vec3d(-1, 0, 0),
|
|
||||||
new Vec3d(0, 0, -1),
|
|
||||||
new Vec3d(1, -1, 0),
|
|
||||||
new Vec3d(0, -1, 1),
|
|
||||||
new Vec3d(-1, -1, 0),
|
|
||||||
new Vec3d(0, -1, -1),
|
|
||||||
new Vec3d(0, -1, 0)
|
|
||||||
};
|
|
||||||
|
|
||||||
private Setting<Boolean> triggerable = register(Settings.b("Triggerable", true));
|
private Setting<Boolean> triggerable = register(Settings.b("Triggerable", true));
|
||||||
private Setting<Integer> timeoutTicks = register(Settings.integerBuilder("TimeoutTicks").withMinimum(1).withValue(20).withMaximum(100).withVisibility(b -> triggerable.getValue()).build());
|
private Setting<Integer> timeoutTicks = register(Settings.integerBuilder("TimeoutTicks").withMinimum(1).withValue(40).withMaximum(100).withVisibility(b -> triggerable.getValue()).build());
|
||||||
private Setting<Integer> blocksPerTick = register(Settings.integerBuilder("Blocks per Tick").withMinimum(1).withValue(4).withMaximum(9).build());
|
private Setting<Integer> blocksPerTick = register(Settings.integerBuilder("BlocksPerTick").withMinimum(1).withValue(4).withMaximum(9).build());
|
||||||
|
private Setting<Integer> tickDelay = register(Settings.integerBuilder("TickDelay").withMinimum(0).withValue(0).withMaximum(10).build());
|
||||||
private Setting<Boolean> rotate = register(Settings.b("Rotate", true));
|
private Setting<Boolean> rotate = register(Settings.b("Rotate", true));
|
||||||
|
private Setting<Boolean> infoMessage = register(Settings.b("InfoMessage", false));
|
||||||
|
|
||||||
|
private int offsetStep = 0;
|
||||||
|
private int delayStep = 0;
|
||||||
|
|
||||||
private int playerHotbarSlot = -1;
|
private int playerHotbarSlot = -1;
|
||||||
private int lastHotbarSlot = -1;
|
private int lastHotbarSlot = -1;
|
||||||
private int offsetStep = 0;
|
|
||||||
|
|
||||||
private int totalTickRuns = 0;
|
|
||||||
|
|
||||||
private boolean isSneaking = false;
|
private boolean isSneaking = false;
|
||||||
|
|
||||||
|
private int totalTicksRunning = 0;
|
||||||
|
private boolean firstRun;
|
||||||
|
private boolean missingObiDisable = false;
|
||||||
|
|
||||||
|
private static EnumFacing getPlaceableSide(BlockPos pos) {
|
||||||
|
|
||||||
|
for (EnumFacing side : EnumFacing.values()) {
|
||||||
|
|
||||||
|
BlockPos neighbour = pos.offset(side);
|
||||||
|
|
||||||
|
if (!mc.world.getBlockState(neighbour).getBlock().canCollideCheck(mc.world.getBlockState(neighbour), false)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
IBlockState blockState = mc.world.getBlockState(neighbour);
|
||||||
|
if (!blockState.getMaterial().isReplaceable()) {
|
||||||
|
return side;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onEnable() {
|
protected void onEnable() {
|
||||||
|
|
||||||
|
@ -62,8 +82,10 @@ public class AutoFeetPlace extends Module {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
firstRun = true;
|
||||||
|
|
||||||
// save initial player hand
|
// save initial player hand
|
||||||
playerHotbarSlot = Wrapper.getPlayer().inventory.currentItem;
|
playerHotbarSlot = mc.player.inventory.currentItem;
|
||||||
lastHotbarSlot = -1;
|
lastHotbarSlot = -1;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -77,7 +99,7 @@ public class AutoFeetPlace extends Module {
|
||||||
|
|
||||||
// load initial player hand
|
// load initial player hand
|
||||||
if (lastHotbarSlot != playerHotbarSlot && playerHotbarSlot != -1) {
|
if (lastHotbarSlot != playerHotbarSlot && playerHotbarSlot != -1) {
|
||||||
Wrapper.getPlayer().inventory.currentItem = playerHotbarSlot;
|
mc.player.inventory.currentItem = playerHotbarSlot;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isSneaking) {
|
if (isSneaking) {
|
||||||
|
@ -88,6 +110,8 @@ public class AutoFeetPlace extends Module {
|
||||||
playerHotbarSlot = -1;
|
playerHotbarSlot = -1;
|
||||||
lastHotbarSlot = -1;
|
lastHotbarSlot = -1;
|
||||||
|
|
||||||
|
missingObiDisable = false;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -97,43 +121,52 @@ public class AutoFeetPlace extends Module {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (triggerable.getValue() && totalTickRuns >= timeoutTicks.getValue()) {
|
if (triggerable.getValue() && totalTicksRunning >= timeoutTicks.getValue()) {
|
||||||
totalTickRuns = 0;
|
totalTicksRunning = 0;
|
||||||
this.disable();
|
this.disable();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!firstRun) {
|
||||||
|
if (delayStep < tickDelay.getValue()) {
|
||||||
|
delayStep++;
|
||||||
|
return;
|
||||||
|
} else {
|
||||||
|
delayStep = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (firstRun) {
|
||||||
|
firstRun = false;
|
||||||
|
}
|
||||||
|
|
||||||
int blocksPlaced = 0;
|
int blocksPlaced = 0;
|
||||||
|
|
||||||
while (blocksPlaced < blocksPerTick.getValue()) {
|
while (blocksPlaced < blocksPerTick.getValue()) {
|
||||||
|
|
||||||
if (offsetStep >= surroundTargets.length) {
|
Vec3d[] offsetPattern = new Vec3d[0];
|
||||||
|
int maxSteps = 0;
|
||||||
|
|
||||||
|
if (mode.getValue().equals(Mode.FULL)) {
|
||||||
|
offsetPattern = Offsets.FULL;
|
||||||
|
maxSteps = Offsets.FULL.length;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (mode.getValue().equals(Mode.SURROUND)) {
|
||||||
|
offsetPattern = Offsets.SURROUND;
|
||||||
|
maxSteps = Offsets.SURROUND.length;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (offsetStep >= maxSteps) {
|
||||||
offsetStep = 0;
|
offsetStep = 0;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
BlockPos offsetPos = new BlockPos(surroundTargets[offsetStep]);
|
BlockPos offsetPos = new BlockPos(offsetPattern[offsetStep]);
|
||||||
BlockPos targetPos = new BlockPos(mc.player.getPositionVector()).add(offsetPos.x, offsetPos.y, offsetPos.z);
|
BlockPos targetPos = new BlockPos(mc.player.getPositionVector()).add(offsetPos.x, offsetPos.y, offsetPos.z);
|
||||||
|
|
||||||
boolean shouldTryToPlace = true;
|
if (placeBlock(targetPos)) {
|
||||||
|
blocksPlaced++;
|
||||||
// check if block is already placed
|
|
||||||
if (!Wrapper.getWorld().getBlockState(targetPos).getMaterial().isReplaceable()) {
|
|
||||||
shouldTryToPlace = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// check if entity blocks placing
|
|
||||||
for (Entity entity : mc.world.getEntitiesWithinAABBExcludingEntity(null, new AxisAlignedBB(targetPos))) {
|
|
||||||
if (!(entity instanceof EntityItem) && !(entity instanceof EntityXPOrb)) {
|
|
||||||
shouldTryToPlace = false;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (shouldTryToPlace) {
|
|
||||||
if (placeBlock(targetPos)) {
|
|
||||||
blocksPlaced++;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
offsetStep++;
|
offsetStep++;
|
||||||
|
@ -143,73 +176,88 @@ public class AutoFeetPlace extends Module {
|
||||||
if (blocksPlaced > 0) {
|
if (blocksPlaced > 0) {
|
||||||
|
|
||||||
if (lastHotbarSlot != playerHotbarSlot && playerHotbarSlot != -1) {
|
if (lastHotbarSlot != playerHotbarSlot && playerHotbarSlot != -1) {
|
||||||
Wrapper.getPlayer().inventory.currentItem = playerHotbarSlot;
|
mc.player.inventory.currentItem = playerHotbarSlot;
|
||||||
lastHotbarSlot = playerHotbarSlot;
|
lastHotbarSlot = playerHotbarSlot;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (isSneaking) {
|
||||||
|
mc.player.connection.sendPacket(new CPacketEntityAction(mc.player, CPacketEntityAction.Action.STOP_SNEAKING));
|
||||||
|
isSneaking = false;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
totalTickRuns++;
|
totalTicksRunning++;
|
||||||
|
|
||||||
|
if (missingObiDisable) {
|
||||||
|
missingObiDisable = false;
|
||||||
|
if (infoMessage.getValue()) {
|
||||||
|
Command.sendChatMessage("[AutoFeetPlace] " + ChatFormatting.RED + "Disabled" + ChatFormatting.RESET + ", Obsidian missing!");
|
||||||
|
}
|
||||||
|
this.disable();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean placeBlock(BlockPos pos) {
|
private boolean placeBlock(BlockPos pos) {
|
||||||
|
|
||||||
// check if block at pos is replaceable
|
// check if block is already placed
|
||||||
if (!mc.world.getBlockState(pos).getMaterial().isReplaceable()) {
|
Block block = mc.world.getBlockState(pos).getBlock();
|
||||||
|
if (!(block instanceof BlockAir) && !(block instanceof BlockLiquid)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// check if we have a block adjacent to blockpos to click at
|
// check if entity blocks placing
|
||||||
if (!checkForNeighbours(pos)) {
|
for (Entity entity : mc.world.getEntitiesWithinAABBExcludingEntity(null, new AxisAlignedBB(pos))) {
|
||||||
return false;
|
if (!(entity instanceof EntityItem) && !(entity instanceof EntityXPOrb)) {
|
||||||
}
|
|
||||||
|
|
||||||
for (EnumFacing side : EnumFacing.values()) {
|
|
||||||
|
|
||||||
BlockPos neighbor = pos.offset(side);
|
|
||||||
EnumFacing side2 = side.getOpposite();
|
|
||||||
|
|
||||||
// check if neighbor can be right clicked
|
|
||||||
if (!canBeClicked(neighbor)) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
int obiSlot = findObiInHotbar();
|
|
||||||
|
|
||||||
// check if any blocks were found
|
|
||||||
if (obiSlot == -1) {
|
|
||||||
this.disable();
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (lastHotbarSlot != obiSlot) {
|
|
||||||
Wrapper.getPlayer().inventory.currentItem = obiSlot;
|
|
||||||
lastHotbarSlot = obiSlot;
|
|
||||||
}
|
|
||||||
|
|
||||||
Block neighborPos = mc.world.getBlockState(neighbor).getBlock();
|
|
||||||
if (BlockInteractionHelper.blackList.contains(neighborPos) || BlockInteractionHelper.shulkerList.contains(neighborPos)) {
|
|
||||||
mc.player.connection.sendPacket(new CPacketEntityAction(mc.player, CPacketEntityAction.Action.START_SNEAKING));
|
|
||||||
isSneaking = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
Vec3d hitVec = new Vec3d(neighbor).add(0.5, 0.5, 0.5).add(new Vec3d(side2.getDirectionVec()).scale(0.5));
|
|
||||||
|
|
||||||
// fake rotation
|
|
||||||
if (rotate.getValue()) {
|
|
||||||
faceVectorPacketInstant(hitVec);
|
|
||||||
}
|
|
||||||
|
|
||||||
// place block
|
|
||||||
mc.playerController.processRightClickBlock(mc.player, mc.world, neighbor, side2, hitVec, EnumHand.MAIN_HAND);
|
|
||||||
mc.player.swingArm(EnumHand.MAIN_HAND);
|
|
||||||
|
|
||||||
return true;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
EnumFacing side = getPlaceableSide(pos);
|
||||||
|
|
||||||
|
// check if we have a block adjacent to blockpos to click at
|
||||||
|
if (side == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
BlockPos neighbour = pos.offset(side);
|
||||||
|
EnumFacing opposite = side.getOpposite();
|
||||||
|
|
||||||
|
// check if neighbor can be right clicked
|
||||||
|
if (!canBeClicked(neighbour)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
Vec3d hitVec = new Vec3d(neighbour).add(0.5, 0.5, 0.5).add(new Vec3d(opposite.getDirectionVec()).scale(0.5));
|
||||||
|
Block neighbourBlock = mc.world.getBlockState(neighbour).getBlock();
|
||||||
|
|
||||||
|
int obiSlot = findObiInHotbar();
|
||||||
|
|
||||||
|
if (obiSlot == -1) {
|
||||||
|
missingObiDisable = true;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (lastHotbarSlot != obiSlot) {
|
||||||
|
mc.player.inventory.currentItem = obiSlot;
|
||||||
|
lastHotbarSlot = obiSlot;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!isSneaking && BlockInteractionHelper.blackList.contains(neighbourBlock) || BlockInteractionHelper.shulkerList.contains(neighbourBlock)) {
|
||||||
|
mc.player.connection.sendPacket(new CPacketEntityAction(mc.player, CPacketEntityAction.Action.START_SNEAKING));
|
||||||
|
isSneaking = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (rotate.getValue()) {
|
||||||
|
faceVectorPacketInstant(hitVec);
|
||||||
|
}
|
||||||
|
|
||||||
|
mc.playerController.processRightClickBlock(mc.player, mc.world, neighbour, opposite, hitVec, EnumHand.MAIN_HAND);
|
||||||
|
mc.player.swingArm(EnumHand.MAIN_HAND);
|
||||||
|
mc.rightClickDelayTimer = 4;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -220,7 +268,7 @@ public class AutoFeetPlace extends Module {
|
||||||
for (int i = 0; i < 9; i++) {
|
for (int i = 0; i < 9; i++) {
|
||||||
|
|
||||||
// filter out non-block items
|
// filter out non-block items
|
||||||
ItemStack stack = Wrapper.getPlayer().inventory.getStackInSlot(i);
|
ItemStack stack = mc.player.inventory.getStackInSlot(i);
|
||||||
|
|
||||||
if (stack == ItemStack.EMPTY || !(stack.getItem() instanceof ItemBlock)) {
|
if (stack == ItemStack.EMPTY || !(stack.getItem() instanceof ItemBlock)) {
|
||||||
continue;
|
continue;
|
||||||
|
@ -238,4 +286,35 @@ public class AutoFeetPlace extends Module {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private enum Mode {
|
||||||
|
SURROUND, FULL
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class Offsets {
|
||||||
|
|
||||||
|
private static final Vec3d[] SURROUND = {
|
||||||
|
new Vec3d(1, 0, 0),
|
||||||
|
new Vec3d(0, 0, 1),
|
||||||
|
new Vec3d(-1, 0, 0),
|
||||||
|
new Vec3d(0, 0, -1),
|
||||||
|
new Vec3d(1, -1, 0),
|
||||||
|
new Vec3d(0, -1, 1),
|
||||||
|
new Vec3d(-1, -1, 0),
|
||||||
|
new Vec3d(0, -1, -1)
|
||||||
|
};
|
||||||
|
|
||||||
|
private static final Vec3d[] FULL = {
|
||||||
|
new Vec3d(1, 0, 0),
|
||||||
|
new Vec3d(0, 0, 1),
|
||||||
|
new Vec3d(-1, 0, 0),
|
||||||
|
new Vec3d(0, 0, -1),
|
||||||
|
new Vec3d(1, -1, 0),
|
||||||
|
new Vec3d(0, -1, 1),
|
||||||
|
new Vec3d(-1, -1, 0),
|
||||||
|
new Vec3d(0, -1, -1),
|
||||||
|
new Vec3d(0, -1, 0)
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue