diff --git a/build.gradle b/build.gradle index e406412d..ea488816 100644 --- a/build.gradle +++ b/build.gradle @@ -117,7 +117,7 @@ dependencies { //modRuntimeOnlyMsk("maven.modrinth:modmenu:15.0.0") modCompileOnly("maven.modrinth:iris:1.9.3+1.21.9-fabric") - modRuntimeOnlyMsk("maven.modrinth:iris:1.9.3+1.21.9-fabric") + //modRuntimeOnlyMsk("maven.modrinth:iris:1.9.3+1.21.9-fabric") //modCompileOnly("maven.modrinth:starlight:1.1.3+1.20.4") diff --git a/src/main/java/me/cortex/voxy/client/VoxyClient.java b/src/main/java/me/cortex/voxy/client/VoxyClient.java index b07d2be7..9279963d 100644 --- a/src/main/java/me/cortex/voxy/client/VoxyClient.java +++ b/src/main/java/me/cortex/voxy/client/VoxyClient.java @@ -8,6 +8,8 @@ import me.cortex.voxy.commonImpl.VoxyCommon; import net.fabricmc.api.ClientModInitializer; import net.fabricmc.fabric.api.client.command.v2.ClientCommandRegistrationCallback; import net.fabricmc.loader.api.FabricLoader; +import net.minecraft.client.gui.hud.debug.DebugHudEntries; +import net.minecraft.util.Identifier; import java.util.HashSet; import java.util.function.Consumer; @@ -16,7 +18,6 @@ import java.util.function.Function; public class VoxyClient implements ClientModInitializer { private static final HashSet FREX = new HashSet<>(); - public static void initVoxyClient() { Capabilities.init();//Ensure clinit is called @@ -39,6 +40,7 @@ public class VoxyClient implements ClientModInitializer { @Override public void onInitializeClient() { + DebugHudEntries.register(Identifier.of("voxy","debug"), new VoxyDebugScreenEntry()); ClientCommandRegistrationCallback.EVENT.register((dispatcher, registryAccess) -> { if (VoxyCommon.isAvailable()) { dispatcher.register(VoxyCommands.register()); diff --git a/src/main/java/me/cortex/voxy/client/VoxyDebugScreenEntry.java b/src/main/java/me/cortex/voxy/client/VoxyDebugScreenEntry.java new file mode 100644 index 00000000..9cef5dd1 --- /dev/null +++ b/src/main/java/me/cortex/voxy/client/VoxyDebugScreenEntry.java @@ -0,0 +1,51 @@ +package me.cortex.voxy.client; + +import me.cortex.voxy.client.core.IGetVoxyRenderSystem; +import me.cortex.voxy.client.core.VoxyRenderSystem; +import me.cortex.voxy.commonImpl.VoxyCommon; +import net.minecraft.client.MinecraftClient; +import net.minecraft.client.gui.hud.debug.DebugHudEntry; +import net.minecraft.client.gui.hud.debug.DebugHudLines; +import net.minecraft.util.Colors; +import net.minecraft.util.Formatting; +import net.minecraft.util.Identifier; +import net.minecraft.world.World; +import net.minecraft.world.chunk.WorldChunk; +import org.jetbrains.annotations.Nullable; + +import java.util.ArrayList; +import java.util.List; + +public class VoxyDebugScreenEntry implements DebugHudEntry { + @Override + public void render(DebugHudLines lines, @Nullable World world, @Nullable WorldChunk clientChunk, @Nullable WorldChunk chunk) { + if (!VoxyCommon.isAvailable()) { + lines.addLine(Formatting.RED + "voxy-"+VoxyCommon.MOD_VERSION);//Voxy installed, not avalible + return; + } + var instance = VoxyCommon.getInstance(); + if (instance == null) { + lines.addLine(Formatting.YELLOW + "voxy-" + VoxyCommon.MOD_VERSION);//Voxy avalible, no instance active + return; + } + VoxyRenderSystem vrs = null; + var wr = MinecraftClient.getInstance().worldRenderer; + if (wr != null) vrs = ((IGetVoxyRenderSystem) wr).getVoxyRenderSystem(); + + //Voxy instance active + lines.addLine((vrs==null?Formatting.DARK_GREEN:Formatting.GREEN)+"voxy-"+VoxyCommon.MOD_VERSION); + + //lines.addLineToSection(); + List instanceLines = new ArrayList<>(); + instance.addDebug(instanceLines); + lines.addLinesToSection(Identifier.of("voxy", "instance_debug"), instanceLines); + + if (vrs != null) { + List renderLines = new ArrayList<>(); + vrs.addDebugInfo(renderLines); + lines.addLinesToSection(Identifier.of("voxy", "render_debug"), renderLines); + } + } + + +} diff --git a/src/main/java/me/cortex/voxy/client/core/VoxyRenderSystem.java b/src/main/java/me/cortex/voxy/client/core/VoxyRenderSystem.java index 6d410bba..704fa47c 100644 --- a/src/main/java/me/cortex/voxy/client/core/VoxyRenderSystem.java +++ b/src/main/java/me/cortex/voxy/client/core/VoxyRenderSystem.java @@ -148,6 +148,12 @@ public class VoxyRenderSystem { for (int i = 0; i < oldBufferBindings.length; i++) { glBindBufferBase(GL_SHADER_STORAGE_BUFFER, i, oldBufferBindings[i]); } + + for (int i = 0; i < 12; i++) { + GlStateManager._activeTexture(GlConst.GL_TEXTURE0+i); + GlStateManager._bindTexture(0); + glBindSampler(i, 0); + } } diff --git a/src/main/java/me/cortex/voxy/client/core/rendering/section/MDICSectionRenderer.java b/src/main/java/me/cortex/voxy/client/core/rendering/section/MDICSectionRenderer.java index 5409f7e0..34df90f4 100644 --- a/src/main/java/me/cortex/voxy/client/core/rendering/section/MDICSectionRenderer.java +++ b/src/main/java/me/cortex/voxy/client/core/rendering/section/MDICSectionRenderer.java @@ -17,6 +17,7 @@ import me.cortex.voxy.client.core.rendering.util.SharedIndexBuffer; import me.cortex.voxy.client.core.rendering.util.UploadStream; import me.cortex.voxy.common.Logger; import me.cortex.voxy.common.world.WorldEngine; +import net.minecraft.client.MinecraftClient; import org.joml.Matrix4f; import org.lwjgl.system.MemoryUtil; @@ -102,6 +103,9 @@ public class MDICSectionRenderer extends AbstractSectionRenderer> cir) { - var ret = cir.getReturnValue(); - var instance = VoxyCommon.getInstance(); - if (instance != null) { - ret.add(""); - ret.add(""); - instance.addDebug(ret); - } - var renderer = ((IGetVoxyRenderSystem) MinecraftClient.getInstance().worldRenderer).getVoxyRenderSystem(); - if (renderer != null) { - renderer.addDebugInfo(ret); - } - }*/ -} diff --git a/src/main/java/me/cortex/voxy/common/world/other/Mapper.java b/src/main/java/me/cortex/voxy/common/world/other/Mapper.java index d7d00cf3..c10ec599 100644 --- a/src/main/java/me/cortex/voxy/common/world/other/Mapper.java +++ b/src/main/java/me/cortex/voxy/common/world/other/Mapper.java @@ -1,12 +1,16 @@ package me.cortex.voxy.common.world.other; +import com.mojang.serialization.Dynamic; import it.unimi.dsi.fastutil.objects.ObjectArrayList; import me.cortex.voxy.common.Logger; import me.cortex.voxy.common.config.IMappingStorage; +import net.minecraft.SharedConstants; import net.minecraft.block.Block; import net.minecraft.block.BlockState; import net.minecraft.block.Blocks; import net.minecraft.block.LeavesBlock; +import net.minecraft.datafixer.Schemas; +import net.minecraft.datafixer.TypeReferences; import net.minecraft.nbt.NbtCompound; import net.minecraft.nbt.NbtIo; import net.minecraft.nbt.NbtOps; @@ -95,26 +99,31 @@ public class Mapper { } private void loadFromStorage() { + //TODO: FIXME: have/store the minecraft version the mappings are from (the data version) + // SharedConstants.getGameVersion().dataVersion().id() + // then use this to create an update path instead + var mappings = this.storage.getIdMappingsData(); List sentries = new ArrayList<>(); List bentries = new ArrayList<>(); List> sentryErrors = new ArrayList<>(); - + boolean[] forceResave = new boolean[1]; for (var entry : mappings.int2ObjectEntrySet()) { int entryType = entry.getIntKey()>>>30; int id = entry.getIntKey() & ((1<<30)-1); if (entryType == BLOCK_STATE_TYPE) { - var sentry = StateEntry.deserialize(id, entry.getValue()); + var sentry = StateEntry.deserialize(id, entry.getValue(), forceResave); if (sentry.state.isAir()) { Logger.error("Deserialization was air, removed block"); sentryErrors.add(new Pair<>(entry.getValue(), id)); continue; } sentries.add(sentry); - var oldEntry = this.block2stateEntry.put(sentry.state, sentry); + var oldEntry = this.block2stateEntry.putIfAbsent(sentry.state, sentry); if (oldEntry != null) { - throw new IllegalStateException("Multiple mappings for blockstate"); + //forceResave[0] |= true; + Logger.warn("Multiple mappings for blockstate, using old state, expect things to possibly go really badly. " + oldEntry.id + ":" + sentry.id + ":" + sentry.state ); } } else if (entryType == BIOME_TYPE) { var bentry = BiomeEntry.deserialize(id, entry.getValue()); @@ -127,7 +136,8 @@ public class Mapper { } } - { + if (!sentryErrors.isEmpty()) { + forceResave[0] |= true; //Insert garbage types into the mapping for those blocks, TODO:FIXME: Need to upgrade the type or have a solution to error blocks var rand = new Random(); for (var error : sentryErrors) { @@ -156,6 +166,10 @@ public class Mapper { this.biomeId2biomeEntry.add(entry); }); + if (forceResave[0]) { + Logger.warn("Forced state resave triggered"); + this.forceResaveStates(); + } } public final int getBlockStateCount() { @@ -357,16 +371,26 @@ public class Mapper { } } - public static StateEntry deserialize(int id, byte[] data) { + public static StateEntry deserialize(int id, byte[] data, boolean[] forceResave) { try { var compound = NbtIo.readCompressed(new ByteArrayInputStream(data), NbtSizeTracker.ofUnlimitedBytes()); if (compound.getInt("id", -1) != id) { throw new IllegalStateException("Encoded id != expected id"); } - var state = BlockState.CODEC.parse(NbtOps.INSTANCE, compound.getCompound("block_state").orElseThrow()); + var bsc = compound.getCompound("block_state").orElseThrow(); + var state = BlockState.CODEC.parse(NbtOps.INSTANCE, bsc); if (state.isError()) { - Logger.error("Could not decode blockstate setting to air. id:" + id + " error: " + state.error().get().message()); - return new StateEntry(id, Blocks.AIR.getDefaultState()); + Logger.info("Could not decode blockstate, attempting fixes, error: "+ state.error().get().message()); + bsc = (NbtCompound) Schemas.getFixer().update(TypeReferences.BLOCK_STATE, new Dynamic<>(NbtOps.INSTANCE,bsc),0, SharedConstants.getGameVersion().dataVersion().id()).getValue(); + state = BlockState.CODEC.parse(NbtOps.INSTANCE, bsc); + if (state.isError()) { + Logger.error("Could not decode blockstate setting to air. id:" + id + " error: " + state.error().get().message()); + return new StateEntry(id, Blocks.AIR.getDefaultState()); + } else { + Logger.info("Fixed blockstate to: " + state.getOrThrow()); + forceResave[0] |= true; + return new StateEntry(id, state.getOrThrow()); + } } else { return new StateEntry(id, state.getOrThrow()); } diff --git a/src/main/java/me/cortex/voxy/commonImpl/VoxyInstance.java b/src/main/java/me/cortex/voxy/commonImpl/VoxyInstance.java index b8fed1b3..679b16e9 100644 --- a/src/main/java/me/cortex/voxy/commonImpl/VoxyInstance.java +++ b/src/main/java/me/cortex/voxy/commonImpl/VoxyInstance.java @@ -183,7 +183,6 @@ public abstract class VoxyInstance { } public void addDebug(List debug) { - debug.add("Voxy Core: " + VoxyCommon.MOD_VERSION); debug.add("MemoryBuffer, Count/Size (mb): " + MemoryBuffer.getCount() + "/" + (MemoryBuffer.getTotalSize()/1_000_000)); debug.add("I/S/AWSC: " + this.ingestService.getTaskCount() + "/" + this.savingService.getTaskCount() + "/[" + this.activeWorlds.values().stream().map(a->""+a.getActiveSectionCount()).collect(Collectors.joining(", ")) + "]");//Active world section count } diff --git a/src/main/resources/assets/voxy/shaders/lod/gl46/quads2.vert b/src/main/resources/assets/voxy/shaders/lod/gl46/quads2.vert index 2b0df07c..33580366 100644 --- a/src/main/resources/assets/voxy/shaders/lod/gl46/quads2.vert +++ b/src/main/resources/assets/voxy/shaders/lod/gl46/quads2.vert @@ -167,6 +167,21 @@ void main() { } //Apply face tint + #ifdef DARKENED_TINTING + if (isShaded) { + //TODO: make branchless, infact apply ahead of time to the texture itself in ModelManager since that is + // per face + if ((face>>1) == 1) {//NORTH, SOUTH + tinting.xyz *= 0.8f; + } else if ((face>>1) == 2) {//EAST, WEST + tinting.xyz *= 0.6f; + } else {//UP DOWN + tinting.xyz *= 0.9f; + } + } else { + tinting.xyz *= 0.9f; + } + #else if (isShaded) { //TODO: make branchless, infact apply ahead of time to the texture itself in ModelManager since that is // per face @@ -178,6 +193,7 @@ void main() { tinting.xyz *= 0.5f; } } + #endif setTintingAndExtra(tinting, conditionalTinting, addin|(face<<8)); #else diff --git a/src/main/resources/client.voxy.mixins.json b/src/main/resources/client.voxy.mixins.json index c354077b..c1bf8506 100644 --- a/src/main/resources/client.voxy.mixins.json +++ b/src/main/resources/client.voxy.mixins.json @@ -20,7 +20,6 @@ "minecraft.MixinClientChunkManager", "minecraft.MixinClientCommonNetworkHandler", "minecraft.MixinClientLoginNetworkHandler", - "minecraft.MixinDebugHud", "minecraft.MixinFogRenderer", "minecraft.MixinGlDebug", "minecraft.MixinMinecraftClient",