automount + rotations + armor hud element

This commit is contained in:
Jess H 2024-06-17 10:00:51 +01:00
parent d743896454
commit 7be74575a7
Signed by: UnixSystemV
GPG key ID: 9B21C50B68D67F19
4 changed files with 214 additions and 0 deletions

View file

@ -37,6 +37,7 @@ public class Setup {
AutoKill.INSTANCE.autoHit,
//AutoKill.INSTANCE.autoCrystal,
new AntiLevitation(),
new AutoMount(),
new AutoTotem(),
new AutoReconnect(),
new AutoRespawn(),

View file

@ -0,0 +1,58 @@
package de.com.baseband.client.feature.modules.ingame;
import de.com.baseband.client.event.events.MotionUpdateEvent;
import de.com.baseband.client.feature.Feature;
import de.com.baseband.client.feature.category.Ingame;
import de.com.baseband.client.util.interact.RotationUtil;
import net.minecraft.entity.Entity;
import net.minecraft.entity.item.EntityBoat;
import net.minecraft.entity.passive.*;
import net.minecraft.util.EnumHand;
import net.minecraft.util.math.Vec2f;
@Ingame
public class AutoMount extends Feature {
@Override
public String toString() {
return "AutoMount";
}
Entity entity = null;
public void preMotion(MotionUpdateEvent.Pre event) {
if (mc.player.getRidingEntity() != null)
return;
for (Entity e : mc.world.loadedEntityList) {
if (valid(e)) {
Vec2f rot = RotationUtil.getRotationTo(e.getPositionVector());
event.pitch = rot.y;
event.yaw = rot.x;
entity = e;
break;
}
}
}
public void postMotion(MotionUpdateEvent.Post event) {
if (mc.player.getRidingEntity() != null)
return;
if(entity != null) {
mc.playerController.interactWithEntity(mc.player, entity, EnumHand.MAIN_HAND);
entity = null;
}
}
boolean valid(Entity entity) {
return (entity instanceof EntityBoat
|| (entity instanceof EntityAnimal && ((EntityAnimal) entity).getGrowingAge() == 1
&& (entity instanceof EntityHorse
|| entity instanceof EntitySkeletonHorse
|| entity instanceof EntityDonkey
|| entity instanceof EntityMule
|| entity instanceof EntityPig && ((EntityPig) entity).getSaddled()
|| entity instanceof EntityLlama))) && mc.player.getDistance(entity) < 6;
}
}

View file

@ -19,7 +19,9 @@ import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.Gui;
import net.minecraft.client.gui.ScaledResolution;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.renderer.RenderItem;
import net.minecraft.entity.Entity;
import net.minecraft.item.ItemStack;
import net.minecraftforge.client.event.RenderGameOverlayEvent;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
@ -161,6 +163,9 @@ public class HUD extends Feature {
@Config("Text shadow")
public boolean textShadow = true;
@Config("Armor HUD")
public boolean armor = true;
@Config("Notification location")
@Description("Where to display notifications. Left and Right display the most recent at the top, Center displays the most recent at the bottom.")
public NotificationLocation nLocation = NotificationLocation.Left;
@ -203,6 +208,8 @@ public class HUD extends Feature {
}
}
private static final RenderItem itemRender = Minecraft.getMinecraft().getRenderItem();
@SubscribeEvent
public void text(RenderGameOverlayEvent.Text e) {
ScaledResolution sr = new ScaledResolution(mc);
@ -234,6 +241,43 @@ public class HUD extends Feature {
if(infoString.endsWith("\n")) infoString = infoString.substring(0, infoString.length() - 1);
}
if(armor) {
GlStateManager.enableTexture2D();
ScaledResolution resolution = new ScaledResolution(mc);
int i = resolution.getScaledWidth() / 2;
int iteration = 0;
int y = resolution.getScaledHeight() - 55 - (mc.player.isInWater() ? 10 : 0);
for (ItemStack is : mc.player.inventory.armorInventory) {
iteration++;
if (is.isEmpty()) continue;
int x = i - 90 + (9 - iteration) * 20 + 2;
GlStateManager.enableDepth();
itemRender.zLevel = 200F;
itemRender.renderItemAndEffectIntoGUI(is, x, y);
itemRender.renderItemOverlayIntoGUI(mc.fontRenderer, is, x, y, "");
itemRender.zLevel = 0F;
GlStateManager.enableTexture2D();
GlStateManager.disableLighting();
GlStateManager.disableDepth();
String s = is.getCount() > 1 ? is.getCount() + "" : "";
mc.fontRenderer.drawStringWithShadow(s, x + 19 - 2 - mc.fontRenderer.getStringWidth(s), y + 9, 0xffffff);
float green = ((float) is.getMaxDamage() - (float) is.getItemDamage()) / (float) is.getMaxDamage();
float red = 1 - green;
int dmg = 100 - (int) (red * 100);
mc.fontRenderer.drawStringWithShadow(dmg + "", x + 8 - mc.fontRenderer.getStringWidth(dmg + "") / 2, y - 11, toHex((int) (red * 255), (int) (green * 255), 0));
}
GlStateManager.enableDepth();
GlStateManager.disableLighting();
}
String initString = "§lBaseBand§r - \"" + BaseBand.buildString + "\" @ " + GitHash.GIT_HASH;
if(infoLoc == InfoLocation.TopLeft) {
initString += "\n" + infoString + "\n";
@ -311,6 +355,10 @@ public class HUD extends Feature {
}
}
public static int toHex(final int r, final int g, final int b) {
return 0xFF000000 | (r & 0xFF) << 16 | (g & 0xFF) << 8 | (b & 0xFF);
}
private void drawSizedBox(int x, int y, int sx, int sy, int color, boolean backwards) {
Gui.drawRect(x, y, x + sx, y + sy * (backwards ? -1 : 1), color);
}

View file

@ -0,0 +1,107 @@
package de.com.baseband.client.util.interact;
import net.minecraft.client.Minecraft;
import net.minecraft.client.entity.EntityPlayerSP;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.math.*;
//TODO: rewrite
// Sponsored by KAMI Blue
// https://github.com/kami-blue/client/blob/master/src/main/kotlin/org/kamiblue/client/util/math/RotationUtils.kt
public class RotationUtil {
private static final Minecraft mc = Minecraft.getMinecraft();
public static float[] getRotationToPos(BlockPos pos) {
double lengthXZ = Math.hypot(pos.getX(), pos.getZ());
double yaw = normalizeAngle(Math.toDegrees(Math.atan2(pos.getZ(), pos.getX())) - 90.0);
double pitch = normalizeAngle(Math.toDegrees(-Math.atan2(pos.getY(), lengthXZ)));
return new float[] {(float) yaw, (float) pitch};
}
public static Vec2f getRotationTo(AxisAlignedBB box) {
EntityPlayerSP player = mc.player;
if (player == null) {
return Vec2f.ZERO;
}
Vec3d eyePos = player.getPositionEyes(1.0f);
if (player.getEntityBoundingBox().intersects(box)) {
return getRotationTo(eyePos, box.getCenter());
}
double x = MathHelper.clamp(eyePos.x, box.minX, box.maxX);
double y = MathHelper.clamp(eyePos.y, box.minY, box.maxY);
double z = MathHelper.clamp(eyePos.z, box.minZ, box.maxZ);
return getRotationTo(eyePos, new Vec3d(x, y, z));
}
/**
* Get rotation from player position to another position vector
*
* @param posTo Calculate rotation to this position vector
*/
public static Vec2f getRotationTo(Vec3d posTo) {
EntityPlayerSP player = mc.player;
return player != null ? getRotationTo(player.getPositionEyes(1.0f), posTo) : Vec2f.ZERO;
}
public static Vec2f getRotationTo(Vec3d posTo, EntityPlayer player) {
return player != null ? getRotationTo(player.getPositionEyes(1.0f), posTo) : Vec2f.ZERO;
}
/**
* Get rotation from a position vector to another position vector
*
* @param posFrom Calculate rotation from this position vector
* @param posTo Calculate rotation to this position vector
*/
public static Vec2f getRotationTo(Vec3d posFrom, Vec3d posTo) {
return getRotationFromVec(posTo.subtract(posFrom));
}
/**
* Get rotation from a vector
*
* @param vec Calculate rotation from this vector
*/
public static Vec2f getRotationFromVec(Vec3d vec) {
double lengthXZ = Math.hypot(vec.x, vec.z);
double yaw = normalizeAngle(Math.toDegrees(Math.atan2(vec.z, vec.x)) - 90.0);
double pitch = normalizeAngle(Math.toDegrees(- Math.atan2(vec.y, lengthXZ)));
return new Vec2f((float) yaw, (float) pitch);
}
public static double normalizeAngle(double angle) {
angle %= 360.0;
if (angle >= 180.0) {
angle -= 360.0;
}
if (angle < - 180.0) {
angle += 360.0;
}
return angle;
}
public static float normalizeAngle(float angle) {
angle %= 360.0f;
if (angle >= 180.0f) {
angle -= 360.0f;
}
if (angle < - 180.0f) {
angle += 360.0f;
}
return angle;
}
}