-
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
8bf60ba
commit a4da6d0
Showing
4 changed files
with
124 additions
and
1 deletion.
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
59 changes: 59 additions & 0 deletions
59
src/main/java/net/zepalesque/zenith/api/biometint/BiomeTint.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,59 @@ | ||
package net.zepalesque.zenith.api.biometint; | ||
|
||
import com.mojang.serialization.Codec; | ||
import net.minecraft.core.registries.Registries; | ||
import net.minecraft.resources.ResourceLocation; | ||
import net.minecraft.world.level.biome.Biome; | ||
import net.neoforged.neoforge.registries.datamaps.DataMapType; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Collection; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
public class BiomeTint { | ||
|
||
private final DataMapType<Biome, Integer> dataMap; | ||
private Map<Biome, Integer> tints = null; | ||
private final int defaultColor; | ||
|
||
public static Collection<DataMapType<Biome, Integer>> MAPS = new ArrayList<>(); | ||
|
||
public BiomeTint(ResourceLocation loc, int defaultColor) { | ||
DataMapType<Biome, Integer> dataMap = createTintMap(loc); | ||
MAPS.add(dataMap); | ||
this.dataMap = dataMap; | ||
this.defaultColor = defaultColor; | ||
} | ||
|
||
private static DataMapType<Biome, Integer> createTintMap(ResourceLocation location) { | ||
return DataMapType.builder(location.withPrefix("tint/"), Registries.BIOME, Codec.INT).synced(Codec.INT, true).build(); | ||
} | ||
|
||
public int getColor(Biome biome) { | ||
if (this.tints == null) { | ||
throw new UnsupportedOperationException("Biome tints have not been initialized yet!"); | ||
} else { | ||
return this.tints.getOrDefault(biome, defaultColor); | ||
} | ||
} | ||
|
||
public void clearTints() { | ||
if (this.tints == null) { | ||
this.tints = new HashMap<>(); | ||
} else { | ||
this.tints.clear(); | ||
} | ||
} | ||
public void addTint(Biome biome, int color) { | ||
if (this.tints == null) { | ||
throw new UnsupportedOperationException("Biome tints have not been initialized yet!"); | ||
} else { | ||
this.tints.put(biome, color); | ||
} | ||
} | ||
|
||
public DataMapType<Biome, Integer> getDataMap() { | ||
return this.dataMap; | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
src/main/java/net/zepalesque/zenith/api/biometint/BiomeTints.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,20 @@ | ||
package net.zepalesque.zenith.api.biometint; | ||
|
||
import com.mojang.serialization.Codec; | ||
import net.minecraft.core.Registry; | ||
import net.neoforged.neoforge.registries.DeferredHolder; | ||
import net.neoforged.neoforge.registries.DeferredRegister; | ||
import net.neoforged.neoforge.registries.RegistryBuilder; | ||
import net.zepalesque.zenith.Zenith; | ||
import net.zepalesque.zenith.api.condition.Condition; | ||
import net.zepalesque.zenith.api.condition.ConfigCondition; | ||
|
||
public class BiomeTints { | ||
|
||
public static final DeferredRegister<BiomeTint> TINTS = DeferredRegister.create(Zenith.Keys.BIOME_TINT, Zenith.MODID); | ||
public static final Registry<BiomeTint> TINT_REGISTRY = new RegistryBuilder<>(Zenith.Keys.BIOME_TINT).sync(true).create(); | ||
|
||
public static final DeferredHolder<BiomeTint, BiomeTint> TEST = TINTS.register("test_tint", () -> new BiomeTint(Zenith.loc("test_tint"), 0xFFFFFF)); | ||
|
||
|
||
} |
32 changes: 32 additions & 0 deletions
32
src/main/java/net/zepalesque/zenith/event/listener/BiomeTintListener.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,32 @@ | ||
package net.zepalesque.zenith.event.listener; | ||
|
||
|
||
import net.minecraft.core.Registry; | ||
import net.minecraft.core.registries.Registries; | ||
import net.minecraft.resources.ResourceKey; | ||
import net.minecraft.world.level.biome.Biome; | ||
import net.neoforged.bus.api.SubscribeEvent; | ||
import net.neoforged.fml.common.Mod; | ||
import net.neoforged.neoforge.client.event.ClientPlayerNetworkEvent; | ||
import net.neoforged.neoforge.registries.datamaps.DataMapType; | ||
import net.zepalesque.zenith.Zenith; | ||
import net.zepalesque.zenith.api.biometint.BiomeTints; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
@Mod.EventBusSubscriber(modid = Zenith.MODID) | ||
public class BiomeTintListener { | ||
|
||
@SubscribeEvent | ||
public static void sendColors(ClientPlayerNetworkEvent.LoggingIn event) { | ||
BiomeTints.TINT_REGISTRY.forEach(tint -> { | ||
tint.clearTints(); | ||
Registry<Biome> registry = event.getPlayer().level().registryAccess().registryOrThrow(Registries.BIOME); | ||
for (Map.Entry<ResourceKey<Biome>, Integer> entry : registry.getDataMap(tint.getDataMap()).entrySet()) { | ||
Biome b = registry.get(entry.getKey()); | ||
tint.addTint(b, entry.getValue()); | ||
} | ||
}); | ||
} | ||
} |