Compare commits
30 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| f5202a4264 | |||
| cc9fedd63b | |||
| 324fea04a9 | |||
| 7acd083e79 | |||
| 9b61dba4c7 | |||
| 0382798a5d | |||
| 1e430ef506 | |||
| 5bd7c08f83 | |||
| 017b2ec590 | |||
| 382b394523 | |||
| 3f2a52fd0a | |||
| c5b3c883ca | |||
| b413592abf | |||
| cc1320d5c6 | |||
| da4351cff2 | |||
| 640e6f801a | |||
| bcfb406547 | |||
| b6f7bfc57b | |||
| e27b1698e4 | |||
| 216855d9c9 | |||
| e42e3adf84 | |||
| 66cbad38cb | |||
| 6640f95291 | |||
| 362bf15a19 | |||
| 2d64426496 | |||
| f5e0c1d426 | |||
| ec31e090b9 | |||
| 935b2225c9 | |||
| cdd0a594f3 | |||
| d3b25b595a |
@@ -1,5 +1,6 @@
|
||||
# User-specific stuff
|
||||
.idea/
|
||||
urlaub/
|
||||
|
||||
*.iml
|
||||
*.ipr
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2024
|
||||
Copyright (c) 2024 skippyall
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
Module ohne Instruction nicht bei Instruction Auswahl vorschlagen ✓
|
||||
Mob Spawning durch Instruction an/aus
|
||||
Referenz kopieren als Item, das beim linken verschwindet ✓
|
||||
zurück-Button (Jain)
|
||||
Instructions stoppen / einfrieren bei Entfernung des Moduls ✓
|
||||
Verbindung mit Minion anzeigen ✓
|
||||
Schlagen auf Entities fixen ✓
|
||||
Signaländerung bei Trigger nach Tod des Minions mit Minion synchronisieren ✓
|
||||
Menüführung für Argumente verbessern (Nö)
|
||||
direkt Wert zeigen ✓
|
||||
@@ -0,0 +1,35 @@
|
||||
- Module:
|
||||
- Bewegungsmodul ✓
|
||||
- Angriffsmodul ✓
|
||||
- Abbaumodul ✓
|
||||
- Platziermodul / Verwendungsmodul ✓
|
||||
- Werfmodul
|
||||
- Inventarmanagementmodul (Noch nicht wirklich)
|
||||
- Inventaropenmodul (Nä)
|
||||
|
||||
- Detektoren:
|
||||
- Blockdetektor
|
||||
- Entitydetektor
|
||||
- Dimensiondetektor
|
||||
- Positiondetektor
|
||||
- Inventardetektor
|
||||
|
||||
- Programmieren: Nö
|
||||
- Variablen Nö
|
||||
- (Listen) Nö
|
||||
- Warten Nö
|
||||
- Wiederholen Nö
|
||||
- Wiederhole bis/während Nö
|
||||
- Wiederhole x mal/(für jedes Element) Nö
|
||||
- Bedingung Nö
|
||||
|
||||
- VariableTypen:
|
||||
- Integer ✓
|
||||
- String ✓
|
||||
- Position (Nö)
|
||||
- Block (weisned)
|
||||
- BlockType
|
||||
- (NBT) Nö
|
||||
- (World) Nö
|
||||
- (Chunk) Nö
|
||||
- Inventory (weisned)
|
||||
+30
-16
@@ -1,21 +1,29 @@
|
||||
plugins {
|
||||
id 'fabric-loom' version '1.8-SNAPSHOT'
|
||||
id 'net.fabricmc.fabric-loom-remap' version '1.16-SNAPSHOT'
|
||||
id 'maven-publish'
|
||||
}
|
||||
|
||||
version = project.mod_version
|
||||
group = project.maven_group
|
||||
|
||||
loom {
|
||||
accessWidenerPath = file("src/main/resources/minions.accesswidener")
|
||||
}
|
||||
|
||||
base {
|
||||
archivesName = project.archives_base_name
|
||||
}
|
||||
|
||||
loom {
|
||||
accessWidenerPath = file("src/main/resources/minions.accesswidener")
|
||||
splitEnvironmentSourceSets()
|
||||
|
||||
mods {
|
||||
minions {
|
||||
sourceSet sourceSets.main
|
||||
sourceSet sourceSets.client
|
||||
}
|
||||
}
|
||||
|
||||
runs.forEach {
|
||||
it.vmArg("-XX:+AllowEnhancedClassRedefinition")
|
||||
}
|
||||
}
|
||||
|
||||
repositories {
|
||||
@@ -42,15 +50,21 @@ repositories {
|
||||
dependencies {
|
||||
// To change the versions see the gradle.properties file
|
||||
minecraft "com.mojang:minecraft:${project.minecraft_version}"
|
||||
mappings "net.fabricmc:yarn:${project.yarn_mappings}:v2"
|
||||
mappings loom.officialMojangMappings()
|
||||
modImplementation "net.fabricmc:fabric-loader:${project.loader_version}"
|
||||
|
||||
// Fabric API. This is technically optional, but you probably want it anyway.
|
||||
modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}"
|
||||
|
||||
modImplementation "eu.pb4:polymer-core:${project.polymer_version}"
|
||||
modImplementation "eu.pb4:polymer-virtual-entity:${project.polymer_version}"
|
||||
modImplementation "eu.pb4:polymer-resource-pack:${project.polymer_version}"
|
||||
modLocalRuntime "eu.pb4:polymer-autohost:${project.polymer_version}"
|
||||
modImplementation include("eu.pb4:sgui:${project.sgui_version}")
|
||||
modImplementation include("xyz.nucleoid:server-translations-api:${project.server_translations_version}")
|
||||
|
||||
implementation include("com.electronwill.night-config:toml:${project.night_config_version}")
|
||||
|
||||
modCompileOnly "maven.modrinth:universal-graves:${project.universal_graves_version}"
|
||||
}
|
||||
|
||||
@@ -92,14 +106,19 @@ java {
|
||||
|
||||
jar {
|
||||
from("LICENSE") {
|
||||
rename { "${it}_${project.archivesBaseName}"}
|
||||
rename { "${it}_${project.archives_base_name}"}
|
||||
}
|
||||
|
||||
from("src/main/resoures/assets/minions/lang") {
|
||||
include("*")
|
||||
into("data/minions/lang/")
|
||||
}
|
||||
}
|
||||
|
||||
// configure the maven publication
|
||||
publishing {
|
||||
publications {
|
||||
minions (MavenPublication) {
|
||||
maven (MavenPublication) {
|
||||
from components.java
|
||||
}
|
||||
}
|
||||
@@ -111,14 +130,9 @@ publishing {
|
||||
// The repositories here will be used for publishing your artifact, not for
|
||||
// retrieving dependencies.
|
||||
maven {
|
||||
def release = "https://maven.foxgalaxy.de/private-releases"
|
||||
def snapshot = "https://maven.foxgalaxy.de/private-snapshot"
|
||||
url = version.endsWith('SNAPSHOT') ? snapshot : release
|
||||
|
||||
credentials {
|
||||
username = "${maven_user}"
|
||||
password = "${maven_password}"
|
||||
}
|
||||
name = "foxgalaxy"
|
||||
url = "https://maven.foxgalaxy.de/private"
|
||||
credentials(PasswordCredentials)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+11
-9
@@ -3,21 +3,23 @@ org.gradle.jvmargs=-Xmx1G
|
||||
|
||||
# Fabric Properties
|
||||
# check these on https://modmuss50.me/fabric.html
|
||||
minecraft_version=1.21.3
|
||||
loader_version=0.16.13
|
||||
yarn_mappings=1.21.3+build.2
|
||||
minecraft_version=1.21.7
|
||||
loader_version=0.16.14
|
||||
yarn_mappings=1.21.7+build.2
|
||||
|
||||
# Mod Properties
|
||||
mod_version = 0.1.2-SNAPSHOT
|
||||
mod_version = 1.0.0-TEST-1
|
||||
maven_group = io.github.skippyall
|
||||
archives_base_name = Minions
|
||||
|
||||
# Dependencies
|
||||
# check this on https://modmuss50.me/fabric.html
|
||||
fabric_version=0.107.0+1.21.3
|
||||
fabric_version=0.128.1+1.21.7
|
||||
|
||||
polymer_version=0.10.0+1.21.2
|
||||
sgui_version=1.7.1+1.21.2
|
||||
server_translations_version=2.4.0+1.21.2-rc1
|
||||
polymer_version=0.13.3+1.21.6
|
||||
sgui_version=1.10.0+1.21.6
|
||||
server_translations_version=2.5.1+1.21.5
|
||||
|
||||
universal_graves_version=3.5.0+1.21.2
|
||||
night_config_version=3.8.3
|
||||
|
||||
universal_graves_version=3.8.0+1.21.6
|
||||
|
||||
Vendored
BIN
Binary file not shown.
+7
-1
@@ -1 +1,7 @@
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.10-bin.zip
|
||||
distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-9.4.1-bin.zip
|
||||
networkTimeout=10000
|
||||
validateDistributionUrl=true
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
zipStorePath=wrapper/dists
|
||||
|
||||
@@ -0,0 +1,248 @@
|
||||
#!/bin/sh
|
||||
|
||||
#
|
||||
# Copyright © 2015 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.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# https://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
#
|
||||
|
||||
##############################################################################
|
||||
#
|
||||
# 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/2d6327017519d23b96af35865dc997fcb544fb40/platforms/jvm/plugins-application/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
|
||||
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
|
||||
|
||||
# This is normally unused
|
||||
# shellcheck disable=SC2034
|
||||
APP_BASE_NAME=${0##*/}
|
||||
# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
|
||||
APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s\n' "$PWD" ) || exit
|
||||
|
||||
# Use the maximum available, or set MAX_FD != -1 to use that value.
|
||||
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 ;; #(
|
||||
MSYS* | MINGW* ) msys=true ;; #(
|
||||
NONSTOP* ) nonstop=true ;;
|
||||
esac
|
||||
|
||||
|
||||
|
||||
# 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
|
||||
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" && ! "$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=SC2039,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=SC2039,SC3045
|
||||
ulimit -n "$MAX_FD" ||
|
||||
warn "Could not set maximum file descriptor limit to $MAX_FD"
|
||||
esac
|
||||
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" || "$msys" ; then
|
||||
APP_HOME=$( cygpath --path --mixed "$APP_HOME" )
|
||||
|
||||
JAVACMD=$( cygpath --unix "$JAVACMD" )
|
||||
|
||||
# Now convert the arguments - kludge to limit ourselves to /bin/sh
|
||||
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
|
||||
# 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
|
||||
fi
|
||||
|
||||
|
||||
# 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 optsEnvironmentVar are not allowed to contain shell fragments,
|
||||
# and any embedded shellness will be escaped.
|
||||
# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be
|
||||
# treated as '${Hostname}' itself on the command line.
|
||||
|
||||
set -- \
|
||||
"-Dorg.gradle.appname=$APP_BASE_NAME" \
|
||||
-jar "$APP_HOME/gradle/wrapper/gradle-wrapper.jar" \
|
||||
"$@"
|
||||
|
||||
# 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" "$@"
|
||||
Vendored
+93
@@ -0,0 +1,93 @@
|
||||
@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
|
||||
@rem SPDX-License-Identifier: Apache-2.0
|
||||
@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. 1>&2
|
||||
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2
|
||||
echo. 1>&2
|
||||
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
|
||||
echo location of your Java installation. 1>&2
|
||||
|
||||
goto fail
|
||||
|
||||
:findJavaFromJavaHome
|
||||
set JAVA_HOME=%JAVA_HOME:"=%
|
||||
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
|
||||
|
||||
if exist "%JAVA_EXE%" goto execute
|
||||
|
||||
echo. 1>&2
|
||||
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2
|
||||
echo. 1>&2
|
||||
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
|
||||
echo location of your Java installation. 1>&2
|
||||
|
||||
goto fail
|
||||
|
||||
:execute
|
||||
@rem Setup the command line
|
||||
|
||||
|
||||
|
||||
@rem Execute Gradle
|
||||
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -jar "%APP_HOME%\gradle\wrapper\gradle-wrapper.jar" %*
|
||||
|
||||
: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
|
||||
@@ -0,0 +1,2 @@
|
||||
#!/bin/bash
|
||||
bash gradlew publish -PfoxgalaxyPassword=$(read -s -p "Enter Password: ")
|
||||
@@ -0,0 +1,17 @@
|
||||
package io.github.skippyall.minions.client;
|
||||
|
||||
import eu.pb4.polymer.networking.api.client.PolymerClientNetworking;
|
||||
import io.github.skippyall.minions.polymer.VersionSync;
|
||||
import io.github.skippyall.minions.registration.MinionBlocks;
|
||||
import net.fabricmc.api.ClientModInitializer;
|
||||
import net.fabricmc.fabric.api.client.rendering.v1.BlockRenderLayerMap;
|
||||
import net.minecraft.client.renderer.chunk.ChunkSectionLayer;
|
||||
|
||||
public class MinionsClient implements ClientModInitializer {
|
||||
@Override
|
||||
public void onInitializeClient() {
|
||||
BlockRenderLayerMap.putBlock(MinionBlocks.MINION_TRIGGER_BLOCK, ChunkSectionLayer.TRANSLUCENT);
|
||||
|
||||
PolymerClientNetworking.registerCommonHandler(VersionSync.VersionSyncPayload.class, (client, handler, payload) -> {});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
package io.github.skippyall.minions;
|
||||
|
||||
import net.fabricmc.loader.api.FabricLoader;
|
||||
import org.objectweb.asm.tree.ClassNode;
|
||||
import org.spongepowered.asm.mixin.extensibility.IMixinConfigPlugin;
|
||||
import org.spongepowered.asm.mixin.extensibility.IMixinInfo;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
public class MinionMixinConfigPlugin implements IMixinConfigPlugin {
|
||||
@Override
|
||||
public void onLoad(String mixinPackage) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getRefMapperConfig() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldApplyMixin(String targetClassName, String mixinClassName) {
|
||||
if(mixinClassName.startsWith("io.github.skippyall.minions.mixins.compat.universal_graves.")) {
|
||||
return MinionsConfig.get().compat.enableGravesCompat && FabricLoader.getInstance().isModLoaded("universal-graves");
|
||||
}
|
||||
if(mixinClassName.startsWith("io.github.skippyall.minions.mixins.antimobcap.")) {
|
||||
return MinionsConfig.get().minion.enableMobCapHacks;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void acceptTargets(Set<String> myTargets, Set<String> otherTargets) {}
|
||||
|
||||
@Override
|
||||
public List<String> getMixins() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void preApply(String targetClassName, ClassNode targetClass, String mixinClassName, IMixinInfo mixinInfo) {}
|
||||
|
||||
@Override
|
||||
public void postApply(String targetClassName, ClassNode targetClass, String mixinClassName, IMixinInfo mixinInfo) {}
|
||||
}
|
||||
@@ -1,70 +1,45 @@
|
||||
package io.github.skippyall.minions;
|
||||
|
||||
import eu.pb4.polymer.core.api.entity.PolymerEntityUtils;
|
||||
import eu.pb4.polymer.core.api.item.SimplePolymerItem;
|
||||
import io.github.skippyall.minions.minion.fakeplayer.MinionFakePlayer;
|
||||
import io.github.skippyall.minions.minion.MinionData;
|
||||
import io.github.skippyall.minions.minion.MinionItem;
|
||||
import eu.pb4.polymer.resourcepack.api.PolymerResourcePackUtils;
|
||||
import io.github.skippyall.minions.command.MinionsCommand;
|
||||
import io.github.skippyall.minions.docs.DocsManager;
|
||||
import io.github.skippyall.minions.minion.MinionPersistentState;
|
||||
import io.github.skippyall.minions.module.Modules;
|
||||
import io.github.skippyall.minions.minion.fakeplayer.MinionFakePlayer;
|
||||
import io.github.skippyall.minions.polymer.VersionSync;
|
||||
import io.github.skippyall.minions.registration.MinionRegistration;
|
||||
import net.fabricmc.api.ModInitializer;
|
||||
import net.fabricmc.fabric.api.command.v2.CommandRegistrationCallback;
|
||||
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerLifecycleEvents;
|
||||
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerTickEvents;
|
||||
import net.minecraft.component.DataComponentTypes;
|
||||
import net.minecraft.component.type.DamageResistantComponent;
|
||||
import net.minecraft.entity.boss.WitherEntity;
|
||||
import net.minecraft.entity.damage.DamageType;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.Items;
|
||||
import net.minecraft.registry.Registries;
|
||||
import net.minecraft.registry.Registry;
|
||||
import net.minecraft.registry.RegistryKey;
|
||||
import net.minecraft.registry.RegistryKeys;
|
||||
import net.minecraft.registry.tag.TagKey;
|
||||
import net.minecraft.server.world.ChunkTicketManager;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.fabricmc.fabric.api.resource.ResourceManagerHelper;
|
||||
import net.minecraft.server.packs.PackType;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.function.Function;
|
||||
|
||||
public class Minions implements ModInitializer {
|
||||
public static final String MOD_ID = "minions";
|
||||
public static final TagKey<DamageType> MINION_ITEM_RESISTS = TagKey.of(RegistryKeys.DAMAGE_TYPE, Identifier.of(MOD_ID, "minion_item_resists"));
|
||||
public static final MinionItem MINION_ITEM = registerItem(Identifier.of(MOD_ID, "minion"), settings -> new MinionItem(settings.component(DataComponentTypes.DAMAGE_RESISTANT, new DamageResistantComponent(MINION_ITEM_RESISTS))));
|
||||
public static final SimplePolymerItem BASIC_UPGRADE_BASE = registerItem(Identifier.of(MOD_ID, "basic_upgrade_base"), settings -> new SimplePolymerItem(settings, Items.NETHERITE_UPGRADE_SMITHING_TEMPLATE));
|
||||
public static final SimplePolymerItem ADVANCED_UPGRADE_BASE = registerItem(Identifier.of(MOD_ID, "advanced_upgrade_base"), settings -> new SimplePolymerItem(settings, Items.NETHERITE_UPGRADE_SMITHING_TEMPLATE));
|
||||
|
||||
public static final Logger LOGGER = LoggerFactory.getLogger(MOD_ID);
|
||||
|
||||
@Override
|
||||
public void onInitialize() {
|
||||
MinionData.register();
|
||||
PolymerEntityUtils.registerType();
|
||||
MinionsConfig.get();
|
||||
|
||||
MinionRegistration.register();
|
||||
|
||||
VersionSync.register();
|
||||
|
||||
ServerLifecycleEvents.SERVER_STARTED.register(server -> {
|
||||
MinionPersistentState.create(server);
|
||||
MinionPersistentState.INSTANCE.getMinionData().forEach((uuid, data) -> {
|
||||
MinionPersistentState.get(server).getMinionData().forEach((uuid, data) -> {
|
||||
if(data.isSpawned()) {
|
||||
MinionFakePlayer.spawnMinion(data, server.getOverworld(), null, null);
|
||||
MinionFakePlayer.spawnMinion(data, server.overworld(), null, null, true);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
CommandRegistrationCallback.EVENT.register((commandDispatcher, commandRegistryAccess, registrationEnvironment) -> {
|
||||
MobCapCommand.registerCommand(commandDispatcher);
|
||||
});
|
||||
CommandRegistrationCallback.EVENT.register(MinionsCommand::register);
|
||||
|
||||
Modules.register();
|
||||
}
|
||||
PolymerResourcePackUtils.addModAssets(Minions.MOD_ID);
|
||||
|
||||
private static <T extends Item> T registerItem(Identifier identifier, Function<Item.Settings, T> constructor, Item.Settings settings) {
|
||||
return Registry.register(Registries.ITEM, identifier, constructor.apply(settings.registryKey(RegistryKey.of(RegistryKeys.ITEM, identifier))));
|
||||
}
|
||||
|
||||
private static <T extends Item> T registerItem(Identifier identifier, Function<Item.Settings, T> constructor) {
|
||||
return registerItem(identifier, constructor, new Item.Settings());
|
||||
ResourceManagerHelper.get(PackType.SERVER_DATA).registerReloadListener(new DocsManager());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,86 @@
|
||||
package io.github.skippyall.minions;
|
||||
|
||||
import com.electronwill.nightconfig.core.CommentedConfig;
|
||||
import com.electronwill.nightconfig.core.io.ParsingException;
|
||||
import com.electronwill.nightconfig.core.io.WritingException;
|
||||
import com.electronwill.nightconfig.core.io.WritingMode;
|
||||
import com.electronwill.nightconfig.core.serde.ObjectDeserializer;
|
||||
import com.electronwill.nightconfig.core.serde.ObjectSerializer;
|
||||
import com.electronwill.nightconfig.core.serde.SerdeException;
|
||||
import com.electronwill.nightconfig.core.serde.annotations.SerdeComment;
|
||||
import com.electronwill.nightconfig.toml.TomlFormat;
|
||||
import com.electronwill.nightconfig.toml.TomlParser;
|
||||
import net.fabricmc.loader.api.FabricLoader;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
|
||||
public class MinionsConfig {
|
||||
private static MinionsConfig INSTANCE;
|
||||
|
||||
public Minion minion = new Minion();
|
||||
|
||||
public static class Minion {
|
||||
@SerdeComment("The prefix for all minion names")
|
||||
public String minionPrefix = "+";
|
||||
|
||||
@SerdeComment("Makes minions not raise the mob cap if they can't spawn mobs.")
|
||||
@SerdeComment("Might cause incompatibilities.")
|
||||
public boolean enableMobCapHacks = true;
|
||||
}
|
||||
|
||||
public Compat compat = new Compat();
|
||||
|
||||
public static class Compat {
|
||||
@SerdeComment("Enables compat with Universal Graves, which allows everyone to pick up graves from minions")
|
||||
public boolean enableGravesCompat = true;
|
||||
}
|
||||
|
||||
private static Path getPath() {
|
||||
Path minionsDir = FabricLoader.getInstance().getConfigDir().resolve("minions");
|
||||
if(!Files.isDirectory(minionsDir)) {
|
||||
try {
|
||||
Files.createDirectory(minionsDir);
|
||||
} catch (IOException e) {
|
||||
Minions.LOGGER.error("Could not create config dir", e);
|
||||
}
|
||||
}
|
||||
return minionsDir.resolve(Minions.MOD_ID + ".toml");
|
||||
}
|
||||
|
||||
public static MinionsConfig get() {
|
||||
if(INSTANCE == null) {
|
||||
loadConfig();
|
||||
}
|
||||
return INSTANCE;
|
||||
}
|
||||
|
||||
public static void loadConfig() {
|
||||
try {
|
||||
CommentedConfig defaultConfig = ObjectSerializer.standard().serializeFields(new MinionsConfig(), TomlFormat::newConfig);
|
||||
|
||||
CommentedConfig config = new TomlParser().parse(getPath(), (file, configFormat) -> {
|
||||
configFormat.createWriter().write(defaultConfig, file, WritingMode.REPLACE);
|
||||
return true;
|
||||
});
|
||||
|
||||
//Always use default values when entries are missing
|
||||
config.addAll(defaultConfig);
|
||||
INSTANCE = ObjectDeserializer.standard().deserializeFields(config, MinionsConfig::new);
|
||||
} catch (SerdeException | ParsingException | WritingException e) {
|
||||
Minions.LOGGER.error("Error while reading config", e);
|
||||
INSTANCE = new MinionsConfig();
|
||||
}
|
||||
}
|
||||
|
||||
/*public static void saveConfig() {
|
||||
try {
|
||||
CommentedConfig config = ObjectSerializer.standard().serializeFields(INSTANCE, TomlFormat::newConfig);
|
||||
new TomlWriter().write(config, getPath(), WritingMode.REPLACE);
|
||||
} catch (SerdeException | ParsingException | WritingException e) {
|
||||
System.out.println("[minions] Error while writing config");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}*/
|
||||
}
|
||||
@@ -1,27 +0,0 @@
|
||||
package io.github.skippyall.minions;
|
||||
|
||||
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerTickEvents;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class MinionsTickExecutor {
|
||||
private static final List<Runnable> executeOnNextTick = Collections.synchronizedList(new ArrayList<>());
|
||||
|
||||
public static void register() {
|
||||
ServerTickEvents.START_SERVER_TICK.register(server -> {
|
||||
synchronized (executeOnNextTick) {
|
||||
for (Runnable run:executeOnNextTick) {
|
||||
run.run();
|
||||
}
|
||||
executeOnNextTick.clear();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static void addExecuteOnNextTick(Runnable run) {
|
||||
executeOnNextTick.add(run);
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,24 +0,0 @@
|
||||
package io.github.skippyall.minions;
|
||||
|
||||
import com.mojang.brigadier.CommandDispatcher;
|
||||
import io.github.skippyall.minions.mixinhelper.ChunkTicketManager$DistanceFromNearestPlayerTrackerAccessor;
|
||||
import io.github.skippyall.minions.mixinhelper.ChunkTicketManagerAccessor;
|
||||
import io.github.skippyall.minions.mixins.antimobcap.ServerChunkManagerAccessor;
|
||||
import net.minecraft.server.command.ServerCommandSource;
|
||||
import net.minecraft.server.world.ChunkTicketManager;
|
||||
import net.minecraft.text.Text;
|
||||
|
||||
import static net.minecraft.server.command.CommandManager.literal;
|
||||
|
||||
public class MobCapCommand {
|
||||
public static void registerCommand(CommandDispatcher<ServerCommandSource> dispatcher) {
|
||||
dispatcher.register(literal("mobcapdebug")
|
||||
.executes(context -> {
|
||||
ChunkTicketManager ticketManager = ((ServerChunkManagerAccessor)context.getSource().getWorld().getChunkManager()).getTicketManager();
|
||||
int tickedChunkCount = ((ChunkTicketManager$DistanceFromNearestPlayerTrackerAccessor)((ChunkTicketManagerAccessor)ticketManager).getMinionless()).minions$getTickedChunkCount();
|
||||
context.getSource().sendFeedback(() -> Text.of(String.valueOf(tickedChunkCount)), false);
|
||||
return 0;
|
||||
})
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package io.github.skippyall.minions.block.input;
|
||||
|
||||
import io.github.skippyall.minions.clipboard.ClipboardItem;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.world.InteractionResult;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.phys.BlockHitResult;
|
||||
|
||||
public class AnalogInputBlock extends Block {
|
||||
public AnalogInputBlock(Properties settings) {
|
||||
super(settings);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected InteractionResult useWithoutItem(BlockState state, Level world, BlockPos pos, Player player, BlockHitResult hit) {
|
||||
if(!world.isClientSide) {
|
||||
player.getInventory().placeItemBackInInventory(ClipboardItem.createBlockPosReference(world, pos), true);
|
||||
}
|
||||
return InteractionResult.SUCCESS;
|
||||
}
|
||||
}
|
||||
+63
@@ -0,0 +1,63 @@
|
||||
package io.github.skippyall.minions.block.instruction_bound;
|
||||
|
||||
import io.github.skippyall.minions.block.miniontrigger.MinionTriggerBlockEntity;
|
||||
import io.github.skippyall.minions.clipboard.InstructionClipboard;
|
||||
import io.github.skippyall.minions.minion.MinionPersistentState;
|
||||
import io.github.skippyall.minions.registration.MinionBlocks;
|
||||
import io.github.skippyall.minions.registration.MinionComponentTypes;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.sounds.SoundEvents;
|
||||
import net.minecraft.sounds.SoundSource;
|
||||
import net.minecraft.world.InteractionHand;
|
||||
import net.minecraft.world.InteractionResult;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.block.EntityBlock;
|
||||
import net.minecraft.world.level.block.entity.BlockEntityType;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.phys.BlockHitResult;
|
||||
|
||||
public abstract class InstructionBoundBlock extends Block implements EntityBlock {
|
||||
public InstructionBoundBlock(Properties settings) {
|
||||
super(settings);
|
||||
}
|
||||
|
||||
protected abstract BlockEntityType<? extends InstructionBoundBlockEntity<?>> getBlockEntityType();
|
||||
|
||||
@Override
|
||||
protected InteractionResult useItemOn(ItemStack stack, BlockState state, Level world, BlockPos pos, Player player, InteractionHand hand, BlockHitResult hit) {
|
||||
if(stack.get(MinionComponentTypes.REFERENCE) instanceof InstructionClipboard instruction) {
|
||||
world.getBlockEntity(pos, getBlockEntityType()).ifPresent(be -> {
|
||||
be.setInstruction(instruction.selectedMinion(), instruction.selectedInstruction());
|
||||
player.playNotifySound(SoundEvents.NOTE_BLOCK_CHIME.value(), SoundSource.BLOCKS, 1, 1);
|
||||
stack.shrink(1);
|
||||
});
|
||||
return InteractionResult.SUCCESS;
|
||||
}
|
||||
|
||||
return super.useItemOn(stack, state, world, pos, player, hand, hit);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected InteractionResult useWithoutItem(BlockState state, Level world, BlockPos pos, Player player, BlockHitResult hit) {
|
||||
if(world.isClientSide()) {
|
||||
return InteractionResult.CONSUME;
|
||||
}
|
||||
|
||||
world.getBlockEntity(pos, getBlockEntityType()).ifPresent(be -> {
|
||||
String name = MinionPersistentState.get(world.getServer()).getMinionData(be.getMinionUuid()).name();
|
||||
player.displayClientMessage(Component.translatable("minions.reference.instruction.tooltip", name, be.getInstructionName()), true);
|
||||
});
|
||||
return InteractionResult.SUCCESS;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void affectNeighborsAfterRemoval(BlockState state, ServerLevel world, BlockPos pos, boolean moved) {
|
||||
super.affectNeighborsAfterRemoval(state, world, pos, moved);
|
||||
world.getBlockEntity(pos, MinionBlocks.MINION_TRIGGER_BE_TYPE).ifPresent(MinionTriggerBlockEntity::removeListener);
|
||||
}
|
||||
}
|
||||
+75
@@ -0,0 +1,75 @@
|
||||
package io.github.skippyall.minions.block.instruction_bound;
|
||||
|
||||
import io.github.skippyall.minions.listener.BlockEntityMinionListener;
|
||||
import io.github.skippyall.minions.minion.MinionRuntime;
|
||||
import io.github.skippyall.minions.minion.fakeplayer.MinionFakePlayer;
|
||||
import io.github.skippyall.minions.program.instruction.ConfiguredInstruction;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||
import net.minecraft.world.level.block.entity.BlockEntityType;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
|
||||
public abstract class InstructionBoundBlockEntity<L extends BlockEntityMinionListener<?>> extends BlockEntity {
|
||||
protected UUID minionUuid;
|
||||
protected String instructionName = "";
|
||||
|
||||
public InstructionBoundBlockEntity(BlockEntityType<?> type, BlockPos pos, BlockState state) {
|
||||
super(type, pos, state);
|
||||
}
|
||||
|
||||
protected abstract L createListener();
|
||||
|
||||
protected abstract Class<L> getListenerClass();
|
||||
|
||||
public void removeListener() {
|
||||
if(level instanceof ServerLevel serverWorld) {
|
||||
L listener = getListener();
|
||||
listener.remove(serverWorld.getServer());
|
||||
}
|
||||
}
|
||||
|
||||
public void addListener() {
|
||||
if(level instanceof ServerLevel serverWorld) {
|
||||
L listener = createListener();
|
||||
listener.add(serverWorld.getServer());
|
||||
}
|
||||
}
|
||||
|
||||
public void setInstruction(UUID minionUuid, String instructionName) {
|
||||
removeListener();
|
||||
this.minionUuid = minionUuid;
|
||||
this.instructionName = instructionName;
|
||||
addListener();
|
||||
setChanged();
|
||||
}
|
||||
|
||||
public Optional<MinionFakePlayer> getMinion() {
|
||||
if(minionUuid != null && level != null && level.getPlayerByUUID(minionUuid) instanceof MinionFakePlayer minion) {
|
||||
return Optional.of(minion);
|
||||
}
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
public UUID getMinionUuid() {
|
||||
return minionUuid;
|
||||
}
|
||||
|
||||
public String getInstructionName() {
|
||||
return instructionName;
|
||||
}
|
||||
|
||||
public Optional<ConfiguredInstruction<MinionRuntime>> getInstruction(MinionFakePlayer minion) {
|
||||
return Optional.ofNullable(minion.getInstructionManager().getInstruction(instructionName));
|
||||
}
|
||||
|
||||
public Optional<ConfiguredInstruction<MinionRuntime>> getInstruction() {
|
||||
return getMinion().flatMap(this::getInstruction);
|
||||
}
|
||||
|
||||
public L getListener() {
|
||||
return BlockEntityMinionListener.getListener(level, worldPosition, minionUuid, getListenerClass());
|
||||
}
|
||||
}
|
||||
+138
@@ -0,0 +1,138 @@
|
||||
package io.github.skippyall.minions.block.miniontrigger;
|
||||
|
||||
import com.mojang.serialization.MapCodec;
|
||||
import eu.pb4.polymer.core.api.block.PolymerBlock;
|
||||
import eu.pb4.polymer.core.api.utils.PolymerClientDecoded;
|
||||
import eu.pb4.polymer.core.api.utils.PolymerKeepModel;
|
||||
import eu.pb4.polymer.resourcepack.api.PolymerResourcePackUtils;
|
||||
import eu.pb4.polymer.virtualentity.api.BlockWithElementHolder;
|
||||
import eu.pb4.polymer.virtualentity.api.ElementHolder;
|
||||
import eu.pb4.polymer.virtualentity.api.elements.ItemDisplayElement;
|
||||
import io.github.skippyall.minions.Minions;
|
||||
import io.github.skippyall.minions.block.instruction_bound.InstructionBoundBlock;
|
||||
import io.github.skippyall.minions.polymer.VersionSync;
|
||||
import io.github.skippyall.minions.registration.MinionBlocks;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.core.component.DataComponents;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.server.network.ServerGamePacketListenerImpl;
|
||||
import net.minecraft.world.item.ItemDisplayContext;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.item.Items;
|
||||
import net.minecraft.world.level.BlockGetter;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.LevelReader;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.block.DiodeBlock;
|
||||
import net.minecraft.world.level.block.SupportType;
|
||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||
import net.minecraft.world.level.block.entity.BlockEntityType;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.level.block.state.StateDefinition;
|
||||
import net.minecraft.world.level.block.state.properties.BooleanProperty;
|
||||
import net.minecraft.world.level.redstone.Orientation;
|
||||
import net.minecraft.world.phys.shapes.CollisionContext;
|
||||
import net.minecraft.world.phys.shapes.VoxelShape;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import xyz.nucleoid.packettweaker.PacketContext;
|
||||
|
||||
public class MinionTriggerBlock extends InstructionBoundBlock implements PolymerBlock, PolymerKeepModel, PolymerClientDecoded, BlockWithElementHolder {
|
||||
public static final MapCodec<MinionTriggerBlock> CODEC = simpleCodec(MinionTriggerBlock::new);
|
||||
|
||||
public static final BooleanProperty POWERED = BooleanProperty.create("powered");
|
||||
public static final VoxelShape SHAPE = Block.column(16.0, 0.0, 2.0);
|
||||
|
||||
public MinionTriggerBlock(Properties settings) {
|
||||
super(settings);
|
||||
registerDefaultState(defaultBlockState().setValue(POWERED, false));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected VoxelShape getShape(BlockState state, BlockGetter world, BlockPos pos, CollisionContext context) {
|
||||
return SHAPE;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean canSurvive(BlockState state, LevelReader world, BlockPos pos) {
|
||||
BlockPos blockPos = pos.below();
|
||||
return this.canPlaceAbove(world, blockPos, world.getBlockState(blockPos));
|
||||
}
|
||||
|
||||
protected boolean canPlaceAbove(LevelReader world, BlockPos pos, BlockState state) {
|
||||
return state.isFaceSturdy(world, pos, Direction.UP, SupportType.RIGID);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> builder) {
|
||||
builder.add(POWERED);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void neighborChanged(BlockState state, Level world, BlockPos pos, Block sourceBlock, @Nullable Orientation wireOrientation, boolean notify) {
|
||||
if(!canSurvive(state, world, pos)) {
|
||||
dropResources(state, world, pos);
|
||||
world.removeBlock(pos, false);
|
||||
return;
|
||||
}
|
||||
|
||||
boolean newPower = world.hasNeighborSignal(pos);
|
||||
if(state.getValue(POWERED) != newPower) {
|
||||
world.setBlockAndUpdate(pos, state.setValue(POWERED, newPower));
|
||||
world.getBlockEntity(pos, MinionBlocks.MINION_TRIGGER_BE_TYPE).ifPresent(MinionTriggerBlockEntity::updatePower);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean hasAnalogOutputSignal(BlockState state) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getAnalogOutputSignal(BlockState state, Level world, BlockPos pos) {
|
||||
return world.getBlockEntity(pos, MinionBlocks.MINION_TRIGGER_BE_TYPE).map(MinionTriggerBlockEntity::getComparatorOutput).orElse(0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable BlockEntity newBlockEntity(BlockPos pos, BlockState state) {
|
||||
return new MinionTriggerBlockEntity(pos, state);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected BlockEntityType<MinionTriggerBlockEntity> getBlockEntityType() {
|
||||
return MinionBlocks.MINION_TRIGGER_BE_TYPE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockState getPolymerBlockState(BlockState state, PacketContext context) {
|
||||
return VersionSync.isOnClient(context) ? state : net.minecraft.world.level.block.Blocks.COMPARATOR.defaultBlockState().setValue(DiodeBlock.POWERED, state.getValue(POWERED));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handleMiningOnServer(ItemStack tool, BlockState state, BlockPos pos, ServerPlayer player) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable ElementHolder createElementHolder(ServerLevel world, BlockPos pos, BlockState initialBlockState) {
|
||||
ElementHolder holder = new ElementHolder() {
|
||||
@Override
|
||||
public boolean startWatching(ServerGamePacketListenerImpl player) {
|
||||
if(PolymerResourcePackUtils.hasMainPack(player) && !VersionSync.isOnClient(player)) {
|
||||
return super.startWatching(player);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
};
|
||||
ItemStack stack = new ItemStack(Items.BARRIER);
|
||||
stack.set(DataComponents.ITEM_MODEL, ResourceLocation.fromNamespaceAndPath(Minions.MOD_ID, "minion_trigger_no_plate_" + (initialBlockState.getValue(MinionTriggerBlock.POWERED) ? "active" : "inactive")));
|
||||
|
||||
ItemDisplayElement element = new ItemDisplayElement(stack);
|
||||
element.setItemDisplayContext(ItemDisplayContext.NONE);
|
||||
holder.addElement(element);
|
||||
return holder;
|
||||
}
|
||||
}
|
||||
+66
@@ -0,0 +1,66 @@
|
||||
package io.github.skippyall.minions.block.miniontrigger;
|
||||
|
||||
import io.github.skippyall.minions.block.instruction_bound.InstructionBoundBlockEntity;
|
||||
import io.github.skippyall.minions.registration.MinionBlocks;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.UUIDUtil;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.level.storage.ValueInput;
|
||||
import net.minecraft.world.level.storage.ValueOutput;
|
||||
|
||||
public class MinionTriggerBlockEntity extends InstructionBoundBlockEntity<MinionTriggerMinionListener> {
|
||||
public MinionTriggerBlockEntity(BlockPos pos, BlockState state) {
|
||||
super(MinionBlocks.MINION_TRIGGER_BE_TYPE, pos, state);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected MinionTriggerMinionListener createListener() {
|
||||
return new MinionTriggerMinionListener(level.dimension(), worldPosition, minionUuid, instructionName);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Class<MinionTriggerMinionListener> getListenerClass() {
|
||||
return MinionTriggerMinionListener.class;
|
||||
}
|
||||
|
||||
public void updatePower() {
|
||||
boolean powered = getBlockState().getValue(MinionTriggerBlock.POWERED);
|
||||
|
||||
MinionTriggerMinionListener listener = getListener();
|
||||
if(listener != null) {
|
||||
listener.incomingPowerCache = powered;
|
||||
}
|
||||
|
||||
getMinion().ifPresent(minion -> {
|
||||
getInstruction().ifPresent(instruction -> {
|
||||
if(powered) {
|
||||
instruction.run(minion.getInstructionManager());
|
||||
} else {
|
||||
instruction.stop(minion.getInstructionManager());
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
public int getComparatorOutput() {
|
||||
MinionTriggerMinionListener listener = getListener();
|
||||
if(listener != null && listener.runningCache) {
|
||||
return 15;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void loadAdditional(ValueInput view) {
|
||||
minionUuid = view.read("minionUuid", UUIDUtil.AUTHLIB_CODEC).orElse(null);
|
||||
instructionName = view.getStringOr("instructionName", "");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void saveAdditional(ValueOutput view) {
|
||||
if(minionUuid != null) {
|
||||
view.store("minionUuid", UUIDUtil.AUTHLIB_CODEC, minionUuid);
|
||||
}
|
||||
view.putString("instructionName", instructionName);
|
||||
}
|
||||
}
|
||||
+25
@@ -0,0 +1,25 @@
|
||||
package io.github.skippyall.minions.block.miniontrigger;
|
||||
|
||||
import eu.pb4.polymer.core.api.item.PolymerBlockItem;
|
||||
import eu.pb4.polymer.resourcepack.api.PolymerResourcePackUtils;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.world.item.Item;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import xyz.nucleoid.packettweaker.PacketContext;
|
||||
|
||||
public class MinionTriggerBlockItem extends PolymerBlockItem {
|
||||
public MinionTriggerBlockItem(Block block, Properties settings, Item polymerItem) {
|
||||
super(block, settings, polymerItem, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable ResourceLocation getPolymerItemModel(ItemStack stack, PacketContext context) {
|
||||
if(PolymerResourcePackUtils.hasMainPack(context)) {
|
||||
return super.getPolymerItemModel(stack, context);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
+113
@@ -0,0 +1,113 @@
|
||||
package io.github.skippyall.minions.block.miniontrigger;
|
||||
|
||||
import com.mojang.serialization.Codec;
|
||||
import com.mojang.serialization.codecs.RecordCodecBuilder;
|
||||
import io.github.skippyall.minions.Minions;
|
||||
import io.github.skippyall.minions.listener.BlockEntityMinionInstructionListener;
|
||||
import io.github.skippyall.minions.minion.MinionRuntime;
|
||||
import io.github.skippyall.minions.minion.fakeplayer.MinionFakePlayer;
|
||||
import io.github.skippyall.minions.program.instruction.ConfiguredInstruction;
|
||||
import io.github.skippyall.minions.program.instruction.ConfiguredInstructionListener;
|
||||
import io.github.skippyall.minions.registration.MinionBlocks;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.UUIDUtil;
|
||||
import net.minecraft.resources.ResourceKey;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.world.level.Level;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
|
||||
public class MinionTriggerMinionListener extends BlockEntityMinionInstructionListener<MinionTriggerBlockEntity> {
|
||||
public static final Codec<MinionTriggerMinionListener> CODEC = RecordCodecBuilder.create(instance ->
|
||||
instance.group(
|
||||
Level.RESOURCE_KEY_CODEC.fieldOf("world").forGetter(listener -> listener.worldKey),
|
||||
BlockPos.CODEC.fieldOf("pos").forGetter(listener -> listener.pos),
|
||||
UUIDUtil.AUTHLIB_CODEC.fieldOf("minionUuid").forGetter(listener -> listener.minionUuid),
|
||||
Codec.STRING.fieldOf("instructionName").forGetter(listener -> listener.instructionName)
|
||||
).apply(instance, MinionTriggerMinionListener::new));
|
||||
|
||||
String instructionName;
|
||||
final TriggerInstructionListener listener = new TriggerInstructionListener();
|
||||
|
||||
boolean runningCache;
|
||||
boolean incomingPowerCache;
|
||||
|
||||
MinionTriggerMinionListener(ResourceKey<Level> worldKey, BlockPos pos, UUID minionUuid, String instructionName) {
|
||||
super(worldKey, pos, minionUuid, MinionBlocks.MINION_TRIGGER_BE_TYPE);
|
||||
this.instructionName = Objects.requireNonNull(instructionName);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Map<String, ConfiguredInstructionListener> getInstructionListeners() {
|
||||
return Map.of(instructionName, listener);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMinionSpawn(MinionFakePlayer minion) {
|
||||
super.onMinionSpawn(minion);
|
||||
runningCache = minion.getInstructionManager().getInstruction(instructionName).isRunning();
|
||||
updateComparatorsIfLoaded(minion.getServer());
|
||||
|
||||
ConfiguredInstruction<MinionRuntime> instruction = minion.getInstructionManager().getInstruction(instructionName);
|
||||
if(instruction.isRunning() && !incomingPowerCache) {
|
||||
instruction.stop(minion.getInstructionManager());
|
||||
} else if (!instruction.isRunning() && incomingPowerCache) {
|
||||
instruction.run(minion.getInstructionManager());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMinionRemove(MinionFakePlayer minion) {
|
||||
super.onMinionRemove(minion);
|
||||
runningCache = false;
|
||||
updateComparatorsIfLoaded(minion.getServer());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onInstructionRename(MinionFakePlayer minion, ConfiguredInstruction<?> instruction, String oldName, String newName) {
|
||||
super.onInstructionRename(minion, instruction, oldName, newName);
|
||||
if(instructionName.equals(oldName)) {
|
||||
instructionName = newName;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void add(MinecraftServer server) {
|
||||
super.add(server);
|
||||
runningCache = minion.getInstructionManager().getInstruction(instructionName).isRunning();
|
||||
updateComparatorsIfLoaded(server);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<ResourceLocation> getCodecId() {
|
||||
return Optional.of(ResourceLocation.fromNamespaceAndPath(Minions.MOD_ID, "minion_trigger"));
|
||||
}
|
||||
|
||||
public void updateComparatorsIfLoaded(MinecraftServer server) {
|
||||
Level world = server.getLevel(worldKey);
|
||||
if(world.isLoaded(pos)) {
|
||||
world.updateNeighbourForOutputSignal(pos, MinionBlocks.MINION_TRIGGER_BLOCK);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isRunning() {
|
||||
return runningCache;
|
||||
}
|
||||
|
||||
public class TriggerInstructionListener implements ConfiguredInstructionListener {
|
||||
@Override
|
||||
public void onRun(ConfiguredInstruction<?> instruction) {
|
||||
runningCache = true;
|
||||
updateComparatorsIfLoaded(minion.getServer());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStop(ConfiguredInstruction<?> instruction) {
|
||||
runningCache = false;
|
||||
updateComparatorsIfLoaded(minion.getServer());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package io.github.skippyall.minions.clipboard;
|
||||
|
||||
import com.mojang.serialization.MapCodec;
|
||||
import com.mojang.serialization.codecs.RecordCodecBuilder;
|
||||
import java.util.function.Consumer;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.component.DataComponentGetter;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.resources.ResourceKey;
|
||||
import net.minecraft.world.item.Item;
|
||||
import net.minecraft.world.item.TooltipFlag;
|
||||
import net.minecraft.world.level.Level;
|
||||
|
||||
public record BlockPosClipboard(ResourceKey<Level> world, BlockPos pos) implements Clipboard {
|
||||
public static final MapCodec<BlockPosClipboard> CODEC = RecordCodecBuilder.mapCodec(instance ->
|
||||
instance.group(
|
||||
Level.RESOURCE_KEY_CODEC.fieldOf("world").forGetter(BlockPosClipboard::world),
|
||||
BlockPos.CODEC.fieldOf("pos").forGetter(BlockPosClipboard::pos)
|
||||
).apply(instance, BlockPosClipboard::new)
|
||||
);
|
||||
|
||||
|
||||
@Override
|
||||
public MapCodec<BlockPosClipboard> getCodec() {
|
||||
return CODEC;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addToTooltip(Item.TooltipContext context, Consumer<Component> textConsumer, TooltipFlag type, DataComponentGetter components) {
|
||||
textConsumer.accept(Component.translatable("minions.reference.block.tooltip", pos.toString()));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package io.github.skippyall.minions.clipboard;
|
||||
|
||||
import com.mojang.serialization.Codec;
|
||||
import com.mojang.serialization.MapCodec;
|
||||
import io.github.skippyall.minions.registration.MinionRegistries;
|
||||
import java.util.function.Function;
|
||||
import net.minecraft.world.item.component.TooltipProvider;
|
||||
|
||||
public interface Clipboard extends TooltipProvider {
|
||||
Codec<Clipboard> CODEC = MinionRegistries.CLIPBOARD_TYPES.byNameCodec().dispatch(Clipboard::getCodec, Function.identity());
|
||||
|
||||
MapCodec<? extends Clipboard> getCodec();
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
package io.github.skippyall.minions.clipboard;
|
||||
|
||||
import eu.pb4.polymer.core.api.item.PolymerItem;
|
||||
import io.github.skippyall.minions.minion.fakeplayer.MinionFakePlayer;
|
||||
import io.github.skippyall.minions.registration.MinionComponentTypes;
|
||||
import io.github.skippyall.minions.registration.MinionItems;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.component.DataComponents;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.world.item.Item;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.item.Items;
|
||||
import net.minecraft.world.item.TooltipFlag;
|
||||
import net.minecraft.world.level.Level;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import xyz.nucleoid.packettweaker.PacketContext;
|
||||
|
||||
public class ClipboardItem extends Item implements PolymerItem {
|
||||
public ClipboardItem(Properties settings) {
|
||||
super(settings);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Item getPolymerItem(ItemStack itemStack, PacketContext context) {
|
||||
return /*VersionSync.isOnClient(context) ? this : */Items.PAPER;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable ResourceLocation getPolymerItemModel(ItemStack stack, PacketContext context) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getPolymerItemStack(ItemStack itemStack, TooltipFlag tooltipType, PacketContext context) {
|
||||
ItemStack stack = PolymerItem.super.getPolymerItemStack(itemStack, tooltipType, context);
|
||||
stack.set(DataComponents.ENCHANTMENT_GLINT_OVERRIDE, true);
|
||||
return stack;
|
||||
}
|
||||
|
||||
public static ItemStack createInstructionReference(MinionFakePlayer minion, String instructionName) {
|
||||
ItemStack stack = new ItemStack(MinionItems.REFERENCE_ITEM);
|
||||
stack.set(MinionComponentTypes.REFERENCE, new InstructionClipboard(minion.getUUID(), instructionName, minion.getGameProfile().getName()));
|
||||
return stack;
|
||||
}
|
||||
|
||||
public static ItemStack createBlockPosReference(Level world, BlockPos pos) {
|
||||
ItemStack stack = new ItemStack(MinionItems.REFERENCE_ITEM);
|
||||
stack.set(MinionComponentTypes.REFERENCE, new BlockPosClipboard(world.dimension(), pos));
|
||||
return stack;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
package io.github.skippyall.minions.clipboard;
|
||||
|
||||
import com.mojang.serialization.Codec;
|
||||
import com.mojang.serialization.MapCodec;
|
||||
import com.mojang.serialization.codecs.RecordCodecBuilder;
|
||||
import java.util.UUID;
|
||||
import java.util.function.Consumer;
|
||||
import net.minecraft.core.UUIDUtil;
|
||||
import net.minecraft.core.component.DataComponentGetter;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.world.item.Item;
|
||||
import net.minecraft.world.item.TooltipFlag;
|
||||
|
||||
public record InstructionClipboard(UUID selectedMinion, String selectedInstruction, String visualMinionName) implements Clipboard {
|
||||
public static final MapCodec<InstructionClipboard> CODEC = RecordCodecBuilder.mapCodec(instance ->
|
||||
instance.group(
|
||||
UUIDUtil.AUTHLIB_CODEC.fieldOf("selectedMinion").forGetter(InstructionClipboard::selectedMinion),
|
||||
Codec.STRING.fieldOf("selectedInstruction").forGetter(InstructionClipboard::selectedInstruction),
|
||||
Codec.STRING.fieldOf("visualMinionName").forGetter(InstructionClipboard::visualMinionName)
|
||||
).apply(instance, InstructionClipboard::new));
|
||||
|
||||
@Override
|
||||
public MapCodec<? extends Clipboard> getCodec() {
|
||||
return CODEC;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addToTooltip(Item.TooltipContext context, Consumer<Component> textConsumer, TooltipFlag type, DataComponentGetter components) {
|
||||
textConsumer.accept(Component.translatable("minions.reference.instruction.tooltip", selectedInstruction, visualMinionName));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
package io.github.skippyall.minions.command;
|
||||
|
||||
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
||||
import com.mojang.brigadier.context.CommandContext;
|
||||
import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
||||
import com.mojang.brigadier.suggestion.Suggestions;
|
||||
import com.mojang.brigadier.suggestion.SuggestionsBuilder;
|
||||
import io.github.skippyall.minions.docs.DocsManager;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import net.minecraft.commands.CommandSourceStack;
|
||||
import net.minecraft.commands.arguments.ResourceLocationArgument;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
|
||||
import static net.minecraft.commands.Commands.argument;
|
||||
import static net.minecraft.commands.Commands.literal;
|
||||
|
||||
public class DocsSubcommand {
|
||||
public static final LiteralArgumentBuilder<CommandSourceStack> DOCS = literal("docs")
|
||||
.then(
|
||||
argument("docName", ResourceLocationArgument.id())
|
||||
.suggests(DocsSubcommand::getSuggestions)
|
||||
.executes(DocsSubcommand::execute)
|
||||
);
|
||||
|
||||
public static CompletableFuture<Suggestions> getSuggestions(CommandContext<CommandSourceStack> context, SuggestionsBuilder builder) {
|
||||
DocsManager.getDocsEntryIds().forEach(id -> builder.suggest(id.toString()));
|
||||
return CompletableFuture.completedFuture(builder.build());
|
||||
}
|
||||
|
||||
public static int execute(CommandContext<CommandSourceStack> context) throws CommandSyntaxException {
|
||||
ResourceLocation id = ResourceLocationArgument.getId(context, "docName");
|
||||
DocsManager.showDocsEntry(context.getSource().getPlayerOrException(), id);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package io.github.skippyall.minions.command;
|
||||
|
||||
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
||||
import com.mojang.brigadier.context.CommandContext;
|
||||
import io.github.skippyall.minions.minion.MinionData;
|
||||
import io.github.skippyall.minions.minion.MinionPersistentState;
|
||||
import java.util.Collection;
|
||||
import net.minecraft.commands.CommandSourceStack;
|
||||
import net.minecraft.network.chat.Component;
|
||||
|
||||
import static net.minecraft.commands.Commands.literal;
|
||||
|
||||
public class ListSubcommand {
|
||||
public static final LiteralArgumentBuilder<CommandSourceStack> LIST = literal("list")
|
||||
.executes(ListSubcommand::list);
|
||||
|
||||
public static int list(CommandContext<CommandSourceStack> context) {
|
||||
Collection<MinionData> minions = MinionPersistentState.get(context.getSource().getServer()).getMinionData().values();
|
||||
for (MinionData minion : minions) {
|
||||
context.getSource().sendSuccess(() -> Component.literal(minion.name() + "(" + minion.uuid() + "):" + minion.isSpawned()), false);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
package io.github.skippyall.minions.command;
|
||||
|
||||
import com.mojang.brigadier.context.CommandContext;
|
||||
import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
||||
import com.mojang.brigadier.exceptions.SimpleCommandExceptionType;
|
||||
import com.mojang.brigadier.suggestion.SuggestionProvider;
|
||||
import com.mojang.brigadier.suggestion.Suggestions;
|
||||
import com.mojang.brigadier.suggestion.SuggestionsBuilder;
|
||||
import io.github.skippyall.minions.minion.MinionData;
|
||||
import io.github.skippyall.minions.minion.MinionPersistentState;
|
||||
import io.github.skippyall.minions.minion.MinionProfileUtils;
|
||||
import net.minecraft.commands.CommandSourceStack;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
public class MinionArgument {
|
||||
public static final SimpleCommandExceptionType MINION_NOT_PRESENT = new SimpleCommandExceptionType(Component.translatable("minions.command.minion.not_present"));
|
||||
|
||||
public static final MinionSuggestionProvider SUGGESTION_PROVIDER = new MinionSuggestionProvider();
|
||||
|
||||
public static MinionData parse(MinecraftServer server, String argument) throws CommandSyntaxException {
|
||||
Optional<MinionData> data = Optional.empty();
|
||||
if(argument.startsWith(MinionProfileUtils.getPrefix())) {
|
||||
data = MinionPersistentState.get(server).getMinionWithName(argument);
|
||||
} else {
|
||||
try {
|
||||
data = Optional.ofNullable(MinionPersistentState.get(server).getMinionData(UUID.fromString(argument)));
|
||||
} catch (IllegalArgumentException ignored) {}
|
||||
}
|
||||
|
||||
if(data.isEmpty()) {
|
||||
throw MINION_NOT_PRESENT.create();
|
||||
}
|
||||
return data.get();
|
||||
}
|
||||
|
||||
public static class MinionSuggestionProvider implements SuggestionProvider<CommandSourceStack> {
|
||||
@Override
|
||||
public CompletableFuture<Suggestions> getSuggestions(CommandContext<CommandSourceStack> context, SuggestionsBuilder builder) throws CommandSyntaxException {
|
||||
for (MinionData data : MinionPersistentState.get(context.getSource().getServer()).getMinionDataList()) {
|
||||
builder.suggest(data.name());
|
||||
}
|
||||
|
||||
return builder.buildFuture();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package io.github.skippyall.minions.command;
|
||||
|
||||
import com.mojang.brigadier.CommandDispatcher;
|
||||
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
||||
import io.github.skippyall.minions.MinionsConfig;
|
||||
import net.minecraft.commands.CommandBuildContext;
|
||||
import net.minecraft.commands.CommandSourceStack;
|
||||
import net.minecraft.commands.Commands;
|
||||
|
||||
import static net.minecraft.commands.Commands.literal;
|
||||
|
||||
public class MinionsCommand {
|
||||
public static void register(CommandDispatcher<CommandSourceStack> dispatcher, CommandBuildContext access, Commands.CommandSelection environment) {
|
||||
LiteralArgumentBuilder<CommandSourceStack> builder = literal("minions")
|
||||
.then(SpawnSubcommand.SPAWN)
|
||||
.then(ListSubcommand.LIST)
|
||||
.then(DocsSubcommand.DOCS)
|
||||
.then(TestSubcommand.TEST);
|
||||
|
||||
if(MinionsConfig.get().minion.enableMobCapHacks) {
|
||||
builder.then(MobCapDebugSubcommand.MOB_CAP_DEBUG);
|
||||
}
|
||||
|
||||
dispatcher.register(
|
||||
builder
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package io.github.skippyall.minions.command;
|
||||
|
||||
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
||||
import com.mojang.brigadier.context.CommandContext;
|
||||
import io.github.skippyall.minions.mixinhelper.antimobcap.ChunkLevelManager$DistanceFromNearestPlayerTrackerAccessor;
|
||||
import io.github.skippyall.minions.mixinhelper.antimobcap.ChunkLevelManagerAccessor;
|
||||
import io.github.skippyall.minions.mixins.antimobcap.ServerChunkCacheAccessor;
|
||||
import net.minecraft.commands.CommandSourceStack;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.server.level.DistanceManager;
|
||||
|
||||
import static net.minecraft.commands.Commands.literal;
|
||||
|
||||
public class MobCapDebugSubcommand {
|
||||
public static final LiteralArgumentBuilder<CommandSourceStack> MOB_CAP_DEBUG = literal("mobcapdebug")
|
||||
.executes(MobCapDebugSubcommand::mobcapdebugCommand);
|
||||
|
||||
public static int mobcapdebugCommand(CommandContext<CommandSourceStack> context) {
|
||||
DistanceManager levelManager = ((ServerChunkCacheAccessor)context.getSource().getLevel().getChunkSource()).getDistanceManager();
|
||||
int tickedChunkCount = ((ChunkLevelManager$DistanceFromNearestPlayerTrackerAccessor)((ChunkLevelManagerAccessor)levelManager).minions$getMinionless()).minions$getTickedChunkCount();
|
||||
context.getSource().sendSuccess(() -> Component.nullToEmpty(String.valueOf(tickedChunkCount)), false);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
package io.github.skippyall.minions.command;
|
||||
|
||||
import com.mojang.brigadier.arguments.BoolArgumentType;
|
||||
import com.mojang.brigadier.arguments.StringArgumentType;
|
||||
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
||||
import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
||||
import io.github.skippyall.minions.minion.MinionData;
|
||||
import io.github.skippyall.minions.minion.fakeplayer.MinionFakePlayer;
|
||||
import net.minecraft.commands.CommandSourceStack;
|
||||
import net.minecraft.commands.arguments.coordinates.Coordinates;
|
||||
import net.minecraft.commands.arguments.coordinates.Vec3Argument;
|
||||
|
||||
import static net.minecraft.commands.Commands.argument;
|
||||
import static net.minecraft.commands.Commands.literal;
|
||||
|
||||
public class SpawnSubcommand {
|
||||
public static final LiteralArgumentBuilder<CommandSourceStack> SPAWN = literal("spawn")
|
||||
.requires(source -> source.hasPermission(2))
|
||||
.then(argument("minion", StringArgumentType.word())
|
||||
.suggests(MinionArgument.SUGGESTION_PROVIDER)
|
||||
.then(argument("pos", Vec3Argument.vec3())
|
||||
.executes(context ->
|
||||
spawnCommand(
|
||||
context.getSource(),
|
||||
StringArgumentType.getString(context, "minion"),
|
||||
Vec3Argument.getCoordinates(context, "pos"),
|
||||
false
|
||||
)
|
||||
)
|
||||
.then(argument("force", BoolArgumentType.bool())
|
||||
.executes(context ->
|
||||
spawnCommand(
|
||||
context.getSource(),
|
||||
StringArgumentType.getString(context, "minion"),
|
||||
Vec3Argument.getCoordinates(context, "pos"),
|
||||
BoolArgumentType.getBool(context, "force")
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
.executes(context ->
|
||||
spawnCommand(
|
||||
context.getSource(),
|
||||
StringArgumentType.getString(context, "minion"),
|
||||
null,
|
||||
false
|
||||
))
|
||||
);
|
||||
|
||||
public static int spawnCommand(CommandSourceStack source, String minion, Coordinates pos, boolean force) throws CommandSyntaxException {
|
||||
MinionData data = MinionArgument.parse(source.getServer(), minion);
|
||||
MinionFakePlayer.spawnMinion(data, source.getLevel(), pos != null ? pos.getPosition(source) : null, pos != null ? pos.getRotation(source) : null, force);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
package io.github.skippyall.minions.command;
|
||||
|
||||
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
||||
import com.mojang.brigadier.context.CommandContext;
|
||||
import io.github.skippyall.minions.Minions;
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import net.minecraft.commands.CommandSourceStack;
|
||||
import net.minecraft.commands.arguments.coordinates.BlockPosArgument;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.block.Blocks;
|
||||
|
||||
import static net.minecraft.commands.Commands.argument;
|
||||
import static net.minecraft.commands.Commands.literal;
|
||||
|
||||
public class TestSubcommand {
|
||||
public static LiteralArgumentBuilder<CommandSourceStack> TEST = literal("test")
|
||||
.then(argument("pos", BlockPosArgument.blockPos())
|
||||
.executes(TestSubcommand::execute)
|
||||
);
|
||||
|
||||
|
||||
private static int execute(CommandContext<CommandSourceStack> context) {
|
||||
try {
|
||||
BlockPos pos = BlockPosArgument.getBlockPos(context, "pos");
|
||||
Collection<BlockPos> result = findInputs(context.getSource().getLevel(), pos);
|
||||
for (BlockPos resultPos : result) {
|
||||
context.getSource().sendSuccess(() -> Component.literal(resultPos.toShortString()), false);
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
Minions.LOGGER.error("Error", e);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
private static Collection<BlockPos> findInputs(Level world, BlockPos pos) {
|
||||
//positions that are already processed
|
||||
Collection<BlockPos> visitedPositions = new HashSet<>();
|
||||
//positions we are currently looking at
|
||||
Collection<BlockPos> currentPositions = new HashSet<>();
|
||||
//new positions are added here
|
||||
Collection<BlockPos> newPositions = new HashSet<>();
|
||||
//resulting machines
|
||||
Collection<BlockPos> machines = new HashSet<>();
|
||||
|
||||
currentPositions.add(pos);
|
||||
|
||||
while(!currentPositions.isEmpty()) {
|
||||
for(BlockPos currentPosition : currentPositions) {
|
||||
for(Direction dir : Direction.values()) {
|
||||
//check each neighbor of the current positions
|
||||
BlockPos newPos = currentPosition.relative(dir);
|
||||
//Do not check blocks that were already checked
|
||||
if(!visitedPositions.contains(newPos)) {
|
||||
if (world.getBlockState(newPos).getBlock() == Blocks.REDSTONE_BLOCK) {
|
||||
//Add pipes to positions for the next iteration
|
||||
newPositions.add(newPos);
|
||||
} else if (world.getBlockState(newPos).getBlock() == Blocks.IRON_BLOCK) {
|
||||
//Add machines to output set
|
||||
machines.add(newPos);
|
||||
}
|
||||
//Add checked blocks here so that they are not checked again
|
||||
visitedPositions.add(newPos);
|
||||
}
|
||||
}
|
||||
}
|
||||
//Check the new positions in the next iteration
|
||||
currentPositions = newPositions;
|
||||
newPositions = new HashSet<>();
|
||||
}
|
||||
|
||||
return machines;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package io.github.skippyall.minions.docs;
|
||||
|
||||
import com.mojang.serialization.Codec;
|
||||
import com.mojang.serialization.MapCodec;
|
||||
import com.mojang.serialization.codecs.RecordCodecBuilder;
|
||||
import io.github.skippyall.minions.registration.MinionRegistries;
|
||||
import java.util.List;
|
||||
import java.util.function.Function;
|
||||
import net.minecraft.core.RegistryAccess;
|
||||
import net.minecraft.server.dialog.body.DialogBody;
|
||||
|
||||
public interface DocsEntry {
|
||||
Codec<DocsEntry> CODEC = MinionRegistries.DOCS_ENTRY_TYPES.byNameCodec().dispatch(DocsEntry::getCodec, Function.identity());
|
||||
|
||||
Metadata getMetadata();
|
||||
|
||||
List<DialogBody> getDialog(RegistryAccess manager);
|
||||
|
||||
MapCodec<? extends DocsEntry> getCodec();
|
||||
|
||||
record Metadata(String titleKey) {
|
||||
public static final MapCodec<Metadata> CODEC = RecordCodecBuilder.mapCodec(instance ->
|
||||
instance.group(
|
||||
Codec.STRING.fieldOf("title").forGetter(Metadata::titleKey)
|
||||
).apply(instance, Metadata::new)
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,143 @@
|
||||
package io.github.skippyall.minions.docs;
|
||||
|
||||
import com.google.gson.JsonParseException;
|
||||
import com.mojang.serialization.JsonOps;
|
||||
import io.github.skippyall.minions.Minions;
|
||||
import net.fabricmc.fabric.api.resource.SimpleResourceReloadListener;
|
||||
import net.minecraft.core.Holder;
|
||||
import net.minecraft.network.chat.ClickEvent;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.server.dialog.ActionButton;
|
||||
import net.minecraft.server.dialog.CommonButtonData;
|
||||
import net.minecraft.server.dialog.CommonDialogData;
|
||||
import net.minecraft.server.dialog.DialogAction;
|
||||
import net.minecraft.server.dialog.MultiActionDialog;
|
||||
import net.minecraft.server.dialog.action.StaticAction;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.server.packs.resources.Resource;
|
||||
import net.minecraft.server.packs.resources.ResourceManager;
|
||||
import net.minecraft.util.StrictJsonParser;
|
||||
import net.minecraft.util.Tuple;
|
||||
import java.io.IOException;
|
||||
import java.io.Reader;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.Executor;
|
||||
|
||||
public class DocsManager implements SimpleResourceReloadListener<Tuple<Map<ResourceLocation, DocsEntry>, DocsTree>> {
|
||||
private static Map<ResourceLocation, DocsEntry> docs;
|
||||
private static DocsTree tree;
|
||||
|
||||
public static DocsTree getTree() {
|
||||
return tree;
|
||||
}
|
||||
|
||||
public static void showDocsEntry(ServerPlayer player, ResourceLocation id) {
|
||||
DocsEntry entry = getDocsEntry(id);
|
||||
if(entry == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
List<ActionButton> buttons = new ArrayList<>();
|
||||
if(tree != null) {
|
||||
DocsTree.DocElement element = tree.getElement(id);
|
||||
if (element.previous() != null) {
|
||||
ResourceLocation previousId = element.previous().getId();
|
||||
buttons.add(getDialogButton(Component.literal("<- ").append(Component.translatable(getDocsEntry(previousId).getMetadata().titleKey())), previousId.toString()));
|
||||
}
|
||||
if (element.next() != null) {
|
||||
ResourceLocation nextId = element.next().getId();
|
||||
buttons.add(getDialogButton(Component.translatable(getDocsEntry(nextId).getMetadata().titleKey()).append(Component.literal(" ->")), nextId.toString()));
|
||||
}
|
||||
}
|
||||
|
||||
buttons.add(new ActionButton(
|
||||
new CommonButtonData(Component.translatable("gui.ok"), 100),
|
||||
Optional.empty()
|
||||
));
|
||||
|
||||
player.openDialog(Holder.direct(new MultiActionDialog(
|
||||
new CommonDialogData(
|
||||
Component.translatable(entry.getMetadata().titleKey()),
|
||||
Optional.empty(),
|
||||
true,
|
||||
false,
|
||||
DialogAction.CLOSE,
|
||||
entry.getDialog(player.registryAccess()),
|
||||
List.of()
|
||||
),
|
||||
buttons,
|
||||
Optional.empty(),
|
||||
2
|
||||
)));
|
||||
}
|
||||
|
||||
private static ActionButton getDialogButton(Component text, String dialogToOpen) {
|
||||
return new ActionButton(
|
||||
new CommonButtonData(
|
||||
text, 100
|
||||
),
|
||||
Optional.of(new StaticAction(new ClickEvent.RunCommand("/minions docs " + dialogToOpen)))
|
||||
);
|
||||
}
|
||||
|
||||
public static DocsEntry getDocsEntry(ResourceLocation id) {
|
||||
return docs.get(id);
|
||||
}
|
||||
|
||||
public static Collection<ResourceLocation> getDocsEntryIds() {
|
||||
return docs.keySet();
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<Tuple<Map<ResourceLocation, DocsEntry>, DocsTree>> load(ResourceManager resourceManager, Executor executor) {
|
||||
return CompletableFuture.supplyAsync(() -> {
|
||||
Map<ResourceLocation, Resource> resources = resourceManager.listResources("docs", id -> id.getNamespace().equals(Minions.MOD_ID) && id.getPath().endsWith(".json"));
|
||||
|
||||
final DocsTree.BranchElement[] root = {null};
|
||||
Map<ResourceLocation, DocsEntry> docsEntries = new HashMap<>();
|
||||
resources.forEach((id, resource) -> {
|
||||
try(Reader reader = resource.openAsReader()) {
|
||||
if(id.getPath().equals("docs/tree.json")) {
|
||||
DocsTree.BranchElement.CODEC.decode(JsonOps.INSTANCE, StrictJsonParser.parse(reader))
|
||||
.ifSuccess(entry -> root[0] = entry.getFirst())
|
||||
.ifError(error -> Minions.LOGGER.warn("Could not parse docs tree {}: {}", id, error.message()));
|
||||
} else {
|
||||
ResourceLocation docId = ResourceLocation.fromNamespaceAndPath(id.getNamespace(), id.getPath().substring("docs/".length(), id.getPath().length() - ".json".length()));
|
||||
DocsEntry.CODEC.decode(JsonOps.INSTANCE, StrictJsonParser.parse(reader))
|
||||
.ifSuccess(entry -> docsEntries.put(docId, entry.getFirst()))
|
||||
.ifError(error -> Minions.LOGGER.warn("Could not parse docs entry {}: {}", id, error.message()));
|
||||
}
|
||||
} catch (IOException | JsonParseException e) {
|
||||
Minions.LOGGER.warn("Could not read file {}", id, e);
|
||||
}
|
||||
});
|
||||
if(root[0] != null) {
|
||||
DocsTree tree = new DocsTree(root[0]);
|
||||
return new Tuple<>(docsEntries, tree);
|
||||
} else {
|
||||
return new Tuple<>(docsEntries, null);
|
||||
}
|
||||
}, executor);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<Void> apply(Tuple<Map<ResourceLocation, DocsEntry>, DocsTree> o, ResourceManager resourceManager, Executor executor) {
|
||||
return CompletableFuture.supplyAsync(() -> {
|
||||
docs = o.getA();
|
||||
tree = o.getB();
|
||||
return null;
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResourceLocation getFabricId() {
|
||||
return ResourceLocation.fromNamespaceAndPath(Minions.MOD_ID, "docs");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,145 @@
|
||||
package io.github.skippyall.minions.docs;
|
||||
|
||||
import com.mojang.datafixers.util.Either;
|
||||
import com.mojang.serialization.Codec;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.function.Function;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
|
||||
public class DocsTree {
|
||||
private final BranchElement root;
|
||||
private final Map<ResourceLocation, DocElement> entries = new HashMap<>();
|
||||
|
||||
public DocsTree(BranchElement root) {
|
||||
this.root = root;
|
||||
initEntries();
|
||||
}
|
||||
|
||||
private void initEntries() {
|
||||
DocElement element = root.first();
|
||||
do {
|
||||
entries.put(element.id, element);
|
||||
element = element.next();
|
||||
} while (element != null);
|
||||
}
|
||||
|
||||
public BranchElement getRoot() {
|
||||
return root;
|
||||
}
|
||||
|
||||
public DocElement getElement(ResourceLocation id) {
|
||||
return entries.get(id);
|
||||
}
|
||||
|
||||
public static abstract sealed class Element {
|
||||
private BranchElement parent;
|
||||
|
||||
public BranchElement getParent() {
|
||||
return parent;
|
||||
}
|
||||
|
||||
void setParent(BranchElement parent) {
|
||||
this.parent = parent;
|
||||
}
|
||||
|
||||
public DocElement next() {
|
||||
return parent.next(this);
|
||||
}
|
||||
|
||||
public DocElement previous() {
|
||||
return parent.previous(this);
|
||||
}
|
||||
}
|
||||
|
||||
public static final class DocElement extends Element {
|
||||
public static final Codec<DocElement> CODEC = ResourceLocation.CODEC.xmap(DocElement::new, DocElement::getId);
|
||||
|
||||
private final ResourceLocation id;
|
||||
|
||||
public DocElement(ResourceLocation element) {
|
||||
this.id = element;
|
||||
}
|
||||
|
||||
public ResourceLocation getId() {
|
||||
return id;
|
||||
}
|
||||
}
|
||||
|
||||
public static final class BranchElement extends Element {
|
||||
public static final Codec<BranchElement> CODEC = Codec.<BranchElement>recursive("DocsBranch", codec ->
|
||||
Codec.either(codec, DocElement.CODEC)
|
||||
.xmap(
|
||||
Either::unwrap,
|
||||
element -> switch (element) {
|
||||
case BranchElement branch -> Either.left(branch);
|
||||
case DocElement doc -> Either.right(doc);
|
||||
}
|
||||
).listOf()
|
||||
.xmap(BranchElement::new, branch -> branch.e)
|
||||
).xmap(BranchElement::setParents, Function.identity());
|
||||
|
||||
private final List<Element> e;
|
||||
|
||||
public BranchElement(List<Element> elements) {
|
||||
e = elements;
|
||||
}
|
||||
|
||||
public DocElement first() {
|
||||
return switch (e.getFirst()) {
|
||||
case BranchElement branch -> branch.first();
|
||||
case DocElement doc -> doc;
|
||||
};
|
||||
}
|
||||
|
||||
public DocElement last() {
|
||||
return switch (e.getLast()) {
|
||||
case BranchElement branch -> branch.last();
|
||||
case DocElement doc -> doc;
|
||||
};
|
||||
}
|
||||
|
||||
public DocElement next(Element current) {
|
||||
int nextIndex = e.indexOf(current) + 1;
|
||||
if(nextIndex < e.size()) {
|
||||
return switch (e.get(nextIndex)) {
|
||||
case BranchElement branch -> branch.first();
|
||||
case DocElement doc -> doc;
|
||||
};
|
||||
} else {
|
||||
if(getParent() != null) {
|
||||
return getParent().next(this);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public DocElement previous(Element current) {
|
||||
int previousIndex = e.indexOf(current) - 1;
|
||||
if(previousIndex >= 0) {
|
||||
return switch (e.get(previousIndex)) {
|
||||
case BranchElement branch -> branch.first();
|
||||
case DocElement doc -> doc;
|
||||
};
|
||||
} else {
|
||||
if(getParent() != null) {
|
||||
return getParent().previous(this);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private BranchElement setParents() {
|
||||
for(Element element : e) {
|
||||
element.setParent(this);
|
||||
if(element instanceof BranchElement branch) {
|
||||
branch.setParents();
|
||||
}
|
||||
}
|
||||
return this;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
package io.github.skippyall.minions.docs;
|
||||
|
||||
import com.mojang.serialization.Codec;
|
||||
import com.mojang.serialization.MapCodec;
|
||||
import com.mojang.serialization.codecs.RecordCodecBuilder;
|
||||
import io.github.skippyall.minions.gui.GuiDisplay;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import net.minecraft.core.RegistryAccess;
|
||||
import net.minecraft.core.registries.BuiltInRegistries;
|
||||
import net.minecraft.core.registries.Registries;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.network.chat.ComponentSerialization;
|
||||
import net.minecraft.resources.ResourceKey;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.server.dialog.body.DialogBody;
|
||||
import net.minecraft.server.dialog.body.ItemBody;
|
||||
import net.minecraft.server.dialog.body.PlainMessage;
|
||||
import net.minecraft.world.item.Item;
|
||||
|
||||
public record ReferenceEntry(Metadata metadata, ResourceKey<?> object, Component shortDescription, Component longDescription) implements DocsEntry {
|
||||
private static final Codec<ResourceKey<?>> REGISTRY_KEY_CODEC = RecordCodecBuilder.create(instance ->
|
||||
instance.group(
|
||||
ResourceLocation.CODEC.fieldOf("registry").forGetter(ResourceKey::registry),
|
||||
ResourceLocation.CODEC.fieldOf("value").forGetter(ResourceKey::location)
|
||||
).apply(instance, (registry, value) -> ResourceKey.create(ResourceKey.createRegistryKey(registry), value))
|
||||
);
|
||||
|
||||
public static final MapCodec<ReferenceEntry> CODEC = RecordCodecBuilder.mapCodec(instance ->
|
||||
instance.group(
|
||||
Metadata.CODEC.fieldOf("metadata").forGetter(ReferenceEntry::getMetadata),
|
||||
REGISTRY_KEY_CODEC.fieldOf("object").forGetter(ReferenceEntry::object),
|
||||
ComponentSerialization.CODEC.fieldOf("shortDescription").forGetter(ReferenceEntry::shortDescription),
|
||||
ComponentSerialization.CODEC.fieldOf("longDescription").forGetter(ReferenceEntry::longDescription)
|
||||
).apply(instance, ReferenceEntry::new));
|
||||
|
||||
@Override
|
||||
public Metadata getMetadata() {
|
||||
return metadata;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<DialogBody> getDialog(RegistryAccess manager) {
|
||||
List<DialogBody> bodyElements = new ArrayList<>();
|
||||
|
||||
GuiDisplay display = getObjectDisplay(manager);
|
||||
if(display != null) {
|
||||
bodyElements.add(new ItemBody(display.createItemStack(), Optional.empty(), false, false, 16, 16));
|
||||
}
|
||||
bodyElements.add(new PlainMessage(Component.translatable(object.location().toLanguageKey(object.registry().getPath())), 200));
|
||||
bodyElements.add(new PlainMessage(longDescription, 200));
|
||||
|
||||
return bodyElements;
|
||||
}
|
||||
|
||||
public GuiDisplay getObjectDisplay(RegistryAccess manager) {
|
||||
GuiDisplay display = GuiDisplay.DEFAULT_DISPLAY;
|
||||
if(object.isFor(Registries.ITEM) || object.isFor(Registries.BLOCK)) {
|
||||
Item item;
|
||||
if(object.isFor(Registries.ITEM)) {
|
||||
item = BuiltInRegistries.ITEM.getValue(object.location());
|
||||
} else {
|
||||
item = BuiltInRegistries.BLOCK.getValue(object.location()).asItem();
|
||||
}
|
||||
if(item != null) {
|
||||
display = new GuiDisplay.ItemBased(item);
|
||||
}
|
||||
} else {
|
||||
ResourceLocation displayId = object.location().withPrefix(object.registry().getPath() + "/");
|
||||
display = GuiDisplay.getGuiDisplay(displayId, manager);
|
||||
}
|
||||
return display;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MapCodec<? extends DocsEntry> getCodec() {
|
||||
return CODEC;
|
||||
}
|
||||
}
|
||||
@@ -1,52 +0,0 @@
|
||||
package io.github.skippyall.minions.gui;
|
||||
|
||||
import eu.pb4.sgui.api.elements.GuiElementBuilder;
|
||||
import eu.pb4.sgui.api.gui.SimpleGui;
|
||||
import io.github.skippyall.minions.module.command.Command;
|
||||
import io.github.skippyall.minions.minion.fakeplayer.MinionFakePlayer;
|
||||
import io.github.skippyall.minions.module.ModuleItem;
|
||||
import net.minecraft.screen.ScreenHandlerType;
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
import net.minecraft.text.Text;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class CommandsGui {
|
||||
public static void openServerModuleCommandGui(ServerPlayerEntity player, MinionFakePlayer minion) {
|
||||
List<ModuleItem> modules = minion.getModuleInventory().getModuleItems();
|
||||
|
||||
SimpleGui gui = new SimpleGui(ScreenHandlerType.GENERIC_9X3, player, false);
|
||||
|
||||
gui.setTitle(Text.translatable("minions.gui.module_commands.title"));
|
||||
|
||||
for (int i = 0; i < modules.size(); i++) {
|
||||
ModuleItem module = modules.get(i);
|
||||
gui.setSlot(i, new GuiElementBuilder()
|
||||
.setItem(module.asItem())
|
||||
.setCallback(() -> openServerCommandGui(player, minion, module))
|
||||
);
|
||||
}
|
||||
|
||||
gui.open();
|
||||
}
|
||||
|
||||
public static void openServerCommandGui(ServerPlayerEntity player, MinionFakePlayer minion, ModuleItem module) {
|
||||
List<Command> commands = module.getCommands();
|
||||
|
||||
SimpleGui commandGui = new SimpleGui(ScreenHandlerType.GENERIC_9X3, player, false);
|
||||
|
||||
commandGui.setTitle(Text.translatable("minions.gui.commands.title", module.asItem().getName()));
|
||||
|
||||
for(int j = 0; j < commands.size(); j++) {
|
||||
Command command = commands.get(j);
|
||||
commandGui.setSlot(j, new GuiElementBuilder()
|
||||
.setItem(command.getItemRepresentation())
|
||||
.setName(command.getName())
|
||||
.addLoreLine(command.getDescription())
|
||||
.setCallback(() -> command.execute(player, minion))
|
||||
);
|
||||
}
|
||||
|
||||
commandGui.open();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
package io.github.skippyall.minions.gui;
|
||||
|
||||
public interface Displayable {
|
||||
GuiDisplay getDisplay();
|
||||
}
|
||||
@@ -0,0 +1,143 @@
|
||||
package io.github.skippyall.minions.gui;
|
||||
|
||||
import com.mojang.authlib.properties.PropertyMap;
|
||||
import com.mojang.serialization.Codec;
|
||||
import io.github.skippyall.minions.registration.MinionRegistries;
|
||||
import io.github.skippyall.minions.util.TranslationUtil;
|
||||
import it.unimi.dsi.fastutil.objects.ReferenceSortedSets;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
import net.minecraft.ChatFormatting;
|
||||
import net.minecraft.core.Registry;
|
||||
import net.minecraft.core.RegistryAccess;
|
||||
import net.minecraft.core.UUIDUtil;
|
||||
import net.minecraft.core.component.DataComponents;
|
||||
import net.minecraft.core.registries.BuiltInRegistries;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.world.item.Item;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.item.Items;
|
||||
import net.minecraft.world.item.Rarity;
|
||||
import net.minecraft.world.item.component.ResolvableProfile;
|
||||
import net.minecraft.world.item.component.TooltipDisplay;
|
||||
|
||||
public interface GuiDisplay {
|
||||
Codec<GuiDisplay> CODEC = MinionRegistries.GUI_DISPLAY_TYPE.byNameCodec().dispatch(GuiDisplay::getCodec, codec -> codec.fieldOf("data"));
|
||||
GuiDisplay DEFAULT_DISPLAY = new ItemBased(Items.BARRIER);
|
||||
|
||||
static GuiDisplay getGuiDisplay(ResourceLocation id, RegistryAccess manager) {
|
||||
return manager.lookup(MinionRegistries.GUI_DISPLAY).map(registry -> registry.getValue(id)).orElse(DEFAULT_DISPLAY);
|
||||
}
|
||||
|
||||
static <T> GuiDisplay getGuiDisplayFor(Registry<T> registry, T element, RegistryAccess manager) {
|
||||
ResourceLocation elementId = registry.getKey(element);
|
||||
if(elementId == null) {
|
||||
return DEFAULT_DISPLAY;
|
||||
}
|
||||
ResourceLocation displayId = elementId.withPrefix(registry.key().location().getPath() + "/");
|
||||
|
||||
return getGuiDisplay(displayId, manager);
|
||||
}
|
||||
|
||||
static <T> ItemStack getDisplayStack(Registry<T> registry, T element, RegistryAccess manager) {
|
||||
return getGuiDisplayFor(registry, element, manager).createItemStack();
|
||||
}
|
||||
|
||||
static <T> ItemStack getDisplayStackWithName(Registry<T> registry, T element, RegistryAccess manager) {
|
||||
ItemStack stack = getDisplayStack(registry, element, manager);
|
||||
stack.set(DataComponents.CUSTOM_NAME, Component.translatable(TranslationUtil.getTranslationKey(element, registry)).withStyle(style -> style.withItalic(false).withColor(ChatFormatting.WHITE)));
|
||||
return stack;
|
||||
}
|
||||
|
||||
ItemStack createItemStack();
|
||||
|
||||
Codec<? extends GuiDisplay> getCodec();
|
||||
|
||||
class ModelBased implements GuiDisplay {
|
||||
public static final Codec<ModelBased> CODEC = ResourceLocation.CODEC.xmap(ModelBased::new, display -> display.model);
|
||||
|
||||
private final ResourceLocation model;
|
||||
|
||||
public ModelBased(ResourceLocation model) {
|
||||
this.model = model;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack createItemStack() {
|
||||
ItemStack stack = new ItemStack(Items.BARRIER);
|
||||
stack.set(DataComponents.ITEM_MODEL, model);
|
||||
return stack;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Codec<? extends GuiDisplay> getCodec() {
|
||||
return CODEC;
|
||||
}
|
||||
}
|
||||
|
||||
class ItemBased implements GuiDisplay {
|
||||
public static final Codec<ItemBased> CODEC = BuiltInRegistries.ITEM.byNameCodec().xmap(ItemBased::new, display -> display.item);
|
||||
|
||||
private final Item item;
|
||||
|
||||
public ItemBased(Item item) {
|
||||
this.item = item;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack createItemStack() {
|
||||
ItemStack stack = new ItemStack(item);
|
||||
stack.set(DataComponents.TOOLTIP_DISPLAY, new TooltipDisplay(true, ReferenceSortedSets.emptySet()));
|
||||
stack.set(DataComponents.RARITY, Rarity.COMMON);
|
||||
return stack;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Codec<? extends GuiDisplay> getCodec() {
|
||||
return CODEC;
|
||||
}
|
||||
}
|
||||
|
||||
class HeadBased implements GuiDisplay {
|
||||
public static final Codec<HeadBased> CODEC = UUIDUtil.AUTHLIB_CODEC.xmap(HeadBased::new, display -> display.uuid);
|
||||
|
||||
private final UUID uuid;
|
||||
|
||||
public HeadBased(UUID uuid) {
|
||||
this.uuid = uuid;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack createItemStack() {
|
||||
ItemStack stack = new ItemStack(Items.PLAYER_HEAD);
|
||||
stack.set(DataComponents.PROFILE, new ResolvableProfile(Optional.empty(), Optional.of(uuid), new PropertyMap()));
|
||||
return stack;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Codec<? extends GuiDisplay> getCodec() {
|
||||
return CODEC;
|
||||
}
|
||||
}
|
||||
|
||||
class StackBased implements GuiDisplay {
|
||||
public static final Codec<StackBased> CODEC = ItemStack.CODEC.xmap(StackBased::new, StackBased::createItemStack);
|
||||
|
||||
private final ItemStack stack;
|
||||
|
||||
public StackBased(ItemStack stack) {
|
||||
this.stack = stack;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack createItemStack() {
|
||||
return stack;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Codec<? extends GuiDisplay> getCodec() {
|
||||
return CODEC;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,77 +0,0 @@
|
||||
package io.github.skippyall.minions.gui;
|
||||
|
||||
import eu.pb4.sgui.api.elements.GuiElementBuilder;
|
||||
import eu.pb4.sgui.api.gui.SimpleGui;
|
||||
import io.github.skippyall.minions.minion.fakeplayer.MinionFakePlayer;
|
||||
import net.minecraft.item.Items;
|
||||
import net.minecraft.screen.ScreenHandlerType;
|
||||
import net.minecraft.screen.slot.Slot;
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
import net.minecraft.text.Text;
|
||||
|
||||
public class MinionGui {
|
||||
public static void openInventory(ServerPlayerEntity player, MinionFakePlayer minion) {
|
||||
openServerSideInventory(player, minion);
|
||||
}
|
||||
|
||||
public static void openServerSideInventory(ServerPlayerEntity player, MinionFakePlayer minion) {
|
||||
SimpleGui gui = new SimpleGui(ScreenHandlerType.GENERIC_3X3, player, false);
|
||||
gui.setTitle(minion.getName());
|
||||
|
||||
gui.setSlot(1, new GuiElementBuilder()
|
||||
.setItem(Items.COMMAND_BLOCK)
|
||||
.setName(Text.translatable("minions.gui.main.commands"))
|
||||
.setCallback((i, clickType, slotActionType) -> {
|
||||
openCommandsGui(player, minion);
|
||||
})
|
||||
);
|
||||
if(minion.isProgrammable()) {
|
||||
gui.setSlot(4, new GuiElementBuilder()
|
||||
.setItem(Items.REDSTONE)
|
||||
.setName(Text.translatable("minions.gui.main.programming"))
|
||||
.setCallback(() -> {
|
||||
openProgrammingInventory(player, minion);
|
||||
})
|
||||
);
|
||||
}
|
||||
gui.setSlot(3, new GuiElementBuilder()
|
||||
.setItem(Items.NETHERITE_UPGRADE_SMITHING_TEMPLATE)
|
||||
.setName(Text.translatable("minions.gui.main.modules"))
|
||||
.setCallback(() -> {
|
||||
ModuleInventory.openModuleInventory(player, minion);
|
||||
})
|
||||
);
|
||||
gui.setSlot(5, new GuiElementBuilder()
|
||||
.setItem(Items.CHEST)
|
||||
.setName(Text.translatable("minions.gui.main.inventory"))
|
||||
.setCallback(() -> {
|
||||
openMinionInventory(player, minion);
|
||||
})
|
||||
);
|
||||
gui.setSlot(7, new GuiElementBuilder()
|
||||
.setItem(Items.BARRIER)
|
||||
.setName(Text.translatable("minions.gui.main.pickup"))
|
||||
.setCallback(() -> {
|
||||
minion.kill(minion.getServerWorld());
|
||||
})
|
||||
);
|
||||
gui.open();
|
||||
}
|
||||
|
||||
public static void openCommandsGui(ServerPlayerEntity player, MinionFakePlayer minion) {
|
||||
CommandsGui.openServerModuleCommandGui(player, minion);
|
||||
}
|
||||
|
||||
public static void openProgrammingInventory(ServerPlayerEntity player, MinionFakePlayer minion) {
|
||||
|
||||
}
|
||||
|
||||
public static void openMinionInventory(ServerPlayerEntity player, MinionFakePlayer minion) {
|
||||
SimpleGui gui = new SimpleGui(ScreenHandlerType.GENERIC_9X5, player, false);
|
||||
gui.setTitle(Text.translatable("minions.gui.inventory.title", minion.getName()));
|
||||
for (int i = 0; i < minion.getInventory().size(); i++) {
|
||||
gui.setSlotRedirect(i, new Slot(minion.getInventory(), i, 0, 0));
|
||||
}
|
||||
gui.open();
|
||||
}
|
||||
}
|
||||
@@ -2,28 +2,28 @@ package io.github.skippyall.minions.gui;
|
||||
|
||||
import eu.pb4.sgui.api.elements.GuiElementBuilder;
|
||||
import eu.pb4.sgui.api.gui.SimpleGui;
|
||||
import io.github.skippyall.minions.input.TextInput;
|
||||
import io.github.skippyall.minions.gui.input.TextInput;
|
||||
import io.github.skippyall.minions.minion.MinionData;
|
||||
import io.github.skippyall.minions.minion.MinionItem;
|
||||
import io.github.skippyall.minions.minion.MinionProfileUtils;
|
||||
import io.github.skippyall.minions.minion.skin.SkinProvider;
|
||||
import io.github.skippyall.minions.minion.skin.SkinProviders;
|
||||
import net.minecraft.component.DataComponentTypes;
|
||||
import net.minecraft.component.type.ProfileComponent;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.Items;
|
||||
import net.minecraft.screen.ScreenHandlerType;
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
import net.minecraft.text.Text;
|
||||
|
||||
import io.github.skippyall.minions.registration.MinionRegistries;
|
||||
import io.github.skippyall.minions.registration.SkinProviders;
|
||||
import java.util.Optional;
|
||||
import net.minecraft.core.component.DataComponents;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.world.inventory.MenuType;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.item.Items;
|
||||
import net.minecraft.world.item.component.ResolvableProfile;
|
||||
|
||||
public class MinionLookGui extends SimpleGui {
|
||||
private ItemStack minionItem;
|
||||
private SkinProvider currentSkinProvider;
|
||||
|
||||
public MinionLookGui(ServerPlayerEntity player, ItemStack minionItem) {
|
||||
super(ScreenHandlerType.GENERIC_9X3, player, false);
|
||||
public MinionLookGui(ServerPlayer player, ItemStack minionItem) {
|
||||
super(MenuType.GENERIC_9x3, player, false);
|
||||
this.minionItem = minionItem;
|
||||
this.currentSkinProvider = SkinProviders.NAME;
|
||||
}
|
||||
@@ -37,7 +37,7 @@ public class MinionLookGui extends SimpleGui {
|
||||
private void updateName() {
|
||||
setSlot(10, new GuiElementBuilder()
|
||||
.setItem(Items.OAK_SIGN)
|
||||
.setName(Text.literal(getData().name()))
|
||||
.setName(Component.literal(getData().name()))
|
||||
.setCallback(() -> {
|
||||
openRenameGui(player, minionItem);
|
||||
})
|
||||
@@ -48,47 +48,47 @@ public class MinionLookGui extends SimpleGui {
|
||||
GuiElementBuilder builder = new GuiElementBuilder()
|
||||
.setItem(Items.PLAYER_HEAD)
|
||||
.setCallback(() -> currentSkinProvider.openSkinMenu(player).thenAccept(skin -> {
|
||||
MinionItem.setData(getData().withSkin(skin), minionItem);
|
||||
MinionItem.setData(player.getServer(), getData().withSkin(skin), minionItem);
|
||||
}));
|
||||
if(MinionItem.getData(minionItem) != null && MinionItem.getData(minionItem).skin().isPresent()) {
|
||||
builder.setComponent(DataComponentTypes.PROFILE, new ProfileComponent(Optional.empty(), Optional.empty(), getData().skin().get()));
|
||||
if(MinionItem.getData(player.getServer(), minionItem) != null && MinionItem.getData(player.getServer(), minionItem).skin().isPresent()) {
|
||||
builder.setComponent(DataComponents.PROFILE, new ResolvableProfile(Optional.empty(), Optional.empty(), getData().skin().get()));
|
||||
}
|
||||
setSlot(16, builder);
|
||||
}
|
||||
|
||||
private void cycleSkinProvider() {
|
||||
int currentId = SkinProviders.SKIN_PROVIDERS.getRawId(currentSkinProvider);
|
||||
int currentId = MinionRegistries.SKIN_PROVIDERS.getId(currentSkinProvider);
|
||||
currentId++;
|
||||
if(SkinProviders.SKIN_PROVIDERS.size() == currentId) {
|
||||
if(MinionRegistries.SKIN_PROVIDERS.size() == currentId) {
|
||||
currentId = 0;
|
||||
}
|
||||
|
||||
currentSkinProvider = SkinProviders.SKIN_PROVIDERS.get(currentId);
|
||||
currentSkinProvider = MinionRegistries.SKIN_PROVIDERS.byId(currentId);
|
||||
updateSkinProvider();
|
||||
}
|
||||
|
||||
private void updateSkinProvider() {
|
||||
setSlot(25, new GuiElementBuilder()
|
||||
.setItem(Items.GREEN_STAINED_GLASS_PANE)
|
||||
.setComponent(DataComponentTypes.CUSTOM_NAME, currentSkinProvider.getDisplayName())
|
||||
.setComponent(DataComponents.CUSTOM_NAME, currentSkinProvider.getDisplayName())
|
||||
.setCallback(this::cycleSkinProvider)
|
||||
);
|
||||
}
|
||||
|
||||
private MinionData getData() {
|
||||
return MinionItem.getDataOrDefault(minionItem);
|
||||
return MinionItem.getDataOrDefault(player.getServer(), minionItem);
|
||||
}
|
||||
|
||||
public static void open(ServerPlayerEntity player, ItemStack minionItem) {
|
||||
public static void open(ServerPlayer player, ItemStack minionItem) {
|
||||
MinionLookGui gui = new MinionLookGui(player, minionItem);
|
||||
gui.update();
|
||||
gui.open();
|
||||
}
|
||||
|
||||
public void openRenameGui(ServerPlayerEntity player, ItemStack minionItem) {
|
||||
TextInput.inputSync(player, Text.translatable("minions.gui.look.rename.title"), "Minion", MinionProfileUtils::checkMinionNameWithoutPrefix)
|
||||
public void openRenameGui(ServerPlayer player, ItemStack minionItem) {
|
||||
TextInput.inputSync(player, Component.translatable("minions.gui.look.rename.title"), "Minion", name -> MinionProfileUtils.checkMinionNameWithoutPrefix(player.getServer(), name))
|
||||
.thenAccept(name -> {
|
||||
MinionItem.setData(getData().withName(MinionProfileUtils.PREFIX + name), minionItem);
|
||||
MinionItem.setData(player.getServer(), getData().withName(MinionProfileUtils.getPrefix() + name), minionItem);
|
||||
open();
|
||||
});
|
||||
}
|
||||
|
||||
@@ -0,0 +1,65 @@
|
||||
package io.github.skippyall.minions.gui;
|
||||
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public abstract class MinionsGui {
|
||||
protected final @Nullable MinionsGui parent;
|
||||
protected final ServerPlayer viewer;
|
||||
protected @Nullable MinionsGui child = null;
|
||||
private boolean open = true;
|
||||
|
||||
public MinionsGui(MinionsGui parent) {
|
||||
this.viewer = parent.viewer;
|
||||
this.parent = parent;
|
||||
parent.child = this;
|
||||
}
|
||||
|
||||
public MinionsGui(ServerPlayer viewer) {
|
||||
this.viewer = viewer;
|
||||
this.parent = null;
|
||||
}
|
||||
|
||||
public ServerPlayer getViewer() {
|
||||
return viewer;
|
||||
}
|
||||
|
||||
protected abstract void open();
|
||||
|
||||
protected void reopen() {
|
||||
open();
|
||||
}
|
||||
|
||||
public void onBackingClosed() {
|
||||
if(child != null && child.open) {
|
||||
return;
|
||||
}
|
||||
|
||||
close();
|
||||
}
|
||||
|
||||
public void close() {
|
||||
if(open) {
|
||||
if(parent != null) {
|
||||
parent.child = null;
|
||||
parent.reopen();
|
||||
}
|
||||
closeNoOpen(parent == null);
|
||||
}
|
||||
}
|
||||
|
||||
private void closeNoOpen(boolean closeBacking) {
|
||||
if(child != null) {
|
||||
child.closeNoOpen(closeBacking);
|
||||
}
|
||||
if(parent != null) {
|
||||
parent.child = null;
|
||||
}
|
||||
if(closeBacking) {
|
||||
closeBacking();
|
||||
}
|
||||
open = false;
|
||||
}
|
||||
|
||||
protected abstract void closeBacking();
|
||||
}
|
||||
@@ -1,84 +0,0 @@
|
||||
package io.github.skippyall.minions.gui;
|
||||
|
||||
import io.github.skippyall.minions.module.command.Command;
|
||||
import io.github.skippyall.minions.minion.fakeplayer.MinionFakePlayer;
|
||||
import io.github.skippyall.minions.module.ModuleItem;
|
||||
import io.github.skippyall.minions.program.block.CodeBlock;
|
||||
import net.minecraft.inventory.Inventories;
|
||||
import net.minecraft.inventory.SimpleInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NbtCompound;
|
||||
import net.minecraft.registry.RegistryWrapper;
|
||||
import net.minecraft.screen.SimpleNamedScreenHandlerFactory;
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
import net.minecraft.text.Text;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class ModuleInventory extends SimpleInventory {
|
||||
public ModuleInventory() {
|
||||
super(27);
|
||||
}
|
||||
|
||||
public static void openModuleInventory(ServerPlayerEntity player, MinionFakePlayer minion) {
|
||||
player.openHandledScreen(new SimpleNamedScreenHandlerFactory((syncId, playerInventory, player2) -> new ModuleInventoryScreenHandler(syncId, playerInventory, minion.getModuleInventory()), Text.translatable("minions.gui.modules.title", minion.getName())));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxCountPerStack() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isValid(int slot, ItemStack stack) {
|
||||
return (stack.getCount() <= getMaxCountPerStack()) && stack.getItem() instanceof ModuleItem;
|
||||
}
|
||||
|
||||
public void readNbt(NbtCompound nbt, RegistryWrapper.WrapperLookup lookup) {
|
||||
Inventories.readNbt(nbt, heldStacks, lookup);
|
||||
}
|
||||
|
||||
public NbtCompound writeNbt(NbtCompound nbt, RegistryWrapper.WrapperLookup lookup) {
|
||||
return Inventories.writeNbt(nbt, heldStacks, lookup);
|
||||
}
|
||||
|
||||
public boolean hasModule(ModuleItem module) {
|
||||
for(ItemStack stack : heldStacks) {
|
||||
if(stack.getItem() instanceof ModuleItem module2 && module2 == module) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public List<ModuleItem> getModuleItems() {
|
||||
ArrayList<ModuleItem> modules = new ArrayList<>();
|
||||
for(ItemStack stack : heldStacks) {
|
||||
if(stack.getItem() instanceof ModuleItem module) {
|
||||
modules.add(module);
|
||||
}
|
||||
}
|
||||
return modules;
|
||||
}
|
||||
|
||||
public List<Command> getAllCommands() {
|
||||
ArrayList<Command> commands = new ArrayList<>();
|
||||
for(ItemStack stack : heldStacks) {
|
||||
if(stack.getItem() instanceof ModuleItem module) {
|
||||
commands.addAll(module.getCommands());
|
||||
}
|
||||
}
|
||||
return commands;
|
||||
}
|
||||
|
||||
public List<CodeBlock<?,?>> getAllCodeBlocks() {
|
||||
ArrayList<CodeBlock<?,?>> commands = new ArrayList<>();
|
||||
for(ItemStack stack : heldStacks) {
|
||||
if(stack.getItem() instanceof ModuleItem module) {
|
||||
commands.addAll(module.getCodeBlocks());
|
||||
}
|
||||
}
|
||||
return commands;
|
||||
}
|
||||
}
|
||||
@@ -1,80 +0,0 @@
|
||||
package io.github.skippyall.minions.gui;
|
||||
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.entity.player.PlayerInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.screen.GenericContainerScreenHandler;
|
||||
import net.minecraft.screen.ScreenHandler;
|
||||
import net.minecraft.screen.ScreenHandlerType;
|
||||
import net.minecraft.screen.slot.Slot;
|
||||
|
||||
public class ModuleInventoryScreenHandler extends ScreenHandler {
|
||||
private final int rows = 3;
|
||||
private final ModuleInventory inventory;
|
||||
public ModuleInventoryScreenHandler(int syncId, ModuleInventory inventory) {
|
||||
super(ScreenHandlerType.GENERIC_9X3, syncId);
|
||||
this.inventory = inventory;
|
||||
}
|
||||
|
||||
public ModuleInventoryScreenHandler(int syncId, PlayerInventory playerInventory, ModuleInventory inventory) {
|
||||
super(ScreenHandlerType.GENERIC_9X3, syncId);
|
||||
int k;
|
||||
int j;
|
||||
GenericContainerScreenHandler.checkSize(inventory, 3 * 9);
|
||||
this.inventory = inventory;
|
||||
inventory.onOpen(playerInventory.player);
|
||||
int i = (rows - 4) * 18;
|
||||
for (j = 0; j < rows; ++j) {
|
||||
for (k = 0; k < 9; ++k) {
|
||||
this.addSlot(new Slot(inventory, k + j * 9, 8 + k * 18, 18 + j * 18) {
|
||||
@Override
|
||||
public boolean canInsert(ItemStack stack) {
|
||||
return super.canInsert(stack) && inventory.isValid(getIndex(), stack);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
for (j = 0; j < 3; ++j) {
|
||||
for (k = 0; k < 9; ++k) {
|
||||
this.addSlot(new Slot(playerInventory, k + j * 9 + 9, 8 + k * 18, 103 + j * 18 + i));
|
||||
}
|
||||
}
|
||||
for (j = 0; j < 9; ++j) {
|
||||
this.addSlot(new Slot(playerInventory, j, 8 + j * 18, 161 + i));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canUse(PlayerEntity player) {
|
||||
return this.inventory.canPlayerUse(player);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack quickMove(PlayerEntity player, int slot) {
|
||||
ItemStack itemStack = ItemStack.EMPTY;
|
||||
Slot slot2 = this.slots.get(slot);
|
||||
if (slot2 != null && slot2.hasStack()) {
|
||||
ItemStack itemStack2 = slot2.getStack();
|
||||
itemStack = itemStack2.copy();
|
||||
if (slot < this.rows * 9 ? !this.insertItem(itemStack2, this.rows * 9, this.slots.size(), true) : !this.insertItem(itemStack2, 0, this.rows * 9, false)) {
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
if (itemStack2.isEmpty()) {
|
||||
slot2.setStack(ItemStack.EMPTY);
|
||||
} else {
|
||||
slot2.markDirty();
|
||||
}
|
||||
}
|
||||
return itemStack;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClosed(PlayerEntity player) {
|
||||
super.onClosed(player);
|
||||
this.inventory.onClose(player);
|
||||
}
|
||||
|
||||
public ModuleInventory getInventory() {
|
||||
return inventory;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
package io.github.skippyall.minions.gui;
|
||||
|
||||
import eu.pb4.sgui.api.elements.GuiElementBuilder;
|
||||
import eu.pb4.sgui.api.gui.SimpleGui;
|
||||
import java.util.List;
|
||||
import java.util.function.BiFunction;
|
||||
import net.minecraft.core.IdMap;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.world.inventory.MenuType;
|
||||
import net.minecraft.world.item.Items;
|
||||
|
||||
public class PaginatedList extends MinionsGui {
|
||||
private int page = 0;
|
||||
private SimpleGui gui;
|
||||
private final Component title;
|
||||
private final int size;
|
||||
private final BiFunction<Integer, PaginatedList, GuiElementBuilder> display;
|
||||
|
||||
public PaginatedList(MinionsGui parent, Component title, int size, BiFunction<Integer, PaginatedList, GuiElementBuilder> display) {
|
||||
super(parent);
|
||||
this.title = title;
|
||||
this.size = size;
|
||||
this.display = display;
|
||||
open();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void open() {
|
||||
gui = new SimpleGui(MenuType.GENERIC_9x4, viewer, false) {
|
||||
@Override
|
||||
public void onClose() {
|
||||
onBackingClosed();
|
||||
}
|
||||
};
|
||||
gui.setTitle(title);
|
||||
addItems();
|
||||
gui.open();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void closeBacking() {
|
||||
gui.close();
|
||||
}
|
||||
|
||||
public static <T> void createList(MinionsGui parent, Component title, List<T> list, BiFunction<T, PaginatedList, GuiElementBuilder> display) {
|
||||
new PaginatedList(parent, title, list.size(), (i, gui) -> display.apply(list.get(i), gui));
|
||||
}
|
||||
|
||||
public static <T> void createList(MinionsGui parent, Component title, IdMap<T> list, BiFunction<T, PaginatedList, GuiElementBuilder> display) {
|
||||
new PaginatedList(parent, title, list.size(), (i, gui) -> display.apply(list.byId(i), gui));
|
||||
}
|
||||
|
||||
private void addItems() {
|
||||
for(int i = 27 * page; i < Math.min(27 * (page + 1), size); i++) {
|
||||
gui.addSlot(display.apply(i, this));
|
||||
}
|
||||
|
||||
if(page > 0) {
|
||||
gui.setSlot(30, new GuiElementBuilder(Items.SPECTRAL_ARROW)
|
||||
.setItemName(Component.translatable("book.page_button.previous"))
|
||||
.setCallback(() -> {
|
||||
page--;
|
||||
addItems();
|
||||
})
|
||||
);
|
||||
} else {
|
||||
gui.clearSlot(30);
|
||||
}
|
||||
|
||||
if(27 * (page + 1) < size) {
|
||||
gui.setSlot(32, new GuiElementBuilder(Items.ARROW)
|
||||
.setItemName(Component.translatable("book.page_button.next"))
|
||||
.setCallback(() -> {
|
||||
page++;
|
||||
addItems();
|
||||
})
|
||||
);
|
||||
} else {
|
||||
gui.clearSlot(32);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,116 @@
|
||||
package io.github.skippyall.minions.gui.input;
|
||||
|
||||
import eu.pb4.sgui.api.elements.GuiElementBuilder;
|
||||
import eu.pb4.sgui.api.gui.SimpleGui;
|
||||
import io.github.skippyall.minions.gui.Displayable;
|
||||
import io.github.skippyall.minions.gui.GuiDisplay;
|
||||
import io.github.skippyall.minions.gui.MinionsGui;
|
||||
import io.github.skippyall.minions.gui.minion.SimpleMinionsGui;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.function.BiFunction;
|
||||
import java.util.function.Function;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.world.inventory.MenuType;
|
||||
import net.minecraft.world.item.Items;
|
||||
|
||||
public class ChoiceInput {
|
||||
public static <T> BiFunction<ServerPlayer, T, CompletableFuture<T>> createDialogOpener(MenuType<?> screen, Component title, Function<T, GuiDisplay> displayFunction, T[] values, @Nullable T fallback) {
|
||||
return (player, object) -> {
|
||||
CompletableFuture<T> future = new CompletableFuture<>();
|
||||
|
||||
SimpleGui gui = new SimpleGui(screen, player, false) {
|
||||
@Override
|
||||
public void onClose() {
|
||||
if(fallback == null) {
|
||||
future.cancel(false);
|
||||
} else {
|
||||
future.complete(fallback);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
gui.setTitle(title);
|
||||
|
||||
for(T value : values) {
|
||||
gui.addSlot(new GuiElementBuilder(displayFunction.apply(value).createItemStack())
|
||||
.setCallback(() -> future.complete(value))
|
||||
);
|
||||
}
|
||||
gui.open();
|
||||
return future;
|
||||
};
|
||||
}
|
||||
|
||||
public static <T extends Displayable> BiFunction<ServerPlayer, T, CompletableFuture<T>> createDialogOpener(T[] values) {
|
||||
return createDialogOpener(MenuType.GENERIC_9x3, Component.empty(), t -> t != null ? t.getDisplay() : null, values, null);
|
||||
}
|
||||
|
||||
public static CompletableFuture<Void> confirm(ServerPlayer player, Component title) {
|
||||
CompletableFuture<Void> future = new CompletableFuture<>();
|
||||
|
||||
SimpleGui gui = new SimpleGui(MenuType.GENERIC_3x3, player, false) {
|
||||
@Override
|
||||
public void onClose() {
|
||||
future.cancel(false);
|
||||
}
|
||||
};
|
||||
|
||||
gui.setTitle(title);
|
||||
|
||||
gui.setSlot(3, new GuiElementBuilder(Items.REDSTONE_BLOCK)
|
||||
.setName(Component.translatable("minions.gui.abort"))
|
||||
.setCallback(() -> future.cancel(false))
|
||||
);
|
||||
|
||||
gui.setSlot(5, new GuiElementBuilder(Items.EMERALD_BLOCK)
|
||||
.setName(Component.translatable("minions.gui.confirm"))
|
||||
.setCallback(() -> future.complete(null))
|
||||
);
|
||||
|
||||
gui.open();
|
||||
return future;
|
||||
}
|
||||
|
||||
public static CompletableFuture<Void> confirm(MinionsGui parent, Component title) {
|
||||
CompletableFuture<Void> future = new CompletableFuture<>();
|
||||
|
||||
new SimpleMinionsGui(parent, (onClose, me) -> {
|
||||
SimpleGui gui = new SimpleGui(MenuType.GENERIC_3x3, parent.getViewer(), false) {
|
||||
@Override
|
||||
public void onClose() {
|
||||
future.cancel(false);
|
||||
onClose.run();
|
||||
}
|
||||
};
|
||||
|
||||
gui.setTitle(title);
|
||||
|
||||
gui.setSlot(3, new GuiElementBuilder(Items.REDSTONE_BLOCK)
|
||||
.setName(Component.translatable("minions.gui.abort"))
|
||||
.setCallback(() -> future.cancel(false))
|
||||
);
|
||||
|
||||
gui.setSlot(5, new GuiElementBuilder(Items.EMERALD_BLOCK)
|
||||
.setName(Component.translatable("minions.gui.confirm"))
|
||||
.setCallback(() -> future.complete(null))
|
||||
);
|
||||
|
||||
gui.open();
|
||||
return gui;
|
||||
});
|
||||
return future;
|
||||
}
|
||||
|
||||
public static BiFunction<ServerPlayer, Boolean, CompletableFuture<Boolean>> inputBoolean(Component title) {
|
||||
return createDialogOpener(MenuType.GENERIC_3x3, title, value -> {
|
||||
if(value) {
|
||||
return new GuiDisplay.ItemBased(Items.EMERALD_BLOCK);
|
||||
} else {
|
||||
return new GuiDisplay.ItemBased(Items.REDSTONE_BLOCK);
|
||||
}
|
||||
}, new Boolean[]{false, true}, false);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,184 @@
|
||||
package io.github.skippyall.minions.gui.input;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Optional;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public interface Result<T, E> {
|
||||
static <T> Result<T, String> wrap(UnsafeOperation<T> toWrap) {
|
||||
return wrapCustomError(toWrap, Exception::getMessage);
|
||||
}
|
||||
|
||||
static <T, E> Result<T, E> wrapCustomError(UnsafeOperation<T> toWrap, E error) {
|
||||
return wrapCustomError(toWrap, e -> error);
|
||||
}
|
||||
|
||||
static <T, E> Result<T, E> wrapCustomError(UnsafeOperation<T> toWrap, Function<Exception, E> errorTransformer) {
|
||||
try {
|
||||
return new Result.Success<>(toWrap.run());
|
||||
} catch (Exception e) {
|
||||
return new Result.Error<>(errorTransformer.apply(e));
|
||||
}
|
||||
}
|
||||
|
||||
static <T, E> Result<T, E> ofNullable(@Nullable T value, E error) {
|
||||
if(value != null) {
|
||||
return new Success<>(value);
|
||||
} else {
|
||||
return new Error<>(error);
|
||||
}
|
||||
}
|
||||
|
||||
static <T, E> Result<T, E> ofNullable(@Nullable T value, Supplier<E> error) {
|
||||
if(value != null) {
|
||||
return new Success<>(value);
|
||||
} else {
|
||||
return new Error<>(error.get());
|
||||
}
|
||||
}
|
||||
|
||||
boolean isSuccess();
|
||||
|
||||
T getOrDefault(T defaultValue);
|
||||
|
||||
T getOrThrow();
|
||||
|
||||
E getErrorOrThrow();
|
||||
|
||||
@NotNull Optional<T> getOptional();
|
||||
|
||||
@NotNull Optional<E> getOptionalError();
|
||||
|
||||
void ifSuccess(@NotNull Consumer<T> handler);
|
||||
|
||||
void ifError(@NotNull Consumer<Error<T, E>> handler);
|
||||
|
||||
<U> Result<U,E> map(Function<T, U> mapper);
|
||||
|
||||
<U> Result<U,E> flatMap(Function<T, Result<U, E>> mapper);
|
||||
|
||||
<U> Result<T,U> mapError(Function<E, U> mapper);
|
||||
|
||||
record Success<T, E>(T result) implements Result<T, E> {
|
||||
@Override
|
||||
public boolean isSuccess() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public T getOrDefault(T defaultValue) {
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull Optional<E> getOptionalError() {
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public T getOrThrow() {
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public E getErrorOrThrow() {
|
||||
throw new RuntimeException("Result was not an Error");
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull Optional<T> getOptional() {
|
||||
return Optional.ofNullable(result);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void ifSuccess(@NotNull Consumer<T> handler) {
|
||||
handler.accept(result);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void ifError(@NotNull Consumer<Error<T, E>> handler) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public <U> Result<U, E> map(Function<T, U> mapper) {
|
||||
return new Success<>(mapper.apply(result));
|
||||
}
|
||||
|
||||
@Override
|
||||
public <U> Result<U, E> flatMap(Function<T, Result<U, E>> mapper) {
|
||||
return mapper.apply(result);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <U> Result<T, U> mapError(Function<E, U> mapper) {
|
||||
return new Success<>(result);
|
||||
}
|
||||
}
|
||||
|
||||
record Error<T, E>(E message) implements Result<T, E> {
|
||||
@Override
|
||||
public boolean isSuccess() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public T getOrDefault(
|
||||
T defaultValue) {
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
@Override
|
||||
public T getOrThrow() {
|
||||
throw new RuntimeException("Result was an error: " + message);
|
||||
}
|
||||
|
||||
@Override
|
||||
public E getErrorOrThrow() {
|
||||
return message;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull Optional<T> getOptional() {
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull Optional<E> getOptionalError() {
|
||||
return Optional.ofNullable(message);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void ifSuccess(@NotNull Consumer<T> handler) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void ifError(@NotNull Consumer<Error<T, E>> handler) {
|
||||
handler.accept(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <U> Result<U, E> map(Function<T, U> mapper) {
|
||||
return new Error<>(message);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <U> Result<U, E> flatMap(Function<T, Result<U, E>> mapper) {
|
||||
return new Error<>(message);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <U> Result<T, U> mapError(Function<E, U> mapper) {
|
||||
return new Error<>(mapper.apply(message));
|
||||
}
|
||||
}
|
||||
|
||||
interface UnsafeOperation<T> {
|
||||
T run() throws Exception;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,122 @@
|
||||
package io.github.skippyall.minions.gui.input;
|
||||
|
||||
import eu.pb4.sgui.api.elements.GuiElementBuilder;
|
||||
import eu.pb4.sgui.api.gui.AnvilInputGui;
|
||||
import io.github.skippyall.minions.gui.MinionsGui;
|
||||
import io.github.skippyall.minions.gui.minion.SimpleMinionsGui;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.function.Function;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.world.inventory.AnvilMenu;
|
||||
import net.minecraft.world.item.Items;
|
||||
|
||||
public class TextInput<T> extends AnvilInputGui {
|
||||
private final GuiElementBuilder valid = new GuiElementBuilder()
|
||||
.setItem(Items.EMERALD_BLOCK)
|
||||
.setName(Component.literal("OK"))
|
||||
.setCallback(this::onConfirm);
|
||||
|
||||
private final GuiElementBuilder invalid = new GuiElementBuilder()
|
||||
.setItem(Items.REDSTONE_BLOCK);
|
||||
private final Function<String, CompletableFuture<Result<T, Component>>> parser;
|
||||
private final CompletableFuture<T> future;
|
||||
private Result<T, Component> result;
|
||||
private boolean isConfirm;
|
||||
|
||||
public TextInput(ServerPlayer player, Component title, String defaultValue, Function<String, CompletableFuture<Result<T, Component>>> parser, CompletableFuture<T> future) {
|
||||
super(player, false);
|
||||
setTitle(title);
|
||||
setDefaultInputValue(defaultValue);
|
||||
this.parser = parser;
|
||||
this.future = future;
|
||||
|
||||
updateConfirmButton(defaultValue);
|
||||
}
|
||||
|
||||
public static <T> CompletableFuture<T> inputSync(ServerPlayer player, Component title, String defaultValue, Function<String, Result<T, Component>> parser) {
|
||||
return input(player, title, defaultValue, (String string) -> CompletableFuture.completedFuture(parser.apply(string)));
|
||||
}
|
||||
|
||||
public static <T> CompletableFuture<T> inputSync(MinionsGui gui, Component title, String defaultValue, Function<String, Result<T, Component>> parser) {
|
||||
return input(gui, title, defaultValue, (String string) -> CompletableFuture.completedFuture(parser.apply(string)));
|
||||
}
|
||||
|
||||
public static <T> CompletableFuture<T> input(ServerPlayer player, Component title, String defaultValue, Function<String, CompletableFuture<Result<T, Component>>> parser) {
|
||||
CompletableFuture<T> future = new CompletableFuture<>();
|
||||
new TextInput<>(player, title, defaultValue, parser, future).open();
|
||||
return future;
|
||||
}
|
||||
|
||||
public static <T> CompletableFuture<T> input(MinionsGui gui, Component title, String defaultValue, Function<String, CompletableFuture<Result<T, Component>>> parser) {
|
||||
CompletableFuture<T> future = new CompletableFuture<>();
|
||||
new SimpleMinionsGui(gui, (onClose, me) -> {
|
||||
TextInput<T> input = new TextInput<>(gui.getViewer(), title, defaultValue, parser, future);
|
||||
future.handle((v, e) -> {
|
||||
onClose.run();
|
||||
return null;
|
||||
});
|
||||
input.open();
|
||||
return input;
|
||||
});
|
||||
return future;
|
||||
}
|
||||
|
||||
public static CompletableFuture<String> inputString(ServerPlayer player, Component title, String defaultValue) {
|
||||
return inputSync(player, title, defaultValue, Result.Success::new);
|
||||
}
|
||||
|
||||
public static CompletableFuture<String> inputString(MinionsGui gui, Component title, String defaultValue) {
|
||||
return inputSync(gui, title, defaultValue, Result.Success::new);
|
||||
}
|
||||
|
||||
public static CompletableFuture<Long> inputLong(ServerPlayer player, Component title, String defaultValue) {
|
||||
return inputSync(player, title, defaultValue, string -> Result.wrapCustomError(() -> Long.valueOf(string), Component.translatable("minions.command.input.int.fail")));
|
||||
}
|
||||
|
||||
public static CompletableFuture<Long> inputLong(MinionsGui gui, Component title, String defaultValue) {
|
||||
return inputSync(gui, title, defaultValue, string -> Result.wrapCustomError(() -> Long.valueOf(string), Component.translatable("minions.command.input.int.fail")));
|
||||
}
|
||||
|
||||
public static CompletableFuture<Double> inputDouble(ServerPlayer player, Component title, String defaultValue) {
|
||||
return inputSync(player, title, defaultValue, string -> Result.wrapCustomError(() -> Double.valueOf(string), Component.translatable("minions.command.input.float.fail")));
|
||||
}
|
||||
|
||||
public static CompletableFuture<Double> inputDouble(MinionsGui gui, Component title, String defaultValue) {
|
||||
return inputSync(gui, title, defaultValue, string -> Result.wrapCustomError(() -> Double.valueOf(string), Component.translatable("minions.command.input.float.fail")));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onInput(String input) {
|
||||
updateConfirmButton(input);
|
||||
}
|
||||
|
||||
public void updateConfirmButton(String input) {
|
||||
parser.apply(input).thenAccept(result -> {
|
||||
this.result = result;
|
||||
if(result.isSuccess()) {
|
||||
setSlot(AnvilMenu.RESULT_SLOT, valid);
|
||||
} else {
|
||||
Component text = result.getErrorOrThrow();
|
||||
setSlot(AnvilMenu.RESULT_SLOT, invalid.setName(text));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClose() {
|
||||
if(!future.isDone() && !isConfirm) {
|
||||
future.cancel(false);
|
||||
}
|
||||
}
|
||||
|
||||
public void onConfirm() {
|
||||
if(result != null) {
|
||||
result.ifSuccess(success -> {
|
||||
isConfirm = true;
|
||||
close();
|
||||
future.complete(success);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,162 @@
|
||||
package io.github.skippyall.minions.gui.instruction;
|
||||
|
||||
import eu.pb4.sgui.api.elements.GuiElementBuilder;
|
||||
import eu.pb4.sgui.api.gui.SimpleGui;
|
||||
import io.github.skippyall.minions.gui.GuiDisplay;
|
||||
import io.github.skippyall.minions.gui.MinionsGui;
|
||||
import io.github.skippyall.minions.gui.PaginatedList;
|
||||
import io.github.skippyall.minions.gui.minion.GuiContext;
|
||||
import io.github.skippyall.minions.minion.MinionRuntime;
|
||||
import io.github.skippyall.minions.minion.fakeplayer.MinionFakePlayer;
|
||||
import io.github.skippyall.minions.program.instruction.ConfiguredInstruction;
|
||||
import io.github.skippyall.minions.program.supplier.Parameter;
|
||||
import io.github.skippyall.minions.program.supplier.ValueSupplier;
|
||||
import io.github.skippyall.minions.program.supplier.ValueSupplierList;
|
||||
import io.github.skippyall.minions.program.supplier.ValueSupplierType;
|
||||
import io.github.skippyall.minions.registration.MinionRegistries;
|
||||
import io.github.skippyall.minions.util.TranslationUtil;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.world.inventory.MenuType;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.item.Items;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class ArgumentGui extends MinionsGui {
|
||||
private final GuiContext.ValueSupplier context;
|
||||
private final MinionFakePlayer minion;
|
||||
private final ConfiguredInstruction<MinionRuntime> instruction;
|
||||
private final Parameter<?> parameter;
|
||||
|
||||
private SimpleGui gui;
|
||||
|
||||
private @Nullable ValueSupplierType<MinionRuntime> argumentType;
|
||||
private @Nullable ValueSupplierList.ValueSupplierEntry<?, MinionRuntime> entry;
|
||||
|
||||
public ArgumentGui(MinionsGui parent, GuiContext.ValueSupplier context) {
|
||||
super(parent);
|
||||
minion = context.getMinion();
|
||||
instruction = context.getInstruction();
|
||||
this.parameter = context.getParameter();
|
||||
this.context = context;
|
||||
|
||||
this.entry = instruction.getArguments().getEntry(parameter);
|
||||
if(entry != null) {
|
||||
this.argumentType = entry.getSupplier().getType();
|
||||
}
|
||||
open();
|
||||
}
|
||||
|
||||
public String getInstructionName() {
|
||||
return context.getName();
|
||||
}
|
||||
|
||||
public @Nullable ValueSupplier<?, MinionRuntime> getArgument() {
|
||||
if(entry != null) {
|
||||
return entry.getSupplier();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void open() {
|
||||
gui = new SimpleGui(MenuType.GENERIC_3x3, viewer, false) {
|
||||
@Override
|
||||
public void onClose() {
|
||||
onBackingClosed();
|
||||
}
|
||||
};
|
||||
gui.setTitle(Component.translatable(
|
||||
"minions.gui.instruction.argument.title",
|
||||
parameter.name(),
|
||||
Component.translatable(TranslationUtil.getTranslationKey(parameter.type(), MinionRegistries.VALUE_TYPES))
|
||||
));
|
||||
|
||||
updateTypeConfiguration();
|
||||
updateArgumentConfiguration();
|
||||
updateConverterConfiguration();
|
||||
gui.open();
|
||||
}
|
||||
|
||||
private void updateTypeConfiguration() {
|
||||
ItemStack displayStack;
|
||||
if(argumentType != null) {
|
||||
displayStack = GuiDisplay.getDisplayStack(MinionRegistries.VALUE_SUPPLIER_TYPES, argumentType, viewer.registryAccess());
|
||||
} else {
|
||||
displayStack = new ItemStack(Items.BARRIER);
|
||||
}
|
||||
|
||||
gui.setSlot(3, new GuiElementBuilder(displayStack)
|
||||
.setName(Component.translatable("minions.gui.instruction.argument.configure.type"))
|
||||
.addLoreLine(Component.translatable(TranslationUtil.getTranslationKey(
|
||||
argumentType,
|
||||
MinionRegistries.VALUE_SUPPLIER_TYPES,
|
||||
"minions.gui.not_set"
|
||||
)))
|
||||
.setCallback(this::selectArgumentType)
|
||||
);
|
||||
}
|
||||
|
||||
private void updateArgumentConfiguration() {
|
||||
if(argumentType != null) {
|
||||
gui.setSlot(4, new GuiElementBuilder(Items.STRUCTURE_VOID)
|
||||
.setName(Component.translatable("minions.gui.instruction.argument.configure.data"))
|
||||
.addLoreLine(getArgument() != null ? getArgument().getDisplayText() : Component.translatable("minions.gui.not_set"))
|
||||
.setCallback(() -> argumentType.openConfiguration(this, parameter.type(), getArgument())
|
||||
.thenAccept(newArgument -> {
|
||||
setArgument(newArgument);
|
||||
if(child != null) {
|
||||
child.close();
|
||||
}
|
||||
})
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
private void updateConverterConfiguration() {
|
||||
if(entry != null) {
|
||||
gui.setSlot(5, new GuiElementBuilder(Items.CRAFTER)
|
||||
.setName(Component.translatable("minions.gui.instruction.converters"))
|
||||
.setCallback(this::configureConvertersMenu)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void closeBacking() {
|
||||
gui.close();
|
||||
}
|
||||
|
||||
public void setArgumentType(ValueSupplierType<MinionRuntime> type) {
|
||||
this.argumentType = type;
|
||||
if(entry != null && getArgument().getType() != argumentType) {
|
||||
instruction.getArguments().removeEntry(parameter);
|
||||
entry = null;
|
||||
}
|
||||
updateTypeConfiguration();
|
||||
}
|
||||
|
||||
public void setArgument(ValueSupplier<?, MinionRuntime> argument) {
|
||||
if(entry != null) {
|
||||
entry.setSupplier(argument);
|
||||
} else {
|
||||
entry = instruction.getArguments().createEntry(parameter, argument);
|
||||
}
|
||||
}
|
||||
|
||||
public void selectArgumentType() {
|
||||
PaginatedList.createList(this, Component.translatable("minions.gui.instruction.argument.configure.type.title"), MinionRegistries.VALUE_SUPPLIER_TYPES, (type, me) ->
|
||||
new GuiElementBuilder(GuiDisplay.getDisplayStackWithName(MinionRegistries.VALUE_SUPPLIER_TYPES, type, viewer.registryAccess()))
|
||||
.setCallback(() -> {
|
||||
setArgumentType(type);
|
||||
me.close();
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
public void configureConvertersMenu() {
|
||||
if(entry != null) {
|
||||
new ConverterListGui(this, entry.getConverters(), entry.getSupplier().getValueType(), entry.getParameter().type());
|
||||
}
|
||||
}
|
||||
}
|
||||
+139
@@ -0,0 +1,139 @@
|
||||
package io.github.skippyall.minions.gui.instruction;
|
||||
|
||||
import eu.pb4.sgui.api.elements.GuiElementBuilder;
|
||||
import eu.pb4.sgui.api.gui.SimpleGui;
|
||||
import io.github.skippyall.minions.clipboard.ClipboardItem;
|
||||
import io.github.skippyall.minions.gui.MinionsGui;
|
||||
import io.github.skippyall.minions.gui.input.ChoiceInput;
|
||||
import io.github.skippyall.minions.gui.minion.GuiContext;
|
||||
import io.github.skippyall.minions.minion.MinionListener;
|
||||
import io.github.skippyall.minions.minion.MinionRuntime;
|
||||
import io.github.skippyall.minions.minion.fakeplayer.MinionFakePlayer;
|
||||
import io.github.skippyall.minions.program.instruction.ConfiguredInstruction;
|
||||
import io.github.skippyall.minions.program.instruction.ConfiguredInstructionListener;
|
||||
import io.github.skippyall.minions.program.supplier.Parameter;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.sounds.SoundEvents;
|
||||
import net.minecraft.sounds.SoundSource;
|
||||
import net.minecraft.world.inventory.MenuType;
|
||||
import net.minecraft.world.item.Items;
|
||||
|
||||
public class ConfigureInstructionGui extends MinionsGui implements ConfiguredInstructionListener, MinionListener {
|
||||
private String name;
|
||||
private final ConfiguredInstruction<MinionRuntime> instruction;
|
||||
private final MinionFakePlayer minion;
|
||||
|
||||
private final GuiContext.Instruction context;
|
||||
|
||||
private SimpleGui gui;
|
||||
|
||||
public ConfigureInstructionGui(MinionsGui parent, GuiContext.Instruction context) {
|
||||
super(parent);
|
||||
this.name = context.getName();
|
||||
this.instruction = context.getInstruction();
|
||||
this.minion = context.getMinion();
|
||||
this.context = context;
|
||||
minion.addMinionListener(this);
|
||||
instruction.addListener(this);
|
||||
open();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void open() {
|
||||
gui = new SimpleGui(MenuType.GENERIC_9x3, viewer, false) {
|
||||
@Override
|
||||
public void onClose() {
|
||||
onBackingClosed();
|
||||
}
|
||||
};
|
||||
|
||||
gui.setTitle(Component.literal(name));
|
||||
|
||||
gui.setSlot(7, new GuiElementBuilder(Items.ANVIL)
|
||||
.setName(Component.translatable("minions.gui.instruction.configure.rename"))
|
||||
.setCallback(() -> InstructionGui.inputInstructionName(this, context, name).thenAccept(newName -> {
|
||||
minion.getInstructionManager().setInstructionName(name, newName);
|
||||
reopen();
|
||||
}))
|
||||
);
|
||||
|
||||
gui.setSlot(8, new GuiElementBuilder(Items.LAVA_BUCKET)
|
||||
.setName(Component.translatable("minions.gui.instruction.configure.delete"))
|
||||
.setCallback(() -> ChoiceInput.confirm(this, Component.translatable("minions.gui.instruction.configure.delete.confirm", name))
|
||||
.thenAccept(v -> {
|
||||
minion.getInstructionManager().removeInstruction(name);
|
||||
close();
|
||||
}))
|
||||
);
|
||||
|
||||
updateSuppliers();
|
||||
|
||||
gui.setSlot(13, InstructionGui.createInstructionElement(instruction.getInstruction(), viewer.registryAccess()));
|
||||
|
||||
gui.setSlot(25, new GuiElementBuilder(Items.FEATHER)
|
||||
.setName(Component.translatable("minions.gui.instruction.configure.copy"))
|
||||
.addLoreLine(Component.translatable("minions.gui.instruction.configure.copy.description"))
|
||||
.setCallback(() -> {
|
||||
viewer.getInventory().placeItemBackInInventory(ClipboardItem.createInstructionReference(minion, name), true);
|
||||
viewer.playNotifySound(SoundEvents.NOTE_BLOCK_CHIME.value(), SoundSource.BLOCKS, 1, 1);
|
||||
})
|
||||
);
|
||||
|
||||
updateRunSlot();
|
||||
gui.open();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void closeBacking() {
|
||||
gui.close();
|
||||
minion.removeMinionListener(this);
|
||||
instruction.removeListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onInstructionRename(MinionFakePlayer minion, ConfiguredInstruction<?> instruction, String oldName, String newName) {
|
||||
gui.setTitle(Component.literal(newName));
|
||||
name = newName;
|
||||
context.setName(newName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRun(ConfiguredInstruction<?> instruction) {
|
||||
updateRunSlot();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStop(ConfiguredInstruction<?> instruction) {
|
||||
updateRunSlot();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSupplierChange(ConfiguredInstruction<?> instruction, Parameter<?> parameter) {
|
||||
updateSuppliers();
|
||||
}
|
||||
|
||||
private void updateRunSlot() {
|
||||
if(!instruction.isRunning()) {
|
||||
gui.setSlot(26, new GuiElementBuilder(Items.ARROW)
|
||||
.setName(Component.translatable("minions.gui.instruction.run"))
|
||||
.setCallback(() -> instruction.run(minion.getInstructionManager()))
|
||||
);
|
||||
} else {
|
||||
gui.setSlot(26, new GuiElementBuilder(Items.BARRIER)
|
||||
.setName(Component.translatable("minions.gui.instruction.stop"))
|
||||
.setCallback(() -> instruction.stop(minion.getInstructionManager()))
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
private void updateSuppliers() {
|
||||
int slot = 12;
|
||||
for(Parameter<?> parameter : instruction.getInstruction().getParameters().reversed()) {
|
||||
gui.setSlot(slot, InstructionGui.createParameterElement(parameter, instruction.getArguments().getArgument(parameter), viewer.registryAccess())
|
||||
.setCallback(() -> new ArgumentGui(this, GuiContext.ValueSupplier.create(context, parameter)))
|
||||
);
|
||||
slot--;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,131 @@
|
||||
package io.github.skippyall.minions.gui.instruction;
|
||||
|
||||
import eu.pb4.sgui.api.elements.GuiElementBuilder;
|
||||
import eu.pb4.sgui.api.gui.SimpleGui;
|
||||
import io.github.skippyall.minions.gui.GuiDisplay;
|
||||
import io.github.skippyall.minions.gui.MinionsGui;
|
||||
import io.github.skippyall.minions.gui.PaginatedList;
|
||||
import io.github.skippyall.minions.program.conversion.ConverterList;
|
||||
import io.github.skippyall.minions.program.conversion.ValueConverter;
|
||||
import io.github.skippyall.minions.program.conversion.ValueConverterType;
|
||||
import io.github.skippyall.minions.program.value.ValueType;
|
||||
import io.github.skippyall.minions.registration.MinionRegistries;
|
||||
import net.minecraft.core.RegistryAccess;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.world.inventory.MenuType;
|
||||
import net.minecraft.world.item.Items;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class ConverterGui extends MinionsGui {
|
||||
private @Nullable ValueConverterType<?> valueConverterType;
|
||||
private @Nullable ValueConverter<?,?> converter;
|
||||
private ConverterList list;
|
||||
private ValueType<?> from, to;
|
||||
|
||||
private SimpleGui gui;
|
||||
private boolean isNew;
|
||||
private int index;
|
||||
|
||||
public ConverterGui(MinionsGui parent, @Nullable ValueConverter<?,?> converter, ValueType<?> from, ValueType<?> to, ConverterList list, boolean isNew, int index) {
|
||||
super(parent);
|
||||
open();
|
||||
this.converter = converter;
|
||||
if(converter != null) {
|
||||
this.valueConverterType = converter.getType();
|
||||
}
|
||||
this.from = from;
|
||||
this.to = to;
|
||||
this.list = list;
|
||||
this.isNew = isNew;
|
||||
this.index = index;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void open() {
|
||||
gui = new SimpleGui(MenuType.GENERIC_3x3, viewer, false) {
|
||||
@Override
|
||||
public void onClose() {
|
||||
onBackingClosed();
|
||||
}
|
||||
};
|
||||
|
||||
gui.setTitle(Component.translatable("minions.gui.instruction.converter.title"));
|
||||
|
||||
updateTypeDisplay();
|
||||
updateConverterDisplay();
|
||||
|
||||
gui.open();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void reopen() {
|
||||
gui.open();
|
||||
}
|
||||
|
||||
private void updateTypeDisplay() {
|
||||
gui.setSlot(3, new GuiElementBuilder(GuiDisplay.getDisplayStackWithName(MinionRegistries.VALUE_CONVERTER_TYPES, valueConverterType, viewer.registryAccess()))
|
||||
.setCallback(this::configureType)
|
||||
);
|
||||
}
|
||||
|
||||
private void updateConverterDisplay() {
|
||||
gui.setSlot(5, new GuiElementBuilder(Items.STRUCTURE_VOID)
|
||||
.setName(Component.translatable("minions.gui.instruction.converter.title"))
|
||||
.addLoreLine(converter == null ? Component.translatable("minions.gui.not_set") : converter.getDisplayText())
|
||||
.setCallback(this::configureData)
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void closeBacking() {
|
||||
gui.close();
|
||||
}
|
||||
|
||||
private void setType(ValueConverterType<?> valueConverterType) {
|
||||
this.valueConverterType = valueConverterType;
|
||||
updateTypeDisplay();
|
||||
}
|
||||
|
||||
public void setConverter(ValueConverter<?,?> converter) {
|
||||
this.converter = converter;
|
||||
if(isNew) {
|
||||
list.getConverters().add(index, converter);
|
||||
isNew = false;
|
||||
} else {
|
||||
list.getConverters().set(index, converter);
|
||||
}
|
||||
updateConverterDisplay();
|
||||
}
|
||||
|
||||
private void configureType() {
|
||||
PaginatedList.createList(
|
||||
this,
|
||||
Component.translatable("minions.gui.instruction.converter.type.title"),
|
||||
MinionRegistries.VALUE_CONVERTER_TYPES,
|
||||
(type, me) -> new GuiElementBuilder(
|
||||
GuiDisplay.getDisplayStackWithName(MinionRegistries.VALUE_CONVERTER_TYPES, type, viewer.registryAccess())
|
||||
).setCallback(() -> {
|
||||
setType(type);
|
||||
me.close();
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
private void configureData() {
|
||||
if(valueConverterType != null) {
|
||||
valueConverterType.configure(this, from, to, converter)
|
||||
.thenAccept(newConverter -> {
|
||||
setConverter(newConverter);
|
||||
if(child != null) {
|
||||
child.close();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public static GuiElementBuilder createConverterElement(ValueConverter<?,?> converter, RegistryAccess manager) {
|
||||
GuiElementBuilder builder = new GuiElementBuilder(GuiDisplay.getDisplayStack(MinionRegistries.VALUE_CONVERTER_TYPES, converter.getType(), manager));
|
||||
builder.addLoreLine(converter.getDisplayText());
|
||||
return builder;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,109 @@
|
||||
package io.github.skippyall.minions.gui.instruction;
|
||||
|
||||
import eu.pb4.sgui.api.elements.GuiElementBuilder;
|
||||
import eu.pb4.sgui.api.gui.SimpleGui;
|
||||
import io.github.skippyall.minions.gui.GuiDisplay;
|
||||
import io.github.skippyall.minions.gui.MinionsGui;
|
||||
import io.github.skippyall.minions.program.conversion.ConverterList;
|
||||
import io.github.skippyall.minions.program.conversion.ValueConverter;
|
||||
import io.github.skippyall.minions.program.value.ValueType;
|
||||
import io.github.skippyall.minions.registration.MinionRegistries;
|
||||
import io.github.skippyall.minions.util.TranslationUtil;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.world.inventory.MenuType;
|
||||
import net.minecraft.world.item.Items;
|
||||
|
||||
public class ConverterListGui extends MinionsGui {
|
||||
private ConverterList converters;
|
||||
|
||||
private SimpleGui gui;
|
||||
private int page = 0;
|
||||
|
||||
private ValueType<?> inputType;
|
||||
private ValueType<?> outputType;
|
||||
|
||||
public ConverterListGui(MinionsGui parent, ConverterList converters, ValueType<?> inputType, ValueType<?> outputType) {
|
||||
super(parent);
|
||||
this.converters = converters;
|
||||
this.inputType = inputType;
|
||||
this.outputType = outputType;
|
||||
open();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void open() {
|
||||
gui = new SimpleGui(MenuType.GENERIC_9x3, viewer, false) {
|
||||
@Override
|
||||
public void onClose() {
|
||||
onBackingClosed();
|
||||
}
|
||||
};
|
||||
|
||||
gui.setTitle(Component.translatable("minions.gui.instruction.converters"));
|
||||
|
||||
updateConverters();
|
||||
|
||||
gui.setSlot(21, new GuiElementBuilder(Items.SPECTRAL_ARROW)
|
||||
.setCallback(() -> {
|
||||
if(page > 0) {
|
||||
page--;
|
||||
updateConverters();
|
||||
}
|
||||
})
|
||||
);
|
||||
|
||||
gui.setSlot(23, new GuiElementBuilder(Items.ARROW)
|
||||
.setCallback(() -> {
|
||||
if(page * 4 + 4 < converters.getConverters().size()) {
|
||||
page++;
|
||||
updateConverters();
|
||||
}
|
||||
})
|
||||
);
|
||||
|
||||
gui.open();
|
||||
}
|
||||
|
||||
public void updateConverters() {
|
||||
int lastConverter = Math.min(5, converters.getConverters().size() + 2 - page * 4);
|
||||
for(int i = 0; i < lastConverter; i++) {
|
||||
//Each page has 5 converters, but the last is displayed on the next page as well
|
||||
int converterIndex = page * 4 + i;
|
||||
//without input element
|
||||
int actualConverterIndex = converterIndex - 1;
|
||||
int slot = 9 + 2 * i;
|
||||
if(converterIndex == 0) {
|
||||
gui.setSlot(slot, new GuiElementBuilder(Items.DROPPER));
|
||||
} else if(converterIndex == converters.getConverters().size() + 1) {
|
||||
gui.setSlot(slot, new GuiElementBuilder(Items.HOPPER));
|
||||
} else {
|
||||
ValueConverter<?, ?> converter = converters.getConverters().get(actualConverterIndex);
|
||||
ValueType<?> fromType = actualConverterIndex >= 1 ? converters.getConverters().get(actualConverterIndex - 1).getTo() : inputType;
|
||||
ValueType<?> toType = actualConverterIndex < converters.getConverters().size() - 1 ? converters.getConverters().get(actualConverterIndex + 1).getFrom() : outputType;
|
||||
|
||||
gui.setSlot(slot, new GuiElementBuilder(GuiDisplay.getDisplayStackWithName(MinionRegistries.VALUE_CONVERTER_TYPES, converter.getType(), viewer.registryAccess()))
|
||||
.addLoreLine(converter.getDisplayText())
|
||||
.setCallback(() -> new ConverterGui(this, converter, fromType, toType, converters, false, actualConverterIndex))
|
||||
);
|
||||
}
|
||||
if(i != 4 && actualConverterIndex != converters.getConverters().size()) {
|
||||
ValueType<?> fromType = actualConverterIndex >= 0 ? converters.getConverters().get(actualConverterIndex).getTo() : inputType;
|
||||
ValueType<?> toType = actualConverterIndex < converters.getConverters().size() - 1 ? converters.getConverters().get(actualConverterIndex + 1).getFrom() : outputType;
|
||||
|
||||
gui.setSlot(slot + 1, new GuiElementBuilder(Items.MAGENTA_GLAZED_TERRACOTTA)
|
||||
.setName(Component.translatable(
|
||||
"minions.gui.instruction.converters.cast",
|
||||
Component.translatable(TranslationUtil.getTranslationKey(fromType, MinionRegistries.VALUE_TYPES)),
|
||||
Component.translatable(TranslationUtil.getTranslationKey(toType, MinionRegistries.VALUE_TYPES))
|
||||
))
|
||||
.setCallback(() -> new ConverterGui(this, null, fromType, toType, converters, true, actualConverterIndex + 1))
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void closeBacking() {
|
||||
gui.close();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,179 @@
|
||||
package io.github.skippyall.minions.gui.instruction;
|
||||
|
||||
import eu.pb4.sgui.api.elements.GuiElementBuilder;
|
||||
import eu.pb4.sgui.api.gui.SimpleGui;
|
||||
import io.github.skippyall.minions.gui.GuiDisplay;
|
||||
import io.github.skippyall.minions.gui.MinionsGui;
|
||||
import io.github.skippyall.minions.gui.input.Result;
|
||||
import io.github.skippyall.minions.gui.input.TextInput;
|
||||
import io.github.skippyall.minions.gui.minion.GuiContext;
|
||||
import io.github.skippyall.minions.gui.minion.SimpleMinionsGui;
|
||||
import io.github.skippyall.minions.minion.MinionRuntime;
|
||||
import io.github.skippyall.minions.minion.fakeplayer.MinionFakePlayer;
|
||||
import io.github.skippyall.minions.module.MinionModule;
|
||||
import io.github.skippyall.minions.program.instruction.ConfiguredInstruction;
|
||||
import io.github.skippyall.minions.program.instruction.InstructionType;
|
||||
import io.github.skippyall.minions.program.supplier.Parameter;
|
||||
import io.github.skippyall.minions.program.supplier.ValueSupplier;
|
||||
import io.github.skippyall.minions.registration.MinionComponentTypes;
|
||||
import io.github.skippyall.minions.registration.MinionRegistries;
|
||||
import io.github.skippyall.minions.util.TranslationUtil;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.NoSuchElementException;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import net.minecraft.core.RegistryAccess;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.world.inventory.MenuType;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.item.Items;
|
||||
|
||||
public class InstructionGui {
|
||||
public static MinionsGui openInstructionMainMenu(MinionsGui parent, GuiContext.Minion context) {
|
||||
return new SimpleMinionsGui(parent, (onClose, me) -> {
|
||||
ServerPlayer player = parent.getViewer();
|
||||
|
||||
SimpleGui gui = new SimpleGui(MenuType.GENERIC_3x3, player, false) {
|
||||
@Override
|
||||
public void onClose() {
|
||||
onClose.run();
|
||||
}
|
||||
};
|
||||
gui.setTitle(Component.translatable("minions.gui.instruction.title"));
|
||||
|
||||
gui.setSlot(3, new GuiElementBuilder()
|
||||
.setItem(Items.BOOK)
|
||||
.setName(Component.translatable("minions.gui.instruction.list"))
|
||||
.setCallback(() -> new InstructionListGui(me, context))
|
||||
);
|
||||
gui.setSlot(5, new GuiElementBuilder()
|
||||
.setItem(Items.WRITABLE_BOOK)
|
||||
.setName(Component.translatable("minions.gui.instruction.create"))
|
||||
.setCallback(() -> createNewInstruction(me, context))
|
||||
);
|
||||
|
||||
gui.open();
|
||||
return gui;
|
||||
});
|
||||
}
|
||||
|
||||
public static void createNewInstruction(MinionsGui parent, GuiContext.Minion context) {
|
||||
MinionFakePlayer minion = context.getMinion();
|
||||
ServerPlayer viewer = parent.getViewer();
|
||||
selectInstructionModuleMenu(parent, context).thenAccept(instructionType ->
|
||||
inputInstructionName(parent, context, "Instruction").thenAccept(name -> {
|
||||
if (!minion.isRemoved() && !minion.hasDisconnected()) {
|
||||
ConfiguredInstruction<MinionRuntime> configuredInstruction = minion.getInstructionManager().createInstruction(name, instructionType);
|
||||
new ConfigureInstructionGui(parent, GuiContext.Instruction.create(context, configuredInstruction, name));
|
||||
}
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
public static CompletableFuture<String> inputInstructionName(MinionsGui parent, GuiContext.Minion context, String defaultValue) {
|
||||
return TextInput.inputSync(parent, Component.translatable("minions.gui.instruction.enter_name"), defaultValue, name -> {
|
||||
if (context.getMinion().getInstructionManager().hasInstruction(name)) {
|
||||
return new Result.Error<>(Component.translatable("minions.gui.instruction.name_already_used"));
|
||||
}
|
||||
return new Result.Success<>(name);
|
||||
});
|
||||
}
|
||||
|
||||
public static boolean checkInstructionExists(String name, ConfiguredInstruction<?> instruction, MinionFakePlayer minion, ServerPlayer player) {
|
||||
boolean stillExists = !minion.isRemoved() && !minion.hasDisconnected() && minion.getInstructionManager().getInstruction(name) == instruction;
|
||||
if (!stillExists) {
|
||||
player.closeContainer();
|
||||
player.sendSystemMessage(Component.translatable("minions.gui.instruction.removed"));
|
||||
}
|
||||
return stillExists;
|
||||
}
|
||||
|
||||
public static CompletableFuture<InstructionType<MinionRuntime>> selectInstructionModuleMenu(MinionsGui parent, GuiContext.Minion context) {
|
||||
MinionFakePlayer minion = context.getMinion();
|
||||
ServerPlayer viewer = parent.getViewer();
|
||||
|
||||
if (minion.getModuleInventory().getModules().isEmpty()) {
|
||||
viewer.sendSystemMessage(Component.translatable("minions.gui.instruction.no_modules"));
|
||||
return CompletableFuture.failedFuture(new NoSuchElementException("No modules"));
|
||||
}
|
||||
|
||||
CompletableFuture<InstructionType<MinionRuntime>> future = new CompletableFuture<>();
|
||||
|
||||
new SimpleMinionsGui(parent, (closeHandler, me) -> {
|
||||
SimpleGui gui = new SimpleGui(MenuType.GENERIC_9x3, viewer, false) {
|
||||
@Override
|
||||
public void onClose() {
|
||||
if (!future.isDone()) {
|
||||
future.cancel(false);
|
||||
}
|
||||
closeHandler.run();
|
||||
}
|
||||
};
|
||||
gui.setTitle(Component.translatable("minions.gui.instruction.select_instruction"));
|
||||
|
||||
for (int i = 0; i < minion.getModuleInventory().getContainerSize(); i++) {
|
||||
ItemStack moduleItem = minion.getModuleInventory().getItem(i);
|
||||
MinionModule module = moduleItem.get(MinionComponentTypes.MODULE);
|
||||
if (module != null && !module.instructions().isEmpty()) {
|
||||
gui.addSlot(new GuiElementBuilder(moduleItem)
|
||||
.setCallback(() -> selectInstructionMenu(parent, context, module)
|
||||
.thenApply(future::complete)
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
gui.open();
|
||||
return gui;
|
||||
});
|
||||
return future;
|
||||
}
|
||||
|
||||
public static CompletableFuture<InstructionType<MinionRuntime>> selectInstructionMenu(MinionsGui parent, GuiContext.Minion context, MinionModule module) {
|
||||
CompletableFuture<InstructionType<MinionRuntime>> future = new CompletableFuture<>();
|
||||
|
||||
new SimpleMinionsGui(parent, (closeHandler, me) -> {
|
||||
SimpleGui gui = new SimpleGui(MenuType.GENERIC_9x3, parent.getViewer(), false) {
|
||||
@Override
|
||||
public void onClose() {
|
||||
if (!future.isDone()) {
|
||||
future.cancel(false);
|
||||
}
|
||||
closeHandler.run();
|
||||
}
|
||||
};
|
||||
gui.setTitle(Component.translatable("minions.gui.instruction.select_instruction"));
|
||||
|
||||
for (InstructionType<MinionRuntime> instructionType : module.instructions()) {
|
||||
gui.addSlot(createInstructionElement(instructionType, parent.getViewer().registryAccess())
|
||||
.setCallback(() -> future.complete(instructionType))
|
||||
);
|
||||
}
|
||||
|
||||
gui.open();
|
||||
return gui;
|
||||
});
|
||||
return future;
|
||||
}
|
||||
|
||||
public static GuiElementBuilder createInstructionElement(InstructionType<MinionRuntime> instructionType, RegistryAccess manager) {
|
||||
GuiElementBuilder instructionBuilder;
|
||||
if (instructionType != null) {
|
||||
instructionBuilder = new GuiElementBuilder(GuiDisplay.getDisplayStackWithName(MinionRegistries.INSTRUCTION_TYPES, instructionType, manager));
|
||||
} else {
|
||||
instructionBuilder = new GuiElementBuilder(Items.RED_WOOL)
|
||||
.setName(Component.translatable("minions.gui.instruction.no_instruction_set"));
|
||||
}
|
||||
return instructionBuilder;
|
||||
}
|
||||
|
||||
public static GuiElementBuilder createParameterElement(Parameter<?> parameter, @Nullable ValueSupplier<?,?> valueSupplier, RegistryAccess manager) {
|
||||
GuiElementBuilder builder = new GuiElementBuilder(GuiDisplay.getDisplayStack(MinionRegistries.VALUE_TYPES, parameter.type(), manager))
|
||||
.setName(Component.translatable("minions.gui.instruction.parameter", parameter.name(), Component.translatable(TranslationUtil.getTranslationKey(parameter.type(), MinionRegistries.VALUE_TYPES))));
|
||||
if(valueSupplier != null) {
|
||||
builder.addLoreLine(Component.translatable("minions.gui.instruction.argument", valueSupplier.getDisplayText()));
|
||||
}
|
||||
return builder;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
package io.github.skippyall.minions.gui.instruction;
|
||||
|
||||
import eu.pb4.sgui.api.elements.GuiElementBuilder;
|
||||
import eu.pb4.sgui.api.gui.SimpleGui;
|
||||
import io.github.skippyall.minions.gui.GuiDisplay;
|
||||
import io.github.skippyall.minions.gui.MinionsGui;
|
||||
import io.github.skippyall.minions.gui.minion.GuiContext;
|
||||
import io.github.skippyall.minions.minion.MinionListener;
|
||||
import io.github.skippyall.minions.minion.MinionRuntime;
|
||||
import io.github.skippyall.minions.minion.fakeplayer.MinionFakePlayer;
|
||||
import io.github.skippyall.minions.program.instruction.ConfiguredInstruction;
|
||||
import io.github.skippyall.minions.registration.MinionRegistries;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.world.inventory.MenuType;
|
||||
|
||||
public class InstructionListGui extends MinionsGui implements MinionListener {
|
||||
private final GuiContext.Minion context;
|
||||
private final MinionFakePlayer minion;
|
||||
private SimpleGui gui;
|
||||
|
||||
public InstructionListGui(MinionsGui parent, GuiContext.Minion context) {
|
||||
super(parent);
|
||||
this.context = context;
|
||||
this.minion = context.getMinion();
|
||||
open();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onInstructionsUpdate(MinionFakePlayer minion) {
|
||||
resetInstructionList();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void open() {
|
||||
minion.addMinionListener(this);
|
||||
gui = new SimpleGui(MenuType.GENERIC_9x3, viewer, false) {
|
||||
@Override
|
||||
public void onClose() {
|
||||
onBackingClosed();
|
||||
}
|
||||
};
|
||||
gui.setTitle(Component.translatable("minions.gui.instruction.title"));
|
||||
resetInstructionList();
|
||||
gui.open();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void reopen() {
|
||||
gui.open();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void closeBacking() {
|
||||
minion.removeMinionListener(this);
|
||||
gui.close();
|
||||
}
|
||||
|
||||
private void resetInstructionList() {
|
||||
int i = 0;
|
||||
for (String instructionName : minion.getInstructionManager().getInstructionNames()) {
|
||||
ConfiguredInstruction<MinionRuntime> instruction = minion.getInstructionManager().getInstruction(instructionName);
|
||||
gui.setSlot(i, new GuiElementBuilder(GuiDisplay.getGuiDisplayFor(MinionRegistries.INSTRUCTION_TYPES, instruction.getInstruction(), viewer.registryAccess()).createItemStack())
|
||||
.setName(Component.literal(instructionName))
|
||||
.setCallback(() -> new ConfigureInstructionGui(this, GuiContext.Instruction.create(context, instruction, instructionName)))
|
||||
);
|
||||
i++;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
package io.github.skippyall.minions.gui.minion;
|
||||
|
||||
import io.github.skippyall.minions.minion.MinionRuntime;
|
||||
import io.github.skippyall.minions.minion.fakeplayer.MinionFakePlayer;
|
||||
import io.github.skippyall.minions.program.instruction.ConfiguredInstruction;
|
||||
import io.github.skippyall.minions.program.supplier.Parameter;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
|
||||
public interface GuiContext {
|
||||
ServerPlayer getViewer();
|
||||
|
||||
static GuiContext create(ServerPlayer viewer) {
|
||||
return new GuiContextImpl(viewer);
|
||||
}
|
||||
|
||||
interface Minion extends GuiContext {
|
||||
MinionFakePlayer getMinion();
|
||||
|
||||
static GuiContext.Minion create(GuiContext context, MinionFakePlayer minion) {
|
||||
return new GuiContextImpl.MinionImpl(context, minion);
|
||||
}
|
||||
}
|
||||
|
||||
interface Instruction extends Minion {
|
||||
ConfiguredInstruction<MinionRuntime> getInstruction();
|
||||
|
||||
String getName();
|
||||
|
||||
void setName(String name);
|
||||
|
||||
static GuiContext.Instruction create(GuiContext.Minion context, ConfiguredInstruction<MinionRuntime> instruction, String name) {
|
||||
return new GuiContextImpl.InstructionImpl(context, instruction, name);
|
||||
}
|
||||
}
|
||||
|
||||
interface ValueSupplier extends Instruction {
|
||||
Parameter<?> getParameter();
|
||||
|
||||
static GuiContext.ValueSupplier create(GuiContext.Instruction context, Parameter<?> parameter) {
|
||||
return new GuiContextImpl.ValueSupplierImpl(context, parameter);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,120 @@
|
||||
package io.github.skippyall.minions.gui.minion;
|
||||
|
||||
import io.github.skippyall.minions.minion.MinionRuntime;
|
||||
import io.github.skippyall.minions.minion.fakeplayer.MinionFakePlayer;
|
||||
import io.github.skippyall.minions.program.instruction.ConfiguredInstruction;
|
||||
import io.github.skippyall.minions.program.supplier.Parameter;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
|
||||
//If only this mod was kotlin
|
||||
public class GuiContextImpl implements GuiContext {
|
||||
private final ServerPlayer viewer;
|
||||
|
||||
public GuiContextImpl(ServerPlayer viewer) {
|
||||
this.viewer = viewer;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ServerPlayer getViewer() {
|
||||
return viewer;
|
||||
}
|
||||
|
||||
public static class MinionImpl extends DelegatingGuiContextImpl<GuiContext> implements GuiContext.Minion {
|
||||
private final MinionFakePlayer minion;
|
||||
|
||||
public MinionImpl(GuiContext context, MinionFakePlayer minion) {
|
||||
super(context);
|
||||
this.minion = minion;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MinionFakePlayer getMinion() {
|
||||
return minion;
|
||||
}
|
||||
}
|
||||
|
||||
public static class InstructionImpl extends DelegatingMinionImpl<GuiContext.Minion> implements GuiContext.Instruction {
|
||||
private final ConfiguredInstruction<MinionRuntime> instruction;
|
||||
private String name;
|
||||
|
||||
public InstructionImpl(GuiContext.Minion context, ConfiguredInstruction<MinionRuntime> instruction, String name) {
|
||||
super(context);
|
||||
this.instruction = instruction;
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ConfiguredInstruction<MinionRuntime> getInstruction() {
|
||||
return instruction;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
}
|
||||
|
||||
public static class ValueSupplierImpl extends DelegatingInstructionImpl<GuiContext.Instruction> implements GuiContext.ValueSupplier {
|
||||
private final Parameter<?> parameter;
|
||||
|
||||
public ValueSupplierImpl(GuiContext.Instruction context, Parameter<?> parameter) {
|
||||
super(context);
|
||||
this.parameter = parameter;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Parameter<?> getParameter() {
|
||||
return parameter;
|
||||
}
|
||||
}
|
||||
|
||||
public static class DelegatingGuiContextImpl<C extends GuiContext> implements GuiContext {
|
||||
protected final C context;
|
||||
|
||||
public DelegatingGuiContextImpl(C context) {
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ServerPlayer getViewer() {
|
||||
return context.getViewer();
|
||||
}
|
||||
}
|
||||
|
||||
public static class DelegatingMinionImpl<C extends GuiContext.Minion> extends DelegatingGuiContextImpl<C> implements GuiContext.Minion {
|
||||
public DelegatingMinionImpl(C context) {
|
||||
super(context);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MinionFakePlayer getMinion() {
|
||||
return context.getMinion();
|
||||
}
|
||||
}
|
||||
|
||||
public static class DelegatingInstructionImpl<C extends GuiContext.Instruction> extends DelegatingMinionImpl<C> implements GuiContext.Instruction {
|
||||
public DelegatingInstructionImpl(C context) {
|
||||
super(context);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ConfiguredInstruction<MinionRuntime> getInstruction() {
|
||||
return context.getInstruction();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return context.getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setName(String name) {
|
||||
context.setName(name);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
package io.github.skippyall.minions.gui.minion;
|
||||
|
||||
import eu.pb4.sgui.api.elements.GuiElementBuilder;
|
||||
import eu.pb4.sgui.api.gui.SimpleGui;
|
||||
import io.github.skippyall.minions.gui.MinionsGui;
|
||||
import io.github.skippyall.minions.gui.instruction.InstructionGui;
|
||||
import io.github.skippyall.minions.minion.MinionListener;
|
||||
import io.github.skippyall.minions.minion.fakeplayer.MinionFakePlayer;
|
||||
import io.github.skippyall.minions.module.ModuleInventory;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.world.inventory.MenuType;
|
||||
import net.minecraft.world.item.Items;
|
||||
|
||||
public class MinionGui extends MinionsGui implements MinionListener {
|
||||
private final MinionFakePlayer minion;
|
||||
private SimpleGui gui;
|
||||
|
||||
public MinionGui(ServerPlayer viewer, MinionFakePlayer minion) {
|
||||
super(viewer);
|
||||
this.minion = minion;
|
||||
minion.addMinionListener(this);
|
||||
open();
|
||||
}
|
||||
|
||||
public MinionFakePlayer getMinion() {
|
||||
return minion;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void open() {
|
||||
gui = new SimpleGui(MenuType.GENERIC_3x3, viewer, false) {
|
||||
@Override
|
||||
public void onClose() {
|
||||
onBackingClosed();
|
||||
}
|
||||
};
|
||||
|
||||
gui.setTitle(minion.getName());
|
||||
|
||||
gui.setSlot(1, new GuiElementBuilder()
|
||||
.setItem(Items.COMMAND_BLOCK)
|
||||
.setName(Component.translatable("minions.gui.main.instructions"))
|
||||
.setCallback(() -> {
|
||||
InstructionGui.openInstructionMainMenu(this, GuiContext.Minion.create(GuiContext.create(viewer), minion));
|
||||
})
|
||||
);
|
||||
gui.setSlot(3, new GuiElementBuilder()
|
||||
.setItem(Items.NETHERITE_UPGRADE_SMITHING_TEMPLATE)
|
||||
.setName(Component.translatable("minions.gui.main.modules"))
|
||||
.setCallback(() -> {
|
||||
ModuleInventory.openModuleInventory(viewer, minion);
|
||||
})
|
||||
);
|
||||
gui.setSlot(5, new GuiElementBuilder()
|
||||
.setItem(Items.CHEST)
|
||||
.setName(Component.translatable("minions.gui.main.inventory"))
|
||||
.setCallback(() -> new MinionInventoryGui(this))
|
||||
);
|
||||
gui.setSlot(7, new GuiElementBuilder()
|
||||
.setItem(Items.BARRIER)
|
||||
.setName(Component.translatable("minions.gui.main.pickup"))
|
||||
.setCallback(() -> minion.kill(minion.level()))
|
||||
);
|
||||
gui.open();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void reopen() {
|
||||
gui.open();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void closeBacking() {
|
||||
gui.close();
|
||||
minion.removeMinionListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMinionRemove(MinionFakePlayer minion) {
|
||||
close();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
package io.github.skippyall.minions.gui.minion;
|
||||
|
||||
import eu.pb4.sgui.api.gui.SimpleGui;
|
||||
import io.github.skippyall.minions.gui.MinionsGui;
|
||||
import io.github.skippyall.minions.minion.fakeplayer.MinionFakePlayer;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.world.entity.EquipmentSlot;
|
||||
import net.minecraft.world.entity.player.Inventory;
|
||||
import net.minecraft.world.inventory.ArmorSlot;
|
||||
import net.minecraft.world.inventory.MenuType;
|
||||
import net.minecraft.world.inventory.Slot;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.item.Items;
|
||||
|
||||
public class MinionInventoryGui extends MinionsGui {
|
||||
protected final MinionGui parent;
|
||||
private final MinionFakePlayer minion;
|
||||
|
||||
private SimpleGui gui;
|
||||
|
||||
public MinionInventoryGui(MinionGui parent) {
|
||||
super(parent);
|
||||
this.parent = parent;
|
||||
this.minion = parent.getMinion();
|
||||
open();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void open() {
|
||||
gui = new SimpleGui(MenuType.GENERIC_9x6, viewer, false) {
|
||||
@Override
|
||||
public void onClose() {
|
||||
onBackingClosed();
|
||||
}
|
||||
};
|
||||
gui.setTitle(Component.translatable("minions.gui.inventory.title"));
|
||||
|
||||
for(int i = 0; i < 18; i++) {
|
||||
gui.setSlot(i, new ItemStack(Items.BARRIER));
|
||||
}
|
||||
|
||||
gui.setSlot(2, new ItemStack(Items.LEATHER_HELMET));
|
||||
gui.setSlot(3, new ItemStack(Items.LEATHER_CHESTPLATE));
|
||||
gui.setSlot(4, new ItemStack(Items.LEATHER_LEGGINGS));
|
||||
gui.setSlot(5, new ItemStack(Items.LEATHER_BOOTS));
|
||||
gui.setSlot(6, new ItemStack(Items.SHIELD));
|
||||
|
||||
gui.setSlotRedirect(2 + 9, new ArmorSlot(minion.getInventory(), minion, EquipmentSlot.HEAD, EquipmentSlot.HEAD.getIndex(Inventory.INVENTORY_SIZE), 0, 0, null));
|
||||
gui.setSlotRedirect(3 + 9, new ArmorSlot(minion.getInventory(), minion, EquipmentSlot.CHEST, EquipmentSlot.CHEST.getIndex(Inventory.INVENTORY_SIZE), 0, 0, null));
|
||||
gui.setSlotRedirect(4 + 9, new ArmorSlot(minion.getInventory(), minion, EquipmentSlot.LEGS, EquipmentSlot.LEGS.getIndex(Inventory.INVENTORY_SIZE), 0, 0, null));
|
||||
gui.setSlotRedirect(5 + 9, new ArmorSlot(minion.getInventory(), minion, EquipmentSlot.FEET, EquipmentSlot.FEET.getIndex(Inventory.INVENTORY_SIZE), 0, 0, null));
|
||||
gui.setSlotRedirect(6 + 9, new Slot(minion.getInventory(), Inventory.SLOT_OFFHAND, 0, 0));
|
||||
|
||||
for (int i = Inventory.SELECTION_SIZE; i < Inventory.INVENTORY_SIZE; i++) {
|
||||
gui.setSlotRedirect(i + 9, new Slot(minion.getInventory(), i, 0, 0));
|
||||
}
|
||||
|
||||
for (int i = 0; i < Inventory.SELECTION_SIZE; i++) {
|
||||
gui.setSlotRedirect(i + 45, new Slot(minion.getInventory(), i, 0, 0));
|
||||
}
|
||||
gui.open();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void closeBacking() {
|
||||
gui.close();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package io.github.skippyall.minions.gui.minion;
|
||||
|
||||
import eu.pb4.sgui.api.gui.GuiInterface;
|
||||
import io.github.skippyall.minions.gui.MinionsGui;
|
||||
|
||||
import java.util.function.BiFunction;
|
||||
|
||||
public class SimpleMinionsGui extends MinionsGui {
|
||||
private GuiInterface gui;
|
||||
private final BiFunction<Runnable, SimpleMinionsGui, GuiInterface> guiFactory;
|
||||
|
||||
public SimpleMinionsGui(MinionsGui parent, BiFunction<Runnable, SimpleMinionsGui, GuiInterface> guiFactory) {
|
||||
super(parent);
|
||||
this.guiFactory = guiFactory;
|
||||
open();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void open() {
|
||||
gui = guiFactory.apply(this::onBackingClosed, this);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void closeBacking() {
|
||||
gui.close();
|
||||
}
|
||||
}
|
||||
@@ -1,117 +0,0 @@
|
||||
package io.github.skippyall.minions.input;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Optional;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Function;
|
||||
|
||||
public interface Result<T, E> {
|
||||
static <T> Result<T, String> wrap(UnsafeOperation<T> toWrap) {
|
||||
return wrapCustomError(toWrap, Exception::getMessage);
|
||||
}
|
||||
|
||||
static <T, E> Result<T, E> wrapCustomError(UnsafeOperation<T> toWrap, E error) {
|
||||
return wrapCustomError(toWrap, e -> error);
|
||||
}
|
||||
|
||||
static <T, E> Result<T, E> wrapCustomError(UnsafeOperation<T> toWrap, Function<Exception, E> errorTransformer) {
|
||||
try {
|
||||
return new Result.Success<>(toWrap.run());
|
||||
} catch (Exception e) {
|
||||
return new Result.Error<>(errorTransformer.apply(e));
|
||||
}
|
||||
}
|
||||
|
||||
boolean isSuccess();
|
||||
|
||||
@NotNull T getOrDefault(@NotNull T defaultValue);
|
||||
|
||||
@NotNull T getOrThrow();
|
||||
|
||||
@NotNull E getErrorOrThrow();
|
||||
|
||||
@NotNull Optional<T> getOptional();
|
||||
|
||||
void ifSuccess(@NotNull Consumer<T> handler);
|
||||
|
||||
void ifError(@NotNull Consumer<Error<T, E>> handler);
|
||||
|
||||
record Success<T, E>(@NotNull T result) implements Result<T, E> {
|
||||
@Override
|
||||
public boolean isSuccess() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull T getOrDefault(@NotNull T defaultValue) {
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull T getOrThrow() {
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull E getErrorOrThrow() {
|
||||
throw new RuntimeException("Result was not an Error");
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull Optional<T> getOptional() {
|
||||
return Optional.of(result);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void ifSuccess(@NotNull Consumer<T> handler) {
|
||||
handler.accept(result);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void ifError(@NotNull Consumer<Error<T, E>> handler) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
record Error<T, E>(@NotNull E message) implements Result<T, E> {
|
||||
@Override
|
||||
public boolean isSuccess() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull T getOrDefault(@NotNull T defaultValue) {
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull T getOrThrow() {
|
||||
throw new RuntimeException("Result was an error: " + message.toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull E getErrorOrThrow() {
|
||||
return message;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull Optional<T> getOptional() {
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void ifSuccess(@NotNull Consumer<T> handler) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void ifError(Consumer<Error<T, E>> handler) {
|
||||
handler.accept(this);
|
||||
}
|
||||
}
|
||||
|
||||
interface UnsafeOperation<T> {
|
||||
T run() throws Exception;
|
||||
}
|
||||
}
|
||||
@@ -1,90 +0,0 @@
|
||||
package io.github.skippyall.minions.input;
|
||||
|
||||
import eu.pb4.sgui.api.elements.GuiElementBuilder;
|
||||
import eu.pb4.sgui.api.gui.AnvilInputGui;
|
||||
import net.minecraft.item.Items;
|
||||
import net.minecraft.screen.AnvilScreenHandler;
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
import net.minecraft.text.Text;
|
||||
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
public class TextInput<T> extends AnvilInputGui {
|
||||
private final GuiElementBuilder valid = new GuiElementBuilder()
|
||||
.setItem(Items.EMERALD_BLOCK)
|
||||
.setName(Text.literal("OK"))
|
||||
.setCallback(this::onConfirm);
|
||||
|
||||
private final GuiElementBuilder invalid = new GuiElementBuilder()
|
||||
.setItem(Items.REDSTONE_BLOCK);
|
||||
private final Function<String, CompletableFuture<Result<T, Text>>> parser;
|
||||
private final CompletableFuture<T> future;
|
||||
private Result<T, Text> result;
|
||||
|
||||
public TextInput(ServerPlayerEntity player, Text title, String defaultValue, Function<String, CompletableFuture<Result<T, Text>>> parser, CompletableFuture<T> future) {
|
||||
super(player, false);
|
||||
setTitle(title);
|
||||
setDefaultInputValue(defaultValue);
|
||||
this.parser = parser;
|
||||
this.future = future;
|
||||
|
||||
updateConfirmButton(defaultValue);
|
||||
}
|
||||
|
||||
public static <T> CompletableFuture<T> inputSync(ServerPlayerEntity player, Text title, String defaultValue, Function<String, Result<T, Text>> parser) {
|
||||
return input(player, title, defaultValue, (String string) -> CompletableFuture.completedFuture(parser.apply(string)));
|
||||
}
|
||||
|
||||
public static <T> CompletableFuture<T> input(ServerPlayerEntity player, Text title, String defaultValue, Function<String, CompletableFuture<Result<T, Text>>> parser) {
|
||||
CompletableFuture<T> future = new CompletableFuture<>();
|
||||
new TextInput<>(player, title, defaultValue, parser, future).open();
|
||||
return future;
|
||||
}
|
||||
|
||||
public static CompletableFuture<String> inputString(ServerPlayerEntity player, Text title, String defaultValue) {
|
||||
return inputSync(player, title, defaultValue, Result.Success::new);
|
||||
}
|
||||
|
||||
public static CompletableFuture<Integer> inputInt(ServerPlayerEntity player, Text title, String defaultValue) {
|
||||
return inputSync(player, title, defaultValue, string -> Result.wrapCustomError(() -> Integer.valueOf(string), Text.translatable("minions.command.input.int.fail")));
|
||||
}
|
||||
|
||||
public static CompletableFuture<Float> inputFloat(ServerPlayerEntity player, Text title, String defaultValue) {
|
||||
return inputSync(player, title, defaultValue, string -> Result.wrapCustomError(() -> Float.valueOf(string), Text.translatable("minions.command.input.float.fail")));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onInput(String input) {
|
||||
updateConfirmButton(input);
|
||||
}
|
||||
|
||||
public void updateConfirmButton(String input) {
|
||||
parser.apply(input).thenAccept(result -> {
|
||||
this.result = result;
|
||||
if(result.isSuccess()) {
|
||||
setSlot(AnvilScreenHandler.OUTPUT_ID, valid);
|
||||
} else {
|
||||
Text text = result.getErrorOrThrow();
|
||||
setSlot(AnvilScreenHandler.OUTPUT_ID, invalid.setName(text));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClose() {
|
||||
if(!future.isDone()) {
|
||||
future.cancel(false);
|
||||
}
|
||||
}
|
||||
|
||||
public void onConfirm() {
|
||||
if(result != null) {
|
||||
result.ifSuccess(success -> {
|
||||
future.complete(success);
|
||||
close();
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
+54
@@ -0,0 +1,54 @@
|
||||
package io.github.skippyall.minions.listener;
|
||||
|
||||
import io.github.skippyall.minions.minion.fakeplayer.MinionFakePlayer;
|
||||
import io.github.skippyall.minions.program.instruction.ConfiguredInstructionListener;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.resources.ResourceKey;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||
import net.minecraft.world.level.block.entity.BlockEntityType;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
public abstract class BlockEntityMinionInstructionListener<E extends BlockEntity> extends BlockEntityMinionListener<E> {
|
||||
protected BlockEntityMinionInstructionListener(ResourceKey<Level> worldKey, BlockPos pos, UUID minionUuid, BlockEntityType<E> type) {
|
||||
super(worldKey, pos, minionUuid, type);
|
||||
}
|
||||
|
||||
protected abstract Map<String, ConfiguredInstructionListener> getInstructionListeners();
|
||||
|
||||
@Override
|
||||
public void onMinionSpawn(MinionFakePlayer minion) {
|
||||
super.onMinionSpawn(minion);
|
||||
registerInstructionListeners();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void add(MinecraftServer server) {
|
||||
super.add(server);
|
||||
if(minion != null) {
|
||||
registerInstructionListeners();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void remove(MinecraftServer server) {
|
||||
super.remove(server);
|
||||
if(minion != null) {
|
||||
removeInstructionListeners();
|
||||
}
|
||||
}
|
||||
|
||||
public void registerInstructionListeners() {
|
||||
for(Map.Entry<String, ConfiguredInstructionListener> listener : getInstructionListeners().entrySet()) {
|
||||
minion.getInstructionManager().getInstruction(listener.getKey()).addListener(listener.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
public void removeInstructionListeners() {
|
||||
for(Map.Entry<String, ConfiguredInstructionListener> listener : getInstructionListeners().entrySet()) {
|
||||
minion.getInstructionManager().getInstruction(listener.getKey()).removeListener(listener.getValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,113 @@
|
||||
package io.github.skippyall.minions.listener;
|
||||
|
||||
import com.mojang.datafixers.util.Function3;
|
||||
import com.mojang.serialization.Codec;
|
||||
import com.mojang.serialization.codecs.RecordCodecBuilder;
|
||||
import io.github.skippyall.minions.minion.MinionListener;
|
||||
import io.github.skippyall.minions.minion.MinionPersistentState;
|
||||
import io.github.skippyall.minions.minion.fakeplayer.MinionFakePlayer;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.UUIDUtil;
|
||||
import net.minecraft.resources.ResourceKey;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||
import net.minecraft.world.level.block.entity.BlockEntityType;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
|
||||
public abstract class BlockEntityMinionListener<E extends BlockEntity> implements MinionListener {
|
||||
protected ResourceKey<Level> worldKey;
|
||||
protected BlockPos pos;
|
||||
protected UUID minionUuid;
|
||||
protected BlockEntityType<E> type;
|
||||
protected @Nullable MinionFakePlayer minion;
|
||||
|
||||
protected BlockEntityMinionListener(ResourceKey<Level> worldKey, BlockPos pos, UUID minionUuid, BlockEntityType<E> type) {
|
||||
this.worldKey = worldKey;
|
||||
this.pos = pos;
|
||||
this.minionUuid = minionUuid;
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMinionSpawn(MinionFakePlayer minion) {
|
||||
MinionListener.super.onMinionSpawn(minion);
|
||||
this.minion = minion;
|
||||
removeIfBeRemoved(minion.getServer());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMinionRemove(MinionFakePlayer minion) {
|
||||
MinionListener.super.onMinionRemove(minion);
|
||||
this.minion = null;
|
||||
}
|
||||
|
||||
public static <T extends BlockEntityMinionListener<?>> T getListener(Level world, BlockPos pos, UUID minionUuid, Class<T> clazz) {
|
||||
if(minionUuid != null) {
|
||||
for (MinionListener listener : MinionPersistentState.get(world.getServer()).getMinionData(minionUuid).listeners()) {
|
||||
if (listener instanceof BlockEntityMinionListener<?> tl && tl.pos.equals(pos) && tl.worldKey.equals(world.dimension()) && clazz.isInstance(tl)) {
|
||||
return clazz.cast(tl);
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static <L extends BlockEntityMinionListener<?>> Codec<L> getCodec(Function3<ResourceKey<Level>, BlockPos, UUID, L> constructor) {
|
||||
return RecordCodecBuilder.create(instance ->
|
||||
instance.group(
|
||||
Level.RESOURCE_KEY_CODEC.fieldOf("world").forGetter(listener -> listener.worldKey),
|
||||
BlockPos.CODEC.fieldOf("pos").forGetter(listener -> listener.pos),
|
||||
UUIDUtil.AUTHLIB_CODEC.fieldOf("minionUuid").forGetter(listener -> listener.minionUuid)
|
||||
).apply(instance, constructor));
|
||||
}
|
||||
|
||||
private BlockEntityState getBlockEntityState(MinecraftServer server) {
|
||||
Level world = server.getLevel(worldKey);
|
||||
if(world == null || !world.isLoaded(pos)) {
|
||||
return BlockEntityState.UNLOADED;
|
||||
}
|
||||
|
||||
if(world.getBlockEntity(pos, type).isPresent()) {
|
||||
return BlockEntityState.LOADED;
|
||||
} else {
|
||||
return BlockEntityState.REMOVED;
|
||||
}
|
||||
}
|
||||
|
||||
public Optional<E> getBlockEntity(MinecraftServer server) {
|
||||
Level world = server.getLevel(worldKey);
|
||||
if(world != null && world.isLoaded(pos)) {
|
||||
return world.getBlockEntity(pos, type);
|
||||
}
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
public boolean removeIfBeRemoved(MinecraftServer server) {
|
||||
if(getBlockEntityState(server) == BlockEntityState.REMOVED) {
|
||||
remove(server);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public void add(MinecraftServer server) {
|
||||
MinionPersistentState.get(server).getMinionData(minionUuid).listeners().addListener(this);
|
||||
MinionPersistentState.get(server).setDirty();
|
||||
this.minion = (MinionFakePlayer) server.getPlayerList().getPlayer(minionUuid);
|
||||
}
|
||||
|
||||
public void remove(MinecraftServer server) {
|
||||
MinionPersistentState.get(server).getMinionData(minionUuid).listeners().removeListener(this);
|
||||
MinionPersistentState.get(server).setDirty();
|
||||
}
|
||||
|
||||
public enum BlockEntityState {
|
||||
LOADED,
|
||||
REMOVED,
|
||||
UNLOADED
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
package io.github.skippyall.minions.listener;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.CopyOnWriteArraySet;
|
||||
|
||||
public class ListenerManager<T> implements Iterable<T> {
|
||||
protected final Set<T> listeners;
|
||||
|
||||
public ListenerManager() {
|
||||
this(new CopyOnWriteArraySet<>());
|
||||
}
|
||||
|
||||
protected ListenerManager(Set<T> listeners) {
|
||||
this.listeners = listeners;
|
||||
}
|
||||
|
||||
public void addListener(T listener) {
|
||||
listeners.add(listener);
|
||||
}
|
||||
|
||||
public void removeListener(T listener) {
|
||||
listeners.remove(listener);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull Iterator<T> iterator() {
|
||||
return listeners.iterator();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
return super.equals(obj);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
package io.github.skippyall.minions.listener;
|
||||
|
||||
import com.mojang.serialization.Codec;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.CopyOnWriteArraySet;
|
||||
import net.minecraft.core.Registry;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
|
||||
public class SerializableListenerManager<T extends SerializableListenerManager.SerializableListener> extends ListenerManager<T> {
|
||||
public SerializableListenerManager() {
|
||||
super();
|
||||
}
|
||||
|
||||
protected SerializableListenerManager(Set<T> listeners) {
|
||||
super(listeners);
|
||||
}
|
||||
|
||||
public static <T extends SerializableListener> Codec<SerializableListenerManager<T>> getCodec(Registry<Codec<? extends T>> registry) {
|
||||
return registry.byNameCodec().<T>dispatch(
|
||||
listener -> listener.getCodecId().map(registry::getValue).orElse(Codec.unit(null)),
|
||||
codec -> codec.fieldOf("data")
|
||||
).listOf().xmap(
|
||||
list -> new SerializableListenerManager<>(new CopyOnWriteArraySet<>(list)),
|
||||
manager -> {
|
||||
List<T> serializableListeners = new ArrayList<>();
|
||||
for(T listener : manager.listeners) {
|
||||
if(listener.getCodecId().isPresent()) {
|
||||
serializableListeners.add(listener);
|
||||
}
|
||||
}
|
||||
return serializableListeners;
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
public interface SerializableListener {
|
||||
default Optional<ResourceLocation> getCodecId() {
|
||||
return Optional.empty();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
package io.github.skippyall.minions.minion;
|
||||
|
||||
import com.mojang.serialization.Codec;
|
||||
import io.github.skippyall.minions.registration.MinionRegistries;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
|
||||
public class MinionConfig {
|
||||
public static final Codec<MinionConfig> CODEC = Codec.<Option<?>, Object>dispatchedMap(
|
||||
MinionRegistries.MINION_CONFIG_OPTIONS.byNameCodec(),
|
||||
Option::codec
|
||||
).xmap(MinionConfig::new, config -> config.values);
|
||||
|
||||
private final Map<Option<?>, Object> values;
|
||||
|
||||
public MinionConfig() {
|
||||
values = new HashMap<>();
|
||||
}
|
||||
|
||||
private MinionConfig(Map<Option<?>, Object> values) {
|
||||
this.values = new HashMap<>(values);
|
||||
}
|
||||
|
||||
public <T> T getOption(Option<T> option) {
|
||||
if(values.containsKey(option)) {
|
||||
//noinspection unchecked
|
||||
return (T) values.get(option);
|
||||
} else {
|
||||
return option.defaultValue();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (!(o instanceof MinionConfig that)) return false;
|
||||
return Objects.equals(values, that.values);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hashCode(values);
|
||||
}
|
||||
|
||||
public static Option<Boolean> booleanOption(ResourceLocation key, boolean defaultValue) {
|
||||
return new Option<>(key, defaultValue, Codec.BOOL);
|
||||
}
|
||||
|
||||
public record Option<T>(ResourceLocation key, T defaultValue, Codec<T> codec) {
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (!(o instanceof Option<?> option)) return false;
|
||||
return Objects.equals(key, option.key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hashCode(key);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,65 +1,58 @@
|
||||
package io.github.skippyall.minions.minion;
|
||||
|
||||
import com.mojang.authlib.properties.PropertyMap;
|
||||
import com.mojang.datafixers.util.Pair;
|
||||
import com.mojang.serialization.Codec;
|
||||
import com.mojang.serialization.codecs.RecordCodecBuilder;
|
||||
import eu.pb4.polymer.core.api.other.PolymerComponent;
|
||||
import io.github.skippyall.minions.Minions;
|
||||
import net.minecraft.component.ComponentType;
|
||||
import net.minecraft.nbt.NbtCompound;
|
||||
import net.minecraft.nbt.NbtOps;
|
||||
import net.minecraft.registry.Registries;
|
||||
import net.minecraft.registry.Registry;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.Uuids;
|
||||
import net.minecraft.util.dynamic.Codecs;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import io.github.skippyall.minions.listener.SerializableListenerManager;
|
||||
import io.github.skippyall.minions.registration.MinionRegistries;
|
||||
import net.minecraft.core.UUIDUtil;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.util.ExtraCodecs;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
|
||||
public record MinionData(UUID uuid, String name, Optional<PropertyMap> skin, boolean isSpawned) {
|
||||
public record MinionData(
|
||||
UUID uuid,
|
||||
String name,
|
||||
Optional<PropertyMap> skin,
|
||||
boolean isSpawned,
|
||||
SerializableListenerManager<MinionListener> listeners,
|
||||
MinionConfig config
|
||||
) {
|
||||
public static final Codec<MinionData> CODEC = RecordCodecBuilder.create(instance ->
|
||||
instance.group(
|
||||
Uuids.CODEC.fieldOf("uuid").forGetter(MinionData::uuid),
|
||||
UUIDUtil.AUTHLIB_CODEC.fieldOf("uuid").forGetter(MinionData::uuid),
|
||||
Codec.STRING.fieldOf("name").forGetter(MinionData::name),
|
||||
Codecs.GAME_PROFILE_PROPERTY_MAP.optionalFieldOf("skin").forGetter(MinionData::skin),
|
||||
Codec.BOOL.optionalFieldOf("isSpawned", false).forGetter(MinionData::isSpawned)
|
||||
ExtraCodecs.PROPERTY_MAP.optionalFieldOf("skin").forGetter(MinionData::skin),
|
||||
Codec.BOOL.optionalFieldOf("isSpawned", false).forGetter(MinionData::isSpawned),
|
||||
SerializableListenerManager.getCodec(MinionRegistries.MINION_LISTENER_CODECS).optionalFieldOf("listeners").xmap(
|
||||
optional -> optional.orElseGet(SerializableListenerManager::new),
|
||||
Optional::of
|
||||
).forGetter(MinionData::listeners),
|
||||
MinionConfig.CODEC.optionalFieldOf("config", new MinionConfig()).forGetter(MinionData::config)
|
||||
).apply(instance, MinionData::new)
|
||||
);
|
||||
|
||||
public static final ComponentType<UUID> COMPONENT = Registry.register(Registries.DATA_COMPONENT_TYPE, Identifier.of(Minions.MOD_ID, "minion_data"), ComponentType.<UUID>builder().codec(Uuids.CODEC).build());
|
||||
|
||||
public static MinionData createDefault() {
|
||||
return new MinionData(UUID.randomUUID(), MinionProfileUtils.newDefaultMinionName(), Optional.empty(), false);
|
||||
}
|
||||
|
||||
public MinionData withUuid(UUID uuid) {
|
||||
return new MinionData(uuid, name, skin, isSpawned);
|
||||
public static MinionData createDefault(MinecraftServer server) {
|
||||
return new MinionData(
|
||||
UUID.randomUUID(),
|
||||
MinionProfileUtils.newDefaultMinionName(server),
|
||||
Optional.empty(),
|
||||
false,
|
||||
new SerializableListenerManager<>(),
|
||||
new MinionConfig()
|
||||
);
|
||||
}
|
||||
|
||||
public MinionData withName(String name) {
|
||||
return new MinionData(uuid, name, skin, isSpawned);
|
||||
return new MinionData(uuid, name, skin, isSpawned, listeners, config);
|
||||
}
|
||||
|
||||
public MinionData withSkin(Optional<PropertyMap> skin) {
|
||||
return new MinionData(uuid, name, skin, isSpawned);
|
||||
return new MinionData(uuid, name, skin, isSpawned, listeners, config);
|
||||
}
|
||||
|
||||
public MinionData withSpawned(boolean isSpawned) {
|
||||
return new MinionData(uuid, name, skin, isSpawned);
|
||||
}
|
||||
|
||||
public NbtCompound writeNbt() {
|
||||
return (NbtCompound) MinionData.CODEC.encode(this, NbtOps.INSTANCE, null).result().orElse(new NbtCompound());
|
||||
}
|
||||
|
||||
public static MinionData readNbt(NbtCompound nbt) {
|
||||
return MinionData.CODEC.decode(NbtOps.INSTANCE, nbt).resultOrPartial().map(Pair::getFirst).orElseGet(MinionData::createDefault);
|
||||
}
|
||||
|
||||
public static void register() {
|
||||
PolymerComponent.registerDataComponent(COMPONENT);
|
||||
return new MinionData(uuid, name, skin, isSpawned, listeners, config);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,33 +4,36 @@ import eu.pb4.polymer.core.api.item.PolymerItem;
|
||||
import eu.pb4.polymer.core.api.item.PolymerItemUtils;
|
||||
import io.github.skippyall.minions.gui.MinionLookGui;
|
||||
import io.github.skippyall.minions.minion.fakeplayer.MinionFakePlayer;
|
||||
import net.minecraft.component.DataComponentTypes;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.ItemUsageContext;
|
||||
import net.minecraft.item.Items;
|
||||
import net.minecraft.item.tooltip.TooltipType;
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
import net.minecraft.server.world.ServerWorld;
|
||||
import net.minecraft.text.Text;
|
||||
import net.minecraft.util.ActionResult;
|
||||
import net.minecraft.util.Hand;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.math.Vec2f;
|
||||
import net.minecraft.world.World;
|
||||
import io.github.skippyall.minions.registration.MinionComponentTypes;
|
||||
import net.minecraft.core.component.DataComponents;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.world.InteractionHand;
|
||||
import net.minecraft.world.InteractionResult;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.item.Item;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.item.Items;
|
||||
import net.minecraft.world.item.TooltipFlag;
|
||||
import net.minecraft.world.item.component.TooltipDisplay;
|
||||
import net.minecraft.world.item.context.UseOnContext;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.phys.Vec2;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import xyz.nucleoid.packettweaker.PacketContext;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public class MinionItem extends Item implements PolymerItem {
|
||||
public MinionItem(Settings settings) {
|
||||
public MinionItem(Properties settings) {
|
||||
super(settings);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable Identifier getPolymerItemModel(ItemStack stack, PacketContext context) {
|
||||
public @Nullable ResourceLocation getPolymerItemModel(ItemStack stack, PacketContext context) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -40,64 +43,64 @@ public class MinionItem extends Item implements PolymerItem {
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getPolymerItemStack(ItemStack stack, TooltipType tooltipType, PacketContext player) {
|
||||
public ItemStack getPolymerItemStack(ItemStack stack, TooltipFlag tooltipType, PacketContext player) {
|
||||
ItemStack out = PolymerItemUtils.createItemStack(stack, tooltipType, player);
|
||||
out.set(DataComponentTypes.ENCHANTMENT_GLINT_OVERRIDE, true);
|
||||
out.set(DataComponents.ENCHANTMENT_GLINT_OVERRIDE, true);
|
||||
return out;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void appendTooltip(ItemStack stack, TooltipContext context, List<Text> tooltip, TooltipType type) {
|
||||
MinionData data = getData(stack);
|
||||
public void appendHoverText(ItemStack stack, TooltipContext context, TooltipDisplay component, Consumer<Component> tooltip, TooltipFlag type) {
|
||||
MinionData data = null /*getData(stack)*/;
|
||||
if(data != null) {
|
||||
tooltip.add(Text.translatable("minions.minion_item.tooltip", data.name()));
|
||||
tooltip.accept(Component.translatable("minions.minion_item.tooltip", data.name()));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ActionResult use(World world, PlayerEntity user, Hand hand) {
|
||||
if(user instanceof ServerPlayerEntity serverPlayer) {
|
||||
ItemStack stack = user.getStackInHand(hand);
|
||||
public InteractionResult use(Level world, Player user, InteractionHand hand) {
|
||||
if(user instanceof ServerPlayer serverPlayer) {
|
||||
ItemStack stack = user.getItemInHand(hand);
|
||||
MinionLookGui.open(serverPlayer, stack);
|
||||
return ActionResult.SUCCESS;
|
||||
return InteractionResult.SUCCESS;
|
||||
}
|
||||
|
||||
return ActionResult.SUCCESS_SERVER;
|
||||
return InteractionResult.SUCCESS_SERVER;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ActionResult useOnBlock(ItemUsageContext context) {
|
||||
if(!context.getWorld().isClient) {
|
||||
MinionData data = getDataOrDefault(context.getStack());
|
||||
MinionFakePlayer.spawnMinion(data, (ServerWorld) context.getWorld(), context.getBlockPos().toCenterPos().add(0,0.5,0), new Vec2f(0, 0));
|
||||
public InteractionResult useOn(UseOnContext context) {
|
||||
if(!context.getLevel().isClientSide) {
|
||||
MinionData data = getDataOrDefault(context.getLevel().getServer(), context.getItemInHand());
|
||||
MinionFakePlayer.spawnMinion(data, (ServerLevel) context.getLevel(), context.getClickedPos().getCenter().add(0,0.5,0), new Vec2(0, 0));
|
||||
}
|
||||
context.getStack().decrement(1);
|
||||
return ActionResult.SUCCESS;
|
||||
context.getItemInHand().shrink(1);
|
||||
return InteractionResult.SUCCESS;
|
||||
}
|
||||
|
||||
public static void setData(MinionData data, ItemStack item) {
|
||||
item.set(MinionData.COMPONENT, data.uuid());
|
||||
MinionPersistentState.INSTANCE.updateMinionData(data);
|
||||
public static void setData(MinecraftServer server, MinionData data, ItemStack item) {
|
||||
item.set(MinionComponentTypes.MINION_DATA, data.uuid());
|
||||
MinionPersistentState.get(server).updateMinionData(data);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static MinionData getData(ItemStack item) {
|
||||
if(item.contains(MinionData.COMPONENT)) {
|
||||
return MinionPersistentState.INSTANCE.getMinionData(item.get(MinionData.COMPONENT));
|
||||
public static MinionData getData(MinecraftServer server, ItemStack item) {
|
||||
if(item.has(MinionComponentTypes.MINION_DATA)) {
|
||||
return MinionPersistentState.get(server).getMinionData(item.get(MinionComponentTypes.MINION_DATA));
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static MinionData getDataOrDefault(ItemStack item) {
|
||||
MinionData data = getData(item);
|
||||
public static MinionData getDataOrDefault(MinecraftServer server, ItemStack item) {
|
||||
MinionData data = getData(server, item);
|
||||
if(data == null) {
|
||||
data = MinionData.createDefault();
|
||||
setData(data, item);
|
||||
data = MinionData.createDefault(server);
|
||||
setData(server, data, item);
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
public static boolean containsData(ItemStack item) {
|
||||
return item.contains(MinionData.COMPONENT);
|
||||
return item.has(MinionComponentTypes.MINION_DATA);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
package io.github.skippyall.minions.minion;
|
||||
|
||||
import io.github.skippyall.minions.listener.SerializableListenerManager;
|
||||
import io.github.skippyall.minions.minion.fakeplayer.MinionFakePlayer;
|
||||
import io.github.skippyall.minions.program.instruction.ConfiguredInstruction;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public interface MinionListener extends SerializableListenerManager.SerializableListener {
|
||||
default void onMinionSpawn(MinionFakePlayer minion) {}
|
||||
|
||||
default void onMinionRemove(MinionFakePlayer minion) {}
|
||||
|
||||
default void onInstructionsUpdate(MinionFakePlayer minion) {}
|
||||
|
||||
default void onInstructionRename(MinionFakePlayer minion, ConfiguredInstruction<?> instruction, String oldName, String newName) {}
|
||||
|
||||
interface Delegating extends MinionListener {
|
||||
@Nullable MinionListener getBacking();
|
||||
|
||||
@Override
|
||||
default void onMinionSpawn(MinionFakePlayer minion) {
|
||||
if(getBacking() != null) {
|
||||
getBacking().onMinionSpawn(minion);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
default void onMinionRemove(MinionFakePlayer minion) {
|
||||
if(getBacking() != null) {
|
||||
getBacking().onMinionRemove(minion);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
default void onInstructionsUpdate(MinionFakePlayer minion) {
|
||||
if(getBacking() != null) {
|
||||
getBacking().onInstructionsUpdate(minion);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
default void onInstructionRename(MinionFakePlayer minion, ConfiguredInstruction<?> instruction, String oldName, String newName) {
|
||||
if(getBacking() != null) {
|
||||
getBacking().onInstructionRename(minion, instruction, oldName, newName);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,45 +1,31 @@
|
||||
package io.github.skippyall.minions.minion;
|
||||
|
||||
import net.minecraft.nbt.NbtCompound;
|
||||
import net.minecraft.nbt.NbtElement;
|
||||
import net.minecraft.nbt.NbtList;
|
||||
import net.minecraft.registry.RegistryWrapper;
|
||||
import com.mojang.serialization.Codec;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.world.PersistentState;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.saveddata.SavedData;
|
||||
import net.minecraft.world.level.saveddata.SavedDataType;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
|
||||
public class MinionPersistentState extends PersistentState {
|
||||
public static Type<MinionPersistentState> TYPE = new Type<>(MinionPersistentState::new, MinionPersistentState::read, null);
|
||||
public class MinionPersistentState extends SavedData {
|
||||
public static final Codec<MinionPersistentState> CODEC = MinionData.CODEC.listOf().xmap(MinionPersistentState::new, MinionPersistentState::getMinionDataList);
|
||||
|
||||
public static MinionPersistentState INSTANCE;
|
||||
public static SavedDataType<MinionPersistentState> TYPE = new SavedDataType<>("minion", MinionPersistentState::new, MinionPersistentState.CODEC, null);
|
||||
|
||||
private final Map<UUID, MinionData> minionData = new HashMap<>();
|
||||
|
||||
@Override
|
||||
public NbtCompound writeNbt(NbtCompound nbt, RegistryWrapper.WrapperLookup registryLookup) {
|
||||
NbtList list = new NbtList();
|
||||
for(MinionData data : minionData.values()) {
|
||||
list.add(data.writeNbt());
|
||||
}
|
||||
nbt.put("minions", list);
|
||||
public MinionPersistentState() {
|
||||
|
||||
return nbt;
|
||||
}
|
||||
|
||||
public static MinionPersistentState read(NbtCompound compound, RegistryWrapper.WrapperLookup lookup) {
|
||||
NbtList list = compound.getList("minions", NbtElement.COMPOUND_TYPE);
|
||||
MinionPersistentState instance = new MinionPersistentState();
|
||||
for(NbtElement element : list) {
|
||||
if(element instanceof NbtCompound compound1) {
|
||||
MinionData data = MinionData.readNbt(compound1);
|
||||
instance.minionData.put(data.uuid(), data);
|
||||
}
|
||||
public MinionPersistentState(List<MinionData> dataList) {
|
||||
for (MinionData data : dataList) {
|
||||
minionData.put(data.uuid(), data);
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
|
||||
public MinionData getMinionData(UUID uuid) {
|
||||
@@ -50,9 +36,13 @@ public class MinionPersistentState extends PersistentState {
|
||||
return minionData;
|
||||
}
|
||||
|
||||
public List<MinionData> getMinionDataList() {
|
||||
return List.copyOf(minionData.values());
|
||||
}
|
||||
|
||||
public void updateMinionData(MinionData data) {
|
||||
minionData.put(data.uuid(), data);
|
||||
markDirty();
|
||||
setDirty();
|
||||
}
|
||||
|
||||
public boolean isMinion(UUID uuid) {
|
||||
@@ -60,10 +50,16 @@ public class MinionPersistentState extends PersistentState {
|
||||
}
|
||||
|
||||
public boolean isMinionNameTaken(String name) {
|
||||
return minionData.values().stream().anyMatch(data -> data.name().equals(name));
|
||||
return getMinionWithName(name).isPresent();
|
||||
}
|
||||
|
||||
public static void create(MinecraftServer server) {
|
||||
INSTANCE = server.getWorld(World.OVERWORLD).getPersistentStateManager().getOrCreate(TYPE, "minion");
|
||||
public Optional<MinionData> getMinionWithName(String name) {
|
||||
return minionData.values().stream()
|
||||
.filter(data -> data.name().equals(name))
|
||||
.findFirst();
|
||||
}
|
||||
|
||||
public static MinionPersistentState get(MinecraftServer server) {
|
||||
return server.getLevel(Level.OVERWORLD).getDataStorage().computeIfAbsent(TYPE);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,25 +1,21 @@
|
||||
package io.github.skippyall.minions.minion;
|
||||
|
||||
import com.mojang.authlib.GameProfile;
|
||||
import com.mojang.authlib.ProfileLookupCallback;
|
||||
import com.mojang.authlib.properties.PropertyMap;
|
||||
import com.mojang.authlib.yggdrasil.ProfileResult;
|
||||
import com.mojang.brigadier.StringReader;
|
||||
import io.github.skippyall.minions.input.Result;
|
||||
import net.minecraft.block.entity.SkullBlockEntity;
|
||||
import io.github.skippyall.minions.MinionsConfig;
|
||||
import io.github.skippyall.minions.gui.input.Result;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.text.Text;
|
||||
import net.minecraft.util.StringHelper;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import net.minecraft.util.StringUtil;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.ForkJoinPool;
|
||||
|
||||
import static io.github.skippyall.minions.Minions.LOGGER;
|
||||
|
||||
public class MinionProfileUtils {
|
||||
public static final String PREFIX = "+";
|
||||
public static String getPrefix() {
|
||||
return MinionsConfig.get().minion.minionPrefix;
|
||||
}
|
||||
|
||||
public static GameProfile makeNewMinionProfile(UUID uuidMinion, String username, PropertyMap skin) {
|
||||
if(uuidMinion == null) {
|
||||
@@ -34,37 +30,37 @@ public class MinionProfileUtils {
|
||||
return newProfile;
|
||||
}
|
||||
|
||||
public static Result<String, Text> checkMinionNameWithoutPrefix(String name) {
|
||||
public static Result<String, Component> checkMinionNameWithoutPrefix(MinecraftServer server, String name) {
|
||||
for(char c : name.toCharArray()) {
|
||||
if(!StringReader.isAllowedInUnquotedString(c)) {
|
||||
return new Result.Error<>(Text.translatable("minions.generic.name.invalid_char"));
|
||||
return new Result.Error<>(Component.translatable("minions.generic.name.invalid_char"));
|
||||
}
|
||||
}
|
||||
|
||||
if((PREFIX + name).length() > 16) {
|
||||
return new Result.Error<>(Text.translatable("minions.generic.name.too_long"));
|
||||
if((getPrefix() + name).length() > 16) {
|
||||
return new Result.Error<>(Component.translatable("minions.generic.name.too_long"));
|
||||
}
|
||||
|
||||
if(!StringHelper.isValidPlayerName(PREFIX + name)) {
|
||||
return new Result.Error<>(Text.translatable("minions.generic.name.invalid"));
|
||||
if(!StringUtil.isValidPlayerName(getPrefix() + name)) {
|
||||
return new Result.Error<>(Component.translatable("minions.generic.name.invalid"));
|
||||
}
|
||||
|
||||
if(MinionPersistentState.INSTANCE.isMinionNameTaken(PREFIX + name)) {
|
||||
return new Result.Error<>(Text.translatable("minions.generic.name.taken"));
|
||||
if(MinionPersistentState.get(server).isMinionNameTaken(getPrefix() + name)) {
|
||||
return new Result.Error<>(Component.translatable("minions.generic.name.taken"));
|
||||
}
|
||||
|
||||
return new Result.Success<>(name);
|
||||
}
|
||||
|
||||
public static String newDefaultMinionName() {
|
||||
public static String newDefaultMinionName(MinecraftServer server) {
|
||||
int i = 0;
|
||||
while (MinionPersistentState.INSTANCE.isMinionNameTaken("+Minion" + i)) {
|
||||
while (MinionPersistentState.get(server).isMinionNameTaken("+Minion" + i)) {
|
||||
i++;
|
||||
}
|
||||
return "+Minion" + i;
|
||||
}
|
||||
|
||||
public static boolean isMinion(UUID uuid) {
|
||||
return MinionPersistentState.INSTANCE.isMinion(uuid);
|
||||
public static boolean isMinion(MinecraftServer server, UUID uuid) {
|
||||
return MinionPersistentState.get(server).isMinion(uuid);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,145 @@
|
||||
package io.github.skippyall.minions.minion;
|
||||
|
||||
import io.github.skippyall.minions.Minions;
|
||||
import io.github.skippyall.minions.minion.fakeplayer.MinionFakePlayer;
|
||||
import io.github.skippyall.minions.program.InstructionRuntime;
|
||||
import io.github.skippyall.minions.program.consumer.ValueConsumerType;
|
||||
import io.github.skippyall.minions.program.instruction.ConfiguredInstruction;
|
||||
import io.github.skippyall.minions.program.instruction.InstructionType;
|
||||
import io.github.skippyall.minions.program.supplier.ValueSupplierType;
|
||||
import io.github.skippyall.minions.registration.MinionRegistries;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import net.minecraft.core.Registry;
|
||||
import net.minecraft.world.level.storage.ValueInput;
|
||||
import net.minecraft.world.level.storage.ValueOutput;
|
||||
|
||||
public class MinionRuntime implements InstructionRuntime<MinionRuntime> {
|
||||
private final MinionFakePlayer minion;
|
||||
private final Map<String, ConfiguredInstruction<MinionRuntime>> configuredInstructions = new HashMap<>();
|
||||
|
||||
public MinionRuntime(MinionFakePlayer minion) {
|
||||
this.minion = minion;
|
||||
}
|
||||
|
||||
public MinionFakePlayer getMinion() {
|
||||
return minion;
|
||||
}
|
||||
|
||||
public void tick() {
|
||||
for (ConfiguredInstruction<MinionRuntime> instruction : configuredInstructions.values()) {
|
||||
instruction.tick(this);
|
||||
}
|
||||
}
|
||||
|
||||
public void disableInstructionType(InstructionType<MinionRuntime> instructionType) {
|
||||
updatePausedStatus(instructionType);
|
||||
}
|
||||
|
||||
public void enableInstructionType(InstructionType<MinionRuntime> instructionType) {
|
||||
updatePausedStatus(instructionType);
|
||||
}
|
||||
|
||||
public void updatePausedStatus(InstructionType<MinionRuntime> instructionType) {
|
||||
for(ConfiguredInstruction<MinionRuntime> instruction : configuredInstructions.values()) {
|
||||
if(instruction.getInstruction() == instructionType) {
|
||||
instruction.updatePauseStatus(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInstructionEnabled(InstructionType<MinionRuntime> type) {
|
||||
return minion.getModuleInventory().hasInstruction(type);
|
||||
}
|
||||
|
||||
public Set<String> getInstructionNames() {
|
||||
return configuredInstructions.keySet();
|
||||
}
|
||||
|
||||
public ConfiguredInstruction<MinionRuntime> createInstruction(String name, InstructionType<MinionRuntime> instructionType) {
|
||||
if(configuredInstructions.containsKey(name)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
ConfiguredInstruction<MinionRuntime> instruction = new ConfiguredInstruction<>(instructionType);
|
||||
configuredInstructions.put(name, instruction);
|
||||
minion.forEachMinionListener(listener -> listener.onInstructionsUpdate(minion));
|
||||
return instruction;
|
||||
}
|
||||
|
||||
public void removeInstruction(String name) {
|
||||
ConfiguredInstruction<MinionRuntime> instruction = getInstruction(name);
|
||||
instruction.stop(this);
|
||||
configuredInstructions.remove(name);
|
||||
|
||||
instruction.onInstructionRemove();
|
||||
minion.forEachMinionListener(listener -> listener.onInstructionsUpdate(minion));
|
||||
}
|
||||
|
||||
public ConfiguredInstruction<MinionRuntime> getInstruction(String name) {
|
||||
return configuredInstructions.get(name);
|
||||
}
|
||||
|
||||
public boolean hasInstruction(String name) {
|
||||
return configuredInstructions.containsKey(name);
|
||||
}
|
||||
|
||||
public void setInstructionName(String oldName, String newName) {
|
||||
if(!configuredInstructions.containsKey(newName) && configuredInstructions.containsKey(oldName)) {
|
||||
ConfiguredInstruction<MinionRuntime> instruction = configuredInstructions.get(oldName);
|
||||
configuredInstructions.remove(oldName);
|
||||
configuredInstructions.put(newName, instruction);
|
||||
|
||||
|
||||
minion.forEachMinionListener(minionListener -> {
|
||||
minionListener.onInstructionRename(minion, instruction, oldName, newName);
|
||||
minionListener.onInstructionsUpdate(minion);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public void save(ValueOutput view) {
|
||||
ValueOutput.ValueOutputList list = view.childrenList("configuredInstructions");
|
||||
for (Map.Entry<String, ConfiguredInstruction<MinionRuntime>> instruction : configuredInstructions.entrySet()) {
|
||||
ValueOutput inner = list.addChild();
|
||||
inner.putString("name", instruction.getKey());
|
||||
instruction.getValue().save(inner, this);
|
||||
}
|
||||
}
|
||||
|
||||
public void load(ValueInput view) {
|
||||
ValueInput.ValueInputList list = view.childrenListOrEmpty("configuredInstructions");
|
||||
for (ValueInput inner : list) {
|
||||
Optional<String> name = inner.getString("name");
|
||||
if(name.isEmpty()) {
|
||||
Minions.LOGGER.error("Tried deserializing configured instruction without a name of minion \"{}\":", minion.getGameProfile().getName());
|
||||
continue;
|
||||
}
|
||||
|
||||
try {
|
||||
ConfiguredInstruction<MinionRuntime> instruction = ConfiguredInstruction.load(inner, this);
|
||||
configuredInstructions.put(name.get(), instruction);
|
||||
} catch (Exception e) {
|
||||
Minions.LOGGER.error("Could not deserialize configured instruction \"{}\" of minion \"{}\":", name.get(), minion.getGameProfile().getName(), e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Registry<ValueSupplierType<MinionRuntime>> getArgumentTypeRegistry() {
|
||||
return MinionRegistries.VALUE_SUPPLIER_TYPES;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Registry<InstructionType<MinionRuntime>> getInstructionTypeRegistry() {
|
||||
return MinionRegistries.INSTRUCTION_TYPES;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Registry<ValueConsumerType<MinionRuntime>> getValueConsumerTypeRegistry() {
|
||||
return MinionRegistries.VALUE_CONSUMER_TYPES;
|
||||
}
|
||||
}
|
||||
+144
-127
@@ -2,44 +2,43 @@
|
||||
package io.github.skippyall.minions.minion.fakeplayer;
|
||||
|
||||
|
||||
import io.github.skippyall.minions.mixins.EntityAccessor;
|
||||
import java.util.EnumMap;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import io.github.skippyall.minions.mixins.EntityAccessor;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.command.argument.EntityAnchorArgumentType;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.decoration.ItemFrameEntity;
|
||||
import net.minecraft.entity.passive.AbstractHorseEntity;
|
||||
import net.minecraft.entity.player.PlayerInventory;
|
||||
import net.minecraft.entity.vehicle.BoatEntity;
|
||||
import net.minecraft.entity.vehicle.MinecartEntity;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.network.packet.c2s.play.PlayerActionC2SPacket;
|
||||
import net.minecraft.network.packet.s2c.play.UpdateSelectedSlotS2CPacket;
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
import net.minecraft.server.world.ServerWorld;
|
||||
import net.minecraft.util.ActionResult;
|
||||
import net.minecraft.util.Hand;
|
||||
import net.minecraft.util.hit.BlockHitResult;
|
||||
import net.minecraft.util.hit.EntityHitResult;
|
||||
import net.minecraft.util.hit.HitResult;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.Direction;
|
||||
import net.minecraft.util.math.MathHelper;
|
||||
import net.minecraft.util.math.Vec2f;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
import net.minecraft.commands.arguments.EntityAnchorArgument;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.network.protocol.game.ClientboundSetHeldSlotPacket;
|
||||
import net.minecraft.network.protocol.game.ServerboundPlayerActionPacket;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.util.Mth;
|
||||
import net.minecraft.world.InteractionHand;
|
||||
import net.minecraft.world.InteractionResult;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.entity.animal.horse.AbstractHorse;
|
||||
import net.minecraft.world.entity.decoration.ItemFrame;
|
||||
import net.minecraft.world.entity.player.Inventory;
|
||||
import net.minecraft.world.entity.vehicle.Boat;
|
||||
import net.minecraft.world.entity.vehicle.Minecart;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.phys.BlockHitResult;
|
||||
import net.minecraft.world.phys.EntityHitResult;
|
||||
import net.minecraft.world.phys.HitResult;
|
||||
import net.minecraft.world.phys.Vec2;
|
||||
import net.minecraft.world.phys.Vec3;
|
||||
|
||||
public class EntityPlayerActionPack
|
||||
{
|
||||
private final ServerPlayerEntity player;
|
||||
private final MinionFakePlayer player;
|
||||
|
||||
private final Map<ActionType, Action> actions = new EnumMap<>(ActionType.class);
|
||||
|
||||
private BlockPos currentBlock;
|
||||
private int blockHitDelay;
|
||||
public int blockHitDelay;
|
||||
private boolean isHittingBlock;
|
||||
private float curBlockDamageMP;
|
||||
|
||||
@@ -50,7 +49,7 @@ public class EntityPlayerActionPack
|
||||
|
||||
private int itemUseCooldown;
|
||||
|
||||
public EntityPlayerActionPack(ServerPlayerEntity playerIn)
|
||||
public EntityPlayerActionPack(MinionFakePlayer playerIn)
|
||||
{
|
||||
player = playerIn;
|
||||
stopAll();
|
||||
@@ -71,6 +70,14 @@ public class EntityPlayerActionPack
|
||||
itemUseCooldown = other.itemUseCooldown;
|
||||
}
|
||||
|
||||
public Action getAction(ActionType type) {
|
||||
return actions.get(type);
|
||||
}
|
||||
|
||||
public boolean hasAction(ActionType type) {
|
||||
return actions.containsKey(type);
|
||||
}
|
||||
|
||||
public EntityPlayerActionPack start(ActionType type, Action action)
|
||||
{
|
||||
Action previous = actions.remove(type);
|
||||
@@ -92,7 +99,7 @@ public class EntityPlayerActionPack
|
||||
public EntityPlayerActionPack setSneaking(boolean doSneak)
|
||||
{
|
||||
sneaking = doSneak;
|
||||
player.setSneaking(doSneak);
|
||||
player.setShiftKeyDown(doSneak);
|
||||
if (sprinting && sneaking)
|
||||
setSprinting(false);
|
||||
return this;
|
||||
@@ -124,35 +131,35 @@ public class EntityPlayerActionPack
|
||||
case SOUTH -> look(0, 0);
|
||||
case EAST -> look(-90, 0);
|
||||
case WEST -> look(90, 0);
|
||||
case UP -> look(player.getYaw(), -90);
|
||||
case DOWN -> look(player.getYaw(), 90);
|
||||
case UP -> look(player.getYRot(), -90);
|
||||
case DOWN -> look(player.getYRot(), 90);
|
||||
};
|
||||
}
|
||||
public EntityPlayerActionPack look(Vec2f rotation)
|
||||
public EntityPlayerActionPack look(Vec2 rotation)
|
||||
{
|
||||
return look(rotation.x, rotation.y);
|
||||
}
|
||||
|
||||
public EntityPlayerActionPack look(float yaw, float pitch)
|
||||
{
|
||||
player.setYaw(yaw % 360); //setYaw
|
||||
player.setPitch(MathHelper.clamp(pitch, -90, 90)); // setPitch
|
||||
player.setYRot(yaw % 360); //setYaw
|
||||
player.setXRot(Mth.clamp(pitch, -90, 90)); // setPitch
|
||||
// maybe player.moveTo(player.getX(), player.getY(), player.getZ(), yaw, Mth.clamp(pitch,-90.0F, 90.0F));
|
||||
return this;
|
||||
}
|
||||
|
||||
public EntityPlayerActionPack lookAt(Vec3d position)
|
||||
public EntityPlayerActionPack lookAt(Vec3 position)
|
||||
{
|
||||
player.lookAt(EntityAnchorArgumentType.EntityAnchor.EYES, position);
|
||||
player.lookAt(EntityAnchorArgument.Anchor.EYES, position);
|
||||
return this;
|
||||
}
|
||||
|
||||
public EntityPlayerActionPack turn(float yaw, float pitch)
|
||||
{
|
||||
return look(player.getYaw() + yaw, player.getPitch() + pitch);
|
||||
return look(player.getYRot() + yaw, player.getXRot() + pitch);
|
||||
}
|
||||
|
||||
public EntityPlayerActionPack turn(Vec2f rotation)
|
||||
public EntityPlayerActionPack turn(Vec2 rotation)
|
||||
{
|
||||
return turn(rotation.x, rotation.y);
|
||||
}
|
||||
@@ -181,12 +188,12 @@ public class EntityPlayerActionPack
|
||||
List<Entity> entities;
|
||||
if (onlyRideables)
|
||||
{
|
||||
entities = player.getWorld().getOtherEntities(player, player.getBoundingBox().expand(3.0D, 1.0D, 3.0D),
|
||||
e -> (e instanceof MinecartEntity || e instanceof BoatEntity || e instanceof AbstractHorseEntity) && ((EntityAccessor)e).invokeCanAddPassenger(player));
|
||||
entities = player.level().getEntities(player, player.getBoundingBox().inflate(3.0D, 1.0D, 3.0D),
|
||||
e -> (e instanceof Minecart || e instanceof Boat || e instanceof AbstractHorse) && ((EntityAccessor)e).minions$canAddPassenger(player));
|
||||
}
|
||||
else
|
||||
{
|
||||
entities = player.getWorld().getOtherEntities(player, player.getBoundingBox().expand(3.0D, 1.0D, 3.0D));
|
||||
entities = player.level().getEntities(player, player.getBoundingBox().inflate(3.0D, 1.0D, 3.0D));
|
||||
}
|
||||
if (entities.size()==0)
|
||||
return this;
|
||||
@@ -197,7 +204,7 @@ public class EntityPlayerActionPack
|
||||
{
|
||||
if (e == player || (currentVehicle == e))
|
||||
continue;
|
||||
double dd = player.squaredDistanceTo(e);
|
||||
double dd = player.distanceToSqr(e);
|
||||
if (dd<distance)
|
||||
{
|
||||
distance = dd;
|
||||
@@ -205,8 +212,8 @@ public class EntityPlayerActionPack
|
||||
}
|
||||
}
|
||||
if (closest == null) return this;
|
||||
if (closest instanceof AbstractHorseEntity && onlyRideables)
|
||||
((AbstractHorseEntity) closest).interactMob(player, Hand.MAIN_HAND);
|
||||
if (closest instanceof AbstractHorse && onlyRideables)
|
||||
((AbstractHorse) closest).mobInteract(player, InteractionHand.MAIN_HAND);
|
||||
else
|
||||
player.startRiding(closest, !onlyRideables);
|
||||
return this;
|
||||
@@ -248,48 +255,52 @@ public class EntityPlayerActionPack
|
||||
float vel = sneaking?0.3F:1.0F;
|
||||
// The != 0.0F checks are needed given else real players can't control minecarts, however it works with fakes and else they don't stop immediately
|
||||
if (forward != 0.0F || player instanceof MinionFakePlayer) {
|
||||
player.forwardSpeed = forward * vel;
|
||||
player.zza = forward * vel;
|
||||
}
|
||||
if (strafing != 0.0F || player instanceof MinionFakePlayer) {
|
||||
player.sidewaysSpeed = strafing * vel;
|
||||
player.xxa = strafing * vel;
|
||||
}
|
||||
|
||||
if(blockHitDelay > 0) {
|
||||
blockHitDelay--;
|
||||
}
|
||||
}
|
||||
|
||||
static HitResult getTarget(ServerPlayerEntity player)
|
||||
public static HitResult getTarget(ServerPlayer player)
|
||||
{
|
||||
double reach = player.interactionManager.isCreative() ? 5 : 4.5f;
|
||||
double reach = player.gameMode.isCreative() ? 5 : 4.5f;
|
||||
return Tracer.rayTrace(player, 1, reach, false);
|
||||
}
|
||||
|
||||
private void dropItemFromSlot(int slot, boolean dropAll)
|
||||
{
|
||||
PlayerInventory inv = player.getInventory(); // getInventory;
|
||||
if (!inv.getStack(slot).isEmpty())
|
||||
player.dropItem(inv.removeStack(slot,
|
||||
dropAll ? inv.getStack(slot).getCount() : 1
|
||||
Inventory inv = player.getInventory(); // getInventory;
|
||||
if (!inv.getItem(slot).isEmpty())
|
||||
player.drop(inv.removeItem(slot,
|
||||
dropAll ? inv.getItem(slot).getCount() : 1
|
||||
), false, true); // scatter, keep owner
|
||||
}
|
||||
|
||||
public void drop(int selectedSlot, boolean dropAll)
|
||||
{
|
||||
PlayerInventory inv = player.getInventory(); // getInventory;
|
||||
Inventory inv = player.getInventory(); // getInventory;
|
||||
if (selectedSlot == -2) // all
|
||||
{
|
||||
for (int i = inv.size(); i >= 0; i--)
|
||||
for (int i = inv.getContainerSize(); i >= 0; i--)
|
||||
dropItemFromSlot(i, dropAll);
|
||||
}
|
||||
else // one slot
|
||||
{
|
||||
if (selectedSlot == -1)
|
||||
selectedSlot = inv.selectedSlot;
|
||||
selectedSlot = inv.getSelectedSlot();
|
||||
dropItemFromSlot(selectedSlot, dropAll);
|
||||
}
|
||||
}
|
||||
|
||||
public void setSlot(int slot)
|
||||
{
|
||||
player.getInventory().selectedSlot = slot-1;
|
||||
player.networkHandler.sendPacket(new UpdateSelectedSlotS2CPacket(slot-1));
|
||||
player.getInventory().setSelectedSlot(slot-1);
|
||||
player.connection.send(new ClientboundSetHeldSlotPacket(slot-1));
|
||||
}
|
||||
|
||||
public enum ActionType
|
||||
@@ -297,9 +308,9 @@ public class EntityPlayerActionPack
|
||||
USE(true)
|
||||
{
|
||||
@Override
|
||||
boolean execute(ServerPlayerEntity player, Action action)
|
||||
boolean execute(MinionFakePlayer player, Action action)
|
||||
{
|
||||
EntityPlayerActionPack ap = ((ServerPlayerInterface) player).minions$getActionPack();
|
||||
EntityPlayerActionPack ap = player.getMinionActionPack();
|
||||
if (ap.itemUseCooldown > 0)
|
||||
{
|
||||
ap.itemUseCooldown--;
|
||||
@@ -310,23 +321,23 @@ public class EntityPlayerActionPack
|
||||
return true;
|
||||
}
|
||||
HitResult hit = getTarget(player);
|
||||
for (Hand hand : Hand.values())
|
||||
for (InteractionHand hand : InteractionHand.values())
|
||||
{
|
||||
switch (hit.getType())
|
||||
{
|
||||
case BLOCK:
|
||||
{
|
||||
player.updateLastActionTime();
|
||||
ServerWorld world = player.getServerWorld();
|
||||
player.resetLastActionTime();
|
||||
ServerLevel world = player.level();
|
||||
BlockHitResult blockHit = (BlockHitResult) hit;
|
||||
BlockPos pos = blockHit.getBlockPos();
|
||||
Direction side = blockHit.getSide();
|
||||
if (pos.getY() < player.getServerWorld().getTopYInclusive() - (side == Direction.UP ? 1 : 0) && world.canPlayerModifyAt(player, pos))
|
||||
Direction side = blockHit.getDirection();
|
||||
if (pos.getY() < player.level().getMaxY() - (side == Direction.UP ? 1 : 0) && world.mayInteract(player, pos))
|
||||
{
|
||||
ActionResult result = player.interactionManager.interactBlock(player, world, player.getStackInHand(hand), hand, blockHit);
|
||||
if (result instanceof ActionResult.Success success)
|
||||
InteractionResult result = player.gameMode.useItemOn(player, world, player.getItemInHand(hand), hand, blockHit);
|
||||
if (result instanceof InteractionResult.Success success)
|
||||
{
|
||||
if (success.swingSource() == ActionResult.SwingSource.SERVER) player.swingHand(hand);
|
||||
if (success.swingSource() == InteractionResult.SwingSource.SERVER) player.swing(hand);
|
||||
ap.itemUseCooldown = 3;
|
||||
return true;
|
||||
}
|
||||
@@ -335,19 +346,19 @@ public class EntityPlayerActionPack
|
||||
}
|
||||
case ENTITY:
|
||||
{
|
||||
player.updateLastActionTime();
|
||||
player.resetLastActionTime();
|
||||
EntityHitResult entityHit = (EntityHitResult) hit;
|
||||
Entity entity = entityHit.getEntity();
|
||||
boolean handWasEmpty = player.getStackInHand(hand).isEmpty();
|
||||
boolean itemFrameEmpty = (entity instanceof ItemFrameEntity) && ((ItemFrameEntity) entity).getHeldItemStack().isEmpty();
|
||||
Vec3d relativeHitPos = entityHit.getPos().subtract(entity.getX(), entity.getY(), entity.getZ());
|
||||
if (entity.interactAt(player, relativeHitPos, hand).isAccepted())
|
||||
boolean handWasEmpty = player.getItemInHand(hand).isEmpty();
|
||||
boolean itemFrameEmpty = (entity instanceof ItemFrame) && ((ItemFrame) entity).getItem().isEmpty();
|
||||
Vec3 relativeHitPos = entityHit.getLocation().subtract(entity.getX(), entity.getY(), entity.getZ());
|
||||
if (entity.interactAt(player, relativeHitPos, hand).consumesAction())
|
||||
{
|
||||
ap.itemUseCooldown = 3;
|
||||
return true;
|
||||
}
|
||||
// fix for SS itemframe always returns CONSUME even if no action is performed
|
||||
if (player.interact(entity, hand).isAccepted() && !(handWasEmpty && itemFrameEmpty))
|
||||
if (player.interactOn(entity, hand).consumesAction() && !(handWasEmpty && itemFrameEmpty))
|
||||
{
|
||||
ap.itemUseCooldown = 3;
|
||||
return true;
|
||||
@@ -355,8 +366,8 @@ public class EntityPlayerActionPack
|
||||
break;
|
||||
}
|
||||
}
|
||||
ItemStack handItem = player.getStackInHand(hand);
|
||||
if (player.interactionManager.interactItem(player, player.getWorld(), handItem, hand).isAccepted())
|
||||
ItemStack handItem = player.getItemInHand(hand);
|
||||
if (player.gameMode.useItem(player, player.level(), handItem, hand).consumesAction())
|
||||
{
|
||||
ap.itemUseCooldown = 3;
|
||||
return true;
|
||||
@@ -366,50 +377,49 @@ public class EntityPlayerActionPack
|
||||
}
|
||||
|
||||
@Override
|
||||
void inactiveTick(ServerPlayerEntity player, Action action)
|
||||
void inactiveTick(MinionFakePlayer player, Action action)
|
||||
{
|
||||
EntityPlayerActionPack ap = ((ServerPlayerInterface) player).minions$getActionPack();
|
||||
EntityPlayerActionPack ap = player.getMinionActionPack();
|
||||
ap.itemUseCooldown = 0;
|
||||
player.stopUsingItem();
|
||||
player.releaseUsingItem();
|
||||
}
|
||||
},
|
||||
ATTACK(true) {
|
||||
@Override
|
||||
boolean execute(ServerPlayerEntity player, Action action) {
|
||||
boolean execute(MinionFakePlayer player, Action action) {
|
||||
HitResult hit = getTarget(player);
|
||||
switch (hit.getType()) {
|
||||
case ENTITY: {
|
||||
EntityHitResult entityHit = (EntityHitResult) hit;
|
||||
if (!action.isContinuous)
|
||||
if (!action.isContinuous || action.first)
|
||||
{
|
||||
player.attack(entityHit.getEntity());
|
||||
player.swingHand(Hand.MAIN_HAND);
|
||||
player.swing(InteractionHand.MAIN_HAND);
|
||||
}
|
||||
player.resetLastAttackedTicks();
|
||||
player.updateLastActionTime();
|
||||
player.resetAttackStrengthTicker();
|
||||
player.resetLastActionTime();
|
||||
return true;
|
||||
}
|
||||
case BLOCK: {
|
||||
EntityPlayerActionPack ap = ((ServerPlayerInterface) player).minions$getActionPack();
|
||||
EntityPlayerActionPack ap = player.getMinionActionPack();
|
||||
if (ap.blockHitDelay > 0)
|
||||
{
|
||||
ap.blockHitDelay--;
|
||||
return false;
|
||||
}
|
||||
BlockHitResult blockHit = (BlockHitResult) hit;
|
||||
BlockPos pos = blockHit.getBlockPos();
|
||||
Direction side = blockHit.getSide();
|
||||
if (player.isBlockBreakingRestricted(player.getWorld(), pos, player.interactionManager.getGameMode())) return false;
|
||||
if (ap.currentBlock != null && player.getWorld().getBlockState(ap.currentBlock).isAir())
|
||||
Direction side = blockHit.getDirection();
|
||||
if (player.blockActionRestricted(player.level(), pos, player.gameMode.getGameModeForPlayer())) return false;
|
||||
if (ap.currentBlock != null && player.level().getBlockState(ap.currentBlock).isAir())
|
||||
{
|
||||
ap.currentBlock = null;
|
||||
return false;
|
||||
}
|
||||
BlockState state = player.getWorld().getBlockState(pos);
|
||||
BlockState state = player.level().getBlockState(pos);
|
||||
boolean blockBroken = false;
|
||||
if (player.interactionManager.getGameMode().isCreative())
|
||||
if (player.gameMode.getGameModeForPlayer().isCreative())
|
||||
{
|
||||
player.interactionManager.processBlockBreakingAction(pos, PlayerActionC2SPacket.Action.START_DESTROY_BLOCK, side, player.getWorld().getTopYInclusive(), -1);
|
||||
player.gameMode.handleBlockBreakAction(pos, ServerboundPlayerActionPacket.Action.START_DESTROY_BLOCK, side, player.level().getMaxY(), -1);
|
||||
ap.blockHitDelay = 5;
|
||||
blockBroken = true;
|
||||
}
|
||||
@@ -417,15 +427,15 @@ public class EntityPlayerActionPack
|
||||
{
|
||||
if (ap.currentBlock != null)
|
||||
{
|
||||
player.interactionManager.processBlockBreakingAction(ap.currentBlock, PlayerActionC2SPacket.Action.ABORT_DESTROY_BLOCK, side, player.getWorld().getTopYInclusive(), -1);
|
||||
player.gameMode.handleBlockBreakAction(ap.currentBlock, ServerboundPlayerActionPacket.Action.ABORT_DESTROY_BLOCK, side, player.level().getMaxY(), -1);
|
||||
}
|
||||
player.interactionManager.processBlockBreakingAction(pos, PlayerActionC2SPacket.Action.START_DESTROY_BLOCK, side, player.getWorld().getTopYInclusive(), -1);
|
||||
player.gameMode.handleBlockBreakAction(pos, ServerboundPlayerActionPacket.Action.START_DESTROY_BLOCK, side, player.level().getMaxY(), -1);
|
||||
boolean notAir = !state.isAir();
|
||||
if (notAir && ap.curBlockDamageMP == 0)
|
||||
{
|
||||
state.onBlockBreakStart(player.getWorld(), pos, player);
|
||||
state.attack(player.level(), pos, player);
|
||||
}
|
||||
if (notAir && state.calcBlockBreakingDelta(player, player.getWorld(), pos) >= 1)
|
||||
if (notAir && state.getDestroyProgress(player, player.level(), pos) >= 1)
|
||||
{
|
||||
ap.currentBlock = null;
|
||||
//instamine??
|
||||
@@ -439,19 +449,19 @@ public class EntityPlayerActionPack
|
||||
}
|
||||
else
|
||||
{
|
||||
ap.curBlockDamageMP += state.calcBlockBreakingDelta(player, player.getWorld(), pos);
|
||||
ap.curBlockDamageMP += state.getDestroyProgress(player, player.level(), pos);
|
||||
if (ap.curBlockDamageMP >= 1)
|
||||
{
|
||||
player.interactionManager.processBlockBreakingAction(pos, PlayerActionC2SPacket.Action.STOP_DESTROY_BLOCK, side, player.getWorld().getTopYInclusive(), -1);
|
||||
player.gameMode.handleBlockBreakAction(pos, ServerboundPlayerActionPacket.Action.STOP_DESTROY_BLOCK, side, player.level().getMaxY(), -1);
|
||||
ap.currentBlock = null;
|
||||
ap.blockHitDelay = 5;
|
||||
blockBroken = true;
|
||||
}
|
||||
player.getWorld().setBlockBreakingInfo(-1, pos, (int) (ap.curBlockDamageMP * 10));
|
||||
player.level().destroyBlockProgress(-1, pos, (int) (ap.curBlockDamageMP * 10));
|
||||
|
||||
}
|
||||
player.updateLastActionTime();
|
||||
player.swingHand(Hand.MAIN_HAND);
|
||||
player.resetLastActionTime();
|
||||
player.swing(InteractionHand.MAIN_HAND);
|
||||
return blockBroken;
|
||||
}
|
||||
}
|
||||
@@ -459,23 +469,23 @@ public class EntityPlayerActionPack
|
||||
}
|
||||
|
||||
@Override
|
||||
void inactiveTick(ServerPlayerEntity player, Action action)
|
||||
void inactiveTick(MinionFakePlayer player, Action action)
|
||||
{
|
||||
EntityPlayerActionPack ap = ((ServerPlayerInterface) player).minions$getActionPack();
|
||||
EntityPlayerActionPack ap = player.getMinionActionPack();
|
||||
if (ap.currentBlock == null) return;
|
||||
player.getWorld().setBlockBreakingInfo(-1, ap.currentBlock, -1);
|
||||
player.interactionManager.processBlockBreakingAction(ap.currentBlock, PlayerActionC2SPacket.Action.ABORT_DESTROY_BLOCK, Direction.DOWN, player.getWorld().getTopYInclusive(), -1);
|
||||
player.level().destroyBlockProgress(-1, ap.currentBlock, -1);
|
||||
player.gameMode.handleBlockBreakAction(ap.currentBlock, ServerboundPlayerActionPacket.Action.ABORT_DESTROY_BLOCK, Direction.DOWN, player.level().getMaxY(), -1);
|
||||
ap.currentBlock = null;
|
||||
}
|
||||
},
|
||||
JUMP(true)
|
||||
{
|
||||
@Override
|
||||
boolean execute(ServerPlayerEntity player, Action action)
|
||||
boolean execute(MinionFakePlayer player, Action action)
|
||||
{
|
||||
if (action.limit == 1)
|
||||
{
|
||||
if (player.isOnGround()) player.jump(); // onGround
|
||||
if (player.onGround()) player.jumpFromGround(); // onGround
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -485,7 +495,7 @@ public class EntityPlayerActionPack
|
||||
}
|
||||
|
||||
@Override
|
||||
void inactiveTick(ServerPlayerEntity player, Action action)
|
||||
void inactiveTick(MinionFakePlayer player, Action action)
|
||||
{
|
||||
player.setJumping(false);
|
||||
}
|
||||
@@ -493,32 +503,32 @@ public class EntityPlayerActionPack
|
||||
DROP_ITEM(true)
|
||||
{
|
||||
@Override
|
||||
boolean execute(ServerPlayerEntity player, Action action)
|
||||
boolean execute(MinionFakePlayer player, Action action)
|
||||
{
|
||||
player.updateLastActionTime();
|
||||
player.dropSelectedItem(false); // dropSelectedItem
|
||||
player.resetLastActionTime();
|
||||
player.drop(false); // dropSelectedItem
|
||||
return false;
|
||||
}
|
||||
},
|
||||
DROP_STACK(true)
|
||||
{
|
||||
@Override
|
||||
boolean execute(ServerPlayerEntity player, Action action)
|
||||
boolean execute(MinionFakePlayer player, Action action)
|
||||
{
|
||||
player.updateLastActionTime();
|
||||
player.dropSelectedItem(true); // dropSelectedItem
|
||||
player.resetLastActionTime();
|
||||
player.drop(true); // dropSelectedItem
|
||||
return false;
|
||||
}
|
||||
},
|
||||
SWAP_HANDS(true)
|
||||
{
|
||||
@Override
|
||||
boolean execute(ServerPlayerEntity player, Action action)
|
||||
boolean execute(MinionFakePlayer player, Action action)
|
||||
{
|
||||
player.updateLastActionTime();
|
||||
ItemStack itemStack_1 = player.getStackInHand(Hand.OFF_HAND);
|
||||
player.setStackInHand(Hand.OFF_HAND, player.getStackInHand(Hand.MAIN_HAND));
|
||||
player.setStackInHand(Hand.MAIN_HAND, itemStack_1);
|
||||
player.resetLastActionTime();
|
||||
ItemStack itemStack_1 = player.getItemInHand(InteractionHand.OFF_HAND);
|
||||
player.setItemInHand(InteractionHand.OFF_HAND, player.getItemInHand(InteractionHand.MAIN_HAND));
|
||||
player.setItemInHand(InteractionHand.MAIN_HAND, itemStack_1);
|
||||
return false;
|
||||
}
|
||||
};
|
||||
@@ -530,10 +540,10 @@ public class EntityPlayerActionPack
|
||||
this.preventSpectator = preventSpectator;
|
||||
}
|
||||
|
||||
void start(ServerPlayerEntity player, Action action) {}
|
||||
abstract boolean execute(ServerPlayerEntity player, Action action);
|
||||
void inactiveTick(ServerPlayerEntity player, Action action) {}
|
||||
void stop(ServerPlayerEntity player, Action action)
|
||||
void start(MinionFakePlayer player, Action action) {}
|
||||
abstract boolean execute(MinionFakePlayer player, Action action);
|
||||
void inactiveTick(MinionFakePlayer player, Action action) {}
|
||||
void stop(MinionFakePlayer player, Action action)
|
||||
{
|
||||
inactiveTick(player, action);
|
||||
}
|
||||
@@ -548,8 +558,9 @@ public class EntityPlayerActionPack
|
||||
private int count;
|
||||
private int next;
|
||||
private final boolean isContinuous;
|
||||
boolean first = true;
|
||||
|
||||
private Action(int limit, int interval, int offset, boolean continuous)
|
||||
private Action(int limit, int interval, int offset, boolean continuous, boolean first)
|
||||
{
|
||||
this.limit = limit;
|
||||
this.interval = interval;
|
||||
@@ -560,22 +571,27 @@ public class EntityPlayerActionPack
|
||||
|
||||
public static Action once()
|
||||
{
|
||||
return new Action(1, 1, 0, false);
|
||||
return new Action(1, 1, 0, false, false);
|
||||
}
|
||||
|
||||
public static Action startContinuous()
|
||||
{
|
||||
return new Action(-1, 1, 0, true, true);
|
||||
}
|
||||
|
||||
public static Action continuous()
|
||||
{
|
||||
return new Action(-1, 1, 0, true);
|
||||
return new Action(-1, 1, 0, true, false);
|
||||
}
|
||||
|
||||
public static Action interval(int interval)
|
||||
{
|
||||
return new Action(-1, interval, 0, false);
|
||||
return new Action(-1, interval, 0, false, false);
|
||||
}
|
||||
|
||||
public static Action interval(int interval, int offset)
|
||||
{
|
||||
return new Action(-1, interval, offset, false);
|
||||
return new Action(-1, interval, offset, false, false);
|
||||
}
|
||||
|
||||
Boolean tick(EntityPlayerActionPack actionPack, ActionType type)
|
||||
@@ -606,6 +622,7 @@ public class EntityPlayerActionPack
|
||||
return cancel;
|
||||
}
|
||||
next = interval;
|
||||
first = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
+9
-9
@@ -2,13 +2,13 @@
|
||||
package io.github.skippyall.minions.minion.fakeplayer;
|
||||
|
||||
import io.netty.channel.embedded.EmbeddedChannel;
|
||||
import net.minecraft.network.ClientConnection;
|
||||
import net.minecraft.network.NetworkSide;
|
||||
import net.minecraft.network.NetworkState;
|
||||
import net.minecraft.network.listener.PacketListener;
|
||||
import net.minecraft.network.Connection;
|
||||
import net.minecraft.network.PacketListener;
|
||||
import net.minecraft.network.ProtocolInfo;
|
||||
import net.minecraft.network.protocol.PacketFlow;
|
||||
|
||||
public class FakeClientConnection extends ClientConnection {
|
||||
public FakeClientConnection(NetworkSide p)
|
||||
public class FakeClientConnection extends Connection {
|
||||
public FakeClientConnection(PacketFlow p)
|
||||
{
|
||||
super(p);
|
||||
// compat with adventure-platform-fabric. This does NOT trigger other vanilla handlers for establishing a channel
|
||||
@@ -17,7 +17,7 @@ public class FakeClientConnection extends ClientConnection {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void tryDisableAutoRead()
|
||||
public void setReadOnly()
|
||||
{
|
||||
}
|
||||
|
||||
@@ -26,11 +26,11 @@ public class FakeClientConnection extends ClientConnection {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setInitialPacketListener(PacketListener packetListener)
|
||||
public void setListenerForServerboundHandshake(PacketListener packetListener)
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T extends PacketListener> void transitionInbound(NetworkState<T> state, T packetListener) {
|
||||
public <T extends PacketListener> void setupInboundProtocol(ProtocolInfo<T> state, T packetListener) {
|
||||
}
|
||||
}
|
||||
|
||||
+181
-181
@@ -3,308 +3,308 @@ package io.github.skippyall.minions.minion.fakeplayer;
|
||||
|
||||
import com.mojang.authlib.GameProfile;
|
||||
import com.mojang.authlib.properties.PropertyMap;
|
||||
import io.github.skippyall.minions.Minions;
|
||||
import io.github.skippyall.minions.MinionsTickExecutor;
|
||||
import io.github.skippyall.minions.gui.minion.MinionGui;
|
||||
import io.github.skippyall.minions.listener.SerializableListenerManager;
|
||||
import io.github.skippyall.minions.minion.MinionData;
|
||||
import io.github.skippyall.minions.gui.MinionGui;
|
||||
import io.github.skippyall.minions.minion.MinionItem;
|
||||
import io.github.skippyall.minions.minion.MinionListener;
|
||||
import io.github.skippyall.minions.minion.MinionPersistentState;
|
||||
import io.github.skippyall.minions.minion.MinionProfileUtils;
|
||||
import io.github.skippyall.minions.gui.ModuleInventory;
|
||||
import io.github.skippyall.minions.program.runtime.MinionRuntime;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.EndPortalBlock;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.EquipmentSlot;
|
||||
import net.minecraft.entity.MovementType;
|
||||
import net.minecraft.entity.attribute.EntityAttributes;
|
||||
import net.minecraft.entity.damage.DamageSource;
|
||||
import net.minecraft.entity.player.HungerManager;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NbtCompound;
|
||||
import net.minecraft.network.DisconnectionInfo;
|
||||
import net.minecraft.network.NetworkSide;
|
||||
import net.minecraft.network.packet.c2s.common.SyncedClientOptions;
|
||||
import net.minecraft.network.packet.c2s.play.ClientStatusC2SPacket;
|
||||
import net.minecraft.network.packet.s2c.play.EntityPositionSyncS2CPacket;
|
||||
import net.minecraft.network.packet.s2c.play.EntitySetHeadYawS2CPacket;
|
||||
import io.github.skippyall.minions.minion.MinionRuntime;
|
||||
import io.github.skippyall.minions.module.ModuleInventory;
|
||||
import io.github.skippyall.minions.registration.MinionConfigOptions;
|
||||
import io.github.skippyall.minions.registration.MinionItems;
|
||||
import io.github.skippyall.minions.registration.SpecialAbilities;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.network.DisconnectionDetails;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.network.chat.contents.TranslatableContents;
|
||||
import net.minecraft.network.protocol.PacketFlow;
|
||||
import net.minecraft.network.protocol.game.ClientboundEntityPositionSyncPacket;
|
||||
import net.minecraft.network.protocol.game.ClientboundRotateHeadPacket;
|
||||
import net.minecraft.network.protocol.game.ServerboundClientCommandPacket;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.server.ServerTask;
|
||||
import net.minecraft.server.network.ConnectedClientData;
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
import net.minecraft.server.world.ServerWorld;
|
||||
import net.minecraft.text.Text;
|
||||
import net.minecraft.text.TranslatableTextContent;
|
||||
import net.minecraft.util.ActionResult;
|
||||
import net.minecraft.util.Hand;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.Vec2f;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
import net.minecraft.world.GameMode;
|
||||
import net.minecraft.world.TeleportTarget;
|
||||
import net.minecraft.server.TickTask;
|
||||
import net.minecraft.server.level.ClientInformation;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.server.network.CommonListenerCookie;
|
||||
import net.minecraft.world.InteractionHand;
|
||||
import net.minecraft.world.InteractionResult;
|
||||
import net.minecraft.world.damagesource.DamageSource;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.entity.EquipmentSlot;
|
||||
import net.minecraft.world.entity.ai.attributes.Attributes;
|
||||
import net.minecraft.world.entity.item.ItemEntity;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.entity.vehicle.AbstractBoat;
|
||||
import net.minecraft.world.food.FoodData;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.level.GameType;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.level.portal.TeleportTransition;
|
||||
import net.minecraft.world.level.storage.ValueInput;
|
||||
import net.minecraft.world.level.storage.ValueOutput;
|
||||
import net.minecraft.world.phys.Vec2;
|
||||
import net.minecraft.world.phys.Vec3;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public class MinionFakePlayer extends ServerPlayerEntity {
|
||||
public class MinionFakePlayer extends ServerPlayer {
|
||||
public Runnable fixStartingPosition = () -> {};
|
||||
|
||||
private float moveForward;
|
||||
private float moveSideways;
|
||||
private EntityPlayerActionPack actionPack;
|
||||
|
||||
private boolean programmable;
|
||||
private final ModuleInventory moduleInventory = new ModuleInventory();
|
||||
private final MinionRuntime runtime = new MinionRuntime(this);
|
||||
|
||||
private final MinionData data;
|
||||
|
||||
public static void spawnMinion(MinionData data, ServerWorld level, @Nullable Vec3d pos, @Nullable Vec2f rot) {
|
||||
MinecraftServer server = level.getServer();
|
||||
|
||||
PropertyMap skin = data.skin().orElse(null);
|
||||
|
||||
GameProfile profile = MinionProfileUtils.makeNewMinionProfile(data.uuid(), data.name(), skin);
|
||||
doSpawn(data, profile, server, level, pos, rot);
|
||||
private final ModuleInventory moduleInventory = new ModuleInventory(this);
|
||||
private final MinionRuntime instructionManager = new MinionRuntime(this);
|
||||
|
||||
public static void spawnMinion(MinionData data, ServerLevel level, @Nullable Vec3 pos, @Nullable Vec2 rot) {
|
||||
spawnMinion(data, level, pos, rot, false);
|
||||
}
|
||||
|
||||
private static void doSpawn(MinionData data, GameProfile profile, MinecraftServer server, ServerWorld level, @Nullable Vec3d pos, @Nullable Vec2f rot) {
|
||||
public static void spawnMinion(MinionData data, ServerLevel level, @Nullable Vec3 pos, @Nullable Vec2 rot, boolean force) {
|
||||
if(!data.isSpawned() || force) {
|
||||
MinecraftServer server = level.getServer();
|
||||
|
||||
MinionFakePlayer instance = new MinionFakePlayer(server, level, profile, SyncedClientOptions.createDefault(), data);
|
||||
MinionPersistentState.INSTANCE.updateMinionData(data.withSpawned(true));
|
||||
PropertyMap skin = data.skin().orElse(null);
|
||||
|
||||
GameProfile profile = MinionProfileUtils.makeNewMinionProfile(data.uuid(), data.name(), skin);
|
||||
server.schedule(server.wrapRunnable(() -> doSpawn(data, profile, server, level, pos, rot)));
|
||||
}
|
||||
}
|
||||
|
||||
private static void doSpawn(MinionData data, GameProfile profile, MinecraftServer server, ServerLevel level, @Nullable Vec3 pos, @Nullable Vec2 rot) {
|
||||
MinionFakePlayer instance = new MinionFakePlayer(server, level, profile, ClientInformation.createDefault());
|
||||
MinionPersistentState.get(server).updateMinionData(data.withSpawned(true));
|
||||
|
||||
if(pos != null && rot != null) {
|
||||
instance.fixStartingPosition = () -> instance.refreshPositionAndAngles(pos.x, pos.y, pos.z, rot.x, rot.y);
|
||||
instance.fixStartingPosition = () -> instance.snapTo(pos.x, pos.y, pos.z, rot.x, rot.y);
|
||||
}
|
||||
server.getPlayerManager().onPlayerConnect(new FakeClientConnection(NetworkSide.SERVERBOUND), instance, new ConnectedClientData(profile, 0, instance.getClientOptions(), false));
|
||||
System.out.println(instance.getPos());
|
||||
server.getPlayerList().placeNewPlayer(new FakeClientConnection(PacketFlow.SERVERBOUND), instance, new CommonListenerCookie(profile, 0, instance.clientInformation(), false));
|
||||
System.out.println(instance.position());
|
||||
if(pos != null && rot != null) {
|
||||
instance.teleport(level, pos.x, pos.y, pos.z, Set.of(), rot.x, rot.y, true);
|
||||
instance.teleportTo(level, pos.x, pos.y, pos.z, Set.of(), rot.x, rot.y, true);
|
||||
}
|
||||
instance.setVelocity(0,0,0);
|
||||
instance.setDeltaMovement(0,0,0);
|
||||
instance.setHealth(20.0F);
|
||||
instance.unsetRemoved();
|
||||
instance.getAttributeInstance(EntityAttributes.STEP_HEIGHT).setBaseValue(0.6F);
|
||||
instance.interactionManager.changeGameMode(GameMode.SURVIVAL);
|
||||
server.getPlayerManager().sendToDimension(new EntitySetHeadYawS2CPacket(instance, (byte) (instance.headYaw * 256 / 360)), level.getRegistryKey());//instance.dimension);
|
||||
server.getPlayerManager().sendToDimension(EntityPositionSyncS2CPacket.create(instance), level.getRegistryKey());//instance.dimension);
|
||||
//instance.world.getChunkManager(). updatePosition(instance);
|
||||
instance.dataTracker.set(PLAYER_MODEL_PARTS, (byte) 0x7f); // show all model layers (incl. capes)
|
||||
instance.getAttribute(Attributes.STEP_HEIGHT).setBaseValue(0.6F);
|
||||
instance.getAttribute(Attributes.WAYPOINT_TRANSMIT_RANGE).setBaseValue(0);
|
||||
instance.gameMode.changeGameModeForPlayer(GameType.SURVIVAL);
|
||||
server.getPlayerList().broadcastAll(new ClientboundRotateHeadPacket(instance, (byte) (instance.yHeadRot * 256 / 360)), level.dimension());
|
||||
server.getPlayerList().broadcastAll(ClientboundEntityPositionSyncPacket.of(instance), level.dimension());
|
||||
instance.level().getChunkSource().move(instance);
|
||||
instance.entityData.set(DATA_PLAYER_MODE_CUSTOMISATION, (byte) 0x7f); // show all model layers (incl. capes)
|
||||
instance.getAbilities().flying = false;
|
||||
|
||||
instance.listeners().forEach(listener -> listener.onMinionSpawn(instance));
|
||||
}
|
||||
|
||||
public static MinionFakePlayer respawnFake(MinecraftServer server, ServerWorld level, GameProfile profile, SyncedClientOptions cli, MinionData data)
|
||||
public static MinionFakePlayer respawnFake(MinecraftServer server, ServerLevel level, GameProfile profile, ClientInformation cli)
|
||||
{
|
||||
return new MinionFakePlayer(server, level, profile, cli, data);
|
||||
return new MinionFakePlayer(server, level, profile, cli);
|
||||
}
|
||||
|
||||
private MinionFakePlayer(MinecraftServer server, ServerWorld worldIn, GameProfile profile, SyncedClientOptions cli, MinionData data)
|
||||
private MinionFakePlayer(MinecraftServer server, ServerLevel worldIn, GameProfile profile, ClientInformation cli)
|
||||
{
|
||||
super(server, worldIn, profile, cli);
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
public boolean isProgrammable() {
|
||||
return programmable;
|
||||
}
|
||||
|
||||
public void setProgrammable(boolean programmable) {
|
||||
this.programmable = programmable;
|
||||
actionPack = new EntityPlayerActionPack(this);
|
||||
}
|
||||
|
||||
public ModuleInventory getModuleInventory() {
|
||||
return moduleInventory;
|
||||
}
|
||||
|
||||
public MinionRuntime getRuntime() {
|
||||
return runtime;
|
||||
}
|
||||
|
||||
public EntityPlayerActionPack getMinionActionPack() {
|
||||
return ((ServerPlayerInterface)this).minions$getActionPack();
|
||||
return actionPack;
|
||||
}
|
||||
|
||||
public MinionRuntime getInstructionManager() {
|
||||
return instructionManager;
|
||||
}
|
||||
|
||||
public MinionData getData() {
|
||||
return MinionPersistentState.get(getServer()).getMinionData(getUUID());
|
||||
}
|
||||
|
||||
public SerializableListenerManager<MinionListener> listeners() {
|
||||
return getData().listeners();
|
||||
}
|
||||
|
||||
public void addMinionListener(MinionListener listener) {
|
||||
listeners().addListener(listener);
|
||||
}
|
||||
|
||||
public void removeMinionListener(MinionListener listener) {
|
||||
listeners().removeListener(listener);
|
||||
}
|
||||
|
||||
public void forEachMinionListener(Consumer<MinionListener> listenerConsumer) {
|
||||
listeners().forEach(listenerConsumer);
|
||||
}
|
||||
|
||||
public boolean canSpawnMobs() {
|
||||
return moduleInventory.hasAbility(SpecialAbilities.MOB_SPAWNING) || getData().config().getOption(MinionConfigOptions.spawnAndDespawnMobs);
|
||||
}
|
||||
|
||||
public boolean canDespawnMobs() {
|
||||
return canSpawnMobs();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ActionResult interact(PlayerEntity player, Hand hand) {
|
||||
if(player instanceof ServerPlayerEntity spe) {
|
||||
MinionGui.openInventory(spe, this);
|
||||
public InteractionResult interact(Player player, InteractionHand hand) {
|
||||
if(player instanceof ServerPlayer spe) {
|
||||
new MinionGui(spe, this);
|
||||
}
|
||||
return ActionResult.CONSUME;
|
||||
return InteractionResult.CONSUME;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ActionResult interactAt(PlayerEntity player, Vec3d hitPos, Hand hand) {
|
||||
public InteractionResult interactAt(Player player, Vec3 hitPos, InteractionHand hand) {
|
||||
return interact(player, hand);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEquipStack(final EquipmentSlot slot, final ItemStack previous, final ItemStack stack)
|
||||
public void onEquipItem(final EquipmentSlot slot, final ItemStack previous, final ItemStack stack)
|
||||
{
|
||||
if (!isUsingItem()) super.onEquipStack(slot, previous, stack);
|
||||
if (!isUsingItem()) super.onEquipItem(slot, previous, stack);
|
||||
}
|
||||
|
||||
/*@Override
|
||||
public void kill()
|
||||
public void kill(Component reason)
|
||||
{
|
||||
kill(Text.literal("Killed"));
|
||||
}*/
|
||||
listeners().forEach(listener -> listener.onMinionRemove(this));
|
||||
|
||||
public void kill(Text reason)
|
||||
{
|
||||
shakeOff();
|
||||
|
||||
if (reason.getContent() instanceof TranslatableTextContent text && text.getKey().equals("multiplayer.disconnect.duplicate_login")) {
|
||||
this.networkHandler.onDisconnected(new DisconnectionInfo(reason));
|
||||
if (reason.getContents() instanceof TranslatableContents text && text.getKey().equals("multiplayer.disconnect.duplicate_login")) {
|
||||
this.connection.onDisconnect(new DisconnectionDetails(reason));
|
||||
} else {
|
||||
this.server.send(new ServerTask(this.server.getTicks(), () -> {
|
||||
this.networkHandler.onDisconnected(new DisconnectionInfo(reason));
|
||||
this.getServer().schedule(new TickTask(this.getServer().getTickCount(), () -> {
|
||||
this.connection.onDisconnect(new DisconnectionDetails(reason));
|
||||
}));
|
||||
}
|
||||
|
||||
MinionPersistentState.INSTANCE.updateMinionData(data.withSpawned(false));
|
||||
MinionPersistentState.get(getServer()).updateMinionData(getData().withSpawned(false));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void tick()
|
||||
{
|
||||
if (this.getServer().getTicks() % 10 == 0)
|
||||
actionPack.onUpdate();
|
||||
if (this.getServer().getTickCount() % 10 == 0)
|
||||
{
|
||||
this.networkHandler.syncWithPlayerPosition();
|
||||
this.getServerWorld().getChunkManager().updatePosition(this);
|
||||
this.connection.resetPosition();
|
||||
this.level().getChunkSource().move(this);
|
||||
}
|
||||
try
|
||||
{
|
||||
super.tick();
|
||||
this.playerTick();
|
||||
this.doTick();
|
||||
instructionManager.tick();
|
||||
}
|
||||
catch (NullPointerException ignored)
|
||||
{
|
||||
// happens with that paper port thingy - not sure what that would fix, but hey
|
||||
// the game not gonna crash violently.
|
||||
}
|
||||
runtime.tick();
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean startRiding(Entity entityToRide, boolean force) {
|
||||
if (super.startRiding(entityToRide, force)) {
|
||||
// from ClientPacketListener.handleSetEntityPassengersPacket
|
||||
if (entityToRide instanceof AbstractBoat) {
|
||||
this.yRotO = entityToRide.getYRot();
|
||||
this.setYRot(entityToRide.getYRot());
|
||||
this.setYHeadRot(entityToRide.getYHeadRot());
|
||||
}
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private void shakeOff()
|
||||
{
|
||||
if (getVehicle() instanceof PlayerEntity) stopRiding();
|
||||
for (Entity passenger : getPassengersDeep())
|
||||
if (getVehicle() instanceof Player) stopRiding();
|
||||
for (Entity passenger : getIndirectPassengers())
|
||||
{
|
||||
if (passenger instanceof PlayerEntity) passenger.stopRiding();
|
||||
if (passenger instanceof Player) passenger.stopRiding();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDeath(DamageSource cause)
|
||||
public void die(DamageSource cause)
|
||||
{
|
||||
shakeOff();
|
||||
super.onDeath(cause);
|
||||
super.die(cause);
|
||||
setHealth(20);
|
||||
this.hungerManager = new HungerManager();
|
||||
kill(this.getDamageTracker().getDeathMessage());
|
||||
this.foodData = new FoodData();
|
||||
kill(this.getCombatTracker().getDeathMessage());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getIp()
|
||||
public String getIpAddress()
|
||||
{
|
||||
return "127.0.0.1";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean allowsServerListing() {
|
||||
public boolean allowsListing() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void fall(double y, boolean onGround, BlockState state, BlockPos pos) {
|
||||
handleFall(0.0, y, 0.0, onGround);
|
||||
protected void checkFallDamage(double y, boolean onGround, BlockState state, BlockPos pos) {
|
||||
doCheckFallDamage(0.0, y, 0.0, onGround);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ServerPlayerEntity teleportTo(TeleportTarget target)
|
||||
public ServerPlayer teleport(TeleportTransition target)
|
||||
{
|
||||
super.teleportTo(target);
|
||||
if (notInAnyWorld) {
|
||||
ClientStatusC2SPacket p = new ClientStatusC2SPacket(ClientStatusC2SPacket.Mode.PERFORM_RESPAWN);
|
||||
networkHandler.onClientStatus(p);
|
||||
super.teleport(target);
|
||||
if (wonGame) {
|
||||
ServerboundClientCommandPacket p = new ServerboundClientCommandPacket(ServerboundClientCommandPacket.Action.PERFORM_RESPAWN);
|
||||
connection.handleClientCommand(p);
|
||||
}
|
||||
|
||||
// If above branch was taken, *this* has been removed and replaced, the new instance has been set
|
||||
// on 'our' connection (which is now theirs, but we still have a ref).
|
||||
if (networkHandler.player.isInTeleportationState()) {
|
||||
networkHandler.player.onTeleportationDone();
|
||||
}
|
||||
return networkHandler.player;
|
||||
}
|
||||
|
||||
public void moveForward(float forward) {
|
||||
this.moveForward += forward;
|
||||
EntityPlayerActionPack actionPack = getMinionActionPack();
|
||||
if (moveForward != 0) {
|
||||
actionPack.setForward(moveForward > 0 ? 1 : -1);
|
||||
}
|
||||
}
|
||||
|
||||
public void moveSideways(float sideways) {
|
||||
this.moveSideways += sideways;
|
||||
EntityPlayerActionPack actionPack = getMinionActionPack();
|
||||
if (moveSideways != 0) {
|
||||
actionPack.setStrafing(moveSideways > 0 ? 1 : -1);
|
||||
if (connection.player.isChangingDimension()) {
|
||||
connection.player.hasChangedDimension();
|
||||
}
|
||||
return connection.player;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void move(MovementType movementType, Vec3d movement) {
|
||||
float newForward = (float) (moveForward - movement.z);
|
||||
float newSideways = (float) (moveSideways - movement.x);
|
||||
Vec3d newMovement = movement;
|
||||
if ((newForward < 0 && moveForward > 0) || (newForward > 0 && moveForward < 0)) {
|
||||
newMovement = new Vec3d(newMovement.x, newMovement.y, moveForward);
|
||||
moveForward = 0;
|
||||
getMinionActionPack().setForward(0);
|
||||
}else {
|
||||
moveForward = newForward;
|
||||
public void dropAllDeathLoot(ServerLevel world, DamageSource damageSource) {
|
||||
super.dropAllDeathLoot(world, damageSource);
|
||||
ItemEntity entity = drop(toItemStack(world.getServer()), true, false);
|
||||
if (entity != null) {
|
||||
entity.setUnlimitedLifetime();
|
||||
}
|
||||
if ((newSideways < 0 && moveSideways > 0) || (newSideways > 0 && moveSideways < 0)) {
|
||||
newMovement = new Vec3d(newMovement.x, newMovement.y, moveSideways);
|
||||
moveSideways = 0;
|
||||
getMinionActionPack().setStrafing(0);
|
||||
}else {
|
||||
moveSideways = newSideways;
|
||||
}
|
||||
super.move(movementType, newMovement);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drop(ServerWorld world, DamageSource damageSource) {
|
||||
super.drop(world, damageSource);
|
||||
dropStack(world, toItemStack()).setNeverDespawn();
|
||||
}
|
||||
|
||||
private ItemStack toItemStack() {
|
||||
ItemStack stack = new ItemStack(Minions.MINION_ITEM);
|
||||
MinionItem.setData(data, stack);
|
||||
private ItemStack toItemStack(MinecraftServer server) {
|
||||
ItemStack stack = new ItemStack(MinionItems.MINION_ITEM);
|
||||
MinionItem.setData(server, getData(), stack);
|
||||
return stack;
|
||||
}
|
||||
|
||||
public MinionData getData() {
|
||||
return data;
|
||||
@Override
|
||||
public void addAdditionalSaveData(ValueOutput view) {
|
||||
super.addAdditionalSaveData(view);
|
||||
moduleInventory.writeData(view.child("modules"));
|
||||
instructionManager.save(view.child("instructionManager"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeCustomDataToNbt(NbtCompound nbt) {
|
||||
super.writeCustomDataToNbt(nbt);
|
||||
nbt.put("modules", moduleInventory.writeNbt(new NbtCompound(), getRegistryManager()));
|
||||
nbt.putBoolean("programmable", programmable);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readCustomDataFromNbt(NbtCompound nbt) {
|
||||
super.readCustomDataFromNbt(nbt);
|
||||
moduleInventory.readNbt(nbt.getCompound("modules"), getRegistryManager());
|
||||
programmable = nbt.getBoolean("programmable");
|
||||
public void readAdditionalSaveData(ValueInput view) {
|
||||
super.readAdditionalSaveData(view);
|
||||
moduleInventory.readData(view.childOrEmpty("modules"));
|
||||
instructionManager.load(view.childOrEmpty("instructionManager"));
|
||||
}
|
||||
}
|
||||
+19
-19
@@ -1,46 +1,46 @@
|
||||
//code from https://github.com/gnembon/fabric-carpet
|
||||
package io.github.skippyall.minions.minion.fakeplayer;
|
||||
|
||||
import net.minecraft.entity.player.PlayerPosition;
|
||||
import net.minecraft.network.ClientConnection;
|
||||
import net.minecraft.network.packet.Packet;
|
||||
import net.minecraft.network.packet.s2c.play.PositionFlag;
|
||||
import net.minecraft.network.Connection;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.network.chat.contents.TranslatableContents;
|
||||
import net.minecraft.network.protocol.Packet;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.server.network.ConnectedClientData;
|
||||
import net.minecraft.server.network.ServerPlayNetworkHandler;
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
import net.minecraft.text.Text;
|
||||
import net.minecraft.text.TranslatableTextContent;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.server.network.CommonListenerCookie;
|
||||
import net.minecraft.server.network.ServerGamePacketListenerImpl;
|
||||
import net.minecraft.world.entity.PositionMoveRotation;
|
||||
import net.minecraft.world.entity.Relative;
|
||||
import java.util.Set;
|
||||
|
||||
public class NetHandlerPlayServerFake extends ServerPlayNetworkHandler
|
||||
public class NetHandlerPlayServerFake extends ServerGamePacketListenerImpl
|
||||
{
|
||||
public NetHandlerPlayServerFake(final MinecraftServer minecraftServer, final ClientConnection connection, final ServerPlayerEntity serverPlayer, final ConnectedClientData i)
|
||||
public NetHandlerPlayServerFake(final MinecraftServer minecraftServer, final Connection connection, final ServerPlayer serverPlayer, final CommonListenerCookie i)
|
||||
{
|
||||
super(minecraftServer, connection, serverPlayer, i);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendPacket(final Packet<?> packetIn)
|
||||
public void send(final Packet<?> packetIn)
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void disconnect(Text message)
|
||||
public void disconnect(Component message)
|
||||
{
|
||||
if (message.getContent() instanceof TranslatableTextContent text && (text.getKey().equals("multiplayer.disconnect.idling") || text.getKey().equals("multiplayer.disconnect.duplicate_login")))
|
||||
if (message.getContents() instanceof TranslatableContents text && (text.getKey().equals("multiplayer.disconnect.idling") || text.getKey().equals("multiplayer.disconnect.duplicate_login")))
|
||||
{
|
||||
((MinionFakePlayer) player).kill(message);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void requestTeleport(PlayerPosition pos, Set<PositionFlag> set)
|
||||
public void teleport(PositionMoveRotation pos, Set<Relative> set)
|
||||
{
|
||||
super.requestTeleport(pos, set);
|
||||
if (player.getServerWorld().getPlayerByUuid(player.getUuid()) != null) {
|
||||
syncWithPlayerPosition();
|
||||
player.getServerWorld().getChunkManager().updatePosition(player);
|
||||
super.teleport(pos, set);
|
||||
if (player.level().getPlayerByUUID(player.getUUID()) != null) {
|
||||
resetPosition();
|
||||
player.level().getChunkSource().move(player);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +0,0 @@
|
||||
//code from https://github.com/gnembon/fabric-carpet
|
||||
package io.github.skippyall.minions.minion.fakeplayer;
|
||||
|
||||
public interface ServerPlayerInterface
|
||||
{
|
||||
EntityPlayerActionPack minions$getActionPack();
|
||||
}
|
||||
@@ -3,14 +3,14 @@ package io.github.skippyall.minions.minion.fakeplayer;
|
||||
|
||||
import java.util.Optional;
|
||||
import java.util.function.Predicate;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.util.hit.BlockHitResult;
|
||||
import net.minecraft.util.hit.EntityHitResult;
|
||||
import net.minecraft.util.hit.HitResult;
|
||||
import net.minecraft.util.math.Box;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
import net.minecraft.world.RaycastContext;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.level.ClipContext;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.phys.AABB;
|
||||
import net.minecraft.world.phys.BlockHitResult;
|
||||
import net.minecraft.world.phys.EntityHitResult;
|
||||
import net.minecraft.world.phys.HitResult;
|
||||
import net.minecraft.world.phys.Vec3;
|
||||
|
||||
public class Tracer
|
||||
{
|
||||
@@ -20,7 +20,7 @@ public class Tracer
|
||||
double maxSqDist = reach * reach;
|
||||
if (blockHit != null)
|
||||
{
|
||||
maxSqDist = blockHit.getPos().squaredDistanceTo(source.getCameraPosVec(partialTicks));
|
||||
maxSqDist = blockHit.getLocation().distanceToSqr(source.getEyePosition(partialTicks));
|
||||
}
|
||||
EntityHitResult entityHit = rayTraceEntities(source, partialTicks, reach, maxSqDist);
|
||||
return entityHit == null ? blockHit : entityHit;
|
||||
@@ -28,31 +28,31 @@ public class Tracer
|
||||
|
||||
public static BlockHitResult rayTraceBlocks(Entity source, float partialTicks, double reach, boolean fluids)
|
||||
{
|
||||
Vec3d pos = source.getCameraPosVec(partialTicks);
|
||||
Vec3d rotation = source.getRotationVec(partialTicks);
|
||||
Vec3d reachEnd = pos.add(rotation.x * reach, rotation.y * reach, rotation.z * reach);
|
||||
return source.getWorld().raycast(new RaycastContext(pos, reachEnd, RaycastContext.ShapeType.OUTLINE, fluids ?
|
||||
RaycastContext.FluidHandling.ANY : RaycastContext.FluidHandling.NONE, source));
|
||||
Vec3 pos = source.getEyePosition(partialTicks);
|
||||
Vec3 rotation = source.getViewVector(partialTicks);
|
||||
Vec3 reachEnd = pos.add(rotation.x * reach, rotation.y * reach, rotation.z * reach);
|
||||
return source.level().clip(new ClipContext(pos, reachEnd, ClipContext.Block.OUTLINE, fluids ?
|
||||
ClipContext.Fluid.ANY : ClipContext.Fluid.NONE, source));
|
||||
}
|
||||
|
||||
public static EntityHitResult rayTraceEntities(Entity source, float partialTicks, double reach, double maxSqDist)
|
||||
{
|
||||
Vec3d pos = source.getCameraPosVec(partialTicks);
|
||||
Vec3d reachVec = source.getRotationVec(partialTicks).multiply(reach);
|
||||
Box box = source.getBoundingBox().stretch(reachVec).expand(1);
|
||||
return rayTraceEntities(source, pos, pos.add(reachVec), box, e -> !e.isSpectator() && e.canHit(), maxSqDist);
|
||||
Vec3 pos = source.getEyePosition(partialTicks);
|
||||
Vec3 reachVec = source.getViewVector(partialTicks).scale(reach);
|
||||
AABB box = source.getBoundingBox().expandTowards(reachVec).inflate(1);
|
||||
return rayTraceEntities(source, pos, pos.add(reachVec), box, e -> !e.isSpectator() && e.isPickable(), maxSqDist);
|
||||
}
|
||||
|
||||
public static EntityHitResult rayTraceEntities(Entity source, Vec3d start, Vec3d end, Box box, Predicate<Entity> predicate, double maxSqDistance)
|
||||
public static EntityHitResult rayTraceEntities(Entity source, Vec3 start, Vec3 end, AABB box, Predicate<Entity> predicate, double maxSqDistance)
|
||||
{
|
||||
World world = source.getWorld();
|
||||
Level world = source.level();
|
||||
double targetDistance = maxSqDistance;
|
||||
Entity target = null;
|
||||
Vec3d targetHitPos = null;
|
||||
for (Entity current : world.getOtherEntities(source, box, predicate))
|
||||
Vec3 targetHitPos = null;
|
||||
for (Entity current : world.getEntities(source, box, predicate))
|
||||
{
|
||||
Box currentBox = current.getBoundingBox().expand(current.getTargetingMargin());
|
||||
Optional<Vec3d> currentHit = currentBox.raycast(start, end);
|
||||
AABB currentBox = current.getBoundingBox().inflate(current.getPickRadius());
|
||||
Optional<Vec3> currentHit = currentBox.clip(start, end);
|
||||
if (currentBox.contains(start))
|
||||
{
|
||||
if (targetDistance >= 0)
|
||||
@@ -64,8 +64,8 @@ public class Tracer
|
||||
}
|
||||
else if (currentHit.isPresent())
|
||||
{
|
||||
Vec3d currentHitPos = currentHit.get();
|
||||
double currentDistance = start.squaredDistanceTo(currentHitPos);
|
||||
Vec3 currentHitPos = currentHit.get();
|
||||
double currentDistance = start.distanceToSqr(currentHitPos);
|
||||
if (currentDistance < targetDistance || targetDistance == 0)
|
||||
{
|
||||
if (current.getRootVehicle() == source.getRootVehicle())
|
||||
|
||||
+51
@@ -0,0 +1,51 @@
|
||||
package io.github.skippyall.minions.minion.program.instruction;
|
||||
|
||||
import io.github.skippyall.minions.minion.MinionRuntime;
|
||||
import io.github.skippyall.minions.minion.fakeplayer.EntityPlayerActionPack;
|
||||
import io.github.skippyall.minions.program.consumer.ValueConsumerList;
|
||||
import io.github.skippyall.minions.program.instruction.execution.ContinuousInstructionExecution;
|
||||
import io.github.skippyall.minions.program.supplier.ParameterValueList;
|
||||
import net.minecraft.world.level.storage.ValueInput;
|
||||
import net.minecraft.world.level.storage.ValueOutput;
|
||||
|
||||
public class ActionExecution implements ContinuousInstructionExecution<MinionRuntime> {
|
||||
private final EntityPlayerActionPack.ActionType action;
|
||||
|
||||
public ActionExecution(EntityPlayerActionPack.ActionType action) {
|
||||
this.action = action;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void start(MinionRuntime minion) {
|
||||
EntityPlayerActionPack ap = minion.getMinion().getMinionActionPack();
|
||||
if(!ap.hasAction(action)) {
|
||||
minion.getMinion().getMinionActionPack().start(action, EntityPlayerActionPack.Action.startContinuous());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stop(MinionRuntime minion, ValueConsumerList<MinionRuntime> valueConsumers) {
|
||||
minion.getMinion().getMinionActionPack().stop(action);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void pause(MinionRuntime runtime) {
|
||||
runtime.getMinion().getMinionActionPack().stop(action);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void resume(MinionRuntime runtime) {
|
||||
runtime.getMinion().getMinionActionPack().start(action, EntityPlayerActionPack.Action.continuous());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readArguments(ParameterValueList parameters, MinionRuntime minion) {}
|
||||
|
||||
@Override
|
||||
public void save(ValueOutput view, MinionRuntime minion) {}
|
||||
|
||||
@Override
|
||||
public void load(ValueInput view, MinionRuntime runtime) {
|
||||
runtime.getMinion().getMinionActionPack().start(action, EntityPlayerActionPack.Action.continuous());
|
||||
}
|
||||
}
|
||||
+142
@@ -0,0 +1,142 @@
|
||||
//partially code from https://github.com/gnembon/fabric-carpet (EntityPlayerActionPack)
|
||||
package io.github.skippyall.minions.minion.program.instruction;
|
||||
|
||||
import io.github.skippyall.minions.minion.MinionRuntime;
|
||||
import io.github.skippyall.minions.minion.fakeplayer.EntityPlayerActionPack;
|
||||
import io.github.skippyall.minions.minion.fakeplayer.MinionFakePlayer;
|
||||
import io.github.skippyall.minions.program.consumer.ValueConsumerList;
|
||||
import io.github.skippyall.minions.program.instruction.InstructionExecution;
|
||||
import io.github.skippyall.minions.program.supplier.ParameterValueList;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.network.protocol.game.ServerboundPlayerActionPacket;
|
||||
import net.minecraft.world.InteractionHand;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.level.storage.ValueInput;
|
||||
import net.minecraft.world.level.storage.ValueOutput;
|
||||
import net.minecraft.world.phys.BlockHitResult;
|
||||
import net.minecraft.world.phys.HitResult;
|
||||
|
||||
public class MineBlockExecution implements InstructionExecution<MinionRuntime> {
|
||||
private BlockPos currentBlock;
|
||||
private float currentBlockDamage = 0;
|
||||
private boolean first = true;
|
||||
private boolean done = false;
|
||||
private boolean success = false;
|
||||
|
||||
@Override
|
||||
public void start(MinionRuntime runtime) {
|
||||
MinionFakePlayer player = runtime.getMinion();
|
||||
if(EntityPlayerActionPack.getTarget(player) instanceof BlockHitResult hit) {
|
||||
this.currentBlock = hit.getBlockPos();
|
||||
|
||||
EntityPlayerActionPack ap = player.getMinionActionPack();
|
||||
if (ap.blockHitDelay > 0) {
|
||||
ap.blockHitDelay--;
|
||||
done = true;
|
||||
return;
|
||||
}
|
||||
if (player.blockActionRestricted(player.level(), hit.getBlockPos(), player.gameMode.getGameModeForPlayer())) {
|
||||
done = true;
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
done = true;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void tick(MinionRuntime runtime) {
|
||||
if(done) {
|
||||
return;
|
||||
}
|
||||
|
||||
MinionFakePlayer player = runtime.getMinion();
|
||||
EntityPlayerActionPack ap = player.getMinionActionPack();
|
||||
|
||||
HitResult newHit = EntityPlayerActionPack.getTarget(player);
|
||||
if(!(newHit instanceof BlockHitResult newBlockHit)) {
|
||||
done = true;
|
||||
return;
|
||||
}
|
||||
|
||||
BlockPos newPos = newBlockHit.getBlockPos();
|
||||
if(!newPos.equals(currentBlock)) {
|
||||
done = true;
|
||||
return;
|
||||
}
|
||||
|
||||
if (player.level().getBlockState(currentBlock).isAir()) {
|
||||
done = true;
|
||||
return;
|
||||
}
|
||||
BlockState state = player.level().getBlockState(currentBlock);
|
||||
boolean blockBroken = false;
|
||||
if (first) {
|
||||
first = false;
|
||||
player.gameMode.handleBlockBreakAction(currentBlock, ServerboundPlayerActionPacket.Action.START_DESTROY_BLOCK, newBlockHit.getDirection(), player.level().getMaxY(), -1);
|
||||
boolean notAir = !state.isAir();
|
||||
if (notAir)
|
||||
{
|
||||
state.attack(player.level(), currentBlock, player);
|
||||
}
|
||||
if (notAir && state.getDestroyProgress(player, player.level(), currentBlock) >= 1)
|
||||
{
|
||||
//instamine??
|
||||
blockBroken = true;
|
||||
}
|
||||
} else {
|
||||
currentBlockDamage += state.getDestroyProgress(player, player.level(), currentBlock);
|
||||
if (currentBlockDamage >= 1) {
|
||||
player.gameMode.handleBlockBreakAction(currentBlock, ServerboundPlayerActionPacket.Action.STOP_DESTROY_BLOCK, newBlockHit.getDirection(), player.level().getMaxY(), -1);
|
||||
ap.blockHitDelay = 5;
|
||||
blockBroken = true;
|
||||
}
|
||||
player.level().destroyBlockProgress(-1, currentBlock, (int) (currentBlockDamage * 10));
|
||||
|
||||
}
|
||||
player.resetLastActionTime();
|
||||
player.swing(InteractionHand.MAIN_HAND);
|
||||
|
||||
if(blockBroken) {
|
||||
done = true;
|
||||
success = true;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDone(MinionRuntime runtime) {
|
||||
return done;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stop(MinionRuntime runtime, ValueConsumerList<MinionRuntime> valueConsumers) {
|
||||
MinionFakePlayer player = runtime.getMinion();
|
||||
EntityPlayerActionPack ap = player.getMinionActionPack();
|
||||
|
||||
if(currentBlock != null) {
|
||||
player.level().destroyBlockProgress(-1, currentBlock, -1);
|
||||
player.gameMode.handleBlockBreakAction(currentBlock, ServerboundPlayerActionPacket.Action.ABORT_DESTROY_BLOCK, Direction.DOWN, player.level().getMaxY(), -1);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readArguments(ParameterValueList arguments, MinionRuntime runtime) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void save(ValueOutput view, MinionRuntime runtime) {
|
||||
view.store("currentBlock", BlockPos.CODEC, currentBlock);
|
||||
view.putFloat("currentBlockDamage", currentBlockDamage);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void load(ValueInput view, MinionRuntime runtime) {
|
||||
currentBlock = view.read("currentBlock", BlockPos.CODEC).orElse(null);
|
||||
currentBlockDamage = view.getFloatOr("currentBlockDamage", 0);
|
||||
if(currentBlock == null) {
|
||||
done = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
+133
@@ -0,0 +1,133 @@
|
||||
package io.github.skippyall.minions.minion.program.instruction.inventory;
|
||||
|
||||
import io.github.skippyall.minions.minion.MinionRuntime;
|
||||
import io.github.skippyall.minions.minion.fakeplayer.MinionFakePlayer;
|
||||
import io.github.skippyall.minions.program.consumer.ValueConsumerList;
|
||||
import io.github.skippyall.minions.program.instruction.InstructionExecution;
|
||||
import io.github.skippyall.minions.program.supplier.Parameter;
|
||||
import io.github.skippyall.minions.program.supplier.ParameterValueList;
|
||||
import io.github.skippyall.minions.registration.ValueTypes;
|
||||
import net.minecraft.world.inventory.AbstractContainerMenu;
|
||||
import net.minecraft.world.inventory.ClickType;
|
||||
import net.minecraft.world.inventory.Slot;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.level.storage.ValueInput;
|
||||
import net.minecraft.world.level.storage.ValueOutput;
|
||||
|
||||
public class SwapItemExecution implements InstructionExecution<MinionRuntime> {
|
||||
public static final Parameter<Long> FROM_SLOT = new Parameter<>("from_slot", ValueTypes.LONG);
|
||||
public static final Parameter<Boolean> FROM_SCREEN = new Parameter<>("from_screen", ValueTypes.BOOLEAN);
|
||||
public static final Parameter<Long> TO_SLOT = new Parameter<>("to_slot", ValueTypes.LONG);
|
||||
public static final Parameter<Boolean> TO_SCREEN = new Parameter<>("to_screen", ValueTypes.BOOLEAN);
|
||||
|
||||
private int fromSlot;
|
||||
private boolean fromScreen;
|
||||
private int toSlot;
|
||||
private boolean toScreen;
|
||||
|
||||
private ItemStack cursor = ItemStack.EMPTY;
|
||||
|
||||
@Override
|
||||
public void start(MinionRuntime runtime) {
|
||||
MinionFakePlayer minion = runtime.getMinion();
|
||||
|
||||
if((fromScreen || toScreen) && minion.containerMenu == null) {
|
||||
return;
|
||||
}
|
||||
if(!(checkBounds(minion, fromSlot, fromScreen) && checkBounds(minion, toSlot, toScreen))) {
|
||||
return;
|
||||
}
|
||||
|
||||
ItemStack fromStack = getStack(minion, fromSlot, fromScreen);
|
||||
ItemStack toStack = getStack(minion, toSlot, toScreen);
|
||||
|
||||
if(!(canExchange(minion, fromSlot, fromScreen, toStack) && canExchange(minion, toSlot, toScreen, fromStack))) {
|
||||
return;
|
||||
}
|
||||
|
||||
simulateClick(minion, fromSlot, fromScreen);
|
||||
simulateClick(minion, toSlot, toScreen);
|
||||
simulateClick(minion, fromSlot, fromScreen);
|
||||
minion.getInventory().placeItemBackInInventory(cursor);
|
||||
}
|
||||
|
||||
private AbstractContainerMenu getScreen(MinionFakePlayer minion, boolean screen) {
|
||||
if(screen) {
|
||||
return minion.containerMenu;
|
||||
} else {
|
||||
return minion.inventoryMenu;
|
||||
}
|
||||
}
|
||||
|
||||
private boolean checkBounds(MinionFakePlayer minion, int slot, boolean screen) {
|
||||
return slot >= 0 && slot < getScreen(minion, screen).slots.size();
|
||||
}
|
||||
|
||||
private ItemStack getStack(MinionFakePlayer minion, int slot, boolean screen) {
|
||||
return getScreen(minion, screen).getSlot(slot).getItem();
|
||||
}
|
||||
|
||||
private boolean canExchange(MinionFakePlayer minion, int slotIndex, boolean screen, ItemStack newStack) {
|
||||
AbstractContainerMenu screenHandler = getScreen(minion, screen);
|
||||
Slot slot = screenHandler.getSlot(slotIndex);
|
||||
if(!slot.getItem().isEmpty() && !slot.mayPickup(minion)) {
|
||||
return false;
|
||||
}
|
||||
if(!newStack.isEmpty() && !slot.mayPlace(newStack)) {
|
||||
return false;
|
||||
}
|
||||
/*else {
|
||||
if(slotIndex >= PlayerInventory.MAIN_SIZE && slotIndex < PlayerInventory.OFF_HAND_SLOT) {
|
||||
if(!minion.canEquip(newStack, PlayerInventory.EQUIPMENT_SLOTS.get(slotIndex))) {
|
||||
return false;
|
||||
}
|
||||
if(EnchantmentHelper.hasAnyEnchantmentsWith(minion.getInventory().getStack(slotIndex), EnchantmentEffectComponentTypes.PREVENT_ARMOR_CHANGE)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}*/
|
||||
return true;
|
||||
}
|
||||
|
||||
private void simulateClick(MinionFakePlayer minion, int slotIndex, boolean screen) {
|
||||
AbstractContainerMenu screenHandler = getScreen(minion, screen);
|
||||
ItemStack previousCursor = screenHandler.getCarried();
|
||||
screenHandler.setCarried(cursor);
|
||||
screenHandler.clicked(slotIndex, 0, ClickType.SWAP, minion);
|
||||
cursor = screenHandler.getCarried();
|
||||
screenHandler.setCarried(previousCursor);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void tick(MinionRuntime runtime) {
|
||||
InstructionExecution.super.tick(runtime);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDone(MinionRuntime runtime) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stop(MinionRuntime runtime, ValueConsumerList<MinionRuntime> valueConsumers) {
|
||||
InstructionExecution.super.stop(runtime, valueConsumers);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readArguments(ParameterValueList arguments, MinionRuntime runtime) {
|
||||
fromSlot = Math.clamp(arguments.getValue(FROM_SLOT), 0, Integer.MAX_VALUE);
|
||||
fromScreen = arguments.getValue(FROM_SCREEN);
|
||||
toSlot = Math.clamp(arguments.getValue(TO_SLOT), 0, Integer.MAX_VALUE);
|
||||
toScreen = arguments.getValue(TO_SCREEN);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void save(ValueOutput view, MinionRuntime runtime) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void load(ValueInput view, MinionRuntime runtime) {
|
||||
|
||||
}
|
||||
}
|
||||
+38
@@ -0,0 +1,38 @@
|
||||
package io.github.skippyall.minions.minion.program.instruction.move;
|
||||
|
||||
import io.github.skippyall.minions.minion.MinionRuntime;
|
||||
import io.github.skippyall.minions.program.instruction.InstructionExecution;
|
||||
import net.minecraft.world.level.storage.ValueInput;
|
||||
import net.minecraft.world.level.storage.ValueOutput;
|
||||
|
||||
public abstract class AbstractTurnExecution implements InstructionExecution<MinionRuntime> {
|
||||
protected float targetYaw;
|
||||
protected float targetPitch;
|
||||
|
||||
private static final float anglePerTick = 10;
|
||||
|
||||
@Override
|
||||
public void tick(MinionRuntime minion) {
|
||||
float rotateYaw = targetYaw - minion.getMinion().getYRot();
|
||||
float rotatePitch = targetPitch - minion.getMinion().getXRot();
|
||||
|
||||
minion.getMinion().getMinionActionPack().turn(Math.min(rotateYaw, anglePerTick), Math.min(rotatePitch, anglePerTick));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDone(MinionRuntime minion) {
|
||||
return Math.abs(targetYaw - minion.getMinion().getYRot()) < 0.001F && Math.abs(targetPitch - minion.getMinion().getXRot()) < 0.001F;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void save(ValueOutput view, MinionRuntime runtime) {
|
||||
view.putFloat("targetYaw", targetYaw);
|
||||
view.putFloat("targetPitch", targetPitch);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void load(ValueInput view, MinionRuntime runtime) {
|
||||
targetYaw = view.getFloatOr("targetYaw", 0);
|
||||
targetPitch = view.getFloatOr("targetPitch", 0);
|
||||
}
|
||||
}
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
package io.github.skippyall.minions.minion.program.instruction.move;
|
||||
|
||||
import io.github.skippyall.minions.minion.MinionRuntime;
|
||||
import io.github.skippyall.minions.program.instruction.InstructionExecution;
|
||||
import io.github.skippyall.minions.program.instruction.execution.ContinuousInstructionExecution;
|
||||
import net.minecraft.world.entity.MoverType;
|
||||
|
||||
public class ContinuousWalkExecution implements ContinuousInstructionExecution<MinionRuntime>, InstructionExecution.Stateless<MinionRuntime> {
|
||||
@Override
|
||||
public void tick(MinionRuntime minion) {
|
||||
minion.getMinion().move(MoverType.SELF, minion.getMinion().getDirection().getUnitVec3().normalize().scale(minion.getMinion().getSpeed()));
|
||||
}
|
||||
}
|
||||
+46
@@ -0,0 +1,46 @@
|
||||
package io.github.skippyall.minions.minion.program.instruction.move;
|
||||
|
||||
import com.mojang.serialization.Codec;
|
||||
import io.github.skippyall.minions.gui.Displayable;
|
||||
import io.github.skippyall.minions.gui.GuiDisplay;
|
||||
import java.util.UUID;
|
||||
import net.minecraft.util.StringRepresentable;
|
||||
|
||||
public enum TurnDirection implements StringRepresentable, Displayable {
|
||||
LEFT("left", -1, 0),
|
||||
UP("up", 0, -1),
|
||||
RIGHT("right", 1, 0),
|
||||
DOWN("down", 0, 1);
|
||||
|
||||
public static final Codec<TurnDirection> CODEC = StringRepresentable.fromEnum(TurnDirection::values);
|
||||
|
||||
private static final UUID MHF_ArrowLeft = UUID.fromString("a68f0b64-8d14-4000-a95f-4b9ba14f8df9");
|
||||
private static final UUID MHF_ArrowUp = UUID.fromString("fef039ef-e6cd-4987-9c84-26a3e6134277");
|
||||
private static final UUID MHF_ArrowRight = UUID.fromString("50c8510b-5ea0-4d60-be9a-7d542d6cd156");
|
||||
private static final UUID MHF_ArrowDown = UUID.fromString("68f59b9b-5b0b-4b05-a9f2-e1d1405aa348");
|
||||
|
||||
public final String name;
|
||||
public final int xFactor;
|
||||
public final int yFactor;
|
||||
|
||||
TurnDirection(String name, int xFactor, int yFactor) {
|
||||
this.xFactor = xFactor;
|
||||
this.yFactor = yFactor;
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSerializedName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public GuiDisplay getDisplay() {
|
||||
return switch (this) {
|
||||
case LEFT -> new GuiDisplay.HeadBased(MHF_ArrowLeft);
|
||||
case UP -> new GuiDisplay.HeadBased(MHF_ArrowUp);
|
||||
case RIGHT -> new GuiDisplay.HeadBased(MHF_ArrowRight);
|
||||
case DOWN -> new GuiDisplay.HeadBased(MHF_ArrowDown);
|
||||
};
|
||||
}
|
||||
}
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
package io.github.skippyall.minions.minion.program.instruction.move;
|
||||
|
||||
import io.github.skippyall.minions.minion.MinionRuntime;
|
||||
import io.github.skippyall.minions.program.supplier.Parameter;
|
||||
import io.github.skippyall.minions.program.supplier.ParameterValueList;
|
||||
import io.github.skippyall.minions.registration.ValueTypes;
|
||||
|
||||
public class TurnExecution extends AbstractTurnExecution {
|
||||
public static final Parameter<Double> ANGLE = new Parameter<>("maxAngle", ValueTypes.DOUBLE);
|
||||
public static final Parameter<TurnDirection> DIRECTION = new Parameter<>("direction", ValueTypes.TURN_DIRECTION);
|
||||
|
||||
@Override
|
||||
public void readArguments(ParameterValueList arguments, MinionRuntime minion) {
|
||||
float maxAngle = arguments.getValue(ANGLE).floatValue();
|
||||
TurnDirection direction = arguments.getValue(DIRECTION);
|
||||
|
||||
float turnYaw = maxAngle * direction.xFactor;
|
||||
float turnPitch = maxAngle * direction.yFactor;
|
||||
|
||||
targetYaw = minion.getMinion().getYRot() + turnYaw;
|
||||
targetPitch = minion.getMinion().getXRot() + turnPitch;
|
||||
}
|
||||
}
|
||||
+36
@@ -0,0 +1,36 @@
|
||||
package io.github.skippyall.minions.minion.program.instruction.move;
|
||||
|
||||
import io.github.skippyall.minions.minion.MinionRuntime;
|
||||
import io.github.skippyall.minions.program.supplier.Parameter;
|
||||
import io.github.skippyall.minions.program.supplier.ParameterValueList;
|
||||
import io.github.skippyall.minions.registration.ValueTypes;
|
||||
import net.minecraft.util.Mth;
|
||||
import net.minecraft.world.phys.Vec2;
|
||||
import net.minecraft.world.phys.Vec3;
|
||||
|
||||
public class TurnVectorExecution extends AbstractTurnExecution {
|
||||
public static final Parameter<Double> X = new Parameter<>("x", ValueTypes.DOUBLE);
|
||||
public static final Parameter<Double> Y = new Parameter<>("y", ValueTypes.DOUBLE);
|
||||
public static final Parameter<Double> Z = new Parameter<>("z", ValueTypes.DOUBLE);
|
||||
|
||||
@Override
|
||||
public void readArguments(ParameterValueList arguments, MinionRuntime runtime) {
|
||||
double x = arguments.getValue(X);
|
||||
double y = arguments.getValue(Y);
|
||||
double z = arguments.getValue(Z);
|
||||
|
||||
Vec3 vector = new Vec3(x, y, z);
|
||||
Vec2 rotation = vectorToRotation(vector);
|
||||
targetYaw = rotation.x;
|
||||
targetPitch = rotation.y;
|
||||
}
|
||||
|
||||
//copied from Entity#lookAt (why no helper, Mojang?)
|
||||
public static Vec2 vectorToRotation(Vec3 vector) {
|
||||
double g = Math.sqrt(vector.x * vector.x + vector.z * vector.z);
|
||||
float pitch = Mth.wrapDegrees((float)(-(Mth.atan2(vector.y, g) * 180.0F / (float)Math.PI)));
|
||||
float yaw = Mth.wrapDegrees((float)(Mth.atan2(vector.z, vector.x) * 180.0F / (float)Math.PI) - 90.0F);
|
||||
|
||||
return new Vec2(yaw, pitch);
|
||||
}
|
||||
}
|
||||
+48
@@ -0,0 +1,48 @@
|
||||
package io.github.skippyall.minions.minion.program.instruction.move;
|
||||
|
||||
import io.github.skippyall.minions.minion.MinionRuntime;
|
||||
import io.github.skippyall.minions.program.instruction.InstructionExecution;
|
||||
import io.github.skippyall.minions.program.supplier.Parameter;
|
||||
import io.github.skippyall.minions.program.supplier.ParameterValueList;
|
||||
import io.github.skippyall.minions.registration.ValueTypes;
|
||||
import net.minecraft.world.entity.MoverType;
|
||||
import net.minecraft.world.level.storage.ValueInput;
|
||||
import net.minecraft.world.level.storage.ValueOutput;
|
||||
|
||||
public class WalkExecution implements InstructionExecution<MinionRuntime> {
|
||||
public static final Parameter<Double> blocksToMoveParam = new Parameter<>("blocksToMove", ValueTypes.DOUBLE);
|
||||
private static final float ACCURACY = 1F / 32F;
|
||||
|
||||
private double totalBlocksToMove;
|
||||
private double blocksMoved;
|
||||
|
||||
@Override
|
||||
public void tick(MinionRuntime minion) {
|
||||
double speed = Math.min(minion.getMinion().getSpeed(), totalBlocksToMove - blocksMoved);
|
||||
minion.getMinion().move(MoverType.SELF, minion.getMinion().getDirection().getUnitVec3().normalize().scale(speed));
|
||||
blocksMoved += speed;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDone(MinionRuntime minion) {
|
||||
return totalBlocksToMove - blocksMoved < ACCURACY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readArguments(ParameterValueList parameters, MinionRuntime minion) {
|
||||
totalBlocksToMove = parameters.getValue(blocksToMoveParam).floatValue();
|
||||
blocksMoved = 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void save(ValueOutput view, MinionRuntime minion) {
|
||||
view.putDouble("totalBlocksToMove", totalBlocksToMove);
|
||||
view.putDouble("blocksMoved", blocksMoved);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void load(ValueInput view, MinionRuntime minion) {
|
||||
totalBlocksToMove = view.getDoubleOr("totalBlocksToMove", 0F);
|
||||
blocksMoved = view.getDoubleOr("blocksMoved", 0F);
|
||||
}
|
||||
}
|
||||
+105
@@ -0,0 +1,105 @@
|
||||
package io.github.skippyall.minions.minion.program.supplier;
|
||||
|
||||
import com.mojang.serialization.Codec;
|
||||
import com.mojang.serialization.codecs.RecordCodecBuilder;
|
||||
import eu.pb4.sgui.api.elements.GuiElementBuilder;
|
||||
import eu.pb4.sgui.api.gui.SimpleGui;
|
||||
import io.github.skippyall.minions.clipboard.BlockPosClipboard;
|
||||
import io.github.skippyall.minions.gui.MinionsGui;
|
||||
import io.github.skippyall.minions.gui.minion.SimpleMinionsGui;
|
||||
import io.github.skippyall.minions.minion.MinionRuntime;
|
||||
import io.github.skippyall.minions.program.supplier.ValueSupplier;
|
||||
import io.github.skippyall.minions.program.supplier.ValueSupplierType;
|
||||
import io.github.skippyall.minions.program.value.ValueType;
|
||||
import io.github.skippyall.minions.registration.MinionBlocks;
|
||||
import io.github.skippyall.minions.registration.MinionComponentTypes;
|
||||
import io.github.skippyall.minions.registration.MinionItems;
|
||||
import io.github.skippyall.minions.registration.ValueSuppliers;
|
||||
import io.github.skippyall.minions.registration.ValueTypes;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.resources.ResourceKey;
|
||||
import net.minecraft.world.inventory.MenuType;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.level.Level;
|
||||
|
||||
public class AnalogInputSupplier implements ValueSupplier<Long, MinionRuntime> {
|
||||
public static final Codec<AnalogInputSupplier> CODEC = RecordCodecBuilder.create(instance ->
|
||||
instance.group(
|
||||
Level.RESOURCE_KEY_CODEC.fieldOf("analogInputWorld").forGetter(s -> s.analogInputWorld),
|
||||
BlockPos.CODEC.fieldOf("analogInputPos").forGetter(s -> s.analogInputPos)
|
||||
).apply(instance, AnalogInputSupplier::new));
|
||||
|
||||
private final ResourceKey<Level> analogInputWorld;
|
||||
private final BlockPos analogInputPos;
|
||||
|
||||
public AnalogInputSupplier(ResourceKey<Level> analogInputWorld, BlockPos analogInputPos) {
|
||||
this.analogInputWorld = analogInputWorld;
|
||||
this.analogInputPos = analogInputPos;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long resolve(MinionRuntime minion) {
|
||||
Level world = minion.getMinion().getServer().getLevel(analogInputWorld);
|
||||
if(world != null && world.isLoaded(analogInputPos) && world.getBlockState(analogInputPos).is(MinionBlocks.ANALOG_INPUT_BLOCK)) {
|
||||
return (long) world.getBestNeighborSignal(analogInputPos);
|
||||
} else {
|
||||
return 0L;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ValueType<Long> getValueType() {
|
||||
return ValueTypes.LONG;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ValueSupplierType<MinionRuntime> getType() {
|
||||
return ValueSuppliers.ANALOG_INPUT;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Component getDisplayText() {
|
||||
return Component.translatable("value_supplier.minions.analog_input.display", analogInputPos.toShortString(), analogInputWorld.location().toString());
|
||||
}
|
||||
|
||||
public static class AnalogInputSupplierType extends ValueSupplierType<MinionRuntime> {
|
||||
@Override
|
||||
public <T> Codec<? extends ValueSupplier<T, MinionRuntime>> getCodec(ValueType<T> type) {
|
||||
if(type == ValueTypes.LONG) {
|
||||
return ValueSupplier.castCodec(CODEC, ValueTypes.LONG, type);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> CompletableFuture<ValueSupplier<?, MinionRuntime>> openConfiguration(MinionsGui parent, ValueType<T> valueType, @Nullable ValueSupplier<?, MinionRuntime> previous) {
|
||||
CompletableFuture<ValueSupplier<?, MinionRuntime>> future = new CompletableFuture<>();
|
||||
new SimpleMinionsGui(parent, (onClose, me) -> {
|
||||
SimpleGui gui = new SimpleGui(MenuType.GENERIC_3x3, parent.getViewer(), false) {
|
||||
@Override
|
||||
public void onClose() {
|
||||
onClose.run();
|
||||
}
|
||||
};
|
||||
gui.setTitle(Component.translatable("value_supplier.minions.analog_input"));
|
||||
|
||||
gui.setSlot(4, new GuiElementBuilder(MinionItems.REFERENCE_ITEM)
|
||||
.setCallback(() -> {
|
||||
ItemStack cursor = parent.getViewer().containerMenu.getCarried();
|
||||
if (cursor.is(MinionItems.REFERENCE_ITEM) && cursor.get(MinionComponentTypes.REFERENCE) instanceof BlockPosClipboard pos) {
|
||||
future.complete(new AnalogInputSupplier(pos.world(), pos.pos()));
|
||||
}
|
||||
})
|
||||
.setItemName(Component.translatable("value_supplier.minions.analog_input.config.click_with_reference"))
|
||||
);
|
||||
gui.open();
|
||||
return gui;
|
||||
});
|
||||
return future;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,26 +2,105 @@ package io.github.skippyall.minions.minion.skin;
|
||||
|
||||
import com.mojang.authlib.properties.Property;
|
||||
import com.mojang.authlib.properties.PropertyMap;
|
||||
import io.github.skippyall.minions.input.TextInput;
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
import net.minecraft.text.Text;
|
||||
|
||||
import io.github.skippyall.minions.Minions;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import net.minecraft.core.Holder;
|
||||
import net.minecraft.core.registries.Registries;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.nbt.Tag;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.resources.ResourceKey;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.server.dialog.ActionButton;
|
||||
import net.minecraft.server.dialog.CommonButtonData;
|
||||
import net.minecraft.server.dialog.CommonDialogData;
|
||||
import net.minecraft.server.dialog.Dialog;
|
||||
import net.minecraft.server.dialog.DialogAction;
|
||||
import net.minecraft.server.dialog.Input;
|
||||
import net.minecraft.server.dialog.NoticeDialog;
|
||||
import net.minecraft.server.dialog.action.CustomAll;
|
||||
import net.minecraft.server.dialog.input.TextInput;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
|
||||
public class Base64SkinProvider implements SkinProvider {
|
||||
public static final ResourceKey<Dialog> DIALOG = ResourceKey.create(Registries.DIALOG, ResourceLocation.fromNamespaceAndPath(Minions.MOD_ID, "base_64_input"));
|
||||
public static final ResourceLocation CUSTOM_DIALOG_ACTION = ResourceLocation.fromNamespaceAndPath(Minions.MOD_ID, "base_64_submit");
|
||||
|
||||
private static long dialogIdCounter = 0;
|
||||
private static Map<Long, CompletableFuture<Optional<PropertyMap>>> futures = new HashMap<>();
|
||||
|
||||
@Override
|
||||
public CompletableFuture<Optional<PropertyMap>> openSkinMenu(ServerPlayerEntity player) {
|
||||
return TextInput.inputString(player, Text.translatable("minions.gui.look.skin.base64.title"), "")
|
||||
.thenApply(base64String -> {
|
||||
public CompletableFuture<Optional<PropertyMap>> openSkinMenu(ServerPlayer player) {
|
||||
dialogIdCounter++;
|
||||
player.openDialog(getDialog());
|
||||
CompletableFuture<Optional<PropertyMap>> future = new CompletableFuture<>();
|
||||
futures.put(dialogIdCounter, future);
|
||||
return future;
|
||||
}
|
||||
|
||||
public static void onCustomDialogAction(Optional<Tag> element) {
|
||||
if(element.isPresent() && element.get() instanceof CompoundTag compound) {
|
||||
Optional<Long> id = compound.getLong("dialog_id");
|
||||
Optional<String> base64 = compound.getString("base_64");
|
||||
if(id.isPresent() && base64.isPresent() && !base64.get().isBlank()) {
|
||||
if(futures.containsKey(id.get())) {
|
||||
PropertyMap map = new PropertyMap();
|
||||
map.put("textures", new Property("textures", base64String));
|
||||
return Optional.of(map);
|
||||
});
|
||||
map.put("textures", new Property("textures", base64.get().strip()));
|
||||
|
||||
futures.get(id.get()).complete(Optional.of(map));
|
||||
futures.remove(id.get());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static Holder<Dialog> getDialog() {
|
||||
CompoundTag additionalData = new CompoundTag();
|
||||
additionalData.putLong("dialog_id", dialogIdCounter);
|
||||
return Holder.direct(
|
||||
new NoticeDialog(
|
||||
new CommonDialogData(
|
||||
Component.translatable("minions.gui.look.skin.base64.title"),
|
||||
Optional.empty(),
|
||||
true,
|
||||
false,
|
||||
DialogAction.CLOSE,
|
||||
List.of(),
|
||||
List.of(
|
||||
new Input("base_64", new TextInput(
|
||||
200,
|
||||
Component.empty(),
|
||||
false,
|
||||
"",
|
||||
2000,
|
||||
Optional.empty()
|
||||
))
|
||||
)
|
||||
),
|
||||
new ActionButton(
|
||||
new CommonButtonData(
|
||||
Component.translatable("gui.ok"),
|
||||
150
|
||||
),
|
||||
Optional.of(
|
||||
new CustomAll(
|
||||
CUSTOM_DIALOG_ACTION,
|
||||
Optional.of(
|
||||
additionalData
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Text getDisplayName() {
|
||||
return Text.translatable("minions.gui.look.skin.base64");
|
||||
public Component getDisplayName() {
|
||||
return Component.translatable("minions.gui.look.skin.base64");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,24 +2,23 @@ package io.github.skippyall.minions.minion.skin;
|
||||
|
||||
import com.mojang.authlib.GameProfile;
|
||||
import com.mojang.authlib.properties.PropertyMap;
|
||||
import io.github.skippyall.minions.input.TextInput;
|
||||
import net.minecraft.block.entity.SkullBlockEntity;
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
import net.minecraft.text.Text;
|
||||
|
||||
import io.github.skippyall.minions.gui.input.TextInput;
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.world.level.block.entity.SkullBlockEntity;
|
||||
|
||||
public class NameSkinProvider implements SkinProvider {
|
||||
@Override
|
||||
public CompletableFuture<Optional<PropertyMap>> openSkinMenu(ServerPlayerEntity player) {
|
||||
return TextInput.inputString(player, Text.translatable("minions.gui.look.skin.name.title"), "")
|
||||
.thenCompose(SkullBlockEntity::fetchProfileByName)
|
||||
public CompletableFuture<Optional<PropertyMap>> openSkinMenu(ServerPlayer player) {
|
||||
return TextInput.inputString(player, Component.translatable("minions.gui.look.skin.name.title"), "")
|
||||
.thenCompose(SkullBlockEntity::fetchGameProfile)
|
||||
.thenApply(gameProfile -> gameProfile.map(GameProfile::getProperties));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Text getDisplayName() {
|
||||
return Text.translatable("minions.gui.look.skin.name");
|
||||
public Component getDisplayName() {
|
||||
return Component.translatable("minions.gui.look.skin.name");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,14 +1,13 @@
|
||||
package io.github.skippyall.minions.minion.skin;
|
||||
|
||||
import com.mojang.authlib.properties.PropertyMap;
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
import net.minecraft.text.Text;
|
||||
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
|
||||
public interface SkinProvider {
|
||||
CompletableFuture<Optional<PropertyMap>> openSkinMenu(ServerPlayerEntity player);
|
||||
CompletableFuture<Optional<PropertyMap>> openSkinMenu(ServerPlayer player);
|
||||
|
||||
Text getDisplayName();
|
||||
Component getDisplayName();
|
||||
}
|
||||
|
||||
@@ -1,25 +0,0 @@
|
||||
package io.github.skippyall.minions.minion.skin;
|
||||
|
||||
import com.mojang.serialization.Lifecycle;
|
||||
import io.github.skippyall.minions.Minions;
|
||||
import net.minecraft.registry.Registry;
|
||||
import net.minecraft.registry.RegistryKey;
|
||||
import net.minecraft.registry.SimpleRegistry;
|
||||
import net.minecraft.util.Identifier;
|
||||
|
||||
public class SkinProviders {
|
||||
public static final Registry<SkinProvider> SKIN_PROVIDERS = new SimpleRegistry<>(RegistryKey.ofRegistry(Identifier.of(Minions.MOD_ID, "skin_providers")), Lifecycle.stable());
|
||||
|
||||
public static NameSkinProvider NAME = register(new NameSkinProvider(), "name");
|
||||
public static UUIDSkinProvider UUID = register(new UUIDSkinProvider(), "uuid");
|
||||
public static Base64SkinProvider BASE64 = register(new Base64SkinProvider(), "base64");
|
||||
|
||||
|
||||
public static <T extends SkinProvider> T register(T skinProvider, String path) {
|
||||
return Registry.register(SKIN_PROVIDERS, Identifier.of(Minions.MOD_ID, path), skinProvider);
|
||||
}
|
||||
|
||||
public static void register() {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -2,31 +2,24 @@ package io.github.skippyall.minions.minion.skin;
|
||||
|
||||
import com.mojang.authlib.GameProfile;
|
||||
import com.mojang.authlib.properties.PropertyMap;
|
||||
import com.mojang.serialization.Codec;
|
||||
import com.mojang.serialization.codecs.RecordCodecBuilder;
|
||||
import io.github.skippyall.minions.input.TextInput;
|
||||
import io.github.skippyall.minions.minion.MinionProfileUtils;
|
||||
import net.minecraft.block.entity.SkullBlockEntity;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
import net.minecraft.text.Text;
|
||||
import net.minecraft.util.Uuids;
|
||||
import net.minecraft.util.dynamic.Codecs;
|
||||
|
||||
import io.github.skippyall.minions.gui.input.TextInput;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.world.level.block.entity.SkullBlockEntity;
|
||||
|
||||
public class UUIDSkinProvider implements SkinProvider {
|
||||
@Override
|
||||
public CompletableFuture<Optional<PropertyMap>> openSkinMenu(ServerPlayerEntity player) {
|
||||
return TextInput.inputString(player, Text.translatable("minions.gui.look.skin.uuid.title"), "")
|
||||
.thenCompose(uuidString -> SkullBlockEntity.fetchProfileByUuid(UUID.fromString(uuidString)))
|
||||
public CompletableFuture<Optional<PropertyMap>> openSkinMenu(ServerPlayer player) {
|
||||
return TextInput.inputString(player, Component.translatable("minions.gui.look.skin.uuid.title"), "")
|
||||
.thenCompose(uuidString -> SkullBlockEntity.fetchGameProfile(UUID.fromString(uuidString)))
|
||||
.thenApply(gameProfile -> gameProfile.map(GameProfile::getProperties));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Text getDisplayName() {
|
||||
return Text.translatable("minions.gui.look.skin.uuid");
|
||||
public Component getDisplayName() {
|
||||
return Component.translatable("minions.gui.look.skin.uuid");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +0,0 @@
|
||||
package io.github.skippyall.minions.mixinhelper;
|
||||
|
||||
import it.unimi.dsi.fastutil.objects.ObjectSet;
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
import net.minecraft.server.world.ChunkTicketManager;
|
||||
|
||||
public interface ChunkTicketManagerAccessor {
|
||||
ObjectSet<ServerPlayerEntity> getPlayers(long chunkpos);
|
||||
|
||||
ChunkTicketManager.DistanceFromNearestPlayerTracker getMinionless();
|
||||
}
|
||||
+2
-3
@@ -1,8 +1,7 @@
|
||||
package io.github.skippyall.minions.mixinhelpers;
|
||||
|
||||
import net.minecraft.entity.Entity;
|
||||
package io.github.skippyall.minions.mixinhelper;
|
||||
|
||||
import java.util.function.Predicate;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
|
||||
public class EntityViewMixinHelper {
|
||||
public static final ThreadLocal<Predicate<Entity>> ADDITIONAL_PREDICATE = ThreadLocal.withInitial(() -> entity -> true);
|
||||
+2
-2
@@ -1,6 +1,6 @@
|
||||
package io.github.skippyall.minions.mixinhelper;
|
||||
package io.github.skippyall.minions.mixinhelper.antimobcap;
|
||||
|
||||
public interface ChunkTicketManager$DistanceFromNearestPlayerTrackerAccessor {
|
||||
public interface ChunkLevelManager$DistanceFromNearestPlayerTrackerAccessor {
|
||||
void minions$markAsMinionless();
|
||||
void minions$markAsTarget();
|
||||
int minions$getTickedChunkCount();
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
package io.github.skippyall.minions.mixinhelper.antimobcap;
|
||||
|
||||
import it.unimi.dsi.fastutil.objects.ObjectSet;
|
||||
import net.minecraft.server.level.DistanceManager;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
|
||||
public interface ChunkLevelManagerAccessor {
|
||||
ObjectSet<ServerPlayer> minions$getPlayers(long chunkpos);
|
||||
|
||||
DistanceManager.FixedPlayerDistanceChunkTracker minions$getMinionless();
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user