diff --git a/dependencies.gradle b/dependencies.gradle index abadfde45..db50a3873 100644 --- a/dependencies.gradle +++ b/dependencies.gradle @@ -67,8 +67,8 @@ dependencies { compileOnly "org.apache.ant:ant:1.8.2" // Because who doesn't want NEI - compileOnly('com.github.GTNewHorizons:NotEnoughItems:2.5.21-GTNH:dev') - compileOnly('com.github.GTNewHorizons:CodeChickenCore:1.2.1:dev') + devOnlyNonPublishable('com.github.GTNewHorizons:NotEnoughItems:2.4.9-GTNH:dev') + devOnlyNonPublishable('com.github.GTNewHorizons:CodeChickenCore:1.2.0:dev') // Notfine Deps compileOnly("thaumcraft:Thaumcraft:1.7.10-4.2.3.5:dev") diff --git a/src/main/java/com/gtnewhorizons/angelica/common/BlockTest.java b/src/main/java/com/gtnewhorizons/angelica/common/BlockTest.java index 82f922c34..35f24868e 100644 --- a/src/main/java/com/gtnewhorizons/angelica/common/BlockTest.java +++ b/src/main/java/com/gtnewhorizons/angelica/common/BlockTest.java @@ -47,7 +47,7 @@ public class BlockTest extends Block implements QuadProvider { false ), }; - public static final List EMPTY = ObjectImmutableList.of(); + private static final List EMPTY = ObjectImmutableList.of(); private static final JsonModel[] model = new JsonModel[4]; public BlockTest() { diff --git a/src/main/java/com/gtnewhorizons/angelica/mixins/early/angelica/models/MixinBlockStone.java b/src/main/java/com/gtnewhorizons/angelica/mixins/early/angelica/models/MixinBlockStone.java index 96217b2e2..f72758b9c 100644 --- a/src/main/java/com/gtnewhorizons/angelica/mixins/early/angelica/models/MixinBlockStone.java +++ b/src/main/java/com/gtnewhorizons/angelica/mixins/early/angelica/models/MixinBlockStone.java @@ -2,6 +2,8 @@ package com.gtnewhorizons.angelica.mixins.early.angelica.models; import com.gtnewhorizons.angelica.compat.mojang.BlockPos; import com.gtnewhorizons.angelica.compat.nd.Quad; +import com.gtnewhorizons.angelica.models.MixinModels; +import com.gtnewhorizons.angelica.models.json.Variant; import com.gtnewhorizons.angelica.utils.ObjectPooler; import java.util.List; import java.util.Random; @@ -18,6 +20,6 @@ public abstract class MixinBlockStone implements QuadProvider { // TODO: Use modern model API public List getQuads(IBlockAccess world, BlockPos pos, Block block, int meta, ForgeDirection dir, Random random, ObjectPooler quadPool) { - return CubeModel.INSTANCE.get().getQuads(world, pos, block, meta, dir, random, quadPool); + return MixinModels.stoneModel.getQuads(world, pos, block, meta, dir, random, quadPool); } } diff --git a/src/main/java/com/gtnewhorizons/angelica/models/EncodingFormat.java b/src/main/java/com/gtnewhorizons/angelica/models/EncodingFormat.java deleted file mode 100644 index a3a8ad765..000000000 --- a/src/main/java/com/gtnewhorizons/angelica/models/EncodingFormat.java +++ /dev/null @@ -1,134 +0,0 @@ -package com.gtnewhorizons.angelica.models; - -import com.gtnewhorizons.angelica.compat.mojang.DefaultVertexFormat; -import com.gtnewhorizons.angelica.compat.mojang.VertexFormat; -import com.gtnewhorizons.angelica.models.material.RenderMaterialImpl; -import net.minecraft.util.MathHelper; -import net.minecraftforge.common.util.ForgeDirection; - -/** - * Holds all the array offsets and bit-wise encoders/decoders for - * packing/unpacking quad data in an array of integers. - * All of this is implementation-specific - that's why it isn't a "helper" class. - */ -public abstract class EncodingFormat { - private EncodingFormat() { } - - static final int HEADER_BITS = 0; - static final int HEADER_FACE_NORMAL = 1; - static final int HEADER_COLOR_INDEX = 2; - static final int HEADER_TAG = 3; - public static final int HEADER_STRIDE = 4; - - static final int VERTEX_X; - static final int VERTEX_Y; - static final int VERTEX_Z; - static final int VERTEX_COLOR; - static final int VERTEX_U; - static final int VERTEX_V; - static final int VERTEX_LIGHTMAP; - static final int VERTEX_NORMAL; - public static final int VERTEX_STRIDE; - - public static final int QUAD_STRIDE; - public static final int QUAD_STRIDE_BYTES; - public static final int TOTAL_STRIDE; - - static { - // Upstream uses POSITION_COLOR_TEXTURE_LIGHT_NORMAL, but Nd uses POSITION_COLOR_TEXTURE_LIGHT_NORMAL_NOPAD - final VertexFormat format = DefaultVertexFormat.POSITION_COLOR_TEXTURE_LIGHT_NORMAL; - VERTEX_X = HEADER_STRIDE + 0; - VERTEX_Y = HEADER_STRIDE + 1; - VERTEX_Z = HEADER_STRIDE + 2; - VERTEX_COLOR = HEADER_STRIDE + 3; - VERTEX_U = HEADER_STRIDE + 4; - VERTEX_V = VERTEX_U + 1; - VERTEX_LIGHTMAP = HEADER_STRIDE + 6; - VERTEX_NORMAL = HEADER_STRIDE + 7; - VERTEX_STRIDE = format.getVertexSize(); - QUAD_STRIDE = VERTEX_STRIDE * 4; - QUAD_STRIDE_BYTES = QUAD_STRIDE * 4; - TOTAL_STRIDE = HEADER_STRIDE + QUAD_STRIDE; - - //Preconditions.checkState(VERTEX_STRIDE == QuadView.VANILLA_VERTEX_STRIDE, "Indigo vertex stride (%s) mismatched with rendering API (%s)", VERTEX_STRIDE, QuadView.VANILLA_VERTEX_STRIDE); - //Preconditions.checkState(QUAD_STRIDE == QuadView.VANILLA_QUAD_STRIDE, "Indigo quad stride (%s) mismatched with rendering API (%s)", QUAD_STRIDE, QuadView.VANILLA_QUAD_STRIDE); - } - - /** used for quick clearing of quad buffers. */ - static final int[] EMPTY = new int[TOTAL_STRIDE]; - - // Default 7 - private static final int DIRECTION_MASK = MathHelper.roundUpToPowerOfTwo(ModelHelper.NULL_FACE_ID) - 1; - // Default 3 - private static final int DIRECTION_BIT_COUNT = Integer.bitCount(DIRECTION_MASK); - private static final int CULL_SHIFT = 0; - private static final int CULL_INVERSE_MASK = ~(DIRECTION_MASK << CULL_SHIFT); - private static final int LIGHT_SHIFT = CULL_SHIFT + DIRECTION_BIT_COUNT; - private static final int LIGHT_INVERSE_MASK = ~(DIRECTION_MASK << LIGHT_SHIFT); - private static final int NORMALS_SHIFT = LIGHT_SHIFT + DIRECTION_BIT_COUNT; - private static final int NORMALS_COUNT = 4; - // Lowest 4 bits - private static final int NORMALS_MASK = (1 << NORMALS_COUNT) - 1; - // -------- -------- ------NN NN------ - private static final int NORMALS_INVERSE_MASK = ~(NORMALS_MASK << NORMALS_SHIFT); - private static final int GEOMETRY_SHIFT = NORMALS_SHIFT + NORMALS_COUNT; - private static final int GEOMETRY_MASK = (1 << GeometryHelper.FLAG_BIT_COUNT) - 1; - private static final int GEOMETRY_INVERSE_MASK = ~(GEOMETRY_MASK << GEOMETRY_SHIFT); - private static final int MATERIAL_SHIFT = GEOMETRY_SHIFT + GeometryHelper.FLAG_BIT_COUNT; - private static final int MATERIAL_MASK = MathHelper.roundUpToPowerOfTwo(RenderMaterialImpl.VALUE_COUNT) - 1; - //private static final int MATERIAL_BIT_COUNT = Integer.bitCount(MATERIAL_MASK); - private static final int MATERIAL_INVERSE_MASK = ~(MATERIAL_MASK << MATERIAL_SHIFT); - - /*static { - Preconditions.checkArgument(MATERIAL_SHIFT + MATERIAL_BIT_COUNT <= 32, "Indigo header encoding bit count (%s) exceeds integer bit length)", TOTAL_STRIDE); - }*/ - - static ForgeDirection cullFace(int bits) { - return ModelHelper.faceFromIndex((bits >>> CULL_SHIFT) & DIRECTION_MASK); - } - - static int cullFace(int bits, ForgeDirection face) { - return (bits & CULL_INVERSE_MASK) | (ModelHelper.toFaceIndex(face) << CULL_SHIFT); - } - - static ForgeDirection lightFace(int bits) { - return ModelHelper.faceFromIndex((bits >>> LIGHT_SHIFT) & DIRECTION_MASK); - } - - static int lightFace(int bits, ForgeDirection face) { - return (bits & LIGHT_INVERSE_MASK) | (ModelHelper.toFaceIndex(face) << LIGHT_SHIFT); - } - - /** indicate if vertex normal has been set - bits correspond to vertex ordinals. */ - static int normalFlags(int bits) { - return (bits >>> NORMALS_SHIFT) & NORMALS_MASK; - } - - /** - * I believe this merges a set of flags with the given normal flags. - */ - public static int normalFlags(int bits, int normalFlags) { - - // (normalFlags & NORMALS_MASK) extracts the bottom four bits - // << NORMALS_SHIFT shifts it up to the right spot - // (bits & NORMALS_INVERSE_MASK) extracts normals from the bits - // The two sets are ORd together and returned - return (bits & NORMALS_INVERSE_MASK) | ((normalFlags & NORMALS_MASK) << NORMALS_SHIFT); - } - - static int geometryFlags(int bits) { - return (bits >>> GEOMETRY_SHIFT) & GEOMETRY_MASK; - } - - static int geometryFlags(int bits, int geometryFlags) { - return (bits & GEOMETRY_INVERSE_MASK) | ((geometryFlags & GEOMETRY_MASK) << GEOMETRY_SHIFT); - } - - static RenderMaterialImpl material(int bits) { - return RenderMaterialImpl.byIndex((bits >>> MATERIAL_SHIFT) & MATERIAL_MASK); - } - - public static int material(int bits, RenderMaterialImpl material) { - return (bits & MATERIAL_INVERSE_MASK) | (material.index() << MATERIAL_SHIFT); - } -} diff --git a/src/main/java/com/gtnewhorizons/angelica/models/Material.java b/src/main/java/com/gtnewhorizons/angelica/models/Material.java new file mode 100644 index 000000000..6f4fdada5 --- /dev/null +++ b/src/main/java/com/gtnewhorizons/angelica/models/Material.java @@ -0,0 +1,55 @@ +package com.gtnewhorizons.angelica.models; + +import org.antlr.v4.codegen.model.TestSetInline; + +import java.util.BitSet; + +public class Material { + + /** + * The following masks control whether the property is enabled. + */ + + // If true, renders face as fullbright + private static final int EMISSIVE_MASK = 1; + private static final int COLOR_MASK = 1 << 1; + // If true, uses diffuse shading/shadows + private static final int DIFFUSE_MASK = 1 << 2; + private static final int AO_MASK = 1 << 3; + + // By default, quads use diffuse shading and AO + private static final int DEFAULTS = DIFFUSE_MASK | AO_MASK; + + private int flags = DEFAULTS; + + public void reset() { + this.flags = DEFAULTS; + } + + private void setMask(int mask, boolean val) { + if (val) + this.flags |= mask; + else + this.flags &= ~mask; + } + + private boolean getMask(int mask) { + return (this.flags & mask) == mask; + } + + public void setAO(boolean val) { + this.setMask(AO_MASK, val); + } + + public boolean getAO() { + return getMask(AO_MASK); + } + + public void setDiffuse(boolean val) { + this.setMask(DIFFUSE_MASK, val); + } + + public boolean getDiffuse() { + return getMask(DIFFUSE_MASK); + } +} diff --git a/src/main/java/com/gtnewhorizons/angelica/models/MixinModels.java b/src/main/java/com/gtnewhorizons/angelica/models/MixinModels.java new file mode 100644 index 000000000..a3263d409 --- /dev/null +++ b/src/main/java/com/gtnewhorizons/angelica/models/MixinModels.java @@ -0,0 +1,26 @@ +package com.gtnewhorizons.angelica.models; + +import com.gtnewhorizons.angelica.compat.nd.Quad; +import com.gtnewhorizons.angelica.models.json.JsonModel; +import com.gtnewhorizons.angelica.models.json.Loader; +import com.gtnewhorizons.angelica.models.json.Variant; +import it.unimi.dsi.fastutil.objects.ObjectImmutableList; +import net.minecraft.util.ResourceLocation; + +import java.util.List; + +public class MixinModels { + + public static final Variant stoneVariant = new Variant( + new ResourceLocation("blocks/stone"), + 0, + 0, + true + ); + public static JsonModel stoneModel; + + public static void loadModels() { + + stoneModel = Loader.getModel(stoneVariant); + } +} diff --git a/src/main/java/com/gtnewhorizons/angelica/models/NdQuadBuilder.java b/src/main/java/com/gtnewhorizons/angelica/models/NdQuadBuilder.java index 098df8d17..9ad76efc7 100644 --- a/src/main/java/com/gtnewhorizons/angelica/models/NdQuadBuilder.java +++ b/src/main/java/com/gtnewhorizons/angelica/models/NdQuadBuilder.java @@ -3,25 +3,19 @@ package com.gtnewhorizons.angelica.models; import com.gtnewhorizons.angelica.compat.nd.Quad; import java.util.Arrays; -import com.gtnewhorizons.angelica.models.material.RenderMaterial; -import com.gtnewhorizons.angelica.models.material.RenderMaterialImpl; -import com.gtnewhorizons.angelica.models.renderer.IndigoRenderer; -import me.jellysquid.mods.sodium.client.render.pipeline.BlockRenderer; import net.minecraft.client.Minecraft; import net.minecraft.util.IIcon; import net.minecraftforge.common.util.ForgeDirection; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.joml.Vector3f; -import org.lwjgl.opengl.GL11; - -import static com.gtnewhorizons.angelica.models.EncodingFormat.*; public class NdQuadBuilder { // x, y, z, u, v, color, normal, lightmap public static final int INTS_PER_VERTEX = 8; public static final int QUAD_STRIDE = INTS_PER_VERTEX * 4; + private static final int HEADER_STRIDE = 2; public static final int X_INDEX = 0; public static final int Y_INDEX = 1; public static final int Z_INDEX = 2; @@ -96,31 +90,30 @@ public class NdQuadBuilder { */ public static float CULL_FACE_EPSILON = 0.00001f; + private ForgeDirection cullFace = ForgeDirection.UNKNOWN; private ForgeDirection nominalFace = ForgeDirection.UNKNOWN; + // Defaults to UP, but only because it can't be UNKNOWN or null + private ForgeDirection lightFace = ForgeDirection.UP; // It's called a header, but because I'm lazy it's at the end + // The header is an int with flags -------- -------- -------- -GGGNNNN, then an int for the normal private final int[] data = new int[QUAD_STRIDE + HEADER_STRIDE]; + private int geometry = 0; + private int normalFlags = 0; private boolean isGeometryInvalid = true; private int tag = 0; private int colorIndex = -1; final Vector3f faceNormal = new Vector3f(); + private int packedNormal = 0; + public final Material mat = new Material(); /** * Dumps to {@param out} and returns it. */ public Quad build(Quad out) { - /*out.setState( - data, - 0, - new BlockRenderer.Flags(true, false, this.colorIndex != -1, false), - GL11.GL_QUADS, - 0, - 0, - 0 - );*/ // FRAPI does this late, but we need to do it before baking to Nd quads this.computeGeometry(); - out.setRaw(this.data, this.hasShade(), this.cullFace(), this.colorIndex, this.data[QUAD_STRIDE + HEADER_BITS]); + out.setRaw(this.data, this.hasShade(), this.cullFace(), this.colorIndex, this.data[QUAD_STRIDE]); this.clear(); return out; } @@ -128,13 +121,15 @@ public class NdQuadBuilder { public void clear() { Arrays.fill(this.data, 0); - this.isGeometryInvalid = true; + this.cullFace = ForgeDirection.UNKNOWN; this.nominalFace = ForgeDirection.UNKNOWN; - this.normalFlags(0); + this.lightFace = ForgeDirection.UP; + this.geometry = 0; + this.normalFlags = 0; + this.isGeometryInvalid = true; this.tag(0); this.colorIndex(-1); - this.cullFace(null); - this.material(IndigoRenderer.MATERIAL_STANDARD); + this.mat.reset(); } /** @@ -163,29 +158,28 @@ public class NdQuadBuilder { } private void computeGeometry() { - if (isGeometryInvalid) { - isGeometryInvalid = false; + if (this.isGeometryInvalid) { + this.isGeometryInvalid = false; - NormalHelper.computeFaceNormal(faceNormal, this); - this.data[QUAD_STRIDE + HEADER_FACE_NORMAL] = NormalHelper.packNormal(this.faceNormal); + NormalHelper.computeFaceNormal(this.faceNormal, this); + this.packedNormal = NormalHelper.packNormal(this.faceNormal); // depends on face normal - this.data[QUAD_STRIDE +HEADER_BITS] = EncodingFormat.lightFace(this.data[QUAD_STRIDE +HEADER_BITS], GeometryHelper.lightFace(this)); + this.lightFace = GeometryHelper.lightFace(this); // depends on light face - this.data[QUAD_STRIDE +HEADER_BITS] = EncodingFormat.geometryFlags(this.data[QUAD_STRIDE +HEADER_BITS], GeometryHelper.computeShapeFlags(this)); + this.geometry = GeometryHelper.computeShapeFlags(this); } } /** - * If non-null, quad should not be rendered in-world if the + * If not {@link ForgeDirection#UNKNOWN}, quad should not be rendered in-world if the * opposite face of a neighbor block occludes it. * * @see NdQuadBuilder#cullFace(ForgeDirection) */ - @Nullable public final ForgeDirection cullFace() { - return EncodingFormat.cullFace(this.data[QUAD_STRIDE + HEADER_BITS]); + return this.cullFace; } /** @@ -203,14 +197,14 @@ public class NdQuadBuilder { * is computed based on face geometry and must be non-{@link ForgeDirection#UNKNOWN} in vanilla quads. * That computed value is returned by {@link #lightFace()}. */ - public void cullFace(@Nullable ForgeDirection dir) { + public void cullFace(ForgeDirection dir) { - this.data[QUAD_STRIDE + HEADER_BITS] = EncodingFormat.cullFace(this.data[QUAD_STRIDE + HEADER_BITS], dir); + this.cullFace = dir; this.nominalFace(dir); } private boolean hasShade() { - return !this.material().disableDiffuse(); + return this.mat.getDiffuse(); } /** @@ -220,28 +214,9 @@ public class NdQuadBuilder { * {@link ForgeDirection#UNKNOWN} or null. */ @NotNull - ForgeDirection lightFace() { + public ForgeDirection lightFace() { this.computeGeometry(); - return EncodingFormat.lightFace(this.data[QUAD_STRIDE + HEADER_BITS]); - } - - /** - * Retrieves the material serialized with the quad. - */ - public final RenderMaterialImpl material() { - return EncodingFormat.material(this.data[QUAD_STRIDE + HEADER_BITS]); - } - - /** - * Assigns a different material to this quad. Useful for transformation of - * existing meshes because lighting and texture blending are controlled by material. - */ - public final void material(RenderMaterial material) { - if (material == null) { - material = IndigoRenderer.MATERIAL_STANDARD; - } - - this.data[QUAD_STRIDE + HEADER_BITS] = EncodingFormat.material(this.data[QUAD_STRIDE + HEADER_BITS], (RenderMaterialImpl) material); + return this.lightFace; } /** @@ -271,8 +246,9 @@ public class NdQuadBuilder { /** * Sets the normal flags. */ - private void normalFlags(int flags) { - this.data[QUAD_STRIDE + HEADER_BITS] = EncodingFormat.normalFlags(this.data[QUAD_STRIDE + HEADER_BITS], flags); + private void normalFlags(int normalFlags) { + + this.normalFlags = normalFlags; } /** @@ -341,7 +317,7 @@ public class NdQuadBuilder { cullFace(nominalFace); depth = 0; // avoid any inconsistency for face quads } else { - cullFace(null); + cullFace(ForgeDirection.UNKNOWN); } nominalFace(nominalFace); @@ -384,6 +360,10 @@ public class NdQuadBuilder { } } + public int tag() { + return this.tag; + } + /** * Encodes an integer tag with this quad that can later be retrieved via * {@link NdQuadBuilder#tag()}. Useful for models that want to perform conditional diff --git a/src/main/java/com/gtnewhorizons/angelica/models/fapi/BooleanFunction.java b/src/main/java/com/gtnewhorizons/angelica/models/fapi/BooleanFunction.java deleted file mode 100644 index a00999c5d..000000000 --- a/src/main/java/com/gtnewhorizons/angelica/models/fapi/BooleanFunction.java +++ /dev/null @@ -1,17 +0,0 @@ -package com.gtnewhorizons.angelica.models.fapi; - -/** - * Represents a function that accepts a boolean-valued argument and produces a result. - * - *

This is the {@code boolean}-consuming primitive specialization for {@link java.util.function.Function}. - */ -@FunctionalInterface -public interface BooleanFunction { - /** - * Applies this function to the given argument. - * - * @param value the function argument - * @return the function result - */ - R apply(boolean value); -} diff --git a/src/main/java/com/gtnewhorizons/angelica/models/fapi/TriState.java b/src/main/java/com/gtnewhorizons/angelica/models/fapi/TriState.java deleted file mode 100644 index b215bcd23..000000000 --- a/src/main/java/com/gtnewhorizons/angelica/models/fapi/TriState.java +++ /dev/null @@ -1,122 +0,0 @@ -package com.gtnewhorizons.angelica.models.fapi; - -import javax.annotation.Nullable; -import java.util.Objects; -import java.util.Optional; -import java.util.function.BooleanSupplier; -import java.util.function.Supplier; - -/** - * Represents a boolean value which can be true, false or refer to a default value. - */ -public enum TriState { - /** - * Represents the boolean value of {@code false}. - */ - FALSE, - /** - * Represents a value that refers to a "default" value, often as a fallback. - */ - DEFAULT, - /** - * Represents the boolean value of {@code true}. - */ - TRUE; - - /** - * Gets the corresponding tri-state from a boolean value. - * - * @param bool the boolean value - * @return {@link TriState#TRUE} or {@link TriState#FALSE} depending on the value of the boolean. - */ - public static TriState of(boolean bool) { - return bool ? TRUE : FALSE; - } - - /** - * Gets a tri-state from a nullable boxed boolean. - * - * @param bool the boolean value - * @return {@link TriState#DEFAULT} if {@code null}. - * Otherwise {@link TriState#TRUE} or {@link TriState#FALSE} depending on the value of the boolean. - */ - public static TriState of(@Nullable Boolean bool) { - return bool == null ? DEFAULT : of(bool.booleanValue()); - } - - /** - * Gets the value of the tri-state. - * - * @return true if the tri-state is {@link TriState#TRUE}, - * otherwise false. - */ - public boolean get() { - return this == TRUE; - } - - /** - * Gets the value of the tri-state as a boxed, nullable boolean. - * - * @return {@code null} if {@link TriState#DEFAULT}. - * Otherwise {@code true} if {@link TriState#TRUE} or {@code false} if {@link TriState#FALSE}. - */ - @Nullable - public Boolean getBoxed() { - return this == DEFAULT ? null : this.get(); - } - - /** - * Gets the value of this tri-state. - * If the value is {@link TriState#DEFAULT} then use the supplied value. - * - * @param value the value to fall back to - * @return the value of the tri-state or the supplied value if {@link TriState#DEFAULT}. - */ - public boolean orElse(boolean value) { - return this == DEFAULT ? value : this.get(); - } - - /** - * Gets the value of this tri-state. - * If the value is {@link TriState#DEFAULT} then use the supplied value. - * - * @param supplier the supplier used to get the value to fall back to - * @return the value of the tri-state or the value of the supplier if the tri-state is {@link TriState#DEFAULT}. - */ - public boolean orElseGet(BooleanSupplier supplier) { - return this == DEFAULT ? supplier.getAsBoolean() : this.get(); - } - - /** - * Maps the boolean value of this tri-state if it is {@link TriState#TRUE} or {@link TriState#FALSE}. - * - * @param mapper the mapper to use - * @param the type of object being supplier by the mapper - * @return an optional containing the mapped value; {@link Optional#empty()} if the tri-state is {@link TriState#DEFAULT} or the value provided by the mapper is {@code null}. - */ - public Optional map(BooleanFunction mapper) { - Objects.requireNonNull(mapper, "Mapper function cannot be null"); - - if (this == DEFAULT) { - return Optional.empty(); - } - - return Optional.ofNullable(mapper.apply(this.get())); - } - - /** - * Gets the value of this tri-state, or throws an exception if this tri-state's value is {@link TriState#DEFAULT}. - * - * @param exceptionSupplier the supplying function that produces an exception to be thrown - * @param Type of the exception to be thrown - * @return the value - * @throws X if the value is {@link TriState#DEFAULT} - */ - public boolean orElseThrow(Supplier exceptionSupplier) throws X { - if (this != DEFAULT) { - return this.get(); - } - - throw exceptionSupplier.get(); - } -} diff --git a/src/main/java/com/gtnewhorizons/angelica/models/json/JsonModel.java b/src/main/java/com/gtnewhorizons/angelica/models/json/JsonModel.java index a0ce566b5..b75670749 100644 --- a/src/main/java/com/gtnewhorizons/angelica/models/json/JsonModel.java +++ b/src/main/java/com/gtnewhorizons/angelica/models/json/JsonModel.java @@ -11,9 +11,6 @@ import com.gtnewhorizons.angelica.compat.mojang.Axis; import com.gtnewhorizons.angelica.compat.mojang.BlockPos; import com.gtnewhorizons.angelica.compat.nd.Quad; import com.gtnewhorizons.angelica.models.NdQuadBuilder; -import com.gtnewhorizons.angelica.models.fapi.TriState; -import com.gtnewhorizons.angelica.models.material.RenderMaterial; -import com.gtnewhorizons.angelica.models.renderer.IndigoRenderer; import com.gtnewhorizons.angelica.utils.DirUtil; import com.gtnewhorizons.angelica.utils.ObjectPooler; import it.unimi.dsi.fastutil.Function; @@ -52,8 +49,9 @@ public class JsonModel implements QuadProvider { private final Map display; private final Map textures; private List elements; - // TODO: Make a sided list - private List bakedQuadStore = new ObjectArrayList<>(); + private List allQuadStore = new ObjectArrayList<>(); + private final Map> sidedQuadStore = new Object2ObjectOpenHashMap<>(); + private static final List EMPTY = ObjectImmutableList.of(); JsonModel(@Nullable ResourceLocation parentId, boolean useAO, Map display, Map textures, List elements) { this.parentId = parentId; @@ -81,14 +79,13 @@ public class JsonModel implements QuadProvider { final Matrix4f vRot = v.getAffineMatrix(); final NdQuadBuilder builder = new NdQuadBuilder(); - final RenderMaterial mat = - IndigoRenderer.INSTANCE.materialFinder().ambientOcclusion(TriState.of(this.useAO)).find(); // Append faces from each element for (ModelElement e : this.elements) { - final Matrix4f rot = (e.getRotation() == null) ? ModelElement.Rotation.NOOP.getAffineMatrix() : e.getRotation().getAffineMatrix(); - //rot.mulLocal(vRot); + final Matrix4f rot = (e.getRotation() == null) + ? ModelElement.Rotation.NOOP.getAffineMatrix() + : e.getRotation().getAffineMatrix(); final Vector3f from = e.getFrom(); final Vector3f to = e.getTo(); @@ -98,7 +95,8 @@ public class JsonModel implements QuadProvider { // Assign vertexes for (int i = 0; i < 4; ++i) { - final Vector3f vert = rot.transformPosition(NdQuadBuilder.mapSideToVertex(from, to, i, f.getName())); + final Vector3f vert = + rot.transformPosition(NdQuadBuilder.mapSideToVertex(from, to, i, f.getName())); vRot.transformPosition(vert); builder.pos(i, vert.x, vert.y, vert.z); } @@ -137,14 +135,17 @@ public class JsonModel implements QuadProvider { builder.color(tint, tint, tint, tint); // Set AO - builder.material(mat); + builder.mat.setAO(this.useAO); // Bake and add it - this.bakedQuadStore.add(builder.build(new Quad())); + final Quad q = builder.build(new Quad()); + this.allQuadStore.add(q); + this.sidedQuadStore.computeIfAbsent(f.getCullFace(), + o -> new ObjectArrayList<>()).add(q); } } - this.bakedQuadStore = new ObjectImmutableList<>(this.bakedQuadStore); + this.allQuadStore = new ObjectImmutableList<>(this.allQuadStore); } public List getParents() { @@ -154,12 +155,13 @@ public class JsonModel implements QuadProvider { @Override public List getQuads(IBlockAccess world, BlockPos pos, Block block, int meta, ForgeDirection dir, Random random, ObjectPooler quadPool) { - final List ret = new ObjectArrayList<>(this.bakedQuadStore.size()); + final List src = this.sidedQuadStore.getOrDefault(dir, EMPTY); + final List ret = new ObjectArrayList<>(src.size()); //noinspection ForLoopReplaceableByForEach - for (int i = 0; i < bakedQuadStore.size(); ++i) { + for (int i = 0; i < src.size(); ++i) { final Quad q = quadPool.getInstance(); - q.copyFrom(this.bakedQuadStore.get(i)); + q.copyFrom(src.get(i)); ret.add(q); } diff --git a/src/main/java/com/gtnewhorizons/angelica/models/material/BlendMode.java b/src/main/java/com/gtnewhorizons/angelica/models/material/BlendMode.java deleted file mode 100644 index 6194d5210..000000000 --- a/src/main/java/com/gtnewhorizons/angelica/models/material/BlendMode.java +++ /dev/null @@ -1,56 +0,0 @@ -package com.gtnewhorizons.angelica.models.material; - -import com.gtnewhorizons.angelica.compat.toremove.RenderLayer; - -/** - * Defines how sprite pixels will be blended with the scene. - */ -public enum BlendMode { - /** - * Emulate blending behavior of {@code BlockRenderLayer} associated with the block. - */ - DEFAULT(null), - - /** - * Fully opaque with depth test, no blending. Used for most normal blocks. - */ - SOLID(RenderLayer.solid()), - - /** - * Pixels with alpha > 0.5 are rendered as if {@code SOLID}. Other pixels are not rendered. - * Texture mip-map enabled. Used for leaves on modern, unused in 1.7.10. - */ - //CUTOUT_MIPPED(RenderLayer.cutout()), - - /** - * Pixels with alpha > 0.5 are rendered as if {@code SOLID}. Other pixels are not rendered. - * Texture mip-map disabled. Used for iron bars, glass and other cutout sprites with hard edges. - */ - CUTOUT(RenderLayer.cutout()), - - /** - * Pixels are blended with the background according to alpha color values. Some performance cost, - * use in moderation. Texture mip-map enabled. Used for stained glass. - */ - TRANSLUCENT(RenderLayer.translucent()); - - public final RenderLayer blockRenderLayer; - - BlendMode(RenderLayer blockRenderLayer) { - this.blockRenderLayer = blockRenderLayer; - } - - public static BlendMode fromRenderLayer(RenderLayer renderLayer) { - if (renderLayer == RenderLayer.solid()) { - return SOLID; - /*} else if (renderLayer == RenderLayer.getCutoutMipped()) { - return CUTOUT_MIPPED;*/ - } else if (renderLayer == RenderLayer.cutout()) { - return CUTOUT; - } else if (renderLayer == RenderLayer.translucent()) { - return TRANSLUCENT; - } else { - return DEFAULT; - } - } -} diff --git a/src/main/java/com/gtnewhorizons/angelica/models/material/MaterialFinder.java b/src/main/java/com/gtnewhorizons/angelica/models/material/MaterialFinder.java deleted file mode 100644 index 036117b74..000000000 --- a/src/main/java/com/gtnewhorizons/angelica/models/material/MaterialFinder.java +++ /dev/null @@ -1,156 +0,0 @@ -package com.gtnewhorizons.angelica.models.material; - -import com.gtnewhorizons.angelica.compat.toremove.RenderLayer; -import com.gtnewhorizons.angelica.models.renderer.IndigoRenderer; -import com.gtnewhorizons.angelica.models.NdQuadBuilder; -import com.gtnewhorizons.angelica.models.fapi.TriState; -import com.gtnewhorizons.angelica.models.json.JsonModel; -import net.minecraft.block.Block; -import net.minecraft.item.ItemStack; - -/** - * Finds standard {@link RenderMaterial} instances used to communicate - * quad rendering characteristics to a {@link RenderContext}. - * - *

Must be obtained via {@link IndigoRenderer#materialFinder()}. - */ -public interface MaterialFinder extends MaterialView { - /** - * Defines how sprite pixels will be blended with the scene. - * - *

See {@link BlendMode} for more information. - */ - MaterialFinder blendMode(BlendMode blendMode); - - /** - * Vertex color(s) will be modified for quad color index unless disabled. - */ - MaterialFinder disableColorIndex(boolean disable); - - /** - * When true, sprite texture and color will be rendered at full brightness. - * Lightmap values provided via {@link NdQuadBuilder#lightmap(int)} will be ignored. - * False by default - * - *

This is the preferred method for emissive lighting effects. Some renderers - * with advanced lighting models may not use block lightmaps and this method will - * allow per-sprite emissive lighting in future extensions that support overlay sprites. - * - *

Note that color will still be modified by diffuse shading and ambient occlusion, - * unless disabled via {@link #disableDiffuse(boolean)} and {@link #ambientOcclusion(TriState)}. - */ - MaterialFinder emissive(boolean isEmissive); - - /** - * Vertex color(s) will be modified for diffuse shading unless disabled. - * - *

This property is guaranteed to be respected in block contexts. Some renderers may also respect it in item - * contexts, but this is not guaranteed. - */ - MaterialFinder disableDiffuse(boolean disable); - - /** - * Controls whether vertex color(s) will be modified for ambient occlusion. - * - *

By default, ambient occlusion will be used if {@link JsonModel#isUseAO() the model uses ambient occlusion} - * and the block has {@link Block#getLightValue() a luminance} of 0. - * Set to {@link TriState#TRUE} or {@link TriState#FALSE} to override this behavior. - * - *

This property is respected only in block contexts. It will not have an effect in other contexts. - */ - MaterialFinder ambientOcclusion(TriState mode); - - /** - * Controls whether glint should be applied. - * - *

By default, glint will be applied in item contexts if {@link ItemStack#isItemEnchanted()} the item stack has glint}. - * Set to {@link TriState#TRUE} or {@link TriState#FALSE} to override this behavior. - * - *

This property is guaranteed to be respected in item contexts. Some renderers may also respect it in block - * contexts, but this is not guaranteed. - */ - MaterialFinder glint(TriState mode); - - /** - * Copies all properties from the given {@link MaterialView} to this material finder. - */ - MaterialFinder copyFrom(MaterialView material); - - /** - * Resets this instance to default values. Values will match those - * in effect when an instance is newly obtained via {@link IndigoRenderer#materialFinder()}. - */ - MaterialFinder clear(); - - /** - * Returns the standard material encoding all - * of the current settings in this finder. The settings in - * this finder are not changed. - * - *

Resulting instances can and should be re-used to prevent - * needless memory allocation. {@link IndigoRenderer} implementations - * may or may not cache standard material instances. - */ - RenderMaterial find(); - - /** - * @deprecated Use {@link #blendMode(BlendMode)} instead. - */ - @Deprecated - default MaterialFinder blendMode(int spriteIndex, RenderLayer renderLayer) { - return blendMode(BlendMode.fromRenderLayer(renderLayer)); - } - - /** - * @deprecated Use {@link #blendMode(BlendMode)} instead. - */ - @Deprecated - default MaterialFinder blendMode(int spriteIndex, BlendMode blendMode) { - // Null check is kept for legacy reasons, but the new blendMode method will NPE if passed null! - if (blendMode == null) { - blendMode = BlendMode.DEFAULT; - } - - return blendMode(blendMode); - } - - /** - * @deprecated Use {@link #disableColorIndex(boolean)} instead. - */ - @Deprecated - default MaterialFinder disableColorIndex(int spriteIndex, boolean disable) { - return disableColorIndex(disable); - } - - /** - * @deprecated Use {@link #emissive(boolean)} instead. - */ - @Deprecated - default MaterialFinder emissive(int spriteIndex, boolean isEmissive) { - return emissive(isEmissive); - } - - /** - * @deprecated Use {@link #disableDiffuse(boolean)} instead. - */ - @Deprecated - default MaterialFinder disableDiffuse(int spriteIndex, boolean disable) { - return disableDiffuse(disable); - } - - /** - * @deprecated Use {@link #ambientOcclusion(TriState)} instead. - */ - @Deprecated - default MaterialFinder disableAo(int spriteIndex, boolean disable) { - return ambientOcclusion(disable ? TriState.FALSE : TriState.DEFAULT); - } - - /** - * Do not use. Does nothing. - */ - @Deprecated - default MaterialFinder spriteDepth(int depth) { - return this; - } -} diff --git a/src/main/java/com/gtnewhorizons/angelica/models/material/MaterialFinderImpl.java b/src/main/java/com/gtnewhorizons/angelica/models/material/MaterialFinderImpl.java deleted file mode 100644 index 6b005de96..000000000 --- a/src/main/java/com/gtnewhorizons/angelica/models/material/MaterialFinderImpl.java +++ /dev/null @@ -1,83 +0,0 @@ -package com.gtnewhorizons.angelica.models.material; - -import com.gtnewhorizons.angelica.models.fapi.TriState; - -import java.util.Objects; - -public class MaterialFinderImpl extends MaterialViewImpl implements MaterialFinder { - private static int defaultBits = 0; - - static { - MaterialFinderImpl finder = new MaterialFinderImpl(); - finder.ambientOcclusion(TriState.DEFAULT); - finder.glint(TriState.DEFAULT); - defaultBits = finder.bits; - - if (!areBitsValid(defaultBits)) { - throw new AssertionError("Default MaterialFinder bits are not valid!"); - } - } - - public MaterialFinderImpl() { - super(defaultBits); - } - - @Override - public MaterialFinder blendMode(BlendMode blendMode) { - Objects.requireNonNull(blendMode, "BlendMode may not be null"); - - bits = (bits & ~BLEND_MODE_MASK) | (blendMode.ordinal() << BLEND_MODE_BIT_OFFSET); - return this; - } - - @Override - public MaterialFinder disableColorIndex(boolean disable) { - bits = disable ? (bits | COLOR_DISABLE_FLAG) : (bits & ~COLOR_DISABLE_FLAG); - return this; - } - - @Override - public MaterialFinder emissive(boolean isEmissive) { - bits = isEmissive ? (bits | EMISSIVE_FLAG) : (bits & ~EMISSIVE_FLAG); - return this; - } - - @Override - public MaterialFinder disableDiffuse(boolean disable) { - bits = disable ? (bits | DIFFUSE_FLAG) : (bits & ~DIFFUSE_FLAG); - return this; - } - - @Override - public MaterialFinder ambientOcclusion(TriState mode) { - Objects.requireNonNull(mode, "ambient occlusion TriState may not be null"); - - bits = (bits & ~AO_MASK) | (mode.ordinal() << AO_BIT_OFFSET); - return this; - } - - @Override - public MaterialFinder glint(TriState mode) { - Objects.requireNonNull(mode, "glint TriState may not be null"); - - bits = (bits & ~GLINT_MASK) | (mode.ordinal() << GLINT_BIT_OFFSET); - return this; - } - - @Override - public MaterialFinder copyFrom(MaterialView material) { - bits = ((MaterialViewImpl) material).bits; - return this; - } - - @Override - public MaterialFinder clear() { - bits = defaultBits; - return this; - } - - @Override - public RenderMaterial find() { - return RenderMaterialImpl.byIndex(bits); - } -} diff --git a/src/main/java/com/gtnewhorizons/angelica/models/material/MaterialView.java b/src/main/java/com/gtnewhorizons/angelica/models/material/MaterialView.java deleted file mode 100644 index f0738f763..000000000 --- a/src/main/java/com/gtnewhorizons/angelica/models/material/MaterialView.java +++ /dev/null @@ -1,41 +0,0 @@ -package com.gtnewhorizons.angelica.models.material; - -import com.gtnewhorizons.angelica.models.fapi.TriState; - -/** - * Getter methods for {@link RenderMaterial} (immutable) and {@link MaterialFinder} (mutable). - * - *

Values returned by the getters may not necessarily be identical to those requested in the {@link MaterialFinder}. - * The renderer may choose different values that are sufficiently representative for its own processing. - */ -public interface MaterialView { - /** - * @see MaterialFinder#blendMode(BlendMode) - */ - BlendMode blendMode(); - - /** - * @see MaterialFinder#disableColorIndex(boolean) - */ - boolean disableColorIndex(); - - /** - * @see MaterialFinder#emissive(boolean) - */ - boolean emissive(); - - /** - * @see MaterialFinder#disableDiffuse(boolean) - */ - boolean disableDiffuse(); - - /** - * @see MaterialFinder#ambientOcclusion(TriState) - */ - TriState ambientOcclusion(); - - /** - * @see MaterialFinder#glint(TriState) - */ - TriState glint(); -} diff --git a/src/main/java/com/gtnewhorizons/angelica/models/material/MaterialViewImpl.java b/src/main/java/com/gtnewhorizons/angelica/models/material/MaterialViewImpl.java deleted file mode 100644 index 781311fd9..000000000 --- a/src/main/java/com/gtnewhorizons/angelica/models/material/MaterialViewImpl.java +++ /dev/null @@ -1,89 +0,0 @@ -package com.gtnewhorizons.angelica.models.material; - -import com.gtnewhorizons.angelica.models.fapi.TriState; -import net.minecraft.util.MathHelper; - -/** - * Default implementation of the standard render materials. - * The underlying representation is simply an int with bit-wise - * packing of the various material properties. This offers - * easy/fast interning via int/object hashmap. - */ -public class MaterialViewImpl implements MaterialView { - private static final BlendMode[] BLEND_MODES = BlendMode.values(); - private static final int BLEND_MODE_COUNT = BLEND_MODES.length; - private static final TriState[] TRI_STATES = TriState.values(); - private static final int TRI_STATE_COUNT = TRI_STATES.length; - - protected static final int BLEND_MODE_BIT_LENGTH = MathHelper.calculateLogBaseTwoDeBruijn(BLEND_MODE_COUNT); - protected static final int COLOR_DISABLE_BIT_LENGTH = 1; - protected static final int EMISSIVE_BIT_LENGTH = 1; - protected static final int DIFFUSE_BIT_LENGTH = 1; - protected static final int AO_BIT_LENGTH = MathHelper.calculateLogBaseTwoDeBruijn(TRI_STATE_COUNT); - protected static final int GLINT_BIT_LENGTH = MathHelper.calculateLogBaseTwoDeBruijn(TRI_STATE_COUNT); - - protected static final int BLEND_MODE_BIT_OFFSET = 0; - protected static final int COLOR_DISABLE_BIT_OFFSET = BLEND_MODE_BIT_OFFSET + BLEND_MODE_BIT_LENGTH; - protected static final int EMISSIVE_BIT_OFFSET = COLOR_DISABLE_BIT_OFFSET + COLOR_DISABLE_BIT_LENGTH; - protected static final int DIFFUSE_BIT_OFFSET = EMISSIVE_BIT_OFFSET + EMISSIVE_BIT_LENGTH; - protected static final int AO_BIT_OFFSET = DIFFUSE_BIT_OFFSET + DIFFUSE_BIT_LENGTH; - protected static final int GLINT_BIT_OFFSET = AO_BIT_OFFSET + AO_BIT_LENGTH; - protected static final int TOTAL_BIT_LENGTH = GLINT_BIT_OFFSET + GLINT_BIT_LENGTH; - - protected static final int BLEND_MODE_MASK = bitMask(BLEND_MODE_BIT_LENGTH, BLEND_MODE_BIT_OFFSET); - protected static final int COLOR_DISABLE_FLAG = bitMask(COLOR_DISABLE_BIT_LENGTH, COLOR_DISABLE_BIT_OFFSET); - protected static final int EMISSIVE_FLAG = bitMask(EMISSIVE_BIT_LENGTH, EMISSIVE_BIT_OFFSET); - protected static final int DIFFUSE_FLAG = bitMask(DIFFUSE_BIT_LENGTH, DIFFUSE_BIT_OFFSET); - protected static final int AO_MASK = bitMask(AO_BIT_LENGTH, AO_BIT_OFFSET); - protected static final int GLINT_MASK = bitMask(GLINT_BIT_LENGTH, GLINT_BIT_OFFSET); - - protected static int bitMask(int bitLength, int bitOffset) { - return ((1 << bitLength) - 1) << bitOffset; - } - - protected static boolean areBitsValid(int bits) { - int blendMode = (bits & BLEND_MODE_MASK) >>> BLEND_MODE_BIT_OFFSET; - int ao = (bits & AO_MASK) >>> AO_BIT_OFFSET; - int glint = (bits & GLINT_MASK) >>> GLINT_BIT_OFFSET; - - return blendMode < BLEND_MODE_COUNT - && ao < TRI_STATE_COUNT - && glint < TRI_STATE_COUNT; - } - - protected int bits; - - protected MaterialViewImpl(int bits) { - this.bits = bits; - } - - @Override - public BlendMode blendMode() { - return BLEND_MODES[(bits & BLEND_MODE_MASK) >>> BLEND_MODE_BIT_OFFSET]; - } - - @Override - public boolean disableColorIndex() { - return (bits & COLOR_DISABLE_FLAG) != 0; - } - - @Override - public boolean emissive() { - return (bits & EMISSIVE_FLAG) != 0; - } - - @Override - public boolean disableDiffuse() { - return (bits & DIFFUSE_FLAG) != 0; - } - - @Override - public TriState ambientOcclusion() { - return TRI_STATES[(bits & AO_MASK) >>> AO_BIT_OFFSET]; - } - - @Override - public TriState glint() { - return TRI_STATES[(bits & GLINT_MASK) >>> GLINT_BIT_OFFSET]; - } -} diff --git a/src/main/java/com/gtnewhorizons/angelica/models/material/RenderMaterial.java b/src/main/java/com/gtnewhorizons/angelica/models/material/RenderMaterial.java deleted file mode 100644 index a0c103814..000000000 --- a/src/main/java/com/gtnewhorizons/angelica/models/material/RenderMaterial.java +++ /dev/null @@ -1,57 +0,0 @@ -package com.gtnewhorizons.angelica.models.material; - -import net.minecraft.util.ResourceLocation; -import net.minecraft.block.Block; - -/** - * All model quads have an associated render material governing - * how the quad will be rendered. - * - *

A material instance is always immutable and thread-safe. References to a material - * remain valid until the end of the current game session. - * - *

Materials can be registered and shared between mods using {@link Renderer#registerMaterial(net.minecraft.util.Identifier, RenderMaterial)}. - * The registering mod is responsible for creating each registered material at startup. - * - *

Materials are not required to know their registration identity, and two materials - * with the same attributes may or may not satisfy equality and identity tests. Model - * implementations should never attempt to analyze materials or implement control logic based on them. - * They are only tokens for communicating quad attributes to the ModelRenderer. - * - *

There are three classes of materials... - * - *

STANDARD MATERIALS - * - *

Standard materials have "normal" rendering with control over lighting, - * color, and texture blending. In the default renderer, "normal" rendering - * emulates unmodified Minecraft. Other renderers may offer a different aesthetic. - * - *

The number of standard materials is finite, but not necessarily small. - * To find a standard material, use {@link Renderer#materialFinder()}. - * - *

All renderer implementations should support standard materials. - * - *

SPECIAL MATERIALS - * - *

Special materials are implemented directly by the Renderer implementation, typically - * with the aim of providing advanced/extended features. Such materials may offer additional - * vertex attributes via extensions to {@link MeshBuilder} and {@link MutableQuadView}. - * - *

Special materials can be obtained using {@link Renderer#materialById(Identifier)} - * with a known identifier. Renderers may provide other means of access. Popular - * special materials could be implemented by multiple renderers, however there is - * no requirement that special materials be cross-compatible. - */ -public interface RenderMaterial extends MaterialView { - /** - * This will be identical to the material that would be obtained by calling {@link MaterialFinder#find()} - * on a new, unaltered, {@link MaterialFinder} instance. It is defined here for clarity and convenience. - * - *

Quads using this material use {@link Block#getRenderBlockPass()} of - * the associated block to determine texture blending, honor block color index, are non-emissive, and apply both - * diffuse and ambient occlusion shading to vertex colors. - * - *

All standard, non-fluid baked models are rendered using this material. - */ - ResourceLocation MATERIAL_STANDARD = new ResourceLocation("fabric", "standard"); -} diff --git a/src/main/java/com/gtnewhorizons/angelica/models/material/RenderMaterialImpl.java b/src/main/java/com/gtnewhorizons/angelica/models/material/RenderMaterialImpl.java deleted file mode 100644 index 045361aa7..000000000 --- a/src/main/java/com/gtnewhorizons/angelica/models/material/RenderMaterialImpl.java +++ /dev/null @@ -1,34 +0,0 @@ -package com.gtnewhorizons.angelica.models.material; - -public class RenderMaterialImpl extends MaterialViewImpl implements RenderMaterial { - public static final int VALUE_COUNT = 1 << TOTAL_BIT_LENGTH; - private static final RenderMaterialImpl[] BY_INDEX = new RenderMaterialImpl[VALUE_COUNT]; - - static { - for (int i = 0; i < VALUE_COUNT; i++) { - if (areBitsValid(i)) { - BY_INDEX[i] = new RenderMaterialImpl(i); - } - } - } - - private RenderMaterialImpl(int bits) { - super(bits); - } - - public int index() { - return bits; - } - - public static RenderMaterialImpl byIndex(int index) { - return BY_INDEX[index]; - } - - public static RenderMaterialImpl setDisableDiffuse(RenderMaterialImpl material, boolean disable) { - if (material.disableDiffuse() != disable) { - return byIndex(disable ? (material.bits | DIFFUSE_FLAG) : (material.bits & ~DIFFUSE_FLAG)); - } - - return material; - } -} diff --git a/src/main/java/com/gtnewhorizons/angelica/models/renderer/IndigoRenderer.java b/src/main/java/com/gtnewhorizons/angelica/models/renderer/IndigoRenderer.java deleted file mode 100644 index 2702ad6e6..000000000 --- a/src/main/java/com/gtnewhorizons/angelica/models/renderer/IndigoRenderer.java +++ /dev/null @@ -1,61 +0,0 @@ -package com.gtnewhorizons.angelica.models.renderer; - -import com.gtnewhorizons.angelica.models.material.MaterialFinder; -import com.gtnewhorizons.angelica.models.material.MaterialFinderImpl; -import com.gtnewhorizons.angelica.models.material.RenderMaterial; -import net.minecraft.util.ResourceLocation; - -import java.util.HashMap; - -/** - * The Fabric default renderer implementation. Supports all - * features defined in the API except shaders and offers no special materials. - */ -public class IndigoRenderer { - public static final IndigoRenderer INSTANCE = new IndigoRenderer(); - - public static final RenderMaterial MATERIAL_STANDARD = INSTANCE.materialFinder().find(); - - static { - INSTANCE.registerMaterial(RenderMaterial.MATERIAL_STANDARD, MATERIAL_STANDARD); - } - - private final HashMap materialMap = new HashMap<>(); - - private IndigoRenderer() { } - - /** - * Obtain a new {@link MaterialFinder} instance used to retrieve - * standard {@link RenderMaterial} instances. - * - *

Renderer does not retain a reference to returned instances and they should be re-used for - * multiple materials when possible to avoid memory allocation overhead. - */ - public MaterialFinder materialFinder() { - return new MaterialFinderImpl(); - } - - /** - * Return a material previously registered via {@link #registerMaterial(ResourceLocation, RenderMaterial)}. - * Will return null if no material was found matching the given identifier. - */ - public RenderMaterial materialById(ResourceLocation id) { - return materialMap.get(id); - } - - /** - * Register a material for re-use by other mods or models within a mod. - * The registry does not persist registrations - mods must create and register - * all materials at game initialization. - * - *

Returns false if a material with the given identifier is already present, - * leaving the existing material intact. - */ - public boolean registerMaterial(ResourceLocation id, RenderMaterial material) { - if (materialMap.containsKey(id)) return false; - - // cast to prevent acceptance of impostor implementations - materialMap.put(id, material); - return true; - } -} diff --git a/src/main/java/com/gtnewhorizons/angelica/proxy/ClientProxy.java b/src/main/java/com/gtnewhorizons/angelica/proxy/ClientProxy.java index b31cf713c..0e6c6a2fe 100644 --- a/src/main/java/com/gtnewhorizons/angelica/proxy/ClientProxy.java +++ b/src/main/java/com/gtnewhorizons/angelica/proxy/ClientProxy.java @@ -7,6 +7,7 @@ import com.gtnewhorizons.angelica.config.AngelicaConfig; import com.gtnewhorizons.angelica.glsm.GLStateManager; import com.gtnewhorizons.angelica.glsm.debug.OpenGLDebugging; import com.gtnewhorizons.angelica.hudcaching.HUDCaching; +import com.gtnewhorizons.angelica.models.MixinModels; import com.gtnewhorizons.angelica.models.json.Loader; import com.gtnewhorizons.angelica.render.CloudRenderer; import com.gtnewhorizons.angelica.rendering.AngelicaBlockSafetyRegistry; @@ -63,6 +64,7 @@ public class ClientProxy extends CommonProxy { MinecraftForge.EVENT_BUS.register(this); Loader.registerModels(BlockTest::loadModel, BlockTest.modelId); + Loader.registerModels(MixinModels::loadModels, MixinModels.stoneVariant); } diff --git a/src/main/resources/assets/minecraft/models/blocks/stone.json b/src/main/resources/assets/minecraft/models/blocks/stone.json new file mode 100644 index 000000000..37aecd917 --- /dev/null +++ b/src/main/resources/assets/minecraft/models/blocks/stone.json @@ -0,0 +1,6 @@ +{ + "parent": "blocks/cube_all", + "textures": { + "all": "stone" + } +}