Skip to content

Commit

Permalink
Updated to 1.19 + Mixin Organization + Wild Registry Rewrite
Browse files Browse the repository at this point in the history
  • Loading branch information
LudoCrypt committed Jul 23, 2022
1 parent 835c8f8 commit 6a299e7
Show file tree
Hide file tree
Showing 52 changed files with 229 additions and 212 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ satin_version=1.8.0
sodium_version=mc1.19-0.4.2
iris_version=1.19.x-v1.2.5

mod_version = 5.3.1
mod_version = 6.0.0
maven_group = net.ludocrypt
archives_base_name = limlib
4 changes: 2 additions & 2 deletions src/main/java/net/ludocrypt/limlib/LimlibClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import ladysnake.satin.api.event.ShaderEffectRenderCallback;
import net.fabricmc.api.ClientModInitializer;
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents;
import net.ludocrypt.limlib.access.DimensionEffectsAccess;
import net.ludocrypt.limlib.access.DimensionTypeAccess;
import net.ludocrypt.limlib.api.render.LiminalShaderApplier;
import net.ludocrypt.limlib.api.sound.SoundEmitter;
import net.minecraft.block.BlockState;
Expand All @@ -19,7 +19,7 @@ public class LimlibClient implements ClientModInitializer {
public void onInitializeClient() {
ShaderEffectRenderCallback.EVENT.register(tickDelta -> {
MinecraftClient client = MinecraftClient.getInstance();
Optional<LiminalShaderApplier> shader = ((DimensionEffectsAccess) (Object) client.world.getDimension()).getLiminalEffects().getShader();
Optional<LiminalShaderApplier> shader = ((DimensionTypeAccess) (Object) client.world.getDimension()).getLiminalEffects().getShader();
if (shader.isPresent()) {
if (shader.get().shouldRender(client, tickDelta)) {
shader.get().getShader(client, tickDelta).render(tickDelta);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import net.ludocrypt.limlib.api.LiminalEffects;

public interface DimensionEffectsAccess {
public interface DimensionTypeAccess {

public LiminalEffects getLiminalEffects();

Expand Down
37 changes: 15 additions & 22 deletions src/main/java/net/ludocrypt/limlib/api/LiminalEffects.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ public class LiminalEffects {
return liminalEffects.getShader();
}), LiminalSkyRenderer.CODEC.optionalFieldOf("sky").stable().forGetter((liminalEffects) -> {
return liminalEffects.getSky();
}), Codec.FLOAT.optionalFieldOf("sky_shading").stable().forGetter((liminalEffects) -> {
return liminalEffects.getSkyShading();
}), MusicSound.CODEC.optionalFieldOf("music").stable().forGetter((liminalEffects) -> {
return liminalEffects.getMusic();
}), ReverbSettings.CODEC.optionalFieldOf("reverb").stable().forGetter((liminalEffects) -> {
Expand All @@ -30,41 +32,23 @@ public class LiminalEffects {
private Optional<LiminalBaseEffects> effects;
private Optional<LiminalShaderApplier> shader;
private Optional<LiminalSkyRenderer> skyRenderer;
private Optional<Float> skyShading;
private Optional<MusicSound> music;
private Optional<ReverbSettings> reverb;

public LiminalEffects() {
this(Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty());
this(Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty());
}

public LiminalEffects(Optional<LiminalBaseEffects> effects, Optional<LiminalShaderApplier> shader, Optional<LiminalSkyRenderer> skyRenderer, Optional<MusicSound> music, Optional<ReverbSettings> reverb) {
public LiminalEffects(Optional<LiminalBaseEffects> effects, Optional<LiminalShaderApplier> shader, Optional<LiminalSkyRenderer> skyRenderer, Optional<Float> skyShading, Optional<MusicSound> music, Optional<ReverbSettings> reverb) {
this.effects = effects;
this.shader = shader;
this.skyRenderer = skyRenderer;
this.skyShading = skyShading;
this.music = music;
this.reverb = reverb;
}

public void setEffects(Optional<LiminalBaseEffects> effects) {
this.effects = effects;
}

public void setMusic(Optional<MusicSound> music) {
this.music = music;
}

public void setReverb(Optional<ReverbSettings> reverb) {
this.reverb = reverb;
}

public void setShader(Optional<LiminalShaderApplier> shader) {
this.shader = shader;
}

public void setSky(Optional<LiminalSkyRenderer> sky) {
this.skyRenderer = sky;
}

public Optional<LiminalBaseEffects> getEffects() {
return effects;
}
Expand All @@ -85,4 +69,13 @@ public Optional<LiminalSkyRenderer> getSky() {
return skyRenderer;
}

public Optional<Float> getSkyShading() {
return skyShading;
}

@Override
public String toString() {
return "LiminalBaseEffects: " + effects.toString() + ", LiminalShaderApplier: " + shader.toString() + ", LiminalSkyRenderer: " + skyRenderer.toString() + ", SkyShading: " + skyShading.toString() + ", MusicSound: " + music.toString() + ", ReverbSettings: " + reverb.toString();
}

}
45 changes: 21 additions & 24 deletions src/main/java/net/ludocrypt/limlib/api/LiminalWorld.java
Original file line number Diff line number Diff line change
@@ -1,63 +1,60 @@
package net.ludocrypt.limlib.api;

import net.ludocrypt.limlib.access.DimensionEffectsAccess;
import net.minecraft.structure.StructureSet;
import com.google.common.base.Supplier;
import com.google.common.base.Suppliers;

import net.ludocrypt.limlib.access.DimensionTypeAccess;
import net.minecraft.util.Identifier;
import net.minecraft.util.math.noise.DoublePerlinNoiseSampler;
import net.minecraft.util.registry.Registry;
import net.minecraft.util.registry.RegistryKey;
import net.minecraft.world.World;
import net.minecraft.world.biome.Biome;
import net.minecraft.world.dimension.DimensionOptions;
import net.minecraft.world.dimension.DimensionType;
import net.minecraft.world.gen.chunk.ChunkGeneratorSettings;

public class LiminalWorld {

private final Identifier identifier;
private final DimensionType dimensionType;
private final DimensionOptionsGetter dimensionOptionsGetter;
private final LiminalEffects liminalEffects;
private final Supplier<DimensionType> dimensionType;
private final Supplier<DimensionOptions> dimensionOptions;

public LiminalWorld(Identifier identifier, DimensionType dimensionType, DimensionOptionsGetter dimensionOptionsGetter, LiminalEffects liminalEffects) {
public LiminalWorld(Identifier identifier, LiminalEffects liminalEffects, Supplier<DimensionType> dimensionType, Supplier<DimensionOptions> dimensionOptions) {
this.identifier = identifier;
this.dimensionType = dimensionType;
this.dimensionOptionsGetter = dimensionOptionsGetter;
this.liminalEffects = liminalEffects;
((DimensionEffectsAccess) (Object) this.dimensionType).setLiminalEffects(liminalEffects);
this.dimensionType = Suppliers.memoize(() -> {
DimensionType type = dimensionType.get();
((DimensionTypeAccess) (Object) type).setLiminalEffects(liminalEffects);
return type;
});
this.dimensionOptions = Suppliers.memoize(dimensionOptions);
}

public Identifier getIdentifier() {
return identifier;
return this.identifier;
}

public RegistryKey<DimensionType> getDimensionTypeKey() {
return RegistryKey.of(Registry.DIMENSION_TYPE_KEY, identifier);
return RegistryKey.of(Registry.DIMENSION_TYPE_KEY, this.identifier);
}

public RegistryKey<DimensionOptions> getDimensionKey() {
return RegistryKey.of(Registry.DIMENSION_KEY, identifier);
return RegistryKey.of(Registry.DIMENSION_KEY, this.identifier);
}

public RegistryKey<World> getWorldKey() {
return RegistryKey.of(Registry.WORLD_KEY, identifier);
return RegistryKey.of(Registry.WORLD_KEY, this.identifier);
}

public DimensionType getDimensionType() {
return dimensionType;
return this.dimensionType.get();
}

public DimensionOptionsGetter getDimensionOptionsGetter() {
return dimensionOptionsGetter;
public DimensionOptions getDimensionOptions() {
return this.dimensionOptions.get();
}

public LiminalEffects getLiminalEffects() {
return liminalEffects;
}

@FunctionalInterface
public static interface DimensionOptionsGetter {
public DimensionOptions get(LiminalWorld world, Registry<DimensionType> dimensionTypeRegistry, Registry<Biome> biomeRegistry, Registry<StructureSet> structureSetRegistry, Registry<ChunkGeneratorSettings> chunkGeneratorSettingsRegistry, Registry<DoublePerlinNoiseSampler.NoiseParameters> noiseParametersRegistry);
return this.liminalEffects;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.ludocrypt.limlib.access.DimensionEffectsAccess;
import net.ludocrypt.limlib.access.DimensionTypeAccess;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.sound.SoundInstance;
import net.minecraft.util.math.MathHelper;
Expand Down Expand Up @@ -60,7 +60,7 @@ public static void update(SoundInstance soundInstance, int sourceID) {
MinecraftClient client = MinecraftClient.getInstance();

if (!(ReverbSettings.shouldIgnore(soundInstance.getId()) || client == null || client.world == null)) {
Optional<ReverbSettings> reverb = ((DimensionEffectsAccess) (Object) client.world.getDimension()).getLiminalEffects().getReverb();
Optional<ReverbSettings> reverb = ((DimensionTypeAccess) (Object) client.world.getDimension()).getLiminalEffects().getReverb();
if (reverb.isPresent()) {
for (int i = 0; i < 2; i++) {
AL11.alSourcei(sourceID, EXTEfx.AL_DIRECT_FILTER, 0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import java.util.HashMap;
import java.util.Optional;

import net.ludocrypt.limlib.mixin.BlockEntityAccessor;
import net.ludocrypt.limlib.mixin.common.BlockEntityAccessor;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
Expand Down

This file was deleted.

22 changes: 0 additions & 22 deletions src/main/java/net/ludocrypt/limlib/mixin/RegistryOpsMixin.java

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package net.ludocrypt.limlib.mixin;
package net.ludocrypt.limlib.mixin.client;

import java.util.Optional;

Expand All @@ -8,7 +8,7 @@
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

import net.ludocrypt.limlib.access.DimensionEffectsAccess;
import net.ludocrypt.limlib.access.DimensionTypeAccess;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.network.ClientPlayerEntity;
import net.minecraft.client.world.ClientWorld;
Expand All @@ -26,7 +26,7 @@ public class MinecraftClientMixin {
@Inject(method = "getMusicType", at = @At("HEAD"), cancellable = true)
private void limlib$getMusicType(CallbackInfoReturnable<MusicSound> ci) {
if (this.player != null) {
Optional<MusicSound> optional = ((DimensionEffectsAccess) (Object) this.world.getDimension()).getLiminalEffects().getMusic();
Optional<MusicSound> optional = ((DimensionTypeAccess) (Object) this.world.getDimension()).getLiminalEffects().getMusic();
if (optional.isPresent()) {
ci.setReturnValue(optional.get());
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package net.ludocrypt.limlib.mixin.client.render;

import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.ModifyVariable;

import net.ludocrypt.limlib.access.DimensionTypeAccess;
import net.ludocrypt.limlib.api.LiminalEffects;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.render.BackgroundRenderer;

@Mixin(BackgroundRenderer.class)
public abstract class BackgroundRendererMixin {

@ModifyVariable(method = "render", at = @At(value = "STORE", ordinal = 4), ordinal = 2)
private static float corners$modifySkyColor(float in) {
MinecraftClient client = MinecraftClient.getInstance();

LiminalEffects effects = ((DimensionTypeAccess) (Object) client.world.getDimension()).getLiminalEffects();

if (effects.getSkyShading().isPresent()) {
return effects.getSkyShading().get();
}

return 1.0F;
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package net.ludocrypt.limlib.mixin;
package net.ludocrypt.limlib.mixin.client.render;

import java.util.Optional;
import java.util.function.Function;
Expand All @@ -11,7 +11,7 @@

import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.ludocrypt.limlib.access.DimensionEffectsAccess;
import net.ludocrypt.limlib.access.DimensionTypeAccess;
import net.ludocrypt.limlib.api.render.LiminalBaseEffects;
import net.minecraft.client.render.DimensionEffects;
import net.minecraft.util.Util;
Expand All @@ -22,7 +22,7 @@
public class DimensionEffectsMixin {

@Unique
private static Function<DimensionType, Optional<DimensionEffects>> limlibEffects = Util.memoize((type) -> ((DimensionEffectsAccess) (Object) type).getLiminalEffects().getEffects().map(LiminalBaseEffects::getDimensionEffects));
private static Function<DimensionType, Optional<DimensionEffects>> limlibEffects = Util.memoize((type) -> ((DimensionTypeAccess) (Object) type).getLiminalEffects().getEffects().map(LiminalBaseEffects::getDimensionEffects));

@Inject(method = "byDimensionType", at = @At("HEAD"), cancellable = true)
private static void limlib$byDimensionType(DimensionType dimensionType, CallbackInfoReturnable<DimensionEffects> ci) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package net.ludocrypt.limlib.mixin;
package net.ludocrypt.limlib.mixin.client.render;

import java.io.IOException;
import java.util.List;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package net.ludocrypt.limlib.mixin;
package net.ludocrypt.limlib.mixin.client.render;

import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package net.ludocrypt.limlib.mixin;
package net.ludocrypt.limlib.mixin.client.render;

import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
Expand Down
Loading

0 comments on commit 6a299e7

Please sign in to comment.