Skip to content
Open
Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 2 additions & 33 deletions src/main/java/twilightforest/client/TwilightForestRenderInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,17 @@
import net.minecraft.client.Camera;
import net.minecraft.client.Minecraft;
import net.minecraft.client.multiplayer.ClientLevel;
import net.minecraft.client.renderer.DimensionSpecialEffects;
import net.minecraft.client.renderer.LightTexture;
import net.minecraft.client.renderer.MultiBufferSource;
import net.minecraft.client.renderer.state.level.LevelRenderState;
import net.minecraft.client.renderer.state.level.SkyRenderState;
import net.minecraft.client.renderer.state.level.WeatherRenderState;
import net.minecraft.resources.ResourceKey;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.level.biome.Biome;
import net.minecraft.world.phys.Vec3;
import net.neoforged.neoforge.client.CustomSkyboxRenderer;
import net.neoforged.neoforge.client.CustomWeatherEffectRenderer;
import org.jetbrains.annotations.Nullable;
import org.joml.Matrix4f;
import org.joml.Matrix4fc;
import twilightforest.client.renderer.TFSkyRenderer;
import twilightforest.client.renderer.TFWeatherRenderer;
import twilightforest.init.TFBiomes;

import java.util.Optional;

public class TwilightForestRenderInfo implements CustomSkyboxRenderer, CustomWeatherEffectRenderer {

Expand All @@ -42,28 +33,6 @@ public class TwilightForestRenderInfo implements CustomSkyboxRenderer, CustomWea
// return biomeFogColor.multiply(daylight * 0.94F + 0.06F, (daylight * 0.94F + 0.06F), (daylight * 0.91F + 0.09F));
// }

@Override
public boolean isFoggyAt(int x, int y) { // true = nearFog

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm assuming this is getting moved to the new effect system

Player player = Minecraft.getInstance().player;

if (player != null) {
Optional<ResourceKey<Biome>> biome = player.level().getBiome(player.blockPosition()).unwrapKey();
if (biome.isPresent()) {
boolean spooky = biome.get() == TFBiomes.SPOOKY_FOREST;

if (player.position().y > 20 && !spooky) {
return false; // If player is above the dark forest then no need to make it so spooky. The darkwood leaves cover everything as low as y42.
}

return spooky || biome.get() == TFBiomes.DARK_FOREST || biome.get() == TFBiomes.DARK_FOREST_CENTER;
}
}

return false;

//Make the fog on these biomes much much darker, maybe pitch black even. Do we keep this harsher fog underground too?
}

@Override
public boolean renderSky(LevelRenderState levelRenderState, SkyRenderState skyRenderState, Matrix4fc modelViewMatrix, Runnable setupFog) {
if (this.skyRenderer == null) {
Expand All @@ -74,11 +43,11 @@ public boolean renderSky(LevelRenderState levelRenderState, SkyRenderState skyRe

@Override
public boolean renderSnowAndRain(LevelRenderState levelRenderState, WeatherRenderState weatherRenderState, MultiBufferSource bufferSource, Vec3 camPos) {
return TFWeatherRenderer.renderSnowAndRain(level, ticks, partialTick, lightTexture, new Vec3(camX, camY, camZ));
return TFWeatherRenderer.renderSnowAndRain(Minecraft.getInstance().level, Minecraft.getInstance().levelRenderer.getTicks(), Minecraft.getInstance().getDeltaTracker().getGameTimeDeltaTicks(), camPos, bufferSource);
}

@Override
public boolean tickRain(ClientLevel level, int ticks, Camera camera) {
return TFWeatherRenderer.tickRain(level, ticks, camera.getBlockPosition());
return TFWeatherRenderer.tickRain(level, ticks, camera.blockPosition());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,20 @@
import net.minecraft.client.renderer.RenderPipelines;
import twilightforest.TwilightForestMod;

import java.util.Optional;

public class TFRenderPipelines {

private static final BlendFunction SHADOW = new BlendFunction(SourceFactor.SRC_ALPHA, DestFactor.ONE_MINUS_SRC_ALPHA);

public static final RenderPipeline RED_THREAD = RenderPipeline.builder(RenderPipelines.MATRICES_FOG_SNIPPET)
.withLocation(TwilightForestMod.prefix("pipeline/red_thread"))
.withLocation(TwilightForestMod.prefix("core/red_thread/red_thread"))
.withSampler("Sampler0")
.withVertexShader(TwilightForestMod.prefix("core/red_thread/red_thread"))
.withFragmentShader(TwilightForestMod.prefix("core/red_thread/red_thread"))
.withVertexFormat(DefaultVertexFormat.BLOCK, VertexFormat.Mode.QUADS)
.withCull(true)
.withDepthStencilState(new DepthStencilState(CompareOp.ALWAYS_PASS, false))
.withDepthStencilState(Optional.of(new DepthStencilState(CompareOp.ALWAYS_PASS, false)))
.build();

public static final RenderPipeline PROTECTION_BOX = RenderPipeline.builder(RenderPipelines.MATRICES_FOG_SNIPPET)
Expand Down
68 changes: 29 additions & 39 deletions src/main/java/twilightforest/client/renderer/TFWeatherRenderer.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@
import com.mojang.blaze3d.vertex.*;
import com.mojang.datafixers.util.Pair;
import net.minecraft.client.Camera;
import net.minecraft.client.GraphicsPreset;
import net.minecraft.client.Minecraft;
import net.minecraft.client.multiplayer.ClientLevel;
import net.minecraft.client.player.LocalPlayer;
import net.minecraft.client.renderer.LevelRenderer;
import net.minecraft.client.renderer.MultiBufferSource;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.core.SectionPos;
Expand Down Expand Up @@ -35,6 +37,7 @@
import twilightforest.TwilightForestMod;
import twilightforest.init.custom.Enforcements;
import twilightforest.util.IntervalUtils;
import twilightforest.util.RenderTypeUtil;
import twilightforest.util.Restriction;

import java.util.ArrayList;
Expand Down Expand Up @@ -81,42 +84,41 @@ public class TFWeatherRenderer {
}
}

public static boolean renderSnowAndRain(ClientLevel level, int ticks, float partialTicks, Vec3 camera) {
// [VanillaCopy] the copy of removed Minecraft.useFancyGraphics
private static boolean useFancyGraphics() {
return Minecraft.getInstance().options.graphicsPreset().get().ordinal() >= GraphicsPreset.FANCY.ordinal();
}

// [VanillaCopy] the copy of removed

public static boolean renderSnowAndRain(ClientLevel level, int ticks, float partialTicks, Vec3 camera, MultiBufferSource buffer) {
Minecraft mc = Minecraft.getInstance();
if (progressionEnforced && mc.player != null && !mc.player.isCreative() && !mc.player.isSpectator()) {
// locked biome weather effects
renderLockedBiome(ticks, partialTicks, level, mc.player, camera);
renderLockedBiome(ticks, partialTicks, level, mc.player, camera, buffer);

// locked structures
renderLockedStructure(ticks, partialTicks, camera);
renderLockedStructure(ticks, partialTicks, camera, buffer);
}

//render normal weather anyway
return false;
}

private static void renderLockedBiome(int ticks, float partialTicks, ClientLevel level, LocalPlayer player, Vec3 camera) {
private static void renderLockedBiome(int ticks, float partialTicks, ClientLevel level, LocalPlayer player, Vec3 camera, MultiBufferSource buffer) {
// check nearby for locked biome
if (isNearLockedBiome(level, player)) {
int px = Mth.floor(camera.x());
int py = Mth.floor(camera.y());
int pz = Mth.floor(camera.z());

RenderSystem.disableCull();
RenderSystem.enableBlend();
RenderSystem.defaultBlendFunc();
RenderSystem.enableDepthTest();

int range = 5;
if (Minecraft.useFancyGraphics()) {
if (useFancyGraphics()) {
range = 10;
}

RenderSystem.depthMask(Minecraft.useShaderTransparency());

WeatherRenderType currentType = null;
float combinedTicks = ticks + partialTicks;
RenderSystem.setShader(CoreShaders.PARTICLE);
BlockPos.MutableBlockPos pos = new BlockPos.MutableBlockPos();

for (int dz = pz - range; dz <= pz + range; ++dz) {
Expand Down Expand Up @@ -155,15 +157,14 @@ private static void renderLockedBiome(int ticks, float partialTicks, ClientLevel
double zRange = (double) ((float) dz + 0.5F) - camera.z();
float distanceToPlayer = Mth.sqrt((float) (xRange * xRange + zRange * zRange)) / (float) range;
float alpha = ((1.0F - distanceToPlayer * distanceToPlayer) * 0.3F + 0.5F);
int worldBrightness = LevelRenderer.getLightColor(level, pos);
int fullbright = 15 << 20 | 15 << 4;

switch (currentType) {
case BLIZZARD -> {
float countFactor = ((float) (ticks & 511) + partialTicks) / 512.0F;
float uFactor = random.nextFloat() + combinedTicks * 0.05F * (float) random.nextGaussian();
float vFactor = random.nextFloat() + combinedTicks * 0.0025F * (float) random.nextGaussian();
renderEffect(currentType.getTextureLocation(), rainX, rainZ, minY, maxY, camera, dx, dz, countFactor, uFactor, vFactor, new float[]{1.0F, 1.0F, 1.0F, alpha}, fullbright);
renderEffect(currentType.getTextureLocation(), rainX, rainZ, minY, maxY, camera, dx, dz, countFactor, uFactor, vFactor, new float[]{1.0F, 1.0F, 1.0F, alpha}, fullbright, buffer);
}
case MOSQUITO -> {
float countFactor = 0;
Expand All @@ -172,41 +173,39 @@ private static void renderLockedBiome(int ticks, float partialTicks, ClientLevel
float red = random.nextFloat() * 0.3F;
float green = random.nextFloat() * 0.3F;
float blue = random.nextFloat() * 0.3F;
renderEffect(currentType.getTextureLocation(), rainX, rainZ, minY, maxY, camera, dx, dz, countFactor, uFactor, vFactor, new float[]{red, green, blue, 1.0F}, fullbright);
renderEffect(currentType.getTextureLocation(), rainX, rainZ, minY, maxY, camera, dx, dz, countFactor, uFactor, vFactor, new float[]{red, green, blue, 1.0F}, fullbright, buffer);
}
case ASHES -> {
float countFactor = -((float) (ticks & 1023) + partialTicks) / 1024.0F;
float uFactor = random.nextFloat() + combinedTicks * 0.0025F * (float) random.nextGaussian();
float vFactor = random.nextFloat() + combinedTicks * 0.005F * (float) random.nextGaussian();
float color = random.nextFloat() * 0.2F + 0.8F;
renderEffect(currentType.getTextureLocation(), rainX, rainZ, minY, maxY, camera, dx, dz, countFactor, uFactor, vFactor, new float[]{color, color, color, alpha}, fullbright);
renderEffect(currentType.getTextureLocation(), rainX, rainZ, minY, maxY, camera, dx, dz, countFactor, uFactor, vFactor, new float[]{color, color, color, alpha}, fullbright, buffer);
}
case DARK_STREAM -> {
float countFactor = -((ticks & 511) + partialTicks) / 512.0F;
float uFactor = 0; //no moving horizontally
float vFactor = random.nextFloat() + combinedTicks * 0.005F * (float) random.nextGaussian();
renderEffect(currentType.getTextureLocation(), rainX, rainZ, minY, maxY, camera, dx, dz, countFactor, uFactor, vFactor, new float[]{1.0F, 1.0F, 1.0F, alpha}, fullbright);
renderEffect(currentType.getTextureLocation(), rainX, rainZ, minY, maxY, camera, dx, dz, countFactor, uFactor, vFactor, new float[]{1.0F, 1.0F, 1.0F, alpha}, fullbright, buffer);
}
case BIG_RAIN -> {
float countFactor = ((float) (ticks + dx * dx * 3121 + dx * 45238971 + dz * dz * 418711 + dz * 13761 & 31) + partialTicks) / 32.0F * (3.0F + random.nextFloat());
float uFactor = random.nextFloat();
float vFactor = random.nextFloat();
renderEffect(currentType.getTextureLocation(), rainX, rainZ, minY, maxY, camera, dx, dz, countFactor, uFactor, vFactor, new float[]{1.0F, 1.0F, 1.0F, alpha}, worldBrightness);
int worldBrightness = LevelRenderer.getLightCoords(level, pos);
renderEffect(currentType.getTextureLocation(), rainX, rainZ, minY, maxY, camera, dx, dz, countFactor, uFactor, vFactor, new float[]{1.0F, 1.0F, 1.0F, alpha}, worldBrightness, buffer);
}
}
}
}
}
}

RenderSystem.enableCull();
RenderSystem.disableBlend();
}
}

@SuppressWarnings("ConstantConditions")
private static void renderLockedStructure(int ticks, float partialTicks, Vec3 camera) {
int range = Minecraft.useFancyGraphics() ? 10 : 5;
private static void renderLockedStructure(int ticks, float partialTicks, Vec3 camera, MultiBufferSource buffer) {
int range = useFancyGraphics() ? 10 : 5;
int px = Mth.floor(camera.x());
int py = Mth.floor(camera.y());
int pz = Mth.floor(camera.z());
Expand All @@ -224,14 +223,8 @@ private static void renderLockedStructure(int ticks, float partialTicks, Vec3 ca
pBoxOld = pBox;
}

RenderSystem.disableCull();
RenderSystem.enableBlend();
RenderSystem.defaultBlendFunc();
RenderSystem.enableDepthTest();

float combinedTicks = ticks + partialTicks;
int drawFlag = -1;
RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F);

for (int x = pBox.minX(); x <= pBox.maxX(); x++) {
for (int z = pBox.minZ(); z <= pBox.maxZ(); z++) {
Expand All @@ -244,7 +237,6 @@ private static void renderLockedStructure(int ticks, float partialTicks, Vec3 ca
random.setSeed((long) x * x * 3121 + x * 45238971L ^ (long) z * z * 418711 + z * 13761L);
if (drawFlag != 0) {
drawFlag = 0;
RenderSystem.setShader(CoreShaders.PARTICLE);
}

float countFactor = ((ticks & 511) + partialTicks) / 512.0F;
Expand All @@ -263,14 +255,12 @@ private static void renderLockedStructure(int ticks, float partialTicks, Vec3 ca
camera, x, z,
countFactor, uFactor, vFactor,
new float[] {1.0F, 1.0F, 1.0F, alpha},
(15 << 20) | (15 << 4)
(15 << 20) | (15 << 4),
buffer
);
}
}
}

RenderSystem.enableCull();
RenderSystem.disableBlend();
}

private static void updateRainIntervals(BoundingBox pBox) {
Expand Down Expand Up @@ -316,8 +306,8 @@ private static List<Pair<Integer, Integer>> getRainIntervals(int x, int z, Bound
return intervals;
}

private static void renderEffect(Identifier type, double rainX, double rainZ, int minY, int maxY, Vec3 camera, int dx, int dz, float countFactor, float uFactor, float vFactor, float[] color, int light) {
VertexConsumer consumer = Minecraft.getInstance().renderBuffers().bufferSource().getBuffer(RenderType.weather(type, Minecraft.useShaderTransparency()));
private static void renderEffect(Identifier type, double rainX, double rainZ, int minY, int maxY, Vec3 camera, int dx, int dz, float countFactor, float uFactor, float vFactor, float[] color, int light, MultiBufferSource bufferSource) {
VertexConsumer consumer = bufferSource.getBuffer(RenderTypeUtil.weather(type, Minecraft.useShaderTransparency()));
consumer
.addVertex((float) (dx - camera.x() - rainX + 0.5F), (float) (minY - camera.y()), (float) (dz - camera.z() - rainZ + 0.5F))
.setUv(0.0F + uFactor, minY * 0.25F + countFactor + vFactor)
Expand Down Expand Up @@ -399,7 +389,7 @@ public Identifier getTextureLocation() {

/**
* [VanillaCopy]:<br>
* {@link net.minecraft.client.renderer.WeatherEffectRenderer#tickRainParticles(ClientLevel, Camera, int, ParticleStatus)}<br>
* {@link net.minecraft.client.renderer.WeatherEffectRenderer#tickRainParticles(ClientLevel, Camera, int, ParticleStatus, int)}<br>
*/
public static boolean tickRain(ClientLevel level, int partialTicks, BlockPos blockpos) {
//TF - render rain if the Ur-Ghast is alive as well
Expand All @@ -409,7 +399,7 @@ public static boolean tickRain(ClientLevel level, int partialTicks, BlockPos blo
} else urGhastRain = Math.max(0.0F, urGhastRain - 0.02F);

//TF - factor in the Ur-Ghast being alive when determining rain level
float rainLevel = Math.max(level.getRainLevel(1.0F), urGhastRain) / (Minecraft.useFancyGraphics() ? 1.0F : 2.0F);
float rainLevel = Math.max(level.getRainLevel(1.0F), urGhastRain) / (useFancyGraphics() ? 1.0F : 2.0F);
if (rainLevel > 0.0F) {
RandomSource randomsource = RandomSource.create((long) partialTicks * 312987231L);
BlockPos blockpos1 = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import net.minecraft.server.packs.resources.ResourceManagerReloadListener;
import net.neoforged.neoforge.client.extensions.common.IClientItemExtensions;
import net.neoforged.neoforge.common.util.Lazy;
import org.jetbrains.annotations.NotNull;

import java.util.ArrayList;
import java.util.HashMap;
Expand Down Expand Up @@ -41,7 +40,7 @@ protected ModelPart getModelPart(ModelLayerLocation layerLocation) {

public static final class ResourceReloadListener implements ResourceManagerReloadListener {
@Override
public void onResourceManagerReload(@NotNull ResourceManager resourceManager) {
public void onResourceManagerReload(ResourceManager resourceManager) {
TFArmorRenderer.resetAllModelCache();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import net.minecraft.client.model.geom.ModelPart;
import net.minecraft.client.resources.model.EquipmentClientInfo;
import net.minecraft.world.item.ItemStack;
import org.jetbrains.annotations.NotNull;
import twilightforest.client.model.armor.TFArmorModel;

import java.util.function.Function;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import net.minecraft.resources.Identifier;
import net.minecraft.util.Mth;
import net.minecraft.world.entity.Pose;
import net.minecraft.world.phys.AABB;
import twilightforest.TwilightForestMod;
import twilightforest.client.model.TFModelLayers;
import twilightforest.client.model.entity.HydraModel;
Expand Down Expand Up @@ -65,4 +66,14 @@ public void extractRenderState(Hydra entity, HydraRenderState state, float parti
public Identifier getTextureLocation(HydraRenderState state) {
return TEXTURE;
}

@Override
protected boolean affectedByCulling(Hydra entity) {
return false;
}

@Override
protected AABB getBoundingBoxForCulling(Hydra entity) {
return entity.getBoundingBox().inflate(16.0D, 16.0D, 16.0D);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import net.minecraft.client.renderer.entity.MobRenderer;
import net.minecraft.resources.Identifier;
import net.minecraft.util.ARGB;
import net.minecraft.world.phys.AABB;
import twilightforest.TwilightForestMod;
import twilightforest.client.model.TFModelLayers;
import twilightforest.client.model.entity.NagaModel;
Expand Down Expand Up @@ -62,4 +63,14 @@ public Identifier getTextureLocation(NagaRenderState state) {
return TEXTURE;
}
}

@Override
protected boolean affectedByCulling(Naga entity) {
return false;
}

@Override
protected AABB getBoundingBoxForCulling(Naga entity) {
return entity.getBoundingBox().inflate(16.0D, 16.0D, 16.0D);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,14 @@ public RedcapArmorLayer(RenderLayerParent<S, M> renderer, ArmorModelSet<A> model

@Override
public void submit(PoseStack poseStack, SubmitNodeCollector submitNodeCollector, int lightCoords, S state, float yRot, float xRot) {
//TODO Need Access Transformer
this.renderArmorPiece(poseStack, submitNodeCollector, state.chestEquipment, EquipmentSlot.CHEST, state, this.getArmorModel(state, EquipmentSlot.CHEST));
this.renderArmorPiece(poseStack, submitNodeCollector, state.legsEquipment, EquipmentSlot.LEGS, state, this.getArmorModel(state, EquipmentSlot.LEGS));
this.renderArmorPiece(poseStack, submitNodeCollector, state.chestEquipment, EquipmentSlot.CHEST, 0, state);
this.renderArmorPiece(poseStack, submitNodeCollector, state.legsEquipment, EquipmentSlot.LEGS, 0, state);
//TF: raise boots
poseStack.pushPose();
poseStack.translate(0.0D, -0.2D, 0.0D);
this.renderArmorPiece(poseStack, submitNodeCollector, state.feetEquipment, EquipmentSlot.FEET, state, this.getArmorModel(state, EquipmentSlot.FEET));
this.renderArmorPiece(poseStack, submitNodeCollector, state.feetEquipment, EquipmentSlot.FEET, 0, state);
poseStack.popPose();
this.renderArmorPiece(poseStack, submitNodeCollector, state.headEquipment, EquipmentSlot.HEAD, state, this.getArmorModel(state, EquipmentSlot.HEAD));
this.renderArmorPiece(poseStack, submitNodeCollector, state.headEquipment, EquipmentSlot.HEAD, 0, state);
}
}
}
Loading
Loading