mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2026-04-18 06:10:16 +00:00
reformat all code
This commit is contained in:
@@ -1,32 +1,22 @@
|
||||
package com.dfsek.terra.forge;
|
||||
|
||||
import com.dfsek.terra.AbstractPlatform;
|
||||
|
||||
import cpw.mods.cl.ModuleClassLoader;
|
||||
import net.minecraftforge.fml.loading.FMLLoader;
|
||||
import org.burningwave.core.classes.Classes;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Field;
|
||||
import java.net.URISyntaxException;
|
||||
import java.net.URL;
|
||||
import java.nio.file.FileVisitOption;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Enumeration;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
import java.util.jar.JarEntry;
|
||||
import java.util.jar.JarFile;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import com.dfsek.terra.AbstractPlatform;
|
||||
import com.dfsek.terra.api.addon.bootstrap.BootstrapAddonClassLoader;
|
||||
|
||||
|
||||
@@ -73,7 +63,7 @@ public final class AwfulForgeHacks {
|
||||
}
|
||||
|
||||
public static void loadAllTerraClasses() {
|
||||
if (FMLLoader.isProduction()) {
|
||||
if(FMLLoader.isProduction()) {
|
||||
try(JarFile jar = getTerraJar()) {
|
||||
jar.stream()
|
||||
.forEach(jarEntry -> {
|
||||
@@ -96,45 +86,52 @@ public final class AwfulForgeHacks {
|
||||
}
|
||||
} else {
|
||||
// Forgive me for what I'm about to do...
|
||||
LOGGER.warn("I felt a great disturbance in the JVM, as if millions of class not found exceptions suddenly cried out in terror and were suddenly silenced.");
|
||||
LOGGER.warn(
|
||||
"I felt a great disturbance in the JVM, as if millions of class not found exceptions suddenly cried out in terror and" +
|
||||
" were suddenly silenced.");
|
||||
ArrayList<Path> pathsToLoad = new ArrayList<>();
|
||||
|
||||
Path terraRoot = Path.of(System.getProperty("user.dir")).getParent().getParent().getParent();
|
||||
Path commonRoot = terraRoot.resolve("common");
|
||||
Path implementationRoot = commonRoot.resolve("implementation");
|
||||
|
||||
|
||||
pathsToLoad.add(commonRoot.resolve("api"));
|
||||
pathsToLoad.add(implementationRoot.resolve("base"));
|
||||
pathsToLoad.add(implementationRoot.resolve("bootstrap-addon-loader"));
|
||||
for (Path path : pathsToLoad) {
|
||||
for(Path path : pathsToLoad) {
|
||||
try {
|
||||
Path target = path.resolve("build").resolve("classes").resolve("java").resolve("main");
|
||||
|
||||
BootstrapAddonClassLoader cl = new BootstrapAddonClassLoader(new URL[] { path.toUri().toURL()});
|
||||
|
||||
Classes.Loaders omegaCL = Classes.Loaders.create();
|
||||
BootstrapAddonClassLoader cl = new BootstrapAddonClassLoader(new URL[]{ path.toUri().toURL() });
|
||||
|
||||
Classes.Loaders omegaCL = Classes.Loaders.create();
|
||||
Files.walk(target, Integer.MAX_VALUE, FileVisitOption.FOLLOW_LINKS)
|
||||
.filter(it -> it.getFileName().toString().endsWith(".class"))
|
||||
.map(Path::toFile)
|
||||
.forEach(it -> {
|
||||
String name = it.getAbsolutePath().replace(target + "/", "").replace('\\', '.').replace('/', '.');
|
||||
name = name.substring(0, name.length() - 6);
|
||||
LOGGER.info("Loading class {}", name);
|
||||
try {
|
||||
Class.forName(name);
|
||||
} catch(ClassNotFoundException e) {
|
||||
try {
|
||||
String pathToJar = cl.loadClass(name).getProtectionDomain().getCodeSource().getLocation().toURI().getPath();
|
||||
|
||||
cl.addURL(new URL("jar:file:" + pathToJar + "!/"));
|
||||
Class newClassLoad = Class.forName(name, true, cl);
|
||||
omegaCL.loadOrDefine(newClassLoad, AbstractPlatform.class.getClassLoader());
|
||||
} catch(ClassNotFoundException | URISyntaxException | IOException ex) {
|
||||
throw new RuntimeException(ex);
|
||||
}
|
||||
|
||||
}
|
||||
});
|
||||
.filter(it -> it.getFileName().toString().endsWith(".class"))
|
||||
.map(Path::toFile)
|
||||
.forEach(it -> {
|
||||
String name = it.getAbsolutePath().replace(target + "/", "").replace('\\', '.').replace('/', '.');
|
||||
name = name.substring(0, name.length() - 6);
|
||||
LOGGER.info("Loading class {}", name);
|
||||
try {
|
||||
Class.forName(name);
|
||||
} catch(ClassNotFoundException e) {
|
||||
try {
|
||||
String pathToJar = cl.loadClass(name)
|
||||
.getProtectionDomain()
|
||||
.getCodeSource()
|
||||
.getLocation()
|
||||
.toURI()
|
||||
.getPath();
|
||||
|
||||
cl.addURL(new URL("jar:file:" + pathToJar + "!/"));
|
||||
Class newClassLoad = Class.forName(name, true, cl);
|
||||
omegaCL.loadOrDefine(newClassLoad, AbstractPlatform.class.getClassLoader());
|
||||
} catch(ClassNotFoundException | URISyntaxException | IOException ex) {
|
||||
throw new RuntimeException(ex);
|
||||
}
|
||||
|
||||
}
|
||||
});
|
||||
} catch(IOException e) {
|
||||
throw new IllegalStateException("Could not load all Terra classes", e);
|
||||
}
|
||||
|
||||
@@ -3,12 +3,13 @@ package com.dfsek.terra.forge;
|
||||
import com.dfsek.terra.mod.MinecraftAddon;
|
||||
import com.dfsek.terra.mod.ModPlatform;
|
||||
|
||||
public class ForgeAddon extends MinecraftAddon {
|
||||
|
||||
public class ForgeAddon extends MinecraftAddon {
|
||||
|
||||
public ForgeAddon(ModPlatform modPlatform) {
|
||||
super(modPlatform);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getID() {
|
||||
return "terra-forge";
|
||||
|
||||
@@ -43,28 +43,24 @@ import com.dfsek.terra.mod.data.Codecs;
|
||||
@Mod("terra")
|
||||
@EventBusSubscriber(bus = Bus.MOD)
|
||||
public class ForgeEntryPoint {
|
||||
private final RegistrySanityCheck sanityCheck = new RegistrySanityCheck();
|
||||
|
||||
public static final String MODID = "terra";
|
||||
private static final Logger logger = LoggerFactory.getLogger(ForgeEntryPoint.class);
|
||||
private static final ForgePlatform TERRA_PLUGIN;
|
||||
static {
|
||||
AwfulForgeHacks.loadAllTerraClasses();
|
||||
TERRA_PLUGIN = new ForgePlatform();
|
||||
}
|
||||
|
||||
public static final String MODID = "terra";
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(ForgeEntryPoint.class);
|
||||
|
||||
private static final ForgePlatform TERRA_PLUGIN;
|
||||
|
||||
public static ForgePlatform getPlatform() {
|
||||
return TERRA_PLUGIN;
|
||||
}
|
||||
private final RegistrySanityCheck sanityCheck = new RegistrySanityCheck();
|
||||
|
||||
public ForgeEntryPoint() {
|
||||
IEventBus modEventBus = FMLJavaModLoadingContext.get().getModEventBus();
|
||||
modEventBus.register(this);
|
||||
}
|
||||
|
||||
public static ForgePlatform getPlatform() {
|
||||
return TERRA_PLUGIN;
|
||||
}
|
||||
|
||||
public static void initialize(RegisterHelper<Biome> helper) {
|
||||
getPlatform().getEventManager().callEvent(
|
||||
new PlatformInitializationEvent());
|
||||
@@ -75,10 +71,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, helper -> sanityCheck.progress(RegistryStep.WORLD_TYPE, () -> TERRA_PLUGIN.registerWorldTypes(helper::register)));
|
||||
event.register(Registry.WORLD_PRESET_KEY,
|
||||
helper -> sanityCheck.progress(RegistryStep.WORLD_TYPE, () -> TERRA_PLUGIN.registerWorldTypes(helper::register)));
|
||||
|
||||
|
||||
event.register(Registry.CHUNK_GENERATOR_KEY, helper -> helper.register(new Identifier("terra:terra"), Codecs.MINECRAFT_CHUNK_GENERATOR_WRAPPER));
|
||||
event.register(Registry.CHUNK_GENERATOR_KEY,
|
||||
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));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -43,33 +43,33 @@ import com.dfsek.terra.mod.generation.MinecraftChunkGeneratorWrapper;
|
||||
public class ForgePlatform extends ModPlatform {
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(ForgePlatform.class);
|
||||
private final Lazy<File> dataFolder = Lazy.lazy(() -> new File("./config/Terra"));
|
||||
|
||||
|
||||
public ForgePlatform() {
|
||||
CommonPlatform.initialize(this);
|
||||
load();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public MinecraftServer getServer() {
|
||||
return ServerLifecycleHooks.getCurrentServer();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean reload() {
|
||||
getTerraConfig().load(this);
|
||||
getRawConfigRegistry().clear();
|
||||
boolean succeed = getRawConfigRegistry().loadAll(this);
|
||||
|
||||
|
||||
MinecraftServer server = getServer();
|
||||
|
||||
if (server != null) {
|
||||
|
||||
if(server != null) {
|
||||
server.reloadResources(server.getDataPackManager().getNames()).exceptionally(throwable -> {
|
||||
LOGGER.warn("Failed to execute reload", throwable);
|
||||
return null;
|
||||
}).join();
|
||||
//BiomeUtil.registerBiomes();
|
||||
server.getWorlds().forEach(world -> {
|
||||
if (world.getChunkManager().getChunkGenerator() instanceof MinecraftChunkGeneratorWrapper chunkGeneratorWrapper) {
|
||||
if(world.getChunkManager().getChunkGenerator() instanceof MinecraftChunkGeneratorWrapper chunkGeneratorWrapper) {
|
||||
getConfigRegistry().get(chunkGeneratorWrapper.getPack().getRegistryKey()).ifPresent(pack -> {
|
||||
chunkGeneratorWrapper.setPack(pack);
|
||||
LOGGER.info("Replaced pack in chunk generator for world {}", world);
|
||||
@@ -79,34 +79,35 @@ public class ForgePlatform extends ModPlatform {
|
||||
}
|
||||
return succeed;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected Iterable<BaseAddon> platformAddon() {
|
||||
List<BaseAddon> addons = new ArrayList<>();
|
||||
|
||||
|
||||
super.platformAddon().forEach(addons::add);
|
||||
|
||||
|
||||
String mcVersion = MinecraftVersion.CURRENT.getReleaseTarget();
|
||||
try {
|
||||
addons.add(new EphemeralAddon(Versions.parseVersion(mcVersion), "minecraft"));
|
||||
} catch (ParseException e) {
|
||||
} catch(ParseException e) {
|
||||
try {
|
||||
addons.add(new EphemeralAddon(Versions.parseVersion(mcVersion + ".0"), "minecraft"));
|
||||
} catch (ParseException ex) {
|
||||
} catch(ParseException ex) {
|
||||
LOGGER.warn("Failed to parse Minecraft version", e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
FMLLoader.getLoadingModList().getMods().forEach(mod -> {
|
||||
String id = mod.getModId();
|
||||
if (id.equals("terra") || id.equals("minecraft") || id.equals("java")) return;
|
||||
Version version = Versions.getVersion(mod.getVersion().getMajorVersion(), mod.getVersion().getMinorVersion(), mod.getVersion().getIncrementalVersion());
|
||||
if(id.equals("terra") || id.equals("minecraft") || id.equals("java")) return;
|
||||
Version version = Versions.getVersion(mod.getVersion().getMajorVersion(), mod.getVersion().getMinorVersion(),
|
||||
mod.getVersion().getIncrementalVersion());
|
||||
addons.add(new EphemeralAddon(version, "forge:" + id));
|
||||
});
|
||||
|
||||
|
||||
return addons;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public @NotNull String platformName() {
|
||||
return "Forge";
|
||||
@@ -116,7 +117,7 @@ public class ForgePlatform extends ModPlatform {
|
||||
public @NotNull File getDataFolder() {
|
||||
return dataFolder.value();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public BaseAddon getPlatformAddon() {
|
||||
return new ForgeAddon(this);
|
||||
|
||||
@@ -24,7 +24,15 @@ public class NoiseConfigMixin {
|
||||
@Final
|
||||
private long legacyWorldSeed;
|
||||
|
||||
@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;"))
|
||||
@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) {
|
||||
|
||||
@@ -1,8 +1,5 @@
|
||||
package com.dfsek.terra.forge.util;
|
||||
|
||||
import com.dfsek.terra.mod.config.VanillaBiomeProperties;
|
||||
import com.dfsek.terra.mod.mixin.access.VillagerTypeAccessor;
|
||||
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.registry.BuiltinRegistries;
|
||||
import net.minecraft.util.registry.Registry;
|
||||
@@ -22,6 +19,8 @@ import com.dfsek.terra.api.world.biome.Biome;
|
||||
import com.dfsek.terra.forge.ForgeEntryPoint;
|
||||
import com.dfsek.terra.mod.config.PreLoadCompatibilityOptions;
|
||||
import com.dfsek.terra.mod.config.ProtoPlatformBiome;
|
||||
import com.dfsek.terra.mod.config.VanillaBiomeProperties;
|
||||
import com.dfsek.terra.mod.mixin.access.VillagerTypeAccessor;
|
||||
import com.dfsek.terra.mod.util.MinecraftUtil;
|
||||
|
||||
|
||||
@@ -32,7 +31,7 @@ public final class BiomeUtil {
|
||||
private BiomeUtil() {
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static void registerBiomes(RegisterHelper<net.minecraft.world.biome.Biome> helper) {
|
||||
logger.info("Registering biomes...");
|
||||
@@ -51,29 +50,41 @@ 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, RegisterHelper<net.minecraft.world.biome.Biome> helper) {
|
||||
RegistryKey<net.minecraft.world.biome.Biome> vanilla = ((ProtoPlatformBiome) biome.getPlatformBiome()) .get(BuiltinRegistries.BIOME);
|
||||
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);
|
||||
|
||||
|
||||
if(pack.getContext().get(PreLoadCompatibilityOptions.class).useVanillaBiomes()) {
|
||||
((ProtoPlatformBiome) biome.getPlatformBiome()).setDelegate(vanilla);
|
||||
} else {
|
||||
VanillaBiomeProperties vanillaBiomeProperties = biome.getContext().get(VanillaBiomeProperties.class);
|
||||
|
||||
net.minecraft.world.biome.Biome minecraftBiome = MinecraftUtil.createBiome(biome, ForgeRegistries.BIOMES.getDelegateOrThrow(vanilla).value(), vanillaBiomeProperties);
|
||||
|
||||
net.minecraft.world.biome.Biome minecraftBiome = MinecraftUtil.createBiome(biome,
|
||||
ForgeRegistries.BIOMES.getDelegateOrThrow(vanilla)
|
||||
.value(),
|
||||
vanillaBiomeProperties);
|
||||
|
||||
Identifier identifier = new Identifier("terra", MinecraftUtil.createBiomeID(pack, id));
|
||||
|
||||
if(ForgeRegistries.BIOMES.containsKey(identifier)) {
|
||||
((ProtoPlatformBiome) biome.getPlatformBiome()).setDelegate(ForgeRegistries.BIOMES.getHolder(identifier).orElseThrow().getKey().orElseThrow());
|
||||
((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());
|
||||
((ProtoPlatformBiome) biome.getPlatformBiome()).setDelegate(ForgeRegistries.BIOMES.getHolder(identifier)
|
||||
.orElseThrow()
|
||||
.getKey()
|
||||
.orElseThrow());
|
||||
}
|
||||
|
||||
Map villagerMap = VillagerTypeAccessor.getBiomeTypeToIdMap();
|
||||
|
||||
villagerMap.put(RegistryKey.of(Registry.BIOME_KEY, identifier), Objects.requireNonNullElse(vanillaBiomeProperties.getVillagerType(), villagerMap.getOrDefault(vanilla, VillagerType.PLAINS)));
|
||||
villagerMap.put(RegistryKey.of(Registry.BIOME_KEY, identifier),
|
||||
Objects.requireNonNullElse(vanillaBiomeProperties.getVillagerType(),
|
||||
villagerMap.getOrDefault(vanilla, VillagerType.PLAINS)));
|
||||
|
||||
MinecraftUtil.TERRA_BIOME_MAP.computeIfAbsent(vanilla.getValue(), i -> new ArrayList<>()).add(identifier);
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
modLoader = "javafml"
|
||||
loaderVersion = "[41,)"
|
||||
license = "GNU General Public License, v3.0"
|
||||
issueTrackerURL="https://github.com/PolyhedralDev/Terra/issues"
|
||||
issueTrackerURL = "https://github.com/PolyhedralDev/Terra/issues"
|
||||
|
||||
[[mods]]
|
||||
modId = "terra"
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"pack": {
|
||||
"description": "Terra Resources",
|
||||
"pack_format": 9
|
||||
}
|
||||
"pack": {
|
||||
"description": "Terra Resources",
|
||||
"pack_format": 9
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
"package": "com.dfsek.terra.forge.mixin",
|
||||
"compatibilityLevel": "JAVA_17",
|
||||
"mixins": [
|
||||
"lifecycle.NoiseConfigMixin"
|
||||
"lifecycle.NoiseConfigMixin"
|
||||
],
|
||||
"client": [
|
||||
],
|
||||
|
||||
Reference in New Issue
Block a user