Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow seasonal color changes without reloading worldRenderer #161

Draft
wants to merge 3 commits into
base: 1.20
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
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
@@ -1,6 +1,7 @@
package io.github.lucaargolo.seasons;

import io.github.lucaargolo.seasons.commands.SeasonDebugCommand;
import io.github.lucaargolo.seasons.mixed.WorldRendererMixed;
import io.github.lucaargolo.seasons.resources.CropConfigs;
import io.github.lucaargolo.seasons.resources.FoliageSeasonColors;
import io.github.lucaargolo.seasons.resources.GrassSeasonColors;
Expand Down Expand Up @@ -60,7 +61,7 @@ public void onInitializeClient() {
ClientTickEvents.END_WORLD_TICK.register((clientWorld) -> {
if(FabricSeasons.getCurrentSeason(clientWorld) != lastRenderedSeasonMap.get(clientWorld.getRegistryKey())) {
lastRenderedSeasonMap.put(clientWorld.getRegistryKey(), FabricSeasons.getCurrentSeason(clientWorld));
MinecraftClient.getInstance().worldRenderer.reload();
((WorldRendererMixed)(MinecraftClient.getInstance().worldRenderer)).reloadOnlyColors();
}
});

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package io.github.lucaargolo.seasons.mixed;

public abstract interface WorldRendererMixed {
void reloadOnlyColors();
}
Original file line number Diff line number Diff line change
@@ -1,18 +1,43 @@
package io.github.lucaargolo.seasons.mixin;

import io.github.lucaargolo.seasons.mixed.WorldRendererMixed;
import io.github.lucaargolo.seasons.utils.ColorsCache;
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
import net.minecraft.client.render.WorldRenderer;
import net.minecraft.client.render.chunk.ChunkBuilder;
import net.minecraft.client.render.chunk.ChunkRendererRegionBuilder;
import net.minecraft.client.world.ClientWorld;
import org.jetbrains.annotations.Nullable;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

@Mixin(WorldRenderer.class)
public class WorldRendererMixin {
public abstract class WorldRendererMixin implements WorldRendererMixed {

@Shadow @Nullable private ClientWorld world;
@Shadow @Nullable private ChunkBuilder chunkBuilder;

@Shadow @Final private ObjectArrayList<WorldRenderer.ChunkInfo> chunkInfos;

@Inject(at = @At("HEAD"), method = "reload()V")
public void reload(CallbackInfo info) {
ColorsCache.clearCache();
}

@Override
public void reloadOnlyColors() {
if (this.world == null || this.chunkBuilder == null) {
return;
}
this.world.reloadColor();

for (WorldRenderer.ChunkInfo chunkInfo : this.chunkInfos) {
ChunkBuilder.BuiltChunk builtChunk = chunkInfo.chunk;
builtChunk.scheduleRebuild(true);
}
}
}
3 changes: 2 additions & 1 deletion src/main/resources/seasons.accesswidener
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ mutable field net/minecraft/world/biome/Biome$Weather temperature F
accessible field net/minecraft/client/option/KeyBinding boundKey Lnet/minecraft/client/util/InputUtil$Key;
accessible method net/minecraft/world/biome/Biome getTemperature (Lnet/minecraft/util/math/BlockPos;)F
accessible method net/minecraft/client/render/model/json/JsonUnbakedModel$Deserializer resolveReference (Lnet/minecraft/util/Identifier;Ljava/lang/String;)Lcom/mojang/datafixers/util/Either;
mutable field net/minecraft/client/render/model/json/JsonUnbakedModel textureMap Ljava/util/Map;
mutable field net/minecraft/client/render/model/json/JsonUnbakedModel textureMap Ljava/util/Map;
accessible field net/minecraft/client/render/WorldRenderer$ChunkInfo chunk Lnet/minecraft/client/render/chunk/ChunkBuilder$BuiltChunk;