Finalize legacy compatibility layer

This commit is contained in:
FlorianMichael 2024-12-28 12:06:45 +01:00
parent ed9ae44140
commit 86060b4d62
No known key found for this signature in database
GPG Key ID: C2FB87E71C425126
17 changed files with 432 additions and 11 deletions

View File

@ -4,4 +4,7 @@ plugins {
dependencies {
compileOnly project(":viafabricplus-api")
modCompileOnly fabricApi.module("fabric-api-base", project.fabric_api_version)
modCompileOnly fabricApi.module("fabric-lifecycle-events-v1", project.fabric_api_version)
}

View File

@ -0,0 +1,50 @@
/*
* This file is part of ViaFabricPlus - https://github.com/ViaVersion/ViaFabricPlus
* Copyright (C) 2021-2024 the original authors
* - FlorianMichael/EnZaXD <florian.michael07@gmail.com>
* - 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;
import net.fabricmc.fabric.api.event.Event;
import net.fabricmc.fabric.impl.base.event.EventFactoryImpl;
import java.util.function.Function;
public class LegacyCompatBridge {
private static boolean warned = false;
public static <T> Event<T> createArrayBacked(Class<? super T> type, Function<T[], T> invokerFactory) {
warn();
return EventFactoryImpl.createArrayBacked(type, invokerFactory);
}
public static void warn() {
if (!warned) {
warned = true;
ViaFabricPlus.INSTANCE.getLogger().warn("===========================================");
ViaFabricPlus.INSTANCE.getLogger().warn("A mod is using deprecated ViaFabricPlus internals which will be removed in the future.");
ViaFabricPlus.INSTANCE.getLogger().warn("Please contact the mod author to update their code to use the general API point added in 4.0.0.");
ViaFabricPlus.INSTANCE.getLogger().warn("The error below will point to the mod calling the deprecated API.");
Thread.dumpStack();
ViaFabricPlus.INSTANCE.getLogger().warn("===========================================");
}
}
}

View File

@ -34,7 +34,7 @@ import java.io.File;
@Deprecated
public class ViaFabricPlus {
private static final ViaFabricPlus INSTANCE = new ViaFabricPlus();
static final ViaFabricPlus INSTANCE = new ViaFabricPlus();
private final Logger logger = LogManager.getLogger("ViaFabricPlus-Legacy");
@ -43,6 +43,7 @@ public class ViaFabricPlus {
@Deprecated
public static ViaFabricPlus global() {
LegacyCompatBridge.warn();
return INSTANCE;
}

View File

@ -0,0 +1,44 @@
/*
* This file is part of ViaFabricPlus - https://github.com/ViaVersion/ViaFabricPlus
* Copyright (C) 2021-2024 the original authors
* - FlorianMichael/EnZaXD <florian.michael07@gmail.com>
* - 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.event;
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
import de.florianmichael.viafabricplus.LegacyCompatBridge;
import net.fabricmc.fabric.api.event.Event;
/**
* Please migrate to the general {@link com.viaversion.viafabricplus.ViaFabricPlus} API point.
*/
@Deprecated
public interface ChangeProtocolVersionCallback {
@Deprecated
Event<ChangeProtocolVersionCallback> EVENT = LegacyCompatBridge.createArrayBacked(ChangeProtocolVersionCallback.class, listeners -> (oldVersion, newVersion) -> {
for (ChangeProtocolVersionCallback listener : listeners) {
listener.onChangeProtocolVersion(oldVersion, newVersion);
}
});
@Deprecated
void onChangeProtocolVersion(final ProtocolVersion oldVersion, final ProtocolVersion newVersion);
}

View File

@ -0,0 +1,37 @@
/*
* This file is part of ViaFabricPlus - https://github.com/ViaVersion/ViaFabricPlus
* Copyright (C) 2021-2024 the original authors
* - FlorianMichael/EnZaXD <florian.michael07@gmail.com>
* - 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.event;
import com.viaversion.viafabricplus.ViaFabricPlus;
import com.viaversion.viafabricplus.api.events.LoadingCycleCallback;
import net.fabricmc.fabric.api.event.Event;
import net.fabricmc.fabric.api.event.EventFactory;
import java.util.function.Function;
public class EventBridge {
public static <T> Event<T> createArrayBacked(Class<? super T> type, Function<T[], T> invokerFactory) {
return EventFactory.createArrayBacked(type, invokerFactory);
}
}

View File

@ -0,0 +1,48 @@
/*
* This file is part of ViaFabricPlus - https://github.com/ViaVersion/ViaFabricPlus
* Copyright (C) 2021-2024 the original authors
* - FlorianMichael/EnZaXD <florian.michael07@gmail.com>
* - 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.event;
import de.florianmichael.viafabricplus.LegacyCompatBridge;
import net.fabricmc.fabric.api.event.Event;
/**
* Please migrate to the general {@link com.viaversion.viafabricplus.ViaFabricPlus} API point.
*/
@Deprecated
public interface LoadCallback {
@Deprecated
Event<LoadCallback> EVENT = LegacyCompatBridge.createArrayBacked(LoadCallback.class, listeners -> state -> {
for (LoadCallback listener : listeners) {
listener.onLoad(state);
}
});
@Deprecated
void onLoad(final State state);
@Deprecated
enum State {
PRE, POST
}
}

View File

@ -0,0 +1,45 @@
/*
* This file is part of ViaFabricPlus - https://github.com/ViaVersion/ViaFabricPlus
* Copyright (C) 2021-2024 the original authors
* - FlorianMichael/EnZaXD <florian.michael07@gmail.com>
* - 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.event;
import de.florianmichael.viafabricplus.LegacyCompatBridge;
import net.fabricmc.fabric.api.event.Event;
import net.raphimc.vialegacy.protocol.classic.c0_30cpetoc0_28_30.data.ClassicProtocolExtension;
/**
* Please migrate to the general {@link com.viaversion.viafabricplus.ViaFabricPlus} API point.
*/
@Deprecated
public interface LoadClassicProtocolExtensionCallback {
@Deprecated
Event<LoadClassicProtocolExtensionCallback> EVENT = LegacyCompatBridge.createArrayBacked(LoadClassicProtocolExtensionCallback.class, listeners -> classicProtocolExtension -> {
for (LoadClassicProtocolExtensionCallback listener : listeners) {
listener.onLoadClassicProtocolExtension(classicProtocolExtension);
}
});
@Deprecated
void onLoadClassicProtocolExtension(final ClassicProtocolExtension classicProtocolExtension);
}

View File

@ -0,0 +1,49 @@
/*
* This file is part of ViaFabricPlus - https://github.com/ViaVersion/ViaFabricPlus
* Copyright (C) 2021-2024 the original authors
* - FlorianMichael/EnZaXD <florian.michael07@gmail.com>
* - 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.event;
import de.florianmichael.viafabricplus.LegacyCompatBridge;
import de.florianmichael.viafabricplus.save.SaveManager;
import net.fabricmc.fabric.api.event.Event;
/**
* Please migrate to the general {@link com.viaversion.viafabricplus.ViaFabricPlus} API point.
*/
@Deprecated
public interface LoadSaveFilesCallback {
@Deprecated
Event<LoadSaveFilesCallback> EVENT = LegacyCompatBridge.createArrayBacked(LoadSaveFilesCallback.class, listeners -> (saveManager, state) -> {
for (LoadSaveFilesCallback listener : listeners) {
listener.onLoadSaveFiles(saveManager, state);
}
});
@Deprecated
void onLoadSaveFiles(final SaveManager saveManager, final State state);
@Deprecated
enum State {
PRE, POST, POST_INIT
}
}

View File

@ -0,0 +1,43 @@
/*
* This file is part of ViaFabricPlus - https://github.com/ViaVersion/ViaFabricPlus
* Copyright (C) 2021-2024 the original authors
* - FlorianMichael/EnZaXD <florian.michael07@gmail.com>
* - 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.event;
import de.florianmichael.viafabricplus.LegacyCompatBridge;
import net.fabricmc.fabric.api.event.Event;
/**
* Please migrate to the general {@link com.viaversion.viafabricplus.ViaFabricPlus} API point.
*/
@Deprecated
public interface PostGameLoadCallback {
@Deprecated
Event<PostGameLoadCallback> EVENT = LegacyCompatBridge.createArrayBacked(PostGameLoadCallback.class, listeners -> () -> {
for (PostGameLoadCallback listener : listeners) {
listener.postGameLoad();
}
});
@Deprecated
void postGameLoad();
}

View File

@ -0,0 +1,43 @@
/*
* This file is part of ViaFabricPlus - https://github.com/ViaVersion/ViaFabricPlus
* Copyright (C) 2021-2024 the original authors
* - FlorianMichael/EnZaXD <florian.michael07@gmail.com>
* - 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.event;
import de.florianmichael.viafabricplus.LegacyCompatBridge;
import net.fabricmc.fabric.api.event.Event;
/**
* Please migrate to the general {@link com.viaversion.viafabricplus.ViaFabricPlus} API point.
*/
@Deprecated
public interface PostViaVersionLoadCallback {
@Deprecated
Event<PostViaVersionLoadCallback> EVENT = LegacyCompatBridge.createArrayBacked(PostViaVersionLoadCallback.class, listeners -> () -> {
for (PostViaVersionLoadCallback listener : listeners) {
listener.onPostViaVersionLoad();
}
});
@Deprecated
void onPostViaVersionLoad();
}

View File

@ -0,0 +1,49 @@
/*
* This file is part of ViaFabricPlus - https://github.com/ViaVersion/ViaFabricPlus
* Copyright (C) 2021-2024 the original authors
* - FlorianMichael/EnZaXD <florian.michael07@gmail.com>
* - 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.event;
import de.florianmichael.viafabricplus.LegacyCompatBridge;
import de.florianmichael.viafabricplus.settings.SettingsManager;
import net.fabricmc.fabric.api.event.Event;
/**
* Please migrate to the general {@link com.viaversion.viafabricplus.ViaFabricPlus} API point.
*/
@Deprecated
public interface RegisterSettingsCallback {
@Deprecated
Event<RegisterSettingsCallback> EVENT = LegacyCompatBridge.createArrayBacked(RegisterSettingsCallback.class, listeners -> (settingsManager, state) -> {
for (RegisterSettingsCallback listener : listeners) {
listener.onRegisterSettings(settingsManager, state);
}
});
@Deprecated
void onRegisterSettings(final SettingsManager settingsManager, final State state);
@Deprecated
enum State {
PRE, POST
}
}

View File

@ -22,6 +22,7 @@
package de.florianmichael.viafabricplus.fixes;
import com.viaversion.viafabricplus.ViaFabricPlus;
import de.florianmichael.viafabricplus.LegacyCompatBridge;
/**
* Please migrate to the general {@link com.viaversion.viafabricplus.ViaFabricPlus} API point.
@ -31,6 +32,7 @@ public class ClientsideFixes {
@Deprecated
public static int getChatLength() {
LegacyCompatBridge.warn();
return ViaFabricPlus.getImpl().getMaxChatLength(ViaFabricPlus.getImpl().getTargetVersion());
}

View File

@ -23,6 +23,7 @@ package de.florianmichael.viafabricplus.fixes.data;
import com.viaversion.viafabricplus.ViaFabricPlus;
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
import de.florianmichael.viafabricplus.LegacyCompatBridge;
import net.minecraft.item.Item;
/**
@ -33,11 +34,13 @@ public class ItemRegistryDiff {
@Deprecated
public static boolean keepItem(final Item item) {
LegacyCompatBridge.warn();
return ViaFabricPlus.getImpl().itemExistsInConnection(item);
}
@Deprecated
public static boolean contains(final Item item, final ProtocolVersion version) {
LegacyCompatBridge.warn();
return ViaFabricPlus.getImpl().itemExists(item, version);
}

View File

@ -24,6 +24,7 @@ package de.florianmichael.viafabricplus.protocoltranslator;
import com.viaversion.viafabricplus.ViaFabricPlus;
import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
import de.florianmichael.viafabricplus.LegacyCompatBridge;
import io.netty.channel.Channel;
/**
@ -34,31 +35,37 @@ public class ProtocolTranslator {
@Deprecated
public static ProtocolVersion getTargetVersion() {
LegacyCompatBridge.warn();
return ViaFabricPlus.getImpl().getTargetVersion();
}
@Deprecated
public static ProtocolVersion getTargetVersion(final Channel channel) {
LegacyCompatBridge.warn();
return ViaFabricPlus.getImpl().getTargetVersion(channel);
}
@Deprecated
public static void setTargetVersion(final ProtocolVersion newVersion) {
LegacyCompatBridge.warn();
ViaFabricPlus.getImpl().setTargetVersion(newVersion);
}
@Deprecated
public static void setTargetVersion(final ProtocolVersion newVersion, final boolean revertOnDisconnect) {
LegacyCompatBridge.warn();
ViaFabricPlus.getImpl().setTargetVersion(newVersion, revertOnDisconnect);
}
@Deprecated
public static UserConnection createDummyUserConnection(final ProtocolVersion clientVersion, final ProtocolVersion serverVersion) {
throw new UnsupportedOperationException("This method is not supported anymore");
LegacyCompatBridge.warn();
return null;
}
@Deprecated
public static UserConnection getPlayNetworkUserConnection() {
LegacyCompatBridge.warn();
return ViaFabricPlus.getImpl().getPlayNetworkUserConnection();
}

View File

@ -33,7 +33,6 @@ import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.network.ServerInfo;
import net.minecraft.item.ItemStack;
import net.minecraft.network.ClientConnection;
import org.apache.logging.log4j.Logger;
import org.jetbrains.annotations.Nullable;
import java.nio.file.Path;

View File

@ -18,6 +18,7 @@ configurations {
modImplementation.extendsFrom modJij
modCompileOnlyApi.extendsFrom modJij
// Include VV dependencies as jij
jij.extendsFrom vvDependencies
}
@ -33,9 +34,9 @@ dependencies {
// Sub projects, since they are Fabric mods as well (mainly to access the game code) we have to first
// implement the namedElements (raw output) to compile against, then include the mappedElements into the output jar
implementation project(path: ":viafabricplus-api", configuration: "namedElements")
implementation project(path: ":viafabricplus-api-legacy", configuration: "namedElements")
implementation project(path: ":viafabricplus-visuals", configuration: "namedElements")
implementation compileOnlyApi(project(path: ":viafabricplus-api", configuration: "namedElements"))
implementation compileOnlyApi(project(path: ":viafabricplus-api-legacy", configuration: "namedElements"))
implementation compileOnlyApi(project(path: ":viafabricplus-visuals", configuration: "namedElements"))
include project(":viafabricplus-api")
include project(":viafabricplus-api-legacy")

View File

@ -4,9 +4,6 @@ ViaFabricPlus in your project comes with some requirements:
- The target version is Java 17
- Fabric loom setup (As ViaFabricPlus is a Minecraft mod and has no API-only dependency like other projects)
Since the API is not exposed as standalone submodule (yet), functions that shouldn't be used are marked with
`ApiStatus.Internal`. Further information about certain functions can be found in the Javadoc in the corresponding file.
## How to include the mod as dependency
### Gradle
```groovy
@ -31,7 +28,7 @@ repositories {
}
dependencies {
modImplementation("com.viaversion:viafabricplus:x.x.x") // Get the latest version from releases
modImplementation("com.viaversion:viafabricplus-api:x.x.x") // Get the latest version from releases
}
```
@ -55,7 +52,7 @@ dependencies {
<dependencies>
<dependency>
<groupId>com.viaversion</groupId>
<artifactId>viafabricplus</artifactId>
<artifactId>viafabricplus-api</artifactId>
<version>x.x.x</version> <!-- Get the latest version from releases -->
</dependency>
</dependencies>