Initial sanctuary sources
This commit is contained in:
File diff suppressed because one or more lines are too long
@@ -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 {
|
||||
"real_ghost" {
|
||||
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=real_ghost
|
||||
|
||||
# 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
|
||||
@@ -0,0 +1,11 @@
|
||||
pluginManagement {
|
||||
repositories {
|
||||
maven {
|
||||
name = "Fabric"
|
||||
url = "https://maven.fabricmc.net/"
|
||||
}
|
||||
gradlePluginPortal()
|
||||
}
|
||||
}
|
||||
|
||||
rootProject.name = "real_ghost"
|
||||
@@ -0,0 +1,16 @@
|
||||
package fr.koka99cab.real_ghost.client;
|
||||
|
||||
import fr.koka99cab.real_ghost.client.model.GhostModel;
|
||||
import fr.koka99cab.real_ghost.client.renderer.GhostRenderer;
|
||||
import fr.koka99cab.real_ghost.registry.ModEntityTypes;
|
||||
import net.fabricmc.api.ClientModInitializer;
|
||||
import net.fabricmc.fabric.api.client.rendering.v1.EntityRendererRegistry;
|
||||
import net.fabricmc.fabric.api.client.rendering.v1.ModelLayerRegistry;
|
||||
|
||||
public final class RealGhostClient implements ClientModInitializer {
|
||||
@Override
|
||||
public void onInitializeClient() {
|
||||
ModelLayerRegistry.registerModelLayer(GhostModel.LAYER_LOCATION, GhostModel::createBodyLayer);
|
||||
EntityRendererRegistry.register(ModEntityTypes.GHOST, GhostRenderer::new);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,191 @@
|
||||
package fr.koka99cab.real_ghost.client.model;
|
||||
|
||||
import fr.koka99cab.real_ghost.RealGhostMod;
|
||||
import fr.koka99cab.real_ghost.client.renderer.GhostRenderState;
|
||||
import fr.koka99cab.real_ghost.entity.GhostVariant;
|
||||
import java.util.EnumMap;
|
||||
import java.util.Map;
|
||||
import net.minecraft.client.model.EntityModel;
|
||||
import net.minecraft.client.model.geom.ModelLayerLocation;
|
||||
import net.minecraft.client.model.geom.ModelPart;
|
||||
import net.minecraft.client.model.geom.PartPose;
|
||||
import net.minecraft.client.model.geom.builders.CubeListBuilder;
|
||||
import net.minecraft.client.model.geom.builders.LayerDefinition;
|
||||
import net.minecraft.client.model.geom.builders.MeshDefinition;
|
||||
import net.minecraft.client.model.geom.builders.PartDefinition;
|
||||
import net.minecraft.client.renderer.rendertype.RenderTypes;
|
||||
import net.minecraft.util.Mth;
|
||||
|
||||
public final class GhostModel extends EntityModel<GhostRenderState> {
|
||||
public static final ModelLayerLocation LAYER_LOCATION = new ModelLayerLocation(RealGhostMod.id("ghost"), "main");
|
||||
private static final float DEG_TO_RAD = (float)(Math.PI / 180.0D);
|
||||
|
||||
private final Map<GhostVariant, ModelPart> variantRoots = new EnumMap<>(GhostVariant.class);
|
||||
private final Map<GhostVariant, ModelPart> heads = new EnumMap<>(GhostVariant.class);
|
||||
private final Map<GhostVariant, ModelPart> rightArms = new EnumMap<>(GhostVariant.class);
|
||||
private final Map<GhostVariant, ModelPart> leftArms = new EnumMap<>(GhostVariant.class);
|
||||
private final Map<GhostVariant, ModelPart> torsos = new EnumMap<>(GhostVariant.class);
|
||||
|
||||
public GhostModel(ModelPart root) {
|
||||
super(root, RenderTypes::entityCutout);
|
||||
|
||||
for (GhostVariant variant : GhostVariant.values()) {
|
||||
ModelPart variantRoot = root.getChild(variant.modelName());
|
||||
this.variantRoots.put(variant, variantRoot);
|
||||
this.heads.put(variant, variantRoot.getChild("head"));
|
||||
this.torsos.put(variant, variantRoot.getChild("torso"));
|
||||
this.rightArms.put(variant, variantRoot.getChild("right_arm"));
|
||||
this.leftArms.put(variant, variantRoot.getChild("left_arm"));
|
||||
}
|
||||
}
|
||||
|
||||
public static LayerDefinition createBodyLayer() {
|
||||
MeshDefinition mesh = new MeshDefinition();
|
||||
PartDefinition root = mesh.getRoot();
|
||||
|
||||
addVariant(root, GhostVariant.SPOOK, false, false);
|
||||
addVariant(root, GhostVariant.WRAITH, false, false);
|
||||
addVariant(root, GhostVariant.ILLAGER, true, false);
|
||||
addVariant(root, GhostVariant.ECLIPSE, false, false);
|
||||
|
||||
return LayerDefinition.create(mesh, 64, 64);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setupAnim(GhostRenderState state) {
|
||||
super.setupAnim(state);
|
||||
|
||||
for (ModelPart root : this.variantRoots.values()) {
|
||||
root.visible = false;
|
||||
}
|
||||
|
||||
ModelPart variantRoot = this.variantRoots.getOrDefault(state.variant, this.variantRoots.get(GhostVariant.SPOOK));
|
||||
ModelPart head = this.heads.getOrDefault(state.variant, this.heads.get(GhostVariant.SPOOK));
|
||||
ModelPart torso = this.torsos.getOrDefault(state.variant, this.torsos.get(GhostVariant.SPOOK));
|
||||
ModelPart rightArm = this.rightArms.getOrDefault(state.variant, this.rightArms.get(GhostVariant.SPOOK));
|
||||
ModelPart leftArm = this.leftArms.getOrDefault(state.variant, this.leftArms.get(GhostVariant.SPOOK));
|
||||
float bob = Mth.sin(state.ageInTicks * 0.16F) * 0.75F;
|
||||
float sway = Mth.sin(state.ageInTicks * 0.09F) * 0.08F;
|
||||
float armSway = Mth.sin(state.ageInTicks * 0.22F) * 0.18F;
|
||||
|
||||
variantRoot.visible = true;
|
||||
variantRoot.yRot = 0.0F;
|
||||
variantRoot.y = bob - (state.isCharging ? 0.45F : 0.0F);
|
||||
variantRoot.zRot = sway;
|
||||
head.xRot = 15.0F * DEG_TO_RAD + (state.xRot * DEG_TO_RAD * 0.25F);
|
||||
head.yRot = state.yRot * DEG_TO_RAD * 0.18F;
|
||||
head.zRot = 2.5F * DEG_TO_RAD + sway * 0.5F;
|
||||
torso.xRot = (state.isCharging ? 27.5F : 17.5F) * DEG_TO_RAD;
|
||||
rightArm.xRot = (state.isCharging ? -98.0F : -72.0F) * DEG_TO_RAD + armSway;
|
||||
leftArm.xRot = (state.isCharging ? -98.0F : -72.0F) * DEG_TO_RAD - armSway;
|
||||
rightArm.zRot = -8.0F * DEG_TO_RAD - sway;
|
||||
leftArm.zRot = 8.0F * DEG_TO_RAD - sway;
|
||||
}
|
||||
|
||||
private static void addVariant(PartDefinition root, GhostVariant variant, boolean illager, boolean leaner) {
|
||||
String name = variant.modelName();
|
||||
PartDefinition ghost = root.addOrReplaceChild(name, CubeListBuilder.create(), PartPose.ZERO);
|
||||
int headHeight = illager ? 10 : 8;
|
||||
int torsoDepth = illager ? 6 : 4;
|
||||
int firstTorsoU = firstTorsoU(variant);
|
||||
int firstTorsoV = firstTorsoV(variant);
|
||||
int secondTorsoU = secondTorsoU(variant);
|
||||
int secondTorsoV = secondTorsoV(variant);
|
||||
|
||||
PartDefinition head = ghost.addOrReplaceChild(
|
||||
"head",
|
||||
CubeListBuilder.create()
|
||||
.texOffs(0, 0)
|
||||
.addBox(-4.0F, -headHeight, -4.0F, 8.0F, headHeight, 8.0F),
|
||||
PartPose.offsetAndRotation(0.0F, 0.0F, 0.0F, 15.0F * DEG_TO_RAD, 0.0F, 2.5F * DEG_TO_RAD)
|
||||
);
|
||||
|
||||
if (illager) {
|
||||
head.addOrReplaceChild(
|
||||
"nose",
|
||||
CubeListBuilder.create()
|
||||
.texOffs(16, 39)
|
||||
.addBox(-1.0F, -3.0F, -6.0F, 2.0F, 4.0F, 2.0F),
|
||||
PartPose.ZERO
|
||||
);
|
||||
}
|
||||
|
||||
ghost.addOrReplaceChild(
|
||||
"torso",
|
||||
CubeListBuilder.create()
|
||||
.texOffs(firstTorsoU, firstTorsoV)
|
||||
.addBox(-4.0F, 0.0F, -torsoDepth / 2.0F, 8.0F, 15.0F, torsoDepth),
|
||||
PartPose.offsetAndRotation(0.0F, 0.0F, 0.0F, (leaner ? 20.0F : 17.5F) * DEG_TO_RAD, 0.0F, 0.0F)
|
||||
).addOrReplaceChild(
|
||||
"inner_torso",
|
||||
CubeListBuilder.create()
|
||||
.texOffs(secondTorsoU, secondTorsoV)
|
||||
.addBox(-4.0F, 3.0F, -torsoDepth / 2.0F, 8.0F, 15.0F, torsoDepth),
|
||||
PartPose.ZERO
|
||||
);
|
||||
|
||||
PartDefinition rightArm = ghost.addOrReplaceChild(
|
||||
"right_arm",
|
||||
CubeListBuilder.create(),
|
||||
PartPose.offsetAndRotation(5.1F, 2.0F, 0.0F, -72.0F * DEG_TO_RAD, -7.75F * DEG_TO_RAD, -8.0F * DEG_TO_RAD)
|
||||
);
|
||||
rightArm.addOrReplaceChild(
|
||||
"upper",
|
||||
CubeListBuilder.create()
|
||||
.texOffs(32, 0)
|
||||
.addBox(-1.1F, -2.0F, -2.0F, 4.0F, 12.0F, 4.0F),
|
||||
PartPose.ZERO
|
||||
);
|
||||
rightArm.addOrReplaceChild(
|
||||
"lower",
|
||||
CubeListBuilder.create()
|
||||
.texOffs(0, illager ? 39 : 35)
|
||||
.addBox(-1.1F, 1.0F, -2.0F, 4.0F, 11.0F, 4.0F),
|
||||
PartPose.ZERO
|
||||
);
|
||||
|
||||
PartDefinition leftArm = ghost.addOrReplaceChild(
|
||||
"left_arm",
|
||||
CubeListBuilder.create(),
|
||||
PartPose.offsetAndRotation(-5.0F, 2.0F, 0.0F, -75.0F * DEG_TO_RAD, 5.15F * DEG_TO_RAD, 8.0F * DEG_TO_RAD)
|
||||
);
|
||||
leftArm.addOrReplaceChild(
|
||||
"upper",
|
||||
CubeListBuilder.create()
|
||||
.texOffs(32, 0)
|
||||
.addBox(-3.0F, -2.0F, -2.0F, 4.0F, 12.0F, 4.0F),
|
||||
PartPose.ZERO
|
||||
);
|
||||
leftArm.addOrReplaceChild(
|
||||
"lower",
|
||||
CubeListBuilder.create()
|
||||
.texOffs(0, illager ? 39 : 35)
|
||||
.addBox(-3.0F, 1.0F, -2.0F, 4.0F, 11.0F, 4.0F),
|
||||
PartPose.ZERO
|
||||
);
|
||||
}
|
||||
|
||||
private static int firstTorsoU(GhostVariant variant) {
|
||||
if (variant == GhostVariant.SPOOK) {
|
||||
return 24;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
private static int firstTorsoV(GhostVariant variant) {
|
||||
return variant == GhostVariant.ILLAGER ? 18 : 16;
|
||||
}
|
||||
|
||||
private static int secondTorsoU(GhostVariant variant) {
|
||||
if (variant == GhostVariant.SPOOK) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return variant == GhostVariant.ILLAGER ? 28 : 24;
|
||||
}
|
||||
|
||||
private static int secondTorsoV(GhostVariant variant) {
|
||||
return variant == GhostVariant.ILLAGER ? 18 : 16;
|
||||
}
|
||||
}
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
package fr.koka99cab.real_ghost.client.renderer;
|
||||
|
||||
import fr.koka99cab.real_ghost.entity.GhostVariant;
|
||||
import net.minecraft.client.renderer.entity.state.LivingEntityRenderState;
|
||||
|
||||
public final class GhostRenderState extends LivingEntityRenderState {
|
||||
public GhostVariant variant = GhostVariant.SPOOK;
|
||||
public boolean isCharging;
|
||||
}
|
||||
+51
@@ -0,0 +1,51 @@
|
||||
package fr.koka99cab.real_ghost.client.renderer;
|
||||
|
||||
import fr.koka99cab.real_ghost.RealGhostMod;
|
||||
import fr.koka99cab.real_ghost.client.model.GhostModel;
|
||||
import fr.koka99cab.real_ghost.entity.GhostEntity;
|
||||
import fr.koka99cab.real_ghost.entity.GhostVariant;
|
||||
import java.util.EnumMap;
|
||||
import java.util.Map;
|
||||
import net.minecraft.client.renderer.entity.EntityRendererProvider;
|
||||
import net.minecraft.client.renderer.entity.MobRenderer;
|
||||
import net.minecraft.resources.Identifier;
|
||||
|
||||
public final class GhostRenderer extends MobRenderer<GhostEntity, GhostRenderState, GhostModel> {
|
||||
private static final Map<GhostVariant, Identifier> TEXTURES = createTextureMap();
|
||||
|
||||
public GhostRenderer(EntityRendererProvider.Context context) {
|
||||
super(context, new GhostModel(context.bakeLayer(GhostModel.LAYER_LOCATION)), 0.0F);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Identifier getTextureLocation(GhostRenderState state) {
|
||||
return TEXTURES.getOrDefault(state.variant, TEXTURES.get(GhostVariant.SPOOK));
|
||||
}
|
||||
|
||||
@Override
|
||||
public GhostRenderState createRenderState() {
|
||||
return new GhostRenderState();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void extractRenderState(GhostEntity ghost, GhostRenderState state, float partialTick) {
|
||||
super.extractRenderState(ghost, state, partialTick);
|
||||
state.variant = ghost.getVariant();
|
||||
state.isCharging = ghost.isCharging();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getModelTint(GhostRenderState state) {
|
||||
return 0xFFFFFFFF;
|
||||
}
|
||||
|
||||
private static Map<GhostVariant, Identifier> createTextureMap() {
|
||||
EnumMap<GhostVariant, Identifier> textures = new EnumMap<>(GhostVariant.class);
|
||||
|
||||
for (GhostVariant variant : GhostVariant.values()) {
|
||||
textures.put(variant, RealGhostMod.id("textures/entity/ghost/" + variant.textureName() + ".png"));
|
||||
}
|
||||
|
||||
return textures;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
package fr.koka99cab.real_ghost;
|
||||
|
||||
import fr.koka99cab.real_ghost.registry.ModEntityTypes;
|
||||
import fr.koka99cab.real_ghost.registry.ModItems;
|
||||
import net.fabricmc.api.ModInitializer;
|
||||
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerEntityEvents;
|
||||
import net.minecraft.resources.Identifier;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.entity.EntityType;
|
||||
import net.minecraft.world.level.Level;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public final class RealGhostMod implements ModInitializer {
|
||||
public static final String MOD_ID = "real_ghost";
|
||||
public static final Logger LOGGER = LoggerFactory.getLogger(MOD_ID);
|
||||
|
||||
@Override
|
||||
public void onInitialize() {
|
||||
ModEntityTypes.register();
|
||||
ModItems.register();
|
||||
ServerEntityEvents.ENTITY_LOAD.register(RealGhostMod::removeVanillaPhantom);
|
||||
LOGGER.info("Real Ghost is drifting into the night");
|
||||
}
|
||||
|
||||
public static Identifier id(String path) {
|
||||
return Identifier.fromNamespaceAndPath(MOD_ID, path);
|
||||
}
|
||||
|
||||
private static void removeVanillaPhantom(Entity entity, Level level) {
|
||||
if (entity.getType() == EntityType.PHANTOM) {
|
||||
entity.discard();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,385 @@
|
||||
package fr.koka99cab.real_ghost.entity;
|
||||
|
||||
import net.minecraft.commands.arguments.EntityAnchorArgument.Anchor;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.particles.ParticleTypes;
|
||||
import net.minecraft.network.syncher.EntityDataAccessor;
|
||||
import net.minecraft.network.syncher.EntityDataSerializers;
|
||||
import net.minecraft.network.syncher.SynchedEntityData;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.sounds.SoundEvent;
|
||||
import net.minecraft.sounds.SoundEvents;
|
||||
import net.minecraft.sounds.SoundSource;
|
||||
import net.minecraft.util.Mth;
|
||||
import net.minecraft.util.RandomSource;
|
||||
import net.minecraft.world.DifficultyInstance;
|
||||
import net.minecraft.world.damagesource.DamageSource;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.entity.EntitySpawnReason;
|
||||
import net.minecraft.world.entity.EntityType;
|
||||
import net.minecraft.world.entity.LivingEntity;
|
||||
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.monster.Monster;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.ServerLevelAccessor;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.level.storage.ValueInput;
|
||||
import net.minecraft.world.level.storage.ValueOutput;
|
||||
import net.minecraft.world.phys.Vec3;
|
||||
|
||||
public final class GhostEntity extends Monster {
|
||||
private static final EntityDataAccessor<Integer> VARIANT = SynchedEntityData.defineId(GhostEntity.class, EntityDataSerializers.INT);
|
||||
private static final EntityDataAccessor<Boolean> CHARGING = SynchedEntityData.defineId(GhostEntity.class, EntityDataSerializers.BOOLEAN);
|
||||
private static final String VARIANT_KEY = "GhostVariant";
|
||||
private static final int HAUNT_TICKS = 20 * 5;
|
||||
private static final int MAX_CHARGE_TICKS = 20 * 3;
|
||||
private static final int TARGET_SCAN_INTERVAL = 20;
|
||||
private static final double TARGET_RANGE = 26.0D;
|
||||
private static final double HAUNT_RADIUS = 2.35D;
|
||||
private static final double ATTACK_REACH = 1.35D;
|
||||
private static final float ATTACK_DAMAGE = 5.0F;
|
||||
private static final int SPAWN_ROLL_BOUND = 3;
|
||||
private static final double MIN_LOOK_DISTANCE_SQR = 1.0E-4D;
|
||||
private static final float TARGET_TURN_DEGREES = 30.0F;
|
||||
private static final float WANDER_TURN_DEGREES = 12.0F;
|
||||
private static final float MAX_LOOK_PITCH = 35.0F;
|
||||
|
||||
private Vec3 wanderTarget;
|
||||
private int hauntTicks;
|
||||
private int chargeTicks;
|
||||
private int nextWhisperTicks;
|
||||
|
||||
public GhostEntity(EntityType<? extends GhostEntity> entityType, Level level) {
|
||||
super(entityType, level);
|
||||
this.setNoGravity(true);
|
||||
this.noPhysics = true;
|
||||
this.xpReward = 3;
|
||||
}
|
||||
|
||||
public static AttributeSupplier.Builder createAttributes() {
|
||||
return Monster.createMonsterAttributes()
|
||||
.add(Attributes.MAX_HEALTH, 14.0D)
|
||||
.add(Attributes.MOVEMENT_SPEED, 0.27D)
|
||||
.add(Attributes.FOLLOW_RANGE, TARGET_RANGE)
|
||||
.add(Attributes.ATTACK_DAMAGE, ATTACK_DAMAGE);
|
||||
}
|
||||
|
||||
public static boolean canSpawn(EntityType<GhostEntity> entityType, ServerLevelAccessor level, EntitySpawnReason spawnReason, BlockPos blockPos, RandomSource random) {
|
||||
return level.getLevel().dimension() == Level.OVERWORLD
|
||||
&& isNight(level.getLevel())
|
||||
&& random.nextInt(SPAWN_ROLL_BOUND) == 0
|
||||
&& Monster.checkMonsterSpawnRules(entityType, level, spawnReason, blockPos, random);
|
||||
}
|
||||
|
||||
public static boolean isNight(Level level) {
|
||||
long time = Math.floorMod(level.getDefaultClockTime(), 24000L);
|
||||
return time >= 13000L && time <= 23000L;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void defineSynchedData(SynchedEntityData.Builder builder) {
|
||||
super.defineSynchedData(builder);
|
||||
builder.define(VARIANT, GhostVariant.SPOOK.id());
|
||||
builder.define(CHARGING, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public SpawnGroupData finalizeSpawn(ServerLevelAccessor level, DifficultyInstance difficulty, EntitySpawnReason spawnReason, SpawnGroupData spawnGroupData) {
|
||||
SpawnGroupData finalizedSpawn = super.finalizeSpawn(level, difficulty, spawnReason, spawnGroupData);
|
||||
this.setVariant(GhostVariant.choose(this.random));
|
||||
this.setCharging(false);
|
||||
this.hauntTicks = this.random.nextInt(25);
|
||||
this.nextWhisperTicks = 12 + this.random.nextInt(26);
|
||||
return finalizedSpawn;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void addAdditionalSaveData(ValueOutput output) {
|
||||
super.addAdditionalSaveData(output);
|
||||
output.putInt(VARIANT_KEY, this.getVariant().id());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void readAdditionalSaveData(ValueInput input) {
|
||||
super.readAdditionalSaveData(input);
|
||||
this.setVariant(GhostVariant.byId(input.getIntOr(VARIANT_KEY, GhostVariant.SPOOK.id())));
|
||||
this.setCharging(false);
|
||||
this.setNoGravity(true);
|
||||
this.noPhysics = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void customServerAiStep(ServerLevel serverLevel) {
|
||||
super.customServerAiStep(serverLevel);
|
||||
this.setNoGravity(true);
|
||||
this.noPhysics = true;
|
||||
|
||||
if (this.tickCount > 20 && !isNight(serverLevel)) {
|
||||
this.vanish(serverLevel);
|
||||
return;
|
||||
}
|
||||
|
||||
LivingEntity target = this.getTarget();
|
||||
|
||||
if (target instanceof Player player && this.isValidHauntTarget(player)) {
|
||||
if (this.isCharging()) {
|
||||
this.tickCharge(serverLevel, player);
|
||||
} else {
|
||||
this.tickHaunt(serverLevel, player);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
this.clearHaunt();
|
||||
|
||||
if (this.tickCount % TARGET_SCAN_INTERVAL == 0) {
|
||||
ServerPlayer player = this.findTarget(serverLevel);
|
||||
|
||||
if (player != null) {
|
||||
this.setTarget(player);
|
||||
this.hauntTicks = 0;
|
||||
this.nextWhisperTicks = 6 + this.random.nextInt(18);
|
||||
this.playSound(SoundEvents.PHANTOM_AMBIENT, 0.35F, 1.45F + this.random.nextFloat() * 0.25F);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
this.tickWander();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void tick() {
|
||||
super.tick();
|
||||
this.setNoGravity(true);
|
||||
this.noPhysics = true;
|
||||
this.updateVisualRotation();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isPushable() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canBeCollidedWith(Entity entity) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void checkFallDamage(double fallDistance, boolean landed, BlockState state, BlockPos pos) {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected SoundEvent getAmbientSound() {
|
||||
return this.isCharging() ? SoundEvents.VEX_CHARGE : SoundEvents.PHANTOM_AMBIENT;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected SoundEvent getHurtSound(DamageSource damageSource) {
|
||||
return SoundEvents.VEX_HURT;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected SoundEvent getDeathSound() {
|
||||
return SoundEvents.PHANTOM_DEATH;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected float getSoundVolume() {
|
||||
return 0.45F;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getVoicePitch() {
|
||||
return 1.25F + this.random.nextFloat() * 0.35F;
|
||||
}
|
||||
|
||||
public GhostVariant getVariant() {
|
||||
return GhostVariant.byId(this.entityData.get(VARIANT));
|
||||
}
|
||||
|
||||
public void setVariant(GhostVariant variant) {
|
||||
this.entityData.set(VARIANT, variant.id());
|
||||
}
|
||||
|
||||
public boolean isCharging() {
|
||||
return this.entityData.get(CHARGING);
|
||||
}
|
||||
|
||||
private void setCharging(boolean charging) {
|
||||
this.entityData.set(CHARGING, charging);
|
||||
this.setAggressive(charging);
|
||||
}
|
||||
|
||||
private void tickHaunt(ServerLevel serverLevel, Player target) {
|
||||
this.hauntTicks++;
|
||||
this.chargeTicks = 0;
|
||||
|
||||
double angle = (this.tickCount * 0.18D) + (this.getId() * 0.45D);
|
||||
double bob = Mth.sin(this.tickCount * 0.18D) * 0.35D;
|
||||
Vec3 targetPos = target.position().add(
|
||||
Mth.cos(angle) * HAUNT_RADIUS,
|
||||
1.25D + bob,
|
||||
Mth.sin(angle) * HAUNT_RADIUS
|
||||
);
|
||||
|
||||
this.moveToward(targetPos, 0.18D, 0.62D);
|
||||
this.lookAt(Anchor.EYES, target.getEyePosition());
|
||||
this.whisperIfNeeded(serverLevel, target, angle);
|
||||
|
||||
if (this.hauntTicks >= HAUNT_TICKS) {
|
||||
this.setCharging(true);
|
||||
this.chargeTicks = 0;
|
||||
this.playSound(SoundEvents.PHANTOM_SWOOP, 0.8F, 1.15F);
|
||||
}
|
||||
}
|
||||
|
||||
private void tickCharge(ServerLevel serverLevel, Player target) {
|
||||
this.chargeTicks++;
|
||||
Vec3 targetPos = target.getEyePosition().add(0.0D, -0.2D, 0.0D);
|
||||
this.moveToward(targetPos, 0.38D, 1.35D);
|
||||
this.lookAt(Anchor.EYES, targetPos);
|
||||
|
||||
if (this.distanceToSqr(target) <= ATTACK_REACH * ATTACK_REACH) {
|
||||
float damage = (float)this.getAttributeValue(Attributes.ATTACK_DAMAGE);
|
||||
target.hurtServer(serverLevel, serverLevel.damageSources().mobAttack(this), damage);
|
||||
serverLevel.playSound(null, target.getX(), target.getEyeY(), target.getZ(), SoundEvents.PHANTOM_BITE, SoundSource.HOSTILE, 0.9F, 0.85F);
|
||||
this.vanish(serverLevel);
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.chargeTicks > MAX_CHARGE_TICKS) {
|
||||
this.vanish(serverLevel);
|
||||
}
|
||||
}
|
||||
|
||||
private void tickWander() {
|
||||
if (this.wanderTarget == null || this.position().distanceToSqr(this.wanderTarget) < 1.0D || this.random.nextInt(90) == 0) {
|
||||
this.wanderTarget = this.position().add(
|
||||
(this.random.nextDouble() - 0.5D) * 12.0D,
|
||||
(this.random.nextDouble() - 0.35D) * 3.0D,
|
||||
(this.random.nextDouble() - 0.5D) * 12.0D
|
||||
);
|
||||
}
|
||||
|
||||
this.moveToward(this.wanderTarget, 0.08D, 0.32D);
|
||||
}
|
||||
|
||||
private void updateVisualRotation() {
|
||||
LivingEntity target = this.getTarget();
|
||||
|
||||
if (target != null && target.isAlive()) {
|
||||
this.facePosition(target.getEyePosition(), TARGET_TURN_DEGREES, true);
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.wanderTarget != null && this.position().distanceToSqr(this.wanderTarget) > MIN_LOOK_DISTANCE_SQR) {
|
||||
this.facePosition(this.wanderTarget, WANDER_TURN_DEGREES, false);
|
||||
return;
|
||||
}
|
||||
|
||||
Vec3 movement = this.getDeltaMovement();
|
||||
if (movement.horizontalDistanceSqr() > MIN_LOOK_DISTANCE_SQR) {
|
||||
this.facePosition(this.position().add(movement), WANDER_TURN_DEGREES, false);
|
||||
}
|
||||
}
|
||||
|
||||
private void facePosition(Vec3 targetPos, float maxTurnDegrees, boolean pitchToTarget) {
|
||||
Vec3 from = this.getEyePosition();
|
||||
double deltaX = targetPos.x - from.x;
|
||||
double deltaY = targetPos.y - from.y;
|
||||
double deltaZ = targetPos.z - from.z;
|
||||
double horizontalDistance = Math.sqrt(deltaX * deltaX + deltaZ * deltaZ);
|
||||
|
||||
if ((horizontalDistance * horizontalDistance) + (deltaY * deltaY) <= MIN_LOOK_DISTANCE_SQR) {
|
||||
return;
|
||||
}
|
||||
|
||||
float targetYaw = (float)(Mth.atan2(deltaZ, deltaX) * Mth.RAD_TO_DEG) - 90.0F;
|
||||
float yaw = Mth.approachDegrees(this.getYRot(), targetYaw, maxTurnDegrees);
|
||||
this.setYRot(yaw);
|
||||
this.setYHeadRot(yaw);
|
||||
this.setYBodyRot(yaw);
|
||||
|
||||
float targetPitch = pitchToTarget ? (float)(-(Mth.atan2(deltaY, horizontalDistance) * Mth.RAD_TO_DEG)) : 0.0F;
|
||||
this.setXRot(Mth.approachDegrees(this.getXRot(), Mth.clamp(targetPitch, -MAX_LOOK_PITCH, MAX_LOOK_PITCH), maxTurnDegrees));
|
||||
}
|
||||
|
||||
private void whisperIfNeeded(ServerLevel serverLevel, Player target, double angle) {
|
||||
this.nextWhisperTicks--;
|
||||
|
||||
if (this.nextWhisperTicks > 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.nextWhisperTicks = 24 + this.random.nextInt(34);
|
||||
double side = this.random.nextBoolean() ? 1.0D : -1.0D;
|
||||
Vec3 ear = target.getEyePosition().add(Mth.cos(angle + side * 1.5708D) * 0.42D, -0.05D, Mth.sin(angle + side * 1.5708D) * 0.42D);
|
||||
SoundEvent whisper = this.random.nextBoolean() ? SoundEvents.BREEZE_INHALE : SoundEvents.BREEZE_IDLE_AIR;
|
||||
serverLevel.playSound(null, ear.x, ear.y, ear.z, whisper, SoundSource.HOSTILE, 0.22F, 1.65F + this.random.nextFloat() * 0.4F);
|
||||
serverLevel.sendParticles(ParticleTypes.WHITE_SMOKE, ear.x, ear.y, ear.z, 2, 0.035D, 0.02D, 0.035D, 0.002D);
|
||||
}
|
||||
|
||||
private void moveToward(Vec3 targetPos, double turnSpeed, double maxSpeed) {
|
||||
Vec3 toTarget = targetPos.subtract(this.position());
|
||||
double distance = toTarget.length();
|
||||
|
||||
if (distance < 0.001D) {
|
||||
this.setDeltaMovement(this.getDeltaMovement().scale(0.72D));
|
||||
return;
|
||||
}
|
||||
|
||||
Vec3 desired = toTarget.normalize().scale(maxSpeed);
|
||||
this.setDeltaMovement(this.getDeltaMovement().lerp(desired, turnSpeed));
|
||||
}
|
||||
|
||||
private ServerPlayer findTarget(ServerLevel serverLevel) {
|
||||
ServerPlayer closest = null;
|
||||
double closestDistance = TARGET_RANGE * TARGET_RANGE;
|
||||
|
||||
for (ServerPlayer player : serverLevel.players()) {
|
||||
if (!this.isValidHauntTarget(player)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
double distance = this.distanceToSqr(player);
|
||||
|
||||
if (distance < closestDistance) {
|
||||
closest = player;
|
||||
closestDistance = distance;
|
||||
}
|
||||
}
|
||||
|
||||
return closest;
|
||||
}
|
||||
|
||||
private boolean isValidHauntTarget(Player player) {
|
||||
return player.isAlive()
|
||||
&& !player.isSpectator()
|
||||
&& !player.isCreative()
|
||||
&& this.distanceToSqr(player) <= TARGET_RANGE * TARGET_RANGE;
|
||||
}
|
||||
|
||||
private void clearHaunt() {
|
||||
this.setTarget(null);
|
||||
this.setCharging(false);
|
||||
this.hauntTicks = 0;
|
||||
this.chargeTicks = 0;
|
||||
}
|
||||
|
||||
private void vanish(ServerLevel serverLevel) {
|
||||
if (this.isRemoved()) {
|
||||
return;
|
||||
}
|
||||
|
||||
serverLevel.sendParticles(ParticleTypes.SOUL, this.getX(), this.getY() + 0.85D, this.getZ(), 14, 0.35D, 0.55D, 0.35D, 0.02D);
|
||||
serverLevel.sendParticles(ParticleTypes.POOF, this.getX(), this.getY() + 0.65D, this.getZ(), 8, 0.25D, 0.25D, 0.25D, 0.01D);
|
||||
serverLevel.playSound(null, this.getX(), this.getY(), this.getZ(), SoundEvents.SOUL_ESCAPE, SoundSource.HOSTILE, 0.55F, 1.25F);
|
||||
this.discard();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
package fr.koka99cab.real_ghost.entity;
|
||||
|
||||
import net.minecraft.util.RandomSource;
|
||||
|
||||
public enum GhostVariant {
|
||||
SPOOK("mob", 42),
|
||||
WRAITH("human", 30),
|
||||
ILLAGER("illager", 18),
|
||||
ECLIPSE("color", 10);
|
||||
|
||||
private static final GhostVariant[] VALUES = values();
|
||||
private static final int TOTAL_WEIGHT = totalWeight();
|
||||
|
||||
private final String textureName;
|
||||
private final int spawnWeight;
|
||||
|
||||
GhostVariant(String textureName, int spawnWeight) {
|
||||
this.textureName = textureName;
|
||||
this.spawnWeight = spawnWeight;
|
||||
}
|
||||
|
||||
public String textureName() {
|
||||
return this.textureName;
|
||||
}
|
||||
|
||||
public String modelName() {
|
||||
return this.textureName;
|
||||
}
|
||||
|
||||
public int id() {
|
||||
return this.ordinal();
|
||||
}
|
||||
|
||||
public static GhostVariant byId(int id) {
|
||||
if (id < 0 || id >= VALUES.length) {
|
||||
return SPOOK;
|
||||
}
|
||||
|
||||
return VALUES[id];
|
||||
}
|
||||
|
||||
public static GhostVariant choose(RandomSource random) {
|
||||
int choice = random.nextInt(TOTAL_WEIGHT);
|
||||
|
||||
for (GhostVariant variant : VALUES) {
|
||||
choice -= variant.spawnWeight;
|
||||
|
||||
if (choice < 0) {
|
||||
return variant;
|
||||
}
|
||||
}
|
||||
|
||||
return SPOOK;
|
||||
}
|
||||
|
||||
private static int totalWeight() {
|
||||
int total = 0;
|
||||
|
||||
for (GhostVariant variant : VALUES) {
|
||||
total += variant.spawnWeight;
|
||||
}
|
||||
|
||||
return total;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
package fr.koka99cab.real_ghost.registry;
|
||||
|
||||
import fr.koka99cab.real_ghost.RealGhostMod;
|
||||
import fr.koka99cab.real_ghost.entity.GhostEntity;
|
||||
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 {
|
||||
private static final int GHOST_SPAWN_WEIGHT = 18;
|
||||
private static final int MIN_GHOSTS_PER_SPAWN = 1;
|
||||
private static final int MAX_GHOSTS_PER_SPAWN = 2;
|
||||
|
||||
public static final Identifier GHOST_ID = RealGhostMod.id("ghost");
|
||||
public static final EntityType<GhostEntity> GHOST = Registry.register(
|
||||
BuiltInRegistries.ENTITY_TYPE,
|
||||
GHOST_ID,
|
||||
FabricEntityTypeBuilder.createMob()
|
||||
.mobCategory(MobCategory.MONSTER)
|
||||
.entityFactory(GhostEntity::new)
|
||||
.dimensions(EntityDimensions.scalable(0.72F, 1.85F))
|
||||
.defaultAttributes(GhostEntity::createAttributes)
|
||||
.spawnPlacement(SpawnPlacementTypes.ON_GROUND, Heightmap.Types.MOTION_BLOCKING_NO_LEAVES, GhostEntity::canSpawn)
|
||||
.trackRangeBlocks(48)
|
||||
.trackedUpdateRate(2)
|
||||
.build(ResourceKey.create(Registries.ENTITY_TYPE, GHOST_ID))
|
||||
);
|
||||
|
||||
private ModEntityTypes() {
|
||||
}
|
||||
|
||||
public static void register() {
|
||||
BiomeModifications.addSpawn(BiomeSelectors.foundInOverworld(), MobCategory.MONSTER, GHOST,
|
||||
GHOST_SPAWN_WEIGHT, MIN_GHOSTS_PER_SPAWN, MAX_GHOSTS_PER_SPAWN);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package fr.koka99cab.real_ghost.registry;
|
||||
|
||||
import fr.koka99cab.real_ghost.RealGhostMod;
|
||||
import net.fabricmc.fabric.api.creativetab.v1.CreativeModeTabEvents;
|
||||
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.item.CreativeModeTab;
|
||||
import net.minecraft.world.item.Item;
|
||||
import net.minecraft.world.item.SpawnEggItem;
|
||||
|
||||
public final class ModItems {
|
||||
private static final ResourceKey<Item> GHOST_SPAWN_EGG_KEY = ResourceKey.create(Registries.ITEM, RealGhostMod.id("ghost_spawn_egg"));
|
||||
private static final ResourceKey<CreativeModeTab> SPAWN_EGGS_TAB = ResourceKey.create(Registries.CREATIVE_MODE_TAB, Identifier.withDefaultNamespace("spawn_eggs"));
|
||||
|
||||
public static final Item GHOST_SPAWN_EGG = Registry.register(
|
||||
BuiltInRegistries.ITEM,
|
||||
GHOST_SPAWN_EGG_KEY,
|
||||
new SpawnEggItem(new Item.Properties()
|
||||
.spawnEgg(ModEntityTypes.GHOST)
|
||||
.setId(GHOST_SPAWN_EGG_KEY))
|
||||
);
|
||||
|
||||
private ModItems() {
|
||||
}
|
||||
|
||||
public static void register() {
|
||||
CreativeModeTabEvents.modifyOutputEvent(SPAWN_EGGS_TAB).register(entries -> entries.accept(GHOST_SPAWN_EGG));
|
||||
}
|
||||
}
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 14 KiB |
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"model": {
|
||||
"type": "minecraft:model",
|
||||
"model": "real_ghost:item/ghost_spawn_egg"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"entity.real_ghost.ghost": "Ghost",
|
||||
"item.real_ghost.ghost_spawn_egg": "Ghost Spawn Egg"
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"entity.real_ghost.ghost": "Fantome",
|
||||
"item.real_ghost.ghost_spawn_egg": "Oeuf d'apparition de fantome"
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"parent": "minecraft:item/generated",
|
||||
"textures": {
|
||||
"layer0": "real_ghost:item/ghost_spawn_egg"
|
||||
}
|
||||
}
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 1.6 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 1.6 KiB |
BIN
Binary file not shown.
|
After Width: | Height: | Size: 1.8 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 1.6 KiB |
BIN
Binary file not shown.
|
After Width: | Height: | Size: 238 B |
@@ -0,0 +1,28 @@
|
||||
{
|
||||
"schemaVersion": 1,
|
||||
"id": "real_ghost",
|
||||
"version": "${version}",
|
||||
"name": "Real Ghost",
|
||||
"description": "Adds rare night ghosts that haunt players, whisper around them, charge, attack, and vanish. Also removes vanilla phantoms.",
|
||||
"authors": [
|
||||
"KOKA99CAB",
|
||||
"Eclipse_Valley (bbmodel)"
|
||||
],
|
||||
"license": "LGPL-3.0-or-later",
|
||||
"icon": "assets/real_ghost/icon.png",
|
||||
"environment": "*",
|
||||
"entrypoints": {
|
||||
"main": [
|
||||
"fr.koka99cab.real_ghost.RealGhostMod"
|
||||
],
|
||||
"client": [
|
||||
"fr.koka99cab.real_ghost.client.RealGhostClient"
|
||||
]
|
||||
},
|
||||
"depends": {
|
||||
"fabricloader": ">=0.19.2",
|
||||
"minecraft": "~26.1.2",
|
||||
"java": ">=25",
|
||||
"fabric-api": "*"
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user