From d1680864edfbc7cec0e6decf1e3a2b30f120aa0e Mon Sep 17 00:00:00 2001 From: Kyle Gunger Date: Tue, 14 Nov 2023 17:09:23 -0500 Subject: Update to 1.20.2 --- LICENSE | 2 +- build.gradle | 50 ++-- gradle.properties | 18 +- gradle/wrapper/gradle-wrapper.jar | Bin 59203 -> 63375 bytes gradle/wrapper/gradle-wrapper.properties | 4 +- gradlew | 281 +++++++++++++-------- gradlew.bat | 181 ++++++------- settings.gradle | 18 +- src/main/java/net/cshift/api/transit/Transit.java | 48 ++++ .../net/cshift/api/transit/network/Channel.java | 142 +++++++++++ .../java/net/cshift/api/transit/network/INode.java | 70 +++++ .../net/cshift/api/transit/network/ISystem.java | 15 ++ .../cshift/api/transit/network/PoolManifest.java | 40 +++ .../api/transit/network/packet/DynamicPacket.java | 43 ++++ .../api/transit/network/packet/IDynamicPacket.java | 14 + .../api/transit/network/packet/IStaticPacket.java | 23 ++ .../transit/network/packet/MetaDynamicPacket.java | 44 ++++ .../api/transit/network/packet/MetaPacket.java | 35 +++ .../api/transit/network/packet/StaticPacket.java | 36 +++ .../net/cshift/api/transit/type/SimpleTypes.java | 43 ++++ .../java/net/cshift/api/transit/type/TFluid.java | 34 +++ .../java/net/cshift/api/transit/type/TItem.java | 57 +++++ .../java/net/cshift/api/transit/type/TMana.java | 31 +++ .../java/net/cshift/api/transit/type/Type.java | 240 ++++++++++++++++++ .../api/transit/type/group/GroupRegistry.java | 50 ++++ .../api/transit/type/group/SimpleGroups.java | 58 +++++ .../cshift/api/transit/type/group/TypeGroup.java | 220 ++++++++++++++++ src/main/java/net/cshift/transit/Transit.java | 17 -- .../java/net/cshift/transit/network/Channel.java | 118 --------- .../java/net/cshift/transit/network/INode.java | 70 ----- .../java/net/cshift/transit/network/ISystem.java | 15 -- .../net/cshift/transit/network/PoolManifest.java | 40 --- .../transit/network/packet/DynamicPacket.java | 43 ---- .../transit/network/packet/IDynamicPacket.java | 14 - .../transit/network/packet/IStaticPacket.java | 23 -- .../transit/network/packet/MetaDynamicPacket.java | 44 ---- .../cshift/transit/network/packet/MetaPacket.java | 35 --- .../transit/network/packet/StaticPacket.java | 36 --- .../java/net/cshift/transit/type/SimpleTypes.java | 19 -- src/main/java/net/cshift/transit/type/TFluid.java | 34 --- src/main/java/net/cshift/transit/type/TItem.java | 33 --- src/main/java/net/cshift/transit/type/TMana.java | 31 --- src/main/java/net/cshift/transit/type/Type.java | 240 ------------------ .../cshift/transit/type/group/GroupRegistry.java | 60 ----- .../cshift/transit/type/group/SimpleGroups.java | 29 --- .../net/cshift/transit/type/group/TypeGroup.java | 204 --------------- src/main/resources/fabric.mod.json | 10 +- 47 files changed, 1561 insertions(+), 1351 deletions(-) create mode 100644 src/main/java/net/cshift/api/transit/Transit.java create mode 100644 src/main/java/net/cshift/api/transit/network/Channel.java create mode 100644 src/main/java/net/cshift/api/transit/network/INode.java create mode 100644 src/main/java/net/cshift/api/transit/network/ISystem.java create mode 100644 src/main/java/net/cshift/api/transit/network/PoolManifest.java create mode 100644 src/main/java/net/cshift/api/transit/network/packet/DynamicPacket.java create mode 100644 src/main/java/net/cshift/api/transit/network/packet/IDynamicPacket.java create mode 100644 src/main/java/net/cshift/api/transit/network/packet/IStaticPacket.java create mode 100644 src/main/java/net/cshift/api/transit/network/packet/MetaDynamicPacket.java create mode 100644 src/main/java/net/cshift/api/transit/network/packet/MetaPacket.java create mode 100644 src/main/java/net/cshift/api/transit/network/packet/StaticPacket.java create mode 100644 src/main/java/net/cshift/api/transit/type/SimpleTypes.java create mode 100644 src/main/java/net/cshift/api/transit/type/TFluid.java create mode 100644 src/main/java/net/cshift/api/transit/type/TItem.java create mode 100644 src/main/java/net/cshift/api/transit/type/TMana.java create mode 100644 src/main/java/net/cshift/api/transit/type/Type.java create mode 100644 src/main/java/net/cshift/api/transit/type/group/GroupRegistry.java create mode 100644 src/main/java/net/cshift/api/transit/type/group/SimpleGroups.java create mode 100644 src/main/java/net/cshift/api/transit/type/group/TypeGroup.java delete mode 100644 src/main/java/net/cshift/transit/Transit.java delete mode 100644 src/main/java/net/cshift/transit/network/Channel.java delete mode 100644 src/main/java/net/cshift/transit/network/INode.java delete mode 100644 src/main/java/net/cshift/transit/network/ISystem.java delete mode 100644 src/main/java/net/cshift/transit/network/PoolManifest.java delete mode 100644 src/main/java/net/cshift/transit/network/packet/DynamicPacket.java delete mode 100644 src/main/java/net/cshift/transit/network/packet/IDynamicPacket.java delete mode 100644 src/main/java/net/cshift/transit/network/packet/IStaticPacket.java delete mode 100644 src/main/java/net/cshift/transit/network/packet/MetaDynamicPacket.java delete mode 100644 src/main/java/net/cshift/transit/network/packet/MetaPacket.java delete mode 100644 src/main/java/net/cshift/transit/network/packet/StaticPacket.java delete mode 100644 src/main/java/net/cshift/transit/type/SimpleTypes.java delete mode 100644 src/main/java/net/cshift/transit/type/TFluid.java delete mode 100644 src/main/java/net/cshift/transit/type/TItem.java delete mode 100644 src/main/java/net/cshift/transit/type/TMana.java delete mode 100644 src/main/java/net/cshift/transit/type/Type.java delete mode 100644 src/main/java/net/cshift/transit/type/group/GroupRegistry.java delete mode 100644 src/main/java/net/cshift/transit/type/group/SimpleGroups.java delete mode 100644 src/main/java/net/cshift/transit/type/group/TypeGroup.java diff --git a/LICENSE b/LICENSE index f42cb7a..2faeaf3 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2020 Kyle Gunger +Copyright (c) 2023 Kyle Gunger Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/build.gradle b/build.gradle index f807b77..1425a6c 100644 --- a/build.gradle +++ b/build.gradle @@ -1,15 +1,15 @@ plugins { - id 'fabric-loom' version '0.8-SNAPSHOT' + id 'fabric-loom' version '1.4-SNAPSHOT' id 'maven-publish' } -sourceCompatibility = JavaVersion.VERSION_16 -targetCompatibility = JavaVersion.VERSION_16 - -archivesBaseName = project.archives_base_name version = project.mod_version group = project.maven_group +base { + archivesName = project.archives_base_name +} + repositories { // Add repositories to retrieve artifacts from in here. // You should only use this when depending on other mods because @@ -18,6 +18,18 @@ repositories { // for more information about repositories. } +loom { + splitEnvironmentSourceSets() + + mods { + "modid" { + sourceSet sourceSets.main + sourceSet sourceSets.client + } + } + +} + dependencies { // To change the versions see the gradle.properties file minecraft "com.mojang:minecraft:${project.minecraft_version}" @@ -26,9 +38,11 @@ dependencies { // Fabric API. This is technically optional, but you probably want it anyway. modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}" + + // Uncomment the following line to enable the deprecated Fabric API modules. + // These are included in the Fabric API production distribution and allow you to update your mod to the latest modules at a later more convenient time. - // PSA: Some older mods, compiled on Loom 0.2.1, might have outdated Maven POMs. - // You may need to force-disable transitiveness on them. + // modImplementation "net.fabricmc.fabric-api:fabric-api-deprecated:${project.fabric_version}" } processResources { @@ -40,14 +54,7 @@ processResources { } tasks.withType(JavaCompile).configureEach { - // ensure that the encoding is set to UTF-8, no matter what the system default is - // this fixes some edge cases with special characters not displaying correctly - // see http://yodaconditions.net/blog/fix-for-java-file-encoding-problems-with-gradle.html - // If Javadoc is generated, this must be specified in that task too. - it.options.encoding = "UTF-8" - - // Minecraft 1.17 (21w19a) upwards uses Java 16. - it.options.release = 16 + it.options.release = 17 } java { @@ -55,11 +62,14 @@ java { // if it is present. // If you remove this line, sources will not be generated. withSourcesJar() + + sourceCompatibility = JavaVersion.VERSION_17 + targetCompatibility = JavaVersion.VERSION_17 } jar { from("LICENSE") { - rename { "${it}_${project.archivesBaseName}"} + rename { "${it}_${project.base.archivesName.get()}"} } } @@ -67,13 +77,7 @@ jar { publishing { publications { mavenJava(MavenPublication) { - // add all the jars that should be included when publishing to maven - artifact(remapJar) { - builtBy remapJar - } - artifact(sourcesJar) { - builtBy remapSourcesJar - } + from components.java } } diff --git a/gradle.properties b/gradle.properties index 04fba21..240d22c 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,17 +1,17 @@ # Done to increase the memory available to gradle. org.gradle.jvmargs=-Xmx1G +org.gradle.parallel=true # Fabric Properties - # check these on https://fabricmc.net/use - minecraft_version=1.17 - yarn_mappings=1.17+build.1 - loader_version=0.11.3 +# check these on https://fabricmc.net/develop +minecraft_version=1.20.2 +yarn_mappings=1.20.2+build.1 +loader_version=0.14.22 # Mod Properties - mod_version = 2.0.0 - maven_group = net.corechg - archives_base_name = transit-api +mod_version=3.0.0-alpha +maven_group=net.cshift.api +archives_base_name=transit # Dependencies - # currently not on the main fabric site, check on the maven: https://maven.fabricmc.net/net/fabricmc/fabric-api/fabric-api - fabric_version=0.34.9+1.17 +fabric_version=0.89.1+1.20.2 diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar index e708b1c..033e24c 100644 Binary files a/gradle/wrapper/gradle-wrapper.jar and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 0f80bbf..ac72c34 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,7 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-7.0.2-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.3-bin.zip +networkTimeout=10000 +validateDistributionUrl=true zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/gradlew b/gradlew index 4f906e0..fcb6fca 100755 --- a/gradlew +++ b/gradlew @@ -1,7 +1,7 @@ -#!/usr/bin/env sh +#!/bin/sh # -# Copyright 2015 the original author or authors. +# Copyright © 2015-2021 the original authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -17,67 +17,98 @@ # ############################################################################## -## -## Gradle start up script for UN*X -## +# +# Gradle start up script for POSIX generated by Gradle. +# +# Important for running: +# +# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is +# noncompliant, but you have some other compliant shell such as ksh or +# bash, then to run this script, type that shell name before the whole +# command line, like: +# +# ksh Gradle +# +# Busybox and similar reduced shells will NOT work, because this script +# requires all of these POSIX shell features: +# * functions; +# * expansions «$var», «${var}», «${var:-default}», «${var+SET}», +# «${var#prefix}», «${var%suffix}», and «$( cmd )»; +# * compound commands having a testable exit status, especially «case»; +# * various built-in commands including «command», «set», and «ulimit». +# +# Important for patching: +# +# (2) This script targets any POSIX shell, so it avoids extensions provided +# by Bash, Ksh, etc; in particular arrays are avoided. +# +# The "traditional" practice of packing multiple parameters into a +# space-separated string is a well documented source of bugs and security +# problems, so this is (mostly) avoided, by progressively accumulating +# options in "$@", and eventually passing that to Java. +# +# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, +# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; +# see the in-line comments for details. +# +# There are tweaks for specific operating systems such as AIX, CygWin, +# Darwin, MinGW, and NonStop. +# +# (3) This script is generated from the Groovy template +# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt +# within the Gradle project. +# +# You can find Gradle at https://github.com/gradle/gradle/. +# ############################################################################## # 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 +app_path=$0 + +# Need this for daisy-chained symlinks. +while + APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path + [ -h "$app_path" ] +do + ls=$( ls -ld "$app_path" ) + link=${ls#*' -> '} + case $link in #( + /*) app_path=$link ;; #( + *) app_path=$APP_HOME$link ;; + esac 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"' +# This is normally unused +# shellcheck disable=SC2034 +APP_BASE_NAME=${0##*/} +APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit # Use the maximum available, or set MAX_FD != -1 to use that value. -MAX_FD="maximum" +MAX_FD=maximum warn () { echo "$*" -} +} >&2 die () { echo echo "$*" echo exit 1 -} +} >&2 # 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 - ;; +case "$( uname )" in #( + CYGWIN* ) cygwin=true ;; #( + Darwin* ) darwin=true ;; #( + MSYS* | MINGW* ) msys=true ;; #( + NONSTOP* ) nonstop=true ;; esac CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar @@ -87,9 +118,9 @@ CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 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" + JAVACMD=$JAVA_HOME/jre/sh/java else - JAVACMD="$JAVA_HOME/bin/java" + JAVACMD=$JAVA_HOME/bin/java fi if [ ! -x "$JAVACMD" ] ; then die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME @@ -98,88 +129,120 @@ 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. + JAVACMD=java + if ! command -v java >/dev/null 2>&1 + then + 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 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 +if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then + case $MAX_FD in #( + max*) + # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC3045 + MAX_FD=$( ulimit -H -n ) || + warn "Could not query maximum file descriptor limit" + esac + case $MAX_FD in #( + '' | soft) :;; #( + *) + # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC3045 + ulimit -n "$MAX_FD" || + warn "Could not set maximum file descriptor limit to $MAX_FD" + esac 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 +# Collect all arguments for the java command, stacking in reverse order: +# * args from the command line +# * the main class name +# * -classpath +# * -D...appname settings +# * --module-path (only if needed) +# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. # 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 +if "$cygwin" || "$msys" ; then + APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) + CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) + + JAVACMD=$( cygpath --unix "$JAVACMD" ) + # 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\"" + for arg do + if + case $arg in #( + -*) false ;; # don't mess with options #( + /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath + [ -e "$t" ] ;; #( + *) false ;; + esac + then + arg=$( cygpath --path --ignore --mixed "$arg" ) fi - i=`expr $i + 1` + # Roll the args list around exactly as many times as the number of + # args, so each arg winds up back in the position where it started, but + # possibly modified. + # + # NB: a `for` loop captures its iteration list before it begins, so + # changing the positional parameters here affects neither the number of + # iterations, nor the values presented in `arg`. + shift # remove old arg + set -- "$@" "$arg" # push replacement arg 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" +# 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"' + +# Collect all arguments for the java command; +# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of +# shell script including quotes and variable substitutions, so put them in +# double quotes to make sure that they get re-expanded; and +# * put everything else in single quotes, so that it's not re-expanded. + +set -- \ + "-Dorg.gradle.appname=$APP_BASE_NAME" \ + -classpath "$CLASSPATH" \ + org.gradle.wrapper.GradleWrapperMain \ + "$@" + +# Stop when "xargs" is not available. +if ! command -v xargs >/dev/null 2>&1 +then + die "xargs is not available" +fi + +# Use "xargs" to parse quoted args. +# +# With -n1 it outputs one arg per line, with the quotes and backslashes removed. +# +# In Bash we could simply go: +# +# readarray ARGS < <( xargs -n1 <<<"$var" ) && +# set -- "${ARGS[@]}" "$@" +# +# but POSIX shell has neither arrays nor command substitution, so instead we +# post-process each arg (as a line of input to sed) to backslash-escape any +# character that might be a shell metacharacter, then use eval to reverse +# that process (while maintaining the separation between arguments), and wrap +# the whole thing up as a single "set" statement. +# +# This will of course break if any of these variables contains a newline or +# an unmatched quote. +# + +eval "set -- $( + printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | + xargs -n1 | + sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | + tr '\n' ' ' + )" '"$@"' exec "$JAVACMD" "$@" diff --git a/gradlew.bat b/gradlew.bat index 107acd3..6689b85 100644 --- a/gradlew.bat +++ b/gradlew.bat @@ -1,89 +1,92 @@ -@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 +@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=. +@rem This is normally unused +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% equ 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% equ 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! +set EXIT_CODE=%ERRORLEVEL% +if %EXIT_CODE% equ 0 set EXIT_CODE=1 +if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE% +exit /b %EXIT_CODE% + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/settings.gradle b/settings.gradle index 5b60df3..75c4d72 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1,10 +1,10 @@ pluginManagement { - repositories { - jcenter() - maven { - name = 'Fabric' - url = 'https://maven.fabricmc.net/' - } - gradlePluginPortal() - } -} + repositories { + maven { + name = 'Fabric' + url = 'https://maven.fabricmc.net/' + } + mavenCentral() + gradlePluginPortal() + } +} \ No newline at end of file diff --git a/src/main/java/net/cshift/api/transit/Transit.java b/src/main/java/net/cshift/api/transit/Transit.java new file mode 100644 index 0000000..adc9f25 --- /dev/null +++ b/src/main/java/net/cshift/api/transit/Transit.java @@ -0,0 +1,48 @@ +/* + MIT License + + Copyright (c) 2023 Kyle Gunger + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in all + copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + SOFTWARE. +*/ + +package net.cshift.api.transit; + +import net.fabricmc.api.ModInitializer; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import net.cshift.api.transit.type.group.SimpleGroups; + +/** + * @author Kyle Gunger + * @apiNote This is the main entry point for Transit. The api is mostly intended for use on server-side connections. + */ +public class Transit implements ModInitializer { + + private static final Logger LOGGER = LoggerFactory.getLogger("Transit API"); + + @Override + public void onInitialize() { + LOGGER.info("Transit API: Providing a thin wrapper over reality!"); + SimpleGroups.init(); + } + +} diff --git a/src/main/java/net/cshift/api/transit/network/Channel.java b/src/main/java/net/cshift/api/transit/network/Channel.java new file mode 100644 index 0000000..bd4cdf2 --- /dev/null +++ b/src/main/java/net/cshift/api/transit/network/Channel.java @@ -0,0 +1,142 @@ +/* + MIT License + + Copyright (c) 2023 Kyle Gunger + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in all + copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + SOFTWARE. +*/ + +package net.cshift.api.transit.network; + +import net.cshift.api.transit.network.packet.IStaticPacket; + +/** + * @author Kyle Gunger + * @apiNote A channel represents a connection between two nodes. It is able to send data in packets, and serves as a way to organize incoming traffic. + * @param The type of data the packets will be transfering + */ +public final class Channel { + private INode to; + private int id; + private String group; + + /** This constructor should be called by a node approving a connection. The approving node can give the connection an ID and group. + * Negative IDs indicate a terminated connection, so do not initialize the class with a negative ID. + * + * @param node The recieving node + * @param id The channel's id, as assigned by the recieving node. In most cases, this will match the pool ID as a way to match channels to pools. + * @param group + */ + public Channel(INode node, int id, String group) + { + to = node; + this.id = id; + this.group = group; + } + + + + // #################### + // # Channel specific # + // #################### + + /** The recieving INode + * + * @return + */ + public INode getReciever() + { + return to; + } + + /** The ID of the connection, assigned by the recieving INode + * + * @return + */ + public int getID() + { + return id; + } + + /** The group that the channel operates on + * + * @return + */ + public String getGroup() { + return group; + } + + /** Returns true if the connection has been terminated + * + * @return + */ + public boolean isTerminated() + { + return id < 0; + } + + + + // ################################ + // # Info from the recieving node # + // ################################ + + /** Pressure + * + * @apiNote This part of the api is not properly documented yet, and it's use is not reccommended for cross-mod communications. + * @return A Number representing the pressure from the channel (in base group units). + */ + public Number pressure() + { + return to.getPressure(this); + } + + /** Max transfer rate + * + * @return A Number representing the max transfer rate from the channel (in base group units per tick). + */ + public Number rate() + { + return to.getRate(this); + } + + + + // ################################ + // # Interact with the other node # + // ################################ + + /** Terminates the connection and relays the termination to the recieving node + */ + public void terminate() + { + id = -1; + to.onTerminate(this); + } + + /** Send a packet to the recieving node + * + * @param packet the packet to send + * @return The overflow data if the packet is only partially accepted. {@code null} otherwise. + */ + public IStaticPacket send(IStaticPacket packet) + { + return to.accept(packet, this); + } +} diff --git a/src/main/java/net/cshift/api/transit/network/INode.java b/src/main/java/net/cshift/api/transit/network/INode.java new file mode 100644 index 0000000..54701e7 --- /dev/null +++ b/src/main/java/net/cshift/api/transit/network/INode.java @@ -0,0 +1,70 @@ +package net.cshift.api.transit.network; + +import net.cshift.api.transit.network.packet.*; + +/** + * @author Kyle Gunger + * @apiNote A node inside or outside a system. + */ +public interface INode +{ + /** Returns a pool manifest for the INode + * + */ + public PoolManifest getManifest(); + + /** Get the system managing the node or {@code null} if there isn't one + * + */ + public ISystem getSystem(); + + + + // ############### + // # Connections # + // ############### + + /** Call this function to establish a connection with a node. + * + * @param The type of connection being asked for + * @param poolID The ID of the pool the channel will interface with (see PoolManifest) + * @param asker The asking node + * @return A channel if the node accepts the request, {@code null} otherwise + */ + public Channel connect(int poolID, INode asker); + + /** Accept a packet from a channel (or not). + * + * @apiNote Do not call this function, use Channel.send(packet) instead. + * @param The type of the packet and channel + * @param packet The packet to be vetted + * @param channel The channel which the packet is coming through + * @return The overflow data if the packet is only partially accepted. {@code null} otherwise. + */ + public IStaticPacket accept(IStaticPacket packet, Channel channel); + + /** Pressure + * + * @apiNote Do not call this function, use Channel.pressure() instead. + * @param channel The channel asking for the pressure + * @return A Number representing the pressure from the channel (in base group units). + */ + public Number getPressure(Channel channel); + + /** Transfer rate + * + * @apiNote Do not call this function, use Channel.rate() instead. + * @param channel The channel asking for the transfer rate + * @return A Number representing the transfer rate from the channel (in base group units per tick). + */ + public Number getRate(Channel channel); + + /** Called when a channel is terminated + * + * @apiNote Do not call this function, use Channel.terminate() instead. + * @param The type of the channel + * @param channel The channel being terminated + */ + public void onTerminate(Channel channel); + +} diff --git a/src/main/java/net/cshift/api/transit/network/ISystem.java b/src/main/java/net/cshift/api/transit/network/ISystem.java new file mode 100644 index 0000000..b7ab9bf --- /dev/null +++ b/src/main/java/net/cshift/api/transit/network/ISystem.java @@ -0,0 +1,15 @@ +package net.cshift.api.transit.network; + + +/** + * @author Kyle Gunger + * @apiNote An ISystem represents a system of nodes which has been optimized for performance. A node can exist on its own, but an ISystem can't exist without a node. + */ +public interface ISystem +{ + /**The nodes stored by the system + * + * @return INode[] + */ + public INode[] getNodes(); +} diff --git a/src/main/java/net/cshift/api/transit/network/PoolManifest.java b/src/main/java/net/cshift/api/transit/network/PoolManifest.java new file mode 100644 index 0000000..26cbece --- /dev/null +++ b/src/main/java/net/cshift/api/transit/network/PoolManifest.java @@ -0,0 +1,40 @@ +package net.cshift.api.transit.network; + +/** + * @author Kyle Gunger + * @apiNote A pool manifest represents a set of possible data/resource pools that another node can request a channel to. + */ +public abstract class PoolManifest { + + /** Represents the number of pools that the node has access to for the specified resource. + * @apiNote A "pool" in this context represents an independant network of resources. + * Pool zero should be the default group that simple nodes will attempt to connect to. + * @param group The TypeGroup that the pool belongs to + */ + public abstract int poolCount(String group); + + /** The ID of the pool. The INode will use this in a connection attempt with the other INode. + * + * @param group The TypeGroup the pool belongs to + * @param pool Array-like index for pool (gotten from poolCount) + */ + public abstract int poolID(String group, int pool); + + /** If the mod supports named pools, the names can be querried through this function. + * + * @param group The TypeGroup the pool belongs to + * @param pool Array-like index for pool (gotten from poolCount) + */ + public String poolName(String group, int pool) { + return ""; + } + + /** If the mod supports pool descriptions, they can be accessed by this method. + * + * @param group The TypeGroup the pool belongs to + * @param pool Array-like index for pool (gotten from poolCount) + */ + public String poolDescription(String group, int pool) { + return ""; + } +} diff --git a/src/main/java/net/cshift/api/transit/network/packet/DynamicPacket.java b/src/main/java/net/cshift/api/transit/network/packet/DynamicPacket.java new file mode 100644 index 0000000..f3a6c47 --- /dev/null +++ b/src/main/java/net/cshift/api/transit/network/packet/DynamicPacket.java @@ -0,0 +1,43 @@ +package net.cshift.api.transit.network.packet; + +import net.cshift.api.transit.type.Type; + +/** + * Simple packet which stores a fluid value. + * + * @author Kyle Gunger + * + * @param The data type (Object) that the packet transfers + */ +public class DynamicPacket implements IDynamicPacket { + private D data; + private Type type; + + /** Constructor. Stores the given data and uses the given type. + * + * @param dat The packet's data + * @param t The packet's type + */ + public DynamicPacket(D dat, Type t) + { + data = dat; + type = t; + } + + @Override + public D getData() + { + return data; + } + + @Override + public void setData(D dat) + { + data = dat; + } + + @Override + public Type getType() { + return type; + } +} diff --git a/src/main/java/net/cshift/api/transit/network/packet/IDynamicPacket.java b/src/main/java/net/cshift/api/transit/network/packet/IDynamicPacket.java new file mode 100644 index 0000000..334d5f6 --- /dev/null +++ b/src/main/java/net/cshift/api/transit/network/packet/IDynamicPacket.java @@ -0,0 +1,14 @@ +package net.cshift.api.transit.network.packet; + +/** Interface describing a fluid packet. + * @author Kyle Gunger + * + * @param The data type (Object) that the packet transfers + */ +public interface IDynamicPacket extends IStaticPacket{ + /**Set the packet's data. + * + * @return The packet's data + */ + public void setData(D dat); +} diff --git a/src/main/java/net/cshift/api/transit/network/packet/IStaticPacket.java b/src/main/java/net/cshift/api/transit/network/packet/IStaticPacket.java new file mode 100644 index 0000000..ba1b17f --- /dev/null +++ b/src/main/java/net/cshift/api/transit/network/packet/IStaticPacket.java @@ -0,0 +1,23 @@ +package net.cshift.api.transit.network.packet; + +import net.cshift.api.transit.type.*; + +/** Interface describing an unchanging packet. + * @author Kyle Gunger + * + * @param The data type (Object) that the packet transfers. + */ +public interface IStaticPacket +{ + /**Get the packet's data. + * + * @return The packet's data + */ + public D getData(); + + /**Get the packet's type. + * + * @return IType<> The type of the packet + */ + public Type getType(); +} diff --git a/src/main/java/net/cshift/api/transit/network/packet/MetaDynamicPacket.java b/src/main/java/net/cshift/api/transit/network/packet/MetaDynamicPacket.java new file mode 100644 index 0000000..d382645 --- /dev/null +++ b/src/main/java/net/cshift/api/transit/network/packet/MetaDynamicPacket.java @@ -0,0 +1,44 @@ +package net.cshift.api.transit.network.packet; + +import net.cshift.api.transit.type.Type; + +/** Static packet with extra data attached. + * @author Kyle Gunger + * + * @param The data type (Object) that the packet transfers + * @param The type of metadata +*/ +public class MetaDynamicPacket extends DynamicPacket +{ + private M metaData; + + /** Constructor + * + * @param dat The data to store + * @param t The Type of the data + * @param meta The metadata to store + */ + public MetaDynamicPacket(D dat, Type t, M meta) + { + super(dat, t); + metaData = meta; + } + + /** Get the metadata of the packet. + * + * @return The packet's metadata + */ + public M getMetaData() + { + return metaData; + } + + /** Set the metadata of the packet. + * + * @param meta The packet's new metadata + */ + public void setMetaData(M meta) + { + metaData = meta; + } +} diff --git a/src/main/java/net/cshift/api/transit/network/packet/MetaPacket.java b/src/main/java/net/cshift/api/transit/network/packet/MetaPacket.java new file mode 100644 index 0000000..aea1b83 --- /dev/null +++ b/src/main/java/net/cshift/api/transit/network/packet/MetaPacket.java @@ -0,0 +1,35 @@ +package net.cshift.api.transit.network.packet; + +import net.cshift.api.transit.type.*; + +/** Static packet with extra data attached. + * @author Kyle Gunger + * + * @param The data type (Object) that the packet transfers + * @param The type of metadata +*/ +public class MetaPacket extends StaticPacket +{ + private M metaData; + + /** Constructor + * + * @param dat The data to store + * @param t The Type of the data + * @param meta The metadata to store + */ + public MetaPacket(D dat, Type t, M meta) + { + super(dat, t); + metaData = meta; + } + + /** Get the metadata of the packet. + * + * @return The packet's metadata + */ + public M getMetaData() + { + return metaData; + } +} diff --git a/src/main/java/net/cshift/api/transit/network/packet/StaticPacket.java b/src/main/java/net/cshift/api/transit/network/packet/StaticPacket.java new file mode 100644 index 0000000..2c6a16a --- /dev/null +++ b/src/main/java/net/cshift/api/transit/network/packet/StaticPacket.java @@ -0,0 +1,36 @@ +package net.cshift.api.transit.network.packet; + +import net.cshift.api.transit.type.*; + +/** Simple packet which stores an unchanging value. + * @author Kyle Gunger + * + * @param The data type (Object) that the packet transfers. + */ +public class StaticPacket implements IStaticPacket +{ + private D data; + private Type type; + + /** Constructor. Stores the given data and uses the given type. + * + * @param dat The packet's data + * @param t The packet's type + */ + public StaticPacket(D dat, Type t) + { + data = dat; + type = t; + } + + @Override + public D getData() + { + return data; + } + + @Override + public Type getType() { + return type; + } +} diff --git a/src/main/java/net/cshift/api/transit/type/SimpleTypes.java b/src/main/java/net/cshift/api/transit/type/SimpleTypes.java new file mode 100644 index 0000000..54106c7 --- /dev/null +++ b/src/main/java/net/cshift/api/transit/type/SimpleTypes.java @@ -0,0 +1,43 @@ +/* + MIT License + + Copyright (c) 2023 Kyle Gunger + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in all + copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + SOFTWARE. +*/ + +package net.cshift.api.transit.type; + +public final class SimpleTypes { + /** Transfers energy. Energy is stored as a numeric. + */ + public static final Type TransitJoule = new Type("Joule", "ENERGY"); + + /** Transfers mana. TMana stores mana count and type. + */ + public static final Type TransitMana = new Type("TMana", "MANA"); + + /** Transfers items. TItem stores an item and an item count. + */ + public static final Type TransitItem = new Type("TItem", "ITEM"); + + /** Transfers fluid. TFluid stores fluid and mB. + */ + public static final Type TransitFluid = new Type("TFluid", "FLUID"); +} diff --git a/src/main/java/net/cshift/api/transit/type/TFluid.java b/src/main/java/net/cshift/api/transit/type/TFluid.java new file mode 100644 index 0000000..522d75c --- /dev/null +++ b/src/main/java/net/cshift/api/transit/type/TFluid.java @@ -0,0 +1,34 @@ +package net.cshift.api.transit.type; + +import net.minecraft.fluid.*; + +/** Units of fluid. + * @author Kyle Gunger + */ +public class TFluid { + private Fluid fluid; + private Number mb; + + /** Constructor. + * Since a bucket of fluid is the same as a block of a fluid, mb can be called millibuckets or milliblocks. + * + * @param f Fluid stored (Water/Lava/etc.) + * @param mB Count of fluid (droplets) + */ + public TFluid(Fluid f, Number mB) { + fluid = f; + mb = mB; + } + + /** Get the fluid stored. + */ + public Fluid getFluid() { + return fluid; + } + + /** Get the millibuckets stored. + */ + public Number getMilliBuckets() { + return mb; + } +} diff --git a/src/main/java/net/cshift/api/transit/type/TItem.java b/src/main/java/net/cshift/api/transit/type/TItem.java new file mode 100644 index 0000000..54a3d23 --- /dev/null +++ b/src/main/java/net/cshift/api/transit/type/TItem.java @@ -0,0 +1,57 @@ +/* + MIT License + + Copyright (c) 2023 Kyle Gunger + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in all + copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + SOFTWARE. +*/ + +package net.cshift.api.transit.type; + +import net.minecraft.item.*; + +/** Item storage + * @author Kyle Gunger + */ +public class TItem { + private Item item; + private Number count; + + /** Constructor. + * + * @param i Item stored + * @param c Item count + */ + public TItem(Item i, Number c) { + item = i; + count = c; + } + + /** Get the item stored. + */ + public Item getItem() { + return item; + } + + /** Get the item count. + */ + public Number getCount() { + return count; + } +} diff --git a/src/main/java/net/cshift/api/transit/type/TMana.java b/src/main/java/net/cshift/api/transit/type/TMana.java new file mode 100644 index 0000000..a73e47c --- /dev/null +++ b/src/main/java/net/cshift/api/transit/type/TMana.java @@ -0,0 +1,31 @@ +package net.cshift.api.transit.type; + +/** Units of mana. + * @author Kyle Gunger + */ +public class TMana { + private String type; + private Number count; + + /** Constructor + * + * @param t Type of mana (Fire/Water/Dark/Light/etc.) leave empty string for an untyped mana system. + * @param ct Count of mana + */ + public TMana(String t, Number ct) { + type = t; + count = ct; + } + + /** Get the mana type. + */ + public String getType() { + return type; + } + + /** Get the mana stored. + */ + public Number getCount() { + return count; + } +} diff --git a/src/main/java/net/cshift/api/transit/type/Type.java b/src/main/java/net/cshift/api/transit/type/Type.java new file mode 100644 index 0000000..d47cd08 --- /dev/null +++ b/src/main/java/net/cshift/api/transit/type/Type.java @@ -0,0 +1,240 @@ +package net.cshift.api.transit.type; + +import net.cshift.api.transit.network.packet.*; + +/**@author Kyle Gunger + * + * @param The type of object transfered by packets of this type + */ +public class Type +{ + protected final String typeID; + protected final String groupID; + + // Should not override, but you can if you must + public Type(String tID, String gID) + { + typeID = tID; + groupID = gID; + } + + + + // ########################################## + // # Converting from this type to base type # + // ########################################## + + /** Return the data formatted in the given group's base type. + * If creating a new type, override this function if required. + * + * @param data The data (of this type) + * @param group The group asking for the conversion + * @return The data in the group's base type + */ + public T toBase(T data, String group) + { + return data; + } + + /** Return the data formatted in the default group's base type. + * + * @param data The data (of this type) + * @return The data in the group's base type + */ + public final T toBase(T data) + { + return this.toBase(data, this.groupID); + } + + /** Return the packet's data formatted in the given group's base type. + * + * @param packet The packet (of this type) + * @param group The group asking for the conversion + * @return The packet's data in the group's base type + */ + public final T toBase(IStaticPacket packet, String group) + { + return this.toBase(packet.getData(), group); + } + + /** Return the packet's data formatted in the default group's base type. + * + * @param packet The packet (of this type) + * @return The packet's data in the group's base type + */ + public final T toBase(IStaticPacket packet) + { + return this.toBase(packet, this.groupID); + } + + + + // ########################################## + // # Converting from base type to this type # + // ########################################## + + /** Convert data from the given group's base type to this type. + * If creating a new type, override this function if required. + * + * @param data The base data + * @param group The group asking for the conversion + * @return The packet's data in the group's base type + */ + public T fromBase(T data, String group) + { + return data; + } + + /** Convert data from the default group's base type to this type. + * + * @param data The base data + * @return The packet's data in the group's base type + */ + public final T fromBase(T data) + { + return fromBase(data, this.groupID); + } + + /** Create a packet from data formatted in the given group's base type. + * + * @param data The base data + * @param group The group asking for the conversion + * @return The packet's data in the group's base type + */ + public final IStaticPacket packetFromBase(T data, String group) + { + return new StaticPacket(this.fromBase(data, group), this); + } + + /** Create a packet from data formatted in the default group's base type. + * + * @param data The base data + * @return The packet's data in the group's base type + */ + public final IStaticPacket packetFromBase(T data) + { + return packetFromBase(data, this.groupID); + } + + + + // ########################################### + // # Converting from other type to this type # + // ########################################### + + /** Convert data from another type to this type in the given group. + * If creating a new type, override this function if required. + * + * @param from The type to convert from + * @param group The group we are converting within + * @param data The data to convert + * @return The data formatted in this type + */ + public T convertFrom(Type from, T data, String group) { + return this.fromBase(from.toBase(data, group), group); + } + + /** Convert data from another type to this type in the default group. + * + * @param from The type to convert from + * @param data The data to convert + * @return The data formatted in this type + */ + public final T convertFrom(Type from, T data) { + return convertFrom(from, data, from.groupID); + } + + /** Convert a packet using another type to a packet using this type within the given group. + * + * @param packet The packet to convert + * @param group The group to convert within + * @return The new packet formatted in this type + */ + public final IStaticPacket convertFrom(IStaticPacket packet, String group) { + return new StaticPacket(convertFrom(packet.getType(), packet.getData(), group), this); + } + + /** Convert a packet using another type to a packet using this type within the default group. + * + * @param packet The packet to convert + * @return The new packet formatted in this type + */ + public final IStaticPacket convertFrom(IStaticPacket packet) { + return this.convertFrom(packet, packet.getType().groupID); + } + + + + // ########################################### + // # Converting from other type to this type # + // ########################################### + + /** Convert data from this type to another type in the given group. + * + * @param from The type to convert from + * @param group The group we are converting within + * @param data The data to convert + * @return The data formatted in this type + */ + public final T convertTo(Type to, T data, String group) { + return to.convertFrom(this, data, group); + } + + /** Convert data from this type to another type in the default group. + * + * @param from The type to convert from + * @param data The data to convert + * @return The data formatted in this type + */ + public final T convertTo(Type to, T data) { + return to.convertFrom(this, data, this.groupID); + } + + /** Convert a packet using this type to a packet using another type within the given group. + * + * @param packet The packet to convert + * @param group The group to convert within + * @return The new packet formatted in this type + */ + public final IStaticPacket convertTo(Type to, IStaticPacket packet, String group) { + return to.convertFrom(packet, group); + } + + /** Convert a packet using this type to a packet using another type within the default group. + * + * @param packet The packet to convert + * @return The new packet formatted in this type + */ + public final IStaticPacket convertTo(Type to, IStaticPacket packet) { + return to.convertFrom(packet, this.groupID); + } + + + + // ############################## + // # Utility and info functions # + // ############################## + + /** The type identifier. Gives the normal type identity of the type. + * + * @return String + */ + public final String getType() + { + return typeID; + } + + /** The group identifier. Gives the normal group identity of the type. + * + * @return String + */ + public final String getGroup() + { + return groupID; + } + + @Override + public final String toString() { + return groupID + ":" + typeID; + } +} diff --git a/src/main/java/net/cshift/api/transit/type/group/GroupRegistry.java b/src/main/java/net/cshift/api/transit/type/group/GroupRegistry.java new file mode 100644 index 0000000..5e09e71 --- /dev/null +++ b/src/main/java/net/cshift/api/transit/type/group/GroupRegistry.java @@ -0,0 +1,50 @@ +package net.cshift.api.transit.type.group; + +import java.security.InvalidKeyException; +import java.util.HashMap; + +import org.slf4j.*; + +import net.cshift.api.transit.type.Type; + +public final class GroupRegistry { + private static final HashMap> GROUPS = new HashMap>(); + + private static final Logger LOGGER = LoggerFactory.getLogger("Transit API/Group Registry"); + + private GroupRegistry() {} + + public static final boolean addGroup(TypeGroup group) + { + if (GROUPS.containsKey(group.getGroup())) { + LOGGER.warn("Failed to add group " + group + " to the registry. Did another mod add a group with the same name?"); + return false; + } + + GROUPS.put(group.getGroup(), group); + LOGGER.info("Successfully added group " + group + " to the registry."); + + return true; + } + + public static final TypeGroup groupByID(String groupID) + { + if (GROUPS.containsKey(groupID)) { + TypeGroup g = GROUPS.get(groupID); + return (TypeGroup) g; + } + + return null; + } + + public static final Type typeByIdentity(String groupID, String typeID) throws InvalidKeyException + { + TypeGroup group = GroupRegistry.groupByID(groupID); + + if(group != null) + return group.getType(typeID); + + return null; + } + +} diff --git a/src/main/java/net/cshift/api/transit/type/group/SimpleGroups.java b/src/main/java/net/cshift/api/transit/type/group/SimpleGroups.java new file mode 100644 index 0000000..66d0121 --- /dev/null +++ b/src/main/java/net/cshift/api/transit/type/group/SimpleGroups.java @@ -0,0 +1,58 @@ +/* + MIT License + + Copyright (c) 2023 Kyle Gunger + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in all + copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + SOFTWARE. +*/ + +package net.cshift.api.transit.type.group; + +import org.slf4j.*; + +import net.cshift.api.transit.type.*; + +public final class SimpleGroups { + /** Transfers energy. Basic unit is TJoule (Transit Joule). + */ + public static final TypeGroup ENERGY = new TypeGroup(SimpleTypes.TransitJoule); + + /** Transfers mana. Basic unit is TMana (Transit Mana). + */ + public static final TypeGroup MANA = new TypeGroup(SimpleTypes.TransitMana); + + /** Transfers items. Basic unit is TItem. + */ + public static final TypeGroup ITEM = new TypeGroup(SimpleTypes.TransitItem); + + /** Transfers fluids. Basic unit is TFluid. + */ + public static final TypeGroup FLUID = new TypeGroup(SimpleTypes.TransitFluid); + + private static final Logger LOGGER = LoggerFactory.getLogger("Transit API/Simple Groups"); + + public static final void init() + { + LOGGER.info("Initializing simple groups"); + GroupRegistry.addGroup(ENERGY); + GroupRegistry.addGroup(MANA); + GroupRegistry.addGroup(ITEM); + GroupRegistry.addGroup(FLUID); + } +} diff --git a/src/main/java/net/cshift/api/transit/type/group/TypeGroup.java b/src/main/java/net/cshift/api/transit/type/group/TypeGroup.java new file mode 100644 index 0000000..fcbb3ef --- /dev/null +++ b/src/main/java/net/cshift/api/transit/type/group/TypeGroup.java @@ -0,0 +1,220 @@ +/* + MIT License + + Copyright (c) 2023 Kyle Gunger + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in all + copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + SOFTWARE. +*/ + +package net.cshift.api.transit.type.group; + +import java.security.InvalidKeyException; +import java.sql.Types; +import java.util.HashMap; + +import org.slf4j.*; + +import net.cshift.api.transit.type.Type; + +/** + * @author Kyle Gunger + * @param The base object which all grouped Types should convert between. + */ +public final class TypeGroup +{ + // The base Type (provides the group's identifier) + private Type baseType; + + // The list of types. + private final HashMap> TYPES; + + // Logger for events in the TypeGroup. + private static final Logger LOGGER = LoggerFactory.getLogger("Transit API/Type Group"); + + + public TypeGroup(Type base) + { + TYPES = new HashMap>(); + baseType = base; + addType(base); + } + + + // Type management + + /** Add a Type to the TypeGroup. + * The Type must have a group-type combo not already found in this TypeGroup. + * Returns {@code true} if the group was added. + * + * @param type The Type to add + * @return + */ + public boolean addType(Type type) + { + if(TYPES.containsKey(type.getType())) + { + LOGGER.info("Failed to add type " + type + " to group " + getGroup() + ". Was the type already added?"); + return false; + } + + TYPES.put(type.toString(), type); + LOGGER.info("Added type " + type + " to group " + getGroup()); + return true; + + } + + /** Remove a Type from the TypeGroup. + * + * @param type The Type to remove + * @return + */ + public boolean removeType(Type type) + { + if(type.toString().equals(baseType.toString())) { + LOGGER.warn("Failed to remove type " + type + " from group " + getGroup() + ". This is the base type and can not be removed."); + return false; + } + + if(TYPES.containsKey(type.toString())) + { + LOGGER.info("Removed type " + TYPES.remove(type.toString()) + " from group " + getGroup()); + return true; + } + + LOGGER.warn("Failed to remove type " + type + " from group " + getGroup() + ". Are we sure that the type was added to the group first?"); + return false; + } + + /** Remove a type from the group based on it's group-type identifier. + * + * @param type + * @return + */ + public boolean removeType(String groupID, String typeID) + { + String typeString = groupID + ":" + typeID; + + if(baseType.toString().equals(typeString)) { + LOGGER.warn("Failed to remove type " + baseType + " from group " + getGroup() + ". This is the base type and can not be removed."); + return false; + } + + if(TYPES.containsKey(typeString)) + { + LOGGER.info("Removed type " + TYPES.remove(typeString) + " from group " + getGroup()); + return true; + } + + LOGGER.warn("Failed to remove type " + typeString + " from group " + getGroup() + ". Are we sure that the type was added to the group first?"); + return false; + } + + /** Remove a type from the group based on it's group-type identifier. + * + * @param type + * @return + */ + public boolean removeType(String typeID) + { + return removeType(getGroup(), typeID); + } + + + // Check if a type is in the group + + /**Check if the type is in the group + * + * @param type + * @return boolean + */ + public boolean isInGroup(Type type) + { + return TYPES.containsKey(type.toString()) && TYPES.get(type.toString()) == type; + } + + /**Check if the type is in the group + * + * @param groupID + * @param typeID + * @return boolean + */ + public boolean isInGroup(String groupID, String typeID) + { + return TYPES.containsKey(groupID + ":" + typeID); + } + + /**Check if the type is in the group + * + * @param typeID + * @return boolean + */ + public boolean isInGroup(String typeID) + { + return isInGroup(getGroup(), typeID); + } + + // Get a type in the group + + /**Get the type from the group + * + * @param groupID The ID of the group the type is originally from + * @param typeID The ID of the type + * @return Type + */ + public Type getType(String groupID, String typeID) throws InvalidKeyException + { + String typeString = groupID + ":" + typeID; + if (!TYPES.containsKey(typeString)) + throw new InvalidKeyException("Invalid key in getType (" + typeString + "is not in group" + getGroup() + ")"); + return TYPES.get(typeString); + } + + /**Get the type from the group + * + * @param typeID The ID of the type + * @return Type + */ + public Type getType(String typeID) throws InvalidKeyException + { + return getType(getGroup(), typeID); + } + + + // DO ALL TYPE CONVERSION USING TYPES. + + /** The group identifier. Given by the Base Group + * @return String + */ + public final String getGroup() + { + return baseType.getGroup(); + } + + /** The base group type + * @return Type + */ + public final Type getBase() { + return baseType; + } + + @Override + public final String toString() { + return this.getGroup(); + } +} diff --git a/src/main/java/net/cshift/transit/Transit.java b/src/main/java/net/cshift/transit/Transit.java deleted file mode 100644 index 71d3fea..0000000 --- a/src/main/java/net/cshift/transit/Transit.java +++ /dev/null @@ -1,17 +0,0 @@ -package net.cshift.transit; - -import net.fabricmc.api.ModInitializer; -import net.cshift.transit.type.group.SimpleGroups; - -/** - * @author Kyle Gunger - * @apiNote This is the main entry point for Transit. The api is mostly intended for use on server-side connections. - */ -public class Transit implements ModInitializer { - - @Override - public void onInitialize() { - SimpleGroups.init(); - } - -} diff --git a/src/main/java/net/cshift/transit/network/Channel.java b/src/main/java/net/cshift/transit/network/Channel.java deleted file mode 100644 index e5c64da..0000000 --- a/src/main/java/net/cshift/transit/network/Channel.java +++ /dev/null @@ -1,118 +0,0 @@ -package net.cshift.transit.network; - -import net.cshift.transit.network.packet.IStaticPacket; - -/** - * @author Kyle Gunger - * @apiNote A channel represents a connection between two nodes. It is able to send data in packets, and serves as a way to organize incoming traffic. - * @param The type of data the packets will be transfering - */ -public final class Channel { - private INode to; - private int id; - private String group; - - /** This constructor should be called by a node approving a connection. The approving node can give the connection an ID and group. - * Negative IDs indicate a terminated connection, so do not initialize the class with a negative ID. - * - * @param node The recieving node - * @param id The channel's id, as assigned by the recieving node. In most cases, this will match the pool ID as a way to match channels to pools. - * @param group - */ - public Channel(INode node, int id, String group) - { - to = node; - this.id = id; - this.group = group; - } - - - - // #################### - // # Channel specific # - // #################### - - /** The recieving INode - * - * @return - */ - public INode getReciever() - { - return to; - } - - /** The ID of the connection, assigned by the recieving INode - * - * @return - */ - public int getID() - { - return id; - } - - /** The group that the channel operates on - * - * @return - */ - public String getGroup() { - return group; - } - - /** Returns true if the connection has been terminated - * - * @return - */ - public boolean isTerminated() - { - return id < 0; - } - - - - // ################################ - // # Info from the recieving node # - // ################################ - - /** Pressure - * - * @apiNote This part of the api is not properly documented yet, and it's use is not reccommended for cross-mod communications. - * @return A Number representing the pressure from the channel (in base group units). - */ - public Number pressure() - { - return to.getPressure(this); - } - - /** Max transfer rate - * - * @return A Number representing the max transfer rate from the channel (in base group units per tick). - */ - public Number rate() - { - return to.getRate(this); - } - - - - // ################################ - // # Interact with the other node # - // ################################ - - /** Terminates the connection and relays the termination to the recieving node - */ - public void terminate() - { - id = -1; - to.onTerminate(this); - } - - /** Send a packet to the recieving node - * - * @param packet the packet to send - * @return The overflow data if the packet is only partially accepted. {@code null} otherwise. - */ - public IStaticPacket send(IStaticPacket packet) - { - return to.accept(packet, this); - } -} diff --git a/src/main/java/net/cshift/transit/network/INode.java b/src/main/java/net/cshift/transit/network/INode.java deleted file mode 100644 index 7cbb1cc..0000000 --- a/src/main/java/net/cshift/transit/network/INode.java +++ /dev/null @@ -1,70 +0,0 @@ -package net.cshift.transit.network; - -import net.cshift.transit.network.packet.*; - -/** - * @author Kyle Gunger - * @apiNote A node inside or outside a system. - */ -public interface INode -{ - /** Returns a pool manifest for the INode - * - */ - public PoolManifest getManifest(); - - /** Get the system managing the node or {@code null} if there isn't one - * - */ - public ISystem getSystem(); - - - - // ############### - // # Connections # - // ############### - - /** Call this function to establish a connection with a node. - * - * @param The type of connection being asked for - * @param poolID The ID of the pool the channel will interface with (see PoolManifest) - * @param asker The asking node - * @return A channel if the node accepts the request, {@code null} otherwise - */ - public Channel connect(int poolID, INode asker); - - /** Accept a packet from a channel (or not). - * - * @apiNote Do not call this function, use Channel.send(packet) instead. - * @param The type of the packet and channel - * @param packet The packet to be vetted - * @param channel The channel which the packet is coming through - * @return The overflow data if the packet is only partially accepted. {@code null} otherwise. - */ - public IStaticPacket accept(IStaticPacket packet, Channel channel); - - /** Pressure - * - * @apiNote Do not call this function, use Channel.pressure() instead. - * @param channel The channel asking for the pressure - * @return A Number representing the pressure from the channel (in base group units). - */ - public Number getPressure(Channel channel); - - /** Transfer rate - * - * @apiNote Do not call this function, use Channel.rate() instead. - * @param channel The channel asking for the transfer rate - * @return A Number representing the transfer rate from the channel (in base group units per tick). - */ - public Number getRate(Channel channel); - - /** Called when a channel is terminated - * - * @apiNote Do not call this function, use Channel.terminate() instead. - * @param The type of the channel - * @param channel The channel being terminated - */ - public void onTerminate(Channel channel); - -} diff --git a/src/main/java/net/cshift/transit/network/ISystem.java b/src/main/java/net/cshift/transit/network/ISystem.java deleted file mode 100644 index 8d41c1d..0000000 --- a/src/main/java/net/cshift/transit/network/ISystem.java +++ /dev/null @@ -1,15 +0,0 @@ -package net.cshift.transit.network; - - -/** - * @author Kyle Gunger - * @apiNote An ISystem represents a system of nodes which has been optimized for performance. A node can exist on its own, but an ISystem can't exist without a node. - */ -public interface ISystem -{ - /**The nodes stored by the system - * - * @return INode[] - */ - public INode[] getNodes(); -} diff --git a/src/main/java/net/cshift/transit/network/PoolManifest.java b/src/main/java/net/cshift/transit/network/PoolManifest.java deleted file mode 100644 index e23d47f..0000000 --- a/src/main/java/net/cshift/transit/network/PoolManifest.java +++ /dev/null @@ -1,40 +0,0 @@ -package net.cshift.transit.network; - -/** - * @author Kyle Gunger - * @apiNote A pool manifest represents a set of possible data/resource pools that another node can request a channel to. - */ -public abstract class PoolManifest { - - /** Represents the number of pools that the node has access to for the specified resource. - * @apiNote A "pool" in this context represents an independant network of resources. - * Pool zero should be the default group that simple nodes will attempt to connect to. - * @param group The TypeGroup that the pool belongs to - */ - public abstract int poolCount(String group); - - /** The ID of the pool. The INode will use this in a connection attempt with the other INode. - * - * @param group The TypeGroup the pool belongs to - * @param pool Array-like index for pool (gotten from poolCount) - */ - public abstract int poolID(String group, int pool); - - /** If the mod supports named pools, the names can be querried through this function. - * - * @param group The TypeGroup the pool belongs to - * @param pool Array-like index for pool (gotten from poolCount) - */ - public String poolName(String group, int pool) { - return ""; - } - - /** If the mod supports pool descriptions, they can be accessed by this method. - * - * @param group The TypeGroup the pool belongs to - * @param pool Array-like index for pool (gotten from poolCount) - */ - public String poolDescription(String group, int pool) { - return ""; - } -} diff --git a/src/main/java/net/cshift/transit/network/packet/DynamicPacket.java b/src/main/java/net/cshift/transit/network/packet/DynamicPacket.java deleted file mode 100644 index 60ad177..0000000 --- a/src/main/java/net/cshift/transit/network/packet/DynamicPacket.java +++ /dev/null @@ -1,43 +0,0 @@ -package net.cshift.transit.network.packet; - -import net.cshift.transit.type.Type; - -/** - * Simple packet which stores a fluid value. - * - * @author Kyle Gunger - * - * @param The data type (Object) that the packet transfers - */ -public class DynamicPacket implements IDynamicPacket { - private D data; - private Type type; - - /** Constructor. Stores the given data and uses the given type. - * - * @param dat The packet's data - * @param t The packet's type - */ - public DynamicPacket(D dat, Type t) - { - data = dat; - type = t; - } - - @Override - public D getData() - { - return data; - } - - @Override - public void setData(D dat) - { - data = dat; - } - - @Override - public Type getType() { - return type; - } -} diff --git a/src/main/java/net/cshift/transit/network/packet/IDynamicPacket.java b/src/main/java/net/cshift/transit/network/packet/IDynamicPacket.java deleted file mode 100644 index 8b7c330..0000000 --- a/src/main/java/net/cshift/transit/network/packet/IDynamicPacket.java +++ /dev/null @@ -1,14 +0,0 @@ -package net.cshift.transit.network.packet; - -/** Interface describing a fluid packet. - * @author Kyle Gunger - * - * @param The data type (Object) that the packet transfers - */ -public interface IDynamicPacket extends IStaticPacket{ - /**Set the packet's data. - * - * @return The packet's data - */ - public void setData(D dat); -} diff --git a/src/main/java/net/cshift/transit/network/packet/IStaticPacket.java b/src/main/java/net/cshift/transit/network/packet/IStaticPacket.java deleted file mode 100644 index bac8745..0000000 --- a/src/main/java/net/cshift/transit/network/packet/IStaticPacket.java +++ /dev/null @@ -1,23 +0,0 @@ -package net.cshift.transit.network.packet; - -import net.cshift.transit.type.*; - -/** Interface describing an unchanging packet. - * @author Kyle Gunger - * - * @param The data type (Object) that the packet transfers. - */ -public interface IStaticPacket -{ - /**Get the packet's data. - * - * @return The packet's data - */ - public D getData(); - - /**Get the packet's type. - * - * @return IType<> The type of the packet - */ - public Type getType(); -} diff --git a/src/main/java/net/cshift/transit/network/packet/MetaDynamicPacket.java b/src/main/java/net/cshift/transit/network/packet/MetaDynamicPacket.java deleted file mode 100644 index b87c2ed..0000000 --- a/src/main/java/net/cshift/transit/network/packet/MetaDynamicPacket.java +++ /dev/null @@ -1,44 +0,0 @@ -package net.cshift.transit.network.packet; - -import net.cshift.transit.type.Type; - -/** Static packet with extra data attached. - * @author Kyle Gunger - * - * @param The data type (Object) that the packet transfers - * @param The type of metadata -*/ -public class MetaDynamicPacket extends DynamicPacket -{ - private M metaData; - - /** Constructor - * - * @param dat The data to store - * @param t The Type of the data - * @param meta The metadata to store - */ - public MetaDynamicPacket(D dat, Type t, M meta) - { - super(dat, t); - metaData = meta; - } - - /** Get the metadata of the packet. - * - * @return The packet's metadata - */ - public M getMetaData() - { - return metaData; - } - - /** Set the metadata of the packet. - * - * @param meta The packet's new metadata - */ - public void setMetaData(M meta) - { - metaData = meta; - } -} diff --git a/src/main/java/net/cshift/transit/network/packet/MetaPacket.java b/src/main/java/net/cshift/transit/network/packet/MetaPacket.java deleted file mode 100644 index 99be83c..0000000 --- a/src/main/java/net/cshift/transit/network/packet/MetaPacket.java +++ /dev/null @@ -1,35 +0,0 @@ -package net.cshift.transit.network.packet; - -import net.cshift.transit.type.*; - -/** Static packet with extra data attached. - * @author Kyle Gunger - * - * @param The data type (Object) that the packet transfers - * @param The type of metadata -*/ -public class MetaPacket extends StaticPacket -{ - private M metaData; - - /** Constructor - * - * @param dat The data to store - * @param t The Type of the data - * @param meta The metadata to store - */ - public MetaPacket(D dat, Type t, M meta) - { - super(dat, t); - metaData = meta; - } - - /** Get the metadata of the packet. - * - * @return The packet's metadata - */ - public M getMetaData() - { - return metaData; - } -} diff --git a/src/main/java/net/cshift/transit/network/packet/StaticPacket.java b/src/main/java/net/cshift/transit/network/packet/StaticPacket.java deleted file mode 100644 index 7c95108..0000000 --- a/src/main/java/net/cshift/transit/network/packet/StaticPacket.java +++ /dev/null @@ -1,36 +0,0 @@ -package net.cshift.transit.network.packet; - -import net.cshift.transit.type.*; - -/** Simple packet which stores an unchanging value. - * @author Kyle Gunger - * - * @param The data type (Object) that the packet transfers. - */ -public class StaticPacket implements IStaticPacket -{ - private D data; - private Type type; - - /** Constructor. Stores the given data and uses the given type. - * - * @param dat The packet's data - * @param t The packet's type - */ - public StaticPacket(D dat, Type t) - { - data = dat; - type = t; - } - - @Override - public D getData() - { - return data; - } - - @Override - public Type getType() { - return type; - } -} diff --git a/src/main/java/net/cshift/transit/type/SimpleTypes.java b/src/main/java/net/cshift/transit/type/SimpleTypes.java deleted file mode 100644 index ee8dd01..0000000 --- a/src/main/java/net/cshift/transit/type/SimpleTypes.java +++ /dev/null @@ -1,19 +0,0 @@ -package net.cshift.transit.type; - -public final class SimpleTypes { - /** Transfers energy. Energy is stored as a numeric. - */ - public static final Type TransitJoule = new Type("TJoule", "ENERGY"); - - /** Transfers mana. TMana stores mana count and type. - */ - public static final Type TransitMana = new Type("TMana", "MANA"); - - /** Transfers items. TItem stores an item and an item count. - */ - public static final Type TransitItem = new Type("TItem", "ITEM"); - - /** Transfers fluid. TFluid stores fluid and mB. - */ - public static final Type TransitFluid = new Type("TFluid", "FLUID"); -} diff --git a/src/main/java/net/cshift/transit/type/TFluid.java b/src/main/java/net/cshift/transit/type/TFluid.java deleted file mode 100644 index 4b980bd..0000000 --- a/src/main/java/net/cshift/transit/type/TFluid.java +++ /dev/null @@ -1,34 +0,0 @@ -package net.cshift.transit.type; - -import net.minecraft.fluid.*; - -/** Units of fluid. - * @author Kyle Gunger - */ -public class TFluid { - private Fluid fluid; - private Number mb; - - /** Constructor. - * Since a bucket of fluid is the same as a block of a fluid, mb can be called millibuckets or milliblocks. - * - * @param f Fluid stored (Water/Lava/etc.) - * @param mB Count of fluid (mB) - */ - public TFluid(Fluid f, Number mB) { - fluid = f; - mb = mB; - } - - /** Get the fluid stored. - */ - public Fluid getFluid() { - return fluid; - } - - /** Get the millibuckets stored. - */ - public Number getMilliBuckets() { - return mb; - } -} diff --git a/src/main/java/net/cshift/transit/type/TItem.java b/src/main/java/net/cshift/transit/type/TItem.java deleted file mode 100644 index b3cc160..0000000 --- a/src/main/java/net/cshift/transit/type/TItem.java +++ /dev/null @@ -1,33 +0,0 @@ -package net.cshift.transit.type; - -import net.minecraft.item.*; - -/** Item storage - * @author Kyle Gunger - */ -public class TItem { - private Item item; - private Number count; - - /** Constructor. - * - * @param i Item stored - * @param c Item count - */ - public TItem(Item i, Number c) { - item = i; - count = c; - } - - /** Get the item stored. - */ - public Item getItem() { - return item; - } - - /** Get the item count. - */ - public Number getCount() { - return count; - } -} diff --git a/src/main/java/net/cshift/transit/type/TMana.java b/src/main/java/net/cshift/transit/type/TMana.java deleted file mode 100644 index 468b04f..0000000 --- a/src/main/java/net/cshift/transit/type/TMana.java +++ /dev/null @@ -1,31 +0,0 @@ -package net.cshift.transit.type; - -/** Units of mana. - * @author Kyle Gunger - */ -public class TMana { - private String type; - private Number count; - - /** Constructor - * - * @param t Type of mana (Fire/Water/Dark/Light/etc.) leave empty string for an untyped mana system. - * @param ct Count of mana - */ - public TMana(String t, Number ct) { - type = t; - count = ct; - } - - /** Get the mana type. - */ - public String getType() { - return type; - } - - /** Get the mana stored. - */ - public Number getCount() { - return count; - } -} diff --git a/src/main/java/net/cshift/transit/type/Type.java b/src/main/java/net/cshift/transit/type/Type.java deleted file mode 100644 index 9049135..0000000 --- a/src/main/java/net/cshift/transit/type/Type.java +++ /dev/null @@ -1,240 +0,0 @@ -package net.cshift.transit.type; - -import net.cshift.transit.network.packet.*; - -/**@author Kyle Gunger - * - * @param The type of object transfered by packets of this type - */ -public class Type -{ - protected final String typeID; - protected final String groupID; - - // Should not override, but you can if you must - public Type(String tID, String gID) - { - typeID = tID; - groupID = gID; - } - - - - // ########################################## - // # Converting from this type to base type # - // ########################################## - - /** Return the data formatted in the given group's base type. - * If creating a new type, override this function if required. - * - * @param data The data (of this type) - * @param group The group asking for the conversion - * @return The data in the group's base type - */ - public T toBase(T data, String group) - { - return data; - } - - /** Return the data formatted in the default group's base type. - * - * @param data The data (of this type) - * @return The data in the group's base type - */ - public final T toBase(T data) - { - return this.toBase(data, this.groupID); - } - - /** Return the packet's data formatted in the given group's base type. - * - * @param packet The packet (of this type) - * @param group The group asking for the conversion - * @return The packet's data in the group's base type - */ - public final T toBase(IStaticPacket packet, String group) - { - return this.toBase(packet.getData(), group); - } - - /** Return the packet's data formatted in the default group's base type. - * - * @param packet The packet (of this type) - * @return The packet's data in the group's base type - */ - public final T toBase(IStaticPacket packet) - { - return this.toBase(packet, this.groupID); - } - - - - // ########################################## - // # Converting from base type to this type # - // ########################################## - - /** Convert data from the given group's base type to this type. - * If creating a new type, override this function if required. - * - * @param data The base data - * @param group The group asking for the conversion - * @return The packet's data in the group's base type - */ - public T fromBase(T data, String group) - { - return data; - } - - /** Convert data from the default group's base type to this type. - * - * @param data The base data - * @return The packet's data in the group's base type - */ - public final T fromBase(T data) - { - return fromBase(data, this.groupID); - } - - /** Create a packet from data formatted in the given group's base type. - * - * @param data The base data - * @param group The group asking for the conversion - * @return The packet's data in the group's base type - */ - public final IStaticPacket packetFromBase(T data, String group) - { - return new StaticPacket(this.fromBase(data, group), this); - } - - /** Create a packet from data formatted in the default group's base type. - * - * @param data The base data - * @return The packet's data in the group's base type - */ - public final IStaticPacket packetFromBase(T data) - { - return packetFromBase(data, this.groupID); - } - - - - // ########################################### - // # Converting from other type to this type # - // ########################################### - - /** Convert data from another type to this type in the given group. - * If creating a new type, override this function if required. - * - * @param from The type to convert from - * @param group The group we are converting within - * @param data The data to convert - * @return The data formatted in this type - */ - public T convertFrom(Type from, T data, String group) { - return this.fromBase(from.toBase(data, group), group); - } - - /** Convert data from another type to this type in the default group. - * - * @param from The type to convert from - * @param data The data to convert - * @return The data formatted in this type - */ - public final T convertFrom(Type from, T data) { - return convertFrom(from, data, from.groupID); - } - - /** Convert a packet using another type to a packet using this type within the given group. - * - * @param packet The packet to convert - * @param group The group to convert within - * @return The new packet formatted in this type - */ - public final IStaticPacket convertFrom(IStaticPacket packet, String group) { - return new StaticPacket(convertFrom(packet.getType(), packet.getData(), group), this); - } - - /** Convert a packet using another type to a packet using this type within the default group. - * - * @param packet The packet to convert - * @return The new packet formatted in this type - */ - public final IStaticPacket convertFrom(IStaticPacket packet) { - return this.convertFrom(packet, packet.getType().groupID); - } - - - - // ########################################### - // # Converting from other type to this type # - // ########################################### - - /** Convert data from this type to another type in the given group. - * - * @param from The type to convert from - * @param group The group we are converting within - * @param data The data to convert - * @return The data formatted in this type - */ - public final T convertTo(Type to, T data, String group) { - return to.convertFrom(this, data, group); - } - - /** Convert data from this type to another type in the default group. - * - * @param from The type to convert from - * @param data The data to convert - * @return The data formatted in this type - */ - public final T convertTo(Type to, T data) { - return to.convertFrom(this, data, this.groupID); - } - - /** Convert a packet using this type to a packet using another type within the given group. - * - * @param packet The packet to convert - * @param group The group to convert within - * @return The new packet formatted in this type - */ - public final IStaticPacket convertTo(Type to, IStaticPacket packet, String group) { - return to.convertFrom(packet, group); - } - - /** Convert a packet using this type to a packet using another type within the default group. - * - * @param packet The packet to convert - * @return The new packet formatted in this type - */ - public final IStaticPacket convertTo(Type to, IStaticPacket packet) { - return to.convertFrom(packet, this.groupID); - } - - - - // ############################## - // # Utility and info functions # - // ############################## - - /** The type identifier. Gives the normal type identity of the type. - * - * @return String - */ - public final String getType() - { - return typeID; - } - - /** The group identifier. Gives the normal group identity of the type. - * - * @return String - */ - public final String getGroup() - { - return groupID; - } - - @Override - public final String toString() { - return groupID + ":" + typeID; - } -} diff --git a/src/main/java/net/cshift/transit/type/group/GroupRegistry.java b/src/main/java/net/cshift/transit/type/group/GroupRegistry.java deleted file mode 100644 index cfebb03..0000000 --- a/src/main/java/net/cshift/transit/type/group/GroupRegistry.java +++ /dev/null @@ -1,60 +0,0 @@ -package net.cshift.transit.type.group; - -import java.util.ArrayList; - -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; - -import net.cshift.transit.type.Type; - -public final class GroupRegistry { - private static final ArrayList> GROUPS = new ArrayList>(0); - - private static final Logger LOG = LogManager.getFormatterLogger("Transit|GroupRegistry"); - - private GroupRegistry() {} - - public static final boolean addGroup(TypeGroup group) - { - for(TypeGroup g : GROUPS) - { - if(g.getGroup().equals(group.getGroup())) - { - LOG.warn("Failed to add group " + group + " to the registry. Did another mod add a group with the same name?"); - return false; - } - } - - GROUPS.add(group); - LOG.info("Successfully added group " + group + " to the registry."); - return true; - } - - public static final TypeGroup groupByID(String groupID) - { - for(TypeGroup g : GROUPS) - { - if(g.getGroup().equals(groupID)){ - try{ - return (TypeGroup) g; - }catch(ClassCastException e) { - return null; - } - } - } - - return null; - - } - - public static final Type typeByIdentity(String groupID, String typeID) - { - TypeGroup group = GroupRegistry.groupByID(groupID); - - if(group != null) - return group.getType(typeID); - - return null; - } - -} diff --git a/src/main/java/net/cshift/transit/type/group/SimpleGroups.java b/src/main/java/net/cshift/transit/type/group/SimpleGroups.java deleted file mode 100644 index d68c5a5..0000000 --- a/src/main/java/net/cshift/transit/type/group/SimpleGroups.java +++ /dev/null @@ -1,29 +0,0 @@ -package net.cshift.transit.type.group; - -import net.cshift.transit.type.*; - -public final class SimpleGroups { - /** Transfers energy. Basic unit is TJoule (Transit Joule). - */ - public static final TypeGroup ENERGY = new TypeGroup(SimpleTypes.TransitJoule); - - /** Transfers mana. Basic unit is TMana (Transit Mana). - */ - public static final TypeGroup MANA = new TypeGroup(SimpleTypes.TransitMana); - - /** Transfers items. Basic unit is TItem. - */ - public static final TypeGroup ITEM = new TypeGroup(SimpleTypes.TransitItem); - - /** Transfers fluids. Basic unit is TFluid. - */ - public static final TypeGroup FLUID = new TypeGroup(SimpleTypes.TransitFluid); - - public static final void init() - { - GroupRegistry.addGroup(ENERGY); - GroupRegistry.addGroup(MANA); - GroupRegistry.addGroup(ITEM); - GroupRegistry.addGroup(FLUID); - } -} diff --git a/src/main/java/net/cshift/transit/type/group/TypeGroup.java b/src/main/java/net/cshift/transit/type/group/TypeGroup.java deleted file mode 100644 index 214f28c..0000000 --- a/src/main/java/net/cshift/transit/type/group/TypeGroup.java +++ /dev/null @@ -1,204 +0,0 @@ -package net.cshift.transit.type.group; - -import java.util.ArrayList; - -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; - -import net.cshift.transit.type.Type; - -/** - * @author Kyle Gunger - * @param The base object which all grouped Types should convert between. - */ -public final class TypeGroup -{ - // The base Type (provides the group's identifier) - private Type baseType; - - // The list of types. - private final ArrayList> TYPES = new ArrayList>(0); - - // Logger for events in the TypeGroup. - private static final Logger LOG = LogManager.getFormatterLogger("Transit|Group"); - - - public TypeGroup(Type base) - { - baseType = base; - addType(base); - } - - - // Type management - - /** Add a Type to the TypeGroup. - * The Type must have a group-type combo not already found in this TypeGroup. - * Returns {@code true} if the group was added. - * - * @param type The Type to add - * @return - */ - public boolean addType(Type type) - { - if(!isInGroup(type)) - { - TYPES.add(type); - LOG.info("Added type " + type + " to group " + getGroup()); - return true; - } - - LOG.info("Failed to add type " + type + " to group " + getGroup() + ". Was the type already added?"); - return false; - } - - /** Remove a Type from the TypeGroup. - * - * @param type The Type to remove - * @return - */ - public boolean removeType(Type type) - { - if(type.equals(baseType)) { - LOG.warn("[WARN] Failed to remove type " + type + " from group " + getGroup() + ". This is the base type and can not be removed."); - return false; - } - - if(TYPES.indexOf(type) != -1) - { - LOG.info("Removed type " + TYPES.remove(TYPES.indexOf(type)) + " from group " + getGroup()); - return true; - } - - LOG.warn("[WARN] Failed to remove type " + type + " from group " + getGroup() + ". Are we sure that the type was added to the group first?"); - return false; - } - - /** Remove a type from the group based on it's group-type identifier. - * - * @param type - * @return - */ - public boolean removeType(String groupID, String typeID) - { - if(baseType.toString() == groupID + ":" + typeID) { - LOG.warn("[WARN] Failed to remove type " + baseType + " from group " + getGroup() + ". This is the base type and can not be removed."); - return false; - } - - for(Type type : TYPES) - { - if(type.toString() == groupID + ":" + typeID) - { - LOG.info("Removed type " + TYPES.remove(TYPES.indexOf(type)) + " from group " + getGroup()); - return true; - } - } - - LOG.warn("[WARN] Failed to remove type " + groupID + ":" + typeID + " from group " + getGroup() + ". Are we sure that the type was added to the group first?"); - return false; - } - - /** Remove a type from the group based on it's group-type identifier. - * - * @param type - * @return - */ - public boolean removeType(String typeID) - { - return removeType(getGroup(), typeID); - } - - - // Check if a type is in the group - - /**Check if the type is in the group - * - * @param type - * @return boolean - */ - public boolean isInGroup(Type type) - { - for(Type t : TYPES) - { - if(t.equals(type)) return true; - } - return false; - } - - /**Check if the type is in the group - * - * @param groupID - * @param typeID - * @return boolean - */ - public boolean isInGroup(String groupID, String typeID) - { - for(Type t : TYPES) - { - if(t.toString() == groupID + ":" + typeID) return true; - } - return false; - } - - /**Check if the type is in the group - * - * @param typeID - * @return boolean - */ - public boolean isInGroup(String typeID) - { - return isInGroup(getGroup(), typeID); - } - - // Get a type in the group - - /**Get the type from the group - * - * @param groupID The ID of the group the type is originally from - * @param typeID The ID of the type - * @return Type - */ - public Type getType(String groupID, String typeID) - { - for(Type t : TYPES) - { - if(t.toString() == groupID + ":" + typeID) return t; - } - - return null; - } - - /**Get the type from the group - * - * @param typeID The ID of the type - * @return Type - */ - public Type getType(String typeID) - { - return getType(getGroup(), typeID); - } - - - // DO ALL TYPE CONVERSION USING TYPES. - - /** The group identifier. Given by the Base Group - * @return String - */ - public final String getGroup() - { - return baseType.getGroup(); - } - - /** The base group type - * @return Type - */ - public final Type getBase() { - return baseType; - } - - @Override - public final String toString() { - return this.getGroup(); - } -} diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index 9768c22..6f2fbd5 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -1,7 +1,7 @@ { "schemaVersion": 1, "id": "transit-api", - "version": "2.0.0", + "version": "3.0.0-alpha", "name": "Transit API", "description": "Move things about!", @@ -9,7 +9,7 @@ "CSKyle" ], "contact": { - "homepage": "https://cshift.net/", + "homepage": "https://cshift.net/TransitAPI", "sources": "https://github.com/CircleShift/TransitAPI", "issues": "https://github.com/CircleShift/TransitAPI/issues" }, @@ -20,12 +20,12 @@ "environment": "*", "entrypoints": { "main": [ - "net.cshift.transit.Transit" + "net.cshift.api.transit.Transit" ] }, "depends": { - "fabricloader": ">=0.7.4", - "minecraft": "1.17.x" + "fabricloader": ">=0.14.0", + "minecraft": "1.20.x" } } -- cgit v1.2.3