Browse Source

Fuck everything

master
Martmists 4 months ago
parent
commit
da68b01675
76 changed files with 1410 additions and 2428 deletions
  1. +31
    -39
      build.gradle
  2. +7
    -7
      gradle.properties
  3. BIN
     
  4. +1
    -1
      gradle/wrapper/gradle-wrapper.properties
  5. +0
    -172
      gradlew
  6. +0
    -84
      gradlew.bat
  7. +11
    -0
      settings.gradle
  8. +0
    -113
      src/main/java/com/martmists/ynet/YNetMod.java
  9. +0
    -34
      src/main/java/com/martmists/ynet/YNetModClient.java
  10. +0
    -5
      src/main/java/com/martmists/ynet/api/BaseProvider.java
  11. +0
    -34
      src/main/java/com/martmists/ynet/api/EnergyProvider.java
  12. +0
    -17
      src/main/java/com/martmists/ynet/api/FluidProvider.java
  13. +0
    -38
      src/main/java/com/martmists/ynet/api/ItemProvider.java
  14. +0
    -24
      src/main/java/com/martmists/ynet/blockentities/ConnectorBlockEntity.java
  15. +0
    -155
      src/main/java/com/martmists/ynet/blockentities/ControllerBlockEntity.java
  16. +0
    -81
      src/main/java/com/martmists/ynet/blocks/CableBlock.java
  17. +0
    -160
      src/main/java/com/martmists/ynet/blocks/ConnectorBlock.java
  18. +0
    -71
      src/main/java/com/martmists/ynet/blocks/ControllerBlock.java
  19. +0
    -28
      src/main/java/com/martmists/ynet/containers/ControllerContainer.java
  20. +0
    -11
      src/main/java/com/martmists/ynet/event/ProviderTickCallback.java
  21. +0
    -68
      src/main/java/com/martmists/ynet/event/impl/EnergyTickCallback.java
  22. +0
    -112
      src/main/java/com/martmists/ynet/event/impl/FluidTickCallback.java
  23. +0
    -103
      src/main/java/com/martmists/ynet/event/impl/ItemTickCallback.java
  24. +0
    -13
      src/main/java/com/martmists/ynet/mixin/accessors/InventoryStacksAccessor.java
  25. +0
    -63
      src/main/java/com/martmists/ynet/mixin/providers/energy/PowerAcceptorMixin.java
  26. +0
    -37
      src/main/java/com/martmists/ynet/mixin/providers/fluid/BlockMachineBaseMixin.java
  27. +0
    -68
      src/main/java/com/martmists/ynet/mixin/providers/item/AbstractFurnaceBlockMixin.java
  28. +0
    -80
      src/main/java/com/martmists/ynet/mixin/providers/item/BrewingStandBlockMixin.java
  29. +0
    -105
      src/main/java/com/martmists/ynet/mixin/providers/item/GenericMachineBlockMixin.java
  30. +0
    -91
      src/main/java/com/martmists/ynet/mixin/providers/item/LootableContainerBlockMixin.java
  31. +0
    -16
      src/main/java/com/martmists/ynet/network/Channel.java
  32. +0
    -70
      src/main/java/com/martmists/ynet/network/ConnectorConfiguration.java
  33. +0
    -162
      src/main/java/com/martmists/ynet/network/Network.java
  34. +0
    -46
      src/main/java/com/martmists/ynet/plugin/TRPlugin.java
  35. +0
    -262
      src/main/java/com/martmists/ynet/screens/ControllerScreen.java
  36. +0
    -20
      src/main/java/spinnery/widget/WCustomTooltipItem.java
  37. +70
    -0
      src/main/kotlin/com/martmists/ynet/YNetMod.kt
  38. +18
    -0
      src/main/kotlin/com/martmists/ynet/YNetModClient.kt
  39. +74
    -0
      src/main/kotlin/com/martmists/ynet/block/CableBlock.kt
  40. +109
    -0
      src/main/kotlin/com/martmists/ynet/block/ConnectorBlock.kt
  41. +72
    -0
      src/main/kotlin/com/martmists/ynet/block/ControllerBlock.kt
  42. +88
    -0
      src/main/kotlin/com/martmists/ynet/blockentity/ControllerBlockEntity.kt
  43. +9
    -0
      src/main/kotlin/com/martmists/ynet/ext/Collection.kt
  44. +10
    -0
      src/main/kotlin/com/martmists/ynet/network/Channel.kt
  45. +11
    -0
      src/main/kotlin/com/martmists/ynet/network/ConfiguredBlockEntity.kt
  46. +7
    -0
      src/main/kotlin/com/martmists/ynet/network/InteractionMode.kt
  47. +164
    -0
      src/main/kotlin/com/martmists/ynet/network/Network.kt
  48. +13
    -0
      src/main/kotlin/com/martmists/ynet/screen/ControllerConfigScreen.kt
  49. +290
    -0
      src/main/kotlin/com/martmists/ynet/screen/ControllerConfigScreenHandler.kt
  50. +13
    -0
      src/main/kotlin/com/martmists/ynet/transfer/data/ItemTransferData.kt
  51. +8
    -0
      src/main/kotlin/com/martmists/ynet/transfer/data/TransferData.kt
  52. +19
    -0
      src/main/kotlin/com/martmists/ynet/transfer/handler/ItemTransferHandler.kt
  53. +35
    -0
      src/main/kotlin/com/martmists/ynet/transfer/handler/TransferHandler.kt
  54. +48
    -0
      src/main/kotlin/com/martmists/ynet/transfer/proxy/ItemTransferProxy.kt
  55. +19
    -0
      src/main/kotlin/com/martmists/ynet/transfer/proxy/TransferProxy.kt
  56. +15
    -0
      src/main/kotlin/com/martmists/ynet/transfer/type/DisabledType.kt
  57. +22
    -0
      src/main/kotlin/com/martmists/ynet/transfer/type/ItemType.kt
  58. +15
    -0
      src/main/kotlin/com/martmists/ynet/transfer/type/Type.kt
  59. +66
    -0
      src/main/kotlin/com/martmists/ynet/util/ColoredButtonWidget.kt
  60. +101
    -0
      src/main/kotlin/com/martmists/ynet/util/WidgetBuilder.kt
  61. +37
    -0
      src/main/kotlin/com/martmists/ynet/util/YNetRegistry.kt
  62. +0
    -0
     
  63. +18
    -7
      src/main/resources/assets/ynet/lang/en_us.json
  64. +1
    -1
      src/main/resources/assets/ynet/models/block/controller.json
  65. BIN
     
  66. BIN
     
  67. BIN
     
  68. +0
    -0
     
  69. +0
    -0
     
  70. +0
    -0
     
  71. +0
    -0
     
  72. +0
    -0
     
  73. +0
    -0
     
  74. +8
    -4
      src/main/resources/fabric.mod.json
  75. +0
    -13
      src/main/resources/mod.mixins.json
  76. +0
    -13
      src/main/resources/tr.mod.mixins.json

+ 31
- 39
build.gradle View File

@@ -1,7 +1,4 @@
buildscript {
dependencies {
classpath "net.fabricmc:fabric-loom:0.2.7-SNAPSHOT"
}
repositories {
maven {
name = 'Fabric'
@@ -11,33 +8,54 @@ buildscript {
}
}

apply plugin: 'fabric-loom'
apply plugin: 'java'
apply plugin: 'idea'
plugins {
id 'java'
id 'fabric-loom' version "0.4.29"
id 'org.jetbrains.kotlin.jvm' version "1.4.0"
}

sourceCompatibility = 1.8
targetCompatibility = 1.8
archivesBaseName = "${project.mod_name}-${project.mod_version}-${project.minecraft_version}"
String root = "."
archivesBaseName = "${project.mod_name}-${project.mod_version}+${project.minecraft_version}"

dependencies {
minecraft "com.mojang:minecraft:${project.minecraft_version}"
mappings "net.fabricmc:yarn:${project.yarn_mappings}:v2"
modImplementation "net.fabricmc:fabric-loader:${project.loader_version}"

modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}"
modCompileOnly "TechReborn:${project.tr_slug}"
modImplementation "com.github.vini2003:spinnery:${project.spinnery_version}"
include "com.github.vini2003:spinnery:${project.spinnery_version}"
modImplementation "net.fabricmc:fabric-language-kotlin:$project.fabric_language_kotlin"

modApi ("alexiil.mc.lib:libblockattributes-fatjar_devonly:0.7.0") {
transitive = false
}
modImplementation ("com.github.vini2003:blade:${project.blade_version}")

include "alexiil.mc.lib:libblockattributes-all:0.7.0"
include "com.github.vini2003:blade:${project.blade_version}"

modRuntime "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}"
modRuntime "net.fabricmc:fabric-language-kotlin:$project.fabric_language_kotlin"
}

repositories {
mavenCentral()
jcenter()
maven {
name = "TechReborn"
url = "https://maven.fabricmc.net/"
}
maven {
name = "Spinnery"
url "https://dl.bintray.com/spinnery/Spinnery"
name = "Blade"
url "https://dl.bintray.com/blade/Blade"
}
maven {
name = "BuildCraft"
url = "https://mod-buildcraft.com/maven"
}
maven {
name = "Jitpack"
url "https://jitpack.io/"
}
}

@@ -54,18 +72,6 @@ processResources {
}
}

sourceSets {
main {
java {
srcDirs = ["${root}/src/main/java"]
exclude "**/compat/**/*.java"
}
resources {
srcDirs = ["${root}/src/main/resources"]
}
}
}

jar {
from "LICENSE"
}
@@ -75,19 +81,5 @@ task sourcesJar(type: Jar, dependsOn: classes) {
from sourceSets.main.allSource
}

task apiJar(type: Jar, dependsOn: classes) {
archiveClassifier.set("api")
from sourceSets.main.allSource.filter { it.path.contains("/api/") }
}

task deleteDev(type: Delete) {
delete "${root}/build/libs/${archivesBaseName}-dev.jar"
delete "${root}/build/libs/${archivesBaseName}-sources-dev.jar"
}

jar.dependsOn apiJar
jar.dependsOn sourcesJar
deleteDev.dependsOn remapJar
deleteDev.dependsOn remapSourcesJar
build.dependsOn jar
build.dependsOn deleteDev

+ 7
- 7
gradle.properties View File

@@ -1,11 +1,11 @@
# Done to increase the memory available to gradle.
org.gradle.jvmargs=-Xmx2G
mod_version=0.1.2
mod_version=1.0.0
mod_name=ynet

minecraft_version=1.15.2
yarn_mappings=1.15.2+build.14
loader_version=0.7.8+build.184
fabric_version=0.4.32+build.292-1.15
tr_slug=TechReborn-1.15:3.3.4+build.193
spinnery_version=2.0.19+fabric-1.15.2
minecraft_version=1.16.2
yarn_mappings=1.16.2+build.42
loader_version=0.9.2+build.206
fabric_version=0.19.0+build.398-1.16
fabric_language_kotlin=1.4.0+build.1
blade_version=d3dce1f

BIN
View File


+ 1
- 1
gradle/wrapper/gradle-wrapper.properties View File

@@ -1,5 +1,5 @@
#Tue Oct 15 13:15:02 CEST 2019
distributionUrl=https\://services.gradle.org/distributions/gradle-5.2.1-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-6.6.1-all.zip
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStorePath=wrapper/dists


+ 0
- 172
gradlew View File

@@ -1,172 +0,0 @@
#!/usr/bin/env sh

##############################################################################
##
## Gradle start up script for UN*X
##
##############################################################################

# Attempt to set APP_HOME
# Resolve links: $0 may be a link
PRG="$0"
# Need this for relative symlinks.
while [ -h "$PRG" ] ; do
ls=`ls -ld "$PRG"`
link=`expr "$ls" : '.*-> \(.*\)$'`
if expr "$link" : '/.*' > /dev/null; then
PRG="$link"
else
PRG=`dirname "$PRG"`"/$link"
fi
done
SAVED="`pwd`"
cd "`dirname \"$PRG\"`/" >/dev/null
APP_HOME="`pwd -P`"
cd "$SAVED" >/dev/null

APP_NAME="Gradle"
APP_BASE_NAME=`basename "$0"`

# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS='"-Xmx64m"'

# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD="maximum"

warn () {
echo "$*"
}

die () {
echo
echo "$*"
echo
exit 1
}

# OS specific support (must be 'true' or 'false').
cygwin=false
msys=false
darwin=false
nonstop=false
case "`uname`" in
CYGWIN* )
cygwin=true
;;
Darwin* )
darwin=true
;;
MINGW* )
msys=true
;;
NONSTOP* )
nonstop=true
;;
esac

CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar

# Determine the Java command to use to start the JVM.
if [ -n "$JAVA_HOME" ] ; then
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
# IBM's JDK on AIX uses strange locations for the executables
JAVACMD="$JAVA_HOME/jre/sh/java"
else
JAVACMD="$JAVA_HOME/bin/java"
fi
if [ ! -x "$JAVACMD" ] ; then
die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME

Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
else
JAVACMD="java"
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.

Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi

# Increase the maximum file descriptors if we can.
if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
MAX_FD_LIMIT=`ulimit -H -n`
if [ $? -eq 0 ] ; then
if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
MAX_FD="$MAX_FD_LIMIT"
fi
ulimit -n $MAX_FD
if [ $? -ne 0 ] ; then
warn "Could not set maximum file descriptor limit: $MAX_FD"
fi
else
warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
fi
fi

# For Darwin, add options to specify how the application appears in the dock
if $darwin; then
GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
fi

# For Cygwin, switch paths to Windows format before running java
if $cygwin ; then
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
JAVACMD=`cygpath --unix "$JAVACMD"`

# We build the pattern for arguments to be converted via cygpath
ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
SEP=""
for dir in $ROOTDIRSRAW ; do
ROOTDIRS="$ROOTDIRS$SEP$dir"
SEP="|"
done
OURCYGPATTERN="(^($ROOTDIRS))"
# Add a user-defined pattern to the cygpath arguments
if [ "$GRADLE_CYGPATTERN" != "" ] ; then
OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
fi
# Now convert the arguments - kludge to limit ourselves to /bin/sh
i=0
for arg in "$@" ; do
CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option

if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
else
eval `echo args$i`="\"$arg\""
fi
i=$((i+1))
done
case $i in
(0) set -- ;;
(1) set -- "$args0" ;;
(2) set -- "$args0" "$args1" ;;
(3) set -- "$args0" "$args1" "$args2" ;;
(4) set -- "$args0" "$args1" "$args2" "$args3" ;;
(5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
(6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
(7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
(8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
(9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
esac
fi

# Escape application args
save () {
for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
echo " "
}
APP_ARGS=$(save "$@")

# Collect all arguments for the java command, following the shell quoting and substitution rules
eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"

# by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
cd "$(dirname "$0")"
fi

exec "$JAVACMD" "$@"

+ 0
- 84
gradlew.bat View File

@@ -1,84 +0,0 @@
@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 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"
@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 init
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 init
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
:init
@rem Get command-line arguments, handling Windows variants
if not "%OS%" == "Windows_NT" goto win9xME_args
:win9xME_args
@rem Slurp the command line arguments.
set CMD_LINE_ARGS=
set _SKIP=2
:win9xME_args_slurp
if "x%~1" == "x" goto execute
set CMD_LINE_ARGS=%*
: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 %CMD_LINE_ARGS%
: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

+ 11
- 0
settings.gradle View File

@@ -1 +1,12 @@
pluginManagement {
repositories {
jcenter()
maven {
name = 'Fabric'
url = 'https://maven.fabricmc.net/'
}
gradlePluginPortal()
}
}

rootProject.name = 'ynet'

+ 0
- 113
src/main/java/com/martmists/ynet/YNetMod.java View File

@@ -1,113 +0,0 @@
package com.martmists.ynet;

import com.martmists.ynet.api.BaseProvider;
import com.martmists.ynet.api.EnergyProvider;
import com.martmists.ynet.api.FluidProvider;
import com.martmists.ynet.api.ItemProvider;
import com.martmists.ynet.blockentities.ConnectorBlockEntity;
import com.martmists.ynet.blockentities.ControllerBlockEntity;
import com.martmists.ynet.blocks.CableBlock;
import com.martmists.ynet.blocks.ConnectorBlock;
import com.martmists.ynet.blocks.ControllerBlock;
import com.martmists.ynet.containers.ControllerContainer;
import com.martmists.ynet.event.ProviderTickCallback;
import com.martmists.ynet.event.impl.EnergyTickCallback;
import com.martmists.ynet.event.impl.FluidTickCallback;
import com.martmists.ynet.event.impl.ItemTickCallback;
import net.fabricmc.api.ModInitializer;
import net.fabricmc.fabric.api.client.itemgroup.FabricItemGroupBuilder;
import net.fabricmc.fabric.api.container.ContainerProviderRegistry;
import net.fabricmc.fabric.api.network.ServerSidePacketRegistry;
import net.minecraft.block.Block;
import net.minecraft.block.Material;
import net.minecraft.block.entity.BlockEntityType;
import net.minecraft.item.BlockItem;
import net.minecraft.item.Item;
import net.minecraft.item.ItemGroup;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.util.Identifier;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.registry.Registry;

import java.util.HashMap;
import java.util.Map;

public class YNetMod implements ModInitializer {
public static Identifier CONTROLLER_UPDATE_S2C = new Identifier("ynet", "cus2c");
public static Identifier CONTROLLER_UPDATE_C2S = new Identifier("ynet", "cuc2s");

public static ItemGroup YNET_GROUP = FabricItemGroupBuilder.build(
new Identifier("ynet", "items"),
() -> new ItemStack(
Registry.ITEM.get(
new Identifier("ynet", "cable")
)
)
);

public static CableBlock CABLE = register("cable", new CableBlock(Block.Settings.of(Material.METAL)));
public static ConnectorBlock CONNECTOR = register("connector", new ConnectorBlock(Block.Settings.of(Material.METAL)));
public static ControllerBlock CONTROLLER = register("controller", new ControllerBlock(Block.Settings.of(Material.METAL)));

public static BlockEntityType<ConnectorBlockEntity> CONNECTOR_BE = Registry.register(
Registry.BLOCK_ENTITY_TYPE,
new Identifier("ynet", "connector"),
BlockEntityType.Builder.create(ConnectorBlockEntity::new, CONNECTOR).build(null)
);
public static BlockEntityType<ControllerBlockEntity> CONTROLLER_BE = Registry.register(
Registry.BLOCK_ENTITY_TYPE,
new Identifier("ynet", "controller"),
BlockEntityType.Builder.create(ControllerBlockEntity::new, CONTROLLER).build(null)
);

// Internal use
public static Map<Class<? extends BaseProvider>, ProviderTickCallback<? extends BaseProvider>> PROVIDERS = new HashMap<>();
public static Map<Class<? extends BaseProvider>, String> PROVIDER_NAMES = new HashMap<>();
public static Map<Class<? extends BaseProvider>, Integer> COLOR_MAP = new HashMap<>();

static <T extends Block> T register(String name, T block) {
return register(name, block, new BlockItem(block, new Item.Settings().group(YNET_GROUP)));
}

static <T extends Block> T register(String name, T block, BlockItem bl) {
T b = Registry.register(Registry.BLOCK, new Identifier("ynet", name), block);
register(name, bl);
return b;
}

static <T extends Item> T register(String name, T item) {
return Registry.register(Registry.ITEM, new Identifier("ynet", name), item);
}

static <T extends BaseProvider> ProviderTickCallback<T> register(String name, int color, Class<T> clazz, ProviderTickCallback<T> callback) {
PROVIDER_NAMES.put(clazz, name);
PROVIDERS.put(clazz, callback);
COLOR_MAP.put(clazz, color);
return callback;
}

@Override
public void onInitialize() {
System.out.println("YNet loading up!");
register("ynet:item", 0xff489030, ItemProvider.class, new ItemTickCallback());
register("ynet:fluid", 0xff0077be, FluidProvider.class, new FluidTickCallback());
register("ynet:energy", 0xfffffe00, EnergyProvider.class, new EnergyTickCallback());
// TODO:
// - Add support for configuring redstone signals on connectorss

ContainerProviderRegistry.INSTANCE.registerFactory(new Identifier("ynet:controller"), (syncId, id, player, buf) -> {
return new ControllerContainer(syncId, player.inventory, buf);
});

ServerSidePacketRegistry.INSTANCE.register(CONTROLLER_UPDATE_C2S, (packetContext, attachedData) -> {
BlockPos pos = attachedData.readBlockPos();
CompoundTag tag = attachedData.readCompoundTag();
packetContext.getTaskQueue().execute(() -> {
ControllerBlockEntity be = (ControllerBlockEntity) packetContext.getPlayer().world.getBlockEntity(pos);
be.fromTag(tag);
be.sMarkDirty();
});
});
}
}

+ 0
- 34
src/main/java/com/martmists/ynet/YNetModClient.java View File

@@ -1,34 +0,0 @@
package com.martmists.ynet;

import com.martmists.ynet.blockentities.ControllerBlockEntity;
import com.martmists.ynet.containers.ControllerContainer;
import com.martmists.ynet.screens.ControllerScreen;
import net.fabricmc.api.ClientModInitializer;
import net.fabricmc.fabric.api.client.screen.ScreenProviderRegistry;
import net.fabricmc.fabric.api.network.ClientSidePacketRegistry;
import net.minecraft.client.MinecraftClient;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.util.Identifier;
import net.minecraft.util.math.BlockPos;

public class YNetModClient implements ClientModInitializer {
@Override
public void onInitializeClient() {
ScreenProviderRegistry.INSTANCE.registerFactory(new Identifier("ynet:controller"), (c) -> {
return new ControllerScreen((ControllerContainer) c);
});
ClientSidePacketRegistry.INSTANCE.register(YNetMod.CONTROLLER_UPDATE_S2C, (packetContext, attachedData) -> {
BlockPos pos = attachedData.readBlockPos();
CompoundTag tag = attachedData.readCompoundTag();
packetContext.getTaskQueue().execute(() -> {
try {
ControllerBlockEntity be = (ControllerBlockEntity) MinecraftClient.getInstance().world.getBlockEntity(pos);
be.fromTag(tag);
be.sMarkDirty();
} catch (Exception ignored) {

}
});
});
}
}

+ 0
- 5
src/main/java/com/martmists/ynet/api/BaseProvider.java View File

@@ -1,5 +0,0 @@
package com.martmists.ynet.api;

// Base interface for implementation checks
public interface BaseProvider {
}

+ 0
- 34
src/main/java/com/martmists/ynet/api/EnergyProvider.java View File

@@ -1,34 +0,0 @@
package com.martmists.ynet.api;

import net.minecraft.util.math.BlockPos;
import net.minecraft.world.BlockView;

public interface EnergyProvider extends BaseProvider {
/**
* @param world The world the block resides in
* @param pos The BlockPos of the block
* @return The maximum energy this block can receive
*/
double getEnergyInputLimit(BlockView world, BlockPos pos);

/**
* @param world The world the block resides in
* @param pos The BlockPos of the block
* @param energy The amount of energy to be added to the machine
*/
void inputEnergy(BlockView world, BlockPos pos, double energy);

/**
* @param world The world the block resides in
* @param pos The BlockPos of the block
* @return The maximum energy this block can output
*/
double getEnergyOutputLimit(BlockView world, BlockPos pos);

/**
* @param world The world the block resides in
* @param pos The BlockPos of the block
* @param energy The amount of energy to be added to the machine
*/
void outputEnergy(BlockView world, BlockPos pos, double energy);
}

+ 0
- 17
src/main/java/com/martmists/ynet/api/FluidProvider.java View File

@@ -1,17 +0,0 @@
package com.martmists.ynet.api;

import net.minecraft.fluid.Fluid;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.BlockView;

public interface FluidProvider extends BaseProvider {
int getFluidOutputCount(BlockView world, BlockPos pos);

Fluid getFluidOutput(BlockView world, BlockPos pos);

int getFluidInputCount(BlockView world, BlockPos pos, Fluid fluid);

void outputFluid(BlockView world, BlockPos pos, Fluid fluid, int amount);

void inputFluid(BlockView world, BlockPos pos, Fluid fluid, int amount);
}

+ 0
- 38
src/main/java/com/martmists/ynet/api/ItemProvider.java View File

@@ -1,38 +0,0 @@
package com.martmists.ynet.api;

import net.minecraft.item.ItemStack;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.BlockView;

public interface ItemProvider extends BaseProvider {
/**
* @param world The world the block resides in
* @param pos The BlockPos of the block
* @param itemStack The ItemStack to attempt to input
* @return The amount of items from the stack that can be input
* Should at most be itemStack.getCount()
*/
int getItemInputCount(BlockView world, BlockPos pos, ItemStack itemStack);

/**
* @param world The world the block resides in
* @param pos The BlockPos of the block
* @param itemStack The ItemStack to add to the block
*/
void inputItem(BlockView world, BlockPos pos, ItemStack itemStack);

/**
* @param world The world the block resides in
* @param pos The BlockPos of the block
* @return The ItemStacks that can be output
*/
ItemStack[] getItemOutputStacks(BlockView world, BlockPos pos);

/**
* @param world The world the block resides in
* @param pos The BlockPos of the block
* @param itemStack the ItemStack to remove from the container
* May not be an exact existing stack, make sure to check the count
*/
void outputItem(BlockView world, BlockPos pos, ItemStack itemStack);
}

+ 0
- 24
src/main/java/com/martmists/ynet/blockentities/ConnectorBlockEntity.java View File

@@ -1,24 +0,0 @@
package com.martmists.ynet.blockentities;

import com.martmists.ynet.YNetMod;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.util.math.Direction;

import java.util.HashMap;
import java.util.Map;

public class ConnectorBlockEntity extends BlockEntity {
private Map<Direction, Integer> redstoneState = new HashMap<>();

public ConnectorBlockEntity() {
super(YNetMod.CONNECTOR_BE);
}

public void setRedstonePower(Direction d, int p) {
redstoneState.put(d, p);
}

public int getRedstonePower(Direction d) {
return redstoneState.getOrDefault(d, 0);
}
}

+ 0
- 155
src/main/java/com/martmists/ynet/blockentities/ControllerBlockEntity.java View File

@@ -1,155 +0,0 @@
package com.martmists.ynet.blockentities;

import com.martmists.ynet.YNetMod;
import com.martmists.ynet.api.BaseProvider;
import com.martmists.ynet.event.ProviderTickCallback;
import com.martmists.ynet.network.Channel;
import com.martmists.ynet.network.ConnectorConfiguration;
import com.martmists.ynet.network.Network;
import io.netty.buffer.Unpooled;
import net.fabricmc.fabric.api.network.ClientSidePacketRegistry;
import net.fabricmc.fabric.api.network.ServerSidePacketRegistry;
import net.fabricmc.fabric.api.util.NbtType;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.ListTag;
import net.minecraft.util.PacketByteBuf;
import net.minecraft.util.Tickable;
import net.minecraft.util.math.BlockPos;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;

public class ControllerBlockEntity extends BlockEntity implements Tickable {
public Network network;
public Channel[] channels = new Channel[9];
private int t;

public ControllerBlockEntity() {
super(YNetMod.CONTROLLER_BE);
this.network = new Network();
t = 0;
}

public void updateNetwork() {
network.reloadAllNodes(world);
}

private List<BlockPos> getConnectedProviders(Set<BlockPos> connectors) {
List<BlockPos> providers = new ArrayList<>();
for (BlockPos c : connectors) {
for (BlockPos offset : new BlockPos[]{c.up(), c.down(), c.north(), c.east(), c.south(), c.west()}) {
if (world.getBlockState(offset).getBlock() instanceof BaseProvider) {
providers.add(offset);
}
}
}
return providers;
}

@Override
public void tick() {
if (network.connectors == null) {
register();
}

t++;
if (t > 5) {
t = 0;
for (Channel ch : channels) {
if (ch != null && ch.providerType != null) {
ProviderTickCallback<?> callback = YNetMod.PROVIDERS.get(ch.providerType);
try {
callback.interact(ch.connectorSettings, this);
} catch (ClassCastException e) {
// Invalid world, log warning and reload nodes
e.printStackTrace();
ch.connectorSettings.removeIf(it -> !(world.getBlockState(it.providerPos).getBlock() instanceof BaseProvider));
}
}
}
}
}

@Override
public void fromTag(CompoundTag tag) {
super.fromTag(tag);
CompoundTag customData = tag.getCompound("controllerData");
for (String key : customData.getKeys()) {
int channelIndex = Integer.parseInt(key.substring(8));
channels[channelIndex] = new Channel();
CompoundTag cData = customData.getCompound(key);
String cType = cData.getString("type");
channels[channelIndex].providerType = YNetMod.PROVIDER_NAMES.entrySet().stream()
.filter(e -> e.getValue().equals(cType))
.map(Map.Entry::getKey)
.findFirst().orElse(null);

if (channels[channelIndex].providerType == null) {
channels[channelIndex] = null;
continue;
}

ListTag connectors = cData.getList("connectors", NbtType.COMPOUND);
channels[channelIndex].connectorSettings = connectors.stream().map(t -> {
ConnectorConfiguration config = new ConnectorConfiguration();
config.fromTag((CompoundTag) t);
return config;
}).collect(Collectors.toSet());
}
}

@Override
public CompoundTag toTag(CompoundTag tag) {
CompoundTag customData = new CompoundTag();
for (int i = 0; i < 9; i++) {
Channel c = channels[i];
if (c != null) {
CompoundTag cData = new CompoundTag();
ListTag connectors = new ListTag();
c.connectorSettings.forEach((s) -> {
s.toTag(connectors);
});
cData.put("connectors", connectors);
String cType = YNetMod.PROVIDER_NAMES.getOrDefault(c.providerType, "null");
cData.putString("type", cType);
customData.put("channel_" + i, cData);
}
}
tag.put("controllerData", customData);
return super.toTag(tag);
}

@Override
public void markDirty() {
PacketByteBuf buf = new PacketByteBuf(Unpooled.buffer());
buf.writeBlockPos(pos);
CompoundTag tag = new CompoundTag();
this.toTag(tag);
buf.writeCompoundTag(tag);

if (world.isClient()) {
// Send C2S
ClientSidePacketRegistry.INSTANCE.sendToServer(YNetMod.CONTROLLER_UPDATE_C2S, buf);
} else {
// Send S2C
for (PlayerEntity player : world.getPlayers()) {
ServerSidePacketRegistry.INSTANCE.sendToPlayer(player, YNetMod.CONTROLLER_UPDATE_S2C, buf);
}
}
super.markDirty();
}

public void sMarkDirty() {
super.markDirty();
}

public void register() {
network.setController(pos);
updateNetwork();
}
}

+ 0
- 81
src/main/java/com/martmists/ynet/blocks/CableBlock.java View File

@@ -1,81 +0,0 @@
package com.martmists.ynet.blocks;

import com.martmists.ynet.YNetMod;
import com.martmists.ynet.api.BaseProvider;
import com.martmists.ynet.network.Network;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.ConnectingBlock;
import net.minecraft.entity.LivingEntity;
import net.minecraft.item.ItemPlacementContext;
import net.minecraft.item.ItemStack;
import net.minecraft.state.StateManager;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
import net.minecraft.world.BlockView;
import net.minecraft.world.IWorld;
import net.minecraft.world.World;

public class CableBlock extends ConnectingBlock {
public CableBlock(Settings settings) {
super(0.1875F, settings);
setDefaultState(getStateManager().getDefaultState()
.with(NORTH, false)
.with(EAST, false)
.with(SOUTH, false)
.with(WEST, false)
.with(UP, false)
.with(DOWN, false)
);
}

@Override
protected void appendProperties(StateManager.Builder<Block, BlockState> builder) {
builder.add(NORTH, EAST, SOUTH, WEST, UP, DOWN);
}

@Override
public BlockState getPlacementState(ItemPlacementContext ctx) {
return this.withConnectionProperties(ctx.getWorld(), ctx.getBlockPos());
}

@Override
public BlockState getStateForNeighborUpdate(BlockState state, Direction facing, BlockState neighborState, IWorld world, BlockPos pos, BlockPos neighborPos) {
if (!state.canPlaceAt(world, pos)) {
world.getBlockTickScheduler().schedule(pos, this, 1);
return super.getStateForNeighborUpdate(state, facing, neighborState, world, pos, neighborPos);
} else {
Block block = neighborState.getBlock();
return state.with(FACING_PROPERTIES.get(facing), block == this || block == YNetMod.CONNECTOR || block instanceof BaseProvider);
}
}

@Override
public void onBroken(IWorld world, BlockPos pos, BlockState state) {
Network.removeCable(world, pos);
}

@Override
public void onPlaced(World world, BlockPos pos, BlockState state, LivingEntity placer, ItemStack itemStack) {
long tStart = System.nanoTime();
Network.addCable(world, pos);
long tEnd = System.nanoTime();
System.out.println(tEnd - tStart + "ns");
}

public BlockState withConnectionProperties(BlockView world, BlockPos pos) {
Block block = world.getBlockState(pos.down()).getBlock();
Block block2 = world.getBlockState(pos.up()).getBlock();
Block block3 = world.getBlockState(pos.north()).getBlock();
Block block4 = world.getBlockState(pos.east()).getBlock();
Block block5 = world.getBlockState(pos.south()).getBlock();
Block block6 = world.getBlockState(pos.west()).getBlock();
return this.getDefaultState()
.with(DOWN, block == this || block == YNetMod.CONNECTOR)
.with(UP, block2 == this || block2 == YNetMod.CONNECTOR)
.with(NORTH, block3 == this || block3 == YNetMod.CONNECTOR)
.with(EAST, block4 == this || block4 == YNetMod.CONNECTOR)
.with(SOUTH, block5 == this || block5 == YNetMod.CONNECTOR)
.with(WEST, block6 == this || block6 == YNetMod.CONNECTOR);
}
}

+ 0
- 160
src/main/java/com/martmists/ynet/blocks/ConnectorBlock.java View File

@@ -1,160 +0,0 @@
package com.martmists.ynet.blocks;

import com.martmists.ynet.YNetMod;
import com.martmists.ynet.api.BaseProvider;
import com.martmists.ynet.blockentities.ConnectorBlockEntity;
import com.martmists.ynet.blockentities.ControllerBlockEntity;
import com.martmists.ynet.network.Channel;
import com.martmists.ynet.network.Network;
import net.minecraft.block.Block;
import net.minecraft.block.BlockEntityProvider;
import net.minecraft.block.BlockState;
import net.minecraft.block.ConnectingBlock;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.entity.LivingEntity;
import net.minecraft.item.ItemPlacementContext;
import net.minecraft.item.ItemStack;
import net.minecraft.state.StateManager;
import net.minecraft.state.property.BooleanProperty;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
import net.minecraft.world.BlockView;
import net.minecraft.world.IWorld;
import net.minecraft.world.World;

import java.util.HashMap;
import java.util.Map;

public class ConnectorBlock extends ConnectingBlock implements BlockEntityProvider {
private static BooleanProperty NORTH_CABLE = BooleanProperty.of("north_cable");
private static BooleanProperty EAST_CABLE = BooleanProperty.of("east_cable");
private static BooleanProperty SOUTH_CABLE = BooleanProperty.of("south_cable");
private static BooleanProperty WEST_CABLE = BooleanProperty.of("west_cable");
private static BooleanProperty UP_CABLE = BooleanProperty.of("up_cable");
private static BooleanProperty DOWN_CABLE = BooleanProperty.of("down_cable");
private static Map<Direction, BooleanProperty> CABLE_FACING_PROPERTIES = new HashMap<>();

static {
CABLE_FACING_PROPERTIES.put(Direction.NORTH, NORTH_CABLE);
CABLE_FACING_PROPERTIES.put(Direction.EAST, EAST_CABLE);
CABLE_FACING_PROPERTIES.put(Direction.SOUTH, SOUTH_CABLE);
CABLE_FACING_PROPERTIES.put(Direction.WEST, WEST_CABLE);
CABLE_FACING_PROPERTIES.put(Direction.UP, UP_CABLE);
CABLE_FACING_PROPERTIES.put(Direction.DOWN, DOWN_CABLE);
}

public ConnectorBlock(Settings settings) {
super(0.1875F, settings);
setDefaultState(getStateManager().getDefaultState()
.with(NORTH, false)
.with(EAST, false)
.with(SOUTH, false)
.with(WEST, false)
.with(UP, false)
.with(DOWN, false)
.with(NORTH_CABLE, false)
.with(EAST_CABLE, false)
.with(SOUTH_CABLE, false)
.with(WEST_CABLE, false)
.with(UP_CABLE, false)
.with(DOWN_CABLE, false)
);
}

@Override
protected void appendProperties(StateManager.Builder<Block, BlockState> builder) {
builder.add(NORTH, EAST, SOUTH, WEST, UP, DOWN, NORTH_CABLE, EAST_CABLE, SOUTH_CABLE, WEST_CABLE, UP_CABLE, DOWN_CABLE);
}

@Override
public BlockState getPlacementState(ItemPlacementContext ctx) {
return this.withConnectionProperties(ctx.getWorld(), ctx.getBlockPos());
}

@Override
public BlockState getStateForNeighborUpdate(BlockState state, Direction facing, BlockState neighborState, IWorld world, BlockPos pos, BlockPos neighborPos) {
if (!state.canPlaceAt(world, pos)) {
world.getBlockTickScheduler().schedule(pos, this, 1);
return super.getStateForNeighborUpdate(state, facing, neighborState, world, pos, neighborPos);
} else {
Block block = neighborState.getBlock();
return state.with(FACING_PROPERTIES.get(facing), block == YNetMod.CONTROLLER || block instanceof BaseProvider)
.with(CABLE_FACING_PROPERTIES.get(facing), block == this || block == YNetMod.CABLE);
}
}

@Override
public void neighborUpdate(BlockState state, World world, BlockPos pos, Block block, BlockPos neighborPos, boolean moved) {
super.neighborUpdate(state, world, pos, block, neighborPos, moved);
if (!(block instanceof BaseProvider)) {
return;
}

for (Map.Entry<BlockPos, Network> e : Network.networks.entrySet()) {
if (e.getValue().connectors.contains(pos)) {
ControllerBlockEntity be = (ControllerBlockEntity)world.getBlockEntity(e.getKey());
for (Channel c : be.channels) {
if (c != null) {
c.connectorSettings.removeIf(s -> s == null || s.providerPos == neighborPos);
}
}
}
}
}

public BlockState withConnectionProperties(BlockView world, BlockPos pos) {
Block block = world.getBlockState(pos.down()).getBlock();
Block block2 = world.getBlockState(pos.up()).getBlock();
Block block3 = world.getBlockState(pos.north()).getBlock();
Block block4 = world.getBlockState(pos.east()).getBlock();
Block block5 = world.getBlockState(pos.south()).getBlock();
Block block6 = world.getBlockState(pos.west()).getBlock();
return this.getDefaultState()
.with(DOWN, block == YNetMod.CONTROLLER || block instanceof BaseProvider)
.with(UP, block2 == YNetMod.CONTROLLER || block2 instanceof BaseProvider)
.with(NORTH, block3 == YNetMod.CONTROLLER || block3 instanceof BaseProvider)
.with(EAST, block4 == YNetMod.CONTROLLER || block4 instanceof BaseProvider)
.with(SOUTH, block5 == YNetMod.CONTROLLER || block5 instanceof BaseProvider)
.with(WEST, block6 == YNetMod.CONTROLLER || block6 instanceof BaseProvider)
.with(DOWN_CABLE, block == this || block == YNetMod.CABLE)
.with(UP_CABLE, block2 == this || block2 == YNetMod.CABLE)
.with(NORTH_CABLE, block3 == this || block3 == YNetMod.CABLE)
.with(EAST_CABLE, block4 == this || block4 == YNetMod.CABLE)
.with(SOUTH_CABLE, block5 == this || block5 == YNetMod.CABLE)
.with(WEST_CABLE, block6 == this || block6 == YNetMod.CABLE);
}

@Override
public int getStrongRedstonePower(BlockState state, BlockView world, BlockPos pos, Direction facing) {
return state.getWeakRedstonePower(world, pos, facing);
}

@Override
public int getWeakRedstonePower(BlockState state, BlockView world, BlockPos pos, Direction facing) {
return ((ConnectorBlockEntity) world.getBlockEntity(pos)).getRedstonePower(facing);
}

public void setRedstoneOutput(Direction facing, BlockView world, BlockPos pos, int strength) {
((ConnectorBlockEntity) world.getBlockEntity(pos)).setRedstonePower(facing, strength);
}

@Override
public void onBroken(IWorld world, BlockPos pos, BlockState state) {
Network.removeConnector(world, pos);
}

@Override
public void onPlaced(World world, BlockPos pos, BlockState state, LivingEntity placer, ItemStack itemStack) {
Network.addConnector(world, pos);
}

public int getRedstoneOutput(Direction facing, BlockView world, BlockPos pos) {
BlockState state = world.getBlockState(pos.offset(facing));
return state.getBlock().getWeakRedstonePower(state, world, pos, facing);
}

@Override
public BlockEntity createBlockEntity(BlockView view) {
return new ConnectorBlockEntity();
}
}

+ 0
- 71
src/main/java/com/martmists/ynet/blocks/ControllerBlock.java View File

@@ -1,71 +0,0 @@
package com.martmists.ynet.blocks;

import com.martmists.ynet.YNetMod;
import com.martmists.ynet.blockentities.ControllerBlockEntity;
import com.martmists.ynet.network.Network;
import io.netty.buffer.Unpooled;
import net.fabricmc.fabric.api.container.ContainerProviderRegistry;
import net.fabricmc.fabric.api.network.ServerSidePacketRegistry;
import net.minecraft.block.*;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemPlacementContext;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.state.StateManager;
import net.minecraft.util.ActionResult;
import net.minecraft.util.Hand;
import net.minecraft.util.Identifier;
import net.minecraft.util.PacketByteBuf;
import net.minecraft.util.hit.BlockHitResult;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
import net.minecraft.world.BlockView;
import net.minecraft.world.IWorld;
import net.minecraft.world.World;

public class ControllerBlock extends FacingBlock implements BlockEntityProvider {
public ControllerBlock(Settings settings) {
super(settings);
setDefaultState(this.stateManager.getDefaultState().with(FACING, Direction.NORTH));
}

@Override
public BlockState getPlacementState(ItemPlacementContext ctx) {
return this.getDefaultState().with(FACING, ctx.getPlayerLookDirection());
}

@Override
public BlockEntity createBlockEntity(BlockView view) {
return new ControllerBlockEntity();
}

@Override
public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) {
if (!world.isClient) {

PacketByteBuf buf = new PacketByteBuf(Unpooled.buffer());
buf.writeBlockPos(pos);
CompoundTag tag = new CompoundTag();
world.getBlockEntity(pos).toTag(tag);
buf.writeCompoundTag(tag);
ServerSidePacketRegistry.INSTANCE.sendToPlayer(player, YNetMod.CONTROLLER_UPDATE_S2C, buf);

ContainerProviderRegistry.INSTANCE.openContainer(new Identifier("ynet:controller"), player, (buffer) -> {
buffer.writeBlockPos(pos);
});
}

return ActionResult.SUCCESS;
}

@Override
protected void appendProperties(StateManager.Builder<Block, BlockState> builder) {
builder.add(FACING);
}

@Override
public void onBreak(World world, BlockPos pos, BlockState state, PlayerEntity player) {
super.onBreak(world, pos, state, player);
Network.networks.remove(pos);
}
}

+ 0
- 28
src/main/java/com/martmists/ynet/containers/ControllerContainer.java View File

@@ -1,28 +0,0 @@
package com.martmists.ynet.containers;

import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.util.PacketByteBuf;
import spinnery.common.BaseContainer;
import spinnery.widget.WInterface;
import spinnery.widget.WSlot;
import spinnery.widget.api.Action;

public class ControllerContainer extends BaseContainer {
public PlayerInventory playerInv;
public PacketByteBuf packet;

public ControllerContainer(int synchronizationID, PlayerInventory linkedPlayerInventory, PacketByteBuf packet) {
super(synchronizationID, linkedPlayerInventory);
playerInv = linkedPlayerInventory;
this.packet = packet;

WInterface mainInterface = getInterface();
WSlot.addHeadlessPlayerInventory(mainInterface);
}

@Override
public void onSlotAction(int slotNumber, int inventoryNumber, int button, Action action, PlayerEntity player) {
super.onSlotAction(slotNumber, inventoryNumber, button, action, player);
}
}

+ 0
- 11
src/main/java/com/martmists/ynet/event/ProviderTickCallback.java View File

@@ -1,11 +0,0 @@
package com.martmists.ynet.event;

import com.martmists.ynet.api.BaseProvider;
import com.martmists.ynet.blockentities.ControllerBlockEntity;
import com.martmists.ynet.network.ConnectorConfiguration;

import java.util.Set;

public interface ProviderTickCallback<T extends BaseProvider> {
void interact(Set<ConnectorConfiguration> listeners, ControllerBlockEntity be);
}

+ 0
- 68
src/main/java/com/martmists/ynet/event/impl/EnergyTickCallback.java View File

@@ -1,68 +0,0 @@
package com.martmists.ynet.event.impl;

import com.martmists.ynet.api.EnergyProvider;
import com.martmists.ynet.blockentities.ControllerBlockEntity;
import com.martmists.ynet.event.ProviderTickCallback;
import com.martmists.ynet.network.ConnectorConfiguration;
import net.minecraft.world.World;

import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;

public class EnergyTickCallback implements ProviderTickCallback<EnergyProvider> {
@Override
public void interact(Set<ConnectorConfiguration> listeners, ControllerBlockEntity be) {
World world = be.getWorld();
List<ConnectorConfiguration> takeEnergy = listeners.stream()
.filter(config -> config.state == ConnectorConfiguration.State.INPUT)
.sorted((a, b) -> a.priority >= b.priority ? 0 : 1)
.collect(Collectors.toList());
List<ConnectorConfiguration> giveEnergy = listeners.stream()
.filter(config -> config.state == ConnectorConfiguration.State.OUTPUT)
.sorted((a, b) -> a.priority >= b.priority ? 0 : 1)
.collect(Collectors.toList());

double lastStored = 0.0;
double lastTaken = 0.0;

while (!takeEnergy.isEmpty() && !giveEnergy.isEmpty()) {

ConnectorConfiguration receiverConfig = takeEnergy.get(0);
ConnectorConfiguration providerConfig = giveEnergy.get(0);
EnergyProvider receiver = (EnergyProvider) world.getBlockState(receiverConfig.providerPos).getBlock();
EnergyProvider provider = (EnergyProvider) world.getBlockState(providerConfig.providerPos).getBlock();

if (lastStored >= receiver.getEnergyInputLimit(world, receiverConfig.providerPos)) {
lastStored = 0.0;
try {
receiverConfig = takeEnergy.get(1);
} catch (IndexOutOfBoundsException exc) {
break;
}
receiver = (EnergyProvider) world.getBlockState(receiverConfig.providerPos);
takeEnergy.remove(0);
}

if (lastTaken >= provider.getEnergyOutputLimit(world, providerConfig.providerPos)) {
lastTaken = 0.0;
try {
providerConfig = giveEnergy.get(1);
} catch (IndexOutOfBoundsException exc) {
break;
}
provider = (EnergyProvider) world.getBlockState(providerConfig.providerPos);
giveEnergy.remove(0);
}

double toTransfer = Math.min(
receiver.getEnergyInputLimit(world, receiverConfig.providerPos),
provider.getEnergyOutputLimit(world, providerConfig.providerPos));

provider.outputEnergy(world, providerConfig.providerPos, toTransfer);
receiver.inputEnergy(world, receiverConfig.providerPos, toTransfer);
lastStored += toTransfer;
lastTaken += toTransfer;
}
}
}

+ 0
- 112
src/main/java/com/martmists/ynet/event/impl/FluidTickCallback.java View File

@@ -1,112 +0,0 @@
package com.martmists.ynet.event.impl;

import com.martmists.ynet.api.FluidProvider;
import com.martmists.ynet.blockentities.ControllerBlockEntity;
import com.martmists.ynet.event.ProviderTickCallback;
import com.martmists.ynet.network.ConnectorConfiguration;
import net.minecraft.fluid.Fluid;
import net.minecraft.fluid.Fluids;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;

import java.util.*;
import java.util.stream.Collectors;

public class FluidTickCallback implements ProviderTickCallback<FluidProvider> {
@Override
public void interact(Set<ConnectorConfiguration> listeners, ControllerBlockEntity be) {
// Simple tuple class
class Entry {
private final BlockPos pos;
private final FluidProvider provider;
private final Fluid fluid;
private int amount;

Entry(BlockPos pos, FluidProvider provider, Fluid fluid, int amount) {
this.pos = pos;
this.provider = provider;
this.fluid = fluid;
this.amount = amount;
}
}

World world = be.getWorld();
List<ConnectorConfiguration> takeItems = listeners.stream()
.filter(config -> config.state == ConnectorConfiguration.State.INPUT)
.sorted((a, b) -> a.priority >= b.priority ? 0 : 1)
.collect(Collectors.toList());
List<Entry> entries = new ArrayList<>();
listeners.stream()
.filter(config -> config.state == ConnectorConfiguration.State.OUTPUT)
.sorted((a, b) -> a.priority >= b.priority ? 0 : 1)
.forEach(config -> {
FluidProvider p = (FluidProvider) world.getBlockState(config.providerPos).getBlock();
Fluid f = p.getFluidOutput(world, config.providerPos);
if (f != Fluids.EMPTY) {
entries.add(new Entry(config.providerPos, p, f, p.getFluidOutputCount(world, config.providerPos)));
}
});

if (entries.isEmpty()) {
return;
}

Entry e = entries.get(0);

Map<FluidProvider, Integer> fluidsStored = new HashMap<>();
Map<FluidProvider, Integer> fluidsRemoved = new HashMap<>();

while (!entries.isEmpty()) {
if (e.amount <= 0) {
try {
e = entries.get(1);
} catch (IndexOutOfBoundsException exc) {
break;
}
entries.remove(0);
}

fluidsRemoved.putIfAbsent(e.provider, 0);

if (fluidsRemoved.get(e.provider) >= 1000) {
e.amount = 0;
continue;
}

boolean found = false;
for (ConnectorConfiguration receiverConfig : takeItems) {
FluidProvider receiver = (FluidProvider) world.getBlockState(receiverConfig.providerPos).getBlock();
fluidsStored.putIfAbsent(receiver, 0);
int count = Math.min(
receiver.getFluidInputCount(world, receiverConfig.providerPos, e.fluid),
Math.min(
1000 - fluidsStored.get(receiver),
1000 - fluidsRemoved.get(e.provider)));

if (receiverConfig.filter != null) {
Entry fe = e;
// TODO
if (Arrays.stream(receiverConfig.filter).noneMatch((obj) -> obj.equals(fe.fluid))) {
continue;
}
}

if (count > 0) {
fluidsStored.put(receiver, fluidsStored.get(receiver) + count);
fluidsRemoved.put(e.provider, fluidsRemoved.get(e.provider) + count);
int finalCount = e.amount - count;
e.amount = count;
e.provider.outputFluid(world, e.pos, e.fluid, e.amount);
receiver.inputFluid(world, e.pos, e.fluid, e.amount);
e.amount = finalCount;
found = true;
}
}

if (!found) {
// Remove next
e.amount = 0;
}
}
}
}

+ 0
- 103
src/main/java/com/martmists/ynet/event/impl/ItemTickCallback.java View File

@@ -1,103 +0,0 @@
package com.martmists.ynet.event.impl;

import com.martmists.ynet.api.ItemProvider;
import com.martmists.ynet.blockentities.ControllerBlockEntity;
import com.martmists.ynet.event.ProviderTickCallback;
import com.martmists.ynet.network.ConnectorConfiguration;
import net.minecraft.item.ItemStack;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;

import java.util.*;
import java.util.stream.Collectors;

public class ItemTickCallback implements ProviderTickCallback<ItemProvider> {
@Override
public void interact(Set<ConnectorConfiguration> listeners, ControllerBlockEntity be) {
// Simple tuple class
class Entry {
private final BlockPos pos;
private final ItemProvider provider;
private final ItemStack items;

Entry(BlockPos pos, ItemProvider provider, ItemStack items) {
this.pos = pos;
this.provider = provider;
this.items = items;
}
}

World world = be.getWorld();
List<ConnectorConfiguration> takeItems = listeners.stream()
.filter(config -> config.state == ConnectorConfiguration.State.INPUT)
.sorted((a, b) -> a.priority >= b.priority ? 0 : 1)
.collect(Collectors.toList());
List<Entry> entries = new ArrayList<>();
listeners.stream()
.filter(config -> config.state == ConnectorConfiguration.State.OUTPUT)
.sorted((a, b) -> a.priority >= b.priority ? 0 : 1)
.forEach(config -> {
ItemProvider p = (ItemProvider) world.getBlockState(config.providerPos).getBlock();
for (ItemStack s : p.getItemOutputStacks(world, config.providerPos)) {
entries.add(new Entry(config.providerPos, p, new ItemStack(s.getItem(), s.getCount())));
}
});

if (entries.isEmpty()) {
return;
}

Entry e = entries.get(0);

Map<ItemProvider, Integer> itemsStored = new HashMap<>();
Map<ItemProvider, Integer> itemsRemoved = new HashMap<>();

boolean found = true;
while (!entries.isEmpty()) {
if (e.items.getCount() <= 0 || !found) {
try {
e = entries.get(1);
} catch (IndexOutOfBoundsException exc) {
break;
}
entries.remove(0);
}

found = false;

itemsRemoved.putIfAbsent(e.provider, 0);

if (itemsRemoved.get(e.provider) >= 64) {
continue;
}

for (ConnectorConfiguration receiverConfig : takeItems) {
ItemProvider receiver = (ItemProvider) world.getBlockState(receiverConfig.providerPos).getBlock();
itemsStored.putIfAbsent(receiver, 0);
int count = Math.min(
receiver.getItemInputCount(world, receiverConfig.providerPos, e.items),
Math.min(
64 - itemsStored.get(receiver),
64 - itemsRemoved.get(e.provider)));

if (receiverConfig.filter.length != 0) {
Entry fe = e;
if (Arrays.stream(receiverConfig.filter).noneMatch((obj) -> obj == fe.items.getItem())) {
continue;
}
}

if (count > 0) {
itemsStored.put(receiver, itemsStored.get(receiver) + count);
itemsRemoved.put(e.provider, itemsRemoved.get(e.provider) + count);
int finalCount = e.items.getCount() - count;
e.items.setCount(count);
receiver.inputItem(world, receiverConfig.providerPos, e.items);
e.provider.outputItem(world, e.pos, e.items);
e.items.setCount(finalCount);
found = true;
}
}
}
}
}

+ 0
- 13
src/main/java/com/martmists/ynet/mixin/accessors/InventoryStacksAccessor.java View File

@@ -1,13 +0,0 @@
package com.martmists.ynet.mixin.accessors;

import net.minecraft.block.entity.LootableContainerBlockEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.util.DefaultedList;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.gen.Invoker;

@Mixin(LootableContainerBlockEntity.class)
public interface InventoryStacksAccessor {
@Invoker("getInvStackList")
DefaultedList<ItemStack> callGetInvStackList();
}

+ 0
- 63
src/main/java/com/martmists/ynet/mixin/providers/energy/PowerAcceptorMixin.java View File

@@ -1,63 +0,0 @@
package com.martmists.ynet.mixin.providers.energy;

import com.martmists.ynet.api.EnergyProvider;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.BlockView;
import org.spongepowered.asm.mixin.Mixin;
import reborncore.common.powerSystem.PowerAcceptorBlockEntity;
import team.reborn.energy.EnergySide;
import techreborn.blocks.GenericMachineBlock;
import techreborn.blocks.generator.BlockSolarPanel;
import techreborn.blocks.generator.GenericGeneratorBlock;
import techreborn.blocks.storage.energy.EnergyStorageBlock;


@Mixin({GenericMachineBlock.class, GenericGeneratorBlock.class, EnergyStorageBlock.class, BlockSolarPanel.class})
public class PowerAcceptorMixin implements EnergyProvider {
@Override
public double getEnergyInputLimit(BlockView world, BlockPos pos) {
PowerAcceptorBlockEntity be = getBlockEntity(world, pos);
if (be == null) {
return 0;
}
return be.canAcceptEnergy(null) ?
Math.min(
be.getMaxStoredPower() - be.getStored(EnergySide.UNKNOWN),
be.getMaxInput(EnergySide.UNKNOWN)) :
0;
}

@Override
public void inputEnergy(BlockView world, BlockPos pos, double energy) {
PowerAcceptorBlockEntity be = getBlockEntity(world, pos);
be.setEnergy(be.getEnergy() + energy);
}

@Override
public double getEnergyOutputLimit(BlockView world, BlockPos pos) {
PowerAcceptorBlockEntity be = getBlockEntity(world, pos);
if (be == null) {
return 0;
}
return be.canProvideEnergy(null) ?
Math.min(
be.getStored(EnergySide.UNKNOWN),
be.getMaxOutput(EnergySide.UNKNOWN)) :
0;
}

@Override
public void outputEnergy(BlockView world, BlockPos pos, double energy) {
PowerAcceptorBlockEntity be = getBlockEntity(world, pos);
be.setEnergy(be.getEnergy() - energy);
}

private PowerAcceptorBlockEntity getBlockEntity(BlockView world, BlockPos pos) {
BlockEntity be = world.getBlockEntity(pos);
if (be instanceof PowerAcceptorBlockEntity) {
return (PowerAcceptorBlockEntity) be;
}
return null;
}
}

+ 0
- 37
src/main/java/com/martmists/ynet/mixin/providers/fluid/BlockMachineBaseMixin.java View File

@@ -1,37 +0,0 @@
package com.martmists.ynet.mixin.providers.fluid;

import com.martmists.ynet.api.FluidProvider;
import net.minecraft.fluid.Fluid;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.BlockView;
import org.spongepowered.asm.mixin.Mixin;
import reborncore.common.blocks.BlockMachineBase;

@Mixin(BlockMachineBase.class)
public class BlockMachineBaseMixin implements FluidProvider {

@Override
public int getFluidOutputCount(BlockView world, BlockPos pos) {
return 0;
}

@Override
public Fluid getFluidOutput(BlockView world, BlockPos pos) {
return null;
}

@Override
public int getFluidInputCount(BlockView world, BlockPos pos, Fluid fluid) {
return 0;
}

@Override
public void outputFluid(BlockView world, BlockPos pos, Fluid fluid, int amount) {

}

@Override
public void inputFluid(BlockView world, BlockPos pos, Fluid fluid, int amount) {

}
}

+ 0
- 68
src/main/java/com/martmists/ynet/mixin/providers/item/AbstractFurnaceBlockMixin.java View File

@@ -1,68 +0,0 @@
package com.martmists.ynet.mixin.providers.item;

import com.martmists.ynet.api.ItemProvider;
import net.minecraft.block.AbstractFurnaceBlock;
import net.minecraft.block.entity.AbstractFurnaceBlockEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.BlockView;
import org.spongepowered.asm.mixin.Mixin;

@Mixin(AbstractFurnaceBlock.class)
public abstract class AbstractFurnaceBlockMixin implements ItemProvider {
@Override
public int getItemInputCount(BlockView world, BlockPos pos, ItemStack itemStack) {
AbstractFurnaceBlockEntity be = getBlockEntity(world, pos);
ItemStack stack = be.getInvStack(AbstractFurnaceBlockEntity.canUseAsFuel(itemStack) ? 1 : 0);
// put in fuel slot
if (stack.isEmpty()) {
return itemStack.getCount();
} else {
if (stack.getItem() == itemStack.getItem()) {
return Math.min(stack.getMaxCount() - stack.getCount(), itemStack.getCount());
} else {
return 0;
}
}
}

@Override
public void inputItem(BlockView world, BlockPos pos, ItemStack itemStack) {
AbstractFurnaceBlockEntity be = getBlockEntity(world, pos);
if (AbstractFurnaceBlockEntity.canUseAsFuel(itemStack)) {
ItemStack stack = be.getInvStack(1);
if (stack.isEmpty()) {
be.setInvStack(1, new ItemStack(itemStack.getItem(), itemStack.getCount()));
} else {
stack.setCount(itemStack.getCount() + stack.getCount());
}
} else {
ItemStack stack = be.getInvStack(0);
if (stack.isEmpty()) {
be.setInvStack(0, new ItemStack(itemStack.getItem(), itemStack.getCount()));
} else {
stack.setCount(itemStack.getCount() + stack.getCount());
}
}
}

@Override
public ItemStack[] getItemOutputStacks(BlockView world, BlockPos pos) {
return new ItemStack[]{ getBlockEntity(world, pos).getInvStack(2) };
}

@Override
public void outputItem(BlockView world, BlockPos pos, ItemStack itemStack) {
AbstractFurnaceBlockEntity be = getBlockEntity(world, pos);
ItemStack stack = be.getInvStack(2);
if (itemStack.getCount() == stack.getCount()) {
be.setInvStack(2, ItemStack.EMPTY);
} else {
stack.setCount(stack.getCount() - itemStack.getCount());
}
}

private AbstractFurnaceBlockEntity getBlockEntity(BlockView world, BlockPos pos) {
return (AbstractFurnaceBlockEntity) world.getBlockEntity(pos);
}
}

+ 0
- 80
src/main/java/com/martmists/ynet/mixin/providers/item/BrewingStandBlockMixin.java View File

@@ -1,80 +0,0 @@
package com.martmists.ynet.mixin.providers.item;

import com.martmists.ynet.api.ItemProvider;
import net.minecraft.block.BrewingStandBlock;
import net.minecraft.block.entity.BrewingStandBlockEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.BlockView;
import org.spongepowered.asm.mixin.Mixin;

import java.util.ArrayList;
import java.util.List;

@Mixin(BrewingStandBlock.class)
public class BrewingStandBlockMixin implements ItemProvider {
// Potions: Slot 0-2
// Ingredient: Slot 3
// Blaze powder: Slot 4

@Override
public int getItemInputCount(BlockView world, BlockPos pos, ItemStack itemStack) {
BrewingStandBlockEntity be = getBlockEntity(world, pos);

int totalInsertable = 0;

for (int i = 0; i < 5; i++) {
if (be.canInsertInvStack(i, itemStack, null)) {
ItemStack stack = be.getInvStack(i);
totalInsertable += stack.getMaxCount() - stack.getCount();
}
}

return Math.min(totalInsertable, itemStack.getCount());
}

@Override
public void inputItem(BlockView world, BlockPos pos, ItemStack itemStack) {
BrewingStandBlockEntity be = getBlockEntity(world, pos);
int totalInserted = 0;
for (int i = 0; i < 5; i++) {
if (be.canInsertInvStack(i, itemStack, null)) {
ItemStack stack = be.getInvStack(i);
int insertible = Math.min(stack.getMaxCount() - stack.getCount(), itemStack.getCount() - totalInserted);
stack.setCount(stack.getCount() + insertible);
totalInserted += insertible;
}
}
}

@Override
public ItemStack[] getItemOutputStacks(BlockView world, BlockPos pos) {
BrewingStandBlockEntity be = getBlockEntity(world, pos);
List<ItemStack> stacks = new ArrayList<>();
for (int i = 0; i < 5; i++) {
ItemStack stack = be.getInvStack(i);
if (be.canExtractInvStack(i, stack, null)) {
stacks.add(stack);
}
}
return stacks.toArray(new ItemStack[0]);
}

@Override
public void outputItem(BlockView world, BlockPos pos, ItemStack itemStack) {
BrewingStandBlockEntity be = getBlockEntity(world, pos);
int totalExtracted = 0;
for (int i = 0; i < 5; i++) {
if (be.canExtractInvStack(i, itemStack, null)) {
ItemStack stack = be.getInvStack(i);
int extractable = Math.min(stack.getCount(), itemStack.getCount() - totalExtracted);
stack.setCount(stack.getCount() - extractable);
totalExtracted += extractable;
}
}
}

private BrewingStandBlockEntity getBlockEntity(BlockView world, BlockPos pos) {
return (BrewingStandBlockEntity) world.getBlockEntity(pos);
}
}

+ 0
- 105
src/main/java/com/martmists/ynet/mixin/providers/item/GenericMachineBlockMixin.java View File

@@ -1,105 +0,0 @@
package com.martmists.ynet.mixin.providers.item;

import com.martmists.ynet.api.ItemProvider;
import net.minecraft.item.ItemStack;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.BlockView;
import org.spongepowered.asm.mixin.Mixin;
import reborncore.common.util.DefaultedListCollector;
import techreborn.blockentity.machine.GenericMachineBlockEntity;
import techreborn.blocks.GenericMachineBlock;

import java.util.Arrays;
import java.util.List;

@Mixin(GenericMachineBlock.class)
public class GenericMachineBlockMixin implements ItemProvider {

@Override
public int getItemInputCount(BlockView world, BlockPos pos, ItemStack itemStack) {
GenericMachineBlockEntity be = getBlockEntity(world, pos);
if (hasInventory(be)) {
List<ItemStack> stacks = getInputStacks(be);
if (stacks.stream().anyMatch(ItemStack::isEmpty)) {
return itemStack.getCount();
}
int available = 0;
for (ItemStack stack : stacks) {
if (stack.getItem() == itemStack.getItem()) {
available += stack.getMaxCount() - stack.getCount();
}
}
return Math.min(available, itemStack.getCount());
}
return 0;
}

@Override
public void inputItem(BlockView world, BlockPos pos, ItemStack itemStack) {
List<ItemStack> stacks = getInputStacks(getBlockEntity(world, pos));
int inputCount = itemStack.getCount();
for (ItemStack stack : stacks) {
if (stack.getItem() == itemStack.getItem()) {
int available = stack.getMaxCount() - stack.getCount();
int inputting = Math.min(available, inputCount);
inputCount -= inputting;
stack.setCount(stack.getCount() + inputting);
}
if (inputCount <= 0) {
return;
}
}
if (inputCount > 0) {
int i = 0;
for (ItemStack stack : stacks) {
if (stack.isEmpty()) {
stacks.set(i, new ItemStack(itemStack.getItem(), inputCount));
return;
}
i++;
}
}
}

@Override
public ItemStack[] getItemOutputStacks(BlockView world, BlockPos pos) {
return getOutputStacks(getBlockEntity(world, pos)).stream().filter(stack -> !stack.isEmpty()).toArray(ItemStack[]::new);
}

@Override
public void outputItem(BlockView world, BlockPos pos, ItemStack itemStack) {
List<ItemStack> stacks = getOutputStacks(getBlockEntity(world, pos));
int outputCount = itemStack.getCount();
int i = 0;
for (ItemStack stack : stacks) {
if (stack.getItem() == itemStack.getItem()) {
int outputting = Math.min(outputCount, stack.getCount());
stack.setCount(stack.getCount() - outputting);
outputCount -= outputting;
if (stack.getCount() == 0) {
stacks.set(i, ItemStack.EMPTY);
}
if (outputCount <= 0) {
return;
}
}
i++;
}
}

private GenericMachineBlockEntity getBlockEntity(BlockView world, BlockPos pos) {
return (GenericMachineBlockEntity) world.getBlockEntity(pos);
}

private List<ItemStack> getInputStacks(GenericMachineBlockEntity be) {
return Arrays.stream(be.crafter.inputSlots).mapToObj(be::getInvStack).collect(DefaultedListCollector.toList());
}

private List<ItemStack> getOutputStacks(GenericMachineBlockEntity be) {
return Arrays.stream(be.crafter.outputSlots).mapToObj(be::getInvStack).collect(DefaultedListCollector.toList());
}

private boolean hasInventory(GenericMachineBlockEntity be) {
return be.getOptionalInventory().isPresent();
}
}

+ 0
- 91
src/main/java/com/martmists/ynet/mixin/providers/item/LootableContainerBlockMixin.java View File

@@ -1,91 +0,0 @@
package com.martmists.ynet.mixin.providers.item;

import com.martmists.ynet.api.ItemProvider;
import com.martmists.ynet.mixin.accessors.InventoryStacksAccessor;
import net.minecraft.block.*;
import net.minecraft.block.entity.LootableContainerBlockEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.BlockView;
import org.spongepowered.asm.mixin.Mixin;

import java.util.List;

@Mixin(value = {
ChestBlock.class, TrappedChestBlock.class,
ShulkerBoxBlock.class, DispenserBlock.class,
HopperBlock.class, BarrelBlock.class})
public abstract class LootableContainerBlockMixin implements ItemProvider {

@Override
public int getItemInputCount(BlockView world, BlockPos pos, ItemStack itemStack) {
List<ItemStack> stacks = ((InventoryStacksAccessor) getBlockEntity(world, pos)).callGetInvStackList();
if (stacks.stream().anyMatch(ItemStack::isEmpty)) {
return itemStack.getCount();
}
int available = 0;
for (ItemStack stack : stacks) {
if (stack.getItem() == itemStack.getItem()) {
available += stack.getMaxCount() - stack.getCount();
}
}
return Math.min(available, itemStack.getCount());
}

@Override
public void inputItem(BlockView world, BlockPos pos, ItemStack itemStack) {
List<ItemStack> stacks = ((InventoryStacksAccessor) getBlockEntity(world, pos)).callGetInvStackList();
int inputCount = itemStack.getCount();
for (ItemStack stack : stacks) {
if (stack.getItem() == itemStack.getItem()) {
int available = stack.getMaxCount() - stack.getCount();
int inputting = Math.min(available, inputCount);
inputCount -= inputting;
stack.setCount(stack.getCount() + inputting);
}
if (inputCount <= 0) {
return;
}
}
if (inputCount > 0) {
int i = 0;
for (ItemStack stack : stacks) {
if (stack.isEmpty()) {
stacks.set(i, new ItemStack(itemStack.getItem(), inputCount));
return;
}
i++;
}
}
}

@Override
public ItemStack[] getItemOutputStacks(BlockView world, BlockPos pos) {
return ((InventoryStacksAccessor) getBlockEntity(world, pos)).callGetInvStackList().stream().filter(stack -> !stack.isEmpty()).toArray(ItemStack[]::new);
}

@Override
public void outputItem(BlockView world, BlockPos pos, ItemStack itemStack) {
List<ItemStack> stacks = ((InventoryStacksAccessor) getBlockEntity(world, pos)).callGetInvStackList();
int outputCount = itemStack.getCount();
int i = 0;
for (ItemStack stack : stacks) {
if (stack.getItem() == itemStack.getItem()) {
int outputting = Math.min(outputCount, stack.getCount());
stack.setCount(stack.getCount() - outputting);
outputCount -= outputting;
if (stack.getCount() == 0) {
stacks.set(i, ItemStack.EMPTY);
}
if (outputCount <= 0) {
return;
}
}
i++;
}
}

private LootableContainerBlockEntity getBlockEntity(BlockView world, BlockPos pos) {
return (LootableContainerBlockEntity) world.getBlockEntity(pos);
}
}

+ 0
- 16
src/main/java/com/martmists/ynet/network/Channel.java View File

@@ -1,16 +0,0 @@
package com.martmists.ynet.network;

import com.martmists.ynet.api.BaseProvider;

import java.util.HashSet;
import java.util.Set;

public class Channel {
public Class<? extends BaseProvider> providerType;
public Set<ConnectorConfiguration> connectorSettings;

public Channel() {
providerType = BaseProvider.class;
connectorSettings = new HashSet<>();
}
}

+ 0
- 70
src/main/java/com/martmists/ynet/network/ConnectorConfiguration.java View File

@@ -1,70 +0,0 @@
package com.martmists.ynet.network;

import net.fabricmc.fabric.api.util.NbtType;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.ListTag;
import net.minecraft.util.math.BlockPos;

import java.util.Arrays;
</