begin working on Forge

This commit is contained in:
dfsek 2022-12-21 21:59:39 -07:00 committed by Astrash
parent 7ea5747f8e
commit 4df23e464b
5 changed files with 44 additions and 36 deletions

View File

@ -17,6 +17,7 @@
package com.dfsek.terra.forge;
import net.minecraft.registry.RegistryKeys;
import net.minecraft.util.Identifier;
import net.minecraft.registry.Registry;
import net.minecraft.world.biome.Biome;
@ -71,12 +72,12 @@ public class ForgeEntryPoint {
public void registerBiomes(RegisterEvent event) {
event.register(Keys.BLOCKS, helper -> sanityCheck.progress(RegistryStep.BLOCK, () -> logger.debug("Block registration detected.")));
event.register(Keys.BIOMES, helper -> sanityCheck.progress(RegistryStep.BIOME, () -> initialize(helper)));
event.register(Registry.WORLD_PRESET_KEY,
event.register(RegistryKeys.WORLD_PRESET,
helper -> sanityCheck.progress(RegistryStep.WORLD_TYPE, () -> TERRA_PLUGIN.registerWorldTypes(helper::register)));
event.register(Registry.CHUNK_GENERATOR_KEY,
event.register(RegistryKeys.CHUNK_GENERATOR,
helper -> helper.register(new Identifier("terra:terra"), Codecs.MINECRAFT_CHUNK_GENERATOR_WRAPPER));
event.register(Registry.BIOME_SOURCE_KEY, helper -> helper.register(new Identifier("terra:terra"), Codecs.TERRA_BIOME_SOURCE));
event.register(RegistryKeys.BIOME_SOURCE, helper -> helper.register(new Identifier("terra:terra"), Codecs.TERRA_BIOME_SOURCE));
}
}

View File

@ -21,10 +21,15 @@ import ca.solostudios.strata.Versions;
import ca.solostudios.strata.parser.tokenizer.ParseException;
import ca.solostudios.strata.version.Version;
import net.minecraft.MinecraftVersion;
import net.minecraft.registry.Registries;
import net.minecraft.registry.Registry;
import net.minecraft.registry.RegistryKey;
import net.minecraft.server.MinecraftServer;
import net.minecraft.world.biome.Biome;
import net.minecraft.world.dimension.DimensionType;
import net.minecraft.world.gen.chunk.ChunkGeneratorSettings;
import net.minecraftforge.fml.loading.FMLLoader;
import net.minecraftforge.registries.ForgeRegistries;
import net.minecraftforge.server.ServerLifecycleHooks;
import org.jetbrains.annotations.NotNull;
import org.slf4j.Logger;
@ -126,7 +131,17 @@ public class ForgePlatform extends ModPlatform {
}
@Override
public <T> Registry<T> getMinecraftRegistry(RegistryKey<T> key) {
public Registry<DimensionType> dimensionTypeRegistry() {
return ForgeRegistries.DI;
}
@Override
public Registry<Biome> biomeRegistry() {
return null;
}
@Override
public Registry<ChunkGeneratorSettings> chunkGeneratorSettingsRegistry() {
return Registries.DIM;
}
}

View File

@ -1,19 +1,26 @@
package com.dfsek.terra.forge.mixin.lifecycle;
import net.minecraft.registry.RegistryEntryLookup;
import net.minecraft.util.math.noise.DoublePerlinNoiseSampler;
import net.minecraft.util.math.noise.DoublePerlinNoiseSampler.NoiseParameters;
import net.minecraft.world.biome.source.util.MultiNoiseUtil.MultiNoiseSampler;
import net.minecraft.world.biome.source.util.MultiNoiseUtil.NoiseHypercube;
import net.minecraft.world.gen.chunk.ChunkGeneratorSettings;
import net.minecraft.world.gen.densityfunction.DensityFunction;
import net.minecraft.world.gen.noise.NoiseConfig;
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 org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.Redirect;
import java.util.List;
import com.dfsek.terra.mod.util.SeedHack;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
/**
* Hack to map noise sampler to seeds
@ -22,23 +29,12 @@ import com.dfsek.terra.mod.util.SeedHack;
public class NoiseConfigMixin {
@Shadow
@Final
private long legacyWorldSeed;
private MultiNoiseSampler multiNoiseSampler;
@Redirect(method = "<init>(Lnet/minecraft/world/gen/chunk/ChunkGeneratorSettings;Lnet/minecraft/util/registry/Registry;J)V",
at = @At(value = "NEW",
target = "(Lnet/minecraft/world/gen/densityfunction/DensityFunction;" +
"Lnet/minecraft/world/gen/densityfunction/DensityFunction;" +
"Lnet/minecraft/world/gen/densityfunction/DensityFunction;" +
"Lnet/minecraft/world/gen/densityfunction/DensityFunction;" +
"Lnet/minecraft/world/gen/densityfunction/DensityFunction;" +
"Lnet/minecraft/world/gen/densityfunction/DensityFunction;Ljava/util/List;)" +
"Lnet/minecraft/world/biome/source/util/MultiNoiseUtil$MultiNoiseSampler;"))
private MultiNoiseSampler t(DensityFunction densityFunction, DensityFunction densityFunction2, DensityFunction densityFunction3,
DensityFunction densityFunction4, DensityFunction densityFunction5, DensityFunction densityFunction6,
List<NoiseHypercube> list) {
MultiNoiseSampler sampler = new MultiNoiseSampler(densityFunction, densityFunction2, densityFunction3, densityFunction4,
densityFunction5, densityFunction6, list);
SeedHack.register(sampler, legacyWorldSeed);
return sampler;
@Inject(method = "<init>(Lnet/minecraft/world/gen/chunk/ChunkGeneratorSettings;Lnet/minecraft/registry/RegistryEntryLookup;J)V",
at = @At("TAIL"))
private void mapMultiNoise(ChunkGeneratorSettings chunkGeneratorSettings, RegistryEntryLookup<NoiseParameters> noiseParametersLookup, long seed,
CallbackInfo ci) {
SeedHack.register(multiNoiseSampler, seed);
}
}

View File

@ -1,9 +1,9 @@
package com.dfsek.terra.forge.util;
import net.minecraft.registry.RegistryKey;
import net.minecraft.registry.RegistryKeys;
import net.minecraft.registry.entry.RegistryEntry;
import net.minecraft.util.Identifier;
import net.minecraft.util.registry.BuiltinRegistries;
import net.minecraft.registry.Registry;
import net.minecraft.util.registry.RegistryKey;
import net.minecraft.village.VillagerType;
import net.minecraftforge.registries.ForgeRegistries;
import net.minecraftforge.registries.RegisterEvent.RegisterHelper;
@ -39,7 +39,6 @@ public final class BiomeUtil {
pack.getCheckedRegistry(Biome.class)
.forEach((id, biome) -> registerBiome(biome, pack, id, helper));
});
MinecraftUtil.registerFlora(BuiltinRegistries.BIOME);
logger.info("Terra biomes registered.");
}
@ -52,7 +51,8 @@ public final class BiomeUtil {
private static void registerBiome(Biome biome, ConfigPack pack,
com.dfsek.terra.api.registry.key.RegistryKey id,
RegisterHelper<net.minecraft.world.biome.Biome> helper) {
RegistryKey<net.minecraft.world.biome.Biome> vanilla = ((ProtoPlatformBiome) biome.getPlatformBiome()).get(BuiltinRegistries.BIOME);
RegistryEntry<net.minecraft.world.biome.Biome>
vanilla = ForgeRegistries.BIOMES.getHolder(((ProtoPlatformBiome) biome.getPlatformBiome()).getHandle()).orElseThrow();
if(pack.getContext().get(PreLoadCompatibilityOptions.class).useVanillaBiomes()) {
@ -61,7 +61,7 @@ public final class BiomeUtil {
VanillaBiomeProperties vanillaBiomeProperties = biome.getContext().get(VanillaBiomeProperties.class);
net.minecraft.world.biome.Biome minecraftBiome = MinecraftUtil.createBiome(biome,
ForgeRegistries.BIOMES.getDelegateOrThrow(vanilla)
ForgeRegistries.BIOMES.getDelegateOrThrow(vanilla.getKey().orElseThrow())
.value(),
vanillaBiomeProperties);
@ -69,24 +69,20 @@ public final class BiomeUtil {
if(ForgeRegistries.BIOMES.containsKey(identifier)) {
((ProtoPlatformBiome) biome.getPlatformBiome()).setDelegate(ForgeRegistries.BIOMES.getHolder(identifier)
.orElseThrow()
.getKey()
.orElseThrow());
} else {
helper.register(MinecraftUtil.registerKey(identifier).getValue(), minecraftBiome);
((ProtoPlatformBiome) biome.getPlatformBiome()).setDelegate(ForgeRegistries.BIOMES.getHolder(identifier)
.orElseThrow()
.getKey()
.orElseThrow());
}
Map villagerMap = VillagerTypeAccessor.getBiomeTypeToIdMap();
Map<RegistryKey<net.minecraft.world.biome.Biome>, VillagerType> villagerMap = VillagerTypeAccessor.getBiomeTypeToIdMap();
villagerMap.put(RegistryKey.of(Registry.BIOME_KEY, identifier),
villagerMap.put(RegistryKey.of(RegistryKeys.BIOME, identifier),
Objects.requireNonNullElse(vanillaBiomeProperties.getVillagerType(),
villagerMap.getOrDefault(vanilla, VillagerType.PLAINS)));
villagerMap.getOrDefault(vanilla.getKey().orElseThrow(), VillagerType.PLAINS)));
MinecraftUtil.TERRA_BIOME_MAP.computeIfAbsent(vanilla.getValue(), i -> new ArrayList<>()).add(identifier);
MinecraftUtil.TERRA_BIOME_MAP.computeIfAbsent(vanilla.getKey().orElseThrow().getValue(), i -> new ArrayList<>()).add(identifier);
}
}
}

View File

@ -43,7 +43,7 @@ public class ProtoPlatformBiome implements PlatformBiome {
}
@Override
public Object getHandle() {
public Identifier getHandle() {
return identifier;
}