Port to java 16 and MC 1.17

This commit is contained in:
ffrann
2021-05-26 20:27:14 -04:00
parent c2d7cacdab
commit f468546eea
21 changed files with 157 additions and 156 deletions
+10 -4
View File
@@ -4,13 +4,15 @@
*The last config library you will ever use.*
ΩConfig is a hyper-minimal config library based on [Auto Config](https://github.com/shedaniel/AutoConfig). It aims to achieve
the following goals:
ΩConfig is a hyper-minimal config library based on [Auto Config](https://github.com/shedaniel/AutoConfig). It aims to
achieve the following goals:
- Be lightweight (<10 KB) for JIJ usage
- Exceedingly simple design & API for developers
- Intuition and usability for players
The following is an example of a simple ΩConfig setup:
```java
public class TestConfig implements Config {
@@ -24,6 +26,7 @@ public class TestConfig implements Config {
}
```
```java
public class MyModInitializer {
@@ -35,7 +38,9 @@ public class MyModInitializer {
}
}
```
---
### Extra API Utilities
ΩConfig provides several utility methods for developers.
@@ -48,6 +53,7 @@ MyModInitializer.CONFIG.save(); // writes the new value to disk
```
---
### License
ΩConfig is available under Public Domain.
You are encouraged to utilize the code in this repository in any way you wish.
ΩConfig is available under Public Domain. You are encouraged to utilize the code in this repository in any way you wish.
+13 -10
View File
@@ -10,7 +10,7 @@ buildscript {
}
dependencies {
classpath 'com.guardsquare:proguard-gradle:7.0.1'
classpath 'com.guardsquare:proguard-gradle:7.1.0-beta4'
}
}
@@ -137,7 +137,7 @@ subprojects {
allprojects {
apply plugin: "fabric-loom"
sourceCompatibility = targetCompatibility = JavaVersion.VERSION_1_8
sourceCompatibility = targetCompatibility = JavaVersion.VERSION_16
version = System.getenv("TRAVIS_TAG") ?: project.mod_version
repositories {
@@ -155,10 +155,19 @@ allprojects {
mappings "net.fabricmc:yarn:${project.yarn_mappings}:v2"
modImplementation "net.fabricmc:fabric-loader:${project.loader_version}"
modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}"
modRuntime "com.terraformersmc:modmenu:1.16.8"
modCompileOnly "com.terraformersmc:modmenu:1.16.8"
modRuntime "com.terraformersmc:modmenu:2.0.0-beta.4"
modCompileOnly "com.terraformersmc:modmenu:2.0.0-beta.4"
}
}
jar {
from(rootProject.file("LICENSE.md")) {
rename { "LICENSE_${project.archivesBaseName.replace('-', '_')}" }
}
}
afterEvaluate {
processResources {
// this will ensure that this task is redone when there"s a change
inputs.property "version", mod_version
@@ -176,12 +185,6 @@ allprojects {
exclude "fabric.mod.json"
}
}
jar {
from(rootProject.file("LICENSE.md")) {
rename { "LICENSE_${project.archivesBaseName.replace('-', '_')}"}
}
}
}
sourceSets {
+4 -7
View File
@@ -1,17 +1,14 @@
# Done to increase the memory available to gradle.
org.gradle.jvmargs=-Xmx1G
# Fabric Properties
# check these on https://modmuss50.me/fabric.html
minecraft_version=1.16.5
yarn_mappings=1.16.5+build.5
loader_version=0.11.2
minecraft_version=21w20a
yarn_mappings=21w20a+build.19
loader_version=0.11.3
# Mod Properties
mod_version=1.0.5
maven_group=draylar
archives_base_name=omega-config
# Dependencies
# check this on https://modmuss50.me/fabric.html
fabric_version=0.32.0+1.16
fabric_version=0.34.6+1.17
@@ -10,8 +10,8 @@ import io.netty.buffer.Unpooled;
import net.fabricmc.fabric.api.networking.v1.ServerPlayConnectionEvents;
import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking;
import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.ListTag;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.nbt.NbtList;
import net.minecraft.network.PacketByteBuf;
import net.minecraft.util.Identifier;
import org.apache.logging.log4j.LogManager;
@@ -28,21 +28,19 @@ import java.util.*;
public class OmegaConfig {
private static final Logger LOGGER = LogManager.getLogger();
private static final List<Config> REGISTERED_CONFIGURATIONS = new ArrayList<>();
public static final Gson GSON = new GsonBuilder().setPrettyPrinting().create();
public static final Identifier CONFIG_SYNC_PACKET = new Identifier("omegaconfig", "sync");
public static final Gson SYNC_ONLY_GSON = new GsonBuilder().addSerializationExclusionStrategy(new SyncableExclusionStrategy()).setPrettyPrinting().create();
private static final Logger LOGGER = LogManager.getLogger();
private static final List<Config> REGISTERED_CONFIGURATIONS = new ArrayList<>();
static {
ServerPlayConnectionEvents.JOIN.register((handler, sender, server) -> {
server.execute(() -> {
ServerPlayConnectionEvents.JOIN.register((handler, sender, server) -> server.execute(() -> {
PacketByteBuf packet = new PacketByteBuf(Unpooled.buffer());
// list of configurations that are synced
CompoundTag root = new CompoundTag();
ListTag configurations = new ListTag();
NbtCompound root = new NbtCompound();
NbtList configurations = new NbtList();
// Iterate over each configuration.
// Find values that should be synced and send the value over.
@@ -54,10 +52,9 @@ public class OmegaConfig {
// save to packet and send to user
root.put("Configurations", configurations);
packet.writeCompoundTag(root);
packet.writeNbt(root);
handler.sendPacket(ServerPlayNetworking.createS2CPacket(CONFIG_SYNC_PACKET, packet));
});
});
}));
}
public static <T extends Config> T register(Class<T> configClass) {
@@ -154,7 +151,7 @@ public class OmegaConfig {
Files.write(configPath, res.toString().getBytes());
} catch (IOException ioException) {
LOGGER.error(ioException);
LOGGER.info(String.format("Write error, using default values for config %s.", configClass.toString()));
LOGGER.info(String.format("Write error, using default values for config %s.", configClass));
}
}
@@ -1,7 +1,7 @@
package draylar.omegaconfig.api;
import draylar.omegaconfig.OmegaConfig;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.NbtCompound;
import org.jetbrains.annotations.Nullable;
import java.util.Arrays;
@@ -16,8 +16,8 @@ public interface Config {
OmegaConfig.writeConfig((Class<Config>) getClass(), this);
}
default CompoundTag writeSyncingTag() {
CompoundTag tag = new CompoundTag();
default NbtCompound writeSyncingTag() {
NbtCompound tag = new NbtCompound();
tag.putString("ConfigName", getName());
// all config vs. individual fields
@@ -67,7 +67,7 @@ public interface Config {
* modids for configuration screen instances in their menu.
* If you are intending for this config to have a ModMenu config
* screen, this method should return the modid specified in your fabric.mod.json.
*
* <p>
* If this method is not overridden, null will be returned, which
* means this config is not explicitly associated with any particular mod.
*
@@ -99,7 +99,7 @@ public interface Config {
* By default, a config such as 'my_config' will appear at /config/my_config.json.
* If this method specifies a directory, such as 'configurations',
* the config file will appear at /config/configurations/my_config.json.
*
* <p>
* Nested directories can be specified by using a string such as 'configurations/client'.
*
* @return the directory of this config
@@ -3,13 +3,12 @@ package draylar.omegaconfig.mixin;
import draylar.omegaconfig.OmegaConfig;
import draylar.omegaconfig.api.Config;
import draylar.omegaconfig.api.Syncing;
import net.fabricmc.fabric.api.network.ClientSidePacketRegistry;
import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking;
import net.fabricmc.fabric.api.util.NbtType;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.RunArgs;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.ListTag;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.nbt.NbtList;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
@@ -31,15 +30,15 @@ public class ClientMixin {
method = "<init>",
at = @At("RETURN"))
private void onReturn(RunArgs args, CallbackInfo ci) {
ClientSidePacketRegistry.INSTANCE.register(OmegaConfig.CONFIG_SYNC_PACKET, (context, buffer) -> {
CompoundTag tag = buffer.readCompoundTag();
ClientPlayNetworking.registerGlobalReceiver(OmegaConfig.CONFIG_SYNC_PACKET, (client, handler, buf, responseSender) -> {
NbtCompound tag = buf.readNbt();
savedClientConfig.clear();
context.getTaskQueue().execute(() -> {
client.execute(() -> {
if (tag != null && tag.contains("Configurations")) {
ListTag list = tag.getList("Configurations", NbtType.COMPOUND);
NbtList list = tag.getList("Configurations", NbtType.COMPOUND);
list.forEach(compound -> {
CompoundTag syncedConfiguration = (CompoundTag) compound;
NbtCompound syncedConfiguration = (NbtCompound) compound;
String name = syncedConfiguration.getString("ConfigName");
String json = syncedConfiguration.getString("Serialized");
boolean allSync = syncedConfiguration.getBoolean("AllSync");
@@ -79,7 +78,7 @@ public class ClientMixin {
@Inject(
method = "disconnect(Lnet/minecraft/client/gui/screen/Screen;)V",
at = @At("RETURN"))
private void restoreConfigurations(Screen screen, CallbackInfo ci) {
private void restoreConfigurations(CallbackInfo ci) {
for (Config config : savedClientConfig) {
for (Config potentiallySynced : OmegaConfig.getRegisteredConfigurations()) {
if (config.getName().equals(potentiallySynced.getName())) {
@@ -4,7 +4,6 @@
"package": "draylar.omegaconfig.mixin",
"compatibilityLevel": "JAVA_8",
"mixins": [
],
"client": [
"ClientMixin"
@@ -12,6 +12,7 @@ public class OmegaConfigGui {
/**
* Registers a ModMenu configuration screen for the given {@link Config} instance.
*
* @param config registered config to create a ModMenu screen for
* @param <T> config type
*/
@@ -5,19 +5,16 @@ import draylar.omegaconfig.api.Config;
import draylar.omegaconfiggui.api.screen.widget.LabelWidget;
import draylar.omegaconfiggui.api.screen.widget.TypeWidgets;
import draylar.omegaconfiggui.api.screen.widget.WidgetSupplier;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.Drawable;
import net.minecraft.client.gui.Element;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.gui.widget.AbstractButtonWidget;
import net.minecraft.client.gui.widget.ButtonWidget;
import net.minecraft.client.gui.widget.ClickableWidget;
import net.minecraft.client.gui.widget.TextFieldWidget;
import net.minecraft.client.render.BufferBuilder;
import net.minecraft.client.render.Tessellator;
import net.minecraft.client.render.VertexFormat;
import net.minecraft.client.render.VertexFormats;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.text.LiteralText;
import net.minecraft.util.Identifier;
import net.minecraft.util.Pair;
import java.lang.reflect.Field;
@@ -32,7 +29,7 @@ public class OmegaConfigScreen<T extends Config> extends Screen {
private static final List<Class<?>> validClasses = Arrays.asList(Double.class, String.class, Boolean.class);
private final T config;
private final Screen parent;
private final Map<Field, Pair<WidgetSupplier<Object, AbstractButtonWidget>, AbstractButtonWidget>> fieldWidgets = new HashMap<>();
private final Map<Field, Pair<WidgetSupplier<Object, ClickableWidget>, ClickableWidget>> fieldWidgets = new HashMap<>();
public OmegaConfigScreen(T config, Screen parent) {
super(new LiteralText(""));
@@ -54,15 +51,15 @@ public class OmegaConfigScreen<T extends Config> extends Screen {
Class<?> unbox = TypeWidgets.unbox(field.getType());
// label
addChild(new LabelWidget(150, 15 + height / 6 + 20 * over, new LiteralText(field.getName())));
addDrawable(new LabelWidget(150, 15 + height / 6 + 20 * over, new LiteralText(field.getName())));
// get value
field.setAccessible(true);
Object value = field.get(config);
// button / interact
AbstractButtonWidget button;
WidgetSupplier<Object, AbstractButtonWidget> widgetSupplier = (WidgetSupplier<Object, AbstractButtonWidget>) TypeWidgets.get(unbox);
ClickableWidget button;
WidgetSupplier<Object, ClickableWidget> widgetSupplier = (WidgetSupplier<Object, ClickableWidget>) TypeWidgets.get(unbox);
if (widgetSupplier != null) {
button = widgetSupplier.create(this, 250, 5 + height / 6 + 25 * over, 100, 20, new LiteralText(field.getName()), value);
} else {
@@ -71,7 +68,7 @@ public class OmegaConfigScreen<T extends Config> extends Screen {
fieldWidgets.put(field, new Pair<>(widgetSupplier, button));
addButton(button);
addSelectableChild(button);
over++;
}
@@ -92,15 +89,17 @@ public class OmegaConfigScreen<T extends Config> extends Screen {
config.save();
});
addButton(save);
addButton(exit);
addSelectableChild(save);
addSelectableChild(exit);
}
@Override
public void render(MatrixStack matrices, int mouseX, int mouseY, float delta) {
renderBackground(matrices);
for (AbstractButtonWidget button : this.buttons) {
//TODO make this work. for Drawables (children) it works in parent method
/*
for (ClickableWidget button : this.) {
button.render(matrices, mouseX, mouseY, delta);
}
@@ -109,6 +108,8 @@ public class OmegaConfigScreen<T extends Config> extends Screen {
((Drawable) element).render(matrices, mouseX, mouseY, delta);
}
}
*/
}
@Override
@@ -129,9 +130,9 @@ public class OmegaConfigScreen<T extends Config> extends Screen {
Tessellator tessellator = Tessellator.getInstance();
BufferBuilder bufferBuilder = tessellator.getBuffer();
this.client.getTextureManager().bindTexture(OPTIONS_BACKGROUND_TEXTURE);
RenderSystem.color4f(1.0F, 1.0F, 1.0F, 1.0F);
RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F);
bufferBuilder.begin(7, VertexFormats.POSITION_TEXTURE_COLOR);
bufferBuilder.begin(VertexFormat.DrawMode.QUADS, VertexFormats.POSITION_TEXTURE_COLOR);
bufferBuilder.vertex(x, height + y, 0.0D).texture(0.0F, (float) height / 32.0F + (float) vOffset).color(r, g, b, 255).next();
bufferBuilder.vertex(width + x, height + y, 0.0D).texture((float) width / 32.0F, (float) height / 32.0F + (float) vOffset).color(r, g, b, 255).next();
bufferBuilder.vertex(width + x, y, 0.0D).texture((float) width / 32.0F, (float) vOffset).color(r, g, b, 255).next();
@@ -1,9 +1,9 @@
package draylar.omegaconfiggui.api.screen.widget;
import draylar.omegaconfiggui.mixin.AbstractButtonWidgetAccessor;
import draylar.omegaconfiggui.mixin.ClickableWidgetInvoker;
import net.minecraft.client.font.TextRenderer;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.gui.widget.AbstractButtonWidget;
import net.minecraft.client.gui.widget.ClickableWidget;
import net.minecraft.client.gui.widget.TextFieldWidget;
import net.minecraft.text.Text;
@@ -20,8 +20,8 @@ public class BaseTextFieldWidget extends TextFieldWidget {
public void setTextFieldFocused(boolean focused) {
// unfocus all others
parent.children().forEach(element -> {
if(element instanceof AbstractButtonWidget) {
((AbstractButtonWidgetAccessor) element).callSetFocused(false);
if (element instanceof ClickableWidget) {
((ClickableWidgetInvoker) element).callSetFocused(false);
}
});
@@ -13,12 +13,10 @@ public class DoubleFieldWidget extends BaseTextFieldWidget {
@Override
public void write(String string) {
try {
if(string.equals(".") && !getText().contains(".")) {
super.write(string);
} else {
if (!string.equals(".") || getText().contains(".")) {
Double.parseDouble(string);
super.write(string);
}
super.write(string);
} catch (NumberFormatException ignored) {
@@ -30,6 +30,10 @@ public class TypeWidgets {
PRIMITIVE_TO_BOXED.put(void.class, Void.class);
}
private TypeWidgets() {
// NO-OP
}
@Nullable
public static <T> WidgetSupplier<T, ?> get(Class<T> typeClass) {
return (WidgetSupplier<T, ?>) CLASS_WIDGETS.get(unbox(typeClass));
@@ -38,8 +42,4 @@ public class TypeWidgets {
public static Class<?> unbox(Class<?> c) {
return PRIMITIVE_TO_BOXED.getOrDefault(c, c);
}
private TypeWidgets() {
// NO-OP
}
}
@@ -1,10 +1,11 @@
package draylar.omegaconfiggui.api.screen.widget;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.gui.widget.AbstractButtonWidget;
import net.minecraft.client.gui.widget.ClickableWidget;
import net.minecraft.text.LiteralText;
public interface WidgetSupplier<T, A extends AbstractButtonWidget> {
AbstractButtonWidget create(Screen parent, int x, int y, int width, int height, LiteralText prompt, T value);
public interface WidgetSupplier<T, A extends ClickableWidget> {
ClickableWidget create(Screen parent, int x, int y, int width, int height, LiteralText prompt, T value);
T get(A widget);
}
@@ -4,7 +4,6 @@ import draylar.omegaconfiggui.api.screen.widget.BaseTextFieldWidget;
import draylar.omegaconfiggui.api.screen.widget.WidgetSupplier;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.gui.widget.AbstractButtonWidget;
import net.minecraft.client.gui.widget.TextFieldWidget;
import net.minecraft.text.LiteralText;
@@ -1,11 +1,11 @@
package draylar.omegaconfiggui.mixin;
import net.minecraft.client.gui.widget.AbstractButtonWidget;
import net.minecraft.client.gui.widget.ClickableWidget;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.gen.Invoker;
@Mixin(AbstractButtonWidget.class)
public interface AbstractButtonWidgetAccessor {
@Mixin(ClickableWidget.class)
public interface ClickableWidgetInvoker {
@Invoker
void callSetFocused(boolean focused);
}
@@ -4,7 +4,7 @@
"package": "draylar.omegaconfiggui.mixin",
"compatibilityLevel": "JAVA_8",
"mixins": [
"AbstractButtonWidgetAccessor",
"ClickableWidgetInvoker",
"ModMenuAccessor"
],
"client": [
@@ -3,8 +3,8 @@ package draylar.omegatest;
import draylar.omegaconfig.OmegaConfig;
import draylar.omegatest.config.ClassConfigTest;
import draylar.omegatest.config.NestedConfigTest;
import draylar.omegatest.config.StructuresConfigTest;
import draylar.omegatest.config.SimpleConfigTest;
import draylar.omegatest.config.StructuresConfigTest;
import net.fabricmc.api.ModInitializer;
public class OmegaTestMain implements ModInitializer {
@@ -19,12 +19,6 @@ public class SimpleConfigTest implements Config {
@Comment(value = "This is an inner static class.")
public Test test = new Test();
public static class Test {
@Comment(value = "This is the value inside the class!")
public boolean innerTest = false;
}
@Override
public String getName() {
return "test-config";
@@ -34,4 +28,10 @@ public class SimpleConfigTest implements Config {
public @Nullable String getModid() {
return "omega-config-test";
}
public static class Test {
@Comment(value = "This is the value inside the class!")
public boolean innerTest = false;
}
}
@@ -21,6 +21,11 @@ public class StructuresConfigTest implements Config {
return "mostructures-config-v2";
}
@Override
public String getExtension() {
return "json5";
}
public static class Features {
@Comment("Airplanes & Air Balloons")
public boolean air_features = true;
@@ -123,9 +128,4 @@ public class StructuresConfigTest implements Config {
public int killer_bunny_castle_seperation = 25;
public int killer_bunny_castle_spacing = 50;
}
@Override
public String getExtension() {
return "json5";
}
}