- Joined
- Jul 11, 2020
- Messages
- 0
- Reaction score
- 25
- Points
- 0
The only thing I can't bypass, please give any tips
Code:
Timer timer = new Timer();
boolean fight;
@Override
public void onEvent(Event event) {
if (event instanceof EventUpdate) {
EventUpdate e = (EventUpdate) event;
if (getEntity() == null) return;
if (!isInFOV(getEntity())) return;
if (e.isPre()) {
if (!fight && (mc.thePlayer.inventory.getCurrentItem() != null) && ((mc.thePlayer.inventory.getCurrentItem().getItem() instanceof ItemSword))) {
// mc.thePlayer.setItemInUse(mc.thePlayer.getCurrentEquippedItem(), 71999);
}
faceEntity(e, getEntity());
} else {
if (mc.thePlayer.isBlocking()) {
// mc.thePlayer.sendQueue.addToSendQueue(new C07PacketPlayerDigging(C07PacketPlayerDigging.Action.RELEASE_USE_ITEM, BlockPos.ORIGIN, EnumFacing.DOWN));
}
if (timer.delay(1000 / MathUtils.randomize(8, 12))) {
if (MathUtils.randomize(0, 10) != 1) {
mc.thePlayer.swingItem();
if (mc.thePlayer.getDistanceToEntity(getEntity()) > 4.5F) return;
fight = true;
mc.thePlayer.sendQueue.addToSendQueue(new C02PacketUseEntity(getEntity(), C02PacketUseEntity.Action.ATTACK));
fight = false;
}
timer.reset();
}
}
}
}
private boolean isInFOV(Entity entity) {
int fov = 180;
return RotationUtils.getYawChange(entity.posX, entity.posZ) <= fov && RotationUtils.getPitchChange(entity, entity.posY) <= fov;
}
private EntityLivingBase getEntity() {
List<EntityLivingBase> load = new ArrayList<>();
for (final Object o : mc.thePlayer.worldObj.loadedEntityList) {
if (!(o instanceof EntityLivingBase)) continue;
final EntityLivingBase entity = (EntityLivingBase) o;
if (entity.isDead) continue;
if (!entity.isEntityAlive()) continue;
if (entity == mc.thePlayer) continue;
load.add(entity);
}
load.sort((o1, o2) -> (int) (o1.getDistanceToEntity(mc.thePlayer) - o2.getDistanceToEntity(mc.thePlayer)));
if (load.get(0) != null) {
return load.get(0);
} else {
return null;
}
}
public static void faceEntity(EventUpdate eventUpdate, Entity entity) {
double diffX = entity.posX - mc.thePlayer.posX;
double diffZ = entity.posZ - mc.thePlayer.posZ;
double diffY;
if (entity instanceof EntityLivingBase) {
final EntityLivingBase elb = (EntityLivingBase) entity;
diffY = (elb.posY + elb.getEyeHeight()) - (mc.thePlayer.posY + mc.thePlayer.getEyeHeight());
} else {
diffY = ((entity.getBoundingBox().minY + entity.getBoundingBox().maxY) / 2.0D) - (mc.thePlayer.posY + mc.thePlayer.getEyeHeight());
}
double dist = MathHelper.sqrt_double((diffX * diffX) + (diffZ * diffZ));
float yaw = (float) ((Math.atan2(diffZ, diffX) * 180.0D) / Math.PI) - 90.0F;
float pitch = (float) -((Math.atan2(diffY, dist) * 180.0D) / Math.PI);
eventUpdate.setYaw(randomize(5, 0, mc.thePlayer.rotationYaw + MathHelper.wrapAngleTo180_float(yaw - mc.thePlayer.rotationYaw), 180F));
eventUpdate.setPitch(randomize(5, 0, mc.thePlayer.rotationPitch + MathHelper.wrapAngleTo180_float(pitch - mc.thePlayer.rotationPitch), 90F));
if (mc.gameSettings.thirdPersonView != 0) {
mc.thePlayer.rotationYawHead = yaw;
}
}
private static float randomize(int max, int min, float f, float maxF) {
if (f <= maxF + max) {
f += MathUtils.randomize(min, max);
} else {
f -= MathUtils.randomize(min, max);
}
return f;
}
}
Last edited by a moderator: