mirror of
https://gitlab.com/cable-mc/cobblemon.git
synced 2026-11-16 13:18:53 -05:00
Compare commits
34
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
433a66124b | ||
|
|
4209ca3845 | ||
|
|
6edd81c0f5 | ||
|
|
7939b4ca71 | ||
|
|
0cc22b6675 | ||
|
|
0405eea167 | ||
|
|
17d07774d2 | ||
|
|
d71373c237 | ||
|
|
fc2335f5d5 | ||
|
|
7d8329b311 | ||
|
|
9b46757d14 | ||
|
|
fe5970180d | ||
|
|
89b81d6882 | ||
|
|
2eb6042d06 | ||
|
|
5ec2fc7937 | ||
|
|
f57093b835 | ||
|
|
03bb782dc4 | ||
|
|
d296fa81dc | ||
|
|
1621bada06 | ||
|
|
873ccc8109 | ||
|
|
eb4257cc26 | ||
|
|
dfcb988f1e | ||
|
|
2ca2a77333 | ||
|
|
b468e4eb6c | ||
|
|
c39397413f | ||
|
|
b3fe03194a | ||
|
|
d2eafe7b41 | ||
|
|
7f78c15f6b | ||
|
|
0cd1f8a2fd | ||
|
|
d6c2da3d90 | ||
|
|
ba84883eae | ||
|
|
fcfdfb270d | ||
|
|
96d1d9d552 | ||
|
|
0d1de548a0 |
No files matched your search
@@ -0,0 +1,18 @@
|
||||
/*
|
||||
* Copyright (C) 2023 Cobblemon Contributors
|
||||
*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
package com.cobblemon.mod.common.duck.biome;
|
||||
|
||||
import net.minecraft.core.Holder;
|
||||
import net.minecraft.world.level.biome.Biome;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface BiomeSourceDuck {
|
||||
void addPossibleBiomes(List<Holder<Biome>> biomes);
|
||||
}
|
||||
@@ -8,14 +8,21 @@
|
||||
|
||||
package com.cobblemon.mod.common.mixin;
|
||||
|
||||
import com.cobblemon.mod.common.Cobblemon;
|
||||
import com.cobblemon.mod.common.duck.MinecraftServerDuck;
|
||||
import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
|
||||
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation;
|
||||
import net.minecraft.core.LayeredRegistryAccess;
|
||||
import net.minecraft.core.RegistryAccess;
|
||||
import net.minecraft.resources.ResourceKey;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.server.RegistryLayer;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.world.level.Level;
|
||||
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 java.util.Map;
|
||||
import java.util.Optional;
|
||||
@@ -23,18 +30,41 @@ import java.util.Optional;
|
||||
@Mixin(MinecraftServer.class)
|
||||
public class MinecraftServerMixin implements MinecraftServerDuck {
|
||||
|
||||
@Shadow
|
||||
@Final
|
||||
private Map<ResourceKey<Level>, ServerLevel> levels;
|
||||
@Shadow
|
||||
@Final
|
||||
private Map<ResourceKey<Level>, ServerLevel> levels;
|
||||
|
||||
@Override
|
||||
public Optional<ResourceKey<Level>> cobblemon$getLevelKey(final Level level) {
|
||||
return this.levels.entrySet()
|
||||
.stream()
|
||||
// Reference equality is intended here, the level we're handed is the same one as in the
|
||||
// map so we don't need to check value semantics.
|
||||
.filter(entry -> entry.getValue() == level)
|
||||
.map(Map.Entry::getKey)
|
||||
.findFirst();
|
||||
}
|
||||
@Override
|
||||
public Optional<ResourceKey<Level>> cobblemon$getLevelKey(final Level level) {
|
||||
return this.levels.entrySet()
|
||||
.stream()
|
||||
// Reference equality is intended here, the level we're handed is the same one as in the
|
||||
// map so we don't need to check value semantics.
|
||||
.filter(entry -> entry.getValue() == level)
|
||||
.map(Map.Entry::getKey)
|
||||
.findFirst();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Wraps the earliest {@code compositeAccess()} call in {@link MinecraftServer}'s constructor
|
||||
* so Cobblemon can capture the server registry access as soon as it exists.
|
||||
*
|
||||
* <p>This sets {@link Cobblemon#registryAccess} before downstream initialization
|
||||
* depends on biome lookups, while still delegating to the original call unchanged.</p>
|
||||
*
|
||||
* @author MeAlam
|
||||
* @since April 9th 2026
|
||||
*/
|
||||
@WrapOperation(method = "<init>", at = @At(
|
||||
value = "INVOKE",
|
||||
target = "Lnet/minecraft/core/LayeredRegistryAccess;compositeAccess()Lnet/minecraft/core/RegistryAccess$Frozen;",
|
||||
ordinal = 0
|
||||
))
|
||||
private RegistryAccess.Frozen cobblemon$captureRegistryAccess
|
||||
(LayeredRegistryAccess<RegistryLayer> instance, Operation<RegistryAccess.Frozen> original) {
|
||||
Cobblemon.registryAccess = instance.compositeAccess();
|
||||
|
||||
return original.call(instance);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
/*
|
||||
* Copyright (C) 2023 Cobblemon Contributors
|
||||
*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
package com.cobblemon.mod.common.mixin.biome;
|
||||
|
||||
|
||||
import net.minecraft.data.worldgen.BootstrapContext;
|
||||
import net.minecraft.data.worldgen.biome.BiomeData;
|
||||
import net.minecraft.world.level.biome.Biome;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
/**
|
||||
* TODO (MeAlam):<br>
|
||||
* This mixin is currently disabled, as it does not appear to be required at this time.
|
||||
* It is retained for potential future use if biome registration issues arise.
|
||||
*
|
||||
* <p>
|
||||
* When enabled, this mixin registers biomes into the bootstrap context
|
||||
* of Minecraft's {@code BiomeData} class.
|
||||
* </p>
|
||||
*
|
||||
* <p>
|
||||
* Example usage:
|
||||
* <pre>{@code
|
||||
* context.register(MY_BIOME_KEY, createMyBiome());
|
||||
*
|
||||
* // e.g.
|
||||
* context.register(
|
||||
* CobblemonBiomes.TEST_BIOME,
|
||||
* CobblemonBiomes.createTestBiome()
|
||||
* );
|
||||
* }</pre>
|
||||
*
|
||||
* @author MeAlam
|
||||
* @since April 9th 2026
|
||||
*/
|
||||
@Mixin(BiomeData.class)
|
||||
public class BiomeDataMixin {
|
||||
@Inject(method = "bootstrap", at = @At("TAIL"))
|
||||
private static void cobblemon$registerBiomes(BootstrapContext<Biome> context, CallbackInfo ci) {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
/*
|
||||
* Copyright (C) 2023 Cobblemon Contributors
|
||||
*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
package com.cobblemon.mod.common.mixin.biome;
|
||||
|
||||
import com.cobblemon.mod.common.duck.biome.BiomeSourceDuck;
|
||||
import it.unimi.dsi.fastutil.objects.ObjectLinkedOpenHashSet;
|
||||
import net.minecraft.core.Holder;
|
||||
import net.minecraft.world.level.biome.Biome;
|
||||
import net.minecraft.world.level.biome.BiomeResolver;
|
||||
import net.minecraft.world.level.biome.BiomeSource;
|
||||
import org.spongepowered.asm.mixin.Final;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Mutable;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.function.Supplier;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* TODO (MeAlam):<br>
|
||||
* This mixin is currently disabled, as it does not appear to be required at this time.
|
||||
* It is retained for potential future use if biome injection becomes necessary.
|
||||
*
|
||||
* <p>
|
||||
* When enabled, this mixin extends the {@code BiomeSource} by modifying the
|
||||
* {@code possibleBiomes} supplier to include additional biomes at runtime.
|
||||
* It merges existing biomes with new ones while ensuring uniqueness.
|
||||
* </p>
|
||||
*
|
||||
* <p>
|
||||
* Example usage:
|
||||
* <pre>{@code
|
||||
* ((BiomeSourceDuck) biomeSource).addPossibleBiomes(List.of(
|
||||
* biomeHolderA,
|
||||
* biomeHolderB
|
||||
* ));
|
||||
*
|
||||
* // Existing and new biomes are merged with duplicates removed.
|
||||
* }</pre>
|
||||
*
|
||||
* @author MeAlam
|
||||
* @since April 9th 2026
|
||||
*/
|
||||
@Mixin(BiomeSource.class)
|
||||
public abstract class BiomeSourceMixin implements BiomeResolver, BiomeSourceDuck {
|
||||
@Mutable
|
||||
@Final
|
||||
@Shadow
|
||||
private Supplier<Set<Holder<Biome>>> possibleBiomes;
|
||||
|
||||
@Override
|
||||
public void addPossibleBiomes(List<Holder<Biome>> biomes) {
|
||||
List<Holder<Biome>> combined = new ArrayList<>();
|
||||
combined.addAll(this.possibleBiomes.get());
|
||||
combined.addAll(biomes);
|
||||
|
||||
this.possibleBiomes = () -> new ObjectLinkedOpenHashSet<>(combined.stream().distinct().collect(Collectors.toList()));
|
||||
}
|
||||
}
|
||||
+123
@@ -0,0 +1,123 @@
|
||||
/*
|
||||
* Copyright (C) 2023 Cobblemon Contributors
|
||||
*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
package com.cobblemon.mod.common.mixin.biome;
|
||||
|
||||
import com.cobblemon.mod.common.Cobblemon;
|
||||
import com.cobblemon.mod.common.util.biome.RegistryExtensions;
|
||||
import com.cobblemon.mod.common.world.biome.CobblemonBiome;
|
||||
import com.cobblemon.mod.common.world.biome.CobblemonBiomeLoader;
|
||||
import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
|
||||
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation;
|
||||
import com.mojang.datafixers.util.Either;
|
||||
import com.mojang.datafixers.util.Pair;
|
||||
import net.minecraft.core.Holder;
|
||||
import net.minecraft.core.HolderGetter;
|
||||
import net.minecraft.core.RegistryAccess;
|
||||
import net.minecraft.core.registries.Registries;
|
||||
import net.minecraft.resources.ResourceKey;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.world.level.biome.*;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
import org.spongepowered.asm.mixin.Unique;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.function.Function;
|
||||
|
||||
/**
|
||||
* Ensures compatibility with Biolith by applying this mixin before its biome modifications.
|
||||
*
|
||||
* <p>
|
||||
* Biolith uses mixins (see
|
||||
* <a href="https://github.com/TerraformersMC/Biolith/blob/1.21.1/common/src/main/java/com/terraformersmc/biolith/impl/mixin/MixinMultiNoiseBiomeSource.java">
|
||||
* MixinMultiNoiseBiomeSource
|
||||
* </a>)
|
||||
* with a priority of {@code 900}, allowing it to run before Terrablender.
|
||||
* </p>
|
||||
*
|
||||
* <p>
|
||||
* Because Biolith includes functionality to disable vanilla biomes, this mixin must
|
||||
* execute before Biolith’s transformations to ensure compatibility and prevent
|
||||
* unintended biome removal or conflicts.
|
||||
* </p>
|
||||
*
|
||||
* @author MeAlam
|
||||
* @since April 9th 2026
|
||||
*/
|
||||
@Mixin(value = MultiNoiseBiomeSource.class, priority = 850)
|
||||
public abstract class MultiNoiseBiomeSourceMixin extends BiomeSource {
|
||||
|
||||
@Shadow
|
||||
protected abstract Climate.ParameterList<Holder<Biome>> parameters();
|
||||
|
||||
@Unique
|
||||
private Climate.ParameterList<Holder.Reference<Biome>> cobblemon$parameters;
|
||||
|
||||
@WrapOperation(
|
||||
method = "parameters",
|
||||
at = @At(value = "INVOKE", target = "Lcom/mojang/datafixers/util/Either;map(Ljava/util/function/Function;Ljava/util/function/Function;)Ljava/lang/Object;"),
|
||||
remap = false
|
||||
)
|
||||
private Object cobblemon$injectBiomes(
|
||||
Either<Climate.ParameterList<RegistryAccess.RegistryEntry<Biome>>,
|
||||
RegistryAccess.RegistryEntry<MultiNoiseBiomeSourceParameterList>> instance,
|
||||
Function<Climate.ParameterList<RegistryAccess.RegistryEntry<Biome>>,
|
||||
Climate.ParameterList<RegistryAccess.RegistryEntry<Biome>>> leftMap,
|
||||
Function<RegistryAccess.RegistryEntry<MultiNoiseBiomeSourceParameterList>,
|
||||
Climate.ParameterList<RegistryAccess.RegistryEntry<Biome>>> rightMap,
|
||||
Operation<Object> original) {
|
||||
synchronized (this) {
|
||||
if (cobblemon$parameters == null) {
|
||||
/* NOTE:
|
||||
* Minecraft also does this exact cast on the return of this operation, so we know it's safe.
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
Climate.ParameterList<Holder.Reference<Biome>> originalEntries =
|
||||
(Climate.ParameterList<Holder.Reference<Biome>>) original.call(instance, leftMap, rightMap);
|
||||
|
||||
Map<ResourceLocation, CobblemonBiome> loadedBiomes = CobblemonBiomeLoader.getLoadedBiomes();
|
||||
List<Pair<Climate.ParameterPoint, Holder.Reference<Biome>>> parameterList =
|
||||
new ArrayList<>(originalEntries.values().size() + loadedBiomes.size());
|
||||
parameterList.addAll(originalEntries.values());
|
||||
|
||||
HolderGetter<Biome> biomeEntryGetter = RegistryExtensions.getRegistryLookup(Registries.BIOME).orElseThrow();
|
||||
int appended = 0;
|
||||
int skipped = 0;
|
||||
|
||||
for (Map.Entry<ResourceLocation, CobblemonBiome> loadedEntry : loadedBiomes.entrySet()) {
|
||||
ResourceKey<Biome> biomeKey = ResourceKey.create(Registries.BIOME, loadedEntry.getKey());
|
||||
Optional<Holder.Reference<Biome>> biomeHolder = biomeEntryGetter.get(biomeKey);
|
||||
|
||||
if (biomeHolder.isEmpty()) {
|
||||
skipped++;
|
||||
Cobblemon.LOGGER.warn("MEALAM Skipping cobblemon biome climate entry for missing biome {}", loadedEntry.getKey());
|
||||
continue;
|
||||
}
|
||||
|
||||
parameterList.add(new Pair<>(loadedEntry.getValue().getParameters(), biomeHolder.get()));
|
||||
appended++;
|
||||
}
|
||||
|
||||
Cobblemon.LOGGER.info(
|
||||
"MEALAM Biome source climate entries: base={}, appended={}, skipped={}.",
|
||||
originalEntries.values().size(),
|
||||
appended,
|
||||
skipped
|
||||
);
|
||||
|
||||
cobblemon$parameters = new Climate.ParameterList<>(parameterList);
|
||||
}
|
||||
return cobblemon$parameters;
|
||||
}
|
||||
}
|
||||
}
|
||||
+67
@@ -0,0 +1,67 @@
|
||||
/*
|
||||
* Copyright (C) 2023 Cobblemon Contributors
|
||||
*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
package com.cobblemon.mod.common.mixin.biome;
|
||||
|
||||
import com.cobblemon.mod.common.Cobblemon;
|
||||
import com.cobblemon.mod.common.CobblemonBiomes;
|
||||
import com.cobblemon.mod.common.world.biome.CobblemonBiomeLoader;
|
||||
import com.mojang.serialization.Decoder;
|
||||
import net.minecraft.core.WritableRegistry;
|
||||
import net.minecraft.core.registries.Registries;
|
||||
import net.minecraft.resources.RegistryDataLoader;
|
||||
import net.minecraft.resources.RegistryOps;
|
||||
import net.minecraft.resources.ResourceKey;
|
||||
import net.minecraft.server.packs.resources.ResourceManager;
|
||||
import net.minecraft.world.level.biome.Biome;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Registers Cobblemon biomes during datapack registry loading.
|
||||
*
|
||||
* <p>Injected into {@link RegistryDataLoader} at the tail of
|
||||
* {@code loadContentsFromManager}.</p>
|
||||
*
|
||||
* <p>At this point, vanilla biome JSON has already been decoded, but registries are not frozen
|
||||
* yet, making this the safest point to add biome entries.</p>
|
||||
*
|
||||
* <p>Only applies when the currently loaded registry is {@link Registries#BIOME}.</p>
|
||||
*
|
||||
* @author MeAlam
|
||||
* @since April 9th 2026
|
||||
*/
|
||||
@Mixin(RegistryDataLoader.class)
|
||||
public class RegistryDataLoaderMixin {
|
||||
@Inject(method = "loadContentsFromManager", at = @At("TAIL"))
|
||||
private static <E> void cobblemon$registerBiomes(
|
||||
ResourceManager resourceManager,
|
||||
RegistryOps.RegistryInfoLookup registryInfoLookup,
|
||||
WritableRegistry<E> registry,
|
||||
Decoder<E> codec,
|
||||
Map<ResourceKey<?>, Exception> loadingErrors,
|
||||
CallbackInfo ci
|
||||
) {
|
||||
if (!registry.key().equals(Registries.BIOME)) {
|
||||
return;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
WritableRegistry<Biome> biomeRegistry = (WritableRegistry<Biome>) registry;
|
||||
|
||||
CobblemonBiomes.register(
|
||||
CobblemonBiomeLoader.load(resourceManager, registryInfoLookup)
|
||||
);
|
||||
CobblemonBiomes.INSTANCE.setRegistry(biomeRegistry);
|
||||
Cobblemon.implementation.registerBiomes();
|
||||
}
|
||||
}
|
||||
@@ -137,6 +137,7 @@ import kotlin.reflect.jvm.isAccessible
|
||||
import kotlin.reflect.jvm.javaField
|
||||
import net.minecraft.client.Minecraft
|
||||
import net.minecraft.commands.synchronization.SingletonArgumentInfo
|
||||
import net.minecraft.core.RegistryAccess
|
||||
import net.minecraft.resources.ResourceKey
|
||||
import net.minecraft.resources.ResourceLocation
|
||||
import net.minecraft.server.level.ServerPlayer
|
||||
@@ -182,7 +183,10 @@ object Cobblemon {
|
||||
var seasonResolver: SeasonResolver = TagSeasonResolver
|
||||
var wallpapers = mutableMapOf<UUID, Set<ResourceLocation>>()
|
||||
|
||||
val serverPlayerStructs = mutableMapOf<UUID, ObjectValue<Player>>()
|
||||
@JvmField
|
||||
var registryAccess: RegistryAccess.Frozen = RegistryAccess.EMPTY
|
||||
|
||||
val serverPlayerStructs = mutableMapOf<UUID, ObjectValue<Player>>()
|
||||
|
||||
val statistics: CobblemonStats = CobblemonStats
|
||||
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
* Copyright (C) 2023 Cobblemon Contributors
|
||||
*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
package com.cobblemon.mod.common
|
||||
|
||||
import com.cobblemon.mod.common.platform.PlatformRegistry
|
||||
import com.cobblemon.mod.common.world.biome.CobblemonBiome
|
||||
import com.cobblemon.mod.common.util.cobblemonResource
|
||||
import net.minecraft.core.Registry
|
||||
import net.minecraft.core.registries.Registries
|
||||
import net.minecraft.resources.ResourceKey
|
||||
import net.minecraft.resources.ResourceLocation
|
||||
import net.minecraft.world.level.biome.Biome
|
||||
|
||||
object CobblemonBiomes : PlatformRegistry<Registry<Biome>, ResourceKey<Registry<Biome>>, Biome>() {
|
||||
override var registry: Registry<Biome>? = null
|
||||
override val resourceKey: ResourceKey<Registry<Biome>> = Registries.BIOME
|
||||
|
||||
@JvmField
|
||||
val TEST_BIOME: ResourceKey<Biome> = registerKey("test_biome")
|
||||
|
||||
@JvmStatic
|
||||
fun register(data: Map<ResourceLocation, CobblemonBiome>) {
|
||||
data.forEach { (identifier, cobblemonBiome) ->
|
||||
create(identifier, cobblemonBiome.biome)
|
||||
}
|
||||
}
|
||||
|
||||
private fun registerKey(key: String): ResourceKey<Biome> {
|
||||
return ResourceKey.create(Registries.BIOME, cobblemonResource(key))
|
||||
}
|
||||
}
|
||||
@@ -20,7 +20,7 @@ import net.minecraft.world.level.block.entity.BlockEntityType
|
||||
|
||||
object CobblemonBlockEntities : PlatformRegistry<Registry<BlockEntityType<*>>, ResourceKey<Registry<BlockEntityType<*>>>, BlockEntityType<*>>() {
|
||||
|
||||
override val registry: Registry<BlockEntityType<*>> = BuiltInRegistries.BLOCK_ENTITY_TYPE
|
||||
override var registry: Registry<BlockEntityType<*>>? = BuiltInRegistries.BLOCK_ENTITY_TYPE
|
||||
override val resourceKey: ResourceKey<Registry<BlockEntityType<*>>> = Registries.BLOCK_ENTITY_TYPE
|
||||
|
||||
@JvmField
|
||||
|
||||
@@ -59,7 +59,7 @@ import net.minecraft.world.level.material.PushReaction
|
||||
@Suppress("SameParameterValue", "HasPlatformType", "MemberVisibilityCanBePrivate", "unused")
|
||||
object CobblemonBlocks : PlatformRegistry<Registry<Block>, ResourceKey<Registry<Block>>, Block>() {
|
||||
|
||||
override val registry: Registry<Block> = BuiltInRegistries.BLOCK
|
||||
override var registry: Registry<Block>? = BuiltInRegistries.BLOCK
|
||||
override val resourceKey: ResourceKey<Registry<Block>> = Registries.BLOCK
|
||||
|
||||
val APRICORN_BLOCK_SET_TYPE = BlockSetType("apricorn")
|
||||
|
||||
@@ -30,7 +30,7 @@ import net.minecraft.world.entity.ai.attributes.AttributeSupplier
|
||||
object CobblemonEntities : PlatformRegistry<Registry<EntityType<*>>, ResourceKey<Registry<EntityType<*>>>, EntityType<*>>() {
|
||||
|
||||
|
||||
override val registry: Registry<EntityType<*>> = BuiltInRegistries.ENTITY_TYPE
|
||||
override var registry: Registry<EntityType<*>>? = BuiltInRegistries.ENTITY_TYPE
|
||||
override val resourceKey: ResourceKey<Registry<EntityType<*>>> = Registries.ENTITY_TYPE
|
||||
|
||||
@JvmField
|
||||
|
||||
@@ -123,6 +123,8 @@ interface CobblemonImplementation {
|
||||
* TODO
|
||||
*/
|
||||
fun registerMobEffects()
|
||||
|
||||
fun registerBiomes()
|
||||
|
||||
|
||||
/**
|
||||
|
||||
@@ -114,7 +114,7 @@ object CobblemonItemComponents : PlatformRegistry<Registry<DataComponentType<*>>
|
||||
Registry.register(BuiltInRegistries.DATA_COMPONENT_TYPE, ResourceLocation.parse("cobblemon:held_item_effect"), HELD_ITEM_EFFECT)
|
||||
}
|
||||
|
||||
override val registry = BuiltInRegistries.DATA_COMPONENT_TYPE
|
||||
override var registry = BuiltInRegistries.DATA_COMPONENT_TYPE
|
||||
override val resourceKey = Registries.DATA_COMPONENT_TYPE
|
||||
|
||||
}
|
||||
@@ -68,7 +68,7 @@ import net.minecraft.world.level.block.Block
|
||||
|
||||
@Suppress("unused", "SameParameterValue")
|
||||
object CobblemonItems : PlatformRegistry<Registry<Item>, ResourceKey<Registry<Item>>, Item>() {
|
||||
override val registry: Registry<Item> = BuiltInRegistries.ITEM
|
||||
override var registry: Registry<Item>? = BuiltInRegistries.ITEM
|
||||
override val resourceKey: ResourceKey<Registry<Item>> = Registries.ITEM
|
||||
|
||||
@JvmField
|
||||
|
||||
@@ -23,8 +23,7 @@ object CobblemonMenuType : PlatformRegistry<Registry<MenuType<*>>, ResourceKey<R
|
||||
val COOKING_POT = MenuType.register("cooking_pot_menu", ::CookingPotMenu)
|
||||
val TM_MACHINE = MenuType.register("tm_machine_menu", ::TMMachineMenu)
|
||||
|
||||
override val registry: Registry<MenuType<*>>
|
||||
get() = BuiltInRegistries.MENU
|
||||
override var registry: Registry<MenuType<*>>? = BuiltInRegistries.MENU
|
||||
override val resourceKey: ResourceKey<Registry<MenuType<*>>>
|
||||
get() = Registries.MENU
|
||||
}
|
||||
@@ -19,7 +19,7 @@ import net.minecraft.resources.ResourceKey
|
||||
import net.minecraft.world.effect.MobEffect
|
||||
|
||||
object CobblemonMobEffects : PlatformRegistry<Registry<MobEffect>, ResourceKey<Registry<MobEffect>>, MobEffect>() {
|
||||
override val registry: Registry<MobEffect> = BuiltInRegistries.MOB_EFFECT
|
||||
override var registry: Registry<MobEffect>? = BuiltInRegistries.MOB_EFFECT
|
||||
override val resourceKey: ResourceKey<Registry<MobEffect>> = Registries.MOB_EFFECT
|
||||
|
||||
@JvmField
|
||||
|
||||
@@ -20,7 +20,7 @@ import net.minecraft.world.level.block.Block
|
||||
import net.minecraft.world.level.block.state.BlockState
|
||||
|
||||
object CobblemonPoiTypes: PlatformRegistry<Registry<PoiType>, ResourceKey<Registry<PoiType>>, PoiType>() {
|
||||
override val registry: Registry<PoiType> = BuiltInRegistries.POINT_OF_INTEREST_TYPE
|
||||
override var registry: Registry<PoiType>? = BuiltInRegistries.POINT_OF_INTEREST_TYPE
|
||||
override val resourceKey: ResourceKey<Registry<PoiType>> = Registries.POINT_OF_INTEREST_TYPE
|
||||
|
||||
@JvmField
|
||||
|
||||
@@ -27,8 +27,7 @@ object CobblemonRecipeSerializers : PlatformRegistry<Registry<RecipeSerializer<*
|
||||
|
||||
val BREWING_STAND: RecipeSerializer<*> = register("cobblemon:brewing_stand", BrewingStandRecipe.Serializer())
|
||||
|
||||
override val registry: Registry<RecipeSerializer<*>>
|
||||
get() = BuiltInRegistries.RECIPE_SERIALIZER
|
||||
override var registry: Registry<RecipeSerializer<*>>? = BuiltInRegistries.RECIPE_SERIALIZER
|
||||
override val resourceKey: ResourceKey<Registry<RecipeSerializer<*>>>
|
||||
get() = Registries.RECIPE_SERIALIZER
|
||||
|
||||
|
||||
@@ -27,8 +27,7 @@ object CobblemonRecipeTypes : PlatformRegistry<Registry<RecipeType<*>>, Resource
|
||||
|
||||
val BREWING_STAND: RecipeType<BrewingStandRecipe> = register("cobblemon:brewing_stand")
|
||||
|
||||
override val registry: Registry<RecipeType<*>>
|
||||
get() = BuiltInRegistries.RECIPE_TYPE
|
||||
override var registry: Registry<RecipeType<*>>? = BuiltInRegistries.RECIPE_TYPE
|
||||
override val resourceKey: ResourceKey<Registry<RecipeType<*>>>
|
||||
get() = Registries.RECIPE_TYPE
|
||||
|
||||
|
||||
@@ -20,7 +20,7 @@ import net.minecraft.world.level.block.SoundType
|
||||
|
||||
object CobblemonSounds : PlatformRegistry<Registry<SoundEvent>, ResourceKey<Registry<SoundEvent>>, SoundEvent>() {
|
||||
|
||||
override val registry: Registry<SoundEvent> = BuiltInRegistries.SOUND_EVENT
|
||||
override var registry: Registry<SoundEvent>? = BuiltInRegistries.SOUND_EVENT
|
||||
override val resourceKey: ResourceKey<Registry<SoundEvent>> = Registries.SOUND_EVENT
|
||||
|
||||
@JvmField
|
||||
|
||||
@@ -20,7 +20,7 @@ import net.minecraft.world.entity.ai.village.poi.PoiType
|
||||
import net.minecraft.world.entity.npc.VillagerProfession
|
||||
|
||||
object CobblemonVillagerProfessions: PlatformRegistry<Registry<VillagerProfession>, ResourceKey<Registry<VillagerProfession>>, VillagerProfession>() {
|
||||
override val registry: Registry<VillagerProfession> = BuiltInRegistries.VILLAGER_PROFESSION
|
||||
override var registry: Registry<VillagerProfession>? = BuiltInRegistries.VILLAGER_PROFESSION
|
||||
override val resourceKey: ResourceKey<Registry<VillagerProfession>> = Registries.VILLAGER_PROFESSION
|
||||
|
||||
@JvmField
|
||||
|
||||
@@ -95,6 +95,6 @@ object CobblemonCriteria : PlatformRegistry<Registry<CriterionTrigger<*>>, Resou
|
||||
@JvmField
|
||||
val LEARN_TM_COUNT = this.create("tms_learned", SimpleCriterionTrigger(CountableCriterion.CODEC))
|
||||
|
||||
override val registry = BuiltInRegistries.TRIGGER_TYPES
|
||||
override var registry = BuiltInRegistries.TRIGGER_TYPES
|
||||
override val resourceKey = Registries.TRIGGER_TYPE
|
||||
}
|
||||
+1
-1
@@ -21,7 +21,7 @@ object CobblemonEntitySubPredicates : PlatformRegistry<Registry<MapCodec<out Ent
|
||||
@JvmStatic
|
||||
val POKE_POBBER = this.create("poke_bobber", FishingBobberPredicate.CODEC)
|
||||
|
||||
override val registry: Registry<MapCodec<out EntitySubPredicate>> = BuiltInRegistries.ENTITY_SUB_PREDICATE_TYPE
|
||||
override var registry: Registry<MapCodec<out EntitySubPredicate>>? = BuiltInRegistries.ENTITY_SUB_PREDICATE_TYPE
|
||||
|
||||
override val resourceKey: ResourceKey<Registry<MapCodec<out EntitySubPredicate>>> = Registries.ENTITY_SUB_PREDICATE_TYPE
|
||||
|
||||
|
||||
@@ -44,8 +44,15 @@ interface JsonDataRegistry<T> : DataRegistry {
|
||||
*/
|
||||
val resourcePath: String
|
||||
|
||||
override fun reload(manager: ResourceManager) {
|
||||
val data = hashMapOf<ResourceLocation, T>()
|
||||
/**
|
||||
* Traverses JSON resources for this registry and maps them to their resolved identifiers.
|
||||
* Returning null from [parse] skips the resource.
|
||||
*/
|
||||
fun <R> loadJsonData(
|
||||
manager: ResourceManager,
|
||||
parse: (reader: BufferedReader, sourceIdentifier: ResourceLocation, resolvedIdentifier: ResourceLocation) -> R?
|
||||
): Map<ResourceLocation, R> {
|
||||
val data = hashMapOf<ResourceLocation, R>()
|
||||
manager.listResources(resourcePath) { path -> path.endsWith(JSON_EXTENSION) }.forEach { (identifier, resource) ->
|
||||
if (identifier.namespace == "pixelmon") {
|
||||
return@forEach
|
||||
@@ -54,11 +61,21 @@ interface JsonDataRegistry<T> : DataRegistry {
|
||||
resource.open().use { stream ->
|
||||
stream.bufferedReader().use { reader ->
|
||||
val resolvedIdentifier = ResourceLocation.fromNamespaceAndPath(identifier.namespace, File(identifier.path).nameWithoutExtension)
|
||||
data[resolvedIdentifier] = parse(reader, resolvedIdentifier)
|
||||
parse(reader, identifier, resolvedIdentifier)?.let { parsed ->
|
||||
data[resolvedIdentifier] = parsed
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return data
|
||||
}
|
||||
|
||||
override fun reload(manager: ResourceManager) {
|
||||
val data = loadJsonData(manager) { reader, _, resolvedIdentifier ->
|
||||
parse(reader, resolvedIdentifier)
|
||||
}
|
||||
|
||||
reload(data)
|
||||
}
|
||||
|
||||
|
||||
@@ -53,6 +53,7 @@ import com.cobblemon.mod.common.util.cobblemonResource
|
||||
import com.cobblemon.mod.common.util.ifClient
|
||||
import com.cobblemon.mod.common.util.server
|
||||
import net.minecraft.core.HolderLookup
|
||||
import com.cobblemon.mod.common.world.biome.CobblemonBiomeLoader
|
||||
import java.util.UUID
|
||||
import net.minecraft.resources.ResourceLocation
|
||||
import net.minecraft.server.level.ServerPlayer
|
||||
@@ -91,6 +92,7 @@ object CobblemonDataProvider : DataProvider {
|
||||
this.register(PokeBalls, reloadable = false)
|
||||
this.register(PropertiesCompletionProvider, reloadable = false)
|
||||
this.register(CobblemonPartyPools, reloadable = false)
|
||||
this.register(CobblemonBiomeLoader, reloadable = true)
|
||||
this.register(CobblemonPartyCompositions, reloadable = false)
|
||||
this.register(SpawnDetailPresets, reloadable = true)
|
||||
this.register(CobblemonSpawnRules, reloadable = true)
|
||||
|
||||
@@ -17,7 +17,7 @@ import net.minecraft.resources.ResourceKey
|
||||
|
||||
object CobblemonParticles : PlatformRegistry<Registry<ParticleType<*>>, ResourceKey<Registry<ParticleType<*>>>, ParticleType<*>>() {
|
||||
|
||||
override val registry: Registry<ParticleType<*>> = BuiltInRegistries.PARTICLE_TYPE
|
||||
override var registry: Registry<ParticleType<*>>? = BuiltInRegistries.PARTICLE_TYPE
|
||||
override val resourceKey: ResourceKey<Registry<ParticleType<*>>> = Registries.PARTICLE_TYPE
|
||||
|
||||
val SNOWSTORM_PARTICLE_TYPE = this.create("snowstorm", SnowstormParticleType())
|
||||
|
||||
@@ -26,66 +26,58 @@ import net.minecraft.resources.ResourceLocation
|
||||
* @author Licious
|
||||
* @since February 11th, 2023
|
||||
*/
|
||||
abstract class PlatformRegistry<R : Registry<T>, K : ResourceKey<R>, T> {
|
||||
abstract class PlatformRegistry<R : Registry<T>, K : ResourceKey<R>, T>(
|
||||
open var registry: R? = null,
|
||||
open val resourceKey: K? = null
|
||||
) {
|
||||
protected val queue = hashMapOf<ResourceLocation, T>()
|
||||
|
||||
/**
|
||||
* The vanilla [Registry].
|
||||
*/
|
||||
abstract val registry: R
|
||||
/**
|
||||
* Creates a new entry in this registry.
|
||||
*
|
||||
* @param E The type of the entry.
|
||||
* @param name The name of the entry, this will be an [ResourceLocation.path].
|
||||
* @param entry The entry being added.
|
||||
* @return The entry created.
|
||||
*/
|
||||
open fun <E : T> create(name: String, entry: E): E {
|
||||
val resourceLocation = cobblemonResource(name)
|
||||
return this.create(resourceLocation, entry)
|
||||
}
|
||||
|
||||
/**
|
||||
* The vanilla [ResourceKey].
|
||||
*/
|
||||
abstract val resourceKey: K
|
||||
/**
|
||||
* Creates a new entry in this registry. Introduced for sidemod usage
|
||||
*
|
||||
* @param E The type of the entry.
|
||||
* @param resourceLocation The name of the entry, this will be an [ResourceLocation.path].
|
||||
* @param entry The entry being added.
|
||||
* @return The entry created.
|
||||
*/
|
||||
open fun <E : T> create(resourceLocation: ResourceLocation, entry: E): E {
|
||||
this.queue[resourceLocation] = entry
|
||||
if (entry is BagItemLike) {
|
||||
BagItems.bagItems.add(
|
||||
priority = Priority.NORMAL,
|
||||
value = entry
|
||||
)
|
||||
}
|
||||
return entry
|
||||
}
|
||||
|
||||
protected val queue = hashMapOf<ResourceLocation, T>()
|
||||
/**
|
||||
* Handles the registration of this registry into the platform specific one.
|
||||
*
|
||||
* @param consumer The consumer that will handle the logic for registering every entry in this registry into the platform specific one.
|
||||
*/
|
||||
open fun register(consumer: (ResourceLocation, T) -> Unit) {
|
||||
this.queue.forEach(consumer)
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new entry in this registry.
|
||||
*
|
||||
* @param E The type of the entry.
|
||||
* @param name The name of the entry, this will be an [ResourceLocation.path].
|
||||
* @param entry The entry being added.
|
||||
* @return The entry created.
|
||||
*/
|
||||
open fun <E : T> create(name: String, entry: E): E {
|
||||
val resourceLocation = cobblemonResource(name)
|
||||
return this.create(resourceLocation, entry)
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new entry in this registry. Introduced for sidemod usage
|
||||
*
|
||||
* @param E The type of the entry.
|
||||
* @param name The name of the entry, this will be an [ResourceLocation.path].
|
||||
* @param entry The entry being added.
|
||||
* @return The entry created.
|
||||
*/
|
||||
open fun <E : T> create(resourceLocation: ResourceLocation, entry: E): E {
|
||||
this.queue[resourceLocation] = entry
|
||||
if (entry is BagItemLike) {
|
||||
BagItems.bagItems.add(
|
||||
priority = Priority.NORMAL,
|
||||
value = entry
|
||||
)
|
||||
}
|
||||
return entry
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles the registration of this registry into the platform specific one.
|
||||
*
|
||||
* @param consumer The consumer that will handle the logic for registering every entry in this registry into the platform specific one.
|
||||
*/
|
||||
open fun register(consumer: (ResourceLocation, T) -> Unit) {
|
||||
this.queue.forEach(consumer)
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a collection of every entry in this registry.
|
||||
*
|
||||
* @return The entries of this registry.
|
||||
*/
|
||||
open fun all(): Collection<T> = this.queue.values.toList()
|
||||
/**
|
||||
* Returns a collection of every entry in this registry.
|
||||
*
|
||||
* @return The entries of this registry.
|
||||
*/
|
||||
open fun all(): Collection<T> = this.queue.values.toList()
|
||||
|
||||
}
|
||||
@@ -52,6 +52,10 @@ fun Collection<JsonElement>.toJsonArray(): JsonArray {
|
||||
return array
|
||||
}
|
||||
|
||||
|
||||
fun JsonElement.asJsonObjectOrNull(): JsonObject? =
|
||||
if (isJsonObject) asJsonObject else null
|
||||
|
||||
fun JsonObject.isEmpty() = size() <= 0
|
||||
|
||||
fun JsonObject.isNotEmpty() = size() > 0
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
* Copyright (C) 2023 Cobblemon Contributors
|
||||
*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
package com.cobblemon.mod.common.util.biome
|
||||
|
||||
import com.cobblemon.mod.common.Cobblemon
|
||||
import net.minecraft.core.HolderLookup
|
||||
import net.minecraft.core.Registry
|
||||
import net.minecraft.core.RegistryAccess
|
||||
import net.minecraft.resources.ResourceKey
|
||||
import java.util.*
|
||||
|
||||
object RegistryExtensions {
|
||||
@JvmStatic
|
||||
fun <T> getRegistryLookup(
|
||||
registryKey: ResourceKey<out Registry<T>>
|
||||
): Optional<HolderLookup.RegistryLookup<T>> {
|
||||
return Cobblemon.registryAccess.getRegistryLookup(registryKey)
|
||||
}
|
||||
}
|
||||
|
||||
fun <T> RegistryAccess?.getRegistryLookup(
|
||||
registryKey: ResourceKey<out Registry<T>>
|
||||
): Optional<HolderLookup.RegistryLookup<T>> {
|
||||
if (this == null || this == RegistryAccess.EMPTY) {
|
||||
return Optional.empty()
|
||||
}
|
||||
|
||||
return this.lookup(registryKey)
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
/*
|
||||
* Copyright (C) 2023 Cobblemon Contributors
|
||||
*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
package com.cobblemon.mod.common.world.biome
|
||||
|
||||
import com.google.gson.JsonElement
|
||||
import net.minecraft.world.level.biome.Biome
|
||||
import net.minecraft.world.level.biome.Climate
|
||||
|
||||
data class CobblemonBiome(
|
||||
val biome: Biome,
|
||||
val parameters: Climate.ParameterPoint,
|
||||
val customData: Map<String, JsonElement> = emptyMap()
|
||||
)
|
||||
@@ -0,0 +1,75 @@
|
||||
/*
|
||||
* Copyright (C) 2023 Cobblemon Contributors
|
||||
*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
package com.cobblemon.mod.common.world.biome
|
||||
|
||||
import com.cobblemon.mod.common.Cobblemon
|
||||
import com.cobblemon.mod.common.api.data.JsonDataRegistry
|
||||
import com.cobblemon.mod.common.api.reactive.SimpleObservable
|
||||
import com.cobblemon.mod.common.util.cobblemonResource
|
||||
import com.cobblemon.mod.common.world.biome.parse.CobblemonBiomeJsonParser
|
||||
import com.google.gson.Gson
|
||||
import com.google.gson.GsonBuilder
|
||||
import com.google.gson.JsonElement
|
||||
import com.google.gson.reflect.TypeToken
|
||||
import com.mojang.serialization.JsonOps
|
||||
import net.minecraft.resources.RegistryOps
|
||||
import net.minecraft.resources.ResourceLocation
|
||||
import net.minecraft.server.level.ServerPlayer
|
||||
import net.minecraft.server.packs.PackType
|
||||
import net.minecraft.server.packs.resources.ResourceManager
|
||||
import java.io.Reader
|
||||
|
||||
object CobblemonBiomeLoader : JsonDataRegistry<CobblemonBiome> {
|
||||
|
||||
override val gson: Gson = GsonBuilder().setPrettyPrinting().create()
|
||||
override val typeToken: TypeToken<CobblemonBiome> = TypeToken.get(CobblemonBiome::class.java)
|
||||
override val resourcePath = "biomes"
|
||||
override val id = cobblemonResource(resourcePath)
|
||||
override val type = PackType.SERVER_DATA
|
||||
override val observable = SimpleObservable<CobblemonBiomeLoader>()
|
||||
|
||||
private var loadedBiomes: Map<ResourceLocation, CobblemonBiome> = emptyMap()
|
||||
|
||||
@JvmStatic
|
||||
fun load(
|
||||
manager: ResourceManager,
|
||||
registryInfoLookup: RegistryOps.RegistryInfoLookup
|
||||
): Map<ResourceLocation, CobblemonBiome> {
|
||||
|
||||
val ops = RegistryOps.create(JsonOps.INSTANCE, registryInfoLookup)
|
||||
|
||||
val result = loadJsonData(manager) { reader, _, _ ->
|
||||
parseBiome(reader, ops)
|
||||
}
|
||||
|
||||
loadedBiomes = result.toMap()
|
||||
|
||||
observable.emit(this)
|
||||
Cobblemon.LOGGER.info("MEALAM Loaded {} cobblemon biomes.", result.size)
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
private fun parseBiome(
|
||||
reader: Reader,
|
||||
ops: RegistryOps<JsonElement>
|
||||
): CobblemonBiome? = CobblemonBiomeJsonParser.parse(reader, ops)
|
||||
|
||||
override fun reload(manager: ResourceManager) = observable.emit(this)
|
||||
override fun reload(data: Map<ResourceLocation, CobblemonBiome>) = Unit
|
||||
override fun sync(player: ServerPlayer) = Unit
|
||||
|
||||
@JvmStatic
|
||||
fun getLoadedBiomes(): Map<ResourceLocation, CobblemonBiome> = loadedBiomes
|
||||
|
||||
@JvmStatic
|
||||
fun getLoadedBiome(location: ResourceLocation): CobblemonBiome =
|
||||
loadedBiomes[location]
|
||||
?: error("MEALAM Unknown location: $location")
|
||||
}
|
||||
+43
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
* Copyright (C) 2023 Cobblemon Contributors
|
||||
*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
package com.cobblemon.mod.common.world.biome.parse
|
||||
|
||||
import com.cobblemon.mod.common.Cobblemon
|
||||
import com.google.gson.JsonElement
|
||||
import com.google.gson.JsonObject
|
||||
import com.mojang.serialization.JsonOps
|
||||
import net.minecraft.resources.RegistryOps
|
||||
import net.minecraft.world.level.biome.Climate
|
||||
|
||||
object ClimateParametersSectionParser : CobblemonBiomeSectionParser {
|
||||
override val id = "parameters"
|
||||
|
||||
override fun parse(
|
||||
root: JsonObject,
|
||||
ops: RegistryOps<JsonElement>,
|
||||
builder: CobblemonBiomeParseBuilder
|
||||
): Boolean {
|
||||
val params = root.getAsJsonObject("parameters")
|
||||
if (params == null) {
|
||||
Cobblemon.LOGGER.error("MEALAM Missing 'parameters' section in biome JSON")
|
||||
return false
|
||||
}
|
||||
|
||||
val result = Climate.ParameterPoint.CODEC.parse(JsonOps.INSTANCE, params)
|
||||
val parameterPoint = result.result().orElse(null)
|
||||
if (parameterPoint == null) {
|
||||
val errorMessage = result.error().map { it.message() }.orElse("unknown error")
|
||||
Cobblemon.LOGGER.error("MEALAM Failed to parse climate parameters: {}", errorMessage)
|
||||
return false
|
||||
}
|
||||
|
||||
builder.parameters = parameterPoint
|
||||
return true
|
||||
}
|
||||
}
|
||||
+45
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
* Copyright (C) 2023 Cobblemon Contributors
|
||||
*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
package com.cobblemon.mod.common.world.biome.parse
|
||||
|
||||
import com.cobblemon.mod.common.util.asJsonObjectOrNull
|
||||
import com.cobblemon.mod.common.world.biome.CobblemonBiome
|
||||
import com.google.gson.JsonElement
|
||||
import com.google.gson.JsonParser
|
||||
import net.minecraft.resources.RegistryOps
|
||||
import java.io.Reader
|
||||
|
||||
object CobblemonBiomeJsonParser {
|
||||
private val sectionParsers = mutableListOf(
|
||||
VanillaBiomeSectionParser,
|
||||
ClimateParametersSectionParser,
|
||||
CustomDataSectionParser(setOf("parameters"))
|
||||
)
|
||||
|
||||
fun parse(reader: Reader, ops: RegistryOps<JsonElement>): CobblemonBiome? {
|
||||
val root = JsonParser.parseReader(reader).asJsonObjectOrNull() ?: return null
|
||||
val builder = CobblemonBiomeParseBuilder()
|
||||
|
||||
for (parser in getParsers()) {
|
||||
if (!parser.parse(root, ops, builder) && parser.required) {
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
return builder.buildOrNull()
|
||||
}
|
||||
|
||||
fun register(parser: CobblemonBiomeSectionParser) {
|
||||
sectionParsers.add(parser)
|
||||
}
|
||||
|
||||
private fun getParsers(): List<CobblemonBiomeSectionParser> = sectionParsers.toList()
|
||||
}
|
||||
|
||||
|
||||
+27
@@ -0,0 +1,27 @@
|
||||
/*
|
||||
* Copyright (C) 2023 Cobblemon Contributors
|
||||
*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
package com.cobblemon.mod.common.world.biome.parse
|
||||
|
||||
import com.cobblemon.mod.common.world.biome.CobblemonBiome
|
||||
import com.google.gson.JsonElement
|
||||
import net.minecraft.world.level.biome.Biome
|
||||
import net.minecraft.world.level.biome.Climate
|
||||
|
||||
class CobblemonBiomeParseBuilder {
|
||||
var biome: Biome? = null
|
||||
var parameters: Climate.ParameterPoint? = null
|
||||
val customData: MutableMap<String, JsonElement> = linkedMapOf()
|
||||
|
||||
fun buildOrNull(): CobblemonBiome? {
|
||||
val parsedBiome = biome ?: return null
|
||||
val parsedParameters = parameters ?: return null
|
||||
return CobblemonBiome(parsedBiome, parsedParameters, customData.toMap())
|
||||
}
|
||||
}
|
||||
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
/*
|
||||
* Copyright (C) 2023 Cobblemon Contributors
|
||||
*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
package com.cobblemon.mod.common.world.biome.parse
|
||||
|
||||
import com.google.gson.JsonElement
|
||||
import com.google.gson.JsonObject
|
||||
import net.minecraft.resources.RegistryOps
|
||||
|
||||
interface CobblemonBiomeSectionParser {
|
||||
val id: String
|
||||
val required: Boolean
|
||||
get() = true
|
||||
|
||||
fun parse(
|
||||
root: JsonObject,
|
||||
ops: RegistryOps<JsonElement>,
|
||||
builder: CobblemonBiomeParseBuilder
|
||||
): Boolean
|
||||
}
|
||||
|
||||
+34
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* Copyright (C) 2023 Cobblemon Contributors
|
||||
*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
package com.cobblemon.mod.common.world.biome.parse
|
||||
|
||||
import com.google.gson.JsonElement
|
||||
import com.google.gson.JsonObject
|
||||
import net.minecraft.resources.RegistryOps
|
||||
|
||||
class CustomDataSectionParser(
|
||||
private val reservedKeys: Set<String>
|
||||
) : CobblemonBiomeSectionParser {
|
||||
override val id = "custom_data"
|
||||
override val required = false
|
||||
|
||||
override fun parse(
|
||||
root: JsonObject,
|
||||
ops: RegistryOps<JsonElement>,
|
||||
builder: CobblemonBiomeParseBuilder
|
||||
): Boolean {
|
||||
for ((key, value) in root.entrySet()) {
|
||||
if (key !in reservedKeys) {
|
||||
builder.customData[key] = value.deepCopy()
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
+36
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
* Copyright (C) 2023 Cobblemon Contributors
|
||||
*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
package com.cobblemon.mod.common.world.biome.parse
|
||||
|
||||
import com.cobblemon.mod.common.Cobblemon
|
||||
import com.google.gson.JsonElement
|
||||
import com.google.gson.JsonObject
|
||||
import net.minecraft.resources.RegistryOps
|
||||
import net.minecraft.world.level.biome.Biome
|
||||
|
||||
object VanillaBiomeSectionParser : CobblemonBiomeSectionParser {
|
||||
override val id = "vanilla_biome"
|
||||
|
||||
override fun parse(
|
||||
root: JsonObject,
|
||||
ops: RegistryOps<JsonElement>,
|
||||
builder: CobblemonBiomeParseBuilder
|
||||
): Boolean {
|
||||
val result = Biome.DIRECT_CODEC.parse(ops, root)
|
||||
val biome = result.result().orElse(null)
|
||||
if (biome == null) {
|
||||
val errorMessage = result.error().map { it.message() }.orElse("unknown error")
|
||||
Cobblemon.LOGGER.error("MEALAM Failed to parse vanilla biome: {}", errorMessage)
|
||||
return false
|
||||
}
|
||||
|
||||
builder.biome = biome
|
||||
return true
|
||||
}
|
||||
}
|
||||
@@ -18,7 +18,7 @@ import net.minecraft.world.level.levelgen.feature.Feature
|
||||
|
||||
object CobblemonFeatures : PlatformRegistry<Registry<Feature<*>>, ResourceKey<Registry<Feature<*>>>, Feature<*>>() {
|
||||
|
||||
override val registry: Registry<Feature<*>> = BuiltInRegistries.FEATURE
|
||||
override var registry: Registry<Feature<*>>? = BuiltInRegistries.FEATURE
|
||||
override val resourceKey: ResourceKey<Registry<Feature<*>>> = Registries.FEATURE
|
||||
|
||||
@JvmField
|
||||
|
||||
@@ -138,6 +138,8 @@ transitive-accessible method net/minecraft/world/inventory/MenuType <init> (Lnet
|
||||
transitive-accessible class net/minecraft/client/gui/screens/MenuScreens$ScreenConstructor
|
||||
transitive-accessible method net/minecraft/client/gui/screens/MenuScreens register (Lnet/minecraft/world/inventory/MenuType;Lnet/minecraft/client/gui/screens/MenuScreens$ScreenConstructor;)V
|
||||
transitive-accessible method net/minecraft/resources/ResourceLocation <init> (Ljava/lang/String;Ljava/lang/String;)V
|
||||
transitive-accessible class net/minecraft/resources/RegistryDataLoader$LoadingFunction
|
||||
transitive-accessible method net/minecraft/resources/RegistryDataLoader$LoadingFunction apply (Lnet/minecraft/resources/RegistryDataLoader$Loader;Lnet/minecraft/resources/RegistryOps$RegistryInfoLookup;)V
|
||||
transitive-accessible field net/minecraft/stats/RecipeBookSettings states Ljava/util/Map;
|
||||
transitive-accessible class net/minecraft/stats/RecipeBookSettings$TypeSettings
|
||||
transitive-accessible field net/minecraft/client/gui/screens/recipebook/RecipeBookComponent tabButtons Ljava/util/List;
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
{
|
||||
"carvers": {},
|
||||
"downfall": 0.0,
|
||||
"effects": {
|
||||
"fog_color": 12638463,
|
||||
"mood_sound": {
|
||||
"block_search_extent": 8,
|
||||
"offset": 2.0,
|
||||
"sound": "minecraft:ambient.cave",
|
||||
"tick_delay": 6000
|
||||
},
|
||||
"sky_color": 8103167,
|
||||
"water_color": 4159204,
|
||||
"water_fog_color": 329011
|
||||
},
|
||||
"features": [],
|
||||
"has_precipitation": false,
|
||||
"temperature": 2,
|
||||
"spawn_costs": {},
|
||||
"spawners": {
|
||||
"ambient": [],
|
||||
"axolotls": [],
|
||||
"creature": [],
|
||||
"misc": [],
|
||||
"monster": [],
|
||||
"underground_water_creature": [],
|
||||
"water_ambient": [],
|
||||
"water_creature": []
|
||||
},
|
||||
"parameters": {
|
||||
"temperature": {
|
||||
"min": 2,
|
||||
"max": 2
|
||||
},
|
||||
"humidity": {
|
||||
"min": 2,
|
||||
"max": 2
|
||||
},
|
||||
"continentalness": {
|
||||
"min": 2,
|
||||
"max": 2
|
||||
},
|
||||
"erosion": {
|
||||
"min": 2,
|
||||
"max": 2
|
||||
},
|
||||
"depth": {
|
||||
"min": 0.0,
|
||||
"max": 0.0
|
||||
},
|
||||
"weirdness": {
|
||||
"min": 2,
|
||||
"max": 2
|
||||
},
|
||||
"offset": 0.0
|
||||
}
|
||||
}
|
||||
@@ -95,6 +95,8 @@
|
||||
"accessor.SinglePoolElementAccessor",
|
||||
"accessor.StatusEffectInstanceAccessor",
|
||||
"accessor.TrackedEntityAccessor",
|
||||
"biome.MultiNoiseBiomeSourceMixin",
|
||||
"biome.RegistryDataLoaderMixin",
|
||||
"brewing.BrewingStandBlockEntityMixin",
|
||||
"brewing.BrewingStandMenuMixin",
|
||||
"brewing.IngredientSlotMixin",
|
||||
|
||||
@@ -407,6 +407,12 @@ object CobblemonFabric : CobblemonImplementation {
|
||||
}
|
||||
}
|
||||
|
||||
override fun registerBiomes() {
|
||||
CobblemonBiomes.register { location, biome ->
|
||||
Registry.register(CobblemonBiomes.registry, location, biome)
|
||||
}
|
||||
}
|
||||
|
||||
private class CobblemonReloadListener(private val identifier: ResourceLocation, private val reloader: PreparableReloadListener, private val dependencies: Collection<ResourceLocation>) : IdentifiableResourceReloadListener {
|
||||
|
||||
override fun reload(synchronizer: PreparableReloadListener.PreparationBarrier, manager: ResourceManager, prepareProfiler: ProfilerFiller, applyProfiler: ProfilerFiller, prepareExecutor: Executor, applyExecutor: Executor): CompletableFuture<Void> = this.reloader.reload(synchronizer, manager, prepareProfiler, applyProfiler, prepareExecutor, applyExecutor)
|
||||
|
||||
@@ -445,6 +445,14 @@ class CobblemonNeoForge : CobblemonImplementation {
|
||||
}
|
||||
}
|
||||
|
||||
override fun registerBiomes() {
|
||||
MOD_BUS.addListener<RegisterEvent> { event ->
|
||||
event.register(CobblemonBiomes.resourceKey) { helper ->
|
||||
CobblemonBiomes.register { identifier, biome -> helper.register(identifier, biome) }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun registerResourceReloader(
|
||||
identifier: ResourceLocation,
|
||||
type: PackType,
|
||||
|
||||
Reference in new issue
Block a user