mirror of
https://github.com/GTNewHorizons/Angelica.git
synced 2026-11-25 22:54:28 +00:00
Refactor Quad, BlockPos, and QuadProvider API
Also optimize static models
This commit is contained in:
1 parent
da8f700068
commit
346a305f1d
49 files changed
+701
-525
No files matched your search
@@ -0,0 +1,49 @@
|
||||
package com.gtnewhorizons.angelica.api;
|
||||
|
||||
import com.gtnewhorizons.angelica.compat.mojang.BlockPosImpl;
|
||||
import net.minecraft.util.MathHelper;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
import java.math.RoundingMode;
|
||||
|
||||
import static com.google.common.math.IntMath.log2;
|
||||
|
||||
public interface BlockPos {
|
||||
|
||||
int SIZE_BITS_X = 1 + log2(MathHelper.roundUpToPowerOfTwo(30000000), RoundingMode.UNNECESSARY);
|
||||
int SIZE_BITS_Z = SIZE_BITS_X;
|
||||
int SIZE_BITS_Y = 64 - SIZE_BITS_X - SIZE_BITS_Z;
|
||||
long BITS_X = (1L << SIZE_BITS_X) - 1L;
|
||||
long BITS_Y = (1L << SIZE_BITS_Y) - 1L;
|
||||
long BITS_Z = (1L << SIZE_BITS_Z) - 1L;
|
||||
int BIT_SHIFT_Z = SIZE_BITS_Y;
|
||||
int BIT_SHIFT_X = SIZE_BITS_Y + SIZE_BITS_Z;
|
||||
|
||||
int getX();
|
||||
int getY();
|
||||
int getZ();
|
||||
BlockPosImpl offset(ForgeDirection d);
|
||||
BlockPosImpl down();
|
||||
BlockPosImpl up();
|
||||
long asLong();
|
||||
|
||||
static long asLong(int x, int y, int z) {
|
||||
long l = 0L;
|
||||
l |= ((long) x & BITS_X) << BIT_SHIFT_X;
|
||||
l |= ((long) y & BITS_Y) << 0;
|
||||
l |= ((long) z & BITS_Z) << BIT_SHIFT_Z;
|
||||
return l;
|
||||
}
|
||||
|
||||
public static int unpackLongX(long packedPos) {
|
||||
return (int)(packedPos << 64 - BIT_SHIFT_X - SIZE_BITS_X >> 64 - SIZE_BITS_X);
|
||||
}
|
||||
|
||||
public static int unpackLongY(long packedPos) {
|
||||
return (int)(packedPos << 64 - SIZE_BITS_Y >> 64 - SIZE_BITS_Y);
|
||||
}
|
||||
|
||||
public static int unpackLongZ(long packedPos) {
|
||||
return (int)(packedPos << 64 - BIT_SHIFT_Z - SIZE_BITS_Z >> 64 - SIZE_BITS_Z);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
package com.gtnewhorizons.angelica.api;
|
||||
|
||||
public interface MutableBlockPos extends BlockPos {
|
||||
|
||||
MutableBlockPos set(int x, int y, int z);
|
||||
|
||||
MutableBlockPos set(long packedPos);
|
||||
}
|
||||
@@ -1,14 +1,12 @@
|
||||
package com.gtnewhorizons.angelica.api;
|
||||
|
||||
import com.gtnewhorizons.angelica.compat.mojang.BlockPos;
|
||||
import com.gtnewhorizons.angelica.compat.nd.Quad;
|
||||
import com.gtnewhorizons.angelica.utils.ObjectPooler;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.world.IBlockAccess;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public interface QuadProvider {
|
||||
|
||||
@@ -23,9 +21,23 @@ public interface QuadProvider {
|
||||
*/
|
||||
default int getColor(IBlockAccess world, BlockPos pos, Block block, int meta, Random random) {
|
||||
|
||||
final int cin = block.colorMultiplier(world, pos.x, pos.y, pos.z);
|
||||
final int cin = block.colorMultiplier(world, pos.getX(), pos.getY(), pos.getZ());
|
||||
return (0xFF << 24) | ((cin & B_MASK) << 16) | (cin & G_MASK) | ((cin & R_MASK) >>> 16);
|
||||
}
|
||||
|
||||
List<Quad> getQuads(IBlockAccess world, BlockPos pos, Block block, int meta, ForgeDirection dir, Random random, int color, ObjectPooler<Quad> quadPool);
|
||||
/**
|
||||
* If you need to allocate new quads, set this to true. If true, the quads returned by {@link #getQuads} are
|
||||
* recycled, and you should not keep a reference to them. Example: stone can return a static list every time, but a
|
||||
* modded block which adds or removes quads based on location would need dynamic quads.
|
||||
*/
|
||||
default boolean isDynamic() {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Provide quads to render. If you need new quads, they should be obtained with the passed supplier and
|
||||
* {@link #isDynamic} overridden to return true. If so, all quads in the list are recycled and references to them
|
||||
* should not be kept.
|
||||
*/
|
||||
List<QuadView> getQuads(IBlockAccess world, BlockPos pos, Block block, int meta, ForgeDirection dir, Random random, int color, Supplier<QuadView> quadPool);
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package com.gtnewhorizons.angelica.api;
|
||||
|
||||
import me.jellysquid.mods.sodium.client.model.quad.ModelQuadViewMutable;
|
||||
import me.jellysquid.mods.sodium.client.render.pipeline.BlockRenderer;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
public interface QuadView extends ModelQuadViewMutable {
|
||||
|
||||
boolean isShade();
|
||||
boolean isDeleted();
|
||||
ForgeDirection getFace();
|
||||
void copyFrom(QuadView src);
|
||||
void setRaw(int[] data, boolean shade, @Nullable ForgeDirection face, int colorIndex, int flags);
|
||||
int[] getRawVertexes();
|
||||
|
||||
/**
|
||||
* Present for compatibility with the Tesselator, not recommended for general use.
|
||||
*/
|
||||
void setState(int[] rawBuffer, int offset, BlockRenderer.Flags flags, int drawMode, float offsetX, float offsetY, float offsetZ);
|
||||
}
|
||||
+11
-10
@@ -1,8 +1,9 @@
|
||||
package com.gtnewhorizons.angelica.client.renderer;
|
||||
|
||||
import com.gtnewhorizons.angelica.compat.mojang.BlockPos;
|
||||
import com.gtnewhorizons.angelica.api.QuadView;
|
||||
import com.gtnewhorizons.angelica.compat.mojang.BlockPosImpl;
|
||||
import com.gtnewhorizons.angelica.compat.mojang.VertexFormat;
|
||||
import com.gtnewhorizons.angelica.compat.nd.Quad;
|
||||
import me.jellysquid.mods.sodium.client.model.quad.Quad;
|
||||
import com.gtnewhorizons.angelica.glsm.stacks.Vector3dStack;
|
||||
import com.gtnewhorizons.angelica.mixins.interfaces.ITessellatorInstance;
|
||||
import com.gtnewhorizons.angelica.utils.ObjectPooler;
|
||||
@@ -39,15 +40,15 @@ public class CapturingTessellator extends Tessellator implements ITessellatorIns
|
||||
private static final MethodHandle sRawBufferSize;
|
||||
private static final MethodHandle gRawBufferSize;
|
||||
private final BlockRenderer.Flags FLAGS = new BlockRenderer.Flags(true, true, true, true);
|
||||
private final ObjectPooler<Quad> quadBuf = new ObjectPooler<>(Quad::new);
|
||||
private final List<Quad> collectedQuads = new ObjectArrayList<>();
|
||||
private final ObjectPooler<QuadView> quadBuf = new ObjectPooler<>(Quad::new);
|
||||
private final List<QuadView> collectedQuads = new ObjectArrayList<>();
|
||||
|
||||
// Any offset we need to the Tesselator's offset!
|
||||
private final BlockPos offset = new BlockPos();
|
||||
private final BlockPosImpl offset = new BlockPosImpl();
|
||||
|
||||
private final Vector3dStack storedTranslation = new Vector3dStack();
|
||||
|
||||
public void setOffset(BlockPos pos) {
|
||||
public void setOffset(BlockPosImpl pos) {
|
||||
this.offset.set(pos);
|
||||
}
|
||||
public void resetOffset() {
|
||||
@@ -93,10 +94,10 @@ public class CapturingTessellator extends Tessellator implements ITessellatorIns
|
||||
|
||||
|
||||
for(int quadI = 0; quadI < this.vertexCount / verticesPerPrimitive; quadI++) {
|
||||
final Quad quad = quadBuf.getInstance();
|
||||
final QuadView quad = quadBuf.getInstance();
|
||||
quad.setState(this.rawBuffer, quadI * (verticesPerPrimitive * 8), FLAGS, this.drawMode, -offset.x, -offset.y, -offset.z);
|
||||
|
||||
if(quad.deleted) {
|
||||
if(quad.isDeleted()) {
|
||||
quadBuf.releaseInstance(quad);
|
||||
} else {
|
||||
this.collectedQuads.add(quad);
|
||||
@@ -115,7 +116,7 @@ public class CapturingTessellator extends Tessellator implements ITessellatorIns
|
||||
}
|
||||
|
||||
|
||||
public List<Quad> getQuads() {
|
||||
public List<QuadView> getQuads() {
|
||||
return collectedQuads;
|
||||
}
|
||||
|
||||
@@ -127,7 +128,7 @@ public class CapturingTessellator extends Tessellator implements ITessellatorIns
|
||||
this.collectedQuads.clear();
|
||||
}
|
||||
|
||||
public static ByteBuffer quadsToBuffer(List<Quad> quads, VertexFormat format) {
|
||||
public static ByteBuffer quadsToBuffer(List<QuadView> quads, VertexFormat format) {
|
||||
if(!format.canWriteQuads()) {
|
||||
throw new IllegalStateException("Vertex format has no quad writer: " + format);
|
||||
}
|
||||
|
||||
@@ -1,12 +1,11 @@
|
||||
package com.gtnewhorizons.angelica.common;
|
||||
|
||||
import com.gtnewhorizons.angelica.api.BlockPos;
|
||||
import com.gtnewhorizons.angelica.api.QuadProvider;
|
||||
import com.gtnewhorizons.angelica.compat.mojang.BlockPos;
|
||||
import com.gtnewhorizons.angelica.compat.nd.Quad;
|
||||
import com.gtnewhorizons.angelica.api.QuadView;
|
||||
import com.gtnewhorizons.angelica.models.json.JsonModel;
|
||||
import com.gtnewhorizons.angelica.models.json.Loader;
|
||||
import com.gtnewhorizons.angelica.models.json.Variant;
|
||||
import com.gtnewhorizons.angelica.utils.ObjectPooler;
|
||||
import it.unimi.dsi.fastutil.objects.ObjectImmutableList;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.material.Material;
|
||||
@@ -19,6 +18,7 @@ import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public class BlockTest extends Block implements QuadProvider {
|
||||
|
||||
@@ -48,7 +48,7 @@ public class BlockTest extends Block implements QuadProvider {
|
||||
false
|
||||
),
|
||||
};
|
||||
private static final List<Quad> EMPTY = ObjectImmutableList.of();
|
||||
private static final List<QuadView> EMPTY = ObjectImmutableList.of();
|
||||
private static final JsonModel[] model = new JsonModel[4];
|
||||
|
||||
public BlockTest() {
|
||||
@@ -78,7 +78,7 @@ public class BlockTest extends Block implements QuadProvider {
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Quad> getQuads(IBlockAccess world, BlockPos pos, Block block, int meta, ForgeDirection dir, Random random, int color, ObjectPooler<Quad> quadPool) {
|
||||
public List<QuadView> getQuads(IBlockAccess world, BlockPos pos, Block block, int meta, ForgeDirection dir, Random random, int color, Supplier<QuadView> quadPool) {
|
||||
|
||||
if (meta < 2 || meta > 5) meta = 2;
|
||||
|
||||
|
||||
@@ -1,102 +0,0 @@
|
||||
package com.gtnewhorizons.angelica.compat.mojang;
|
||||
|
||||
import net.minecraft.util.MathHelper;
|
||||
import net.minecraft.world.ChunkPosition;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import org.joml.Vector3i;
|
||||
|
||||
import java.math.RoundingMode;
|
||||
|
||||
import static com.google.common.math.IntMath.log2;
|
||||
|
||||
// Should we keep this?
|
||||
public class BlockPos extends Vector3i {
|
||||
|
||||
private static final int SIZE_BITS_X = 1 + log2(MathHelper.roundUpToPowerOfTwo(30000000), RoundingMode.UNNECESSARY);
|
||||
private static final int SIZE_BITS_Z = SIZE_BITS_X;
|
||||
private static final int SIZE_BITS_Y = 64 - SIZE_BITS_X - SIZE_BITS_Z;
|
||||
private static final long BITS_X = (1L << SIZE_BITS_X) - 1L;
|
||||
private static final long BITS_Y = (1L << SIZE_BITS_Y) - 1L;
|
||||
private static final long BITS_Z = (1L << SIZE_BITS_Z) - 1L;
|
||||
private static final int BIT_SHIFT_Z = SIZE_BITS_Y;
|
||||
private static final int BIT_SHIFT_X = SIZE_BITS_Y + SIZE_BITS_Z;
|
||||
|
||||
public BlockPos() {
|
||||
super();
|
||||
}
|
||||
public BlockPos(int x, int y, int z) {
|
||||
super(x, y, z);
|
||||
}
|
||||
|
||||
public BlockPos(ChunkPosition chunkPosition) {
|
||||
super(chunkPosition.chunkPosX, chunkPosition.chunkPosY, chunkPosition.chunkPosZ);
|
||||
}
|
||||
|
||||
public int getX() {
|
||||
return this.x;
|
||||
}
|
||||
public int getY() {
|
||||
return this.y;
|
||||
}
|
||||
public int getZ() {
|
||||
return this.z;
|
||||
}
|
||||
|
||||
public BlockPos set(int x, int y, int z) {
|
||||
super.set(x, y, z);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method does NOT mutate the BlockPos
|
||||
*/
|
||||
public BlockPos offset(ForgeDirection d) {
|
||||
return new BlockPos(this.x + d.offsetX, this.y + d.offsetY, this.z + d.offsetZ);
|
||||
}
|
||||
|
||||
/**
|
||||
* This method does NOT mutate the BlockPos
|
||||
*/
|
||||
public BlockPos down() {
|
||||
return offset(ForgeDirection.DOWN);
|
||||
}
|
||||
|
||||
/**
|
||||
* This method does NOT mutate the BlockPos
|
||||
*/
|
||||
public BlockPos up() {
|
||||
return offset(ForgeDirection.UP);
|
||||
}
|
||||
|
||||
public long asLong() {
|
||||
return asLong(this.x, this.y, this.z);
|
||||
}
|
||||
|
||||
public static long asLong(int x, int y, int z) {
|
||||
long l = 0L;
|
||||
l |= ((long)x & BITS_X) << BIT_SHIFT_X;
|
||||
l |= ((long)y & BITS_Y) << 0;
|
||||
l |= ((long)z & BITS_Z) << BIT_SHIFT_Z;
|
||||
return l;
|
||||
}
|
||||
|
||||
public BlockPos set(long packedPos) {
|
||||
return set(unpackLongX(packedPos), unpackLongY(packedPos), unpackLongZ(packedPos));
|
||||
}
|
||||
|
||||
public static int unpackLongX(long packedPos) {
|
||||
return (int)(packedPos << 64 - BIT_SHIFT_X - SIZE_BITS_X >> 64 - SIZE_BITS_X);
|
||||
}
|
||||
|
||||
public static int unpackLongY(long packedPos) {
|
||||
return (int)(packedPos << 64 - SIZE_BITS_Y >> 64 - SIZE_BITS_Y);
|
||||
}
|
||||
|
||||
public static int unpackLongZ(long packedPos) {
|
||||
return (int)(packedPos << 64 - BIT_SHIFT_Z - SIZE_BITS_Z >> 64 - SIZE_BITS_Z);
|
||||
}
|
||||
|
||||
public static class Mutable extends BlockPos {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
package com.gtnewhorizons.angelica.compat.mojang;
|
||||
|
||||
import com.gtnewhorizons.angelica.api.BlockPos;
|
||||
import com.gtnewhorizons.angelica.api.MutableBlockPos;
|
||||
import net.minecraft.world.ChunkPosition;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import org.joml.Vector3i;
|
||||
|
||||
import static com.gtnewhorizons.angelica.api.BlockPos.unpackLongX;
|
||||
import static com.gtnewhorizons.angelica.api.BlockPos.unpackLongY;
|
||||
import static com.gtnewhorizons.angelica.api.BlockPos.unpackLongZ;
|
||||
|
||||
// Should we keep this?
|
||||
public class BlockPosImpl extends Vector3i implements MutableBlockPos {
|
||||
|
||||
public BlockPosImpl() {
|
||||
super();
|
||||
}
|
||||
public BlockPosImpl(int x, int y, int z) {
|
||||
super(x, y, z);
|
||||
}
|
||||
|
||||
public BlockPosImpl(ChunkPosition chunkPosition) {
|
||||
super(chunkPosition.chunkPosX, chunkPosition.chunkPosY, chunkPosition.chunkPosZ);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getX() {
|
||||
return this.x;
|
||||
}
|
||||
@Override
|
||||
public int getY() {
|
||||
return this.y;
|
||||
}
|
||||
@Override
|
||||
public int getZ() {
|
||||
return this.z;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockPosImpl offset(ForgeDirection d) {
|
||||
return new BlockPosImpl(this.x + d.offsetX, this.y + d.offsetY, this.z + d.offsetZ);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockPosImpl down() {
|
||||
return offset(ForgeDirection.DOWN);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockPosImpl up() {
|
||||
return offset(ForgeDirection.UP);
|
||||
}
|
||||
|
||||
@Override
|
||||
public long asLong() {
|
||||
return BlockPos.asLong(this.x, this.y, this.z);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockPosImpl set(int x, int y, int z) {
|
||||
super.set(x, y, z);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockPosImpl set(long packedPos) {
|
||||
return set(unpackLongX(packedPos), unpackLongY(packedPos), unpackLongZ(packedPos));
|
||||
}
|
||||
}
|
||||
@@ -13,7 +13,7 @@ import org.joml.Vector4f;
|
||||
@Getter
|
||||
public class Camera {
|
||||
final Vector3d pos = new Vector3d();
|
||||
final BlockPos.Mutable blockPos = new BlockPos.Mutable();
|
||||
final BlockPosImpl blockPos = new BlockPosImpl();
|
||||
float pitch;
|
||||
float yaw;
|
||||
EntityLivingBase entity;
|
||||
|
||||
+2
-2
@@ -36,12 +36,12 @@ public class ChunkOcclusionDataBuilder {
|
||||
}
|
||||
private int openCount = 4096;
|
||||
|
||||
public void markClosed(BlockPos pos) {
|
||||
public void markClosed(BlockPosImpl pos) {
|
||||
this.closed.set(pack(pos), true);
|
||||
--this.openCount;
|
||||
}
|
||||
|
||||
private static int pack(BlockPos pos) {
|
||||
private static int pack(BlockPosImpl pos) {
|
||||
return pack(pos.getX() & 15, pos.getY() & 15, pos.getZ() & 15);
|
||||
}
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@ public class ChunkPos {
|
||||
this.z = z;
|
||||
}
|
||||
|
||||
public ChunkPos(BlockPos pos) {
|
||||
public ChunkPos(BlockPosImpl pos) {
|
||||
this.x = pos.getX() >> 4;
|
||||
this.z = pos.getZ() >> 4;
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ public class ChunkSectionPos extends Vector3i {
|
||||
return new ChunkSectionPos(x, y, z);
|
||||
}
|
||||
|
||||
public static ChunkSectionPos from(BlockPos pos) {
|
||||
public static ChunkSectionPos from(BlockPosImpl pos) {
|
||||
return new ChunkSectionPos(getSectionCoord(pos.getX()), getSectionCoord(pos.getY()), getSectionCoord(pos.getZ()));
|
||||
}
|
||||
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
package com.gtnewhorizons.angelica.compat.mojang;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.gtnewhorizons.angelica.api.QuadView;
|
||||
import com.gtnewhorizons.angelica.compat.nd.IWriteQuads;
|
||||
import com.gtnewhorizons.angelica.compat.nd.Quad;
|
||||
import it.unimi.dsi.fastutil.ints.IntArrayList;
|
||||
import it.unimi.dsi.fastutil.ints.IntList;
|
||||
import lombok.Getter;
|
||||
@@ -79,7 +79,7 @@ public class VertexFormat {
|
||||
return quadWriter != null;
|
||||
}
|
||||
|
||||
public void writeQuad(Quad quad, ByteBuffer byteBuffer) {
|
||||
public void writeQuad(QuadView quad, ByteBuffer byteBuffer) {
|
||||
if(quadWriter == null) {
|
||||
throw new IllegalStateException("No quad writer set");
|
||||
}
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
package com.gtnewhorizons.angelica.compat.nd;
|
||||
|
||||
import com.gtnewhorizons.angelica.api.QuadView;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
public interface IWriteQuads {
|
||||
void writeQuad(Quad quad, ByteBuffer buf);
|
||||
void writeQuad(QuadView quad, ByteBuffer buf);
|
||||
}
|
||||
@@ -1,218 +0,0 @@
|
||||
package com.gtnewhorizons.angelica.compat.nd;
|
||||
|
||||
import lombok.Getter;
|
||||
import me.jellysquid.mods.sodium.client.model.quad.ModelQuadView;
|
||||
import me.jellysquid.mods.sodium.client.model.quad.properties.ModelQuadFacing;
|
||||
import me.jellysquid.mods.sodium.client.model.quad.properties.ModelQuadFlags;
|
||||
import me.jellysquid.mods.sodium.client.render.pipeline.BlockRenderer;
|
||||
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import org.joml.Vector3f;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.Locale;
|
||||
|
||||
public class Quad implements ModelQuadView {
|
||||
// Adapted from Neodymium
|
||||
|
||||
private final static int DEFAULT_BRIGHTNESS = 15 << 20 | 15 << 4;
|
||||
private final static int DEFAULT_COLOR = 0xFFFFFFFF;
|
||||
|
||||
public float[] xs = new float[4];
|
||||
public float[] ys = new float[4];
|
||||
public float[] zs = new float[4];
|
||||
public float[] us = new float[4];
|
||||
public float[] vs = new float[4];
|
||||
public int[] cs = new int[4];
|
||||
public int[] ns = new int[4];
|
||||
public int[] bs = new int[4];
|
||||
|
||||
public boolean deleted;
|
||||
|
||||
private final Vector3f vectorA = new Vector3f(), vectorB = new Vector3f(), vectorC = new Vector3f();
|
||||
|
||||
@Getter
|
||||
private boolean shade;
|
||||
private int cachedFlags;
|
||||
@Getter
|
||||
private ForgeDirection face;
|
||||
private int colorIndex = -1;
|
||||
|
||||
public int[] getColors() {
|
||||
return this.cs;
|
||||
}
|
||||
|
||||
/** Returns the face, forced to take one of 6 directions to mirror the behavior of baked quads in 1.16.5. */
|
||||
@Override
|
||||
public ForgeDirection getLightFace() {
|
||||
return this.face != ForgeDirection.UNKNOWN ? this.face : ForgeDirection.UP;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getX(int idx) {
|
||||
return xs[idx];
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getY(int idx) {
|
||||
return ys[idx];
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getZ(int idx) {
|
||||
return zs[idx];
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getColor(int idx) {
|
||||
return cs[idx];
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getTexU(int idx) {
|
||||
return us[idx];
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getTexV(int idx) {
|
||||
return vs[idx];
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getFlags() {
|
||||
return this.cachedFlags;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getLight(int idx) {
|
||||
return bs[idx];
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getNormal(int idx) {
|
||||
return ns[idx];
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getColorIndex() {
|
||||
return colorIndex;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TextureAtlasSprite rubidium$getSprite() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public void copyFrom(Quad quad) {
|
||||
|
||||
System.arraycopy(quad.xs, 0, this.xs, 0, 4);
|
||||
System.arraycopy(quad.ys, 0, this.ys, 0, 4);
|
||||
System.arraycopy(quad.zs, 0, this.zs, 0, 4);
|
||||
|
||||
System.arraycopy(quad.us, 0, this.us, 0, 4);
|
||||
System.arraycopy(quad.vs, 0, this.vs, 0, 4);
|
||||
|
||||
System.arraycopy(quad.cs, 0, this.cs, 0, 4);
|
||||
System.arraycopy(quad.ns, 0, this.ns, 0, 4);
|
||||
System.arraycopy(quad.bs, 0, this.bs, 0, 4);
|
||||
|
||||
this.deleted = quad.deleted;
|
||||
this.shade = quad.shade;
|
||||
this.cachedFlags = quad.cachedFlags;
|
||||
this.face = quad.face;
|
||||
this.colorIndex = quad.colorIndex;
|
||||
}
|
||||
|
||||
public void setRaw(int[] data, boolean shade, @Nullable ForgeDirection face, int colorIndex, int flags) {
|
||||
|
||||
int i = 0;
|
||||
for(int vi = 0; vi < 4; vi++) {
|
||||
|
||||
xs[vi] = Float.intBitsToFloat(data[i + 0]);
|
||||
ys[vi] = Float.intBitsToFloat(data[i + 1]);
|
||||
zs[vi] = Float.intBitsToFloat(data[i + 2]);
|
||||
|
||||
us[vi] = Float.intBitsToFloat(data[i + 3]);
|
||||
vs[vi] = Float.intBitsToFloat(data[i + 4]);
|
||||
|
||||
cs[vi] = data[i + 5];
|
||||
ns[vi] = data[i + 6];
|
||||
bs[vi] = data[i + 7];
|
||||
|
||||
i += 8;
|
||||
}
|
||||
|
||||
this.shade = shade;
|
||||
this.deleted = false;
|
||||
this.face = face;
|
||||
this.colorIndex = colorIndex;
|
||||
this.cachedFlags = flags;
|
||||
}
|
||||
|
||||
private void read(int[] rawBuffer, int offset, float offsetX, float offsetY, float offsetZ, int drawMode, BlockRenderer.Flags flags) {
|
||||
final int vertices = drawMode == GL11.GL_TRIANGLES ? 3 : 4;
|
||||
int i = offset;
|
||||
for(int vi = 0; vi < vertices; vi++) {
|
||||
|
||||
xs[vi] = Float.intBitsToFloat(rawBuffer[i + 0]) + offsetX;
|
||||
ys[vi] = Float.intBitsToFloat(rawBuffer[i + 1]) + offsetY;
|
||||
zs[vi] = Float.intBitsToFloat(rawBuffer[i + 2]) + offsetZ;
|
||||
|
||||
us[vi] = Float.intBitsToFloat(rawBuffer[i + 3]);
|
||||
vs[vi] = Float.intBitsToFloat(rawBuffer[i + 4]);
|
||||
|
||||
cs[vi] = flags.hasColor ? rawBuffer[i + 5] : DEFAULT_COLOR;
|
||||
ns[vi] = flags.hasNormals ? rawBuffer[i + 6] : 0;
|
||||
bs[vi] = flags.hasBrightness ? rawBuffer[i + 7] : DEFAULT_BRIGHTNESS;
|
||||
|
||||
i += 8;
|
||||
}
|
||||
|
||||
// sus
|
||||
this.shade = flags.hasBrightness;
|
||||
|
||||
if(vertices == 3) {
|
||||
|
||||
// Quadrangulate!
|
||||
xs[3] = xs[2];
|
||||
ys[3] = ys[2];
|
||||
zs[3] = zs[2];
|
||||
|
||||
us[3] = us[2];
|
||||
vs[3] = vs[2];
|
||||
|
||||
bs[3] = bs[2];
|
||||
cs[3] = cs[2];
|
||||
ns[3] = ns[2];
|
||||
}
|
||||
}
|
||||
|
||||
public void setState(int[] rawBuffer, int offset, BlockRenderer.Flags flags, int drawMode, float offsetX, float offsetY, float offsetZ) {
|
||||
deleted = false;
|
||||
|
||||
read(rawBuffer, offset, offsetX, offsetY, offsetZ, drawMode, flags);
|
||||
|
||||
if(xs[0] == xs[1] && xs[1] == xs[2] && xs[2] == xs[3] && ys[0] == ys[1] && ys[1] == ys[2] && ys[2] == ys[3]) {
|
||||
// ignore empty quads (e.g. alpha pass of EnderIO item conduits)
|
||||
deleted = true;
|
||||
return;
|
||||
}
|
||||
|
||||
vectorA.set(xs[1] - xs[0], ys[1] - ys[0], zs[1] - zs[0]);
|
||||
vectorB.set(xs[2] - xs[1], ys[2] - ys[1], zs[2] - zs[1]);
|
||||
vectorA.cross(vectorB, vectorC);
|
||||
|
||||
this.face = ModelQuadFacing.toDirection(ModelQuadFacing.fromVector(vectorC));
|
||||
this.cachedFlags = ModelQuadFlags.getQuadFlags(this);
|
||||
}
|
||||
|
||||
public static boolean isValid(Quad q) {
|
||||
return q != null && !q.deleted;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return String.format(Locale.ENGLISH, "%s[(%.1f, %.1f, %.1f), (%.1f, %.1f, %.1f), (%.1f, %.1f, %.1f), (%.1f, %.1f, %.1f)]", deleted ? "XXX " : "", xs[0], ys[0], zs[0], xs[1], ys[1], zs[1], xs[2], ys[2], zs[2], xs[3], ys[3], zs[3]);
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
package com.gtnewhorizons.angelica.compat.nd.writers;
|
||||
|
||||
import com.gtnewhorizons.angelica.api.QuadView;
|
||||
import com.gtnewhorizons.angelica.compat.nd.IWriteQuads;
|
||||
import com.gtnewhorizons.angelica.compat.nd.Quad;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
@@ -17,7 +17,7 @@ public class ItemVBOQuadWriter implements IWriteQuads {
|
||||
this.direct = direct;
|
||||
}
|
||||
@Override
|
||||
public void writeQuad(Quad quad, ByteBuffer buf) {
|
||||
public void writeQuad(QuadView quad, ByteBuffer buf) {
|
||||
if(direct) {
|
||||
writeQuadDirect(quad, buf);
|
||||
} else {
|
||||
@@ -25,11 +25,11 @@ public class ItemVBOQuadWriter implements IWriteQuads {
|
||||
}
|
||||
}
|
||||
|
||||
protected void writeQuadDirect(Quad quad, ByteBuffer buf) {
|
||||
protected void writeQuadDirect(QuadView quad, ByteBuffer buf) {
|
||||
throw new UnsupportedOperationException("Direct mode not supported yet");
|
||||
}
|
||||
|
||||
protected void writeQuadIndirect(Quad quad, ByteBuffer buf) {
|
||||
protected void writeQuadIndirect(QuadView quad, ByteBuffer buf) {
|
||||
for(int idx = 0; idx < 4; ++idx) {
|
||||
// Position
|
||||
buf.putFloat(quad.getX(idx));
|
||||
|
||||
+4
-4
@@ -1,7 +1,7 @@
|
||||
package com.gtnewhorizons.angelica.compat.nd.writers;
|
||||
|
||||
import com.gtnewhorizons.angelica.api.QuadView;
|
||||
import com.gtnewhorizons.angelica.compat.nd.IWriteQuads;
|
||||
import com.gtnewhorizons.angelica.compat.nd.Quad;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
@@ -17,7 +17,7 @@ public class PositionColorTextureQuadWriter implements IWriteQuads {
|
||||
this.direct = direct;
|
||||
}
|
||||
@Override
|
||||
public void writeQuad(Quad quad, ByteBuffer buf) {
|
||||
public void writeQuad(QuadView quad, ByteBuffer buf) {
|
||||
if(direct) {
|
||||
writeQuadDirect(quad, buf);
|
||||
} else {
|
||||
@@ -25,11 +25,11 @@ public class PositionColorTextureQuadWriter implements IWriteQuads {
|
||||
}
|
||||
}
|
||||
|
||||
protected void writeQuadDirect(Quad quad, ByteBuffer buf) {
|
||||
protected void writeQuadDirect(QuadView quad, ByteBuffer buf) {
|
||||
throw new UnsupportedOperationException("Direct mode not supported yet");
|
||||
}
|
||||
|
||||
protected void writeQuadIndirect(Quad quad, ByteBuffer buf) {
|
||||
protected void writeQuadIndirect(QuadView quad, ByteBuffer buf) {
|
||||
for(int idx = 0; idx < 4; ++idx) {
|
||||
// Position
|
||||
buf.putFloat(quad.getX(idx));
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package com.gtnewhorizons.angelica.compat.nd.writers;
|
||||
|
||||
import com.gtnewhorizons.angelica.api.QuadView;
|
||||
import com.gtnewhorizons.angelica.compat.nd.IWriteQuads;
|
||||
import com.gtnewhorizons.angelica.compat.nd.Quad;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
@@ -17,7 +17,7 @@ public class PositionQuadWriter implements IWriteQuads {
|
||||
this.direct = direct;
|
||||
}
|
||||
@Override
|
||||
public void writeQuad(Quad quad, ByteBuffer buf) {
|
||||
public void writeQuad(QuadView quad, ByteBuffer buf) {
|
||||
if(direct) {
|
||||
writeQuadDirect(quad, buf);
|
||||
} else {
|
||||
@@ -25,11 +25,11 @@ public class PositionQuadWriter implements IWriteQuads {
|
||||
}
|
||||
}
|
||||
|
||||
protected void writeQuadDirect(Quad quad, ByteBuffer buf) {
|
||||
protected void writeQuadDirect(QuadView quad, ByteBuffer buf) {
|
||||
throw new UnsupportedOperationException("Direct mode not supported yet");
|
||||
}
|
||||
|
||||
protected void writeQuadIndirect(Quad quad, ByteBuffer buf) {
|
||||
protected void writeQuadIndirect(QuadView quad, ByteBuffer buf) {
|
||||
for(int idx = 0; idx < 4; ++idx) {
|
||||
// Position
|
||||
buf.putFloat(quad.getX(idx));
|
||||
|
||||
+4
-4
@@ -1,7 +1,7 @@
|
||||
package com.gtnewhorizons.angelica.compat.nd.writers;
|
||||
|
||||
import com.gtnewhorizons.angelica.api.QuadView;
|
||||
import com.gtnewhorizons.angelica.compat.nd.IWriteQuads;
|
||||
import com.gtnewhorizons.angelica.compat.nd.Quad;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
@@ -17,7 +17,7 @@ public class PositionTextureColorQuadWriter implements IWriteQuads {
|
||||
this.direct = direct;
|
||||
}
|
||||
@Override
|
||||
public void writeQuad(Quad quad, ByteBuffer buf) {
|
||||
public void writeQuad(QuadView quad, ByteBuffer buf) {
|
||||
if(direct) {
|
||||
writeQuadDirect(quad, buf);
|
||||
} else {
|
||||
@@ -25,11 +25,11 @@ public class PositionTextureColorQuadWriter implements IWriteQuads {
|
||||
}
|
||||
}
|
||||
|
||||
protected void writeQuadDirect(Quad quad, ByteBuffer buf) {
|
||||
protected void writeQuadDirect(QuadView quad, ByteBuffer buf) {
|
||||
throw new UnsupportedOperationException("Direct mode not supported yet");
|
||||
}
|
||||
|
||||
protected void writeQuadIndirect(Quad quad, ByteBuffer buf) {
|
||||
protected void writeQuadIndirect(QuadView quad, ByteBuffer buf) {
|
||||
for(int idx = 0; idx < 4; ++idx) {
|
||||
// Position
|
||||
buf.putFloat(quad.getX(idx));
|
||||
|
||||
+4
-4
@@ -1,7 +1,7 @@
|
||||
package com.gtnewhorizons.angelica.compat.nd.writers;
|
||||
|
||||
import com.gtnewhorizons.angelica.api.QuadView;
|
||||
import com.gtnewhorizons.angelica.compat.nd.IWriteQuads;
|
||||
import com.gtnewhorizons.angelica.compat.nd.Quad;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
@@ -17,7 +17,7 @@ public class PositionTextureQuadWriter implements IWriteQuads {
|
||||
this.direct = direct;
|
||||
}
|
||||
@Override
|
||||
public void writeQuad(Quad quad, ByteBuffer buf) {
|
||||
public void writeQuad(QuadView quad, ByteBuffer buf) {
|
||||
if(direct) {
|
||||
writeQuadDirect(quad, buf);
|
||||
} else {
|
||||
@@ -25,11 +25,11 @@ public class PositionTextureQuadWriter implements IWriteQuads {
|
||||
}
|
||||
}
|
||||
|
||||
protected void writeQuadDirect(Quad quad, ByteBuffer buf) {
|
||||
protected void writeQuadDirect(QuadView quad, ByteBuffer buf) {
|
||||
throw new UnsupportedOperationException("Direct mode not supported yet");
|
||||
}
|
||||
|
||||
protected void writeQuadIndirect(Quad quad, ByteBuffer buf) {
|
||||
protected void writeQuadIndirect(QuadView quad, ByteBuffer buf) {
|
||||
for(int idx = 0; idx < 4; ++idx) {
|
||||
// Position
|
||||
buf.putFloat(quad.getX(idx));
|
||||
|
||||
@@ -1,16 +1,15 @@
|
||||
package com.gtnewhorizons.angelica.glsm;
|
||||
|
||||
import com.gtnewhorizons.angelica.api.QuadView;
|
||||
import com.gtnewhorizons.angelica.client.renderer.CapturingTessellator;
|
||||
import com.gtnewhorizons.angelica.compat.mojang.VertexBuffer;
|
||||
import com.gtnewhorizons.angelica.compat.mojang.VertexFormat;
|
||||
import com.gtnewhorizons.angelica.compat.nd.Quad;
|
||||
import net.minecraft.client.renderer.Tessellator;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.List;
|
||||
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public class TessellatorManager {
|
||||
private static final ThreadLocal<CapturingTessellator> capturingTessellator = ThreadLocal.withInitial(CapturingTessellator::new);
|
||||
@@ -51,7 +50,7 @@ public class TessellatorManager {
|
||||
* Stop the CapturingTessellator and return the pooled quads. The quads are valid until clearQuads() is
|
||||
* called on the CapturingTesselator, which must be done before starting capturing again.
|
||||
*/
|
||||
public static List<Quad> stopCapturingToPooledQuads() {
|
||||
public static List<QuadView> stopCapturingToPooledQuads() {
|
||||
if(!currentlyCapturing.get()) throw new IllegalStateException("Tried to stop capturing when not capturing!");
|
||||
currentlyCapturing.set(false);
|
||||
final CapturingTessellator tess = capturingTessellator.get();
|
||||
@@ -59,7 +58,7 @@ public class TessellatorManager {
|
||||
// Be sure we got all the quads
|
||||
if(tess.isDrawing) tess.draw();
|
||||
|
||||
final List<Quad> quads = tess.getQuads();
|
||||
final List<QuadView> quads = tess.getQuads();
|
||||
tess.discard();
|
||||
tess.restoreTranslation();
|
||||
|
||||
|
||||
+9
-6
@@ -1,25 +1,28 @@
|
||||
package com.gtnewhorizons.angelica.mixins.early.angelica.models;
|
||||
|
||||
import com.gtnewhorizons.angelica.api.BlockPos;
|
||||
import com.gtnewhorizons.angelica.api.QuadProvider;
|
||||
import com.gtnewhorizons.angelica.compat.mojang.BlockPos;
|
||||
import com.gtnewhorizons.angelica.compat.nd.Quad;
|
||||
import com.gtnewhorizons.angelica.utils.ObjectPooler;
|
||||
import com.gtnewhorizons.angelica.api.QuadView;
|
||||
import it.unimi.dsi.fastutil.objects.ObjectImmutableList;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockAir;
|
||||
import net.minecraft.world.IBlockAccess;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Unique;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
@Mixin(BlockAir.class)
|
||||
public abstract class MixinBlockAir implements QuadProvider {
|
||||
|
||||
private static List<Quad> quads = ObjectImmutableList.of();
|
||||
@Unique
|
||||
private static final List<QuadView> angelica$EMPTY = ObjectImmutableList.of();
|
||||
|
||||
public List<Quad> getQuads(IBlockAccess world, BlockPos pos, Block block, int meta, ForgeDirection dir, Random random, int color, ObjectPooler<Quad> quadPool) {
|
||||
return quads;
|
||||
@Override
|
||||
public List<QuadView> getQuads(IBlockAccess world, BlockPos pos, Block block, int meta, ForgeDirection dir, Random random, int color, Supplier<QuadView> quadPool) {
|
||||
return angelica$EMPTY;
|
||||
}
|
||||
}
|
||||
+10
-4
@@ -1,9 +1,8 @@
|
||||
package com.gtnewhorizons.angelica.mixins.early.angelica.models;
|
||||
|
||||
import com.gtnewhorizons.angelica.api.BlockPos;
|
||||
import com.gtnewhorizons.angelica.api.QuadProvider;
|
||||
import com.gtnewhorizons.angelica.compat.mojang.BlockPos;
|
||||
import com.gtnewhorizons.angelica.compat.nd.Quad;
|
||||
import com.gtnewhorizons.angelica.utils.ObjectPooler;
|
||||
import com.gtnewhorizons.angelica.api.QuadView;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockLeaves;
|
||||
import net.minecraft.block.material.Material;
|
||||
@@ -13,13 +12,20 @@ import org.spongepowered.asm.mixin.Mixin;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import static com.gtnewhorizons.angelica.models.CubeModel.INSTANCE;
|
||||
|
||||
@Mixin(BlockLeaves.class)
|
||||
public abstract class MixinBlockLeaves extends Block implements QuadProvider {
|
||||
|
||||
public List<Quad> getQuads(IBlockAccess world, BlockPos pos, Block block, int meta, ForgeDirection dir, Random random, int color, ObjectPooler<Quad> quadPool) {
|
||||
@Override
|
||||
public boolean isDynamic() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<QuadView> getQuads(IBlockAccess world, BlockPos pos, Block block, int meta, ForgeDirection dir, Random random, int color, Supplier<QuadView> quadPool) {
|
||||
return INSTANCE.get().getQuads(world, pos, block, meta, dir, random, color, quadPool);
|
||||
}
|
||||
|
||||
|
||||
+5
-5
@@ -1,10 +1,9 @@
|
||||
package com.gtnewhorizons.angelica.mixins.early.angelica.models;
|
||||
|
||||
import com.gtnewhorizons.angelica.api.BlockPos;
|
||||
import com.gtnewhorizons.angelica.api.QuadProvider;
|
||||
import com.gtnewhorizons.angelica.compat.mojang.BlockPos;
|
||||
import com.gtnewhorizons.angelica.compat.nd.Quad;
|
||||
import com.gtnewhorizons.angelica.api.QuadView;
|
||||
import com.gtnewhorizons.angelica.models.VanillaModels;
|
||||
import com.gtnewhorizons.angelica.utils.ObjectPooler;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockStone;
|
||||
import net.minecraft.world.IBlockAccess;
|
||||
@@ -13,12 +12,13 @@ import org.spongepowered.asm.mixin.Mixin;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
@Mixin(BlockStone.class)
|
||||
public abstract class MixinBlockStone implements QuadProvider {
|
||||
|
||||
// TODO: Use modern model API
|
||||
public List<Quad> getQuads(IBlockAccess world, BlockPos pos, Block block, int meta, ForgeDirection dir, Random random, int color, ObjectPooler<Quad> quadPool) {
|
||||
@Override
|
||||
public List<QuadView> getQuads(IBlockAccess world, BlockPos pos, Block block, int meta, ForgeDirection dir, Random random, int color, Supplier<QuadView> quadPool) {
|
||||
return VanillaModels.stoneModel.getQuads(world, pos, block, meta, dir, random, color, quadPool);
|
||||
}
|
||||
}
|
||||
+5
-5
@@ -1,10 +1,9 @@
|
||||
package com.gtnewhorizons.angelica.mixins.early.angelica.models;
|
||||
|
||||
import com.gtnewhorizons.angelica.api.BlockPos;
|
||||
import com.gtnewhorizons.angelica.api.QuadProvider;
|
||||
import com.gtnewhorizons.angelica.compat.mojang.BlockPos;
|
||||
import com.gtnewhorizons.angelica.compat.nd.Quad;
|
||||
import com.gtnewhorizons.angelica.api.QuadView;
|
||||
import com.gtnewhorizons.angelica.models.CubeModel;
|
||||
import com.gtnewhorizons.angelica.utils.ObjectPooler;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockWorkbench;
|
||||
import net.minecraft.world.IBlockAccess;
|
||||
@@ -13,12 +12,13 @@ import org.spongepowered.asm.mixin.Mixin;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
@Mixin(BlockWorkbench.class)
|
||||
public class MixinBlockWorkbench implements QuadProvider {
|
||||
|
||||
// TODO: Use modern model API
|
||||
public List<Quad> getQuads(IBlockAccess world, BlockPos pos, Block block, int meta, ForgeDirection dir, Random random, int color, ObjectPooler<Quad> quadPool) {
|
||||
@Override
|
||||
public List<QuadView> getQuads(IBlockAccess world, BlockPos pos, Block block, int meta, ForgeDirection dir, Random random, int color, Supplier<QuadView> quadPool) {
|
||||
return CubeModel.INSTANCE.get().getQuads(world, pos, block, meta, dir, random, color, quadPool);
|
||||
}
|
||||
}
|
||||
@@ -1,9 +1,8 @@
|
||||
package com.gtnewhorizons.angelica.models;
|
||||
|
||||
import com.gtnewhorizons.angelica.api.BlockPos;
|
||||
import com.gtnewhorizons.angelica.api.QuadProvider;
|
||||
import com.gtnewhorizons.angelica.compat.mojang.BlockPos;
|
||||
import com.gtnewhorizons.angelica.compat.nd.Quad;
|
||||
import com.gtnewhorizons.angelica.utils.ObjectPooler;
|
||||
import com.gtnewhorizons.angelica.api.QuadView;
|
||||
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
|
||||
import it.unimi.dsi.fastutil.objects.ObjectImmutableList;
|
||||
import net.minecraft.block.Block;
|
||||
@@ -13,6 +12,7 @@ import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public class CubeModel implements QuadProvider {
|
||||
|
||||
@@ -23,8 +23,8 @@ public class CubeModel implements QuadProvider {
|
||||
|
||||
public static final ThreadLocal<CubeModel> INSTANCE = ThreadLocal.withInitial(CubeModel::new);
|
||||
private final NdQuadBuilder builder = new NdQuadBuilder();
|
||||
private static final List<Quad> EMPTY = ObjectImmutableList.of();
|
||||
private final List<Quad> ONE = new ObjectArrayList<>(1);
|
||||
private static final List<QuadView> EMPTY = ObjectImmutableList.of();
|
||||
private final List<QuadView> ONE = new ObjectArrayList<>(1);
|
||||
|
||||
public CubeModel() {
|
||||
|
||||
@@ -32,7 +32,12 @@ public class CubeModel implements QuadProvider {
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Quad> getQuads(IBlockAccess world, BlockPos pos, Block block, int meta, ForgeDirection dir, Random random, int color, ObjectPooler<Quad> quadPool) {
|
||||
public boolean isDynamic() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<QuadView> getQuads(IBlockAccess world, BlockPos pos, Block block, int meta, ForgeDirection dir, Random random, int color, Supplier<QuadView> quadPool) {
|
||||
|
||||
if (dir == ForgeDirection.UNKNOWN)
|
||||
return EMPTY;
|
||||
@@ -43,7 +48,7 @@ public class CubeModel implements QuadProvider {
|
||||
|
||||
this.builder.color(color, color, color, color);
|
||||
|
||||
ONE.set(0, this.builder.build(quadPool.getInstance()));
|
||||
ONE.set(0, this.builder.build(quadPool.get()));
|
||||
return ONE;
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
package com.gtnewhorizons.angelica.models;
|
||||
|
||||
import com.gtnewhorizons.angelica.compat.mojang.Axis;
|
||||
import com.gtnewhorizons.angelica.compat.nd.Quad;
|
||||
import me.jellysquid.mods.sodium.client.model.quad.Quad;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import org.joml.Vector3f;
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.gtnewhorizons.angelica.models;
|
||||
|
||||
import com.gtnewhorizons.angelica.compat.nd.Quad;
|
||||
import com.gtnewhorizons.angelica.api.QuadView;
|
||||
import me.jellysquid.mods.sodium.client.model.quad.Quad;
|
||||
import lombok.Getter;
|
||||
import me.jellysquid.mods.sodium.client.model.quad.ModelQuadView;
|
||||
import me.jellysquid.mods.sodium.client.model.quad.properties.ModelQuadFlags;
|
||||
@@ -16,18 +17,6 @@ import java.util.Arrays;
|
||||
|
||||
public class NdQuadBuilder implements ModelQuadView {
|
||||
|
||||
// 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;
|
||||
public static final int X_INDEX = 0;
|
||||
public static final int Y_INDEX = 1;
|
||||
public static final int Z_INDEX = 2;
|
||||
public static final int U_INDEX = 3;
|
||||
public static final int V_INDEX = 4;
|
||||
public static final int COLOR_INDEX = 5;
|
||||
public static final int NORMAL_INDEX = 6;
|
||||
public static final int LIGHTMAP_INDEX = 7;
|
||||
|
||||
/**
|
||||
* Causes texture to appear with no rotation.
|
||||
* Pass in bakeFlags parameter to {@link #spriteBake(IIcon, int)}.
|
||||
@@ -99,7 +88,7 @@ public class NdQuadBuilder implements ModelQuadView {
|
||||
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];
|
||||
private final int[] data = new int[Quad.QUAD_STRIDE];
|
||||
private int geometryFlags = 0;
|
||||
private boolean isGeometryInvalid = true;
|
||||
private int tag = 0;
|
||||
@@ -111,7 +100,7 @@ public class NdQuadBuilder implements ModelQuadView {
|
||||
/**
|
||||
* Dumps to {@param out} and returns it.
|
||||
*/
|
||||
public Quad build(Quad out) {
|
||||
public QuadView build(QuadView out) {
|
||||
|
||||
// FRAPI does this late, but we need to do it before baking to Nd quads
|
||||
this.computeGeometry();
|
||||
@@ -137,7 +126,7 @@ public class NdQuadBuilder implements ModelQuadView {
|
||||
* Set vertex color in ARGB format (0xAARRGGBB).
|
||||
*/
|
||||
public void color(int vertexIndex, int color) {
|
||||
data[vertexIndex * INTS_PER_VERTEX + COLOR_INDEX] = color;
|
||||
data[vertexIndex * Quad.INTS_PER_VERTEX + Quad.COLOR_INDEX] = color;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -247,18 +236,18 @@ public class NdQuadBuilder implements ModelQuadView {
|
||||
*/
|
||||
public void pos(int vertexIndex, float x, float y, float z) {
|
||||
|
||||
data[vertexIndex * INTS_PER_VERTEX + X_INDEX] = Float.floatToRawIntBits(x);
|
||||
data[vertexIndex * INTS_PER_VERTEX + Y_INDEX] = Float.floatToRawIntBits(y);
|
||||
data[vertexIndex * INTS_PER_VERTEX + Z_INDEX] = Float.floatToRawIntBits(z);
|
||||
data[vertexIndex * Quad.INTS_PER_VERTEX + Quad.X_INDEX] = Float.floatToRawIntBits(x);
|
||||
data[vertexIndex * Quad.INTS_PER_VERTEX + Quad.Y_INDEX] = Float.floatToRawIntBits(y);
|
||||
data[vertexIndex * Quad.INTS_PER_VERTEX + Quad.Z_INDEX] = Float.floatToRawIntBits(z);
|
||||
isGeometryInvalid = true;
|
||||
}
|
||||
|
||||
public Vector3f pos(int vertexIndex) {
|
||||
|
||||
return new Vector3f(
|
||||
Float.intBitsToFloat(data[vertexIndex * INTS_PER_VERTEX + X_INDEX]),
|
||||
Float.intBitsToFloat(data[vertexIndex * INTS_PER_VERTEX + Y_INDEX]),
|
||||
Float.intBitsToFloat(data[vertexIndex * INTS_PER_VERTEX + Z_INDEX])
|
||||
Float.intBitsToFloat(data[vertexIndex * Quad.INTS_PER_VERTEX + Quad.X_INDEX]),
|
||||
Float.intBitsToFloat(data[vertexIndex * Quad.INTS_PER_VERTEX + Quad.Y_INDEX]),
|
||||
Float.intBitsToFloat(data[vertexIndex * Quad.INTS_PER_VERTEX + Quad.Z_INDEX])
|
||||
);
|
||||
}
|
||||
|
||||
@@ -266,7 +255,7 @@ public class NdQuadBuilder implements ModelQuadView {
|
||||
* Convenience: access x, y, z by index 0-2.
|
||||
*/
|
||||
float posByIndex(int vertexIndex, int coordinateIndex) {
|
||||
return Float.intBitsToFloat(data[vertexIndex * INTS_PER_VERTEX + X_INDEX + coordinateIndex]);
|
||||
return Float.intBitsToFloat(data[vertexIndex * Quad.INTS_PER_VERTEX + Quad.X_INDEX + coordinateIndex]);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -365,48 +354,48 @@ public class NdQuadBuilder implements ModelQuadView {
|
||||
*/
|
||||
public void uv(int vertexIndex, float u, float v) {
|
||||
|
||||
data[vertexIndex * INTS_PER_VERTEX + U_INDEX] = Float.floatToRawIntBits(u);
|
||||
data[vertexIndex * INTS_PER_VERTEX + V_INDEX] = Float.floatToRawIntBits(v);
|
||||
data[vertexIndex * Quad.INTS_PER_VERTEX + Quad.U_INDEX] = Float.floatToRawIntBits(u);
|
||||
data[vertexIndex * Quad.INTS_PER_VERTEX + Quad.V_INDEX] = Float.floatToRawIntBits(v);
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getX(int vertexIndex) {
|
||||
return Float.intBitsToFloat(data[vertexIndex * INTS_PER_VERTEX + X_INDEX]);
|
||||
return Float.intBitsToFloat(data[vertexIndex * Quad.INTS_PER_VERTEX + Quad.X_INDEX]);
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getY(int vertexIndex) {
|
||||
return Float.intBitsToFloat(data[vertexIndex * INTS_PER_VERTEX + Y_INDEX]);
|
||||
return Float.intBitsToFloat(data[vertexIndex * Quad.INTS_PER_VERTEX + Quad.Y_INDEX]);
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getZ(int vertexIndex) {
|
||||
return Float.intBitsToFloat(data[vertexIndex * INTS_PER_VERTEX + Z_INDEX]);
|
||||
return Float.intBitsToFloat(data[vertexIndex * Quad.INTS_PER_VERTEX + Quad.Z_INDEX]);
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getTexU(int vertexIndex) {
|
||||
return Float.intBitsToFloat(data[vertexIndex * INTS_PER_VERTEX + U_INDEX]);
|
||||
return Float.intBitsToFloat(data[vertexIndex * Quad.INTS_PER_VERTEX + Quad.U_INDEX]);
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getTexV(int vertexIndex) {
|
||||
return Float.intBitsToFloat(data[vertexIndex * INTS_PER_VERTEX + V_INDEX]);
|
||||
return Float.intBitsToFloat(data[vertexIndex * Quad.INTS_PER_VERTEX + Quad.V_INDEX]);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getColor(int vertexIndex) {
|
||||
return this.data[vertexIndex * INTS_PER_VERTEX + COLOR_INDEX];
|
||||
return this.data[vertexIndex * Quad.INTS_PER_VERTEX + Quad.COLOR_INDEX];
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getNormal(int vertexIndex) {
|
||||
return this.data[vertexIndex * INTS_PER_VERTEX + NORMAL_INDEX];
|
||||
return this.data[vertexIndex * Quad.INTS_PER_VERTEX + Quad.NORMAL_INDEX];
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getLight(int vertexIndex) {
|
||||
return this.data[vertexIndex * INTS_PER_VERTEX + LIGHTMAP_INDEX];
|
||||
return this.data[vertexIndex * Quad.INTS_PER_VERTEX + Quad.LIGHTMAP_INDEX];
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -6,13 +6,13 @@ import com.google.gson.JsonDeserializer;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonParseException;
|
||||
import com.gtnewhorizons.angelica.api.BlockPos;
|
||||
import com.gtnewhorizons.angelica.api.QuadProvider;
|
||||
import com.gtnewhorizons.angelica.api.QuadView;
|
||||
import com.gtnewhorizons.angelica.compat.mojang.Axis;
|
||||
import com.gtnewhorizons.angelica.compat.mojang.BlockPos;
|
||||
import com.gtnewhorizons.angelica.compat.nd.Quad;
|
||||
import me.jellysquid.mods.sodium.client.model.quad.Quad;
|
||||
import com.gtnewhorizons.angelica.models.NdQuadBuilder;
|
||||
import com.gtnewhorizons.angelica.utils.DirUtil;
|
||||
import com.gtnewhorizons.angelica.utils.ObjectPooler;
|
||||
import it.unimi.dsi.fastutil.Function;
|
||||
import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap;
|
||||
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
|
||||
@@ -32,6 +32,7 @@ import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import static com.gtnewhorizons.angelica.utils.JsonUtil.*;
|
||||
import static me.jellysquid.mods.sodium.common.util.DirectionUtil.ALL_DIRECTIONS;
|
||||
@@ -47,9 +48,9 @@ public class JsonModel implements QuadProvider {
|
||||
private final Map<ModelDisplay.Position, ModelDisplay> display;
|
||||
private final Map<String, String> textures;
|
||||
private List<ModelElement> elements;
|
||||
private List<Quad> allQuadStore = new ObjectArrayList<>();
|
||||
private final Map<ForgeDirection, List<Quad>> sidedQuadStore = new Object2ObjectOpenHashMap<>();
|
||||
private static final List<Quad> EMPTY = ObjectImmutableList.of();
|
||||
private List<QuadView> allQuadStore = new ObjectArrayList<>();
|
||||
private final Map<ForgeDirection, List<QuadView>> sidedQuadStore = new Object2ObjectOpenHashMap<>();
|
||||
private static final List<QuadView> EMPTY = ObjectImmutableList.of();
|
||||
|
||||
JsonModel(@Nullable ResourceLocation parentId, boolean useAO, Map<ModelDisplay.Position, ModelDisplay> display, Map<String, String> textures, List<ModelElement> elements) {
|
||||
this.parentId = parentId;
|
||||
@@ -136,7 +137,7 @@ public class JsonModel implements QuadProvider {
|
||||
builder.mat.setAO(this.useAO);
|
||||
|
||||
// Bake and add it
|
||||
final Quad q = builder.build(new Quad());
|
||||
final QuadView q = builder.build(new Quad());
|
||||
this.allQuadStore.add(q);
|
||||
this.sidedQuadStore.computeIfAbsent(f.getCullFace(),
|
||||
o -> new ObjectArrayList<>()).add(q);
|
||||
@@ -147,7 +148,7 @@ public class JsonModel implements QuadProvider {
|
||||
this.allQuadStore = new ObjectImmutableList<>(this.allQuadStore);
|
||||
for (ForgeDirection f : ALL_DIRECTIONS) {
|
||||
|
||||
List<Quad> l = this.sidedQuadStore.computeIfAbsent(f, o -> EMPTY);
|
||||
List<QuadView> l = this.sidedQuadStore.computeIfAbsent(f, o -> EMPTY);
|
||||
if (!l.isEmpty())
|
||||
this.sidedQuadStore.put(f, new ObjectImmutableList<>(l));
|
||||
}
|
||||
@@ -158,19 +159,9 @@ public class JsonModel implements QuadProvider {
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Quad> getQuads(IBlockAccess world, BlockPos pos, Block block, int meta, ForgeDirection dir, Random random, int color, ObjectPooler<Quad> quadPool) {
|
||||
public List<QuadView> getQuads(IBlockAccess world, BlockPos pos, Block block, int meta, ForgeDirection dir, Random random, int color, Supplier<QuadView> quadPool) {
|
||||
|
||||
final List<Quad> src = this.sidedQuadStore.getOrDefault(dir, EMPTY);
|
||||
final List<Quad> ret = new ObjectArrayList<>(src.size());
|
||||
|
||||
//noinspection ForLoopReplaceableByForEach
|
||||
for (int i = 0; i < src.size(); ++i) {
|
||||
final Quad q = quadPool.getInstance();
|
||||
q.copyFrom(src.get(i));
|
||||
ret.add(q);
|
||||
}
|
||||
|
||||
return ret;
|
||||
return this.sidedQuadStore.getOrDefault(dir, EMPTY);
|
||||
}
|
||||
|
||||
public void resolveParents(Function<ResourceLocation, JsonModel> modelLoader) {
|
||||
|
||||
Reference in new issue
Block a user