Initial sanctuary sources

This commit is contained in:
cnstiout
2026-07-04 20:27:08 +02:00
commit c796a20321
1582 changed files with 253264 additions and 0 deletions
+34
View File
@@ -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
+67
View File
@@ -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 {
}
}
+21
View File
@@ -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
Vendored Executable
+253
View File
@@ -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" "$@"
+93
View File
@@ -0,0 +1,93 @@
@rem
@rem Copyright 2015 the original author or authors.
@rem
@rem Licensed under the Apache License, Version 2.0 (the "License");
@rem you may not use this file except in compliance with the License.
@rem You may obtain a copy of the License at
@rem
@rem https://www.apache.org/licenses/LICENSE-2.0
@rem
@rem Unless required by applicable law or agreed to in writing, software
@rem distributed under the License is distributed on an "AS IS" BASIS,
@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@rem See the License for the specific language governing permissions and
@rem limitations under the License.
@rem
@rem SPDX-License-Identifier: Apache-2.0
@rem
@if "%DEBUG%"=="" @echo off
@rem ##########################################################################
@rem
@rem Gradle startup script for Windows
@rem
@rem ##########################################################################
@rem Set local scope for the variables with windows NT shell
if "%OS%"=="Windows_NT" setlocal
set DIRNAME=%~dp0
if "%DIRNAME%"=="" set DIRNAME=.
@rem This is normally unused
set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME%
@rem Resolve any "." and ".." in APP_HOME to make it shorter.
for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
@rem Find java.exe
if defined JAVA_HOME goto findJavaFromJavaHome
set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1
if %ERRORLEVEL% equ 0 goto execute
echo. 1>&2
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2
echo. 1>&2
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
echo location of your Java installation. 1>&2
goto fail
:findJavaFromJavaHome
set JAVA_HOME=%JAVA_HOME:"=%
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
if exist "%JAVA_EXE%" goto execute
echo. 1>&2
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2
echo. 1>&2
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
echo location of your Java installation. 1>&2
goto fail
:execute
@rem Setup the command line
@rem Execute Gradle
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -jar "%APP_HOME%\gradle\wrapper\gradle-wrapper.jar" %*
:end
@rem End local scope for the variables with windows NT shell
if %ERRORLEVEL% equ 0 goto mainEnd
:fail
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
rem the _cmd.exe /c_ return code!
set EXIT_CODE=%ERRORLEVEL%
if %EXIT_CODE% equ 0 set EXIT_CODE=1
if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE%
exit /b %EXIT_CODE%
:mainEnd
if "%OS%"=="Windows_NT" endlocal
:omega
Binary file not shown.

After

Width:  |  Height:  |  Size: 564 B

+12
View File
@@ -0,0 +1,12 @@
pluginManagement {
repositories {
maven {
name = "Fabric"
url = "https://maven.fabricmc.net/"
}
mavenCentral()
gradlePluginPortal()
}
}
rootProject.name = "happy_creeper"
@@ -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);
}
}
@@ -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;
}
}
@@ -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);
}
}
@@ -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;
}
}
@@ -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();
}
@@ -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");
}
}
@@ -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();
}
}
}
@@ -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());
}
}
}
@@ -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);
}
}
}
@@ -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;
}
}
@@ -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"
}
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": "*"
}
}
+67
View File
@@ -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 {
"no_phantoms" {
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 {
}
}
+21
View File
@@ -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=no_phantoms
# 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
Vendored Executable
+253
View File
@@ -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" "$@"
+93
View File
@@ -0,0 +1,93 @@
@rem
@rem Copyright 2015 the original author or authors.
@rem
@rem Licensed under the Apache License, Version 2.0 (the "License");
@rem you may not use this file except in compliance with the License.
@rem You may obtain a copy of the License at
@rem
@rem https://www.apache.org/licenses/LICENSE-2.0
@rem
@rem Unless required by applicable law or agreed to in writing, software
@rem distributed under the License is distributed on an "AS IS" BASIS,
@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@rem See the License for the specific language governing permissions and
@rem limitations under the License.
@rem
@rem SPDX-License-Identifier: Apache-2.0
@rem
@if "%DEBUG%"=="" @echo off
@rem ##########################################################################
@rem
@rem Gradle startup script for Windows
@rem
@rem ##########################################################################
@rem Set local scope for the variables with windows NT shell
if "%OS%"=="Windows_NT" setlocal
set DIRNAME=%~dp0
if "%DIRNAME%"=="" set DIRNAME=.
@rem This is normally unused
set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME%
@rem Resolve any "." and ".." in APP_HOME to make it shorter.
for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
@rem Find java.exe
if defined JAVA_HOME goto findJavaFromJavaHome
set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1
if %ERRORLEVEL% equ 0 goto execute
echo. 1>&2
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2
echo. 1>&2
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
echo location of your Java installation. 1>&2
goto fail
:findJavaFromJavaHome
set JAVA_HOME=%JAVA_HOME:"=%
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
if exist "%JAVA_EXE%" goto execute
echo. 1>&2
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2
echo. 1>&2
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
echo location of your Java installation. 1>&2
goto fail
:execute
@rem Setup the command line
@rem Execute Gradle
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -jar "%APP_HOME%\gradle\wrapper\gradle-wrapper.jar" %*
:end
@rem End local scope for the variables with windows NT shell
if %ERRORLEVEL% equ 0 goto mainEnd
:fail
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
rem the _cmd.exe /c_ return code!
set EXIT_CODE=%ERRORLEVEL%
if %EXIT_CODE% equ 0 set EXIT_CODE=1
if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE%
exit /b %EXIT_CODE%
:mainEnd
if "%OS%"=="Windows_NT" endlocal
:omega
+12
View File
@@ -0,0 +1,12 @@
pluginManagement {
repositories {
maven {
name = "Fabric"
url = "https://maven.fabricmc.net/"
}
mavenCentral()
gradlePluginPortal()
}
}
rootProject.name = "no_phantoms"
@@ -0,0 +1,34 @@
package fr.koka99cab.no_phantoms;
import net.fabricmc.api.ModInitializer;
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerEntityEvents;
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 NoPhantomsMod implements ModInitializer {
public static final String MOD_ID = "no_phantoms";
public static final Logger LOGGER = LoggerFactory.getLogger(MOD_ID);
private static final boolean KEEP_PHANTOMS_IN_OVERWORLD = false;
@Override
public void onInitialize() {
ServerEntityEvents.ENTITY_LOAD.register(NoPhantomsMod::removeForbiddenPhantom);
LOGGER.info("No Phantoms charge: les phantoms sont retires du monde.");
}
private static void removeForbiddenPhantom(Entity entity, Level level) {
if (entity.getType() != EntityType.PHANTOM) {
return;
}
if (KEEP_PHANTOMS_IN_OVERWORLD && level.dimension() == Level.OVERWORLD) {
return;
}
entity.discard();
}
}
@@ -0,0 +1,3 @@
{
"modmenu.descriptionTranslation.no_phantoms": "Removes phantom mobs from realtime worlds."
}
@@ -0,0 +1,3 @@
{
"modmenu.descriptionTranslation.no_phantoms": "Supprime les phantoms des mondes en temps reel."
}
@@ -0,0 +1,23 @@
{
"schemaVersion": 1,
"id": "no_phantoms",
"version": "${version}",
"name": "No Phantoms",
"description": "Removes phantom mobs as soon as they appear, keeping realtime worlds free from insomnia swarms.",
"authors": [
"KOKA99CAB"
],
"license": "LGPL-3.0-or-later",
"environment": "*",
"entrypoints": {
"main": [
"fr.koka99cab.no_phantoms.NoPhantomsMod"
]
},
"depends": {
"fabricloader": ">=0.19.2",
"minecraft": "~26.1.2",
"java": ">=25",
"fabric-api": "*"
}
}
@@ -0,0 +1 @@
{"meta":{"format_version":"5.0","model_format":"modded_entity","box_uv":true},"name":"butterfly","model_identifier":"pipallon:butterfly","modded_entity_entity_class":"fr.koka99cab.pipallon.entity.ButterflyEntity","modded_entity_version":"1.17","modded_entity_flip_y":true,"visible_box":[1,1,0],"variable_placeholders":"","multi_file_ruleset":"","variable_placeholder_buttons":[],"timeline_setups":[],"unhandled_root_fields":{},"resolution":{"width":32,"height":32},"elements":[{"name":"body","box_uv":true,"render_order":"default","locked":false,"export":true,"scope":0,"allow_mirror_modeling":true,"from":[-1,0,-1],"to":[1,2,3],"autouv":0,"color":6,"origin":[0,1,1],"uv_offset":[0,16],"faces":{"north":{"uv":[4,20,6,22],"texture":0},"east":{"uv":[0,20,4,22],"texture":0},"south":{"uv":[10,20,12,22],"texture":0},"west":{"uv":[6,20,10,22],"texture":0},"up":{"uv":[6,20,4,16],"texture":0},"down":{"uv":[8,16,6,20],"texture":0}},"type":"cube","uuid":"f554aa52-27d3-c7d5-b995-c55ec3574fd8"},{"name":"left-wing","box_uv":true,"render_order":"default","locked":false,"export":true,"scope":0,"allow_mirror_modeling":true,"from":[-5,2,-3],"to":[0,2,5],"autouv":0,"color":9,"origin":[0,2,1],"faces":{"north":{"uv":[8,8,13,8],"texture":0},"east":{"uv":[0,8,8,8],"texture":0},"south":{"uv":[21,8,26,8],"texture":0},"west":{"uv":[13,8,21,8],"texture":0},"up":{"uv":[13,8,8,0],"texture":0},"down":{"uv":[18,0,13,8],"texture":0}},"type":"cube","uuid":"3936b2b0-a079-134c-3389-47f48c4da143","uv_offset":[0,0]},{"name":"right-wing","box_uv":true,"render_order":"default","locked":false,"export":true,"scope":0,"allow_mirror_modeling":true,"from":[0,2,-3],"to":[5,2,5],"autouv":0,"color":9,"origin":[0,2,1],"uv_offset":[0,8],"faces":{"north":{"uv":[8,16,13,16],"texture":0},"east":{"uv":[0,16,8,16],"texture":0},"south":{"uv":[21,16,26,16],"texture":0},"west":{"uv":[13,16,21,16],"texture":0},"up":{"uv":[13,16,8,8],"texture":0},"down":{"uv":[18,8,13,16],"texture":0}},"type":"cube","uuid":"81db23db-8756-ed17-c130-20cd284bf5a2"}],"groups":[],"outliner":[{"name":"body_root","uuid":"efdf16b6-0c8d-4f1f-8c34-45318f3cc5c9","origin":[0,1,1],"children":["f554aa52-27d3-c7d5-b995-c55ec3574fd8",{"name":"left_wing_pivot","uuid":"9b2a8291-298d-4fa9-9a2e-0d479b3e5f77","origin":[0,2,1],"children":["3936b2b0-a079-134c-3389-47f48c4da143"]},{"name":"right_wing_pivot","uuid":"bb610bbb-0b0a-48aa-9fd9-ded14661a20f","origin":[0,2,1],"children":["81db23db-8756-ed17-c130-20cd284bf5a2"]}]}],"textures":[{"name":"monarch.png","path":"../src/main/resources/assets/pipallon/textures/entity/butterfly/monarch.png","folder":"entity/butterfly","namespace":"pipallon","id":"0","group":"","scope":0,"width":32,"height":32,"uv_width":32,"uv_height":32,"particle":false,"use_as_default":true,"layers_enabled":false,"sync_to_project":"","file_format":"png","render_mode":"default","render_sides":"auto","wrap_mode":"limited","pbr_channel":"color","fps":7,"frame_time":1,"frame_order_type":"loop","frame_order":"","frame_interpolate":false,"visible":true,"internal":false,"saved":true,"uuid":"3ed85cd8-b795-8be9-c27a-ce37361a9bb2","relative_path":"../src/main/resources/assets/pipallon/textures/entity/butterfly/monarch.png"}]}
Binary file not shown.

After

Width:  |  Height:  |  Size: 6.2 KiB

+67
View File
@@ -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 {
"pipallon" {
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 {
}
}
+21
View File
@@ -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=pipallon
# 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
Vendored Executable
+253
View File
@@ -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" "$@"
+93
View File
@@ -0,0 +1,93 @@
@rem
@rem Copyright 2015 the original author or authors.
@rem
@rem Licensed under the Apache License, Version 2.0 (the "License");
@rem you may not use this file except in compliance with the License.
@rem You may obtain a copy of the License at
@rem
@rem https://www.apache.org/licenses/LICENSE-2.0
@rem
@rem Unless required by applicable law or agreed to in writing, software
@rem distributed under the License is distributed on an "AS IS" BASIS,
@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@rem See the License for the specific language governing permissions and
@rem limitations under the License.
@rem
@rem SPDX-License-Identifier: Apache-2.0
@rem
@if "%DEBUG%"=="" @echo off
@rem ##########################################################################
@rem
@rem Gradle startup script for Windows
@rem
@rem ##########################################################################
@rem Set local scope for the variables with windows NT shell
if "%OS%"=="Windows_NT" setlocal
set DIRNAME=%~dp0
if "%DIRNAME%"=="" set DIRNAME=.
@rem This is normally unused
set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME%
@rem Resolve any "." and ".." in APP_HOME to make it shorter.
for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
@rem Find java.exe
if defined JAVA_HOME goto findJavaFromJavaHome
set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1
if %ERRORLEVEL% equ 0 goto execute
echo. 1>&2
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2
echo. 1>&2
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
echo location of your Java installation. 1>&2
goto fail
:findJavaFromJavaHome
set JAVA_HOME=%JAVA_HOME:"=%
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
if exist "%JAVA_EXE%" goto execute
echo. 1>&2
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2
echo. 1>&2
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
echo location of your Java installation. 1>&2
goto fail
:execute
@rem Setup the command line
@rem Execute Gradle
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -jar "%APP_HOME%\gradle\wrapper\gradle-wrapper.jar" %*
:end
@rem End local scope for the variables with windows NT shell
if %ERRORLEVEL% equ 0 goto mainEnd
:fail
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
rem the _cmd.exe /c_ return code!
set EXIT_CODE=%ERRORLEVEL%
if %EXIT_CODE% equ 0 set EXIT_CODE=1
if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE%
exit /b %EXIT_CODE%
:mainEnd
if "%OS%"=="Windows_NT" endlocal
:omega
+12
View File
@@ -0,0 +1,12 @@
pluginManagement {
repositories {
maven {
name = "Fabric"
url = "https://maven.fabricmc.net/"
}
mavenCentral()
gradlePluginPortal()
}
}
rootProject.name = "pipallon"
@@ -0,0 +1,16 @@
package fr.koka99cab.pipallon.client;
import fr.koka99cab.pipallon.client.model.ButterflyModel;
import fr.koka99cab.pipallon.client.renderer.ButterflyRenderer;
import fr.koka99cab.pipallon.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 PipallonClient implements ClientModInitializer {
@Override
public void onInitializeClient() {
ModelLayerRegistry.registerModelLayer(ButterflyModel.LAYER_LOCATION, ButterflyModel::createBodyLayer);
EntityRendererRegistry.register(ModEntityTypes.BUTTERFLY, ButterflyRenderer::new);
}
}
@@ -0,0 +1,82 @@
package fr.koka99cab.pipallon.client.model;
import fr.koka99cab.pipallon.PipallonMod;
import fr.koka99cab.pipallon.client.renderer.ButterflyRenderState;
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.util.Mth;
public final class ButterflyModel extends EntityModel<ButterflyRenderState> {
public static final ModelLayerLocation LAYER_LOCATION = new ModelLayerLocation(PipallonMod.id("butterfly"), "main");
private final ModelPart bodyRoot;
private final ModelPart leftWingPivot;
private final ModelPart rightWingPivot;
public ButterflyModel(ModelPart root) {
super(root);
this.bodyRoot = root.getChild("body_root");
this.leftWingPivot = this.bodyRoot.getChild("left_wing_pivot");
this.rightWingPivot = this.bodyRoot.getChild("right_wing_pivot");
}
public static LayerDefinition createBodyLayer() {
MeshDefinition mesh = new MeshDefinition();
PartDefinition root = mesh.getRoot();
PartDefinition bodyRoot = root.addOrReplaceChild("body_root", CubeListBuilder.create(), PartPose.offset(0.0F, 23.0F, 1.0F));
bodyRoot.addOrReplaceChild(
"body",
CubeListBuilder.create()
.texOffs(0, 16)
.addBox(-1.0F, -1.0F, -2.0F, 2.0F, 2.0F, 4.0F),
PartPose.ZERO
);
PartDefinition leftWingPivot = bodyRoot.addOrReplaceChild("left_wing_pivot", CubeListBuilder.create(), PartPose.offset(0.0F, -1.0F, 0.0F));
leftWingPivot.addOrReplaceChild(
"left_wing",
CubeListBuilder.create()
.texOffs(0, 0)
.addBox(-5.0F, 0.0F, -4.0F, 5.0F, 0.0F, 8.0F),
PartPose.ZERO
);
PartDefinition rightWingPivot = bodyRoot.addOrReplaceChild("right_wing_pivot", CubeListBuilder.create(), PartPose.offset(0.0F, -1.0F, 0.0F));
rightWingPivot.addOrReplaceChild(
"right_wing",
CubeListBuilder.create()
.texOffs(0, 8)
.addBox(0.0F, 0.0F, -4.0F, 5.0F, 0.0F, 8.0F),
PartPose.ZERO
);
return LayerDefinition.create(mesh, 32, 32);
}
@Override
public void setupAnim(ButterflyRenderState state) {
super.setupAnim(state);
float speed = state.isAngry ? 1.9F : 1.15F;
float maxLift = state.isAngry ? 0.95F : 0.75F;
float wingLift = 0.12F + ((Mth.sin(state.ageInTicks * speed) + 1.0F) * 0.5F) * maxLift;
float idleTilt = Mth.sin(state.ageInTicks * 0.17F) * 0.08F;
this.bodyRoot.y = 23.0F + Mth.sin(state.ageInTicks * 0.21F) * 0.35F;
this.bodyRoot.z = 1.0F;
this.bodyRoot.xRot = state.isFlying ? idleTilt : 0.0F;
this.bodyRoot.yRot = Mth.sin(state.ageInTicks * 0.09F) * 0.06F;
this.leftWingPivot.xRot = 0.0F;
this.rightWingPivot.xRot = 0.0F;
this.leftWingPivot.yRot = 0.04F;
this.rightWingPivot.yRot = -0.04F;
this.leftWingPivot.zRot = wingLift;
this.rightWingPivot.zRot = -wingLift;
}
}
@@ -0,0 +1,10 @@
package fr.koka99cab.pipallon.client.renderer;
import fr.koka99cab.pipallon.entity.ButterflyVariant;
import net.minecraft.client.renderer.entity.state.LivingEntityRenderState;
public final class ButterflyRenderState extends LivingEntityRenderState {
public ButterflyVariant variant = ButterflyVariant.MONARCH;
public boolean isAngry;
public boolean isFlying;
}
@@ -0,0 +1,47 @@
package fr.koka99cab.pipallon.client.renderer;
import fr.koka99cab.pipallon.PipallonMod;
import fr.koka99cab.pipallon.client.model.ButterflyModel;
import fr.koka99cab.pipallon.entity.ButterflyEntity;
import fr.koka99cab.pipallon.entity.ButterflyVariant;
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 ButterflyRenderer extends MobRenderer<ButterflyEntity, ButterflyRenderState, ButterflyModel> {
private static final Map<ButterflyVariant, Identifier> TEXTURES = createTextureMap();
public ButterflyRenderer(EntityRendererProvider.Context context) {
super(context, new ButterflyModel(context.bakeLayer(ButterflyModel.LAYER_LOCATION)), 0.18F);
}
@Override
public Identifier getTextureLocation(ButterflyRenderState state) {
return TEXTURES.getOrDefault(state.variant, TEXTURES.get(ButterflyVariant.MONARCH));
}
@Override
public ButterflyRenderState createRenderState() {
return new ButterflyRenderState();
}
@Override
public void extractRenderState(ButterflyEntity butterfly, ButterflyRenderState state, float partialTick) {
super.extractRenderState(butterfly, state, partialTick);
state.variant = butterfly.getVariant();
state.isAngry = butterfly.isAngryVisual();
state.isFlying = butterfly.isFlying();
}
private static Map<ButterflyVariant, Identifier> createTextureMap() {
EnumMap<ButterflyVariant, Identifier> textures = new EnumMap<>(ButterflyVariant.class);
for (ButterflyVariant variant : ButterflyVariant.values()) {
textures.put(variant, PipallonMod.id("textures/entity/butterfly/" + variant.textureName() + ".png"));
}
return textures;
}
}
@@ -0,0 +1,24 @@
package fr.koka99cab.pipallon;
import fr.koka99cab.pipallon.registry.ModEntityTypes;
import fr.koka99cab.pipallon.registry.ModItems;
import net.fabricmc.api.ModInitializer;
import net.minecraft.resources.Identifier;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public final class PipallonMod implements ModInitializer {
public static final String MOD_ID = "pipallon";
public static final Logger LOGGER = LoggerFactory.getLogger(MOD_ID);
@Override
public void onInitialize() {
ModEntityTypes.register();
ModItems.register();
LOGGER.info("Pipallon butterflies are taking off");
}
public static Identifier id(String path) {
return Identifier.fromNamespaceAndPath(MOD_ID, path);
}
}
@@ -0,0 +1,348 @@
package fr.koka99cab.pipallon.entity;
import fr.koka99cab.pipallon.registry.ModEntityTypes;
import java.util.EnumSet;
import net.minecraft.core.BlockPos;
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.sounds.SoundEvent;
import net.minecraft.sounds.SoundEvents;
import net.minecraft.tags.BlockTags;
import net.minecraft.tags.ItemTags;
import net.minecraft.util.RandomSource;
import net.minecraft.util.TimeUtil;
import net.minecraft.util.valueproviders.UniformInt;
import net.minecraft.world.DifficultyInstance;
import net.minecraft.world.damagesource.DamageSource;
import net.minecraft.world.entity.AgeableMob;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.EntityReference;
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.NeutralMob;
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.control.FlyingMoveControl;
import net.minecraft.world.entity.ai.goal.FloatGoal;
import net.minecraft.world.entity.ai.goal.FollowParentGoal;
import net.minecraft.world.entity.ai.goal.Goal;
import net.minecraft.world.entity.ai.goal.LookAtPlayerGoal;
import net.minecraft.world.entity.ai.goal.MeleeAttackGoal;
import net.minecraft.world.entity.ai.goal.RandomLookAroundGoal;
import net.minecraft.world.entity.ai.goal.TemptGoal;
import net.minecraft.world.entity.ai.goal.WaterAvoidingRandomFlyingGoal;
import net.minecraft.world.entity.ai.goal.target.HurtByTargetGoal;
import net.minecraft.world.entity.ai.goal.target.ResetUniversalAngerTargetGoal;
import net.minecraft.world.entity.ai.navigation.FlyingPathNavigation;
import net.minecraft.world.entity.ai.navigation.PathNavigation;
import net.minecraft.world.entity.animal.Animal;
import net.minecraft.world.entity.animal.FlyingAnimal;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.LevelReader;
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;
public final class ButterflyEntity extends Animal implements FlyingAnimal, NeutralMob {
private static final EntityDataAccessor<Integer> VARIANT = SynchedEntityData.defineId(ButterflyEntity.class, EntityDataSerializers.INT);
private static final EntityDataAccessor<Boolean> ANGRY = SynchedEntityData.defineId(ButterflyEntity.class, EntityDataSerializers.BOOLEAN);
private static final UniformInt PERSISTENT_ANGER_TIME = TimeUtil.rangeOfSeconds(18, 35);
private static final String VARIANT_KEY = "ButterflyVariant";
private long persistentAngerEndTime;
private EntityReference<LivingEntity> persistentAngerTarget;
public ButterflyEntity(EntityType<? extends ButterflyEntity> entityType, Level level) {
super(entityType, level);
this.moveControl = new FlyingMoveControl(this, 20, true);
this.setNoGravity(true);
}
public static AttributeSupplier.Builder createAttributes() {
return Animal.createAnimalAttributes()
.add(Attributes.MAX_HEALTH, 6.0D)
.add(Attributes.FOLLOW_RANGE, 20.0D)
.add(Attributes.MOVEMENT_SPEED, 0.22D)
.add(Attributes.FLYING_SPEED, 0.45D)
.add(Attributes.ATTACK_DAMAGE, 1.0D);
}
public static boolean canSpawn(EntityType<ButterflyEntity> entityType, ServerLevelAccessor level, EntitySpawnReason spawnReason, BlockPos blockPos, RandomSource random) {
return Animal.checkAnimalSpawnRules(entityType, level, spawnReason, blockPos, random);
}
@Override
protected void defineSynchedData(SynchedEntityData.Builder builder) {
super.defineSynchedData(builder);
builder.define(VARIANT, ButterflyVariant.MONARCH.id());
builder.define(ANGRY, false);
}
@Override
protected void registerGoals() {
this.goalSelector.addGoal(0, new FloatGoal(this));
this.goalSelector.addGoal(1, new MeleeAttackGoal(this, 1.25D, true));
this.goalSelector.addGoal(2, new HoverNearFlowersGoal(this));
this.goalSelector.addGoal(3, new TemptGoal(this, 1.05D, stack -> stack.is(ItemTags.FLOWERS), false));
this.goalSelector.addGoal(4, new FollowParentGoal(this, 1.05D));
this.goalSelector.addGoal(5, new WaterAvoidingRandomFlyingGoal(this, 0.85D));
this.goalSelector.addGoal(6, new LookAtPlayerGoal(this, Player.class, 6.0F));
this.goalSelector.addGoal(7, new RandomLookAroundGoal(this));
this.targetSelector.addGoal(0, new HurtByTargetGoal(this));
this.targetSelector.addGoal(1, new ResetUniversalAngerTargetGoal<>(this, true));
}
@Override
protected PathNavigation createNavigation(Level level) {
return new FlyingPathNavigation(this, level);
}
@Override
public SpawnGroupData finalizeSpawn(ServerLevelAccessor level, DifficultyInstance difficulty, EntitySpawnReason spawnReason, SpawnGroupData spawnGroupData) {
SpawnGroupData finalizedSpawn = super.finalizeSpawn(level, difficulty, spawnReason, spawnGroupData);
this.setVariant(ButterflyVariant.choose(this.random));
this.setNoGravity(true);
return finalizedSpawn;
}
@Override
protected void customServerAiStep(ServerLevel serverLevel) {
super.customServerAiStep(serverLevel);
this.setNoGravity(true);
this.updatePersistentAnger(serverLevel, true);
this.setAngryVisual(this.isAngry() || this.getTarget() != null);
}
@Override
public void tick() {
super.tick();
this.setNoGravity(true);
}
@Override
protected void addAdditionalSaveData(ValueOutput output) {
super.addAdditionalSaveData(output);
output.putInt(VARIANT_KEY, this.getVariant().id());
this.addPersistentAngerSaveData(output);
}
@Override
protected void readAdditionalSaveData(ValueInput input) {
super.readAdditionalSaveData(input);
this.setVariant(ButterflyVariant.byId(input.getIntOr(VARIANT_KEY, ButterflyVariant.MONARCH.id())));
this.readPersistentAngerSaveData(this.level(), input);
this.setNoGravity(true);
}
@Override
public boolean hurtServer(ServerLevel serverLevel, DamageSource damageSource, float amount) {
boolean hurt = super.hurtServer(serverLevel, damageSource, amount);
Entity attacker = damageSource.getEntity();
if (hurt && attacker instanceof LivingEntity livingEntity && livingEntity != this && this.canAttack(livingEntity)) {
this.setPersistentAngerTarget(EntityReference.of(livingEntity));
this.setTarget(livingEntity);
this.startPersistentAngerTimer();
this.setAngryVisual(true);
}
return hurt;
}
@Override
public boolean doHurtTarget(ServerLevel serverLevel, Entity entity) {
boolean hurt = super.doHurtTarget(serverLevel, entity);
if (hurt) {
this.playSound(SoundEvents.BEE_STING, 0.35F, 1.45F);
}
return hurt;
}
@Override
public boolean isFood(ItemStack itemStack) {
return itemStack.is(ItemTags.FLOWERS);
}
@Override
public ButterflyEntity getBreedOffspring(ServerLevel serverLevel, AgeableMob ageableMob) {
ButterflyEntity baby = ModEntityTypes.BUTTERFLY.create(serverLevel, EntitySpawnReason.BREEDING);
if (baby != null) {
if (ageableMob instanceof ButterflyEntity otherButterfly && this.random.nextBoolean()) {
baby.setVariant(otherButterfly.getVariant());
} else {
baby.setVariant(this.getVariant());
}
}
return baby;
}
@Override
public float getWalkTargetValue(BlockPos blockPos, LevelReader levelReader) {
if (isAttractiveFlower(levelReader, blockPos) || isAttractiveFlower(levelReader, blockPos.below())) {
return 10.0F;
}
return levelReader.getPathfindingCostFromLightLevels(blockPos);
}
@Override
protected void checkFallDamage(double fallDistance, boolean landed, BlockState state, BlockPos pos) {
}
@Override
public boolean isFlying() {
return !this.onGround();
}
@Override
protected SoundEvent getAmbientSound() {
return this.isAngryVisual() ? SoundEvents.BEE_LOOP_AGGRESSIVE : SoundEvents.BAT_AMBIENT;
}
@Override
protected SoundEvent getHurtSound(DamageSource damageSource) {
return SoundEvents.BEE_HURT;
}
@Override
protected SoundEvent getDeathSound() {
return SoundEvents.BEE_DEATH;
}
@Override
protected float getSoundVolume() {
return 0.25F;
}
@Override
public float getVoicePitch() {
return 1.35F + this.random.nextFloat() * 0.25F;
}
public ButterflyVariant getVariant() {
return ButterflyVariant.byId(this.entityData.get(VARIANT));
}
public void setVariant(ButterflyVariant variant) {
this.entityData.set(VARIANT, variant.id());
}
public boolean isAngryVisual() {
return this.entityData.get(ANGRY);
}
private void setAngryVisual(boolean angry) {
this.entityData.set(ANGRY, angry);
this.setAggressive(angry);
}
@Override
public long getPersistentAngerEndTime() {
return this.persistentAngerEndTime;
}
@Override
public void setPersistentAngerEndTime(long persistentAngerEndTime) {
this.persistentAngerEndTime = persistentAngerEndTime;
}
@Override
public EntityReference<LivingEntity> getPersistentAngerTarget() {
return this.persistentAngerTarget;
}
@Override
public void setPersistentAngerTarget(EntityReference<LivingEntity> persistentAngerTarget) {
this.persistentAngerTarget = persistentAngerTarget;
}
@Override
public void startPersistentAngerTimer() {
this.setPersistentAngerEndTime(this.level().getGameTime() + PERSISTENT_ANGER_TIME.sample(this.random));
}
private static boolean isAttractiveFlower(LevelReader levelReader, BlockPos blockPos) {
BlockState state = levelReader.getBlockState(blockPos);
return state.is(BlockTags.BEE_ATTRACTIVE) || state.is(BlockTags.FLOWERS);
}
private static final class HoverNearFlowersGoal extends Goal {
private static final int SEARCH_RADIUS = 7;
private static final int VERTICAL_RADIUS = 4;
private final ButterflyEntity butterfly;
private BlockPos flowerPos;
private HoverNearFlowersGoal(ButterflyEntity butterfly) {
this.butterfly = butterfly;
this.setFlags(EnumSet.of(Goal.Flag.MOVE));
}
@Override
public boolean canUse() {
if (this.butterfly.isAngryVisual() || this.butterfly.getTarget() != null || this.butterfly.random.nextInt(12) != 0) {
return false;
}
this.flowerPos = this.findNearbyFlower();
return this.flowerPos != null;
}
@Override
public boolean canContinueToUse() {
return this.flowerPos != null
&& !this.butterfly.isAngryVisual()
&& this.butterfly.distanceToSqr(this.flowerPos.getX() + 0.5D, this.flowerPos.getY() + 0.8D, this.flowerPos.getZ() + 0.5D) > 0.8D
&& this.butterfly.distanceToSqr(this.flowerPos.getX() + 0.5D, this.flowerPos.getY() + 0.8D, this.flowerPos.getZ() + 0.5D) < 100.0D;
}
@Override
public void tick() {
this.butterfly.getMoveControl().setWantedPosition(
this.flowerPos.getX() + 0.5D,
this.flowerPos.getY() + 0.9D,
this.flowerPos.getZ() + 0.5D,
1.05D
);
}
@Override
public void stop() {
this.flowerPos = null;
}
private BlockPos findNearbyFlower() {
BlockPos origin = this.butterfly.blockPosition();
for (int attempt = 0; attempt < 18; attempt++) {
int x = origin.getX() + this.butterfly.random.nextInt(SEARCH_RADIUS * 2 + 1) - SEARCH_RADIUS;
int y = origin.getY() + this.butterfly.random.nextInt(VERTICAL_RADIUS * 2 + 1) - VERTICAL_RADIUS;
int z = origin.getZ() + this.butterfly.random.nextInt(SEARCH_RADIUS * 2 + 1) - SEARCH_RADIUS;
BlockPos candidate = new BlockPos(x, y, z);
if (!this.butterfly.level().isLoaded(candidate)) {
continue;
}
if (isAttractiveFlower(this.butterfly.level(), candidate) && this.butterfly.level().isEmptyBlock(candidate.above())) {
return candidate;
}
}
return null;
}
}
}
@@ -0,0 +1,68 @@
package fr.koka99cab.pipallon.entity;
import net.minecraft.util.RandomSource;
public enum ButterflyVariant {
MONARCH("monarch", 50, 0xE77B12),
MORPHO("morpho", 22, 0x09A5F0),
EYED_MOTH("eyed_moth", 13, 0xB58B72),
ATLAS("atlas", 9, 0xB97842),
EMERALD_SWALLOWTAIL("emerald_swallowtail", 6, 0x58DFA5);
private static final ButterflyVariant[] VALUES = values();
private static final int TOTAL_WEIGHT = totalWeight();
private final String textureName;
private final int spawnWeight;
private final int eggColor;
ButterflyVariant(String textureName, int spawnWeight, int eggColor) {
this.textureName = textureName;
this.spawnWeight = spawnWeight;
this.eggColor = eggColor;
}
public String textureName() {
return this.textureName;
}
public int eggColor() {
return this.eggColor;
}
public int id() {
return this.ordinal();
}
public static ButterflyVariant byId(int id) {
if (id < 0 || id >= VALUES.length) {
return MONARCH;
}
return VALUES[id];
}
public static ButterflyVariant choose(RandomSource random) {
int choice = random.nextInt(TOTAL_WEIGHT);
for (ButterflyVariant variant : VALUES) {
choice -= variant.spawnWeight;
if (choice < 0) {
return variant;
}
}
return MONARCH;
}
private static int totalWeight() {
int total = 0;
for (ButterflyVariant variant : VALUES) {
total += variant.spawnWeight;
}
return total;
}
}
@@ -0,0 +1,51 @@
package fr.koka99cab.pipallon.registry;
import fr.koka99cab.pipallon.PipallonMod;
import fr.koka99cab.pipallon.entity.ButterflyEntity;
import java.util.function.Predicate;
import net.fabricmc.fabric.api.biome.v1.BiomeModifications;
import net.fabricmc.fabric.api.biome.v1.BiomeSelectionContext;
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.biome.Biomes;
import net.minecraft.world.level.levelgen.Heightmap;
public final class ModEntityTypes {
public static final Identifier BUTTERFLY_ID = PipallonMod.id("butterfly");
public static final EntityType<ButterflyEntity> BUTTERFLY = Registry.register(
BuiltInRegistries.ENTITY_TYPE,
BUTTERFLY_ID,
FabricEntityTypeBuilder.createMob()
.mobCategory(MobCategory.CREATURE)
.entityFactory(ButterflyEntity::new)
.dimensions(EntityDimensions.scalable(0.45F, 0.35F))
.defaultAttributes(ButterflyEntity::createAttributes)
.spawnPlacement(SpawnPlacementTypes.ON_GROUND, Heightmap.Types.MOTION_BLOCKING_NO_LEAVES, ButterflyEntity::canSpawn)
.trackRangeBlocks(8)
.trackedUpdateRate(2)
.build(ResourceKey.create(Registries.ENTITY_TYPE, BUTTERFLY_ID))
);
private ModEntityTypes() {
}
public static void register() {
Predicate<BiomeSelectionContext> flowerBiomes = BiomeSelectors.includeByKey(
Biomes.FLOWER_FOREST,
Biomes.MEADOW,
Biomes.SUNFLOWER_PLAINS,
Biomes.CHERRY_GROVE
);
Predicate<BiomeSelectionContext> beeBiomes = BiomeSelectors.spawnsOneOf(EntityType.BEE);
BiomeModifications.addSpawn(flowerBiomes.or(beeBiomes), MobCategory.CREATURE, BUTTERFLY, 8, 2, 4);
}
}
@@ -0,0 +1,32 @@
package fr.koka99cab.pipallon.registry;
import fr.koka99cab.pipallon.PipallonMod;
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> BUTTERFLY_SPAWN_EGG_KEY = ResourceKey.create(Registries.ITEM, PipallonMod.id("butterfly_spawn_egg"));
private static final ResourceKey<CreativeModeTab> SPAWN_EGGS_TAB = ResourceKey.create(Registries.CREATIVE_MODE_TAB, Identifier.withDefaultNamespace("spawn_eggs"));
public static final Item BUTTERFLY_SPAWN_EGG = Registry.register(
BuiltInRegistries.ITEM,
BUTTERFLY_SPAWN_EGG_KEY,
new SpawnEggItem(new Item.Properties()
.spawnEgg(ModEntityTypes.BUTTERFLY)
.setId(BUTTERFLY_SPAWN_EGG_KEY))
);
private ModItems() {
}
public static void register() {
CreativeModeTabEvents.modifyOutputEvent(SPAWN_EGGS_TAB).register(entries -> entries.accept(BUTTERFLY_SPAWN_EGG));
}
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

@@ -0,0 +1,6 @@
{
"model": {
"type": "minecraft:model",
"model": "pipallon:item/butterfly_spawn_egg"
}
}
@@ -0,0 +1,4 @@
{
"entity.pipallon.butterfly": "Butterfly",
"item.pipallon.butterfly_spawn_egg": "Butterfly Spawn Egg"
}
@@ -0,0 +1,4 @@
{
"entity.pipallon.butterfly": "Papillon",
"item.pipallon.butterfly_spawn_egg": "Oeuf d'apparition de papillon"
}
@@ -0,0 +1,6 @@
{
"parent": "minecraft:item/generated",
"textures": {
"layer0": "pipallon:item/butterfly_spawn_egg"
}
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 355 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 346 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 350 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 368 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 366 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 244 B

@@ -0,0 +1,27 @@
{
"schemaVersion": 1,
"id": "pipallon",
"version": "${version}",
"name": "Pipallon",
"description": "Adds neutral flying butterflies that spawn around flower-rich biomes.",
"authors": [
"KOKA99CAB"
],
"license": "LGPL-3.0-or-later",
"icon": "assets/pipallon/icon.png",
"environment": "*",
"entrypoints": {
"main": [
"fr.koka99cab.pipallon.PipallonMod"
],
"client": [
"fr.koka99cab.pipallon.client.PipallonClient"
]
},
"depends": {
"fabricloader": ">=0.19.2",
"minecraft": "~26.1.2",
"java": ">=25",
"fabric-api": "*"
}
}
File diff suppressed because one or more lines are too long
+67
View File
@@ -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 {
}
}
+21
View File
@@ -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
Vendored Executable
+253
View File
@@ -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" "$@"
+93
View File
@@ -0,0 +1,93 @@
@rem
@rem Copyright 2015 the original author or authors.
@rem
@rem Licensed under the Apache License, Version 2.0 (the "License");
@rem you may not use this file except in compliance with the License.
@rem You may obtain a copy of the License at
@rem
@rem https://www.apache.org/licenses/LICENSE-2.0
@rem
@rem Unless required by applicable law or agreed to in writing, software
@rem distributed under the License is distributed on an "AS IS" BASIS,
@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@rem See the License for the specific language governing permissions and
@rem limitations under the License.
@rem
@rem SPDX-License-Identifier: Apache-2.0
@rem
@if "%DEBUG%"=="" @echo off
@rem ##########################################################################
@rem
@rem Gradle startup script for Windows
@rem
@rem ##########################################################################
@rem Set local scope for the variables with windows NT shell
if "%OS%"=="Windows_NT" setlocal
set DIRNAME=%~dp0
if "%DIRNAME%"=="" set DIRNAME=.
@rem This is normally unused
set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME%
@rem Resolve any "." and ".." in APP_HOME to make it shorter.
for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
@rem Find java.exe
if defined JAVA_HOME goto findJavaFromJavaHome
set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1
if %ERRORLEVEL% equ 0 goto execute
echo. 1>&2
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2
echo. 1>&2
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
echo location of your Java installation. 1>&2
goto fail
:findJavaFromJavaHome
set JAVA_HOME=%JAVA_HOME:"=%
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
if exist "%JAVA_EXE%" goto execute
echo. 1>&2
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2
echo. 1>&2
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
echo location of your Java installation. 1>&2
goto fail
:execute
@rem Setup the command line
@rem Execute Gradle
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -jar "%APP_HOME%\gradle\wrapper\gradle-wrapper.jar" %*
:end
@rem End local scope for the variables with windows NT shell
if %ERRORLEVEL% equ 0 goto mainEnd
:fail
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
rem the _cmd.exe /c_ return code!
set EXIT_CODE=%ERRORLEVEL%
if %EXIT_CODE% equ 0 set EXIT_CODE=1
if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE%
exit /b %EXIT_CODE%
:mainEnd
if "%OS%"=="Windows_NT" endlocal
:omega
+11
View File
@@ -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;
}
}
@@ -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;
}
@@ -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

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB

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": "*"
}
}
+34
View File
@@ -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
+67
View File
@@ -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 {
"villagers" {
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 {
}
}
+21
View File
@@ -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=villagers
# 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

Some files were not shown because too many files have changed in this diff Show More