8 Commits

Author SHA1 Message Date
86f67529dc 1.21.11 2025-12-11 21:34:32 +01:00
8df1c1244f Update gradle.properties 2025-10-11 18:48:21 +02:00
dcb81f8a0f 1.21.9 2025-10-01 20:16:16 +02:00
e19e164c69 remove plugin 2025-09-18 14:57:51 +02:00
4a8c1819a3 Fix leashes 2025-08-20 20:48:47 +02:00
0e5a830912 Update FastGhast.java 2025-08-20 20:37:38 +02:00
799d7075ac mod version 2025-08-20 20:37:02 +02:00
1ed722c299 Add leash protection 2025-08-11 22:01:28 +02:00
16 changed files with 233 additions and 94 deletions

8
.gitignore vendored
View File

@@ -1,4 +1,4 @@
/.gradle .gradle
/.idea .idea
/build build
/run run

21
LICENSE.txt Normal file
View File

@@ -0,0 +1,21 @@
The MIT License (MIT)
Copyright (c) 2025
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

View File

@@ -1,55 +1,47 @@
plugins { plugins {
id 'java' id 'fabric-loom' version "${loom_version}"
id("xyz.jpenilla.run-paper") version "2.3.1" id 'maven-publish'
} }
group = 'com.kasetoatz' version = project.mod_version
version = '1.0' group = project.maven_group
repositories { base {
mavenCentral() archivesName = project.archives_base_name
maven {
name = "spigotmc-repo"
url = "https://hub.spigotmc.org/nexus/content/repositories/snapshots/"
}
} }
dependencies { dependencies {
compileOnly("org.spigotmc:spigot-api:1.21.8-R0.1-SNAPSHOT") 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}"
} }
tasks { processResources {
runServer { inputs.property "version", project.version
// Configure the Minecraft version for our task. inputs.property "minecraft_version", project.minecraft_version
// This is the only required configuration besides applying the plugin. inputs.property "loader_version", project.loader_version
// Your plugin's jar (or shadowJar if present) will be used automatically. filteringCharset "UTF-8"
minecraftVersion("1.21.8")
filesMatching("fabric.mod.json") {
expand "version": project.version,
"minecraft_version": project.minecraft_version,
"loader_version": project.loader_version
} }
} }
def targetJavaVersion = 21 def targetJavaVersion = 21
tasks.withType(JavaCompile).configureEach {
it.options.encoding = "UTF-8"
if (targetJavaVersion >= 10 || JavaVersion.current().isJava10Compatible()) {
it.options.release.set(targetJavaVersion)
}
}
java { java {
def javaVersion = JavaVersion.toVersion(targetJavaVersion) def javaVersion = JavaVersion.toVersion(targetJavaVersion)
sourceCompatibility = javaVersion
targetCompatibility = javaVersion
if (JavaVersion.current() < javaVersion) { if (JavaVersion.current() < javaVersion) {
toolchain.languageVersion = JavaLanguageVersion.of(targetJavaVersion) toolchain.languageVersion = JavaLanguageVersion.of(targetJavaVersion)
} }
} withSourcesJar()
tasks.withType(JavaCompile).configureEach {
options.encoding = 'UTF-8'
if (targetJavaVersion >= 10 || JavaVersion.current().isJava10Compatible()) {
options.release.set(targetJavaVersion)
}
}
processResources {
def props = [version: version]
inputs.properties props
filteringCharset 'UTF-8'
filesMatching('plugin.yml') {
expand props
}
} }

View File

@@ -0,0 +1,15 @@
# Done to increase the memory available to gradle.
org.gradle.jvmargs=-Xmx1G
# Fabric Properties
# check these on https://modmuss50.me/fabric.html
minecraft_version=1.21.11
yarn_mappings=1.21.11+build.2
loader_version=0.18.2
loom_version=1.14-SNAPSHOT
# Mod Properties
mod_version=1.3
maven_group=com.kasetoatz
archives_base_name=fastghast
# Dependencies
# check this on https://modmuss50.me/fabric.html
fabric_version=0.139.5+1.21.11

Binary file not shown.

View File

@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.8-bin.zip distributionUrl=https\://services.gradle.org/distributions/gradle-9.2.1-bin.zip
networkTimeout=10000 networkTimeout=10000
validateDistributionUrl=true validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME zipStoreBase=GRADLE_USER_HOME

10
gradlew vendored
View File

@@ -15,6 +15,8 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
# #
# SPDX-License-Identifier: Apache-2.0
#
############################################################################## ##############################################################################
# #
@@ -84,7 +86,7 @@ done
# shellcheck disable=SC2034 # shellcheck disable=SC2034
APP_BASE_NAME=${0##*/} APP_BASE_NAME=${0##*/}
# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036) # Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
APP_HOME=$( cd "${APP_HOME:-./}" > /dev/null && pwd -P ) || exit APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s\n' "$PWD" ) || exit
# Use the maximum available, or set MAX_FD != -1 to use that value. # Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD=maximum MAX_FD=maximum
@@ -112,7 +114,7 @@ case "$( uname )" in #(
NONSTOP* ) nonstop=true ;; NONSTOP* ) nonstop=true ;;
esac esac
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar CLASSPATH="\\\"\\\""
# Determine the Java command to use to start the JVM. # Determine the Java command to use to start the JVM.
@@ -203,7 +205,7 @@ fi
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
# Collect all arguments for the java command: # Collect all arguments for the java command:
# * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments, # * DEFAULT_JVM_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments,
# and any embedded shellness will be escaped. # 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 # * 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. # treated as '${Hostname}' itself on the command line.
@@ -211,7 +213,7 @@ DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
set -- \ set -- \
"-Dorg.gradle.appname=$APP_BASE_NAME" \ "-Dorg.gradle.appname=$APP_BASE_NAME" \
-classpath "$CLASSPATH" \ -classpath "$CLASSPATH" \
org.gradle.wrapper.GradleWrapperMain \ -jar "$APP_HOME/gradle/wrapper/gradle-wrapper.jar" \
"$@" "$@"
# Stop when "xargs" is not available. # Stop when "xargs" is not available.

6
gradlew.bat vendored
View File

@@ -13,6 +13,8 @@
@rem See the License for the specific language governing permissions and @rem See the License for the specific language governing permissions and
@rem limitations under the License. @rem limitations under the License.
@rem @rem
@rem SPDX-License-Identifier: Apache-2.0
@rem
@if "%DEBUG%"=="" @echo off @if "%DEBUG%"=="" @echo off
@rem ########################################################################## @rem ##########################################################################
@@ -68,11 +70,11 @@ goto fail
:execute :execute
@rem Setup the command line @rem Setup the command line
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar set CLASSPATH=
@rem Execute Gradle @rem Execute Gradle
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" -jar "%APP_HOME%\gradle\wrapper\gradle-wrapper.jar" %*
:end :end
@rem End local scope for the variables with windows NT shell @rem End local scope for the variables with windows NT shell

View File

@@ -1 +1,9 @@
rootProject.name = 'FastGhast' pluginManagement {
repositories {
maven {
name = 'Fabric'
url = 'https://maven.fabricmc.net/'
}
gradlePluginPortal()
}
}

View File

@@ -1,49 +1,26 @@
package com.kasetoatz.fastGhast; package com.kasetoatz.fastghast;
import org.bukkit.attribute.Attribute; import net.fabricmc.api.ModInitializer;
import org.bukkit.attribute.AttributeInstance; import net.fabricmc.fabric.api.event.lifecycle.v1.ServerTickEvents;
import org.bukkit.entity.Entity; import net.minecraft.entity.Leashable;
import org.bukkit.entity.HappyGhast; import net.minecraft.entity.passive.HappyGhastEntity;
import org.bukkit.event.EventHandler; import net.minecraft.network.packet.s2c.play.PositionFlag;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntityDismountEvent;
import org.bukkit.event.entity.EntityMountEvent;
import org.bukkit.plugin.java.JavaPlugin;
public final class FastGhast extends JavaPlugin implements Listener import java.util.EnumSet;
import static com.kasetoatz.fastghast.config.Config.load;
public class FastGhast implements ModInitializer
{ {
private static final double DEFAULT = 0.05;
private double SPEED;
@Override @Override
public void onEnable() public void onInitialize()
{ {
saveDefaultConfig(); load();
SPEED = getConfig().getDouble("speed"); ServerTickEvents.END_SERVER_TICK.register((server) -> server.getWorlds().forEach(world -> world.iterateEntities().forEach(entity -> {
getServer().getPluginManager().registerEvents(this, this); if (entity instanceof Leashable leashed && leashed.isLeashed() && leashed.getLeashHolder() instanceof HappyGhastEntity ghast && leashed.getDistanceToCenter(ghast) > 8)
}
private void setSpeed(Entity entity, double speed)
{
if (entity instanceof HappyGhast ghast)
{
AttributeInstance attr = ghast.getAttribute(Attribute.FLYING_SPEED);
if (attr != null)
{ {
attr.setBaseValue(speed); entity.teleport(world, ghast.getX(), ghast.getY(), ghast.getZ(), EnumSet.noneOf(PositionFlag.class), entity.getYaw(), entity.getPitch(), false);
} }
} })));
}
@EventHandler
public void onEntityMount(EntityMountEvent event)
{
setSpeed(event.getMount(), SPEED);
}
@EventHandler
public void onEntityDismount(EntityDismountEvent event)
{
setSpeed(event.getDismounted(), DEFAULT);
} }
} }

View File

@@ -0,0 +1,62 @@
package com.kasetoatz.fastghast.config;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonObject;
import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.util.crash.CrashException;
import net.minecraft.util.crash.CrashReport;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
public class Config
{
public static double UNMOUNTED_SPEED = 0.05;
public static double MOUNTED_SPEED = 0.15;
private static final Path FILE = FabricLoader.getInstance().getConfigDir().resolve("fastghast.json");
private static final Gson GSON = new GsonBuilder().setPrettyPrinting().create();
public static void load() {
if (!Files.exists(FILE))
{
save();
return;
}
try
{
String json = Files.readString(FILE);
JsonObject data = GSON.fromJson(json, JsonObject.class);
if (data.has("unmounted-speed"))
{
UNMOUNTED_SPEED = data.get("unmounted-speed").getAsDouble();
}
if (data.has("mounted-speed"))
{
MOUNTED_SPEED = data.get("mounted-speed").getAsDouble();
}
save();
}
catch (IOException exc)
{
throw new CrashException(CrashReport.create(exc, "Loading config file."));
}
}
private static void save()
{
try
{
JsonObject data = new JsonObject();
data.addProperty("unmounted-speed", UNMOUNTED_SPEED);
data.addProperty("mounted-speed", MOUNTED_SPEED);
Files.writeString(FILE, GSON.toJson(data));
}
catch (IOException exc)
{
throw new CrashException(CrashReport.create(exc, "Saving config file."));
}
}
}

View File

@@ -0,0 +1,27 @@
package com.kasetoatz.fastghast.mixin;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.attribute.EntityAttribute;
import net.minecraft.entity.passive.HappyGhastEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.registry.entry.RegistryEntry;
import org.jetbrains.annotations.Nullable;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Redirect;
import static com.kasetoatz.fastghast.config.Config.MOUNTED_SPEED;
import static com.kasetoatz.fastghast.config.Config.UNMOUNTED_SPEED;
@Mixin(HappyGhastEntity.class)
public abstract class HappyGhastMixin
{
@Shadow @Nullable public abstract LivingEntity getControllingPassenger();
@Redirect(method="travel", at=@At(value="INVOKE", target="Lnet/minecraft/entity/passive/HappyGhastEntity;getAttributeValue(Lnet/minecraft/registry/entry/RegistryEntry;)D"))
public double speed(HappyGhastEntity instance, RegistryEntry<EntityAttribute> registryEntry)
{
return getControllingPassenger() instanceof PlayerEntity ? MOUNTED_SPEED : UNMOUNTED_SPEED;
}
}

View File

@@ -1,2 +0,0 @@
# Flying speed of mounted Happy Ghasts, default speed is 0.05 so 0.15 is 3 times as fast.
speed: 0.15

View File

@@ -0,0 +1,24 @@
{
"schemaVersion": 1,
"id": "fastghast",
"version": "${version}",
"name": "FastGhast",
"description": "",
"authors": [],
"contact": {},
"license": "MIT",
"environment": "*",
"entrypoints": {
"main": [
"com.kasetoatz.fastghast.FastGhast"
]
},
"mixins": [
"fastghast.mixins.json"
],
"depends": {
"fabricloader": ">=${loader_version}",
"fabric": "*",
"minecraft": "${minecraft_version}"
}
}

View File

@@ -0,0 +1,15 @@
{
"required": true,
"minVersion": "0.8",
"package": "com.kasetoatz.fastghast.mixin",
"compatibilityLevel": "JAVA_21",
"mixins": [
"HappyGhastMixin"
],
"injectors": {
"defaultRequire": 1
},
"overwrites": {
"requireAnnotations": true
}
}

View File

@@ -1,4 +0,0 @@
name: FastGhast
version: '1.0'
main: com.kasetoatz.fastGhast.FastGhast
api-version: '1.21'