first commit
This commit is contained in:
@@ -0,0 +1,240 @@
|
||||
package online.bobtony;
|
||||
|
||||
import com.mojang.blaze3d.systems.RenderSystem;
|
||||
import online.bobtony.handlers.*;
|
||||
import online.bobtony.gui.Color;
|
||||
import online.bobtony.utils.render.Render3D;
|
||||
import online.bobtony.enums.Modes;
|
||||
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents;
|
||||
import net.fabricmc.fabric.api.client.keybinding.v1.KeyBindingHelper;
|
||||
import net.fabricmc.fabric.api.client.message.v1.ClientSendMessageEvents;
|
||||
import net.fabricmc.fabric.api.client.rendering.v1.WorldRenderEvents;
|
||||
import net.minecraft.block.*;
|
||||
import net.minecraft.block.entity.*;
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.client.option.KeyBinding;
|
||||
import net.minecraft.client.render.*;
|
||||
import net.minecraft.client.util.InputUtil;
|
||||
import net.minecraft.client.network.ClientPlayerEntity;
|
||||
import net.minecraft.client.util.math.MatrixStack;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.network.packet.c2s.play.PlayerMoveC2SPacket;
|
||||
import net.minecraft.text.Text;
|
||||
import net.minecraft.util.math.*;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.chunk.WorldChunk;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.lwjgl.glfw.GLFW;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public class BobTony {
|
||||
public static KeyBinding toggleModeKey = null;
|
||||
public static KeyBinding overlayEditor = null;
|
||||
|
||||
public static final String PREFIX = "§8[§6BobTony§8] §r";
|
||||
|
||||
public static List<String> trackerList = new ArrayList<>();
|
||||
public static long lastUpdateTime = System.currentTimeMillis();
|
||||
public static long lastJumpTime = 0;
|
||||
public static boolean wasJumping = false;
|
||||
public static long lastModeSwitchTime = 0;
|
||||
public static final long MODE_SWITCH_COOLDOWN = 1000;
|
||||
public static float flyspeed = 0.1f;
|
||||
public static float strength = 2.0f;
|
||||
public static float speed = 1.0f;
|
||||
public static boolean nofall = false;
|
||||
public static Modes mode = Modes.NONE;
|
||||
public List<Block> trackerBlockList = new ArrayList<>();
|
||||
public static boolean chestesp = false;
|
||||
public static boolean fly = false;
|
||||
public static volatile int hashesPerSecond = 0;
|
||||
|
||||
public BobTony() {
|
||||
toggleModeKey = KeyBindingHelper.registerKeyBinding(new KeyBinding(
|
||||
"bobtony.switchmodes",
|
||||
InputUtil.Type.KEYSYM,
|
||||
GLFW.GLFW_KEY_M,
|
||||
"BobTony"
|
||||
));
|
||||
|
||||
overlayEditor = KeyBindingHelper.registerKeyBinding(new KeyBinding(
|
||||
"bobtony.overlayeditor",
|
||||
InputUtil.Type.KEYSYM,
|
||||
GLFW.GLFW_KEY_RIGHT_SHIFT,
|
||||
"BobTony"
|
||||
));
|
||||
|
||||
ClientTickEvents.END_CLIENT_TICK.register(client -> {
|
||||
if (client.player == null) return;
|
||||
ClientPlayerEntity player = client.player;
|
||||
ModeSwitchHandler.handleModeSwitch(player);
|
||||
DoubleJumpHandler.handleDoubleJump(player);
|
||||
|
||||
if (nofall && client.player != null && !client.player.getAbilities().flying) {
|
||||
client.getNetworkHandler().sendPacket(new PlayerMoveC2SPacket.PositionAndOnGround(
|
||||
client.player.getX(),
|
||||
client.player.getY(),
|
||||
client.player.getZ(),
|
||||
true,
|
||||
false
|
||||
));
|
||||
client.player.fallDistance = 0.0f;
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
ClientSendMessageEvents.ALLOW_CHAT.register(message -> {
|
||||
if (message.startsWith(".strength ")){
|
||||
StrengthCommandHandler.handleStrengthCommand(message);
|
||||
return false;
|
||||
}else if (message.equals(".nofall")) {
|
||||
NoFallCommandHandler.handelNoFallCommand();
|
||||
return false;
|
||||
} else if (message.startsWith(".flyspeed ")) {
|
||||
FlySpeedCommandHandler.handelFlySpeedCommand(message);
|
||||
return false;
|
||||
} else if (message.equals(".nukeserver")) {
|
||||
NukeCommandHandler.handleNukeCommand();
|
||||
return false;
|
||||
} else if (message.startsWith(".speed ")) {
|
||||
SpeedCommandHandler.handleSpeedCommand(message);
|
||||
return false;
|
||||
} else if (message.startsWith(".tracker ")) {
|
||||
TrackerHandler.handleTracker(message);
|
||||
return false;
|
||||
} else if (message.equals(".chestesp")) {
|
||||
ChestESPHandler.handleChestESP();
|
||||
return false;
|
||||
} else if (message.equals(".fly")){
|
||||
FlyHandler.handleFly();
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
});
|
||||
|
||||
WorldRenderEvents.AFTER_ENTITIES.register(context -> {
|
||||
MinecraftClient client = MinecraftClient.getInstance();
|
||||
MatrixStack matrices = context.matrixStack();
|
||||
VertexConsumerProvider vertexConsumer = context.consumers();
|
||||
Vec3d cameraPos = client.gameRenderer.getCamera().getPos();
|
||||
World world = client.world;
|
||||
|
||||
float tickDelta = context.tickCounter().getTickDelta(false);
|
||||
Color color = new Color(255, 0, 0, 1.0F);
|
||||
|
||||
for (Entity entity : client.world.getEntities()) {
|
||||
if (trackerList != null) {
|
||||
for (String name : trackerList) {
|
||||
if (Objects.equals(entity.getName(), Text.literal(name))) {
|
||||
Render3D.drawLineToEntity(matrices, client.player, entity, tickDelta, color, 2.0f);
|
||||
if (entity != client.player) {
|
||||
double interpolatedX = entity.prevX + (entity.getX() - entity.prevX) * tickDelta;
|
||||
double interpolatedY = entity.prevY + (entity.getY() - entity.prevY) * tickDelta;
|
||||
double interpolatedZ = entity.prevZ + (entity.getZ() - entity.prevZ) * tickDelta;
|
||||
|
||||
Box box = entity.getBoundingBox().offset(
|
||||
interpolatedX - entity.getX() - cameraPos.x,
|
||||
interpolatedY - entity.getY() - cameraPos.y,
|
||||
interpolatedZ - entity.getZ() - cameraPos.z
|
||||
);
|
||||
|
||||
Render3D.draw3DHitBox(matrices, box, color, 2.0F);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (chestesp){
|
||||
getTileEntities().forEach(blockEntity ->
|
||||
{
|
||||
Box box = new Box(
|
||||
blockEntity.getPos().getX() - cameraPos.x,
|
||||
blockEntity.getPos().getY() - cameraPos.y,
|
||||
blockEntity.getPos().getZ() - cameraPos.z,
|
||||
blockEntity.getPos().getX() + 1 - cameraPos.x,
|
||||
blockEntity.getPos().getY() + 1 - cameraPos.y,
|
||||
blockEntity.getPos().getZ() + 1 - cameraPos.z
|
||||
);
|
||||
if (blockEntity instanceof ChestBlockEntity || blockEntity instanceof TrappedChestBlockEntity) {
|
||||
Color blockColor = new Color(0, 255, 0, 1.0F);
|
||||
Render3D.draw3DBox(matrices, box, blockColor, 2.0F);
|
||||
Render3D.drawLineToBlockEntity(matrices, client.player, blockEntity, tickDelta, blockColor, 2.0f);
|
||||
RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F);
|
||||
}else if (blockEntity instanceof BarrelBlockEntity){
|
||||
Color blockColor = new Color(0, 0, 255, 1.0F);
|
||||
Render3D.draw3DBox(matrices, box, blockColor, 2.0F);
|
||||
Render3D.drawLineToBlockEntity(matrices, client.player, blockEntity, tickDelta, blockColor, 2.0f);
|
||||
RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F);
|
||||
}else if (blockEntity instanceof FurnaceBlockEntity){
|
||||
Color blockColor = new Color(255, 0, 0, 1.0F);
|
||||
Render3D.draw3DBox(matrices, box, blockColor, 2.0F);
|
||||
Render3D.drawLineToBlockEntity(matrices, client.player, blockEntity, tickDelta, blockColor, 2.0f);
|
||||
RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F);
|
||||
}else if (blockEntity instanceof ShulkerBoxBlockEntity){
|
||||
Color blockColor = new Color(255, 100, 0, 1.0F);
|
||||
Render3D.draw3DBox(matrices, box, blockColor, 2.0F);
|
||||
Render3D.drawLineToBlockEntity(matrices, client.player, blockEntity, tickDelta, blockColor, 2.0f);
|
||||
RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F);
|
||||
}else if (blockEntity instanceof BeaconBlockEntity){
|
||||
Color blockColor = new Color(0, 255, 255, 1.0F);
|
||||
Render3D.draw3DBox(matrices, box, blockColor, 2.0F);
|
||||
Render3D.drawLineToBlockEntity(matrices, client.player, blockEntity, tickDelta, blockColor, 2.0f);
|
||||
RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F);
|
||||
}else if (blockEntity instanceof DropperBlockEntity){
|
||||
Color blockColor = new Color(255, 255, 0, 1.0F);
|
||||
Render3D.draw3DBox(matrices, box, blockColor, 2.0F);
|
||||
Render3D.drawLineToBlockEntity(matrices, client.player, blockEntity, tickDelta, blockColor, 2.0f);
|
||||
RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F);
|
||||
} else if (blockEntity instanceof DispenserBlockEntity) {
|
||||
Color blockColor = new Color(255, 255, 255, 1.0F);
|
||||
Render3D.draw3DBox(matrices, box, blockColor, 2.0F);
|
||||
Render3D.drawLineToBlockEntity(matrices, client.player, blockEntity, tickDelta, blockColor, 2.0f);
|
||||
RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F);
|
||||
} else if (blockEntity instanceof EnderChestBlockEntity){
|
||||
Color blockColor = new Color(255, 0, 255, 1.0F);
|
||||
Render3D.draw3DBox(matrices, box, blockColor, 2.0F);
|
||||
Render3D.drawLineToBlockEntity(matrices, client.player, blockEntity, tickDelta, blockColor, 2.0f);
|
||||
RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static Stream<BlockEntity> getTileEntities() {
|
||||
return getLoadedChunks().flatMap(chunk -> chunk.getBlockEntities().values().stream());
|
||||
}
|
||||
|
||||
public static Stream<WorldChunk> getLoadedChunks() {
|
||||
int radius = Math.max(2, MinecraftClient.getInstance().options.getClampedViewDistance()) + 3;
|
||||
int diameter = radius * 2 + 1;
|
||||
|
||||
ChunkPos center = MinecraftClient.getInstance().player.getChunkPos();
|
||||
ChunkPos min = new ChunkPos(center.x - radius, center.z - radius);
|
||||
ChunkPos max = new ChunkPos(center.x + radius, center.z + radius);
|
||||
|
||||
Stream<WorldChunk> stream = Stream.<ChunkPos>iterate(min, pos -> {
|
||||
int x = pos.x;
|
||||
int z = pos.z;
|
||||
x++;
|
||||
|
||||
if (x > max.x) {
|
||||
x = min.x;
|
||||
z++;
|
||||
}
|
||||
return new ChunkPos(x, z);
|
||||
}).limit((long) diameter * diameter).filter(c -> MinecraftClient.getInstance().world.isChunkLoaded(c.x, c.z)).map(c -> MinecraftClient.getInstance().world.getChunk(c.x, c.z)).filter(Objects::nonNull);
|
||||
|
||||
return stream;
|
||||
}
|
||||
|
||||
public static void sendMessage(@NotNull ClientPlayerEntity player,@NotNull String message, boolean overlay) {
|
||||
player.sendMessage(Text.literal(PREFIX + message), overlay);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package online.bobtony;
|
||||
|
||||
import net.fabricmc.api.ClientModInitializer;
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
|
||||
|
||||
public class BobtonyClient implements ClientModInitializer {
|
||||
private static MinecraftClient instance;
|
||||
|
||||
@Override
|
||||
public void onInitializeClient() {
|
||||
instance = MinecraftClient.getInstance();
|
||||
new BobTony();
|
||||
}
|
||||
|
||||
public static MinecraftClient getInstance() {
|
||||
return instance;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package online.bobtony.enums;
|
||||
|
||||
public enum Modes {
|
||||
|
||||
FLY, BOOST, NONE
|
||||
|
||||
}
|
||||
@@ -0,0 +1,271 @@
|
||||
package online.bobtony.gui;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.joml.Vector3f;
|
||||
|
||||
public class Color {
|
||||
private int r;
|
||||
private int g;
|
||||
private int b;
|
||||
private int alpha = 255;
|
||||
|
||||
private float hue;
|
||||
private float saturation;
|
||||
private float luminance;
|
||||
|
||||
public Color(int r, int g, int b) {
|
||||
this.r = r;
|
||||
this.g = g;
|
||||
this.b = b;
|
||||
|
||||
HSVFromRGB(r, g, b);
|
||||
}
|
||||
|
||||
public Color(int r, int g, int b, int alpha) {
|
||||
this.r = r;
|
||||
this.g = g;
|
||||
this.b = b;
|
||||
|
||||
HSVFromRGB(r, g, b);
|
||||
|
||||
this.alpha = alpha;
|
||||
}
|
||||
|
||||
public Color(float r, float g, float b, float alpha) {
|
||||
this.r = (int) (r * 255f);
|
||||
this.g = (int) (g * 255f);
|
||||
this.b = (int) (b * 255f);
|
||||
this.alpha = (int) (alpha * 255f);
|
||||
}
|
||||
|
||||
public Color getAsSolid() {
|
||||
return new Color(r, g, b, 255);
|
||||
}
|
||||
|
||||
public static Color interpolate(Color color1, Color color2, float factor) {
|
||||
int r = (int) (color1.r + (color2.r - color1.r) * factor);
|
||||
int g = (int) (color1.g + (color2.g - color1.g) * factor);
|
||||
int b = (int) (color1.b + (color2.b - color1.b) * factor);
|
||||
int alpha = (int) (color1.alpha + (color2.alpha - color1.alpha) * factor);
|
||||
return new Color(r, g, b, alpha);
|
||||
}
|
||||
|
||||
private void HSVFromRGB(int r, int g, int b) {
|
||||
float rPrime = r / 255.0f;
|
||||
float gPrime = g / 255.0f;
|
||||
float bPrime = b / 255.0f;
|
||||
|
||||
float cMax = Math.max(rPrime, Math.max(gPrime, bPrime));
|
||||
float cMin = Math.min(rPrime, Math.min(gPrime, bPrime));
|
||||
|
||||
float delta = cMax - cMin;
|
||||
|
||||
if (delta == 0.0f) {
|
||||
hue = 0.0f;
|
||||
} else {
|
||||
if (cMax == rPrime) {
|
||||
hue = (60.0f * (((gPrime - bPrime) / delta) % 6));
|
||||
} else if (cMax == gPrime) {
|
||||
hue = (60.0f * (((bPrime - rPrime) / delta) + 2));
|
||||
} else if (cMax == bPrime) {
|
||||
hue = (60.0f * (((rPrime - gPrime) / delta) + 2));
|
||||
}
|
||||
}
|
||||
|
||||
if (cMax == 0.0f)
|
||||
saturation = 0.0f;
|
||||
else
|
||||
saturation = delta / cMax;
|
||||
|
||||
luminance = cMax;
|
||||
}
|
||||
|
||||
public Color(float hue, float saturation, float luminance) {
|
||||
this.setHSV(hue, saturation, luminance);
|
||||
}
|
||||
|
||||
public float getHue() {
|
||||
return hue;
|
||||
}
|
||||
|
||||
public float getSaturation() {
|
||||
return saturation;
|
||||
}
|
||||
|
||||
public float getLuminance() {
|
||||
return luminance;
|
||||
}
|
||||
|
||||
public void setHSV(float hue, float saturation, float luminance) {
|
||||
this.hue = hue;
|
||||
this.saturation = saturation;
|
||||
this.luminance = luminance;
|
||||
Color vec = hsv2rgb(hue, saturation, luminance);
|
||||
if (vec != null) {
|
||||
this.r = vec.r;
|
||||
this.g = vec.g;
|
||||
this.b = vec.b;
|
||||
}
|
||||
}
|
||||
|
||||
public void setHue(float hue) {
|
||||
this.hue = hue;
|
||||
Color vec = hsv2rgb(this.hue, this.saturation, this.luminance);
|
||||
if (vec != null) {
|
||||
this.r = vec.r;
|
||||
this.g = vec.g;
|
||||
this.b = vec.b;
|
||||
}
|
||||
}
|
||||
|
||||
public void setSaturation(float saturation) {
|
||||
this.saturation = saturation;
|
||||
Color vec = hsv2rgb(this.hue, this.saturation, this.luminance);
|
||||
if (vec != null) {
|
||||
this.r = vec.r;
|
||||
this.g = vec.g;
|
||||
this.b = vec.b;
|
||||
}
|
||||
}
|
||||
|
||||
public void setLuminance(float luminance) {
|
||||
this.luminance = luminance;
|
||||
Color vec = hsv2rgb(this.hue, this.saturation, this.luminance);
|
||||
if (vec != null) {
|
||||
this.r = vec.r;
|
||||
this.g = vec.g;
|
||||
this.b = vec.b;
|
||||
}
|
||||
}
|
||||
|
||||
public void setRGB(int r, int g, int b) {
|
||||
this.r = r;
|
||||
this.g = g;
|
||||
this.b = b;
|
||||
}
|
||||
|
||||
public void setRGBA(int r, int g, int b, int alpha) {
|
||||
this.r = r;
|
||||
this.g = b;
|
||||
this.b = b;
|
||||
this.alpha = alpha;
|
||||
}
|
||||
|
||||
public void setAlpha(int alpha) {
|
||||
this.alpha = alpha;
|
||||
}
|
||||
|
||||
public String getColorAsString() {
|
||||
String rs = Integer.toString((int) (r));
|
||||
String gs = Integer.toString((int) (g));
|
||||
String bs = Integer.toString((int) (b));
|
||||
return rs + gs + bs;
|
||||
}
|
||||
|
||||
public int getColorAsInt() {
|
||||
int Alpha = ((this.alpha) << 24) & 0xFF000000;
|
||||
int R = ((this.r) << 16) & 0x00FF0000;
|
||||
int G = ((this.g) << 8) & 0x0000FF00;
|
||||
int B = (this.b) & 0x000000FF;
|
||||
return Alpha | R | G | B;
|
||||
}
|
||||
|
||||
public String getColorAsHex() {
|
||||
return String.format("#%06X", this.getColorAsInt());
|
||||
}
|
||||
|
||||
public float getRed() {
|
||||
return ((float) this.r) / 255.0f;
|
||||
}
|
||||
|
||||
public float getGreen() {
|
||||
return ((float) this.g) / 255.0f;
|
||||
}
|
||||
|
||||
public float getBlue() {
|
||||
return ((float) this.b) / 255.0f;
|
||||
}
|
||||
|
||||
public float getAlpha() {
|
||||
return ((float) this.alpha) / 255.0f;
|
||||
}
|
||||
|
||||
public Color add(Color color) {
|
||||
return new Color(this.r + color.r, this.g + color.g, this.b + color.b);
|
||||
}
|
||||
|
||||
public Color add(float r, float g, float b) {
|
||||
return new Color((int) Math.min(255, this.r + r), (int) Math.min(255, this.g + g),
|
||||
(int) Math.min(255, this.b + b));
|
||||
}
|
||||
|
||||
public static String rgbToString(int r, int g, int b) {
|
||||
String rs = Integer.toString((int) (r));
|
||||
String gs = Integer.toString((int) (g));
|
||||
String bs = Integer.toString((int) (b));
|
||||
return rs + gs + bs;
|
||||
}
|
||||
|
||||
public static int rgbToInt(int r, int g, int b) {
|
||||
String rs = Integer.toString((int) (r));
|
||||
String gs = Integer.toString((int) (g));
|
||||
String bs = Integer.toString((int) (b));
|
||||
return Integer.parseInt(rs + gs + bs);
|
||||
}
|
||||
|
||||
public static int convertRGBToHex(int r, int g, int b) {
|
||||
String strr = StringUtils.leftPad(Integer.toHexString(r), 2, '0');
|
||||
String strg = StringUtils.leftPad(Integer.toHexString(g), 2, '0');
|
||||
String strb = StringUtils.leftPad(Integer.toHexString(b), 2, '0');
|
||||
String string = strr + strg + strb;
|
||||
return Integer.parseInt(string, 16);
|
||||
}
|
||||
|
||||
public static Color convertHextoRGB(String hexColor) {
|
||||
hexColor = hexColor.replace("#", "");
|
||||
if (hexColor.length() == 6) {
|
||||
int r = Integer.valueOf(hexColor.substring(0, 2), 16);
|
||||
int g = Integer.valueOf(hexColor.substring(2, 4), 16);
|
||||
int b = Integer.valueOf(hexColor.substring(4, 6), 16);
|
||||
return new Color(r, g, b);
|
||||
} else if (hexColor.length() == 8) {
|
||||
int alpha = Integer.valueOf(hexColor.substring(0, 2), 16);
|
||||
int r = Integer.valueOf(hexColor.substring(2, 4), 16);
|
||||
int g = Integer.valueOf(hexColor.substring(4, 6), 16);
|
||||
int b = Integer.valueOf(hexColor.substring(6, 8), 16);
|
||||
return new Color(r, g, b, alpha);
|
||||
} else {
|
||||
throw new IllegalArgumentException("Invalid hex color format. Expected 6 or 8 characters.");
|
||||
}
|
||||
}
|
||||
|
||||
public static Color hsv2rgb(float hue, float saturation, float luminance) {
|
||||
float h = (hue / 60);
|
||||
float chroma = luminance * saturation;
|
||||
float x = chroma * (1 - Math.abs((h % 2) - 1));
|
||||
|
||||
Vector3f rgbVec;
|
||||
if (h >= 0 && h <= 1) {
|
||||
rgbVec = new Vector3f(chroma, x, 0);
|
||||
} else if (h >= 1 && h <= 2) {
|
||||
rgbVec = new Vector3f(x, chroma, 0);
|
||||
} else if (h >= 2 && h <= 3) {
|
||||
rgbVec = new Vector3f(0, chroma, x);
|
||||
} else if (h >= 3 && h <= 4) {
|
||||
rgbVec = new Vector3f(0, x, chroma);
|
||||
} else if (h >= 4 && h <= 5) {
|
||||
rgbVec = new Vector3f(x, 0, chroma);
|
||||
} else if (h >= 5 && h <= 6) {
|
||||
rgbVec = new Vector3f(chroma, 0, x);
|
||||
} else {
|
||||
rgbVec = null;
|
||||
}
|
||||
|
||||
if (rgbVec != null) {
|
||||
float m = luminance - chroma;
|
||||
return new Color((int) (255.0f * (rgbVec.x + m)), (int) (255.0f * (rgbVec.y + m)),
|
||||
(int) (255.0f * (rgbVec.z + m)));
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,102 @@
|
||||
package online.bobtony.gui;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class Rectangle {
|
||||
public static final Rectangle INFINITE = new Rectangle(Float.POSITIVE_INFINITY, Float.POSITIVE_INFINITY,
|
||||
Float.POSITIVE_INFINITY, Float.POSITIVE_INFINITY);
|
||||
|
||||
private Float x = null;
|
||||
private Float y = null;
|
||||
private Float width = null;
|
||||
private Float height = null;
|
||||
|
||||
public Rectangle() {
|
||||
}
|
||||
|
||||
public Rectangle(Float x, Float y, Float width, Float height) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
}
|
||||
|
||||
public Rectangle(Rectangle rect) {
|
||||
this.x = rect.x;
|
||||
this.y = rect.y;
|
||||
this.width = rect.width;
|
||||
this.height = rect.height;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public Float getX() {
|
||||
return this.x;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public Float getY() {
|
||||
return this.y;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public Float getWidth() {
|
||||
return this.width;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public Float getHeight() {
|
||||
return this.height;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object other) {
|
||||
if (this == other)
|
||||
return true;
|
||||
if (other == null || getClass() != other.getClass())
|
||||
return false;
|
||||
|
||||
Rectangle otherRect = (Rectangle) other;
|
||||
|
||||
if (!Objects.equals(x, otherRect.x))
|
||||
return false;
|
||||
if (!Objects.equals(y, otherRect.y))
|
||||
return false;
|
||||
if (!Objects.equals(width, otherRect.width))
|
||||
return false;
|
||||
return Objects.equals(height, otherRect.height);
|
||||
}
|
||||
|
||||
public boolean intersects(Rectangle rectangle) {
|
||||
return (Math.abs(x - rectangle.x) * 2 < (width + rectangle.width))
|
||||
&& (Math.abs(y - rectangle.y) * 2 < (height + rectangle.height));
|
||||
}
|
||||
|
||||
public boolean intersects(float x, float y) {
|
||||
float x2 = this.x + width;
|
||||
float y2 = this.y + height;
|
||||
|
||||
return (x >= this.x && x <= x2 && y >= this.y && y <= y2);
|
||||
}
|
||||
|
||||
public void setX(Float x) {
|
||||
this.x = x;
|
||||
}
|
||||
|
||||
public void setY(Float y) {
|
||||
this.y = y;
|
||||
}
|
||||
|
||||
public void setWidth(Float width) {
|
||||
this.width = width;
|
||||
}
|
||||
|
||||
public void setHeight(Float height) {
|
||||
this.height = height;
|
||||
}
|
||||
|
||||
public boolean isDrawable() {
|
||||
return !(x == null || y == null || width == null || height == null);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,572 @@
|
||||
package online.bobtony.gui.render;
|
||||
|
||||
import com.mojang.blaze3d.systems.RenderSystem;
|
||||
import online.bobtony.gui.Color;
|
||||
import online.bobtony.gui.Rectangle;
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.client.font.TextRenderer;
|
||||
import net.minecraft.client.gl.ShaderProgramKeys;
|
||||
import net.minecraft.client.gui.DrawContext;
|
||||
import net.minecraft.client.network.AbstractClientPlayerEntity;
|
||||
import net.minecraft.client.render.*;
|
||||
import net.minecraft.client.util.math.MatrixStack;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.math.MathHelper;
|
||||
import net.minecraft.util.math.RotationAxis;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
import org.joml.Matrix4f;
|
||||
import org.joml.Vector3f;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
public class Render2D {
|
||||
public static Vec3d center;
|
||||
|
||||
public static MinecraftClient mc = MinecraftClient.getInstance();
|
||||
|
||||
public static void updateScreenCenter() {
|
||||
Vector3f pos = new Vector3f(0, 0, 1);
|
||||
|
||||
if (mc.options.getBobView().getValue())
|
||||
{
|
||||
MatrixStack bobViewMatrices = new MatrixStack();
|
||||
|
||||
bobView(bobViewMatrices);
|
||||
pos.mulPosition(bobViewMatrices.peek().getPositionMatrix().invert());
|
||||
}
|
||||
|
||||
center = new Vec3d(pos.x, -pos.y, pos.z)
|
||||
.rotateX(-(float) Math.toRadians(mc.gameRenderer.getCamera().getPitch()))
|
||||
.rotateY(-(float) Math.toRadians(mc.gameRenderer.getCamera().getYaw()))
|
||||
.add(mc.gameRenderer.getCamera().getPos());
|
||||
}
|
||||
|
||||
private static void bobView(MatrixStack matrices) {
|
||||
Entity cameraEntity = MinecraftClient.getInstance().getCameraEntity();
|
||||
|
||||
if (cameraEntity instanceof AbstractClientPlayerEntity abstractClientPlayerEntity)
|
||||
{
|
||||
float tickDelta = mc.getRenderTickCounter().getTickDelta(true);
|
||||
|
||||
float var7 = abstractClientPlayerEntity.distanceMoved - abstractClientPlayerEntity.lastDistanceMoved;
|
||||
float g = -(abstractClientPlayerEntity.distanceMoved + var7 * tickDelta);
|
||||
float h = MathHelper.lerp(tickDelta, abstractClientPlayerEntity.prevStrideDistance, abstractClientPlayerEntity.strideDistance);
|
||||
|
||||
matrices.translate(MathHelper.sin(g * (float) Math.PI) * h * 0.5F, -Math.abs(MathHelper.cos(g * (float) Math.PI) * h), 0.0F);
|
||||
matrices.multiply(RotationAxis.POSITIVE_Z.rotationDegrees(MathHelper.sin(g * (float) Math.PI) * h * 3f));
|
||||
matrices.multiply(RotationAxis.POSITIVE_X.rotationDegrees(Math.abs(MathHelper.cos(g * (float) Math.PI - 0.2f) * h) * 5f));
|
||||
}
|
||||
}
|
||||
|
||||
public static void drawTexturedQuad(Matrix4f matrix4f, Identifier texture, Rectangle size, Color color) {
|
||||
drawTexturedQuad(matrix4f, texture, size.getX(), size.getY(), size.getWidth(), size.getHeight(), color);
|
||||
}
|
||||
|
||||
public static void drawTexturedQuad(Matrix4f matrix4f, Identifier texture, float x1, float y1, float width, float height, Color color) {
|
||||
int colorInt = color.getColorAsInt();
|
||||
|
||||
float x2 = x1 + width;
|
||||
float y2 = y1 + height;
|
||||
|
||||
RenderSystem.setShaderTexture(0, texture);
|
||||
RenderSystem.setShader(ShaderProgramKeys.POSITION_TEX_COLOR);
|
||||
RenderSystem.enableBlend();
|
||||
Tessellator tessellator = RenderSystem.renderThreadTesselator();
|
||||
BufferBuilder bufferBuilder = tessellator.begin(VertexFormat.DrawMode.QUADS,
|
||||
VertexFormats.POSITION_TEXTURE_COLOR);
|
||||
bufferBuilder.vertex(matrix4f, x1, y1, 0).color(colorInt).texture(0, 0);
|
||||
bufferBuilder.vertex(matrix4f, x1, y2, 0).color(colorInt).texture(0, 1);
|
||||
bufferBuilder.vertex(matrix4f, x2, y2, 0).color(colorInt).texture(1, 1);
|
||||
bufferBuilder.vertex(matrix4f, x2, y1, 0).color(colorInt).texture(1, 0);
|
||||
BufferRenderer.drawWithGlobalProgram(bufferBuilder.end());
|
||||
RenderSystem.disableBlend();
|
||||
}
|
||||
|
||||
public static void drawBox(Matrix4f matrix4f, Rectangle size, Color color) {
|
||||
drawBox(matrix4f, size.getX(), size.getY(), size.getWidth(), size.getHeight(), color);
|
||||
}
|
||||
|
||||
public static void drawBox(Matrix4f matrix4f, float x, float y, float width, float height, Color color) {
|
||||
int colorInt = color.getColorAsInt();
|
||||
|
||||
RenderSystem.enableBlend();
|
||||
RenderSystem.disableDepthTest();
|
||||
GL11.glEnable(GL11.GL_LINE_SMOOTH);
|
||||
Tessellator tessellator = RenderSystem.renderThreadTesselator();
|
||||
|
||||
RenderSystem.setShader(ShaderProgramKeys.POSITION_COLOR);
|
||||
BufferBuilder bufferBuilder = tessellator.begin(VertexFormat.DrawMode.QUADS, VertexFormats.POSITION_COLOR);
|
||||
bufferBuilder.vertex(matrix4f, x, y, 0).color(colorInt);
|
||||
bufferBuilder.vertex(matrix4f, x + width, y, 0).color(colorInt);
|
||||
bufferBuilder.vertex(matrix4f, x + width, y + height, 0).color(colorInt);
|
||||
bufferBuilder.vertex(matrix4f, x, y + height, 0).color(colorInt);
|
||||
BufferRenderer.drawWithGlobalProgram(bufferBuilder.end());
|
||||
|
||||
GL11.glDisable(GL11.GL_LINE_SMOOTH);
|
||||
RenderSystem.disableBlend();
|
||||
RenderSystem.enableDepthTest();
|
||||
}
|
||||
|
||||
public static void drawRoundedBox(Matrix4f matrix4f, Rectangle size, float radius, Color color) {
|
||||
drawRoundedBox(matrix4f, size.getX(), size.getY(), size.getWidth(), size.getHeight(), radius, color);
|
||||
}
|
||||
|
||||
public static void drawRoundedBox(Matrix4f matrix4f, float x, float y, float width, float height, float radius, Color color) {
|
||||
int colorInt = color.getColorAsInt();
|
||||
|
||||
RenderSystem.enableBlend();
|
||||
RenderSystem.disableDepthTest();
|
||||
GL11.glEnable(GL11.GL_LINE_SMOOTH);
|
||||
Tessellator tessellator = RenderSystem.renderThreadTesselator();
|
||||
RenderSystem.setShader(ShaderProgramKeys.POSITION_COLOR);
|
||||
|
||||
BufferBuilder bufferBuilder = tessellator.begin(VertexFormat.DrawMode.TRIANGLE_STRIP, VertexFormats.POSITION_COLOR);
|
||||
buildFilledArc(bufferBuilder, matrix4f, x + radius, y + radius, radius, 180.0f, 90.0f, color);
|
||||
buildFilledArc(bufferBuilder, matrix4f, x + width - radius, y + radius, radius, 270.0f, 90.0f, color);
|
||||
buildFilledArc(bufferBuilder, matrix4f, x + width - radius, y + height - radius, radius, 0.0f, 90.0f, color);
|
||||
buildFilledArc(bufferBuilder, matrix4f, x + radius, y + height - radius, radius, 90.0f, 90.0f, color);
|
||||
|
||||
bufferBuilder.vertex(matrix4f, x + radius, y, 0).color(colorInt);
|
||||
bufferBuilder.vertex(matrix4f, x + width - radius, y, 0).color(colorInt);
|
||||
bufferBuilder.vertex(matrix4f, x + radius, y + radius, 0).color(colorInt);
|
||||
|
||||
bufferBuilder.vertex(matrix4f, x + radius, y + radius, 0).color(colorInt);
|
||||
bufferBuilder.vertex(matrix4f, x + width - radius, y, 0).color(colorInt);
|
||||
bufferBuilder.vertex(matrix4f, x + width - radius, y + radius, 0).color(colorInt);
|
||||
|
||||
bufferBuilder.vertex(matrix4f, x + width - radius, y + radius, 0).color(colorInt);
|
||||
bufferBuilder.vertex(matrix4f, x + width, y + radius, 0).color(colorInt);
|
||||
bufferBuilder.vertex(matrix4f, x + width - radius, y + height - radius, 0).color(colorInt);
|
||||
|
||||
bufferBuilder.vertex(matrix4f, x + width, y + radius, 0).color(colorInt);
|
||||
bufferBuilder.vertex(matrix4f, x + width, y + height - radius, 0).color(colorInt);
|
||||
bufferBuilder.vertex(matrix4f, x + width - radius, y + height - radius, 0).color(colorInt);
|
||||
|
||||
bufferBuilder.vertex(matrix4f, x + width - radius, y + height - radius, 0).color(colorInt);
|
||||
bufferBuilder.vertex(matrix4f, x + width - radius, y + height, 0).color(colorInt);
|
||||
bufferBuilder.vertex(matrix4f, x + radius, y + height - radius, 0).color(colorInt);
|
||||
|
||||
bufferBuilder.vertex(matrix4f, x + radius, y + height - radius, 0).color(colorInt);
|
||||
bufferBuilder.vertex(matrix4f, x + radius, y + height, 0).color(colorInt);
|
||||
bufferBuilder.vertex(matrix4f, x + width - radius, y + height, 0).color(colorInt);
|
||||
|
||||
bufferBuilder.vertex(matrix4f, x + radius, y + height - radius, 0).color(colorInt);
|
||||
bufferBuilder.vertex(matrix4f, x, y + height - radius, 0).color(colorInt);
|
||||
bufferBuilder.vertex(matrix4f, x, y + radius, 0).color(colorInt);
|
||||
|
||||
bufferBuilder.vertex(matrix4f, x, y + radius, 0).color(colorInt);
|
||||
bufferBuilder.vertex(matrix4f, x + radius, y + radius, 0).color(colorInt);
|
||||
bufferBuilder.vertex(matrix4f, x + radius, y + height - radius, 0).color(colorInt);
|
||||
|
||||
bufferBuilder.vertex(matrix4f, x + radius, y + radius, 0).color(colorInt);
|
||||
bufferBuilder.vertex(matrix4f, x + width - radius, y + radius, 0).color(colorInt);
|
||||
bufferBuilder.vertex(matrix4f, x + radius, y + height - radius, 0).color(colorInt);
|
||||
|
||||
bufferBuilder.vertex(matrix4f, x + radius, y + height - radius, 0).color(colorInt);
|
||||
bufferBuilder.vertex(matrix4f, x + width - radius, y + height - radius, 0).color(colorInt);
|
||||
bufferBuilder.vertex(matrix4f, x + width - radius, y + radius, 0).color(colorInt);
|
||||
|
||||
BufferRenderer.drawWithGlobalProgram(bufferBuilder.end());
|
||||
GL11.glDisable(GL11.GL_LINE_SMOOTH);
|
||||
RenderSystem.disableBlend();
|
||||
RenderSystem.enableDepthTest();
|
||||
}
|
||||
|
||||
public static void drawCircle(Matrix4f matrix4f, float x, float y, float radius, Color color) {
|
||||
int colorInt = color.getColorAsInt();
|
||||
|
||||
RenderSystem.enableBlend();
|
||||
RenderSystem.disableDepthTest();
|
||||
GL11.glEnable(GL11.GL_LINE_SMOOTH);
|
||||
Tessellator tessellator = RenderSystem.renderThreadTesselator();
|
||||
RenderSystem.setShader(ShaderProgramKeys.POSITION_COLOR);
|
||||
|
||||
BufferBuilder bufferBuilder = tessellator.begin(VertexFormat.DrawMode.TRIANGLES, VertexFormats.POSITION_COLOR);
|
||||
double roundedInterval = (360.0f / 30.0f);
|
||||
|
||||
for (int i = 0; i < 30; i++) {
|
||||
double angle = Math.toRadians(0 + (i * roundedInterval));
|
||||
double angle2 = Math.toRadians(0 + ((i + 1) * roundedInterval));
|
||||
float radiusX1 = (float) (Math.cos(angle) * radius);
|
||||
float radiusY1 = (float) Math.sin(angle) * radius;
|
||||
float radiusX2 = (float) Math.cos(angle2) * radius;
|
||||
float radiusY2 = (float) Math.sin(angle2) * radius;
|
||||
|
||||
bufferBuilder.vertex(matrix4f, x, y, 0).color(colorInt);
|
||||
bufferBuilder.vertex(matrix4f, x + radiusX1, y + radiusY1, 0).color(colorInt);
|
||||
bufferBuilder.vertex(matrix4f, x + radiusX2, y + radiusY2, 0).color(colorInt);
|
||||
}
|
||||
BufferRenderer.drawWithGlobalProgram(bufferBuilder.end());
|
||||
GL11.glDisable(GL11.GL_LINE_SMOOTH);
|
||||
RenderSystem.disableBlend();
|
||||
RenderSystem.enableDepthTest();
|
||||
}
|
||||
|
||||
public static void drawTranslucentBlurredRoundedBox(Matrix4f matrix4f, float x, float y, float width, float height, float radius, Color color) {
|
||||
RenderSystem.enableBlend();
|
||||
RenderSystem.disableDepthTest();
|
||||
GL11.glEnable(GL11.GL_LINE_SMOOTH);
|
||||
RenderSystem.setShader(ShaderProgramKeys.POSITION_COLOR);
|
||||
|
||||
for (int i = 0; i < 5; i++) {
|
||||
float r = color.getRed();
|
||||
float g = color.getGreen();
|
||||
float b = color.getBlue();
|
||||
float alpha = color.getAlpha() * (1.0f / (i + 1));
|
||||
|
||||
Color newColor = new Color(r, g, b, alpha);
|
||||
drawRoundedBox(matrix4f, x - i, y - i, width + 2 * i, height + 2 * i, radius + i, newColor);
|
||||
}
|
||||
|
||||
drawRoundedBox(matrix4f, x, y, width, height, radius, color);
|
||||
GL11.glDisable(GL11.GL_LINE_SMOOTH);
|
||||
RenderSystem.disableBlend();
|
||||
RenderSystem.enableDepthTest();
|
||||
}
|
||||
|
||||
public static void drawOutlinedBox(Matrix4f matrix4f, Rectangle size, Color outlineColor, Color backgroundColor) {
|
||||
drawOutlinedBox(matrix4f, size.getX(), size.getY(), size.getWidth(), size.getHeight(), outlineColor,
|
||||
backgroundColor);
|
||||
}
|
||||
|
||||
public static void drawOutlinedBox(Matrix4f matrix4f, float x, float y, float width, float height, Color outlineColor, Color backgroundColor) {
|
||||
int backgroundColorInt = backgroundColor.getColorAsInt();
|
||||
|
||||
RenderSystem.enableBlend();
|
||||
RenderSystem.disableDepthTest();
|
||||
GL11.glEnable(GL11.GL_LINE_SMOOTH);
|
||||
Tessellator tessellator = RenderSystem.renderThreadTesselator();
|
||||
RenderSystem.setShader(ShaderProgramKeys.POSITION_COLOR);
|
||||
|
||||
BufferBuilder bufferBuilder = tessellator.begin(VertexFormat.DrawMode.QUADS, VertexFormats.POSITION_COLOR);
|
||||
bufferBuilder.vertex(matrix4f, x, y, 0).color(backgroundColorInt);
|
||||
bufferBuilder.vertex(matrix4f, x + width, y, 0).color(backgroundColorInt);
|
||||
bufferBuilder.vertex(matrix4f, x + width, y + height, 0).color(backgroundColorInt);
|
||||
bufferBuilder.vertex(matrix4f, x, y + height, 0).color(backgroundColorInt);
|
||||
BufferRenderer.drawWithGlobalProgram(bufferBuilder.end());
|
||||
|
||||
int outlineColorInt = outlineColor.getColorAsInt();
|
||||
|
||||
bufferBuilder = tessellator.begin(VertexFormat.DrawMode.DEBUG_LINE_STRIP, VertexFormats.POSITION_COLOR);
|
||||
bufferBuilder.vertex(matrix4f, x, y, 0).color(outlineColorInt);
|
||||
bufferBuilder.vertex(matrix4f, x + width, y, 0).color(outlineColorInt);
|
||||
bufferBuilder.vertex(matrix4f, x + width, y + height, 0).color(outlineColorInt);
|
||||
bufferBuilder.vertex(matrix4f, x, y + height, 0).color(outlineColorInt);
|
||||
bufferBuilder.vertex(matrix4f, x, y, 0).color(outlineColorInt);
|
||||
|
||||
BufferRenderer.drawWithGlobalProgram(bufferBuilder.end());
|
||||
GL11.glDisable(GL11.GL_LINE_SMOOTH);
|
||||
RenderSystem.disableBlend();
|
||||
RenderSystem.enableDepthTest();
|
||||
}
|
||||
|
||||
public static void drawBoxOutline(Matrix4f matrix4f, Rectangle size, Color color) {
|
||||
drawBoxOutline(matrix4f, size.getX(), size.getY(), size.getWidth(), size.getHeight(), color);
|
||||
}
|
||||
|
||||
public static void drawBoxOutline(Matrix4f matrix4f, float x, float y, float width, float height, Color color) {
|
||||
int colorInt = color.getColorAsInt();
|
||||
|
||||
RenderSystem.enableBlend();
|
||||
RenderSystem.disableDepthTest();
|
||||
GL11.glEnable(GL11.GL_LINE_SMOOTH);
|
||||
Tessellator tessellator = RenderSystem.renderThreadTesselator();
|
||||
RenderSystem.setShader(ShaderProgramKeys.POSITION_COLOR);
|
||||
|
||||
BufferBuilder bufferBuilder = tessellator.begin(VertexFormat.DrawMode.DEBUG_LINE_STRIP,
|
||||
VertexFormats.POSITION_COLOR);
|
||||
bufferBuilder.vertex(matrix4f, x, y, 0).color(colorInt);
|
||||
bufferBuilder.vertex(matrix4f, x + width, y, 0).color(colorInt);
|
||||
bufferBuilder.vertex(matrix4f, x + width, y + height, 0).color(colorInt);
|
||||
bufferBuilder.vertex(matrix4f, x, y + height, 0).color(colorInt);
|
||||
bufferBuilder.vertex(matrix4f, x, y, 0).color(colorInt);
|
||||
|
||||
BufferRenderer.drawWithGlobalProgram(bufferBuilder.end());
|
||||
|
||||
GL11.glDisable(GL11.GL_LINE_SMOOTH);
|
||||
RenderSystem.disableBlend();
|
||||
RenderSystem.enableDepthTest();
|
||||
}
|
||||
|
||||
public static void drawRoundedBoxOutline(Matrix4f matrix4f, Rectangle size, float radius, Color color) {
|
||||
drawRoundedBoxOutline(matrix4f, size.getX(), size.getY(), size.getWidth(), size.getHeight(), radius, color);
|
||||
}
|
||||
|
||||
public static void drawOutlinedRoundedBox(Matrix4f matrix4f, float x, float y, float width, float height, float radius, Color outlineColor, Color backgroundColor) {
|
||||
int backgroundColorInt = backgroundColor.getColorAsInt();
|
||||
|
||||
RenderSystem.enableBlend();
|
||||
RenderSystem.disableDepthTest();
|
||||
GL11.glEnable(GL11.GL_LINE_SMOOTH);
|
||||
|
||||
Tessellator tessellator = RenderSystem.renderThreadTesselator();
|
||||
RenderSystem.setShader(ShaderProgramKeys.POSITION_COLOR);
|
||||
|
||||
BufferBuilder bufferBuilder = tessellator.begin(VertexFormat.DrawMode.TRIANGLES, VertexFormats.POSITION_COLOR);
|
||||
buildFilledArc(bufferBuilder, matrix4f, x + radius, y + radius, radius, 180.0f, 90.0f, backgroundColor);
|
||||
buildFilledArc(bufferBuilder, matrix4f, x + width - radius, y + radius, radius, 270.0f, 90.0f, backgroundColor);
|
||||
buildFilledArc(bufferBuilder, matrix4f, x + width - radius, y + height - radius, radius, 0.0f, 90.0f,
|
||||
backgroundColor);
|
||||
buildFilledArc(bufferBuilder, matrix4f, x + radius, y + height - radius, radius, 90.0f, 90.0f, backgroundColor);
|
||||
|
||||
bufferBuilder.vertex(matrix4f, x + radius, y, 0).color(backgroundColorInt);
|
||||
bufferBuilder.vertex(matrix4f, x + width - radius, y, 0).color(backgroundColorInt);
|
||||
bufferBuilder.vertex(matrix4f, x + radius, y + radius, 0).color(backgroundColorInt);
|
||||
|
||||
bufferBuilder.vertex(matrix4f, x + radius, y + radius, 0).color(backgroundColorInt);
|
||||
bufferBuilder.vertex(matrix4f, x + width - radius, y, 0).color(backgroundColorInt);
|
||||
bufferBuilder.vertex(matrix4f, x + width - radius, y + radius, 0).color(backgroundColorInt);
|
||||
|
||||
bufferBuilder.vertex(matrix4f, x + width - radius, y + radius, 0).color(backgroundColorInt);
|
||||
bufferBuilder.vertex(matrix4f, x + width, y + radius, 0).color(backgroundColorInt);
|
||||
bufferBuilder.vertex(matrix4f, x + width - radius, y + height - radius, 0).color(backgroundColorInt);
|
||||
|
||||
bufferBuilder.vertex(matrix4f, x + width, y + radius, 0).color(backgroundColorInt);
|
||||
bufferBuilder.vertex(matrix4f, x + width, y + height - radius, 0).color(backgroundColorInt);
|
||||
bufferBuilder.vertex(matrix4f, x + width - radius, y + height - radius, 0).color(backgroundColorInt);
|
||||
|
||||
bufferBuilder.vertex(matrix4f, x + width - radius, y + height - radius, 0).color(backgroundColorInt);
|
||||
bufferBuilder.vertex(matrix4f, x + width - radius, y + height, 0).color(backgroundColorInt);
|
||||
bufferBuilder.vertex(matrix4f, x + radius, y + height - radius, 0).color(backgroundColorInt);
|
||||
|
||||
bufferBuilder.vertex(matrix4f, x + radius, y + height - radius, 0).color(backgroundColorInt);
|
||||
bufferBuilder.vertex(matrix4f, x + radius, y + height, 0).color(backgroundColorInt);
|
||||
bufferBuilder.vertex(matrix4f, x + width - radius, y + height, 0).color(backgroundColorInt);
|
||||
|
||||
bufferBuilder.vertex(matrix4f, x + radius, y + height - radius, 0).color(backgroundColorInt);
|
||||
bufferBuilder.vertex(matrix4f, x, y + height - radius, 0).color(backgroundColorInt);
|
||||
bufferBuilder.vertex(matrix4f, x, y + radius, 0).color(backgroundColorInt);
|
||||
|
||||
bufferBuilder.vertex(matrix4f, x, y + radius, 0).color(backgroundColorInt);
|
||||
bufferBuilder.vertex(matrix4f, x + radius, y + radius, 0).color(backgroundColorInt);
|
||||
bufferBuilder.vertex(matrix4f, x + radius, y + height - radius, 0).color(backgroundColorInt);
|
||||
|
||||
bufferBuilder.vertex(matrix4f, x + radius, y + radius, 0).color(backgroundColorInt);
|
||||
bufferBuilder.vertex(matrix4f, x + width - radius, y + radius, 0).color(backgroundColorInt);
|
||||
bufferBuilder.vertex(matrix4f, x + radius, y + height - radius, 0).color(backgroundColorInt);
|
||||
|
||||
bufferBuilder.vertex(matrix4f, x + radius, y + height - radius, 0).color(backgroundColorInt);
|
||||
bufferBuilder.vertex(matrix4f, x + width - radius, y + height - radius, 0).color(backgroundColorInt);
|
||||
bufferBuilder.vertex(matrix4f, x + width - radius, y + radius, 0).color(backgroundColorInt);
|
||||
|
||||
BufferRenderer.drawWithGlobalProgram(bufferBuilder.end());
|
||||
|
||||
int outlineColorInt = outlineColor.getColorAsInt();
|
||||
|
||||
bufferBuilder = tessellator.begin(VertexFormat.DrawMode.DEBUG_LINE_STRIP, VertexFormats.POSITION_COLOR);
|
||||
buildArc(bufferBuilder, matrix4f, x + radius, y + radius, radius, 180.0f, 90.0f, outlineColor);
|
||||
bufferBuilder.vertex(matrix4f, x + radius, y, 0).color(outlineColorInt);
|
||||
bufferBuilder.vertex(matrix4f, x + width - radius, y, 0).color(outlineColorInt);
|
||||
|
||||
buildArc(bufferBuilder, matrix4f, x + width - radius, y + radius, radius, 270.0f, 90.0f, outlineColor);
|
||||
bufferBuilder.vertex(matrix4f, x + width, y + radius, 0).color(outlineColorInt);
|
||||
bufferBuilder.vertex(matrix4f, x + width, y + height - radius, 0).color(outlineColorInt);
|
||||
|
||||
buildArc(bufferBuilder, matrix4f, x + width - radius, y + height - radius, radius, 0.0f, 90.0f, outlineColor);
|
||||
bufferBuilder.vertex(matrix4f, x + width - radius, y + height, 0).color(outlineColorInt);
|
||||
bufferBuilder.vertex(matrix4f, x + radius, y + height, 0).color(outlineColorInt);
|
||||
|
||||
buildArc(bufferBuilder, matrix4f, x + radius, y + height - radius, radius, 90.0f, 90.0f, outlineColor);
|
||||
bufferBuilder.vertex(matrix4f, x, y + height - radius, 0).color(outlineColorInt);
|
||||
bufferBuilder.vertex(matrix4f, x, y + radius, 0).color(outlineColorInt);
|
||||
|
||||
BufferRenderer.drawWithGlobalProgram(bufferBuilder.end());
|
||||
|
||||
GL11.glDisable(GL11.GL_LINE_SMOOTH);
|
||||
RenderSystem.disableBlend();
|
||||
RenderSystem.enableDepthTest();
|
||||
}
|
||||
|
||||
public static void drawRoundedBoxOutline(Matrix4f matrix4f, float x, float y, float width, float height, float radius, Color color) {
|
||||
int colorInt = color.getColorAsInt();
|
||||
|
||||
RenderSystem.enableBlend();
|
||||
RenderSystem.disableDepthTest();
|
||||
GL11.glEnable(GL11.GL_LINE_SMOOTH);
|
||||
Tessellator tessellator = RenderSystem.renderThreadTesselator();
|
||||
RenderSystem.setShader(ShaderProgramKeys.POSITION_COLOR);
|
||||
|
||||
BufferBuilder bufferBuilder = tessellator.begin(VertexFormat.DrawMode.DEBUG_LINE_STRIP, VertexFormats.POSITION_COLOR);
|
||||
buildArc(bufferBuilder, matrix4f, x + radius, y + radius, radius, 180.0f, 90.0f, color);
|
||||
bufferBuilder.vertex(matrix4f, x + radius, y, 0).color(colorInt);
|
||||
bufferBuilder.vertex(matrix4f, x + width - radius, y, 0).color(colorInt);
|
||||
|
||||
buildArc(bufferBuilder, matrix4f, x + width - radius, y + radius, radius, 270.0f, 90.0f, color);
|
||||
bufferBuilder.vertex(matrix4f, x + width, y + radius, 0).color(colorInt);
|
||||
bufferBuilder.vertex(matrix4f, x + width, y + height - radius, 0).color(colorInt);
|
||||
|
||||
buildArc(bufferBuilder, matrix4f, x + width - radius, y + height - radius, radius, 0.0f, 90.0f, color);
|
||||
bufferBuilder.vertex(matrix4f, x + width - radius, y + height, 0).color(colorInt);
|
||||
bufferBuilder.vertex(matrix4f, x + radius, y + height, 0).color(colorInt);
|
||||
|
||||
buildArc(bufferBuilder, matrix4f, x + radius, y + height - radius, radius, 90.0f, 90.0f, color);
|
||||
bufferBuilder.vertex(matrix4f, x, y + height - radius, 0).color(colorInt);
|
||||
bufferBuilder.vertex(matrix4f, x, y + radius, 0).color(colorInt);
|
||||
|
||||
BufferRenderer.drawWithGlobalProgram(bufferBuilder.end());
|
||||
|
||||
GL11.glDisable(GL11.GL_LINE_SMOOTH);
|
||||
RenderSystem.disableBlend();
|
||||
RenderSystem.enableDepthTest();
|
||||
}
|
||||
|
||||
public static void drawLine(Matrix4f matrix4f, float x1, float y1, float x2, float y2, Color color) {
|
||||
int colorInt = color.getColorAsInt();
|
||||
|
||||
RenderSystem.enableBlend();
|
||||
RenderSystem.disableDepthTest();
|
||||
GL11.glEnable(GL11.GL_LINE_SMOOTH);
|
||||
Tessellator tessellator = RenderSystem.renderThreadTesselator();
|
||||
RenderSystem.setShader(ShaderProgramKeys.POSITION_COLOR);
|
||||
|
||||
BufferBuilder bufferBuilder = tessellator.begin(VertexFormat.DrawMode.DEBUG_LINES,
|
||||
VertexFormats.POSITION_COLOR);
|
||||
bufferBuilder.vertex(matrix4f, x1, y1, 0).color(colorInt);
|
||||
bufferBuilder.vertex(matrix4f, x2, y2, 0).color(colorInt);
|
||||
BufferRenderer.drawWithGlobalProgram(bufferBuilder.end());
|
||||
|
||||
GL11.glDisable(GL11.GL_LINE_SMOOTH);
|
||||
RenderSystem.disableBlend();
|
||||
RenderSystem.enableDepthTest();
|
||||
}
|
||||
|
||||
public static void drawHorizontalGradient(Matrix4f matrix4f, Rectangle size, Color startColor, Color endColor) {
|
||||
drawHorizontalGradient(matrix4f, size.getX(), size.getY(), size.getWidth(), size.getHeight(), startColor, endColor);
|
||||
}
|
||||
|
||||
public static void drawHorizontalGradient(Matrix4f matrix4f, float x, float y, float width, float height, Color startColor, Color endColor) {
|
||||
int startColorInt = startColor.getColorAsInt();
|
||||
int endColorInt = endColor.getColorAsInt();
|
||||
|
||||
RenderSystem.enableBlend();
|
||||
RenderSystem.disableDepthTest();
|
||||
GL11.glEnable(GL11.GL_LINE_SMOOTH);
|
||||
Tessellator tessellator = RenderSystem.renderThreadTesselator();
|
||||
RenderSystem.setShader(ShaderProgramKeys.POSITION_COLOR);
|
||||
|
||||
BufferBuilder bufferBuilder = tessellator.begin(VertexFormat.DrawMode.QUADS, VertexFormats.POSITION_COLOR);
|
||||
bufferBuilder.vertex(matrix4f, x, y, 0.0F).color(startColorInt);
|
||||
bufferBuilder.vertex(matrix4f, x + width, y, 0.0F).color(endColorInt);
|
||||
bufferBuilder.vertex(matrix4f, x + width, y + height, 0.0F).color(endColorInt);
|
||||
bufferBuilder.vertex(matrix4f, x, y + height, 0.0F).color(startColorInt);
|
||||
|
||||
BufferRenderer.drawWithGlobalProgram(bufferBuilder.end());
|
||||
GL11.glDisable(GL11.GL_LINE_SMOOTH);
|
||||
RenderSystem.disableBlend();
|
||||
RenderSystem.enableDepthTest();
|
||||
}
|
||||
|
||||
public static void drawVerticalGradient(Matrix4f matrix4f, Rectangle size, Color startColor, Color endColor) {
|
||||
drawVerticalGradient(matrix4f, size.getX(), size.getY(), size.getWidth(), size.getHeight(), startColor, endColor);
|
||||
}
|
||||
|
||||
public static void drawVerticalGradient(Matrix4f matrix4f, float x, float y, float width, float height, Color startColor, Color endColor) {
|
||||
int startColorInt = startColor.getColorAsInt();
|
||||
int endColorInt = endColor.getColorAsInt();
|
||||
|
||||
RenderSystem.enableBlend();
|
||||
RenderSystem.disableDepthTest();
|
||||
GL11.glEnable(GL11.GL_LINE_SMOOTH);
|
||||
Tessellator tessellator = RenderSystem.renderThreadTesselator();
|
||||
RenderSystem.setShader(ShaderProgramKeys.POSITION_COLOR);
|
||||
|
||||
BufferBuilder bufferBuilder = tessellator.begin(VertexFormat.DrawMode.QUADS, VertexFormats.POSITION_COLOR);
|
||||
bufferBuilder.vertex(matrix4f, x, y, 0.0F).color(startColorInt);
|
||||
bufferBuilder.vertex(matrix4f, x + width, y, 0.0F).color(startColorInt);
|
||||
bufferBuilder.vertex(matrix4f, x + width, y + height, 0.0F).color(endColorInt);
|
||||
bufferBuilder.vertex(matrix4f, x, y + height, 0.0F).color(endColorInt);
|
||||
|
||||
BufferRenderer.drawWithGlobalProgram(bufferBuilder.end());
|
||||
GL11.glDisable(GL11.GL_LINE_SMOOTH);
|
||||
RenderSystem.disableBlend();
|
||||
RenderSystem.enableDepthTest();
|
||||
}
|
||||
|
||||
public static void drawItem(DrawContext drawContext, ItemStack stack, float x, float y) {
|
||||
drawContext.drawItem(stack, (int) x, (int) y);
|
||||
}
|
||||
|
||||
public static void drawString(DrawContext drawContext, String text, Vec3d pos, Color color) {
|
||||
|
||||
}
|
||||
|
||||
public static void drawStringWithScale(DrawContext drawContext, String text, float x, float y, Color color, float scale) {
|
||||
MinecraftClient client = MinecraftClient.getInstance();
|
||||
MatrixStack matrixStack = drawContext.getMatrices();
|
||||
matrixStack.push();
|
||||
matrixStack.scale(scale, scale, 1.0f);
|
||||
if (scale > 1.0f) {
|
||||
matrixStack.translate(-x / scale, -y / scale, 0.0f);
|
||||
}
|
||||
else {
|
||||
matrixStack.translate((x / scale) - x, (y * scale) - y, 0.0f);
|
||||
}
|
||||
drawContext.drawText(client.textRenderer, text, (int) x, (int) y, color.getColorAsInt(), false);
|
||||
matrixStack.pop();
|
||||
}
|
||||
|
||||
public static void buildFilledArc(BufferBuilder bufferBuilder, Matrix4f matrix, float x, float y, float radius, float startAngle, float sweepAngle, Color color) {
|
||||
double roundedInterval = (sweepAngle / radius);
|
||||
|
||||
int colorInt = color.getColorAsInt();
|
||||
|
||||
for (int i = 0; i < radius; i++) {
|
||||
double angle = Math.toRadians(startAngle + (i * roundedInterval));
|
||||
double angle2 = Math.toRadians(startAngle + ((i + 1) * roundedInterval));
|
||||
float radiusX1 = (float) (Math.cos(angle) * radius);
|
||||
float radiusY1 = (float) Math.sin(angle) * radius;
|
||||
float radiusX2 = (float) Math.cos(angle2) * radius;
|
||||
float radiusY2 = (float) Math.sin(angle2) * radius;
|
||||
|
||||
bufferBuilder.vertex(matrix, x, y, 0).color(colorInt);
|
||||
bufferBuilder.vertex(matrix, x + radiusX1, y + radiusY1, 0).color(colorInt);
|
||||
bufferBuilder.vertex(matrix, x + radiusX2, y + radiusY2, 0).color(colorInt);
|
||||
}
|
||||
}
|
||||
|
||||
public static void drawRoundedBox2(Matrix4f matrix4f, float x, float y, float width, float height, float radius, Color color) {
|
||||
int colorInt = color.getColorAsInt();
|
||||
|
||||
RenderSystem.enableBlend();
|
||||
RenderSystem.disableDepthTest();
|
||||
GL11.glEnable(GL11.GL_LINE_SMOOTH);
|
||||
|
||||
Tessellator tessellator = RenderSystem.renderThreadTesselator();
|
||||
BufferBuilder bufferBuilder = tessellator.begin(VertexFormat.DrawMode.TRIANGLE_STRIP, VertexFormats.POSITION_COLOR);
|
||||
|
||||
bufferBuilder.vertex(matrix4f, x + radius, y + radius, 0).color(colorInt);
|
||||
bufferBuilder.vertex(matrix4f, x + width - radius, y + radius, 0).color(colorInt);
|
||||
bufferBuilder.vertex(matrix4f, x + radius, y + height - radius, 0).color(colorInt);
|
||||
bufferBuilder.vertex(matrix4f, x + width - radius, y + height - radius, 0).color(colorInt);
|
||||
|
||||
buildFilledArc(bufferBuilder, matrix4f, x + radius, y + radius, radius, 180.0f, 90.0f, color);
|
||||
buildFilledArc(bufferBuilder, matrix4f, x + width - radius, y + radius, radius, 270.0f, 90.0f, color);
|
||||
buildFilledArc(bufferBuilder, matrix4f, x + width - radius, y + height - radius, radius, 0.0f, 90.0f, color);
|
||||
buildFilledArc(bufferBuilder, matrix4f, x + radius, y + height - radius, radius, 90.0f, 90.0f, color);
|
||||
|
||||
BufferRenderer.drawWithGlobalProgram(bufferBuilder.end());
|
||||
|
||||
GL11.glDisable(GL11.GL_LINE_SMOOTH);
|
||||
RenderSystem.disableBlend();
|
||||
RenderSystem.enableDepthTest();
|
||||
}
|
||||
|
||||
private static void buildArc(BufferBuilder bufferBuilder, Matrix4f matrix, float x, float y, float radius, float startAngle, float sweepAngle, Color color) {
|
||||
float roundedInterval = (sweepAngle / radius);
|
||||
|
||||
int colorInt = color.getColorAsInt();
|
||||
for (int i = 0; i < radius; i++) {
|
||||
double angle = Math.toRadians(startAngle + (i * roundedInterval));
|
||||
float radiusX1 = (float) (Math.cos(angle) * radius);
|
||||
float radiusY1 = (float) Math.sin(angle) * radius;
|
||||
|
||||
bufferBuilder.vertex(matrix, x + radiusX1, y + radiusY1, 0).color(colorInt);
|
||||
}
|
||||
}
|
||||
|
||||
public static int getStringWidth(String text) {
|
||||
TextRenderer textRenderer = MinecraftClient.getInstance().textRenderer;
|
||||
return textRenderer.getWidth(text);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
package online.bobtony.gui.render;
|
||||
|
||||
import com.mojang.blaze3d.systems.RenderSystem;
|
||||
import net.minecraft.client.gl.ShaderProgramKeys;
|
||||
import net.minecraft.client.render.*;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
import org.joml.Matrix4f;
|
||||
|
||||
import java.awt.Color;
|
||||
|
||||
public class RoundedBoxRenderer {
|
||||
public static void drawRoundedBox(Matrix4f matrix4f, float x, float y, float width, float height, float radius, Color color) {
|
||||
int colorInt = color.getRGB();
|
||||
|
||||
RenderSystem.enableBlend();
|
||||
RenderSystem.disableDepthTest();
|
||||
GL11.glEnable(GL11.GL_LINE_SMOOTH);
|
||||
Tessellator tessellator = RenderSystem.renderThreadTesselator();
|
||||
RenderSystem.setShader(ShaderProgramKeys.POSITION_COLOR);
|
||||
|
||||
BufferBuilder bufferBuilder = tessellator.begin(VertexFormat.DrawMode.LINES, VertexFormats.POSITION_COLOR);
|
||||
|
||||
drawFilledArc(bufferBuilder, matrix4f, x + radius, y + radius, radius, 180.0f, 90.0f, colorInt);
|
||||
drawFilledArc(bufferBuilder, matrix4f, x + width - radius, y + radius, radius, 270.0f, 90.0f, colorInt);
|
||||
drawFilledArc(bufferBuilder, matrix4f, x + width - radius, y + height - radius, radius, 0.0f, 90.0f, colorInt);
|
||||
drawFilledArc(bufferBuilder, matrix4f, x + radius, y + height - radius, radius, 90.0f, 90.0f, colorInt);
|
||||
|
||||
drawRect(bufferBuilder, matrix4f, x + radius, y, width - 2 * radius, height, colorInt);
|
||||
drawRect(bufferBuilder, matrix4f, x, y + radius, width, height - 2 * radius, colorInt);
|
||||
|
||||
BufferRenderer.drawWithGlobalProgram(bufferBuilder.end());
|
||||
GL11.glDisable(GL11.GL_LINE_SMOOTH);
|
||||
RenderSystem.disableBlend();
|
||||
RenderSystem.enableDepthTest();
|
||||
}
|
||||
|
||||
private static void drawRect(BufferBuilder buffer, Matrix4f matrix, float x, float y, float width, float height, int color) {
|
||||
buffer.vertex(matrix, x, y, 0).color(color);
|
||||
buffer.vertex(matrix, x + width, y, 0).color(color);
|
||||
buffer.vertex(matrix, x + width, y + height, 0).color(color);
|
||||
buffer.vertex(matrix, x, y + height, 0).color(color);
|
||||
}
|
||||
|
||||
private static void drawFilledArc(BufferBuilder buffer, Matrix4f matrix, float cx, float cy, float radius, float startAngle, float arcAngle, int color) {
|
||||
int segments = 20;
|
||||
float angleStep = arcAngle / segments;
|
||||
for (int i = 0; i < segments; i++) {
|
||||
float theta1 = (float) Math.toRadians(startAngle + i * angleStep);
|
||||
float theta2 = (float) Math.toRadians(startAngle + (i + 1) * angleStep);
|
||||
|
||||
float x1 = cx + (float) Math.cos(theta1) * radius;
|
||||
float y1 = cy + (float) Math.sin(theta1) * radius;
|
||||
float x2 = cx + (float) Math.cos(theta2) * radius;
|
||||
float y2 = cy + (float) Math.sin(theta2) * radius;
|
||||
|
||||
buffer.vertex(matrix, cx, cy, 0).color(color);
|
||||
buffer.vertex(matrix, x1, y1, 0).color(color);
|
||||
buffer.vertex(matrix, x2, y2, 0).color(color);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
package online.bobtony.gui.widgets;
|
||||
|
||||
import net.minecraft.client.sound.PositionedSoundInstance;
|
||||
import net.minecraft.sound.SoundEvents;
|
||||
import online.bobtony.gui.render.Render2D;
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.client.gui.DrawContext;
|
||||
import net.minecraft.client.gui.screen.narration.NarrationMessageBuilder;
|
||||
import net.minecraft.client.gui.widget.ClickableWidget;
|
||||
import online.bobtony.gui.Color;
|
||||
import net.minecraft.text.Text;
|
||||
import org.joml.Matrix4f;
|
||||
|
||||
public class RoundedButton extends ClickableWidget {
|
||||
private final Runnable onClick;
|
||||
private final Color color;
|
||||
private final Color hoverColor;
|
||||
private boolean isHovered = false;
|
||||
|
||||
public RoundedButton(int x, int y, int width, int height, Text message, Color color, Runnable onClick) {
|
||||
super(x, y, width, height, message);
|
||||
this.color = color;
|
||||
this.hoverColor = color.add(1.0F, 1.0F, 1.0F);
|
||||
this.onClick = onClick;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void renderWidget(DrawContext context, int mouseX, int mouseY, float delta) {
|
||||
isHovered = isMouseOver(mouseX, mouseY);
|
||||
Matrix4f matrix4f = context.getMatrices().peek().getPositionMatrix();
|
||||
drawRoundedBox(matrix4f, getX(), getY(), getWidth(), getHeight(), 2, isHovered ? hoverColor : color);
|
||||
|
||||
int textX = getX() + getWidth() / 2;
|
||||
int textY = getY() + getHeight() / 2 - 4;
|
||||
context.drawCenteredTextWithShadow(MinecraftClient.getInstance().textRenderer, getMessage(), textX, textY, 0xFFFFFF);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean mouseClicked(double mouseX, double mouseY, int button) {
|
||||
if (isMouseOver(mouseX, mouseY) && button == 0) {
|
||||
onClick.run();
|
||||
PositionedSoundInstance.master(SoundEvents.UI_BUTTON_CLICK, 1.0F);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void appendClickableNarrations(NarrationMessageBuilder builder) {
|
||||
|
||||
}
|
||||
|
||||
public static void drawRoundedBox(Matrix4f matrix4f, float x, float y, float width, float height, float radius, Color color) {
|
||||
Render2D.drawRoundedBoxOutline(matrix4f, x, y, width, height, radius, color);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package online.bobtony.handlers;
|
||||
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.text.Text;
|
||||
import online.bobtony.BobTony;
|
||||
|
||||
public class ChestESPHandler {
|
||||
public static void handleChestESP(){
|
||||
MinecraftClient client = MinecraftClient.getInstance();
|
||||
BobTony.chestesp = !BobTony.chestesp;
|
||||
if (BobTony.chestesp){
|
||||
BobTony.sendMessage(client.player, "ChestESP: §aOn", false);
|
||||
}else {
|
||||
BobTony.sendMessage(client.player, "ChestESP: §cOff", false);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
package online.bobtony.handlers;
|
||||
|
||||
import net.minecraft.client.network.ClientPlayerEntity;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
import online.bobtony.BobTony;
|
||||
import online.bobtony.enums.Modes;
|
||||
|
||||
public class DoubleJumpHandler {
|
||||
|
||||
public static void handleDoubleJump(ClientPlayerEntity player) {
|
||||
boolean isJumping = player.input.playerInput.jump();
|
||||
|
||||
if (isJumping && !BobTony.wasJumping) {
|
||||
long currentTime = System.currentTimeMillis();
|
||||
if (currentTime - BobTony.lastJumpTime < 300) {
|
||||
if(BobTony.mode == Modes.FLY) {
|
||||
toggleFlyMode(player);
|
||||
}else {
|
||||
boostPlayer(player);
|
||||
}
|
||||
}
|
||||
BobTony.lastJumpTime = currentTime;
|
||||
}
|
||||
|
||||
BobTony.wasJumping = isJumping;
|
||||
}
|
||||
|
||||
private static void toggleFlyMode(ClientPlayerEntity player) {
|
||||
boolean isFlying = !player.getAbilities().flying;
|
||||
player.getAbilities().flying = isFlying;
|
||||
player.getAbilities().setFlySpeed(BobTony.flyspeed);
|
||||
|
||||
if (isFlying) {
|
||||
BobTony.sendMessage(player, "Fly: §aEnabled", true);
|
||||
} else {
|
||||
BobTony.sendMessage(player, "Fly: §cDisabled", true);
|
||||
}
|
||||
|
||||
player.sendAbilitiesUpdate();
|
||||
}
|
||||
|
||||
private static void boostPlayer(ClientPlayerEntity apfel) {
|
||||
double pitch = apfel.getPitch();
|
||||
Vec3d velocity;
|
||||
|
||||
if (pitch > 70) {
|
||||
velocity = new Vec3d(0.0, 1.0, 0.0).multiply(BobTony.strength);
|
||||
} else {
|
||||
velocity = apfel.getRotationVector().multiply(BobTony.strength);
|
||||
}
|
||||
|
||||
apfel.addVelocity(velocity.x, velocity.y + 0.5, velocity.z);
|
||||
apfel.velocityModified = true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package online.bobtony.handlers;
|
||||
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import online.bobtony.BobTony;
|
||||
import online.bobtony.enums.Modes;
|
||||
|
||||
public class FlyHandler {
|
||||
public static void handleFly(){
|
||||
MinecraftClient client = MinecraftClient.getInstance();
|
||||
|
||||
if (BobTony.mode != Modes.FLY){
|
||||
BobTony.mode = Modes.FLY;
|
||||
BobTony.sendMessage(client.player, "Fly: §aOn", false);
|
||||
}else {
|
||||
BobTony.mode = Modes.NONE;
|
||||
BobTony.sendMessage(client.player, "Fly: §cOff", false);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
package online.bobtony.handlers;
|
||||
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.client.network.ClientPlayerEntity;
|
||||
import online.bobtony.BobTony;
|
||||
|
||||
public class FlySpeedCommandHandler {
|
||||
static float flyspeed = BobTony.flyspeed;
|
||||
|
||||
public static void handelFlySpeedCommand(String message){
|
||||
MinecraftClient client = MinecraftClient.getInstance();
|
||||
String[] parts = message.split(" ");
|
||||
if (parts.length == 2) {
|
||||
try {
|
||||
adjustFlySpeed(client.player, Float.parseFloat(parts[1]));
|
||||
BobTony.sendMessage(client.player, "Flyspeed: §c" + flyspeed, false);
|
||||
} catch (NumberFormatException e) {
|
||||
BobTony.sendMessage(client.player, "§cKeine richtige Zahl!", false);
|
||||
}
|
||||
} else {
|
||||
BobTony.sendMessage(client.player, "§cUsage: .strength <value>", false);
|
||||
}
|
||||
}
|
||||
|
||||
private static void adjustFlySpeed(ClientPlayerEntity player, float amount) {
|
||||
flyspeed = amount;
|
||||
player.getAbilities().setFlySpeed(flyspeed);
|
||||
player.sendAbilitiesUpdate();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package online.bobtony.handlers;
|
||||
|
||||
import net.minecraft.client.network.ClientPlayerEntity;
|
||||
import online.bobtony.BobTony;
|
||||
import online.bobtony.enums.Modes;
|
||||
|
||||
public class ModeSwitchHandler {
|
||||
public static void handleModeSwitch(ClientPlayerEntity player) {
|
||||
long currentTime = System.currentTimeMillis();
|
||||
if (BobTony.toggleModeKey.isPressed() && currentTime - BobTony.lastModeSwitchTime > BobTony.MODE_SWITCH_COOLDOWN) {
|
||||
if (BobTony.mode == Modes.FLY){
|
||||
BobTony.mode = Modes.BOOST;
|
||||
BobTony.sendMessage(player, " Fly: §cOff", false);
|
||||
BobTony.sendMessage(player, " Boost: §aOn", false);
|
||||
}else {
|
||||
BobTony.mode = Modes.FLY;
|
||||
BobTony.sendMessage(player, " Fly: §cOn", false);
|
||||
BobTony.sendMessage(player, " Boost: §aOff", false);
|
||||
}
|
||||
|
||||
BobTony.lastModeSwitchTime = currentTime;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package online.bobtony.handlers;
|
||||
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import online.bobtony.BobTony;
|
||||
|
||||
public class NoFallCommandHandler {
|
||||
|
||||
public static void handelNoFallCommand(){
|
||||
MinecraftClient client = MinecraftClient.getInstance();
|
||||
BobTony.nofall = !BobTony.nofall;
|
||||
if (BobTony.nofall){
|
||||
BobTony.sendMessage(client.player, "NoFall: §aOn", false);
|
||||
}else {
|
||||
BobTony.sendMessage(client.player, "NoFall: §cOff", false);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package online.bobtony.handlers;
|
||||
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.network.packet.c2s.play.PlayerInteractEntityC2SPacket;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
|
||||
public class NukeCommandHandler {
|
||||
public static void handleNukeCommand() {
|
||||
MinecraftClient client = MinecraftClient.getInstance();
|
||||
MinecraftServer server = client.getServer();
|
||||
|
||||
if (server != null) {
|
||||
server.getOverworld().getPlayers().forEach(player -> {
|
||||
PlayerInteractEntityC2SPacket packet = PlayerInteractEntityC2SPacket.attack(player, client.player.isSneaking());
|
||||
client.getNetworkHandler().sendPacket(packet);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
package online.bobtony.handlers;
|
||||
|
||||
import net.minecraft.client.network.ClientPlayerEntity;
|
||||
import net.minecraft.network.packet.c2s.play.PlayerMoveC2SPacket;
|
||||
import online.bobtony.BobTony;
|
||||
|
||||
public class SimulateMovementHandler {
|
||||
|
||||
public static void simulateMovement(ClientPlayerEntity player) {
|
||||
new Thread(() -> {
|
||||
try {
|
||||
boolean wasSneaking = player.input.playerInput.sneak();
|
||||
boolean wasTouchingCeiling = false;
|
||||
while (player.getAbilities().flying) {
|
||||
boolean isSneaking = player.input.playerInput.sneak();
|
||||
|
||||
if (!isSneaking) {
|
||||
long currentTime = System.currentTimeMillis();
|
||||
if (currentTime - BobTony.lastUpdateTime > 50) {
|
||||
player.networkHandler.sendPacket(
|
||||
new PlayerMoveC2SPacket.PositionAndOnGround(
|
||||
player.getX(), player.getY() + 0.05, player.getZ(), true, false
|
||||
)
|
||||
);
|
||||
player.networkHandler.sendPacket(
|
||||
new PlayerMoveC2SPacket.PositionAndOnGround(
|
||||
player.getX(), player.getY(), player.getZ(), true, false
|
||||
)
|
||||
);
|
||||
BobTony.lastUpdateTime = currentTime;
|
||||
}
|
||||
}
|
||||
|
||||
wasSneaking = isSneaking;
|
||||
|
||||
Thread.sleep(50);
|
||||
}
|
||||
} catch (InterruptedException ignored) {
|
||||
}
|
||||
}).start();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package online.bobtony.handlers;
|
||||
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import online.bobtony.BobTony;
|
||||
|
||||
public class SpeedCommandHandler {
|
||||
|
||||
public static void handleSpeedCommand(String message){
|
||||
MinecraftClient client = MinecraftClient.getInstance();
|
||||
|
||||
String[] parts = message.split(" ");
|
||||
if (parts.length == 2) {
|
||||
try {
|
||||
BobTony.speed = Float.parseFloat(parts[1]);
|
||||
client.player.setMovementSpeed(0.3f);
|
||||
BobTony.sendMessage(client.player, "Speed: §c" + client.player.getMovementSpeed(), false);
|
||||
} catch (NumberFormatException e) {
|
||||
BobTony.sendMessage(client.player, "§cKeine richtige Zahl!", false);
|
||||
}
|
||||
} else {
|
||||
BobTony.sendMessage(client.player, "§cUsage: .speed <value>", false);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package online.bobtony.handlers;
|
||||
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import online.bobtony.BobTony;
|
||||
|
||||
public class StrengthCommandHandler {
|
||||
public static void handleStrengthCommand(String message) {
|
||||
MinecraftClient client = MinecraftClient.getInstance();
|
||||
String[] parts = message.split(" ");
|
||||
if (parts.length == 2) {
|
||||
try {
|
||||
BobTony.strength = Float.parseFloat(parts[1]);
|
||||
BobTony.sendMessage(client.player, "Boost Strength: §c" + BobTony.strength, false);
|
||||
} catch (NumberFormatException e) {
|
||||
BobTony.sendMessage(client.player, "§cKeine richtige Zahl!", false);
|
||||
}
|
||||
} else {
|
||||
BobTony.sendMessage(client.player, "§cUsage: .strength <value>", false);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package online.bobtony.handlers;
|
||||
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import online.bobtony.BobTony;
|
||||
|
||||
public class TrackerHandler {
|
||||
|
||||
public static void handleTracker(String message){
|
||||
MinecraftClient client = MinecraftClient.getInstance();
|
||||
|
||||
String[] parts = message.split(" ");
|
||||
if (parts.length == 3) {
|
||||
if (parts[1].equals("add")){
|
||||
BobTony.trackerList.add(parts[2]);
|
||||
BobTony.sendMessage(client.player, "§aAdded " + parts[2] + " to Trackerlist: " + BobTony.trackerList, false);
|
||||
}else if (parts[1].equals("remove")){
|
||||
BobTony.trackerList.remove(parts[2]);
|
||||
}
|
||||
} else {
|
||||
BobTony.sendMessage(client.player, "§cUsage: .tracker <add|remove> <player_name>", false);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
package online.bobtony.handlers;
|
||||
|
||||
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents;
|
||||
import net.fabricmc.fabric.api.client.keybinding.v1.KeyBindingHelper;
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.client.option.KeyBinding;
|
||||
import net.minecraft.client.util.InputUtil;
|
||||
import org.lwjgl.glfw.GLFW;
|
||||
|
||||
public class ZoomHandler {
|
||||
private static boolean isZooming = false;
|
||||
private static final int DEFAULT_FOV = MinecraftClient.getInstance().options.getFov().getValue();
|
||||
private static final int ZOOMED_FOV = 30;
|
||||
private static final int ZOOM_SPEED = 2;
|
||||
|
||||
private static KeyBinding zoomKey;
|
||||
|
||||
public static void initialize() {
|
||||
zoomKey = KeyBindingHelper.registerKeyBinding(new KeyBinding(
|
||||
"bobtony.zoom",
|
||||
InputUtil.Type.KEYSYM,
|
||||
GLFW.GLFW_KEY_C,
|
||||
"BobTony"
|
||||
));
|
||||
|
||||
ClientTickEvents.END_CLIENT_TICK.register(client -> {
|
||||
boolean shouldZoom = zoomKey.isPressed();
|
||||
|
||||
if (shouldZoom != isZooming) {
|
||||
isZooming = shouldZoom;
|
||||
}
|
||||
|
||||
int currentFov = client.options.getFov().getValue();
|
||||
int targetFov = isZooming ? ZOOMED_FOV : DEFAULT_FOV;
|
||||
|
||||
if (currentFov != targetFov) {
|
||||
int newFov = currentFov;
|
||||
|
||||
if (isZooming) {
|
||||
newFov = Math.max(targetFov, currentFov - ZOOM_SPEED);
|
||||
} else {
|
||||
newFov = Math.min(targetFov, currentFov + ZOOM_SPEED);
|
||||
}
|
||||
|
||||
client.options.getFov().setValue(newFov);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
package online.bobtony.mixin;
|
||||
|
||||
import com.llamalad7.mixinextras.injector.ModifyReturnValue;
|
||||
import online.bobtony.utils.CapeHandler;
|
||||
import net.minecraft.client.network.AbstractClientPlayerEntity;
|
||||
import net.minecraft.client.network.PlayerListEntry;
|
||||
import net.minecraft.client.util.DefaultSkinHelper;
|
||||
import net.minecraft.client.util.SkinTextures;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
|
||||
@Mixin(AbstractClientPlayerEntity.class)
|
||||
public class AbstractClientPlayerEntityMixin {
|
||||
|
||||
@Shadow
|
||||
private PlayerListEntry playerListEntry;
|
||||
|
||||
@ModifyReturnValue(method = "getSkinTextures", at = @At("RETURN"))
|
||||
public SkinTextures handelCapes(SkinTextures original){
|
||||
|
||||
if (playerListEntry == null) {
|
||||
DefaultSkinHelper.getSkinTextures(((AbstractClientPlayerEntity) (Object) this).getUuid());
|
||||
}else {
|
||||
return CapeHandler.getCapes(original, ((AbstractClientPlayerEntity) (Object) this));
|
||||
}
|
||||
|
||||
return original;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package online.bobtony.mixin;
|
||||
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.client.network.ClientPlayerEntity;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||
|
||||
@Mixin(ClientPlayerEntity.class)
|
||||
public class ClientPlayerEntityMixin {
|
||||
|
||||
@Inject(method = "isSneaking", at = @At("HEAD"), cancellable = true)
|
||||
private void onIsSneaking(CallbackInfoReturnable<Boolean> info) {
|
||||
if (MinecraftClient.getInstance().player.getAbilities().flying)
|
||||
info.setReturnValue(false);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
package online.bobtony.mixin;
|
||||
|
||||
import net.minecraft.client.render.entity.EntityRenderer;
|
||||
import net.minecraft.text.Style;
|
||||
import net.minecraft.text.Text;
|
||||
import net.minecraft.util.Identifier;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.ModifyArgs;
|
||||
import org.spongepowered.asm.mixin.injection.invoke.arg.Args;
|
||||
|
||||
@Mixin(EntityRenderer.class)
|
||||
public class EntityRendererMixin {
|
||||
|
||||
private Identifier font = Identifier.of("bobtony", "iconfont");
|
||||
|
||||
@ModifyArgs(
|
||||
method = "renderLabelIfPresent",
|
||||
at = @At(
|
||||
value = "INVOKE",
|
||||
target = "Lnet/minecraft/client/font/TextRenderer;draw(Lnet/minecraft/text/Text;FFIZLorg/joml/Matrix4f;Lnet/minecraft/client/render/VertexConsumerProvider;Lnet/minecraft/client/font/TextRenderer$TextLayerType;II)I"
|
||||
)
|
||||
)
|
||||
private void modifyNameTag(Args args) {
|
||||
Text originalText = args.get(0);
|
||||
Text newText = Text.empty().append(Text.literal("").setStyle(Style.EMPTY.withFont(font))).append(" ").append(originalText);
|
||||
args.set(0, newText);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
package online.bobtony.mixin;
|
||||
|
||||
import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
|
||||
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation;
|
||||
import com.mojang.blaze3d.systems.RenderSystem;
|
||||
import online.bobtony.utils.render.WorldToScreen;
|
||||
import net.minecraft.client.render.*;
|
||||
import net.minecraft.client.util.ObjectAllocator;
|
||||
import org.joml.Matrix4f;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
|
||||
@Mixin(GameRenderer.class)
|
||||
public abstract class GameRendererMixin {
|
||||
|
||||
@WrapOperation(method = "renderWorld", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/render/WorldRenderer;render(Lnet/minecraft/client/util/ObjectAllocator;Lnet/minecraft/client/render/RenderTickCounter;ZLnet/minecraft/client/render/Camera;Lnet/minecraft/client/render/GameRenderer;Lorg/joml/Matrix4f;Lorg/joml/Matrix4f;)V"))
|
||||
void renderer_postWorldRender(WorldRenderer instance, ObjectAllocator allocator, RenderTickCounter tickCounter, boolean renderBlockOutline, Camera camera, GameRenderer gameRenderer, Matrix4f positionMatrix, Matrix4f projectionMatrix, Operation<Void> original) {
|
||||
original.call(instance, allocator, tickCounter, renderBlockOutline, camera, gameRenderer, positionMatrix, projectionMatrix);
|
||||
|
||||
|
||||
WorldToScreen.lastProjMat.set(RenderSystem.getProjectionMatrix());
|
||||
WorldToScreen.lastModMat.set(RenderSystem.getModelViewMatrix());
|
||||
WorldToScreen.lastWorldSpaceMatrix.set(positionMatrix);
|
||||
GL11.glGetIntegerv(GL11.GL_VIEWPORT, WorldToScreen.lastViewport);
|
||||
|
||||
RenderSystem.depthMask(true);
|
||||
RenderSystem.disableBlend();
|
||||
RenderSystem.setShaderFog(Fog.DUMMY);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package online.bobtony.mixin;
|
||||
|
||||
import net.minecraft.client.network.PlayerListEntry;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.gen.Accessor;
|
||||
|
||||
@Mixin(PlayerListEntry.class)
|
||||
public interface PlayerListEntryMixin {
|
||||
@Accessor("latency")
|
||||
int getLatency();
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package online.bobtony.mixin;
|
||||
|
||||
import net.minecraft.server.network.ServerPlayNetworkHandler;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
|
||||
@Mixin(ServerPlayNetworkHandler.class)
|
||||
public class ServerPlayNetworkHanderMixin {
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger("PacketLogger");
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
package online.bobtony.mixin;
|
||||
|
||||
import online.bobtony.gui.Color;
|
||||
import online.bobtony.gui.widgets.RoundedButton;
|
||||
import net.minecraft.client.gui.screen.Screen;
|
||||
import net.minecraft.client.gui.screen.TitleScreen;
|
||||
import net.minecraft.client.gui.screen.multiplayer.MultiplayerScreen;
|
||||
import net.minecraft.client.gui.screen.multiplayer.MultiplayerWarningScreen;
|
||||
import net.minecraft.client.gui.screen.option.OptionsScreen;
|
||||
import net.minecraft.client.gui.screen.world.SelectWorldScreen;
|
||||
import net.minecraft.text.Text;
|
||||
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
@Mixin(TitleScreen.class)
|
||||
public abstract class TitleScreenMixin extends Screen {
|
||||
|
||||
public TitleScreenMixin(Text title) {
|
||||
super(title);
|
||||
}
|
||||
|
||||
@Inject(method = "init", at = @At("TAIL"))
|
||||
private void addButtons(CallbackInfo ci) {
|
||||
|
||||
int l = this.height / 4 + 48;
|
||||
RoundedButton singleplayer = new RoundedButton(this.width / 2 - 100, l, 200, 20, Text.literal("Singleplayer"), new Color(255, 255, 255), () -> {
|
||||
this.client.setScreen(new SelectWorldScreen(this));
|
||||
});
|
||||
|
||||
RoundedButton multiplayer = new RoundedButton(this.width / 2 - 100, l + 24, 200, 20, Text.literal("Multiplayer"), new Color(255, 255, 255), () -> {
|
||||
Screen screen = this.client.options.skipMultiplayerWarning ? new MultiplayerScreen(this) : new MultiplayerWarningScreen(this);
|
||||
this.client.setScreen(screen);
|
||||
});
|
||||
|
||||
RoundedButton options = new RoundedButton(
|
||||
this.width / 2 - 100, l + 48, 100, 20,
|
||||
Text.literal("Options"),
|
||||
new Color(255, 255, 255),
|
||||
() -> this.client.setScreen(new OptionsScreen(this, this.client.options))
|
||||
);
|
||||
|
||||
RoundedButton quit = new RoundedButton(
|
||||
this.width / 2, l + 48, 100, 20,
|
||||
Text.literal("Quit Game"),
|
||||
new Color(255, 255, 255),
|
||||
() -> this.client.scheduleStop()
|
||||
);
|
||||
|
||||
|
||||
clearChildren();
|
||||
blur();
|
||||
|
||||
this.addDrawableChild(singleplayer);
|
||||
this.addDrawableChild(multiplayer);
|
||||
this.addDrawableChild(options);
|
||||
this.addDrawableChild(quit);
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package online.bobtony.utils;
|
||||
|
||||
import net.minecraft.client.network.AbstractClientPlayerEntity;
|
||||
import net.minecraft.client.util.SkinTextures;
|
||||
import net.minecraft.util.Identifier;
|
||||
|
||||
public class CapeHandler {
|
||||
|
||||
public static SkinTextures bobTexture;
|
||||
public static Identifier capeTexture;
|
||||
|
||||
public static SkinTextures getCapes(SkinTextures original, AbstractClientPlayerEntity player){
|
||||
|
||||
capeTexture = Identifier.of("bobtony", "textures/capes/cape.png");
|
||||
|
||||
bobTexture = new SkinTextures(
|
||||
original.texture(),
|
||||
original.textureUrl(),
|
||||
capeTexture,
|
||||
capeTexture,
|
||||
original.model(),
|
||||
original.secure()
|
||||
);
|
||||
|
||||
return bobTexture;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
package online.bobtony.utils;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
public abstract class Manager<T, S> {
|
||||
|
||||
protected final ConcurrentHashMap<T, S> entries = new ConcurrentHashMap<>();
|
||||
|
||||
public boolean register(@NotNull T key, @NotNull S value) {
|
||||
return entries.putIfAbsent(key, value) == null;
|
||||
}
|
||||
|
||||
public boolean unregister(@NotNull T key) {
|
||||
return entries.remove(key) != null;
|
||||
}
|
||||
|
||||
public @Nullable S get(@NotNull T key) {
|
||||
return entries.get(key);
|
||||
}
|
||||
|
||||
public boolean contains(@NotNull T key) {
|
||||
return entries.containsKey(key);
|
||||
}
|
||||
|
||||
public Collection<S> values() {
|
||||
return entries.values();
|
||||
}
|
||||
|
||||
public Set<Map.Entry<T, S>> entries() {
|
||||
return entries.entrySet();
|
||||
}
|
||||
|
||||
public Set<T> keys() {
|
||||
return entries.keySet();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
package online.bobtony.utils;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Unmodifiable;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.concurrent.ConcurrentLinkedDeque;
|
||||
|
||||
public abstract class Registry<T> {
|
||||
|
||||
private final ConcurrentLinkedDeque<T> entries = new ConcurrentLinkedDeque<>();
|
||||
|
||||
|
||||
public boolean register(@NotNull T key) {
|
||||
return entries.add(key);
|
||||
}
|
||||
|
||||
|
||||
public boolean unregister(@NotNull T key) {
|
||||
return entries.remove(key);
|
||||
}
|
||||
|
||||
public boolean contains(@NotNull T key) {
|
||||
return entries.contains(key);
|
||||
}
|
||||
public @Unmodifiable Collection<T> entries() {
|
||||
return Collections.unmodifiableCollection(this.entries);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,308 @@
|
||||
package online.bobtony.utils.render;
|
||||
|
||||
import com.mojang.blaze3d.systems.RenderSystem;
|
||||
|
||||
import online.bobtony.gui.Color;
|
||||
import net.fabricmc.fabric.api.client.rendering.v1.WorldRenderContext;
|
||||
import net.minecraft.block.entity.BlockEntity;
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.client.gl.ShaderProgramKeys;
|
||||
import net.minecraft.client.gui.DrawContext;
|
||||
import net.minecraft.client.render.*;
|
||||
import net.minecraft.client.util.math.MatrixStack;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.util.math.Box;
|
||||
import net.minecraft.util.math.Direction;
|
||||
import net.minecraft.util.math.MathHelper;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
import org.joml.Matrix4f;
|
||||
import org.joml.Quaternionf;
|
||||
|
||||
public class Render3D {
|
||||
public static void draw3DHitBox(MatrixStack matrices, Box box, Color color, float lineThickness) {
|
||||
RenderSystem.setShaderColor(color.getRed(), color.getGreen(), color.getBlue(), color.getAlpha());
|
||||
|
||||
RenderSystem.enableBlend();
|
||||
RenderSystem.defaultBlendFunc();
|
||||
RenderSystem.disableCull();
|
||||
RenderSystem.disableDepthTest();
|
||||
|
||||
RenderSystem.setShader(ShaderProgramKeys.RENDERTYPE_LINES);
|
||||
RenderSystem.lineWidth(lineThickness);
|
||||
|
||||
MatrixStack.Entry entry = matrices.peek();
|
||||
Matrix4f matrix4f = entry.getPositionMatrix();
|
||||
|
||||
Tessellator tessellator = RenderSystem.renderThreadTesselator();
|
||||
BufferBuilder bufferBuilder = tessellator.begin(VertexFormat.DrawMode.LINES, VertexFormats.LINES);
|
||||
|
||||
RenderSystem.setShaderColor(color.getRed(), color.getGreen(), color.getBlue(), color.getAlpha());
|
||||
|
||||
buildLine3d(matrices, bufferBuilder, (float) box.minX, (float) box.minY, (float) box.minZ, (float) box.maxX, (float) box.minY, (float) box.minZ, color);
|
||||
buildLine3d(matrices, bufferBuilder, (float) box.maxX, (float) box.minY, (float) box.minZ, (float) box.maxX, (float) box.minY, (float) box.maxZ, color);
|
||||
buildLine3d(matrices, bufferBuilder, (float) box.maxX, (float) box.minY, (float) box.maxZ, (float) box.minX, (float) box.minY, (float) box.maxZ, color);
|
||||
buildLine3d(matrices, bufferBuilder, (float) box.minX, (float) box.minY, (float) box.maxZ, (float) box.minX, (float) box.minY, (float) box.minZ, color);
|
||||
buildLine3d(matrices, bufferBuilder, (float) box.minX, (float) box.minY, (float) box.minZ, (float) box.minX, (float) box.maxY, (float) box.minZ, color);
|
||||
buildLine3d(matrices, bufferBuilder, (float) box.maxX, (float) box.minY, (float) box.minZ, (float) box.maxX, (float) box.maxY, (float) box.minZ, color);
|
||||
buildLine3d(matrices, bufferBuilder, (float) box.maxX, (float) box.minY, (float) box.maxZ, (float) box.maxX, (float) box.maxY, (float) box.maxZ, color);
|
||||
buildLine3d(matrices, bufferBuilder, (float) box.minX, (float) box.minY, (float) box.maxZ, (float) box.minX, (float) box.maxY, (float) box.maxZ, color);
|
||||
buildLine3d(matrices, bufferBuilder, (float) box.minX, (float) box.maxY, (float) box.minZ, (float) box.maxX, (float) box.maxY, (float) box.minZ, color);
|
||||
buildLine3d(matrices, bufferBuilder, (float) box.maxX, (float) box.maxY, (float) box.minZ, (float) box.maxX, (float) box.maxY, (float) box.maxZ, color);
|
||||
buildLine3d(matrices, bufferBuilder, (float) box.maxX, (float) box.maxY, (float) box.maxZ, (float) box.minX, (float) box.maxY, (float) box.maxZ, color);
|
||||
buildLine3d(matrices, bufferBuilder, (float) box.minX, (float) box.maxY, (float) box.maxZ, (float) box.minX, (float) box.maxY, (float) box.minZ, color);
|
||||
|
||||
BufferRenderer.drawWithGlobalProgram(bufferBuilder.end());
|
||||
|
||||
RenderSystem.setShaderColor(1.0f, 1.0f, 1.0f, 1.0f);
|
||||
|
||||
RenderSystem.enableCull();
|
||||
RenderSystem.lineWidth(1f);
|
||||
RenderSystem.enableDepthTest();
|
||||
RenderSystem.disableBlend();
|
||||
}
|
||||
|
||||
public static void draw3DBox(MatrixStack matrixStack, Box box, Color color, float lineThickness) {
|
||||
RenderSystem.setShaderColor(color.getRed(), color.getGreen(), color.getBlue(), color.getAlpha());
|
||||
|
||||
MatrixStack.Entry entry = matrixStack.peek();
|
||||
Matrix4f matrix4f = entry.getPositionMatrix();
|
||||
|
||||
Tessellator tessellator = RenderSystem.renderThreadTesselator();
|
||||
|
||||
RenderSystem.enableBlend();
|
||||
RenderSystem.defaultBlendFunc();
|
||||
RenderSystem.disableCull();
|
||||
RenderSystem.disableDepthTest();
|
||||
|
||||
RenderSystem.setShader(ShaderProgramKeys.POSITION);
|
||||
|
||||
RenderSystem.setShaderColor(color.getRed(), color.getGreen(), color.getBlue(), 0.5F);
|
||||
|
||||
BufferBuilder bufferBuilder = tessellator.begin(VertexFormat.DrawMode.QUADS, VertexFormats.POSITION);
|
||||
bufferBuilder.vertex(matrix4f, (float) box.minX, (float) box.minY, (float) box.minZ);
|
||||
bufferBuilder.vertex(matrix4f, (float) box.maxX, (float) box.minY, (float) box.minZ);
|
||||
bufferBuilder.vertex(matrix4f, (float) box.maxX, (float) box.minY, (float) box.maxZ);
|
||||
bufferBuilder.vertex(matrix4f, (float) box.minX, (float) box.minY, (float) box.maxZ);
|
||||
|
||||
bufferBuilder.vertex(matrix4f, (float) box.minX, (float) box.maxY, (float) box.minZ);
|
||||
bufferBuilder.vertex(matrix4f, (float) box.minX, (float) box.maxY, (float) box.maxZ);
|
||||
bufferBuilder.vertex(matrix4f, (float) box.maxX, (float) box.maxY, (float) box.maxZ);
|
||||
bufferBuilder.vertex(matrix4f, (float) box.maxX, (float) box.maxY, (float) box.minZ);
|
||||
|
||||
bufferBuilder.vertex(matrix4f, (float) box.minX, (float) box.minY, (float) box.minZ);
|
||||
bufferBuilder.vertex(matrix4f, (float) box.minX, (float) box.maxY, (float) box.minZ);
|
||||
bufferBuilder.vertex(matrix4f, (float) box.maxX, (float) box.maxY, (float) box.minZ);
|
||||
bufferBuilder.vertex(matrix4f, (float) box.maxX, (float) box.minY, (float) box.minZ);
|
||||
|
||||
bufferBuilder.vertex(matrix4f, (float) box.maxX, (float) box.minY, (float) box.minZ);
|
||||
bufferBuilder.vertex(matrix4f, (float) box.maxX, (float) box.maxY, (float) box.minZ);
|
||||
bufferBuilder.vertex(matrix4f, (float) box.maxX, (float) box.maxY, (float) box.maxZ);
|
||||
bufferBuilder.vertex(matrix4f, (float) box.maxX, (float) box.minY, (float) box.maxZ);
|
||||
|
||||
bufferBuilder.vertex(matrix4f, (float) box.minX, (float) box.minY, (float) box.maxZ);
|
||||
bufferBuilder.vertex(matrix4f, (float) box.maxX, (float) box.minY, (float) box.maxZ);
|
||||
bufferBuilder.vertex(matrix4f, (float) box.maxX, (float) box.maxY, (float) box.maxZ);
|
||||
bufferBuilder.vertex(matrix4f, (float) box.minX, (float) box.maxY, (float) box.maxZ);
|
||||
|
||||
bufferBuilder.vertex(matrix4f, (float) box.minX, (float) box.minY, (float) box.minZ);
|
||||
bufferBuilder.vertex(matrix4f, (float) box.minX, (float) box.minY, (float) box.maxZ);
|
||||
bufferBuilder.vertex(matrix4f, (float) box.minX, (float) box.maxY, (float) box.maxZ);
|
||||
bufferBuilder.vertex(matrix4f, (float) box.minX, (float) box.maxY, (float) box.minZ);
|
||||
BufferRenderer.drawWithGlobalProgram(bufferBuilder.end());
|
||||
|
||||
RenderSystem.setShaderColor(color.getRed(), color.getGreen(), color.getBlue(), color.getAlpha());
|
||||
|
||||
RenderSystem.setShader(ShaderProgramKeys.RENDERTYPE_LINES);
|
||||
|
||||
RenderSystem.lineWidth(lineThickness);
|
||||
|
||||
bufferBuilder = tessellator.begin(VertexFormat.DrawMode.LINES, VertexFormats.LINES);
|
||||
|
||||
buildLine3d(matrixStack, bufferBuilder, (float) box.minX, (float) box.minY, (float) box.minZ, (float) box.maxX,
|
||||
(float) box.minY, (float) box.minZ, color);
|
||||
buildLine3d(matrixStack, bufferBuilder, (float) box.maxX, (float) box.minY, (float) box.minZ, (float) box.maxX,
|
||||
(float) box.minY, (float) box.maxZ, color);
|
||||
buildLine3d(matrixStack, bufferBuilder, (float) box.maxX, (float) box.minY, (float) box.maxZ, (float) box.minX,
|
||||
(float) box.minY, (float) box.maxZ, color);
|
||||
buildLine3d(matrixStack, bufferBuilder, (float) box.minX, (float) box.minY, (float) box.maxZ, (float) box.minX,
|
||||
(float) box.minY, (float) box.minZ, color);
|
||||
buildLine3d(matrixStack, bufferBuilder, (float) box.minX, (float) box.minY, (float) box.minZ, (float) box.minX,
|
||||
(float) box.maxY, (float) box.minZ, color);
|
||||
buildLine3d(matrixStack, bufferBuilder, (float) box.maxX, (float) box.minY, (float) box.minZ, (float) box.maxX,
|
||||
(float) box.maxY, (float) box.minZ, color);
|
||||
buildLine3d(matrixStack, bufferBuilder, (float) box.maxX, (float) box.minY, (float) box.maxZ, (float) box.maxX,
|
||||
(float) box.maxY, (float) box.maxZ, color);
|
||||
buildLine3d(matrixStack, bufferBuilder, (float) box.minX, (float) box.minY, (float) box.maxZ, (float) box.minX,
|
||||
(float) box.maxY, (float) box.maxZ, color);
|
||||
buildLine3d(matrixStack, bufferBuilder, (float) box.minX, (float) box.maxY, (float) box.minZ, (float) box.maxX,
|
||||
(float) box.maxY, (float) box.minZ, color);
|
||||
buildLine3d(matrixStack, bufferBuilder, (float) box.maxX, (float) box.maxY, (float) box.minZ, (float) box.maxX,
|
||||
(float) box.maxY, (float) box.maxZ, color);
|
||||
buildLine3d(matrixStack, bufferBuilder, (float) box.maxX, (float) box.maxY, (float) box.maxZ, (float) box.minX,
|
||||
(float) box.maxY, (float) box.maxZ, color);
|
||||
buildLine3d(matrixStack, bufferBuilder, (float) box.minX, (float) box.maxY, (float) box.maxZ, (float) box.minX,
|
||||
(float) box.maxY, (float) box.minZ, color);
|
||||
|
||||
BufferRenderer.drawWithGlobalProgram(bufferBuilder.end());
|
||||
|
||||
RenderSystem.enableCull();
|
||||
RenderSystem.lineWidth(1f);
|
||||
RenderSystem.enableDepthTest();
|
||||
RenderSystem.disableBlend();
|
||||
|
||||
}
|
||||
|
||||
public static void drawLineToEntity(MatrixStack matrices, PlayerEntity player, Entity entity, float delta, Color color, float lineWidth) {
|
||||
Vec3d playerPos = getEntityPositionInterpolated(player, delta);
|
||||
Vec3d entityPos = getEntityPositionInterpolated(entity, delta);
|
||||
|
||||
|
||||
Vec3d cameraPos = MinecraftClient.getInstance().gameRenderer.getCamera().getPos();
|
||||
|
||||
float x1 = (float) (playerPos.x - cameraPos.x);
|
||||
float y1 = (float) (playerPos.y - cameraPos.y);
|
||||
float z1 = (float) (playerPos.z - cameraPos.z);
|
||||
|
||||
float x2 = (float) (entityPos.x - cameraPos.x);
|
||||
float y2 = (float) (entityPos.y - cameraPos.y);
|
||||
float z2 = (float) (entityPos.z - cameraPos.z);
|
||||
|
||||
Render3D.drawLine3D(matrices, x1, y1, z1, x2, y2, z2, color, 5.0f);
|
||||
}
|
||||
|
||||
public static void drawLineToBlockEntity(MatrixStack matrices, PlayerEntity player, BlockEntity blockEntity, float delta, Color color, float lineWidth) {
|
||||
Vec3d playerPos = getEntityPositionInterpolated(player, delta);
|
||||
Vec3d blockPos = new Vec3d(
|
||||
blockEntity.getPos().getX() + 0.5,
|
||||
blockEntity.getPos().getY() + 0.5,
|
||||
blockEntity.getPos().getZ() + 0.5
|
||||
);
|
||||
|
||||
Vec3d cameraPos = MinecraftClient.getInstance().gameRenderer.getCamera().getPos();
|
||||
|
||||
float x1 = (float) (playerPos.x - cameraPos.x);
|
||||
float y1 = (float) (playerPos.y - cameraPos.y);
|
||||
float z1 = (float) (playerPos.z - cameraPos.z);
|
||||
|
||||
float x2 = (float) (blockPos.x - cameraPos.x);
|
||||
float y2 = (float) (blockPos.y - cameraPos.y);
|
||||
float z2 = (float) (blockPos.z - cameraPos.z);
|
||||
|
||||
Render3D.drawLine3D(matrices, x1, y1, z1, x2, y2, z2, color, lineWidth);
|
||||
}
|
||||
|
||||
public static Vec3d rotateVector(Vec3d vec, double yaw, double pitch) {
|
||||
double cosYaw = Math.cos(Math.toRadians(-yaw));
|
||||
double sinYaw = Math.sin(Math.toRadians(-yaw));
|
||||
|
||||
double rotatedX = cosYaw * vec.x - sinYaw * vec.z;
|
||||
double rotatedZ = sinYaw * vec.x + cosYaw * vec.z;
|
||||
|
||||
double cosPitch = Math.cos(Math.toRadians(-pitch));
|
||||
double sinPitch = Math.sin(Math.toRadians(-pitch));
|
||||
|
||||
double rotatedY = cosPitch * vec.y - sinPitch * rotatedZ;
|
||||
rotatedZ = sinPitch * vec.y + cosPitch * rotatedZ;
|
||||
|
||||
return new Vec3d(rotatedX, rotatedY, rotatedZ);
|
||||
}
|
||||
|
||||
public static void drawLine3D(MatrixStack matrixStack, Vec3d pos1, Vec3d pos2, Color color, float lineWidth) {
|
||||
drawLine3D(matrixStack, (float) pos1.x, (float) pos1.y, (float) pos1.z, (float) pos2.x, (float) pos2.y,
|
||||
(float) pos2.z, color, lineWidth);
|
||||
}
|
||||
|
||||
public static void drawLine3D(MatrixStack matrices, float x1, float y1, float z1, float x2, float y2, float z2,
|
||||
Color color, float lineWidth) {
|
||||
|
||||
RenderSystem.enableBlend();
|
||||
RenderSystem.defaultBlendFunc();
|
||||
RenderSystem.disableCull();
|
||||
RenderSystem.disableDepthTest();
|
||||
|
||||
Tessellator tessellator = RenderSystem.renderThreadTesselator();
|
||||
RenderSystem.setShaderColor(color.getRed(), color.getGreen(), color.getBlue(), color.getAlpha());
|
||||
|
||||
RenderSystem.setShader(ShaderProgramKeys.RENDERTYPE_LINES);
|
||||
RenderSystem.lineWidth(lineWidth);
|
||||
|
||||
BufferBuilder bufferBuilder = tessellator.begin(VertexFormat.DrawMode.LINES, VertexFormats.LINES);
|
||||
buildLine3d(matrices, bufferBuilder, x1, y1, z1, x2, y2, z2, color);
|
||||
BufferRenderer.drawWithGlobalProgram(bufferBuilder.end());
|
||||
RenderSystem.enableCull();
|
||||
RenderSystem.lineWidth(1f);
|
||||
RenderSystem.enableDepthTest();
|
||||
RenderSystem.disableBlend();
|
||||
}
|
||||
|
||||
public static void drawWorldText(WorldRenderContext context, String text, Vec3d entityPos, Color color, float scale) {
|
||||
MinecraftClient client = MinecraftClient.getInstance();
|
||||
MatrixStack matrices = context.matrixStack();
|
||||
Vec3d cameraPos = context.camera().getPos();
|
||||
VertexConsumerProvider.Immediate consumerProvider = (VertexConsumerProvider.Immediate) context.consumers();
|
||||
DrawContext drawContext = new DrawContext(client, consumerProvider);
|
||||
|
||||
double x = entityPos.x - cameraPos.x;
|
||||
double y = entityPos.y - cameraPos.y;
|
||||
double z = entityPos.z - cameraPos.z;
|
||||
|
||||
if (z < 0) return;
|
||||
|
||||
matrices.push();
|
||||
|
||||
matrices.translate(x, y, z);
|
||||
|
||||
Quaternionf rotation = new Quaternionf()
|
||||
.rotateY((float) Math.toRadians(-context.camera().getYaw()))
|
||||
.rotateX((float) Math.toRadians(context.camera().getPitch()));
|
||||
|
||||
matrices.multiply(rotation);
|
||||
|
||||
float distance = (float) client.player.squaredDistanceTo(entityPos);
|
||||
float textScale = Math.max(0.02F, scale / (distance * 0.1F));
|
||||
matrices.scale(-textScale, -textScale, textScale);
|
||||
|
||||
drawContext.drawText(client.textRenderer, text, -client.textRenderer.getWidth(text) / 2, 0, color.getColorAsInt(), false);
|
||||
|
||||
matrices.pop();
|
||||
}
|
||||
|
||||
private static float getYaw(Direction direction) {
|
||||
return switch (direction)
|
||||
{
|
||||
case SOUTH -> 90.0f;
|
||||
case WEST -> 0.0f;
|
||||
case NORTH -> 270.0f;
|
||||
case EAST -> 180.0f;
|
||||
default -> 0.0f;
|
||||
};
|
||||
}
|
||||
|
||||
private static void buildLine3d(MatrixStack matrices, BufferBuilder bufferBuilder, float x1, float y1, float z1, float x2, float y2, float z2, Color color) {
|
||||
MatrixStack.Entry entry = matrices.peek();
|
||||
Matrix4f matrix4f = entry.getPositionMatrix();
|
||||
|
||||
Vec3d normalized = new Vec3d(x2 - x1, y2 - y1, z2 - z1).normalize();
|
||||
|
||||
float r = color.getRed();
|
||||
float g = color.getGreen();
|
||||
float b = color.getBlue();
|
||||
|
||||
bufferBuilder.vertex(matrix4f, x1, y1, z1).color(r, g, b, 1.0f).normal(entry, (float) normalized.x,
|
||||
(float) normalized.y, (float) normalized.z);
|
||||
bufferBuilder.vertex(matrix4f, x2, y2, z2).color(r, g, b, 1.0f).normal(entry, (float) normalized.x,
|
||||
(float) normalized.y, (float) normalized.z);
|
||||
}
|
||||
|
||||
public static Vec3d getEntityPositionInterpolated(Entity entity, float delta) {
|
||||
return new Vec3d(MathHelper.lerp(delta, entity.prevX, entity.getX()),
|
||||
MathHelper.lerp(delta, entity.prevY, entity.getY()),
|
||||
MathHelper.lerp(delta, entity.prevZ, entity.getZ()));
|
||||
}
|
||||
|
||||
public static Vec3d getEntityPositionOffsetInterpolated(Entity entity, float delta) {
|
||||
Vec3d interpolated = getEntityPositionInterpolated(entity, delta);
|
||||
return entity.getPos().subtract(interpolated);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
package online.bobtony.utils.render;
|
||||
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.client.render.Camera;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
import org.joml.Matrix4f;
|
||||
import org.joml.Vector3f;
|
||||
import org.joml.Vector4f;
|
||||
|
||||
public class WorldToScreen {
|
||||
public static final Matrix4f lastProjMat = new Matrix4f();
|
||||
public static final Matrix4f lastModMat = new Matrix4f();
|
||||
public static final Matrix4f lastWorldSpaceMatrix = new Matrix4f();
|
||||
public static final int[] lastViewport = new int[4];
|
||||
private static final MinecraftClient client = MinecraftClient.getInstance();
|
||||
|
||||
public static Vec3d worldSpaceToScreenSpace(Vec3d pos) {
|
||||
Camera camera = client.getEntityRenderDispatcher().camera;
|
||||
int displayHeight = client.getWindow().getHeight();
|
||||
Vector3f target = new Vector3f();
|
||||
|
||||
double deltaX = pos.x - camera.getPos().x;
|
||||
double deltaY = pos.y - camera.getPos().y;
|
||||
double deltaZ = pos.z - camera.getPos().z;
|
||||
|
||||
Vector4f transformedCoordinates = new Vector4f((float) deltaX, (float) deltaY, (float) deltaZ, 1.f).mul(lastWorldSpaceMatrix);
|
||||
|
||||
Matrix4f matrixProj = new Matrix4f(lastProjMat);
|
||||
Matrix4f matrixModel = new Matrix4f(lastModMat);
|
||||
|
||||
matrixProj.mul(matrixModel).project(transformedCoordinates.x(), transformedCoordinates.y(), transformedCoordinates.z(), lastViewport, target);
|
||||
|
||||
return new Vec3d(target.x / client.getWindow().getScaleFactor(), (displayHeight - target.y) / client.getWindow().getScaleFactor(), target.z);
|
||||
}
|
||||
|
||||
public static boolean screenSpaceCoordinateIsVisible(Vec3d pos) {
|
||||
return pos != null && pos.z > -1 && pos.z < 1;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user