From 99be0ad281f0cb9f923c0c791eb40c80e935ac70 Mon Sep 17 00:00:00 2001 From: Jozufozu Date: Wed, 22 Nov 2023 21:30:58 -0800 Subject: [PATCH] First blood - Make a quick pass resolving conflicts - Mostly joml related, or to do with the world -> level rename - Basically left model builders and virtual levels alone - There are also some forge events that seem to no longer exist --- .../java/com/jozufozu/flywheel/Flywheel.java | 9 +- .../flywheel/api/event/RenderContext.java | 8 +- .../flywheel/api/event/RenderStageEvent.java | 3 +- .../visualization/VisualizationManager.java | 8 +- .../jozufozu/flywheel/backend/Backends.java | 12 +- .../backend/engine/AbstractEngine.java | 2 +- .../engine/batching/BatchedDrawTracker.java | 4 +- .../engine/batching/TransformCall.java | 4 +- .../flywheel/config/BackendArgument.java | 4 +- .../jozufozu/flywheel/config/FlwCommands.java | 23 +-- .../com/jozufozu/flywheel/glsl/LoadError.java | 8 + .../jozufozu/flywheel/glsl/ShaderSources.java | 18 ++- .../flywheel/impl/BackendManagerImpl.java | 5 +- .../VisualizationEventHandler.java | 14 +- .../manager/EntityVisualManager.java | 2 +- .../lib/instance/OrientedInstance.java | 9 +- .../flywheel/lib/instance/OrientedType.java | 17 +-- .../lib/instance/TransformedInstance.java | 42 +++-- .../flywheel/lib/math/MatrixUtil.java | 144 ++++++------------ .../flywheel/lib/transform/Rotate.java | 12 +- .../flywheel/lib/transform/Transform.java | 9 +- .../flywheel/lib/transform/Translate.java | 2 +- .../lib/uniform/FlwShaderUniforms.java | 6 +- .../jozufozu/flywheel/lib/util/FlwUtil.java | 4 +- .../flywheel/lib/util/LevelAttached.java | 6 +- .../lib/vertex/VertexTransformations.java | 5 +- .../lib/visual/AbstractEntityVisual.java | 4 +- .../flywheel/mixin/LevelRendererMixin.java | 2 +- .../mixin/matrix/Matrix3fAccessor.java | 36 ----- .../mixin/matrix/Matrix4fAccessor.java | 57 ------- .../flywheel/mixin/matrix/PoseStackMixin.java | 4 +- .../mixin/sodium/FlywheelCompatMixin.java | 24 --- .../jozufozu/flywheel/vanilla/BellVisual.java | 10 +- .../flywheel/vanilla/ChestVisual.java | 6 +- .../flywheel/vanilla/MinecartVisual.java | 3 +- .../flywheel/vanilla/ShulkerBoxVisual.java | 8 +- src/main/resources/flywheel.mixins.json | 2 - .../resources/flywheel.sodium.mixins.json | 3 +- 38 files changed, 194 insertions(+), 345 deletions(-) delete mode 100644 src/main/java/com/jozufozu/flywheel/mixin/matrix/Matrix3fAccessor.java delete mode 100644 src/main/java/com/jozufozu/flywheel/mixin/matrix/Matrix4fAccessor.java delete mode 100644 src/main/java/com/jozufozu/flywheel/mixin/sodium/FlywheelCompatMixin.java diff --git a/src/main/java/com/jozufozu/flywheel/Flywheel.java b/src/main/java/com/jozufozu/flywheel/Flywheel.java index 61eeb0132..b5f4d63f3 100644 --- a/src/main/java/com/jozufozu/flywheel/Flywheel.java +++ b/src/main/java/com/jozufozu/flywheel/Flywheel.java @@ -36,14 +36,12 @@ import com.jozufozu.flywheel.vanilla.VanillaVisuals; import com.mojang.logging.LogUtils; import net.minecraft.client.Minecraft; -import net.minecraft.commands.synchronization.ArgumentTypes; -import net.minecraft.commands.synchronization.EmptyArgumentSerializer; 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.common.MinecraftForge; -import net.minecraftforge.event.world.WorldEvent; +import net.minecraftforge.event.level.LevelEvent; import net.minecraftforge.eventbus.api.IEventBus; import net.minecraftforge.fml.DistExecutor; import net.minecraftforge.fml.IExtensionPoint; @@ -51,7 +49,6 @@ import net.minecraftforge.fml.ModLoadingContext; import net.minecraftforge.fml.common.Mod; import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent; import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext; -import net.minecraftforge.network.NetworkConstants; @Mod(Flywheel.ID) public class Flywheel { @@ -101,7 +98,7 @@ public class Flywheel { forgeEventBus.addListener(LightUpdater::onClientTick); forgeEventBus.addListener((ReloadRenderersEvent e) -> ModelCache.onReloadRenderers(e)); forgeEventBus.addListener(ModelHolder::onReloadRenderers); - forgeEventBus.addListener((WorldEvent.Unload e) -> LevelAttached.onUnloadLevel(e)); + forgeEventBus.addListener((LevelEvent.Unload e) -> LevelAttached.onUnloadLevel(e)); modEventBus.addListener(PartialModel::onModelRegistry); modEventBus.addListener(PartialModel::onModelBake); @@ -155,7 +152,7 @@ public class Flywheel { info.add("Origin: " + renderOrigin.getX() + ", " + renderOrigin.getY() + ", " + renderOrigin.getZ()); } - info.add("Memory Usage: CPU: " + StringUtil.formatBytes(FlwMemoryTracker.getCPUMemory()) + ", GPU: " + StringUtil.formatBytes(FlwMemoryTracker.getGPUMemory())); + info.add("Memory Usage: CPU: " + StringUtil.formatBytes(FlwMemoryTracker.getCPUMemory()) + ", GPU: " + StringUtil.formatBytes(FlwMemoryTracker.getGPUMemory())); } public static ArtifactVersion getVersion() { diff --git a/src/main/java/com/jozufozu/flywheel/api/event/RenderContext.java b/src/main/java/com/jozufozu/flywheel/api/event/RenderContext.java index 10a1491e1..a336d97be 100644 --- a/src/main/java/com/jozufozu/flywheel/api/event/RenderContext.java +++ b/src/main/java/com/jozufozu/flywheel/api/event/RenderContext.java @@ -1,7 +1,8 @@ package com.jozufozu.flywheel.api.event; +import org.joml.Matrix4f; + import com.mojang.blaze3d.vertex.PoseStack; -import com.mojang.math.Matrix4f; import net.minecraft.client.Camera; import net.minecraft.client.multiplayer.ClientLevel; @@ -11,8 +12,9 @@ import net.minecraft.client.renderer.RenderBuffers; public record RenderContext(LevelRenderer renderer, ClientLevel level, RenderBuffers buffers, PoseStack stack, Matrix4f projection, Matrix4f viewProjection, Camera camera, float partialTick) { public static RenderContext create(LevelRenderer renderer, ClientLevel level, RenderBuffers buffers, PoseStack stack, Matrix4f projection, Camera camera, float partialTick) { - Matrix4f viewProjection = projection.copy(); - viewProjection.multiply(stack.last().pose()); + Matrix4f viewProjection = new Matrix4f(projection); + viewProjection.mul(stack.last() + .pose()); return new RenderContext(renderer, level, buffers, stack, projection, viewProjection, camera, partialTick); } diff --git a/src/main/java/com/jozufozu/flywheel/api/event/RenderStageEvent.java b/src/main/java/com/jozufozu/flywheel/api/event/RenderStageEvent.java index 8c4040737..0f7a50222 100644 --- a/src/main/java/com/jozufozu/flywheel/api/event/RenderStageEvent.java +++ b/src/main/java/com/jozufozu/flywheel/api/event/RenderStageEvent.java @@ -1,7 +1,8 @@ package com.jozufozu.flywheel.api.event; +import org.joml.Matrix4f; + import com.mojang.blaze3d.vertex.PoseStack; -import com.mojang.math.Matrix4f; import net.minecraft.client.Camera; import net.minecraft.client.multiplayer.ClientLevel; diff --git a/src/main/java/com/jozufozu/flywheel/api/visualization/VisualizationManager.java b/src/main/java/com/jozufozu/flywheel/api/visualization/VisualizationManager.java index 8463949ee..ab42306ff 100644 --- a/src/main/java/com/jozufozu/flywheel/api/visualization/VisualizationManager.java +++ b/src/main/java/com/jozufozu/flywheel/api/visualization/VisualizationManager.java @@ -27,7 +27,7 @@ public interface VisualizationManager { } /** - * Call this when you want to run {@link Visual#update()}. + * Call this when you want to run {@link Visual#update}. * @param blockEntity The block entity whose visual you want to update. */ static void queueUpdate(BlockEntity blockEntity) { @@ -41,11 +41,11 @@ public interface VisualizationManager { } /** - * Call this when you want to run {@link Visual#update()}. + * Call this when you want to run {@link Visual#update}. * @param entity The entity whose visual you want to update. */ static void queueUpdate(Entity entity) { - Level level = entity.level; + Level level = entity.level(); VisualizationManager manager = get(level); if (manager == null) { return; @@ -55,7 +55,7 @@ public interface VisualizationManager { } /** - * Call this when you want to run {@link Visual#update()}. + * Call this when you want to run {@link Visual#update}. * @param effect The effect whose visual you want to update. */ static void queueUpdate(LevelAccessor level, Effect effect) { diff --git a/src/main/java/com/jozufozu/flywheel/backend/Backends.java b/src/main/java/com/jozufozu/flywheel/backend/Backends.java index f19af77c0..49d2281e0 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/Backends.java +++ b/src/main/java/com/jozufozu/flywheel/backend/Backends.java @@ -1,5 +1,6 @@ package com.jozufozu.flywheel.backend; + import com.jozufozu.flywheel.Flywheel; import com.jozufozu.flywheel.api.backend.Backend; import com.jozufozu.flywheel.backend.compile.IndirectPrograms; @@ -13,14 +14,15 @@ import com.jozufozu.flywheel.lib.context.Contexts; import com.jozufozu.flywheel.lib.util.ShadersModHandler; import net.minecraft.ChatFormatting; -import net.minecraft.network.chat.TextComponent; +import net.minecraft.network.chat.Component; public class Backends { /** * Use a thread pool to buffer instances in parallel on the CPU. */ public static final Backend BATCHING = SimpleBackend.builder() - .engineMessage(new TextComponent("Using Batching Engine").withStyle(ChatFormatting.GREEN)) + .engineMessage(Component.literal("Using Batching Engine") + .withStyle(ChatFormatting.GREEN)) .engineFactory(level -> new BatchingEngine(256)) .supported(() -> !ShadersModHandler.isShaderPackInUse()) .register(Flywheel.rl("batching")); @@ -29,7 +31,8 @@ public class Backends { * Use GPU instancing to render everything. */ public static final Backend INSTANCING = SimpleBackend.builder() - .engineMessage(new TextComponent("Using Instancing Engine").withStyle(ChatFormatting.GREEN)) + .engineMessage(Component.literal("Using Instancing Engine") + .withStyle(ChatFormatting.GREEN)) .engineFactory(level -> new InstancingEngine(256, Contexts.WORLD)) .fallback(() -> Backends.BATCHING) .supported(() -> !ShadersModHandler.isShaderPackInUse() && GlCompat.supportsInstancing() && InstancingPrograms.allLoaded()) @@ -39,7 +42,8 @@ public class Backends { * Use Compute shaders to cull instances. */ public static final Backend INDIRECT = SimpleBackend.builder() - .engineMessage(new TextComponent("Using Indirect Engine").withStyle(ChatFormatting.GREEN)) + .engineMessage(Component.literal("Using Indirect Engine") + .withStyle(ChatFormatting.GREEN)) .engineFactory(level -> new IndirectEngine(256)) .fallback(() -> Backends.INSTANCING) .supported(() -> !ShadersModHandler.isShaderPackInUse() && GlCompat.supportsIndirect() && IndirectPrograms.allLoaded()) diff --git a/src/main/java/com/jozufozu/flywheel/backend/engine/AbstractEngine.java b/src/main/java/com/jozufozu/flywheel/backend/engine/AbstractEngine.java index 34df84ef5..404fe524d 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/engine/AbstractEngine.java +++ b/src/main/java/com/jozufozu/flywheel/backend/engine/AbstractEngine.java @@ -27,7 +27,7 @@ public abstract class AbstractEngine implements Engine { return false; } - renderOrigin = new BlockPos(cameraPos); + renderOrigin = BlockPos.containing(cameraPos); onRenderOriginChanged(); return true; } diff --git a/src/main/java/com/jozufozu/flywheel/backend/engine/batching/BatchedDrawTracker.java b/src/main/java/com/jozufozu/flywheel/backend/engine/batching/BatchedDrawTracker.java index 7e4e03517..31b4d1535 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/engine/batching/BatchedDrawTracker.java +++ b/src/main/java/com/jozufozu/flywheel/backend/engine/batching/BatchedDrawTracker.java @@ -71,7 +71,9 @@ public class BatchedDrawTracker { if (buffer.hasVertices()) { BufferBuilderExtension scratch = (BufferBuilderExtension) this.scratch; buffer.inject(scratch); - buffer.getRenderType().end(this.scratch, 0, 0, 0); + // FIXME: Maybe we shouldn't pass null. + buffer.getRenderType() + .end(this.scratch, null); } buffer.reset(); } diff --git a/src/main/java/com/jozufozu/flywheel/backend/engine/batching/TransformCall.java b/src/main/java/com/jozufozu/flywheel/backend/engine/batching/TransformCall.java index d014514b5..14f454321 100644 --- a/src/main/java/com/jozufozu/flywheel/backend/engine/batching/TransformCall.java +++ b/src/main/java/com/jozufozu/flywheel/backend/engine/batching/TransformCall.java @@ -3,6 +3,8 @@ package com.jozufozu.flywheel.backend.engine.batching; import java.util.concurrent.atomic.AtomicInteger; import org.joml.FrustumIntersection; +import org.joml.Matrix3f; +import org.joml.Matrix4f; import org.joml.Vector4f; import org.joml.Vector4fc; @@ -17,8 +19,6 @@ import com.jozufozu.flywheel.api.vertex.ReusableVertexList; import com.jozufozu.flywheel.lib.task.ForEachSlicePlan; import com.jozufozu.flywheel.lib.vertex.VertexTransformations; import com.mojang.blaze3d.vertex.PoseStack; -import com.mojang.math.Matrix3f; -import com.mojang.math.Matrix4f; import net.minecraft.client.multiplayer.ClientLevel; diff --git a/src/main/java/com/jozufozu/flywheel/config/BackendArgument.java b/src/main/java/com/jozufozu/flywheel/config/BackendArgument.java index 35e783735..3be4a1b35 100644 --- a/src/main/java/com/jozufozu/flywheel/config/BackendArgument.java +++ b/src/main/java/com/jozufozu/flywheel/config/BackendArgument.java @@ -14,14 +14,14 @@ import com.mojang.brigadier.suggestion.Suggestions; import com.mojang.brigadier.suggestion.SuggestionsBuilder; import net.minecraft.commands.SharedSuggestionProvider; -import net.minecraft.network.chat.TextComponent; +import net.minecraft.network.chat.Component; import net.minecraft.resources.ResourceLocation; public class BackendArgument implements ArgumentType { private static final List STRING_IDS = Backend.REGISTRY.getAllIds().stream().map(ResourceLocation::toString).toList(); public static final DynamicCommandExceptionType ERROR_UNKNOWN_BACKEND = new DynamicCommandExceptionType(arg -> { - return new TextComponent("Unknown backend '" + arg + "'"); + return Component.literal("Unknown backend '" + arg + "'"); }); public static final BackendArgument INSTANCE = new BackendArgument(); diff --git a/src/main/java/com/jozufozu/flywheel/config/FlwCommands.java b/src/main/java/com/jozufozu/flywheel/config/FlwCommands.java index c166a3649..0318068fc 100644 --- a/src/main/java/com/jozufozu/flywheel/config/FlwCommands.java +++ b/src/main/java/com/jozufozu/flywheel/config/FlwCommands.java @@ -19,7 +19,6 @@ import net.minecraft.commands.arguments.coordinates.BlockPosArgument; import net.minecraft.core.BlockPos; import net.minecraft.network.chat.Component; import net.minecraft.network.chat.MutableComponent; -import net.minecraft.network.chat.TextComponent; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.entity.Entity; import net.minecraftforge.client.event.RegisterClientCommandsEvent; @@ -42,13 +41,13 @@ public class FlwCommands { try { backendId = new ResourceLocation(backendIdStr); } catch (ResourceLocationException e) { - player.displayClientMessage(new TextComponent("Config contains invalid backend ID '" + backendIdStr + "'!"), false); + player.displayClientMessage(Component.literal("Config contains invalid backend ID '" + backendIdStr + "'!"), false); return 0; } Backend backend = Backend.REGISTRY.get(backendId); if (backend == null) { - player.displayClientMessage(new TextComponent("Config contains non-existent backend with ID '" + backendId + "'!"), false); + player.displayClientMessage(Component.literal("Config contains non-existent backend with ID '" + backendId + "'!"), false); return 0; } @@ -71,7 +70,8 @@ public class FlwCommands { var actualBackend = BackendManager.getBackend(); if (actualBackend != requestedBackend) { - player.displayClientMessage(new TextComponent("'" + requestedId + "' not available").withStyle(ChatFormatting.RED), false); + player.displayClientMessage(Component.literal("'" + requestedId + "' not available") + .withStyle(ChatFormatting.RED), false); } Component message = actualBackend.engineMessage(); @@ -85,14 +85,16 @@ public class FlwCommands { LocalPlayer player = Minecraft.getInstance().player; if (player == null) return; - Component text = new TextComponent("Update limiting is currently: ").append(boolToText(bool)); + Component text = Component.literal("Update limiting is currently: ") + .append(boolToText(bool)); player.displayClientMessage(text, false); }, (source, bool) -> { LocalPlayer player = Minecraft.getInstance().player; if (player == null) return; - Component text = boolToText(bool).append(new TextComponent(" update limiting.").withStyle(ChatFormatting.WHITE)); + Component text = boolToText(bool).append(Component.literal(" update limiting.") + .withStyle(ChatFormatting.WHITE)); player.displayClientMessage(text, false); Minecraft.getInstance().levelRenderer.allChanged(); @@ -105,7 +107,7 @@ public class FlwCommands { LocalPlayer player = Minecraft.getInstance().player; if (player == null) return 0; - player.displayClientMessage(new TextComponent("This command is not yet implemented."), false); + player.displayClientMessage(Component.literal("This command is not yet implemented."), false); return Command.SINGLE_SUCCESS; }); @@ -124,7 +126,8 @@ public class FlwCommands { return 0; } - executor.level.destroyBlockProgress(executor.getId(), pos, value); + executor.level() + .destroyBlockProgress(executor.getId(), pos, value); return Command.SINGLE_SUCCESS; })))); @@ -176,6 +179,8 @@ public class FlwCommands { } public static MutableComponent boolToText(boolean b) { - return b ? new TextComponent("enabled").withStyle(ChatFormatting.DARK_GREEN) : new TextComponent("disabled").withStyle(ChatFormatting.RED); + return b ? Component.literal("enabled") + .withStyle(ChatFormatting.DARK_GREEN) : Component.literal("disabled") + .withStyle(ChatFormatting.RED); } } diff --git a/src/main/java/com/jozufozu/flywheel/glsl/LoadError.java b/src/main/java/com/jozufozu/flywheel/glsl/LoadError.java index 84d5f7f62..111b91cdd 100644 --- a/src/main/java/com/jozufozu/flywheel/glsl/LoadError.java +++ b/src/main/java/com/jozufozu/flywheel/glsl/LoadError.java @@ -63,6 +63,14 @@ sealed public interface LoadError { } } + record ResourceError(ResourceLocation location) implements LoadError { + @Override + public ErrorBuilder generateMessage() { + return ErrorBuilder.create() + .error("\"" + location + "\" was not found"); + } + } + record MalformedInclude(ResourceLocationException exception) implements LoadError { @Override public ErrorBuilder generateMessage() { diff --git a/src/main/java/com/jozufozu/flywheel/glsl/ShaderSources.java b/src/main/java/com/jozufozu/flywheel/glsl/ShaderSources.java index 2f918a9b0..99561f190 100644 --- a/src/main/java/com/jozufozu/flywheel/glsl/ShaderSources.java +++ b/src/main/java/com/jozufozu/flywheel/glsl/ShaderSources.java @@ -15,7 +15,6 @@ import org.jetbrains.annotations.VisibleForTesting; import com.jozufozu.flywheel.lib.util.ResourceUtil; import net.minecraft.resources.ResourceLocation; -import net.minecraft.server.packs.resources.Resource; import net.minecraft.server.packs.resources.ResourceManager; /** @@ -68,12 +67,15 @@ public class ShaderSources { @NotNull protected LoadResult load(ResourceLocation loc) { - try (Resource resource = manager.getResource(ResourceUtil.prefixed(SHADER_DIR, loc))) { - InputStream stream = resource.getInputStream(); - String sourceString = new String(stream.readAllBytes(), StandardCharsets.UTF_8); - return SourceFile.parse(this, loc, sourceString); - } catch (IOException e) { - return new LoadResult.Failure(new LoadError.IOError(loc, e)); - } + return manager.getResource(ResourceUtil.prefixed(SHADER_DIR, loc)) + .map(resource -> { + try (InputStream stream = resource.open()) { + String sourceString = new String(stream.readAllBytes(), StandardCharsets.UTF_8); + return SourceFile.parse(this, loc, sourceString); + } catch (IOException e) { + return new LoadResult.Failure(new LoadError.IOError(loc, e)); + } + }) + .orElseGet(() -> new LoadResult.Failure(new LoadError.ResourceError(loc))); } } diff --git a/src/main/java/com/jozufozu/flywheel/impl/BackendManagerImpl.java b/src/main/java/com/jozufozu/flywheel/impl/BackendManagerImpl.java index e0d4202f8..bc67ece63 100644 --- a/src/main/java/com/jozufozu/flywheel/impl/BackendManagerImpl.java +++ b/src/main/java/com/jozufozu/flywheel/impl/BackendManagerImpl.java @@ -14,7 +14,7 @@ import com.mojang.logging.LogUtils; import net.minecraft.ChatFormatting; import net.minecraft.client.multiplayer.ClientLevel; -import net.minecraft.network.chat.TextComponent; +import net.minecraft.network.chat.Component; import net.minecraft.resources.ResourceLocation; import net.minecraftforge.fml.CrashReportCallables; @@ -22,7 +22,8 @@ public final class BackendManagerImpl { private static final Logger LOGGER = LogUtils.getLogger(); private static final Backend OFF_BACKEND = SimpleBackend.builder() - .engineMessage(new TextComponent("Disabled Flywheel").withStyle(ChatFormatting.RED)) + .engineMessage(Component.literal("Disabled Flywheel") + .withStyle(ChatFormatting.RED)) .engineFactory(level -> { throw new UnsupportedOperationException("Cannot create engine when backend is off."); }) diff --git a/src/main/java/com/jozufozu/flywheel/impl/visualization/VisualizationEventHandler.java b/src/main/java/com/jozufozu/flywheel/impl/visualization/VisualizationEventHandler.java index 64a89b977..846b3b822 100644 --- a/src/main/java/com/jozufozu/flywheel/impl/visualization/VisualizationEventHandler.java +++ b/src/main/java/com/jozufozu/flywheel/impl/visualization/VisualizationEventHandler.java @@ -10,8 +10,8 @@ import net.minecraft.client.multiplayer.ClientLevel; import net.minecraft.world.entity.Entity; import net.minecraft.world.level.Level; import net.minecraftforge.event.TickEvent; -import net.minecraftforge.event.entity.EntityJoinWorldEvent; -import net.minecraftforge.event.entity.EntityLeaveWorldEvent; +import net.minecraftforge.event.entity.EntityJoinLevelEvent; +import net.minecraftforge.event.entity.EntityLeaveLevelEvent; public final class VisualizationEventHandler { private VisualizationEventHandler() { @@ -32,7 +32,7 @@ public final class VisualizationEventHandler { return; } - Level level = cameraEntity.level; + Level level = cameraEntity.level(); VisualizationManagerImpl manager = VisualizationManagerImpl.get(level); if (manager == null) { return; @@ -65,8 +65,8 @@ public final class VisualizationEventHandler { manager.renderStage(event.getContext(), event.getStage()); } - public static void onEntityJoinWorld(EntityJoinWorldEvent event) { - Level level = event.getWorld(); + public static void onEntityJoinWorld(EntityJoinLevelEvent event) { + Level level = event.getLevel(); VisualizationManager manager = VisualizationManager.get(level); if (manager == null) { return; @@ -75,8 +75,8 @@ public final class VisualizationEventHandler { manager.getEntities().queueAdd(event.getEntity()); } - public static void onEntityLeaveWorld(EntityLeaveWorldEvent event) { - Level level = event.getWorld(); + public static void onEntityLeaveWorld(EntityLeaveLevelEvent event) { + Level level = event.getLevel(); VisualizationManager manager = VisualizationManager.get(level); if (manager == null) { return; diff --git a/src/main/java/com/jozufozu/flywheel/impl/visualization/manager/EntityVisualManager.java b/src/main/java/com/jozufozu/flywheel/impl/visualization/manager/EntityVisualManager.java index f4b33bb4d..b12c9baf8 100644 --- a/src/main/java/com/jozufozu/flywheel/impl/visualization/manager/EntityVisualManager.java +++ b/src/main/java/com/jozufozu/flywheel/impl/visualization/manager/EntityVisualManager.java @@ -49,7 +49,7 @@ public class EntityVisualManager extends AbstractVisualManager { return false; } - Level level = entity.level; + Level level = entity.level(); return level != null; } } diff --git a/src/main/java/com/jozufozu/flywheel/lib/instance/OrientedInstance.java b/src/main/java/com/jozufozu/flywheel/lib/instance/OrientedInstance.java index aba40c003..36e1d231a 100644 --- a/src/main/java/com/jozufozu/flywheel/lib/instance/OrientedInstance.java +++ b/src/main/java/com/jozufozu/flywheel/lib/instance/OrientedInstance.java @@ -1,9 +1,10 @@ package com.jozufozu.flywheel.lib.instance; +import org.joml.Quaternionf; +import org.joml.Vector3f; + import com.jozufozu.flywheel.api.instance.InstanceHandle; import com.jozufozu.flywheel.api.instance.InstanceType; -import com.mojang.math.Quaternion; -import com.mojang.math.Vector3f; import net.minecraft.core.BlockPos; @@ -63,8 +64,8 @@ public class OrientedInstance extends ColoredLitInstance { return this; } - public OrientedInstance setRotation(Quaternion q) { - return setRotation(q.i(), q.j(), q.k(), q.r()); + public OrientedInstance setRotation(Quaternionf q) { + return setRotation(q.x, q.y, q.z, q.w); } public OrientedInstance setRotation(float x, float y, float z, float w) { diff --git a/src/main/java/com/jozufozu/flywheel/lib/instance/OrientedType.java b/src/main/java/com/jozufozu/flywheel/lib/instance/OrientedType.java index 7a97743bf..b0b0d92ec 100644 --- a/src/main/java/com/jozufozu/flywheel/lib/instance/OrientedType.java +++ b/src/main/java/com/jozufozu/flywheel/lib/instance/OrientedType.java @@ -1,5 +1,7 @@ package com.jozufozu.flywheel.lib.instance; +import org.joml.Matrix3f; +import org.joml.Matrix4f; import org.joml.Quaternionf; import com.jozufozu.flywheel.api.instance.InstanceBoundingSphereTransformer; @@ -11,9 +13,6 @@ import com.jozufozu.flywheel.api.layout.BufferLayout; import com.jozufozu.flywheel.lib.layout.CommonItems; import com.jozufozu.flywheel.lib.math.RenderMath; import com.jozufozu.flywheel.lib.vertex.VertexTransformations; -import com.mojang.math.Matrix3f; -import com.mojang.math.Matrix4f; -import com.mojang.math.Quaternion; import net.minecraft.resources.ResourceLocation; @@ -49,15 +48,15 @@ public class OrientedType implements InstanceType { @Override public InstanceVertexTransformer getVertexTransformer() { return (vertexList, instance) -> { - Quaternion q = new Quaternion(instance.qX, instance.qY, instance.qZ, instance.qW); + Quaternionf q = new Quaternionf(instance.qX, instance.qY, instance.qZ, instance.qW); Matrix4f modelMatrix = new Matrix4f(); - modelMatrix.setIdentity(); - modelMatrix.multiplyWithTranslation(instance.posX + instance.pivotX, instance.posY + instance.pivotY, instance.posZ + instance.pivotZ); - modelMatrix.multiply(q); - modelMatrix.multiplyWithTranslation(-instance.pivotX, -instance.pivotY, -instance.pivotZ); + modelMatrix.translate(instance.posX + instance.pivotX, instance.posY + instance.pivotY, instance.posZ + instance.pivotZ); + modelMatrix.rotate(q); + modelMatrix.translate(-instance.pivotX, -instance.pivotY, -instance.pivotZ); - Matrix3f normalMatrix = new Matrix3f(q); + Matrix3f normalMatrix = new Matrix3f(); + normalMatrix.set(q); float r = RenderMath.uf(instance.r); float g = RenderMath.uf(instance.g); diff --git a/src/main/java/com/jozufozu/flywheel/lib/instance/TransformedInstance.java b/src/main/java/com/jozufozu/flywheel/lib/instance/TransformedInstance.java index 4d33c0f12..a1f3fd57e 100644 --- a/src/main/java/com/jozufozu/flywheel/lib/instance/TransformedInstance.java +++ b/src/main/java/com/jozufozu/flywheel/lib/instance/TransformedInstance.java @@ -1,12 +1,13 @@ package com.jozufozu.flywheel.lib.instance; +import org.joml.Matrix3f; +import org.joml.Matrix4f; +import org.joml.Quaternionf; + import com.jozufozu.flywheel.api.instance.InstanceHandle; import com.jozufozu.flywheel.api.instance.InstanceType; import com.jozufozu.flywheel.lib.transform.Transform; import com.mojang.blaze3d.vertex.PoseStack; -import com.mojang.math.Matrix3f; -import com.mojang.math.Matrix4f; -import com.mojang.math.Quaternion; import net.minecraft.util.Mth; @@ -17,11 +18,6 @@ public class TransformedInstance extends ColoredLitInstance implements Transform public final Matrix4f model = new Matrix4f(); public final Matrix3f normal = new Matrix3f(); - { - model.setIdentity(); - normal.setIdentity(); - } - public TransformedInstance(InstanceType type, InstanceHandle handle) { super(type, handle); } @@ -29,9 +25,9 @@ public class TransformedInstance extends ColoredLitInstance implements Transform public TransformedInstance setTransform(PoseStack stack) { setChanged(); - this.model.load(stack.last() + this.model.set(stack.last() .pose()); - this.normal.load(stack.last() + this.normal.set(stack.last() .normal()); return this; } @@ -46,25 +42,25 @@ public class TransformedInstance extends ColoredLitInstance implements Transform public TransformedInstance setEmptyTransform() { setChanged(); - model.load(ZERO_MATRIX_4f); - normal.load(ZERO_MATRIX_3f); + model.set(ZERO_MATRIX_4f); + normal.set(ZERO_MATRIX_3f); return this; } public TransformedInstance loadIdentity() { setChanged(); - model.setIdentity(); - normal.setIdentity(); + model.identity(); + normal.identity(); return this; } @Override - public TransformedInstance multiply(Quaternion quaternion) { + public TransformedInstance multiply(Quaternionf quaternion) { setChanged(); - model.multiply(quaternion); - normal.mul(quaternion); + model.rotate(quaternion); + normal.rotate(quaternion); return this; } @@ -72,11 +68,11 @@ public class TransformedInstance extends ColoredLitInstance implements Transform public TransformedInstance scale(float x, float y, float z) { setChanged(); - model.multiply(Matrix4f.createScaleMatrix(x, y, z)); + model.scale(x, y, z); if (x == y && y == z) { if (x < 0.0f) { - normal.mul(-1.0f); + normal.scale(-1.0f); } return this; @@ -86,7 +82,7 @@ public class TransformedInstance extends ColoredLitInstance implements Transform float invY = 1.0f / y; float invZ = 1.0f / z; float f = Mth.fastInvCubeRoot(Math.abs(invX * invY * invZ)); - normal.mul(Matrix3f.createScaleMatrix(f * invX, f * invY, f * invZ)); + normal.scale(f * invX, f * invY, f * invZ); return this; } @@ -94,7 +90,7 @@ public class TransformedInstance extends ColoredLitInstance implements Transform public TransformedInstance translate(double x, double y, double z) { setChanged(); - model.multiplyWithTranslation((float) x, (float) y, (float) z); + model.translate((float) x, (float) y, (float) z); return this; } @@ -102,7 +98,7 @@ public class TransformedInstance extends ColoredLitInstance implements Transform public TransformedInstance mulPose(Matrix4f pose) { setChanged(); - model.multiply(pose); + this.model.mul(pose); return this; } @@ -110,7 +106,7 @@ public class TransformedInstance extends ColoredLitInstance implements Transform public TransformedInstance mulNormal(Matrix3f normal) { setChanged(); - normal.mul(normal); + this.normal.mul(normal); return this; } } diff --git a/src/main/java/com/jozufozu/flywheel/lib/math/MatrixUtil.java b/src/main/java/com/jozufozu/flywheel/lib/math/MatrixUtil.java index 7f495936e..bf22e9a96 100644 --- a/src/main/java/com/jozufozu/flywheel/lib/math/MatrixUtil.java +++ b/src/main/java/com/jozufozu/flywheel/lib/math/MatrixUtil.java @@ -5,139 +5,88 @@ import static org.joml.Math.fma; import java.nio.ByteBuffer; import org.joml.Math; +import org.joml.Matrix3f; +import org.joml.Matrix4f; import org.lwjgl.system.MemoryUtil; -import com.jozufozu.flywheel.mixin.matrix.Matrix3fAccessor; -import com.jozufozu.flywheel.mixin.matrix.Matrix4fAccessor; -import com.mojang.math.Matrix3f; -import com.mojang.math.Matrix4f; - public final class MatrixUtil { public static float transformPositionX(Matrix4f matrix, float x, float y, float z) { - Matrix4fAccessor m = (Matrix4fAccessor) (Object) matrix; - return fma(m.flywheel$m00(), x, fma(m.flywheel$m01(), y, fma(m.flywheel$m02(), z, m.flywheel$m03()))); + return fma(matrix.m00(), x, fma(matrix.m01(), y, fma(matrix.m02(), z, matrix.m03()))); } public static float transformPositionY(Matrix4f matrix, float x, float y, float z) { - Matrix4fAccessor m = (Matrix4fAccessor) (Object) matrix; - return fma(m.flywheel$m10(), x, fma(m.flywheel$m11(), y, fma(m.flywheel$m12(), z, m.flywheel$m13()))); + return fma(matrix.m10(), x, fma(matrix.m11(), y, fma(matrix.m12(), z, matrix.m13()))); } public static float transformPositionZ(Matrix4f matrix, float x, float y, float z) { - Matrix4fAccessor m = (Matrix4fAccessor) (Object) matrix; - return fma(m.flywheel$m20(), x, fma(m.flywheel$m21(), y, fma(m.flywheel$m22(), z, m.flywheel$m23()))); + return fma(matrix.m20(), x, fma(matrix.m21(), y, fma(matrix.m22(), z, matrix.m23()))); } public static float transformNormalX(Matrix3f matrix, float x, float y, float z) { - Matrix3fAccessor m = (Matrix3fAccessor) (Object) matrix; - return fma(m.flywheel$m00(), x, fma(m.flywheel$m01(), y, m.flywheel$m02() * z)); + return fma(matrix.m00(), x, fma(matrix.m01(), y, matrix.m02() * z)); } public static float transformNormalY(Matrix3f matrix, float x, float y, float z) { - Matrix3fAccessor m = (Matrix3fAccessor) (Object) matrix; - return fma(m.flywheel$m10(), x, fma(m.flywheel$m11(), y, m.flywheel$m12() * z)); + return fma(matrix.m10(), x, fma(matrix.m11(), y, matrix.m12() * z)); } public static float transformNormalZ(Matrix3f matrix, float x, float y, float z) { - Matrix3fAccessor m = (Matrix3fAccessor) (Object) matrix; - return fma(m.flywheel$m20(), x, fma(m.flywheel$m21(), y, m.flywheel$m22() * z)); + return fma(matrix.m20(), x, fma(matrix.m21(), y, matrix.m22() * z)); } public static void write(Matrix4f matrix, ByteBuffer buf) { - Matrix4fAccessor m = (Matrix4fAccessor) (Object) matrix; - buf.putFloat(m.flywheel$m00()); - buf.putFloat(m.flywheel$m10()); - buf.putFloat(m.flywheel$m20()); - buf.putFloat(m.flywheel$m30()); - buf.putFloat(m.flywheel$m01()); - buf.putFloat(m.flywheel$m11()); - buf.putFloat(m.flywheel$m21()); - buf.putFloat(m.flywheel$m31()); - buf.putFloat(m.flywheel$m02()); - buf.putFloat(m.flywheel$m12()); - buf.putFloat(m.flywheel$m22()); - buf.putFloat(m.flywheel$m32()); - buf.putFloat(m.flywheel$m03()); - buf.putFloat(m.flywheel$m13()); - buf.putFloat(m.flywheel$m23()); - buf.putFloat(m.flywheel$m33()); + matrix.get(buf); } public static void writeUnsafe(Matrix4f matrix, long ptr) { - Matrix4fAccessor m = (Matrix4fAccessor) (Object) matrix; - MemoryUtil.memPutFloat(ptr, m.flywheel$m00()); - MemoryUtil.memPutFloat(ptr + 4, m.flywheel$m10()); - MemoryUtil.memPutFloat(ptr + 8, m.flywheel$m20()); - MemoryUtil.memPutFloat(ptr + 12, m.flywheel$m30()); - MemoryUtil.memPutFloat(ptr + 16, m.flywheel$m01()); - MemoryUtil.memPutFloat(ptr + 20, m.flywheel$m11()); - MemoryUtil.memPutFloat(ptr + 24, m.flywheel$m21()); - MemoryUtil.memPutFloat(ptr + 28, m.flywheel$m31()); - MemoryUtil.memPutFloat(ptr + 32, m.flywheel$m02()); - MemoryUtil.memPutFloat(ptr + 36, m.flywheel$m12()); - MemoryUtil.memPutFloat(ptr + 40, m.flywheel$m22()); - MemoryUtil.memPutFloat(ptr + 44, m.flywheel$m32()); - MemoryUtil.memPutFloat(ptr + 48, m.flywheel$m03()); - MemoryUtil.memPutFloat(ptr + 52, m.flywheel$m13()); - MemoryUtil.memPutFloat(ptr + 56, m.flywheel$m23()); - MemoryUtil.memPutFloat(ptr + 60, m.flywheel$m33()); + MemoryUtil.memPutFloat(ptr, matrix.m00()); + MemoryUtil.memPutFloat(ptr + 4, matrix.m10()); + MemoryUtil.memPutFloat(ptr + 8, matrix.m20()); + MemoryUtil.memPutFloat(ptr + 12, matrix.m30()); + MemoryUtil.memPutFloat(ptr + 16, matrix.m01()); + MemoryUtil.memPutFloat(ptr + 20, matrix.m11()); + MemoryUtil.memPutFloat(ptr + 24, matrix.m21()); + MemoryUtil.memPutFloat(ptr + 28, matrix.m31()); + MemoryUtil.memPutFloat(ptr + 32, matrix.m02()); + MemoryUtil.memPutFloat(ptr + 36, matrix.m12()); + MemoryUtil.memPutFloat(ptr + 40, matrix.m22()); + MemoryUtil.memPutFloat(ptr + 44, matrix.m32()); + MemoryUtil.memPutFloat(ptr + 48, matrix.m03()); + MemoryUtil.memPutFloat(ptr + 52, matrix.m13()); + MemoryUtil.memPutFloat(ptr + 56, matrix.m23()); + MemoryUtil.memPutFloat(ptr + 60, matrix.m33()); } public static void write(Matrix3f matrix, ByteBuffer buf) { - Matrix3fAccessor m = (Matrix3fAccessor) (Object) matrix; - buf.putFloat(m.flywheel$m00()); - buf.putFloat(m.flywheel$m10()); - buf.putFloat(m.flywheel$m20()); - buf.putFloat(m.flywheel$m01()); - buf.putFloat(m.flywheel$m11()); - buf.putFloat(m.flywheel$m21()); - buf.putFloat(m.flywheel$m02()); - buf.putFloat(m.flywheel$m12()); - buf.putFloat(m.flywheel$m22()); + matrix.get(buf); } public static void writeUnsafe(Matrix3f matrix, long ptr) { - Matrix3fAccessor m = (Matrix3fAccessor) (Object) matrix; - MemoryUtil.memPutFloat(ptr, m.flywheel$m00()); - MemoryUtil.memPutFloat(ptr + 4, m.flywheel$m10()); - MemoryUtil.memPutFloat(ptr + 8, m.flywheel$m20()); - MemoryUtil.memPutFloat(ptr + 12, m.flywheel$m01()); - MemoryUtil.memPutFloat(ptr + 16, m.flywheel$m11()); - MemoryUtil.memPutFloat(ptr + 20, m.flywheel$m21()); - MemoryUtil.memPutFloat(ptr + 24, m.flywheel$m02()); - MemoryUtil.memPutFloat(ptr + 28, m.flywheel$m12()); - MemoryUtil.memPutFloat(ptr + 32, m.flywheel$m22()); + MemoryUtil.memPutFloat(ptr, matrix.m00()); + MemoryUtil.memPutFloat(ptr + 4, matrix.m10()); + MemoryUtil.memPutFloat(ptr + 8, matrix.m20()); + MemoryUtil.memPutFloat(ptr + 12, matrix.m01()); + MemoryUtil.memPutFloat(ptr + 16, matrix.m11()); + MemoryUtil.memPutFloat(ptr + 20, matrix.m21()); + MemoryUtil.memPutFloat(ptr + 24, matrix.m02()); + MemoryUtil.memPutFloat(ptr + 28, matrix.m12()); + MemoryUtil.memPutFloat(ptr + 32, matrix.m22()); } - public static void store(Matrix4f matrix, org.joml.Matrix4f jomlMatrix) { - Matrix4fAccessor m = (Matrix4fAccessor) (Object) matrix; - jomlMatrix.set( - m.flywheel$m00(), m.flywheel$m10(), m.flywheel$m20(), m.flywheel$m30(), - m.flywheel$m01(), m.flywheel$m11(), m.flywheel$m21(), m.flywheel$m31(), - m.flywheel$m02(), m.flywheel$m12(), m.flywheel$m22(), m.flywheel$m32(), - m.flywheel$m03(), m.flywheel$m13(), m.flywheel$m23(), m.flywheel$m33() - ); + public static void store(Matrix4f matrix, Matrix4f jomlMatrix) { + jomlMatrix.set(matrix); } - public static org.joml.Matrix4f toJoml(Matrix4f matrix) { - Matrix4fAccessor m = (Matrix4fAccessor) (Object) matrix; - return new org.joml.Matrix4f( - m.flywheel$m00(), m.flywheel$m10(), m.flywheel$m20(), m.flywheel$m30(), - m.flywheel$m01(), m.flywheel$m11(), m.flywheel$m21(), m.flywheel$m31(), - m.flywheel$m02(), m.flywheel$m12(), m.flywheel$m22(), m.flywheel$m32(), - m.flywheel$m03(), m.flywheel$m13(), m.flywheel$m23(), m.flywheel$m33() - ); + public static Matrix4f toJoml(Matrix4f matrix) { + return new Matrix4f(matrix); } public static void store(Matrix3f matrix, org.joml.Matrix3f jomlMatrix) { - Matrix3fAccessor m = (Matrix3fAccessor) (Object) matrix; - jomlMatrix.set( - m.flywheel$m00(), m.flywheel$m10(), m.flywheel$m20(), m.flywheel$m01(), m.flywheel$m11(), m.flywheel$m21(), m.flywheel$m02(), m.flywheel$m12(), m.flywheel$m22()); + jomlMatrix.set(matrix); } - public static org.joml.Matrix3f toJoml(Matrix3f matrix) { - Matrix3fAccessor m = (Matrix3fAccessor) (Object) matrix; - return new org.joml.Matrix3f(m.flywheel$m00(), m.flywheel$m10(), m.flywheel$m20(), m.flywheel$m01(), m.flywheel$m11(), m.flywheel$m21(), m.flywheel$m02(), m.flywheel$m12(), m.flywheel$m22()); + public static Matrix3f toJoml(Matrix3f matrix) { + return new Matrix3f(matrix); } /** @@ -147,10 +96,9 @@ public final class MatrixUtil { * @return The greatest scale factor across all axes. */ public static float extractScale(Matrix4f matrix) { - Matrix4fAccessor m = (Matrix4fAccessor) (Object) matrix; - float scaleSqrX = m.flywheel$m00() * m.flywheel$m00() + m.flywheel$m01() * m.flywheel$m01() + m.flywheel$m02() * m.flywheel$m02(); - float scaleSqrY = m.flywheel$m10() * m.flywheel$m10() + m.flywheel$m11() * m.flywheel$m11() + m.flywheel$m12() * m.flywheel$m12(); - float scaleSqrZ = m.flywheel$m20() * m.flywheel$m20() + m.flywheel$m21() * m.flywheel$m21() + m.flywheel$m22() * m.flywheel$m22(); - return (float) Math.sqrt(Math.max(Math.max(scaleSqrX, scaleSqrY), scaleSqrZ)); + float scaleSqrX = matrix.m00() * matrix.m00() + matrix.m01() * matrix.m01() + matrix.m02() * matrix.m02(); + float scaleSqrY = matrix.m10() * matrix.m10() + matrix.m11() * matrix.m11() + matrix.m12() * matrix.m12(); + float scaleSqrZ = matrix.m20() * matrix.m20() + matrix.m21() * matrix.m21() + matrix.m22() * matrix.m22(); + return Math.sqrt(Math.max(Math.max(scaleSqrX, scaleSqrY), scaleSqrZ)); } } 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 cb068cd58..7130e2fa7 100644 --- a/src/main/java/com/jozufozu/flywheel/lib/transform/Rotate.java +++ b/src/main/java/com/jozufozu/flywheel/lib/transform/Rotate.java @@ -1,19 +1,19 @@ package com.jozufozu.flywheel.lib.transform; -import com.mojang.math.Quaternion; -import com.mojang.math.Vector3f; +import org.joml.AxisAngle4f; +import org.joml.Quaternionf; +import org.joml.Vector3f; import net.minecraft.core.Direction; public interface Rotate { - Self multiply(Quaternion quaternion); + Self multiply(Quaternionf quaternion); @SuppressWarnings("unchecked") default Self rotate(Direction axis, float radians) { if (radians == 0) return (Self) this; - return multiply(axis.step() - .rotation(radians)); + return multiplyRadians(axis.step(), radians); } default Self rotate(double angle, Direction.Axis axis) { @@ -57,7 +57,7 @@ public interface Rotate { default Self multiplyRadians(Vector3f axis, double angle) { if (angle == 0) return (Self) this; - return multiply(axis.rotation((float) angle)); + return multiply(new Quaternionf(new AxisAngle4f((float) angle, axis))); } @SuppressWarnings("unchecked") diff --git a/src/main/java/com/jozufozu/flywheel/lib/transform/Transform.java b/src/main/java/com/jozufozu/flywheel/lib/transform/Transform.java index 4805f74ca..779cf0b9e 100644 --- a/src/main/java/com/jozufozu/flywheel/lib/transform/Transform.java +++ b/src/main/java/com/jozufozu/flywheel/lib/transform/Transform.java @@ -1,9 +1,10 @@ package com.jozufozu.flywheel.lib.transform; +import org.joml.Matrix3f; +import org.joml.Matrix4f; +import org.joml.Quaternionf; + import com.mojang.blaze3d.vertex.PoseStack; -import com.mojang.math.Matrix3f; -import com.mojang.math.Matrix4f; -import com.mojang.math.Quaternion; import net.minecraft.core.Direction; @@ -30,7 +31,7 @@ public interface Transform> extends Translate } @SuppressWarnings("unchecked") - default Self rotateCentered(Quaternion q) { + default Self rotateCentered(Quaternionf q) { translate(.5f, .5f, .5f).multiply(q) .translate(-.5f, -.5f, -.5f); return (Self) this; diff --git a/src/main/java/com/jozufozu/flywheel/lib/transform/Translate.java b/src/main/java/com/jozufozu/flywheel/lib/transform/Translate.java index dbc5ffccc..3a14fe4d9 100644 --- a/src/main/java/com/jozufozu/flywheel/lib/transform/Translate.java +++ b/src/main/java/com/jozufozu/flywheel/lib/transform/Translate.java @@ -1,6 +1,6 @@ package com.jozufozu.flywheel.lib.transform; -import com.mojang.math.Vector3f; +import org.joml.Vector3f; import net.minecraft.core.Vec3i; import net.minecraft.world.phys.Vec3; diff --git a/src/main/java/com/jozufozu/flywheel/lib/uniform/FlwShaderUniforms.java b/src/main/java/com/jozufozu/flywheel/lib/uniform/FlwShaderUniforms.java index f24736d78..702537dcc 100644 --- a/src/main/java/com/jozufozu/flywheel/lib/uniform/FlwShaderUniforms.java +++ b/src/main/java/com/jozufozu/flywheel/lib/uniform/FlwShaderUniforms.java @@ -2,6 +2,7 @@ package com.jozufozu.flywheel.lib.uniform; import java.util.function.Consumer; +import org.joml.Matrix4f; import org.lwjgl.system.MemoryUtil; import com.jozufozu.flywheel.Flywheel; @@ -83,9 +84,8 @@ public class FlwShaderUniforms implements ShaderUniforms { var camZ = (float) (camera.z - renderOrigin.getZ()); // don't want to mutate viewProjection - var vp = context.viewProjection() - .copy(); - vp.multiplyWithTranslation(-camX, -camY, -camZ); + var vp = new Matrix4f(context.viewProjection()); + vp.translate(-camX, -camY, -camZ); MatrixUtil.writeUnsafe(vp, ptr + 32); MemoryUtil.memPutFloat(ptr + 96, camX); diff --git a/src/main/java/com/jozufozu/flywheel/lib/util/FlwUtil.java b/src/main/java/com/jozufozu/flywheel/lib/util/FlwUtil.java index 60daa2fb8..04f27c4d4 100644 --- a/src/main/java/com/jozufozu/flywheel/lib/util/FlwUtil.java +++ b/src/main/java/com/jozufozu/flywheel/lib/util/FlwUtil.java @@ -25,11 +25,11 @@ public final class FlwUtil { PoseStack copy = new PoseStack(); copy.last() .pose() - .load(stack.last() + .set(stack.last() .pose()); copy.last() .normal() - .load(stack.last() + .set(stack.last() .normal()); return copy; } diff --git a/src/main/java/com/jozufozu/flywheel/lib/util/LevelAttached.java b/src/main/java/com/jozufozu/flywheel/lib/util/LevelAttached.java index 551ffc5e0..e19bd7e40 100644 --- a/src/main/java/com/jozufozu/flywheel/lib/util/LevelAttached.java +++ b/src/main/java/com/jozufozu/flywheel/lib/util/LevelAttached.java @@ -14,7 +14,7 @@ import com.google.common.cache.CacheLoader; import com.google.common.cache.LoadingCache; import net.minecraft.world.level.LevelAccessor; -import net.minecraftforge.event.world.WorldEvent; +import net.minecraftforge.event.level.LevelEvent; public final class LevelAttached { private static final ConcurrentLinkedDeque>> ALL = new ConcurrentLinkedDeque<>(); @@ -43,8 +43,8 @@ public final class LevelAttached { } @ApiStatus.Internal - public static void onUnloadLevel(WorldEvent.Unload event) { - invalidateLevel(event.getWorld()); + public static void onUnloadLevel(LevelEvent.Unload event) { + invalidateLevel(event.getLevel()); } public static void invalidateLevel(LevelAccessor level) { diff --git a/src/main/java/com/jozufozu/flywheel/lib/vertex/VertexTransformations.java b/src/main/java/com/jozufozu/flywheel/lib/vertex/VertexTransformations.java index 2cba218d2..7ec160a72 100644 --- a/src/main/java/com/jozufozu/flywheel/lib/vertex/VertexTransformations.java +++ b/src/main/java/com/jozufozu/flywheel/lib/vertex/VertexTransformations.java @@ -1,9 +1,10 @@ package com.jozufozu.flywheel.lib.vertex; +import org.joml.Matrix3f; +import org.joml.Matrix4f; + import com.jozufozu.flywheel.api.vertex.MutableVertexList; import com.jozufozu.flywheel.lib.math.MatrixUtil; -import com.mojang.math.Matrix3f; -import com.mojang.math.Matrix4f; public final class VertexTransformations { private VertexTransformations() { diff --git a/src/main/java/com/jozufozu/flywheel/lib/visual/AbstractEntityVisual.java b/src/main/java/com/jozufozu/flywheel/lib/visual/AbstractEntityVisual.java index df23d40a0..cb26bf352 100644 --- a/src/main/java/com/jozufozu/flywheel/lib/visual/AbstractEntityVisual.java +++ b/src/main/java/com/jozufozu/flywheel/lib/visual/AbstractEntityVisual.java @@ -1,6 +1,7 @@ package com.jozufozu.flywheel.lib.visual; import org.joml.FrustumIntersection; +import org.joml.Vector3f; import com.jozufozu.flywheel.api.visual.DynamicVisual; import com.jozufozu.flywheel.api.visual.EntityVisual; @@ -10,7 +11,6 @@ import com.jozufozu.flywheel.api.visualization.VisualizationManager; import com.jozufozu.flywheel.lib.box.Box; import com.jozufozu.flywheel.lib.box.MutableBox; import com.jozufozu.flywheel.lib.light.TickingLightListener; -import com.mojang.math.Vector3f; import net.minecraft.util.Mth; import net.minecraft.world.entity.Entity; @@ -38,7 +38,7 @@ public abstract class AbstractEntityVisual extends AbstractVis protected final EntityVisibilityTester visibilityTester; public AbstractEntityVisual(VisualizationContext ctx, T entity) { - super(ctx, entity.level); + super(ctx, entity.level()); this.entity = entity; bounds = MutableBox.from(entity.getBoundingBox()); visibilityTester = new EntityVisibilityTester(entity, ctx.renderOrigin()); diff --git a/src/main/java/com/jozufozu/flywheel/mixin/LevelRendererMixin.java b/src/main/java/com/jozufozu/flywheel/mixin/LevelRendererMixin.java index f09813b56..25caa920d 100644 --- a/src/main/java/com/jozufozu/flywheel/mixin/LevelRendererMixin.java +++ b/src/main/java/com/jozufozu/flywheel/mixin/LevelRendererMixin.java @@ -1,5 +1,6 @@ package com.jozufozu.flywheel.mixin; +import org.joml.Matrix4f; import org.objectweb.asm.Opcodes; import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; @@ -16,7 +17,6 @@ import com.jozufozu.flywheel.api.event.RenderContext; import com.jozufozu.flywheel.api.event.RenderStage; import com.jozufozu.flywheel.api.event.RenderStageEvent; import com.mojang.blaze3d.vertex.PoseStack; -import com.mojang.math.Matrix4f; import net.minecraft.client.Camera; import net.minecraft.client.multiplayer.ClientLevel; diff --git a/src/main/java/com/jozufozu/flywheel/mixin/matrix/Matrix3fAccessor.java b/src/main/java/com/jozufozu/flywheel/mixin/matrix/Matrix3fAccessor.java deleted file mode 100644 index cab5194df..000000000 --- a/src/main/java/com/jozufozu/flywheel/mixin/matrix/Matrix3fAccessor.java +++ /dev/null @@ -1,36 +0,0 @@ -package com.jozufozu.flywheel.mixin.matrix; - -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.gen.Accessor; - -import com.mojang.math.Matrix3f; - -@Mixin(Matrix3f.class) -public interface Matrix3fAccessor { - @Accessor("m00") - float flywheel$m00(); - - @Accessor("m01") - float flywheel$m01(); - - @Accessor("m02") - float flywheel$m02(); - - @Accessor("m10") - float flywheel$m10(); - - @Accessor("m11") - float flywheel$m11(); - - @Accessor("m12") - float flywheel$m12(); - - @Accessor("m20") - float flywheel$m20(); - - @Accessor("m21") - float flywheel$m21(); - - @Accessor("m22") - float flywheel$m22(); -} diff --git a/src/main/java/com/jozufozu/flywheel/mixin/matrix/Matrix4fAccessor.java b/src/main/java/com/jozufozu/flywheel/mixin/matrix/Matrix4fAccessor.java deleted file mode 100644 index 8da1c56f1..000000000 --- a/src/main/java/com/jozufozu/flywheel/mixin/matrix/Matrix4fAccessor.java +++ /dev/null @@ -1,57 +0,0 @@ -package com.jozufozu.flywheel.mixin.matrix; - -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.gen.Accessor; - -import com.mojang.math.Matrix4f; - -@Mixin(Matrix4f.class) -public interface Matrix4fAccessor { - @Accessor("m00") - float flywheel$m00(); - - @Accessor("m01") - float flywheel$m01(); - - @Accessor("m02") - float flywheel$m02(); - - @Accessor("m03") - float flywheel$m03(); - - @Accessor("m10") - float flywheel$m10(); - - @Accessor("m11") - float flywheel$m11(); - - @Accessor("m12") - float flywheel$m12(); - - @Accessor("m13") - float flywheel$m13(); - - @Accessor("m20") - float flywheel$m20(); - - @Accessor("m21") - float flywheel$m21(); - - @Accessor("m22") - float flywheel$m22(); - - @Accessor("m23") - float flywheel$m23(); - - @Accessor("m30") - float flywheel$m30(); - - @Accessor("m31") - float flywheel$m31(); - - @Accessor("m32") - float flywheel$m32(); - - @Accessor("m33") - float flywheel$m33(); -} diff --git a/src/main/java/com/jozufozu/flywheel/mixin/matrix/PoseStackMixin.java b/src/main/java/com/jozufozu/flywheel/mixin/matrix/PoseStackMixin.java index e3e807723..dbed35c30 100644 --- a/src/main/java/com/jozufozu/flywheel/mixin/matrix/PoseStackMixin.java +++ b/src/main/java/com/jozufozu/flywheel/mixin/matrix/PoseStackMixin.java @@ -1,15 +1,15 @@ package com.jozufozu.flywheel.mixin.matrix; +import org.joml.Quaternionf; import org.spongepowered.asm.mixin.Mixin; import com.jozufozu.flywheel.lib.transform.TransformStack; import com.mojang.blaze3d.vertex.PoseStack; -import com.mojang.math.Quaternion; @Mixin(PoseStack.class) public abstract class PoseStackMixin implements TransformStack { @Override - public TransformStack multiply(Quaternion quaternion) { + public TransformStack multiply(Quaternionf quaternion) { ((PoseStack) (Object) this).mulPose(quaternion); return this; } diff --git a/src/main/java/com/jozufozu/flywheel/mixin/sodium/FlywheelCompatMixin.java b/src/main/java/com/jozufozu/flywheel/mixin/sodium/FlywheelCompatMixin.java deleted file mode 100644 index 674a144cb..000000000 --- a/src/main/java/com/jozufozu/flywheel/mixin/sodium/FlywheelCompatMixin.java +++ /dev/null @@ -1,24 +0,0 @@ -package com.jozufozu.flywheel.mixin.sodium; - -import java.util.Collection; - -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Overwrite; - -import me.jellysquid.mods.sodium.client.compat.FlywheelCompat; -import net.minecraft.world.level.block.entity.BlockEntity; - -/** - * Overwrite all methods in this class with stubs. These methods use Flywheel classes that no longer exist and would cause a NoClassDefFoundError if invoked. - */ -@Mixin(value = FlywheelCompat.class, remap = false) -public class FlywheelCompatMixin { - @Overwrite - public static boolean addAndFilterBEs(BlockEntity blockEntity) { - return true; - } - - @Overwrite - public static void filterBlockEntityList(Collection blockEntities) { - } -} diff --git a/src/main/java/com/jozufozu/flywheel/vanilla/BellVisual.java b/src/main/java/com/jozufozu/flywheel/vanilla/BellVisual.java index e56d3c596..14ff861da 100644 --- a/src/main/java/com/jozufozu/flywheel/vanilla/BellVisual.java +++ b/src/main/java/com/jozufozu/flywheel/vanilla/BellVisual.java @@ -2,6 +2,10 @@ package com.jozufozu.flywheel.vanilla; import java.util.List; +import org.joml.AxisAngle4f; +import org.joml.Quaternionf; +import org.joml.Vector3f; + import com.jozufozu.flywheel.api.event.RenderStage; import com.jozufozu.flywheel.api.instance.Instance; import com.jozufozu.flywheel.api.visual.DynamicVisual; @@ -14,8 +18,6 @@ import com.jozufozu.flywheel.lib.model.ModelHolder; import com.jozufozu.flywheel.lib.model.SimpleModel; import com.jozufozu.flywheel.lib.model.part.ModelPartConverter; import com.jozufozu.flywheel.lib.visual.AbstractBlockEntityVisual; -import com.mojang.math.Quaternion; -import com.mojang.math.Vector3f; import net.minecraft.client.model.geom.ModelLayers; import net.minecraft.client.renderer.blockentity.BellRenderer; @@ -73,9 +75,9 @@ public class BellVisual extends AbstractBlockEntityVisual imple Vector3f ringAxis = blockEntity.clickDirection.getCounterClockWise() .step(); - bell.setRotation(ringAxis.rotation(angle)); + bell.setRotation(new Quaternionf(new AxisAngle4f(angle, ringAxis))); } else { - bell.setRotation(Quaternion.ONE); + bell.setRotation(new Quaternionf()); } } diff --git a/src/main/java/com/jozufozu/flywheel/vanilla/ChestVisual.java b/src/main/java/com/jozufozu/flywheel/vanilla/ChestVisual.java index dbe4d1885..1fce755c9 100644 --- a/src/main/java/com/jozufozu/flywheel/vanilla/ChestVisual.java +++ b/src/main/java/com/jozufozu/flywheel/vanilla/ChestVisual.java @@ -5,6 +5,8 @@ import java.util.EnumMap; import java.util.List; import java.util.Map; +import org.joml.Quaternionf; + import com.jozufozu.flywheel.api.event.RenderStage; import com.jozufozu.flywheel.api.instance.Instance; import com.jozufozu.flywheel.api.visual.DynamicVisual; @@ -19,8 +21,6 @@ import com.jozufozu.flywheel.lib.model.SimpleModel; import com.jozufozu.flywheel.lib.model.part.ModelPartConverter; import com.jozufozu.flywheel.lib.util.Pair; import com.jozufozu.flywheel.lib.visual.AbstractBlockEntityVisual; -import com.mojang.math.Quaternion; -import com.mojang.math.Vector3f; import it.unimi.dsi.fastutil.floats.Float2FloatFunction; import net.minecraft.client.model.geom.ModelLayerLocation; @@ -60,7 +60,7 @@ public class ChestVisual extends Abstrac private ChestType chestType; private Material texture; - private Quaternion baseRotation; + private Quaternionf baseRotation; private Float2FloatFunction lidProgress; private float lastProgress = Float.NaN; diff --git a/src/main/java/com/jozufozu/flywheel/vanilla/MinecartVisual.java b/src/main/java/com/jozufozu/flywheel/vanilla/MinecartVisual.java index fea3ef492..fa3adde0d 100644 --- a/src/main/java/com/jozufozu/flywheel/vanilla/MinecartVisual.java +++ b/src/main/java/com/jozufozu/flywheel/vanilla/MinecartVisual.java @@ -15,7 +15,6 @@ import com.jozufozu.flywheel.lib.model.SimpleModel; import com.jozufozu.flywheel.lib.model.part.ModelPartConverter; import com.jozufozu.flywheel.lib.visual.AbstractEntityVisual; import com.mojang.blaze3d.vertex.PoseStack; -import com.mojang.math.Vector3f; import net.minecraft.client.model.geom.ModelLayers; import net.minecraft.util.Mth; @@ -124,7 +123,7 @@ public class MinecartVisual extends AbstractEntityVi if (pos != null) { Vec3 offset1 = entity.getPosOffs(posX, posY, posZ, 0.3F); Vec3 offset2 = entity.getPosOffs(posX, posY, posZ, -0.3F); - + if (offset1 == null) { offset1 = pos; } diff --git a/src/main/java/com/jozufozu/flywheel/vanilla/ShulkerBoxVisual.java b/src/main/java/com/jozufozu/flywheel/vanilla/ShulkerBoxVisual.java index 48ded16a5..9ae935058 100644 --- a/src/main/java/com/jozufozu/flywheel/vanilla/ShulkerBoxVisual.java +++ b/src/main/java/com/jozufozu/flywheel/vanilla/ShulkerBoxVisual.java @@ -2,6 +2,8 @@ package com.jozufozu.flywheel.vanilla; import java.util.List; +import org.joml.Quaternionf; + import com.jozufozu.flywheel.api.event.RenderStage; import com.jozufozu.flywheel.api.instance.Instance; import com.jozufozu.flywheel.api.visual.DynamicVisual; @@ -16,8 +18,6 @@ import com.jozufozu.flywheel.lib.model.part.ModelPartConverter; import com.jozufozu.flywheel.lib.transform.TransformStack; import com.jozufozu.flywheel.lib.visual.AbstractBlockEntityVisual; import com.mojang.blaze3d.vertex.PoseStack; -import com.mojang.math.Quaternion; -import com.mojang.math.Vector3f; import net.minecraft.client.model.geom.ModelLayers; import net.minecraft.client.renderer.Sheets; @@ -56,7 +56,7 @@ public class ShulkerBoxVisual extends AbstractBlockEntityVisual