Initial sanctuary sources
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
# Gradle
|
||||
.gradle/
|
||||
build/
|
||||
out/
|
||||
classes/
|
||||
|
||||
# Eclipse
|
||||
*.launch
|
||||
|
||||
# IntelliJ IDEA
|
||||
.idea/
|
||||
*.iml
|
||||
*.ipr
|
||||
*.iws
|
||||
|
||||
# VS Code
|
||||
.settings/
|
||||
.vscode/
|
||||
bin/
|
||||
.classpath
|
||||
.project
|
||||
|
||||
# macOS
|
||||
*.DS_Store
|
||||
|
||||
# Fabric
|
||||
run/
|
||||
|
||||
# Java
|
||||
.jdk/
|
||||
hs_err_*.log
|
||||
replay_*.log
|
||||
*.hprof
|
||||
*.jfr
|
||||
@@ -0,0 +1,67 @@
|
||||
plugins {
|
||||
id "net.fabricmc.fabric-loom" version "${loom_version}"
|
||||
id "maven-publish"
|
||||
}
|
||||
|
||||
version = project.mod_version
|
||||
group = project.maven_group
|
||||
|
||||
repositories {
|
||||
}
|
||||
|
||||
loom {
|
||||
splitEnvironmentSourceSets()
|
||||
|
||||
mods {
|
||||
"happy_creeper" {
|
||||
sourceSet sourceSets.main
|
||||
sourceSet sourceSets.client
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
minecraft "com.mojang:minecraft:${project.minecraft_version}"
|
||||
implementation "net.fabricmc:fabric-loader:${project.loader_version}"
|
||||
implementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_api_version}"
|
||||
}
|
||||
|
||||
processResources {
|
||||
def version = project.version
|
||||
inputs.property "version", version
|
||||
|
||||
filesMatching("fabric.mod.json") {
|
||||
expand "version": version
|
||||
}
|
||||
}
|
||||
|
||||
tasks.withType(JavaCompile).configureEach {
|
||||
it.options.release = 25
|
||||
}
|
||||
|
||||
java {
|
||||
withSourcesJar()
|
||||
|
||||
sourceCompatibility = JavaVersion.VERSION_25
|
||||
targetCompatibility = JavaVersion.VERSION_25
|
||||
}
|
||||
|
||||
jar {
|
||||
def projectName = project.name
|
||||
inputs.property "projectName", projectName
|
||||
|
||||
from("../../license.txt") {
|
||||
rename { "${it}_${projectName}" }
|
||||
}
|
||||
}
|
||||
|
||||
publishing {
|
||||
publications {
|
||||
create("mavenJava", MavenPublication) {
|
||||
from components.java
|
||||
}
|
||||
}
|
||||
|
||||
repositories {
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
# Done to increase the memory available to Gradle.
|
||||
org.gradle.jvmargs=-Xmx1G
|
||||
org.gradle.parallel=true
|
||||
|
||||
# IntelliJ IDEA is not yet fully compatible with configuration cache:
|
||||
# https://github.com/FabricMC/fabric-loom/issues/1349
|
||||
org.gradle.configuration-cache=false
|
||||
|
||||
# Fabric properties
|
||||
# Check current versions on https://fabricmc.net/develop
|
||||
minecraft_version=26.1.2
|
||||
loader_version=0.19.2
|
||||
loom_version=1.16-SNAPSHOT
|
||||
|
||||
# Mod properties
|
||||
mod_version=1.0.0
|
||||
maven_group=fr.koka99cab
|
||||
archives_base_name=happy_creeper
|
||||
|
||||
# Dependencies
|
||||
fabric_api_version=0.148.0+26.1.2
|
||||
Binary file not shown.
@@ -0,0 +1,7 @@
|
||||
distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-9.4.1-bin.zip
|
||||
networkTimeout=10000
|
||||
validateDistributionUrl=true
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
zipStorePath=wrapper/dists
|
||||
+253
@@ -0,0 +1,253 @@
|
||||
#!/bin/sh
|
||||
|
||||
#
|
||||
# Copyright © 2015 the original authors.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# https://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
#
|
||||
|
||||
##############################################################################
|
||||
#
|
||||
# Gradle start up script for POSIX generated by Gradle.
|
||||
#
|
||||
# Important for running:
|
||||
#
|
||||
# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is
|
||||
# noncompliant, but you have some other compliant shell such as ksh or
|
||||
# bash, then to run this script, type that shell name before the whole
|
||||
# command line, like:
|
||||
#
|
||||
# ksh Gradle
|
||||
#
|
||||
# Busybox and similar reduced shells will NOT work, because this script
|
||||
# requires all of these POSIX shell features:
|
||||
# * functions;
|
||||
# * expansions «$var», «${var}», «${var:-default}», «${var+SET}»,
|
||||
# «${var#prefix}», «${var%suffix}», and «$( cmd )»;
|
||||
# * compound commands having a testable exit status, especially «case»;
|
||||
# * various built-in commands including «command», «set», and «ulimit».
|
||||
#
|
||||
# Important for patching:
|
||||
#
|
||||
# (2) This script targets any POSIX shell, so it avoids extensions provided
|
||||
# by Bash, Ksh, etc; in particular arrays are avoided.
|
||||
#
|
||||
# The "traditional" practice of packing multiple parameters into a
|
||||
# space-separated string is a well documented source of bugs and security
|
||||
# problems, so this is (mostly) avoided, by progressively accumulating
|
||||
# options in "$@", and eventually passing that to Java.
|
||||
#
|
||||
# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS,
|
||||
# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly;
|
||||
# see the in-line comments for details.
|
||||
#
|
||||
# There are tweaks for specific operating systems such as AIX, CygWin,
|
||||
# Darwin, MinGW, and NonStop.
|
||||
#
|
||||
# (3) This script is generated from the Groovy template
|
||||
# https://github.com/gradle/gradle/blob/2d6327017519d23b96af35865dc997fcb544fb40/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
|
||||
# within the Gradle project.
|
||||
#
|
||||
# You can find Gradle at https://github.com/gradle/gradle/.
|
||||
#
|
||||
##############################################################################
|
||||
|
||||
# Attempt to set APP_HOME
|
||||
|
||||
# Resolve links: $0 may be a link
|
||||
app_path=$0
|
||||
|
||||
# Need this for daisy-chained symlinks.
|
||||
while
|
||||
APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path
|
||||
[ -h "$app_path" ]
|
||||
do
|
||||
ls=$( ls -ld "$app_path" )
|
||||
link=${ls#*' -> '}
|
||||
case $link in #(
|
||||
/*) app_path=$link ;; #(
|
||||
*) app_path=$APP_HOME$link ;;
|
||||
esac
|
||||
done
|
||||
|
||||
# This is normally unused
|
||||
# shellcheck disable=SC2034
|
||||
APP_BASE_NAME=${0##*/}
|
||||
# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
|
||||
APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s\n' "$PWD" ) || exit
|
||||
|
||||
if [ -z "$JAVA_HOME" ] && [ -x "$APP_HOME/.jdk/current/bin/java" ] ; then
|
||||
JAVA_HOME=$APP_HOME/.jdk/current
|
||||
export JAVA_HOME
|
||||
fi
|
||||
|
||||
# Use the maximum available, or set MAX_FD != -1 to use that value.
|
||||
MAX_FD=maximum
|
||||
|
||||
warn () {
|
||||
echo "$*"
|
||||
} >&2
|
||||
|
||||
die () {
|
||||
echo
|
||||
echo "$*"
|
||||
echo
|
||||
exit 1
|
||||
} >&2
|
||||
|
||||
# OS specific support (must be 'true' or 'false').
|
||||
cygwin=false
|
||||
msys=false
|
||||
darwin=false
|
||||
nonstop=false
|
||||
case "$( uname )" in #(
|
||||
CYGWIN* ) cygwin=true ;; #(
|
||||
Darwin* ) darwin=true ;; #(
|
||||
MSYS* | MINGW* ) msys=true ;; #(
|
||||
NONSTOP* ) nonstop=true ;;
|
||||
esac
|
||||
|
||||
|
||||
|
||||
# Determine the Java command to use to start the JVM.
|
||||
if [ -n "$JAVA_HOME" ] ; then
|
||||
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
|
||||
# IBM's JDK on AIX uses strange locations for the executables
|
||||
JAVACMD=$JAVA_HOME/jre/sh/java
|
||||
else
|
||||
JAVACMD=$JAVA_HOME/bin/java
|
||||
fi
|
||||
if [ ! -x "$JAVACMD" ] ; then
|
||||
die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
|
||||
|
||||
Please set the JAVA_HOME variable in your environment to match the
|
||||
location of your Java installation."
|
||||
fi
|
||||
else
|
||||
JAVACMD=java
|
||||
if ! command -v java >/dev/null 2>&1
|
||||
then
|
||||
die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
||||
|
||||
Please set the JAVA_HOME variable in your environment to match the
|
||||
location of your Java installation."
|
||||
fi
|
||||
fi
|
||||
|
||||
# Increase the maximum file descriptors if we can.
|
||||
if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
|
||||
case $MAX_FD in #(
|
||||
max*)
|
||||
# In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked.
|
||||
# shellcheck disable=SC2039,SC3045
|
||||
MAX_FD=$( ulimit -H -n ) ||
|
||||
warn "Could not query maximum file descriptor limit"
|
||||
esac
|
||||
case $MAX_FD in #(
|
||||
'' | soft) :;; #(
|
||||
*)
|
||||
# In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.
|
||||
# shellcheck disable=SC2039,SC3045
|
||||
ulimit -n "$MAX_FD" ||
|
||||
warn "Could not set maximum file descriptor limit to $MAX_FD"
|
||||
esac
|
||||
fi
|
||||
|
||||
# Collect all arguments for the java command, stacking in reverse order:
|
||||
# * args from the command line
|
||||
# * the main class name
|
||||
# * -classpath
|
||||
# * -D...appname settings
|
||||
# * --module-path (only if needed)
|
||||
# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables.
|
||||
|
||||
# For Cygwin or MSYS, switch paths to Windows format before running java
|
||||
if "$cygwin" || "$msys" ; then
|
||||
APP_HOME=$( cygpath --path --mixed "$APP_HOME" )
|
||||
|
||||
JAVACMD=$( cygpath --unix "$JAVACMD" )
|
||||
|
||||
# Now convert the arguments - kludge to limit ourselves to /bin/sh
|
||||
for arg do
|
||||
if
|
||||
case $arg in #(
|
||||
-*) false ;; # don't mess with options #(
|
||||
/?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath
|
||||
[ -e "$t" ] ;; #(
|
||||
*) false ;;
|
||||
esac
|
||||
then
|
||||
arg=$( cygpath --path --ignore --mixed "$arg" )
|
||||
fi
|
||||
# Roll the args list around exactly as many times as the number of
|
||||
# args, so each arg winds up back in the position where it started, but
|
||||
# possibly modified.
|
||||
#
|
||||
# NB: a `for` loop captures its iteration list before it begins, so
|
||||
# changing the positional parameters here affects neither the number of
|
||||
# iterations, nor the values presented in `arg`.
|
||||
shift # remove old arg
|
||||
set -- "$@" "$arg" # push replacement arg
|
||||
done
|
||||
fi
|
||||
|
||||
|
||||
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
|
||||
|
||||
# Collect all arguments for the java command:
|
||||
# * DEFAULT_JVM_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments,
|
||||
# and any embedded shellness will be escaped.
|
||||
# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be
|
||||
# treated as '${Hostname}' itself on the command line.
|
||||
|
||||
set -- \
|
||||
"-Dorg.gradle.appname=$APP_BASE_NAME" \
|
||||
-jar "$APP_HOME/gradle/wrapper/gradle-wrapper.jar" \
|
||||
"$@"
|
||||
|
||||
# Stop when "xargs" is not available.
|
||||
if ! command -v xargs >/dev/null 2>&1
|
||||
then
|
||||
die "xargs is not available"
|
||||
fi
|
||||
|
||||
# Use "xargs" to parse quoted args.
|
||||
#
|
||||
# With -n1 it outputs one arg per line, with the quotes and backslashes removed.
|
||||
#
|
||||
# In Bash we could simply go:
|
||||
#
|
||||
# readarray ARGS < <( xargs -n1 <<<"$var" ) &&
|
||||
# set -- "${ARGS[@]}" "$@"
|
||||
#
|
||||
# but POSIX shell has neither arrays nor command substitution, so instead we
|
||||
# post-process each arg (as a line of input to sed) to backslash-escape any
|
||||
# character that might be a shell metacharacter, then use eval to reverse
|
||||
# that process (while maintaining the separation between arguments), and wrap
|
||||
# the whole thing up as a single "set" statement.
|
||||
#
|
||||
# This will of course break if any of these variables contains a newline or
|
||||
# an unmatched quote.
|
||||
#
|
||||
|
||||
eval "set -- $(
|
||||
printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" |
|
||||
xargs -n1 |
|
||||
sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' |
|
||||
tr '\n' ' '
|
||||
)" '"$@"'
|
||||
|
||||
exec "$JAVACMD" "$@"
|
||||
Vendored
+93
@@ -0,0 +1,93 @@
|
||||
@rem
|
||||
@rem Copyright 2015 the original author or authors.
|
||||
@rem
|
||||
@rem Licensed under the Apache License, Version 2.0 (the "License");
|
||||
@rem you may not use this file except in compliance with the License.
|
||||
@rem You may obtain a copy of the License at
|
||||
@rem
|
||||
@rem https://www.apache.org/licenses/LICENSE-2.0
|
||||
@rem
|
||||
@rem Unless required by applicable law or agreed to in writing, software
|
||||
@rem distributed under the License is distributed on an "AS IS" BASIS,
|
||||
@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
@rem See the License for the specific language governing permissions and
|
||||
@rem limitations under the License.
|
||||
@rem
|
||||
@rem SPDX-License-Identifier: Apache-2.0
|
||||
@rem
|
||||
|
||||
@if "%DEBUG%"=="" @echo off
|
||||
@rem ##########################################################################
|
||||
@rem
|
||||
@rem Gradle startup script for Windows
|
||||
@rem
|
||||
@rem ##########################################################################
|
||||
|
||||
@rem Set local scope for the variables with windows NT shell
|
||||
if "%OS%"=="Windows_NT" setlocal
|
||||
|
||||
set DIRNAME=%~dp0
|
||||
if "%DIRNAME%"=="" set DIRNAME=.
|
||||
@rem This is normally unused
|
||||
set APP_BASE_NAME=%~n0
|
||||
set APP_HOME=%DIRNAME%
|
||||
|
||||
@rem Resolve any "." and ".." in APP_HOME to make it shorter.
|
||||
for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
|
||||
|
||||
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||
set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
|
||||
|
||||
@rem Find java.exe
|
||||
if defined JAVA_HOME goto findJavaFromJavaHome
|
||||
|
||||
set JAVA_EXE=java.exe
|
||||
%JAVA_EXE% -version >NUL 2>&1
|
||||
if %ERRORLEVEL% equ 0 goto execute
|
||||
|
||||
echo. 1>&2
|
||||
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2
|
||||
echo. 1>&2
|
||||
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
|
||||
echo location of your Java installation. 1>&2
|
||||
|
||||
goto fail
|
||||
|
||||
:findJavaFromJavaHome
|
||||
set JAVA_HOME=%JAVA_HOME:"=%
|
||||
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
|
||||
|
||||
if exist "%JAVA_EXE%" goto execute
|
||||
|
||||
echo. 1>&2
|
||||
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2
|
||||
echo. 1>&2
|
||||
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
|
||||
echo location of your Java installation. 1>&2
|
||||
|
||||
goto fail
|
||||
|
||||
:execute
|
||||
@rem Setup the command line
|
||||
|
||||
|
||||
|
||||
@rem Execute Gradle
|
||||
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -jar "%APP_HOME%\gradle\wrapper\gradle-wrapper.jar" %*
|
||||
|
||||
:end
|
||||
@rem End local scope for the variables with windows NT shell
|
||||
if %ERRORLEVEL% equ 0 goto mainEnd
|
||||
|
||||
:fail
|
||||
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
|
||||
rem the _cmd.exe /c_ return code!
|
||||
set EXIT_CODE=%ERRORLEVEL%
|
||||
if %EXIT_CODE% equ 0 set EXIT_CODE=1
|
||||
if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE%
|
||||
exit /b %EXIT_CODE%
|
||||
|
||||
:mainEnd
|
||||
if "%OS%"=="Windows_NT" endlocal
|
||||
|
||||
:omega
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 564 B |
@@ -0,0 +1,12 @@
|
||||
pluginManagement {
|
||||
repositories {
|
||||
maven {
|
||||
name = "Fabric"
|
||||
url = "https://maven.fabricmc.net/"
|
||||
}
|
||||
mavenCentral()
|
||||
gradlePluginPortal()
|
||||
}
|
||||
}
|
||||
|
||||
rootProject.name = "happy_creeper"
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
package fr.koka99cab.happy_creeper.client;
|
||||
|
||||
import fr.koka99cab.happy_creeper.client.renderer.HappyCreeperRenderer;
|
||||
import fr.koka99cab.happy_creeper.registry.ModEntityTypes;
|
||||
import net.fabricmc.fabric.api.client.rendering.v1.EntityRendererRegistry;
|
||||
import net.fabricmc.api.ClientModInitializer;
|
||||
|
||||
public final class HappyCreeperClient implements ClientModInitializer {
|
||||
@Override
|
||||
public void onInitializeClient() {
|
||||
EntityRendererRegistry.register(ModEntityTypes.HAPPY_CREEPER, HappyCreeperRenderer::new);
|
||||
}
|
||||
}
|
||||
+41
@@ -0,0 +1,41 @@
|
||||
package fr.koka99cab.happy_creeper.client.model;
|
||||
|
||||
import fr.koka99cab.happy_creeper.client.renderer.HappyCreeperRenderState;
|
||||
import net.minecraft.client.model.EntityModel;
|
||||
import net.minecraft.client.model.HeadedModel;
|
||||
import net.minecraft.client.model.geom.ModelPart;
|
||||
import net.minecraft.util.Mth;
|
||||
|
||||
public final class HappyCreeperModel extends EntityModel<HappyCreeperRenderState> implements HeadedModel {
|
||||
private final ModelPart head;
|
||||
private final ModelPart rightHindLeg;
|
||||
private final ModelPart leftHindLeg;
|
||||
private final ModelPart rightFrontLeg;
|
||||
private final ModelPart leftFrontLeg;
|
||||
|
||||
public HappyCreeperModel(ModelPart modelPart) {
|
||||
super(modelPart);
|
||||
this.head = modelPart.getChild("head");
|
||||
this.leftHindLeg = modelPart.getChild("right_hind_leg");
|
||||
this.rightHindLeg = modelPart.getChild("left_hind_leg");
|
||||
this.leftFrontLeg = modelPart.getChild("right_front_leg");
|
||||
this.rightFrontLeg = modelPart.getChild("left_front_leg");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setupAnim(HappyCreeperRenderState happyCreeperRenderState) {
|
||||
this.head.yRot = happyCreeperRenderState.yRot * Mth.DEG_TO_RAD;
|
||||
this.head.xRot = happyCreeperRenderState.xRot * Mth.DEG_TO_RAD;
|
||||
float walkPosition = happyCreeperRenderState.walkAnimationPos;
|
||||
float walkSpeed = happyCreeperRenderState.walkAnimationSpeed;
|
||||
this.rightHindLeg.xRot = Mth.cos(walkPosition * 0.6662F) * 1.4F * walkSpeed;
|
||||
this.leftHindLeg.xRot = Mth.cos(walkPosition * 0.6662F + Mth.PI) * 1.4F * walkSpeed;
|
||||
this.rightFrontLeg.xRot = Mth.cos(walkPosition * 0.6662F + Mth.PI) * 1.4F * walkSpeed;
|
||||
this.leftFrontLeg.xRot = Mth.cos(walkPosition * 0.6662F) * 1.4F * walkSpeed;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ModelPart getHead() {
|
||||
return this.head;
|
||||
}
|
||||
}
|
||||
+58
@@ -0,0 +1,58 @@
|
||||
package fr.koka99cab.happy_creeper.client.renderer;
|
||||
|
||||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
import com.mojang.math.Axis;
|
||||
import fr.koka99cab.happy_creeper.client.model.HappyCreeperModel;
|
||||
import net.minecraft.client.renderer.SubmitNodeCollector;
|
||||
import net.minecraft.client.renderer.block.BlockModelRenderState;
|
||||
import net.minecraft.client.renderer.entity.LivingEntityRenderer;
|
||||
import net.minecraft.client.renderer.entity.RenderLayerParent;
|
||||
import net.minecraft.client.renderer.entity.layers.RenderLayer;
|
||||
|
||||
public final class HappyCreeperFlowerLayer extends RenderLayer<HappyCreeperRenderState, HappyCreeperModel> {
|
||||
public HappyCreeperFlowerLayer(RenderLayerParent<HappyCreeperRenderState, HappyCreeperModel> renderLayerParent) {
|
||||
super(renderLayerParent);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void submit(PoseStack poseStack, SubmitNodeCollector submitNodeCollector, int packedLight, HappyCreeperRenderState happyCreeperRenderState, float limbAngle, float limbDistance) {
|
||||
BlockModelRenderState flowerBlock = happyCreeperRenderState.flowerBlock;
|
||||
|
||||
if (flowerBlock.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
boolean renderOutline = happyCreeperRenderState.appearsGlowing() && happyCreeperRenderState.isInvisible;
|
||||
if (happyCreeperRenderState.isInvisible && !renderOutline) {
|
||||
return;
|
||||
}
|
||||
|
||||
int overlay = LivingEntityRenderer.getOverlayCoords(happyCreeperRenderState, 0.0F);
|
||||
|
||||
poseStack.pushPose();
|
||||
this.getParentModel().getHead().translateAndRotate(poseStack);
|
||||
poseStack.translate(0.0F, -0.72F, 0.0F);
|
||||
poseStack.mulPose(Axis.YP.rotationDegrees(-45.0F));
|
||||
poseStack.scale(-0.7F, -0.7F, 0.7F);
|
||||
poseStack.translate(-0.5F, -0.5F, -0.5F);
|
||||
this.submitFlowerBlock(poseStack, submitNodeCollector, packedLight, renderOutline, happyCreeperRenderState.outlineColor, flowerBlock, overlay);
|
||||
poseStack.popPose();
|
||||
}
|
||||
|
||||
private void submitFlowerBlock(
|
||||
PoseStack poseStack,
|
||||
SubmitNodeCollector submitNodeCollector,
|
||||
int packedLight,
|
||||
boolean renderOutline,
|
||||
int outlineColor,
|
||||
BlockModelRenderState flowerBlock,
|
||||
int overlay
|
||||
) {
|
||||
if (renderOutline) {
|
||||
flowerBlock.submitOnlyOutline(poseStack, submitNodeCollector, packedLight, overlay, outlineColor);
|
||||
return;
|
||||
}
|
||||
|
||||
flowerBlock.submit(poseStack, submitNodeCollector, packedLight, overlay, outlineColor);
|
||||
}
|
||||
}
|
||||
+39
@@ -0,0 +1,39 @@
|
||||
package fr.koka99cab.happy_creeper.client.renderer;
|
||||
|
||||
import fr.koka99cab.happy_creeper.client.model.HappyCreeperModel;
|
||||
import net.minecraft.client.model.geom.EntityModelSet;
|
||||
import net.minecraft.client.model.geom.ModelLayers;
|
||||
import net.minecraft.client.renderer.entity.RenderLayerParent;
|
||||
import net.minecraft.client.renderer.entity.layers.EnergySwirlLayer;
|
||||
import net.minecraft.resources.Identifier;
|
||||
|
||||
public final class HappyCreeperPowerLayer extends EnergySwirlLayer<HappyCreeperRenderState, HappyCreeperModel> {
|
||||
private static final Identifier POWER_TEXTURE = Identifier.withDefaultNamespace("textures/entity/creeper/creeper_armor.png");
|
||||
|
||||
private final HappyCreeperModel model;
|
||||
|
||||
public HappyCreeperPowerLayer(RenderLayerParent<HappyCreeperRenderState, HappyCreeperModel> renderLayerParent, EntityModelSet entityModelSet) {
|
||||
super(renderLayerParent);
|
||||
this.model = new HappyCreeperModel(entityModelSet.bakeLayer(ModelLayers.CREEPER_ARMOR));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isPowered(HappyCreeperRenderState happyCreeperRenderState) {
|
||||
return happyCreeperRenderState.isPowered;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected float xOffset(float ageInTicks) {
|
||||
return ageInTicks * 0.01F;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Identifier getTextureLocation() {
|
||||
return POWER_TEXTURE;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected HappyCreeperModel model() {
|
||||
return this.model;
|
||||
}
|
||||
}
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
package fr.koka99cab.happy_creeper.client.renderer;
|
||||
|
||||
import net.minecraft.client.renderer.block.BlockModelRenderState;
|
||||
import net.minecraft.client.renderer.entity.state.CreeperRenderState;
|
||||
|
||||
public final class HappyCreeperRenderState extends CreeperRenderState {
|
||||
public final BlockModelRenderState flowerBlock = new BlockModelRenderState();
|
||||
}
|
||||
+60
@@ -0,0 +1,60 @@
|
||||
package fr.koka99cab.happy_creeper.client.renderer;
|
||||
|
||||
import fr.koka99cab.happy_creeper.HappyCreeperMod;
|
||||
import fr.koka99cab.happy_creeper.client.model.HappyCreeperModel;
|
||||
import fr.koka99cab.happy_creeper.entity.HappyCreeperEntity;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.model.geom.ModelLayers;
|
||||
import net.minecraft.client.renderer.block.BlockModelResolver;
|
||||
import net.minecraft.client.renderer.block.model.BlockDisplayContext;
|
||||
import net.minecraft.client.renderer.entity.EntityRendererProvider;
|
||||
import net.minecraft.client.renderer.entity.MobRenderer;
|
||||
import net.minecraft.resources.Identifier;
|
||||
|
||||
public final class HappyCreeperRenderer extends MobRenderer<HappyCreeperEntity, HappyCreeperRenderState, HappyCreeperModel> {
|
||||
private static final BlockDisplayContext BLOCK_DISPLAY_CONTEXT = BlockDisplayContext.create();
|
||||
private static final Identifier CREEPER_TEXTURE = Identifier.fromNamespaceAndPath(HappyCreeperMod.MOD_ID, "textures/entity/creeper.png");
|
||||
private static final Identifier HAPPY_CREEPER_TEXTURE = Identifier.fromNamespaceAndPath(HappyCreeperMod.MOD_ID, "textures/entity/happy_creeper.png");
|
||||
private static final Identifier FALLBACK_TEXTURE = Identifier.withDefaultNamespace("textures/entity/creeper/creeper.png");
|
||||
|
||||
private final BlockModelResolver blockModelResolver;
|
||||
|
||||
public HappyCreeperRenderer(EntityRendererProvider.Context context) {
|
||||
super(context, new HappyCreeperModel(context.bakeLayer(ModelLayers.CREEPER)), 0.5F);
|
||||
this.blockModelResolver = context.getBlockModelResolver();
|
||||
this.addLayer(new HappyCreeperPowerLayer(this, context.getModelSet()));
|
||||
this.addLayer(new HappyCreeperFlowerLayer(this));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Identifier getTextureLocation(HappyCreeperRenderState happyCreeperRenderState) {
|
||||
if (!Minecraft.getInstance().getResourceManager().getResourceStack(CREEPER_TEXTURE).isEmpty()) {
|
||||
return CREEPER_TEXTURE;
|
||||
}
|
||||
|
||||
if (!Minecraft.getInstance().getResourceManager().getResourceStack(HAPPY_CREEPER_TEXTURE).isEmpty()) {
|
||||
return HAPPY_CREEPER_TEXTURE;
|
||||
}
|
||||
|
||||
return FALLBACK_TEXTURE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HappyCreeperRenderState createRenderState() {
|
||||
return new HappyCreeperRenderState();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void extractRenderState(HappyCreeperEntity happyCreeperEntity, HappyCreeperRenderState happyCreeperRenderState, float partialTick) {
|
||||
super.extractRenderState(happyCreeperEntity, happyCreeperRenderState, partialTick);
|
||||
happyCreeperRenderState.isPowered = happyCreeperEntity.isPowered();
|
||||
happyCreeperRenderState.swelling = 0.0F;
|
||||
|
||||
if (happyCreeperEntity.hasFlower()) {
|
||||
this.blockModelResolver.update(happyCreeperRenderState.flowerBlock, happyCreeperEntity.getFlowerBlockStateForRendering(), BLOCK_DISPLAY_CONTEXT);
|
||||
return;
|
||||
}
|
||||
|
||||
happyCreeperRenderState.flowerBlock.clear();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package fr.koka99cab.happy_creeper;
|
||||
|
||||
import fr.koka99cab.happy_creeper.registry.ModEntityTypes;
|
||||
import fr.koka99cab.happy_creeper.registry.ModEntityInteractions;
|
||||
import net.fabricmc.api.ModInitializer;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public final class HappyCreeperMod implements ModInitializer {
|
||||
public static final String MOD_ID = "happy_creeper";
|
||||
public static final Logger LOGGER = LoggerFactory.getLogger(MOD_ID);
|
||||
|
||||
@Override
|
||||
public void onInitialize() {
|
||||
ModEntityTypes.register();
|
||||
ModEntityInteractions.register();
|
||||
LOGGER.info("Happy Creeper is waking up");
|
||||
}
|
||||
}
|
||||
+350
@@ -0,0 +1,350 @@
|
||||
package fr.koka99cab.happy_creeper.entity;
|
||||
|
||||
import fr.koka99cab.happy_creeper.entity.ai.HappyCreeperFollowPlayerGoal;
|
||||
import fr.koka99cab.happy_creeper.registry.ModEntityTypes;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.registries.BuiltInRegistries;
|
||||
import net.minecraft.network.syncher.EntityDataAccessor;
|
||||
import net.minecraft.network.syncher.EntityDataSerializers;
|
||||
import net.minecraft.network.syncher.SynchedEntityData;
|
||||
import net.minecraft.resources.Identifier;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.sounds.SoundEvent;
|
||||
import net.minecraft.sounds.SoundEvents;
|
||||
import net.minecraft.util.RandomSource;
|
||||
import net.minecraft.world.DifficultyInstance;
|
||||
import net.minecraft.world.InteractionHand;
|
||||
import net.minecraft.world.InteractionResult;
|
||||
import net.minecraft.world.damagesource.DamageSource;
|
||||
import net.minecraft.world.entity.AgeableMob;
|
||||
import net.minecraft.world.entity.ConversionParams;
|
||||
import net.minecraft.world.entity.EntitySpawnReason;
|
||||
import net.minecraft.world.entity.EntityType;
|
||||
import net.minecraft.world.entity.Mob;
|
||||
import net.minecraft.world.entity.SpawnGroupData;
|
||||
import net.minecraft.world.entity.ai.attributes.AttributeSupplier;
|
||||
import net.minecraft.world.entity.ai.attributes.Attributes;
|
||||
import net.minecraft.world.entity.ai.goal.BreedGoal;
|
||||
import net.minecraft.world.entity.ai.goal.FloatGoal;
|
||||
import net.minecraft.world.entity.ai.goal.FollowParentGoal;
|
||||
import net.minecraft.world.entity.ai.goal.LookAtPlayerGoal;
|
||||
import net.minecraft.world.entity.ai.goal.RandomLookAroundGoal;
|
||||
import net.minecraft.world.entity.ai.goal.WaterAvoidingRandomStrollGoal;
|
||||
import net.minecraft.world.entity.animal.Animal;
|
||||
import net.minecraft.world.entity.monster.Monster;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.item.Item;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.item.Items;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.ServerLevelAccessor;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.block.Blocks;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.level.storage.ValueInput;
|
||||
import net.minecraft.world.level.storage.ValueOutput;
|
||||
|
||||
public final class HappyCreeperEntity extends Animal {
|
||||
private static final EntityDataAccessor<String> FLOWER_ID = SynchedEntityData.defineId(HappyCreeperEntity.class, EntityDataSerializers.STRING);
|
||||
private static final EntityDataAccessor<Boolean> HAS_FLOWER = SynchedEntityData.defineId(HappyCreeperEntity.class, EntityDataSerializers.BOOLEAN);
|
||||
private static final EntityDataAccessor<Boolean> IS_POWERED = SynchedEntityData.defineId(HappyCreeperEntity.class, EntityDataSerializers.BOOLEAN);
|
||||
private static final List<Item> FLOWERS = List.of(
|
||||
Items.DANDELION,
|
||||
Items.POPPY,
|
||||
Items.BLUE_ORCHID,
|
||||
Items.ALLIUM,
|
||||
Items.AZURE_BLUET,
|
||||
Items.RED_TULIP,
|
||||
Items.ORANGE_TULIP,
|
||||
Items.WHITE_TULIP,
|
||||
Items.PINK_TULIP,
|
||||
Items.OXEYE_DAISY,
|
||||
Items.CORNFLOWER,
|
||||
Items.LILY_OF_THE_VALLEY,
|
||||
Items.TORCHFLOWER
|
||||
);
|
||||
|
||||
private static final String FLOWER_ID_KEY = "HappyFlowerId";
|
||||
private static final String HAS_FLOWER_KEY = "HappyFlowerReady";
|
||||
private static final String FLOWER_REGROW_TICKS_KEY = "HappyFlowerRegrowTicks";
|
||||
private static final String FOLLOW_TARGET_KEY = "HappyFollowTarget";
|
||||
private static final String POWERED_KEY = "HappyPowered";
|
||||
private static final int FLOWER_MIN_REGROW_TICKS = 20 * 45;
|
||||
private static final int FLOWER_MAX_REGROW_TICKS = 20 * 90;
|
||||
|
||||
private UUID rememberedPlayerUuid;
|
||||
private int flowerRegrowTicks;
|
||||
|
||||
public HappyCreeperEntity(EntityType<? extends HappyCreeperEntity> entityType, Level level) {
|
||||
super(entityType, level);
|
||||
}
|
||||
|
||||
public static AttributeSupplier.Builder createAttributes() {
|
||||
return Animal.createAnimalAttributes()
|
||||
.add(Attributes.MAX_HEALTH, 20.0D)
|
||||
.add(Attributes.MOVEMENT_SPEED, 0.25D)
|
||||
.add(Attributes.FOLLOW_RANGE, 32.0D);
|
||||
}
|
||||
|
||||
public static boolean canSpawn(EntityType<HappyCreeperEntity> entityType, ServerLevelAccessor level, EntitySpawnReason spawnReason, BlockPos blockPos, RandomSource random) {
|
||||
return Mob.checkMobSpawnRules(entityType, level, spawnReason, blockPos, random)
|
||||
&& Monster.isDarkEnoughToSpawn(level, blockPos, random);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void defineSynchedData(SynchedEntityData.Builder builder) {
|
||||
super.defineSynchedData(builder);
|
||||
builder.define(FLOWER_ID, "");
|
||||
builder.define(HAS_FLOWER, true);
|
||||
builder.define(IS_POWERED, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void registerGoals() {
|
||||
this.goalSelector.addGoal(0, new FloatGoal(this));
|
||||
this.goalSelector.addGoal(1, new BreedGoal(this, 1.0D));
|
||||
this.goalSelector.addGoal(2, new HappyCreeperFollowPlayerGoal(this, 1.1D, 2.5F));
|
||||
this.goalSelector.addGoal(3, new FollowParentGoal(this, 1.1D));
|
||||
this.goalSelector.addGoal(4, new WaterAvoidingRandomStrollGoal(this, 0.95D));
|
||||
this.goalSelector.addGoal(5, new LookAtPlayerGoal(this, Player.class, 8.0F));
|
||||
this.goalSelector.addGoal(6, new RandomLookAroundGoal(this));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void customServerAiStep(ServerLevel serverLevel) {
|
||||
super.customServerAiStep(serverLevel);
|
||||
this.ensureFlowerAssigned();
|
||||
|
||||
if (this.rememberedPlayerUuid == null && this.tickCount % 20 == 0) {
|
||||
this.rememberNearbyPlayer(serverLevel);
|
||||
}
|
||||
|
||||
if (!this.hasFlower() && this.flowerRegrowTicks > 0) {
|
||||
this.flowerRegrowTicks--;
|
||||
|
||||
if (this.flowerRegrowTicks == 0) {
|
||||
this.setFlowerReady(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public SpawnGroupData finalizeSpawn(ServerLevelAccessor level, DifficultyInstance difficulty, EntitySpawnReason spawnReason, SpawnGroupData spawnGroupData) {
|
||||
SpawnGroupData finalizedSpawn = super.finalizeSpawn(level, difficulty, spawnReason, spawnGroupData);
|
||||
this.assignRandomFlower();
|
||||
this.setFlowerReady(true);
|
||||
this.flowerRegrowTicks = 0;
|
||||
return finalizedSpawn;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void addAdditionalSaveData(ValueOutput output) {
|
||||
super.addAdditionalSaveData(output);
|
||||
output.putString(FLOWER_ID_KEY, this.entityData.get(FLOWER_ID));
|
||||
output.putBoolean(HAS_FLOWER_KEY, this.hasFlower());
|
||||
output.putInt(FLOWER_REGROW_TICKS_KEY, this.flowerRegrowTicks);
|
||||
output.putBoolean(POWERED_KEY, this.isPowered());
|
||||
|
||||
if (this.rememberedPlayerUuid != null) {
|
||||
output.putString(FOLLOW_TARGET_KEY, this.rememberedPlayerUuid.toString());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void readAdditionalSaveData(ValueInput input) {
|
||||
super.readAdditionalSaveData(input);
|
||||
String flowerId = input.getStringOr(FLOWER_ID_KEY, "");
|
||||
this.entityData.set(FLOWER_ID, flowerId);
|
||||
this.entityData.set(HAS_FLOWER, input.getBooleanOr(HAS_FLOWER_KEY, true));
|
||||
this.entityData.set(IS_POWERED, input.getBooleanOr(POWERED_KEY, false));
|
||||
this.flowerRegrowTicks = input.getIntOr(FLOWER_REGROW_TICKS_KEY, 0);
|
||||
this.rememberedPlayerUuid = null;
|
||||
|
||||
input.getString(FOLLOW_TARGET_KEY).ifPresent(uuid -> {
|
||||
try {
|
||||
this.rememberedPlayerUuid = UUID.fromString(uuid);
|
||||
} catch (IllegalArgumentException ignored) {
|
||||
this.rememberedPlayerUuid = null;
|
||||
}
|
||||
});
|
||||
|
||||
this.ensureFlowerAssigned();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isFood(ItemStack itemStack) {
|
||||
return itemStack.is(Blocks.MOSS_BLOCK.asItem()) || itemStack.is(Blocks.MOSS_CARPET.asItem());
|
||||
}
|
||||
|
||||
@Override
|
||||
public InteractionResult mobInteract(Player player, InteractionHand interactionHand) {
|
||||
ItemStack heldItem = player.getItemInHand(interactionHand);
|
||||
|
||||
if (heldItem.is(Items.SHEARS) && this.hasFlower()) {
|
||||
if (this.level().isClientSide()) {
|
||||
return InteractionResult.SUCCESS;
|
||||
}
|
||||
|
||||
this.shearFlower(heldItem, player, interactionHand);
|
||||
return InteractionResult.SUCCESS_SERVER;
|
||||
}
|
||||
|
||||
return super.mobInteract(player, interactionHand);
|
||||
}
|
||||
|
||||
@Override
|
||||
public HappyCreeperEntity getBreedOffspring(ServerLevel serverLevel, AgeableMob ageableMob) {
|
||||
HappyCreeperEntity baby = ModEntityTypes.HAPPY_CREEPER.create(serverLevel, EntitySpawnReason.BREEDING);
|
||||
|
||||
if (baby != null) {
|
||||
baby.assignRandomFlower();
|
||||
baby.setFlowerReady(true);
|
||||
}
|
||||
|
||||
return baby;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected SoundEvent getHurtSound(DamageSource damageSource) {
|
||||
return SoundEvents.CREEPER_HURT;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected SoundEvent getDeathSound() {
|
||||
return SoundEvents.CREEPER_DEATH;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void thunderHit(ServerLevel serverLevel, net.minecraft.world.entity.LightningBolt lightningBolt) {
|
||||
super.thunderHit(serverLevel, lightningBolt);
|
||||
this.setPowered(true);
|
||||
}
|
||||
|
||||
public boolean hasFlower() {
|
||||
return this.entityData.get(HAS_FLOWER);
|
||||
}
|
||||
|
||||
public boolean isPowered() {
|
||||
return this.entityData.get(IS_POWERED);
|
||||
}
|
||||
|
||||
public ItemStack getFlowerStackForRendering() {
|
||||
if (!this.hasFlower()) {
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
|
||||
return new ItemStack(this.getFlowerItem());
|
||||
}
|
||||
|
||||
public BlockState getFlowerBlockStateForRendering() {
|
||||
if (!this.hasFlower()) {
|
||||
return Blocks.AIR.defaultBlockState();
|
||||
}
|
||||
|
||||
Block block = Block.byItem(this.getFlowerItem());
|
||||
return block.defaultBlockState();
|
||||
}
|
||||
|
||||
public void setFlowerItem(Item flowerItem) {
|
||||
Identifier flowerId = BuiltInRegistries.ITEM.getKey(flowerItem);
|
||||
this.entityData.set(FLOWER_ID, flowerId.toString());
|
||||
this.setFlowerReady(true);
|
||||
this.flowerRegrowTicks = 0;
|
||||
}
|
||||
|
||||
public void setPowered(boolean powered) {
|
||||
this.entityData.set(IS_POWERED, powered);
|
||||
}
|
||||
|
||||
public Player getRememberedPlayer() {
|
||||
if (this.rememberedPlayerUuid == null || !(this.level() instanceof ServerLevel serverLevel)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return serverLevel.getPlayerByUUID(this.rememberedPlayerUuid);
|
||||
}
|
||||
|
||||
public void rememberPlayer(Player player) {
|
||||
this.rememberedPlayerUuid = player.getUUID();
|
||||
}
|
||||
|
||||
private void shearFlower(ItemStack shears, Player player, InteractionHand interactionHand) {
|
||||
if (!(this.level() instanceof ServerLevel serverLevel)) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.playSound(SoundEvents.SHEEP_SHEAR, 1.0F, 1.0F);
|
||||
this.spawnAtLocation(serverLevel, new ItemStack(this.getFlowerItem()));
|
||||
shears.hurtAndBreak(1, player, interactionHand);
|
||||
this.convertTo(EntityType.CREEPER, ConversionParams.single(this, false, false), EntitySpawnReason.CONVERSION, creeper -> {
|
||||
MobConversionUtil.copyCommonState(this, creeper);
|
||||
|
||||
if (this.isPowered()) {
|
||||
net.minecraft.world.entity.LightningBolt lightningBolt = this.createConversionLightning(serverLevel, creeper);
|
||||
if (lightningBolt != null) {
|
||||
creeper.thunderHit(serverLevel, lightningBolt);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private net.minecraft.world.entity.LightningBolt createConversionLightning(ServerLevel serverLevel, Mob target) {
|
||||
net.minecraft.world.entity.LightningBolt lightningBolt = EntityType.LIGHTNING_BOLT.create(serverLevel, EntitySpawnReason.TRIGGERED);
|
||||
if (lightningBolt != null) {
|
||||
lightningBolt.copyPosition(target);
|
||||
}
|
||||
|
||||
return lightningBolt;
|
||||
}
|
||||
|
||||
private void ensureFlowerAssigned() {
|
||||
if (this.entityData.get(FLOWER_ID).isEmpty()) {
|
||||
this.assignRandomFlower();
|
||||
}
|
||||
}
|
||||
|
||||
private void assignRandomFlower() {
|
||||
Item flower = FLOWERS.get(this.random.nextInt(FLOWERS.size()));
|
||||
this.setFlowerItem(flower);
|
||||
}
|
||||
|
||||
private Item getFlowerItem() {
|
||||
Identifier flowerId = Identifier.tryParse(this.entityData.get(FLOWER_ID));
|
||||
|
||||
if (flowerId == null) {
|
||||
return Items.DANDELION;
|
||||
}
|
||||
|
||||
return BuiltInRegistries.ITEM.getOptional(flowerId).orElse(Items.DANDELION);
|
||||
}
|
||||
|
||||
private void setFlowerReady(boolean hasFlower) {
|
||||
this.entityData.set(HAS_FLOWER, hasFlower);
|
||||
}
|
||||
|
||||
private void rememberNearbyPlayer(ServerLevel serverLevel) {
|
||||
Player rememberedPlayer = null;
|
||||
double bestDistanceSquared = 12.0D * 12.0D;
|
||||
|
||||
for (Player player : serverLevel.players()) {
|
||||
if (!player.isAlive() || player.isSpectator()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
double distanceSquared = this.distanceToSqr(player);
|
||||
|
||||
if (distanceSquared > bestDistanceSquared || !this.hasLineOfSight(player)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
rememberedPlayer = player;
|
||||
bestDistanceSquared = distanceSquared;
|
||||
}
|
||||
|
||||
if (rememberedPlayer != null) {
|
||||
this.rememberedPlayerUuid = rememberedPlayer.getUUID();
|
||||
}
|
||||
}
|
||||
}
|
||||
+36
@@ -0,0 +1,36 @@
|
||||
package fr.koka99cab.happy_creeper.entity;
|
||||
|
||||
import net.minecraft.world.entity.Mob;
|
||||
|
||||
public final class MobConversionUtil {
|
||||
private MobConversionUtil() {
|
||||
}
|
||||
|
||||
public static <T extends Mob> void copyCommonState(Mob source, T target) {
|
||||
target.copyPosition(source);
|
||||
target.setYRot(source.getYRot());
|
||||
target.setXRot(source.getXRot());
|
||||
target.setYBodyRot(source.yBodyRot);
|
||||
target.setYHeadRot(source.getYHeadRot());
|
||||
target.yBodyRotO = source.yBodyRotO;
|
||||
target.yHeadRotO = source.yHeadRotO;
|
||||
target.setDeltaMovement(source.getDeltaMovement());
|
||||
target.setPose(source.getPose());
|
||||
target.setHealth(Math.min(target.getMaxHealth(), source.getHealth()));
|
||||
target.setSilent(source.isSilent());
|
||||
target.setInvulnerable(source.isInvulnerable());
|
||||
|
||||
if (source.isPersistenceRequired()) {
|
||||
target.setPersistenceRequired();
|
||||
}
|
||||
|
||||
if (source.isNoAi()) {
|
||||
target.setNoAi(true);
|
||||
}
|
||||
|
||||
if (source.hasCustomName()) {
|
||||
target.setCustomName(source.getCustomName());
|
||||
target.setCustomNameVisible(source.isCustomNameVisible());
|
||||
}
|
||||
}
|
||||
}
|
||||
+70
@@ -0,0 +1,70 @@
|
||||
package fr.koka99cab.happy_creeper.entity.ai;
|
||||
|
||||
import fr.koka99cab.happy_creeper.entity.HappyCreeperEntity;
|
||||
import java.util.EnumSet;
|
||||
import net.minecraft.world.entity.ai.goal.Goal;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
|
||||
public final class HappyCreeperFollowPlayerGoal extends Goal {
|
||||
private final HappyCreeperEntity happyCreeper;
|
||||
private final double speedModifier;
|
||||
private final float stopDistance;
|
||||
private Player player;
|
||||
private int recalculatePathTicks;
|
||||
|
||||
public HappyCreeperFollowPlayerGoal(HappyCreeperEntity happyCreeper, double speedModifier, float stopDistance) {
|
||||
this.happyCreeper = happyCreeper;
|
||||
this.speedModifier = speedModifier;
|
||||
this.stopDistance = stopDistance;
|
||||
this.setFlags(EnumSet.of(Goal.Flag.MOVE, Goal.Flag.LOOK));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canUse() {
|
||||
this.player = this.happyCreeper.getRememberedPlayer();
|
||||
return this.player != null && this.player.isAlive();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canContinueToUse() {
|
||||
this.player = this.happyCreeper.getRememberedPlayer();
|
||||
return this.player != null && this.player.isAlive();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void start() {
|
||||
this.recalculatePathTicks = 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stop() {
|
||||
this.player = null;
|
||||
this.happyCreeper.getNavigation().stop();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean requiresUpdateEveryTick() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void tick() {
|
||||
if (this.player == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.happyCreeper.getLookControl().setLookAt(this.player, 10.0F, this.happyCreeper.getMaxHeadXRot());
|
||||
double distanceToPlayer = this.happyCreeper.distanceToSqr(this.player);
|
||||
double stopDistanceSquared = this.stopDistance * this.stopDistance;
|
||||
|
||||
if (distanceToPlayer <= stopDistanceSquared) {
|
||||
this.happyCreeper.getNavigation().stop();
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.recalculatePathTicks-- <= 0) {
|
||||
this.recalculatePathTicks = 10;
|
||||
this.happyCreeper.getNavigation().moveTo(this.player, this.speedModifier);
|
||||
}
|
||||
}
|
||||
}
|
||||
+62
@@ -0,0 +1,62 @@
|
||||
package fr.koka99cab.happy_creeper.registry;
|
||||
|
||||
import fr.koka99cab.happy_creeper.entity.HappyCreeperEntity;
|
||||
import fr.koka99cab.happy_creeper.entity.MobConversionUtil;
|
||||
import net.fabricmc.fabric.api.event.player.UseEntityCallback;
|
||||
import net.minecraft.tags.ItemTags;
|
||||
import net.minecraft.world.InteractionHand;
|
||||
import net.minecraft.world.InteractionResult;
|
||||
import net.minecraft.world.entity.ConversionParams;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.entity.EntitySpawnReason;
|
||||
import net.minecraft.world.entity.monster.Creeper;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.phys.EntityHitResult;
|
||||
|
||||
public final class ModEntityInteractions {
|
||||
private ModEntityInteractions() {
|
||||
}
|
||||
|
||||
public static void register() {
|
||||
UseEntityCallback.EVENT.register(ModEntityInteractions::interactWithEntity);
|
||||
}
|
||||
|
||||
private static InteractionResult interactWithEntity(Player player, Level level, InteractionHand interactionHand, Entity entity, EntityHitResult entityHitResult) {
|
||||
if (!(entity instanceof Creeper creeper)) {
|
||||
return InteractionResult.PASS;
|
||||
}
|
||||
|
||||
ItemStack heldItem = player.getItemInHand(interactionHand);
|
||||
if (!heldItem.is(ItemTags.FLOWERS)) {
|
||||
return InteractionResult.PASS;
|
||||
}
|
||||
|
||||
if (level.isClientSide()) {
|
||||
return InteractionResult.SUCCESS;
|
||||
}
|
||||
|
||||
HappyCreeperEntity happyCreeper = creeper.convertTo(
|
||||
ModEntityTypes.HAPPY_CREEPER,
|
||||
ConversionParams.single(creeper, false, false),
|
||||
EntitySpawnReason.CONVERSION,
|
||||
convertedHappyCreeper -> {
|
||||
MobConversionUtil.copyCommonState(creeper, convertedHappyCreeper);
|
||||
convertedHappyCreeper.setPowered(creeper.isPowered());
|
||||
convertedHappyCreeper.setFlowerItem(heldItem.getItem());
|
||||
convertedHappyCreeper.rememberPlayer(player);
|
||||
}
|
||||
);
|
||||
|
||||
if (happyCreeper == null) {
|
||||
return InteractionResult.PASS;
|
||||
}
|
||||
|
||||
if (!player.getAbilities().instabuild) {
|
||||
heldItem.shrink(1);
|
||||
}
|
||||
|
||||
return InteractionResult.SUCCESS_SERVER;
|
||||
}
|
||||
}
|
||||
+41
@@ -0,0 +1,41 @@
|
||||
package fr.koka99cab.happy_creeper.registry;
|
||||
|
||||
import fr.koka99cab.happy_creeper.HappyCreeperMod;
|
||||
import fr.koka99cab.happy_creeper.entity.HappyCreeperEntity;
|
||||
import net.fabricmc.fabric.api.biome.v1.BiomeModifications;
|
||||
import net.fabricmc.fabric.api.biome.v1.BiomeSelectors;
|
||||
import net.fabricmc.fabric.api.object.builder.v1.entity.FabricEntityTypeBuilder;
|
||||
import net.minecraft.core.Registry;
|
||||
import net.minecraft.core.registries.BuiltInRegistries;
|
||||
import net.minecraft.core.registries.Registries;
|
||||
import net.minecraft.resources.Identifier;
|
||||
import net.minecraft.resources.ResourceKey;
|
||||
import net.minecraft.world.entity.EntityDimensions;
|
||||
import net.minecraft.world.entity.EntityType;
|
||||
import net.minecraft.world.entity.MobCategory;
|
||||
import net.minecraft.world.entity.SpawnPlacementTypes;
|
||||
import net.minecraft.world.level.levelgen.Heightmap;
|
||||
|
||||
public final class ModEntityTypes {
|
||||
public static final Identifier HAPPY_CREEPER_ID = Identifier.fromNamespaceAndPath(HappyCreeperMod.MOD_ID, "happy_creeper");
|
||||
public static final EntityType<HappyCreeperEntity> HAPPY_CREEPER = Registry.register(
|
||||
BuiltInRegistries.ENTITY_TYPE,
|
||||
HAPPY_CREEPER_ID,
|
||||
FabricEntityTypeBuilder.createMob()
|
||||
.mobCategory(MobCategory.CREATURE)
|
||||
.entityFactory(HappyCreeperEntity::new)
|
||||
.dimensions(EntityDimensions.scalable(0.6F, 1.7F))
|
||||
.defaultAttributes(HappyCreeperEntity::createAttributes)
|
||||
.spawnPlacement(SpawnPlacementTypes.ON_GROUND, Heightmap.Types.MOTION_BLOCKING_NO_LEAVES, HappyCreeperEntity::canSpawn)
|
||||
.trackRangeBlocks(10)
|
||||
.trackedUpdateRate(2)
|
||||
.build(ResourceKey.create(Registries.ENTITY_TYPE, HAPPY_CREEPER_ID))
|
||||
);
|
||||
|
||||
private ModEntityTypes() {
|
||||
}
|
||||
|
||||
public static void register() {
|
||||
BiomeModifications.addSpawn(BiomeSelectors.spawnsOneOf(EntityType.CREEPER), MobCategory.CREATURE, HAPPY_CREEPER, 5, 1, 1);
|
||||
}
|
||||
}
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 564 B |
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"entity.happy_creeper.happy_creeper": "Happy Creeper"
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"entity.happy_creeper.happy_creeper": "Happy Creeper"
|
||||
}
|
||||
BIN
Binary file not shown.
|
After Width: | Height: | Size: 3.1 KiB |
@@ -0,0 +1,27 @@
|
||||
{
|
||||
"schemaVersion": 1,
|
||||
"id": "happy_creeper",
|
||||
"version": "${version}",
|
||||
"name": "Happy-Creeper",
|
||||
"description": "Adds a passive Happy Creeper that follows players, carries a persistent flower, and can breed with moss.",
|
||||
"authors": [
|
||||
"KOKA99CAB"
|
||||
],
|
||||
"license": "LGPL-3.0-or-later",
|
||||
"icon": "assets/happy_creeper/icon.png",
|
||||
"environment": "*",
|
||||
"entrypoints": {
|
||||
"main": [
|
||||
"fr.koka99cab.happy_creeper.HappyCreeperMod"
|
||||
],
|
||||
"client": [
|
||||
"fr.koka99cab.happy_creeper.client.HappyCreeperClient"
|
||||
]
|
||||
},
|
||||
"depends": {
|
||||
"fabricloader": ">=0.19.2",
|
||||
"minecraft": "~26.1.2",
|
||||
"java": ">=25",
|
||||
"fabric-api": "*"
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user