Skip to content

Commit

Permalink
0.18.60 pre release; Untested but probably good (am committing to tes…
Browse files Browse the repository at this point in the history
…t on second machine)

Fixes the multiple mod jar distribution issue, and also adds thread limiting
  • Loading branch information
jediminer543 committed Oct 9, 2020
1 parent 433f1c8 commit 95f7aaf
Show file tree
Hide file tree
Showing 7 changed files with 197 additions and 36 deletions.
41 changes: 19 additions & 22 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ apply plugin: 'maven-publish'

version = "${mcmt_ver}"
group = 'org.jmt.mcmt' // http://maven.apache.org/guides/mini/guide-naming-conventions.html
archivesBaseName = "jmt_mcmt"
archivesBaseName = "jmt_mcmt-${mc_ver}"

sourceSets {
syncfu {
Expand Down Expand Up @@ -51,8 +51,10 @@ minecraft {

mods {
jmt_mcmt {
source sourceSets.main
source sourceSets.syncfu
source sourceSets.main
}
jmt_mcmt_syncfu {
source sourceSets.syncfu
}
}
}
Expand All @@ -68,7 +70,9 @@ minecraft {
mods {
jmt_mcmt {
source sourceSets.main
source sourceSets.syncfu
}
jmt_mcmt_syncfu {
source sourceSets.syncfu
}
}
}
Expand All @@ -87,7 +91,9 @@ minecraft {
mods {
jmt_mcmt {
source sourceSets.main
source sourceSets.syncfu
}
jmt_mcmt_syncfu {
source sourceSets.syncfu
}
}
}
Expand Down Expand Up @@ -121,9 +127,9 @@ dependencies {
}

// Example for how to get properties into the manifest for reading by the runtime..
jar {
jar {
from sourceSets.main.output
classifier "${mc_ver}"
classifier "modcore"
manifest {
attributes([
"Specification-Title": "jmt_mcmt",
Expand All @@ -137,28 +143,20 @@ jar {
}
}

task combiJar(type: Jar) {
from sourceSets.main.output
from sourceSets.syncfu.output
classifier "${mc_ver}-combi"
}

configure(combiJar) {
group = 'Build'
description = 'Create a combined mod syncfu jar'
}

task syncFuJar(type: Jar) {
task fullJar(type: Jar) {
from sourceSets.syncfu.output
classifier 'syncfu'
from jar.outputs.files
dependsOn jar
}

configure(syncFuJar) {
configure(fullJar) {
group = 'Build'
description = 'Create the syncfu jar'
description = 'Create the full mod'
}

build.dependsOn syncFuJar
build.dependsOn fullJar

task cleanModToml(type: Delete) {
delete 'src/main/resources/META-INF/mods.toml'
Expand Down Expand Up @@ -193,7 +191,6 @@ configure(generateModToml) {

processResources.dependsOn generateModToml


// Example configuration to allow publishing using the maven-publish task
// This is the preferred method to reobfuscate your jar file
jar.finalizedBy('reobfJar')
Expand Down
4 changes: 4 additions & 0 deletions etc/update.json
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
{
"homepage": "https://github.com/jediminer543/JMT-MCMT",
"1.16.3": {
"0.18.60": "Fixed loading so you only need one jar; and added thread capping to the config",
"0.17.54": "Added update checking and made mod actually load again",
"0.17.52": "Added FU patching"
},
"1.16.2": {
"0.18.60": "Fixed loading so you only need one jar; and added thread capping to the config",
"0.17.54": "Added update checking and made mod actually load again",
"0.17.52": "Added FU patching"
},
"1.16.1": {
"0.18.60": "Fixed loading so you only need one jar; and added thread capping to the config",
"0.17.54": "Added update checking and made mod actually load again",
"0.17.52": "Added FU patching"
},
"1.15.2": {
"0.18.60": "Fixed loading so you only need one jar; and added thread capping to the config",
"0.17.54": "Added update checking and made mod actually load again",
"0.17.52": "Added FU patching"
},
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
org.gradle.jvmargs=-Xmx3G
org.gradle.daemon=false

mcmt_ver=0.18.59-DEV
mcmt_ver=0.18.60-PRE

mappings_ver =20200723-1.16.1
mappings_chan=snapshot
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/org/jmt/mcmt/asmdest/ASMHookTerminator.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ public class ASMHookTerminator {
private static final Logger LOGGER = LogManager.getLogger();

static Phaser p;
static ExecutorService ex = Executors.newWorkStealingPool();
static ExecutorService ex = GeneralConfig.paraMax <= 1 ? Executors.newWorkStealingPool() :
Executors.newWorkStealingPool(Math.max(2, Math.min(Runtime.getRuntime().availableProcessors(), GeneralConfig.paraMax)));
static MinecraftServer mcs;
static AtomicBoolean isTicking = new AtomicBoolean();

Expand Down
12 changes: 12 additions & 0 deletions src/main/java/org/jmt/mcmt/config/GeneralConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
public class GeneralConfig {

public static boolean disabled;
public static int paraMax;

public static boolean disableWorld;

Expand Down Expand Up @@ -80,6 +81,8 @@ public static void onModConfigEvent(final ModConfig.ModConfigEvent configEvent)
*/
public static void bakeConfig() {
disabled = GENERAL.disabled.get();
paraMax = GENERAL.paraMax.get();

disableWorld = GENERAL.disableWorld.get();
disableEntity = GENERAL.disableEntity.get();
disableTileEntity = GENERAL.disableTileEntity.get();
Expand Down Expand Up @@ -118,6 +121,8 @@ public static void bakeConfig() {

public static void saveConfig() {
GENERAL.disabled.set(disabled);
GENERAL.paraMax.set(paraMax);

GENERAL.disableWorld.set(disableWorld);
GENERAL.disableEntity.set(disableEntity);
GENERAL.disableTileEntity.set(disableTileEntity);
Expand All @@ -143,6 +148,7 @@ public static void saveConfig() {
public static class GeneralConfigTemplate {

public final BooleanValue disabled;
public final IntValue paraMax;

public final BooleanValue disableWorld;

Expand All @@ -164,6 +170,11 @@ public GeneralConfigTemplate(ForgeConfigSpec.Builder builder) {
disabled = builder
.comment("Globally disable all toggleable functionality")
.define("disabled", false);
paraMax = builder
.comment("Maximum amount of threads; will never create more threads\n"
+ "than there are CPU threads (as that causeses Context switch churning)\n"
+ "Values <=1 are treated as 'all cores'")
.defineInRange("timeoutCount", -1, -1, Integer.MAX_VALUE);
builder.push("world");
disableWorld = builder
.comment("Disable world parallelisation")
Expand Down Expand Up @@ -201,6 +212,7 @@ public GeneralConfigTemplate(ForgeConfigSpec.Builder builder) {
disableChunkProvider = builder
.comment("Disable parallelised chunk caching; doing this will result in much lower performance with little to no gain")
.define("disableChunkProvider", false);
builder.push("load-forcing");
enableChunkTimeout = builder
.comment("Enable chunk loading timeouts; this will forcably kill any chunks that fail to load in sufficient time\n"
+"may allow for loading of damaged/corrupted worlds")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,26 @@

import java.io.File;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URL;
import java.nio.file.FileSystemNotFoundException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.spi.FileSystemProvider;
import java.security.CodeSource;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map.Entry;
import java.util.Optional;
import java.util.Set;
import java.util.Map.Entry;
import java.util.function.Function;
import java.util.function.Supplier;
import java.util.stream.Stream;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
Expand All @@ -28,30 +37,23 @@
import cpw.mods.modlauncher.api.ITransformerVotingContext;
import cpw.mods.modlauncher.api.IncompatibleEnvironmentException;
import cpw.mods.modlauncher.api.TransformerVoteResult;
import net.minecraftforge.fml.loading.FMLPaths;

public class FastUtilTransformerService implements ITransformer<ClassNode>, ITransformationService {
public class FastUtilTransformerService implements ITransformer<ClassNode>, ITransformationService {

private static final Logger LOGGER = LogManager.getLogger();
private static final Marker M_LOCATOR = MarkerManager.getMarker("LOCATE");
private boolean isActive = true;

@Override
public String name() {
return "sync_fu";
}

@Override
public void initialize(IEnvironment environment) {}

@Override
public void beginScanning(IEnvironment environment) {}

@Override
public void onLoad(IEnvironment env, Set<String> otherServices) throws IncompatibleEnvironmentException {}


@Override
public Entry<Set<String>, Supplier<Function<String, Optional<URL>>>> additionalClassesLocator() {
LOGGER.info("Sync_Fu preparing...");
LOGGER.info("Prepping fu_add...");
Optional<URL> fujarurl = Arrays.stream(System.getProperty("java.class.path").split(File.pathSeparator)).flatMap(path -> {
File file = new File(path);
if (file.isDirectory()) {
Expand Down Expand Up @@ -118,6 +120,7 @@ public Supplier<Function<String, Optional<URL>>> setValue(Supplier<Function<Stri
@SuppressWarnings("rawtypes")
@Override
public List<ITransformer> transformers() {

List<ITransformer> out = new ArrayList<>();
out.add(this);
return out;
Expand Down Expand Up @@ -160,5 +163,61 @@ public Set<Target> targets() {
out.add(Target.targetClass("it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap"));
return out;
}

@Override
public void initialize(IEnvironment environment) {

}

@Override
public void beginScanning(IEnvironment environment) {
System.out.println("HAI1");
/*
try {
Field f = FMLLoader.class.getDeclaredField("coreModProvider");
f.setAccessible(true);
ICoreModProvider icmp = (ICoreModProvider) f.get(null);
f.set(null, new FakeCoreModProvider(icmp));
}
catch (Exception e) {
e.printStackTrace();
}
*/
try {
CodeSource src = SyncFuLocator.class.getProtectionDomain().getCodeSource();
URL jar = src.getLocation();
if (!jar.toString().endsWith(".jar")) {
LOGGER.warn(M_LOCATOR, "This be dev!!!");
return;
}
URI uri = new URI("jar:".concat(jar.toString()).concat("!/"));
//Thanks SO https://stackoverflow.com/a/48298758
for (FileSystemProvider provider: FileSystemProvider.installedProviders()) {
if (provider.getScheme().equalsIgnoreCase("jar")) {
try {
provider.getFileSystem(uri);
} catch (FileSystemNotFoundException e) {
// in this case we need to initialize it first:
provider.newFileSystem(uri, Collections.emptyMap());
}
}
}
Path myPath = Paths.get(uri);
System.out.println(myPath);
Stream<Path> walk = Files.walk(myPath, 1).peek(p -> LOGGER.warn(M_LOCATOR, "Found {}", p)).filter(p -> p.toString().endsWith(".jar"));
Path root = FMLPaths.MODSDIR.get();
for (Iterator<Path> it = walk.iterator(); it.hasNext();){
Path file = it.next();
LOGGER.info(M_LOCATOR, "Found target jar: {}", file);
Files.copy(file, root.resolve(file.getFileName().toString()));
}
}
catch (Exception e) {
e.printStackTrace();
}
}

@Override
public void onLoad(IEnvironment env, Set<String> otherServices) throws IncompatibleEnvironmentException {}

}
Loading

0 comments on commit 95f7aaf

Please sign in to comment.