1.17 "backport", include legacy compatibility layer

This commit is contained in:
JFronny 2021-10-09 12:44:01 +02:00
parent 5e5a0d9003
commit ff53ac5a15
No known key found for this signature in database
GPG Key ID: BEC5ACBBD4EE17E5
21 changed files with 346 additions and 23 deletions

View File

@ -1,3 +1,5 @@
import com.modrinth.minotaur.TaskModrinthUpload
plugins {
id "java"
id "idea"
@ -92,7 +94,7 @@ allprojects {
mappings "net.fabricmc:yarn:${project.minecraft_version}+${project.yarn_mappings}:v2"
modImplementation "net.fabricmc:fabric-loader:${project.loader_version}"
modRuntime modCompileOnly("com.terraformersmc:modmenu:3.0.0")
modRuntime modCompileOnly("com.terraformersmc:modmenu:2.0.14")
include modImplementation(fabricApi.module("fabric-tag-extensions-v0", "${project.fabric_version}"))
include modImplementation(fabricApi.module("fabric-resource-loader-v0", "${project.fabric_version}"))
}
@ -169,6 +171,15 @@ subprojects {
setupRepositories(repositories)
}
loom.disableDeprecatedPomGeneration(publishing.publications.mavenJava)
javadoc.enabled = false
afterEvaluate {
genSources.enabled = false
unpickJar.enabled = false
}
}
task remapMavenJar(type: net.fabricmc.loom.task.RemapJarTask, dependsOn: jar) {
@ -205,6 +216,8 @@ publishing {
setupRepositories(repositories)
}
loom.disableDeprecatedPomGeneration(publishing.publications.mavenJava)
void setupRepositories(RepositoryHandler repositories) {
//repositories.mavenLocal() // uncomment for testing
def ENV = System.getenv()
@ -241,15 +254,15 @@ dependencies {
api project(path: ":${it.name}", configuration: "dev")
if (!(it.name in devOnlyModules)) {
include project("${it.name}:")
include it
}
testmodImplementation project("${it.name}:").sourceSets.testmod.output
testmodImplementation it.sourceSets.testmod.output
}
}
}
task modrinth(type: com.modrinth.minotaur.TaskModrinthUpload, dependsOn: remapJar) {
task modrinth(type: TaskModrinthUpload, dependsOn: remapJar) {
onlyIf {
ENV.MODRINTH_API_TOKEN
}

View File

@ -2,12 +2,12 @@
org.gradle.jvmargs=-Xmx1G
# Fabric Properties
# check these on https://fabricmc.net/versions.html
minecraft_version=21w39a
yarn_mappings=build.13
loader_version=0.12.0
minecraft_version=1.17.1
yarn_mappings=build.61
loader_version=0.12.1
# Mod Properties
mod_version=2.0
maven_group=io.gitlab.jfronny
archives_base_name=libjf
fabric_version=0.40.5+1.18
fabric_version=0.40.6+1.17

View File

@ -1,16 +1,17 @@
{
"schemaVersion": 1,
"id": "libjf-base",
"name": "LibJF Base",
"version": "${version}",
"authors": [
"JFronny"
],
"environment": "*",
"license": "MIT",
"contact": {
"website": "https://jfronny.gitlab.io",
"repo": "https://gitlab.com/jfmods/libjf"
},
"license": "MIT",
"environment": "*",
"authors": [
"JFronny"
],
"depends": {
"fabricloader": ">=0.12.0",
"minecraft": "*"

View File

@ -1,7 +1,7 @@
{
"schemaVersion": 1,
"id": "libjf-config-v0",
"name": "LibJF Base",
"name": "LibJF Config",
"version": "${version}",
"authors": [
"JFronny"
@ -28,7 +28,9 @@
},
"depends": {
"fabricloader": ">=0.12.0",
"minecraft": "*"
"minecraft": "*",
"libjf-base": "${version}",
"libjf-unsafe-v0": "${version}"
},
"custom": {
"modmenu": {

View File

@ -17,7 +17,10 @@ public class ResourcePackHookPatch implements AsmConfig {
private static final String HOOK_IMPLEMENTATION = Type.getInternalName(ResourcePackHook.class);
@Override
public Set<String> skipClasses() {
return Set.of(PatchUtil.getRemapped(TARGET_CLASS_INTERMEDIARY));
return Set.of(PatchUtil.getRemapped(TARGET_CLASS_INTERMEDIARY),
"io.gitlab.jfronny.libjf.data.WrappedPack", //TODO remove for 1.18
"io.gitlab.jfronny.libjf.data.wrappedPackImpl.WrappedResourcePack",
"io.gitlab.jfronny.libjf.data.wrappedPackImpl.SafeWrappedResourcePack");
}
@Override

View File

@ -1,6 +1,7 @@
{
"schemaVersion": 1,
"id": "libjf-data-manipulation-v0",
"name": "LibJF Data Manipulation",
"version": "${version}",
"authors": [
"JFronny"
@ -19,7 +20,9 @@
},
"depends": {
"fabricloader": ">=0.12.0",
"minecraft": "*"
"minecraft": "*",
"libjf-base": "${version}",
"libjf-unsafe-v0": "${version}"
},
"custom": {
"modmenu": {

View File

@ -1,6 +1,7 @@
{
"schemaVersion": 1,
"id": "libjf-data-v0",
"name": "LibJF Data",
"version": "${version}",
"authors": [
"JFronny"
@ -14,7 +15,8 @@
"mixins": ["libjf-data-v0.mixins.json"],
"depends": {
"fabricloader": ">=0.12.0",
"minecraft": "*"
"minecraft": "*",
"libjf-base": "${version}"
},
"custom": {
"modmenu": {

View File

@ -1,6 +1,7 @@
{
"schemaVersion": 1,
"id": "libjf-devutil-v0",
"name": "LibJF Development Util",
"version": "${version}",
"authors": [
"JFronny"
@ -19,7 +20,8 @@
"mixins": ["libjf-devutil-v0.mixins.json"],
"depends": {
"fabricloader": ">=0.12.0",
"minecraft": "*"
"minecraft": "*",
"libjf-base": "${version}"
},
"custom": {
"modmenu": {

View File

@ -43,8 +43,10 @@ public class AsmTransformer implements IMixinTransformer {
classBytes = delegate.transformClassBytes(name, transformedName, classBytes);
if (classBytes == null || name == null)
return classBytes;
if (isClassUnmoddable(name, null))
if (isClassUnmoddable(name, null)) {
if (LibJf.DEV) LibJf.LOGGER.info("Skipping " + name);
return classBytes;
}
ClassNode klazz = new ClassNode();
ClassReader reader = new ClassReader(classBytes);

View File

@ -1,6 +1,7 @@
{
"schemaVersion": 1,
"id": "libjf-unsafe-v0",
"name": "LibJF Unsafe",
"version": "${version}",
"authors": [
"JFronny"
@ -17,7 +18,8 @@
"mixins": ["libjf-unsafe-v0.mixins.json"],
"depends": {
"fabricloader": ">=0.12.0",
"minecraft": "*"
"minecraft": "*",
"libjf-base": "${version}"
},
"custom": {
"modmenu": {

View File

@ -15,5 +15,5 @@ include 'libjf-base'
include 'libjf-config-v0'
include 'libjf-data-v0'
include 'libjf-data-manipulation-v0'
include 'libjf-devutil-v0'
//include 'libjf-devutil-v0' //TODO re-enable for 1.18
include 'libjf-unsafe-v0'

View File

@ -0,0 +1,27 @@
package io.gitlab.jfronny.libjf;
import io.gitlab.jfronny.libjf.config.impl.ConfigHolder;
import io.gitlab.jfronny.libjf.data.WrappedPack;
import io.gitlab.jfronny.libjf.data.manipulation.api.UserResourceEvents;
import net.fabricmc.api.ModInitializer;
//TODO remove for 1.18
@Deprecated(forRemoval = true)
public class Libjf implements ModInitializer {
@Deprecated(forRemoval = true)
public static void registerConfig(String modId, Class<?> config) {
ConfigHolder.registerConfig(modId, config);
}
@Override
public void onInitialize() {
UserResourceEvents.CONTAINS.register((type, id, previous, pack) ->
io.gitlab.jfronny.libjf.data.UserResourceEvents.CONTAINS.invoker().contains(type, id, previous, WrappedPack.create(pack)));
UserResourceEvents.FIND_RESOURCE.register((type, namespace, prefix, maxDepth, pathFilter, previous, pack) ->
io.gitlab.jfronny.libjf.data.UserResourceEvents.FIND_RESOURCE.invoker().findResources(type, namespace, prefix, maxDepth, pathFilter, previous, WrappedPack.create(pack)));
UserResourceEvents.OPEN.register((type, id, previous, pack) ->
io.gitlab.jfronny.libjf.data.UserResourceEvents.OPEN.invoker().open(type, id, previous, WrappedPack.create(pack)));
UserResourceEvents.OPEN_ROOT.register((fileName, previous, pack) ->
io.gitlab.jfronny.libjf.data.UserResourceEvents.OPEN_ROOT.invoker().openRoot(fileName, previous, WrappedPack.create(pack)));
}
}

View File

@ -0,0 +1,5 @@
package io.gitlab.jfronny.libjf.config;
@Deprecated(forRemoval = true)
public interface JfConfig extends io.gitlab.jfronny.libjf.config.api.JfConfig {
}

View File

@ -0,0 +1,24 @@
package io.gitlab.jfronny.libjf.data;
import net.minecraft.item.ItemStack;
import java.util.Set;
@Deprecated(forRemoval = true)
public class RecipeUtil {
public static void removeRecipe(String id) {
RecipeUtil.removeRecipe(id);
}
public static void removeRecipeFor(ItemStack product) {
RecipeUtil.removeRecipeFor(product);
}
public static Iterable<ItemStack> getRecipesForRemoval() {
return RecipeUtil.getRecipesForRemoval();
}
public static Set<String> getIdentifiersForRemoval() {
return RecipeUtil.getIdentifiersForRemoval();
}
}

View File

@ -0,0 +1,15 @@
package io.gitlab.jfronny.libjf.data;
import net.minecraft.resource.ResourceType;
import net.minecraft.util.Identifier;
@Deprecated(forRemoval = true)
public class ResourcePath extends io.gitlab.jfronny.libjf.ResourcePath {
public ResourcePath(ResourceType type, Identifier id) {
super(type, id);
}
public ResourcePath(String name) throws IllegalStateException {
super(name);
}
}

View File

@ -0,0 +1,62 @@
package io.gitlab.jfronny.libjf.data;
import net.fabricmc.fabric.api.event.Event;
import net.fabricmc.fabric.api.event.EventFactory;
import net.minecraft.resource.ResourceType;
import net.minecraft.util.Identifier;
import java.io.IOException;
import java.io.InputStream;
import java.util.Collection;
import java.util.function.Predicate;
@Deprecated(forRemoval = true)
public class UserResourceEvents {
public static final Event<Contains> CONTAINS = EventFactory.createArrayBacked(Contains.class,
(listeners) -> (type, id, previous, pack) -> {
for (Contains listener : listeners) {
previous = listener.contains(type, id, previous, pack);
}
return previous;
});
public static final Event<FindResource> FIND_RESOURCE = EventFactory.createArrayBacked(FindResource.class,
(listeners) -> ((type, namespace, prefix, maxDepth, pathFilter, previous, pack) -> {
for (FindResource listener : listeners) {
previous = listener.findResources(type, namespace, prefix, maxDepth, pathFilter, previous, pack);
}
return previous;
}));
public static final Event<Open> OPEN = EventFactory.createArrayBacked(Open.class,
(listeners) -> ((type, id, previous, pack) -> {
for (Open listener : listeners) {
previous = listener.open(type, id, previous, pack);
}
return previous;
}));
public static final Event<OpenRoot> OPEN_ROOT = EventFactory.createArrayBacked(OpenRoot.class,
(listeners) -> ((fileName, previous, pack) -> {
for (OpenRoot listener : listeners) {
previous = listener.openRoot(fileName, previous, pack);
}
return previous;
}));
public interface Contains {
boolean contains(ResourceType type, Identifier id, boolean previous, WrappedPack pack);
}
public interface FindResource {
Collection<Identifier> findResources(ResourceType type, String namespace, String prefix, int maxDepth, Predicate<String> pathFilter, Collection<Identifier> previous, WrappedPack pack);
}
public interface Open {
InputStream open(ResourceType type, Identifier id, InputStream previous, WrappedPack pack) throws IOException;
}
public interface OpenRoot {
InputStream openRoot(String fileName, InputStream previous, WrappedPack pack) throws IOException;
}
}

View File

@ -0,0 +1,15 @@
package io.gitlab.jfronny.libjf.data;
import io.gitlab.jfronny.libjf.data.wrappedPackImpl.WrappedResourcePack;
import net.minecraft.resource.ResourcePack;
@Deprecated(forRemoval = true)
public abstract class WrappedPack implements ResourcePack {
public abstract ResourcePack getUnderlying();
public static WrappedPack create(ResourcePack underlying) {
//if (underlying instanceof ModNioResourcePack mi)
// return new WrappedModNioResourcePack(mi);
return new WrappedResourcePack(underlying);
}
}

View File

@ -0,0 +1,64 @@
package io.gitlab.jfronny.libjf.data.wrappedPackImpl;
import io.gitlab.jfronny.libjf.data.manipulation.api.UserResourceEvents;
import net.minecraft.resource.ResourcePack;
import net.minecraft.resource.ResourceType;
import net.minecraft.resource.metadata.ResourceMetadataReader;
import net.minecraft.util.Identifier;
import org.jetbrains.annotations.Nullable;
import java.io.IOException;
import java.io.InputStream;
import java.util.Collection;
import java.util.Set;
import java.util.function.Predicate;
@Deprecated(forRemoval = true)
public class SafeWrappedResourcePack implements ResourcePack {
ResourcePack pack;
public SafeWrappedResourcePack(ResourcePack pack) {
this.pack = pack;
}
@Nullable
@Override
public InputStream openRoot(String fileName) throws IOException {
return UserResourceEvents.disable(() -> pack.openRoot(fileName));
}
@Override
public InputStream open(ResourceType type, Identifier id) throws IOException {
return UserResourceEvents.disable(() -> pack.open(type, id));
}
@Override
public Collection<Identifier> findResources(ResourceType type, String namespace, String prefix, int maxDepth, Predicate<String> pathFilter) {
return UserResourceEvents.disable(() -> pack.findResources(type, namespace, prefix, maxDepth, pathFilter));
}
@Override
public boolean contains(ResourceType type, Identifier id) {
return UserResourceEvents.disable(() -> pack.contains(type, id));
}
@Override
public Set<String> getNamespaces(ResourceType type) {
return UserResourceEvents.disable(() -> pack.getNamespaces(type));
}
@Nullable
@Override
public <T> T parseMetadata(ResourceMetadataReader<T> metaReader) throws IOException {
return UserResourceEvents.disable(() -> pack.parseMetadata(metaReader));
}
@Override
public String getName() {
return UserResourceEvents.disable(() -> pack.getName());
}
@Override
public void close() {
UserResourceEvents.disable(() -> pack.close());
}
}

View File

@ -0,0 +1,71 @@
package io.gitlab.jfronny.libjf.data.wrappedPackImpl;
import io.gitlab.jfronny.libjf.data.WrappedPack;
import net.minecraft.resource.ResourcePack;
import net.minecraft.resource.ResourceType;
import net.minecraft.resource.metadata.ResourceMetadataReader;
import net.minecraft.util.Identifier;
import org.jetbrains.annotations.Nullable;
import java.io.IOException;
import java.io.InputStream;
import java.util.Collection;
import java.util.Set;
import java.util.function.Predicate;
@Deprecated(forRemoval = true)
public class WrappedResourcePack extends WrappedPack {
ResourcePack pack;
SafeWrappedResourcePack safeWrappedResourcePack;
public WrappedResourcePack(ResourcePack pack) {
this.pack = pack;
safeWrappedResourcePack = new SafeWrappedResourcePack(pack);
}
@Override
public ResourcePack getUnderlying() {
return safeWrappedResourcePack;
}
@Nullable
@Override
public InputStream openRoot(String fileName) throws IOException {
return pack.openRoot(fileName);
}
@Override
public InputStream open(ResourceType type, Identifier id) throws IOException {
return pack.open(type, id);
}
@Override
public Collection<Identifier> findResources(ResourceType type, String namespace, String prefix, int maxDepth, Predicate<String> pathFilter) {
return pack.findResources(type, namespace, prefix, maxDepth, pathFilter);
}
@Override
public boolean contains(ResourceType type, Identifier id) {
return pack.contains(type, id);
}
@Override
public Set<String> getNamespaces(ResourceType type) {
return pack.getNamespaces(type);
}
@Nullable
@Override
public <T> T parseMetadata(ResourceMetadataReader<T> metaReader) throws IOException {
return pack.parseMetadata(metaReader);
}
@Override
public String getName() {
return pack.getName();
}
@Override
public void close() {
pack.close();
}
}

View File

@ -0,0 +1,4 @@
package io.gitlab.jfronny.libjf.entry;
public interface UltraEarlyInit extends io.gitlab.jfronny.libjf.unsafe.UltraEarlyInit {
}

View File

@ -14,9 +14,15 @@
"license": "MIT",
"icon": "assets/libjf/icon.png",
"environment": "*",
"entrypoints": {
"main": ["io.gitlab.jfronny.libjf.Libjf"]
},
"depends": {
"fabricloader": ">=0.12.0",
"minecraft": "*"
"minecraft": "*",
"libjf-config-v0": "${version}",
"libjf-data-v0": "${version}",
"libjf-base": "${version}"
},
"custom": {
"modmenu": {