Update to 1.18-pre2

This commit is contained in:
JFronny 2021-11-17 12:38:17 +01:00
parent 39555b3270
commit 115c8c19b1
No known key found for this signature in database
GPG Key ID: BEC5ACBBD4EE17E5
19 changed files with 66 additions and 342 deletions

View File

@ -1,4 +1,4 @@
image: gradle:jdk16
image: gradle:jdk17
variables:
GRADLE_OPTS: "-Dorg.gradle.daemon=false"

View File

@ -1,4 +1,5 @@
import com.modrinth.minotaur.TaskModrinthUpload
import org.w3c.dom.Node
plugins {
id "java"
@ -69,7 +70,7 @@ allprojects {
apply plugin: "fabric-loom"
tasks.withType(JavaCompile).configureEach {
it.options.release = 16
it.options.release = 17
}
group = "io.gitlab.jfronny.libjf"

View File

@ -2,12 +2,12 @@
org.gradle.jvmargs=-Xmx1G
# Fabric Properties
# check these on https://fabricmc.net/versions.html
minecraft_version=1.17.1
yarn_mappings=build.61
loader_version=0.12.1
minecraft_version=1.18-pre2
yarn_mappings=build.1
loader_version=0.12.5
# Mod Properties
mod_version=2.1.3
mod_version=2.1.4
maven_group=io.gitlab.jfronny
archives_base_name=libjf
fabric_version=0.40.6+1.17
fabric_version=0.42.5+1.18

View File

@ -18,7 +18,6 @@ public class ResourcePackHookPatch implements AsmConfig {
@Override
public Set<String> skipClasses() {
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");
}

View File

@ -15,8 +15,11 @@ import net.minecraft.server.command.CommandManager;
import net.minecraft.server.command.ServerCommandSource;
import net.minecraft.text.LiteralText;
import java.util.concurrent.atomic.AtomicBoolean;
public class JfWeb implements ClientModInitializer, DedicatedServerModInitializer, ModInitializer {
public static final WebServer SERVER;
private static final AtomicBoolean SERVER_STARTED = new AtomicBoolean(false);
static {
JfWebConfig.ensureValidPort();
SERVER = new JfWebServer(JfWebConfig.port, JfWebConfig.maxConnections);
@ -25,16 +28,34 @@ public class JfWeb implements ClientModInitializer, DedicatedServerModInitialize
@Override
public void onInitializeClient() {
if (isEnabled()) {
ClientLifecycleEvents.CLIENT_STARTED.register(client -> SERVER.restart());
ClientLifecycleEvents.CLIENT_STOPPING.register(client -> SERVER.stop());
ClientLifecycleEvents.CLIENT_STARTED.register(client -> {
if (!SERVER_STARTED.get()) {
SERVER.restart();
SERVER_STARTED.set(true);
}
});
ClientLifecycleEvents.CLIENT_STOPPING.register(client -> {
if (SERVER_STARTED.get()) {
SERVER.stop();
}
});
}
}
@Override
public void onInitializeServer() {
if (isEnabled()) {
ServerLifecycleEvents.SERVER_STARTED.register(client -> SERVER.restart());
ServerLifecycleEvents.SERVER_STOPPED.register(client -> SERVER.stop());
ServerLifecycleEvents.SERVER_STARTED.register(server -> {
if (!SERVER_STARTED.get()) {
SERVER.restart();
SERVER_STARTED.set(true);
}
});
ServerLifecycleEvents.SERVER_STOPPED.register(server -> {
if (SERVER_STARTED.get()) {
SERVER.stop();
}
});
}
}

View File

@ -20,7 +20,7 @@ import java.util.Objects;
import java.util.stream.Stream;
public class JfWebServer implements WebServer {
private HttpServer server;
private HttpServer server = null;
private final RequestHandler handler = new RequestHandler();
private final int port;
private final int maxConnections;
@ -161,11 +161,11 @@ public class JfWebServer implements WebServer {
}
@Override
public void stop() {
public synchronized void stop() {
for (AdvancedSubServer subServer : handler.subServers.values()) subServer.onStop();
if (isActive()) server.close();
if (server != null) {
try {
server.close();
server.join();
}
catch (InterruptedException e) {
@ -175,7 +175,7 @@ public class JfWebServer implements WebServer {
}
@Override
public void restart() {
public synchronized void restart() {
JfWebConfig.ensureValidPort();
int tmpPort = port;
if (server != null) {
@ -191,6 +191,12 @@ public class JfWebServer implements WebServer {
});
});
server.start();
try {
server.waitUntilReady();
} catch (InterruptedException e) {
stop();
LibJf.LOGGER.error("Server could not be readied", e);
}
for (AdvancedSubServer subServer : handler.subServers.values()) {
subServer.onStart();
}

View File

@ -27,10 +27,7 @@ package io.gitlab.jfronny.libjf.web.impl.util.bluemapcore;
import io.gitlab.jfronny.libjf.LibJf;
import java.io.IOException;
import java.net.InetAddress;
import java.net.ServerSocket;
import java.net.Socket;
import java.net.SocketException;
import java.net.*;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.RejectedExecutionException;
import java.util.concurrent.ThreadPoolExecutor;
@ -49,7 +46,10 @@ public class HttpServer extends Thread {
private ServerSocket server;
private State state = State.Initialized;
public HttpServer(InetAddress bindAddress, int port, int maxConnections, HttpRequestHandler handler, Runnable startCallback) {
super("LibJF HTTP Server");
this.port = port;
this.maxConnections = maxConnections;
this.bindAddress = bindAddress;
@ -69,8 +69,9 @@ public class HttpServer extends Thread {
try {
server = new ServerSocket(port, maxConnections, bindAddress);
server.setSoTimeout(0);
server.setSoTimeout(1000);
} catch (IOException e){
state = State.Failed;
LibJf.LOGGER.error("Error while starting the WebServer!", e);
return;
}
@ -79,7 +80,7 @@ public class HttpServer extends Thread {
LibJf.LOGGER.info("WebServer started.");
while (!server.isClosed() && server.isBound()){
state = State.Running;
try {
Socket connection = server.accept();
@ -90,13 +91,13 @@ public class HttpServer extends Thread {
LibJf.LOGGER.warn("Dropped an incoming HttpConnection! (Too many connections?)");
}
} catch (SocketException e){
// this mainly occurs if the socket got closed, so we ignore this error
} catch (IOException e){
} catch (SocketException | SocketTimeoutException e) {
// ignored
} catch (IOException e) {
LibJf.LOGGER.error("Error while creating a new HttpConnection!", e);
}
}
state = State.Closed;
LibJf.LOGGER.info("WebServer closed.");
}
@ -113,7 +114,8 @@ public class HttpServer extends Thread {
this.maxConnections = maxConnections;
}
public synchronized void close(){
public synchronized void close() {
state = State.Closed;
if (connectionThreads != null) connectionThreads.shutdown();
try {
@ -124,4 +126,12 @@ public class HttpServer extends Thread {
LibJf.LOGGER.error("Error while closing WebServer!", e);
}
}
public void waitUntilReady() throws InterruptedException {
while (state == State.Initialized) Thread.sleep(1L);
}
enum State {
Initialized, Running, Closed, Failed
}
}

View File

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

View File

@ -1,28 +0,0 @@
package io.gitlab.jfronny.libjf;
import io.gitlab.jfronny.libjf.config.api.ConfigHolder;
import io.gitlab.jfronny.libjf.config.impl.ConfigHolderImpl;
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.getInstance().register(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

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

View File

@ -1,21 +0,0 @@
package io.gitlab.jfronny.libjf.config.impl;
import java.util.Map;
@Deprecated
public class ConfigHolder {
@Deprecated
public static void registerConfig(String modId, Class<?> config) {
ConfigHolderImpl.INSTANCE.register(modId, config);
}
@Deprecated
public static Map<String, Config> getConfigs() {
return ConfigHolderImpl.INSTANCE.getRegistered();
}
@Deprecated
public static boolean isRegistered(Class<?> config) {
return ConfigHolderImpl.INSTANCE.isRegistered(config);
}
}

View File

@ -1,24 +0,0 @@
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

@ -1,15 +0,0 @@
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

@ -1,62 +0,0 @@
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

@ -1,15 +0,0 @@
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

@ -1,64 +0,0 @@
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

@ -1,71 +0,0 @@
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

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

View File

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