close #280 and reduce conformity
This commit is contained in:
parent
f4bc787551
commit
2878dcb0c1
0
Common/logs/latest.log
Normal file
0
Common/logs/latest.log
Normal file
|
@ -31,19 +31,21 @@ import net.minecraft.world.entity.npc.VillagerProfession
|
|||
import net.minecraft.world.entity.npc.VillagerType
|
||||
import net.minecraft.world.item.ItemStack
|
||||
import net.minecraft.world.level.Level
|
||||
import net.minecraft.world.level.levelgen.XoroshiroRandomSource
|
||||
import net.minecraft.world.level.levelgen.synth.PerlinNoise
|
||||
import net.minecraft.world.level.levelgen.SingleThreadedRandomSource
|
||||
import net.minecraft.world.level.levelgen.synth.SimplexNoise
|
||||
import net.minecraft.world.phys.Vec2
|
||||
import kotlin.math.abs
|
||||
import kotlin.math.min
|
||||
import kotlin.math.sin
|
||||
|
||||
/**
|
||||
* Source of perlin noise
|
||||
*/
|
||||
val NOISE: PerlinNoise = PerlinNoise.create(XoroshiroRandomSource(9001L), listOf(0, 1, 2, 3, 4))
|
||||
val NOISE: SimplexNoise = SimplexNoise(SingleThreadedRandomSource(9001L))
|
||||
|
||||
val CAP_THETA: Float = 18f
|
||||
// see the test; perlin noise seems to output almost exclusively between -0.5 and 0.5
|
||||
// i could probably impl this "properly" with some kind of exponent but it's faster and easier to divide
|
||||
fun getNoise(x: Double, y: Double, z: Double): Double =
|
||||
NOISE.getValue(x * 0.6, y * 0.6, z * 0.6) / 2.0
|
||||
|
||||
const val CAP_THETA: Float = 18f
|
||||
|
||||
/**
|
||||
* Draw a sequence of linePoints spanning the given points.
|
||||
|
@ -209,8 +211,9 @@ fun drawPatternFromPoints(
|
|||
tail: Int,
|
||||
head: Int,
|
||||
flowIrregular: Float,
|
||||
seed: Double
|
||||
) {
|
||||
val zappyPts = makeZappy(points, dupIndices, 10f, 2.5f, 0.1f, flowIrregular)
|
||||
val zappyPts = makeZappy(points, dupIndices, 10f, 2.5f, 0.1f, flowIrregular, seed)
|
||||
val nodes = if (drawLast) {
|
||||
points
|
||||
} else {
|
||||
|
@ -237,9 +240,10 @@ fun makeZappy(
|
|||
hops: Float,
|
||||
variance: Float,
|
||||
speed: Float,
|
||||
flowIrregular: Float
|
||||
flowIrregular: Float,
|
||||
seed: Double,
|
||||
) =
|
||||
makeZappy(points, dupIndices, hops.toInt(), variance, speed, flowIrregular, 0.2f)
|
||||
makeZappy(points, dupIndices, hops.toInt(), variance, speed, flowIrregular, 0.2f, seed)
|
||||
|
||||
/**
|
||||
* Split up a sequence of linePoints with a lightning effect
|
||||
|
@ -248,7 +252,7 @@ fun makeZappy(
|
|||
*/
|
||||
fun makeZappy(
|
||||
barePoints: List<Vec2>, dupIndices: Set<Int>?, hops: Int, variance: Float, speed: Float, flowIrregular: Float,
|
||||
readabilityOffset: Float
|
||||
readabilityOffset: Float, seed: Double
|
||||
): List<Vec2> {
|
||||
// Nothing in, nothing out
|
||||
if (barePoints.isEmpty()) {
|
||||
|
@ -275,16 +279,16 @@ fun makeZappy(
|
|||
// as well as some random variance...
|
||||
// (We use i, j (segment #, subsegment #) as seeds for the Perlin noise,
|
||||
// and zSeed (i.e. time elapsed) to perturb the shape gradually over time)
|
||||
val minorPerturb = NOISE.getValue(i.toDouble(), j.toDouble(), sin(zSeed)) * flowIrregular
|
||||
val theta = (3 * NOISE.getValue(
|
||||
i.toDouble() + j.toDouble() / (hops + 1) + minorPerturb - zSeed,
|
||||
val minorPerturb = getNoise(i.toDouble(), j.toDouble(), sin(zSeed)) * flowIrregular
|
||||
val theta = (3 * getNoise(
|
||||
i + progress + minorPerturb - zSeed,
|
||||
1337.0,
|
||||
0.0
|
||||
seed
|
||||
) * TAU).toFloat()
|
||||
val r = (NOISE.getValue(
|
||||
i.toDouble() + j.toDouble() / (hops + 1) - zSeed,
|
||||
val r = (getNoise(
|
||||
i + progress - zSeed,
|
||||
69420.0,
|
||||
0.0
|
||||
seed
|
||||
) * maxVariance * scaleVariance(progress)).toFloat()
|
||||
val randomHop = Vec2(r * Mth.cos(theta), r * Mth.sin(theta))
|
||||
// Then record the new location.
|
||||
|
|
|
@ -22,7 +22,7 @@ public class BlockEntityAkashicBookshelfRenderer implements BlockEntityRenderer<
|
|||
|
||||
@Override
|
||||
public void render(BlockEntityAkashicBookshelf tile, float pPartialTick, PoseStack ps,
|
||||
MultiBufferSource buffer, int light, int overlay) {
|
||||
MultiBufferSource buffer, int light, int overlay) {
|
||||
HexPattern pattern = tile.getPattern();
|
||||
if (pattern == null) {
|
||||
return;
|
||||
|
@ -73,7 +73,8 @@ public class BlockEntityAkashicBookshelfRenderer implements BlockEntityRenderer<
|
|||
lines2.set(j, new Vec2(-v.x, v.y));
|
||||
}
|
||||
|
||||
var zappy = RenderLib.makeZappy(lines2, RenderLib.findDupIndices(pattern.positions()), 10f, 0.5f, 0f, 0f);
|
||||
var stupidHash = tile.getBlockPos().hashCode();
|
||||
var zappy = RenderLib.makeZappy(lines2, RenderLib.findDupIndices(pattern.positions()), 10f, 0.5f, 0f, 0f, stupidHash);
|
||||
|
||||
int outer = 0xff_d2c8c8;
|
||||
int inner = 0xc8_322b33;
|
||||
|
|
|
@ -22,7 +22,7 @@ public class BlockEntitySlateRenderer implements BlockEntityRenderer<BlockEntity
|
|||
|
||||
@Override
|
||||
public void render(BlockEntitySlate tile, float pPartialTick, PoseStack ps,
|
||||
MultiBufferSource buffer, int light, int overlay) {
|
||||
MultiBufferSource buffer, int light, int overlay) {
|
||||
if (tile.pattern == null) {
|
||||
return;
|
||||
}
|
||||
|
@ -84,7 +84,8 @@ public class BlockEntitySlateRenderer implements BlockEntityRenderer<BlockEntity
|
|||
}
|
||||
|
||||
var isLit = bs.getValue(BlockSlate.ENERGIZED);
|
||||
var zappy = RenderLib.makeZappy(lines2, RenderLib.findDupIndices(tile.pattern.positions()), 10f, isLit ? 2.5f : 0.5f, isLit ? 0.1f : 0f, 0.2f);
|
||||
var stupidHash = tile.getBlockPos().hashCode();
|
||||
var zappy = RenderLib.makeZappy(lines2, RenderLib.findDupIndices(tile.pattern.positions()), 10f, isLit ? 2.5f : 0.5f, isLit ? 0.1f : 0f, 0.2f, stupidHash);
|
||||
|
||||
int outer = isLit ? 0xff_64c8ff : 0xff_d2c8c8;
|
||||
int inner = isLit ? RenderLib.screenCol(outer) : 0xc8_322b33;
|
||||
|
|
|
@ -234,6 +234,7 @@ class GuiSpellcasting constructor(
|
|||
// Well, we never managed to get anything on the stack this go-around.
|
||||
this.drawState = PatternDrawState.BetweenPatterns
|
||||
}
|
||||
|
||||
is PatternDrawState.Drawing -> {
|
||||
val (start, _, pat) = this.drawState as PatternDrawState.Drawing
|
||||
this.drawState = PatternDrawState.BetweenPatterns
|
||||
|
@ -325,7 +326,8 @@ class GuiSpellcasting constructor(
|
|||
}
|
||||
RenderSystem.defaultBlendFunc()
|
||||
|
||||
for ((pat, origin, valid) in this.patterns) {
|
||||
for ((idx, elts) in this.patterns.withIndex()) {
|
||||
val (pat, origin, valid) = elts
|
||||
drawPatternFromPoints(
|
||||
mat,
|
||||
pat.toLines(
|
||||
|
@ -336,7 +338,8 @@ class GuiSpellcasting constructor(
|
|||
true,
|
||||
valid.color or (0xC8 shl 24),
|
||||
valid.fadeColor or (0xC8 shl 24),
|
||||
if (valid.success) 0.2f else 0.9f
|
||||
if (valid.success) 0.2f else 0.9f,
|
||||
idx.toDouble()
|
||||
)
|
||||
}
|
||||
|
||||
|
@ -358,7 +361,8 @@ class GuiSpellcasting constructor(
|
|||
}
|
||||
|
||||
points.add(mousePos)
|
||||
drawPatternFromPoints(mat, points, dupIndices, false, 0xff_64c8ff_u.toInt(), 0xff_fecbe6_u.toInt(), 0.1f)
|
||||
// Use the size of the patterns as the seed so that way when this one is added the zappies don't jump
|
||||
drawPatternFromPoints(mat, points, dupIndices, false, 0xff_64c8ff_u.toInt(), 0xff_fecbe6_u.toInt(), 0.1f, this.patterns.size.toDouble())
|
||||
}
|
||||
|
||||
RenderSystem.enableDepthTest()
|
||||
|
|
|
@ -48,7 +48,7 @@ public class PatternTooltipComponent implements ClientTooltipComponent {
|
|||
var pair = RenderLib.getCenteredPattern(pattern, RENDER_SIZE, RENDER_SIZE, 8f);
|
||||
this.scale = pair.getFirst();
|
||||
var dots = pair.getSecond();
|
||||
this.zappyPoints = RenderLib.makeZappy(dots, RenderLib.findDupIndices(pattern.positions()), 10f, 0.8f, 0f, 0f);
|
||||
this.zappyPoints = RenderLib.makeZappy(dots, RenderLib.findDupIndices(pattern.positions()), 10f, 0.8f, 0f, 0f, 0.0);
|
||||
this.pathfinderDots = dots.stream().distinct().collect(Collectors.toList());
|
||||
}
|
||||
|
||||
|
@ -79,7 +79,7 @@ public class PatternTooltipComponent implements ClientTooltipComponent {
|
|||
RenderSystem.setShader(GameRenderer::getPositionColorShader);
|
||||
RenderSystem.disableCull();
|
||||
RenderSystem.blendFunc(GlStateManager.SourceFactor.SRC_ALPHA,
|
||||
GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA);
|
||||
GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA);
|
||||
ps.translate(width / 2f, height / 2f, 1);
|
||||
|
||||
var mat = ps.last().pose();
|
||||
|
@ -87,9 +87,9 @@ public class PatternTooltipComponent implements ClientTooltipComponent {
|
|||
var innerLight = 0xc8_aba2a2;
|
||||
var innerDark = 0xc8_322b33;
|
||||
RenderLib.drawLineSeq(mat, this.zappyPoints, 5f, 0,
|
||||
outer, outer);
|
||||
outer, outer);
|
||||
RenderLib.drawLineSeq(mat, this.zappyPoints, 2f, 0,
|
||||
innerDark, innerLight);
|
||||
innerDark, innerLight);
|
||||
RenderLib.drawSpot(mat, this.zappyPoints.get(0), 2.5f, 1f, 0.1f, 0.15f, 0.6f);
|
||||
|
||||
for (var dot : this.pathfinderDots) {
|
||||
|
|
|
@ -19,7 +19,7 @@ import java.util.List;
|
|||
|
||||
public final class PatternDrawingUtil {
|
||||
public static void drawPattern(PoseStack poseStack, int x, int y, List<PatternEntry> patterns, List<Vec2> dots,
|
||||
boolean strokeOrder, long animTicks, int outer, int innerLight, int innerDark, int dotColor) {
|
||||
boolean strokeOrder, long animTicks, int outer, int innerLight, int innerDark, int dotColor) {
|
||||
poseStack.pushPose();
|
||||
poseStack.translate(x, y, 1);
|
||||
var mat = poseStack.last().pose();
|
||||
|
@ -103,12 +103,13 @@ public final class PatternDrawingUtil {
|
|||
var realCom = HexUtils.findCenter(seenRealPoints);
|
||||
|
||||
// and NOW for real!
|
||||
for (var pat : patternEntries) {
|
||||
for (int i = 0; i < patternEntries.size(); i++) {
|
||||
PatternEntry pat = patternEntries.get(i);
|
||||
var localOrigin = HexUtils.coordToPx(pat.origin(), hexSize, realCom.negated());
|
||||
var points = pat.pattern().toLines(hexSize, localOrigin);
|
||||
pat.zappyPoints()
|
||||
.addAll(RenderLib.makeZappy(points, RenderLib.findDupIndices(pat.pattern().positions()), 10f, 0.8f, 0f,
|
||||
0f));
|
||||
0f, i));
|
||||
}
|
||||
|
||||
var pathfinderDots = seenCoords.stream()
|
||||
|
|
|
@ -0,0 +1,39 @@
|
|||
import net.minecraft.world.level.levelgen.SingleThreadedRandomSource;
|
||||
import net.minecraft.world.level.levelgen.synth.PerlinNoise;
|
||||
import net.minecraft.world.level.levelgen.synth.SimplexNoise;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class WhatRangeDoTheNoisesOutputAnywaysTest {
|
||||
@Test
|
||||
public void test() {
|
||||
var perlin = PerlinNoise.create(new SingleThreadedRandomSource(12345), List.of(0, 1, 2, 3, 4));
|
||||
var simplex = new SimplexNoise(new SingleThreadedRandomSource(12345));
|
||||
|
||||
System.out.println("Perlin:");
|
||||
for (int i = 0; i < 20; i++) {
|
||||
System.out.printf(" %f%n", perlin.getValue(i / 10.0, 69420.0, 1337.0));
|
||||
}
|
||||
|
||||
System.out.println("Simplex:");
|
||||
for (int i = 0; i < 20; i++) {
|
||||
System.out.printf(" %f%n", simplex.getValue(i / 10.0, 69420.0, 1337.0));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void perlinBounds() {
|
||||
var perlin = PerlinNoise.create(new SingleThreadedRandomSource(12345), List.of(0, 1, 2, 3, 4));
|
||||
var min = Double.POSITIVE_INFINITY;
|
||||
var max = Double.NEGATIVE_INFINITY;
|
||||
|
||||
for (int i = 0; i < 10000; i++) {
|
||||
var it = perlin.getValue(i / 10.0, 12345.0, 7604.0);
|
||||
min = Math.min(min, it);
|
||||
max = Math.max(max, it);
|
||||
}
|
||||
|
||||
System.out.printf("Min: %f\nMax: %f\n", min, max);
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue