-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
dcb2177
commit 9f3da36
Showing
10 changed files
with
136 additions
and
48 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
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
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
14 changes: 14 additions & 0 deletions
14
src/main/java/net/zepalesque/zenith/util/codec/ZenithCodecs.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,14 @@ | ||
package net.zepalesque.zenith.util.codec; | ||
|
||
import com.mojang.serialization.Codec; | ||
import net.minecraft.core.Holder; | ||
import net.minecraft.util.ExtraCodecs; | ||
import net.minecraft.world.level.biome.Biome; | ||
|
||
import java.util.Map; | ||
|
||
public class ZenithCodecs { | ||
|
||
public static final Codec<Map<Holder<Biome>, Integer>> BIOME_COLOR_MAP = ExtraCodecs.strictUnboundedMap(Biome.CODEC, Codec.INT); | ||
|
||
} |
70 changes: 70 additions & 0 deletions
70
src/main/java/net/zepalesque/zenith/world/biome/modifier/BiomeTintMapModifier.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,70 @@ | ||
package net.zepalesque.zenith.world.biome.modifier; | ||
|
||
import com.mojang.serialization.Codec; | ||
import com.mojang.serialization.codecs.RecordCodecBuilder; | ||
import net.minecraft.core.Holder; | ||
import net.minecraft.core.HolderSet; | ||
import net.minecraft.resources.ResourceKey; | ||
import net.minecraft.sounds.Music; | ||
import net.minecraft.sounds.SoundEvent; | ||
import net.minecraft.world.level.biome.Biome; | ||
import net.neoforged.neoforge.common.world.BiomeModifier; | ||
import net.neoforged.neoforge.common.world.ModifiableBiomeInfo; | ||
import net.zepalesque.zenith.api.biometint.BiomeTint; | ||
import net.zepalesque.zenith.api.biometint.BiomeTints; | ||
import net.zepalesque.zenith.util.codec.ZenithCodecs; | ||
import net.zepalesque.zenith.util.predicate.MusicPredicate; | ||
|
||
import javax.annotation.ParametersAreNonnullByDefault; | ||
import java.util.Map; | ||
import java.util.Optional; | ||
import java.util.function.UnaryOperator; | ||
|
||
public record BiomeTintMapModifier(Holder<BiomeTint> tintHolder, Map<Holder<Biome>, Integer> colors, Optional<Integer> defaultOverride) implements BiomeModifier { | ||
|
||
|
||
public static final Codec<BiomeTintMapModifier> CODEC = RecordCodecBuilder.create(builder -> builder.group( | ||
BiomeTints.TINT_REGISTRY.holderByNameCodec().fieldOf("tint_id").forGetter(BiomeTintMapModifier::tintHolder), | ||
ZenithCodecs.BIOME_COLOR_MAP.fieldOf("colors").forGetter(BiomeTintMapModifier::colors), | ||
Codec.INT.optionalFieldOf("default_color_override").forGetter(BiomeTintMapModifier::defaultOverride)).apply(builder, BiomeTintMapModifier::new)); | ||
|
||
|
||
@Override | ||
@ParametersAreNonnullByDefault | ||
public void modify(Holder<Biome> biome, Phase phase, ModifiableBiomeInfo.BiomeInfo.Builder builder) { | ||
if (phase == Phase.AFTER_EVERYTHING && this.colors.containsKey(biome) && this.tintHolder.isBound()) { | ||
BiomeTint tint = this.tintHolder.value(); | ||
tint. | ||
} | ||
} | ||
|
||
@Override | ||
public Codec<? extends BiomeModifier> codec() { | ||
return CODEC; | ||
} | ||
|
||
public record MusicOperator(Optional<Holder<SoundEvent>> sound, Optional<Integer> minDelay, Optional<Integer> maxDelay, Optional<Boolean> replaceCurrent) implements UnaryOperator<Music> { | ||
|
||
public static final Codec<MusicOperator> CODEC = RecordCodecBuilder.create(builder -> builder.group( | ||
SoundEvent.CODEC.optionalFieldOf("sound").forGetter(MusicOperator::sound), | ||
Codec.INT.optionalFieldOf("min_delay").forGetter(MusicOperator::minDelay), | ||
Codec.INT.optionalFieldOf("max_delay").forGetter(MusicOperator::maxDelay), | ||
Codec.BOOL.optionalFieldOf("replace_current").forGetter(MusicOperator::replaceCurrent)).apply(builder, MusicOperator::new)); | ||
|
||
@Override | ||
public Music apply(Music music) { | ||
if (sound.isEmpty() && minDelay.isEmpty() && maxDelay.isEmpty() && replaceCurrent.isEmpty()) { | ||
return music; | ||
} | ||
Holder<SoundEvent> soundEvent = music.getEvent(); | ||
int minimum = music.getMinDelay(); | ||
int maximum = music.getMaxDelay(); | ||
boolean replace = music.replaceCurrentMusic(); | ||
if (sound.isPresent()) { soundEvent = sound.get(); } | ||
if (minDelay.isPresent()) { minimum = minDelay.get(); } | ||
if (maxDelay.isPresent()) { maximum = maxDelay.get(); } | ||
if (replaceCurrent.isPresent()) { replace = replaceCurrent.get(); } | ||
return new Music(soundEvent, minimum, maximum, replace); | ||
} | ||
} | ||
} |
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
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