diff --git a/src/main/java/com/jozufozu/flywheel/api/backend/Engine.java b/src/main/java/com/jozufozu/flywheel/api/backend/Engine.java
index 22c755acd..e21e2658e 100644
--- a/src/main/java/com/jozufozu/flywheel/api/backend/Engine.java
+++ b/src/main/java/com/jozufozu/flywheel/api/backend/Engine.java
@@ -6,7 +6,10 @@ import com.jozufozu.flywheel.api.BackendImplemented;
import com.jozufozu.flywheel.api.event.RenderContext;
import com.jozufozu.flywheel.api.event.RenderStage;
import com.jozufozu.flywheel.api.instance.Instance;
+import com.jozufozu.flywheel.api.instance.InstanceType;
+import com.jozufozu.flywheel.api.instance.Instancer;
import com.jozufozu.flywheel.api.instance.InstancerProvider;
+import com.jozufozu.flywheel.api.model.Model;
import com.jozufozu.flywheel.api.task.Plan;
import com.jozufozu.flywheel.api.task.TaskExecutor;
@@ -15,7 +18,21 @@ import net.minecraft.core.BlockPos;
import net.minecraft.core.Vec3i;
@BackendImplemented
-public interface Engine extends InstancerProvider {
+public interface Engine {
+ /**
+ * Get an instancer for the given instance type, model, and render stage.
+ *
+ *
Calling this method twice with the same arguments will return the same instancer.
+ *
+ * If you are writing a visual you should probably be using
+ * {@link InstancerProvider#instancer(InstanceType, Model)}, which will decide the {@code RenderStage}
+ * based on what type of visual is getting the instancer.
+ *
+ * @return An instancer for the given instance type, model, and render stage.
+ * @see InstancerProvider
+ */
+ Instancer instancer(InstanceType type, Model model, RenderStage stage);
+
/**
* Create a plan that will be executed every frame.
* @return A new plan.
diff --git a/src/main/java/com/jozufozu/flywheel/api/instance/InstancerProvider.java b/src/main/java/com/jozufozu/flywheel/api/instance/InstancerProvider.java
index 1cc987d50..cc3cbcc9a 100644
--- a/src/main/java/com/jozufozu/flywheel/api/instance/InstancerProvider.java
+++ b/src/main/java/com/jozufozu/flywheel/api/instance/InstancerProvider.java
@@ -1,17 +1,14 @@
package com.jozufozu.flywheel.api.instance;
-import com.jozufozu.flywheel.api.BackendImplemented;
-import com.jozufozu.flywheel.api.event.RenderStage;
import com.jozufozu.flywheel.api.model.Model;
-@BackendImplemented
public interface InstancerProvider {
/**
- * Get an instancer for the given instance type, model, and render stage.
- *
- * Calling this method twice with the same arguments will return the same instancer.
+ * Get an instancer for the given instance type rendering the given model.
*
- * @return An instancer for the given instance type, model, and render stage.
+ * Calling this method twice with the same arguments will return the same instancer.
+ *
+ * @return An instancer for the given instance type rendering the given model.
*/
- Instancer instancer(InstanceType type, Model model, RenderStage stage);
+ Instancer instancer(InstanceType type, Model model);
}
diff --git a/src/main/java/com/jozufozu/flywheel/impl/visualization/InstancerProviderImpl.java b/src/main/java/com/jozufozu/flywheel/impl/visualization/InstancerProviderImpl.java
new file mode 100644
index 000000000..aea75eb37
--- /dev/null
+++ b/src/main/java/com/jozufozu/flywheel/impl/visualization/InstancerProviderImpl.java
@@ -0,0 +1,25 @@
+package com.jozufozu.flywheel.impl.visualization;
+
+import java.util.function.Supplier;
+
+import com.jozufozu.flywheel.api.backend.Engine;
+import com.jozufozu.flywheel.api.event.RenderStage;
+import com.jozufozu.flywheel.api.instance.Instance;
+import com.jozufozu.flywheel.api.instance.InstanceType;
+import com.jozufozu.flywheel.api.instance.Instancer;
+import com.jozufozu.flywheel.api.instance.InstancerProvider;
+import com.jozufozu.flywheel.api.model.Model;
+import com.jozufozu.flywheel.api.visualization.VisualizationContext;
+
+public record InstancerProviderImpl(Engine engine,
+ RenderStage renderStage) implements InstancerProvider, Supplier {
+ @Override
+ public Instancer instancer(InstanceType type, Model model) {
+ return engine.instancer(type, model, renderStage);
+ }
+
+ @Override
+ public VisualizationContext get() {
+ return new VisualizationContextImpl(this, engine.renderOrigin());
+ }
+}
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 76fdedcb1..e06ec0f8f 100644
--- a/src/main/java/com/jozufozu/flywheel/impl/visualization/VisualizationManagerImpl.java
+++ b/src/main/java/com/jozufozu/flywheel/impl/visualization/VisualizationManagerImpl.java
@@ -3,7 +3,6 @@ package com.jozufozu.flywheel.impl.visualization;
import java.util.ArrayList;
import java.util.List;
import java.util.SortedSet;
-import java.util.function.Supplier;
import org.jetbrains.annotations.Contract;
import org.jetbrains.annotations.Nullable;
@@ -23,7 +22,6 @@ import com.jozufozu.flywheel.api.visual.TickableVisual;
import com.jozufozu.flywheel.api.visual.VisualFrameContext;
import com.jozufozu.flywheel.api.visual.VisualTickContext;
import com.jozufozu.flywheel.api.visualization.VisualManager;
-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;
@@ -86,11 +84,9 @@ public class VisualizationManagerImpl implements VisualizationManager {
.createEngine(level);
taskExecutor = FlwTaskExecutor.get();
- Supplier contextSupplier = () -> new VisualizationContextImpl(engine, engine.renderOrigin());
-
- var blockEntitiesStorage = new BlockEntityStorage(contextSupplier);
- var entitiesStorage = new EntityStorage(contextSupplier);
- var effectsStorage = new EffectStorage(contextSupplier);
+ var blockEntitiesStorage = new BlockEntityStorage(new InstancerProviderImpl(engine, RenderStage.AFTER_BLOCK_ENTITIES));
+ var entitiesStorage = new EntityStorage(new InstancerProviderImpl(engine, RenderStage.AFTER_ENTITIES));
+ var effectsStorage = new EffectStorage(new InstancerProviderImpl(engine, RenderStage.AFTER_PARTICLES));
blockEntities = new VisualManagerImpl<>(blockEntitiesStorage);
entities = new VisualManagerImpl<>(entitiesStorage);
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 49a7b62eb..15ce01bdc 100644
--- a/src/main/java/com/jozufozu/flywheel/lib/visual/FireComponent.java
+++ b/src/main/java/com/jozufozu/flywheel/lib/visual/FireComponent.java
@@ -3,7 +3,6 @@ package com.jozufozu.flywheel.lib.visual;
import org.joml.Vector4f;
import org.joml.Vector4fc;
-import com.jozufozu.flywheel.api.event.RenderStage;
import com.jozufozu.flywheel.api.material.Material;
import com.jozufozu.flywheel.api.vertex.MutableVertexList;
import com.jozufozu.flywheel.api.visual.VisualFrameContext;
@@ -54,7 +53,7 @@ public class FireComponent {
private TransformedInstance createInstance(net.minecraft.client.resources.model.Material texture) {
TransformedInstance instance = context.instancerProvider()
- .instancer(InstanceTypes.TRANSFORMED, FIRE_MODELS.get(texture), RenderStage.AFTER_ENTITIES)
+ .instancer(InstanceTypes.TRANSFORMED, FIRE_MODELS.get(texture))
.createInstance();
instance.setBlockLight(LightTexture.block(LightTexture.FULL_BLOCK));
instance.setChanged();
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 08766cf89..b4d8930c2 100644
--- a/src/main/java/com/jozufozu/flywheel/lib/visual/ShadowComponent.java
+++ b/src/main/java/com/jozufozu/flywheel/lib/visual/ShadowComponent.java
@@ -4,7 +4,6 @@ import org.jetbrains.annotations.Nullable;
import org.joml.Vector4f;
import org.joml.Vector4fc;
-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;
@@ -70,7 +69,7 @@ public class ShadowComponent {
private ShadowInstance createInstance() {
return context.instancerProvider()
- .instancer(InstanceTypes.SHADOW, SHADOW_MODEL, RenderStage.AFTER_ENTITIES)
+ .instancer(InstanceTypes.SHADOW, SHADOW_MODEL)
.createInstance();
}
diff --git a/src/main/java/com/jozufozu/flywheel/vanilla/BellVisual.java b/src/main/java/com/jozufozu/flywheel/vanilla/BellVisual.java
index aded9687b..32c12ba07 100644
--- a/src/main/java/com/jozufozu/flywheel/vanilla/BellVisual.java
+++ b/src/main/java/com/jozufozu/flywheel/vanilla/BellVisual.java
@@ -6,7 +6,6 @@ import org.joml.AxisAngle4f;
import org.joml.Quaternionf;
import org.joml.Vector3f;
-import com.jozufozu.flywheel.api.event.RenderStage;
import com.jozufozu.flywheel.api.instance.Instance;
import com.jozufozu.flywheel.api.visual.DynamicVisual;
import com.jozufozu.flywheel.api.visual.VisualFrameContext;
@@ -50,7 +49,7 @@ public class BellVisual extends AbstractBlockEntityVisual imple
}
private OrientedInstance createBellInstance() {
- return instancerProvider.instancer(InstanceTypes.ORIENTED, BELL_MODEL.get(), RenderStage.AFTER_BLOCK_ENTITIES)
+ return instancerProvider.instancer(InstanceTypes.ORIENTED, BELL_MODEL.get())
.createInstance();
}
diff --git a/src/main/java/com/jozufozu/flywheel/vanilla/ChestVisual.java b/src/main/java/com/jozufozu/flywheel/vanilla/ChestVisual.java
index e5ed24fdd..ccabc2e10 100644
--- a/src/main/java/com/jozufozu/flywheel/vanilla/ChestVisual.java
+++ b/src/main/java/com/jozufozu/flywheel/vanilla/ChestVisual.java
@@ -7,7 +7,6 @@ import java.util.function.Consumer;
import org.joml.Quaternionf;
-import com.jozufozu.flywheel.api.event.RenderStage;
import com.jozufozu.flywheel.api.instance.Instance;
import com.jozufozu.flywheel.api.visual.DynamicVisual;
import com.jozufozu.flywheel.api.visual.VisualFrameContext;
@@ -98,17 +97,17 @@ public class ChestVisual extends Abstrac
}
private OrientedInstance createBottomInstance(Material texture) {
- return instancerProvider.instancer(InstanceTypes.ORIENTED, BOTTOM_MODELS.get(Pair.of(chestType, texture)), RenderStage.AFTER_BLOCK_ENTITIES)
+ return instancerProvider.instancer(InstanceTypes.ORIENTED, BOTTOM_MODELS.get(Pair.of(chestType, texture)))
.createInstance();
}
private TransformedInstance createLidInstance(Material texture) {
- return instancerProvider.instancer(InstanceTypes.TRANSFORMED, LID_MODELS.get(Pair.of(chestType, texture)), RenderStage.AFTER_BLOCK_ENTITIES)
+ return instancerProvider.instancer(InstanceTypes.TRANSFORMED, LID_MODELS.get(Pair.of(chestType, texture)))
.createInstance();
}
private TransformedInstance createLockInstance(Material texture) {
- return instancerProvider.instancer(InstanceTypes.TRANSFORMED, LOCK_MODELS.get(Pair.of(chestType, texture)), RenderStage.AFTER_BLOCK_ENTITIES)
+ return instancerProvider.instancer(InstanceTypes.TRANSFORMED, LOCK_MODELS.get(Pair.of(chestType, texture)))
.createInstance();
}
diff --git a/src/main/java/com/jozufozu/flywheel/vanilla/MinecartVisual.java b/src/main/java/com/jozufozu/flywheel/vanilla/MinecartVisual.java
index 61dde9ea6..2b19898f8 100644
--- a/src/main/java/com/jozufozu/flywheel/vanilla/MinecartVisual.java
+++ b/src/main/java/com/jozufozu/flywheel/vanilla/MinecartVisual.java
@@ -2,7 +2,6 @@ package com.jozufozu.flywheel.vanilla;
import org.jetbrains.annotations.Nullable;
-import com.jozufozu.flywheel.api.event.RenderStage;
import com.jozufozu.flywheel.api.visual.DynamicVisual;
import com.jozufozu.flywheel.api.visual.TickableVisual;
import com.jozufozu.flywheel.api.visual.VisualFrameContext;
@@ -70,7 +69,7 @@ public class MinecartVisual extends AbstractEntityVi
}
private TransformedInstance createBodyInstance() {
- return instancerProvider.instancer(InstanceTypes.TRANSFORMED, bodyModel.get(), RenderStage.AFTER_ENTITIES)
+ return instancerProvider.instancer(InstanceTypes.TRANSFORMED, bodyModel.get())
.createInstance();
}
@@ -89,7 +88,7 @@ public class MinecartVisual extends AbstractEntityVi
return null;
}
- return instancerProvider.instancer(InstanceTypes.TRANSFORMED, Models.block(blockState), RenderStage.AFTER_ENTITIES)
+ return instancerProvider.instancer(InstanceTypes.TRANSFORMED, Models.block(blockState))
.createInstance();
}
diff --git a/src/main/java/com/jozufozu/flywheel/vanilla/ShulkerBoxVisual.java b/src/main/java/com/jozufozu/flywheel/vanilla/ShulkerBoxVisual.java
index efa9491e8..c302045a8 100644
--- a/src/main/java/com/jozufozu/flywheel/vanilla/ShulkerBoxVisual.java
+++ b/src/main/java/com/jozufozu/flywheel/vanilla/ShulkerBoxVisual.java
@@ -4,7 +4,6 @@ import java.util.function.Consumer;
import org.joml.Quaternionf;
-import com.jozufozu.flywheel.api.event.RenderStage;
import com.jozufozu.flywheel.api.instance.Instance;
import com.jozufozu.flywheel.api.visual.DynamicVisual;
import com.jozufozu.flywheel.api.visual.VisualFrameContext;
@@ -78,12 +77,12 @@ public class ShulkerBoxVisual extends AbstractBlockEntityVisual