) materials.computeIfAbsent(spec, this::createInstanceMaterial);
- }
-
- private InstanceMaterial> createInstanceMaterial(MaterialSpec> type) {
- InstanceMaterial> material = new InstanceMaterial<>(owner::getOriginCoordinate, type);
-
- this.renderers.add(new MaterialRenderer<>(owner.getProgram(type.getProgramName()), material, this::setup));
-
- return material;
- }
-
public void clear() {
materials.values().forEach(InstanceMaterial::clear);
}
@@ -58,4 +62,12 @@ public class MaterialGroup {
materials.clear();
renderers.clear();
}
+
+ private InstanceMaterial> createInstanceMaterial(MaterialSpec> type) {
+ InstanceMaterial> material = new InstanceMaterial<>(type);
+
+ this.renderers.add(new MaterialRenderer<>(owner.getProgram(type.getProgramName()), material, this::setup));
+
+ return material;
+ }
}
diff --git a/src/main/java/com/jozufozu/flywheel/backend/material/MaterialManager.java b/src/main/java/com/jozufozu/flywheel/backend/material/MaterialManager.java
index d9436c117..869be4cff 100644
--- a/src/main/java/com/jozufozu/flywheel/backend/material/MaterialManager.java
+++ b/src/main/java/com/jozufozu/flywheel/backend/material/MaterialManager.java
@@ -60,9 +60,44 @@ public class MaterialManager
{
}
}
+ /**
+ * Get a material group that will render in the given layer with the given state.
+ *
+ * @param layer The {@link RenderLayer} you want to draw in.
+ * @param state The {@link IRenderState} you need to draw with.
+ * @return A material group whose children will
+ */
+ public MaterialGroup
state(RenderLayer layer, IRenderState state) {
+ return layers.get(layer).computeIfAbsent(state, this::createGroup);
+ }
+
+ public MaterialGroup
solid(IRenderState state) {
+ return layers.get(RenderLayer.SOLID).computeIfAbsent(state, this::createGroup);
+ }
+
+ public MaterialGroup
cutout(IRenderState state) {
+ return layers.get(RenderLayer.CUTOUT).computeIfAbsent(state, this::createGroup);
+ }
+
+ public MaterialGroup
transparent(IRenderState state) {
+ return layers.get(RenderLayer.TRANSPARENT).computeIfAbsent(state, this::createGroup);
+ }
+
+ public MaterialGroup
defaultSolid() {
+ return solid(TextureRenderState.get(PlayerContainer.BLOCK_ATLAS));
+ }
+
+ public MaterialGroup
defaultCutout() {
+ return cutout(TextureRenderState.get(PlayerContainer.BLOCK_ATLAS));
+ }
+
+ public MaterialGroup
defaultTransparent() {
+ return transparent(TextureRenderState.get(PlayerContainer.BLOCK_ATLAS));
+ }
+
/**
* Render every model for every material.
- * @param layer Which vanilla {@link RenderType} is being drawn?
+ * @param layer Which of the 3 {@link RenderLayer render layers} is being drawn?
* @param viewProjection How do we get from camera space to clip space?
*/
public void render(RenderLayer layer, Matrix4f viewProjection, double camX, double camY, double camZ) {
@@ -95,34 +130,6 @@ public class MaterialManager
{
}
}
- public MaterialGroup
state(RenderLayer layer, IRenderState state) {
- return layers.get(layer).computeIfAbsent(state, this::createGroup);
- }
-
- public MaterialGroup
solid(IRenderState state) {
- return layers.get(RenderLayer.SOLID).computeIfAbsent(state, this::createGroup);
- }
-
- public MaterialGroup
cutout(IRenderState state) {
- return layers.get(RenderLayer.CUTOUT).computeIfAbsent(state, this::createGroup);
- }
-
- public MaterialGroup
transparent(IRenderState state) {
- return layers.get(RenderLayer.TRANSPARENT).computeIfAbsent(state, this::createGroup);
- }
-
- public MaterialGroup
defaultSolid() {
- return solid(TextureRenderState.get(PlayerContainer.BLOCK_ATLAS));
- }
-
- public MaterialGroup
defaultCutout() {
- return cutout(TextureRenderState.get(PlayerContainer.BLOCK_ATLAS));
- }
-
- public MaterialGroup
defaultTransparent() {
- return transparent(TextureRenderState.get(PlayerContainer.BLOCK_ATLAS));
- }
-
@Deprecated
public InstanceMaterial getMaterial(MaterialSpec materialType) {
return defaultCutout().material(materialType);
@@ -155,6 +162,11 @@ public class MaterialManager {
listeners.add(listener);
}
+ /**
+ * Maintain the integer origin coordinate to be within a certain distance from the camera in all directions.
+ *
+ * This prevents floating point precision issues at high coordinates.
+ */
public void checkAndShiftOrigin(ActiveRenderInfo info) {
int cX = MathHelper.floor(info.getPosition().x);
int cY = MathHelper.floor(info.getPosition().y);
diff --git a/src/main/java/com/jozufozu/flywheel/backend/material/MaterialSpec.java b/src/main/java/com/jozufozu/flywheel/backend/material/MaterialSpec.java
index 8946fcbff..9b3a87b5a 100644
--- a/src/main/java/com/jozufozu/flywheel/backend/material/MaterialSpec.java
+++ b/src/main/java/com/jozufozu/flywheel/backend/material/MaterialSpec.java
@@ -4,7 +4,6 @@ import com.jozufozu.flywheel.backend.gl.attrib.VertexFormat;
import com.jozufozu.flywheel.backend.instancing.IInstanceFactory;
import com.jozufozu.flywheel.backend.instancing.InstanceData;
-import net.minecraft.inventory.container.PlayerContainer;
import net.minecraft.util.ResourceLocation;
public class MaterialSpec {
@@ -15,19 +14,13 @@ public class MaterialSpec {
private final VertexFormat modelFormat;
private final VertexFormat instanceFormat;
private final IInstanceFactory instanceFactory;
- private final ResourceLocation texture;
public MaterialSpec(ResourceLocation name, ResourceLocation programSpec, VertexFormat modelFormat, VertexFormat instanceFormat, IInstanceFactory instanceFactory) {
- this(name, programSpec, modelFormat, instanceFormat, PlayerContainer.BLOCK_ATLAS, instanceFactory);
- }
-
- public MaterialSpec(ResourceLocation name, ResourceLocation programSpec, VertexFormat modelFormat, VertexFormat instanceFormat, ResourceLocation texture, IInstanceFactory instanceFactory) {
this.name = name;
this.programSpec = programSpec;
this.modelFormat = modelFormat;
this.instanceFormat = instanceFormat;
this.instanceFactory = instanceFactory;
- this.texture = texture;
}
public ResourceLocation getProgramName() {
diff --git a/src/main/java/com/jozufozu/flywheel/backend/material/package-info.java b/src/main/java/com/jozufozu/flywheel/backend/material/package-info.java
new file mode 100644
index 000000000..da6906de5
--- /dev/null
+++ b/src/main/java/com/jozufozu/flywheel/backend/material/package-info.java
@@ -0,0 +1,6 @@
+@ParametersAreNonnullByDefault @MethodsReturnNonnullByDefault
+package com.jozufozu.flywheel.backend.material;
+
+import javax.annotation.ParametersAreNonnullByDefault;
+
+import mcp.MethodsReturnNonnullByDefault;
diff --git a/src/main/java/com/jozufozu/flywheel/backend/state/RenderLayer.java b/src/main/java/com/jozufozu/flywheel/backend/state/RenderLayer.java
index 231e5cead..8594f1f00 100644
--- a/src/main/java/com/jozufozu/flywheel/backend/state/RenderLayer.java
+++ b/src/main/java/com/jozufozu/flywheel/backend/state/RenderLayer.java
@@ -4,9 +4,36 @@ import javax.annotation.Nullable;
import net.minecraft.client.renderer.RenderType;
+/**
+ * The 3 discrete stages the world is rendered in.
+ */
public enum RenderLayer {
+ /**
+ * Solid layer:
+ *
+ * All polygons will entirely occlude everything behind them.
+ *
+ *
+ * e.g. stone, dirt, solid blocks
+ */
SOLID,
+ /**
+ * Cutout layer:
+ *
+ * Fragments will either occlude or not occlude depending on the texture/material.
+ *
+ *
+ * e.g. leaves, cobwebs, tall grass, saplings, glass
+ */
CUTOUT,
+ /**
+ * Transparent layer:
+ *
+ * Nothing is guaranteed to occlude and fragments blend their color with what's behind them.
+ *
+ *
+ * e.g. stained glass, water
+ */
TRANSPARENT,
;
diff --git a/src/main/java/com/jozufozu/flywheel/backend/state/package-info.java b/src/main/java/com/jozufozu/flywheel/backend/state/package-info.java
new file mode 100644
index 000000000..0fb20311b
--- /dev/null
+++ b/src/main/java/com/jozufozu/flywheel/backend/state/package-info.java
@@ -0,0 +1,6 @@
+@ParametersAreNonnullByDefault @MethodsReturnNonnullByDefault
+package com.jozufozu.flywheel.backend.state;
+
+import javax.annotation.ParametersAreNonnullByDefault;
+
+import mcp.MethodsReturnNonnullByDefault;
diff --git a/src/main/java/com/jozufozu/flywheel/core/crumbling/package-info.java b/src/main/java/com/jozufozu/flywheel/core/crumbling/package-info.java
new file mode 100644
index 000000000..00190daac
--- /dev/null
+++ b/src/main/java/com/jozufozu/flywheel/core/crumbling/package-info.java
@@ -0,0 +1,6 @@
+@ParametersAreNonnullByDefault @MethodsReturnNonnullByDefault
+package com.jozufozu.flywheel.core.crumbling;
+
+import javax.annotation.ParametersAreNonnullByDefault;
+
+import mcp.MethodsReturnNonnullByDefault;
diff --git a/src/main/java/com/jozufozu/flywheel/core/model/BlockModel.java b/src/main/java/com/jozufozu/flywheel/core/model/BlockModel.java
index 3a30847c6..631c87da1 100644
--- a/src/main/java/com/jozufozu/flywheel/core/model/BlockModel.java
+++ b/src/main/java/com/jozufozu/flywheel/core/model/BlockModel.java
@@ -30,6 +30,12 @@ public class BlockModel implements IModel {
private final VertexFormat modelFormat;
+ public BlockModel(VertexFormat modelFormat, BlockState state) {
+ this(modelFormat, Minecraft.getInstance()
+ .getBlockRenderer()
+ .getBlockModel(state), state);
+ }
+
public BlockModel(VertexFormat modelFormat, IBakedModel model, BlockState referenceState) {
this(modelFormat, model, referenceState, IDENTITY);
}
diff --git a/src/main/java/com/jozufozu/flywheel/event/ReloadRenderersEvent.java b/src/main/java/com/jozufozu/flywheel/event/ReloadRenderersEvent.java
index dc7bac5fb..aad67e6fd 100644
--- a/src/main/java/com/jozufozu/flywheel/event/ReloadRenderersEvent.java
+++ b/src/main/java/com/jozufozu/flywheel/event/ReloadRenderersEvent.java
@@ -1,5 +1,7 @@
package com.jozufozu.flywheel.event;
+import javax.annotation.Nullable;
+
import net.minecraft.client.world.ClientWorld;
import net.minecraftforge.eventbus.api.Event;
@@ -10,6 +12,7 @@ public class ReloadRenderersEvent extends Event {
this.world = world;
}
+ @Nullable
public ClientWorld getWorld() {
return world;
}
diff --git a/src/main/java/com/jozufozu/flywheel/event/RenderLayerEvent.java b/src/main/java/com/jozufozu/flywheel/event/RenderLayerEvent.java
index a22816f71..fafcfbf75 100644
--- a/src/main/java/com/jozufozu/flywheel/event/RenderLayerEvent.java
+++ b/src/main/java/com/jozufozu/flywheel/event/RenderLayerEvent.java
@@ -1,5 +1,9 @@
package com.jozufozu.flywheel.event;
+import javax.annotation.Nullable;
+
+import com.jozufozu.flywheel.backend.state.RenderLayer;
+
import net.minecraft.client.renderer.RenderType;
import net.minecraft.client.world.ClientWorld;
import net.minecraft.util.math.vector.Matrix4f;
@@ -12,6 +16,7 @@ public class RenderLayerEvent extends Event {
public final double camX;
public final double camY;
public final double camZ;
+ public final RenderLayer layer;
public RenderLayerEvent(ClientWorld world, RenderType type, Matrix4f viewProjection, double camX, double camY, double camZ) {
this.world = world;
@@ -20,6 +25,13 @@ public class RenderLayerEvent extends Event {
this.camX = camX;
this.camY = camY;
this.camZ = camZ;
+
+ this.layer = RenderLayer.fromRenderType(type);
+ }
+
+ @Nullable
+ public RenderLayer getLayer() {
+ return layer;
}
public ClientWorld getWorld() {
diff --git a/src/main/java/com/jozufozu/flywheel/event/package-info.java b/src/main/java/com/jozufozu/flywheel/event/package-info.java
new file mode 100644
index 000000000..b2b0463bf
--- /dev/null
+++ b/src/main/java/com/jozufozu/flywheel/event/package-info.java
@@ -0,0 +1,6 @@
+@ParametersAreNonnullByDefault @MethodsReturnNonnullByDefault
+package com.jozufozu.flywheel.event;
+
+import javax.annotation.ParametersAreNonnullByDefault;
+
+import mcp.MethodsReturnNonnullByDefault;