MidnightLib v0.1.0 for 21w08b
25
.gitignore
vendored
Normal file
@@ -0,0 +1,25 @@
|
||||
# gradle
|
||||
|
||||
.gradle/
|
||||
out/
|
||||
classes/
|
||||
build/
|
||||
|
||||
# idea
|
||||
|
||||
.idea/
|
||||
*.iml
|
||||
*.ipr
|
||||
*.iws
|
||||
|
||||
# vscode
|
||||
|
||||
.settings/
|
||||
.vscode/
|
||||
bin/
|
||||
.classpath
|
||||
.project
|
||||
|
||||
# fabric
|
||||
|
||||
run/
|
||||
21
LICENSE
Normal file
@@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2020 MidnightDust
|
||||
|
||||
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.
|
||||
@@ -1,2 +1,3 @@
|
||||
# MidnightLib
|
||||
Common Library for Team MidnightDust's mods. Provides a config api, common utils, and cosmetics.
|
||||
Common Library for Team MidnightDust's mods.
|
||||
Provides a config api, common utils, and cosmetics.
|
||||
|
||||
83
build.gradle
Normal file
@@ -0,0 +1,83 @@
|
||||
plugins {
|
||||
id 'fabric-loom' version '0.6-SNAPSHOT'
|
||||
id 'maven-publish'
|
||||
}
|
||||
|
||||
sourceCompatibility = JavaVersion.VERSION_1_8
|
||||
targetCompatibility = JavaVersion.VERSION_1_8
|
||||
|
||||
archivesBaseName = project.archives_base_name
|
||||
version = project.mod_version
|
||||
group = project.maven_group
|
||||
|
||||
minecraft {
|
||||
}
|
||||
|
||||
repositories {
|
||||
maven { url "https://maven.shedaniel.me/" }
|
||||
maven { url "https://jitpack.io" }
|
||||
}
|
||||
|
||||
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"
|
||||
modCompile "net.fabricmc:fabric-loader:${project.loader_version}"
|
||||
|
||||
modCompile "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}"
|
||||
|
||||
modImplementation ("io.github.prospector:modmenu:${project.mod_menu_version}")
|
||||
}
|
||||
|
||||
processResources {
|
||||
inputs.property "version", project.version
|
||||
|
||||
from(sourceSets.main.resources.srcDirs) {
|
||||
include "fabric.mod.json"
|
||||
expand "version": project.version
|
||||
}
|
||||
|
||||
from(sourceSets.main.resources.srcDirs) {
|
||||
exclude "fabric.mod.json"
|
||||
}
|
||||
}
|
||||
|
||||
// ensure that the encoding is set to UTF-8, no matter what the system default is
|
||||
// this fixes some edge cases with special characters not displaying correctly
|
||||
// see http://yodaconditions.net/blog/fix-for-java-file-encoding-problems-with-gradle.html
|
||||
tasks.withType(JavaCompile) {
|
||||
options.encoding = "UTF-8"
|
||||
}
|
||||
|
||||
// Loom will automatically attach sourcesJar to a RemapSourcesJar task and to the "build" task
|
||||
// if it is present.
|
||||
// If you remove this task, sources will not be generated.
|
||||
task sourcesJar(type: Jar, dependsOn: classes) {
|
||||
classifier = "sources"
|
||||
from sourceSets.main.allSource
|
||||
}
|
||||
|
||||
jar {
|
||||
from "LICENSE"
|
||||
}
|
||||
|
||||
// configure the maven publication
|
||||
publishing {
|
||||
publications {
|
||||
mavenJava(MavenPublication) {
|
||||
// add all the jars that should be included when publishing to maven
|
||||
artifact(remapJar) {
|
||||
builtBy remapJar
|
||||
}
|
||||
artifact(sourcesJar) {
|
||||
builtBy remapSourcesJar
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// select the repositories you want to publish to
|
||||
repositories {
|
||||
// uncomment to publish to the local maven
|
||||
// mavenLocal()
|
||||
}
|
||||
}
|
||||
18
gradle.properties
Normal file
@@ -0,0 +1,18 @@
|
||||
# Done to increase the memory available to gradle.
|
||||
org.gradle.jvmargs=-Xmx1G
|
||||
|
||||
# Fabric Properties
|
||||
# check these on https://fabricmc.net/use
|
||||
minecraft_version=21w08b
|
||||
yarn_mappings=21w08b+build.5
|
||||
loader_version=0.11.2
|
||||
|
||||
# Mod Properties
|
||||
mod_version = 0.1.0
|
||||
maven_group = eu.midnightdust
|
||||
archives_base_name = midnightlib
|
||||
|
||||
# Dependencies
|
||||
# currently not on the main fabric site, check on the maven: https://maven.fabricmc.net/net/fabricmc/fabric-api/fabric-api
|
||||
fabric_version=0.31.1+1.17
|
||||
mod_menu_version = 2.0.0-beta.1+build.2
|
||||
BIN
gradle/wrapper/gradle-wrapper.jar
vendored
Normal file
5
gradle/wrapper/gradle-wrapper.properties
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-5.5.1-bin.zip
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
zipStorePath=wrapper/dists
|
||||
188
gradlew
vendored
Normal file
@@ -0,0 +1,188 @@
|
||||
#!/usr/bin/env sh
|
||||
|
||||
#
|
||||
# Copyright 2015 the original author or 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 UN*X
|
||||
##
|
||||
##############################################################################
|
||||
|
||||
# Attempt to set APP_HOME
|
||||
# Resolve links: $0 may be a link
|
||||
PRG="$0"
|
||||
# Need this for relative symlinks.
|
||||
while [ -h "$PRG" ] ; do
|
||||
ls=`ls -ld "$PRG"`
|
||||
link=`expr "$ls" : '.*-> \(.*\)$'`
|
||||
if expr "$link" : '/.*' > /dev/null; then
|
||||
PRG="$link"
|
||||
else
|
||||
PRG=`dirname "$PRG"`"/$link"
|
||||
fi
|
||||
done
|
||||
SAVED="`pwd`"
|
||||
cd "`dirname \"$PRG\"`/" >/dev/null
|
||||
APP_HOME="`pwd -P`"
|
||||
cd "$SAVED" >/dev/null
|
||||
|
||||
APP_NAME="Gradle"
|
||||
APP_BASE_NAME=`basename "$0"`
|
||||
|
||||
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
|
||||
|
||||
# Use the maximum available, or set MAX_FD != -1 to use that value.
|
||||
MAX_FD="maximum"
|
||||
|
||||
warn () {
|
||||
echo "$*"
|
||||
}
|
||||
|
||||
die () {
|
||||
echo
|
||||
echo "$*"
|
||||
echo
|
||||
exit 1
|
||||
}
|
||||
|
||||
# OS specific support (must be 'true' or 'false').
|
||||
cygwin=false
|
||||
msys=false
|
||||
darwin=false
|
||||
nonstop=false
|
||||
case "`uname`" in
|
||||
CYGWIN* )
|
||||
cygwin=true
|
||||
;;
|
||||
Darwin* )
|
||||
darwin=true
|
||||
;;
|
||||
MINGW* )
|
||||
msys=true
|
||||
;;
|
||||
NONSTOP* )
|
||||
nonstop=true
|
||||
;;
|
||||
esac
|
||||
|
||||
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
|
||||
|
||||
# Determine the Java command to use to start the JVM.
|
||||
if [ -n "$JAVA_HOME" ] ; then
|
||||
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
|
||||
# IBM's JDK on AIX uses strange locations for the executables
|
||||
JAVACMD="$JAVA_HOME/jre/sh/java"
|
||||
else
|
||||
JAVACMD="$JAVA_HOME/bin/java"
|
||||
fi
|
||||
if [ ! -x "$JAVACMD" ] ; then
|
||||
die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
|
||||
|
||||
Please set the JAVA_HOME variable in your environment to match the
|
||||
location of your Java installation."
|
||||
fi
|
||||
else
|
||||
JAVACMD="java"
|
||||
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
||||
|
||||
Please set the JAVA_HOME variable in your environment to match the
|
||||
location of your Java installation."
|
||||
fi
|
||||
|
||||
# Increase the maximum file descriptors if we can.
|
||||
if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
|
||||
MAX_FD_LIMIT=`ulimit -H -n`
|
||||
if [ $? -eq 0 ] ; then
|
||||
if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
|
||||
MAX_FD="$MAX_FD_LIMIT"
|
||||
fi
|
||||
ulimit -n $MAX_FD
|
||||
if [ $? -ne 0 ] ; then
|
||||
warn "Could not set maximum file descriptor limit: $MAX_FD"
|
||||
fi
|
||||
else
|
||||
warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
|
||||
fi
|
||||
fi
|
||||
|
||||
# For Darwin, add options to specify how the application appears in the dock
|
||||
if $darwin; then
|
||||
GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
|
||||
fi
|
||||
|
||||
# For Cygwin, switch paths to Windows format before running java
|
||||
if $cygwin ; then
|
||||
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
|
||||
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
|
||||
JAVACMD=`cygpath --unix "$JAVACMD"`
|
||||
|
||||
# We build the pattern for arguments to be converted via cygpath
|
||||
ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
|
||||
SEP=""
|
||||
for dir in $ROOTDIRSRAW ; do
|
||||
ROOTDIRS="$ROOTDIRS$SEP$dir"
|
||||
SEP="|"
|
||||
done
|
||||
OURCYGPATTERN="(^($ROOTDIRS))"
|
||||
# Add a user-defined pattern to the cygpath arguments
|
||||
if [ "$GRADLE_CYGPATTERN" != "" ] ; then
|
||||
OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
|
||||
fi
|
||||
# Now convert the arguments - kludge to limit ourselves to /bin/sh
|
||||
i=0
|
||||
for arg in "$@" ; do
|
||||
CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
|
||||
CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
|
||||
|
||||
if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
|
||||
eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
|
||||
else
|
||||
eval `echo args$i`="\"$arg\""
|
||||
fi
|
||||
i=$((i+1))
|
||||
done
|
||||
case $i in
|
||||
(0) set -- ;;
|
||||
(1) set -- "$args0" ;;
|
||||
(2) set -- "$args0" "$args1" ;;
|
||||
(3) set -- "$args0" "$args1" "$args2" ;;
|
||||
(4) set -- "$args0" "$args1" "$args2" "$args3" ;;
|
||||
(5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
|
||||
(6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
|
||||
(7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
|
||||
(8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
|
||||
(9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
|
||||
esac
|
||||
fi
|
||||
|
||||
# Escape application args
|
||||
save () {
|
||||
for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
|
||||
echo " "
|
||||
}
|
||||
APP_ARGS=$(save "$@")
|
||||
|
||||
# Collect all arguments for the java command, following the shell quoting and substitution rules
|
||||
eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
|
||||
|
||||
# by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
|
||||
if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
|
||||
cd "$(dirname "$0")"
|
||||
fi
|
||||
|
||||
exec "$JAVACMD" "$@"
|
||||
100
gradlew.bat
vendored
Normal file
@@ -0,0 +1,100 @@
|
||||
@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 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 init
|
||||
|
||||
echo.
|
||||
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
||||
echo.
|
||||
echo Please set the JAVA_HOME variable in your environment to match the
|
||||
echo location of your Java installation.
|
||||
|
||||
goto fail
|
||||
|
||||
:findJavaFromJavaHome
|
||||
set JAVA_HOME=%JAVA_HOME:"=%
|
||||
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
|
||||
|
||||
if exist "%JAVA_EXE%" goto init
|
||||
|
||||
echo.
|
||||
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
|
||||
echo.
|
||||
echo Please set the JAVA_HOME variable in your environment to match the
|
||||
echo location of your Java installation.
|
||||
|
||||
goto fail
|
||||
|
||||
:init
|
||||
@rem Get command-line arguments, handling Windows variants
|
||||
|
||||
if not "%OS%" == "Windows_NT" goto win9xME_args
|
||||
|
||||
:win9xME_args
|
||||
@rem Slurp the command line arguments.
|
||||
set CMD_LINE_ARGS=
|
||||
set _SKIP=2
|
||||
|
||||
:win9xME_args_slurp
|
||||
if "x%~1" == "x" goto execute
|
||||
|
||||
set CMD_LINE_ARGS=%*
|
||||
|
||||
:execute
|
||||
@rem Setup the command line
|
||||
|
||||
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
|
||||
|
||||
@rem Execute Gradle
|
||||
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
|
||||
|
||||
:end
|
||||
@rem End local scope for the variables with windows NT shell
|
||||
if "%ERRORLEVEL%"=="0" goto mainEnd
|
||||
|
||||
:fail
|
||||
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
|
||||
rem the _cmd.exe /c_ return code!
|
||||
if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
|
||||
exit /b 1
|
||||
|
||||
:mainEnd
|
||||
if "%OS%"=="Windows_NT" endlocal
|
||||
|
||||
:omega
|
||||
0
logs/latest.log
Normal file
10
settings.gradle
Normal file
@@ -0,0 +1,10 @@
|
||||
pluginManagement {
|
||||
repositories {
|
||||
jcenter()
|
||||
maven {
|
||||
name = 'Fabric'
|
||||
url = 'https://maven.fabricmc.net/'
|
||||
}
|
||||
gradlePluginPortal()
|
||||
}
|
||||
}
|
||||
29
src/main/java/eu/midnightdust/hats/HatsClient.java
Normal file
@@ -0,0 +1,29 @@
|
||||
package eu.midnightdust.hats;
|
||||
|
||||
import eu.midnightdust.hats.bunny.BunnyEarsFeatureRenderer;
|
||||
import eu.midnightdust.hats.christmas.ChristmasHatFeatureRenderer;
|
||||
import eu.midnightdust.hats.config.HatsConfig;
|
||||
import eu.midnightdust.hats.tater.TinyPotatoFeatureRenderer;
|
||||
import eu.midnightdust.hats.web.HatLoader;
|
||||
import eu.midnightdust.hats.witch.WitchHatFeatureRenderer;
|
||||
import net.fabricmc.api.ClientModInitializer;
|
||||
import net.fabricmc.fabric.api.client.rendereregistry.v1.EntityModelLayerRegistry;
|
||||
|
||||
@SuppressWarnings({"deprecation", "UnstableApiUsage"})
|
||||
public class HatsClient implements ClientModInitializer {
|
||||
|
||||
public static final String MOD_ID = "midnightlib";
|
||||
|
||||
@Override
|
||||
public void onInitializeClient() {
|
||||
HatsConfig.init("midnightlib", HatsConfig.class);
|
||||
|
||||
EntityModelLayerRegistry.registerModelLayer(BunnyEarsFeatureRenderer.RABBIT_EARS_MODEL_LAYER, BunnyEarsFeatureRenderer::getTexturedModelData);
|
||||
EntityModelLayerRegistry.registerModelLayer(ChristmasHatFeatureRenderer.CHRISTMAS_HAT_MODEL_LAYER, ChristmasHatFeatureRenderer::getTexturedModelData);
|
||||
EntityModelLayerRegistry.registerModelLayer(TinyPotatoFeatureRenderer.TINY_POTATO_MODEL_LAYER, TinyPotatoFeatureRenderer::getTexturedModelData);
|
||||
EntityModelLayerRegistry.registerModelLayer(WitchHatFeatureRenderer.WITCH_HAT_MODEL_LAYER, WitchHatFeatureRenderer::getTexturedModelData);
|
||||
if (HatsConfig.special_hats) {
|
||||
HatLoader.init();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
package eu.midnightdust.hats.bunny;
|
||||
|
||||
import eu.midnightdust.hats.HatsClient;
|
||||
import eu.midnightdust.hats.config.AreEventHatsEnabled;
|
||||
import eu.midnightdust.hats.web.HatLoader;
|
||||
import net.fabricmc.api.EnvType;
|
||||
import net.fabricmc.api.Environment;
|
||||
import net.fabricmc.loader.api.FabricLoader;
|
||||
import net.minecraft.client.model.TexturedModelData;
|
||||
import net.minecraft.client.network.AbstractClientPlayerEntity;
|
||||
import net.minecraft.client.render.OverlayTexture;
|
||||
import net.minecraft.client.render.RenderLayer;
|
||||
import net.minecraft.client.render.VertexConsumer;
|
||||
import net.minecraft.client.render.VertexConsumerProvider;
|
||||
import net.minecraft.client.render.entity.feature.FeatureRenderer;
|
||||
import net.minecraft.client.render.entity.feature.FeatureRendererContext;
|
||||
import net.minecraft.client.render.entity.model.*;
|
||||
import net.minecraft.client.render.item.ItemRenderer;
|
||||
import net.minecraft.client.util.math.MatrixStack;
|
||||
import net.minecraft.entity.LivingEntity;
|
||||
import net.minecraft.util.Identifier;
|
||||
|
||||
import java.util.Calendar;
|
||||
import java.util.UUID;
|
||||
|
||||
@Environment(EnvType.CLIENT)
|
||||
public class BunnyEarsFeatureRenderer<T extends LivingEntity, M extends EntityModel<T>> extends FeatureRenderer<T, M> {
|
||||
private static final String MOD_ID = HatsClient.MOD_ID;
|
||||
public static final EntityModelLayer RABBIT_EARS_MODEL_LAYER = new EntityModelLayer(new Identifier("midnight-hats","bunny_ears"), "main");
|
||||
private static final UUID MOTSCHEN = UUID.fromString("a44c2660-630f-478f-946a-e518669fcf0c");
|
||||
|
||||
private static final Identifier DEACTIVATED = new Identifier(MOD_ID,"textures/hats/empty.png");
|
||||
private static final Identifier RABBIT = new Identifier("textures/entity/rabbit/brown.png");
|
||||
private final BunnyEarsModel<T> bunnyEars;
|
||||
|
||||
public BunnyEarsFeatureRenderer(FeatureRendererContext<T, M> featureRendererContext, EntityModelLoader entityModelLoader) {
|
||||
super(featureRendererContext);
|
||||
this.bunnyEars = new BunnyEarsModel(entityModelLoader.getModelPart(RABBIT_EARS_MODEL_LAYER));
|
||||
}
|
||||
|
||||
public static TexturedModelData getTexturedModelData() {
|
||||
return TexturedModelData.of(BunnyEarsModel.getModelData(), 64, 32);
|
||||
}
|
||||
|
||||
public void render(MatrixStack matrixStack, VertexConsumerProvider vertexConsumerProvider, int i, T livingEntity, float f, float g, float h, float j, float k, float l) {
|
||||
{
|
||||
AbstractClientPlayerEntity abstractClientPlayerEntity = (AbstractClientPlayerEntity)livingEntity;
|
||||
Identifier hat_type;
|
||||
if (livingEntity != null) {
|
||||
|
||||
if (Calendar.getInstance().get(Calendar.MONTH) == Calendar.APRIL && Calendar.getInstance().get(Calendar.DAY_OF_MONTH) <= 4) {
|
||||
if (FabricLoader.getInstance().isModLoaded("cloth-config2")) {
|
||||
if (AreEventHatsEnabled.areEventHatsEnabled()) {
|
||||
hat_type = RABBIT;
|
||||
}
|
||||
else hat_type = DEACTIVATED;
|
||||
}
|
||||
else hat_type = RABBIT;
|
||||
}else {
|
||||
hat_type = DEACTIVATED;
|
||||
}
|
||||
} else {
|
||||
hat_type = DEACTIVATED;
|
||||
}
|
||||
|
||||
if (!(hat_type == DEACTIVATED) && !HatLoader.PLAYER_HATS.containsKey(abstractClientPlayerEntity.getUuid()) && !abstractClientPlayerEntity.getUuid().equals(MOTSCHEN)) {
|
||||
matrixStack.push();
|
||||
|
||||
((ModelWithHead) this.getContextModel()).getHead().rotate(matrixStack);
|
||||
VertexConsumer vertexConsumer = ItemRenderer.getArmorGlintConsumer(vertexConsumerProvider, RenderLayer.getEntityCutoutNoCull(hat_type), false, false);
|
||||
this.bunnyEars.render(matrixStack, vertexConsumer, i, OverlayTexture.DEFAULT_UV, 1.0F, 1.0F, 1.0F, 1.0F);
|
||||
|
||||
matrixStack.pop();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
44
src/main/java/eu/midnightdust/hats/bunny/BunnyEarsModel.java
Normal file
@@ -0,0 +1,44 @@
|
||||
package eu.midnightdust.hats.bunny;
|
||||
|
||||
import net.minecraft.client.model.*;
|
||||
import net.minecraft.client.render.VertexConsumer;
|
||||
import net.minecraft.client.render.entity.model.SinglePartEntityModel;
|
||||
import net.minecraft.client.util.math.MatrixStack;
|
||||
import net.minecraft.entity.LivingEntity;
|
||||
|
||||
public class BunnyEarsModel<T extends LivingEntity> extends SinglePartEntityModel<T> {
|
||||
private final ModelPart right_ear;
|
||||
|
||||
public BunnyEarsModel(ModelPart root) {
|
||||
this.right_ear = root;
|
||||
|
||||
right_ear.setPivot(0.0F, -3.0F, -1.0F);
|
||||
|
||||
}
|
||||
public static ModelData getModelData(){
|
||||
ModelData modelData = new ModelData();
|
||||
ModelPartData modelPartData = modelData.getRoot();
|
||||
modelPartData.addChild("right_ear", ModelPartBuilder.create().uv(52, 0).cuboid(-2.5F, -9.0F, -1.0F, 2.0F, 5.0F, 1.0F), ModelTransform.NONE);
|
||||
modelPartData.addChild("left_ear", ModelPartBuilder.create().uv(58, 0).mirrored().cuboid(0.5F, -9.0F, -1.0F, 2.0F, 5.0F, 1.0F), ModelTransform.NONE);
|
||||
return modelData;
|
||||
}
|
||||
|
||||
public ModelPart getPart() {
|
||||
return this.right_ear;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAngles(T entity, float limbAngle, float limbDistance, float animationProgress, float headYaw, float headPitch) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(MatrixStack matrixStack, VertexConsumer buffer, int packedLight, int packedOverlay, float red, float green, float blue, float alpha){
|
||||
right_ear.render(matrixStack, buffer, packedLight, packedOverlay);
|
||||
}
|
||||
|
||||
public void setRotationAngle(ModelPart bone, float x, float y, float z) {
|
||||
bone.pitch = x;
|
||||
bone.yaw = y;
|
||||
bone.roll = z;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
package eu.midnightdust.hats.christmas;
|
||||
|
||||
import eu.midnightdust.hats.HatsClient;
|
||||
import eu.midnightdust.hats.config.AreEventHatsEnabled;
|
||||
import eu.midnightdust.hats.web.HatLoader;
|
||||
import net.fabricmc.api.EnvType;
|
||||
import net.fabricmc.api.Environment;
|
||||
import net.fabricmc.loader.api.FabricLoader;
|
||||
import net.minecraft.client.model.TexturedModelData;
|
||||
import net.minecraft.client.network.AbstractClientPlayerEntity;
|
||||
import net.minecraft.client.render.OverlayTexture;
|
||||
import net.minecraft.client.render.RenderLayer;
|
||||
import net.minecraft.client.render.VertexConsumer;
|
||||
import net.minecraft.client.render.VertexConsumerProvider;
|
||||
import net.minecraft.client.render.entity.feature.FeatureRenderer;
|
||||
import net.minecraft.client.render.entity.feature.FeatureRendererContext;
|
||||
import net.minecraft.client.render.entity.model.EntityModel;
|
||||
import net.minecraft.client.render.entity.model.EntityModelLayer;
|
||||
import net.minecraft.client.render.entity.model.EntityModelLoader;
|
||||
import net.minecraft.client.render.entity.model.ModelWithHead;
|
||||
import net.minecraft.client.render.item.ItemRenderer;
|
||||
import net.minecraft.client.util.math.MatrixStack;
|
||||
import net.minecraft.entity.LivingEntity;
|
||||
import net.minecraft.util.Identifier;
|
||||
|
||||
import java.util.Calendar;
|
||||
import java.util.UUID;
|
||||
|
||||
@Environment(EnvType.CLIENT)
|
||||
public class ChristmasHatFeatureRenderer<T extends LivingEntity, M extends EntityModel<T>> extends FeatureRenderer<T, M> {
|
||||
private static final String MOD_ID = HatsClient.MOD_ID;
|
||||
public static final EntityModelLayer CHRISTMAS_HAT_MODEL_LAYER = new EntityModelLayer(new Identifier("midnight-hats","christmas_hat"), "main");
|
||||
private static final UUID MOTSCHEN = UUID.fromString("a44c2660-630f-478f-946a-e518669fcf0c");
|
||||
|
||||
private static final Identifier DEACTIVATED = new Identifier(MOD_ID,"textures/hats/empty.png");
|
||||
private static final Identifier CHRISTMAS = new Identifier(MOD_ID,"textures/hats/christmas.png");
|
||||
private final ChristmasHatModel<T> christmasHat;
|
||||
|
||||
public ChristmasHatFeatureRenderer(FeatureRendererContext<T, M> featureRendererContext, EntityModelLoader entityModelLoader) {
|
||||
super(featureRendererContext);
|
||||
this.christmasHat = new ChristmasHatModel(entityModelLoader.getModelPart(CHRISTMAS_HAT_MODEL_LAYER));
|
||||
}
|
||||
|
||||
public static TexturedModelData getTexturedModelData() {
|
||||
return TexturedModelData.of(ChristmasHatModel.getModelData(), 64, 64);
|
||||
}
|
||||
|
||||
public void render(MatrixStack matrixStack, VertexConsumerProvider vertexConsumerProvider, int i, T livingEntity, float f, float g, float h, float j, float k, float l) {
|
||||
{
|
||||
AbstractClientPlayerEntity abstractClientPlayerEntity = (AbstractClientPlayerEntity)livingEntity;
|
||||
Identifier hat_type;
|
||||
if (livingEntity != null) {
|
||||
if (Calendar.getInstance().get(Calendar.MONTH) == Calendar.DECEMBER && Calendar.getInstance().get(Calendar.DAY_OF_MONTH) >= 23 && Calendar.getInstance().get(Calendar.DAY_OF_MONTH) <= 26) {
|
||||
if (FabricLoader.getInstance().isModLoaded("cloth-config2")) {
|
||||
if (AreEventHatsEnabled.areEventHatsEnabled()) {
|
||||
hat_type = CHRISTMAS;
|
||||
}
|
||||
else hat_type = DEACTIVATED;
|
||||
}
|
||||
else hat_type = CHRISTMAS;
|
||||
}else {
|
||||
hat_type = DEACTIVATED;
|
||||
}
|
||||
} else {
|
||||
hat_type = DEACTIVATED;
|
||||
}
|
||||
|
||||
if (!(hat_type == DEACTIVATED) && !HatLoader.PLAYER_HATS.containsKey(abstractClientPlayerEntity.getUuid()) && !abstractClientPlayerEntity.getUuid().equals(MOTSCHEN)) {
|
||||
matrixStack.push();
|
||||
|
||||
((ModelWithHead) this.getContextModel()).getHead().rotate(matrixStack);
|
||||
VertexConsumer vertexConsumer = ItemRenderer.getArmorGlintConsumer(vertexConsumerProvider, RenderLayer.getEntityCutoutNoCull(hat_type), false, false);
|
||||
this.christmasHat.render(matrixStack, vertexConsumer, i, OverlayTexture.DEFAULT_UV, 1.0F, 1.0F, 1.0F, 1.0F);
|
||||
|
||||
matrixStack.pop();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
package eu.midnightdust.hats.christmas;
|
||||
|
||||
import net.minecraft.client.model.*;
|
||||
import net.minecraft.client.render.VertexConsumer;
|
||||
import net.minecraft.client.render.entity.model.SinglePartEntityModel;
|
||||
import net.minecraft.client.util.math.MatrixStack;
|
||||
import net.minecraft.entity.LivingEntity;
|
||||
|
||||
public class ChristmasHatModel<T extends LivingEntity> extends SinglePartEntityModel<T> {
|
||||
private final ModelPart headwear;
|
||||
private final ModelPart bone;
|
||||
private final ModelPart bone2;
|
||||
private final ModelPart bone3;
|
||||
|
||||
public ChristmasHatModel(ModelPart root) {
|
||||
headwear = root;
|
||||
root.setPivot(5.0F, -9.0F, -5.0F);
|
||||
|
||||
bone = headwear.getChild("bone");
|
||||
bone.setPivot(-8.5F, -0.1F, 1.5F);
|
||||
setRotationAngle(bone, -0.0524F, 0.0F, 0.0349F);
|
||||
|
||||
bone2 = bone.getChild("bone2");
|
||||
bone2.setPivot(1.5F, -4.0F, 1.5F);
|
||||
setRotationAngle(bone2, -0.1222F, 0.0F, 0.0698F);
|
||||
|
||||
bone3 = bone2.getChild("bone3");
|
||||
bone3.setPivot(1.5F, -4.0F, 1.5F);
|
||||
setRotationAngle(bone3, -0.2618F, 0.0F, 0.1047F);
|
||||
}
|
||||
public static ModelData getModelData(){
|
||||
ModelData modelData = new ModelData();
|
||||
ModelPartData modelPartData = modelData.getRoot();
|
||||
modelPartData.addChild("headwear", ModelPartBuilder.create().uv(0, 0).cuboid(-10.0F, -0.1F, 0.0F, 10.0F, 2.0F, 10.0F), ModelTransform.NONE);
|
||||
ModelPartData modelPartData2 = modelPartData.addChild("bone", ModelPartBuilder.create().uv(0, 12).cuboid(0.0F, -4.0F, 0.0F, 7.0F, 4.0F, 7.0F), ModelTransform.rotation(-0.0524F, 0.0F, 0.0349F));
|
||||
ModelPartData modelPartData3 = modelPartData2.addChild("bone2", ModelPartBuilder.create().uv(0, 23).cuboid(0.0F, -4.0F, 0.0F, 4.0F, 4.0F, 4.0F), ModelTransform.rotation(-0.1222F, 0.0F, 0.0698F));
|
||||
ModelPartData modelPartData4 = modelPartData3.addChild("bone3", ModelPartBuilder.create().uv(21, 12).cuboid(0.0F, -3.0F, 0.0F, 3.0F, 3.0F, 3.0F), ModelTransform.rotation(-0.2618F, 0.0F, 0.1047F));
|
||||
|
||||
return modelData;
|
||||
}
|
||||
public ModelPart getPart() {
|
||||
return this.headwear;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAngles(T entity, float limbAngle, float limbDistance, float animationProgress, float headYaw, float headPitch) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(MatrixStack matrixStack, VertexConsumer buffer, int packedLight, int packedOverlay, float red, float green, float blue, float alpha){
|
||||
headwear.render(matrixStack, buffer, packedLight, packedOverlay);
|
||||
}
|
||||
|
||||
public void setRotationAngle(ModelPart bone, float x, float y, float z) {
|
||||
bone.pitch = x;
|
||||
bone.yaw = y;
|
||||
bone.roll = z;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
package eu.midnightdust.hats.config;
|
||||
|
||||
public class AreEventHatsEnabled {
|
||||
|
||||
public static boolean areEventHatsEnabled() {
|
||||
return HatsConfig.event_hats;
|
||||
}
|
||||
}
|
||||
12
src/main/java/eu/midnightdust/hats/config/HatsConfig.java
Normal file
@@ -0,0 +1,12 @@
|
||||
package eu.midnightdust.hats.config;
|
||||
|
||||
import eu.midnightdust.lib.config.MidnightConfig;
|
||||
|
||||
public class HatsConfig extends MidnightConfig {
|
||||
|
||||
@Entry // Enable or disable event hats
|
||||
public static boolean event_hats = true;
|
||||
|
||||
@Entry // Enable or disable hats for contributors, friends and donors.
|
||||
public static boolean special_hats = true;
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package eu.midnightdust.hats.config;
|
||||
|
||||
import io.github.prospector.modmenu.api.ConfigScreenFactory;
|
||||
import io.github.prospector.modmenu.api.ModMenuApi;
|
||||
import net.fabricmc.api.EnvType;
|
||||
import net.fabricmc.api.Environment;
|
||||
|
||||
@Environment(EnvType.CLIENT)
|
||||
public class ModMenuIntegration implements ModMenuApi {
|
||||
|
||||
@Override
|
||||
public ConfigScreenFactory<?> getModConfigScreenFactory() {
|
||||
return parent -> new HatsConfig().getScreen(parent);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
package eu.midnightdust.hats.mixin;
|
||||
|
||||
import eu.midnightdust.hats.bunny.BunnyEarsFeatureRenderer;
|
||||
import eu.midnightdust.hats.christmas.ChristmasHatFeatureRenderer;
|
||||
import eu.midnightdust.hats.tater.TinyPotatoFeatureRenderer;
|
||||
import eu.midnightdust.hats.witch.WitchHatFeatureRenderer;
|
||||
import net.minecraft.client.network.AbstractClientPlayerEntity;
|
||||
import net.minecraft.client.render.entity.EntityRendererFactory;
|
||||
import net.minecraft.client.render.entity.LivingEntityRenderer;
|
||||
import net.minecraft.client.render.entity.PlayerEntityRenderer;
|
||||
import net.minecraft.client.render.entity.model.PlayerEntityModel;
|
||||
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.CallbackInfo;
|
||||
|
||||
@Mixin(PlayerEntityRenderer.class)
|
||||
public abstract class PlayerEntityRendererMixin extends LivingEntityRenderer<AbstractClientPlayerEntity, PlayerEntityModel<AbstractClientPlayerEntity>> {
|
||||
public PlayerEntityRendererMixin(EntityRendererFactory.Context ctx, PlayerEntityModel<AbstractClientPlayerEntity> model, float shadowSize) {
|
||||
super(ctx, model, shadowSize);
|
||||
}
|
||||
|
||||
@Inject(at = @At("TAIL"), method = "<init>")
|
||||
public void addFeatures(EntityRendererFactory.Context ctx, boolean slim, CallbackInfo ci) {
|
||||
this.addFeature(new WitchHatFeatureRenderer<>(this, ctx.getModelLoader()));
|
||||
this.addFeature(new ChristmasHatFeatureRenderer<>(this, ctx.getModelLoader()));
|
||||
this.addFeature(new BunnyEarsFeatureRenderer<>(this, ctx.getModelLoader()));
|
||||
this.addFeature(new TinyPotatoFeatureRenderer<>(this, ctx.getModelLoader()));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
package eu.midnightdust.hats.tater;
|
||||
|
||||
import eu.midnightdust.hats.HatsClient;
|
||||
import eu.midnightdust.hats.config.AreEventHatsEnabled;
|
||||
import eu.midnightdust.hats.web.HatLoader;
|
||||
import net.fabricmc.api.EnvType;
|
||||
import net.fabricmc.api.Environment;
|
||||
import net.fabricmc.loader.api.FabricLoader;
|
||||
import net.minecraft.client.model.TexturedModelData;
|
||||
import net.minecraft.client.network.AbstractClientPlayerEntity;
|
||||
import net.minecraft.client.render.OverlayTexture;
|
||||
import net.minecraft.client.render.RenderLayer;
|
||||
import net.minecraft.client.render.VertexConsumer;
|
||||
import net.minecraft.client.render.VertexConsumerProvider;
|
||||
import net.minecraft.client.render.entity.feature.FeatureRenderer;
|
||||
import net.minecraft.client.render.entity.feature.FeatureRendererContext;
|
||||
import net.minecraft.client.render.entity.model.EntityModel;
|
||||
import net.minecraft.client.render.entity.model.EntityModelLayer;
|
||||
import net.minecraft.client.render.entity.model.EntityModelLoader;
|
||||
import net.minecraft.client.render.entity.model.ModelWithHead;
|
||||
import net.minecraft.client.render.item.ItemRenderer;
|
||||
import net.minecraft.client.util.math.MatrixStack;
|
||||
import net.minecraft.entity.LivingEntity;
|
||||
import net.minecraft.util.Identifier;
|
||||
|
||||
import java.util.Calendar;
|
||||
import java.util.UUID;
|
||||
|
||||
@Environment(EnvType.CLIENT)
|
||||
public class TinyPotatoFeatureRenderer<T extends LivingEntity, M extends EntityModel<T>> extends FeatureRenderer<T, M> {
|
||||
private static final String MOD_ID = HatsClient.MOD_ID;
|
||||
public static final EntityModelLayer TINY_POTATO_MODEL_LAYER = new EntityModelLayer(new Identifier("midnight-hats","tiny_potato"), "main");
|
||||
private static final UUID MOTSCHEN = UUID.fromString("a44c2660-630f-478f-946a-e518669fcf0c");
|
||||
|
||||
private static final Identifier DEACTIVATED = new Identifier(MOD_ID,"textures/hats/empty.png");
|
||||
private static final Identifier TATER = new Identifier(MOD_ID,"textures/hats/tater.png");
|
||||
private final TinyPotatoModel<T> tinyPotato;
|
||||
|
||||
public TinyPotatoFeatureRenderer(FeatureRendererContext<T, M> featureRendererContext, EntityModelLoader entityModelLoader) {
|
||||
super(featureRendererContext);
|
||||
this.tinyPotato = new TinyPotatoModel(entityModelLoader.getModelPart(TINY_POTATO_MODEL_LAYER));
|
||||
}
|
||||
|
||||
public static TexturedModelData getTexturedModelData() {
|
||||
return TexturedModelData.of(TinyPotatoModel.getModelData(), 16, 16);
|
||||
}
|
||||
|
||||
public void render(MatrixStack matrixStack, VertexConsumerProvider vertexConsumerProvider, int i, T livingEntity, float f, float g, float h, float j, float k, float l) {
|
||||
{
|
||||
AbstractClientPlayerEntity abstractClientPlayerEntity = (AbstractClientPlayerEntity)livingEntity;
|
||||
Identifier hat_type;
|
||||
if (livingEntity != null) {
|
||||
|
||||
if (Calendar.getInstance().get(Calendar.MONTH) == Calendar.DECEMBER && Calendar.getInstance().get(Calendar.DAY_OF_MONTH) == 10) {
|
||||
if (FabricLoader.getInstance().isModLoaded("cloth-config2")) {
|
||||
if (AreEventHatsEnabled.areEventHatsEnabled()) {
|
||||
hat_type = TATER;
|
||||
}
|
||||
else hat_type = DEACTIVATED;
|
||||
}
|
||||
else hat_type = TATER;
|
||||
}else {
|
||||
hat_type = DEACTIVATED;
|
||||
}
|
||||
} else {
|
||||
hat_type = DEACTIVATED;
|
||||
}
|
||||
|
||||
if (!(hat_type == DEACTIVATED) && !HatLoader.PLAYER_HATS.containsKey(abstractClientPlayerEntity.getUuid()) && !abstractClientPlayerEntity.getUuid().equals(MOTSCHEN)) {
|
||||
matrixStack.push();
|
||||
|
||||
((ModelWithHead) this.getContextModel()).getHead().rotate(matrixStack);
|
||||
VertexConsumer vertexConsumer = ItemRenderer.getArmorGlintConsumer(vertexConsumerProvider, RenderLayer.getEntityCutoutNoCull(hat_type), false, false);
|
||||
this.tinyPotato.render(matrixStack, vertexConsumer, i, OverlayTexture.DEFAULT_UV, 1.0F, 1.0F, 1.0F, 1.0F);
|
||||
|
||||
matrixStack.pop();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
package eu.midnightdust.hats.tater;
|
||||
|
||||
import net.minecraft.client.model.*;
|
||||
import net.minecraft.client.render.VertexConsumer;
|
||||
import net.minecraft.client.render.entity.model.SinglePartEntityModel;
|
||||
import net.minecraft.client.util.math.MatrixStack;
|
||||
import net.minecraft.entity.LivingEntity;
|
||||
|
||||
public class TinyPotatoModel <T extends LivingEntity> extends SinglePartEntityModel<T> {
|
||||
private final ModelPart tater;
|
||||
public TinyPotatoModel(ModelPart root) {
|
||||
tater = root;
|
||||
tater.setPivot(0.0F, -8.0F, 0.0F);
|
||||
}
|
||||
|
||||
public static ModelData getModelData() {
|
||||
ModelData modelData = new ModelData();
|
||||
ModelPartData modelPartData = modelData.getRoot();
|
||||
modelPartData.addChild("tater", ModelPartBuilder.create().uv(0, 0).cuboid(-2.0F, -6.0F, -2.0F, 4.0F, 6.0F, 4.0F), ModelTransform.NONE);
|
||||
|
||||
return modelData;
|
||||
}
|
||||
public ModelPart getPart() {
|
||||
return this.tater;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAngles(T entity, float limbSwing, float limbSwingAmount, float ageInTicks, float netHeadYaw, float headPitch){
|
||||
//previously the render function, render code was moved to a method below
|
||||
}
|
||||
@Override
|
||||
public void render(MatrixStack matrixStack, VertexConsumer buffer, int packedLight, int packedOverlay, float red, float green, float blue, float alpha){
|
||||
|
||||
tater.render(matrixStack, buffer, packedLight, packedOverlay);
|
||||
}
|
||||
|
||||
public void setRotationAngle(ModelPart bone, float x, float y, float z) {
|
||||
bone.pitch = x;
|
||||
bone.yaw = y;
|
||||
bone.roll = z;
|
||||
}
|
||||
}
|
||||
48
src/main/java/eu/midnightdust/hats/web/HatLoader.java
Normal file
@@ -0,0 +1,48 @@
|
||||
package eu.midnightdust.hats.web;
|
||||
|
||||
import com.google.common.reflect.TypeToken;
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import org.apache.logging.log4j.Level;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.Reader;
|
||||
import java.lang.reflect.Type;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
import static net.minecraft.datafixer.fix.BlockEntitySignTextStrictJsonFix.GSON;
|
||||
|
||||
public class HatLoader {
|
||||
public static final Logger logger = LogManager.getLogger("MidnightLib");
|
||||
private final static String HATS_URL = "https://raw.githubusercontent.com/TeamMidnightDust/MidnightHats/master/hats.json";
|
||||
public static final Type HAT_TYPE = new TypeToken<Map<UUID, PlayerHatData>>(){}.getType();
|
||||
public static Map<UUID, PlayerHatData> PLAYER_HATS;
|
||||
|
||||
public static void init() {
|
||||
CompletableFuture.supplyAsync(() -> {
|
||||
try (Reader reader = new InputStreamReader(new URL(HATS_URL).openStream())) {
|
||||
Map<UUID, PlayerHatData> playerData = GSON.fromJson(reader, HAT_TYPE);
|
||||
return playerData;
|
||||
} catch (MalformedURLException error) {
|
||||
logger.log(Level.ERROR, "Unable to load player hats because of connection problems: " + error.getMessage());
|
||||
} catch (IOException error) {
|
||||
logger.log(Level.ERROR, "Unable to load player hats because of an I/O Exception: " + error.getMessage());
|
||||
}
|
||||
|
||||
return null;
|
||||
}).thenAcceptAsync(playerData -> {
|
||||
if (playerData != null) {
|
||||
PLAYER_HATS = playerData;
|
||||
logger.log(Level.INFO, "Player hats successfully loaded!");
|
||||
} else {
|
||||
PLAYER_HATS = Collections.emptyMap();
|
||||
logger.log(Level.WARN, "A problem with the database occured, the hats could not be initialized.");
|
||||
}
|
||||
}, MinecraftClient.getInstance());
|
||||
}
|
||||
}
|
||||
13
src/main/java/eu/midnightdust/hats/web/PlayerHatData.java
Normal file
@@ -0,0 +1,13 @@
|
||||
package eu.midnightdust.hats.web;
|
||||
|
||||
public class PlayerHatData {
|
||||
private final String hat;
|
||||
|
||||
public PlayerHatData(String hat) {
|
||||
this.hat = hat;
|
||||
}
|
||||
|
||||
public String getHatType() {
|
||||
return hat;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,94 @@
|
||||
package eu.midnightdust.hats.witch;
|
||||
|
||||
import eu.midnightdust.hats.HatsClient;
|
||||
import eu.midnightdust.hats.config.AreEventHatsEnabled;
|
||||
import eu.midnightdust.hats.web.HatLoader;
|
||||
import net.fabricmc.api.EnvType;
|
||||
import net.fabricmc.api.Environment;
|
||||
import net.fabricmc.loader.api.FabricLoader;
|
||||
import net.minecraft.client.model.TexturedModelData;
|
||||
import net.minecraft.client.network.AbstractClientPlayerEntity;
|
||||
import net.minecraft.client.render.OverlayTexture;
|
||||
import net.minecraft.client.render.RenderLayer;
|
||||
import net.minecraft.client.render.VertexConsumer;
|
||||
import net.minecraft.client.render.VertexConsumerProvider;
|
||||
import net.minecraft.client.render.entity.feature.FeatureRenderer;
|
||||
import net.minecraft.client.render.entity.feature.FeatureRendererContext;
|
||||
import net.minecraft.client.render.entity.model.EntityModel;
|
||||
import net.minecraft.client.render.entity.model.EntityModelLayer;
|
||||
import net.minecraft.client.render.entity.model.EntityModelLoader;
|
||||
import net.minecraft.client.render.entity.model.ModelWithHead;
|
||||
import net.minecraft.client.render.item.ItemRenderer;
|
||||
import net.minecraft.client.util.math.MatrixStack;
|
||||
import net.minecraft.entity.LivingEntity;
|
||||
import net.minecraft.util.Identifier;
|
||||
|
||||
import java.util.Calendar;
|
||||
import java.util.UUID;
|
||||
|
||||
@Environment(EnvType.CLIENT)
|
||||
public class WitchHatFeatureRenderer<T extends LivingEntity, M extends EntityModel<T>> extends FeatureRenderer<T, M> {
|
||||
private static final String MOD_ID = HatsClient.MOD_ID;
|
||||
public static final EntityModelLayer WITCH_HAT_MODEL_LAYER = new EntityModelLayer(new Identifier("midnight-hats","witch_hat"), "main");
|
||||
private static final UUID MOTSCHEN = UUID.fromString("a44c2660-630f-478f-946a-e518669fcf0c");
|
||||
|
||||
private static final Identifier DEACTIVATED = new Identifier(MOD_ID,"textures/hats/empty.png");
|
||||
private static final Identifier WITCH = new Identifier("textures/entity/witch.png");
|
||||
private static final Identifier MOTSCHEN_SKIN = new Identifier(MOD_ID,"textures/hats/motschen.png");
|
||||
private static final Identifier CONTRIBUTER_SKIN = new Identifier(MOD_ID,"textures/hats/contributer.png");
|
||||
private static final Identifier FRIEND_SKIN = new Identifier(MOD_ID,"textures/hats/friend.png");
|
||||
private static final Identifier DONATOR_SKIN = new Identifier(MOD_ID,"textures/hats/donator.png");
|
||||
private static final Identifier SOCIAL_SKIN = new Identifier(MOD_ID,"textures/hats/social.png");
|
||||
private static final Identifier PRIDE_SKIN = new Identifier(MOD_ID,"textures/hats/pride.png");
|
||||
private final WitchHatModel<T> witchHat;
|
||||
|
||||
public WitchHatFeatureRenderer(FeatureRendererContext<T, M> featureRendererContext, EntityModelLoader entityModelLoader) {
|
||||
super(featureRendererContext);
|
||||
this.witchHat = new WitchHatModel(entityModelLoader.getModelPart(WITCH_HAT_MODEL_LAYER));
|
||||
}
|
||||
|
||||
public static TexturedModelData getTexturedModelData() {
|
||||
return TexturedModelData.of(WitchHatModel.getModelData(), 64, 128);
|
||||
}
|
||||
|
||||
public void render(MatrixStack matrixStack, VertexConsumerProvider vertexConsumerProvider, int i, T livingEntity, float f, float g, float h, float j, float k, float l) {
|
||||
{
|
||||
Identifier hat_type = DEACTIVATED;
|
||||
if (livingEntity instanceof AbstractClientPlayerEntity) {
|
||||
AbstractClientPlayerEntity abstractClientPlayerEntity = (AbstractClientPlayerEntity)livingEntity;
|
||||
|
||||
if (abstractClientPlayerEntity.getUuid().equals(MOTSCHEN)) {
|
||||
hat_type = MOTSCHEN_SKIN;
|
||||
}else if (HatLoader.PLAYER_HATS.containsKey(abstractClientPlayerEntity.getUuid()) && HatLoader.PLAYER_HATS.get(abstractClientPlayerEntity.getUuid()).getHatType().contains("contributer")) {
|
||||
hat_type = CONTRIBUTER_SKIN;
|
||||
}else if (HatLoader.PLAYER_HATS.containsKey(abstractClientPlayerEntity.getUuid()) && HatLoader.PLAYER_HATS.get(abstractClientPlayerEntity.getUuid()).getHatType().contains("friend")) {
|
||||
hat_type = FRIEND_SKIN;
|
||||
}else if (HatLoader.PLAYER_HATS.containsKey(abstractClientPlayerEntity.getUuid()) && HatLoader.PLAYER_HATS.get(abstractClientPlayerEntity.getUuid()).getHatType().contains("donator")) {
|
||||
hat_type = DONATOR_SKIN;
|
||||
}else if (HatLoader.PLAYER_HATS.containsKey(abstractClientPlayerEntity.getUuid()) && HatLoader.PLAYER_HATS.get(abstractClientPlayerEntity.getUuid()).getHatType().contains("social")) {
|
||||
hat_type = SOCIAL_SKIN;
|
||||
}else if (HatLoader.PLAYER_HATS.containsKey(abstractClientPlayerEntity.getUuid()) && HatLoader.PLAYER_HATS.get(abstractClientPlayerEntity.getUuid()).getHatType().contains("pride")) {
|
||||
hat_type = PRIDE_SKIN;
|
||||
}else if (Calendar.getInstance().get(Calendar.MONTH) == Calendar.OCTOBER && Calendar.getInstance().get(Calendar.DAY_OF_MONTH) >= 30) {
|
||||
if (FabricLoader.getInstance().isModLoaded("cloth-config2")) {
|
||||
if (AreEventHatsEnabled.areEventHatsEnabled()) {
|
||||
hat_type = WITCH;
|
||||
}
|
||||
else hat_type = DEACTIVATED;
|
||||
}
|
||||
else hat_type = WITCH;
|
||||
}else hat_type = DEACTIVATED;
|
||||
} else { hat_type = DEACTIVATED; }
|
||||
|
||||
if (!(hat_type == DEACTIVATED)) {
|
||||
matrixStack.push();
|
||||
|
||||
((ModelWithHead) this.getContextModel()).getHead().rotate(matrixStack);
|
||||
VertexConsumer vertexConsumer = ItemRenderer.getArmorGlintConsumer(vertexConsumerProvider, RenderLayer.getEntityCutoutNoCull(hat_type), false, false);
|
||||
this.witchHat.render(matrixStack, vertexConsumer, i, OverlayTexture.DEFAULT_UV, 1.0F, 1.0F, 1.0F, 1.0F);
|
||||
|
||||
matrixStack.pop();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
65
src/main/java/eu/midnightdust/hats/witch/WitchHatModel.java
Normal file
@@ -0,0 +1,65 @@
|
||||
package eu.midnightdust.hats.witch;
|
||||
|
||||
import net.minecraft.client.model.*;
|
||||
import net.minecraft.client.render.VertexConsumer;
|
||||
import net.minecraft.client.render.entity.model.SinglePartEntityModel;
|
||||
import net.minecraft.client.util.math.MatrixStack;
|
||||
import net.minecraft.entity.LivingEntity;
|
||||
|
||||
public class WitchHatModel<T extends LivingEntity> extends SinglePartEntityModel<T> {
|
||||
private final ModelPart headwear;
|
||||
private final ModelPart bone;
|
||||
private final ModelPart bone2;
|
||||
private final ModelPart bone3;
|
||||
|
||||
public WitchHatModel(ModelPart root) {
|
||||
headwear = root;
|
||||
root.setPivot(5.0F, -9.0F, -5.0F);
|
||||
|
||||
bone = headwear.getChild("bone");
|
||||
bone.setPivot(-8.5F, -0.1F, 1.5F);
|
||||
setRotationAngle(bone, -0.0524F, 0.0F, 0.0349F);
|
||||
|
||||
bone2 = bone.getChild("bone2");
|
||||
bone2.setPivot(1.5F, -4.0F, 1.5F);
|
||||
setRotationAngle(bone2, -0.1222F, 0.0F, 0.0698F);
|
||||
|
||||
bone3 = bone2.getChild("bone3");
|
||||
bone3.setPivot(1.5F, -4.0F, 1.5F);
|
||||
setRotationAngle(bone3, -0.2618F, 0.0F, 0.1047F);
|
||||
}
|
||||
|
||||
public static ModelData getModelData(){
|
||||
ModelData modelData = new ModelData();
|
||||
ModelPartData modelPartData = modelData.getRoot();
|
||||
modelPartData.addChild("headwear", ModelPartBuilder.create().uv(0, 64).cuboid(-10.0F, -0.1F, 0.0F, 10.0F, 2.0F, 10.0F), ModelTransform.NONE);
|
||||
ModelPartData modelPartData2 = modelPartData.addChild("bone", ModelPartBuilder.create().uv(0, 76).cuboid(0.0F, -4.0F, 0.0F, 7.0F, 4.0F, 7.0F), ModelTransform.rotation(-0.0524F, 0.0F, 0.0349F));
|
||||
ModelPartData modelPartData3 = modelPartData2.addChild("bone2", ModelPartBuilder.create().uv(0, 87).cuboid(0.0F, -4.0F, 0.0F, 4.0F, 4.0F, 4.0F), ModelTransform.rotation(-0.1222F, 0.0F, 0.0698F));
|
||||
ModelPartData modelPartData4 = modelPartData3.addChild("bone3", ModelPartBuilder.create().uv(0, 95).cuboid(0.0F, -2.0F, 0.0F, 1.0F, 2.0F, 1.0F), ModelTransform.rotation(-0.2618F, 0.0F, 0.1047F));
|
||||
|
||||
return modelData;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAngles(T entity, float limbAngle, float limbDistance, float animationProgress, float headYaw, float headPitch) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(MatrixStack matrixStack, VertexConsumer buffer, int packedLight, int packedOverlay, float red, float green, float blue, float alpha){
|
||||
|
||||
headwear.render(matrixStack, buffer, packedLight, packedOverlay);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ModelPart getPart() {
|
||||
return headwear;
|
||||
}
|
||||
|
||||
public void setRotationAngle(ModelPart bone, float x, float y, float z) {
|
||||
bone.pitch = x;
|
||||
bone.yaw = y;
|
||||
bone.roll = z;
|
||||
}
|
||||
|
||||
}
|
||||
288
src/main/java/eu/midnightdust/lib/config/MidnightConfig.java
Normal file
@@ -0,0 +1,288 @@
|
||||
package eu.midnightdust.lib.config;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import net.fabricmc.loader.api.FabricLoader;
|
||||
import net.minecraft.client.gui.screen.Screen;
|
||||
import net.minecraft.client.gui.screen.ScreenTexts;
|
||||
import net.minecraft.client.gui.widget.ButtonWidget;
|
||||
import net.minecraft.client.gui.widget.TextFieldWidget;
|
||||
import net.minecraft.client.resource.language.I18n;
|
||||
import net.minecraft.client.util.math.MatrixStack;
|
||||
import net.minecraft.text.*;
|
||||
import net.minecraft.util.Formatting;
|
||||
|
||||
import java.lang.annotation.*;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.*;
|
||||
import java.util.function.BiFunction;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Predicate;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
// MidnightConfig v0.1.0 //
|
||||
|
||||
/* Based on https://github.com/Minenash/TinyConfig
|
||||
Credits to Minenash - CC0-1.0
|
||||
You can copy this class to get a standalone version of MidnightConfig */
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
public class MidnightConfig {
|
||||
|
||||
private static final Pattern INTEGER_ONLY = Pattern.compile("(-?[0-9]*)");
|
||||
private static final Pattern DECIMAL_ONLY = Pattern.compile("-?([\\d]+\\.?[\\d]*|[\\d]*\\.?[\\d]+|\\.)");
|
||||
|
||||
private static final List<EntryInfo> entries = new ArrayList<>();
|
||||
|
||||
protected static class EntryInfo {
|
||||
Field field;
|
||||
Object widget;
|
||||
int width;
|
||||
Method dynamicTooltip;
|
||||
Map.Entry<TextFieldWidget,Text> error;
|
||||
Object defaultValue;
|
||||
Object value;
|
||||
String tempValue;
|
||||
boolean inLimits = true;
|
||||
}
|
||||
|
||||
private static Class configClass;
|
||||
private static String translationPrefix;
|
||||
private static Path path;
|
||||
|
||||
private static final Gson gson = new GsonBuilder()
|
||||
.excludeFieldsWithModifiers(Modifier.TRANSIENT)
|
||||
.excludeFieldsWithModifiers(Modifier.PRIVATE)
|
||||
.setPrettyPrinting()
|
||||
.create();
|
||||
|
||||
public static void init(String modid, Class<?> config) {
|
||||
translationPrefix = modid + ".midnightconfig.";
|
||||
path = FabricLoader.getInstance().getConfigDir().resolve(modid + ".json");
|
||||
configClass = config;
|
||||
|
||||
for (Field field : config.getFields()) {
|
||||
Class<?> type = field.getType();
|
||||
EntryInfo info = new EntryInfo();
|
||||
|
||||
Entry e;
|
||||
try { e = field.getAnnotation(Entry.class); }
|
||||
catch (Exception ignored) { continue; }
|
||||
|
||||
info.width = e.width();
|
||||
info.field = field;
|
||||
|
||||
if (type == int.class) textField(info, Integer::parseInt, INTEGER_ONLY, e.min(), e.max(), true);
|
||||
else if (type == double.class) textField(info, Double::parseDouble, DECIMAL_ONLY, e.min(), e.max(),false);
|
||||
else if (type == String.class) textField(info, String::length, null, Math.min(e.min(),0), Math.max(e.max(),1),true);
|
||||
else if (type == boolean.class) {
|
||||
Function<Object,Text> func = value -> new LiteralText((Boolean) value ? "True" : "False").formatted((Boolean) value ? Formatting.GREEN : Formatting.RED);
|
||||
info.widget = new AbstractMap.SimpleEntry<ButtonWidget.PressAction, Function<Object, Text>>(button -> {
|
||||
info.value = !(Boolean) info.value;
|
||||
button.setMessage(func.apply(info.value));
|
||||
}, func);
|
||||
}
|
||||
else if (type.isEnum()) {
|
||||
List<?> values = Arrays.asList(field.getType().getEnumConstants());
|
||||
Function<Object,Text> func = value -> new TranslatableText(translationPrefix + "enum." + type.getSimpleName() + "." + info.value.toString());
|
||||
info.widget = new AbstractMap.SimpleEntry<ButtonWidget.PressAction, Function<Object,Text>>( button -> {
|
||||
int index = values.indexOf(info.value) + 1;
|
||||
info.value = values.get(index >= values.size()? 0 : index);
|
||||
button.setMessage(func.apply(info.value));
|
||||
}, func);
|
||||
}
|
||||
else
|
||||
continue;
|
||||
|
||||
entries.add(info);
|
||||
|
||||
try { info.defaultValue = field.get(null); }
|
||||
catch (IllegalAccessException ignored) {}
|
||||
|
||||
try {
|
||||
info.dynamicTooltip = config.getMethod(e.dynamicTooltip());
|
||||
info.dynamicTooltip.setAccessible(true);
|
||||
} catch (Exception ignored) {}
|
||||
|
||||
}
|
||||
|
||||
try { gson.fromJson(Files.newBufferedReader(path), config); }
|
||||
catch (Exception e) { write(); }
|
||||
|
||||
for (EntryInfo info : entries) {
|
||||
try {
|
||||
info.value = info.field.get(null);
|
||||
info.tempValue = info.value.toString();
|
||||
}
|
||||
catch (IllegalAccessException ignored) {}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static void textField(EntryInfo info, Function<String,Number> f, Pattern pattern, double min, double max, boolean cast) {
|
||||
boolean isNumber = pattern != null;
|
||||
info.widget = (BiFunction<TextFieldWidget, ButtonWidget, Predicate<String>>) (t, b) -> s -> {
|
||||
s = s.trim();
|
||||
if (!(s.isEmpty() || !isNumber || pattern.matcher(s).matches()))
|
||||
return false;
|
||||
|
||||
Number value = 0;
|
||||
boolean inLimits = false;
|
||||
System.out.println(((isNumber ^ s.isEmpty())));
|
||||
System.out.println(!s.equals("-") && !s.equals("."));
|
||||
info.error = null;
|
||||
if (!(isNumber && s.isEmpty()) && !s.equals("-") && !s.equals(".")) {
|
||||
value = f.apply(s);
|
||||
inLimits = value.doubleValue() >= min && value.doubleValue() <= max;
|
||||
info.error = inLimits? null : new AbstractMap.SimpleEntry<>(t, new LiteralText(value.doubleValue() < min ?
|
||||
"§cMinimum " + (isNumber? "value" : "length") + (cast? " is " + (int)min : " is " + min) :
|
||||
"§cMaximum " + (isNumber? "value" : "length") + (cast? " is " + (int)max : " is " + max)));
|
||||
}
|
||||
|
||||
info.tempValue = s;
|
||||
t.setEditableColor(inLimits? 0xFFFFFFFF : 0xFFFF7777);
|
||||
info.inLimits = inLimits;
|
||||
b.active = entries.stream().allMatch(e -> e.inLimits);
|
||||
|
||||
if (inLimits)
|
||||
info.value = isNumber? value : s;
|
||||
|
||||
return true;
|
||||
};
|
||||
}
|
||||
|
||||
public static void write() {
|
||||
try {
|
||||
if (!Files.exists(path)) Files.createFile(path);
|
||||
Files.write(path, gson.toJson(configClass.newInstance()).getBytes());
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public Screen getScreen(Screen parent) {
|
||||
return new TinyConfigScreen(parent);
|
||||
}
|
||||
|
||||
private static class TinyConfigScreen extends Screen {
|
||||
protected TinyConfigScreen(Screen parent) {
|
||||
super(new TranslatableText(MidnightConfig.translationPrefix + "title"));
|
||||
this.parent = parent;
|
||||
}
|
||||
private final Screen parent;
|
||||
|
||||
// Real Time config update //
|
||||
@Override
|
||||
public void tick() {
|
||||
for (EntryInfo info : entries)
|
||||
try { info.field.set(null, info.value); }
|
||||
catch (IllegalAccessException ignore) {}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void init() {
|
||||
super.init();
|
||||
this.addButton(new ButtonWidget(this.width / 2 - 154, this.height - 28, 150, 20, ScreenTexts.CANCEL, button -> {
|
||||
try { gson.fromJson(Files.newBufferedReader(path), configClass); }
|
||||
catch (Exception e) { write(); }
|
||||
|
||||
for (EntryInfo info : entries) {
|
||||
try {
|
||||
info.value = info.field.get(null);
|
||||
info.tempValue = info.value.toString();
|
||||
}
|
||||
catch (IllegalAccessException ignored) {}
|
||||
}
|
||||
Objects.requireNonNull(client).openScreen(parent);
|
||||
}));
|
||||
|
||||
ButtonWidget done = this.addButton(new ButtonWidget(this.width / 2 + 4, this.height - 28, 150, 20, ScreenTexts.DONE, (button) -> {
|
||||
for (EntryInfo info : entries)
|
||||
try { info.field.set(null, info.value); }
|
||||
catch (IllegalAccessException ignore) {}
|
||||
write();
|
||||
Objects.requireNonNull(client).openScreen(parent);
|
||||
}));
|
||||
|
||||
int y = 45;
|
||||
for (EntryInfo info : entries) {
|
||||
addButton(new ButtonWidget(width - 155, y, 40,20, new LiteralText("Reset").formatted(Formatting.RED), (button -> {
|
||||
info.value = info.defaultValue;
|
||||
info.tempValue = info.value.toString();
|
||||
Objects.requireNonNull(client).openScreen(this);
|
||||
})));
|
||||
|
||||
if (info.widget instanceof Map.Entry) {
|
||||
Map.Entry<ButtonWidget.PressAction,Function<Object,Text>> widget = (Map.Entry<ButtonWidget.PressAction, Function<Object, Text>>) info.widget;
|
||||
addButton(new ButtonWidget(width-110,y,info.width,20, widget.getValue().apply(info.value), widget.getKey()));
|
||||
}
|
||||
else {
|
||||
TextFieldWidget widget = addButton(new TextFieldWidget(textRenderer, width-110, y, info.width, 20, null));
|
||||
widget.setText(info.tempValue);
|
||||
|
||||
Predicate<String> processor = ((BiFunction<TextFieldWidget, ButtonWidget, Predicate<String>>) info.widget).apply(widget,done);
|
||||
widget.setTextPredicate(processor);
|
||||
|
||||
children.add(widget);
|
||||
}
|
||||
y += 25;
|
||||
}
|
||||
|
||||
}
|
||||
int aniX = this.width / 2;
|
||||
@Override
|
||||
public void render(MatrixStack matrices, int mouseX, int mouseY, float delta) {
|
||||
this.renderBackground(matrices);
|
||||
|
||||
if (aniX < this.width / 2) {
|
||||
aniX = aniX +40;
|
||||
}
|
||||
|
||||
int stringWidth = (int) (title.getString().length() * 2.75f);
|
||||
this.fillGradient(matrices, this.width / 2 - stringWidth, 10, this.width /2 + stringWidth, 29, -1072689136, -804253680);
|
||||
this.fillGradient(matrices, this.width / 2 - aniX, 35, width/2 + aniX, this.height - 40, -1072689136, -804253680);
|
||||
|
||||
super.render(matrices, mouseX, mouseY, delta);
|
||||
drawCenteredText(matrices, textRenderer, title, width/2, 15, 0xFFFFFF);
|
||||
|
||||
int y = 40;
|
||||
for (EntryInfo info : entries) {
|
||||
drawTextWithShadow(matrices, textRenderer, new TranslatableText(translationPrefix + info.field.getName()), 12, y + 10, 0xFFFFFF);
|
||||
|
||||
if (info.error != null && info.error.getKey().isMouseOver(mouseX,mouseY))
|
||||
renderTooltip(matrices, info.error.getValue(), mouseX, mouseY);
|
||||
else if (mouseY >= y && mouseY < (y + 25)) {
|
||||
if (info.dynamicTooltip != null) {
|
||||
try {
|
||||
renderTooltip(matrices, (List<Text>) info.dynamicTooltip.invoke(null, entries), mouseX, mouseY);
|
||||
y += 25;
|
||||
continue;
|
||||
} catch (Exception e) { e.printStackTrace(); }
|
||||
}
|
||||
String key = translationPrefix + info.field.getName() + ".tooltip";
|
||||
if (I18n.hasTranslation(key)) {
|
||||
List<Text> list = new ArrayList<>();
|
||||
for (String str : I18n.translate(key).split("\n"))
|
||||
list.add(new LiteralText(str));
|
||||
renderTooltip(matrices, list, mouseX, mouseY);
|
||||
}
|
||||
}
|
||||
y += 25;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target(ElementType.FIELD)
|
||||
public @interface Entry {
|
||||
String dynamicTooltip() default "";
|
||||
int width() default 100;
|
||||
double min() default Double.MIN_NORMAL;
|
||||
double max() default Double.MAX_VALUE;
|
||||
}
|
||||
}
|
||||
BIN
src/main/resources/assets/midnightlib/icon.png
Normal file
|
After Width: | Height: | Size: 7.6 KiB |
7
src/main/resources/assets/midnightlib/lang/en_us.json
Normal file
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"midnightlib.midnightconfig.title":"MidnightLib Config",
|
||||
"midnightlib.midnightconfig.event_hats":"Enable Event Hats",
|
||||
"midnightlib.midnightconfig.event_hats.tooltip":"Enable or disable event hats",
|
||||
"midnightlib.midnightconfig.special_hats":"Enable Special Hats",
|
||||
"midnightlib.midnightconfig.special_hats.tooltip":"Enable or disable hats for contributors, friends and donors."
|
||||
}
|
||||
|
After Width: | Height: | Size: 1.6 KiB |
|
After Width: | Height: | Size: 649 B |
BIN
src/main/resources/assets/midnightlib/textures/hats/donator.png
Normal file
|
After Width: | Height: | Size: 629 B |
BIN
src/main/resources/assets/midnightlib/textures/hats/empty.png
Normal file
|
After Width: | Height: | Size: 139 B |
BIN
src/main/resources/assets/midnightlib/textures/hats/friend.png
Normal file
|
After Width: | Height: | Size: 621 B |
BIN
src/main/resources/assets/midnightlib/textures/hats/motschen.png
Normal file
|
After Width: | Height: | Size: 622 B |
BIN
src/main/resources/assets/midnightlib/textures/hats/pride.png
Normal file
|
After Width: | Height: | Size: 1.0 KiB |
BIN
src/main/resources/assets/midnightlib/textures/hats/social.png
Normal file
|
After Width: | Height: | Size: 622 B |
BIN
src/main/resources/assets/midnightlib/textures/hats/tater.png
Normal file
|
After Width: | Height: | Size: 639 B |
42
src/main/resources/fabric.mod.json
Normal file
@@ -0,0 +1,42 @@
|
||||
{
|
||||
"schemaVersion": 1,
|
||||
"id": "midnightlib",
|
||||
"version": "${version}",
|
||||
|
||||
"name": "MidnightLib",
|
||||
"description": "Common Library for Team MidnightDust's mods.\nProvides a config api, common utils, and cosmetics.",
|
||||
"authors": [
|
||||
"Motschen",
|
||||
"TeamMidnightDust"
|
||||
],
|
||||
"contact": {
|
||||
"homepage": "https://www.midnightdust.eu/",
|
||||
"sources": "https://github.com/TeamMidnightDust/MidnightLib",
|
||||
"issues": "https://github.com/TeamMidnightDust/MidnightLib/issues"
|
||||
},
|
||||
|
||||
"license": "MIT",
|
||||
"icon": "assets/midnightlib/icon.png",
|
||||
|
||||
"environment": "*",
|
||||
"entrypoints": {
|
||||
"client": [
|
||||
"eu.midnightdust.hats.HatsClient"
|
||||
],
|
||||
"modmenu": [
|
||||
"eu.midnightdust.hats.config.ModMenuIntegration"
|
||||
]
|
||||
},
|
||||
|
||||
"mixins": [
|
||||
"midnight-hats.mixins.json"
|
||||
],
|
||||
|
||||
"depends": {
|
||||
"fabric": "*"
|
||||
},
|
||||
|
||||
"custom": {
|
||||
"modmenu:api": true
|
||||
}
|
||||
}
|
||||
11
src/main/resources/midnight-hats.mixins.json
Normal file
@@ -0,0 +1,11 @@
|
||||
{
|
||||
"required": true,
|
||||
"package": "eu.midnightdust.hats.mixin",
|
||||
"compatibilityLevel": "JAVA_8",
|
||||
"client": [
|
||||
"PlayerEntityRendererMixin"
|
||||
],
|
||||
"injectors": {
|
||||
"defaultRequire": 1
|
||||
}
|
||||
}
|
||||