Skip to content

Commit

Permalink
1.7.10 compatible
Browse files Browse the repository at this point in the history
  • Loading branch information
Kamesuta committed Oct 9, 2017
1 parent 3d30c77 commit 49581ce
Show file tree
Hide file tree
Showing 11 changed files with 270 additions and 95 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import cpw.mods.fml.common.event.FMLPostInitializationEvent;
import cpw.mods.fml.common.event.FMLPreInitializationEvent;

public class CommonProxy implements IProxy {
public class CommonProxy implements IProxyL {
@Override
public void preInit(final FMLPreInitializationEvent event) {
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import cpw.mods.fml.common.event.FMLPostInitializationEvent;
import cpw.mods.fml.common.event.FMLPreInitializationEvent;

public interface IProxy {
public interface IProxyL {

void preInit(@Nonnull FMLPreInitializationEvent event);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
@Mod(modid = Reference.MODID, name = Reference.NAME, version = Reference.VERSION, guiFactory = Reference.GUI_FACTORY)
public class ServerObserver {
@SidedProxy(serverSide = Reference.PROXY_SERVER, clientSide = Reference.PROXY_CLIENT)
private static @Nullable IProxy proxy;
private static @Nullable IProxyL proxy;

@NetworkCheckHandler
public boolean checkModList(final @Nonnull Map<String, String> versions, final @Nonnull Side side) {
Expand Down
46 changes: 27 additions & 19 deletions common.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,21 @@ sourceSets {
apply plugin: project.forgegradle_plugin
def fg_plugin = plugins.findPlugin project.forgegradle_plugin

sourceSets {
[[common: common_api, src: api], [common: common_main, src: main], [common: common_test, src: test]].each { s ->
s.common.java {
srcDirs = ["../src/${s.src.name}/java"]
}
s.common.resources {
srcDirs = ["../src/${s.src.name}/resources"]
}
s.common.compileClasspath += s.src.compileClasspath
s.common.runtimeClasspath += s.src.runtimeClasspath
s.src.compileClasspath += s.common.output
s.src.runtimeClasspath += s.common.output
}
}

// Fix compatibility issue between Gradle 4 and ForgeGradle 2.1
if (project.forgegradle.contains('1.2') || project.forgegradle.contains('2.1'))
if (gradle.startParameter.logLevel.compareTo(org.gradle.api.logging.LogLevel.LIFECYCLE) >= 0)
Expand Down Expand Up @@ -93,22 +108,22 @@ task setupSourceSets {
processResources {
// this will ensure that this task is redone when the versions change.
inputs.property 'version', mod_version
inputs.property 'mcversion', project.minecraft.version
inputs.property 'mcversion', project.version_minecraft

from(sourceSets.main.resources.srcDirs) {
from(sourceSets.common_main.resources.srcDirs) {
include 'mcmod.info'

expand([
/*expand([
'modid' : project.modid,
'modname' : project.modname,
'version' : mod_version,
'mcversion' : project.version_minecraft,
'forgeversion' : project.version_forge,
'minforgeversion': project.isProperty('version_minforge') ? project.version_minforge : project.version_forge,
])
])*/
}

from(sourceSets.main.resources.srcDirs) {
from(sourceSets.common_main.resources.srcDirs) {
exclude 'mcmod.info'
}
}
Expand All @@ -119,28 +134,20 @@ repositories {
name = 'CurseForge'
url = 'https://minecraft.curseforge.com/api/maven/'
}
maven {
name = 'Bintray TeamFruit'
url = "https://dl.bintray.com/team-fruit/mods/"
}
}

dependencies {
compile fileTree(dir: 'libs', include: '*.jar')
shade fileTree(dir: 'libs/shade', include: '*.jar')
compile fileTree(dir: '../libs', include: '*.jar')
shade fileTree(dir: '../libs/shade', include: '*.jar')
}

sourceSets {
[[common: common_api, src: api], [common: common_main, src: main], [common: common_test, src: test]].each { s ->
s.common.java {
srcDirs = ["../src/${s.src.name}/java"]
}
s.common.resources {
srcDirs = ["../src/${s.src.name}/resources"]
}
s.common.compileClasspath += s.src.compileClasspath
s.common.runtimeClasspath += s.src.runtimeClasspath
s.src.compileClasspath += s.common.output
s.src.runtimeClasspath += s.common.output
}
if (project.name==mod_commonname)
compile 'net.teamfruit:fmllegacydependency:1.0.2'
}

ext.commonManifest = {
Expand Down Expand Up @@ -173,6 +180,7 @@ jar {
classifier 'diff'
manifest commonManifest
}
tasks.jar.dependsOn 'shadowJar'

// println !reobf.hasProperty('dependsOn')
if (!reobf.hasProperty('dependsOn')) {
Expand Down
17 changes: 17 additions & 0 deletions common/src/main/java/net/teamfruit/serverobserver/IProxyL.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package net.teamfruit.serverobserver;

import javax.annotation.Nonnull;

import cpw.mods.fml.common.event.FMLInitializationEvent;
import cpw.mods.fml.common.event.FMLPostInitializationEvent;
import cpw.mods.fml.common.event.FMLPreInitializationEvent;

public interface IProxyL {

void preInit(@Nonnull FMLPreInitializationEvent event);

void init(@Nonnull FMLInitializationEvent event);

void postInit(@Nonnull FMLPostInitializationEvent event);

}
Original file line number Diff line number Diff line change
@@ -1,34 +1,18 @@
package net.teamfruit.serverobserver;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.util.Map;
import java.util.Map.Entry;
import java.util.zip.ZipFile;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;

import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.StringUtils;

import com.google.common.collect.Maps;

import net.minecraft.launchwrapper.Launch;
import net.minecraftforge.fml.common.Loader;
import net.minecraftforge.fml.common.LoaderException;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.Mod.EventHandler;
import net.minecraftforge.fml.common.Mod.Instance;
import net.minecraftforge.fml.common.ModContainer;
import net.minecraftforge.fml.common.SidedProxy;
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPostInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
import net.minecraftforge.fml.common.network.NetworkCheckHandler;
import net.minecraftforge.fml.relauncher.FMLInjectionData;
import net.minecraftforge.fml.relauncher.Side;

@Mod(modid = Reference.MODID, name = Reference.NAME, version = Reference.VERSION, guiFactory = Reference.GUI_FACTORY)
Expand All @@ -37,64 +21,12 @@ public class ServerObserver {
public static @Nullable ServerObserver instance;

static {
final ModContainer container = Loader.instance().activeModContainer();
Log.log.info(container);
final Object[] data = FMLInjectionData.data();
String mccversion = (String) data[4];

final Map<String, String> versions = Maps.newHashMap();
versions.put("1.8", "1.8.9");
versions.put("1.9", "1.9.4");
versions.put("1.10", "1.10.2");
versions.put("1.11", "1.11.2");
versions.put("1.12", "1.12.2");
for (final Entry<String, String> entry : versions.entrySet()) {
final String key = entry.getKey();
if (StringUtils.startsWith(mccversion, key)) {
final String value = entry.getValue();
mccversion = value;
break;
}
}

final File minecraftDir = (File) data[6];
final File modsDir = new File(minecraftDir, "mods");
if (container!=null) {
final File modFile = container.getSource();
if (modFile!=null) {
Log.log.info(container.getSource());
ZipFile file = null;
InputStream stream = null;
try {
final File canonicalModsDir = modsDir.getCanonicalFile();
final File versionSpecificModsDir = new File(canonicalModsDir, mccversion);
final File modVersionSpecific = new File(versionSpecificModsDir, Reference.MODID);

final String jarname = String.format("%s.jar", mccversion);
final File destMod = new File(modVersionSpecific, jarname);

file = new ZipFile(modFile);
stream = file.getInputStream(file.getEntry(jarname));

FileUtils.copyInputStreamToFile(stream, destMod);
Launch.classLoader.addURL(destMod.toURI().toURL());
} catch (final IOException e) {
new LoaderException("Could not load version-specific file.", e);
} finally {
IOUtils.closeQuietly(file);
IOUtils.closeQuietly(stream);
}

}
}
Log.log.info("init");
UniversalVersioner.loadVersion();
}

@SidedProxy(serverSide = Reference.PROXY_SERVER, clientSide = Reference.PROXY_CLIENT)
public static @Nullable IProxy proxy;

// public static final @Nonnull ICompat compat = new Compat();

@NetworkCheckHandler
public boolean checkModList(final @Nonnull Map<String, String> versions, final @Nonnull Side side) {
return true;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package net.teamfruit.serverobserver;

import java.util.Map;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;

import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.Mod.EventHandler;
import cpw.mods.fml.common.Mod.Instance;
import cpw.mods.fml.common.SidedProxy;
import cpw.mods.fml.common.event.FMLInitializationEvent;
import cpw.mods.fml.common.event.FMLPostInitializationEvent;
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
import cpw.mods.fml.common.network.NetworkCheckHandler;
import cpw.mods.fml.relauncher.Side;

@Mod(modid = Reference.MODID, name = Reference.NAME, version = Reference.VERSION, guiFactory = Reference.GUI_FACTORY)
public class ServerObserverL {
@Instance(Reference.MODID)
public static @Nullable ServerObserverL instance;

static {
UniversalVersioner.loadVersion();
}

@SidedProxy(serverSide = Reference.PROXY_SERVER, clientSide = Reference.PROXY_CLIENT)
public static @Nullable IProxyL proxy;

@NetworkCheckHandler
public boolean checkModList(final @Nonnull Map<String, String> versions, final @Nonnull Side side) {
return true;
}

@EventHandler
public void preInit(final @Nonnull FMLPreInitializationEvent event) {
if (proxy!=null)
proxy.preInit(event);
}

@EventHandler
public void init(final @Nonnull FMLInitializationEvent event) {
if (proxy!=null)
proxy.init(event);
}

@EventHandler
public void postInit(final @Nonnull FMLPostInitializationEvent event) {
if (proxy!=null)
proxy.postInit(event);
}
}
Loading

0 comments on commit 49581ce

Please sign in to comment.