Skip to content

Commit

Permalink
Update MythologicalRitual
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinthegreat1 committed Nov 22, 2023
1 parent cb4c7e2 commit ac225c7
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -100,14 +100,11 @@ public static void onParticle(ParticleS2CPacket packet) {
if (Double.isNaN(slope)) {
return;
}
Vec3d nextBurrowDirection = new Vec3d(100, 0, slope * 100).normalize().multiply(100);
if (burrow.nextBurrowPlane == null) {
burrow.nextBurrowPlane = new Vec3d[4];
Vec3d nextBurrowDirection = new Vec3d(100, 0, slope * 100).normalize();
if (burrow.nextBurrowLine == null) {
burrow.nextBurrowLine = new Vec3d[1001];
}
burrow.nextBurrowPlane[0] = Vec3d.of(pos).add(nextBurrowDirection).subtract(0, 50, 0);
burrow.nextBurrowPlane[1] = Vec3d.of(pos).subtract(nextBurrowDirection).subtract(0, 50, 0);
burrow.nextBurrowPlane[2] = burrow.nextBurrowPlane[1].add(0, 100, 0);
burrow.nextBurrowPlane[3] = burrow.nextBurrowPlane[0].add(0, 100, 0);
fillLine(burrow.nextBurrowLine, Vec3d.of(pos), nextBurrowDirection);
} else if (ParticleTypes.DRIPPING_LAVA.equals(packet.getParameters().getType()) && packet.getCount() == 2) {
if (System.currentTimeMillis() > lastEchoTime + 10_000) {
return;
Expand All @@ -120,30 +117,37 @@ public static void onParticle(ParticleS2CPacket packet) {
if (previousBurrow.echoBurrowDirection[0] == null || previousBurrow.echoBurrowDirection[1] == null) {
return;
}
Vec3d echoBurrowDirection = previousBurrow.echoBurrowDirection[1].subtract(previousBurrow.echoBurrowDirection[0]).normalize().multiply(100);
if (previousBurrow.echoBurrowPlane == null) {
previousBurrow.echoBurrowPlane = new Vec3d[4];
Vec3d echoBurrowDirection = previousBurrow.echoBurrowDirection[1].subtract(previousBurrow.echoBurrowDirection[0]).normalize();
if (previousBurrow.echoBurrowLine == null) {
previousBurrow.echoBurrowLine = new Vec3d[1001];
}
previousBurrow.echoBurrowPlane[0] = previousBurrow.echoBurrowDirection[0].add(echoBurrowDirection).subtract(0, 50, 0);
previousBurrow.echoBurrowPlane[1] = previousBurrow.echoBurrowDirection[0].subtract(echoBurrowDirection).subtract(0, 50, 0);
previousBurrow.echoBurrowPlane[2] = previousBurrow.echoBurrowPlane[1].add(0, 100, 0);
previousBurrow.echoBurrowPlane[3] = previousBurrow.echoBurrowPlane[0].add(0, 100, 0);
fillLine(previousBurrow.echoBurrowLine, previousBurrow.echoBurrowDirection[0], echoBurrowDirection);
}
}
}

static void fillLine(Vec3d[] line, Vec3d start, Vec3d direction) {
assert line.length % 2 == 1;
int middle = line.length / 2;
line[middle] = start;
for (int i = 0; i < middle; i++) {
line[middle + 1 + i] = line[middle + i].add(direction);
line[middle - 1 - i] = line[middle - i].subtract(direction);
}
}

public static void render(WorldRenderContext context) {
if (isActive()) {
for (GriffinBurrow burrow : griffinBurrows.values()) {
if (burrow.shouldRender()) {
burrow.render(context);
}
if (burrow.confirmed != TriState.FALSE) {
if (burrow.nextBurrowPlane != null) {
RenderHelper.renderQuad(context, burrow.nextBurrowPlane, ORANGE_COLOR_COMPONENTS, 0.25F, true);
if (burrow.nextBurrowLine != null) {
RenderHelper.renderLinesFromPoints(context, burrow.nextBurrowLine, ORANGE_COLOR_COMPONENTS, 0.5F, 5F);
}
if (burrow.echoBurrowPlane != null) {
RenderHelper.renderQuad(context, burrow.echoBurrowPlane, ORANGE_COLOR_COMPONENTS, 0.25F, true);
if (burrow.echoBurrowLine != null) {
RenderHelper.renderLinesFromPoints(context, burrow.echoBurrowLine, ORANGE_COLOR_COMPONENTS, 0.5F, 5F);
}
}
}
Expand Down Expand Up @@ -191,10 +195,12 @@ private static class GriffinBurrow extends Waypoint {
private int enchantParticle;
private TriState confirmed = TriState.FALSE;
private final SimpleRegression regression = new SimpleRegression();
private Vec3d[] nextBurrowPlane;
@Nullable
private Vec3d[] nextBurrowLine;
@Nullable
private Vec3d[] echoBurrowDirection;
private Vec3d[] echoBurrowPlane;
@Nullable
private Vec3d[] echoBurrowLine;

private GriffinBurrow(BlockPos pos) {
super(pos, Type.WAYPOINT, ORANGE_COLOR_COMPONENTS, 0.25F);
Expand Down
19 changes: 10 additions & 9 deletions src/main/java/de/hysky/skyblocker/utils/render/RenderHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import com.mojang.blaze3d.systems.RenderSystem;
import com.mojang.logging.LogUtils;

import de.hysky.skyblocker.SkyblockerMod;
import de.hysky.skyblocker.mixin.accessor.BeaconBlockEntityRendererInvoker;
import de.hysky.skyblocker.utils.render.culling.OcclusionCulling;
Expand All @@ -23,16 +22,16 @@
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Box;
import net.minecraft.util.math.Vec3d;

import java.lang.invoke.MethodHandle;
import java.lang.invoke.MethodHandles;
import java.lang.invoke.MethodType;

import org.joml.Matrix3f;
import org.joml.Matrix4f;
import org.joml.Vector3f;
import org.lwjgl.opengl.GL11;
import org.slf4j.Logger;

import java.lang.invoke.MethodHandle;
import java.lang.invoke.MethodHandles;
import java.lang.invoke.MethodType;

public class RenderHelper {
private static final Logger LOGGER = LogUtils.getLogger();
private static final Identifier TRANSLUCENT_DRAW = new Identifier(SkyblockerMod.NAMESPACE, "translucent_draw");
Expand Down Expand Up @@ -164,11 +163,12 @@ public static void renderLinesFromPoints(WorldRenderContext context, Vec3d[] poi
buffer.begin(DrawMode.LINE_STRIP, VertexFormats.LINES);

for (int i = 0; i < points.length; i++) {
Vec3d normalVec = points[(i + 1) % points.length].subtract(points[i]).normalize();
Vec3d nextPoint = points[i + 1 == points.length ? i - 1 : i + 1];
Vector3f normalVec = new Vector3f((float) nextPoint.getX(), (float) nextPoint.getY(), (float) nextPoint.getZ()).sub((float) points[i].getX(), (float) points[i].getY(), (float) points[i].getZ()).normalize().mul(normalMatrix);
buffer
.vertex(positionMatrix, (float) points[i].getX(), (float) points[i].getY(), (float) points[i].getZ())
.color(colorComponents[0], colorComponents[1], colorComponents[2], alpha)
.normal(normalMatrix, (float) normalVec.x, (float) normalVec.y, (float) normalVec.z)
.normal(normalVec.x, normalVec.y, normalVec.z)
.next();
}

Expand Down Expand Up @@ -322,7 +322,8 @@ private static MethodHandle getDeferredRenderTaskHandle() {
MethodType mt = MethodType.methodType(void.class, Runnable.class);

return lookup.findStatic(deferredTaskClass, "schedule", mt);
} catch (Throwable ignored) {}
} catch (Throwable ignored) {
}

return null;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package de.hysky.skyblocker.skyblock.diana;

import net.minecraft.util.math.Vec3d;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

public class MythologicalRitualTest {
@Test
void testFillLine() {
Vec3d[] line = new Vec3d[21];
Vec3d start = new Vec3d(0, 0, 0);
Vec3d direction = new Vec3d(1, 0, 0);
MythologicalRitual.fillLine(line, start, direction);
for (int i = 0; i < line.length; i++) {
Assertions.assertEquals(new Vec3d(i - 10, 0, 0), line[i]);
}
}
}

0 comments on commit ac225c7

Please sign in to comment.