Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
guimc233 committed Aug 14, 2024
1 parent ac7837f commit f9dbe6b
Show file tree
Hide file tree
Showing 7 changed files with 200 additions and 8 deletions.
8 changes: 5 additions & 3 deletions src/main/java/win/cuteguimc/zombieshelper/ZombiesHelper.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package win.cuteguimc.zombieshelper;

import win.cuteguimc.zombieshelper.command.OpenGUICommand;
import win.cuteguimc.zombieshelper.config.ZombiesHelperConfig;
import cc.polyfrost.oneconfig.events.event.InitializationEvent;
import net.minecraftforge.fml.common.Mod;
import cc.polyfrost.oneconfig.utils.commands.CommandManager;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
import win.cuteguimc.zombieshelper.command.OpenGUICommand;
import win.cuteguimc.zombieshelper.config.ZombiesHelperConfig;
import win.cuteguimc.zombieshelper.listener.BlockUseEntityListener;
import win.cuteguimc.zombieshelper.listener.NoPuncherListener;
import win.cuteguimc.zombieshelper.listener.RendHudListener;

/**
* The entrypoint of the Example Mod that initializes it.
Expand All @@ -32,6 +33,7 @@ public void onInit(FMLInitializationEvent event) {
config = new ZombiesHelperConfig();
new NoPuncherListener();
new BlockUseEntityListener();
new RendHudListener();
CommandManager.INSTANCE.registerCommand(new OpenGUICommand());
}
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
package win.cuteguimc.zombieshelper.config;

import cc.polyfrost.oneconfig.config.Config;
import cc.polyfrost.oneconfig.config.annotations.HUD;
import cc.polyfrost.oneconfig.config.annotations.KeyBind;
import cc.polyfrost.oneconfig.config.core.OneKeyBind;
import cc.polyfrost.oneconfig.libs.universal.UKeyboard;
import win.cuteguimc.zombieshelper.ZombiesHelper;
import cc.polyfrost.oneconfig.config.Config;
import cc.polyfrost.oneconfig.config.annotations.Slider;
import cc.polyfrost.oneconfig.config.annotations.Switch;
import cc.polyfrost.oneconfig.config.core.OneKeyBind;
import cc.polyfrost.oneconfig.config.data.Mod;
import cc.polyfrost.oneconfig.config.data.ModType;
import cc.polyfrost.oneconfig.libs.universal.UKeyboard;
import cc.polyfrost.oneconfig.utils.Notifications;
import win.cuteguimc.zombieshelper.ZombiesHelper;
import win.cuteguimc.zombieshelper.hud.ZombiesHelperHud;

public class ZombiesHelperConfig extends Config {
Expand Down Expand Up @@ -38,6 +39,12 @@ public class ZombiesHelperConfig extends Config {
)
public static boolean esp = false;

@Slider(
name = "ESP Arrow Radius",
min = 55f, max = 160f
)
public static float espArrowRadius = 70f;

@Slider(
name = "ESP Range",
min = 0f, max = 100f
Expand All @@ -52,7 +59,10 @@ public class ZombiesHelperConfig extends Config {

public ZombiesHelperConfig() {
super(new Mod(ZombiesHelper.NAME, ModType.UTIL_QOL), ZombiesHelper.MODID + ".json");
registerKeyBind(toggleBlockUseEntityKeyBind, () -> blockUseEntity = !blockUseEntity);
registerKeyBind(toggleBlockUseEntityKeyBind, () -> {
blockUseEntity = !blockUseEntity;
Notifications.INSTANCE.send("Zombies Helper", "Block UseEntity -> " + (blockUseEntity?"On":"Off"));
});
initialize();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@
import net.minecraft.network.Packet;
import net.minecraft.network.play.client.C02PacketUseEntity;
import net.minecraft.network.play.client.C08PacketPlayerBlockPlacement;
import net.minecraft.network.play.client.C0APacketAnimation;
import win.cuteguimc.zombieshelper.config.ZombiesHelperConfig;
import win.cuteguimc.zombieshelper.utils.Utils;

public class BlockUseEntityListener {
private final Minecraft mc = Minecraft.getMinecraft();
private boolean cancelNextSwing = false;

public BlockUseEntityListener() {
EventManager.INSTANCE.register(this);
Expand All @@ -26,6 +28,13 @@ public void onPacketSend(SendPacketEvent event) {
mc.theWorld.getBlockState(((C08PacketPlayerBlockPlacement) packet).getPosition()).getBlock() instanceof BlockChest) ||
packet instanceof C02PacketUseEntity && !Utils.isTarget(((C02PacketUseEntity) packet).getEntityFromWorld(mc.theWorld))) {
event.isCancelled = true;
mc.getNetHandler().addToSendQueue(new C08PacketPlayerBlockPlacement(mc.thePlayer.inventory.getCurrentItem()));
if (packet instanceof C08PacketPlayerBlockPlacement) {
cancelNextSwing = true;
}
} else if (packet instanceof C0APacketAnimation && cancelNextSwing) {
cancelNextSwing = false;
event.isCancelled = true;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import net.minecraft.network.Packet;
import net.minecraft.network.play.client.C02PacketUseEntity;
import net.minecraft.network.play.client.C08PacketPlayerBlockPlacement;
import net.minecraft.network.play.client.C0APacketAnimation;
import win.cuteguimc.zombieshelper.config.ZombiesHelperConfig;
import win.cuteguimc.zombieshelper.utils.Utils;

Expand All @@ -17,6 +18,7 @@
public class NoPuncherListener {
private int lastPuncherTick = -9999987;
private final Minecraft mc = Minecraft.getMinecraft();
private boolean cancelNextSwing = false;

public NoPuncherListener() {
EventManager.INSTANCE.register(this);
Expand Down Expand Up @@ -44,6 +46,13 @@ public void onPacketSend(SendPacketEvent event) {
packet instanceof C02PacketUseEntity && !Utils.isTarget(((C02PacketUseEntity) packet).getEntityFromWorld(mc.theWorld))) &&
mc.thePlayer.ticksExisted - lastPuncherTick <= 20*10.2) {
event.isCancelled = true;
mc.getNetHandler().addToSendQueue(new C08PacketPlayerBlockPlacement(mc.thePlayer.inventory.getCurrentItem()));
if (packet instanceof C08PacketPlayerBlockPlacement) {
cancelNextSwing = true;
}
} else if (packet instanceof C0APacketAnimation && cancelNextSwing) {
cancelNextSwing = false;
event.isCancelled = true;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
package win.cuteguimc.zombieshelper.listener;

import cc.polyfrost.oneconfig.events.EventManager;
import cc.polyfrost.oneconfig.events.event.HudRenderEvent;
import cc.polyfrost.oneconfig.libs.eventbus.Subscribe;
import net.minecraft.client.Minecraft;
import net.minecraft.client.entity.EntityPlayerSP;
import net.minecraft.client.gui.ScaledResolution;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.entity.Entity;
import org.lwjgl.opengl.GL11;
import win.cuteguimc.zombieshelper.config.ZombiesHelperConfig;
import win.cuteguimc.zombieshelper.mixin.MinecraftAccessor;
import win.cuteguimc.zombieshelper.utils.RenderUtils;
import win.cuteguimc.zombieshelper.utils.RotationUtils;
import win.cuteguimc.zombieshelper.utils.Utils;

import java.awt.*;
import java.util.Comparator;
import java.util.stream.Collectors;

import static java.lang.Math.toRadians;
import static net.minecraft.util.MathHelper.*;
import static win.cuteguimc.zombieshelper.utils.RotationUtils.getYawToPoint;

public class RendHudListener {
private static final int HALF_PI_DEGREES_INT = 90;
private static final float TWO_PI_DEGREES_FLOAT = 360.0F;
private static final float RGB_MAX_FLOAT = 255.0F;
private static double WIDTH = 0.03D;
private static double HEIGHT = 5;

public RendHudListener() {
EventManager.INSTANCE.register(this);
}

@Subscribe
public void onRenderHudEvent(HudRenderEvent event) {
if (!ZombiesHelperConfig.esp) return;
Minecraft minecraft = Minecraft.getMinecraft();
EntityPlayerSP player = minecraft.thePlayer;
float playerYaw = player.rotationYaw;
WIDTH = 0.03D * (135D / ZombiesHelperConfig.espArrowRadius);

ScaledResolution resolution = new ScaledResolution(minecraft);
double width = resolution.getScaledWidth();
double height = resolution.getScaledHeight();
double centerX = width / 2.0D;
double centerY = height / 2.0D;


int radius = (int) ZombiesHelperConfig.espArrowRadius;
Color color = new Color(255, 43, 28);

//endregion

for (Entity entity : minecraft.theWorld.getLoadedEntityList().stream().sorted(Comparator.comparingDouble(entity ->
toRadians(((
getYawToPoint(
entity.posX, entity.posZ) +
TWO_PI_DEGREES_FLOAT) %
TWO_PI_DEGREES_FLOAT - playerYaw +
TWO_PI_DEGREES_FLOAT) %
TWO_PI_DEGREES_FLOAT -
HALF_PI_DEGREES_INT)
)).collect(Collectors.toList())) {
if (!Utils.isTarget(entity)) continue;
if (minecraft.thePlayer.getDistanceToEntity(entity) > 8) continue;

double distEntity2Player = entity.getDistanceToEntity(player);

RenderUtils.start2D();
GL11.glPushMatrix();
switch (minecraft.gameSettings.guiScale){
case 0:
GlStateManager.scale(0.5,0.5,0.5);
break;
case 1:
GlStateManager.scale(2,2,2);
break;
case 3:
GlStateManager.scale(0.6666666666666667,0.6666666666666667,0.6666666666666667);

}
GL11.glLineWidth(4);

float alpha = 1.0F - clamp_float(color.getAlpha() / RGB_MAX_FLOAT * (float) distEntity2Player * 3.0F, 0, 255) / RGB_MAX_FLOAT;


Color temp = color;

float red = (temp.getRGB() >> 16 & 0xFF) / RGB_MAX_FLOAT;
float green = (temp.getRGB() >> 8 & 0xFF) / RGB_MAX_FLOAT;
float blue = (temp.getRGB() & 0xFF) / RGB_MAX_FLOAT;

GL11.glColor4f(red, green, blue, alpha);
GL11.glEnable(GL11.GL_POLYGON_SMOOTH);
GL11.glBegin(GL11.GL_TRIANGLE_STRIP);

float yawToEntity = (RotationUtils.getYawToPoint(entity.lastTickPosX + (entity.posX - entity.lastTickPosX) * ((MinecraftAccessor) minecraft).getTimer().elapsedPartialTicks, entity.lastTickPosZ + (entity.posZ - entity.lastTickPosZ) * ((MinecraftAccessor) minecraft).getTimer().elapsedPartialTicks) + TWO_PI_DEGREES_FLOAT) % TWO_PI_DEGREES_FLOAT;
float yawDiff = (yawToEntity - playerYaw + TWO_PI_DEGREES_FLOAT) % TWO_PI_DEGREES_FLOAT - HALF_PI_DEGREES_INT;
double yawDiffRad = toRadians(yawDiff);

GL11.glVertex2d(centerX + cos((float) yawDiffRad) * radius, centerY + sin((float) yawDiffRad) * radius);
GL11.glVertex2d(centerX + cos((float) (yawDiffRad + WIDTH)) * (radius - HEIGHT), centerY + sin((float) (yawDiffRad + WIDTH)) * (radius - HEIGHT));
GL11.glVertex2d(centerX + cos((float) (yawDiffRad - WIDTH)) * (radius - HEIGHT), centerY + sin((float) (yawDiffRad - WIDTH)) * (radius - HEIGHT));
GL11.glVertex2d(centerX + cos((float) yawDiffRad) * radius, centerY + sin((float) yawDiffRad) * radius);

GL11.glEnd();
GL11.glDisable(GL11.GL_POLYGON_SMOOTH);
GL11.glPopMatrix();
RenderUtils.stop2D();
}
}
}
31 changes: 31 additions & 0 deletions src/main/java/win/cuteguimc/zombieshelper/utils/RenderUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.client.renderer.WorldRenderer;
import net.minecraft.client.renderer.culling.Frustum;
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
import net.minecraft.entity.Entity;
import net.minecraft.util.AxisAlignedBB;
Expand All @@ -16,6 +17,8 @@
import java.util.HashMap;
import java.util.Map;

import static net.minecraft.client.renderer.GlStateManager.disableBlend;
import static net.minecraft.client.renderer.GlStateManager.enableTexture2D;
import static org.lwjgl.opengl.GL11.*;

public class RenderUtils {
Expand Down Expand Up @@ -217,4 +220,32 @@ public static void drawFilledBox(final AxisAlignedBB axisAlignedBB) {
worldRenderer.pos(axisAlignedBB.maxX, axisAlignedBB.minY, axisAlignedBB.maxZ).endVertex();
tessellator.draw();
}

private final static Frustum frustum = new Frustum();

public static boolean isInViewFrustrum(Entity entity) {
return isInViewFrustrum(entity.getEntityBoundingBox()) || entity.ignoreFrustumCheck;
}

public static boolean isInViewFrustrum(AxisAlignedBB bb) {
Entity current = Minecraft.getMinecraft().getRenderViewEntity();
frustum.setPosition(current.posX, current.posY, current.posZ);
return frustum.isBoundingBoxInFrustum(bb);
}

public static void start2D() {
glEnable(3042);
glDisable(3553);
glBlendFunc(770, 771);
glEnable(2848);
}

public static void stop2D() {
glEnable(3553);
glDisable(3042);
glDisable(2848);
enableTexture2D();
disableBlend();
glColor4f(1, 1, 1, 1);
}
}
16 changes: 16 additions & 0 deletions src/main/java/win/cuteguimc/zombieshelper/utils/RotationUtils.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package win.cuteguimc.zombieshelper.utils;

import net.minecraft.client.Minecraft;
import net.minecraft.util.MathHelper;
import win.cuteguimc.zombieshelper.mixin.MinecraftAccessor;

public class RotationUtils {
private static final Minecraft mc = Minecraft.getMinecraft();

public static float getYawToPoint(double posX, double posZ) {
Minecraft instance = mc;
double xDiff = posX - (instance.thePlayer.lastTickPosX + (instance.thePlayer.posX - instance.thePlayer.lastTickPosX) * ((MinecraftAccessor) instance).getTimer().elapsedPartialTicks), zDiff = posZ - (instance.thePlayer.lastTickPosZ + (instance.thePlayer.posZ - instance.thePlayer.lastTickPosZ) * ((MinecraftAccessor) instance).getTimer().elapsedPartialTicks), dist = MathHelper.sqrt_double(
xDiff * xDiff + zDiff * zDiff);
return (float) (Math.atan2(zDiff, xDiff) * 180.0D / Math.PI) - 90.0F;
}
}

0 comments on commit f9dbe6b

Please sign in to comment.