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
This commit is contained in:
Jozufozu 2023-11-22 21:30:58 -08:00
parent 57faab9291
commit df93b09f44
38 changed files with 194 additions and 345 deletions

View file

@ -36,14 +36,12 @@ import com.jozufozu.flywheel.vanilla.VanillaVisuals;
import com.mojang.logging.LogUtils; import com.mojang.logging.LogUtils;
import net.minecraft.client.Minecraft; 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.core.Vec3i;
import net.minecraft.resources.ResourceLocation; import net.minecraft.resources.ResourceLocation;
import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.client.event.RenderGameOverlayEvent; import net.minecraftforge.client.event.RenderGameOverlayEvent;
import net.minecraftforge.common.MinecraftForge; 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.eventbus.api.IEventBus;
import net.minecraftforge.fml.DistExecutor; import net.minecraftforge.fml.DistExecutor;
import net.minecraftforge.fml.IExtensionPoint; import net.minecraftforge.fml.IExtensionPoint;
@ -51,7 +49,6 @@ import net.minecraftforge.fml.ModLoadingContext;
import net.minecraftforge.fml.common.Mod; import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent; import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent;
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext; import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
import net.minecraftforge.network.NetworkConstants;
@Mod(Flywheel.ID) @Mod(Flywheel.ID)
public class Flywheel { public class Flywheel {
@ -101,7 +98,7 @@ public class Flywheel {
forgeEventBus.addListener(LightUpdater::onClientTick); forgeEventBus.addListener(LightUpdater::onClientTick);
forgeEventBus.addListener((ReloadRenderersEvent e) -> ModelCache.onReloadRenderers(e)); forgeEventBus.addListener((ReloadRenderersEvent e) -> ModelCache.onReloadRenderers(e));
forgeEventBus.addListener(ModelHolder::onReloadRenderers); 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::onModelRegistry);
modEventBus.addListener(PartialModel::onModelBake); modEventBus.addListener(PartialModel::onModelBake);

View file

@ -1,7 +1,8 @@
package com.jozufozu.flywheel.api.event; package com.jozufozu.flywheel.api.event;
import org.joml.Matrix4f;
import com.mojang.blaze3d.vertex.PoseStack; import com.mojang.blaze3d.vertex.PoseStack;
import com.mojang.math.Matrix4f;
import net.minecraft.client.Camera; import net.minecraft.client.Camera;
import net.minecraft.client.multiplayer.ClientLevel; 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, public record RenderContext(LevelRenderer renderer, ClientLevel level, RenderBuffers buffers, PoseStack stack,
Matrix4f projection, Matrix4f viewProjection, Camera camera, float partialTick) { 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) { public static RenderContext create(LevelRenderer renderer, ClientLevel level, RenderBuffers buffers, PoseStack stack, Matrix4f projection, Camera camera, float partialTick) {
Matrix4f viewProjection = projection.copy(); Matrix4f viewProjection = new Matrix4f(projection);
viewProjection.multiply(stack.last().pose()); viewProjection.mul(stack.last()
.pose());
return new RenderContext(renderer, level, buffers, stack, projection, viewProjection, camera, partialTick); return new RenderContext(renderer, level, buffers, stack, projection, viewProjection, camera, partialTick);
} }

View file

@ -1,7 +1,8 @@
package com.jozufozu.flywheel.api.event; package com.jozufozu.flywheel.api.event;
import org.joml.Matrix4f;
import com.mojang.blaze3d.vertex.PoseStack; import com.mojang.blaze3d.vertex.PoseStack;
import com.mojang.math.Matrix4f;
import net.minecraft.client.Camera; import net.minecraft.client.Camera;
import net.minecraft.client.multiplayer.ClientLevel; import net.minecraft.client.multiplayer.ClientLevel;

View file

@ -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. * @param blockEntity The block entity whose visual you want to update.
*/ */
static void queueUpdate(BlockEntity blockEntity) { 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. * @param entity The entity whose visual you want to update.
*/ */
static void queueUpdate(Entity entity) { static void queueUpdate(Entity entity) {
Level level = entity.level; Level level = entity.level();
VisualizationManager manager = get(level); VisualizationManager manager = get(level);
if (manager == null) { if (manager == null) {
return; 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. * @param effect The effect whose visual you want to update.
*/ */
static void queueUpdate(LevelAccessor level, Effect effect) { static void queueUpdate(LevelAccessor level, Effect effect) {

View file

@ -1,5 +1,6 @@
package com.jozufozu.flywheel.backend; package com.jozufozu.flywheel.backend;
import com.jozufozu.flywheel.Flywheel; import com.jozufozu.flywheel.Flywheel;
import com.jozufozu.flywheel.api.backend.Backend; import com.jozufozu.flywheel.api.backend.Backend;
import com.jozufozu.flywheel.backend.compile.IndirectPrograms; 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 com.jozufozu.flywheel.lib.util.ShadersModHandler;
import net.minecraft.ChatFormatting; import net.minecraft.ChatFormatting;
import net.minecraft.network.chat.TextComponent; import net.minecraft.network.chat.Component;
public class Backends { public class Backends {
/** /**
* Use a thread pool to buffer instances in parallel on the CPU. * Use a thread pool to buffer instances in parallel on the CPU.
*/ */
public static final Backend BATCHING = SimpleBackend.builder() 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)) .engineFactory(level -> new BatchingEngine(256))
.supported(() -> !ShadersModHandler.isShaderPackInUse()) .supported(() -> !ShadersModHandler.isShaderPackInUse())
.register(Flywheel.rl("batching")); .register(Flywheel.rl("batching"));
@ -29,7 +31,8 @@ public class Backends {
* Use GPU instancing to render everything. * Use GPU instancing to render everything.
*/ */
public static final Backend INSTANCING = SimpleBackend.builder() 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)) .engineFactory(level -> new InstancingEngine(256, Contexts.WORLD))
.fallback(() -> Backends.BATCHING) .fallback(() -> Backends.BATCHING)
.supported(() -> !ShadersModHandler.isShaderPackInUse() && GlCompat.supportsInstancing() && InstancingPrograms.allLoaded()) .supported(() -> !ShadersModHandler.isShaderPackInUse() && GlCompat.supportsInstancing() && InstancingPrograms.allLoaded())
@ -39,7 +42,8 @@ public class Backends {
* Use Compute shaders to cull instances. * Use Compute shaders to cull instances.
*/ */
public static final Backend INDIRECT = SimpleBackend.builder() 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)) .engineFactory(level -> new IndirectEngine(256))
.fallback(() -> Backends.INSTANCING) .fallback(() -> Backends.INSTANCING)
.supported(() -> !ShadersModHandler.isShaderPackInUse() && GlCompat.supportsIndirect() && IndirectPrograms.allLoaded()) .supported(() -> !ShadersModHandler.isShaderPackInUse() && GlCompat.supportsIndirect() && IndirectPrograms.allLoaded())

View file

@ -27,7 +27,7 @@ public abstract class AbstractEngine implements Engine {
return false; return false;
} }
renderOrigin = new BlockPos(cameraPos); renderOrigin = BlockPos.containing(cameraPos);
onRenderOriginChanged(); onRenderOriginChanged();
return true; return true;
} }

View file

@ -71,7 +71,9 @@ public class BatchedDrawTracker {
if (buffer.hasVertices()) { if (buffer.hasVertices()) {
BufferBuilderExtension scratch = (BufferBuilderExtension) this.scratch; BufferBuilderExtension scratch = (BufferBuilderExtension) this.scratch;
buffer.inject(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(); buffer.reset();
} }

View file

@ -3,6 +3,8 @@ package com.jozufozu.flywheel.backend.engine.batching;
import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicInteger;
import org.joml.FrustumIntersection; import org.joml.FrustumIntersection;
import org.joml.Matrix3f;
import org.joml.Matrix4f;
import org.joml.Vector4f; import org.joml.Vector4f;
import org.joml.Vector4fc; 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.task.ForEachSlicePlan;
import com.jozufozu.flywheel.lib.vertex.VertexTransformations; import com.jozufozu.flywheel.lib.vertex.VertexTransformations;
import com.mojang.blaze3d.vertex.PoseStack; import com.mojang.blaze3d.vertex.PoseStack;
import com.mojang.math.Matrix3f;
import com.mojang.math.Matrix4f;
import net.minecraft.client.multiplayer.ClientLevel; import net.minecraft.client.multiplayer.ClientLevel;

View file

@ -14,14 +14,14 @@ import com.mojang.brigadier.suggestion.Suggestions;
import com.mojang.brigadier.suggestion.SuggestionsBuilder; import com.mojang.brigadier.suggestion.SuggestionsBuilder;
import net.minecraft.commands.SharedSuggestionProvider; import net.minecraft.commands.SharedSuggestionProvider;
import net.minecraft.network.chat.TextComponent; import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation; import net.minecraft.resources.ResourceLocation;
public class BackendArgument implements ArgumentType<Backend> { public class BackendArgument implements ArgumentType<Backend> {
private static final List<String> STRING_IDS = Backend.REGISTRY.getAllIds().stream().map(ResourceLocation::toString).toList(); private static final List<String> STRING_IDS = Backend.REGISTRY.getAllIds().stream().map(ResourceLocation::toString).toList();
public static final DynamicCommandExceptionType ERROR_UNKNOWN_BACKEND = new DynamicCommandExceptionType(arg -> { 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(); public static final BackendArgument INSTANCE = new BackendArgument();

View file

@ -19,7 +19,6 @@ import net.minecraft.commands.arguments.coordinates.BlockPosArgument;
import net.minecraft.core.BlockPos; import net.minecraft.core.BlockPos;
import net.minecraft.network.chat.Component; import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.MutableComponent; import net.minecraft.network.chat.MutableComponent;
import net.minecraft.network.chat.TextComponent;
import net.minecraft.resources.ResourceLocation; import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.Entity;
import net.minecraftforge.client.event.RegisterClientCommandsEvent; import net.minecraftforge.client.event.RegisterClientCommandsEvent;
@ -42,13 +41,13 @@ public class FlwCommands {
try { try {
backendId = new ResourceLocation(backendIdStr); backendId = new ResourceLocation(backendIdStr);
} catch (ResourceLocationException e) { } 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; return 0;
} }
Backend backend = Backend.REGISTRY.get(backendId); Backend backend = Backend.REGISTRY.get(backendId);
if (backend == null) { 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; return 0;
} }
@ -71,7 +70,8 @@ public class FlwCommands {
var actualBackend = BackendManager.getBackend(); var actualBackend = BackendManager.getBackend();
if (actualBackend != requestedBackend) { 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(); Component message = actualBackend.engineMessage();
@ -85,14 +85,16 @@ public class FlwCommands {
LocalPlayer player = Minecraft.getInstance().player; LocalPlayer player = Minecraft.getInstance().player;
if (player == null) return; 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); player.displayClientMessage(text, false);
}, },
(source, bool) -> { (source, bool) -> {
LocalPlayer player = Minecraft.getInstance().player; LocalPlayer player = Minecraft.getInstance().player;
if (player == null) return; 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); player.displayClientMessage(text, false);
Minecraft.getInstance().levelRenderer.allChanged(); Minecraft.getInstance().levelRenderer.allChanged();
@ -105,7 +107,7 @@ public class FlwCommands {
LocalPlayer player = Minecraft.getInstance().player; LocalPlayer player = Minecraft.getInstance().player;
if (player == null) return 0; 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; return Command.SINGLE_SUCCESS;
}); });
@ -124,7 +126,8 @@ public class FlwCommands {
return 0; return 0;
} }
executor.level.destroyBlockProgress(executor.getId(), pos, value); executor.level()
.destroyBlockProgress(executor.getId(), pos, value);
return Command.SINGLE_SUCCESS; return Command.SINGLE_SUCCESS;
})))); }))));
@ -176,6 +179,8 @@ public class FlwCommands {
} }
public static MutableComponent boolToText(boolean b) { 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);
} }
} }

View file

@ -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 { record MalformedInclude(ResourceLocationException exception) implements LoadError {
@Override @Override
public ErrorBuilder generateMessage() { public ErrorBuilder generateMessage() {

View file

@ -15,7 +15,6 @@ import org.jetbrains.annotations.VisibleForTesting;
import com.jozufozu.flywheel.lib.util.ResourceUtil; import com.jozufozu.flywheel.lib.util.ResourceUtil;
import net.minecraft.resources.ResourceLocation; import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.packs.resources.Resource;
import net.minecraft.server.packs.resources.ResourceManager; import net.minecraft.server.packs.resources.ResourceManager;
/** /**
@ -68,12 +67,15 @@ public class ShaderSources {
@NotNull @NotNull
protected LoadResult load(ResourceLocation loc) { protected LoadResult load(ResourceLocation loc) {
try (Resource resource = manager.getResource(ResourceUtil.prefixed(SHADER_DIR, loc))) { return manager.getResource(ResourceUtil.prefixed(SHADER_DIR, loc))
InputStream stream = resource.getInputStream(); .map(resource -> {
String sourceString = new String(stream.readAllBytes(), StandardCharsets.UTF_8); try (InputStream stream = resource.open()) {
return SourceFile.parse(this, loc, sourceString); String sourceString = new String(stream.readAllBytes(), StandardCharsets.UTF_8);
} catch (IOException e) { return SourceFile.parse(this, loc, sourceString);
return new LoadResult.Failure(new LoadError.IOError(loc, e)); } catch (IOException e) {
} return new LoadResult.Failure(new LoadError.IOError(loc, e));
}
})
.orElseGet(() -> new LoadResult.Failure(new LoadError.ResourceError(loc)));
} }
} }

View file

@ -14,7 +14,7 @@ import com.mojang.logging.LogUtils;
import net.minecraft.ChatFormatting; import net.minecraft.ChatFormatting;
import net.minecraft.client.multiplayer.ClientLevel; 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.minecraft.resources.ResourceLocation;
import net.minecraftforge.fml.CrashReportCallables; import net.minecraftforge.fml.CrashReportCallables;
@ -22,7 +22,8 @@ public final class BackendManagerImpl {
private static final Logger LOGGER = LogUtils.getLogger(); private static final Logger LOGGER = LogUtils.getLogger();
private static final Backend OFF_BACKEND = SimpleBackend.builder() 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 -> { .engineFactory(level -> {
throw new UnsupportedOperationException("Cannot create engine when backend is off."); throw new UnsupportedOperationException("Cannot create engine when backend is off.");
}) })

View file

@ -10,8 +10,8 @@ import net.minecraft.client.multiplayer.ClientLevel;
import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.Entity;
import net.minecraft.world.level.Level; import net.minecraft.world.level.Level;
import net.minecraftforge.event.TickEvent; import net.minecraftforge.event.TickEvent;
import net.minecraftforge.event.entity.EntityJoinWorldEvent; import net.minecraftforge.event.entity.EntityJoinLevelEvent;
import net.minecraftforge.event.entity.EntityLeaveWorldEvent; import net.minecraftforge.event.entity.EntityLeaveLevelEvent;
public final class VisualizationEventHandler { public final class VisualizationEventHandler {
private VisualizationEventHandler() { private VisualizationEventHandler() {
@ -32,7 +32,7 @@ public final class VisualizationEventHandler {
return; return;
} }
Level level = cameraEntity.level; Level level = cameraEntity.level();
VisualizationManagerImpl manager = VisualizationManagerImpl.get(level); VisualizationManagerImpl manager = VisualizationManagerImpl.get(level);
if (manager == null) { if (manager == null) {
return; return;
@ -65,8 +65,8 @@ public final class VisualizationEventHandler {
manager.renderStage(event.getContext(), event.getStage()); manager.renderStage(event.getContext(), event.getStage());
} }
public static void onEntityJoinWorld(EntityJoinWorldEvent event) { public static void onEntityJoinWorld(EntityJoinLevelEvent event) {
Level level = event.getWorld(); Level level = event.getLevel();
VisualizationManager manager = VisualizationManager.get(level); VisualizationManager manager = VisualizationManager.get(level);
if (manager == null) { if (manager == null) {
return; return;
@ -75,8 +75,8 @@ public final class VisualizationEventHandler {
manager.getEntities().queueAdd(event.getEntity()); manager.getEntities().queueAdd(event.getEntity());
} }
public static void onEntityLeaveWorld(EntityLeaveWorldEvent event) { public static void onEntityLeaveWorld(EntityLeaveLevelEvent event) {
Level level = event.getWorld(); Level level = event.getLevel();
VisualizationManager manager = VisualizationManager.get(level); VisualizationManager manager = VisualizationManager.get(level);
if (manager == null) { if (manager == null) {
return; return;

View file

@ -49,7 +49,7 @@ public class EntityVisualManager extends AbstractVisualManager<Entity> {
return false; return false;
} }
Level level = entity.level; Level level = entity.level();
return level != null; return level != null;
} }
} }

View file

@ -1,9 +1,10 @@
package com.jozufozu.flywheel.lib.instance; 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.InstanceHandle;
import com.jozufozu.flywheel.api.instance.InstanceType; import com.jozufozu.flywheel.api.instance.InstanceType;
import com.mojang.math.Quaternion;
import com.mojang.math.Vector3f;
import net.minecraft.core.BlockPos; import net.minecraft.core.BlockPos;
@ -63,8 +64,8 @@ public class OrientedInstance extends ColoredLitInstance {
return this; return this;
} }
public OrientedInstance setRotation(Quaternion q) { public OrientedInstance setRotation(Quaternionf q) {
return setRotation(q.i(), q.j(), q.k(), q.r()); return setRotation(q.x, q.y, q.z, q.w);
} }
public OrientedInstance setRotation(float x, float y, float z, float w) { public OrientedInstance setRotation(float x, float y, float z, float w) {

View file

@ -1,5 +1,7 @@
package com.jozufozu.flywheel.lib.instance; package com.jozufozu.flywheel.lib.instance;
import org.joml.Matrix3f;
import org.joml.Matrix4f;
import org.joml.Quaternionf; import org.joml.Quaternionf;
import com.jozufozu.flywheel.api.instance.InstanceBoundingSphereTransformer; 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.layout.CommonItems;
import com.jozufozu.flywheel.lib.math.RenderMath; import com.jozufozu.flywheel.lib.math.RenderMath;
import com.jozufozu.flywheel.lib.vertex.VertexTransformations; 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; import net.minecraft.resources.ResourceLocation;
@ -49,15 +48,15 @@ public class OrientedType implements InstanceType<OrientedInstance> {
@Override @Override
public InstanceVertexTransformer<OrientedInstance> getVertexTransformer() { public InstanceVertexTransformer<OrientedInstance> getVertexTransformer() {
return (vertexList, instance) -> { 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(); Matrix4f modelMatrix = new Matrix4f();
modelMatrix.setIdentity(); modelMatrix.translate(instance.posX + instance.pivotX, instance.posY + instance.pivotY, instance.posZ + instance.pivotZ);
modelMatrix.multiplyWithTranslation(instance.posX + instance.pivotX, instance.posY + instance.pivotY, instance.posZ + instance.pivotZ); modelMatrix.rotate(q);
modelMatrix.multiply(q); modelMatrix.translate(-instance.pivotX, -instance.pivotY, -instance.pivotZ);
modelMatrix.multiplyWithTranslation(-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 r = RenderMath.uf(instance.r);
float g = RenderMath.uf(instance.g); float g = RenderMath.uf(instance.g);

View file

@ -1,12 +1,13 @@
package com.jozufozu.flywheel.lib.instance; 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.InstanceHandle;
import com.jozufozu.flywheel.api.instance.InstanceType; import com.jozufozu.flywheel.api.instance.InstanceType;
import com.jozufozu.flywheel.lib.transform.Transform; import com.jozufozu.flywheel.lib.transform.Transform;
import com.mojang.blaze3d.vertex.PoseStack; 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; import net.minecraft.util.Mth;
@ -17,11 +18,6 @@ public class TransformedInstance extends ColoredLitInstance implements Transform
public final Matrix4f model = new Matrix4f(); public final Matrix4f model = new Matrix4f();
public final Matrix3f normal = new Matrix3f(); public final Matrix3f normal = new Matrix3f();
{
model.setIdentity();
normal.setIdentity();
}
public TransformedInstance(InstanceType<? extends TransformedInstance> type, InstanceHandle handle) { public TransformedInstance(InstanceType<? extends TransformedInstance> type, InstanceHandle handle) {
super(type, handle); super(type, handle);
} }
@ -29,9 +25,9 @@ public class TransformedInstance extends ColoredLitInstance implements Transform
public TransformedInstance setTransform(PoseStack stack) { public TransformedInstance setTransform(PoseStack stack) {
setChanged(); setChanged();
this.model.load(stack.last() this.model.set(stack.last()
.pose()); .pose());
this.normal.load(stack.last() this.normal.set(stack.last()
.normal()); .normal());
return this; return this;
} }
@ -46,25 +42,25 @@ public class TransformedInstance extends ColoredLitInstance implements Transform
public TransformedInstance setEmptyTransform() { public TransformedInstance setEmptyTransform() {
setChanged(); setChanged();
model.load(ZERO_MATRIX_4f); model.set(ZERO_MATRIX_4f);
normal.load(ZERO_MATRIX_3f); normal.set(ZERO_MATRIX_3f);
return this; return this;
} }
public TransformedInstance loadIdentity() { public TransformedInstance loadIdentity() {
setChanged(); setChanged();
model.setIdentity(); model.identity();
normal.setIdentity(); normal.identity();
return this; return this;
} }
@Override @Override
public TransformedInstance multiply(Quaternion quaternion) { public TransformedInstance multiply(Quaternionf quaternion) {
setChanged(); setChanged();
model.multiply(quaternion); model.rotate(quaternion);
normal.mul(quaternion); normal.rotate(quaternion);
return this; return this;
} }
@ -72,11 +68,11 @@ public class TransformedInstance extends ColoredLitInstance implements Transform
public TransformedInstance scale(float x, float y, float z) { public TransformedInstance scale(float x, float y, float z) {
setChanged(); setChanged();
model.multiply(Matrix4f.createScaleMatrix(x, y, z)); model.scale(x, y, z);
if (x == y && y == z) { if (x == y && y == z) {
if (x < 0.0f) { if (x < 0.0f) {
normal.mul(-1.0f); normal.scale(-1.0f);
} }
return this; return this;
@ -86,7 +82,7 @@ public class TransformedInstance extends ColoredLitInstance implements Transform
float invY = 1.0f / y; float invY = 1.0f / y;
float invZ = 1.0f / z; float invZ = 1.0f / z;
float f = Mth.fastInvCubeRoot(Math.abs(invX * invY * invZ)); 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; return this;
} }
@ -94,7 +90,7 @@ public class TransformedInstance extends ColoredLitInstance implements Transform
public TransformedInstance translate(double x, double y, double z) { public TransformedInstance translate(double x, double y, double z) {
setChanged(); setChanged();
model.multiplyWithTranslation((float) x, (float) y, (float) z); model.translate((float) x, (float) y, (float) z);
return this; return this;
} }
@ -102,7 +98,7 @@ public class TransformedInstance extends ColoredLitInstance implements Transform
public TransformedInstance mulPose(Matrix4f pose) { public TransformedInstance mulPose(Matrix4f pose) {
setChanged(); setChanged();
model.multiply(pose); this.model.mul(pose);
return this; return this;
} }
@ -110,7 +106,7 @@ public class TransformedInstance extends ColoredLitInstance implements Transform
public TransformedInstance mulNormal(Matrix3f normal) { public TransformedInstance mulNormal(Matrix3f normal) {
setChanged(); setChanged();
normal.mul(normal); this.normal.mul(normal);
return this; return this;
} }
} }

View file

@ -5,139 +5,88 @@ import static org.joml.Math.fma;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import org.joml.Math; import org.joml.Math;
import org.joml.Matrix3f;
import org.joml.Matrix4f;
import org.lwjgl.system.MemoryUtil; 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 final class MatrixUtil {
public static float transformPositionX(Matrix4f matrix, float x, float y, float z) { public static float transformPositionX(Matrix4f matrix, float x, float y, float z) {
Matrix4fAccessor m = (Matrix4fAccessor) (Object) matrix; return fma(matrix.m00(), x, fma(matrix.m01(), y, fma(matrix.m02(), z, matrix.m03())));
return fma(m.flywheel$m00(), x, fma(m.flywheel$m01(), y, fma(m.flywheel$m02(), z, m.flywheel$m03())));
} }
public static float transformPositionY(Matrix4f matrix, float x, float y, float z) { public static float transformPositionY(Matrix4f matrix, float x, float y, float z) {
Matrix4fAccessor m = (Matrix4fAccessor) (Object) matrix; return fma(matrix.m10(), x, fma(matrix.m11(), y, fma(matrix.m12(), z, matrix.m13())));
return fma(m.flywheel$m10(), x, fma(m.flywheel$m11(), y, fma(m.flywheel$m12(), z, m.flywheel$m13())));
} }
public static float transformPositionZ(Matrix4f matrix, float x, float y, float z) { public static float transformPositionZ(Matrix4f matrix, float x, float y, float z) {
Matrix4fAccessor m = (Matrix4fAccessor) (Object) matrix; return fma(matrix.m20(), x, fma(matrix.m21(), y, fma(matrix.m22(), z, matrix.m23())));
return fma(m.flywheel$m20(), x, fma(m.flywheel$m21(), y, fma(m.flywheel$m22(), z, m.flywheel$m23())));
} }
public static float transformNormalX(Matrix3f matrix, float x, float y, float z) { public static float transformNormalX(Matrix3f matrix, float x, float y, float z) {
Matrix3fAccessor m = (Matrix3fAccessor) (Object) matrix; return fma(matrix.m00(), x, fma(matrix.m01(), y, matrix.m02() * z));
return fma(m.flywheel$m00(), x, fma(m.flywheel$m01(), y, m.flywheel$m02() * z));
} }
public static float transformNormalY(Matrix3f matrix, float x, float y, float z) { public static float transformNormalY(Matrix3f matrix, float x, float y, float z) {
Matrix3fAccessor m = (Matrix3fAccessor) (Object) matrix; return fma(matrix.m10(), x, fma(matrix.m11(), y, matrix.m12() * z));
return fma(m.flywheel$m10(), x, fma(m.flywheel$m11(), y, m.flywheel$m12() * z));
} }
public static float transformNormalZ(Matrix3f matrix, float x, float y, float z) { public static float transformNormalZ(Matrix3f matrix, float x, float y, float z) {
Matrix3fAccessor m = (Matrix3fAccessor) (Object) matrix; return fma(matrix.m20(), x, fma(matrix.m21(), y, matrix.m22() * z));
return fma(m.flywheel$m20(), x, fma(m.flywheel$m21(), y, m.flywheel$m22() * z));
} }
public static void write(Matrix4f matrix, ByteBuffer buf) { public static void write(Matrix4f matrix, ByteBuffer buf) {
Matrix4fAccessor m = (Matrix4fAccessor) (Object) matrix; matrix.get(buf);
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());
} }
public static void writeUnsafe(Matrix4f matrix, long ptr) { public static void writeUnsafe(Matrix4f matrix, long ptr) {
Matrix4fAccessor m = (Matrix4fAccessor) (Object) matrix; MemoryUtil.memPutFloat(ptr, matrix.m00());
MemoryUtil.memPutFloat(ptr, m.flywheel$m00()); MemoryUtil.memPutFloat(ptr + 4, matrix.m10());
MemoryUtil.memPutFloat(ptr + 4, m.flywheel$m10()); MemoryUtil.memPutFloat(ptr + 8, matrix.m20());
MemoryUtil.memPutFloat(ptr + 8, m.flywheel$m20()); MemoryUtil.memPutFloat(ptr + 12, matrix.m30());
MemoryUtil.memPutFloat(ptr + 12, m.flywheel$m30()); MemoryUtil.memPutFloat(ptr + 16, matrix.m01());
MemoryUtil.memPutFloat(ptr + 16, m.flywheel$m01()); MemoryUtil.memPutFloat(ptr + 20, matrix.m11());
MemoryUtil.memPutFloat(ptr + 20, m.flywheel$m11()); MemoryUtil.memPutFloat(ptr + 24, matrix.m21());
MemoryUtil.memPutFloat(ptr + 24, m.flywheel$m21()); MemoryUtil.memPutFloat(ptr + 28, matrix.m31());
MemoryUtil.memPutFloat(ptr + 28, m.flywheel$m31()); MemoryUtil.memPutFloat(ptr + 32, matrix.m02());
MemoryUtil.memPutFloat(ptr + 32, m.flywheel$m02()); MemoryUtil.memPutFloat(ptr + 36, matrix.m12());
MemoryUtil.memPutFloat(ptr + 36, m.flywheel$m12()); MemoryUtil.memPutFloat(ptr + 40, matrix.m22());
MemoryUtil.memPutFloat(ptr + 40, m.flywheel$m22()); MemoryUtil.memPutFloat(ptr + 44, matrix.m32());
MemoryUtil.memPutFloat(ptr + 44, m.flywheel$m32()); MemoryUtil.memPutFloat(ptr + 48, matrix.m03());
MemoryUtil.memPutFloat(ptr + 48, m.flywheel$m03()); MemoryUtil.memPutFloat(ptr + 52, matrix.m13());
MemoryUtil.memPutFloat(ptr + 52, m.flywheel$m13()); MemoryUtil.memPutFloat(ptr + 56, matrix.m23());
MemoryUtil.memPutFloat(ptr + 56, m.flywheel$m23()); MemoryUtil.memPutFloat(ptr + 60, matrix.m33());
MemoryUtil.memPutFloat(ptr + 60, m.flywheel$m33());
} }
public static void write(Matrix3f matrix, ByteBuffer buf) { public static void write(Matrix3f matrix, ByteBuffer buf) {
Matrix3fAccessor m = (Matrix3fAccessor) (Object) matrix; matrix.get(buf);
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());
} }
public static void writeUnsafe(Matrix3f matrix, long ptr) { public static void writeUnsafe(Matrix3f matrix, long ptr) {
Matrix3fAccessor m = (Matrix3fAccessor) (Object) matrix; MemoryUtil.memPutFloat(ptr, matrix.m00());
MemoryUtil.memPutFloat(ptr, m.flywheel$m00()); MemoryUtil.memPutFloat(ptr + 4, matrix.m10());
MemoryUtil.memPutFloat(ptr + 4, m.flywheel$m10()); MemoryUtil.memPutFloat(ptr + 8, matrix.m20());
MemoryUtil.memPutFloat(ptr + 8, m.flywheel$m20()); MemoryUtil.memPutFloat(ptr + 12, matrix.m01());
MemoryUtil.memPutFloat(ptr + 12, m.flywheel$m01()); MemoryUtil.memPutFloat(ptr + 16, matrix.m11());
MemoryUtil.memPutFloat(ptr + 16, m.flywheel$m11()); MemoryUtil.memPutFloat(ptr + 20, matrix.m21());
MemoryUtil.memPutFloat(ptr + 20, m.flywheel$m21()); MemoryUtil.memPutFloat(ptr + 24, matrix.m02());
MemoryUtil.memPutFloat(ptr + 24, m.flywheel$m02()); MemoryUtil.memPutFloat(ptr + 28, matrix.m12());
MemoryUtil.memPutFloat(ptr + 28, m.flywheel$m12()); MemoryUtil.memPutFloat(ptr + 32, matrix.m22());
MemoryUtil.memPutFloat(ptr + 32, m.flywheel$m22());
} }
public static void store(Matrix4f matrix, org.joml.Matrix4f jomlMatrix) { public static void store(Matrix4f matrix, Matrix4f jomlMatrix) {
Matrix4fAccessor m = (Matrix4fAccessor) (Object) matrix; jomlMatrix.set(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 org.joml.Matrix4f toJoml(Matrix4f matrix) { public static Matrix4f toJoml(Matrix4f matrix) {
Matrix4fAccessor m = (Matrix4fAccessor) (Object) matrix; return new Matrix4f(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 void store(Matrix3f matrix, org.joml.Matrix3f jomlMatrix) { public static void store(Matrix3f matrix, org.joml.Matrix3f jomlMatrix) {
Matrix3fAccessor m = (Matrix3fAccessor) (Object) matrix; jomlMatrix.set(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());
} }
public static org.joml.Matrix3f toJoml(Matrix3f matrix) { public static Matrix3f toJoml(Matrix3f matrix) {
Matrix3fAccessor m = (Matrix3fAccessor) (Object) matrix; return new Matrix3f(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());
} }
/** /**
@ -147,10 +96,9 @@ public final class MatrixUtil {
* @return The greatest scale factor across all axes. * @return The greatest scale factor across all axes.
*/ */
public static float extractScale(Matrix4f matrix) { public static float extractScale(Matrix4f matrix) {
Matrix4fAccessor m = (Matrix4fAccessor) (Object) matrix; float scaleSqrX = matrix.m00() * matrix.m00() + matrix.m01() * matrix.m01() + matrix.m02() * matrix.m02();
float scaleSqrX = m.flywheel$m00() * m.flywheel$m00() + m.flywheel$m01() * m.flywheel$m01() + m.flywheel$m02() * m.flywheel$m02(); float scaleSqrY = matrix.m10() * matrix.m10() + matrix.m11() * matrix.m11() + matrix.m12() * matrix.m12();
float scaleSqrY = m.flywheel$m10() * m.flywheel$m10() + m.flywheel$m11() * m.flywheel$m11() + m.flywheel$m12() * m.flywheel$m12(); float scaleSqrZ = matrix.m20() * matrix.m20() + matrix.m21() * matrix.m21() + matrix.m22() * matrix.m22();
float scaleSqrZ = m.flywheel$m20() * m.flywheel$m20() + m.flywheel$m21() * m.flywheel$m21() + m.flywheel$m22() * m.flywheel$m22(); return Math.sqrt(Math.max(Math.max(scaleSqrX, scaleSqrY), scaleSqrZ));
return (float) Math.sqrt(Math.max(Math.max(scaleSqrX, scaleSqrY), scaleSqrZ));
} }
} }

View file

@ -1,19 +1,19 @@
package com.jozufozu.flywheel.lib.transform; package com.jozufozu.flywheel.lib.transform;
import com.mojang.math.Quaternion; import org.joml.AxisAngle4f;
import com.mojang.math.Vector3f; import org.joml.Quaternionf;
import org.joml.Vector3f;
import net.minecraft.core.Direction; import net.minecraft.core.Direction;
public interface Rotate<Self> { public interface Rotate<Self> {
Self multiply(Quaternion quaternion); Self multiply(Quaternionf quaternion);
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
default Self rotate(Direction axis, float radians) { default Self rotate(Direction axis, float radians) {
if (radians == 0) if (radians == 0)
return (Self) this; return (Self) this;
return multiply(axis.step() return multiplyRadians(axis.step(), radians);
.rotation(radians));
} }
default Self rotate(double angle, Direction.Axis axis) { default Self rotate(double angle, Direction.Axis axis) {
@ -57,7 +57,7 @@ public interface Rotate<Self> {
default Self multiplyRadians(Vector3f axis, double angle) { default Self multiplyRadians(Vector3f axis, double angle) {
if (angle == 0) if (angle == 0)
return (Self) this; return (Self) this;
return multiply(axis.rotation((float) angle)); return multiply(new Quaternionf(new AxisAngle4f((float) angle, axis)));
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")

View file

@ -1,9 +1,10 @@
package com.jozufozu.flywheel.lib.transform; 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.blaze3d.vertex.PoseStack;
import com.mojang.math.Matrix3f;
import com.mojang.math.Matrix4f;
import com.mojang.math.Quaternion;
import net.minecraft.core.Direction; import net.minecraft.core.Direction;
@ -30,7 +31,7 @@ public interface Transform<Self extends Transform<Self>> extends Translate<Self>
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
default Self rotateCentered(Quaternion q) { default Self rotateCentered(Quaternionf q) {
translate(.5f, .5f, .5f).multiply(q) translate(.5f, .5f, .5f).multiply(q)
.translate(-.5f, -.5f, -.5f); .translate(-.5f, -.5f, -.5f);
return (Self) this; return (Self) this;

View file

@ -1,6 +1,6 @@
package com.jozufozu.flywheel.lib.transform; package com.jozufozu.flywheel.lib.transform;
import com.mojang.math.Vector3f; import org.joml.Vector3f;
import net.minecraft.core.Vec3i; import net.minecraft.core.Vec3i;
import net.minecraft.world.phys.Vec3; import net.minecraft.world.phys.Vec3;

View file

@ -2,6 +2,7 @@ package com.jozufozu.flywheel.lib.uniform;
import java.util.function.Consumer; import java.util.function.Consumer;
import org.joml.Matrix4f;
import org.lwjgl.system.MemoryUtil; import org.lwjgl.system.MemoryUtil;
import com.jozufozu.flywheel.Flywheel; import com.jozufozu.flywheel.Flywheel;
@ -83,9 +84,8 @@ public class FlwShaderUniforms implements ShaderUniforms {
var camZ = (float) (camera.z - renderOrigin.getZ()); var camZ = (float) (camera.z - renderOrigin.getZ());
// don't want to mutate viewProjection // don't want to mutate viewProjection
var vp = context.viewProjection() var vp = new Matrix4f(context.viewProjection());
.copy(); vp.translate(-camX, -camY, -camZ);
vp.multiplyWithTranslation(-camX, -camY, -camZ);
MatrixUtil.writeUnsafe(vp, ptr + 32); MatrixUtil.writeUnsafe(vp, ptr + 32);
MemoryUtil.memPutFloat(ptr + 96, camX); MemoryUtil.memPutFloat(ptr + 96, camX);

View file

@ -25,11 +25,11 @@ public final class FlwUtil {
PoseStack copy = new PoseStack(); PoseStack copy = new PoseStack();
copy.last() copy.last()
.pose() .pose()
.load(stack.last() .set(stack.last()
.pose()); .pose());
copy.last() copy.last()
.normal() .normal()
.load(stack.last() .set(stack.last()
.normal()); .normal());
return copy; return copy;
} }

View file

@ -14,7 +14,7 @@ import com.google.common.cache.CacheLoader;
import com.google.common.cache.LoadingCache; import com.google.common.cache.LoadingCache;
import net.minecraft.world.level.LevelAccessor; import net.minecraft.world.level.LevelAccessor;
import net.minecraftforge.event.world.WorldEvent; import net.minecraftforge.event.level.LevelEvent;
public final class LevelAttached<T> { public final class LevelAttached<T> {
private static final ConcurrentLinkedDeque<WeakReference<LevelAttached<?>>> ALL = new ConcurrentLinkedDeque<>(); private static final ConcurrentLinkedDeque<WeakReference<LevelAttached<?>>> ALL = new ConcurrentLinkedDeque<>();
@ -43,8 +43,8 @@ public final class LevelAttached<T> {
} }
@ApiStatus.Internal @ApiStatus.Internal
public static void onUnloadLevel(WorldEvent.Unload event) { public static void onUnloadLevel(LevelEvent.Unload event) {
invalidateLevel(event.getWorld()); invalidateLevel(event.getLevel());
} }
public static void invalidateLevel(LevelAccessor level) { public static void invalidateLevel(LevelAccessor level) {

View file

@ -1,9 +1,10 @@
package com.jozufozu.flywheel.lib.vertex; 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.api.vertex.MutableVertexList;
import com.jozufozu.flywheel.lib.math.MatrixUtil; import com.jozufozu.flywheel.lib.math.MatrixUtil;
import com.mojang.math.Matrix3f;
import com.mojang.math.Matrix4f;
public final class VertexTransformations { public final class VertexTransformations {
private VertexTransformations() { private VertexTransformations() {

View file

@ -1,6 +1,7 @@
package com.jozufozu.flywheel.lib.visual; package com.jozufozu.flywheel.lib.visual;
import org.joml.FrustumIntersection; import org.joml.FrustumIntersection;
import org.joml.Vector3f;
import com.jozufozu.flywheel.api.visual.DynamicVisual; import com.jozufozu.flywheel.api.visual.DynamicVisual;
import com.jozufozu.flywheel.api.visual.EntityVisual; 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.Box;
import com.jozufozu.flywheel.lib.box.MutableBox; import com.jozufozu.flywheel.lib.box.MutableBox;
import com.jozufozu.flywheel.lib.light.TickingLightListener; import com.jozufozu.flywheel.lib.light.TickingLightListener;
import com.mojang.math.Vector3f;
import net.minecraft.util.Mth; import net.minecraft.util.Mth;
import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.Entity;
@ -38,7 +38,7 @@ public abstract class AbstractEntityVisual<T extends Entity> extends AbstractVis
protected final EntityVisibilityTester visibilityTester; protected final EntityVisibilityTester visibilityTester;
public AbstractEntityVisual(VisualizationContext ctx, T entity) { public AbstractEntityVisual(VisualizationContext ctx, T entity) {
super(ctx, entity.level); super(ctx, entity.level());
this.entity = entity; this.entity = entity;
bounds = MutableBox.from(entity.getBoundingBox()); bounds = MutableBox.from(entity.getBoundingBox());
visibilityTester = new EntityVisibilityTester(entity, ctx.renderOrigin()); visibilityTester = new EntityVisibilityTester(entity, ctx.renderOrigin());

View file

@ -1,5 +1,6 @@
package com.jozufozu.flywheel.mixin; package com.jozufozu.flywheel.mixin;
import org.joml.Matrix4f;
import org.objectweb.asm.Opcodes; import org.objectweb.asm.Opcodes;
import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin; 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.RenderStage;
import com.jozufozu.flywheel.api.event.RenderStageEvent; import com.jozufozu.flywheel.api.event.RenderStageEvent;
import com.mojang.blaze3d.vertex.PoseStack; import com.mojang.blaze3d.vertex.PoseStack;
import com.mojang.math.Matrix4f;
import net.minecraft.client.Camera; import net.minecraft.client.Camera;
import net.minecraft.client.multiplayer.ClientLevel; import net.minecraft.client.multiplayer.ClientLevel;

View file

@ -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();
}

View file

@ -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();
}

View file

@ -1,15 +1,15 @@
package com.jozufozu.flywheel.mixin.matrix; package com.jozufozu.flywheel.mixin.matrix;
import org.joml.Quaternionf;
import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Mixin;
import com.jozufozu.flywheel.lib.transform.TransformStack; import com.jozufozu.flywheel.lib.transform.TransformStack;
import com.mojang.blaze3d.vertex.PoseStack; import com.mojang.blaze3d.vertex.PoseStack;
import com.mojang.math.Quaternion;
@Mixin(PoseStack.class) @Mixin(PoseStack.class)
public abstract class PoseStackMixin implements TransformStack { public abstract class PoseStackMixin implements TransformStack {
@Override @Override
public TransformStack multiply(Quaternion quaternion) { public TransformStack multiply(Quaternionf quaternion) {
((PoseStack) (Object) this).mulPose(quaternion); ((PoseStack) (Object) this).mulPose(quaternion);
return this; return this;
} }

View file

@ -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<BlockEntity> blockEntities) {
}
}

View file

@ -2,6 +2,10 @@ package com.jozufozu.flywheel.vanilla;
import java.util.List; 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.event.RenderStage;
import com.jozufozu.flywheel.api.instance.Instance; import com.jozufozu.flywheel.api.instance.Instance;
import com.jozufozu.flywheel.api.visual.DynamicVisual; 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.SimpleModel;
import com.jozufozu.flywheel.lib.model.part.ModelPartConverter; import com.jozufozu.flywheel.lib.model.part.ModelPartConverter;
import com.jozufozu.flywheel.lib.visual.AbstractBlockEntityVisual; 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.model.geom.ModelLayers;
import net.minecraft.client.renderer.blockentity.BellRenderer; import net.minecraft.client.renderer.blockentity.BellRenderer;
@ -73,9 +75,9 @@ public class BellVisual extends AbstractBlockEntityVisual<BellBlockEntity> imple
Vector3f ringAxis = blockEntity.clickDirection.getCounterClockWise() Vector3f ringAxis = blockEntity.clickDirection.getCounterClockWise()
.step(); .step();
bell.setRotation(ringAxis.rotation(angle)); bell.setRotation(new Quaternionf(new AxisAngle4f(angle, ringAxis)));
} else { } else {
bell.setRotation(Quaternion.ONE); bell.setRotation(new Quaternionf());
} }
} }

View file

@ -5,6 +5,8 @@ import java.util.EnumMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import org.joml.Quaternionf;
import com.jozufozu.flywheel.api.event.RenderStage; import com.jozufozu.flywheel.api.event.RenderStage;
import com.jozufozu.flywheel.api.instance.Instance; import com.jozufozu.flywheel.api.instance.Instance;
import com.jozufozu.flywheel.api.visual.DynamicVisual; 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.model.part.ModelPartConverter;
import com.jozufozu.flywheel.lib.util.Pair; import com.jozufozu.flywheel.lib.util.Pair;
import com.jozufozu.flywheel.lib.visual.AbstractBlockEntityVisual; 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 it.unimi.dsi.fastutil.floats.Float2FloatFunction;
import net.minecraft.client.model.geom.ModelLayerLocation; import net.minecraft.client.model.geom.ModelLayerLocation;
@ -60,7 +60,7 @@ public class ChestVisual<T extends BlockEntity & LidBlockEntity> extends Abstrac
private ChestType chestType; private ChestType chestType;
private Material texture; private Material texture;
private Quaternion baseRotation; private Quaternionf baseRotation;
private Float2FloatFunction lidProgress; private Float2FloatFunction lidProgress;
private float lastProgress = Float.NaN; private float lastProgress = Float.NaN;

View file

@ -15,7 +15,6 @@ import com.jozufozu.flywheel.lib.model.SimpleModel;
import com.jozufozu.flywheel.lib.model.part.ModelPartConverter; import com.jozufozu.flywheel.lib.model.part.ModelPartConverter;
import com.jozufozu.flywheel.lib.visual.AbstractEntityVisual; import com.jozufozu.flywheel.lib.visual.AbstractEntityVisual;
import com.mojang.blaze3d.vertex.PoseStack; import com.mojang.blaze3d.vertex.PoseStack;
import com.mojang.math.Vector3f;
import net.minecraft.client.model.geom.ModelLayers; import net.minecraft.client.model.geom.ModelLayers;
import net.minecraft.util.Mth; import net.minecraft.util.Mth;

View file

@ -2,6 +2,8 @@ package com.jozufozu.flywheel.vanilla;
import java.util.List; import java.util.List;
import org.joml.Quaternionf;
import com.jozufozu.flywheel.api.event.RenderStage; import com.jozufozu.flywheel.api.event.RenderStage;
import com.jozufozu.flywheel.api.instance.Instance; import com.jozufozu.flywheel.api.instance.Instance;
import com.jozufozu.flywheel.api.visual.DynamicVisual; 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.transform.TransformStack;
import com.jozufozu.flywheel.lib.visual.AbstractBlockEntityVisual; import com.jozufozu.flywheel.lib.visual.AbstractBlockEntityVisual;
import com.mojang.blaze3d.vertex.PoseStack; 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.model.geom.ModelLayers;
import net.minecraft.client.renderer.Sheets; import net.minecraft.client.renderer.Sheets;
@ -56,7 +56,7 @@ public class ShulkerBoxVisual extends AbstractBlockEntityVisual<ShulkerBoxBlockE
texture = Sheets.SHULKER_TEXTURE_LOCATION.get(color.getId()); texture = Sheets.SHULKER_TEXTURE_LOCATION.get(color.getId());
} }
Quaternion rotation = getDirection().getRotation(); var rotation = getDirection().getRotation();
TransformStack tstack = TransformStack.cast(stack); TransformStack tstack = TransformStack.cast(stack);
tstack.translate(getVisualPosition()) tstack.translate(getVisualPosition())
@ -102,7 +102,7 @@ public class ShulkerBoxVisual extends AbstractBlockEntityVisual<ShulkerBoxBlockE
} }
lastProgress = progress; lastProgress = progress;
Quaternion spin = Vector3f.YP.rotationDegrees(270.0f * progress); Quaternionf spin = Vector3f.YP.rotationDegrees(270.0f * progress);
TransformStack.cast(stack) TransformStack.cast(stack)
.pushPose() .pushPose()

View file

@ -19,8 +19,6 @@
"VertexFormatMixin", "VertexFormatMixin",
"fix.FixFabulousDepthMixin", "fix.FixFabulousDepthMixin",
"fix.FixNormalScalingMixin", "fix.FixNormalScalingMixin",
"matrix.Matrix3fAccessor",
"matrix.Matrix4fAccessor",
"matrix.PoseStackMixin", "matrix.PoseStackMixin",
"visualmanage.ChunkRebuildHooksMixin", "visualmanage.ChunkRebuildHooksMixin",
"visualmanage.VisualAddMixin", "visualmanage.VisualAddMixin",

View file

@ -6,8 +6,7 @@
"refmap": "flywheel.refmap.json", "refmap": "flywheel.refmap.json",
"plugin": "com.jozufozu.flywheel.compat.SodiumMixinPlugin", "plugin": "com.jozufozu.flywheel.compat.SodiumMixinPlugin",
"client": [ "client": [
"ChunkRenderRebuildTaskMixin", "ChunkRenderRebuildTaskMixin"
"FlywheelCompatMixin"
], ],
"injectors": { "injectors": {
"defaultRequire": 1 "defaultRequire": 1