diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..fcfb133 --- /dev/null +++ b/.gitignore @@ -0,0 +1,40 @@ +# gradle + +.gradle/ +build/ +out/ +classes/ + +# eclipse + +*.launch + +# idea + +.idea/ +*.iml +*.ipr +*.iws + +# vscode + +.settings/ +.vscode/ +bin/ +.classpath +.project + +# macos + +*.DS_Store + +# fabric + +run/ +remappedSrc/ + +# Ignore Gradle project-specific cache directory +.gradle + +# Ignore Gradle build output directory +build diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..e66a8a9 --- /dev/null +++ b/LICENSE @@ -0,0 +1,19 @@ +Copyright (c) 2021 Evan Steinkerchner (Roundaround). + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..730ed5e --- /dev/null +++ b/README.md @@ -0,0 +1,16 @@ +# Roundaround's Custom Paintings + + + + + +Add your own custom paintings to Minecraft! Custom sizes, unlimited amount, and +an easy GUI for placing and managing your paintings! + +## Download + +https://modrinth.com/mod/roundaround-custom-paintings + +## License + +This mod is available under the MIT license. Please see the LICENSE file for more info. \ No newline at end of file diff --git a/assets/icon.png b/assets/icon.png new file mode 100644 index 0000000..ca95b42 Binary files /dev/null and b/assets/icon.png differ diff --git a/assets/icon.psd b/assets/icon.psd new file mode 100644 index 0000000..4440c77 Binary files /dev/null and b/assets/icon.psd differ diff --git a/assets/painting.png b/assets/painting.png new file mode 100644 index 0000000..c20db4f Binary files /dev/null and b/assets/painting.png differ diff --git a/assets/starrynight.jpg b/assets/starrynight.jpg new file mode 100644 index 0000000..2f0a227 Binary files /dev/null and b/assets/starrynight.jpg differ diff --git a/build.gradle b/build.gradle new file mode 100644 index 0000000..c14af7b --- /dev/null +++ b/build.gradle @@ -0,0 +1,83 @@ +plugins { + id 'fabric-loom' version '0.12-SNAPSHOT' + id 'maven-publish' +} + +sourceCompatibility = JavaVersion.VERSION_17 +targetCompatibility = JavaVersion.VERSION_17 + +archivesBaseName = project.archives_base_name +version = project.mod_version +group = project.maven_group + +repositories { + maven { + name = "ModMenu" + url = "https://maven.terraformersmc.com/releases/" + } + maven { + name = 'Roundaround Maven' + url = "https://maven.rnda.dev/releases" + } +} + +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" + modImplementation "net.fabricmc:fabric-loader:${project.loader_version}" + modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}" + + // ModMenu integration + modCompileOnly "com.terraformersmc:modmenu:${project.mod_menu_version}" +} + +processResources { + inputs.property "version", project.version + + filesMatching("fabric.mod.json") { + expand "version": project.version + } +} + +tasks.withType(JavaCompile).configureEach { + it.options.encoding = "UTF-8" + it.options.release = 17 +} + +java { + withSourcesJar() +} + +jar { + from("LICENSE") { + rename { "${it}_${project.archives_base_name}"} + } +} + +tasks.publish.dependsOn build +publishing { + publications { + mavenJava(MavenPublication) { + artifactId project.archives_base_name + version = project.mod_version + "+" + project.minecraft_version + + artifact(remapJar) { + builtBy remapJar + } + } + } + repositories { + maven { + allowInsecureProtocol = true + url = "https://maven.rnda.dev/releases" + credentials { + username = selfHostedMavenUser + password = selfHostedMavenPass + } + authentication { + basic(BasicAuthentication) + } + } + } +} diff --git a/gradle.properties b/gradle.properties new file mode 100644 index 0000000..71eb93b --- /dev/null +++ b/gradle.properties @@ -0,0 +1,16 @@ +# Done to increase the memory available to gradle. +org.gradle.jvmargs=-Xmx1G + +# Fabric Properties +minecraft_version=1.19 +yarn_mappings=1.19+build.4 +loader_version=0.14.9 + +# Mod Properties +mod_version = 1.0.0 +maven_group = me.roundaround +archives_base_name = custompaintings + +# Dependencies +fabric_version=0.58.0+1.19 +mod_menu_version=4.0.0 diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 0000000..7454180 Binary files /dev/null and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 0000000..84d1f85 --- /dev/null +++ b/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,5 @@ +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.1-bin.zip +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists diff --git a/gradlew b/gradlew new file mode 100644 index 0000000..1b6c787 --- /dev/null +++ b/gradlew @@ -0,0 +1,234 @@ +#!/bin/sh + +# +# Copyright © 2015-2021 the original authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +############################################################################## +# +# Gradle start up script for 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/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt +# within the Gradle project. +# +# You can find Gradle at https://github.com/gradle/gradle/. +# +############################################################################## + +# Attempt to set APP_HOME + +# Resolve links: $0 may be a link +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 + +APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit + +APP_NAME="Gradle" +APP_BASE_NAME=${0##*/} + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD=maximum + +warn () { + echo "$*" +} >&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 + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD=$JAVA_HOME/jre/sh/java + else + JAVACMD=$JAVA_HOME/bin/java + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD=java + which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." +fi + +# Increase the maximum file descriptors if we can. +if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then + case $MAX_FD in #( + max*) + MAX_FD=$( ulimit -H -n ) || + warn "Could not query maximum file descriptor limit" + esac + case $MAX_FD in #( + '' | soft) :;; #( + *) + 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" ) + CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) + + 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 + +# Collect all arguments for the java command; +# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of +# shell script including quotes and variable substitutions, so put them in +# double quotes to make sure that they get re-expanded; and +# * put everything else in single quotes, so that it's not re-expanded. + +set -- \ + "-Dorg.gradle.appname=$APP_BASE_NAME" \ + -classpath "$CLASSPATH" \ + org.gradle.wrapper.GradleWrapperMain \ + "$@" + +# Use "xargs" to parse quoted args. +# +# With -n1 it outputs one arg per line, with the quotes and backslashes removed. +# +# In Bash we could simply go: +# +# readarray ARGS < <( xargs -n1 <<<"$var" ) && +# set -- "${ARGS[@]}" "$@" +# +# but POSIX shell has neither arrays nor command substitution, so instead we +# post-process each arg (as a line of input to sed) to backslash-escape any +# character that might be a shell metacharacter, then use eval to reverse +# that process (while maintaining the separation between arguments), and wrap +# the whole thing up as a single "set" statement. +# +# This will of course break if any of these variables contains a newline or +# an unmatched quote. +# + +eval "set -- $( + printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | + xargs -n1 | + sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | + tr '\n' ' ' + )" '"$@"' + +exec "$JAVACMD" "$@" diff --git a/gradlew.bat b/gradlew.bat new file mode 100644 index 0000000..107acd3 --- /dev/null +++ b/gradlew.bat @@ -0,0 +1,89 @@ +@rem +@rem Copyright 2015 the original author or authors. +@rem +@rem Licensed under the Apache License, Version 2.0 (the "License"); +@rem you may not use this file except in compliance with the License. +@rem You may obtain a copy of the License at +@rem +@rem https://www.apache.org/licenses/LICENSE-2.0 +@rem +@rem Unless required by applicable law or agreed to in writing, software +@rem distributed under the License is distributed on an "AS IS" BASIS, +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@rem See the License for the specific language governing permissions and +@rem limitations under the License. +@rem + +@if "%DEBUG%" == "" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +set DIRNAME=%~dp0 +if "%DIRNAME%" == "" set DIRNAME=. +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Resolve any "." and ".." in APP_HOME to make it shorter. +for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if "%ERRORLEVEL%" == "0" goto execute + +echo. +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto execute + +echo. +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* + +:end +@rem End local scope for the variables with windows NT shell +if "%ERRORLEVEL%"=="0" goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 +exit /b 1 + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/settings.gradle b/settings.gradle new file mode 100644 index 0000000..767bc9b --- /dev/null +++ b/settings.gradle @@ -0,0 +1,9 @@ +pluginManagement { + repositories { + maven { + name = 'Fabric' + url = 'https://maven.fabricmc.net/' + } + gradlePluginPortal() + } +} diff --git a/src/main/java/me/roundaround/armorstands/ArmorStandsMod.java b/src/main/java/me/roundaround/armorstands/ArmorStandsMod.java new file mode 100644 index 0000000..886fd5f --- /dev/null +++ b/src/main/java/me/roundaround/armorstands/ArmorStandsMod.java @@ -0,0 +1,17 @@ +package me.roundaround.armorstands; + +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; + +import me.roundaround.armorstands.network.ServerNetworking; +import net.fabricmc.api.ModInitializer; + +public final class ArmorStandsMod implements ModInitializer { + public static final String MOD_ID = "custompaintings"; + public static final Logger LOGGER = LogManager.getLogger(MOD_ID); + + @Override + public void onInitialize() { + ServerNetworking.registerReceivers(); + } +} diff --git a/src/main/java/me/roundaround/armorstands/client/ArmorStandsClientMod.java b/src/main/java/me/roundaround/armorstands/client/ArmorStandsClientMod.java new file mode 100644 index 0000000..1746d9e --- /dev/null +++ b/src/main/java/me/roundaround/armorstands/client/ArmorStandsClientMod.java @@ -0,0 +1,9 @@ +package me.roundaround.armorstands.client; + +import net.fabricmc.api.ClientModInitializer; + +public class ArmorStandsClientMod implements ClientModInitializer { + @Override + public void onInitializeClient() { + } +} diff --git a/src/main/java/me/roundaround/armorstands/client/gui/screen/ArmorStandScreen.java b/src/main/java/me/roundaround/armorstands/client/gui/screen/ArmorStandScreen.java new file mode 100644 index 0000000..b6ddb25 --- /dev/null +++ b/src/main/java/me/roundaround/armorstands/client/gui/screen/ArmorStandScreen.java @@ -0,0 +1,60 @@ +package me.roundaround.armorstands.client.gui.screen; + +import me.roundaround.armorstands.client.network.ClientNetworking; +import me.roundaround.armorstands.network.ArmorStandFlag; +import net.minecraft.client.gui.screen.Screen; +import net.minecraft.client.gui.widget.ButtonWidget; +import net.minecraft.client.util.math.MatrixStack; +import net.minecraft.entity.decoration.ArmorStandEntity; +import net.minecraft.text.Text; + +public class ArmorStandScreen extends Screen { + private ArmorStandEntity armorStand; + + public ArmorStandScreen(ArmorStandEntity armorStand) { + super(Text.translatable("")); + this.armorStand = armorStand; + passEvents = true; + } + + @Override + public boolean shouldPause() { + return false; + } + + @Override + protected void init() { + addDrawableChild(new ButtonWidget( + (width - 100) / 2, + (height - 20) / 2 + 20, + 100, + 20, + Text.literal("Rotate 45 deg"), + (button) -> { + ClientNetworking.sendAdjustYawPacket(armorStand, 45); + })); + + addDrawableChild(new ButtonWidget( + (width - 100) / 2, + (height - 20) / 2 + 44, + 100, + 20, + Text.literal("Toggle base plate"), + (button) -> { + ClientNetworking.sendToggleFlagPacket(armorStand, ArmorStandFlag.BASE); + })); + } + + @Override + public void render(MatrixStack matrixStack, int mouseX, int mouseY, float delta) { + drawCenteredText( + matrixStack, + textRenderer, + Text.literal("Test"), + width / 2, + height / 2, + 0xFFFFFFFF); + + super.render(matrixStack, mouseX, mouseY, delta); + } +} diff --git a/src/main/java/me/roundaround/armorstands/client/hooks/ClientHooks.java b/src/main/java/me/roundaround/armorstands/client/hooks/ClientHooks.java new file mode 100644 index 0000000..c480917 --- /dev/null +++ b/src/main/java/me/roundaround/armorstands/client/hooks/ClientHooks.java @@ -0,0 +1,15 @@ +package me.roundaround.armorstands.client.hooks; + +import me.roundaround.armorstands.client.gui.screen.ArmorStandScreen; +import net.minecraft.client.MinecraftClient; +import net.minecraft.entity.decoration.ArmorStandEntity; + +/* + * Used to separate client-only code for mixed-purpose classes like Mixins. + */ +public class ClientHooks { + public static void openArmorStandScreen(ArmorStandEntity armorStand) { + MinecraftClient client = MinecraftClient.getInstance(); + client.setScreen(new ArmorStandScreen(armorStand)); + } +} diff --git a/src/main/java/me/roundaround/armorstands/client/network/ClientNetworking.java b/src/main/java/me/roundaround/armorstands/client/network/ClientNetworking.java new file mode 100644 index 0000000..faaf95b --- /dev/null +++ b/src/main/java/me/roundaround/armorstands/client/network/ClientNetworking.java @@ -0,0 +1,26 @@ +package me.roundaround.armorstands.client.network; + +import io.netty.buffer.Unpooled; +import me.roundaround.armorstands.network.ArmorStandFlag; +import me.roundaround.armorstands.network.NetworkPackets; +import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking; +import net.minecraft.entity.decoration.ArmorStandEntity; +import net.minecraft.network.PacketByteBuf; + +public class ClientNetworking { + public static void sendAdjustYawPacket(ArmorStandEntity armorStand, int amount) { + PacketByteBuf buf = new PacketByteBuf(Unpooled.buffer()); + buf.writeUuid(armorStand.getUuid()); + buf.writeInt(amount); + + ClientPlayNetworking.send(NetworkPackets.ADJUST_YAW_PACKET, buf); + } + + public static void sendToggleFlagPacket(ArmorStandEntity armorStand, ArmorStandFlag flag) { + PacketByteBuf buf = new PacketByteBuf(Unpooled.buffer()); + buf.writeUuid(armorStand.getUuid()); + buf.writeString(flag.toString()); + + ClientPlayNetworking.send(NetworkPackets.TOGGLE_FLAG_PACKET, buf); + } +} diff --git a/src/main/java/me/roundaround/armorstands/mixin/ArmorStandEntityAccessor.java b/src/main/java/me/roundaround/armorstands/mixin/ArmorStandEntityAccessor.java new file mode 100644 index 0000000..874f58a --- /dev/null +++ b/src/main/java/me/roundaround/armorstands/mixin/ArmorStandEntityAccessor.java @@ -0,0 +1,22 @@ +package me.roundaround.armorstands.mixin; + +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.gen.Accessor; +import org.spongepowered.asm.mixin.gen.Invoker; + +import net.minecraft.entity.decoration.ArmorStandEntity; + +@Mixin(ArmorStandEntity.class) +public interface ArmorStandEntityAccessor { + @Invoker("setSmall") + public void invokeSetSmall(boolean small); + + @Invoker("setShowArms") + public void invokeSetShowArms(boolean showArms); + + @Invoker("setHideBasePlate") + public void invokeSetHideBasePlate(boolean hideBasePlate); + + @Accessor("disabledSlots") + public void setDisabledSlots(int disabledSlots); +} diff --git a/src/main/java/me/roundaround/armorstands/mixin/ArmorStandEntityMixin.java b/src/main/java/me/roundaround/armorstands/mixin/ArmorStandEntityMixin.java new file mode 100644 index 0000000..74cd334 --- /dev/null +++ b/src/main/java/me/roundaround/armorstands/mixin/ArmorStandEntityMixin.java @@ -0,0 +1,23 @@ +package me.roundaround.armorstands.mixin; + +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; + +import me.roundaround.armorstands.client.hooks.ClientHooks; +import net.minecraft.entity.decoration.ArmorStandEntity; +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.util.ActionResult; +import net.minecraft.util.Hand; +import net.minecraft.util.math.Vec3d; + +@Mixin(ArmorStandEntity.class) +public abstract class ArmorStandEntityMixin { + @Inject(method = "interactAt", at = @At(value = "HEAD")) + public void interactAt(PlayerEntity player, Vec3d hitPos, Hand hand, CallbackInfoReturnable info) { + if (player.world.isClient) { + ClientHooks.openArmorStandScreen((ArmorStandEntity) (Object) this); + } + } +} diff --git a/src/main/java/me/roundaround/armorstands/network/ArmorStandFlag.java b/src/main/java/me/roundaround/armorstands/network/ArmorStandFlag.java new file mode 100644 index 0000000..9623ed5 --- /dev/null +++ b/src/main/java/me/roundaround/armorstands/network/ArmorStandFlag.java @@ -0,0 +1,30 @@ +package me.roundaround.armorstands.network; + +import java.util.Arrays; +import java.util.Optional; + +public enum ArmorStandFlag { + BASE("base"), + ARMS("arms"), + SMALL("small"), + GRAVITY("gravity"), + VISIBLE("visible"), + NAME("name"); + + private final String value; + + private ArmorStandFlag(String value) { + this.value = value; + } + + @Override + public String toString() { + return value; + } + + public static Optional fromString(String value) { + return Arrays.stream(ArmorStandFlag.values()) + .filter((flag) -> flag.value.equals(value)) + .findFirst(); + } +} diff --git a/src/main/java/me/roundaround/armorstands/network/NetworkPackets.java b/src/main/java/me/roundaround/armorstands/network/NetworkPackets.java new file mode 100644 index 0000000..878510e --- /dev/null +++ b/src/main/java/me/roundaround/armorstands/network/NetworkPackets.java @@ -0,0 +1,14 @@ +package me.roundaround.armorstands.network; + +import me.roundaround.armorstands.ArmorStandsMod; +import net.minecraft.util.Identifier; + +public class NetworkPackets { + public static final Identifier ADJUST_YAW_PACKET = new Identifier( + ArmorStandsMod.MOD_ID, + "adjust_yaw_packet"); + + public static final Identifier TOGGLE_FLAG_PACKET = new Identifier( + ArmorStandsMod.MOD_ID, + "toggle_flag"); +} diff --git a/src/main/java/me/roundaround/armorstands/network/ServerNetworking.java b/src/main/java/me/roundaround/armorstands/network/ServerNetworking.java new file mode 100644 index 0000000..e664711 --- /dev/null +++ b/src/main/java/me/roundaround/armorstands/network/ServerNetworking.java @@ -0,0 +1,85 @@ +package me.roundaround.armorstands.network; + +import java.util.UUID; + +import me.roundaround.armorstands.mixin.ArmorStandEntityAccessor; +import net.fabricmc.fabric.api.networking.v1.PacketSender; +import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking; +import net.minecraft.entity.Entity; +import net.minecraft.entity.decoration.ArmorStandEntity; +import net.minecraft.network.PacketByteBuf; +import net.minecraft.server.MinecraftServer; +import net.minecraft.server.network.ServerPlayNetworkHandler; +import net.minecraft.server.network.ServerPlayerEntity; + +public class ServerNetworking { + public static void registerReceivers() { + ServerPlayNetworking.registerGlobalReceiver( + NetworkPackets.ADJUST_YAW_PACKET, + ServerNetworking::handleAdjustYawPacket); + ServerPlayNetworking.registerGlobalReceiver( + NetworkPackets.TOGGLE_FLAG_PACKET, + ServerNetworking::handleToggleFlagPacket); + } + + public static void handleAdjustYawPacket( + MinecraftServer server, + ServerPlayerEntity player, + ServerPlayNetworkHandler handler, + PacketByteBuf buf, + PacketSender responseSender) { + UUID armorStandUuid = buf.readUuid(); + int amount = buf.readInt(); + + Entity entity = player.getWorld().getEntity(armorStandUuid); + + if (entity == null || !(entity instanceof ArmorStandEntity)) { + return; + } + + float currentYaw = entity.getYaw(); + entity.setYaw((currentYaw + amount) % 360f); + } + + public static void handleToggleFlagPacket( + MinecraftServer server, + ServerPlayerEntity player, + ServerPlayNetworkHandler handler, + PacketByteBuf buf, + PacketSender responseSender) { + // TODO: Handle error case for non-existant flag values. + + UUID armorStandUuid = buf.readUuid(); + ArmorStandFlag flag = ArmorStandFlag.fromString(buf.readString()).get(); + + Entity entity = player.getWorld().getEntity(armorStandUuid); + + if (entity == null || !(entity instanceof ArmorStandEntity)) { + return; + } + + ArmorStandEntity armorStand = (ArmorStandEntity) entity; + ArmorStandEntityAccessor accessor = (ArmorStandEntityAccessor) entity; + + switch (flag) { + case BASE: + accessor.invokeSetHideBasePlate(!armorStand.shouldHideBasePlate()); + break; + case ARMS: + accessor.invokeSetShowArms(!armorStand.shouldShowArms()); + break; + case SMALL: + accessor.invokeSetSmall(!armorStand.isSmall()); + break; + case GRAVITY: + armorStand.setNoGravity(!armorStand.hasNoGravity()); + break; + case VISIBLE: + armorStand.setInvisible(!armorStand.isInvisible()); + break; + case NAME: + armorStand.setCustomNameVisible(!armorStand.isCustomNameVisible()); + break; + } + } +} diff --git a/src/main/resources/armorstands.mixins.json b/src/main/resources/armorstands.mixins.json new file mode 100644 index 0000000..09b90bf --- /dev/null +++ b/src/main/resources/armorstands.mixins.json @@ -0,0 +1,15 @@ +{ + "required": true, + "minVersion": "0.8", + "package": "me.roundaround.armorstands.mixin", + "compatibilityLevel": "JAVA_17", + "mixins": [ + "ArmorStandEntityAccessor", + "ArmorStandEntityMixin" + ], + "client": [], + "server": [], + "injectors": { + "defaultRequire": 1 + } +} \ No newline at end of file diff --git a/src/main/resources/assets/armorstands/icon.png b/src/main/resources/assets/armorstands/icon.png new file mode 100644 index 0000000..ca95b42 Binary files /dev/null and b/src/main/resources/assets/armorstands/icon.png differ diff --git a/src/main/resources/assets/armorstands/lang/en_us.json b/src/main/resources/assets/armorstands/lang/en_us.json new file mode 100644 index 0000000..7a73a41 --- /dev/null +++ b/src/main/resources/assets/armorstands/lang/en_us.json @@ -0,0 +1,2 @@ +{ +} \ No newline at end of file diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json new file mode 100644 index 0000000..b4f9a4b --- /dev/null +++ b/src/main/resources/fabric.mod.json @@ -0,0 +1,35 @@ +{ + "schemaVersion": 1, + "id": "armorstands", + "version": "${version}", + "name": "Armor Stands", + "description": "Place, pose, and dress armor stands with an easy-to-use UI.", + "authors": [ + "Roundaround" + ], + "contact": { + "homepage": "https://modrinth.com/mod/roundaround-armor-stands", + "sources": "https://github.com/Roundaround/mc-fabric-armor-stands", + "issues": "https://github.com/Roundaround/mc-fabric-armor-stands/issues" + }, + "license": "MIT", + "icon": "assets/armorstands/icon.png", + "environment": "*", + "entrypoints": { + "client": [ + "me.roundaround.armorstands.client.ArmorStandsClientMod" + ], + "main": [ + "me.roundaround.armorstands.ArmorStandsMod" + ] + }, + "mixins": [ + "armorstands.mixins.json" + ], + "depends": { + "fabricloader": ">=0.13.3", + "fabric": "*", + "minecraft": "1.19.x", + "java": ">=17" + } +}