-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fancy wrapping logic to not make level files incompatible
- Loading branch information
1 parent
17fd513
commit 600a955
Showing
8 changed files
with
161 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
src/main/java/dev/lukebemish/biomesquisher/impl/injected/KnowsOriginalKey.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package dev.lukebemish.biomesquisher.impl.injected; | ||
|
||
import net.minecraft.resources.ResourceKey; | ||
import net.minecraft.world.level.levelgen.NoiseGeneratorSettings; | ||
|
||
public interface KnowsOriginalKey { | ||
ResourceKey<NoiseGeneratorSettings> biomesquisher_generatorKey(); | ||
void biomesquisher_generatorKey(ResourceKey<NoiseGeneratorSettings> key); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
src/main/java/dev/lukebemish/biomesquisher/impl/mixin/NoiseGeneratorSettingsMixin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package dev.lukebemish.biomesquisher.impl.mixin; | ||
|
||
import com.llamalad7.mixinextras.injector.ModifyExpressionValue; | ||
import com.mojang.serialization.Codec; | ||
import dev.lukebemish.biomesquisher.impl.WrappingRuleSource; | ||
import dev.lukebemish.biomesquisher.impl.injected.KnowsOriginalKey; | ||
import net.minecraft.resources.ResourceKey; | ||
import net.minecraft.world.level.levelgen.NoiseGeneratorSettings; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.Unique; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
|
||
@Mixin(NoiseGeneratorSettings.class) | ||
public class NoiseGeneratorSettingsMixin implements KnowsOriginalKey { | ||
@Unique | ||
private ResourceKey<NoiseGeneratorSettings> biomesquisher_generatorKey; | ||
|
||
@Override | ||
public ResourceKey<NoiseGeneratorSettings> biomesquisher_generatorKey() { | ||
return biomesquisher_generatorKey; | ||
} | ||
|
||
@Override | ||
public synchronized void biomesquisher_generatorKey(ResourceKey<NoiseGeneratorSettings> key) { | ||
this.biomesquisher_generatorKey = key; | ||
} | ||
|
||
@ModifyExpressionValue( | ||
method = "<clinit>()V", | ||
at = @At( | ||
value = "INVOKE", | ||
target = "Lcom/mojang/serialization/codecs/RecordCodecBuilder;create(Ljava/util/function/Function;)Lcom/mojang/serialization/Codec;" | ||
) | ||
) | ||
private static Codec<NoiseGeneratorSettings> biome_squisher$wrapCodec(Codec<NoiseGeneratorSettings> original) { | ||
return WrappingRuleSource.wrap(original); | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
src/main/java/dev/lukebemish/biomesquisher/impl/mixin/RuleSourceMixin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package dev.lukebemish.biomesquisher.impl.mixin; | ||
|
||
import com.llamalad7.mixinextras.injector.ModifyExpressionValue; | ||
import com.mojang.datafixers.util.Pair; | ||
import com.mojang.serialization.Codec; | ||
import com.mojang.serialization.DataResult; | ||
import com.mojang.serialization.DynamicOps; | ||
import dev.lukebemish.biomesquisher.impl.WrappingRuleSource; | ||
import net.minecraft.world.level.levelgen.SurfaceRules; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
|
||
@Mixin(SurfaceRules.RuleSource.class) | ||
public interface RuleSourceMixin { | ||
@ModifyExpressionValue( | ||
method = "<clinit>()V", | ||
at = @At( | ||
value = "INVOKE", | ||
target = "Lcom/mojang/serialization/Codec;dispatch(Ljava/util/function/Function;Ljava/util/function/Function;)Lcom/mojang/serialization/Codec;" | ||
) | ||
) | ||
private static Codec<SurfaceRules.RuleSource> biome_squisher$wrapCodec(Codec<SurfaceRules.RuleSource> original) { | ||
return new Codec<>() { | ||
@Override | ||
public <T> DataResult<Pair<SurfaceRules.RuleSource, T>> decode(DynamicOps<T> ops, T input) { | ||
return original.decode(ops, input); | ||
} | ||
|
||
@Override | ||
public <T> DataResult<T> encode(SurfaceRules.RuleSource input, DynamicOps<T> ops, T prefix) { | ||
if (input instanceof WrappingRuleSource wrapped) { | ||
if (ops instanceof WrappingRuleSource.NotifyingOps notifying) { | ||
notifying.wrapped(wrapped); | ||
} | ||
return encode(wrapped.delegate(), ops, prefix); | ||
} | ||
return original.encode(input, ops, prefix); | ||
} | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters