-
Автор темы
- #1
ss ->
Пожалуйста, авторизуйтесь для просмотра ссылки.
Java:
package cc.paycheck.modules.impl.render;
import com.google.common.eventbus.Subscribe;
import cc.paycheck.modules.settings.impl.ColorSetting;
import cc.paycheck.utils.client.IMinecraft;
import net.minecraft.client.renderer.ItemModelMesher;
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
import net.minecraft.entity.Entity;
import net.minecraft.entity.item.EnderPearlEntity;
import net.minecraft.entity.item.ItemEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.projectile.ThrowableEntity;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.BlockRayTraceResult;
import net.minecraft.util.math.RayTraceContext;
import net.minecraft.util.math.RayTraceResult;
import net.minecraft.util.math.vector.Vector2f;
import net.minecraft.util.math.vector.Vector3d;
import cc.paycheck.events.EventDisplay;
import cc.paycheck.events.WorldEvent;
import cc.paycheck.modules.api.Category;
import cc.paycheck.modules.api.Module;
import cc.paycheck.modules.api.ModuleRegister;
import cc.paycheck.utils.math.Vector4i;
import cc.paycheck.utils.projections.ProjectionUtil;
import cc.paycheck.utils.render.color.ColorUtils;
import cc.paycheck.utils.render.rect.DisplayUtils;
import cc.paycheck.utils.render.font.Fonts;
import net.minecraft.util.math.vector.Vector4f;
import java.util.ArrayList;
import java.util.List;
import static org.lwjgl.opengl.GL11.*;
@ModuleRegister(name = "Predictions", category = Category.Render)
public class Predictions extends Module {
private float lineWidth = 1.5f;
public Predictions() {
}
public void setLineWidth(float newWidth) {
if (newWidth >= 1.0f && newWidth <= 10.0f) {
lineWidth = newWidth;
System.out.println("Толщина линии изменена на: " + lineWidth);
} else {
System.out.println("Толщина линии должна быть в диапазоне от 1.0 до 10.0.");
}
}
record ThrowablePoint(Vector3d position, int ticks, ResourceLocation texture) {
}
final List<ThrowablePoint> throwablePoints = new ArrayList<>();
@Subscribe
public void onRender(EventDisplay e) {
for (ThrowablePoint throwablePoint : throwablePoints) {
Vector3d pos = throwablePoint.position;
Vector2f projection = ProjectionUtil.project(pos.x, pos.y - 0.3F, pos.z);
int ticks = throwablePoint.ticks;
ResourceLocation texture = throwablePoint.texture;
if (projection.equals(new Vector2f(Float.MAX_VALUE, Float.MAX_VALUE))) {
continue;
}
boolean isMoving = ticks > 0;
if (isMoving) {
double time = ticks * 50 / 1000.0;
String text = String.format("%.1f" + " сек.", time);
float width = Fonts.montserrat.getWidth(text, 5);
float textWidth = width + 8 + 8;
float posX = projection.x - textWidth / 2;
float posY = projection.y;
DisplayUtils.drawRoundedRect(posX + 2, posY + 2 - 3, textWidth - 4, 12 - 3, 0, ColorUtils.rgba(24, 24, 24, 80));
DisplayUtils.drawImage(texture, (int) posX + 4, (int) posY + 2 + 1 - 4, 8, 8, -1);
Fonts.montserrat.drawText(e.getMatrixStack(), text, (float) (posX + 14), (float) (posY + 4.5f - 4), -1, 5);
}
}
}
@Subscribe
public void onWorldRender(WorldEvent event) {
glPushMatrix();
glDisable(GL_TEXTURE_2D);
glDisable(GL_DEPTH_TEST);
glEnable(GL_BLEND);
glEnable(GL_LINE_SMOOTH);
Vector3d renderOffset = mc.getRenderManager().info.getProjectedView();
glTranslated(-renderOffset.x, -renderOffset.y, -renderOffset.z);
glLineWidth(lineWidth);
buffer.begin(1, DefaultVertexFormats.POSITION);
throwablePoints.clear();
for (Entity entity : mc.world.getAllEntities()) {
if (entity instanceof ThrowableEntity throwable) {
Vector3d motion = throwable.getMotion();
Vector3d pos = throwable.getPositionVec();
Vector3d prevPos;
int ticks = 0;
ResourceLocation texture = getTextureForThrowable(throwable);
for (int i = 0; i < 150; i++) {
prevPos = pos;
pos = pos.add(motion);
motion = getNextMotion(throwable, motion);
ColorUtils.setAlpha(ColorUtils.getColor(0), 165);
buffer.pos(prevPos.x, prevPos.y, prevPos.z).endVertex();
RayTraceContext rayTraceContext = new RayTraceContext(
prevPos,
pos,
RayTraceContext.BlockMode.COLLIDER,
RayTraceContext.FluidMode.NONE,
throwable
);
BlockRayTraceResult blockHitResult = mc.world.rayTraceBlocks(rayTraceContext);
boolean isLast = blockHitResult.getType() == RayTraceResult.Type.BLOCK;
if (isLast) {
pos = blockHitResult.getHitVec();
}
buffer.pos(pos.x, pos.y, pos.z).endVertex();
if (blockHitResult.getType() == BlockRayTraceResult.Type.BLOCK || pos.y < -128) {
if (motion.lengthSquared() < 0.04) {
break;
}
throwablePoints.add(new ThrowablePoint(pos, ticks, texture));
break;
}
ticks++;
}
} else if (entity instanceof ItemEntity itemEntity) {
Vector3d motion = itemEntity.getMotion();
Vector3d pos = itemEntity.getPositionVec();
Vector3d prevPos;
int ticks = 0;
ItemStack itemStack = itemEntity.getItem();
ResourceLocation texture = getTextureForItem(itemStack.getItem());
for (int i = 0; i < 150; i++) {
prevPos = pos;
pos = pos.add(motion);
motion = getNextMotionForItem(motion);
ColorUtils.setAlpha(ColorUtils.getColor(0), 165);
buffer.pos(prevPos.x, prevPos.y, prevPos.z).endVertex();
RayTraceContext rayTraceContext = new RayTraceContext(
prevPos,
pos,
RayTraceContext.BlockMode.COLLIDER,
RayTraceContext.FluidMode.NONE,
itemEntity
);
BlockRayTraceResult blockHitResult = mc.world.rayTraceBlocks(rayTraceContext);
boolean isLast = blockHitResult.getType() == RayTraceResult.Type.BLOCK;
if (isLast) {
pos = blockHitResult.getHitVec();
}
buffer.pos(pos.x, pos.y, pos.z).endVertex();
if (blockHitResult.getType() == BlockRayTraceResult.Type.BLOCK || pos.y < -128) {
if (motion.lengthSquared() < 0.04) {
break;
}
throwablePoints.add(new ThrowablePoint(pos, ticks, texture));
break;
}
ticks++;
}
}
}
tessellator.draw();
glDisable(GL_BLEND);
glDisable(GL_LINE_SMOOTH);
glEnable(GL_TEXTURE_2D);
glEnable(GL_DEPTH_TEST);
glPopMatrix();
}
private Vector3d getNextMotion(ThrowableEntity throwable, Vector3d motion) {
if (throwable.isInWater()) {
motion = motion.scale(0.8);
} else {
motion = motion.scale(0.99);
}
if (!throwable.hasNoGravity()) {
motion.y -= throwable.getGravityVelocity();
}
return motion;
}
private Vector3d getNextMotionForItem(Vector3d motion) {
motion = motion.scale(0.99);
motion = motion.subtract(0, 0.04, 0);
return motion;
}
private ResourceLocation getTextureForThrowable(ThrowableEntity throwable) {
if (throwable instanceof EnderPearlEntity) {
return new ResourceLocation("textures/item/ender_pearl.png");
} else if (throwable.getClass().getSimpleName().toLowerCase().contains("snowball")) {
return new ResourceLocation("textures/item/snowball.png");
} else if (throwable.getClass().getSimpleName().toLowerCase().contains("egg")) {
return new ResourceLocation("textures/item/egg.png");
} else {
System.err.println("Unknown throwable type: " + throwable.getClass().getSimpleName());
return new ResourceLocation("textures/item/ender_pearl.png");
}
}
private ResourceLocation getTextureForItem(Item item) {
String itemName = item.getTranslationKey().replace("item.minecraft.", "");
ResourceLocation texture = new ResourceLocation("textures/item/" + itemName + ".png");
System.out.println("Requested texture: " + texture);
return texture;
}
}