diff --git a/src/main/java/com/jozufozu/flywheel/Flywheel.java b/src/main/java/com/jozufozu/flywheel/Flywheel.java index b5f4d63f3..f9065081d 100644 --- a/src/main/java/com/jozufozu/flywheel/Flywheel.java +++ b/src/main/java/com/jozufozu/flywheel/Flywheel.java @@ -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 info = event.getRight(); info.add(""); diff --git a/src/main/java/com/jozufozu/flywheel/lib/material/Materials.java b/src/main/java/com/jozufozu/flywheel/lib/material/Materials.java index fae96ce0e..109fada6d 100644 --- a/src/main/java/com/jozufozu/flywheel/lib/material/Materials.java +++ b/src/main/java/com/jozufozu/flywheel/lib/material/Materials.java @@ -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()); diff --git a/src/main/java/com/jozufozu/flywheel/lib/math/MoreMath.java b/src/main/java/com/jozufozu/flywheel/lib/math/MoreMath.java index 1a7ca414d..986b32b57 100644 --- a/src/main/java/com/jozufozu/flywheel/lib/math/MoreMath.java +++ b/src/main/java/com/jozufozu/flywheel/lib/math/MoreMath.java @@ -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.

* Uses a different format that is friendly towards an optimized instruction-parallel diff --git a/src/main/java/com/jozufozu/flywheel/lib/math/RenderMath.java b/src/main/java/com/jozufozu/flywheel/lib/math/RenderMath.java index ad29c1549..f37489df9 100644 --- a/src/main/java/com/jozufozu/flywheel/lib/math/RenderMath.java +++ b/src/main/java/com/jozufozu/flywheel/lib/math/RenderMath.java @@ -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) { diff --git a/src/main/java/com/jozufozu/flywheel/lib/transform/Rotate.java b/src/main/java/com/jozufozu/flywheel/lib/transform/Rotate.java index 7130e2fa7..2db61984f 100644 --- a/src/main/java/com/jozufozu/flywheel/lib/transform/Rotate.java +++ b/src/main/java/com/jozufozu/flywheel/lib/transform/Rotate.java @@ -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 { } 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 { @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; } diff --git a/src/main/java/com/jozufozu/flywheel/lib/util/Axes.java b/src/main/java/com/jozufozu/flywheel/lib/util/Axes.java new file mode 100644 index 000000000..b65420f5f --- /dev/null +++ b/src/main/java/com/jozufozu/flywheel/lib/util/Axes.java @@ -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)); + } + } +} diff --git a/src/main/java/com/jozufozu/flywheel/mixin/visualmanage/ChunkRebuildHooksMixin.java b/src/main/java/com/jozufozu/flywheel/mixin/visualmanage/ChunkRebuildHooksMixin.java index aa660871d..9a6e092cf 100644 --- a/src/main/java/com/jozufozu/flywheel/mixin/visualmanage/ChunkRebuildHooksMixin.java +++ b/src/main/java/com/jozufozu/flywheel/mixin/visualmanage/ChunkRebuildHooksMixin.java @@ -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 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 void flywheel$tryAddBlockEntity(Object pCompileResults, E pBlockEntity, CallbackInfo ci) { + if (VisualizationHelper.tryAddBlockEntity(pBlockEntity)) { ci.cancel(); } } diff --git a/src/main/java/com/jozufozu/flywheel/vanilla/ChestVisual.java b/src/main/java/com/jozufozu/flywheel/vanilla/ChestVisual.java index 1fce755c9..90ef3d688 100644 --- a/src/main/java/com/jozufozu/flywheel/vanilla/ChestVisual.java +++ b/src/main/java/com/jozufozu/flywheel/vanilla/ChestVisual.java @@ -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 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 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 wrapper = chestBlock.combine(blockState, level, pos, true); lidProgress = wrapper.apply(ChestBlock.opennessCombiner(blockEntity)); } else { - baseRotation = Quaternion.ONE; + baseRotation.identity(); lidProgress = $ -> 0f; } diff --git a/src/main/java/com/jozufozu/flywheel/vanilla/MinecartVisual.java b/src/main/java/com/jozufozu/flywheel/vanilla/MinecartVisual.java index fa3adde0d..27d7bda1e 100644 --- a/src/main/java/com/jozufozu/flywheel/vanilla/MinecartVisual.java +++ b/src/main/java/com/jozufozu/flywheel/vanilla/MinecartVisual.java @@ -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 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 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 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(); } diff --git a/src/main/java/com/jozufozu/flywheel/vanilla/ShulkerBoxVisual.java b/src/main/java/com/jozufozu/flywheel/vanilla/ShulkerBoxVisual.java index 9ae935058..739dcba97 100644 --- a/src/main/java/com/jozufozu/flywheel/vanilla/ShulkerBoxVisual.java +++ b/src/main/java/com/jozufozu/flywheel/vanilla/ShulkerBoxVisual.java @@ -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(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);