Fixed Sky renderering for private pockets and simplified sky render. Will need to later on look into overriding sky color when custom biomes are added to pocket schematics to prevent sky from changing.

This commit is contained in:
Waterpicker 2021-11-21 07:29:41 -06:00
parent 1998ba65fc
commit 00d12e9ca3
8 changed files with 174 additions and 169 deletions

View file

@ -0,0 +1,111 @@
package org.dimdev.dimdoors.client;
import java.util.List;
import com.mojang.blaze3d.systems.RenderSystem;
import org.dimdev.dimdoors.listener.pocket.PocketListenerUtil;
import org.dimdev.dimdoors.mixin.client.WorldRendererMixin;
import org.dimdev.dimdoors.world.ModDimensions;
import org.dimdev.dimdoors.world.pocket.type.addon.SkyAddon;
import org.spongepowered.asm.mixin.Unique;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.render.BufferBuilder;
import net.minecraft.client.render.BufferRenderer;
import net.minecraft.client.render.GameRenderer;
import net.minecraft.client.render.Tessellator;
import net.minecraft.client.render.VertexFormat;
import net.minecraft.client.render.VertexFormats;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.client.world.ClientWorld;
import net.minecraft.util.Identifier;
import net.minecraft.util.math.Matrix4f;
import net.minecraft.util.math.Vec3f;
import net.minecraft.util.registry.RegistryKey;
import net.minecraft.world.World;
import net.fabricmc.fabric.api.client.rendering.v1.DimensionRenderingRegistry;
public class DimensionRenderering {
private static final Identifier MOON_RENDER_PATH = new Identifier("dimdoors:textures/other/limbo_moon.png");
private static final Identifier SUN_RENDER_PATH = new Identifier("dimdoors:textures/other/limbo_sun.png");
public static void initClient() {
DimensionRenderingRegistry.CloudRenderer noCloudRenderer = context -> {
};
DimensionRenderingRegistry.registerCloudRenderer(ModDimensions.LIMBO, noCloudRenderer);
DimensionRenderingRegistry.registerCloudRenderer(ModDimensions.DUNGEON, noCloudRenderer);
DimensionRenderingRegistry.registerCloudRenderer(ModDimensions.PERSONAL, noCloudRenderer);
DimensionRenderingRegistry.registerCloudRenderer(ModDimensions.PUBLIC, noCloudRenderer);
DimensionRenderingRegistry.registerSkyRenderer(ModDimensions.LIMBO, context -> renderLimboSky(context.matrixStack()));
DimensionRenderingRegistry.SkyRenderer pocketRenderer = context -> {
ClientWorld world = context.world();
MatrixStack matrices = context.matrixStack();
List<SkyAddon> skyAddons = PocketListenerUtil.applicableAddonsClient(SkyAddon.class, world, context.camera().getBlockPos());
SkyAddon skyAddon = null;
if (skyAddons.size() > 0) {
// There should really only be one of these.
// If anyone needs to use multiple SkyAddons then go ahead and change this.
skyAddon = skyAddons.get(0);
}
if (skyAddon != null) {
RegistryKey<World> key = skyAddon.getWorld();
DimensionRenderingRegistry.SkyRenderer skyRenderer = DimensionRenderingRegistry.getSkyRenderer(key);
if (skyRenderer != null) {
skyRenderer.render(context);
} else {
if (key.equals(World.END)) {
context.gameRenderer().getClient().worldRenderer.renderEndSky(matrices);
} else if (key.equals(ModDimensions.LIMBO)) {
renderLimboSky(matrices);
}
}
}
};
DimensionRenderingRegistry.registerSkyRenderer(ModDimensions.DUNGEON, pocketRenderer);
DimensionRenderingRegistry.registerSkyRenderer(ModDimensions.PERSONAL, pocketRenderer);
DimensionRenderingRegistry.registerSkyRenderer(ModDimensions.PUBLIC, pocketRenderer);
}
private static void renderLimboSky(MatrixStack matrices) {
Matrix4f matrix4f = matrices.peek().getModel();
Tessellator tessellator = Tessellator.getInstance();
BufferBuilder bufferBuilder = tessellator.getBuffer();
RenderSystem.enableBlend();
RenderSystem.defaultBlendFunc();
RenderSystem.depthMask(false);
RenderSystem.setShader(GameRenderer::getPositionTexColorShader);
RenderSystem.setShaderColor(1, 1, 1, 1);
float s = 30.0F;
RenderSystem.setShader(GameRenderer::getPositionTexShader);
RenderSystem.setShaderTexture(0, SUN_RENDER_PATH);
bufferBuilder.begin(VertexFormat.DrawMode.QUADS, VertexFormats.POSITION_TEXTURE);
bufferBuilder.vertex(matrix4f, -s, 100.0F, -s).texture(0.0F, 0.0F).next();
bufferBuilder.vertex(matrix4f, s, 100.0F, -s).texture(1.0F, 0.0F).next();
bufferBuilder.vertex(matrix4f, s, 100.0F, s).texture(1.0F, 1.0F).next();
bufferBuilder.vertex(matrix4f, -s, 100.0F, s).texture(0.0F, 1.0F).next();
bufferBuilder.end();
BufferRenderer.draw(bufferBuilder);
RenderSystem.setShaderTexture(0, MOON_RENDER_PATH);
bufferBuilder.begin(VertexFormat.DrawMode.QUADS, VertexFormats.POSITION_TEXTURE);
bufferBuilder.vertex(matrix4f, -s, -100.0F, -s).texture(0.0F, 0.0F).next();
bufferBuilder.vertex(matrix4f, s, -100.0F, -s).texture(1.0F, 0.0F).next();
bufferBuilder.vertex(matrix4f, s, -100.0F, s).texture(1.0F, 1.0F).next();
bufferBuilder.vertex(matrix4f, -s, -100.0F, s).texture(0.0F, 1.0F).next();
bufferBuilder.end();
BufferRenderer.draw(bufferBuilder);
RenderSystem.depthMask(true);
RenderSystem.enableTexture();
RenderSystem.disableBlend();
}
}

View file

@ -19,6 +19,9 @@ import net.fabricmc.api.ClientModInitializer;
import net.fabricmc.api.EnvType; import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment; import net.fabricmc.api.Environment;
import net.fabricmc.fabric.api.client.rendereregistry.v1.BlockEntityRendererRegistry; import net.fabricmc.fabric.api.client.rendereregistry.v1.BlockEntityRendererRegistry;
import net.fabricmc.fabric.api.client.rendering.v1.DimensionRenderingRegistry;
import net.fabricmc.fabric.api.client.rendering.v1.WorldRenderContext;
import org.dimdev.dimdoors.world.ModDimensions; import org.dimdev.dimdoors.world.ModDimensions;
@Environment(EnvType.CLIENT) @Environment(EnvType.CLIENT)
@ -37,9 +40,9 @@ public class DimensionalDoorsClientInitializer implements ClientModInitializer {
ModEntityModelLayers.initClient(); ModEntityModelLayers.initClient();
ModParticleTypes.initClient(); ModParticleTypes.initClient();
registerListeners(); DimensionRenderering.initClient();
SkyPropertiesAccessor.getIdMap().put(ModDimensions.LIMBO_TYPE_KEY.getValue(), new LimboSkyProperties()); registerListeners();
} }
private void registerListeners() { private void registerListeners() {

View file

@ -0,0 +1,29 @@
package org.dimdev.dimdoors.mixin.client;
import org.dimdev.dimdoors.world.ModDimensions;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.ModifyVariable;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.render.BackgroundRenderer;
import net.minecraft.client.world.ClientWorld;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
@Environment(EnvType.CLIENT)
@Mixin(BackgroundRenderer.class)
public class BackgroundRendererMixin {
@ModifyVariable(
method = "render",
at = @At(value = "STORE", ordinal = 0),
ordinal = 0
)
private static double modifyVoidColor(double scale) {
if(ModDimensions.isPrivatePocketDimension(MinecraftClient.getInstance().world)) {
scale = 1.0;
}
return scale;
}
}

View file

@ -13,8 +13,14 @@ import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.Unique; import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.gen.Accessor;
import org.spongepowered.asm.mixin.gen.Invoker;
import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Constant;
import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.ModifyConstant;
import org.spongepowered.asm.mixin.injection.ModifyVariable;
import org.spongepowered.asm.mixin.injection.Slice;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import net.minecraft.client.MinecraftClient; import net.minecraft.client.MinecraftClient;
@ -35,10 +41,6 @@ import java.util.Map;
@Mixin(WorldRenderer.class) @Mixin(WorldRenderer.class)
@Environment(EnvType.CLIENT) @Environment(EnvType.CLIENT)
public abstract class WorldRendererMixin { public abstract class WorldRendererMixin {
@Unique
private static final Identifier MOON_RENDER_PATH = new Identifier("dimdoors:textures/other/limbo_moon.png");
@Unique
private static final Identifier SUN_RENDER_PATH = new Identifier("dimdoors:textures/other/limbo_sun.png");
@Shadow @Shadow
private ClientWorld world; private ClientWorld world;
@ -53,166 +55,6 @@ public abstract class WorldRendererMixin {
@Shadow @Shadow
private int ticks; private int ticks;
@Shadow
@Final
private static Identifier END_SKY;
@Shadow
protected abstract void renderEndSky(MatrixStack matrices);
@Inject(method = "renderSky", at = @At("HEAD"), cancellable = true)
public void beforeRenderSky(MatrixStack matrices, Matrix4f matrix4f, float f, Runnable runnable, CallbackInfo ci) {
List<SkyAddon> skyAddons = PocketListenerUtil.applicableAddonsClient(SkyAddon.class, this.world, this.client.gameRenderer.getCamera().getBlockPos());
SkyAddon skyAddon = null;
if (skyAddons.size() > 0) {
// There should really only be one of these.
// If anyone needs to use multiple SkyAddons then go ahead and change this.
skyAddon = skyAddons.get(0);
}
if (skyAddon != null) {
RegistryKey<World> world = skyAddon.getWorld();
if (world.equals(World.END)) {
this.renderEndSky(matrices);
ci.cancel();
return;
} else if (world.equals(ModDimensions.LIMBO)) {
this.renderLimboSky(matrices);
ci.cancel();
return;
}
}
if (ModDimensions.isLimboDimension(this.world)) {
renderLimboSky(matrices);
ci.cancel();
} else if (ModDimensions.isPrivatePocketDimension(this.world)) {
this.renderPocketSky(matrices, 255, 255, 255);
ci.cancel();
} else if (ModDimensions.isPocketDimension(this.world)) {
this.renderPocketSky(matrices, 0, 0, 0);
ci.cancel();
}
}
@Inject(method = "renderClouds(Lnet/minecraft/client/util/math/MatrixStack;Lnet/minecraft/util/math/Matrix4f;FDDD)V", at = @At("HEAD"), cancellable = true)
public void beforeRendererCloud(MatrixStack matrices, Matrix4f matrix4f, float f, double d, double e, double g, CallbackInfo ci) {
if (ModDimensions.isLimboDimension(this.world) || ModDimensions.isPrivatePocketDimension(this.world) || ModDimensions.isPocketDimension(this.world)) {
ci.cancel();
}
}
@Unique
private void renderLimboSky(MatrixStack matrices) {
Matrix4f matrix4f = matrices.peek().getModel();
Tessellator tessellator = Tessellator.getInstance();
BufferBuilder bufferBuilder = tessellator.getBuffer();
RenderSystem.enableBlend();
RenderSystem.defaultBlendFunc();
RenderSystem.depthMask(false);
RenderSystem.setShader(GameRenderer::getPositionTexColorShader);
RenderSystem.setShaderColor(1, 1, 1, 1);
for (int i = 0; i < 6; ++i) {
matrices.push();
if (i == 1) {
matrices.multiply(Vec3f.POSITIVE_X.getDegreesQuaternion(90.0F));
}
if (i == 2) {
matrices.multiply(Vec3f.POSITIVE_X.getDegreesQuaternion(-90.0F));
}
if (i == 3) {
matrices.multiply(Vec3f.POSITIVE_X.getDegreesQuaternion(180.0F));
}
if (i == 4) {
matrices.multiply(Vec3f.POSITIVE_Z.getDegreesQuaternion(90.0F));
}
if (i == 5) {
matrices.multiply(Vec3f.POSITIVE_Z.getDegreesQuaternion(-90.0F));
}
bufferBuilder.begin(VertexFormat.DrawMode.QUADS, VertexFormats.POSITION_COLOR);
bufferBuilder.vertex(matrix4f, -100.0F, -100.0F, -100.0F).color(40, 40, 40, 255).next();
bufferBuilder.vertex(matrix4f, -100.0F, -100.0F, 100.0F).color(40, 40, 40, 255).next();
bufferBuilder.vertex(matrix4f, 100.0F, -100.0F, 100.0F).color(40, 40, 40, 255).next();
bufferBuilder.vertex(matrix4f, 100.0F, -100.0F, -100.0F).color(40, 40, 40, 255).next();
tessellator.draw();
matrices.pop();
}
float s = 30.0F;
RenderSystem.setShader(GameRenderer::getPositionTexShader);
RenderSystem.setShaderTexture(0, SUN_RENDER_PATH);
bufferBuilder.begin(VertexFormat.DrawMode.QUADS, VertexFormats.POSITION_TEXTURE);
bufferBuilder.vertex(matrix4f, -s, 100.0F, -s).texture(0.0F, 0.0F).next();
bufferBuilder.vertex(matrix4f, s, 100.0F, -s).texture(1.0F, 0.0F).next();
bufferBuilder.vertex(matrix4f, s, 100.0F, s).texture(1.0F, 1.0F).next();
bufferBuilder.vertex(matrix4f, -s, 100.0F, s).texture(0.0F, 1.0F).next();
bufferBuilder.end();
BufferRenderer.draw(bufferBuilder);
RenderSystem.setShaderTexture(0, MOON_RENDER_PATH);
bufferBuilder.begin(VertexFormat.DrawMode.QUADS, VertexFormats.POSITION_TEXTURE);
bufferBuilder.vertex(matrix4f, -s, -100.0F, -s).texture(0.0F, 0.0F).next();
bufferBuilder.vertex(matrix4f, s, -100.0F, -s).texture(1.0F, 0.0F).next();
bufferBuilder.vertex(matrix4f, s, -100.0F, s).texture(1.0F, 1.0F).next();
bufferBuilder.vertex(matrix4f, -s, -100.0F, s).texture(0.0F, 1.0F).next();
bufferBuilder.end();
BufferRenderer.draw(bufferBuilder);
RenderSystem.depthMask(true);
RenderSystem.enableTexture();
RenderSystem.disableBlend();
}
private void renderPocketSky(MatrixStack matrices, int r, int g, int b) {
RenderSystem.enableBlend();
RenderSystem.defaultBlendFunc();
RenderSystem.depthMask(false);
RenderSystem.setShader(GameRenderer::getPositionColorShader);
Tessellator tessellator = Tessellator.getInstance();
BufferBuilder bufferBuilder = tessellator.getBuffer();
for (int i = 0; i < 6; ++i) {
matrices.push();
if (i == 1) {
matrices.multiply(Vec3f.POSITIVE_X.getDegreesQuaternion(90.0F));
}
if (i == 2) {
matrices.multiply(Vec3f.POSITIVE_X.getDegreesQuaternion(-90.0F));
}
if (i == 3) {
matrices.multiply(Vec3f.POSITIVE_X.getDegreesQuaternion(180.0F));
}
if (i == 4) {
matrices.multiply(Vec3f.POSITIVE_Z.getDegreesQuaternion(90.0F));
}
if (i == 5) {
matrices.multiply(Vec3f.POSITIVE_Z.getDegreesQuaternion(-90.0F));
}
Matrix4f matrix4f = matrices.peek().getModel();
bufferBuilder.begin(VertexFormat.DrawMode.QUADS, VertexFormats.POSITION_COLOR);
bufferBuilder.vertex(matrix4f, -100.0F, -100.0F, -100.0F).color(r, g, b, 255).next();
bufferBuilder.vertex(matrix4f, -100.0F, -100.0F, 100.0F).color(r, g, b, 255).next();
bufferBuilder.vertex(matrix4f, 100.0F, -100.0F, 100.0F).color(r, g, b, 255).next();
bufferBuilder.vertex(matrix4f, 100.0F, -100.0F, -100.0F).color(r, g, b, 255).next();
tessellator.draw();
matrices.pop();
}
RenderSystem.depthMask(true);
RenderSystem.enableTexture();
RenderSystem.disableBlend();
}
@Inject(method = "render(Lnet/minecraft/client/util/math/MatrixStack;FJZLnet/minecraft/client/render/Camera;Lnet/minecraft/client/render/GameRenderer;Lnet/minecraft/client/render/LightmapTextureManager;Lnet/minecraft/util/math/Matrix4f;)V", @Inject(method = "render(Lnet/minecraft/client/util/math/MatrixStack;FJZLnet/minecraft/client/render/Camera;Lnet/minecraft/client/render/GameRenderer;Lnet/minecraft/client/render/LightmapTextureManager;Lnet/minecraft/util/math/Matrix4f;)V",
at = @At(value = "FIELD", target = "Lnet/minecraft/client/render/WorldRenderer;blockBreakingProgressions:Lit/unimi/dsi/fastutil/longs/Long2ObjectMap;", ordinal = 1)) // bytecode order is flipped from java code order, notice the ordinal at = @At(value = "FIELD", target = "Lnet/minecraft/client/render/WorldRenderer;blockBreakingProgressions:Lit/unimi/dsi/fastutil/longs/Long2ObjectMap;", ordinal = 1)) // bytecode order is flipped from java code order, notice the ordinal
public void renderCustomBreakBlockAnimation(MatrixStack matrices, float tickDelta, long limitTime, boolean renderBlockOutline, Camera camera, GameRenderer gameRenderer, LightmapTextureManager lightmapTextureManager, Matrix4f matrix4f, CallbackInfo ci) { public void renderCustomBreakBlockAnimation(MatrixStack matrices, float tickDelta, long limitTime, boolean renderBlockOutline, Camera camera, GameRenderer gameRenderer, LightmapTextureManager lightmapTextureManager, Matrix4f matrix4f, CallbackInfo ci) {
@ -240,4 +82,21 @@ public abstract class WorldRendererMixin {
} }
} }
} }
@ModifyConstant(
method = "renderSky(Lnet/minecraft/client/util/math/MatrixStack;Lnet/minecraft/util/math/Matrix4f;FLjava/lang/Runnable;)V",
constant = @Constant(doubleValue = 0.0, ordinal = 0),
slice = @Slice(
from = @At(
value = "INVOKE",
target = "Lnet/minecraft/client/world/ClientWorld$Properties;getSkyDarknessHeight(Lnet/minecraft/world/HeightLimitView;)D"
)
)
)
private double modifyVoidBackgroundCondition(double zero) {
if(ModDimensions.isPrivatePocketDimension(world)) {
zero = Double.NEGATIVE_INFINITY;
}
return zero;
}
} }

View file

@ -48,8 +48,8 @@ public final class ModBiomes {
BiomeEffects.Builder builder = new BiomeEffects.Builder() BiomeEffects.Builder builder = new BiomeEffects.Builder()
.waterColor(0x3f76e4) .waterColor(0x3f76e4)
.waterFogColor(0x50533) .waterFogColor(0x50533)
.fogColor(white ? 0xFFFFFF : 0xc0d8ff) .fogColor(white ? 0xFFFFFF : 0x000000)
.skyColor(white ? 0xFFFFFF : 0x111111) .skyColor(white ? 0xFFFFFF : 0x000000)
.grassColorModifier(BiomeEffects.GrassColorModifier.NONE); .grassColorModifier(BiomeEffects.GrassColorModifier.NONE);
if (white) { if (white) {
builder.music(new MusicSound(ModSoundEvents.WHITE_VOID, 0, 0, true)); builder.music(new MusicSound(ModSoundEvents.WHITE_VOID, 0, 0, true));

View file

@ -9,7 +9,7 @@
"bed_works" : false, "bed_works" : false,
"respawn_anchor_works": true, "respawn_anchor_works": true,
"has_raids" : false, "has_raids" : false,
"min_y": 0, "min_y": -16,
"height": 256, "height": 256,
"logical_height" : 256, "logical_height" : 256,
"infiniburn": "minecraft:infiniburn_overworld", "infiniburn": "minecraft:infiniburn_overworld",

View file

@ -18,3 +18,5 @@ accessible field net/minecraft/state/State codec Lcom/mojang/seriali
# for lazy pocket gen/ getting all currently loaded chunks # for lazy pocket gen/ getting all currently loaded chunks
accessible method net/minecraft/server/world/ThreadedAnvilChunkStorage entryIterator ()Ljava/lang/Iterable; accessible method net/minecraft/server/world/ThreadedAnvilChunkStorage entryIterator ()Ljava/lang/Iterable;
accessible method net/minecraft/client/render/WorldRenderer renderEndSky (Lnet/minecraft/client/util/math/MatrixStack;)V

View file

@ -38,6 +38,7 @@
"client.InGameHudMixin", "client.InGameHudMixin",
"client.PostProcessShaderMixin", "client.PostProcessShaderMixin",
"client.WorldRendererMixin", "client.WorldRendererMixin",
"client.BackgroundRendererMixin",
"client.accessor.RenderLayerAccessor", "client.accessor.RenderLayerAccessor",
"client.accessor.SkyPropertiesAccessor" "client.accessor.SkyPropertiesAccessor"
], ],