Skip to content

Commit

Permalink
Cleanup of the rendering code.
Browse files Browse the repository at this point in the history
  • Loading branch information
marchermans committed Dec 19, 2021
1 parent 280b1e1 commit 8d5bdb0
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class ChiselsAndBitsBakedQuad extends BakedQuad
public static final ConcurrentHashMap<VertexFormat, FormatInfo> formatData = new ConcurrentHashMap<>();

private static int[] packData(
float[][][] unpackedData)
float[][][] unpackedData, final Direction orientation)
{
FormatInfo fi = formatData.get(DefaultVertexFormat.BLOCK);

Expand All @@ -27,7 +27,7 @@ private static int[] packData(
formatData.put(DefaultVertexFormat.BLOCK, fi);
}

return fi.pack(unpackedData);
return fi.pack(unpackedData, orientation);
}

private static float[] getRawPart(
Expand Down Expand Up @@ -59,7 +59,7 @@ public ChiselsAndBitsBakedQuad(
final Direction orientation,
final TextureAtlasSprite sprite)
{
super(buildProcessedVertexData(packData(unpackedData)), tint, orientation, sprite, true);
super(buildProcessedVertexData(packData(unpackedData, orientation)), tint, orientation, sprite, false);
}

public static class Builder implements IVertexConsumer, IFaceBuilder
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@

import java.util.*;

import static net.minecraft.core.Direction.*;
import static net.minecraft.core.Direction.EAST;

public final class FaceManager {
private static final Random RANDOM = new Random();

Expand All @@ -43,6 +46,7 @@ public final class FaceManager {
() -> IPlatformRegistryManager.getInstance().getBlockStateIdMap().size() == 0 ? 1000 : IPlatformRegistryManager.getInstance().getBlockStateIdMap().size()
);


private FaceManager() {
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,24 @@
package mod.chiselsandbits.client.model.baked.face;

import com.mojang.blaze3d.vertex.VertexFormat;
import net.minecraft.core.Direction;

import static net.minecraft.core.Direction.*;
import static net.minecraft.core.Direction.EAST;

public class FormatInfo
{

private static final int[][] VERTEX_ORDER_MAP = new int[6][4];
static {
VERTEX_ORDER_MAP[DOWN.get3DDataValue()] = new int[] { 0, 1, 2, 3 };
VERTEX_ORDER_MAP[UP.get3DDataValue()] = new int[] { 2, 3, 0, 1 };
VERTEX_ORDER_MAP[NORTH.get3DDataValue()] = new int[] { 3, 0, 1, 2 };
VERTEX_ORDER_MAP[SOUTH.get3DDataValue()] = new int[] { 0, 1, 2, 3 };
VERTEX_ORDER_MAP[WEST.get3DDataValue()] = new int[] { 3, 0, 1, 2 };
VERTEX_ORDER_MAP[EAST.get3DDataValue()] = new int[] { 1, 2, 3, 0 };
}

final int totalSize;
final int faceSize;

Expand Down Expand Up @@ -40,17 +55,20 @@ public FormatInfo(
}

public int[] pack(
float[][][] unpackedData )
float[][][] unpackedData, final Direction orientation)
{
int[] out = new int[this.faceSize];

final int[] orderedFaceIndexes = VERTEX_ORDER_MAP[orientation.get3DDataValue()];

int offset = 0;
for ( int f = 0; f < 4; ++f )
for ( int faceIndex = 0; faceIndex < 4; ++faceIndex )
{
float[][] run2 = unpackedData[f];
final int orderedFaceIndex = orderedFaceIndexes[faceIndex];
float[][] unpackedFaceData = unpackedData[orderedFaceIndex];
for ( int x = 0; x < indexLengths.length; ++x )
{
float[] run = run2[x];
float[] run = unpackedFaceData[x];
for ( int z = 0; z < indexLengths[x]; z++ )
{
if ( run.length > z )
Expand Down
4 changes: 2 additions & 2 deletions Platforms/Fabric/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,13 @@ loom {
client()
setConfigName("Fabric Client")
ideConfigGenerated(true)
runDir(project.file("run").toPath().relativize(project.file("/").toPath()).toString())
runDir(project.rootProject.projectDir.toPath().relativize(project(":Platforms:Fabric").file("run").toPath()).toString())
}
server {
server()
setConfigName("Fabric Server")
ideConfigGenerated(true)
runDir(project.file("run").toPath().relativize(project.file("/").toPath()).toString())
runDir(project.rootProject.projectDir.toPath().relativize(project(":Platforms:Fabric").file("run").toPath()).toString())
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import net.fabricmc.fabric.api.networking.v1.PacketSender;
import net.fabricmc.fabric.api.networking.v1.ServerPlayConnectionEvents;
import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking;
import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.client.Minecraft;
import net.minecraft.client.multiplayer.ClientPacketListener;
import net.minecraft.network.FriendlyByteBuf;
Expand All @@ -22,10 +23,7 @@
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.server.network.ServerGamePacketListenerImpl;

import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.*;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.List;
Expand Down Expand Up @@ -122,7 +120,8 @@ public IConfigurationBuilder createBuilder(
private JsonObject loadLocalConfig(final String name) {
try
{
final Path configPath = Path.of("./", "configs", name + ".json");
final File configurationDirectory = FabricLoader.getInstance().getConfigDirectory();
final Path configPath = Path.of(configurationDirectory.getAbsolutePath(), name + ".json");

final FileReader fileReader = new FileReader(configPath.toAbsolutePath().toFile().getAbsolutePath());

Expand All @@ -141,15 +140,17 @@ private JsonObject loadLocalConfig(final String name) {
}

private boolean doesLocalConfigExist(final String name) {
final Path configPath = Path.of("./", "configs", name + ".json");
final File configurationDirectory = FabricLoader.getInstance().getConfigDirectory();
final Path configPath = Path.of(configurationDirectory.getAbsolutePath(), name + ".json");
return Files.exists(configPath);
}

@SuppressWarnings("ResultOfMethodCallIgnored")
private void saveLocalConfig(final String name, final JsonObject config) {
try
{
final Path configPath = Path.of("./", "configs", name + ".json");
final File configurationDirectory = FabricLoader.getInstance().getConfigDirectory();
final Path configPath = Path.of(configurationDirectory.getAbsolutePath(), name + ".json");
if (Files.exists(configPath))
Files.delete(configPath);

Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.1.1-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.2-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists

0 comments on commit 8d5bdb0

Please sign in to comment.