This commit is contained in:
creeper123123321 2019-01-18 17:19:33 -02:00
parent 9bc592aa6f
commit ac1cdf1b83
No known key found for this signature in database
GPG Key ID: 0AC57D54786721D1
3 changed files with 28 additions and 26 deletions

View File

@ -35,13 +35,13 @@ configurations {
}
dependencies {
shade('us.myles:viaversion:2.0.0-19w03a') {
shade('us.myles:viaversion:2.0.0-19w03c') {
transitive = false
changing = true
}
minecraft "com.mojang:minecraft:19w03a"
mappings "net.fabricmc:yarn:19w03a.3"
minecraft "com.mojang:minecraft:19w03c"
mappings "net.fabricmc:yarn:19w03c.1"
modCompile "net.fabricmc:fabric-loader:0.3.2.96"
// Fabric API. This is technically optional, but you probably want it anyway.

View File

@ -37,10 +37,20 @@ import org.apache.logging.log4j.LogManager;
import us.myles.ViaVersion.ViaManager;
import us.myles.ViaVersion.api.Via;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadFactory;
public class ViaFabric implements ClientModInitializer {
public static final java.util.logging.Logger JLOGGER = new JLoggerToLog4j(LogManager.getLogger("ViaFabric"));
public static final EventLoop EVENT_LOOP = new DefaultEventLoop(new ThreadFactoryBuilder()
.setNameFormat("ViaFabric").build());
public static final ExecutorService ASYNC_EXECUTOR;
public static final EventLoop EVENT_LOOP;
static {
ThreadFactory factory = new ThreadFactoryBuilder().setNameFormat("ViaFabric").build();
ASYNC_EXECUTOR = Executors.newCachedThreadPool(factory);
EVENT_LOOP = new DefaultEventLoop(factory);
}
@Override
public void onInitializeClient() {

View File

@ -27,7 +27,6 @@ package com.github.creeper123123321.viafabric.platform;
import com.github.creeper123123321.viafabric.ViaFabric;
import com.github.creeper123123321.viafabric.protocol.Interceptor;
import com.github.creeper123123321.viafabric.util.FutureTaskId;
import com.github.creeper123123321.viafabric.util.ManagedBlockerRunnable;
import net.fabricmc.loader.FabricLoader;
import us.myles.ViaVersion.api.PacketWrapper;
import us.myles.ViaVersion.api.Via;
@ -48,7 +47,6 @@ import us.myles.viaversion.libs.gson.JsonObject;
import java.io.File;
import java.util.UUID;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ForkJoinPool;
import java.util.concurrent.TimeUnit;
import java.util.logging.Logger;
@ -81,30 +79,24 @@ public class VRPlatform implements ViaPlatform {
@Override
public TaskId runAsync(Runnable runnable) {
return new FutureTaskId(
CompletableFuture
.runAsync(() -> {
try {
ForkJoinPool.managedBlock(new ManagedBlockerRunnable(runnable));
} catch (InterruptedException e) {
e.printStackTrace();
}
}).exceptionally(ex -> {
if (ex != null) ex.printStackTrace();
return null;
})
return new FutureTaskId(CompletableFuture
.runAsync(runnable, ViaFabric.ASYNC_EXECUTOR)
.exceptionally(throwable -> {
throwable.printStackTrace();
return null;
})
);
}
@Override
public TaskId runSync(Runnable runnable) {
return new FutureTaskId(
CompletableFuture
.runAsync(runnable)
.exceptionally(ex -> {
if (ex != null) ex.printStackTrace();
return null;
})
return new FutureTaskId(ViaFabric.EVENT_LOOP
.submit(runnable)
.addListener(future -> {
if (!future.isSuccess()) {
future.cause().printStackTrace();
}
})
);
}