mirror of
https://github.com/JonasunderscoreJones/nicer-skies.git
synced 2025-10-22 19:29:18 +02:00
switch to client entrypoint + non-static fields
This commit is contained in:
parent
094d9e716e
commit
c8f8622546
6 changed files with 59 additions and 33 deletions
|
@ -1,24 +1,35 @@
|
|||
package codes.ztereohype.nicerskies;
|
||||
|
||||
import codes.ztereohype.nicerskies.config.ConfigManager;
|
||||
import codes.ztereohype.nicerskies.config.Config;
|
||||
import codes.ztereohype.nicerskies.sky.SkyManager;
|
||||
import net.fabricmc.api.ModInitializer;
|
||||
import lombok.Getter;
|
||||
import net.fabricmc.api.ClientModInitializer;
|
||||
import net.fabricmc.loader.api.FabricLoader;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.logging.LogManager;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
public class NicerSkies implements ModInitializer {
|
||||
public static final Logger LOGGER = LogManager.getLogManager().getLogger("NicerSkies");
|
||||
|
||||
public static ConfigManager config = ConfigManager.fromFile(new File(FabricLoader.getInstance()
|
||||
.getConfigDir()
|
||||
.toFile(), "nicerskies.json"));
|
||||
public static SkyManager skyManager = new SkyManager();
|
||||
@Getter
|
||||
public class NicerSkies implements ClientModInitializer {
|
||||
public static final Logger LOGGER = LogManager.getLogManager().getLogger("nicer-skies");
|
||||
private static NicerSkies INSTANCE;
|
||||
|
||||
private Config config;
|
||||
private SkyManager skyManager;
|
||||
|
||||
@Override
|
||||
public void onInitialize() {
|
||||
public void onInitializeClient() {
|
||||
INSTANCE = this;
|
||||
|
||||
this.config = Config.fromFile(new File(FabricLoader.getInstance()
|
||||
.getConfigDir()
|
||||
.toFile(), "nicerskies.json"));
|
||||
|
||||
this.skyManager = new SkyManager();
|
||||
}
|
||||
|
||||
public static NicerSkies getInstance() {
|
||||
return INSTANCE;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,11 @@
|
|||
package codes.ztereohype.nicerskies.mixin;
|
||||
|
||||
import codes.ztereohype.nicerskies.NicerSkies;
|
||||
import com.mojang.blaze3d.vertex.*;
|
||||
import codes.ztereohype.nicerskies.config.Config;
|
||||
import codes.ztereohype.nicerskies.sky.SkyManager;
|
||||
import com.mojang.blaze3d.vertex.BufferBuilder;
|
||||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
import com.mojang.blaze3d.vertex.VertexBuffer;
|
||||
import net.minecraft.client.Camera;
|
||||
import net.minecraft.client.multiplayer.ClientLevel;
|
||||
import net.minecraft.client.renderer.GameRenderer;
|
||||
|
@ -20,13 +24,17 @@ import org.spongepowered.asm.mixin.injection.callback.LocalCapture;
|
|||
|
||||
@Mixin(value = LevelRenderer.class, priority = 999)
|
||||
public abstract class LevelRendererMixin {
|
||||
@Shadow private VertexBuffer starBuffer;
|
||||
@Shadow private int ticks;
|
||||
@Shadow private ClientLevel level;
|
||||
@Shadow
|
||||
private VertexBuffer starBuffer;
|
||||
@Shadow
|
||||
private int ticks;
|
||||
@Shadow
|
||||
private ClientLevel level;
|
||||
|
||||
@Inject(at = @At("HEAD"), method = "createStars", cancellable = true)
|
||||
private void generateStars(CallbackInfo ci) {
|
||||
if (!NicerSkies.config.getTwinklingStars()) return;
|
||||
Config config = NicerSkies.getInstance().getConfig();
|
||||
if (!config.areTwinlkingStarsEnabled()) return;
|
||||
|
||||
starBuffer = new VertexBuffer(VertexBuffer.Usage.DYNAMIC);
|
||||
ci.cancel();
|
||||
|
@ -34,10 +42,13 @@ public abstract class LevelRendererMixin {
|
|||
|
||||
@Inject(at = @At("HEAD"), method = "tick")
|
||||
private void tickStars(CallbackInfo ci) {
|
||||
if (!NicerSkies.config.getTwinklingStars()) return;
|
||||
Config config = NicerSkies.getInstance().getConfig();
|
||||
SkyManager skyManager = NicerSkies.getInstance().getSkyManager();
|
||||
|
||||
if (!config.areTwinlkingStarsEnabled()) return;
|
||||
if (this.level.getStarBrightness(0) < 0.0F) return;
|
||||
|
||||
NicerSkies.skyManager.tick(ticks);
|
||||
skyManager.tick(ticks);
|
||||
}
|
||||
|
||||
@ModifyArg(
|
||||
|
@ -46,7 +57,9 @@ public abstract class LevelRendererMixin {
|
|||
index = 2
|
||||
)
|
||||
private ShaderInstance injectStarColour(ShaderInstance shaderInstance) {
|
||||
if (!NicerSkies.config.getTwinklingStars()) return shaderInstance;
|
||||
Config config = NicerSkies.getInstance().getConfig();
|
||||
|
||||
if (!config.areTwinlkingStarsEnabled()) return shaderInstance;
|
||||
|
||||
return GameRenderer.getPositionColorShader();
|
||||
}
|
||||
|
@ -57,8 +70,11 @@ public abstract class LevelRendererMixin {
|
|||
locals = LocalCapture.CAPTURE_FAILHARD
|
||||
)
|
||||
private void drawSkybox(PoseStack poseStack, Matrix4f matrix4f, float f, Camera camera, boolean bl, Runnable runnable, CallbackInfo ci, FogType fogType, Vec3 vec3, float g, float h, float i, BufferBuilder bufferBuilder, ShaderInstance shaderInstance, float[] fs, float j, Matrix4f matrix4f3, float l, int s, int t, int n, float u, float p, float q, float r) {
|
||||
if (!NicerSkies.config.getNebulas() || NicerSkies.skyManager.getSkybox() == null) return;
|
||||
Config config = NicerSkies.getInstance().getConfig();
|
||||
SkyManager skyManager = NicerSkies.getInstance().getSkyManager();
|
||||
|
||||
NicerSkies.skyManager.getSkybox().render(poseStack, matrix4f);
|
||||
if (!config.areNebulasEnabled() || skyManager.getSkybox() == null) return;
|
||||
|
||||
skyManager.getSkybox().render(poseStack, matrix4f);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,7 +20,7 @@ public abstract class LightTextureMixin {
|
|||
)
|
||||
@SneakyThrows
|
||||
private void injectWarmLight(float partialTicks, CallbackInfo ci, ClientLevel clientLevel, float f, float g, float h, float i, float j, float l, float k, Vector3f vector3f, float m, Vector3f vector3f2, int n, int o, float p, float q, float r, float s, float t, boolean bl, float v, Vector3f vector3f5) {
|
||||
if (!NicerSkies.config.getLightmapTweaked()) return;
|
||||
if (!NicerSkies.getInstance().getConfig().getLightmapTweaked()) return;
|
||||
Vector3f warmTint = new Vector3f(0.36F, 0.13F, -0.15F);
|
||||
|
||||
float warmness = o / 15f * // increase w/ blocklight
|
||||
|
|
|
@ -12,6 +12,6 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
|||
public class MinecraftMixin {
|
||||
@Inject(at = @At("TAIL"), method = "setLevel")
|
||||
private void onWorldLoad(CallbackInfo ci) {
|
||||
NicerSkies.skyManager.generateSky(NebulaSeedManager.getSeed(), NicerSkies.config.getTwinklingStars(), NicerSkies.config.getNebulas());
|
||||
NicerSkies.getInstance().getSkyManager().generateSky(NebulaSeedManager.getSeed());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package codes.ztereohype.nicerskies.sky.nebula;
|
||||
|
||||
import codes.ztereohype.nicerskies.NicerSkies;
|
||||
import codes.ztereohype.nicerskies.config.Config;
|
||||
import com.mojang.blaze3d.platform.NativeImage;
|
||||
import com.mojang.blaze3d.systems.RenderSystem;
|
||||
import com.mojang.blaze3d.vertex.BufferBuilder;
|
||||
|
@ -91,6 +92,7 @@ public class Skybox {
|
|||
latch.countDown();
|
||||
}
|
||||
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
private enum CoordMap {
|
||||
X((texX, texY) -> (texX / (float) RESOLUTION) * 2 - 1),
|
||||
|
@ -98,7 +100,6 @@ public class Skybox {
|
|||
ONE((texX, texY) -> 1F),
|
||||
NEG_ONE((texX, texY) -> -1F);
|
||||
|
||||
@Getter
|
||||
private final BiFunction<Integer, Integer, Float> map;
|
||||
}
|
||||
|
||||
|
@ -149,11 +150,6 @@ public class Skybox {
|
|||
skyboxBuilder.vertex(80F, -80F, 80F).uv(0.75f, 0.75f).endVertex();
|
||||
skyboxBuilder.vertex(80F, -80F, -80F).uv(0.75f, 0.5f).endVertex();
|
||||
|
||||
// skyboxBuilder.vertex(-1F, -1F, -1F).uv(0f, 0f).endVertex();
|
||||
// skyboxBuilder.vertex(-1F, -1F, 1F).uv(0f, 1f).endVertex();
|
||||
// skyboxBuilder.vertex(1F, -1F, 1F).uv(1f, 1f).endVertex();
|
||||
// skyboxBuilder.vertex(1F, -1F, -1F).uv(1f, 0f).endVertex();
|
||||
|
||||
// top face
|
||||
skyboxBuilder.vertex(-80F, 80F, -80F).uv(0.5f, 0f).endVertex();
|
||||
skyboxBuilder.vertex(80F, 80F, -80F).uv(0.75f, 0f).endVertex();
|
||||
|
@ -177,14 +173,17 @@ public class Skybox {
|
|||
}
|
||||
|
||||
private float getSkyboxBrightness(ClientLevel level) {
|
||||
float config = NicerSkies.config.getNebulaStrength();
|
||||
Config config = NicerSkies.getInstance().getConfig();
|
||||
|
||||
float strength = config.getNebulaStrength();
|
||||
boolean renderDuringDay = config.getRenderDuringDay();
|
||||
|
||||
float timeOfDay = level.getTimeOfDay(0);
|
||||
float nightness = 1F - (Mth.cos(timeOfDay * (float) (Math.PI * 2)) * 4.0F + 0.5F);
|
||||
nightness = Mth.clamp(nightness, (NicerSkies.config.getRenderDuringDay() ? 1f : 0f), 1.0F);
|
||||
nightness = Mth.clamp(nightness, (renderDuringDay ? 1f : 0f), 1.0F);
|
||||
|
||||
float rain = level.getRainLevel(0);
|
||||
|
||||
return nightness * (1f - rain) * config;
|
||||
return nightness * (1f - rain) * strength;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
{
|
||||
"schemaVersion": 1,
|
||||
"id": "nicer-skies",
|
||||
"version": "1.2.1",
|
||||
"version": "1.3.0",
|
||||
"name": "Nicer Skies",
|
||||
"description": "This is a mod that improves the minecraft skies a little whilst keeping the behaviours vanilla and compatible.",
|
||||
"authors": [
|
||||
|
@ -14,7 +14,7 @@
|
|||
"icon": "assets/nicer_skies/icon.png",
|
||||
"environment": "client",
|
||||
"entrypoints": {
|
||||
"main": [
|
||||
"client": [
|
||||
"codes.ztereohype.nicerskies.NicerSkies"
|
||||
],
|
||||
"modmenu": [
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue