Skip to content

Commit

Permalink
switch to mojang mappings
Browse files Browse the repository at this point in the history
  • Loading branch information
Rogo committed Apr 9, 2024
1 parent 3555b10 commit 8fae8d3
Show file tree
Hide file tree
Showing 47 changed files with 855 additions and 688 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ repositories {
dependencies {
// To change the versions see the gradle.properties file
minecraft "com.mojang:minecraft:${project.minecraft_version}"
mappings "net.fabricmc:yarn:${project.yarn_mappings}:v2"
mappings loom.officialMojangMappings()
modImplementation "net.fabricmc:fabric-loader:${project.loader_version}"

// Fabric API. This is technically optional, but you probably want it anyway.
Expand Down
14 changes: 7 additions & 7 deletions src/main/java/rogo/renderingculling/api/ChunkCullingMap.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package rogo.renderingculling.api;

import net.minecraft.client.MinecraftClient;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3d;
import net.minecraft.client.Minecraft;
import net.minecraft.core.BlockPos;
import net.minecraft.world.phys.Vec3;
import rogo.renderingculling.util.Vec2i;

import java.util.HashMap;
Expand All @@ -21,11 +21,11 @@ int delayCount() {

@Override
int bindFrameBufferId() {
return CullingHandler.CHUNK_CULLING_MAP_TARGET.fbo;
return CullingHandler.CHUNK_CULLING_MAP_TARGET.frameBufferId;
}

public int getPosIndex(BlockPos pos) {
int renderDistance = MinecraftClient.getInstance().options.getViewDistance();
int renderDistance = Minecraft.getInstance().options.getEffectiveRenderDistance();
int spacePartitionSize = 2 * renderDistance + 1;
int x = pos.getX() + renderDistance;
int z = pos.getZ() + renderDistance;
Expand Down Expand Up @@ -56,7 +56,7 @@ public void generateIndex(int renderDistance) {
}

public boolean isChunkVisible(BlockPos pos) {
Vec3d camera = MinecraftClient.getInstance().gameRenderer.getCamera().getPos();
Vec3 camera = Minecraft.getInstance().gameRenderer.getMainCamera().getPosition();
int cameraX = (int)camera.x >> 4;
int cameraY = (int)camera.y/16;
int cameraZ = (int)camera.z >> 4;
Expand All @@ -68,7 +68,7 @@ public boolean isChunkVisible(BlockPos pos) {
int chunkX = pos.getX() >> 4;
int chunkY = pos.getY()/16 + CullingHandler.LEVEL_MIN_SECTION_ABS;
int chunkZ = pos.getZ() >> 4;
pos = new BlockPos(chunkX, chunkY, chunkZ).subtract(cameraPos).withY(chunkY);
pos = new BlockPos(chunkX, chunkY, chunkZ).subtract(cameraPos).atY(chunkY);

if(screenIndex.containsKey(pos)) {
Integer index = screenIndex.get(pos);
Expand Down
93 changes: 68 additions & 25 deletions src/main/java/rogo/renderingculling/api/Config.java
Original file line number Diff line number Diff line change
@@ -1,22 +1,44 @@
package rogo.renderingculling.api;

import io.github.fablabsmc.fablabs.api.fiber.v1.FiberId;
import io.github.fablabsmc.fablabs.api.fiber.v1.exception.ValueDeserializationException;
import io.github.fablabsmc.fablabs.api.fiber.v1.schema.type.derived.ConfigTypes;
import io.github.fablabsmc.fablabs.api.fiber.v1.serialization.FiberSerialization;
import io.github.fablabsmc.fablabs.api.fiber.v1.serialization.JanksonValueSerializer;
import io.github.fablabsmc.fablabs.api.fiber.v1.tree.ConfigBranch;
import io.github.fablabsmc.fablabs.api.fiber.v1.tree.ConfigTree;
import io.github.fablabsmc.fablabs.api.fiber.v1.tree.PropertyMirror;
import net.minecraft.network.chat.TranslatableComponent;

import java.io.*;
import java.nio.file.*;
import java.util.ArrayList;
import java.util.List;

public class Config {
public static PropertyMirror<Double> SAMPLING = PropertyMirror.create(ConfigTypes.DOUBLE);
public static PropertyMirror<Boolean> CULL_ENTITY = PropertyMirror.create(ConfigTypes.BOOLEAN);
public static PropertyMirror<Boolean> CULL_CHUNK = PropertyMirror.create(ConfigTypes.BOOLEAN);
public static PropertyMirror<Integer> UPDATE_DELAY = PropertyMirror.create(ConfigTypes.INTEGER);
public static PropertyMirror<Integer> CULLING_ENTITY_RATE = PropertyMirror.create(ConfigTypes.INTEGER);
private static PropertyMirror<Double> SAMPLING = PropertyMirror.create(ConfigTypes.DOUBLE);
public static double getSampling() {
return SAMPLING.getValue();
}
private static PropertyMirror<Boolean> CULL_ENTITY = PropertyMirror.create(ConfigTypes.BOOLEAN);
private static PropertyMirror<Boolean> CULL_CHUNK = PropertyMirror.create(ConfigTypes.BOOLEAN);
private static PropertyMirror<Integer> UPDATE_DELAY = PropertyMirror.create(ConfigTypes.INTEGER);
private static PropertyMirror<Integer> CULLING_ENTITY_RATE = PropertyMirror.create(ConfigTypes.INTEGER);

private static PropertyMirror<List<String>> ENTITY_SKIP = PropertyMirror.create(ConfigTypes.makeList(ConfigTypes.STRING));
private static PropertyMirror<List<String>> BLOCK_ENTITY_SKIP = PropertyMirror.create(ConfigTypes.makeList(ConfigTypes.STRING));

public static PropertyMirror<List<String>> ENTITY_SKIP = PropertyMirror.create(ConfigTypes.makeList(ConfigTypes.STRING));
public static PropertyMirror<List<String>> BLOCK_ENTITY_SKIP = PropertyMirror.create(ConfigTypes.makeList(ConfigTypes.STRING));
private static ConfigContext CONTEXT;
private static ConfigBranch BRANCH;
private static String getTranslatedItem(String s) {
String Translated = new TranslatableComponent(s).getString();
return Translated;
}

public static void save() {
if(CONTEXT != null) {
writeConfig(CONTEXT);
}
}

public static void init() {
List<String> entityList = new ArrayList<>();
Expand All @@ -25,38 +47,59 @@ public static void init() {
List<String> blockList = new ArrayList<>();
blockList.add("minecraft:beacon");

ConfigTree.builder()
.withValue("Sampling multiple", ConfigTypes.DOUBLE.withValidRange(0.0, 1.0, 0.01), 0.2)
.beginValue("multiple", ConfigTypes.DOUBLE, 0.2)
BRANCH = ConfigTree.builder()
.beginValue(getTranslatedItem("brute_force_rendering_culling.sampler"), ConfigTypes.DOUBLE.withValidRange(0.0, 1.0, 0.01), 0.2)
.finishValue(SAMPLING::mirror)

.withValue("Culling Map update delay", ConfigTypes.INTEGER.withValidRange(0, 10, 1), 1)
.beginValue("delay frame", ConfigTypes.INTEGER, 1)
.beginValue(getTranslatedItem("brute_force_rendering_culling.culling_map_update_delay"), ConfigTypes.INTEGER, 1)
.finishValue(UPDATE_DELAY::mirror)

.withValue("Cull entity", ConfigTypes.BOOLEAN, true)
.beginValue("enable cull entity", ConfigTypes.BOOLEAN, true)
.beginValue(getTranslatedItem("brute_force_rendering_culling.cull_entity"), ConfigTypes.BOOLEAN, true)
.finishValue(CULL_ENTITY::mirror)

.withValue("Cull chunk", ConfigTypes.BOOLEAN, true)
.beginValue("enable cull chunk", ConfigTypes.BOOLEAN, true)
.beginValue(getTranslatedItem("brute_force_rendering_culling.cull_chunk"), ConfigTypes.BOOLEAN, true)
.finishValue(CULL_CHUNK::mirror)

.withValue("Culling entity update frequency", ConfigTypes.INTEGER.withValidRange(0, 20, 1), 20)
.beginValue("frequency", ConfigTypes.INTEGER, 20)
.beginValue(getTranslatedItem("brute_force_rendering_culling.culling_entity_update_rate"), ConfigTypes.INTEGER, 20)
.finishValue(CULLING_ENTITY_RATE::mirror)

.withValue("Entity skip CULLING", ConfigTypes.makeList(ConfigTypes.STRING), entityList)
.withComment("Entity that skip CULLING, example: \n" +
.beginValue(getTranslatedItem("brute_force_rendering_culling.skip_culling_entities"), ConfigTypes.makeList(ConfigTypes.STRING), entityList)
.withComment("Example: \n" +
"[\"minecraft:creeper\", \"minecraft:zombie\"]")
.beginValue("Entity ResourceLocation", ConfigTypes.makeList(ConfigTypes.STRING), entityList)
.finishValue(ENTITY_SKIP::mirror)

.withValue("Block Entity skip CULLING", ConfigTypes.makeList(ConfigTypes.STRING), blockList)
.withComment("Block Entity that skip CULLING, example: \n" +
.beginValue(getTranslatedItem("brute_force_rendering_culling.skip_culling_block_entities"), ConfigTypes.makeList(ConfigTypes.STRING), blockList)
.withComment("Example: \n" +
"[\"minecraft:chest\", \"minecraft:mob_spawner\"]")
.beginValue("Block Entity ResourceLocation", ConfigTypes.makeList(ConfigTypes.STRING), blockList)
.finishValue(BLOCK_ENTITY_SKIP::mirror)
.build();
}

public static void loadConfig() {
try {
Files.createDirectory(Paths.get("config"));
} catch (IOException ignored) {
}
JanksonValueSerializer serializer = new JanksonValueSerializer(false);
CONTEXT = new ConfigContext(BRANCH, Paths.get("config", CullingHandler.MOD_ID + ".json"), serializer);
setupConfig(CONTEXT);
}

private static void writeConfig(ConfigContext context) {
try (OutputStream s = new BufferedOutputStream(Files.newOutputStream(context.path, StandardOpenOption.WRITE, StandardOpenOption.CREATE_NEW))) {
FiberSerialization.serialize(context.config, s, context.serializer);
} catch (IOException ignored) {
}
}

private static void setupConfig(ConfigContext context) {
writeConfig(context);

try (InputStream s = new BufferedInputStream(Files.newInputStream(context.path, StandardOpenOption.READ, StandardOpenOption.CREATE))) {
FiberSerialization.deserialize(context.config, s, context.serializer);
} catch (IOException | ValueDeserializationException ignored) {
}
}

public record ConfigContext(ConfigTree config, Path path, JanksonValueSerializer serializer){}
}
Loading

0 comments on commit 8fae8d3

Please sign in to comment.