mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2026-04-19 14:50:30 +00:00
Change Java whitespace handling in .editorconfig (#425)
* Change whitespace handling in .editorconfig * Reformat code * fix format error * Reformat code --------- Co-authored-by: Zoë Gidiere <duplexsys@protonmail.com>
This commit is contained in:
@@ -26,7 +26,7 @@ import com.dfsek.terra.api.addon.bootstrap.BootstrapAddonClassLoader;
|
||||
*/
|
||||
public final class AwfulForgeHacks {
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(AwfulForgeHacks.class);
|
||||
|
||||
|
||||
/**
|
||||
* Forge tampers with code source to make the *normal* way of getting the current JAR file useless, so this awful hack is
|
||||
* needed.
|
||||
@@ -42,114 +42,114 @@ public final class AwfulForgeHacks {
|
||||
public static JarFile getTerraJar() throws IOException {
|
||||
LOGGER.info("Scanning for Terra JAR...");
|
||||
return Files.walk(Path.of(System.getProperty("user.dir"), "mods"), 1, FileVisitOption.FOLLOW_LINKS)
|
||||
.filter(it -> it.getFileName().toString().endsWith(".jar"))
|
||||
.peek(path -> LOGGER.info("Found mod: {}", path))
|
||||
.map(Path::toFile)
|
||||
.flatMap(path -> {
|
||||
try {
|
||||
return Stream.of(new JarFile(path));
|
||||
} catch(IOException e) {
|
||||
LOGGER.error("Malformed mod JAR: {}: {}", path, e);
|
||||
return Stream.of();
|
||||
}
|
||||
})
|
||||
.filter(jar -> jar
|
||||
.stream()
|
||||
.anyMatch(entry -> entry
|
||||
.getName()
|
||||
.equals(ForgeEntryPoint.class.getName().replace('.', '/') + ".class")))
|
||||
.findFirst()
|
||||
.orElseThrow(() -> new IllegalStateException("Could not find Terra JAR"));
|
||||
.filter(it -> it.getFileName().toString().endsWith(".jar"))
|
||||
.peek(path -> LOGGER.info("Found mod: {}", path))
|
||||
.map(Path::toFile)
|
||||
.flatMap(path -> {
|
||||
try {
|
||||
return Stream.of(new JarFile(path));
|
||||
} catch(IOException e) {
|
||||
LOGGER.error("Malformed mod JAR: {}: {}", path, e);
|
||||
return Stream.of();
|
||||
}
|
||||
})
|
||||
.filter(jar -> jar
|
||||
.stream()
|
||||
.anyMatch(entry -> entry
|
||||
.getName()
|
||||
.equals(ForgeEntryPoint.class.getName().replace('.', '/') + ".class")))
|
||||
.findFirst()
|
||||
.orElseThrow(() -> new IllegalStateException("Could not find Terra JAR"));
|
||||
}
|
||||
|
||||
|
||||
public static void loadAllTerraClasses() {
|
||||
if(FMLLoader.isProduction()) {
|
||||
try(JarFile jar = getTerraJar()) {
|
||||
jar.stream()
|
||||
.forEach(jarEntry -> {
|
||||
if(jarEntry.getName().startsWith("com/dfsek/terra/forge/mixin")
|
||||
|| jarEntry.getName().startsWith("com/dfsek/terra/mod/mixin")) {
|
||||
return;
|
||||
}
|
||||
if(jarEntry.getName().endsWith(".class")) {
|
||||
String name = jarEntry.getName().replace('/', '.');
|
||||
name = name.substring(0, name.length() - 6);
|
||||
try {
|
||||
Class.forName(name);
|
||||
} catch(ClassNotFoundException | NoClassDefFoundError e) {
|
||||
LOGGER.warn("Failed to load class {}: {}", name, e);
|
||||
}
|
||||
}
|
||||
});
|
||||
.forEach(jarEntry -> {
|
||||
if(jarEntry.getName().startsWith("com/dfsek/terra/forge/mixin")
|
||||
|| jarEntry.getName().startsWith("com/dfsek/terra/mod/mixin")) {
|
||||
return;
|
||||
}
|
||||
if(jarEntry.getName().endsWith(".class")) {
|
||||
String name = jarEntry.getName().replace('/', '.');
|
||||
name = name.substring(0, name.length() - 6);
|
||||
try {
|
||||
Class.forName(name);
|
||||
} catch(ClassNotFoundException | NoClassDefFoundError e) {
|
||||
LOGGER.warn("Failed to load class {}: {}", name, e);
|
||||
}
|
||||
}
|
||||
});
|
||||
} catch(IOException e) {
|
||||
throw new IllegalStateException("Could not load all Terra classes", e);
|
||||
}
|
||||
} 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.");
|
||||
"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) {
|
||||
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();
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public enum RegistryStep {
|
||||
BLOCK,
|
||||
BIOME,
|
||||
WORLD_TYPE,
|
||||
DONE
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public static class RegistrySanityCheck {
|
||||
private final AtomicReference<RegistryStep> step = new AtomicReference<>(RegistryStep.BLOCK);
|
||||
|
||||
|
||||
public <T> void progress(RegistryStep expected, Runnable action) {
|
||||
step.getAndUpdate(s -> {
|
||||
if(s != expected) {
|
||||
|
||||
@@ -5,11 +5,11 @@ import com.dfsek.terra.mod.ModPlatform;
|
||||
|
||||
|
||||
public class ForgeAddon extends MinecraftAddon {
|
||||
|
||||
|
||||
public ForgeAddon(ModPlatform modPlatform) {
|
||||
super(modPlatform);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getID() {
|
||||
return "terra-forge";
|
||||
|
||||
@@ -51,32 +51,32 @@ public class ForgeEntryPoint {
|
||||
TERRA_PLUGIN = new ForgePlatform();
|
||||
}
|
||||
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());
|
||||
new PlatformInitializationEvent());
|
||||
BiomeUtil.registerBiomes(helper);
|
||||
}
|
||||
|
||||
|
||||
@SubscribeEvent(priority = EventPriority.LOWEST)
|
||||
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(RegistryKeys.WORLD_PRESET,
|
||||
helper -> sanityCheck.progress(RegistryStep.WORLD_TYPE, () -> TERRA_PLUGIN.registerWorldTypes(helper::register)));
|
||||
|
||||
|
||||
helper -> sanityCheck.progress(RegistryStep.WORLD_TYPE, () -> TERRA_PLUGIN.registerWorldTypes(helper::register)));
|
||||
|
||||
|
||||
event.register(RegistryKeys.CHUNK_GENERATOR,
|
||||
helper -> helper.register(new Identifier("terra:terra"), Codecs.MINECRAFT_CHUNK_GENERATOR_WRAPPER));
|
||||
helper -> helper.register(new Identifier("terra:terra"), Codecs.MINECRAFT_CHUNK_GENERATOR_WRAPPER));
|
||||
event.register(RegistryKeys.BIOME_SOURCE, helper -> helper.register(new Identifier("terra:terra"), Codecs.TERRA_BIOME_SOURCE));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -48,25 +48,25 @@ 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) {
|
||||
server.reloadResources(server.getDataPackManager().getNames()).exceptionally(throwable -> {
|
||||
LOGGER.warn("Failed to execute reload", throwable);
|
||||
@@ -84,13 +84,13 @@ 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.getName();
|
||||
try {
|
||||
addons.add(new EphemeralAddon(Versions.parseVersion(mcVersion), "minecraft"));
|
||||
@@ -101,48 +101,48 @@ public class ForgePlatform extends ModPlatform {
|
||||
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());
|
||||
mod.getVersion().getIncrementalVersion());
|
||||
addons.add(new EphemeralAddon(version, "forge:" + id));
|
||||
});
|
||||
|
||||
|
||||
return addons;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public @NotNull String platformName() {
|
||||
return "Forge";
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public @NotNull File getDataFolder() {
|
||||
return dataFolder.value();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public BaseAddon getPlatformAddon() {
|
||||
return new ForgeAddon(this);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Registry<DimensionType> dimensionTypeRegistry() {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Registry<Biome> biomeRegistry() {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Registry<ChunkGeneratorSettings> chunkGeneratorSettingsRegistry() {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Registry<MultiNoiseBiomeSourceParameterList> multiNoiseBiomeSourceParameterListRegistry() {
|
||||
return null;
|
||||
|
||||
@@ -23,7 +23,7 @@ public class NoiseConfigMixin {
|
||||
@Shadow
|
||||
@Final
|
||||
private MultiNoiseSampler multiNoiseSampler;
|
||||
|
||||
|
||||
@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,
|
||||
|
||||
@@ -26,13 +26,13 @@ import com.dfsek.terra.mod.util.MinecraftUtil;
|
||||
|
||||
public final class BiomeUtil {
|
||||
private static final Logger logger = LoggerFactory.getLogger(BiomeUtil.class);
|
||||
|
||||
|
||||
|
||||
|
||||
private BiomeUtil() {
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public static void registerBiomes(RegisterHelper<net.minecraft.world.biome.Biome> helper) {
|
||||
logger.info("Registering biomes...");
|
||||
ForgeEntryPoint.getPlatform().getConfigRegistry().forEach(pack -> { // Register all Terra biomes.
|
||||
@@ -41,7 +41,7 @@ public final class BiomeUtil {
|
||||
});
|
||||
logger.info("Terra biomes registered.");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Clones a Vanilla biome and injects Terra data to create a Terra-vanilla biome delegate.
|
||||
*
|
||||
@@ -52,39 +52,39 @@ public final class BiomeUtil {
|
||||
com.dfsek.terra.api.registry.key.RegistryKey id,
|
||||
RegisterHelper<net.minecraft.world.biome.Biome> helper) {
|
||||
RegistryEntry<net.minecraft.world.biome.Biome>
|
||||
vanilla = ForgeRegistries.BIOMES.getHolder(((ProtoPlatformBiome) biome.getPlatformBiome()).getHandle()).orElseThrow();
|
||||
|
||||
|
||||
vanilla = ForgeRegistries.BIOMES.getHolder(((ProtoPlatformBiome) biome.getPlatformBiome()).getHandle()).orElseThrow();
|
||||
|
||||
|
||||
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.getKey().orElseThrow())
|
||||
.value(),
|
||||
vanillaBiomeProperties);
|
||||
|
||||
ForgeRegistries.BIOMES.getDelegateOrThrow(
|
||||
vanilla.getKey().orElseThrow())
|
||||
.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());
|
||||
.orElseThrow());
|
||||
} else {
|
||||
helper.register(MinecraftUtil.registerKey(identifier).getValue(), minecraftBiome);
|
||||
((ProtoPlatformBiome) biome.getPlatformBiome()).setDelegate(ForgeRegistries.BIOMES.getHolder(identifier)
|
||||
.orElseThrow());
|
||||
.orElseThrow());
|
||||
}
|
||||
|
||||
|
||||
Map<RegistryKey<net.minecraft.world.biome.Biome>, VillagerType> villagerMap = VillagerTypeAccessor.getBiomeTypeToIdMap();
|
||||
|
||||
|
||||
villagerMap.put(RegistryKey.of(RegistryKeys.BIOME, identifier),
|
||||
Objects.requireNonNullElse(vanillaBiomeProperties.getVillagerType(),
|
||||
villagerMap.getOrDefault(vanilla.getKey().orElseThrow(), VillagerType.PLAINS)));
|
||||
|
||||
Objects.requireNonNullElse(vanillaBiomeProperties.getVillagerType(),
|
||||
villagerMap.getOrDefault(vanilla.getKey().orElseThrow(), VillagerType.PLAINS)));
|
||||
|
||||
MinecraftUtil.TERRA_BIOME_MAP.computeIfAbsent(vanilla.getKey().orElseThrow().getValue(), i -> new ArrayList<>()).add(
|
||||
identifier);
|
||||
identifier);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user