Skip to content

Commit

Permalink
Finish code base rewrite
Browse files Browse the repository at this point in the history
  • Loading branch information
FlorianMichael committed Dec 24, 2024
1 parent e31e76a commit 2d96ea2
Show file tree
Hide file tree
Showing 69 changed files with 376 additions and 239 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

package de.florianmichael.viafabricplus;

import de.florianmichael.viafabricplus.settings.SettingsManager;
import org.apache.logging.log4j.Logger;

import java.io.File;
Expand All @@ -33,6 +34,8 @@ public class ViaFabricPlus {

private static final ViaFabricPlus INSTANCE = new ViaFabricPlus();

private final SettingsManager settingsManager = new SettingsManager();

@Deprecated
public static ViaFabricPlus global() {
return INSTANCE;
Expand All @@ -50,7 +53,7 @@ public File getDirectory() {

@Deprecated
public Object getSettingsManager() {
throw new IllegalArgumentException("ViaFabricPlus#getSettingsManager is not supported anymore.");
return settingsManager;
}

@Deprecated
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* This file is part of ViaFabricPlus - https://github.com/ViaVersion/ViaFabricPlus
* Copyright (C) 2021-2024 the original authors
* - FlorianMichael/EnZaXD <[email protected]>
* - RK_01/RaphiMC
* Copyright (C) 2023-2024 ViaVersion and contributors
*
* This program 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.
*
* This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
*/

package de.florianmichael.viafabricplus.settings;

import com.viaversion.viafabricplus.ViaFabricPlus;
import com.viaversion.viafabricplus.api.settings.SettingGroup;

import java.util.List;

/**
* Please migrate to the general {@link com.viaversion.viafabricplus.ViaFabricPlus} API point.
*/
@Deprecated
public class SettingsManager {

@Deprecated
public void addGroup(final SettingGroup... groups) {
for (SettingGroup group : groups) {
ViaFabricPlus.getImpl().addSettingGroup(group);
}
}

@Deprecated
public List<SettingGroup> getGroups() {
return ViaFabricPlus.getImpl().settingGroups();
}

}
4 changes: 4 additions & 0 deletions api/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,8 @@ plugins {

dependencies {
compileOnly "com.viaversion:viaversion-common:5.2.1-SNAPSHOT"
compileOnly ("net.raphimc:ViaLoader:3.0.4") {
exclude group: "com.google.guava", module: "guava"
exclude group: "org.slf4j", module: "slf4j-api"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,19 @@
package com.viaversion.viafabricplus.api;

import com.viaversion.viafabricplus.ViaFabricPlus;
import com.viaversion.viafabricplus.api.events.ChangeProtocolVersionCallback;
import com.viaversion.viafabricplus.api.events.LoadingCycleCallback;
import com.viaversion.viafabricplus.api.settings.SettingGroup;
import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.minecraft.item.Item;
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
import io.netty.channel.Channel;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.item.ItemStack;
import org.apache.logging.log4j.Logger;

import java.nio.file.Path;
import java.util.List;

/**
* General API point for mods. Get instance via {@link ViaFabricPlus#getImpl()}.
Expand Down Expand Up @@ -118,4 +125,58 @@ default int apiVersion() {
*/
int getMaxChatLength(final ProtocolVersion version);

/**
* All setting groups of the mod.
*
* @return The setting groups
*/
List<SettingGroup> settingGroups();

/**
* Add a setting group to the mod.
*
* @param group The setting group
*/
void addSettingGroup(final SettingGroup group);

/**
* Get a setting group by its translationKey.
*
* @param translationKey The translationKey of the setting group
* @return The setting group or null if it does not exist
*/
SettingGroup getSettingGroup(final String translationKey);

/**
* Open the protocol selection screen.
*
* @param parent The parent screen
*/
void openProtocolSelectionScreen(final Screen parent);

/**
* Open the settings screen.
*
* @param parent The parent screen
*/
void openSettingsScreen(final Screen parent);

/**
* Converts a Minecraft item stack to a ViaVersion item
*
* @param stack The Minecraft item stack
* @param targetVersion The target version to convert to (e.g. v1.13)
* @return The ViaVersion item for the target version
*/
Item translateItem(final ItemStack stack, final ProtocolVersion targetVersion);

/**
* Converts a ViaVersion item to a Minecraft item stack
*
* @param item The ViaVersion item
* @param sourceVersion The source version of the item (e.g. b1.8)
* @return The Minecraft item stack
*/
ItemStack translateItem(final Item item, final ProtocolVersion sourceVersion);

}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package com.viaversion.viafabricplus.api;
package com.viaversion.viafabricplus.api.events;

import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package com.viaversion.viafabricplus.api;
package com.viaversion.viafabricplus.api.events;

/**
* This event is fired in various loading stages of ViaFabricPlus. See {@link LoadingCycle} for more information.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,9 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package com.viaversion.viafabricplus.settings.base;
package com.viaversion.viafabricplus.api.settings;

import com.google.gson.JsonObject;
import com.viaversion.viafabricplus.base.screen.VFPListEntry;
import com.viaversion.viafabricplus.util.ChatUtil;
import net.minecraft.text.MutableText;
import net.minecraft.text.Text;
Expand Down Expand Up @@ -53,12 +52,6 @@ public AbstractSetting(final SettingGroup parent, final MutableText name, final
parent.getSettings().add(this);
}

/**
* This method is used to create a renderer for the setting.
* @return The renderer, see {@link VFPListEntry} for more details.
*/
public abstract VFPListEntry makeSettingRenderer();

public abstract void write(final JsonObject object);
public abstract void read(final JsonObject object);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package com.viaversion.viafabricplus.settings.base;
package com.viaversion.viafabricplus.api.settings;

import net.minecraft.text.Text;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package com.viaversion.viafabricplus.settings.base;
package com.viaversion.viafabricplus.api.settings.type;

import com.google.gson.JsonObject;
import com.viaversion.viafabricplus.base.screen.VFPListEntry;
import com.viaversion.viafabricplus.screen.settings.BooleanSettingRenderer;
import com.viaversion.viafabricplus.api.settings.AbstractSetting;
import com.viaversion.viafabricplus.api.settings.SettingGroup;
import net.minecraft.text.MutableText;

public class BooleanSetting extends AbstractSetting<Boolean> {
Expand All @@ -32,11 +32,6 @@ public BooleanSetting(SettingGroup parent, MutableText name, Boolean defaultValu
super(parent, name, defaultValue);
}

@Override
public VFPListEntry makeSettingRenderer() {
return new BooleanSettingRenderer(this);
}

@Override
public void write(JsonObject object) {
object.addProperty(getTranslationKey(), getValue());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package com.viaversion.viafabricplus.settings.base;
package com.viaversion.viafabricplus.api.settings.type;

import com.google.gson.JsonObject;
import com.viaversion.viafabricplus.base.screen.VFPListEntry;
import com.viaversion.viafabricplus.screen.settings.ButtonSettingRenderer;
import com.viaversion.viafabricplus.api.settings.AbstractSetting;
import com.viaversion.viafabricplus.api.settings.SettingGroup;
import net.minecraft.text.MutableText;

public class ButtonSetting extends AbstractSetting<Runnable> {
Expand All @@ -32,10 +32,6 @@ public ButtonSetting(SettingGroup parent, MutableText name, Runnable onClick) {
super(parent, name, onClick);
}

@Override
public VFPListEntry makeSettingRenderer() {
return new ButtonSettingRenderer(this);
}

public MutableText displayValue() {
return getName();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package com.viaversion.viafabricplus.settings.base;
package com.viaversion.viafabricplus.api.settings.type;

import com.google.gson.JsonObject;
import com.viaversion.viafabricplus.base.screen.VFPListEntry;
import com.viaversion.viafabricplus.screen.settings.ModeSettingRenderer;
import com.viaversion.viafabricplus.api.settings.AbstractSetting;
import com.viaversion.viafabricplus.api.settings.SettingGroup;
import com.viaversion.viafabricplus.util.ChatUtil;
import net.minecraft.text.MutableText;

Expand All @@ -42,11 +42,6 @@ public ModeSetting(SettingGroup parent, MutableText name, int defaultOption, Mut
this.options = options;
}

@Override
public VFPListEntry makeSettingRenderer() {
return new ModeSettingRenderer(this);
}

@Override
public void write(JsonObject object) {
object.addProperty(getTranslationKey(), mapTranslationKey(ChatUtil.uncoverTranslationKey(getValue())));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package com.viaversion.viafabricplus.settings.base;
package com.viaversion.viafabricplus.api.settings.type;

import com.google.gson.JsonObject;
import com.viaversion.viafabricplus.ViaFabricPlus;
import com.viaversion.viafabricplus.api.settings.AbstractSetting;
import com.viaversion.viafabricplus.api.settings.SettingGroup;
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
import com.viaversion.viafabricplus.protocoltranslator.ProtocolTranslator;
import com.viaversion.viafabricplus.base.screen.VFPListEntry;
import com.viaversion.viafabricplus.screen.settings.VersionedBooleanSettingRenderer;
import net.minecraft.text.MutableText;
import net.raphimc.vialoader.util.VersionRange;

Expand All @@ -43,11 +43,6 @@ public VersionedBooleanSetting(SettingGroup parent, MutableText name, VersionRan
this.protocolRange = protocolRange;
}

@Override
public VFPListEntry makeSettingRenderer() {
return new VersionedBooleanSettingRenderer(this);
}

@Override
public void write(JsonObject object) {
object.addProperty(getTranslationKey(), getValue() == AUTO_INDEX ? "auto" : getValue() == ENABLED_INDEX ? "enabled" : "disabled");
Expand All @@ -65,7 +60,7 @@ public boolean isAuto() {
}

public boolean isEnabled() {
return isEnabled(ProtocolTranslator.getTargetVersion());
return isEnabled(ViaFabricPlus.getImpl().getTargetVersion());
}

public boolean isEnabled(final ProtocolVersion version) {
Expand Down
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ dependencies {
modJij fabricApi.module("fabric-particles-v1", project.fabric_api_version)
modJij fabricApi.module("fabric-registry-sync-v0", project.fabric_api_version)

// Workaround resolution errors by not using jij tasks
include implementation(project(":viafabricplus-api"))
// Manually include to ignore dependencies
include implementation(project(path: ":viafabricplus-api", configuration: "namedElements"))
include implementation(project(":viafabricplus-api-legacy"))

jij "com.viaversion:viaversion-common:5.2.1-SNAPSHOT"
Expand Down
Loading

0 comments on commit 2d96ea2

Please sign in to comment.