Skip to content

Commit

Permalink
Adjust getPrecipitationAt approach for better mod compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
Adubbz committed Mar 7, 2024
1 parent a5c301d commit 7acbaf8
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 63 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*******************************************************************************
* Copyright 2024, the Glitchfiend Team.
* All rights reserved.
******************************************************************************/
package sereneseasons.mixin.client;

import net.minecraft.client.Minecraft;
import net.minecraft.core.BlockPos;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.biome.Biome;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import sereneseasons.season.SeasonHooks;

@Mixin(Biome.class)
public class MixinBiomeClient
{
@Inject(method="getPrecipitationAt", at=@At("HEAD"), cancellable = true)
public void onGetPrecipitationAt(BlockPos pos, CallbackInfoReturnable<Biome.Precipitation> cir)
{
Minecraft minecraft = Minecraft.getInstance();
Level level = minecraft.level;

if (level != null)
{
cir.setReturnValue(SeasonHooks.getPrecipitationAtSeasonal(level, level.getBiome(pos), pos));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,12 @@
import net.minecraft.core.BlockPos;
import net.minecraft.core.Holder;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.LevelReader;
import net.minecraft.world.level.biome.Biome;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Redirect;
import sereneseasons.season.SeasonHooks;
import sereneseasons.season.SeasonHooksClient;

@Mixin(LevelRenderer.class)
public class MixinLevelRenderer
Expand All @@ -24,13 +22,6 @@ public class MixinLevelRenderer
private Level renderSnowAndRain_level;
@Unique
private Holder<Biome> renderSnowAndRain_biome;
@Unique
private BlockPos renderSnowAndRain_pos;

@Unique
private Level tickRain_level;
@Unique
private Holder<Biome> tickRain_biome;

/*
* renderSnowAndRain
Expand All @@ -41,37 +32,12 @@ public Holder<Biome> renderSnowAndRain_getBiome(Level level, BlockPos pos)
{
this.renderSnowAndRain_level = level;
this.renderSnowAndRain_biome = level.getBiome(pos);
this.renderSnowAndRain_pos = pos;
return this.renderSnowAndRain_biome;
}

@Redirect(method="renderSnowAndRain", at=@At(value = "INVOKE", target = "Lnet/minecraft/world/level/biome/Biome;getPrecipitationAt(Lnet/minecraft/core/BlockPos;)Lnet/minecraft/world/level/biome/Biome$Precipitation;"))
public Biome.Precipitation renderSnowAndRain_getPrecipitationAt(Biome biome, BlockPos pos)
{
return SeasonHooksClient.getPrecipitationAtLevelRendererHook(this.renderSnowAndRain_biome, pos);
}

@Redirect(method="renderSnowAndRain", at=@At(value = "INVOKE", target = "Lnet/minecraft/world/level/biome/Biome;hasPrecipitation()Z"))
public boolean renderSnowAndRain_hasPrecipitation(Biome biome)
{
return SeasonHooks.hasPrecipitationSeasonal(this.renderSnowAndRain_level, this.renderSnowAndRain_biome);
}

/*
* tickRain
*/

@Redirect(method="tickRain", at=@At(value = "INVOKE", target = "Lnet/minecraft/world/level/LevelReader;getBiome(Lnet/minecraft/core/BlockPos;)Lnet/minecraft/core/Holder;"))
public Holder<Biome> tickRain_getBiome(LevelReader level, BlockPos pos)
{
this.tickRain_level = (Level)level;
this.tickRain_biome = level.getBiome(pos);
return this.tickRain_biome;
}

@Redirect(method="tickRain", at=@At(value = "INVOKE", target = "Lnet/minecraft/world/level/biome/Biome;getPrecipitationAt(Lnet/minecraft/core/BlockPos;)Lnet/minecraft/world/level/biome/Biome$Precipitation;"))
public Biome.Precipitation tickRain_getPrecipitationAt(Biome biome, BlockPos pos)
{
return SeasonHooksClient.getPrecipitationAtLevelRendererHook(this.tickRain_biome, pos);
}
}
28 changes: 0 additions & 28 deletions common/src/main/java/sereneseasons/season/SeasonHooksClient.java

This file was deleted.

3 changes: 2 additions & 1 deletion common/src/main/resources/sereneseasons.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
"MixinServerLevel"
],
"client": [
"client.MixinLevelRenderer"
"client.MixinLevelRenderer",
"client.MixinBiomeClient"
],
"injectors": {
"defaultRequire": 1
Expand Down

0 comments on commit 7acbaf8

Please sign in to comment.