diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..823aca8 --- /dev/null +++ b/.gitignore @@ -0,0 +1,25 @@ +# gradle + +.gradle/ +out/ +classes/ +build/ + +# idea + +.idea/ +*.iml +*.ipr +*.iws + +# vscode + +.settings/ +.vscode/ +bin/ +.classpath +.project + +# fabric + +run/ \ No newline at end of file diff --git a/Modfest_Singularity b/Modfest_Singularity new file mode 100644 index 0000000..00209ef --- /dev/null +++ b/Modfest_Singularity @@ -0,0 +1,27 @@ +Modfest: Singularity + +Mod name: Celestria + +Feature: Celestrial Events (Shooting stars => Luck effect, Full moon => chance of insomnia potion effect) + +Chat messages: (Configurable via MidnightConfig lists, translation strings, \n for line break) + - Shooting stars: (On occurance) + - Oh, look! A shooting star appeared and blessed you with good luck! + - Wow, make a wish, a shooting star appeared! + - ♪ Can we pretend that airplanes in the night sky are like shooting stars... ♫ + Oh wait, there's a real one! + - + - Full moon: (When trying to sleep w/ insomnia effect) + - You're afraid of the full moon, so you just can't find no rest... + - Ouuwwwh... You hear strange noises from afar and can't close your eyes + - + +Technical details: + - Shooting stars: + - randomly triggered serverside (only at night) and synced to all players + - can also be created using commands (for showcase - /celestria shooting_star %PLAYER% x z) + - server sends packet to client which then renders the shooting star (mixin into WorldRenderer) + - players get Minecraft's Luck effect + - Full moon: + - on start of night with full moon, players have an individual and configurable chance of receiving the 'Insomnia' effect + - effect prevents players from entering a bed, instead sending a chat message to inform them about the reason diff --git a/build.gradle b/build.gradle new file mode 100755 index 0000000..398b449 --- /dev/null +++ b/build.gradle @@ -0,0 +1,82 @@ +plugins { + id 'fabric-loom' version '0.12-SNAPSHOT' + id 'maven-publish' +} + +sourceCompatibility = JavaVersion.VERSION_17 +targetCompatibility = JavaVersion.VERSION_17 + +archivesBaseName = project.archives_base_name +version = project.mod_version +group = project.maven_group + +repositories { + maven { url "https://api.modrinth.com/maven" } +} + +dependencies { + //to change the versions see the gradle.properties file + minecraft "com.mojang:minecraft:${project.minecraft_version}" + mappings "net.fabricmc:yarn:${project.yarn_mappings}:v2" + modImplementation "net.fabricmc:fabric-loader:${project.loader_version}" + + modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}" + modImplementation "maven.modrinth:midnightlib:${midnightlib_version}" + include "maven.modrinth:midnightlib:${midnightlib_version}" + +} + +processResources { + inputs.property "version", project.version + + filesMatching("fabric.mod.json") { + expand "version": project.version + } +} + +tasks.withType(JavaCompile).configureEach { + // ensure that the encoding is set to UTF-8, no matter what the system default is + // this fixes some edge cases with special characters not displaying correctly + // see http://yodaconditions.net/blog/fix-for-java-file-encoding-problems-with-gradle.html + // If Javadoc is generated, this must be specified in that task too. + it.options.encoding = "UTF-8" + + // Minecraft 1.17 (21w19a) upwards uses Java 16. + it.options.release = 17 +} + +java { + // Loom will automatically attach sourcesJar to a RemapSourcesJar task and to the "build" task + // if it is present. + // If you remove this line, sources will not be generated. + withSourcesJar() +} + +jar { + from("LICENSE") { + rename { "${it}_${project.archivesBaseName}"} + } +} + +// configure the maven publication +publishing { + publications { + mavenJava(MavenPublication) { + // add all the jars that should be included when publishing to maven + artifact(remapJar) { + builtBy remapJar + } + artifact(sourcesJar) { + builtBy remapSourcesJar + } + } + } + + // See https://docs.gradle.org/current/userguide/publishing_maven.html for information on how to set up publishing. + repositories { + // Add repositories to publish to here. + // Notice: This block does NOT have the same function as the block in the top level. + // The repositories here will be used for publishing your artifact, not for + // retrieving dependencies. + } +} diff --git a/celestria.png b/celestria.png new file mode 100644 index 0000000..c8c8983 Binary files /dev/null and b/celestria.png differ diff --git a/celestria.svg b/celestria.svg new file mode 100644 index 0000000..601e52d --- /dev/null +++ b/celestria.svg @@ -0,0 +1,186 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/celestria64.png b/celestria64.png new file mode 100644 index 0000000..33276aa Binary files /dev/null and b/celestria64.png differ diff --git a/gradle.properties b/gradle.properties new file mode 100755 index 0000000..1d17611 --- /dev/null +++ b/gradle.properties @@ -0,0 +1,18 @@ +# Done to increase the memory available to gradle. +org.gradle.jvmargs=-Xmx1G + +# Fabric Properties + # check these on https://fabricmc.net/use + minecraft_version=1.19.2 + yarn_mappings=1.19.2+build.4 + loader_version=0.14.9 + +# Mod Properties + mod_version = 1.0.0 + maven_group = eu.midnightdust + archives_base_name = celestria + +# Dependencies + # currently not on the main fabric site, check on the maven: https://maven.fabricmc.net/net/fabricmc/fabric-api/fabric-api + fabric_version=0.59.0+1.19.2 + midnightlib_version=0.5.2 diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar new file mode 100755 index 0000000..7454180 Binary files /dev/null and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties new file mode 100755 index 0000000..ffed3a2 --- /dev/null +++ b/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,5 @@ +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-bin.zip +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists diff --git a/gradlew b/gradlew new file mode 100755 index 0000000..1b6c787 --- /dev/null +++ b/gradlew @@ -0,0 +1,234 @@ +#!/bin/sh + +# +# Copyright © 2015-2021 the original authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +############################################################################## +# +# Gradle start up script for POSIX generated by Gradle. +# +# Important for running: +# +# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is +# noncompliant, but you have some other compliant shell such as ksh or +# bash, then to run this script, type that shell name before the whole +# command line, like: +# +# ksh Gradle +# +# Busybox and similar reduced shells will NOT work, because this script +# requires all of these POSIX shell features: +# * functions; +# * expansions «$var», «${var}», «${var:-default}», «${var+SET}», +# «${var#prefix}», «${var%suffix}», and «$( cmd )»; +# * compound commands having a testable exit status, especially «case»; +# * various built-in commands including «command», «set», and «ulimit». +# +# Important for patching: +# +# (2) This script targets any POSIX shell, so it avoids extensions provided +# by Bash, Ksh, etc; in particular arrays are avoided. +# +# The "traditional" practice of packing multiple parameters into a +# space-separated string is a well documented source of bugs and security +# problems, so this is (mostly) avoided, by progressively accumulating +# options in "$@", and eventually passing that to Java. +# +# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, +# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; +# see the in-line comments for details. +# +# There are tweaks for specific operating systems such as AIX, CygWin, +# Darwin, MinGW, and NonStop. +# +# (3) This script is generated from the Groovy template +# https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt +# within the Gradle project. +# +# You can find Gradle at https://github.com/gradle/gradle/. +# +############################################################################## + +# Attempt to set APP_HOME + +# Resolve links: $0 may be a link +app_path=$0 + +# Need this for daisy-chained symlinks. +while + APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path + [ -h "$app_path" ] +do + ls=$( ls -ld "$app_path" ) + link=${ls#*' -> '} + case $link in #( + /*) app_path=$link ;; #( + *) app_path=$APP_HOME$link ;; + esac +done + +APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit + +APP_NAME="Gradle" +APP_BASE_NAME=${0##*/} + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD=maximum + +warn () { + echo "$*" +} >&2 + +die () { + echo + echo "$*" + echo + exit 1 +} >&2 + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +nonstop=false +case "$( uname )" in #( + CYGWIN* ) cygwin=true ;; #( + Darwin* ) darwin=true ;; #( + MSYS* | MINGW* ) msys=true ;; #( + NONSTOP* ) nonstop=true ;; +esac + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD=$JAVA_HOME/jre/sh/java + else + JAVACMD=$JAVA_HOME/bin/java + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD=java + which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." +fi + +# Increase the maximum file descriptors if we can. +if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then + case $MAX_FD in #( + max*) + MAX_FD=$( ulimit -H -n ) || + warn "Could not query maximum file descriptor limit" + esac + case $MAX_FD in #( + '' | soft) :;; #( + *) + ulimit -n "$MAX_FD" || + warn "Could not set maximum file descriptor limit to $MAX_FD" + esac +fi + +# Collect all arguments for the java command, stacking in reverse order: +# * args from the command line +# * the main class name +# * -classpath +# * -D...appname settings +# * --module-path (only if needed) +# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. + +# For Cygwin or MSYS, switch paths to Windows format before running java +if "$cygwin" || "$msys" ; then + APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) + CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) + + JAVACMD=$( cygpath --unix "$JAVACMD" ) + + # Now convert the arguments - kludge to limit ourselves to /bin/sh + for arg do + if + case $arg in #( + -*) false ;; # don't mess with options #( + /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath + [ -e "$t" ] ;; #( + *) false ;; + esac + then + arg=$( cygpath --path --ignore --mixed "$arg" ) + fi + # Roll the args list around exactly as many times as the number of + # args, so each arg winds up back in the position where it started, but + # possibly modified. + # + # NB: a `for` loop captures its iteration list before it begins, so + # changing the positional parameters here affects neither the number of + # iterations, nor the values presented in `arg`. + shift # remove old arg + set -- "$@" "$arg" # push replacement arg + done +fi + +# Collect all arguments for the java command; +# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of +# shell script including quotes and variable substitutions, so put them in +# double quotes to make sure that they get re-expanded; and +# * put everything else in single quotes, so that it's not re-expanded. + +set -- \ + "-Dorg.gradle.appname=$APP_BASE_NAME" \ + -classpath "$CLASSPATH" \ + org.gradle.wrapper.GradleWrapperMain \ + "$@" + +# Use "xargs" to parse quoted args. +# +# With -n1 it outputs one arg per line, with the quotes and backslashes removed. +# +# In Bash we could simply go: +# +# readarray ARGS < <( xargs -n1 <<<"$var" ) && +# set -- "${ARGS[@]}" "$@" +# +# but POSIX shell has neither arrays nor command substitution, so instead we +# post-process each arg (as a line of input to sed) to backslash-escape any +# character that might be a shell metacharacter, then use eval to reverse +# that process (while maintaining the separation between arguments), and wrap +# the whole thing up as a single "set" statement. +# +# This will of course break if any of these variables contains a newline or +# an unmatched quote. +# + +eval "set -- $( + printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | + xargs -n1 | + sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | + tr '\n' ' ' + )" '"$@"' + +exec "$JAVACMD" "$@" diff --git a/gradlew.bat b/gradlew.bat new file mode 100755 index 0000000..107acd3 --- /dev/null +++ b/gradlew.bat @@ -0,0 +1,89 @@ +@rem +@rem Copyright 2015 the original author or authors. +@rem +@rem Licensed under the Apache License, Version 2.0 (the "License"); +@rem you may not use this file except in compliance with the License. +@rem You may obtain a copy of the License at +@rem +@rem https://www.apache.org/licenses/LICENSE-2.0 +@rem +@rem Unless required by applicable law or agreed to in writing, software +@rem distributed under the License is distributed on an "AS IS" BASIS, +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@rem See the License for the specific language governing permissions and +@rem limitations under the License. +@rem + +@if "%DEBUG%" == "" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +set DIRNAME=%~dp0 +if "%DIRNAME%" == "" set DIRNAME=. +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Resolve any "." and ".." in APP_HOME to make it shorter. +for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if "%ERRORLEVEL%" == "0" goto execute + +echo. +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto execute + +echo. +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* + +:end +@rem End local scope for the variables with windows NT shell +if "%ERRORLEVEL%"=="0" goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 +exit /b 1 + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/settings.gradle b/settings.gradle new file mode 100755 index 0000000..5b60df3 --- /dev/null +++ b/settings.gradle @@ -0,0 +1,10 @@ +pluginManagement { + repositories { + jcenter() + maven { + name = 'Fabric' + url = 'https://maven.fabricmc.net/' + } + gradlePluginPortal() + } +} diff --git a/src/main/java/eu/midnightdust/celestria/Celestria.java b/src/main/java/eu/midnightdust/celestria/Celestria.java new file mode 100755 index 0000000..77ca21f --- /dev/null +++ b/src/main/java/eu/midnightdust/celestria/Celestria.java @@ -0,0 +1,88 @@ +package eu.midnightdust.celestria; + +import com.mojang.brigadier.arguments.IntegerArgumentType; +import com.mojang.brigadier.builder.LiteralArgumentBuilder; +import eu.midnightdust.lib.util.MidnightColorUtil; +import eu.midnightdust.celestria.config.CelestriaConfig; +import eu.midnightdust.celestria.effect.InsomniaStatusEffect; +import io.netty.buffer.Unpooled; +import net.fabricmc.api.ModInitializer; +import net.fabricmc.fabric.api.command.v2.CommandRegistrationCallback; +import net.fabricmc.fabric.api.event.lifecycle.v1.ServerTickEvents; +import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking; +import net.minecraft.command.argument.EntityArgumentType; +import net.minecraft.entity.effect.StatusEffect; +import net.minecraft.entity.effect.StatusEffectCategory; +import net.minecraft.entity.effect.StatusEffectInstance; +import net.minecraft.entity.effect.StatusEffects; +import net.minecraft.network.PacketByteBuf; +import net.minecraft.server.command.CommandManager; +import net.minecraft.server.command.ServerCommandSource; +import net.minecraft.server.network.ServerPlayerEntity; +import net.minecraft.text.Text; +import net.minecraft.util.Identifier; +import net.minecraft.util.math.random.Random; +import net.minecraft.util.registry.Registry; + +import java.util.Collection; + +public class Celestria implements ModInitializer { + public static final String MOD_ID = "celestria"; + public static final Identifier SHOOTING_STAR_PACKET = new Identifier(MOD_ID, "shooting_star"); + public static final Identifier WELCOME_PACKET = new Identifier(MOD_ID, "welcome"); + public static final StatusEffect INSOMNIA = new InsomniaStatusEffect(StatusEffectCategory.HARMFUL, MidnightColorUtil.hex2Rgb("88A9C8").getRGB()); + public static int shootingStarCooldown = 0; + private int prevPlayerAmount = 0; + + public void onInitialize() { + CelestriaConfig.init(MOD_ID, CelestriaConfig.class); + Registry.register(Registry.STATUS_EFFECT, new Identifier(MOD_ID, "insomnia"), INSOMNIA); + LiteralArgumentBuilder command = CommandManager.literal("shootingStar"); + var commandPlayers = command.then(CommandManager.argument("players", EntityArgumentType.players())); + var commandX = commandPlayers.then(CommandManager.argument("x", IntegerArgumentType.integer(90, 180))); + var commandY = commandX.then(CommandManager.argument("y", IntegerArgumentType.integer(0, 360))); + var commandType = commandY.then(CommandManager.argument("type", IntegerArgumentType.integer(0, 3))); + LiteralArgumentBuilder finalized = CommandManager.literal("celestria").requires(source -> source.hasPermissionLevel(2)).then(commandType).executes(ctx -> + createShootingStar(EntityArgumentType.getPlayers(ctx, "players"), + IntegerArgumentType.getInteger(ctx, "x"), IntegerArgumentType.getInteger(ctx, "y"), IntegerArgumentType.getInteger(ctx, "type"))); + + CommandRegistrationCallback.EVENT.register((dispatcher, dedicated, registrationEnvironment) -> dispatcher.register(finalized)); + ServerTickEvents.END_WORLD_TICK.register(world -> { + if (shootingStarCooldown > 0) --shootingStarCooldown; + if (world.getPlayers().size() > prevPlayerAmount) { + world.getPlayers().forEach(player -> ServerPlayNetworking.send(player, WELCOME_PACKET, new PacketByteBuf(Unpooled.buffer()))); + prevPlayerAmount = world.getPlayers().size(); + } + if (world.isNight() && world.getMoonPhase() == 0) { + for (ServerPlayerEntity player : world.getPlayers()) { + if (world.random.nextInt(CelestriaConfig.insomniaChance) == 0) { + player.addStatusEffect(new StatusEffectInstance(INSOMNIA, CelestriaConfig.insomniaDuration, 0, true, false, true)); + } + } + } + if (world.isNight() && Celestria.shootingStarCooldown <= 0 && world.random.nextInt(CelestriaConfig.shootingStarChance) == 0) { + int x = world.random.nextBetween(100, 150); + int y = world.random.nextInt(360); + int type = world.random.nextInt(3); + createShootingStar(world.getPlayers(), x, y, type); + Celestria.shootingStarCooldown = CelestriaConfig.shootingStarCooldownLength; + } + }); + } + public int createShootingStar(Collection players, int x, int y, int type) { + int[] array = new int[3]; + array[0] = x; + array[1] = y; + array[2] = type; + PacketByteBuf passedData = new PacketByteBuf(Unpooled.buffer()); + passedData.writeIntArray(array); + + int message = Random.create().nextInt(CelestriaConfig.shootingStarMessages.size()); + players.forEach(player -> { + player.addStatusEffect(new StatusEffectInstance(StatusEffects.LUCK, CelestriaConfig.shootingStarLuckDuration, 0, true, false, true)); + ServerPlayNetworking.send(player, SHOOTING_STAR_PACKET, passedData); + if (CelestriaConfig.sendChatMessages) player.sendMessageToClient(Text.literal("§f§l[§7§lC§8§le§7§ll§f§le§7§ls§8§lt§7§lr§f§li§7§la§8§l] ").append(Text.translatable(CelestriaConfig.shootingStarMessages.get(message))),false); + }); + return 1; + } +} diff --git a/src/main/java/eu/midnightdust/celestria/CelestriaClient.java b/src/main/java/eu/midnightdust/celestria/CelestriaClient.java new file mode 100755 index 0000000..1cdb015 --- /dev/null +++ b/src/main/java/eu/midnightdust/celestria/CelestriaClient.java @@ -0,0 +1,56 @@ +package eu.midnightdust.celestria; + +import eu.midnightdust.celestria.config.CelestriaConfig; +import net.fabricmc.api.ClientModInitializer; +import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents; +import net.fabricmc.fabric.api.client.networking.v1.ClientPlayConnectionEvents; +import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking; +import net.fabricmc.fabric.api.resource.ResourceManagerHelper; +import net.fabricmc.fabric.api.resource.ResourcePackActivationType; +import net.fabricmc.loader.api.FabricLoader; +import net.minecraft.util.Identifier; + +public class CelestriaClient implements ClientModInitializer { + private static boolean clientOnlyMode = true; + public static int shootingStarProgress = 0; + public static int shootingStarType = 0; + public static int shootingStarX = 0; + public static int shootingStarY = 0; + + @Override + public void onInitializeClient() { + FabricLoader.getInstance().getModContainer(Celestria.MOD_ID).ifPresent(modContainer -> { + ResourceManagerHelper.registerBuiltinResourcePack(new Identifier(Celestria.MOD_ID,"realistic"), modContainer, ResourcePackActivationType.NORMAL); + ResourceManagerHelper.registerBuiltinResourcePack(new Identifier(Celestria.MOD_ID,"pixelperfect"), modContainer, ResourcePackActivationType.NORMAL); + }); + ClientPlayNetworking.registerGlobalReceiver(Celestria.SHOOTING_STAR_PACKET, + (client, handler, attachedData, packetSender) -> { + int[] array = attachedData.readIntArray(3); + client.execute(() -> { + if (client.world != null) { + CelestriaClient.clientOnlyMode = false; // If the welcome packet wasn't received correctly for some reason, disable clientOnlyMode on shooting star occurrence + CelestriaClient.shootingStarX = array[0]; + CelestriaClient.shootingStarY = array[1]; + CelestriaClient.shootingStarType = array[2]; + CelestriaClient.shootingStarProgress = 100 + shootingStarType * 10; + } + }); + }); + ClientPlayNetworking.registerGlobalReceiver(Celestria.WELCOME_PACKET, + (client, handler, attachedData, packetSender) -> client.execute(() -> CelestriaClient.clientOnlyMode = false)); + ClientTickEvents.END_CLIENT_TICK.register(client -> { + if (shootingStarProgress > 0) --shootingStarProgress; + if (CelestriaClient.clientOnlyMode && client.world != null) { + if (Celestria.shootingStarCooldown > 0) --Celestria.shootingStarCooldown; + if (client.world.isNight() && Celestria.shootingStarCooldown <= 0 && client.world.random.nextInt(CelestriaConfig.shootingStarChance) == 0) { + CelestriaClient.shootingStarX = client.world.random.nextBetween(100, 150); + CelestriaClient.shootingStarY = client.world.random.nextInt(360); + CelestriaClient.shootingStarType = client.world.random.nextInt(3); + CelestriaClient.shootingStarProgress = 100 + shootingStarType * 10; + Celestria.shootingStarCooldown = CelestriaConfig.shootingStarCooldownLength; + } + } + }); + ClientPlayConnectionEvents.DISCONNECT.register((handler, client) -> CelestriaClient.clientOnlyMode = true); + } +} diff --git a/src/main/java/eu/midnightdust/celestria/config/CelestriaConfig.java b/src/main/java/eu/midnightdust/celestria/config/CelestriaConfig.java new file mode 100755 index 0000000..ccbed38 --- /dev/null +++ b/src/main/java/eu/midnightdust/celestria/config/CelestriaConfig.java @@ -0,0 +1,17 @@ +package eu.midnightdust.celestria.config; + +import com.google.common.collect.Lists; +import eu.midnightdust.lib.config.MidnightConfig; + +import java.util.List; + +public class CelestriaConfig extends MidnightConfig { + @Entry public static boolean sendChatMessages = true; + @Entry public static int shootingStarChance = 10000; + @Entry public static int shootingStarCooldownLength = 1000; + @Entry public static int shootingStarLuckDuration = 1000; + @Entry public static int insomniaChance = 30000; + @Entry public static int insomniaDuration = 1000; + @Entry public static List shootingStarMessages = Lists.newArrayList("celestria.shootingStar.1", "celestria.shootingStar.2", "celestria.shootingStar.3"); + @Entry public static List insomniaMessages = Lists.newArrayList("celestria.insomnia.1", "celestria.insomnia.2"); +} diff --git a/src/main/java/eu/midnightdust/celestria/effect/InsomniaStatusEffect.java b/src/main/java/eu/midnightdust/celestria/effect/InsomniaStatusEffect.java new file mode 100644 index 0000000..8212dfa --- /dev/null +++ b/src/main/java/eu/midnightdust/celestria/effect/InsomniaStatusEffect.java @@ -0,0 +1,10 @@ +package eu.midnightdust.celestria.effect; + +import net.minecraft.entity.effect.StatusEffect; +import net.minecraft.entity.effect.StatusEffectCategory; + +public class InsomniaStatusEffect extends StatusEffect { + public InsomniaStatusEffect(StatusEffectCategory statusEffectCategory, int color) { + super(statusEffectCategory, color); + } +} diff --git a/src/main/java/eu/midnightdust/celestria/mixin/MixinBedBlock.java b/src/main/java/eu/midnightdust/celestria/mixin/MixinBedBlock.java new file mode 100644 index 0000000..3acdf2a --- /dev/null +++ b/src/main/java/eu/midnightdust/celestria/mixin/MixinBedBlock.java @@ -0,0 +1,29 @@ +package eu.midnightdust.celestria.mixin; + +import eu.midnightdust.celestria.Celestria; +import eu.midnightdust.celestria.config.CelestriaConfig; +import net.minecraft.block.BedBlock; +import net.minecraft.block.BlockState; +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.server.network.ServerPlayerEntity; +import net.minecraft.text.Text; +import net.minecraft.util.ActionResult; +import net.minecraft.util.Hand; +import net.minecraft.util.hit.BlockHitResult; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.World; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; + +@Mixin(BedBlock.class) +public abstract class MixinBedBlock { + @Inject(at = @At("HEAD"), method = "onUse", cancellable = true) + public void celestria$onBedUse(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit, CallbackInfoReturnable cir) { + if (!world.isClient() && player instanceof ServerPlayerEntity serverPlayer && player.hasStatusEffect(Celestria.INSOMNIA)) { + if (CelestriaConfig.sendChatMessages) serverPlayer.sendMessageToClient(Text.literal("§f§l[§7§lC§8§le§7§ll§f§le§7§ls§8§lt§7§lr§f§li§7§la§8§l] ").append(Text.translatable(CelestriaConfig.insomniaMessages.get(world.random.nextInt(CelestriaConfig.insomniaMessages.size())))),false); + cir.setReturnValue(ActionResult.FAIL); + } + } +} diff --git a/src/main/java/eu/midnightdust/celestria/mixin/MixinWorldRenderer.java b/src/main/java/eu/midnightdust/celestria/mixin/MixinWorldRenderer.java new file mode 100644 index 0000000..d6804e0 --- /dev/null +++ b/src/main/java/eu/midnightdust/celestria/mixin/MixinWorldRenderer.java @@ -0,0 +1,25 @@ +package eu.midnightdust.celestria.mixin; + +import eu.midnightdust.celestria.render.ShootingStarRenderer; +import net.minecraft.client.render.*; +import net.minecraft.client.util.math.MatrixStack; +import net.minecraft.client.world.ClientWorld; +import net.minecraft.util.math.Matrix4f; +import org.jetbrains.annotations.Nullable; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.Unique; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +@Mixin(WorldRenderer.class) +public abstract class MixinWorldRenderer { + @Unique private final ShootingStarRenderer shootingStarRenderer = new ShootingStarRenderer(); + @Shadow @Nullable private ClientWorld world; + + @Inject(at = @At(value = "INVOKE", target = "Lnet/minecraft/util/profiler/Profiler;swap(Ljava/lang/String;)V", ordinal = 6, shift = At.Shift.BEFORE), method = "render") + public void celestria$renderShootingStars(MatrixStack matrices, float tickDelta, long limitTime, boolean renderBlockOutline, Camera camera, GameRenderer gameRenderer, LightmapTextureManager lightmapTextureManager, Matrix4f positionMatrix, CallbackInfo ci) { + shootingStarRenderer.renderShootingStar(world, matrices); + } +} diff --git a/src/main/java/eu/midnightdust/celestria/render/ShootingStarRenderer.java b/src/main/java/eu/midnightdust/celestria/render/ShootingStarRenderer.java new file mode 100644 index 0000000..3fcff42 --- /dev/null +++ b/src/main/java/eu/midnightdust/celestria/render/ShootingStarRenderer.java @@ -0,0 +1,42 @@ +package eu.midnightdust.celestria.render; + +import com.mojang.blaze3d.systems.RenderSystem; +import eu.midnightdust.celestria.Celestria; +import eu.midnightdust.celestria.CelestriaClient; +import eu.midnightdust.lib.util.MidnightMathUtil; +import net.minecraft.client.render.*; +import net.minecraft.client.util.math.MatrixStack; +import net.minecraft.client.world.ClientWorld; +import net.minecraft.util.Identifier; +import net.minecraft.util.math.Matrix4f; +import net.minecraft.util.math.Vec3f; + +public class ShootingStarRenderer { + public void renderShootingStar(ClientWorld world, MatrixStack matrices) { + if (world != null && CelestriaClient.shootingStarProgress > 0) { + world.getProfiler().swap("shooting_star"); + matrices.push(); + matrices.multiply(Vec3f.POSITIVE_Y.getDegreesQuaternion(MidnightMathUtil.isEven(CelestriaClient.shootingStarType) ? CelestriaClient.shootingStarY + CelestriaClient.shootingStarProgress : CelestriaClient.shootingStarY - CelestriaClient.shootingStarProgress)); + matrices.multiply(Vec3f.POSITIVE_X.getDegreesQuaternion(CelestriaClient.shootingStarX)); + Matrix4f matrix4f = matrices.peek().getPositionMatrix(); + Tessellator tessellator = Tessellator.getInstance(); + BufferBuilder bufferBuilder = tessellator.getBuffer(); + RenderSystem.enableTexture(); + RenderSystem.defaultBlendFunc(); + RenderSystem.enableDepthTest(); + RenderSystem.enableBlend(); + float alpha = (float) (Math.log(CelestriaClient.shootingStarProgress) / 5f); + RenderSystem.setShaderColor(1,1,1,alpha); + RenderSystem.setShader(GameRenderer::getPositionTexShader); + RenderSystem.setShaderTexture(0, new Identifier(Celestria.MOD_ID, "textures/environment/shooting_star"+(CelestriaClient.shootingStarType+1)+".png")); + bufferBuilder.begin(VertexFormat.DrawMode.QUADS, VertexFormats.POSITION_TEXTURE); + bufferBuilder.vertex(matrix4f, -20.0F, -100.0F, 20.0F).texture(0.0F, 0.0F).next(); + bufferBuilder.vertex(matrix4f, 20.0F, -100.0F, 20.0F).texture(1.0F, 0.0F).next(); + bufferBuilder.vertex(matrix4f, 20.0F, -100.0F, -20.0F).texture(1.0F, 1.0F).next(); + bufferBuilder.vertex(matrix4f, -20.0F, -100.0F, -20.0F).texture(0.0F, 1.0F).next(); + BufferRenderer.drawWithShader(bufferBuilder.end()); + RenderSystem.disableTexture(); + matrices.pop(); + } + } +} diff --git a/src/main/resources/assets/celestria/icon.png b/src/main/resources/assets/celestria/icon.png new file mode 100644 index 0000000..33276aa Binary files /dev/null and b/src/main/resources/assets/celestria/icon.png differ diff --git a/src/main/resources/assets/celestria/lang/de_de.json b/src/main/resources/assets/celestria/lang/de_de.json new file mode 100755 index 0000000..fd359ad --- /dev/null +++ b/src/main/resources/assets/celestria/lang/de_de.json @@ -0,0 +1,17 @@ +{ + "celestria.midnightconfig.title": "Celestria Konfiguration", + "celestria.midnightconfig.sendChatMessages": "Sende Chat Nachrichten bei Events", + "celestria.midnightconfig.shootingStarChance": "Sternschnuppen-Wahrscheinlichkeit", + "celestria.midnightconfig.shootingStarCooldownLength": "Sternschnuppen Cooldown Länge", + "celestria.midnightconfig.shootingStarLuckDuration": "Sternschnuppen Glück Effektlänge", + "celestria.midnightconfig.shootingStarMessages": "Sternschnuppen-Nachrichten", + "celestria.midnightconfig.insomniaChance": "Schlaflosigkeits-Wahrscheinlichkeit", + "celestria.midnightconfig.insomniaMessages": "Schlaflosigkeits-Nachrichten", + "celestria.midnightconfig.insomniaDuration": "Schlaflosigkeit Effektlänge", + "celestria.shootingStar.1": "§eOh, schau! Eine Sternschnuppe ist erschienen und hat dir Glück gebracht!", + "celestria.shootingStar.2": "§6Wow, eine Sternschnuppe ist erschienen, wünsch dir was!", + "celestria.shootingStar.3": "§2♪ Can we pretend that airplanes in the night sky are like shooting stars... ♫\n§3Oh warte, da ist ja eine echte Sternschnuppe!", + "celestria.insomnia.1": "§cDu hast Angst vor dem Vollmond, also kannst du einfach nicht einschlafen...", + "celestria.insomnia.2": "§3Ouuwwwh... Du hörst seltsame Geräusche und kannst deine Augen nicht schließen", + "celestria.mob_effect.insomnia": "Schlaflosigkeit" +} \ No newline at end of file diff --git a/src/main/resources/assets/celestria/lang/en_us.json b/src/main/resources/assets/celestria/lang/en_us.json new file mode 100755 index 0000000..9ca14ee --- /dev/null +++ b/src/main/resources/assets/celestria/lang/en_us.json @@ -0,0 +1,17 @@ +{ + "celestria.midnightconfig.title": "Celestria Config", + "celestria.midnightconfig.sendChatMessages": "Send Chat Messages on Events", + "celestria.midnightconfig.shootingStarChance": "Shooting Star Chance", + "celestria.midnightconfig.shootingStarCooldownLength": "Shooting Star Cooldown Length", + "celestria.midnightconfig.shootingStarLuckDuration": "Shooting Star Luck Duration", + "celestria.midnightconfig.shootingStarMessages": "Shooting Star Messages", + "celestria.midnightconfig.insomniaChance": "Insomnia Chance", + "celestria.midnightconfig.insomniaMessages": "Insomnia Messages", + "celestria.midnightconfig.insomniaDuration": "Insomnia Effect Duration", + "celestria.shootingStar.1": "§eOh, look! A shooting star appeared and blessed you with good luck!", + "celestria.shootingStar.2": "§6Wow, a shooting star appeared, make a wish!", + "celestria.shootingStar.3": "§2♪ Can we pretend that airplanes in the night sky are like shooting stars... ♫\n§3Oh wait, there's a real one!", + "celestria.insomnia.1": "§cYou're afraid of the full moon, so you just can't find no rest...", + "celestria.insomnia.2": "§3Ouuwwwh... You hear strange noises from afar and can't close your eyes", + "celestria.mob_effect.insomnia": "Insomnia" +} \ No newline at end of file diff --git a/src/main/resources/assets/celestria/textures/environment/shooting_star1.png b/src/main/resources/assets/celestria/textures/environment/shooting_star1.png new file mode 100644 index 0000000..b0d3396 Binary files /dev/null and b/src/main/resources/assets/celestria/textures/environment/shooting_star1.png differ diff --git a/src/main/resources/assets/celestria/textures/environment/shooting_star2.png b/src/main/resources/assets/celestria/textures/environment/shooting_star2.png new file mode 100644 index 0000000..6c3e927 Binary files /dev/null and b/src/main/resources/assets/celestria/textures/environment/shooting_star2.png differ diff --git a/src/main/resources/assets/celestria/textures/environment/shooting_star3.png b/src/main/resources/assets/celestria/textures/environment/shooting_star3.png new file mode 100644 index 0000000..be8902f Binary files /dev/null and b/src/main/resources/assets/celestria/textures/environment/shooting_star3.png differ diff --git a/src/main/resources/assets/celestria/textures/environment/shooting_star4.png b/src/main/resources/assets/celestria/textures/environment/shooting_star4.png new file mode 100644 index 0000000..382cc0f Binary files /dev/null and b/src/main/resources/assets/celestria/textures/environment/shooting_star4.png differ diff --git a/src/main/resources/assets/celestria/textures/mob_effect/insomnia.png b/src/main/resources/assets/celestria/textures/mob_effect/insomnia.png new file mode 100644 index 0000000..2d877d2 Binary files /dev/null and b/src/main/resources/assets/celestria/textures/mob_effect/insomnia.png differ diff --git a/src/main/resources/celestria.mixins.json b/src/main/resources/celestria.mixins.json new file mode 100755 index 0000000..b6e3fcb --- /dev/null +++ b/src/main/resources/celestria.mixins.json @@ -0,0 +1,14 @@ +{ + "required": true, + "package": "eu.midnightdust.celestria.mixin", + "compatibilityLevel": "JAVA_17", + "client": [ + "MixinWorldRenderer" + ], + "mixins": [ + "MixinBedBlock" + ], + "injectors": { + "defaultRequire": 1 + } +} \ No newline at end of file diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json new file mode 100755 index 0000000..815255b --- /dev/null +++ b/src/main/resources/fabric.mod.json @@ -0,0 +1,34 @@ +{ + "schemaVersion": 1, + "id": "celestria", + "version": "${version}", + + "name": "Celestria", + "description": "Adds celestrial events, such as shooting stars and occasional insomnia from full moon.", + "authors": [ + "Motschen", + "TeamMidnightDust" + ], + "contact": { + "homepage": "https://www.midnightdust.eu/", + "sources": "https://github.com/TeamMidnightDust/Celestria", + "issues": "https://github.com/TeamMidnightDust/Celestria/issues" + }, + + "license": "MIT", + "icon": "assets/celestria/icon.png", + + "environment": "*", + "entrypoints": { + "main": [ + "eu.midnightdust.celestria.Celestria" + ], + "client": [ + "eu.midnightdust.celestria.CelestriaClient" + ] + }, + + "mixins": [ + "celestria.mixins.json" + ] +} diff --git a/src/main/resources/resourcepacks/pixelperfect/assets/celestria/textures/environment/shooting_star1.png b/src/main/resources/resourcepacks/pixelperfect/assets/celestria/textures/environment/shooting_star1.png new file mode 100644 index 0000000..54f4b80 Binary files /dev/null and b/src/main/resources/resourcepacks/pixelperfect/assets/celestria/textures/environment/shooting_star1.png differ diff --git a/src/main/resources/resourcepacks/pixelperfect/assets/celestria/textures/environment/shooting_star2.png b/src/main/resources/resourcepacks/pixelperfect/assets/celestria/textures/environment/shooting_star2.png new file mode 100644 index 0000000..f0465cb Binary files /dev/null and b/src/main/resources/resourcepacks/pixelperfect/assets/celestria/textures/environment/shooting_star2.png differ diff --git a/src/main/resources/resourcepacks/pixelperfect/assets/celestria/textures/environment/shooting_star3.png b/src/main/resources/resourcepacks/pixelperfect/assets/celestria/textures/environment/shooting_star3.png new file mode 100644 index 0000000..b5269a1 Binary files /dev/null and b/src/main/resources/resourcepacks/pixelperfect/assets/celestria/textures/environment/shooting_star3.png differ diff --git a/src/main/resources/resourcepacks/pixelperfect/assets/celestria/textures/environment/shooting_star4.png b/src/main/resources/resourcepacks/pixelperfect/assets/celestria/textures/environment/shooting_star4.png new file mode 100644 index 0000000..29dc359 Binary files /dev/null and b/src/main/resources/resourcepacks/pixelperfect/assets/celestria/textures/environment/shooting_star4.png differ diff --git a/src/main/resources/resourcepacks/pixelperfect/pack.mcmeta b/src/main/resources/resourcepacks/pixelperfect/pack.mcmeta new file mode 100755 index 0000000..1d19095 --- /dev/null +++ b/src/main/resources/resourcepacks/pixelperfect/pack.mcmeta @@ -0,0 +1,6 @@ +{ + "pack": { + "pack_format": 9, + "description": "Makes the shooting star texture consistent with vanilla stars" + } +} diff --git a/src/main/resources/resourcepacks/pixelperfect/pack.png b/src/main/resources/resourcepacks/pixelperfect/pack.png new file mode 100644 index 0000000..ce0db2e Binary files /dev/null and b/src/main/resources/resourcepacks/pixelperfect/pack.png differ diff --git a/src/main/resources/resourcepacks/realistic/SOURCES b/src/main/resources/resourcepacks/realistic/SOURCES new file mode 100755 index 0000000..33c48cb --- /dev/null +++ b/src/main/resources/resourcepacks/realistic/SOURCES @@ -0,0 +1,2 @@ +https://www.pngkey.com/maxpic/u2a9o0o0o0y3u2u2/ +https://picsart.com/i/sticker-275568554020211 diff --git a/src/main/resources/resourcepacks/realistic/assets/celestria/textures/environment/shooting_star1.png b/src/main/resources/resourcepacks/realistic/assets/celestria/textures/environment/shooting_star1.png new file mode 100644 index 0000000..3240e47 Binary files /dev/null and b/src/main/resources/resourcepacks/realistic/assets/celestria/textures/environment/shooting_star1.png differ diff --git a/src/main/resources/resourcepacks/realistic/assets/celestria/textures/environment/shooting_star2.png b/src/main/resources/resourcepacks/realistic/assets/celestria/textures/environment/shooting_star2.png new file mode 100644 index 0000000..4d56b5d Binary files /dev/null and b/src/main/resources/resourcepacks/realistic/assets/celestria/textures/environment/shooting_star2.png differ diff --git a/src/main/resources/resourcepacks/realistic/assets/celestria/textures/environment/shooting_star3.png b/src/main/resources/resourcepacks/realistic/assets/celestria/textures/environment/shooting_star3.png new file mode 100644 index 0000000..db661da Binary files /dev/null and b/src/main/resources/resourcepacks/realistic/assets/celestria/textures/environment/shooting_star3.png differ diff --git a/src/main/resources/resourcepacks/realistic/assets/celestria/textures/environment/shooting_star4.png b/src/main/resources/resourcepacks/realistic/assets/celestria/textures/environment/shooting_star4.png new file mode 100644 index 0000000..9b6d095 Binary files /dev/null and b/src/main/resources/resourcepacks/realistic/assets/celestria/textures/environment/shooting_star4.png differ diff --git a/src/main/resources/resourcepacks/realistic/pack.mcmeta b/src/main/resources/resourcepacks/realistic/pack.mcmeta new file mode 100755 index 0000000..c735173 --- /dev/null +++ b/src/main/resources/resourcepacks/realistic/pack.mcmeta @@ -0,0 +1,6 @@ +{ + "pack": { + "pack_format": 9, + "description": "Makes the shooting star textures appear realistic" + } +} diff --git a/src/main/resources/resourcepacks/realistic/pack.png b/src/main/resources/resourcepacks/realistic/pack.png new file mode 100644 index 0000000..db661da Binary files /dev/null and b/src/main/resources/resourcepacks/realistic/pack.png differ