Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,8 @@ def setUpLibrary(project) {
implementation "org.apache.logging.log4j:log4j-api:2.19.0"
implementation "org.apache.logging.log4j:log4j-core:2.19.0"

implementation "org.quiltmc.parsers:json:${project.rootProject.quilt_parsers_version}"

implementation project.dependencies.project(path: ':libraries:core', configuration: 'namedElements')

libraries.each { libraryPath ->
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package net.ornithemc.osl.core.api.util;

public enum Unit {

INSTANCE

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package net.ornithemc.osl.core.api.util.function;

import java.io.IOException;

public interface IOSupplier<T> {

T get() throws IOException;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package net.ornithemc.osl.core.impl.util;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.CompletableFuture;

public final class Util {

public static <V> CompletableFuture<List<V>> sequence(List<? extends CompletableFuture<? extends V>> futures) {
List<V> results = new ArrayList<>(futures.size());

CompletableFuture<?>[] sequence = new CompletableFuture[futures.size()];
CompletableFuture<Void> failure = new CompletableFuture<>();

futures.forEach(future -> {
int i = results.size();
results.add(null);

sequence[i] = future.whenComplete((result, exception) -> {
if (exception != null) {
failure.completeExceptionally(exception);
} else {
results.set(i, result);
}
});
});

return CompletableFuture.allOf(sequence).applyToEither(failure, v -> results);
}
}
3 changes: 3 additions & 0 deletions libraries/localization/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Localization API

The Localization API provides a consistent access point for localized text, and adds support for localization in versions that do not natively do so.
5 changes: 5 additions & 0 deletions libraries/localization/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
setUpLibrary(project)

dependencies {
implementation 'com.google.code.gson:gson:2.8.0'
}
6 changes: 6 additions & 0 deletions libraries/localization/gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
library_id = localization
library_name = Localization
library_description = Localization API and events.
library_version = 0.1.0-alpha.1

osl_dependencies = core:>=0.7.0,text-components:>=0.1.0-,resource-loader:>=0.6.0
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
min_mc_version = 11w49a
max_mc_version = 1.5.2
minecraft_dependency = >=1.1-alpha.11.49.a <=1.5.2

minecraft_version = 1.5.2
client_nests_build = 6
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package net.ornithemc.osl.localization.impl.mixin.client;

import java.util.Properties;

import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.gen.Accessor;

import net.minecraft.locale.Language;

@Mixin(Language.class)
public interface LanguageAccess {

@Accessor("translations")
Properties accessTranslations();

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package net.ornithemc.osl.localization.impl.mixin.client;

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.callback.CallbackInfo;

import net.minecraft.locale.Language;

import net.ornithemc.osl.localization.impl.Localization;

@Mixin(Language.class)
public class LanguageMixin {

@Shadow
private static Language INSTANCE;

@Shadow
private String currentCode;

@Inject(
method = "<clinit>",
at = @At(
value = "TAIL"
)
)
private static void osl$localization$initLocale(CallbackInfo ci) {
Localization.getLocale().wrap(((LanguageAccess) INSTANCE).accessTranslations());
}

@Inject(
method = "load",
at = @At(
value = "TAIL"
)
)
private void osl$localization$reloadLanguageManager(CallbackInfo ci) {
// each ServerPlayerEntity also holds an instance of this class
if ((Language) (Object) this == INSTANCE) {
Localization.reloadLanguageManager();
}
}

@Inject(
method = "loadLanguage",
at = @At(
value = "TAIL"
)
)
private void osl$localization$setLanguage(CallbackInfo ci) {
// each ServerPlayerEntity also holds an instance of this class
if ((Language) (Object) this == INSTANCE) {
Localization.getLanguageManager().setSelectedLanguage(this.currentCode);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"schemaVersion": 1,
"id": "osl-localization",
"version": "0.1.0-alpha.1+mc11w49a-mc1.5.2",
"environment": "*",
"mixins": [
"osl.localization.mixins.json"
],
"depends": {
"fabricloader": "\u003e\u003d0.18.0",
"minecraft": "\u003e\u003d1.1-alpha.11.49.a \u003c\u003d1.5.2",
"osl-core": "\u003e\u003d0.7.0",
"osl-text-components": "\u003e\u003d0.1.0-",
"osl-resource-loader": "\u003e\u003d0.6.0"
},
"name": "OSL Localization",
"description": "Localization API and events.",
"authors": [
"OrnitheMC"
],
"contact": {
"homepage": "https://ornithemc.net/",
"issues": "https://github.com/OrnitheMC/ornithe-standard-libraries/issues",
"sources": "https://github.com/OrnitheMC/ornithe-standard-libraries"
},
"license": "Apache-2.0"
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{
"required": true,
"minVersion": "0.8",
"package": "net.ornithemc.osl.resource.loader.impl.mixin",
"package": "net.ornithemc.osl.localization.impl.mixin",
"compatibilityLevel": "JAVA_8",
"mixins": [
],
"client": [
"client.TexturePackMixin",
"client.LanguageAccess",
"client.LanguageMixin"
],
"server": [
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
min_mc_version = 13w26a
max_mc_version = 18w01a
minecraft_dependency = >=1.6-alpha.13.26.a <=1.13-alpha.18.1.a

minecraft_version = 1.8.2-pre4
raven_build = 1
sparrow_build = 1
nests_build = 3
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package net.ornithemc.osl.localization.impl.access;

import net.ornithemc.osl.core.api.util.NamespacedIdentifier;

public interface SimpleResourceAccess {

NamespacedIdentifier osl$localization$getLocation();

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package net.ornithemc.osl.localization.impl.mixin.client;

import java.util.Map;

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.callback.CallbackInfo;

import net.minecraft.client.resource.language.LanguageManager;

import net.ornithemc.osl.localization.api.language.Language;
import net.ornithemc.osl.localization.impl.Localization;

@Mixin(LanguageManager.class)
public class LanguageManagerMixin {

@Shadow
private Map<String, Language> languages;

@Shadow
private String currentCode;

@Inject(
method = "<init>",
at = @At(
value = "TAIL"
)
)
private void osl$localization$initLanguageManager(CallbackInfo ci) {
Localization.getLanguageManager().wrap(this.languages, net.minecraft.client.resource.language.Language::new);
}

@Inject(
method = "setLanguage",
at = @At(
value = "TAIL"
)
)
private void osl$localization$setLanguage(CallbackInfo ci) {
Localization.getLanguageManager().setSelectedLanguage(this.currentCode);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package net.ornithemc.osl.localization.impl.mixin.client;

import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;

import net.ornithemc.osl.localization.api.language.Language;

@Mixin(net.minecraft.client.resource.language.Language.class)
public class LanguageMixin implements Language {

@Shadow
private String code;
@Shadow
private String region;
@Shadow
private String name;
@Shadow
private boolean bidirectional;

@Override
public String code() {
return this.code;
}

@Override
public String name() {
return this.name;
}

@Override
public String region() {
return this.region;
}

@Override
public boolean bidirectional() {
return this.bidirectional;
}
}
Loading
Loading