Initializing repository

main
Shinare 2 years ago
parent f858896387
commit c5762c5708

1
.gitignore vendored

@ -0,0 +1 @@
target/

@ -0,0 +1,2 @@
#Thu Sep 21 16:48:14 EEST 2023
gradle.version=7.4.2

Binary file not shown.

@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>CinderModlistCore</name>
<comment>Project CinderModlistCore created by Buildship.</comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.buildship.core.gradleprojectbuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.buildship.core.gradleprojectnature</nature>
</natures>
</projectDescription>

@ -0,0 +1,13 @@
arguments=
auto.sync=false
build.scans.enabled=false
connection.gradle.distribution=GRADLE_DISTRIBUTION(WRAPPER)
connection.project.dir=
eclipse.preferences.version=1
gradle.user.home=/usr/share/java/gradle
java.home=
jvm.arguments=
offline.mode=false
override.workspace.settings=true
show.console.view=true
show.executions.view=true

@ -0,0 +1,12 @@
#!/bin/bash
# Clean the build environment
./gradlew clean
# Ensure the required directory exists and create the mixins.srg file
mkdir -p build/tmp/reobf/
touch build/tmp/reobf/mixins.srg
# Build and create the jar file
./gradlew build jar
#./gradlew shadowJar

@ -1,3 +1,37 @@
# CinderModListCore
# anatawa12's ForgeGradle 1.2 fork for Gradle 4.4.1+ - example project
Mod list component for Cinder Core. Necessary for it to work. Only exists as separate plugin due to me not finding a ForgeGradle setup that can handle both mixins and access transformers at once.
This is an example mod using the [fork of ForgeGradle-1.2 made by anatawa12](https://github.com/anatawa12/ForgeGradle-1.2).
This fork supports Gradle 4.4.1 and later. This example project uses Gradle 5.6.4.
## How to use this example project
You can download this example project from [here](https://github.com/anatawa12/ForgeGradle-example/archive/master.zip), or use it as a template on Github.
This project can be used as a replacement for Forge's 1.7.10 MDK.
## How to replace ForgeGradle 1.2. with anatawa12's fork
Although this example project has some differences to Forge's 1.7.10 MDK, anatawa12's fork of ForgeGradle 1.2 can be used by most projects with only minimal changes to their Gradle build script.
Here is a list of changes to Forge's 1.7.10 MDK Gradle build script, to replace the official ForgeGradle 1.2 plugin with the fork. These changes are likely to work with most projects based on Forge's 1.7.10 MDK.
In the repositories block of the buildscript section, add jcenter, and switch the Forge maven to use HTTPS instead of HTTP:
```diff
repositories {
mavenCentral()
maven {
name = "forge"
- url = "http://files.minecraftforge.net/maven"
+ url = "https://maven.minecraftforge.net/"
}
```
Also in the dependencies block of the buildscript section, change the dependency on Forge's official ForgeGradle 1.2 to the fork:
```diff
dependencies {
- classpath 'net.minecraftforge.gradle:ForgeGradle:1.2-SNAPSHOT'
+ classpath ('com.anatawa12.forge:ForgeGradle:1.2-1.1.+') {
+ changing = true
+ }
}
```
The Gradle wrapper should also be changed to use Gradle 4.4.1 or higher. <!--Currently, the plugin [does not support Gradle 6.x](https://github.com/anatawa12/ForgeGradle-1.2/issues/9), although this may change in the future. As such, the latest version of Gradle this plugin supports is Gradle 5.6.4.-->

@ -0,0 +1,164 @@
buildscript {
repositories {
mavenCentral()
maven {
name = "forge"
url = "https://maven.minecraftforge.net/"
}
}
dependencies {
classpath ('com.anatawa12.forge:ForgeGradle:1.2-1.1.+') {
changing = true
}
}
}
plugins {
id 'java-library'
id 'maven-publish'
// id 'com.github.johnrengelman.shadow' version '6.1.0' // Use the latest version
}
apply plugin: 'forge'
// These settings allow you to choose what version of Java you want to be compatible with. Forge 1.7.10 runs on Java 6 to 8.
sourceCompatibility = 1.8
targetCompatibility = 1.8
version = project.version
group = project.group
def yourMixinConfig = 'mixins.cindercore_modlist.json'
def refMapForYourConfig = 'mixins.cindercore_modlist.refmap.json'
def relativePathToMixinAP = 'libs/mixin-0.8-SNAPSHOT.jar'
def refMap = 'src/main/resources/' + refMapForYourConfig
def mixinSrg = "${tasks.reobf.temporaryDir}" + File.separator + "mixins.srg"
repositories {
flatDir {
dirs 'libs'
}
maven {
name = 'sponge'
url = 'https://repo.spongepowered.org/repository/maven-public'
}
}
dependencies {
// implementation 'com.google.code.gson:gson:2.8.6'
implementation('org.spongepowered:mixin:0.7.11-SNAPSHOT') {
// Mixin includes a lot of dependencies that are too up-to-date
exclude module: 'launchwrapper'
exclude module: 'guava'
exclude module: 'gson'
exclude module: 'commons-io'
exclude module: 'log4j-core'
}
// implementation name: 'mixin-0.8-SNAPSHOT', ext: 'jar'
// implementation name: 'SpongeMixins-1.5.0', ext: 'jar'
implementation name: 'cindercore', ext: 'jar'
}
minecraft {
version = project.minecraft_version + "-" + project.forge_version
runDir = "run"
}
processResources {
// This will ensure that this task is redone when the versions change.
inputs.property "version", project.version
inputs.property "mcversion", project.minecraft.version
// Replace values in only mcmod.info.
filesMatching('mcmod.info') {
// Replace version and mcversion.
expand 'version':project.version, 'mcversion':project.minecraft.version
}
}
// Ensures that the encoding of source files is set to UTF-8, see http://yodaconditions.net/blog/fix-for-java-file-encoding-problems-with-gradle.html
tasks.withType(JavaCompile) {
options.encoding = "UTF-8"
}
// This task creates a .jar file containing the source code of this mod.
task sourcesJar(type: Jar, dependsOn: classes) {
classifier = "sources"
from sourceSets.main.allSource
}
// This task creates a .jar file containing a deobfuscated version of this mod, for other developers to use in a development environment.
task devJar(type: Jar) {
classifier = "dev"
from sourceSets.main.output
}
// Creates the listed artifacts on building the mod.
artifacts {
archives sourcesJar
archives devJar
}
// This block configures any maven publications you want to make.
publishing {
publications {
mavenJava(MavenPublication) {
// Add any other artifacts here that you would like to publish!
artifact(jar) {
builtBy build
}
artifact(sourcesJar) {
builtBy sourcesJar
}
artifact(devJar) {
builtBy devJar
}
}
}
// This block selects the repositories you want to publish to.
}
jar {
duplicatesStrategy = DuplicatesStrategy.INCLUDE
from sourceSets.main.output.resourcesDir
from refMap
manifest {
attributes([
"Manifest-Version": "1.0",
"TweakClass": "org.spongepowered.asm.launch.MixinTweaker",
'MixinConfigs': yourMixinConfig,
"FMLCorePlugin": "com.zivilon.cindercore_modlist.coremod.ModListCore",
'FMLCorePluginContainsFMLMod': 'true',
"ForceLoadAsMod": true
])
}
}
reobf {
addExtraSrgFile mixinSrg
}
afterEvaluate {
def fixedRelPathToAP = relativePathToMixinAP
if(fixedRelPathToAP.startsWith('./') || fixedRelPathToAP.startsWith('.\\')){
fixedRelPathToAP = fixedRelPathToAP.substring(2)
} else if(fixedRelPathToAP.startsWith('/') || fixedRelPathToAP.startsWith('\\')){
fixedRelPathToAP = fixedRelPathToAP.substring(1)
}
tasks.withType(JavaCompile) {
options.annotationProcessorPath = files(projectDir.absolutePath + '/' + fixedRelPathToAP)
println "Refmap path: ${refMap}"
options.compilerArgs += [
"-ArefMapFile=${refMap}",
"-AoutRefMapFile=${refMap}",
"-AdefaultObfuscationEnv=searge"
]
}
}
sourceSets {
main {
output.resourcesDir = output.classesDirs.asPath
ext.refMap = refMapForYourConfig
}
}

@ -0,0 +1,8 @@
# Mod properties
version=1.0
# http://maven.apache.org/guides/mini/guide-naming-conventions.html
group=com.zivilon.cindercore_modlist
# Forge properties
minecraft_version=1.7.10
forge_version=10.13.4.1614-1.7.10

Binary file not shown.

@ -0,0 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4.2-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists

185
gradlew vendored

@ -0,0 +1,185 @@
#!/usr/bin/env sh
#
# Copyright 2015 the original author or authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
##############################################################################
##
## Gradle start up script for UN*X
##
##############################################################################
# Attempt to set APP_HOME
# Resolve links: $0 may be a link
PRG="$0"
# Need this for relative symlinks.
while [ -h "$PRG" ] ; do
ls=`ls -ld "$PRG"`
link=`expr "$ls" : '.*-> \(.*\)$'`
if expr "$link" : '/.*' > /dev/null; then
PRG="$link"
else
PRG=`dirname "$PRG"`"/$link"
fi
done
SAVED="`pwd`"
cd "`dirname \"$PRG\"`/" >/dev/null
APP_HOME="`pwd -P`"
cd "$SAVED" >/dev/null
APP_NAME="Gradle"
APP_BASE_NAME=`basename "$0"`
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD="maximum"
warn () {
echo "$*"
}
die () {
echo
echo "$*"
echo
exit 1
}
# OS specific support (must be 'true' or 'false').
cygwin=false
msys=false
darwin=false
nonstop=false
case "`uname`" in
CYGWIN* )
cygwin=true
;;
Darwin* )
darwin=true
;;
MINGW* )
msys=true
;;
NONSTOP* )
nonstop=true
;;
esac
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
# Determine the Java command to use to start the JVM.
if [ -n "$JAVA_HOME" ] ; then
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
# IBM's JDK on AIX uses strange locations for the executables
JAVACMD="$JAVA_HOME/jre/sh/java"
else
JAVACMD="$JAVA_HOME/bin/java"
fi
if [ ! -x "$JAVACMD" ] ; then
die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
else
JAVACMD="java"
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
# Increase the maximum file descriptors if we can.
if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
MAX_FD_LIMIT=`ulimit -H -n`
if [ $? -eq 0 ] ; then
if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
MAX_FD="$MAX_FD_LIMIT"
fi
ulimit -n $MAX_FD
if [ $? -ne 0 ] ; then
warn "Could not set maximum file descriptor limit: $MAX_FD"
fi
else
warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
fi
fi
# For Darwin, add options to specify how the application appears in the dock
if $darwin; then
GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
fi
# For Cygwin or MSYS, switch paths to Windows format before running java
if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
JAVACMD=`cygpath --unix "$JAVACMD"`
# We build the pattern for arguments to be converted via cygpath
ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
SEP=""
for dir in $ROOTDIRSRAW ; do
ROOTDIRS="$ROOTDIRS$SEP$dir"
SEP="|"
done
OURCYGPATTERN="(^($ROOTDIRS))"
# Add a user-defined pattern to the cygpath arguments
if [ "$GRADLE_CYGPATTERN" != "" ] ; then
OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
fi
# Now convert the arguments - kludge to limit ourselves to /bin/sh
i=0
for arg in "$@" ; do
CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
else
eval `echo args$i`="\"$arg\""
fi
i=`expr $i + 1`
done
case $i in
0) set -- ;;
1) set -- "$args0" ;;
2) set -- "$args0" "$args1" ;;
3) set -- "$args0" "$args1" "$args2" ;;
4) set -- "$args0" "$args1" "$args2" "$args3" ;;
5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
esac
fi
# Escape application args
save () {
for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
echo " "
}
APP_ARGS=`save "$@"`
# Collect all arguments for the java command, following the shell quoting and substitution rules
eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
exec "$JAVACMD" "$@"

89
gradlew.bat vendored

@ -0,0 +1,89 @@
@rem
@rem Copyright 2015 the original author or authors.
@rem
@rem Licensed under the Apache License, Version 2.0 (the "License");
@rem you may not use this file except in compliance with the License.
@rem You may obtain a copy of the License at
@rem
@rem https://www.apache.org/licenses/LICENSE-2.0
@rem
@rem Unless required by applicable law or agreed to in writing, software
@rem distributed under the License is distributed on an "AS IS" BASIS,
@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@rem See the License for the specific language governing permissions and
@rem limitations under the License.
@rem
@if "%DEBUG%" == "" @echo off
@rem ##########################################################################
@rem
@rem Gradle startup script for Windows
@rem
@rem ##########################################################################
@rem Set local scope for the variables with windows NT shell
if "%OS%"=="Windows_NT" setlocal
set DIRNAME=%~dp0
if "%DIRNAME%" == "" set DIRNAME=.
set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME%
@rem Resolve any "." and ".." in APP_HOME to make it shorter.
for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
@rem Find java.exe
if defined JAVA_HOME goto findJavaFromJavaHome
set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1
if "%ERRORLEVEL%" == "0" goto execute
echo.
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
goto fail
:findJavaFromJavaHome
set JAVA_HOME=%JAVA_HOME:"=%
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
if exist "%JAVA_EXE%" goto execute
echo.
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
goto fail
:execute
@rem Setup the command line
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
@rem Execute Gradle
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*
:end
@rem End local scope for the variables with windows NT shell
if "%ERRORLEVEL%"=="0" goto mainEnd
:fail
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
rem the _cmd.exe /c_ return code!
if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
exit /b 1
:mainEnd
if "%OS%"=="Windows_NT" endlocal
:omega

Binary file not shown.

Binary file not shown.

@ -0,0 +1 @@
rootProject.name = 'cindercore_modlist'

@ -0,0 +1,292 @@
package com.zivilon.cindercore_modlist;
import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.Mod.EventHandler;
import cpw.mods.fml.common.event.FMLInitializationEvent;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import cpw.mods.fml.common.network.FMLNetworkEvent;
import cpw.mods.fml.common.network.FMLNetworkEvent.ServerConnectionFromClientEvent;
import java.util.Collections;
import java.util.HashMap;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.UUID;
import io.netty.channel.ChannelDuplexHandler;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelHandler;
import io.netty.channel.Channel;
import io.netty.channel.ChannelPipeline;
import io.netty.channel.ChannelPromise;
import net.minecraft.command.CommandHandler;
import net.minecraft.command.ICommand;
import net.minecraft.command.ICommandSender;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.server.MinecraftServer;
import net.minecraft.util.ChatComponentText;
import io.netty.channel.Channel;
@Mod(modid = CinderCoreModlist.MODID, version = CinderCoreModlist.VERSION, dependencies = "required-after:spongemixins@[1.1.0,)", acceptableRemoteVersions = "*", useMetadata = true)
public class CinderCoreModlist
{
public static final String MODID = "cindercore_modlist";
public static final String VERSION = "1.0";
// public static final Map<UUID, Channel> channel_map = new HashMap<>();
public static final Map<UUID, Map<String, String>> player_mods = new HashMap<>();
public static final Map<Integer, FallbackEntry> item_fallback_map = new HashMap<>();
public static final Map<Integer, FallbackEntry> entity_fallback_map = new HashMap<>();
public static final Map<String, CustomFallbackEntry> custom_fallback_map = new HashMap<>();
public static final Map<UUID, Map<Integer, Integer>> player_item_fallback_map = new HashMap<>();
public static final Map<UUID, Map<Integer, Integer>> player_entity_fallback_map = new HashMap<>();
public static final Map<UUID, Map<String, Map<Integer, Integer>>> player_custom_fallback_map = new HashMap<>();
public static final boolean debug = false;
@EventHandler
public void init(FMLInitializationEvent event)
{
System.out.println("Cinder Core Modlist initialized");
}
// Used to save mod list into player_mods. Invoked in handshake process. USE WITH EXTREME CAUTION.
public static void savePlayerModList(UUID player_id, Map<String, String> modList) {
player_mods.put(player_id, modList);
}
/* public static Channel get_FML_channel(UUID uuid) {
return channel_map.get(uuid);
}*/
// Get map of all mods player has installed. Includes versions.
public static Map<String, String> getPlayerMods(String playerName) {
return player_mods.get(playerName);
}
// Returns true if player has mod installed. False if not.
public static boolean hasPlayerMod(String playerName, String modId) {
Map<String, String> mods = player_mods.get(playerName);
return mods != null && mods.containsKey(modId);
}
// Get base fallback maps. Used for generating player's fallback maps.
public static Map<Integer, FallbackEntry> getItemFallbackMap() {
return item_fallback_map;
}
public static Map<Integer, FallbackEntry> getEntityFallbackMap() {
return entity_fallback_map;
}
public static Map<String, CustomFallbackEntry> getCustomFallbackMap() {
return custom_fallback_map;
}
// Register fallbacks. Recommended to use the wrappers from CinderCore instead.
public static void register_item_fallback(Integer original_id, FallbackEntry fallback) {
item_fallback_map.put(original_id, fallback);
if (debug) {
if (item_fallback_map == null) {
System.out.println("[CinderCoreModList] Item fallback map is null");
} else if (item_fallback_map.isEmpty()) {
System.out.println("[CinderCoreModList] Item fallback map is empty");
} else {
System.out.println("[CinderCoreModList] Contents of item fallback map:");
printMapContents(item_fallback_map);
}
}
}
public static void register_entity_fallback(Integer entity_id, FallbackEntry fallback) {
entity_fallback_map.put(entity_id, fallback);
if (debug) {
if (entity_fallback_map == null) {
System.out.println("[CinderCoreModList] Entity fallback map is null");
} else if (entity_fallback_map.isEmpty()) {
System.out.println("[CinderCoreModList] Entity fallback map is empty");
} else {
System.out.println("[CinderCoreModList] Contents of entity fallback map:");
printMapContents(entity_fallback_map);
}
}
}
public static void register_custom_fallback(String type, CustomFallbackEntry fallback) {
custom_fallback_map.put(type, fallback);
if (debug) {
if (custom_fallback_map == null) {
System.out.println("[CinderCoreModList] Custom fallback map is null");
} else if (entity_fallback_map.isEmpty()) {
System.out.println("[CinderCoreModList] Custom fallback map is empty");
} else {
System.out.println("[CinderCoreModList] Contents of custom fallback map:");
printMapContentsCustom(custom_fallback_map);
}
}
}
// Get map of specific player's fallbacks
public static Map<Integer, Integer> getPlayerItemFallbacks(UUID player_id) {
return player_item_fallback_map.get(player_id);
}
public static Map<Integer, Integer> getPlayerEntityFallbacks(UUID player_id) {
return player_entity_fallback_map.get(player_id);
}
public static Map<String, Map<Integer, Integer>> getPlayerCustomFallbacks(UUID player_id) {
if (debug) {
System.out.println("[CinderCoreModlist] Getting custom fallbacks for user " + player_id);
System.out.println("[CinderCoreModlist] Full list of player fallbacks:");
printAllPlayerMapContentsCustom(player_custom_fallback_map);
}
return player_custom_fallback_map.get(player_id);
}
// Generate specific player's fallbacks. Invoked during handshake process.
public static void generatePlayerItemFallbackMap(UUID player_id) {
System.out.println("[CinderCoreModList] Generating fallback map for " + player_id);
Map<String, String> player_modlist = player_mods.get(player_id);
Map<Integer, Integer> fallbacks = new HashMap<>();
if (debug) {
if (item_fallback_map == null) {
System.out.println("[CinderCoreModList] Item fallback map is null");
} else {
System.out.println("[CinderCoreModList] Contents of general fallback map during player map generation:");
printMapContents(item_fallback_map);
}
}
for (Map.Entry<Integer, FallbackEntry> entry : item_fallback_map.entrySet()) {
FallbackEntry fallbackEntry = entry.getValue();
String player_version = player_modlist.get(fallbackEntry.mod_name);
if (player_version == null || compare_versions(player_version, fallbackEntry.version) < 0) {
if (debug) System.out.println("[CinderCoreModList] Player missing mod: " + fallbackEntry.mod_name + " version " + fallbackEntry.version);
fallbacks.put(entry.getKey(), fallbackEntry.fallback_id);
}
}
if (debug) {
System.out.println("[CinderCoreModList] Adding to fallback map:");
printMapContentsInt(fallbacks);
}
player_item_fallback_map.put(player_id, fallbacks);
}
public static void generatePlayerEntityFallbackMap(UUID player_id) {
Map<String, String> player_modlist = player_mods.get(player_id);
Map<Integer, Integer> fallbacks = new HashMap<>();
for (Map.Entry<Integer, FallbackEntry> entry : entity_fallback_map.entrySet()) {
FallbackEntry fallbackEntry = entry.getValue();
String player_version = player_modlist.get(fallbackEntry.mod_name);
if (player_version == null || compare_versions(player_version, fallbackEntry.version) < 0) {
fallbacks.put(entry.getKey(), fallbackEntry.fallback_id);
}
}
player_entity_fallback_map.put(player_id, fallbacks);
}
public static void generatePlayerCustomFallbackMap(UUID player_id) {
Map<String, String> player_modlist = player_mods.get(player_id);
Map<String, Map<Integer, Integer>> fallbacks = new HashMap<>(); // Nested structure
for (Map.Entry<String, CustomFallbackEntry> entry : custom_fallback_map.entrySet()) {
CustomFallbackEntry fallbackEntry = entry.getValue();
String player_version = player_modlist.get(fallbackEntry.mod_name);
if (player_version == null || compare_versions(player_version, fallbackEntry.version) < 0) {
Map<Integer, Integer> type_fallbacks = fallbacks.get(fallbackEntry.type);
if (type_fallbacks == null) {
type_fallbacks = new HashMap<>();
fallbacks.put(fallbackEntry.type, type_fallbacks);
}
type_fallbacks.put(fallbackEntry.original_id, fallbackEntry.fallback_id);
}
}
player_custom_fallback_map.put(player_id, fallbacks);
}
// Used for comparing versions of mods. Version must be numbers separated by . and nothing else.
public static int compare_versions(String version1, String version2) {
String[] parts1 = version1.split("\\.");
String[] parts2 = version2.split("\\.");
for (int i = 0; i < Math.max(parts1.length, parts2.length); i++) {
int part1 = i < parts1.length ? Integer.parseInt(parts1[i]) : 0;
int part2 = i < parts2.length ? Integer.parseInt(parts2[i]) : 0;
if (part1 != part2) {
return part1 < part2 ? -1 : 1;
}
}
return 0;
}
// Debug method
public static void printMapContents(Map<Integer, FallbackEntry> map) {
if (map.isEmpty()) {
System.out.println("[CinderCoreModList] Map is empty.");
} else {
for (Map.Entry<Integer, FallbackEntry> entry : map.entrySet()) {
System.out.println("[CinderCoreModList] Key: " + entry.getKey() + ", Value: " + entry.getValue().fallback_id);
}
}
}
public static void printMapContentsCustom(Map<String, CustomFallbackEntry> map) {
/* if (map.isEmpty()) {
System.out.println("[CinderCoreModList] Map is empty.");
} else {
for (Map.Entry<Integer, CustomFallbackEntry> entry : map.entrySet()) {
System.out.println("[CinderCoreModList] Key: " + entry.getKey() + ", Value: " + entry.getValue().fallback_id);
}
}*/
}
// Debug method
public static void printMapContentsInt(Map<Integer, Integer> map) {
if (map.isEmpty()) {
System.out.println("[CinderCoreModList] Map is empty.");
} else {
for (Map.Entry<Integer, Integer> entry : map.entrySet()) {
System.out.println("[CinderCoreModList] Key: " + entry.getKey() + ", Value: " + entry.getValue());
}
}
}
// Debug method
public static void printAllPlayerMapContents(Map<UUID, Map<Integer, Integer>> map) {
if (map.isEmpty()) {
System.out.println("[CinderCoreModList] There are no player fallback maps.");
} else {
for (Map.Entry<UUID, Map<Integer, Integer>> entry : map.entrySet()) {
System.out.println("[CinderCoreModList] Reading player fallback map: " + entry.getKey());
printMapContentsInt(entry.getValue());
}
}
}
public static void printAllPlayerMapContentsCustom(Map<UUID, Map<String, Map<Integer, Integer>>> map) {
if (map.isEmpty()) {
System.out.println("[CinderCoreModList] There are no player fallback maps.");
} else {
for (Map.Entry<UUID, Map<String, Map<Integer, Integer>>> playerEntry : map.entrySet()) {
UUID playerUUID = playerEntry.getKey();
Map<String, Map<Integer, Integer>> typeMap = playerEntry.getValue();
System.out.println("[CinderCoreModList] Reading player fallback map for UUID: " + playerUUID);
for (Map.Entry<String, Map<Integer, Integer>> typeEntry : typeMap.entrySet()) {
String dataType = typeEntry.getKey();
Map<Integer, Integer> fallbackMap = typeEntry.getValue();
System.out.println("[CinderCoreModList] Fallbacks for type: " + dataType);
printMapContentsInt(fallbackMap);
}
}
}
}
}

@ -0,0 +1,17 @@
package com.zivilon.cindercore_modlist;
public class CustomFallbackEntry {
public final int original_id;
public final int fallback_id;
public final String mod_name;
public final String version;
public final String type;
public CustomFallbackEntry(int default_id, int fall_id, String custom_type, String mod, String mod_version) {
original_id = default_id;
fallback_id = fall_id;
mod_name = mod;
version = mod_version;
type = custom_type;
}
}

@ -0,0 +1,15 @@
package com.zivilon.cindercore_modlist;
public class FallbackEntry {
public final int original_id;
public final int fallback_id;
public final String mod_name;
public final String version;
public FallbackEntry(int default_id, int fall_id, String mod, String mod_version) {
original_id = default_id;
fallback_id = fall_id;
mod_name = mod;
version = mod_version;
}
}

@ -0,0 +1,43 @@
package com.zivilon.cindercore_modlist.coremod;
import cpw.mods.fml.relauncher.IFMLLoadingPlugin;
import cpw.mods.fml.relauncher.IFMLLoadingPlugin.MCVersion;
import cpw.mods.fml.relauncher.IFMLLoadingPlugin.SortingIndex;
import cpw.mods.fml.relauncher.IFMLLoadingPlugin.TransformerExclusions;
import org.spongepowered.asm.launch.MixinBootstrap;
import org.spongepowered.asm.mixin.Mixins;
import java.util.Map;
@TransformerExclusions({"com.zivilon.cindercore_modlist.coremod"})
@SortingIndex(1001)
@MCVersion("1.7.10")
public class ModListCore implements IFMLLoadingPlugin {
@Override
public String[] getASMTransformerClass() {
return new String[] {};
}
@Override
public String getModContainerClass() {
// Return the class name of your @Mod class
return null;
}
@Override
public String getSetupClass() {
// Return the class name that sets up coremod environment, or null if none
return null;
}
@Override
public void injectData(Map<String, Object> data) {
MixinBootstrap.init();
Mixins.addConfiguration("mixins.cindercore_modlist.json");
}
@Override
public String getAccessTransformerClass() {
// Return the class name of your access transformer or null if none
return null;
}
}

@ -0,0 +1,50 @@
package com.zivilon.cindercore_modlist.mixins;
import java.lang.reflect.Field;
import io.netty.channel.ChannelHandlerContext;
import cpw.mods.fml.common.network.handshake.FMLHandshakeMessage;
import cpw.mods.fml.common.network.handshake.FMLHandshakeServerState;
import cpw.mods.fml.common.network.handshake.NetworkDispatcher;
import cpw.mods.fml.common.network.handshake.FMLHandshakeMessage.ModList;
import net.minecraft.entity.player.EntityPlayerMP;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import cpw.mods.fml.common.FMLLog;
import cpw.mods.fml.relauncher.Side;
import java.util.Map;
import java.util.UUID;
import com.zivilon.cindercore_modlist.CinderCoreModlist;
@Mixin(targets = "cpw.mods.fml.common.network.handshake.FMLHandshakeServerState$2")
public abstract class MixinFMLHandshakeServerStateHELLO {
@Inject(method = "accept", at = @At("RETURN"), cancellable = false)
private void onAccept(ChannelHandlerContext ctx, FMLHandshakeMessage msg, CallbackInfoReturnable<FMLHandshakeServerState> cir) {
if (msg == null || !(msg instanceof FMLHandshakeMessage.ModList)) {
return;
}
System.out.println("[CinderCore] Initiating modified handshake HELLO");
FMLHandshakeMessage.ModList modListMsg = (FMLHandshakeMessage.ModList) msg;
Map<String, String> modList = modListMsg.modList();
NetworkDispatcher dispatcher = ctx.channel().attr(NetworkDispatcher.FML_DISPATCHER).get();
if (dispatcher == null) {
return;
}
try {
Field playerField = NetworkDispatcher.class.getDeclaredField("player");
playerField.setAccessible(true);
EntityPlayerMP player = (EntityPlayerMP) playerField.get(dispatcher);
System.out.println("[CinderCore] Player " + player.getCommandSenderName() + " is connecting with mods " + modList);
if (player != null) {
CinderCoreModlist.savePlayerModList(player.getUniqueID(), modList);
}
} catch (NoSuchFieldException | IllegalAccessException e) {
e.printStackTrace();
}
}
}

@ -0,0 +1,77 @@
package com.zivilon.cindercore_modlist.mixins;
import java.lang.reflect.Field;
import io.netty.channel.Channel;
import io.netty.channel.ChannelFutureListener;
import io.netty.channel.ChannelHandlerContext;
import cpw.mods.fml.common.network.handshake.FMLHandshakeMessage;
import cpw.mods.fml.common.network.handshake.FMLHandshakeServerState;
import cpw.mods.fml.common.network.handshake.NetworkDispatcher;
import cpw.mods.fml.common.network.handshake.FMLHandshakeMessage.ModList;
import cpw.mods.fml.common.network.NetworkRegistry;
import net.minecraft.entity.player.EntityPlayerMP;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.Overwrite;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import cpw.mods.fml.common.FMLLog;
import cpw.mods.fml.relauncher.Side;
import java.util.Map;
import java.util.UUID;
import cpw.mods.fml.common.registry.GameData;
import cpw.mods.fml.common.registry.GameData.GameDataSnapshot;
import com.zivilon.cindercore_modlist.CinderCoreModlist;
import com.zivilon.cindercore_modlist.util.HandshakeUtils;
import com.zivilon.cindercore.network.PacketInterceptor;
@Mixin(targets = "cpw.mods.fml.common.network.handshake.FMLHandshakeServerState$3")
public abstract class MixinFMLHandshakeServerStateWAITINGCACK {
@Overwrite
public FMLHandshakeServerState accept(ChannelHandlerContext ctx, FMLHandshakeMessage msg)
{
if (!ctx.channel().attr(NetworkDispatcher.IS_LOCAL).get())
{
System.out.println("[CinderCore] Initiating modified handshake WAITINGCACK");
// Get the player instance
EntityPlayerMP player = null;
try {
// Performance loss from reflection doesn't matter on login
NetworkDispatcher dispatcher = ctx.channel().attr(NetworkDispatcher.FML_DISPATCHER).get();
Field playerField = NetworkDispatcher.class.getDeclaredField("player");
playerField.setAccessible(true);
player = (EntityPlayerMP) playerField.get(dispatcher);
} catch (NoSuchFieldException | IllegalAccessException e) {
System.out.println("[CinderModlistCore] Reflection error in MixinFMLHandshakeServerStateWAITINGCACK");
e.printStackTrace();
}
UUID uuid = player.getUniqueID();
CinderCoreModlist.generatePlayerItemFallbackMap(uuid);
CinderCoreModlist.generatePlayerEntityFallbackMap(uuid);
CinderCoreModlist.generatePlayerCustomFallbackMap(uuid);
GameDataSnapshot itemlist = GameData.buildItemDataList();
Map<Integer, Integer> fallbacks = CinderCoreModlist.getPlayerItemFallbacks(uuid);
// Modifying the Map
itemlist = HandshakeUtils.modifyGameDataSnapshot(itemlist, fallbacks);
ctx.writeAndFlush(new FMLHandshakeMessage.ModIdData(itemlist)).addListener(ChannelFutureListener.FIRE_EXCEPTION_ON_FAILURE);
}
FMLHandshakeServerState currentState = FMLHandshakeServerState.WAITINGCACK;
FMLHandshakeMessage new_msg = new FMLHandshakeMessage.HandshakeAck(currentState.ordinal());
/* if (new_msg instanceof FMLHandshakeMessage.ClientHello) System.out.println("[CinderModlistCore] Sending instance of ClientHello");
if (new_msg instanceof FMLHandshakeMessage.ModIdData) System.out.println("[CinderModlistCore] Sending instance of ModIdData");
if (new_msg instanceof FMLHandshakeMessage.HandshakeAck) System.out.println("[CinderModlistCore] Sending instance of HandshakeAck");
System.out.println("Sent");*/
ctx.writeAndFlush(new_msg).addListener(ChannelFutureListener.FIRE_EXCEPTION_ON_FAILURE);
NetworkRegistry.INSTANCE.fireNetworkHandshake(ctx.channel().attr(NetworkDispatcher.FML_DISPATCHER).get(), Side.SERVER);
return FMLHandshakeServerState.COMPLETE;
}
}

@ -0,0 +1,40 @@
package com.zivilon.cindercore_modlist.util;
import java.util.Map;
import java.util.ArrayList;
import java.util.List;
import cpw.mods.fml.common.registry.GameData.GameDataSnapshot;
import com.zivilon.cindercore_modlist.CinderCoreModlist;
import com.zivilon.cindercore_modlist.FallbackEntry;
public class HandshakeUtils {
private static boolean shouldRemove(Map.Entry<String, Integer> entry, Map<Integer, Integer> fallbackMap) {
return fallbackMap.containsKey(entry.getValue());
}
public static GameDataSnapshot modifyGameDataSnapshot(GameDataSnapshot itemlist, Map<Integer, Integer> fallbackMap) {
List<String> removedKeys = new ArrayList<>();
itemlist.idMap.entrySet().removeIf(entry -> {
boolean toRemove = shouldRemove(entry, fallbackMap);
if (toRemove) {
removedKeys.add(entry.getKey());
}
return toRemove;
});
itemlist.blockSubstitutions.removeIf(removedKeys::contains);
itemlist.itemSubstitutions.removeIf(removedKeys::contains);
return itemlist;
}
public static void printGameDataSnapshot(GameDataSnapshot itemlist) {
System.out.println("[CinderCoreModlist] Current GameDataSnapshot Items:");
for (Map.Entry<String, Integer> entry : itemlist.idMap.entrySet()) {
System.out.println("Name: " + entry.getKey() + ", ID: " + entry.getValue());
}
}
}

@ -0,0 +1,3 @@
public cpw.mods.fml.common.network.handshake.FMLHandshakeServerState
public cpw.mods.fml.common.network.handshake.NetworkDispatcher player
public cpw.mods.fml.common.network.handshake.FMLHandshakeMessage$HandshakeAck <init>(I)V

@ -0,0 +1,17 @@
[
{
"modid": "cindercore_modlist",
"name": "Cinder Core Modlist",
"description": "Mod list provider for Cinder Core",
"version": "${version}",
"mcversion": "${mcversion}",
"url": "",
"updateUrl": "",
"authorList": ["Shinare"],
"credits": "",
"logoFile": "",
"screenshots": [],
"dependencies": [],
"accessTransformer": "cindercore_at.cfg"
}
]

@ -0,0 +1,13 @@
{
"required": true,
"minVersion": "0.7.11",
"package": "com.zivilon.cindercore_modlist.mixins",
"refmap": "mixins.cindercore_modlist.refmap.json",
"target": "@env(DEFAULT)",
"compatibilityLevel": "JAVA_8",
"mixins": [
"MixinFMLHandshakeServerStateHELLO",
"MixinFMLHandshakeServerStateWAITINGCACK"
],
"client": []
}
Loading…
Cancel
Save