mirror of
https://github.com/Jozufozu/Flywheel.git
synced 2024-12-27 07:26:48 +01:00
Round 2
- Add Axes class to (temporarily?) replace old mojmath Vector3f.$axis. - Add helper for getting a random float between 2 values. - Implement diffuse light formula. - Fix debug overlay event. - Try and fix ChunkRebuildHooksMixin but the first parameter isn't visible. Hopefully stubbing in Object will compile later.
This commit is contained in:
parent
df93b09f44
commit
3f3f2b5791
11 changed files with 91 additions and 50 deletions
|
@ -36,10 +36,12 @@ import com.jozufozu.flywheel.vanilla.VanillaVisuals;
|
|||
import com.mojang.logging.LogUtils;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.commands.synchronization.ArgumentTypeInfos;
|
||||
import net.minecraft.commands.synchronization.SingletonArgumentInfo;
|
||||
import net.minecraft.core.Vec3i;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.client.event.RenderGameOverlayEvent;
|
||||
import net.minecraftforge.client.event.CustomizeGuiOverlayEvent;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.event.level.LevelEvent;
|
||||
import net.minecraftforge.eventbus.api.IEventBus;
|
||||
|
@ -72,8 +74,8 @@ public class Flywheel {
|
|||
FlwConfig.get().registerSpecs(modLoadingContext);
|
||||
|
||||
modLoadingContext.registerExtensionPoint(IExtensionPoint.DisplayTest.class, () -> new IExtensionPoint.DisplayTest(
|
||||
() -> NetworkConstants.IGNORESERVERONLY,
|
||||
(serverVersion, isNetwork) -> isNetwork
|
||||
() -> "any",
|
||||
(serverVersion, isNetwork) -> true
|
||||
));
|
||||
|
||||
DistExecutor.unsafeRunWhenOn(Dist.CLIENT, () -> () -> Flywheel.clientInit(forgeEventBus, modEventBus));
|
||||
|
@ -128,14 +130,15 @@ public class Flywheel {
|
|||
RegistryImpl.freezeAll();
|
||||
IdRegistryImpl.freezeAll();
|
||||
|
||||
ArgumentTypes.register(rl("backend").toString(), BackendArgument.class, new EmptyArgumentSerializer<>(() -> BackendArgument.INSTANCE));
|
||||
ArgumentTypeInfos.registerByClass(BackendArgument.class, SingletonArgumentInfo.contextFree(() -> BackendArgument.INSTANCE));
|
||||
}
|
||||
|
||||
private static void addDebugInfo(RenderGameOverlayEvent.Text event) {
|
||||
private static void addDebugInfo(CustomizeGuiOverlayEvent.DebugText event) {
|
||||
Minecraft mc = Minecraft.getInstance();
|
||||
if (!mc.options.renderDebug) {
|
||||
return;
|
||||
}
|
||||
// FIXME: do we need this check anymore?
|
||||
// if (!mc.options.renderDebug) {
|
||||
// return;
|
||||
// }
|
||||
|
||||
ArrayList<String> info = event.getRight();
|
||||
info.add("");
|
||||
|
|
|
@ -166,7 +166,7 @@ public final class Materials {
|
|||
return new GlStateShard(
|
||||
() -> {
|
||||
GlTextureUnit.T0.makeActive();
|
||||
RenderSystem.enableTexture();
|
||||
// FIXME: I think it got removed RenderSystem.enableTexture();
|
||||
AbstractTexture texture = Minecraft.getInstance().getTextureManager().getTexture(loc);
|
||||
texture.setFilter(blur, mipmap);
|
||||
RenderSystem.setShaderTexture(0, texture.getId());
|
||||
|
|
|
@ -4,6 +4,8 @@ import org.joml.Math;
|
|||
import org.joml.Matrix4f;
|
||||
import org.lwjgl.system.MemoryUtil;
|
||||
|
||||
import net.minecraft.util.RandomSource;
|
||||
|
||||
public final class MoreMath {
|
||||
public static int align16(int numToRound) {
|
||||
return (numToRound + 16 - 1) & -16;
|
||||
|
@ -50,6 +52,10 @@ public final class MoreMath {
|
|||
}
|
||||
}
|
||||
|
||||
public static float nextFloat(RandomSource rs, float min, float max) {
|
||||
return rs.nextFloat() * (max - min) + min;
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes the frustum planes of the given projection matrix to the given buffer.<p>
|
||||
* Uses a different format that is friendly towards an optimized instruction-parallel
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
package com.jozufozu.flywheel.lib.math;
|
||||
|
||||
import net.minecraftforge.client.model.pipeline.LightUtil;
|
||||
|
||||
public final class RenderMath {
|
||||
/**
|
||||
* Convert a signed byte into a signed, normalized float.
|
||||
|
@ -40,7 +38,8 @@ public final class RenderMath {
|
|||
if (!shaded) {
|
||||
return 1f;
|
||||
}
|
||||
return LightUtil.diffuseLight(x, y, z);
|
||||
// FIXME: once we compile make sure this is correct.
|
||||
return Math.min(x * x + y * y * (3f + y) + z, 1f);
|
||||
}
|
||||
|
||||
public static float diffuseLightNether(float x, float y, float z, boolean shaded) {
|
||||
|
|
|
@ -2,7 +2,9 @@ package com.jozufozu.flywheel.lib.transform;
|
|||
|
||||
import org.joml.AxisAngle4f;
|
||||
import org.joml.Quaternionf;
|
||||
import org.joml.Vector3f;
|
||||
import org.joml.Vector3fc;
|
||||
|
||||
import com.jozufozu.flywheel.lib.util.Axes;
|
||||
|
||||
import net.minecraft.core.Direction;
|
||||
|
||||
|
@ -17,44 +19,47 @@ public interface Rotate<Self> {
|
|||
}
|
||||
|
||||
default Self rotate(double angle, Direction.Axis axis) {
|
||||
Vector3f vec =
|
||||
axis == Direction.Axis.X ? Vector3f.XP : axis == Direction.Axis.Y ? Vector3f.YP : Vector3f.ZP;
|
||||
return multiply(vec, angle);
|
||||
Axes.Axis vec = switch (axis) {
|
||||
case X -> Axes.XP;
|
||||
case Y -> Axes.YP;
|
||||
case Z -> Axes.ZP;
|
||||
};
|
||||
return multiply(vec.vec(), angle);
|
||||
}
|
||||
|
||||
default Self rotateX(double angle) {
|
||||
return multiply(Vector3f.XP, angle);
|
||||
return multiply(Axes.XP.vec(), angle);
|
||||
}
|
||||
|
||||
default Self rotateY(double angle) {
|
||||
return multiply(Vector3f.YP, angle);
|
||||
return multiply(Axes.YP.vec(), angle);
|
||||
}
|
||||
|
||||
default Self rotateZ(double angle) {
|
||||
return multiply(Vector3f.ZP, angle);
|
||||
return multiply(Axes.ZP.vec(), angle);
|
||||
}
|
||||
|
||||
default Self rotateXRadians(double angle) {
|
||||
return multiplyRadians(Vector3f.XP, angle);
|
||||
return multiplyRadians(Axes.XP.vec(), angle);
|
||||
}
|
||||
|
||||
default Self rotateYRadians(double angle) {
|
||||
return multiplyRadians(Vector3f.YP, angle);
|
||||
return multiplyRadians(Axes.YP.vec(), angle);
|
||||
}
|
||||
|
||||
default Self rotateZRadians(double angle) {
|
||||
return multiplyRadians(Vector3f.ZP, angle);
|
||||
return multiplyRadians(Axes.ZP.vec(), angle);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
default Self multiply(Vector3f axis, double angle) {
|
||||
default Self multiply(Vector3fc axis, double angle) {
|
||||
if (angle == 0)
|
||||
return (Self) this;
|
||||
return multiply(axis.rotationDegrees((float) angle));
|
||||
return multiplyRadians(axis, Math.toRadians(angle));
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
default Self multiplyRadians(Vector3f axis, double angle) {
|
||||
default Self multiplyRadians(Vector3fc axis, double angle) {
|
||||
if (angle == 0)
|
||||
return (Self) this;
|
||||
return multiply(new Quaternionf(new AxisAngle4f((float) angle, axis)));
|
||||
|
@ -63,12 +68,12 @@ public interface Rotate<Self> {
|
|||
@SuppressWarnings("unchecked")
|
||||
default Self rotateToFace(Direction facing) {
|
||||
switch (facing) {
|
||||
case SOUTH -> multiply(Vector3f.YP.rotationDegrees(180));
|
||||
case WEST -> multiply(Vector3f.YP.rotationDegrees(90));
|
||||
case NORTH -> multiply(Vector3f.YP.rotationDegrees(0));
|
||||
case EAST -> multiply(Vector3f.YP.rotationDegrees(270));
|
||||
case UP -> multiply(Vector3f.XP.rotationDegrees(90));
|
||||
case DOWN -> multiply(Vector3f.XN.rotationDegrees(90));
|
||||
case SOUTH -> multiply(Axes.YP.rotationDegrees(180));
|
||||
case WEST -> multiply(Axes.YP.rotationDegrees(90));
|
||||
case NORTH -> multiply(Axes.YP.rotationDegrees(0));
|
||||
case EAST -> multiply(Axes.YP.rotationDegrees(270));
|
||||
case UP -> multiply(Axes.XP.rotationDegrees(90));
|
||||
case DOWN -> multiply(Axes.XN.rotationDegrees(90));
|
||||
}
|
||||
return (Self) this;
|
||||
}
|
||||
|
|
25
src/main/java/com/jozufozu/flywheel/lib/util/Axes.java
Normal file
25
src/main/java/com/jozufozu/flywheel/lib/util/Axes.java
Normal file
|
@ -0,0 +1,25 @@
|
|||
package com.jozufozu.flywheel.lib.util;
|
||||
|
||||
import org.joml.Quaternionf;
|
||||
import org.joml.Vector3f;
|
||||
import org.joml.Vector3fc;
|
||||
|
||||
public class Axes {
|
||||
|
||||
public static Axis XP = new Axis(new Vector3f(1, 0, 0));
|
||||
public static Axis YP = new Axis(new Vector3f(0, 1, 0));
|
||||
public static Axis ZP = new Axis(new Vector3f(0, 0, 1));
|
||||
public static Axis XN = new Axis(new Vector3f(-1, 0, 0));
|
||||
public static Axis YN = new Axis(new Vector3f(0, -1, 0));
|
||||
public static Axis ZN = new Axis(new Vector3f(0, 0, -1));
|
||||
|
||||
public record Axis(Vector3fc vec) {
|
||||
public Quaternionf rotation(float radians) {
|
||||
return new Quaternionf().setAngleAxis(radians, vec.x(), vec.y(), vec.z());
|
||||
}
|
||||
|
||||
public Quaternionf rotationDegrees(float degrees) {
|
||||
return rotation((float) Math.toRadians(degrees));
|
||||
}
|
||||
}
|
||||
}
|
|
@ -9,14 +9,13 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
|||
|
||||
import com.jozufozu.flywheel.impl.visualization.VisualizationHelper;
|
||||
|
||||
import net.minecraft.client.renderer.chunk.ChunkRenderDispatcher;
|
||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||
|
||||
@Mixin(targets = "net.minecraft.client.renderer.chunk.ChunkRenderDispatcher$RenderChunk$RebuildTask")
|
||||
@Mixin(targets = "net.minecraft.client.renderer.chunk.SectionRenderDispatcher$RenderSection$RebuildTask")
|
||||
public class ChunkRebuildHooksMixin {
|
||||
@Inject(method = "handleBlockEntity(Lnet/minecraft/client/renderer/chunk/ChunkRenderDispatcher$CompiledChunk;Ljava/util/Set;Lnet/minecraft/world/level/block/entity/BlockEntity;)V", at = @At("HEAD"), cancellable = true)
|
||||
private void flywheel$tryAddBlockEntity(ChunkRenderDispatcher.CompiledChunk compiledChunk, Set<BlockEntity> globalBlockEntities, BlockEntity blockEntity, CallbackInfo ci) {
|
||||
if (VisualizationHelper.tryAddBlockEntity(blockEntity)) {
|
||||
@Inject(method = "handleBlockEntity(Lnet/minecraft/client/renderer/chunk/SectionRenderDispatcher$RenderSection$RebuildTask$CompileResults;Lnet/minecraft/world/level/block/entity/BlockEntity;)V", at = @At("HEAD"), cancellable = true)
|
||||
private <E extends BlockEntity> void flywheel$tryAddBlockEntity(Object pCompileResults, E pBlockEntity, CallbackInfo ci) {
|
||||
if (VisualizationHelper.tryAddBlockEntity(pBlockEntity)) {
|
||||
ci.cancel();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,6 +19,7 @@ import com.jozufozu.flywheel.lib.material.Materials;
|
|||
import com.jozufozu.flywheel.lib.model.ModelCache;
|
||||
import com.jozufozu.flywheel.lib.model.SimpleModel;
|
||||
import com.jozufozu.flywheel.lib.model.part.ModelPartConverter;
|
||||
import com.jozufozu.flywheel.lib.util.Axes;
|
||||
import com.jozufozu.flywheel.lib.util.Pair;
|
||||
import com.jozufozu.flywheel.lib.visual.AbstractBlockEntityVisual;
|
||||
|
||||
|
@ -60,7 +61,7 @@ public class ChestVisual<T extends BlockEntity & LidBlockEntity> extends Abstrac
|
|||
|
||||
private ChestType chestType;
|
||||
private Material texture;
|
||||
private Quaternionf baseRotation;
|
||||
private final Quaternionf baseRotation = new Quaternionf();
|
||||
private Float2FloatFunction lidProgress;
|
||||
|
||||
private float lastProgress = Float.NaN;
|
||||
|
@ -81,13 +82,13 @@ public class ChestVisual<T extends BlockEntity & LidBlockEntity> extends Abstrac
|
|||
Block block = blockState.getBlock();
|
||||
if (block instanceof AbstractChestBlock<?> chestBlock) {
|
||||
float horizontalAngle = blockState.getValue(ChestBlock.FACING).toYRot();
|
||||
baseRotation = Vector3f.YP.rotationDegrees(-horizontalAngle);
|
||||
baseRotation.setAngleAxis(Math.toRadians(-horizontalAngle), 0, 1, 0);
|
||||
bottom.setRotation(baseRotation);
|
||||
|
||||
DoubleBlockCombiner.NeighborCombineResult<? extends ChestBlockEntity> wrapper = chestBlock.combine(blockState, level, pos, true);
|
||||
lidProgress = wrapper.apply(ChestBlock.opennessCombiner(blockEntity));
|
||||
} else {
|
||||
baseRotation = Quaternion.ONE;
|
||||
baseRotation.identity();
|
||||
lidProgress = $ -> 0f;
|
||||
}
|
||||
|
||||
|
|
|
@ -13,6 +13,7 @@ import com.jozufozu.flywheel.lib.model.ModelHolder;
|
|||
import com.jozufozu.flywheel.lib.model.Models;
|
||||
import com.jozufozu.flywheel.lib.model.SimpleModel;
|
||||
import com.jozufozu.flywheel.lib.model.part.ModelPartConverter;
|
||||
import com.jozufozu.flywheel.lib.util.Axes;
|
||||
import com.jozufozu.flywheel.lib.visual.AbstractEntityVisual;
|
||||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
|
||||
|
@ -142,8 +143,8 @@ public class MinecartVisual<T extends AbstractMinecart> extends AbstractEntityVi
|
|||
}
|
||||
|
||||
stack.translate(0.0D, 0.375D, 0.0D);
|
||||
stack.mulPose(Vector3f.YP.rotationDegrees(180 - yaw));
|
||||
stack.mulPose(Vector3f.ZP.rotationDegrees(-pitch));
|
||||
stack.mulPose(Axes.YP.rotationDegrees(180 - yaw));
|
||||
stack.mulPose(Axes.ZP.rotationDegrees(-pitch));
|
||||
|
||||
float hurtTime = entity.getHurtTime() - partialTick;
|
||||
float damage = entity.getDamage() - partialTick;
|
||||
|
@ -153,7 +154,7 @@ public class MinecartVisual<T extends AbstractMinecart> extends AbstractEntityVi
|
|||
}
|
||||
|
||||
if (hurtTime > 0) {
|
||||
stack.mulPose(Vector3f.XP.rotationDegrees(Mth.sin(hurtTime) * hurtTime * damage / 10.0F * (float) entity.getHurtDir()));
|
||||
stack.mulPose(Axes.XP.rotationDegrees(Mth.sin(hurtTime) * hurtTime * damage / 10.0F * (float) entity.getHurtDir()));
|
||||
}
|
||||
|
||||
int displayOffset = entity.getDisplayOffset();
|
||||
|
@ -161,7 +162,7 @@ public class MinecartVisual<T extends AbstractMinecart> extends AbstractEntityVi
|
|||
stack.pushPose();
|
||||
stack.scale(0.75F, 0.75F, 0.75F);
|
||||
stack.translate(-0.5D, (float) (displayOffset - 8) / 16, 0.5D);
|
||||
stack.mulPose(Vector3f.YP.rotationDegrees(90));
|
||||
stack.mulPose(Axes.YP.rotationDegrees(90));
|
||||
contents.setTransform(stack);
|
||||
stack.popPose();
|
||||
}
|
||||
|
|
|
@ -16,6 +16,7 @@ import com.jozufozu.flywheel.lib.model.ModelCache;
|
|||
import com.jozufozu.flywheel.lib.model.SimpleModel;
|
||||
import com.jozufozu.flywheel.lib.model.part.ModelPartConverter;
|
||||
import com.jozufozu.flywheel.lib.transform.TransformStack;
|
||||
import com.jozufozu.flywheel.lib.util.Axes;
|
||||
import com.jozufozu.flywheel.lib.visual.AbstractBlockEntityVisual;
|
||||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
|
||||
|
@ -102,7 +103,7 @@ public class ShulkerBoxVisual extends AbstractBlockEntityVisual<ShulkerBoxBlockE
|
|||
}
|
||||
lastProgress = progress;
|
||||
|
||||
Quaternionf spin = Vector3f.YP.rotationDegrees(270.0f * progress);
|
||||
Quaternionf spin = Axes.YP.rotationDegrees(270.0f * progress);
|
||||
|
||||
TransformStack.cast(stack)
|
||||
.pushPose()
|
||||
|
|
|
@ -17,6 +17,7 @@ import com.jozufozu.flywheel.api.visualization.VisualizationContext;
|
|||
import com.jozufozu.flywheel.api.visualization.VisualizationManager;
|
||||
import com.jozufozu.flywheel.lib.instance.InstanceTypes;
|
||||
import com.jozufozu.flywheel.lib.instance.TransformedInstance;
|
||||
import com.jozufozu.flywheel.lib.math.MoreMath;
|
||||
import com.jozufozu.flywheel.lib.model.Models;
|
||||
import com.jozufozu.flywheel.lib.task.ForEachPlan;
|
||||
|
||||
|
@ -88,9 +89,9 @@ public class ExampleEffect implements Effect {
|
|||
|
||||
Vec3 playerPos = player.position();
|
||||
|
||||
var x = (float) (playerPos.x + level.random.nextFloat(-20, 20));
|
||||
var y = (float) (playerPos.y + level.random.nextFloat(0, 5));
|
||||
var z = (float) (playerPos.z + level.random.nextFloat(-20, 20));
|
||||
var x = (float) (playerPos.x + MoreMath.nextFloat(level.random, -20, 20));
|
||||
var y = (float) (playerPos.y + MoreMath.nextFloat(level.random, 0, 5));
|
||||
var z = (float) (playerPos.z + MoreMath.nextFloat(level.random, -20, 20));
|
||||
|
||||
ExampleEffect effect = new ExampleEffect(level, new Vector3f(x, y, z));
|
||||
ALL_EFFECTS.add(effect);
|
||||
|
@ -111,9 +112,9 @@ public class ExampleEffect implements Effect {
|
|||
this.boids = new ArrayList<>(VISUAL_COUNT);
|
||||
|
||||
for (int i = 0; i < VISUAL_COUNT; i++) {
|
||||
var x = targetPoint.x + level.random.nextFloat(-SPAWN_RADIUS, SPAWN_RADIUS);
|
||||
var y = targetPoint.y + level.random.nextFloat(-SPAWN_RADIUS, SPAWN_RADIUS);
|
||||
var z = targetPoint.z + level.random.nextFloat(-SPAWN_RADIUS, SPAWN_RADIUS);
|
||||
var x = targetPoint.x + MoreMath.nextFloat(level.random, -SPAWN_RADIUS, SPAWN_RADIUS);
|
||||
var y = targetPoint.y + MoreMath.nextFloat(level.random, -SPAWN_RADIUS, SPAWN_RADIUS);
|
||||
var z = targetPoint.z + MoreMath.nextFloat(level.random, -SPAWN_RADIUS, SPAWN_RADIUS);
|
||||
|
||||
Boid boid = new Boid(x, y, z);
|
||||
boids.add(boid);
|
||||
|
|
Loading…
Reference in a new issue