properly fix #164
This commit is contained in:
parent
f15c975d8a
commit
b0beb23ba8
5 changed files with 45 additions and 93 deletions
|
@ -35,7 +35,6 @@ import net.minecraft.world.level.levelgen.XoroshiroRandomSource
|
|||
import net.minecraft.world.level.levelgen.synth.PerlinNoise
|
||||
import net.minecraft.world.phys.Vec2
|
||||
import kotlin.math.abs
|
||||
import kotlin.math.floor
|
||||
import kotlin.math.min
|
||||
import kotlin.math.sin
|
||||
|
||||
|
@ -45,14 +44,12 @@ import kotlin.math.sin
|
|||
val NOISE: PerlinNoise = PerlinNoise.create(XoroshiroRandomSource(9001L), listOf(0, 1, 2, 3, 4))
|
||||
|
||||
val CAP_THETA: Float = 18f
|
||||
val READABILITY_OFFSET: Float = 0.2f
|
||||
|
||||
/**
|
||||
* Draw a sequence of linePoints spanning the given points.
|
||||
*
|
||||
* Please make sure to enable the right asinine shaders; see [GuiSpellcasting]
|
||||
*/
|
||||
@JvmOverloads
|
||||
fun drawLineSeq(
|
||||
mat: Matrix4f,
|
||||
points: List<Vec2>,
|
||||
|
@ -60,7 +57,6 @@ fun drawLineSeq(
|
|||
z: Float,
|
||||
tail: Int,
|
||||
head: Int,
|
||||
animTime: Float? = null,
|
||||
) {
|
||||
if (points.size <= 1) return
|
||||
|
||||
|
@ -83,19 +79,22 @@ fun drawLineSeq(
|
|||
val n = points.size
|
||||
val joinAngles = FloatArray(n)
|
||||
val joinOffsets = FloatArray(n)
|
||||
for (i in 2..n-1) {
|
||||
for (i in 2..n - 1) {
|
||||
val p0 = points[i - 2];
|
||||
val p1 = points[i - 1];
|
||||
val p2 = points[i];
|
||||
val prev = p1.add(p0.negated())
|
||||
val next = p2.add(p1.negated())
|
||||
val angle = Mth.atan2((prev.x * next.y - prev.y * next.x).toDouble(), (prev.x * next.x + prev.y * next.y).toDouble()).toFloat()
|
||||
val angle =
|
||||
Mth.atan2((prev.x * next.y - prev.y * next.x).toDouble(), (prev.x * next.x + prev.y * next.y).toDouble())
|
||||
.toFloat()
|
||||
joinAngles[i - 1] = angle
|
||||
val clamp = Math.min(prev.length(), next.length()) / (width * 0.5f);
|
||||
joinOffsets[i - 1] = Mth.clamp(Mth.sin(angle) / (1 + Mth.cos(angle)), -clamp, clamp)
|
||||
}
|
||||
|
||||
fun vertex(color: BlockPos, pos: Vec2) = buf.vertex(mat, pos.x, pos.y, z).color(color.x, color.y, color.z, a).endVertex()
|
||||
fun vertex(color: BlockPos, pos: Vec2) =
|
||||
buf.vertex(mat, pos.x, pos.y, z).color(color.x, color.y, color.z, a).endVertex()
|
||||
for ((i, pair) in points.zipWithNext().withIndex()) {
|
||||
val (p1, p2) = pair
|
||||
// https://github.com/not-fl3/macroquad/blob/master/src/shapes.rs#L163
|
||||
|
@ -158,32 +157,6 @@ fun drawLineSeq(
|
|||
}
|
||||
drawCaps(BlockPos(r1.toInt(), g1.toInt(), b1.toInt()), points[0], points[1])
|
||||
drawCaps(BlockPos(r2.toInt(), g2.toInt(), b2.toInt()), points[n - 1], points[n - 2])
|
||||
|
||||
if (animTime != null) {
|
||||
val pointCircuit =
|
||||
(animTime * 30f * HexConfig.client().patternPointSpeedMultiplier().toFloat()) % (points.size + 10)
|
||||
// subtract 1 to avoid the point appearing between the end and start for 1 frame
|
||||
if (pointCircuit < points.size - 1) {
|
||||
val pointMacro = floor(pointCircuit).toInt()
|
||||
val pointMicro = pointCircuit - pointMacro
|
||||
|
||||
val p1 = points[pointMacro]
|
||||
val p2 = points[(pointMacro + 1) % points.size]
|
||||
val drawPos = Vec2(
|
||||
p1.x + (p2.x - p1.x) * pointMicro,
|
||||
p1.y + (p2.y - p1.y) * pointMicro,
|
||||
)
|
||||
drawSpot(
|
||||
mat,
|
||||
drawPos,
|
||||
2f,
|
||||
(r1 + 255) / 2f / 255f,
|
||||
(g1 + 255) / 2f / 255f,
|
||||
(b1 + 255) / 2f / 255f,
|
||||
a / 1.2f / 255f
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun rotate(vec: Vec2, theta: Float): Vec2 {
|
||||
|
@ -196,7 +169,6 @@ fun rotate(vec: Vec2, theta: Float): Vec2 {
|
|||
* * Draw a hex pattern from the given list of non-zappy points (as in, do the *style* of drawing it,
|
||||
* * you have to do the conversion yourself.)
|
||||
* */
|
||||
@JvmOverloads
|
||||
fun drawPatternFromPoints(
|
||||
mat: Matrix4f,
|
||||
points: List<Vec2>,
|
||||
|
@ -205,7 +177,6 @@ fun drawPatternFromPoints(
|
|||
tail: Int,
|
||||
head: Int,
|
||||
flowIrregular: Float,
|
||||
animTime: Float? = null
|
||||
) {
|
||||
val zappyPts = makeZappy(points, dupIndices, 10f, 2.5f, 0.1f, flowIrregular)
|
||||
val nodes = if (drawLast) {
|
||||
|
@ -213,8 +184,8 @@ fun drawPatternFromPoints(
|
|||
} else {
|
||||
points.dropLast(1)
|
||||
}
|
||||
drawLineSeq(mat, zappyPts, 5f, 0f, tail, head, null)
|
||||
drawLineSeq(mat, zappyPts, 2f, 1f, screenCol(tail), screenCol(head), animTime)
|
||||
drawLineSeq(mat, zappyPts, 5f, 0f, tail, head)
|
||||
drawLineSeq(mat, zappyPts, 2f, 1f, screenCol(tail), screenCol(head))
|
||||
for (node in nodes) {
|
||||
drawSpot(
|
||||
mat,
|
||||
|
@ -228,15 +199,25 @@ fun drawPatternFromPoints(
|
|||
}
|
||||
}
|
||||
|
||||
fun makeZappy(points: List<Vec2>, dupIndices: Set<Int>?, hops: Float, variance: Float, speed: Float, flowIrregular: Float) =
|
||||
makeZappy(points, dupIndices, hops.toInt(), variance, speed, flowIrregular)
|
||||
fun makeZappy(
|
||||
points: List<Vec2>,
|
||||
dupIndices: Set<Int>?,
|
||||
hops: Float,
|
||||
variance: Float,
|
||||
speed: Float,
|
||||
flowIrregular: Float
|
||||
) =
|
||||
makeZappy(points, dupIndices, hops.toInt(), variance, speed, flowIrregular, 0.2f)
|
||||
|
||||
/**
|
||||
* Split up a sequence of linePoints with a lightning effect
|
||||
* @param hops: rough number of points to subdivide each segment into
|
||||
* @param speed: rate at which the lightning effect should move/shake/etc
|
||||
*/
|
||||
fun makeZappy(barePoints: List<Vec2>, dupIndices: Set<Int>?, hops: Int, variance: Float, speed: Float, flowIrregular: Float): List<Vec2> {
|
||||
fun makeZappy(
|
||||
barePoints: List<Vec2>, dupIndices: Set<Int>?, hops: Int, variance: Float, speed: Float, flowIrregular: Float,
|
||||
readabilityOffset: Float
|
||||
): List<Vec2> {
|
||||
// Nothing in, nothing out
|
||||
if (barePoints.isEmpty()) {
|
||||
return emptyList()
|
||||
|
@ -282,12 +263,13 @@ fun makeZappy(barePoints: List<Vec2>, dupIndices: Set<Int>?, hops: Int, variance
|
|||
}
|
||||
return zappyPts
|
||||
}
|
||||
|
||||
val points = mutableListOf<Vec2>()
|
||||
val daisyChain = mutableListOf<Vec2>()
|
||||
return if (dupIndices != null) {
|
||||
for ((i, pair) in barePoints.zipWithNext().withIndex()) {
|
||||
val (head, tail) = pair
|
||||
val tangent = tail.add(head.negated()).scale(READABILITY_OFFSET)
|
||||
val tangent = tail.add(head.negated()).scale(readabilityOffset)
|
||||
if (i != 0 && dupIndices.contains(i)) {
|
||||
daisyChain.add(head.add(tangent))
|
||||
} else {
|
||||
|
@ -308,7 +290,7 @@ fun makeZappy(barePoints: List<Vec2>, dupIndices: Set<Int>?, hops: Int, variance
|
|||
}
|
||||
}
|
||||
|
||||
fun<T> findDupIndices(pts: Iterable<T>): Set<Int> {
|
||||
fun <T> findDupIndices(pts: Iterable<T>): Set<Int> {
|
||||
val dedup = HashMap<T, Int>()
|
||||
val found = HashSet<Int>()
|
||||
for ((i, pt) in pts.withIndex()) {
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
package at.petrak.hexcasting.client.entity;
|
||||
|
||||
import at.petrak.hexcasting.api.mod.HexConfig;
|
||||
import at.petrak.hexcasting.common.entities.EntityWallScroll;
|
||||
import com.mojang.blaze3d.systems.RenderSystem;
|
||||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
|
@ -122,36 +121,8 @@ public class WallScrollRenderer extends EntityRenderer<EntityWallScroll> {
|
|||
ps.translate(0, 0, 0.01);
|
||||
theCoolerDrawLineSeq(mat, norm, light, verts, points, wallScroll.blockSize * 2f / 3f, inner);
|
||||
|
||||
if (wallScroll.getShowsStrokeOrder()) {
|
||||
if (wallScroll.getShowsStartPos()) {
|
||||
var spotFrac = 0.8f * wallScroll.blockSize;
|
||||
|
||||
var animTime = wallScroll.tickCount + partialTicks;
|
||||
var pointCircuit =
|
||||
(animTime * HexConfig.client().patternPointSpeedMultiplier()) % (points.size() + 10);
|
||||
if (pointCircuit < points.size() - 1) {
|
||||
var pointMacro = Mth.floor(pointCircuit);
|
||||
var pointMicro = pointCircuit - pointMacro;
|
||||
|
||||
var p1 = points.get(pointMacro);
|
||||
var p2 = points.get((pointMacro + 1) % points.size());
|
||||
var drawPos = new Vec2(
|
||||
(float) (p1.x + (p2.x - p1.x) * pointMicro),
|
||||
(float) (p1.y + (p2.y - p1.y) * pointMicro)
|
||||
);
|
||||
|
||||
ps.translate(0, 0, 0.01);
|
||||
theCoolerDrawSpot(mat, norm, light, verts, drawPos, 2.6666f / 3f * spotFrac,
|
||||
0xff_cfa0f3);
|
||||
ps.translate(0, 0, 0.01);
|
||||
theCoolerDrawSpot(mat, norm, light, verts, drawPos, 2f / 3f * spotFrac,
|
||||
0xff_8d6acc);
|
||||
} else {
|
||||
ps.translate(0, 0, 0.02);
|
||||
}
|
||||
|
||||
ps.translate(0, 0, 0.01);
|
||||
theCoolerDrawSpot(mat, norm, light, verts, points.get(0), spotFrac, 0xff_4946d3);
|
||||
ps.translate(0, 0, 0.01);
|
||||
theCoolerDrawSpot(mat, norm, light, verts, points.get(0), 2f / 3f * spotFrac,
|
||||
0xff_5b7bd7);
|
||||
}
|
||||
|
|
|
@ -178,9 +178,9 @@ class GuiSpellcasting constructor(
|
|||
if (anchorCoord != null) {
|
||||
val anchor = this.coordToPx(anchorCoord)
|
||||
val mouse = Vec2(mx.toFloat(), my.toFloat())
|
||||
if (anchor.distanceToSqr(mouse) >=
|
||||
this.hexSize() * this.hexSize() * 2.0 * HexConfig.client().gridSnapThreshold()
|
||||
) {
|
||||
val snapDist =
|
||||
this.hexSize() * this.hexSize() * 2.0 * Mth.clamp(HexConfig.client().gridSnapThreshold(), 0.5, 1.0)
|
||||
if (anchor.distanceToSqr(mouse) >= snapDist) {
|
||||
val delta = mouse.add(anchor.negated())
|
||||
val angle = atan2(delta.y, delta.x)
|
||||
// 0 is right, increases clockwise(?)
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package at.petrak.hexcasting.client.gui;
|
||||
|
||||
import at.petrak.hexcasting.api.spell.math.HexPattern;
|
||||
import at.petrak.hexcasting.client.ClientTickCounter;
|
||||
import at.petrak.hexcasting.client.RenderLib;
|
||||
import at.petrak.hexcasting.common.misc.PatternTooltip;
|
||||
import com.mojang.blaze3d.platform.GlStateManager;
|
||||
|
@ -84,10 +83,9 @@ public class PatternTooltipComponent implements ClientTooltipComponent {
|
|||
var innerLight = 0xc8_aba2a2;
|
||||
var innerDark = 0xc8_322b33;
|
||||
RenderLib.drawLineSeq(mat, this.zappyPoints, 5f, 0,
|
||||
outer, outer, null);
|
||||
outer, outer);
|
||||
RenderLib.drawLineSeq(mat, this.zappyPoints, 2f, 0,
|
||||
innerDark, innerLight,
|
||||
ClientTickCounter.getTotal() / 40f);
|
||||
innerDark, innerLight);
|
||||
RenderLib.drawSpot(mat, this.zappyPoints.get(0), 2.5f, 1f, 0.1f, 0.15f, 0.6f);
|
||||
|
||||
for (var dot : this.pathfinderDots) {
|
||||
|
|
|
@ -35,7 +35,7 @@ import org.jetbrains.annotations.Nullable;
|
|||
import java.util.List;
|
||||
|
||||
public class EntityWallScroll extends HangingEntity {
|
||||
private static final EntityDataAccessor<Boolean> SHOWS_STROKE_ORDER = SynchedEntityData.defineId(
|
||||
private static final EntityDataAccessor<Boolean> SHOWS_START_POS = SynchedEntityData.defineId(
|
||||
EntityWallScroll.class,
|
||||
EntityDataSerializers.BOOLEAN);
|
||||
|
||||
|
@ -55,7 +55,7 @@ public class EntityWallScroll extends HangingEntity {
|
|||
super(HexEntities.WALL_SCROLL, world, pos);
|
||||
this.setDirection(dir);
|
||||
this.blockSize = blockSize;
|
||||
this.setShowsStrokeOrder(showStrokeOrder);
|
||||
this.setShowsStartPos(showStrokeOrder);
|
||||
|
||||
this.loadDataFromScrollItem(scroll);
|
||||
this.recalculateBoundingBox();
|
||||
|
@ -71,7 +71,8 @@ public class EntityWallScroll extends HangingEntity {
|
|||
var pair = RenderLib.getCenteredPattern(pattern, 128f / 3 * blockSize, 128f / 3 * blockSize,
|
||||
16f / 3 * blockSize);
|
||||
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);
|
||||
}
|
||||
|
||||
this.isAncient = NBTHelper.hasString(scroll, ItemScroll.TAG_OP_ID);
|
||||
|
@ -85,15 +86,15 @@ public class EntityWallScroll extends HangingEntity {
|
|||
@Override
|
||||
protected void defineSynchedData() {
|
||||
super.defineSynchedData();
|
||||
this.entityData.define(SHOWS_STROKE_ORDER, false);
|
||||
this.entityData.define(SHOWS_START_POS, false);
|
||||
}
|
||||
|
||||
public boolean getShowsStrokeOrder() {
|
||||
return this.entityData.get(SHOWS_STROKE_ORDER);
|
||||
public boolean getShowsStartPos() {
|
||||
return this.entityData.get(SHOWS_START_POS);
|
||||
}
|
||||
|
||||
public void setShowsStrokeOrder(boolean b) {
|
||||
this.entityData.set(SHOWS_STROKE_ORDER, b);
|
||||
public void setShowsStartPos(boolean b) {
|
||||
this.entityData.set(SHOWS_START_POS, b);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -123,11 +124,11 @@ public class EntityWallScroll extends HangingEntity {
|
|||
@Override
|
||||
public InteractionResult interactAt(Player pPlayer, Vec3 pVec, InteractionHand pHand) {
|
||||
var handStack = pPlayer.getItemInHand(pHand);
|
||||
if (handStack.is(HexItems.AMETHYST_DUST) && !this.getShowsStrokeOrder()) {
|
||||
if (handStack.is(HexItems.AMETHYST_DUST) && !this.getShowsStartPos()) {
|
||||
if (!pPlayer.getAbilities().instabuild) {
|
||||
handStack.shrink(1);
|
||||
}
|
||||
this.setShowsStrokeOrder(true);
|
||||
this.setShowsStartPos(true);
|
||||
|
||||
pPlayer.level.playSound(pPlayer, this, HexSounds.SCROLL_DUST, SoundSource.PLAYERS, 1f, 1f);
|
||||
return InteractionResult.SUCCESS;
|
||||
|
@ -144,14 +145,14 @@ public class EntityWallScroll extends HangingEntity {
|
|||
public Packet<?> getAddEntityPacket() {
|
||||
return IXplatAbstractions.INSTANCE.toVanillaClientboundPacket(
|
||||
new MsgNewWallScrollAck(new ClientboundAddEntityPacket(this),
|
||||
pos, direction, scroll, getShowsStrokeOrder(), blockSize));
|
||||
pos, direction, scroll, getShowsStartPos(), blockSize));
|
||||
}
|
||||
|
||||
public void readSpawnData(BlockPos pos, Direction dir, ItemStack scrollItem,
|
||||
boolean showsStrokeOrder, int blockSize) {
|
||||
this.pos = pos;
|
||||
this.setDirection(dir);
|
||||
this.setShowsStrokeOrder(showsStrokeOrder);
|
||||
this.setShowsStartPos(showsStrokeOrder);
|
||||
this.blockSize = blockSize;
|
||||
|
||||
this.recalculateBoundingBox();
|
||||
|
@ -162,7 +163,7 @@ public class EntityWallScroll extends HangingEntity {
|
|||
public void addAdditionalSaveData(CompoundTag tag) {
|
||||
tag.putByte("direction", (byte) this.direction.ordinal());
|
||||
tag.put("scroll", HexUtils.serializeToNBT(this.scroll));
|
||||
tag.putBoolean("showsStrokeOrder", this.getShowsStrokeOrder());
|
||||
tag.putBoolean("showsStrokeOrder", this.getShowsStartPos());
|
||||
tag.putInt("blockSize", this.blockSize);
|
||||
super.addAdditionalSaveData(tag);
|
||||
}
|
||||
|
@ -171,7 +172,7 @@ public class EntityWallScroll extends HangingEntity {
|
|||
public void readAdditionalSaveData(CompoundTag tag) {
|
||||
this.direction = Direction.values()[tag.getByte("direction")];
|
||||
var scroll = ItemStack.of(tag.getCompound("scroll"));
|
||||
this.setShowsStrokeOrder(tag.getBoolean("showsStrokeOrder"));
|
||||
this.setShowsStartPos(tag.getBoolean("showsStrokeOrder"));
|
||||
if (tag.contains("blockSize")) {
|
||||
this.blockSize = tag.getInt("blockSize");
|
||||
} else {
|
||||
|
|
Loading…
Reference in a new issue