Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,19 @@
import net.minecraft.client.renderer.RenderPipelines;
import twilightforest.TwilightForestMod;

public class TFRenderPipelines {
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
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,8 @@

//TODO check all of these in-game, im bad at writing these
public class TFRenderTypes {

public static final RenderType RED_THREAD = RenderType.create("twilightforest:red_thread", RenderSetup.builder(TFRenderPipelines.RED_THREAD)
.withTexture("Sampler0", RedThreadRenderer.TEXTURE)
.affectsCrumbling()
.useLightmap()
.useOverlay()
.setOutline(RenderSetup.OutlineProperty.AFFECTS_OUTLINE)
Expand Down
39 changes: 11 additions & 28 deletions src/main/java/twilightforest/client/renderer/TFWeatherRenderer.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package twilightforest.client.renderer;

import com.mojang.blaze3d.systems.RenderSystem;
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.rendertype.RenderTypes;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.core.SectionPos;
Expand All @@ -33,10 +34,11 @@
import net.minecraft.world.phys.shapes.VoxelShape;
import org.jetbrains.annotations.Nullable;
import twilightforest.TwilightForestMod;
import twilightforest.init.TFGameRules;
import twilightforest.init.custom.Enforcements;
import twilightforest.network.EnforceProgressionStatusPacket;
import twilightforest.util.IntervalUtils;
import twilightforest.util.Restriction;
import twilightforest.util.landmarks.LandmarkUtil;

import java.util.ArrayList;
import java.util.HashMap;
Expand Down Expand Up @@ -82,7 +84,7 @@ public class TFWeatherRenderer {

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

Expand All @@ -101,21 +103,14 @@ private static void renderLockedBiome(int ticks, float partialTicks, ClientLevel
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 (Minecraft.getInstance().options.graphicsPreset().get() != GraphicsPreset.FAST) {
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 @@ -154,7 +149,7 @@ 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 worldBrightness = LevelRenderer.getLightCoords(level, pos);
int fullbright = 15 << 20 | 15 << 4;

switch (currentType) {
Expand Down Expand Up @@ -197,15 +192,12 @@ private static void renderLockedBiome(int ticks, float partialTicks, ClientLevel
}
}
}

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

@SuppressWarnings("ConstantConditions")
private static void renderLockedStructure(int ticks, float partialTicks, Vec3 camera) {
int range = Minecraft.useFancyGraphics() ? 10 : 5;
int range = Minecraft.getInstance().options.graphicsPreset().get() != GraphicsPreset.FAST ? 10 : 5;
int px = Mth.floor(camera.x());
int py = Mth.floor(camera.y());
int pz = Mth.floor(camera.z());
Expand All @@ -223,14 +215,9 @@ 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 @@ -243,7 +230,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 @@ -267,9 +253,6 @@ private static void renderLockedStructure(int ticks, float partialTicks, Vec3 ca
}
}
}

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

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

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()));
VertexConsumer consumer = Minecraft.getInstance().renderBuffers().bufferSource().getBuffer(RenderTypes.entityTranslucentEmissive(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 @@ -394,7 +377,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 @@ -404,7 +387,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) / (Minecraft.getInstance().options.graphicsPreset().get() != GraphicsPreset.FAST ? 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 @@ -16,7 +16,7 @@

public abstract class TFArmorRenderer implements IClientItemExtensions {
public static final List<TFSimpleArmorRenderer> INSTANCES = new ArrayList<>();
protected final Map<ModelLayerLocation, Lazy<ModelPart>> ARMOR_MODELS = new HashMap<>();
protected final Map<ModelLayerLocation, Lazy<@NotNull ModelPart>> ARMOR_MODELS = new HashMap<>();

public TFArmorRenderer(ModelLayerLocation... layerLocations) {
for (ModelLayerLocation layerLocation : layerLocations) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package twilightforest.client.renderer.armor;

import net.minecraft.client.model.HumanoidModel;
import net.minecraft.client.model.Model;
import net.minecraft.client.model.geom.ModelLayerLocation;
import net.minecraft.client.model.geom.ModelPart;
import net.minecraft.client.resources.model.EquipmentClientInfo;
import net.minecraft.world.entity.EquipmentSlot;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.item.ItemStack;
import org.jetbrains.annotations.NotNull;
import twilightforest.client.model.armor.TFArmorModel;
Expand All @@ -24,8 +24,8 @@ public TFSimpleArmorRenderer(Function<ModelPart, TFArmorModel> createModelInstan
}

@Override
public @NotNull HumanoidModel<?> getHumanoidArmorModel(@NotNull LivingEntity living, @NotNull ItemStack stack, @NotNull EquipmentSlot slot, @NotNull HumanoidModel<?> model) {
return slot == EquipmentSlot.LEGS ?
public @NotNull TFArmorModel getHumanoidArmorModel(@NotNull ItemStack itemStack, EquipmentClientInfo.@NotNull LayerType layerType, @NotNull Model original) {
return itemStack.getEquipmentSlot() == EquipmentSlot.LEGS ?
CREATE_MODEL_INSTANCE.apply(getModelPart(INNER_ARMOR_MODEL)) :
CREATE_MODEL_INSTANCE.apply(getModelPart(OUTER_ARMOR_MODEL));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import net.minecraft.world.level.block.CandleBlock;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.phys.Vec3;
import org.jetbrains.annotations.NotNull;
import org.jspecify.annotations.Nullable;
import twilightforest.block.CandelabraBlock;
import twilightforest.block.LightableBlock;
Expand All @@ -25,8 +26,7 @@
import java.util.ArrayList;
import java.util.List;

public class CandelabraRenderer implements BlockEntityRenderer<CandelabraBlockEntity, CandelabraRenderState> {

public class CandelabraRenderer implements BlockEntityRenderer<@NotNull CandelabraBlockEntity, @NotNull CandelabraRenderState> {
private final BlockModelResolver blockModelResolver;

public CandelabraRenderer(BlockEntityRendererProvider.Context context) {
Expand Down
Loading
Loading