Skip to content

Commit

Permalink
Fix crash with SereneSeasons mod (#1)
Browse files Browse the repository at this point in the history
  • Loading branch information
Hantonik committed Feb 18, 2024
1 parent 8278e71 commit 5540ecf
Show file tree
Hide file tree
Showing 11 changed files with 133 additions and 52 deletions.
4 changes: 4 additions & 0 deletions Fabric/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ loom {
}

repositories {
maven { url 'https://maven.minecraftforge.net/' }
maven { url 'https://maven.parchmentmc.org' }
}

Expand All @@ -63,6 +64,9 @@ dependencies {
modImplementation "net.fabricmc:fabric-loader:$loader_version"
modImplementation "net.fabricmc.fabric-api:fabric-api:$fabric_version+$mc_version"

modCompileOnly "com.github.glitchfiend:SereneSeasons-fabric:$mc_version-$sereneseasons_version"
modCompileOnly "com.github.glitchfiend:GlitchCore-fabric:$mc_version-$glitchcore_version"

compileOnly "org.projectlombok:lombok:$lombok_version"
annotationProcessor "org.projectlombok:lombok:$lombok_version"
}
Expand Down
39 changes: 22 additions & 17 deletions Fabric/src/main/java/hantonik/fbp/mixins/MixinLevelRenderer.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
package hantonik.fbp.mixins;

import com.llamalad7.mixinextras.sugar.Local;
import com.mojang.blaze3d.systems.RenderSystem;
import hantonik.fbp.FancyBlockParticles;
import hantonik.fbp.particle.FBPRainParticle;
import hantonik.fbp.particle.FBPSnowParticle;
import hantonik.fbp.util.FBPConstants;
import hantonik.fbp.util.FBPUtils;
import net.minecraft.client.Camera;
import net.minecraft.client.Minecraft;
import net.minecraft.client.multiplayer.ClientLevel;
import net.minecraft.client.renderer.LevelRenderer;
import net.minecraft.client.renderer.LightTexture;
import net.minecraft.core.BlockPos;
import net.minecraft.core.particles.ParticleOptions;
import net.minecraft.core.particles.ParticleTypes;
Expand Down Expand Up @@ -59,23 +63,20 @@ private void tickRain(Camera camera, CallbackInfo callback) {
continue;

var pos = BlockPos.containing(x, this.minecraft.player.getY(), z);
var biome = this.level.getBiome(pos).value();
var surfaceHeight = this.level.getHeightmapPos(Heightmap.Types.MOTION_BLOCKING, pos).getY();

var y = (int) (this.minecraft.player.getY() + 15.0D + FBPConstants.RANDOM.nextDouble() * 10.0D + (this.minecraft.player.getDeltaMovement().y * 6.0D));

if (y <= surfaceHeight + 2)
y = surfaceHeight + 10;

if (biome.hasPrecipitation()) {
if (biome.getPrecipitationAt(pos) == Biome.Precipitation.RAIN) {
if (FancyBlockParticles.CONFIG.isFancyRain())
this.minecraft.particleEngine.add(new FBPRainParticle(this.level, x, y, z, 0.1D, -(FBPConstants.RANDOM.nextDouble(0.75D, 0.99D) + td / 2.0D), 0.1D, this.minecraft.getBlockRenderer().getBlockModelShaper().getParticleIcon(Blocks.WATER.defaultBlockState())));
} else {
if (FancyBlockParticles.CONFIG.isFancySnow())
if (i % 2 == 0)
this.minecraft.particleEngine.add(new FBPSnowParticle(this.level, x, y, z, FBPConstants.RANDOM.nextDouble(-0.5D, 0.5D), -(FBPConstants.RANDOM.nextDouble(0.25D, 1.0D) + td * 1.5D), FBPConstants.RANDOM.nextDouble(-0.5D, 0.5D), this.minecraft.getBlockRenderer().getBlockModelShaper().getParticleIcon(Blocks.SNOW.defaultBlockState())));
}
if (FBPUtils.getPrecipitationAtLevelRenderer(this.level.getBiome(pos), pos) == Biome.Precipitation.RAIN) {
if (FancyBlockParticles.CONFIG.isFancyRain())
this.minecraft.particleEngine.add(new FBPRainParticle(this.level, x, y, z, 0.1D, -(FBPConstants.RANDOM.nextDouble(0.75D, 0.99D) + td / 2.0D), 0.1D, this.minecraft.getBlockRenderer().getBlockModelShaper().getParticleIcon(Blocks.WATER.defaultBlockState())));
} else {
if (FancyBlockParticles.CONFIG.isFancySnow())
if (i % 2 == 0)
this.minecraft.particleEngine.add(new FBPSnowParticle(this.level, x, y, z, FBPConstants.RANDOM.nextDouble(-0.5D, 0.5D), -(FBPConstants.RANDOM.nextDouble(0.25D, 1.0D) + td * 1.5D), FBPConstants.RANDOM.nextDouble(-0.5D, 0.5D), this.minecraft.getBlockRenderer().getBlockModelShaper().getParticleIcon(Blocks.SNOW.defaultBlockState())));
}
}
}
Expand All @@ -87,16 +88,20 @@ private void addParticle(ClientLevel instance, ParticleOptions particleData, dou
instance.addParticle(particleData, x, y, z, xSpeed, ySpeed, zSpeed);
}

@Redirect(at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/biome/Biome;getPrecipitationAt(Lnet/minecraft/core/BlockPos;)Lnet/minecraft/world/level/biome/Biome$Precipitation;"), method = "renderSnowAndRain")
private Biome.Precipitation getPrecipitationAt(Biome instance, BlockPos pos) {
@Inject(at = @At(value = "INVOKE_ASSIGN", target = "Lnet/minecraft/world/level/biome/Biome;getPrecipitationAt(Lnet/minecraft/core/BlockPos;)Lnet/minecraft/world/level/biome/Biome$Precipitation;", shift = At.Shift.AFTER), method = "renderSnowAndRain", cancellable = true)
private void renderSnowAndRain(LightTexture lightTexture, float partialTick, double camX, double camY, double camZ, CallbackInfo callback, @Local Biome.Precipitation precipitation) {
if (FancyBlockParticles.CONFIG.isEnabled()) {
if (instance.getPrecipitationAt(pos) == Biome.Precipitation.RAIN && FancyBlockParticles.CONFIG.isFancyRain())
return Biome.Precipitation.NONE;
if (precipitation == Biome.Precipitation.RAIN && FancyBlockParticles.CONFIG.isFancyRain())
callback.cancel();

if (instance.getPrecipitationAt(pos) == Biome.Precipitation.SNOW && FancyBlockParticles.CONFIG.isFancySnow())
return Biome.Precipitation.NONE;
if (precipitation == Biome.Precipitation.SNOW && FancyBlockParticles.CONFIG.isFancySnow())
callback.cancel();
}

return instance.getPrecipitationAt(pos);
if (callback.isCancelled()) {
RenderSystem.enableCull();
RenderSystem.disableBlend();
lightTexture.turnOffLightLayer();
}
}
}
16 changes: 16 additions & 0 deletions Fabric/src/main/java/hantonik/fbp/util/FBPUtils.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package hantonik.fbp.util;

import lombok.AccessLevel;
import lombok.NoArgsConstructor;
import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Holder;
import net.minecraft.world.level.biome.Biome;
import sereneseasons.season.SeasonHooksClient;

@NoArgsConstructor(access = AccessLevel.PRIVATE)
public final class FBPUtils {
public static Biome.Precipitation getPrecipitationAtLevelRenderer(Holder<Biome> biome, BlockPos pos) {
return FabricLoader.getInstance().isModLoaded("sereneseasons") ? SeasonHooksClient.getPrecipitationAtLevelRendererHook(biome, pos) : biome.value().getPrecipitationAt(pos);
}
}
3 changes: 3 additions & 0 deletions Forge/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ dependencies {

compileOnly "org.projectlombok:lombok:$lombok_version"

compileOnly fg.deobf("com.github.glitchfiend:SereneSeasons-forge:$mc_version-$sereneseasons_version")
compileOnly fg.deobf("com.github.glitchfiend:GlitchCore-forge:$mc_version-$glitchcore_version")

compileOnly(annotationProcessor("io.github.llamalad7:mixinextras-common:$mixinextras_version"))

implementation(jarJar("io.github.llamalad7:mixinextras-forge:$mixinextras_version")) {
Expand Down
39 changes: 22 additions & 17 deletions Forge/src/main/java/hantonik/fbp/mixins/MixinLevelRenderer.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
package hantonik.fbp.mixins;

import com.llamalad7.mixinextras.sugar.Local;
import com.mojang.blaze3d.systems.RenderSystem;
import hantonik.fbp.FancyBlockParticles;
import hantonik.fbp.particle.FBPRainParticle;
import hantonik.fbp.particle.FBPSnowParticle;
import hantonik.fbp.util.FBPConstants;
import hantonik.fbp.util.FBPUtils;
import net.minecraft.client.Camera;
import net.minecraft.client.Minecraft;
import net.minecraft.client.multiplayer.ClientLevel;
import net.minecraft.client.renderer.LevelRenderer;
import net.minecraft.client.renderer.LightTexture;
import net.minecraft.core.BlockPos;
import net.minecraft.core.particles.ParticleOptions;
import net.minecraft.core.particles.ParticleTypes;
Expand Down Expand Up @@ -60,23 +64,20 @@ private void tickRain(Camera camera, CallbackInfo callback) {
continue;

var pos = BlockPos.containing(x, this.minecraft.player.getY(), z);
var biome = this.level.getBiome(pos).value();
var surfaceHeight = this.level.getHeightmapPos(Heightmap.Types.MOTION_BLOCKING, pos).getY();

var y = (int) (this.minecraft.player.getY() + 15.0D + FBPConstants.RANDOM.nextDouble() * 10.0D + (this.minecraft.player.getDeltaMovement().y * 6.0D));

if (y <= surfaceHeight + 2)
y = surfaceHeight + 10;

if (biome.hasPrecipitation()) {
if (biome.getPrecipitationAt(pos) == Biome.Precipitation.RAIN) {
if (FancyBlockParticles.CONFIG.isFancyRain())
this.minecraft.particleEngine.add(new FBPRainParticle(this.level, x, y, z, 0.1D, -(FBPConstants.RANDOM.nextDouble(0.75D, 0.99D) + td / 2.0D), 0.1D, this.minecraft.getBlockRenderer().getBlockModelShaper().getParticleIcon(Blocks.WATER.defaultBlockState())));
} else {
if (FancyBlockParticles.CONFIG.isFancySnow())
if (i % 2 == 0)
this.minecraft.particleEngine.add(new FBPSnowParticle(this.level, x, y, z, FBPConstants.RANDOM.nextDouble(-0.5D, 0.5D), -(FBPConstants.RANDOM.nextDouble(0.25D, 1.0D) + td * 1.5D), FBPConstants.RANDOM.nextDouble(-0.5D, 0.5D), this.minecraft.getBlockRenderer().getBlockModelShaper().getParticleIcon(Blocks.SNOW.defaultBlockState())));
}
if (FBPUtils.getPrecipitationAtLevelRenderer(this.level.getBiome(pos), pos) == Biome.Precipitation.RAIN) {
if (FancyBlockParticles.CONFIG.isFancyRain())
this.minecraft.particleEngine.add(new FBPRainParticle(this.level, x, y, z, 0.1D, -(FBPConstants.RANDOM.nextDouble(0.75D, 0.99D) + td / 2.0D), 0.1D, this.minecraft.getBlockRenderer().getBlockModelShaper().getParticleIcon(Blocks.WATER.defaultBlockState())));
} else {
if (FancyBlockParticles.CONFIG.isFancySnow())
if (i % 2 == 0)
this.minecraft.particleEngine.add(new FBPSnowParticle(this.level, x, y, z, FBPConstants.RANDOM.nextDouble(-0.5D, 0.5D), -(FBPConstants.RANDOM.nextDouble(0.25D, 1.0D) + td * 1.5D), FBPConstants.RANDOM.nextDouble(-0.5D, 0.5D), this.minecraft.getBlockRenderer().getBlockModelShaper().getParticleIcon(Blocks.SNOW.defaultBlockState())));
}
}
}
Expand All @@ -88,16 +89,20 @@ private void addParticle(ClientLevel instance, ParticleOptions particleData, dou
instance.addParticle(particleData, x, y, z, xSpeed, ySpeed, zSpeed);
}

@Redirect(at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/biome/Biome;getPrecipitationAt(Lnet/minecraft/core/BlockPos;)Lnet/minecraft/world/level/biome/Biome$Precipitation;"), method = "renderSnowAndRain")
private Biome.Precipitation getPrecipitationAt(Biome instance, BlockPos pos) {
@Inject(at = @At(value = "INVOKE_ASSIGN", target = "Lnet/minecraft/world/level/biome/Biome;getPrecipitationAt(Lnet/minecraft/core/BlockPos;)Lnet/minecraft/world/level/biome/Biome$Precipitation;", shift = At.Shift.AFTER), method = "renderSnowAndRain", cancellable = true)
private void renderSnowAndRain(LightTexture lightTexture, float partialTick, double camX, double camY, double camZ, CallbackInfo callback, @Local Biome.Precipitation precipitation) {
if (FancyBlockParticles.CONFIG.isEnabled()) {
if (instance.getPrecipitationAt(pos) == Biome.Precipitation.RAIN && FancyBlockParticles.CONFIG.isFancyRain())
return Biome.Precipitation.NONE;
if (precipitation == Biome.Precipitation.RAIN && FancyBlockParticles.CONFIG.isFancyRain())
callback.cancel();

if (instance.getPrecipitationAt(pos) == Biome.Precipitation.SNOW && FancyBlockParticles.CONFIG.isFancySnow())
return Biome.Precipitation.NONE;
if (precipitation == Biome.Precipitation.SNOW && FancyBlockParticles.CONFIG.isFancySnow())
callback.cancel();
}

return instance.getPrecipitationAt(pos);
if (callback.isCancelled()) {
RenderSystem.enableCull();
RenderSystem.disableBlend();
lightTexture.turnOffLightLayer();
}
}
}
16 changes: 16 additions & 0 deletions Forge/src/main/java/hantonik/fbp/util/FBPUtils.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package hantonik.fbp.util;

import lombok.AccessLevel;
import lombok.NoArgsConstructor;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Holder;
import net.minecraft.world.level.biome.Biome;
import net.minecraftforge.fml.ModList;
import sereneseasons.season.SeasonHooksClient;

@NoArgsConstructor(access = AccessLevel.PRIVATE)
public final class FBPUtils {
public static Biome.Precipitation getPrecipitationAtLevelRenderer(Holder<Biome> biome, BlockPos pos) {
return ModList.get().isLoaded("sereneseasons") ? SeasonHooksClient.getPrecipitationAtLevelRendererHook(biome, pos) : biome.value().getPrecipitationAt(pos);
}
}
7 changes: 7 additions & 0 deletions NeoForge/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,16 @@ runs {
}
}

repositories {
maven { url 'https://maven.minecraftforge.net/' }
}

dependencies {
implementation "net.neoforged:neoforge:$neo_version"

compileOnly "com.github.glitchfiend:SereneSeasons-neoforge:$mc_version-$sereneseasons_version"
compileOnly "com.github.glitchfiend:GlitchCore-neoforge:$mc_version-$glitchcore_version"

compileOnly "org.projectlombok:lombok:$lombok_version"
annotationProcessor "org.projectlombok:lombok:$lombok_version"
}
Expand Down
39 changes: 22 additions & 17 deletions NeoForge/src/main/java/hantonik/fbp/mixins/MixinLevelRenderer.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
package hantonik.fbp.mixins;

import com.llamalad7.mixinextras.sugar.Local;
import com.mojang.blaze3d.systems.RenderSystem;
import hantonik.fbp.FancyBlockParticles;
import hantonik.fbp.particle.FBPRainParticle;
import hantonik.fbp.particle.FBPSnowParticle;
import hantonik.fbp.util.FBPConstants;
import hantonik.fbp.util.FBPUtils;
import net.minecraft.client.Camera;
import net.minecraft.client.Minecraft;
import net.minecraft.client.multiplayer.ClientLevel;
import net.minecraft.client.renderer.LevelRenderer;
import net.minecraft.client.renderer.LightTexture;
import net.minecraft.core.BlockPos;
import net.minecraft.core.particles.ParticleOptions;
import net.minecraft.core.particles.ParticleTypes;
Expand Down Expand Up @@ -60,23 +64,20 @@ private void tickRain(Camera camera, CallbackInfo callback) {
continue;

var pos = BlockPos.containing(x, this.minecraft.player.getY(), z);
var biome = this.level.getBiome(pos).value();
var surfaceHeight = this.level.getHeightmapPos(Heightmap.Types.MOTION_BLOCKING, pos).getY();

var y = (int) (this.minecraft.player.getY() + 15.0D + FBPConstants.RANDOM.nextDouble() * 10.0D + (this.minecraft.player.getDeltaMovement().y * 6.0D));

if (y <= surfaceHeight + 2)
y = surfaceHeight + 10;

if (biome.hasPrecipitation()) {
if (biome.getPrecipitationAt(pos) == Biome.Precipitation.RAIN) {
if (FancyBlockParticles.CONFIG.isFancyRain())
this.minecraft.particleEngine.add(new FBPRainParticle(this.level, x, y, z, 0.1D, -(FBPConstants.RANDOM.nextDouble(0.75D, 0.99D) + td / 2.0D), 0.1D, this.minecraft.getBlockRenderer().getBlockModelShaper().getParticleIcon(Blocks.WATER.defaultBlockState())));
} else {
if (FancyBlockParticles.CONFIG.isFancySnow())
if (i % 2 == 0)
this.minecraft.particleEngine.add(new FBPSnowParticle(this.level, x, y, z, FBPConstants.RANDOM.nextDouble(-0.5D, 0.5D), -(FBPConstants.RANDOM.nextDouble(0.25D, 1.0D) + td * 1.5D), FBPConstants.RANDOM.nextDouble(-0.5D, 0.5D), this.minecraft.getBlockRenderer().getBlockModelShaper().getParticleIcon(Blocks.SNOW.defaultBlockState())));
}
if (FBPUtils.getPrecipitationAtLevelRenderer(this.level.getBiome(pos), pos) == Biome.Precipitation.RAIN) {
if (FancyBlockParticles.CONFIG.isFancyRain())
this.minecraft.particleEngine.add(new FBPRainParticle(this.level, x, y, z, 0.1D, -(FBPConstants.RANDOM.nextDouble(0.75D, 0.99D) + td / 2.0D), 0.1D, this.minecraft.getBlockRenderer().getBlockModelShaper().getParticleIcon(Blocks.WATER.defaultBlockState())));
} else {
if (FancyBlockParticles.CONFIG.isFancySnow())
if (i % 2 == 0)
this.minecraft.particleEngine.add(new FBPSnowParticle(this.level, x, y, z, FBPConstants.RANDOM.nextDouble(-0.5D, 0.5D), -(FBPConstants.RANDOM.nextDouble(0.25D, 1.0D) + td * 1.5D), FBPConstants.RANDOM.nextDouble(-0.5D, 0.5D), this.minecraft.getBlockRenderer().getBlockModelShaper().getParticleIcon(Blocks.SNOW.defaultBlockState())));
}
}
}
Expand All @@ -88,16 +89,20 @@ private void addParticle(ClientLevel instance, ParticleOptions particleData, dou
instance.addParticle(particleData, x, y, z, xSpeed, ySpeed, zSpeed);
}

@Redirect(at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/biome/Biome;getPrecipitationAt(Lnet/minecraft/core/BlockPos;)Lnet/minecraft/world/level/biome/Biome$Precipitation;"), method = "renderSnowAndRain")
private Biome.Precipitation getPrecipitationAt(Biome instance, BlockPos pos) {
@Inject(at = @At(value = "INVOKE_ASSIGN", target = "Lnet/minecraft/world/level/biome/Biome;getPrecipitationAt(Lnet/minecraft/core/BlockPos;)Lnet/minecraft/world/level/biome/Biome$Precipitation;", shift = At.Shift.AFTER), method = "renderSnowAndRain", cancellable = true)
private void renderSnowAndRain(LightTexture lightTexture, float partialTick, double camX, double camY, double camZ, CallbackInfo callback, @Local Biome.Precipitation precipitation) {
if (FancyBlockParticles.CONFIG.isEnabled()) {
if (instance.getPrecipitationAt(pos) == Biome.Precipitation.RAIN && FancyBlockParticles.CONFIG.isFancyRain())
return Biome.Precipitation.NONE;
if (precipitation == Biome.Precipitation.RAIN && FancyBlockParticles.CONFIG.isFancyRain())
callback.cancel();

if (instance.getPrecipitationAt(pos) == Biome.Precipitation.SNOW && FancyBlockParticles.CONFIG.isFancySnow())
return Biome.Precipitation.NONE;
if (precipitation == Biome.Precipitation.SNOW && FancyBlockParticles.CONFIG.isFancySnow())
callback.cancel();
}

return instance.getPrecipitationAt(pos);
if (callback.isCancelled()) {
RenderSystem.enableCull();
RenderSystem.disableBlend();
lightTexture.turnOffLightLayer();
}
}
}
16 changes: 16 additions & 0 deletions NeoForge/src/main/java/hantonik/fbp/util/FBPUtils.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package hantonik.fbp.util;

import lombok.AccessLevel;
import lombok.NoArgsConstructor;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Holder;
import net.minecraft.world.level.biome.Biome;
import net.neoforged.fml.ModList;
import sereneseasons.season.SeasonHooksClient;

@NoArgsConstructor(access = AccessLevel.PRIVATE)
public final class FBPUtils {
public static Biome.Precipitation getPrecipitationAtLevelRenderer(Holder<Biome> biome, BlockPos pos) {
return ModList.get().isLoaded("sereneseasons") ? SeasonHooksClient.getPrecipitationAtLevelRendererHook(biome, pos) : biome.value().getPrecipitationAt(pos);
}
}
3 changes: 3 additions & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ loader_version = 0.15.7
fabric_version = 0.96.1

# Dependencies
sereneseasons_version = 9.3.0.19
glitchcore_version = 1.0.0.59

mixinextras_version = 0.3.5

mixin_processor_version = 0.8.5
Expand Down
3 changes: 2 additions & 1 deletion update.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@
"homepage": "https://www.curseforge.com/minecraft/mc-mods/fbp-renewed",

"promos": {
"1.20.4-latest": "1.0.2.4-beta"
"1.20.4-latest": "1.0.2.5-beta"
},

"1.20.4": {
"1.0.2.5-beta": "Fix crash with SereneSeasons mod",
"1.0.2.4-beta": "[Fabric] Restore Item Pickup Particle",
"1.0.2.3-beta": "[Forge & NeoForge] Fix Smoke Particles too small",
"1.0.2.2-beta": "[Fabric] Fix duplicate button in FBP Settings menu",
Expand Down

0 comments on commit 5540ecf

Please sign in to comment.