diff --git a/build.gradle b/build.gradle
index 928e603ea..36053f7a1 100644
--- a/build.gradle
+++ b/build.gradle
@@ -94,8 +94,9 @@ test {
mixin {
add sourceSets.main, 'flywheel.refmap.json'
- config 'flywheel.mixins.json'
- config 'flywheel.sodium.mixins.json'
+ config 'flywheel.backend.mixins.json'
+ config 'flywheel.impl.mixins.json'
+ config 'flywheel.impl.sodium.mixins.json'
debug.verbose = true
debug.export = true
diff --git a/src/main/java/com/jozufozu/flywheel/Flywheel.java b/src/main/java/com/jozufozu/flywheel/Flywheel.java
index 38a0ea375..10ff45ee9 100644
--- a/src/main/java/com/jozufozu/flywheel/Flywheel.java
+++ b/src/main/java/com/jozufozu/flywheel/Flywheel.java
@@ -16,8 +16,8 @@ import com.jozufozu.flywheel.config.BackendArgument;
import com.jozufozu.flywheel.config.FlwCommands;
import com.jozufozu.flywheel.config.FlwConfig;
import com.jozufozu.flywheel.impl.BackendManagerImpl;
-import com.jozufozu.flywheel.impl.IdRegistryImpl;
-import com.jozufozu.flywheel.impl.RegistryImpl;
+import com.jozufozu.flywheel.impl.registry.IdRegistryImpl;
+import com.jozufozu.flywheel.impl.registry.RegistryImpl;
import com.jozufozu.flywheel.impl.visualization.VisualizationEventHandler;
import com.jozufozu.flywheel.lib.context.Contexts;
import com.jozufozu.flywheel.lib.instance.InstanceTypes;
diff --git a/src/main/java/com/jozufozu/flywheel/api/backend/Backend.java b/src/main/java/com/jozufozu/flywheel/api/backend/Backend.java
index 8a23cb5c0..31dce2dce 100644
--- a/src/main/java/com/jozufozu/flywheel/api/backend/Backend.java
+++ b/src/main/java/com/jozufozu/flywheel/api/backend/Backend.java
@@ -1,15 +1,15 @@
package com.jozufozu.flywheel.api.backend;
import com.jozufozu.flywheel.api.BackendImplemented;
+import com.jozufozu.flywheel.api.internal.InternalFlywheelApi;
import com.jozufozu.flywheel.api.registry.IdRegistry;
-import com.jozufozu.flywheel.impl.IdRegistryImpl;
import net.minecraft.network.chat.Component;
import net.minecraft.world.level.LevelAccessor;
@BackendImplemented
public interface Backend {
- static IdRegistry REGISTRY = IdRegistryImpl.create();
+ static IdRegistry REGISTRY = InternalFlywheelApi.INSTANCE.createIdRegistry();
/**
* Get a message to display to the user when the engine is enabled.
diff --git a/src/main/java/com/jozufozu/flywheel/api/backend/BackendManager.java b/src/main/java/com/jozufozu/flywheel/api/backend/BackendManager.java
index d8778c867..bf6e7d751 100644
--- a/src/main/java/com/jozufozu/flywheel/api/backend/BackendManager.java
+++ b/src/main/java/com/jozufozu/flywheel/api/backend/BackendManager.java
@@ -1,27 +1,27 @@
package com.jozufozu.flywheel.api.backend;
-import com.jozufozu.flywheel.impl.BackendManagerImpl;
+import com.jozufozu.flywheel.api.internal.InternalFlywheelApi;
public final class BackendManager {
+ private BackendManager() {
+ }
+
/**
* Get the current backend.
*/
public static Backend getBackend() {
- return BackendManagerImpl.getBackend();
+ return InternalFlywheelApi.INSTANCE.getBackend();
}
- public static boolean isOn() {
- return BackendManagerImpl.isOn();
+ public static boolean isBackendOn() {
+ return InternalFlywheelApi.INSTANCE.isBackendOn();
}
public static Backend getOffBackend() {
- return BackendManagerImpl.getOffBackend();
+ return InternalFlywheelApi.INSTANCE.getOffBackend();
}
public static Backend getDefaultBackend() {
- return BackendManagerImpl.getDefaultBackend();
- }
-
- private BackendManager() {
+ return InternalFlywheelApi.INSTANCE.getDefaultBackend();
}
}
diff --git a/src/main/java/com/jozufozu/flywheel/api/context/Context.java b/src/main/java/com/jozufozu/flywheel/api/context/Context.java
index 7e448e596..769fb0c80 100644
--- a/src/main/java/com/jozufozu/flywheel/api/context/Context.java
+++ b/src/main/java/com/jozufozu/flywheel/api/context/Context.java
@@ -1,13 +1,13 @@
package com.jozufozu.flywheel.api.context;
+import com.jozufozu.flywheel.api.internal.InternalFlywheelApi;
import com.jozufozu.flywheel.api.registry.Registry;
import com.jozufozu.flywheel.backend.gl.shader.GlProgram;
-import com.jozufozu.flywheel.impl.RegistryImpl;
import net.minecraft.resources.ResourceLocation;
public interface Context {
- static Registry REGISTRY = RegistryImpl.create();
+ static Registry REGISTRY = InternalFlywheelApi.INSTANCE.createRegistry();
void onProgramLink(GlProgram program);
diff --git a/src/main/java/com/jozufozu/flywheel/api/instance/InstanceType.java b/src/main/java/com/jozufozu/flywheel/api/instance/InstanceType.java
index 3bc8a04a1..189d12906 100644
--- a/src/main/java/com/jozufozu/flywheel/api/instance/InstanceType.java
+++ b/src/main/java/com/jozufozu/flywheel/api/instance/InstanceType.java
@@ -1,8 +1,8 @@
package com.jozufozu.flywheel.api.instance;
+import com.jozufozu.flywheel.api.internal.InternalFlywheelApi;
import com.jozufozu.flywheel.api.layout.Layout;
import com.jozufozu.flywheel.api.registry.Registry;
-import com.jozufozu.flywheel.impl.RegistryImpl;
import net.minecraft.resources.ResourceLocation;
@@ -12,7 +12,7 @@ import net.minecraft.resources.ResourceLocation;
* @param The java representation of the instance.
*/
public interface InstanceType {
- static Registry> REGISTRY = RegistryImpl.create();
+ static Registry> REGISTRY = InternalFlywheelApi.INSTANCE.createRegistry();
/**
* @param handle A handle that allows you to mark the instance as dirty or deleted.
diff --git a/src/main/java/com/jozufozu/flywheel/api/internal/InternalFlywheelApi.java b/src/main/java/com/jozufozu/flywheel/api/internal/InternalFlywheelApi.java
new file mode 100644
index 000000000..72c368630
--- /dev/null
+++ b/src/main/java/com/jozufozu/flywheel/api/internal/InternalFlywheelApi.java
@@ -0,0 +1,99 @@
+package com.jozufozu.flywheel.api.internal;
+
+import java.lang.reflect.Constructor;
+
+import org.jetbrains.annotations.Nullable;
+
+import com.jozufozu.flywheel.api.backend.Backend;
+import com.jozufozu.flywheel.api.layout.LayoutBuilder;
+import com.jozufozu.flywheel.api.registry.IdRegistry;
+import com.jozufozu.flywheel.api.registry.Registry;
+import com.jozufozu.flywheel.api.vertex.VertexViewProvider;
+import com.jozufozu.flywheel.api.visualization.BlockEntityVisualizer;
+import com.jozufozu.flywheel.api.visualization.EntityVisualizer;
+import com.jozufozu.flywheel.api.visualization.VisualizationManager;
+import com.jozufozu.flywheel.lib.transform.PoseTransformStack;
+import com.mojang.blaze3d.vertex.PoseStack;
+import com.mojang.blaze3d.vertex.VertexFormat;
+
+import net.minecraft.world.entity.Entity;
+import net.minecraft.world.entity.EntityType;
+import net.minecraft.world.level.LevelAccessor;
+import net.minecraft.world.level.block.entity.BlockEntity;
+import net.minecraft.world.level.block.entity.BlockEntityType;
+
+public interface InternalFlywheelApi {
+ InternalFlywheelApi INSTANCE = load();
+
+ // Adapted from https://github.com/CaffeineMC/sodium-fabric/blob/bf4fc9dab16e1cca07b2f23a1201c9bf237c8044/src/api/java/net/caffeinemc/mods/sodium/api/internal/DependencyInjection.java
+ private static InternalFlywheelApi load() {
+ Class apiClass = InternalFlywheelApi.class;
+ Class> implClass;
+
+ try {
+ implClass = Class.forName("com.jozufozu.flywheel.impl.InternalFlywheelImpl");
+ } catch (ReflectiveOperationException e) {
+ throw new RuntimeException("Could not find implementation", e);
+ }
+
+ if (!apiClass.isAssignableFrom(implClass)) {
+ throw new RuntimeException("Class %s does not implement interface %s"
+ .formatted(implClass.getName(), apiClass.getName()));
+ }
+
+ Constructor> implConstructor;
+
+ try {
+ implConstructor = implClass.getConstructor();
+ } catch (ReflectiveOperationException e) {
+ throw new RuntimeException("Could not find default constructor", e);
+ }
+
+ Object implInstance;
+
+ try {
+ implInstance = implConstructor.newInstance();
+ } catch (ReflectiveOperationException e) {
+ throw new RuntimeException("Could not instantiate implementation", e);
+ }
+
+ return apiClass.cast(implInstance);
+ }
+
+ Registry createRegistry();
+
+ IdRegistry createIdRegistry();
+
+ Backend getBackend();
+
+ boolean isBackendOn();
+
+ Backend getOffBackend();
+
+ Backend getDefaultBackend();
+
+ LayoutBuilder createLayoutBuilder();
+
+ VertexViewProvider getVertexViewProvider(VertexFormat format);
+
+ void setVertexViewProvider(VertexFormat format, VertexViewProvider provider);
+
+ boolean supportsVisualization(@Nullable LevelAccessor level);
+
+ @Nullable
+ VisualizationManager getVisualizationManager(@Nullable LevelAccessor level);
+
+ VisualizationManager getVisualizationManagerOrThrow(@Nullable LevelAccessor level);
+
+ @Nullable
+ BlockEntityVisualizer super T> getVisualizer(BlockEntityType type);
+
+ @Nullable
+ EntityVisualizer super T> getVisualizer(EntityType type);
+
+ void setVisualizer(BlockEntityType type, BlockEntityVisualizer super T> visualizer);
+
+ void setVisualizer(EntityType type, EntityVisualizer super T> visualizer);
+
+ PoseTransformStack getPoseTransformStackOf(PoseStack stack);
+}
diff --git a/src/main/java/com/jozufozu/flywheel/api/internal/package-info.java b/src/main/java/com/jozufozu/flywheel/api/internal/package-info.java
new file mode 100644
index 000000000..dd1e31fc1
--- /dev/null
+++ b/src/main/java/com/jozufozu/flywheel/api/internal/package-info.java
@@ -0,0 +1,12 @@
+@ApiStatus.Internal
+@ParametersAreNonnullByDefault
+@FieldsAreNonnullByDefault
+@MethodsReturnNonnullByDefault
+package com.jozufozu.flywheel.api.internal;
+
+import javax.annotation.ParametersAreNonnullByDefault;
+
+import org.jetbrains.annotations.ApiStatus;
+
+import net.minecraft.FieldsAreNonnullByDefault;
+import net.minecraft.MethodsReturnNonnullByDefault;
diff --git a/src/main/java/com/jozufozu/flywheel/api/layout/LayoutBuilder.java b/src/main/java/com/jozufozu/flywheel/api/layout/LayoutBuilder.java
index 30bd44069..c001316ff 100644
--- a/src/main/java/com/jozufozu/flywheel/api/layout/LayoutBuilder.java
+++ b/src/main/java/com/jozufozu/flywheel/api/layout/LayoutBuilder.java
@@ -3,7 +3,7 @@ package com.jozufozu.flywheel.api.layout;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.Range;
-import com.jozufozu.flywheel.impl.layout.LayoutBuilderImpl;
+import com.jozufozu.flywheel.api.internal.InternalFlywheelApi;
@ApiStatus.NonExtendable
public interface LayoutBuilder {
@@ -18,6 +18,6 @@ public interface LayoutBuilder {
Layout build();
static LayoutBuilder create() {
- return new LayoutBuilderImpl();
+ return InternalFlywheelApi.INSTANCE.createLayoutBuilder();
}
}
diff --git a/src/main/java/com/jozufozu/flywheel/api/material/CutoutShader.java b/src/main/java/com/jozufozu/flywheel/api/material/CutoutShader.java
index 70d397c8a..be469762f 100644
--- a/src/main/java/com/jozufozu/flywheel/api/material/CutoutShader.java
+++ b/src/main/java/com/jozufozu/flywheel/api/material/CutoutShader.java
@@ -1,12 +1,12 @@
package com.jozufozu.flywheel.api.material;
+import com.jozufozu.flywheel.api.internal.InternalFlywheelApi;
import com.jozufozu.flywheel.api.registry.Registry;
-import com.jozufozu.flywheel.impl.RegistryImpl;
import net.minecraft.resources.ResourceLocation;
public interface CutoutShader {
- static Registry REGISTRY = RegistryImpl.create();
+ static Registry REGISTRY = InternalFlywheelApi.INSTANCE.createRegistry();
ResourceLocation source();
}
diff --git a/src/main/java/com/jozufozu/flywheel/api/material/FogShader.java b/src/main/java/com/jozufozu/flywheel/api/material/FogShader.java
index 75dfccbdb..4d891afbd 100644
--- a/src/main/java/com/jozufozu/flywheel/api/material/FogShader.java
+++ b/src/main/java/com/jozufozu/flywheel/api/material/FogShader.java
@@ -1,12 +1,12 @@
package com.jozufozu.flywheel.api.material;
+import com.jozufozu.flywheel.api.internal.InternalFlywheelApi;
import com.jozufozu.flywheel.api.registry.Registry;
-import com.jozufozu.flywheel.impl.RegistryImpl;
import net.minecraft.resources.ResourceLocation;
public interface FogShader {
- static Registry REGISTRY = RegistryImpl.create();
+ static Registry REGISTRY = InternalFlywheelApi.INSTANCE.createRegistry();
ResourceLocation source();
}
diff --git a/src/main/java/com/jozufozu/flywheel/api/material/MaterialShaders.java b/src/main/java/com/jozufozu/flywheel/api/material/MaterialShaders.java
index a158211de..6cab5f4d1 100644
--- a/src/main/java/com/jozufozu/flywheel/api/material/MaterialShaders.java
+++ b/src/main/java/com/jozufozu/flywheel/api/material/MaterialShaders.java
@@ -1,12 +1,12 @@
package com.jozufozu.flywheel.api.material;
+import com.jozufozu.flywheel.api.internal.InternalFlywheelApi;
import com.jozufozu.flywheel.api.registry.Registry;
-import com.jozufozu.flywheel.impl.RegistryImpl;
import net.minecraft.resources.ResourceLocation;
public interface MaterialShaders {
- static Registry REGISTRY = RegistryImpl.create();
+ static Registry REGISTRY = InternalFlywheelApi.INSTANCE.createRegistry();
ResourceLocation vertexShader();
diff --git a/src/main/java/com/jozufozu/flywheel/api/vertex/VertexViewProviderRegistry.java b/src/main/java/com/jozufozu/flywheel/api/vertex/VertexViewProviderRegistry.java
index c59183ed8..541e9248a 100644
--- a/src/main/java/com/jozufozu/flywheel/api/vertex/VertexViewProviderRegistry.java
+++ b/src/main/java/com/jozufozu/flywheel/api/vertex/VertexViewProviderRegistry.java
@@ -1,17 +1,17 @@
package com.jozufozu.flywheel.api.vertex;
-import com.jozufozu.flywheel.impl.vertex.VertexListProviderRegistryImpl;
+import com.jozufozu.flywheel.api.internal.InternalFlywheelApi;
import com.mojang.blaze3d.vertex.VertexFormat;
public final class VertexViewProviderRegistry {
+ private VertexViewProviderRegistry() {
+ }
+
public static VertexViewProvider getProvider(VertexFormat format) {
- return VertexListProviderRegistryImpl.getProvider(format);
+ return InternalFlywheelApi.INSTANCE.getVertexViewProvider(format);
}
public static void setProvider(VertexFormat format, VertexViewProvider provider) {
- VertexListProviderRegistryImpl.setProvider(format, provider);
- }
-
- private VertexViewProviderRegistry() {
+ InternalFlywheelApi.INSTANCE.setVertexViewProvider(format, provider);
}
}
diff --git a/src/main/java/com/jozufozu/flywheel/api/visual/VisualFrameContext.java b/src/main/java/com/jozufozu/flywheel/api/visual/VisualFrameContext.java
index 1b0aab569..84e5dff56 100644
--- a/src/main/java/com/jozufozu/flywheel/api/visual/VisualFrameContext.java
+++ b/src/main/java/com/jozufozu/flywheel/api/visual/VisualFrameContext.java
@@ -7,17 +7,11 @@ import net.minecraft.client.Camera;
@ApiStatus.NonExtendable
public interface VisualFrameContext {
- double cameraX();
-
- double cameraY();
-
- double cameraZ();
+ Camera camera();
FrustumIntersection frustum();
float partialTick();
DistanceUpdateLimiter limiter();
-
- Camera camera();
}
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 edeb95552..a9f000e89 100644
--- a/src/main/java/com/jozufozu/flywheel/api/visualization/VisualizationManager.java
+++ b/src/main/java/com/jozufozu/flywheel/api/visualization/VisualizationManager.java
@@ -3,9 +3,9 @@ package com.jozufozu.flywheel.api.visualization;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.Nullable;
+import com.jozufozu.flywheel.api.internal.InternalFlywheelApi;
import com.jozufozu.flywheel.api.visual.Effect;
import com.jozufozu.flywheel.api.visual.Visual;
-import com.jozufozu.flywheel.impl.visualization.VisualizationManagerImpl;
import net.minecraft.core.Vec3i;
import net.minecraft.world.entity.Entity;
@@ -16,16 +16,16 @@ import net.minecraft.world.level.block.entity.BlockEntity;
@ApiStatus.NonExtendable
public interface VisualizationManager {
static boolean supportsVisualization(@Nullable LevelAccessor level) {
- return VisualizationManagerImpl.supportsVisualization(level);
+ return InternalFlywheelApi.INSTANCE.supportsVisualization(level);
}
@Nullable
static VisualizationManager get(@Nullable LevelAccessor level) {
- return VisualizationManagerImpl.get(level);
+ return InternalFlywheelApi.INSTANCE.getVisualizationManager(level);
}
static VisualizationManager getOrThrow(@Nullable LevelAccessor level) {
- return VisualizationManagerImpl.getOrThrow(level);
+ return InternalFlywheelApi.INSTANCE.getVisualizationManagerOrThrow(level);
}
/**
diff --git a/src/main/java/com/jozufozu/flywheel/api/visualization/VisualizerRegistry.java b/src/main/java/com/jozufozu/flywheel/api/visualization/VisualizerRegistry.java
index 3bd1238ad..604aea42f 100644
--- a/src/main/java/com/jozufozu/flywheel/api/visualization/VisualizerRegistry.java
+++ b/src/main/java/com/jozufozu/flywheel/api/visualization/VisualizerRegistry.java
@@ -2,7 +2,7 @@ package com.jozufozu.flywheel.api.visualization;
import org.jetbrains.annotations.Nullable;
-import com.jozufozu.flywheel.impl.visualization.VisualizerRegistryImpl;
+import com.jozufozu.flywheel.api.internal.InternalFlywheelApi;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.EntityType;
@@ -10,9 +10,12 @@ import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.entity.BlockEntityType;
/**
- * A utility class for registering and retrieving {@code Visualizer}s.
+ * The registry for {@code Visualizer}s.
*/
public final class VisualizerRegistry {
+ private VisualizerRegistry() {
+ }
+
/**
* Gets the visualizer for the given block entity type, if one exists.
* @param type The block entity type to get the visualizer for.
@@ -21,7 +24,7 @@ public final class VisualizerRegistry {
*/
@Nullable
public static BlockEntityVisualizer super T> getVisualizer(BlockEntityType type) {
- return VisualizerRegistryImpl.getVisualizer(type);
+ return InternalFlywheelApi.INSTANCE.getVisualizer(type);
}
/**
@@ -32,7 +35,7 @@ public final class VisualizerRegistry {
*/
@Nullable
public static EntityVisualizer super T> getVisualizer(EntityType type) {
- return VisualizerRegistryImpl.getVisualizer(type);
+ return InternalFlywheelApi.INSTANCE.getVisualizer(type);
}
/**
@@ -42,7 +45,7 @@ public final class VisualizerRegistry {
* @param The type of the block entity.
*/
public static void setVisualizer(BlockEntityType type, BlockEntityVisualizer super T> visualizer) {
- VisualizerRegistryImpl.setVisualizer(type, visualizer);
+ InternalFlywheelApi.INSTANCE.setVisualizer(type, visualizer);
}
/**
@@ -52,9 +55,6 @@ public final class VisualizerRegistry {
* @param The type of the entity.
*/
public static void setVisualizer(EntityType type, EntityVisualizer super T> visualizer) {
- VisualizerRegistryImpl.setVisualizer(type, visualizer);
- }
-
- private VisualizerRegistry() {
+ InternalFlywheelApi.INSTANCE.setVisualizer(type, visualizer);
}
}
diff --git a/src/main/java/com/jozufozu/flywheel/backend/engine/uniform/Uniforms.java b/src/main/java/com/jozufozu/flywheel/backend/engine/uniform/Uniforms.java
index 523c3a25b..cf941ab04 100644
--- a/src/main/java/com/jozufozu/flywheel/backend/engine/uniform/Uniforms.java
+++ b/src/main/java/com/jozufozu/flywheel/backend/engine/uniform/Uniforms.java
@@ -2,6 +2,7 @@ package com.jozufozu.flywheel.backend.engine.uniform;
import com.jozufozu.flywheel.api.event.ReloadLevelRendererEvent;
import com.jozufozu.flywheel.api.event.RenderContext;
+import com.jozufozu.flywheel.backend.gl.GlStateTracker;
public class Uniforms {
public static boolean frustumPaused = false;
@@ -28,15 +29,21 @@ public class Uniforms {
bindFog();
}
+ public static void bindFrame() {
+ if (frame != null) {
+ frame.bind();
+ }
+ }
+
public static void bindFog() {
if (fog != null) {
fog.bind();
}
}
- public static void bindFrame() {
- if (frame != null) {
- frame.bind();
+ public static void onFogUpdate() {
+ try (var restoreState = GlStateTracker.getRestoreState()) {
+ fog().update();
}
}
diff --git a/src/main/java/com/jozufozu/flywheel/mixin/GlStateManagerMixin.java b/src/main/java/com/jozufozu/flywheel/backend/mixin/GlStateManagerMixin.java
similarity index 95%
rename from src/main/java/com/jozufozu/flywheel/mixin/GlStateManagerMixin.java
rename to src/main/java/com/jozufozu/flywheel/backend/mixin/GlStateManagerMixin.java
index 644098384..695e4399d 100644
--- a/src/main/java/com/jozufozu/flywheel/mixin/GlStateManagerMixin.java
+++ b/src/main/java/com/jozufozu/flywheel/backend/mixin/GlStateManagerMixin.java
@@ -1,4 +1,4 @@
-package com.jozufozu.flywheel.mixin;
+package com.jozufozu.flywheel.backend.mixin;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
diff --git a/src/main/java/com/jozufozu/flywheel/backend/mixin/RenderSystemMixin.java b/src/main/java/com/jozufozu/flywheel/backend/mixin/RenderSystemMixin.java
new file mode 100644
index 000000000..07c786b45
--- /dev/null
+++ b/src/main/java/com/jozufozu/flywheel/backend/mixin/RenderSystemMixin.java
@@ -0,0 +1,32 @@
+package com.jozufozu.flywheel.backend.mixin;
+
+import org.spongepowered.asm.mixin.Mixin;
+import org.spongepowered.asm.mixin.injection.At;
+import org.spongepowered.asm.mixin.injection.Inject;
+import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
+
+import com.jozufozu.flywheel.backend.engine.uniform.Uniforms;
+import com.mojang.blaze3d.systems.RenderSystem;
+
+@Mixin(RenderSystem.class)
+abstract class RenderSystemMixin {
+ @Inject(method = "setShaderFogStart(F)V", at = @At("RETURN"))
+ private static void flywheel$onSetFogStart(CallbackInfo ci) {
+ Uniforms.onFogUpdate();
+ }
+
+ @Inject(method = "setShaderFogEnd(F)V", at = @At("RETURN"))
+ private static void flywheel$onSetFogEnd(CallbackInfo ci) {
+ Uniforms.onFogUpdate();
+ }
+
+ @Inject(method = "setShaderFogShape(Lcom/mojang/blaze3d/shaders/FogShape;)V", at = @At("RETURN"))
+ private static void flywheel$onSetFogShape(CallbackInfo ci) {
+ Uniforms.onFogUpdate();
+ }
+
+ @Inject(method = "setShaderFogColor(FFFF)V", at = @At("RETURN"))
+ private static void flywheel$onSetFogColor(CallbackInfo ci) {
+ Uniforms.onFogUpdate();
+ }
+}
diff --git a/src/main/java/com/jozufozu/flywheel/impl/BackendManagerImpl.java b/src/main/java/com/jozufozu/flywheel/impl/BackendManagerImpl.java
index b36a8fc0b..eeb0ac378 100644
--- a/src/main/java/com/jozufozu/flywheel/impl/BackendManagerImpl.java
+++ b/src/main/java/com/jozufozu/flywheel/impl/BackendManagerImpl.java
@@ -21,7 +21,7 @@ import net.minecraftforge.fml.CrashReportCallables;
public final class BackendManagerImpl {
private static final Logger LOGGER = LogUtils.getLogger();
- private static final Backend OFF_BACKEND = SimpleBackend.builder()
+ public static final Backend OFF_BACKEND = SimpleBackend.builder()
.engineMessage(Component.literal("Disabled Flywheel")
.withStyle(ChatFormatting.RED))
.engineFactory(level -> {
@@ -30,7 +30,7 @@ public final class BackendManagerImpl {
.supported(() -> true)
.register(Flywheel.rl("off"));
- private static final Backend DEFAULT_BACKEND = findDefaultBackend();
+ public static final Backend DEFAULT_BACKEND = findDefaultBackend();
private static Backend backend = OFF_BACKEND;
@@ -41,18 +41,10 @@ public final class BackendManagerImpl {
return backend;
}
- public static boolean isOn() {
+ public static boolean isBackendOn() {
return backend != OFF_BACKEND;
}
- public static Backend getOffBackend() {
- return OFF_BACKEND;
- }
-
- public static Backend getDefaultBackend() {
- return DEFAULT_BACKEND;
- }
-
private static Backend findDefaultBackend() {
// TODO: Automatically select the best default config based on the user's driver
// TODO: Figure out how this will work if custom backends are registered and without hardcoding the default backends
diff --git a/src/main/java/com/jozufozu/flywheel/impl/InternalFlywheelImpl.java b/src/main/java/com/jozufozu/flywheel/impl/InternalFlywheelImpl.java
new file mode 100644
index 000000000..c32738e52
--- /dev/null
+++ b/src/main/java/com/jozufozu/flywheel/impl/InternalFlywheelImpl.java
@@ -0,0 +1,119 @@
+package com.jozufozu.flywheel.impl;
+
+import org.jetbrains.annotations.Nullable;
+
+import com.jozufozu.flywheel.api.backend.Backend;
+import com.jozufozu.flywheel.api.internal.InternalFlywheelApi;
+import com.jozufozu.flywheel.api.layout.LayoutBuilder;
+import com.jozufozu.flywheel.api.registry.IdRegistry;
+import com.jozufozu.flywheel.api.registry.Registry;
+import com.jozufozu.flywheel.api.vertex.VertexViewProvider;
+import com.jozufozu.flywheel.api.visualization.BlockEntityVisualizer;
+import com.jozufozu.flywheel.api.visualization.EntityVisualizer;
+import com.jozufozu.flywheel.api.visualization.VisualizationManager;
+import com.jozufozu.flywheel.impl.extension.PoseStackExtension;
+import com.jozufozu.flywheel.impl.layout.LayoutBuilderImpl;
+import com.jozufozu.flywheel.impl.registry.IdRegistryImpl;
+import com.jozufozu.flywheel.impl.registry.RegistryImpl;
+import com.jozufozu.flywheel.impl.vertex.VertexViewProviderRegistryImpl;
+import com.jozufozu.flywheel.impl.visualization.VisualizationManagerImpl;
+import com.jozufozu.flywheel.impl.visualization.VisualizerRegistryImpl;
+import com.jozufozu.flywheel.lib.transform.PoseTransformStack;
+import com.mojang.blaze3d.vertex.PoseStack;
+import com.mojang.blaze3d.vertex.VertexFormat;
+
+import net.minecraft.world.entity.Entity;
+import net.minecraft.world.entity.EntityType;
+import net.minecraft.world.level.LevelAccessor;
+import net.minecraft.world.level.block.entity.BlockEntity;
+import net.minecraft.world.level.block.entity.BlockEntityType;
+
+public final class InternalFlywheelImpl implements InternalFlywheelApi {
+ @Override
+ public Registry createRegistry() {
+ return new RegistryImpl<>();
+ }
+
+ @Override
+ public IdRegistry createIdRegistry() {
+ return new IdRegistryImpl<>();
+ }
+
+ @Override
+ public Backend getBackend() {
+ return BackendManagerImpl.getBackend();
+ }
+
+ @Override
+ public boolean isBackendOn() {
+ return BackendManagerImpl.isBackendOn();
+ }
+
+ @Override
+ public Backend getOffBackend() {
+ return BackendManagerImpl.OFF_BACKEND;
+ }
+
+ @Override
+ public Backend getDefaultBackend() {
+ return BackendManagerImpl.DEFAULT_BACKEND;
+ }
+
+ @Override
+ public LayoutBuilder createLayoutBuilder() {
+ return new LayoutBuilderImpl();
+ }
+
+ @Override
+ public VertexViewProvider getVertexViewProvider(VertexFormat format) {
+ return VertexViewProviderRegistryImpl.getProvider(format);
+ }
+
+ @Override
+ public void setVertexViewProvider(VertexFormat format, VertexViewProvider provider) {
+ VertexViewProviderRegistryImpl.setProvider(format, provider);
+ }
+
+ @Override
+ public boolean supportsVisualization(@Nullable LevelAccessor level) {
+ return VisualizationManagerImpl.supportsVisualization(level);
+ }
+
+ @Override
+ @Nullable
+ public VisualizationManager getVisualizationManager(@Nullable LevelAccessor level) {
+ return VisualizationManagerImpl.get(level);
+ }
+
+ @Override
+ public VisualizationManager getVisualizationManagerOrThrow(@Nullable LevelAccessor level) {
+ return VisualizationManagerImpl.getOrThrow(level);
+ }
+
+ @Override
+ @Nullable
+ public BlockEntityVisualizer super T> getVisualizer(BlockEntityType type) {
+ return VisualizerRegistryImpl.getVisualizer(type);
+ }
+
+ @Override
+ @Nullable
+ public EntityVisualizer super T> getVisualizer(EntityType type) {
+ return VisualizerRegistryImpl.getVisualizer(type);
+ }
+
+ @Override
+ public void setVisualizer(BlockEntityType type, BlockEntityVisualizer super T> visualizer) {
+ VisualizerRegistryImpl.setVisualizer(type, visualizer);
+ }
+
+ @Override
+ public void setVisualizer(EntityType type, EntityVisualizer super T> visualizer) {
+ VisualizerRegistryImpl.setVisualizer(type, visualizer);
+ }
+
+ @Override
+ public PoseTransformStack getPoseTransformStackOf(PoseStack stack) {
+ return ((PoseStackExtension) stack).flywheel$transformStack();
+ }
+}
diff --git a/src/main/java/com/jozufozu/flywheel/extension/BlockEntityTypeExtension.java b/src/main/java/com/jozufozu/flywheel/impl/extension/BlockEntityTypeExtension.java
similarity index 89%
rename from src/main/java/com/jozufozu/flywheel/extension/BlockEntityTypeExtension.java
rename to src/main/java/com/jozufozu/flywheel/impl/extension/BlockEntityTypeExtension.java
index e81515fe0..bff16e7ef 100644
--- a/src/main/java/com/jozufozu/flywheel/extension/BlockEntityTypeExtension.java
+++ b/src/main/java/com/jozufozu/flywheel/impl/extension/BlockEntityTypeExtension.java
@@ -1,4 +1,4 @@
-package com.jozufozu.flywheel.extension;
+package com.jozufozu.flywheel.impl.extension;
import org.jetbrains.annotations.Nullable;
diff --git a/src/main/java/com/jozufozu/flywheel/extension/EntityTypeExtension.java b/src/main/java/com/jozufozu/flywheel/impl/extension/EntityTypeExtension.java
similarity index 88%
rename from src/main/java/com/jozufozu/flywheel/extension/EntityTypeExtension.java
rename to src/main/java/com/jozufozu/flywheel/impl/extension/EntityTypeExtension.java
index b3cbe36fc..8a406a65c 100644
--- a/src/main/java/com/jozufozu/flywheel/extension/EntityTypeExtension.java
+++ b/src/main/java/com/jozufozu/flywheel/impl/extension/EntityTypeExtension.java
@@ -1,4 +1,4 @@
-package com.jozufozu.flywheel.extension;
+package com.jozufozu.flywheel.impl.extension;
import org.jetbrains.annotations.Nullable;
diff --git a/src/main/java/com/jozufozu/flywheel/extension/LevelExtension.java b/src/main/java/com/jozufozu/flywheel/impl/extension/LevelExtension.java
similarity index 94%
rename from src/main/java/com/jozufozu/flywheel/extension/LevelExtension.java
rename to src/main/java/com/jozufozu/flywheel/impl/extension/LevelExtension.java
index 3c4e7ba68..5a894cbda 100644
--- a/src/main/java/com/jozufozu/flywheel/extension/LevelExtension.java
+++ b/src/main/java/com/jozufozu/flywheel/impl/extension/LevelExtension.java
@@ -1,4 +1,4 @@
-package com.jozufozu.flywheel.extension;
+package com.jozufozu.flywheel.impl.extension;
import net.minecraft.client.multiplayer.ClientLevel;
import net.minecraft.world.entity.Entity;
diff --git a/src/main/java/com/jozufozu/flywheel/extension/PoseStackExtension.java b/src/main/java/com/jozufozu/flywheel/impl/extension/PoseStackExtension.java
similarity index 91%
rename from src/main/java/com/jozufozu/flywheel/extension/PoseStackExtension.java
rename to src/main/java/com/jozufozu/flywheel/impl/extension/PoseStackExtension.java
index f70eb5ad0..4b30bdff9 100644
--- a/src/main/java/com/jozufozu/flywheel/extension/PoseStackExtension.java
+++ b/src/main/java/com/jozufozu/flywheel/impl/extension/PoseStackExtension.java
@@ -1,4 +1,4 @@
-package com.jozufozu.flywheel.extension;
+package com.jozufozu.flywheel.impl.extension;
import com.jozufozu.flywheel.lib.transform.PoseTransformStack;
import com.mojang.blaze3d.vertex.PoseStack;
diff --git a/src/main/java/com/jozufozu/flywheel/extension/VertexFormatExtension.java b/src/main/java/com/jozufozu/flywheel/impl/extension/VertexFormatExtension.java
similarity index 90%
rename from src/main/java/com/jozufozu/flywheel/extension/VertexFormatExtension.java
rename to src/main/java/com/jozufozu/flywheel/impl/extension/VertexFormatExtension.java
index 6bdcf7d42..1d7f0a1c3 100644
--- a/src/main/java/com/jozufozu/flywheel/extension/VertexFormatExtension.java
+++ b/src/main/java/com/jozufozu/flywheel/impl/extension/VertexFormatExtension.java
@@ -1,4 +1,4 @@
-package com.jozufozu.flywheel.extension;
+package com.jozufozu.flywheel.impl.extension;
import com.jozufozu.flywheel.api.vertex.VertexViewProvider;
import com.mojang.blaze3d.vertex.VertexFormat;
@@ -9,7 +9,6 @@ import com.mojang.blaze3d.vertex.VertexFormat;
* @see VertexFormat
*/
public interface VertexFormatExtension {
-
/**
* @return The VertexViewProvider associated with this VertexFormat.
*/
diff --git a/src/main/java/com/jozufozu/flywheel/mixin/BlockEntityTypeMixin.java b/src/main/java/com/jozufozu/flywheel/impl/mixin/BlockEntityTypeMixin.java
similarity index 87%
rename from src/main/java/com/jozufozu/flywheel/mixin/BlockEntityTypeMixin.java
rename to src/main/java/com/jozufozu/flywheel/impl/mixin/BlockEntityTypeMixin.java
index 20ca6577f..fb7ee2574 100644
--- a/src/main/java/com/jozufozu/flywheel/mixin/BlockEntityTypeMixin.java
+++ b/src/main/java/com/jozufozu/flywheel/impl/mixin/BlockEntityTypeMixin.java
@@ -1,11 +1,11 @@
-package com.jozufozu.flywheel.mixin;
+package com.jozufozu.flywheel.impl.mixin;
import org.jetbrains.annotations.Nullable;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Unique;
import com.jozufozu.flywheel.api.visualization.BlockEntityVisualizer;
-import com.jozufozu.flywheel.extension.BlockEntityTypeExtension;
+import com.jozufozu.flywheel.impl.extension.BlockEntityTypeExtension;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.entity.BlockEntityType;
diff --git a/src/main/java/com/jozufozu/flywheel/mixin/ClientLevelMixin.java b/src/main/java/com/jozufozu/flywheel/impl/mixin/ClientLevelMixin.java
similarity index 96%
rename from src/main/java/com/jozufozu/flywheel/mixin/ClientLevelMixin.java
rename to src/main/java/com/jozufozu/flywheel/impl/mixin/ClientLevelMixin.java
index 7928a85df..57ffbcc71 100644
--- a/src/main/java/com/jozufozu/flywheel/mixin/ClientLevelMixin.java
+++ b/src/main/java/com/jozufozu/flywheel/impl/mixin/ClientLevelMixin.java
@@ -1,4 +1,4 @@
-package com.jozufozu.flywheel.mixin;
+package com.jozufozu.flywheel.impl.mixin;
import java.util.ArrayList;
diff --git a/src/main/java/com/jozufozu/flywheel/mixin/EntityTypeMixin.java b/src/main/java/com/jozufozu/flywheel/impl/mixin/EntityTypeMixin.java
similarity index 87%
rename from src/main/java/com/jozufozu/flywheel/mixin/EntityTypeMixin.java
rename to src/main/java/com/jozufozu/flywheel/impl/mixin/EntityTypeMixin.java
index 253d00d2d..d21881db2 100644
--- a/src/main/java/com/jozufozu/flywheel/mixin/EntityTypeMixin.java
+++ b/src/main/java/com/jozufozu/flywheel/impl/mixin/EntityTypeMixin.java
@@ -1,11 +1,11 @@
-package com.jozufozu.flywheel.mixin;
+package com.jozufozu.flywheel.impl.mixin;
import org.jetbrains.annotations.Nullable;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Unique;
import com.jozufozu.flywheel.api.visualization.EntityVisualizer;
-import com.jozufozu.flywheel.extension.EntityTypeExtension;
+import com.jozufozu.flywheel.impl.extension.EntityTypeExtension;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.EntityType;
diff --git a/src/main/java/com/jozufozu/flywheel/mixin/LayerLightSectionStorageMixin.java b/src/main/java/com/jozufozu/flywheel/impl/mixin/LayerLightSectionStorageMixin.java
similarity index 68%
rename from src/main/java/com/jozufozu/flywheel/mixin/LayerLightSectionStorageMixin.java
rename to src/main/java/com/jozufozu/flywheel/impl/mixin/LayerLightSectionStorageMixin.java
index 5ed59c3d9..e16a24d24 100644
--- a/src/main/java/com/jozufozu/flywheel/mixin/LayerLightSectionStorageMixin.java
+++ b/src/main/java/com/jozufozu/flywheel/impl/mixin/LayerLightSectionStorageMixin.java
@@ -1,4 +1,4 @@
-package com.jozufozu.flywheel.mixin;
+package com.jozufozu.flywheel.impl.mixin;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
@@ -15,26 +15,28 @@ import net.minecraft.world.level.chunk.LightChunkGetter;
import net.minecraft.world.level.lighting.LayerLightSectionStorage;
@Mixin(LayerLightSectionStorage.class)
-public abstract class LayerLightSectionStorageMixin {
-
+abstract class LayerLightSectionStorageMixin {
+ @Shadow
+ @Final
+ protected LightChunkGetter chunkSource;
@Shadow
@Final
protected LongSet sectionsAffectedByLightUpdates;
- @Shadow
- @Final
- protected LightChunkGetter chunkSource;
-
- @Inject(at = @At("HEAD"), method = "swapSectionMap")
+ @Inject(method = "swapSectionMap()V", at = @At("HEAD"))
private void flywheel$listenForChangedSections(CallbackInfo ci) {
- if (this.sectionsAffectedByLightUpdates.isEmpty()) {
+ if (sectionsAffectedByLightUpdates.isEmpty()) {
return;
}
- var manager = VisualizationManagerImpl.get((LevelAccessor) this.chunkSource.getLevel());
+ if (!(chunkSource.getLevel() instanceof LevelAccessor level)) {
+ return;
+ }
+
+ var manager = VisualizationManagerImpl.get(level);
if (manager != null) {
- manager.enqueueLightUpdateSections(this.sectionsAffectedByLightUpdates);
+ manager.enqueueLightUpdateSections(sectionsAffectedByLightUpdates);
}
}
}
diff --git a/src/main/java/com/jozufozu/flywheel/mixin/LevelMixin.java b/src/main/java/com/jozufozu/flywheel/impl/mixin/LevelMixin.java
similarity index 82%
rename from src/main/java/com/jozufozu/flywheel/mixin/LevelMixin.java
rename to src/main/java/com/jozufozu/flywheel/impl/mixin/LevelMixin.java
index 4739c28ba..f6a80dde7 100644
--- a/src/main/java/com/jozufozu/flywheel/mixin/LevelMixin.java
+++ b/src/main/java/com/jozufozu/flywheel/impl/mixin/LevelMixin.java
@@ -1,9 +1,9 @@
-package com.jozufozu.flywheel.mixin;
+package com.jozufozu.flywheel.impl.mixin;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
-import com.jozufozu.flywheel.extension.LevelExtension;
+import com.jozufozu.flywheel.impl.extension.LevelExtension;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.level.Level;
diff --git a/src/main/java/com/jozufozu/flywheel/mixin/LevelRendererMixin.java b/src/main/java/com/jozufozu/flywheel/impl/mixin/LevelRendererMixin.java
similarity index 99%
rename from src/main/java/com/jozufozu/flywheel/mixin/LevelRendererMixin.java
rename to src/main/java/com/jozufozu/flywheel/impl/mixin/LevelRendererMixin.java
index 0c0f02788..05c7af4f7 100644
--- a/src/main/java/com/jozufozu/flywheel/mixin/LevelRendererMixin.java
+++ b/src/main/java/com/jozufozu/flywheel/impl/mixin/LevelRendererMixin.java
@@ -1,4 +1,4 @@
-package com.jozufozu.flywheel.mixin;
+package com.jozufozu.flywheel.impl.mixin;
import java.util.SortedSet;
diff --git a/src/main/java/com/jozufozu/flywheel/mixin/MinecraftMixin.java b/src/main/java/com/jozufozu/flywheel/impl/mixin/MinecraftMixin.java
similarity index 97%
rename from src/main/java/com/jozufozu/flywheel/mixin/MinecraftMixin.java
rename to src/main/java/com/jozufozu/flywheel/impl/mixin/MinecraftMixin.java
index 1029a8e80..38ad493bb 100644
--- a/src/main/java/com/jozufozu/flywheel/mixin/MinecraftMixin.java
+++ b/src/main/java/com/jozufozu/flywheel/impl/mixin/MinecraftMixin.java
@@ -1,4 +1,4 @@
-package com.jozufozu.flywheel.mixin;
+package com.jozufozu.flywheel.impl.mixin;
import java.util.Optional;
import java.util.concurrent.CompletableFuture;
diff --git a/src/main/java/com/jozufozu/flywheel/mixin/PoseStackMixin.java b/src/main/java/com/jozufozu/flywheel/impl/mixin/PoseStackMixin.java
similarity index 87%
rename from src/main/java/com/jozufozu/flywheel/mixin/PoseStackMixin.java
rename to src/main/java/com/jozufozu/flywheel/impl/mixin/PoseStackMixin.java
index e7fc8333a..a1d1a0337 100644
--- a/src/main/java/com/jozufozu/flywheel/mixin/PoseStackMixin.java
+++ b/src/main/java/com/jozufozu/flywheel/impl/mixin/PoseStackMixin.java
@@ -1,9 +1,9 @@
-package com.jozufozu.flywheel.mixin;
+package com.jozufozu.flywheel.impl.mixin;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Unique;
-import com.jozufozu.flywheel.extension.PoseStackExtension;
+import com.jozufozu.flywheel.impl.extension.PoseStackExtension;
import com.jozufozu.flywheel.lib.transform.PoseTransformStack;
import com.mojang.blaze3d.vertex.PoseStack;
diff --git a/src/main/java/com/jozufozu/flywheel/mixin/VertexFormatMixin.java b/src/main/java/com/jozufozu/flywheel/impl/mixin/VertexFormatMixin.java
similarity index 84%
rename from src/main/java/com/jozufozu/flywheel/mixin/VertexFormatMixin.java
rename to src/main/java/com/jozufozu/flywheel/impl/mixin/VertexFormatMixin.java
index b363e3816..8e2043373 100644
--- a/src/main/java/com/jozufozu/flywheel/mixin/VertexFormatMixin.java
+++ b/src/main/java/com/jozufozu/flywheel/impl/mixin/VertexFormatMixin.java
@@ -1,10 +1,10 @@
-package com.jozufozu.flywheel.mixin;
+package com.jozufozu.flywheel.impl.mixin;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Unique;
import com.jozufozu.flywheel.api.vertex.VertexViewProvider;
-import com.jozufozu.flywheel.extension.VertexFormatExtension;
+import com.jozufozu.flywheel.impl.extension.VertexFormatExtension;
import com.mojang.blaze3d.vertex.VertexFormat;
@Mixin(VertexFormat.class)
diff --git a/src/main/java/com/jozufozu/flywheel/mixin/fix/FixFabulousDepthMixin.java b/src/main/java/com/jozufozu/flywheel/impl/mixin/fix/FixFabulousDepthMixin.java
similarity index 93%
rename from src/main/java/com/jozufozu/flywheel/mixin/fix/FixFabulousDepthMixin.java
rename to src/main/java/com/jozufozu/flywheel/impl/mixin/fix/FixFabulousDepthMixin.java
index 70a99b62e..e617dbdfc 100644
--- a/src/main/java/com/jozufozu/flywheel/mixin/fix/FixFabulousDepthMixin.java
+++ b/src/main/java/com/jozufozu/flywheel/impl/mixin/fix/FixFabulousDepthMixin.java
@@ -1,4 +1,4 @@
-package com.jozufozu.flywheel.mixin.fix;
+package com.jozufozu.flywheel.impl.mixin.fix;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
diff --git a/src/main/java/com/jozufozu/flywheel/mixin/fix/FixNormalScalingMixin.java b/src/main/java/com/jozufozu/flywheel/impl/mixin/fix/FixNormalScalingMixin.java
similarity index 97%
rename from src/main/java/com/jozufozu/flywheel/mixin/fix/FixNormalScalingMixin.java
rename to src/main/java/com/jozufozu/flywheel/impl/mixin/fix/FixNormalScalingMixin.java
index 16ef24ff0..b94f596c2 100644
--- a/src/main/java/com/jozufozu/flywheel/mixin/fix/FixNormalScalingMixin.java
+++ b/src/main/java/com/jozufozu/flywheel/impl/mixin/fix/FixNormalScalingMixin.java
@@ -1,4 +1,4 @@
-package com.jozufozu.flywheel.mixin.fix;
+package com.jozufozu.flywheel.impl.mixin.fix;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
diff --git a/src/main/java/com/jozufozu/flywheel/mixin/sodium/ChunkBuilderMeshingTaskMixin.java b/src/main/java/com/jozufozu/flywheel/impl/mixin/sodium/ChunkBuilderMeshingTaskMixin.java
similarity index 95%
rename from src/main/java/com/jozufozu/flywheel/mixin/sodium/ChunkBuilderMeshingTaskMixin.java
rename to src/main/java/com/jozufozu/flywheel/impl/mixin/sodium/ChunkBuilderMeshingTaskMixin.java
index 41b26daff..71e32d0cd 100644
--- a/src/main/java/com/jozufozu/flywheel/mixin/sodium/ChunkBuilderMeshingTaskMixin.java
+++ b/src/main/java/com/jozufozu/flywheel/impl/mixin/sodium/ChunkBuilderMeshingTaskMixin.java
@@ -1,4 +1,4 @@
-package com.jozufozu.flywheel.mixin.sodium;
+package com.jozufozu.flywheel.impl.mixin.sodium;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
diff --git a/src/main/java/com/jozufozu/flywheel/compat/SodiumMixinPlugin.java b/src/main/java/com/jozufozu/flywheel/impl/mixin/sodium/SodiumMixinPlugin.java
similarity index 96%
rename from src/main/java/com/jozufozu/flywheel/compat/SodiumMixinPlugin.java
rename to src/main/java/com/jozufozu/flywheel/impl/mixin/sodium/SodiumMixinPlugin.java
index 26da383c4..aa58d4c7a 100644
--- a/src/main/java/com/jozufozu/flywheel/compat/SodiumMixinPlugin.java
+++ b/src/main/java/com/jozufozu/flywheel/impl/mixin/sodium/SodiumMixinPlugin.java
@@ -1,4 +1,4 @@
-package com.jozufozu.flywheel.compat;
+package com.jozufozu.flywheel.impl.mixin.sodium;
import java.util.List;
import java.util.Set;
diff --git a/src/main/java/com/jozufozu/flywheel/mixin/visualmanage/VisualRemoveMixin.java b/src/main/java/com/jozufozu/flywheel/impl/mixin/visualmanage/BlockEntityMixin.java
similarity index 90%
rename from src/main/java/com/jozufozu/flywheel/mixin/visualmanage/VisualRemoveMixin.java
rename to src/main/java/com/jozufozu/flywheel/impl/mixin/visualmanage/BlockEntityMixin.java
index b924127b8..201b03d6b 100644
--- a/src/main/java/com/jozufozu/flywheel/mixin/visualmanage/VisualRemoveMixin.java
+++ b/src/main/java/com/jozufozu/flywheel/impl/mixin/visualmanage/BlockEntityMixin.java
@@ -1,4 +1,4 @@
-package com.jozufozu.flywheel.mixin.visualmanage;
+package com.jozufozu.flywheel.impl.mixin.visualmanage;
import org.jetbrains.annotations.Nullable;
import org.spongepowered.asm.mixin.Mixin;
@@ -13,7 +13,7 @@ import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.entity.BlockEntity;
@Mixin(BlockEntity.class)
-abstract class VisualRemoveMixin {
+abstract class BlockEntityMixin {
@Shadow
@Nullable
protected Level level;
diff --git a/src/main/java/com/jozufozu/flywheel/mixin/visualmanage/VisualAddMixin.java b/src/main/java/com/jozufozu/flywheel/impl/mixin/visualmanage/LevelChunkMixin.java
similarity index 92%
rename from src/main/java/com/jozufozu/flywheel/mixin/visualmanage/VisualAddMixin.java
rename to src/main/java/com/jozufozu/flywheel/impl/mixin/visualmanage/LevelChunkMixin.java
index 3144de0f9..011b76c8a 100644
--- a/src/main/java/com/jozufozu/flywheel/mixin/visualmanage/VisualAddMixin.java
+++ b/src/main/java/com/jozufozu/flywheel/impl/mixin/visualmanage/LevelChunkMixin.java
@@ -1,4 +1,4 @@
-package com.jozufozu.flywheel.mixin.visualmanage;
+package com.jozufozu.flywheel.impl.mixin.visualmanage;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
@@ -14,7 +14,7 @@ import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.chunk.LevelChunk;
@Mixin(LevelChunk.class)
-abstract class VisualAddMixin {
+abstract class LevelChunkMixin {
@Shadow
@Final
Level level;
diff --git a/src/main/java/com/jozufozu/flywheel/mixin/visualmanage/VisualUpdateMixin.java b/src/main/java/com/jozufozu/flywheel/impl/mixin/visualmanage/LevelRendererMixin.java
similarity index 93%
rename from src/main/java/com/jozufozu/flywheel/mixin/visualmanage/VisualUpdateMixin.java
rename to src/main/java/com/jozufozu/flywheel/impl/mixin/visualmanage/LevelRendererMixin.java
index 1ddff522d..e5cd96ba2 100644
--- a/src/main/java/com/jozufozu/flywheel/mixin/visualmanage/VisualUpdateMixin.java
+++ b/src/main/java/com/jozufozu/flywheel/impl/mixin/visualmanage/LevelRendererMixin.java
@@ -1,4 +1,4 @@
-package com.jozufozu.flywheel.mixin.visualmanage;
+package com.jozufozu.flywheel.impl.mixin.visualmanage;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
@@ -15,7 +15,7 @@ import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.state.BlockState;
@Mixin(LevelRenderer.class)
-abstract class VisualUpdateMixin {
+abstract class LevelRendererMixin {
@Shadow
private ClientLevel level;
diff --git a/src/main/java/com/jozufozu/flywheel/mixin/visualmanage/ChunkRebuildHooksMixin.java b/src/main/java/com/jozufozu/flywheel/impl/mixin/visualmanage/RebuildTaskMixin.java
similarity index 91%
rename from src/main/java/com/jozufozu/flywheel/mixin/visualmanage/ChunkRebuildHooksMixin.java
rename to src/main/java/com/jozufozu/flywheel/impl/mixin/visualmanage/RebuildTaskMixin.java
index 116f7b236..7b55a0279 100644
--- a/src/main/java/com/jozufozu/flywheel/mixin/visualmanage/ChunkRebuildHooksMixin.java
+++ b/src/main/java/com/jozufozu/flywheel/impl/mixin/visualmanage/RebuildTaskMixin.java
@@ -1,4 +1,4 @@
-package com.jozufozu.flywheel.mixin.visualmanage;
+package com.jozufozu.flywheel.impl.mixin.visualmanage;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
@@ -11,7 +11,7 @@ import com.jozufozu.flywheel.impl.visualization.VisualizationHelper;
import net.minecraft.world.level.block.entity.BlockEntity;
@Mixin(targets = "net.minecraft.client.renderer.chunk.ChunkRenderDispatcher$RenderChunk$RebuildTask")
-abstract class ChunkRebuildHooksMixin {
+abstract class RebuildTaskMixin {
@Inject(method = "handleBlockEntity(Lnet/minecraft/client/renderer/chunk/ChunkRenderDispatcher$RenderChunk$RebuildTask$CompileResults;Lnet/minecraft/world/level/block/entity/BlockEntity;)V", at = @At("HEAD"), cancellable = true)
private void flywheel$tryAddBlockEntity(@Coerce Object compileResults, BlockEntity blockEntity, CallbackInfo ci) {
if (VisualizationHelper.tryAddBlockEntity(blockEntity)) {
diff --git a/src/main/java/com/jozufozu/flywheel/impl/IdRegistryImpl.java b/src/main/java/com/jozufozu/flywheel/impl/registry/IdRegistryImpl.java
similarity index 96%
rename from src/main/java/com/jozufozu/flywheel/impl/IdRegistryImpl.java
rename to src/main/java/com/jozufozu/flywheel/impl/registry/IdRegistryImpl.java
index b7c3b6f25..58cca6c5d 100644
--- a/src/main/java/com/jozufozu/flywheel/impl/IdRegistryImpl.java
+++ b/src/main/java/com/jozufozu/flywheel/impl/registry/IdRegistryImpl.java
@@ -1,4 +1,4 @@
-package com.jozufozu.flywheel.impl;
+package com.jozufozu.flywheel.impl.registry;
import java.util.Collection;
import java.util.Iterator;
@@ -31,14 +31,10 @@ public class IdRegistryImpl implements IdRegistry {
private final ObjectList freezeCallbacks = new ObjectArrayList<>();
private boolean frozen;
- private IdRegistryImpl() {
+ public IdRegistryImpl() {
ALL.add(this);
}
- public static IdRegistry create() {
- return new IdRegistryImpl<>();
- }
-
@Override
public void register(ResourceLocation id, T object) {
if (frozen) {
diff --git a/src/main/java/com/jozufozu/flywheel/impl/RegistryImpl.java b/src/main/java/com/jozufozu/flywheel/impl/registry/RegistryImpl.java
similarity index 92%
rename from src/main/java/com/jozufozu/flywheel/impl/RegistryImpl.java
rename to src/main/java/com/jozufozu/flywheel/impl/registry/RegistryImpl.java
index 45512c8c7..2c50b0bbc 100644
--- a/src/main/java/com/jozufozu/flywheel/impl/RegistryImpl.java
+++ b/src/main/java/com/jozufozu/flywheel/impl/registry/RegistryImpl.java
@@ -1,4 +1,4 @@
-package com.jozufozu.flywheel.impl;
+package com.jozufozu.flywheel.impl.registry;
import java.util.Iterator;
import java.util.Set;
@@ -21,14 +21,10 @@ public class RegistryImpl implements Registry {
private final ObjectList freezeCallbacks = new ObjectArrayList<>();
private boolean frozen;
- private RegistryImpl() {
+ public RegistryImpl() {
ALL.add(this);
}
- public static Registry create() {
- return new RegistryImpl<>();
- }
-
@Override
public void register(T object) {
if (frozen) {
diff --git a/src/main/java/com/jozufozu/flywheel/impl/vertex/VertexListProviderRegistryImpl.java b/src/main/java/com/jozufozu/flywheel/impl/vertex/VertexViewProviderRegistryImpl.java
similarity index 81%
rename from src/main/java/com/jozufozu/flywheel/impl/vertex/VertexListProviderRegistryImpl.java
rename to src/main/java/com/jozufozu/flywheel/impl/vertex/VertexViewProviderRegistryImpl.java
index b9575fd3e..539714a9d 100644
--- a/src/main/java/com/jozufozu/flywheel/impl/vertex/VertexListProviderRegistryImpl.java
+++ b/src/main/java/com/jozufozu/flywheel/impl/vertex/VertexViewProviderRegistryImpl.java
@@ -1,11 +1,14 @@
package com.jozufozu.flywheel.impl.vertex;
import com.jozufozu.flywheel.api.vertex.VertexViewProvider;
-import com.jozufozu.flywheel.extension.VertexFormatExtension;
+import com.jozufozu.flywheel.impl.extension.VertexFormatExtension;
import com.mojang.blaze3d.vertex.VertexFormat;
// TODO: Add freezing
-public final class VertexListProviderRegistryImpl {
+public final class VertexViewProviderRegistryImpl {
+ private VertexViewProviderRegistryImpl() {
+ }
+
public static VertexViewProvider getProvider(VertexFormat format) {
VertexFormatExtension extension = (VertexFormatExtension) format;
VertexViewProvider provider = extension.flywheel$getVertexViewProvider();
@@ -19,7 +22,4 @@ public final class VertexListProviderRegistryImpl {
public static void setProvider(VertexFormat format, VertexViewProvider provider) {
((VertexFormatExtension) format).flywheel$setVertexViewProvider(provider);
}
-
- private VertexListProviderRegistryImpl() {
- }
}
diff --git a/src/main/java/com/jozufozu/flywheel/impl/visual/VisualFrameContextImpl.java b/src/main/java/com/jozufozu/flywheel/impl/visual/VisualFrameContextImpl.java
index c1a0951f9..f794c119a 100644
--- a/src/main/java/com/jozufozu/flywheel/impl/visual/VisualFrameContextImpl.java
+++ b/src/main/java/com/jozufozu/flywheel/impl/visual/VisualFrameContextImpl.java
@@ -7,7 +7,6 @@ import com.jozufozu.flywheel.api.visual.VisualFrameContext;
import net.minecraft.client.Camera;
-public record VisualFrameContextImpl(double cameraX, double cameraY, double cameraZ, FrustumIntersection frustum,
- float partialTick, DistanceUpdateLimiter limiter,
- Camera camera) implements VisualFrameContext {
+public record VisualFrameContextImpl(Camera camera, FrustumIntersection frustum,
+ float partialTick, DistanceUpdateLimiter limiter) implements VisualFrameContext {
}
diff --git a/src/main/java/com/jozufozu/flywheel/impl/visualization/VisualizationManagerImpl.java b/src/main/java/com/jozufozu/flywheel/impl/visualization/VisualizationManagerImpl.java
index e5332277e..42e268138 100644
--- a/src/main/java/com/jozufozu/flywheel/impl/visualization/VisualizationManagerImpl.java
+++ b/src/main/java/com/jozufozu/flywheel/impl/visualization/VisualizationManagerImpl.java
@@ -27,7 +27,7 @@ import com.jozufozu.flywheel.api.visualization.VisualizationContext;
import com.jozufozu.flywheel.api.visualization.VisualizationLevel;
import com.jozufozu.flywheel.api.visualization.VisualizationManager;
import com.jozufozu.flywheel.config.FlwConfig;
-import com.jozufozu.flywheel.extension.LevelExtension;
+import com.jozufozu.flywheel.impl.extension.LevelExtension;
import com.jozufozu.flywheel.impl.task.FlwTaskExecutor;
import com.jozufozu.flywheel.impl.visual.VisualFrameContextImpl;
import com.jozufozu.flywheel.impl.visual.VisualTickContextImpl;
@@ -102,7 +102,9 @@ public class VisualizationManagerImpl implements VisualizationManager {
.then(RaisePlan.raise(tickFlag))
.simplify();
- var recreate = SimplePlan.of(context -> blockEntitiesStorage.recreateAll(context.partialTick()), context -> entitiesStorage.recreateAll(context.partialTick()), context -> effectsStorage.recreateAll(context.partialTick()));
+ var recreate = SimplePlan.of(context -> blockEntitiesStorage.recreateAll(context.partialTick()),
+ context -> entitiesStorage.recreateAll(context.partialTick()),
+ context -> effectsStorage.recreateAll(context.partialTick()));
var update = MapContextPlan.map(this::createVisualFrameContext)
.to(NestedPlan.of(blockEntities.framePlan(), entities.framePlan(), effects.framePlan()));
@@ -126,15 +128,12 @@ public class VisualizationManagerImpl implements VisualizationManager {
Vec3i renderOrigin = engine.renderOrigin();
var cameraPos = ctx.camera()
.getPosition();
- double cameraX = cameraPos.x;
- double cameraY = cameraPos.y;
- double cameraZ = cameraPos.z;
Matrix4f viewProjection = new Matrix4f(ctx.viewProjection());
- viewProjection.translate((float) (renderOrigin.getX() - cameraX), (float) (renderOrigin.getY() - cameraY), (float) (renderOrigin.getZ() - cameraZ));
+ viewProjection.translate((float) (renderOrigin.getX() - cameraPos.x), (float) (renderOrigin.getY() - cameraPos.y), (float) (renderOrigin.getZ() - cameraPos.z));
FrustumIntersection frustum = new FrustumIntersection(viewProjection);
- return new VisualFrameContextImpl(cameraX, cameraY, cameraZ, frustum, ctx.partialTick(), frameLimiter, ctx.camera());
+ return new VisualFrameContextImpl(ctx.camera(), frustum, ctx.partialTick(), frameLimiter);
}
protected DistanceUpdateLimiterImpl createUpdateLimiter() {
@@ -148,7 +147,7 @@ public class VisualizationManagerImpl implements VisualizationManager {
@Contract("null -> false")
public static boolean supportsVisualization(@Nullable LevelAccessor level) {
- if (!BackendManager.isOn()) {
+ if (!BackendManager.isBackendOn()) {
return false;
}
@@ -186,10 +185,10 @@ public class VisualizationManagerImpl implements VisualizationManager {
// TODO: Consider making these reset actions reuse the existing game objects instead of re-adding them
// potentially by keeping the same VisualizationManagerImpl and deleting the engine and visuals but not the game objects
-
public static void reset(LevelAccessor level) {
MANAGERS.remove(level);
}
+
public static void resetAll() {
MANAGERS.reset();
}
diff --git a/src/main/java/com/jozufozu/flywheel/impl/visualization/VisualizerRegistryImpl.java b/src/main/java/com/jozufozu/flywheel/impl/visualization/VisualizerRegistryImpl.java
index a9fe88a67..c9b3f3031 100644
--- a/src/main/java/com/jozufozu/flywheel/impl/visualization/VisualizerRegistryImpl.java
+++ b/src/main/java/com/jozufozu/flywheel/impl/visualization/VisualizerRegistryImpl.java
@@ -4,8 +4,8 @@ import org.jetbrains.annotations.Nullable;
import com.jozufozu.flywheel.api.visualization.BlockEntityVisualizer;
import com.jozufozu.flywheel.api.visualization.EntityVisualizer;
-import com.jozufozu.flywheel.extension.BlockEntityTypeExtension;
-import com.jozufozu.flywheel.extension.EntityTypeExtension;
+import com.jozufozu.flywheel.impl.extension.BlockEntityTypeExtension;
+import com.jozufozu.flywheel.impl.extension.EntityTypeExtension;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.EntityType;
diff --git a/src/main/java/com/jozufozu/flywheel/impl/visualization/storage/LitVisualStorage.java b/src/main/java/com/jozufozu/flywheel/impl/visualization/storage/LitVisualStorage.java
index 1900a2532..58bc4342d 100644
--- a/src/main/java/com/jozufozu/flywheel/impl/visualization/storage/LitVisualStorage.java
+++ b/src/main/java/com/jozufozu/flywheel/impl/visualization/storage/LitVisualStorage.java
@@ -7,8 +7,6 @@ import java.util.WeakHashMap;
import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.atomic.AtomicLong;
-import org.jetbrains.annotations.NotNull;
-
import com.jozufozu.flywheel.api.task.Plan;
import com.jozufozu.flywheel.api.task.TaskExecutor;
import com.jozufozu.flywheel.api.visual.LitVisual;
@@ -161,7 +159,6 @@ public class LitVisualStorage {
return -1;
}
- @NotNull
private static Updater createUpdater(LitVisual visual, int sectionCount) {
if (sectionCount == 1) {
return new Updater.Simple(visual);
diff --git a/src/main/java/com/jozufozu/flywheel/lib/transform/PoseTransformStack.java b/src/main/java/com/jozufozu/flywheel/lib/transform/PoseTransformStack.java
index 2cb098981..14e46855e 100644
--- a/src/main/java/com/jozufozu/flywheel/lib/transform/PoseTransformStack.java
+++ b/src/main/java/com/jozufozu/flywheel/lib/transform/PoseTransformStack.java
@@ -12,8 +12,8 @@ import com.mojang.blaze3d.vertex.PoseStack;
*
* Only one instance of this class should exist per {@link PoseStack}.
*/
-public class PoseTransformStack implements TransformStack {
- public final PoseStack stack;
+public final class PoseTransformStack implements TransformStack {
+ private final PoseStack stack;
@ApiStatus.Internal
public PoseTransformStack(PoseStack stack) {
@@ -71,4 +71,8 @@ public class PoseTransformStack implements TransformStack {
stack.translate(x, y, z);
return this;
}
+
+ public PoseStack unwrap() {
+ return stack;
+ }
}
diff --git a/src/main/java/com/jozufozu/flywheel/lib/transform/TransformStack.java b/src/main/java/com/jozufozu/flywheel/lib/transform/TransformStack.java
index 5fcfeae62..306972421 100644
--- a/src/main/java/com/jozufozu/flywheel/lib/transform/TransformStack.java
+++ b/src/main/java/com/jozufozu/flywheel/lib/transform/TransformStack.java
@@ -1,14 +1,14 @@
package com.jozufozu.flywheel.lib.transform;
-import com.jozufozu.flywheel.extension.PoseStackExtension;
+import com.jozufozu.flywheel.api.internal.InternalFlywheelApi;
import com.mojang.blaze3d.vertex.PoseStack;
public interface TransformStack> extends Transform {
+ static PoseTransformStack of(PoseStack stack) {
+ return InternalFlywheelApi.INSTANCE.getPoseTransformStackOf(stack);
+ }
+
Self pushPose();
Self popPose();
-
- static PoseTransformStack of(PoseStack stack) {
- return ((PoseStackExtension) stack).flywheel$transformStack();
- }
}
diff --git a/src/main/java/com/jozufozu/flywheel/lib/visual/AbstractBlockEntityVisual.java b/src/main/java/com/jozufozu/flywheel/lib/visual/AbstractBlockEntityVisual.java
index 2d4cf59f1..9eefda60b 100644
--- a/src/main/java/com/jozufozu/flywheel/lib/visual/AbstractBlockEntityVisual.java
+++ b/src/main/java/com/jozufozu/flywheel/lib/visual/AbstractBlockEntityVisual.java
@@ -107,6 +107,6 @@ public abstract class AbstractBlockEntityVisual extends A
*/
public boolean doDistanceLimitThisFrame(VisualFrameContext context) {
return !context.limiter()
- .shouldUpdate(pos.distToCenterSqr(context.cameraX(), context.cameraY(), context.cameraZ()));
+ .shouldUpdate(pos.distToCenterSqr(context.camera().getPosition()));
}
}
diff --git a/src/main/java/com/jozufozu/flywheel/lib/visual/FireComponent.java b/src/main/java/com/jozufozu/flywheel/lib/visual/FireComponent.java
index df7d58d7f..49a7b62eb 100644
--- a/src/main/java/com/jozufozu/flywheel/lib/visual/FireComponent.java
+++ b/src/main/java/com/jozufozu/flywheel/lib/visual/FireComponent.java
@@ -1,15 +1,10 @@
package com.jozufozu.flywheel.lib.visual;
-import java.util.Map;
-
import org.joml.Vector4f;
import org.joml.Vector4fc;
-import com.google.common.collect.ImmutableMap;
import com.jozufozu.flywheel.api.event.RenderStage;
import com.jozufozu.flywheel.api.material.Material;
-import com.jozufozu.flywheel.api.model.Mesh;
-import com.jozufozu.flywheel.api.model.Model;
import com.jozufozu.flywheel.api.vertex.MutableVertexList;
import com.jozufozu.flywheel.api.visual.VisualFrameContext;
import com.jozufozu.flywheel.api.visualization.VisualizationContext;
@@ -19,11 +14,11 @@ import com.jozufozu.flywheel.lib.material.Materials;
import com.jozufozu.flywheel.lib.material.SimpleMaterial;
import com.jozufozu.flywheel.lib.model.ModelCache;
import com.jozufozu.flywheel.lib.model.QuadMesh;
+import com.jozufozu.flywheel.lib.model.SingleMeshModel;
import com.mojang.blaze3d.vertex.PoseStack;
import com.mojang.math.Axis;
import net.minecraft.client.renderer.LightTexture;
-import net.minecraft.client.renderer.texture.OverlayTexture;
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
import net.minecraft.client.resources.model.ModelBakery;
import net.minecraft.util.Mth;
@@ -33,6 +28,15 @@ import net.minecraft.world.entity.Entity;
* A component that uses instances to render the fire animation on an entity.
*/
public class FireComponent {
+ private static final Material FIRE_MATERIAL = SimpleMaterial.builderOf(Materials.CHUNK_CUTOUT_UNSHADED)
+ .backfaceCulling(false) // Disable backface because we want to be able to flip the model.
+ .build();
+ // Parameterize by the material instead of the sprite
+ // because Material#sprite is a surprisingly heavy operation.
+ private static final ModelCache FIRE_MODELS = new ModelCache<>(texture -> {
+ return new SingleMeshModel(new FireMesh(texture.sprite()), FIRE_MATERIAL);
+ });
+
private final VisualizationContext context;
private final Entity entity;
private final PoseStack stack = new PoseStack();
@@ -44,12 +48,17 @@ public class FireComponent {
this.context = context;
this.entity = entity;
- fire0 = new InstanceRecycler<>(() -> context.instancerProvider()
- .instancer(InstanceTypes.TRANSFORMED, FireModel.CACHE.get(ModelBakery.FIRE_0), RenderStage.AFTER_BLOCK_ENTITIES)
- .createInstance());
- fire1 = new InstanceRecycler<>(() -> context.instancerProvider()
- .instancer(InstanceTypes.TRANSFORMED, FireModel.CACHE.get(ModelBakery.FIRE_1), RenderStage.AFTER_BLOCK_ENTITIES)
- .createInstance());
+ fire0 = new InstanceRecycler<>(() -> createInstance(ModelBakery.FIRE_0));
+ fire1 = new InstanceRecycler<>(() -> createInstance(ModelBakery.FIRE_1));
+ }
+
+ private TransformedInstance createInstance(net.minecraft.client.resources.model.Material texture) {
+ TransformedInstance instance = context.instancerProvider()
+ .instancer(InstanceTypes.TRANSFORMED, FIRE_MODELS.get(texture), RenderStage.AFTER_ENTITIES)
+ .createInstance();
+ instance.setBlockLight(LightTexture.block(LightTexture.FULL_BLOCK));
+ instance.setChanged();
+ return instance;
}
/**
@@ -100,8 +109,6 @@ public class FireComponent {
instance.scaleX(-1);
}
- instance.setBlockLight(LightTexture.block(240));
-
instance.setChanged();
y += 0.45F;
@@ -117,25 +124,24 @@ public class FireComponent {
fire1.delete();
}
- private static class FireModel implements Model {
- // Parameterize by the material instead of the sprite
- // because Material#sprite is a surprisingly heavy operation.
- public static final ModelCache CACHE = new ModelCache<>(mat -> new FireModel(mat.sprite()));
-
- public static final Material MATERIAL = SimpleMaterial.builderOf(Materials.CHUNK_CUTOUT_UNSHADED)
- .backfaceCulling(false) // Disable backface because we want to be able to flip the model.
- .build();
+ private record FireMesh(TextureAtlasSprite sprite) implements QuadMesh {
private static final Vector4fc BOUNDING_SPHERE = new Vector4f(0, 0.5f, 0, (float) (Math.sqrt(2) * 0.5));
- private final ImmutableMap meshes;
-
- private FireModel(TextureAtlasSprite sprite) {
- meshes = ImmutableMap.of(MATERIAL, new FireMesh(sprite));
+ @Override
+ public int vertexCount() {
+ return 4;
}
@Override
- public Map meshes() {
- return meshes;
+ public void write(MutableVertexList vertexList) {
+ float u0 = sprite.getU0();
+ float v0 = sprite.getV0();
+ float u1 = sprite.getU1();
+ float v1 = sprite.getV1();
+ writeVertex(vertexList, 0, 0.5f, 0, u1, v1);
+ writeVertex(vertexList, 1, -0.5f, 0, u0, v1);
+ writeVertex(vertexList, 2, -0.5f, 1.4f, u0, v0);
+ writeVertex(vertexList, 3, 0.5f, 1.4f, u1, v0);
}
@Override
@@ -143,62 +149,25 @@ public class FireComponent {
return BOUNDING_SPHERE;
}
- @Override
- public int vertexCount() {
- return 4;
- }
-
@Override
public void delete() {
-
}
- private record FireMesh(TextureAtlasSprite sprite) implements QuadMesh {
- @Override
- public int vertexCount() {
- return 4;
- }
-
- @Override
- public void write(MutableVertexList vertexList) {
- float u0 = sprite.getU0();
- float v0 = sprite.getV0();
- float u1 = sprite.getU1();
- float v1 = sprite.getV1();
- writeVertex(vertexList, 0, 0.5f, 0, u1, v1);
- writeVertex(vertexList, 1, -0.5f, 0, u0, v1);
- writeVertex(vertexList, 2, -0.5f, 1.4f, u0, v0);
- writeVertex(vertexList, 3, 0.5f, 1.4f, u1, v0);
- }
-
- @Override
- public Vector4fc boundingSphere() {
- return BOUNDING_SPHERE;
- }
-
- @Override
- public void delete() {
-
- }
-
- // Magic numbers taken from:
- // net.minecraft.client.renderer.entity.EntityRenderDispatcher#fireVertex
- private static void writeVertex(MutableVertexList vertexList, int i, float x, float y, float u, float v) {
- vertexList.x(i, x);
- vertexList.y(i, y);
- vertexList.z(i, 0);
- vertexList.r(i, 1);
- vertexList.g(i, 1);
- vertexList.b(i, 1);
- vertexList.u(i, u);
- vertexList.v(i, v);
- vertexList.overlay(i, OverlayTexture.NO_OVERLAY);
- vertexList.light(i, 240);
- vertexList.normalX(i, 0);
- vertexList.normalY(i, 1);
- vertexList.normalZ(i, 0);
-
- }
+ // Magic numbers taken from:
+ // net.minecraft.client.renderer.entity.EntityRenderDispatcher#fireVertex
+ private static void writeVertex(MutableVertexList vertexList, int i, float x, float y, float u, float v) {
+ vertexList.x(i, x);
+ vertexList.y(i, y);
+ vertexList.z(i, 0);
+ vertexList.r(i, 1);
+ vertexList.g(i, 1);
+ vertexList.b(i, 1);
+ vertexList.u(i, u);
+ vertexList.v(i, v);
+ vertexList.light(i, LightTexture.FULL_BLOCK);
+ vertexList.normalX(i, 0);
+ vertexList.normalY(i, 1);
+ vertexList.normalZ(i, 0);
}
}
}
diff --git a/src/main/java/com/jozufozu/flywheel/lib/visual/InstanceRecycler.java b/src/main/java/com/jozufozu/flywheel/lib/visual/InstanceRecycler.java
index 56af0f14e..af6931bbb 100644
--- a/src/main/java/com/jozufozu/flywheel/lib/visual/InstanceRecycler.java
+++ b/src/main/java/com/jozufozu/flywheel/lib/visual/InstanceRecycler.java
@@ -15,7 +15,6 @@ import com.jozufozu.flywheel.api.instance.Instance;
* @param The type of instance to recycle.
*/
public class InstanceRecycler {
-
private final Supplier factory;
private final List instances = new ArrayList<>();
diff --git a/src/main/java/com/jozufozu/flywheel/lib/visual/ShadowComponent.java b/src/main/java/com/jozufozu/flywheel/lib/visual/ShadowComponent.java
index 561ae2f51..08766cf89 100644
--- a/src/main/java/com/jozufozu/flywheel/lib/visual/ShadowComponent.java
+++ b/src/main/java/com/jozufozu/flywheel/lib/visual/ShadowComponent.java
@@ -1,17 +1,13 @@
package com.jozufozu.flywheel.lib.visual;
-import java.util.Map;
-
import org.jetbrains.annotations.Nullable;
import org.joml.Vector4f;
import org.joml.Vector4fc;
-import com.google.common.collect.ImmutableMap;
import com.jozufozu.flywheel.api.event.RenderStage;
import com.jozufozu.flywheel.api.material.Material;
import com.jozufozu.flywheel.api.material.Transparency;
import com.jozufozu.flywheel.api.material.WriteMask;
-import com.jozufozu.flywheel.api.model.Mesh;
import com.jozufozu.flywheel.api.model.Model;
import com.jozufozu.flywheel.api.vertex.MutableVertexList;
import com.jozufozu.flywheel.api.visual.VisualFrameContext;
@@ -20,18 +16,20 @@ import com.jozufozu.flywheel.lib.instance.InstanceTypes;
import com.jozufozu.flywheel.lib.instance.ShadowInstance;
import com.jozufozu.flywheel.lib.material.SimpleMaterial;
import com.jozufozu.flywheel.lib.model.QuadMesh;
+import com.jozufozu.flywheel.lib.model.SingleMeshModel;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.LightTexture;
import net.minecraft.core.BlockPos;
+import net.minecraft.core.BlockPos.MutableBlockPos;
+import net.minecraft.core.Direction.Axis;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.util.Mth;
import net.minecraft.world.entity.Entity;
-import net.minecraft.world.level.LevelReader;
+import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.RenderShape;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.chunk.ChunkAccess;
-import net.minecraft.world.phys.AABB;
import net.minecraft.world.phys.shapes.VoxelShape;
/**
@@ -44,21 +42,44 @@ import net.minecraft.world.phys.shapes.VoxelShape;
* The shadow will be cast on blocks at most {@code min(radius, 2 * strength)} blocks below the entity.
*/
public class ShadowComponent {
+ private static final Material SHADOW_MATERIAL = SimpleMaterial.builder()
+ .texture(new ResourceLocation("textures/misc/shadow.png"))
+ .mipmap(false)
+ .polygonOffset(true) // vanilla shadows use "view offset" but this seems to work fine
+ .transparency(Transparency.TRANSLUCENT)
+ .writeMask(WriteMask.COLOR)
+ .build();
+ private static final Model SHADOW_MODEL = new SingleMeshModel(ShadowMesh.INSTANCE, SHADOW_MATERIAL);
private final VisualizationContext context;
- private final LevelReader level;
private final Entity entity;
- private final InstanceRecycler instances = new InstanceRecycler<>(this::instance);
+ private final Level level;
private final BlockPos.MutableBlockPos pos = new BlockPos.MutableBlockPos();
+ private final InstanceRecycler instances = new InstanceRecycler<>(this::createInstance);
+
// Defaults taken from EntityRenderer.
private float radius = 0;
private float strength = 1.0F;
public ShadowComponent(VisualizationContext context, Entity entity) {
this.context = context;
- this.level = entity.level();
this.entity = entity;
+ this.level = entity.level();
+ }
+
+ private ShadowInstance createInstance() {
+ return context.instancerProvider()
+ .instancer(InstanceTypes.SHADOW, SHADOW_MODEL, RenderStage.AFTER_ENTITIES)
+ .createInstance();
+ }
+
+ public float radius() {
+ return radius;
+ }
+
+ public float strength() {
+ return strength;
}
/**
@@ -114,18 +135,18 @@ public class ShadowComponent {
for (int z = minZPos; z <= maxZPos; ++z) {
for (int x = minXPos; x <= maxXPos; ++x) {
pos.set(x, 0, z);
- ChunkAccess chunkaccess = level.getChunk(pos);
+ ChunkAccess chunk = level.getChunk(pos);
for (int y = minYPos; y <= maxYPos; ++y) {
pos.setY(y);
float strengthGivenYFalloff = strength - (float) (entityY - pos.getY()) * 0.5F;
- maybeSetupShadowInstance(chunkaccess, (float) entityX, (float) entityZ, strengthGivenYFalloff);
+ setupInstance(chunk, pos, (float) entityX, (float) entityZ, strengthGivenYFalloff);
}
}
}
}
- private void maybeSetupShadowInstance(ChunkAccess pChunk, float entityX, float entityZ, float strength) {
+ private void setupInstance(ChunkAccess chunk, MutableBlockPos pos, float entityX, float entityZ, float strength) {
// TODO: cache this?
var maxLocalRawBrightness = level.getMaxLocalRawBrightness(pos);
if (maxLocalRawBrightness <= 3) {
@@ -134,7 +155,7 @@ public class ShadowComponent {
}
float blockBrightness = LightTexture.getBrightness(level.dimensionType(), maxLocalRawBrightness);
float alpha = strength * 0.5F * blockBrightness;
- if (!(alpha >= 0.0F)) {
+ if (alpha < 0.0F) {
// Too far away/too weak to render.
return;
}
@@ -144,9 +165,9 @@ public class ShadowComponent {
// Grab the AABB for the block below the current position.
pos.setY(pos.getY() - 1);
- var aabb = getAabbForPos(pChunk, pos);
- if (aabb == null) {
- // No aabb means the block shouldn't receive a shadow.
+ var shape = getShapeAt(chunk, pos);
+ if (shape == null) {
+ // No shape means the block shouldn't receive a shadow.
return;
}
@@ -155,11 +176,11 @@ public class ShadowComponent {
int y = pos.getY() - renderOrigin.getY() + 1; // +1 since we moved the pos down.
int z = pos.getZ() - renderOrigin.getZ();
- double minX = x + aabb.minX;
- double minY = y + aabb.minY;
- double minZ = z + aabb.minZ;
- double maxX = x + aabb.maxX;
- double maxZ = z + aabb.maxZ;
+ double minX = x + shape.min(Axis.X);
+ double minY = y + shape.min(Axis.Y);
+ double minZ = z + shape.min(Axis.Z);
+ double maxX = x + shape.max(Axis.X);
+ double maxZ = z + shape.max(Axis.Z);
var instance = instances.get();
instance.x = (float) minX;
@@ -175,48 +196,48 @@ public class ShadowComponent {
}
@Nullable
- private AABB getAabbForPos(ChunkAccess pChunk, BlockPos pos) {
- BlockState blockstate = pChunk.getBlockState(pos);
- if (blockstate.getRenderShape() == RenderShape.INVISIBLE) {
+ private VoxelShape getShapeAt(ChunkAccess chunk, BlockPos pos) {
+ BlockState state = chunk.getBlockState(pos);
+ if (state.getRenderShape() == RenderShape.INVISIBLE) {
return null;
}
- if (!blockstate.isCollisionShapeFullBlock(pChunk, pos)) {
+ if (!state.isCollisionShapeFullBlock(chunk, pos)) {
return null;
}
- VoxelShape voxelshape = blockstate.getShape(pChunk, pos);
- if (voxelshape.isEmpty()) {
+ VoxelShape shape = state.getShape(chunk, pos);
+ if (shape.isEmpty()) {
return null;
}
- return voxelshape.bounds();
- }
-
- private ShadowInstance instance() {
- return context.instancerProvider()
- .instancer(InstanceTypes.SHADOW, ShadowModel.INSTANCE, RenderStage.AFTER_ENTITIES)
- .createInstance();
+ return shape;
}
public void delete() {
instances.delete();
}
- private static class ShadowModel implements Model {
- public static final ShadowModel INSTANCE = new ShadowModel();
- public static final Material MATERIAL = SimpleMaterial.builder()
- .transparency(Transparency.TRANSLUCENT)
- .writeMask(WriteMask.COLOR)
- .polygonOffset(true) // vanilla shadows use "view offset" but this seems to work fine
- .texture(new ResourceLocation("minecraft", "textures/misc/shadow.png"))
- .build();
+ /**
+ * A single quad extending from the origin to (1, 0, 1).
+ *
+ * To be scaled and translated to the correct position and size.
+ */
+ private static class ShadowMesh implements QuadMesh {
private static final Vector4fc BOUNDING_SPHERE = new Vector4f(0.5f, 0, 0.5f, (float) (Math.sqrt(2) * 0.5));
- private static final ImmutableMap meshes = ImmutableMap.of(MATERIAL, ShadowMesh.INSTANCE);
+ private static final ShadowMesh INSTANCE = new ShadowMesh();
- private ShadowModel() {
+ private ShadowMesh() {
}
@Override
- public Map meshes() {
- return meshes;
+ public int vertexCount() {
+ return 4;
+ }
+
+ @Override
+ public void write(MutableVertexList vertexList) {
+ writeVertex(vertexList, 0, 0, 0);
+ writeVertex(vertexList, 1, 0, 1);
+ writeVertex(vertexList, 2, 1, 1);
+ writeVertex(vertexList, 3, 1, 0);
}
@Override
@@ -224,68 +245,25 @@ public class ShadowComponent {
return BOUNDING_SPHERE;
}
- @Override
- public int vertexCount() {
- return ShadowMesh.INSTANCE.vertexCount();
- }
-
@Override
public void delete() {
-
}
- /**
- * A single quad extending from the origin to (1, 0, 1).
- *
- * To be scaled and translated to the correct position and size.
- */
- private static class ShadowMesh implements QuadMesh {
- public static final ShadowMesh INSTANCE = new ShadowMesh();
-
- private ShadowMesh() {
- }
-
- @Override
- public int vertexCount() {
- return 4;
- }
-
- @Override
- public void write(MutableVertexList vertexList) {
- writeVertex(vertexList, 0, 0, 0);
- writeVertex(vertexList, 1, 0, 1);
- writeVertex(vertexList, 2, 1, 1);
- writeVertex(vertexList, 3, 1, 0);
- }
-
- @Override
- public Vector4fc boundingSphere() {
- return BOUNDING_SPHERE;
- }
-
- @Override
- public void delete() {
-
- }
-
- // Magic numbers taken from:
- // net.minecraft.client.renderer.entity.EntityRenderDispatcher#shadowVertex
- private static void writeVertex(MutableVertexList vertexList, int i, float x, float z) {
- vertexList.x(i, x);
- vertexList.y(i, 0);
- vertexList.z(i, z);
- vertexList.r(i, 1);
- vertexList.g(i, 1);
- vertexList.b(i, 1);
- vertexList.u(i, 0);
- vertexList.v(i, 0);
- vertexList.light(i, 15728880);
- vertexList.normalX(i, 0);
- vertexList.normalY(i, 1);
- vertexList.normalZ(i, 0);
-
- }
+ // Magic numbers taken from:
+ // net.minecraft.client.renderer.entity.EntityRenderDispatcher#shadowVertex
+ private static void writeVertex(MutableVertexList vertexList, int i, float x, float z) {
+ vertexList.x(i, x);
+ vertexList.y(i, 0);
+ vertexList.z(i, z);
+ vertexList.r(i, 1);
+ vertexList.g(i, 1);
+ vertexList.b(i, 1);
+ vertexList.u(i, 0);
+ vertexList.v(i, 0);
+ vertexList.light(i, LightTexture.FULL_BRIGHT);
+ vertexList.normalX(i, 0);
+ vertexList.normalY(i, 1);
+ vertexList.normalZ(i, 0);
}
}
-
}
diff --git a/src/main/java/com/jozufozu/flywheel/mixin/FogUpdateMixin.java b/src/main/java/com/jozufozu/flywheel/mixin/FogUpdateMixin.java
deleted file mode 100644
index 92e50e5dc..000000000
--- a/src/main/java/com/jozufozu/flywheel/mixin/FogUpdateMixin.java
+++ /dev/null
@@ -1,38 +0,0 @@
-package com.jozufozu.flywheel.mixin;
-
-import org.spongepowered.asm.mixin.Mixin;
-import org.spongepowered.asm.mixin.Unique;
-import org.spongepowered.asm.mixin.injection.At;
-import org.spongepowered.asm.mixin.injection.Inject;
-import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
-
-import com.jozufozu.flywheel.backend.engine.uniform.Uniforms;
-import com.jozufozu.flywheel.backend.gl.GlStateTracker;
-
-import net.minecraft.client.renderer.FogRenderer;
-
-@Mixin(FogRenderer.class)
-abstract class FogUpdateMixin {
- @Unique
- private static void flywheel$updateFog() {
- try (var restoreState = GlStateTracker.getRestoreState()) {
- Uniforms.fog()
- .update();
- }
- }
-
- @Inject(method = "setupNoFog()V", at = @At("RETURN"))
- private static void flywheel$onNoFog(CallbackInfo ci) {
- flywheel$updateFog();
- }
-
- @Inject(method = "setupFog(Lnet/minecraft/client/Camera;Lnet/minecraft/client/renderer/FogRenderer$FogMode;FZF)V", at = @At("RETURN"), remap = false)
- private static void flywheel$onFog(CallbackInfo ci) {
- flywheel$updateFog();
- }
-
- @Inject(method = "levelFogColor()V", at = @At("RETURN"))
- private static void flywheel$onFogColor(CallbackInfo ci) {
- flywheel$updateFog();
- }
-}
diff --git a/src/main/resources/flywheel.backend.mixins.json b/src/main/resources/flywheel.backend.mixins.json
new file mode 100644
index 000000000..07bbade87
--- /dev/null
+++ b/src/main/resources/flywheel.backend.mixins.json
@@ -0,0 +1,14 @@
+{
+ "required": true,
+ "minVersion": "0.8",
+ "package": "com.jozufozu.flywheel.backend.mixin",
+ "compatibilityLevel": "JAVA_17",
+ "refmap": "flywheel.refmap.json",
+ "client": [
+ "GlStateManagerMixin",
+ "RenderSystemMixin"
+ ],
+ "injectors": {
+ "defaultRequire": 1
+ }
+}
diff --git a/src/main/resources/flywheel.mixins.json b/src/main/resources/flywheel.impl.mixins.json
similarity index 65%
rename from src/main/resources/flywheel.mixins.json
rename to src/main/resources/flywheel.impl.mixins.json
index e2c5fc7ba..47b52454b 100644
--- a/src/main/resources/flywheel.mixins.json
+++ b/src/main/resources/flywheel.impl.mixins.json
@@ -1,15 +1,13 @@
{
"required": true,
"minVersion": "0.8",
- "package": "com.jozufozu.flywheel.mixin",
+ "package": "com.jozufozu.flywheel.impl.mixin",
"compatibilityLevel": "JAVA_17",
"refmap": "flywheel.refmap.json",
"client": [
"BlockEntityTypeMixin",
"ClientLevelMixin",
"EntityTypeMixin",
- "FogUpdateMixin",
- "GlStateManagerMixin",
"LayerLightSectionStorageMixin",
"LevelMixin",
"LevelRendererMixin",
@@ -18,10 +16,10 @@
"VertexFormatMixin",
"fix.FixFabulousDepthMixin",
"fix.FixNormalScalingMixin",
- "visualmanage.ChunkRebuildHooksMixin",
- "visualmanage.VisualAddMixin",
- "visualmanage.VisualRemoveMixin",
- "visualmanage.VisualUpdateMixin"
+ "visualmanage.BlockEntityMixin",
+ "visualmanage.LevelChunkMixin",
+ "visualmanage.LevelRendererMixin",
+ "visualmanage.RebuildTaskMixin"
],
"injectors": {
"defaultRequire": 1
diff --git a/src/main/resources/flywheel.sodium.mixins.json b/src/main/resources/flywheel.impl.sodium.mixins.json
similarity index 62%
rename from src/main/resources/flywheel.sodium.mixins.json
rename to src/main/resources/flywheel.impl.sodium.mixins.json
index 997dfa2da..c02f33509 100644
--- a/src/main/resources/flywheel.sodium.mixins.json
+++ b/src/main/resources/flywheel.impl.sodium.mixins.json
@@ -1,10 +1,10 @@
{
"required": true,
"minVersion": "0.8",
- "package": "com.jozufozu.flywheel.mixin.sodium",
+ "package": "com.jozufozu.flywheel.impl.mixin.sodium",
"compatibilityLevel": "JAVA_17",
"refmap": "flywheel.refmap.json",
- "plugin": "com.jozufozu.flywheel.compat.SodiumMixinPlugin",
+ "plugin": "com.jozufozu.flywheel.impl.mixin.sodium.SodiumMixinPlugin",
"client": [
"ChunkBuilderMeshingTaskMixin"
],