mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2026-02-16 10:30:42 +00:00
more work on evil update
This commit is contained in:
@@ -21,6 +21,8 @@ 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.Registry;
|
||||
import net.minecraft.registry.RegistryKey;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraftforge.fml.loading.FMLLoader;
|
||||
import net.minecraftforge.server.ServerLifecycleHooks;
|
||||
@@ -86,7 +88,7 @@ public class ForgePlatform extends ModPlatform {
|
||||
|
||||
super.platformAddon().forEach(addons::add);
|
||||
|
||||
String mcVersion = MinecraftVersion.CURRENT.getReleaseTarget();
|
||||
String mcVersion = MinecraftVersion.CURRENT.getName();
|
||||
try {
|
||||
addons.add(new EphemeralAddon(Versions.parseVersion(mcVersion), "minecraft"));
|
||||
} catch(ParseException e) {
|
||||
@@ -122,4 +124,9 @@ public class ForgePlatform extends ModPlatform {
|
||||
public BaseAddon getPlatformAddon() {
|
||||
return new ForgeAddon(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> Registry<T> getMinecraftRegistry(RegistryKey<T> key) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,6 +7,8 @@ import net.minecraft.entity.EntityType;
|
||||
import net.minecraft.entity.SpawnGroup;
|
||||
import net.minecraft.registry.BuiltinRegistries;
|
||||
import net.minecraft.registry.DynamicRegistryManager;
|
||||
import net.minecraft.registry.Registry;
|
||||
import net.minecraft.registry.RegistryKey;
|
||||
import net.minecraft.registry.RegistryKeys;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.sound.BiomeAdditionsSound;
|
||||
@@ -94,9 +96,9 @@ public abstract class ModPlatform extends AbstractPlatform {
|
||||
.registerLoader(VillagerType.class, VillagerTypeTemplate::new);
|
||||
}
|
||||
|
||||
private ProtoPlatformBiome parseBiome(DynamicRegistryManager registryManager, String id, DepthTracker tracker) throws LoadException {
|
||||
private ProtoPlatformBiome parseBiome(String id, DepthTracker tracker) throws LoadException {
|
||||
Identifier identifier = Identifier.tryParse(id);
|
||||
if(registryManager.get(RegistryKeys.BIOME).get(identifier) == null) throw new LoadException("Invalid Biome ID: " + identifier, tracker); // failure.
|
||||
if(getMinecraftRegistry(RegistryKeys.BIOME).get(identifier) == null) throw new LoadException("Invalid Biome ID: " + identifier, tracker); // failure.
|
||||
return new ProtoPlatformBiome(identifier);
|
||||
}
|
||||
|
||||
@@ -107,6 +109,8 @@ public abstract class ModPlatform extends AbstractPlatform {
|
||||
|
||||
protected abstract BaseAddon getPlatformAddon();
|
||||
|
||||
public abstract <T> Registry<T> getMinecraftRegistry(RegistryKey<? extends Registry<? extends T>> key);
|
||||
|
||||
@Override
|
||||
public @NotNull WorldHandle getWorldHandle() {
|
||||
return worldHandle;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package com.dfsek.terra.mod.mixin.access;
|
||||
|
||||
import net.minecraft.util.registry.RegistryKey;
|
||||
import net.minecraft.registry.RegistryKey;
|
||||
import net.minecraft.village.VillagerType;
|
||||
import net.minecraft.world.biome.Biome;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
package com.dfsek.terra.mod.util;
|
||||
|
||||
import net.minecraft.command.CommandRegistryAccess;
|
||||
import net.minecraft.registry.BuiltinRegistries;
|
||||
import net.minecraft.registry.RegistryKeys;
|
||||
import net.minecraft.structure.StructureSet;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.math.noise.DoublePerlinNoiseSampler.NoiseParameters;
|
||||
@@ -30,12 +33,15 @@ import com.dfsek.terra.mod.generation.MinecraftChunkGeneratorWrapper;
|
||||
import com.dfsek.terra.mod.generation.TerraBiomeSource;
|
||||
|
||||
|
||||
|
||||
public class PresetUtil {
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(PresetUtil.class);
|
||||
private static final List<Identifier> PRESETS = new ArrayList<>();
|
||||
|
||||
public static Pair<Identifier, WorldPreset> createDefault(ConfigPack pack) {
|
||||
Registry<DimensionType> dimensionTypeRegistry = BuiltinRegistries.DIMENSION_TYPE;
|
||||
|
||||
|
||||
Registry<DimensionType> dimensionTypeRegistry = access.;
|
||||
Registry<ChunkGeneratorSettings> chunkGeneratorSettingsRegistry = BuiltinRegistries.CHUNK_GENERATOR_SETTINGS;
|
||||
Registry<StructureSet> structureSetRegistry = BuiltinRegistries.STRUCTURE_SET;
|
||||
Registry<NoiseParameters> noiseParametersRegistry = BuiltinRegistries.NOISE_PARAMETERS;
|
||||
|
||||
@@ -3,6 +3,9 @@ package com.dfsek.terra.lifecycle;
|
||||
import ca.solostudios.strata.Versions;
|
||||
import ca.solostudios.strata.parser.tokenizer.ParseException;
|
||||
import net.minecraft.MinecraftVersion;
|
||||
import net.minecraft.registry.DynamicRegistryManager;
|
||||
import net.minecraft.registry.Registry;
|
||||
import net.minecraft.registry.RegistryKey;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
@@ -10,6 +13,8 @@ import org.slf4j.LoggerFactory;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
import com.dfsek.terra.addon.EphemeralAddon;
|
||||
import com.dfsek.terra.api.addon.BaseAddon;
|
||||
@@ -23,6 +28,8 @@ public abstract class LifecyclePlatform extends ModPlatform {
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(LifecyclePlatform.class);
|
||||
private static MinecraftServer server;
|
||||
|
||||
private static final AtomicReference<DynamicRegistryManager> DYNAMIC_REGISTRY_MANAGER = new AtomicReference<>();
|
||||
|
||||
public LifecyclePlatform() {
|
||||
CommonPlatform.initialize(this);
|
||||
load();
|
||||
@@ -49,7 +56,7 @@ public abstract class LifecyclePlatform extends ModPlatform {
|
||||
LOGGER.warn("Failed to execute reload", throwable);
|
||||
return null;
|
||||
}).join();
|
||||
BiomeUtil.registerBiomes();
|
||||
BiomeUtil.registerBiomes(DYNAMIC_REGISTRY_MANAGER.get());
|
||||
server.getWorlds().forEach(world -> {
|
||||
if(world.getChunkManager().getChunkGenerator() instanceof MinecraftChunkGeneratorWrapper chunkGeneratorWrapper) {
|
||||
getConfigRegistry().get(chunkGeneratorWrapper.getPack().getRegistryKey()).ifPresent(pack -> {
|
||||
@@ -62,13 +69,20 @@ public abstract class LifecyclePlatform extends ModPlatform {
|
||||
return succeed;
|
||||
}
|
||||
|
||||
public static void addRegistryManager(DynamicRegistryManager in) {
|
||||
if(DYNAMIC_REGISTRY_MANAGER.get() == null) {
|
||||
DYNAMIC_REGISTRY_MANAGER.set(Objects.requireNonNull(in));
|
||||
}
|
||||
throw new IllegalStateException("Already set!");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Iterable<BaseAddon> platformAddon() {
|
||||
List<BaseAddon> addons = new ArrayList<>();
|
||||
|
||||
super.platformAddon().forEach(addons::add);
|
||||
|
||||
String mcVersion = MinecraftVersion.CURRENT.getReleaseTarget();
|
||||
String mcVersion = MinecraftVersion.CURRENT.getName();
|
||||
try {
|
||||
addons.add(new EphemeralAddon(Versions.parseVersion(mcVersion), "minecraft"));
|
||||
} catch(ParseException e) {
|
||||
@@ -84,5 +98,10 @@ public abstract class LifecyclePlatform extends ModPlatform {
|
||||
return addons;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> Registry<T> getMinecraftRegistry(RegistryKey<? extends Registry<? extends T>> key) {
|
||||
return DYNAMIC_REGISTRY_MANAGER.get().get(key);
|
||||
}
|
||||
|
||||
protected abstract Collection<BaseAddon> getPlatformMods();
|
||||
}
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
package com.dfsek.terra.lifecycle.mixin.lifecycle;
|
||||
|
||||
import com.dfsek.terra.lifecycle.util.LifecycleUtil;
|
||||
|
||||
import net.minecraft.registry.DynamicRegistryManager;
|
||||
import net.minecraft.server.SaveLoading;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.ModifyArg;
|
||||
|
||||
|
||||
@Mixin(SaveLoading.class)
|
||||
public class SaveLoadingMixin {
|
||||
@ModifyArg(
|
||||
method = "method_42097(Lnet/minecraft/registry/DynamicRegistryManager$Immutable;" +
|
||||
"Lnet/minecraft/server/SaveLoading$SaveApplierFactory;Lnet/minecraft/resource/LifecycledResourceManager;" +
|
||||
"Lnet/minecraft/registry/CombinedDynamicRegistries;Lnet/minecraft/server/SaveLoading$LoadContext;" +
|
||||
"Lnet/minecraft/server/DataPackContents;)Ljava/lang/Object;",
|
||||
at = @At(
|
||||
value = "INVOKE",
|
||||
target = "Lnet/minecraft/server/DataPackContents;refresh(Lnet/minecraft/registry/DynamicRegistryManager;)V"
|
||||
),
|
||||
index = 0
|
||||
)
|
||||
private DynamicRegistryManager redirect(DynamicRegistryManager in) {
|
||||
LifecycleUtil.initialize(in);
|
||||
return in;
|
||||
}
|
||||
}
|
||||
@@ -1,41 +0,0 @@
|
||||
/*
|
||||
* This file is part of Terra.
|
||||
*
|
||||
* Terra is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Terra is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Terra. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.dfsek.terra.lifecycle.mixin.lifecycle.client;
|
||||
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.client.RunArgs;
|
||||
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 com.dfsek.terra.lifecycle.util.LifecycleUtil;
|
||||
|
||||
|
||||
@Mixin(MinecraftClient.class)
|
||||
public class MinecraftClientMixin {
|
||||
@Inject(method = "<init>", at = @At(value = "INVOKE",
|
||||
target = "Lnet/minecraft/client/util/WindowProvider;createWindow" +
|
||||
"(Lnet/minecraft/client/WindowSettings;Ljava/lang/String;Ljava/lang/String;)" +
|
||||
"Lnet/minecraft/client/util/Window;",
|
||||
// sorta arbitrary position, after mod init, before window opens
|
||||
shift = At.Shift.BEFORE))
|
||||
public void injectConstructor(RunArgs args, CallbackInfo callbackInfo) {
|
||||
LifecycleUtil.initialize();
|
||||
}
|
||||
}
|
||||
@@ -1,40 +0,0 @@
|
||||
/*
|
||||
* This file is part of Terra.
|
||||
*
|
||||
* Terra is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Terra is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Terra. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.dfsek.terra.lifecycle.mixin.lifecycle.server;
|
||||
|
||||
import net.minecraft.server.Main;
|
||||
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 com.dfsek.terra.lifecycle.util.LifecycleUtil;
|
||||
|
||||
|
||||
@Mixin(Main.class)
|
||||
public class ServerMainMixin {
|
||||
@Inject(method = "main([Ljava/lang/String;)V",
|
||||
at = @At(value = "INVOKE",
|
||||
target = "Lnet/minecraft/resource/ResourcePackManager;<init>(Lnet/minecraft/resource/ResourceType;" +
|
||||
"[Lnet/minecraft/resource/ResourcePackProvider;)V")
|
||||
// after registry manager creation
|
||||
)
|
||||
private static void injectConstructor(String[] args, CallbackInfo ci) {
|
||||
LifecycleUtil.initialize();
|
||||
}
|
||||
}
|
||||
@@ -1,9 +1,10 @@
|
||||
package com.dfsek.terra.lifecycle.util;
|
||||
|
||||
import net.minecraft.registry.DynamicRegistryManager;
|
||||
import net.minecraft.registry.RegistryKey;
|
||||
import net.minecraft.registry.RegistryKeys;
|
||||
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 org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
@@ -29,13 +30,14 @@ public final class BiomeUtil {
|
||||
|
||||
}
|
||||
|
||||
public static void registerBiomes() {
|
||||
public static void registerBiomes(DynamicRegistryManager registryManager) {
|
||||
Registry<net.minecraft.world.biome.Biome> biomeRegistry = registryManager.get(RegistryKeys.BIOME);
|
||||
logger.info("Registering biomes...");
|
||||
CommonPlatform.get().getConfigRegistry().forEach(pack -> { // Register all Terra biomes.
|
||||
pack.getCheckedRegistry(Biome.class)
|
||||
.forEach((id, biome) -> registerBiome(biome, pack, id));
|
||||
.forEach((id, biome) -> registerBiome(biome, pack, id, biomeRegistry));
|
||||
});
|
||||
MinecraftUtil.registerFlora(BuiltinRegistries.BIOME);
|
||||
MinecraftUtil.registerFlora(biomeRegistry);
|
||||
logger.info("Terra biomes registered.");
|
||||
}
|
||||
|
||||
@@ -46,8 +48,8 @@ public final class BiomeUtil {
|
||||
* @param pack The ConfigPack this biome belongs to.
|
||||
*/
|
||||
private static void registerBiome(Biome biome, ConfigPack pack,
|
||||
com.dfsek.terra.api.registry.key.RegistryKey id) {
|
||||
Registry<net.minecraft.world.biome.Biome> registry = BuiltinRegistries.BIOME;
|
||||
com.dfsek.terra.api.registry.key.RegistryKey id,
|
||||
Registry<net.minecraft.world.biome.Biome> registry) {
|
||||
RegistryKey<net.minecraft.world.biome.Biome> vanilla = ((ProtoPlatformBiome) biome.getPlatformBiome()).get(registry);
|
||||
|
||||
|
||||
@@ -56,7 +58,7 @@ public final class BiomeUtil {
|
||||
} else {
|
||||
VanillaBiomeProperties vanillaBiomeProperties = biome.getContext().get(VanillaBiomeProperties.class);
|
||||
|
||||
net.minecraft.world.biome.Biome minecraftBiome = MinecraftUtil.createBiome(biome, registry.get(vanilla),
|
||||
net.minecraft.world.biome.Biome minecraftBiome = MinecraftUtil.createBiome(biome, Objects.requireNonNull(registry.get(vanilla)),
|
||||
vanillaBiomeProperties);
|
||||
|
||||
Identifier identifier = new Identifier("terra", MinecraftUtil.createBiomeID(pack, id));
|
||||
@@ -67,15 +69,15 @@ public final class BiomeUtil {
|
||||
.getKey()
|
||||
.orElseThrow());
|
||||
} else {
|
||||
((ProtoPlatformBiome) biome.getPlatformBiome()).setDelegate(BuiltinRegistries.add(registry,
|
||||
((ProtoPlatformBiome) biome.getPlatformBiome()).setDelegate(Registry.registerReference(registry,
|
||||
MinecraftUtil.registerKey(identifier)
|
||||
.getValue(),
|
||||
minecraftBiome).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)));
|
||||
|
||||
|
||||
@@ -1,6 +1,10 @@
|
||||
package com.dfsek.terra.lifecycle.util;
|
||||
|
||||
import net.minecraft.util.registry.BuiltinRegistries;
|
||||
import com.dfsek.terra.lifecycle.LifecyclePlatform;
|
||||
|
||||
import net.minecraft.registry.DynamicRegistryManager;
|
||||
import net.minecraft.registry.Registry;
|
||||
import net.minecraft.registry.RegistryKeys;
|
||||
|
||||
import com.dfsek.terra.api.event.events.platform.PlatformInitializationEvent;
|
||||
import com.dfsek.terra.mod.CommonPlatform;
|
||||
@@ -11,9 +15,10 @@ public final class LifecycleUtil {
|
||||
|
||||
}
|
||||
|
||||
public static void initialize() {
|
||||
public static void initialize(DynamicRegistryManager registryManager) {
|
||||
LifecyclePlatform.addRegistryManager(registryManager);
|
||||
CommonPlatform.get().getEventManager().callEvent(new PlatformInitializationEvent());
|
||||
BiomeUtil.registerBiomes();
|
||||
CommonPlatform.get().registerWorldTypes((id, preset) -> BuiltinRegistries.add(BuiltinRegistries.WORLD_PRESET, id, preset));
|
||||
BiomeUtil.registerBiomes(registryManager);
|
||||
CommonPlatform.get().registerWorldTypes((id, preset) -> Registry.register(registryManager.get(RegistryKeys.WORLD_PRESET), id, preset));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,13 +6,12 @@
|
||||
"mixins": [
|
||||
"NoiseConfigMixin",
|
||||
"RegistryMixin",
|
||||
"lifecycle.SaveLoadingMixin",
|
||||
"lifecycle.MinecraftServerMixin"
|
||||
],
|
||||
"client": [
|
||||
"lifecycle.client.MinecraftClientMixin"
|
||||
],
|
||||
"server": [
|
||||
"lifecycle.server.ServerMainMixin"
|
||||
],
|
||||
"injectors": {
|
||||
"defaultRequire": 1
|
||||
|
||||
Reference in New Issue
Block a user