Initial commit
All checks were successful
build / build (push) Successful in 2m24s

This commit is contained in:
2026-03-12 19:48:20 +01:00
commit 7c9c5b8ab1
32 changed files with 1488 additions and 0 deletions

29
.editorconfig Normal file
View File

@@ -0,0 +1,29 @@
root = true
[*]
charset = utf-8
end_of_line = lf
insert_final_newline = true
tab_width = 4
trim_trailing_whitespace = true
[*.md]
trim_trailing_whitespace = false
[*.gradle.kts]
indent_style = tab
[*.java]
indent_style = tab
[*.json]
indent_style = space
indent_size = 2
[fabric.mod.json]
indent_style = tab
tab_width = 2
[*.properties]
indent_style = space
indent_size = 2

5
.gitattributes vendored Normal file
View File

@@ -0,0 +1,5 @@
* text=auto eol=lf
gradlew text eol=lf
*.bat text eol=crlf
*.cmd text eol=crlf
gradle-wrapper.jar -text -diff -merge -filter

View File

@@ -0,0 +1,38 @@
name: build
on: [push, pull_request]
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: checkout repository
uses: actions/checkout@v6
- name: cache gradle
uses: actions/cache@v4
with:
path: |
~/.gradle/caches
~/.gradle/wrapper
key: gradle-${{ runner.os }}-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
restore-keys: |
gradle-${{ runner.os }}-
- name: setup jdk
uses: actions/setup-java@v5
with:
java-version: 21
distribution: temurin
- name: make gradle wrapper executable
run: chmod +x ./gradlew
- name: build
run: ./gradlew build --no-daemon -x test
- name: upload artifacts
uses: actions/upload-artifact@v3
with:
name: artifacts
path: build/libs/

8
.gitignore vendored Normal file
View File

@@ -0,0 +1,8 @@
.gradle/
.idea/
.vscode/
bin/
build/
out/
run/
run-server/

121
LICENSE Normal file
View File

@@ -0,0 +1,121 @@
Creative Commons Legal Code
CC0 1.0 Universal
CREATIVE COMMONS CORPORATION IS NOT A LAW FIRM AND DOES NOT PROVIDE
LEGAL SERVICES. DISTRIBUTION OF THIS DOCUMENT DOES NOT CREATE AN
ATTORNEY-CLIENT RELATIONSHIP. CREATIVE COMMONS PROVIDES THIS
INFORMATION ON AN "AS-IS" BASIS. CREATIVE COMMONS MAKES NO WARRANTIES
REGARDING THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS
PROVIDED HEREUNDER, AND DISCLAIMS LIABILITY FOR DAMAGES RESULTING FROM
THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS PROVIDED
HEREUNDER.
Statement of Purpose
The laws of most jurisdictions throughout the world automatically confer
exclusive Copyright and Related Rights (defined below) upon the creator
and subsequent owner(s) (each and all, an "owner") of an original work of
authorship and/or a database (each, a "Work").
Certain owners wish to permanently relinquish those rights to a Work for
the purpose of contributing to a commons of creative, cultural and
scientific works ("Commons") that the public can reliably and without fear
of later claims of infringement build upon, modify, incorporate in other
works, reuse and redistribute as freely as possible in any form whatsoever
and for any purposes, including without limitation commercial purposes.
These owners may contribute to the Commons to promote the ideal of a free
culture and the further production of creative, cultural and scientific
works, or to gain reputation or greater distribution for their Work in
part through the use and efforts of others.
For these and/or other purposes and motivations, and without any
expectation of additional consideration or compensation, the person
associating CC0 with a Work (the "Affirmer"), to the extent that he or she
is an owner of Copyright and Related Rights in the Work, voluntarily
elects to apply CC0 to the Work and publicly distribute the Work under its
terms, with knowledge of his or her Copyright and Related Rights in the
Work and the meaning and intended legal effect of CC0 on those rights.
1. Copyright and Related Rights. A Work made available under CC0 may be
protected by copyright and related or neighboring rights ("Copyright and
Related Rights"). Copyright and Related Rights include, but are not
limited to, the following:
i. the right to reproduce, adapt, distribute, perform, display,
communicate, and translate a Work;
ii. moral rights retained by the original author(s) and/or performer(s);
iii. publicity and privacy rights pertaining to a person's image or
likeness depicted in a Work;
iv. rights protecting against unfair competition in regards to a Work,
subject to the limitations in paragraph 4(a), below;
v. rights protecting the extraction, dissemination, use and reuse of data
in a Work;
vi. database rights (such as those arising under Directive 96/9/EC of the
European Parliament and of the Council of 11 March 1996 on the legal
protection of databases, and under any national implementation
thereof, including any amended or successor version of such
directive); and
vii. other similar, equivalent or corresponding rights throughout the
world based on applicable law or treaty, and any national
implementations thereof.
2. Waiver. To the greatest extent permitted by, but not in contravention
of, applicable law, Affirmer hereby overtly, fully, permanently,
irrevocably and unconditionally waives, abandons, and surrenders all of
Affirmer's Copyright and Related Rights and associated claims and causes
of action, whether now known or unknown (including existing as well as
future claims and causes of action), in the Work (i) in all territories
worldwide, (ii) for the maximum duration provided by applicable law or
treaty (including future time extensions), (iii) in any current or future
medium and for any number of copies, and (iv) for any purpose whatsoever,
including without limitation commercial, advertising or promotional
purposes (the "Waiver"). Affirmer makes the Waiver for the benefit of each
member of the public at large and to the detriment of Affirmer's heirs and
successors, fully intending that such Waiver shall not be subject to
revocation, rescission, cancellation, termination, or any other legal or
equitable action to disrupt the quiet enjoyment of the Work by the public
as contemplated by Affirmer's express Statement of Purpose.
3. Public License Fallback. Should any part of the Waiver for any reason
be judged legally invalid or ineffective under applicable law, then the
Waiver shall be preserved to the maximum extent permitted taking into
account Affirmer's express Statement of Purpose. In addition, to the
extent the Waiver is so judged Affirmer hereby grants to each affected
person a royalty-free, non transferable, non sublicensable, non exclusive,
irrevocable and unconditional license to exercise Affirmer's Copyright and
Related Rights in the Work (i) in all territories worldwide, (ii) for the
maximum duration provided by applicable law or treaty (including future
time extensions), (iii) in any current or future medium and for any number
of copies, and (iv) for any purpose whatsoever, including without
limitation commercial, advertising or promotional purposes (the
"License"). The License shall be deemed effective as of the date CC0 was
applied by Affirmer to the Work. Should any part of the License for any
reason be judged legally invalid or ineffective under applicable law, such
partial invalidity or ineffectiveness shall not invalidate the remainder
of the License, and in such case Affirmer hereby affirms that he or she
will not (i) exercise any of his or her remaining Copyright and Related
Rights in the Work or (ii) assert any associated claims and causes of
action with respect to the Work, in either case contrary to Affirmer's
express Statement of Purpose.
4. Limitations and Disclaimers.
a. No trademark or patent rights held by Affirmer are waived, abandoned,
surrendered, licensed or otherwise affected by this document.
b. Affirmer offers the Work as-is and makes no representations or
warranties of any kind concerning the Work, express, implied,
statutory or otherwise, including without limitation warranties of
title, merchantability, fitness for a particular purpose, non
infringement, or the absence of latent or other defects, accuracy, or
the present or absence of errors, whether or not discoverable, all to
the greatest extent permissible under applicable law.
c. Affirmer disclaims responsibility for clearing rights of other persons
that may apply to the Work or any use thereof, including without
limitation any person's Copyright and Related Rights in the Work.
Further, Affirmer disclaims responsibility for obtaining any necessary
consents, permissions or other rights required for any use of the
Work.
d. Affirmer understands and acknowledges that Creative Commons is not a
party to this document and has no duty or obligation with respect to
this CC0 or use of the Work.

39
README.md Normal file
View File

@@ -0,0 +1,39 @@
# Example Mod
Template for making Babric mods for BTA!
**Note: *DO NOT fork this repository unless you want to contribute!***
## Prerequisites
- JDK for Java 21 ([Eclipse Temurin](https://adoptium.net/temurin/releases/) recommended)
- [Intellij IDEA](https://www.jetbrains.com/idea/download/) (Scroll down for the free community edition, if using linux **DO NOT** use the flatpak distribution)
- Minecraft Development plugin (Optional, but highly recommended)
## Setup instructions
1. Click the `Use this template` button on this repo's page above (Will only appear if logged in). Choose `Create a new repository`, you will be redirected to a new page. Enter your repo's name and description, and hit `Create repository`.
To get your project, open IntelliJ IDEA and click `Clone Repository` (`Get from VCS` on older versions). Select `Repository URL` and enter your repo's url
2. After the project has finished importing, close it and open it again.
If that does not work, open the right sidebar with `Gradle` on it, open `Tasks` > `fabric` and run `ideaSyncTask`.
3. Create a new run configuration by going in `Run > Edit Configurations`.
Then click on the plus icon and select Gradle. In the `Tasks and Arguments` field enter `build`.
Running it will build your finished jar files and put them in `build/libs/`.
4. Lastly, open `File` > `Settings` and head to `Build, Execution, Development` > `Build Tools` > `Gradle`.
Make sure `Build and run using` and `Run tests using` is set to `Gradle`.
5. Done! Now, all that's left is to change every mention of `quetzal` and `ciomek` to your own mod id and mod group, respectively. Happy modding!
## Tips
1. If you quetzal't already you should join the BTA modding discord! https://discord.gg/FTUNJhswBT
2. You can set your username when launching the client run configuration by setting `--username <username>` in your program arguments.
3. When launching the server run configuration you may want to remove the `nogui` program argument in order to see the regular server GUI.
4. In Intellij you can double press shift or press ctrl+N to search class files, change the search from the default `Project Files` to `All Places` you can easily explore the classes for your dependencies and even BTA itself.
5. In Intellij if ctrl+left-click on a field or method you can quickly get information on when and where that field or method is assign or used.
6. Ensure IntelliJ is updated to the latest version. This is important because this template uses the latest Gradle version and if your IntelliJ installation is outdated, it may not support the latest version.
7. In the `quetzal.mixins.json` you'll see `"compatibilityLevel": "JAVA_${java}",` along with an error message from the `Minecraft Development` plugin stating `Cannot resolve compatibility level 'JAVA_${java}'`. You can safely ignore this. The Gradle build system has been set up to grab the Java version from your `gradle.properties` and replace `${java}` with it. So the compiled binary will properly have it as `JAVA_8`.

128
build.gradle.kts Normal file
View File

@@ -0,0 +1,128 @@
import com.smushytaco.lwjgl_gradle.Preset
plugins {
alias(libs.plugins.loom)
alias(libs.plugins.lwjgl)
java
}
val modVersion: Provider<String> = providers.gradleProperty("mod_version")
val modGroup: Provider<String> = providers.gradleProperty("mod_group")
val modName: Provider<String> = providers.gradleProperty("mod_name")
val javaVersion: Provider<Int> = libs.versions.java.map { it.toInt() }
base.archivesName = modName
group = modGroup.get()
version = modVersion.get()
loom {
customMinecraftMetadata.set("https://downloads.betterthanadventure.net/bta-client/${libs.versions.btaChannel.get()}/v${libs.versions.bta.get()}/manifest.json")
}
repositories {
mavenCentral()
maven("https://maven.fabricmc.net/") { name = "Fabric" }
maven("https://maven.thesignalumproject.net/infrastructure") { name = "SignalumMavenInfrastructure" }
maven("https://maven.thesignalumproject.net/releases") { name = "SignalumMavenReleases" }
ivy("https://github.com/Better-than-Adventure") {
patternLayout { artifact("[organisation]/releases/download/[revision]/[module]-bta-[revision].jar") }
metadataSources { artifact() }
}
ivy("https://downloads.betterthanadventure.net/bta-client/${libs.versions.btaChannel.get()}/") {
patternLayout { artifact("/v[revision]/client.jar") }
metadataSources { artifact() }
}
ivy("https://downloads.betterthanadventure.net/bta-server/${libs.versions.btaChannel.get()}/") {
patternLayout { artifact("/v[revision]/server.jar") }
metadataSources { artifact() }
}
ivy("https://piston-data.mojang.com") {
patternLayout { artifact("v1/[organisation]/[revision]/[module].jar") }
metadataSources { artifact() }
}
}
lwjgl {
version = libs.versions.lwjgl
implementation(Preset.MINIMAL_OPENGL)
}
dependencies {
minecraft("::${libs.versions.bta.get()}")
runtimeOnly(libs.clientJar)
implementation(libs.loader)
// If you do not need Halplibe you can comment out or delete this line.
implementation(libs.halplibe)
implementation(libs.modMenu)
implementation(libs.legacyLwjgl)
implementation(libs.slf4jApi)
implementation(libs.guava)
implementation(libs.log4j.slf4j2.impl)
implementation(libs.log4j.core)
implementation(libs.log4j.api)
implementation(libs.log4j.api12)
implementation(libs.gson)
implementation(libs.commonsLang3)
include(libs.commonsLang3)
}
java {
toolchain {
languageVersion = javaVersion.map { JavaLanguageVersion.of(it) }
vendor = JvmVendorSpec.ADOPTIUM
}
sourceCompatibility = JavaVersion.toVersion(javaVersion.get())
targetCompatibility = JavaVersion.toVersion(javaVersion.get())
withSourcesJar()
}
val licenseFile = run {
val rootLicense = layout.projectDirectory.file("LICENSE")
val parentLicense = layout.projectDirectory.file("../LICENSE")
when {
rootLicense.asFile.exists() -> {
logger.lifecycle("Using LICENSE from project root: {}", rootLicense.asFile)
rootLicense
}
parentLicense.asFile.exists() -> {
logger.lifecycle("Using LICENSE from parent directory: {}", parentLicense.asFile)
parentLicense
}
else -> {
logger.warn("No LICENSE file found in project or parent directory.")
null
}
}
}
tasks {
withType<JavaCompile>().configureEach {
options.encoding = "UTF-8"
sourceCompatibility = javaVersion.get().toString()
targetCompatibility = javaVersion.get().toString()
if (javaVersion.get() > 8) options.release = javaVersion
}
named<UpdateDaemonJvm>("updateDaemonJvm") {
languageVersion = libs.versions.gradleJava.map { JavaLanguageVersion.of(it.toInt()) }
vendor = JvmVendorSpec.ADOPTIUM
}
withType<JavaExec>().configureEach { defaultCharacterEncoding = "UTF-8" }
withType<Javadoc>().configureEach { options.encoding = "UTF-8" }
withType<Test>().configureEach { defaultCharacterEncoding = "UTF-8" }
withType<Jar>().configureEach {
licenseFile?.let {
from(it) {
rename { original -> "${original}_${archiveBaseName.get()}" }
}
}
}
processResources {
val resourceMap = mapOf(
"version" to modVersion.get(),
"fabricloader" to libs.versions.loader.get(),
"halplibe" to libs.versions.halplibe.get(),
"java" to libs.versions.java.get(),
"modmenu" to libs.versions.modMenu.get()
)
inputs.properties(resourceMap)
filesMatching("fabric.mod.json") { expand(resourceMap) }
filesMatching("**/*.mixins.json") { expand(resourceMap.filterKeys { it == "java" }) }
}
}
// Removes LWJGL2 dependencies
configurations.configureEach { exclude(group = "org.lwjgl.lwjgl") }

18
gradle.properties Normal file
View File

@@ -0,0 +1,18 @@
##########################################################################
# Standard Properties
org.gradle.jvmargs = -Xmx6G
org.gradle.warning.mode = all
# This currently has to be set to false because the "Minecraft Client" and "Minecraft Server" configurations generated
# by IntelliJ aren't currently compatible with the configuration cache. If you use the runClient and runServer Gradle
# tasks instead, then this can (and should) be set to true.
org.gradle.configuration-cache = false
##########################################################################
# Mod Properties
mod_version = 0.1.0
mod_group = ciomek
mod_name = quetzal
##########################################################################
# Plugin Dependency
# Check this on https://plugins.gradle.org/plugin/org.gradle.toolchains.foojay-resolver-convention/
foojay_resolver_version = 1.0.0
##########################################################################

View File

@@ -0,0 +1,13 @@
#This file is generated by updateDaemonJvm
toolchainUrl.FREE_BSD.AARCH64=https\://api.foojay.io/disco/v3.0/ids/df211d3c3eefdc408b462041881bc575/redirect
toolchainUrl.FREE_BSD.X86_64=https\://api.foojay.io/disco/v3.0/ids/b41931cf1e70bc8e08d7dd19c343ef00/redirect
toolchainUrl.LINUX.AARCH64=https\://api.foojay.io/disco/v3.0/ids/df211d3c3eefdc408b462041881bc575/redirect
toolchainUrl.LINUX.X86_64=https\://api.foojay.io/disco/v3.0/ids/93aeea858331bd6bb00ba94759830234/redirect
toolchainUrl.MAC_OS.AARCH64=https\://api.foojay.io/disco/v3.0/ids/46949723aaa20c7b64d7ecfed7207034/redirect
toolchainUrl.MAC_OS.X86_64=https\://api.foojay.io/disco/v3.0/ids/f636c800fdb3f9ae33f019dfa048ba72/redirect
toolchainUrl.UNIX.AARCH64=https\://api.foojay.io/disco/v3.0/ids/df211d3c3eefdc408b462041881bc575/redirect
toolchainUrl.UNIX.X86_64=https\://api.foojay.io/disco/v3.0/ids/b41931cf1e70bc8e08d7dd19c343ef00/redirect
toolchainUrl.WINDOWS.AARCH64=https\://api.foojay.io/disco/v3.0/ids/3cd7045fca9a72cd9bc7d14a385e594c/redirect
toolchainUrl.WINDOWS.X86_64=https\://api.foojay.io/disco/v3.0/ids/552c7bffe0370c66410a51c55985b511/redirect
toolchainVendor=ADOPTIUM
toolchainVersion=21

62
gradle/libs.versions.toml Normal file
View File

@@ -0,0 +1,62 @@
[versions]
##########################################################################
# Plugins
# Check this on https://github.com/FabricMC/fabric-loom/releases/latest/
loom = "1.15-SNAPSHOT"
# Check this on https://plugins.gradle.org/plugin/com.smushytaco.lwjgl3/
lwjglPlugin = "1.0.2"
##########################################################################
# Java Configuration
# The Java version the JDK will be for compiling and running code.
java = "8"
# The Java version the JDK will be for running Gradle.
gradleJava = "21"
##########################################################################
# Mod Dependencies
# Check this on https://downloads.betterthanadventure.net/bta-client/
bta = "7.3_04"
# Options are release, prerelease, nightly, and misc.
btaChannel = "release"
# Check this on https://maven.thesignalumproject.net/#/infrastructure/net/fabricmc/fabric-loader/
loader = "0.18.4-bta.10"
# Check this on https://github.com/Turnip-Labs/ModMenu/releases/latest/
modMenu = "4.0.0"
# Check this on https://github.com/Turnip-Labs/bta-halplibe/releases/latest/
halplibe = "5.4.0"
# Check this on https://github.com/Better-than-Adventure/legacy-lwjgl3/releases/latest/
legacyLwjgl = "1.0.6"
##########################################################################
# Dependencies
# Check this on https://central.sonatype.com/artifact/org.slf4j/slf4j-api/
slf4jApi = "2.0.17"
# Check this on https://central.sonatype.com/artifact/com.google.guava/guava/
guava = "33.5.0-jre"
# Check this on https://central.sonatype.com/artifact/org.apache.logging.log4j/log4j-api/
log4j = "2.20.0"
# Check this on https://central.sonatype.com/artifact/com.google.code.gson/gson/
gson = "2.13.2"
# Check this on https://central.sonatype.com/artifact/org.apache.commons/commons-lang3/
commonsLang3 = "3.20.0"
# This should match the version used by the current BTA release.
lwjgl = "3.3.3"
##########################################################################
[libraries]
loader = { group = "net.fabricmc", name = "fabric-loader", version.ref = "loader" }
halplibe = { group = "turniplabs", name = "halplibe", version.ref = "halplibe" }
modMenu = { group = "turniplabs", name = "modmenu-bta", version.ref = "modMenu" }
legacyLwjgl = { group = "legacy-lwjgl3", name = "legacy-lwjgl3", version.ref = "legacyLwjgl" }
slf4jApi = { group = "org.slf4j", name = "slf4j-api", version.ref = "slf4jApi" }
guava = { group = "com.google.guava", name = "guava", version.ref = "guava" }
log4j-slf4j2-impl = { group = "org.apache.logging.log4j", name = "log4j-slf4j2-impl", version.ref = "log4j" }
log4j-core = { group = "org.apache.logging.log4j", name = "log4j-core", version.ref = "log4j" }
log4j-api = { group = "org.apache.logging.log4j", name = "log4j-api", version.ref = "log4j" }
log4j-api12 = { group = "org.apache.logging.log4j", name = "log4j-1.2-api", version.ref = "log4j" }
gson = { group = "com.google.code.gson", name = "gson", version.ref = "gson" }
commonsLang3 = { group = "org.apache.commons", name = "commons-lang3", version.ref = "commonsLang3" }
# https://piston-data.mojang.com/v1/objects/43db9b498cb67058d2e12d394e6507722e71bb45/client.jar
clientJar = { group = "objects", name = "client", version = "43db9b498cb67058d2e12d394e6507722e71bb45" }
[plugins]
loom = { id = "net.fabricmc.fabric-loom", version.ref = "loom" }
lwjgl = { id = "com.smushytaco.lwjgl3", version.ref = "lwjglPlugin" }

BIN
gradle/wrapper/gradle-wrapper.jar vendored Normal file

Binary file not shown.

View File

@@ -0,0 +1,8 @@
# Check this on https://gradle.org/releases/
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-9.3.1-all.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists

248
gradlew vendored Executable file
View File

@@ -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/HEAD/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" "$@"

93
gradlew.bat vendored Executable file
View File

@@ -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

59
settings.gradle.kts Normal file
View File

@@ -0,0 +1,59 @@
val modName: Provider<String> = providers.gradleProperty("mod_name")
rootProject.name = modName.get()
pluginManagement {
fun isRepoHealthy(url: String): Boolean {
var connection: javax.net.ssl.HttpsURLConnection? = null
return try {
connection = java.net.URI(url).toURL().openConnection() as javax.net.ssl.HttpsURLConnection
connection.requestMethod = "HEAD"
connection.connectTimeout = 2000
connection.readTimeout = 2000
connection.instanceFollowRedirects = true
connection.connect()
val code = connection.responseCode
code in 200..399
} catch (_: Exception) {
false
} finally {
connection?.disconnect()
}
}
fun repoUrlWithFallbacks(candidates: List<String>): String {
if (candidates.isEmpty()) {
val badLink = "https://mock.httpstatus.io/500"
logger.error("No repositories have been provided. Defaulting to: {}", badLink)
return badLink
}
val chosenRepository = candidates.firstOrNull { isRepoHealthy(it) } ?: run {
if (candidates.size == 1) {
logger.error("\"{}\" could not be resolved.", candidates.first())
} else {
logger.error("All {} repositories could not be resolved. Defaulting to: {}", candidates.size, candidates.first())
}
return candidates.first()
}
logger.lifecycle("Using \"{}\" as the Fabric repository.", chosenRepository)
return chosenRepository
}
repositories {
maven(
repoUrlWithFallbacks(
listOf(
"https://maven.fabricmc.net",
"https://maven2.fabricmc.net",
"https://maven3.fabricmc.net"
)
)
) { name = "Fabric" }
maven("https://maven.thesignalumproject.net/infrastructure") { name = "SignalumMavenInfrastructure" }
mavenCentral()
gradlePluginPortal()
}
val foojayResolverVersion = providers.gradleProperty("foojay_resolver_version")
plugins {
id("org.gradle.toolchains.foojay-resolver-convention").version(foojayResolverVersion.get())
}
}
plugins {
id("org.gradle.toolchains.foojay-resolver-convention")
}

View File

@@ -0,0 +1,21 @@
package ciomek.quetzal;
import ciomek.quetzal.teleport.TeleportRequest;
import ciomek.quetzal.tick.TickTimer;
import net.minecraft.core.entity.player.Player;
import net.minecraft.core.world.World;
import java.util.List;
import java.util.function.Consumer;
public interface IWorldUtils {
void addTickCallback(int delayTicks, Consumer<World> callback);
void addRequestToTeleportTo(Player sender, Player receiver);
void addRequestToTeleportFrom(Player sender, Player receiver);
List<TeleportRequest> getPendingRequests(Player receiver);
TeleportRequest getNewestRequest(Player receiver);
TickTimer getTickTimer();
}

View File

@@ -0,0 +1,39 @@
package ciomek.quetzal;
import ciomek.quetzal.commands.HomeCommand;
import ciomek.quetzal.commands.TeleportAcceptCommand;
import ciomek.quetzal.commands.TeleportCommand;
import ciomek.quetzal.commands.TeleportDeclineCommand;
import net.fabricmc.api.ModInitializer;
import net.minecraft.core.net.command.CommandManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import turniplabs.halplibe.util.GameStartEntrypoint;
import turniplabs.halplibe.util.RecipeEntrypoint;
public class Quetzal implements ModInitializer, RecipeEntrypoint, GameStartEntrypoint {
public static final String MOD_ID = "quetzal";
public static final Logger LOGGER = LoggerFactory.getLogger(MOD_ID);
@Override
public void onInitialize() {
LOGGER.info("quetzal initialized.");
CommandManager.registerCommand(new TeleportCommand());
CommandManager.registerCommand(new TeleportAcceptCommand());
CommandManager.registerCommand(new TeleportDeclineCommand());
CommandManager.registerCommand(new HomeCommand());
}
@Override
public void onRecipesReady() {}
@Override
public void initNamespaces() {}
@Override
public void beforeGameStart() {}
@Override
public void afterGameStart() {}
}

View File

@@ -0,0 +1,32 @@
package ciomek.quetzal;
import ciomek.quetzal.tick.TickTimer;
import net.minecraft.core.entity.player.Player;
import net.minecraft.server.entity.player.PlayerServer;
public class Utils {
public static void TeleportPlayer(Player fromPlayer, Player toPlayer, TickTimer timer)
{
double startX = round1(fromPlayer.x);
double startY = round1(fromPlayer.y);
double startZ = round1(fromPlayer.z);
fromPlayer.sendMessage("Teleporting home. Don't move for 5 seconds...");
timer.addTickTask(100, (world) -> {
if (round1(fromPlayer.x) != startX || round1(fromPlayer.y) != startY || round1(fromPlayer.z) != startZ) {
fromPlayer.sendMessage("Teleport cancelled because you moved.");
return;
}
((PlayerServer)fromPlayer).playerNetServerHandler.teleportAndRotate(toPlayer.x, toPlayer.y, toPlayer.z, toPlayer.yRot, toPlayer.xRot);
fromPlayer.sendMessage("Teleported to " + toPlayer.username + "!");
toPlayer.sendMessage(fromPlayer.username + " teleported to you!");
});
}
private static double round1(double value) {
return Math.round(value * 10.0) / 10.0;
}
}

View File

@@ -0,0 +1,117 @@
package ciomek.quetzal.commands;
import ciomek.quetzal.IWorldUtils;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.builder.ArgumentBuilderLiteral;
import net.minecraft.core.entity.player.Player;
import net.minecraft.core.net.command.CommandManager;
import net.minecraft.core.net.command.CommandSource;
import net.fabricmc.api.ModInitializer;
import net.minecraft.server.entity.player.PlayerServer;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.lang.reflect.Type;
import java.util.HashMap;
import java.util.Map;
public class HomeCommand implements CommandManager.CommandRegistry, ModInitializer {
private static final Map<String, double[]> homes = new HashMap<>();
private static final Gson gson = new Gson();
private static final File homesFile = new File("homes.json");
@Override
public void onInitialize() {
loadHomes();
}
private void loadHomes() {
if (!homesFile.exists()) return;
try (FileReader reader = new FileReader(homesFile)) {
Type type = new TypeToken<Map<String, double[]>>(){}.getType();
Map<String, double[]> loaded = gson.fromJson(reader, type);
if (loaded != null) homes.putAll(loaded);
} catch (IOException e) {
System.err.println("Failed to load homes: " + e.getMessage());
}
}
private void saveHomes() {
try (FileWriter writer = new FileWriter(homesFile)) {
gson.toJson(homes, writer);
} catch (IOException e) {
System.err.println("Failed to save homes: " + e.getMessage());
}
}
@Override
public void register(CommandDispatcher<CommandSource> dispatcher) {
dispatcher.register(
ArgumentBuilderLiteral.<CommandSource>literal("sethome")
.executes(context -> {
CommandSource source = context.getSource();
Player player = source.getSender();
if (player == null) {
source.sendMessage("This command can only be run by a player!");
return 0;
}
homes.put(player.username, new double[]{player.x, player.y, player.z});
saveHomes();
player.sendMessage("Home set.");
return 1;
})
);
dispatcher.register(
ArgumentBuilderLiteral.<CommandSource>literal("home")
.executes(context -> {
CommandSource source = context.getSource();
Player player = source.getSender();
IWorldUtils worldUtils = (IWorldUtils) source.getWorld();
if (player == null) {
source.sendMessage("This command can only be run by a player!");
return 0;
}
if (!homes.containsKey(player.username)) {
homes.put(player.username, new double[]{player.x, player.y, player.z});
saveHomes();
player.sendMessage("Home was not set. Setting it to your current location.");
return 1;
}
double[] home = homes.get(player.username);
double startX = round1(player.x);
double startY = round1(player.y);
double startZ = round1(player.z);
player.sendMessage("Teleporting home. Don't move for 5 seconds...");
worldUtils.addTickCallback(100, (w) -> {
if (round1(player.x) != startX || round1(player.y) != startY || round1(player.z) != startZ) {
player.sendMessage("Teleport cancelled because you moved.");
return;
}
((PlayerServer)player).playerNetServerHandler.teleport(home[0], home[1], home[2]);
player.sendMessage("Teleported home.");
});
return 1;
})
);
}
private double round1(double value) {
return Math.round(value * 10.0) / 10.0;
}
}

View File

@@ -0,0 +1,34 @@
package ciomek.quetzal.commands;
import ciomek.quetzal.IWorldUtils;
import ciomek.quetzal.teleport.TeleportRequest;
import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.builder.ArgumentBuilderLiteral;
import net.minecraft.core.entity.player.Player;
import net.minecraft.core.net.command.CommandManager;
import net.minecraft.core.net.command.CommandSource;
import static com.mojang.brigadier.builder.ArgumentBuilderLiteral.literal;
public class TeleportAcceptCommand implements CommandManager.CommandRegistry {
@SuppressWarnings("unchecked")
@Override
public void register(CommandDispatcher<CommandSource> commandDispatcher) {
commandDispatcher
.register(
(ArgumentBuilderLiteral<CommandSource>) (Object) literal("tpa")
.executes(context -> {
CommandSource source = (CommandSource) context.getSource();
Player player = source.getSender();
IWorldUtils worldUtils = (IWorldUtils) source.getWorld();
TeleportRequest tpr = worldUtils.getNewestRequest(player);
tpr.accept(worldUtils.getTickTimer());
return 1;
})
);
}
}

View File

@@ -0,0 +1,92 @@
package ciomek.quetzal.commands;
import ciomek.quetzal.IWorldUtils;
import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.builder.ArgumentBuilderLiteral;
import com.mojang.brigadier.builder.ArgumentBuilderRequired;
import net.minecraft.core.entity.Entity;
import net.minecraft.core.entity.player.Player;
import net.minecraft.core.net.command.CommandManager;
import net.minecraft.core.net.command.CommandSource;
import net.minecraft.core.net.command.arguments.ArgumentTypeEntity;
import net.minecraft.core.net.command.helpers.EntitySelector;
import static com.mojang.brigadier.builder.ArgumentBuilderLiteral.literal;
public class TeleportCommand implements CommandManager.CommandRegistry {
@SuppressWarnings("unchecked")
@Override
public void register(CommandDispatcher<CommandSource> commandDispatcher) {
commandDispatcher
.register(
(ArgumentBuilderLiteral<CommandSource>) (Object) literal("tpr")
.then(
ArgumentBuilderRequired.argument("player", ArgumentTypeEntity.username())
.executes(context -> {
CommandSource source = (CommandSource) context.getSource();
EntitySelector entitySelector = context.getArgument("player", EntitySelector.class);
if (entitySelector.get(source).isEmpty()) {
source.sendMessage("None selected!");
return 0;
}
Entity entity = entitySelector.get(source).get(0);
Player target = (Player) entity;
Player player = source.getSender();
IWorldUtils worldUtils = (IWorldUtils) source.getWorld();
if (player == null) {
source.sendMessage("This command can only be run by a player!");
return 0;
}
worldUtils.addRequestToTeleportTo(player, target);
player.sendMessage("Sent request to " + target.username + ".");
target.sendMessage("Do you want " + target.username + " to teleport to you?");
return 1;
})
)
);
commandDispatcher
.register(
(ArgumentBuilderLiteral<CommandSource>) (Object) literal("tpfr")
.then(
ArgumentBuilderRequired.argument("player", ArgumentTypeEntity.username())
.executes(context -> {
CommandSource source = (CommandSource) context.getSource();
EntitySelector entitySelector = context.getArgument("player", EntitySelector.class);
if (entitySelector.get(source).isEmpty()) {
source.sendMessage("None selected!");
return 0;
}
Entity entity = entitySelector.get(source).get(0);
Player target = (Player) entity;
Player player = source.getSender();
IWorldUtils worldUtils = (IWorldUtils) source.getWorld();
if (player == null) {
source.sendMessage("This command can only be run by a player!");
return 0;
}
worldUtils.addRequestToTeleportFrom(player, target);
player.sendMessage("Sent request to " + target.username + ".");
target.sendMessage("Do you want to teleport to " + target.username + "?");
return 1;
})
)
);
}
}

View File

@@ -0,0 +1,34 @@
package ciomek.quetzal.commands;
import ciomek.quetzal.IWorldUtils;
import ciomek.quetzal.teleport.TeleportRequest;
import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.builder.ArgumentBuilderLiteral;
import net.minecraft.core.entity.player.Player;
import net.minecraft.core.net.command.CommandManager;
import net.minecraft.core.net.command.CommandSource;
import static com.mojang.brigadier.builder.ArgumentBuilderLiteral.literal;
public class TeleportDeclineCommand implements CommandManager.CommandRegistry {
@SuppressWarnings("unchecked")
@Override
public void register(CommandDispatcher<CommandSource> commandDispatcher) {
commandDispatcher
.register(
(ArgumentBuilderLiteral<CommandSource>) (Object) literal("tpd")
.executes(context -> {
CommandSource source = (CommandSource) context.getSource();
Player player = source.getSender();
IWorldUtils worldUtils = (IWorldUtils) source.getWorld();
TeleportRequest tpr = worldUtils.getNewestRequest(player);
tpr.decline();
return 1;
})
);
}
}

View File

@@ -0,0 +1,76 @@
package ciomek.quetzal.mixin;
import ciomek.quetzal.IWorldUtils;
import ciomek.quetzal.teleport.TeleportRequest;
import ciomek.quetzal.teleport.TeleportToRequest;
import ciomek.quetzal.tick.TickTimer;
import net.minecraft.core.entity.player.Player;
import net.minecraft.core.world.World;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import java.time.LocalDate;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.Objects;
import java.util.function.Consumer;
import java.util.stream.Collectors;
@Mixin(value = World.class, remap = false)
public class WorldOverwriteMixin implements IWorldUtils {
@Unique
private final TickTimer tickTimer = new TickTimer();
@Unique
private final List<TeleportRequest> teleportRequests = new ArrayList<>();
@Override
public TickTimer getTickTimer()
{
return tickTimer;
}
@Override
public void addTickCallback(int delayTicks, Consumer<World> callback) {
tickTimer.addTickTask(delayTicks, callback);
}
@Inject(method = "tick", at = @At(value = "TAIL"))
public void tick(CallbackInfo ci) {
tickTimer.tick((World) (Object) this);
}
@Override
public void addRequestToTeleportTo(Player sender, Player receiver) {
TeleportRequest tpr = new TeleportToRequest(sender, receiver, LocalDate.now());
teleportRequests.add(tpr);
}
@Override
public void addRequestToTeleportFrom(Player sender, Player receiver) {
TeleportRequest tpr = new TeleportToRequest(sender, receiver, LocalDate.now());
teleportRequests.add(tpr);
}
@Override
public TeleportRequest getNewestRequest(Player receiver)
{
return teleportRequests.stream()
.filter(tr -> Objects.equals(tr.receiver, receiver))
.max(Comparator.comparing(tr -> tr.sentAt))
.orElse(null);
}
@Override
public List<TeleportRequest> getPendingRequests(Player receiver) {
return teleportRequests.stream()
.filter(tr -> Objects.equals(tr.receiver, receiver))
.collect(Collectors.toList());
}
}

View File

@@ -0,0 +1,24 @@
package ciomek.quetzal.teleport;
import ciomek.quetzal.Utils;
import ciomek.quetzal.tick.TickTimer;
import net.minecraft.core.entity.player.Player;
import java.time.LocalDate;
public class TeleportFromRequest extends TeleportRequest {
public TeleportFromRequest(Player sender, Player receiver, LocalDate sentAt) {
super(sender, receiver, sentAt);
}
public void accept(TickTimer timer)
{
sender.sendMessage(receiver.username + " has accepted the teleportation request. ");
Utils.TeleportPlayer(receiver, sender, timer);
}
public void decline()
{
sender.sendMessage(receiver.username + " has declined the teleportation request. ");
}
}

View File

@@ -0,0 +1,24 @@
package ciomek.quetzal.teleport;
import ciomek.quetzal.tick.TickTimer;
import net.minecraft.core.entity.player.Player;
import java.time.LocalDate;
public abstract class TeleportRequest {
public Player sender;
public Player receiver;
public LocalDate sentAt;
public TeleportRequest(Player sender, Player receiver, LocalDate sentAt) {
this.sender = sender;
this.receiver = receiver;
this.sentAt = sentAt;
}
public abstract void accept(TickTimer timer);
public abstract void decline();
}

View File

@@ -0,0 +1,24 @@
package ciomek.quetzal.teleport;
import ciomek.quetzal.Utils;
import ciomek.quetzal.tick.TickTimer;
import net.minecraft.core.entity.player.Player;
import java.time.LocalDate;
public class TeleportToRequest extends TeleportRequest {
public TeleportToRequest(Player sender, Player receiver, LocalDate sentAt) {
super(sender, receiver, sentAt);
}
public void accept(TickTimer timer)
{
sender.sendMessage(receiver.username + " has accepted the teleportation request. ");
Utils.TeleportPlayer(sender, receiver, timer);
}
public void decline()
{
sender.sendMessage(receiver.username + " has declined the teleportation request. ");
}
}

View File

@@ -0,0 +1,15 @@
package ciomek.quetzal.tick;
import net.minecraft.core.world.World;
import java.util.function.Consumer;
public class TickTask {
public int ticksLeft;
public Consumer<World> callback;
public TickTask(int ticksLeft, Consumer<World> callback) {
this.ticksLeft = ticksLeft;
this.callback = callback;
}
}

View File

@@ -0,0 +1,32 @@
package ciomek.quetzal.tick;
import net.minecraft.core.world.World;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.function.Consumer;
public class TickTimer {
private final List<TickTask> tickTasks = new ArrayList<>();
public void addTickTask(int delayTicks, Consumer<World> callback) {
tickTasks.add(new TickTask(delayTicks, callback));
}
public void tick(World world) {
Iterator<TickTask> iterator = tickTasks.iterator();
while (iterator.hasNext()) {
TickTask task = iterator.next();
task.ticksLeft--;
if (task.ticksLeft <= 0) {
task.callback.accept(world);
iterator.remove();
}
}
}
}

View File

@@ -0,0 +1,43 @@
{
"schemaVersion": 1,
"id": "quetzal",
"version": "${version}",
"name": "Quetzal",
"description": "Basic stuff for servers.",
"authors": [
"ciomek"
],
"contact": {
"homepage": "",
"sources": ""
},
"icon": "icon.png",
"license": "CC0-1.0",
"environment": "*",
"entrypoints": {
"main": [
"ciomek.quetzal.Quetzal"
],
"beforeGameStart": [
"ciomek.quetzal.Quetzal"
],
"afterGameStart": [
"ciomek.quetzal.Quetzal"
],
"recipesReady": [
"ciomek.quetzal.Quetzal"
]
},
"mixins": [
"quetzal.mixins.json"
],
"depends": {
"fabricloader": ">=${fabricloader}",
"halplibe": ">=${halplibe}",
"minecraft": "*",
"java": ">=${java}"
},
"suggests": {
"modmenu": ">=${modmenu}"
}
}

BIN
src/main/resources/icon.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 59 KiB

View File

@@ -0,0 +1,12 @@
{
"required": true,
"package": "ciomek.quetzal.mixin",
"compatibilityLevel": "JAVA_${java}",
"injectors": {
"defaultRequire": 1
},
"mixins": [
"WorldOverwriteMixin"
],
"client": []
}