mod version

This commit is contained in:
2025-08-20 20:37:02 +02:00
parent 1ed722c299
commit 799d7075ac
24 changed files with 724 additions and 93 deletions

View File

@@ -1,57 +1,14 @@
package com.kasetoatz.fastGhast;
package com.kasetoatz.fastghast;
import org.bukkit.Bukkit;
import org.bukkit.attribute.Attribute;
import org.bukkit.attribute.AttributeInstance;
import org.bukkit.entity.*;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntityDismountEvent;
import org.bukkit.event.entity.EntityMountEvent;
import org.bukkit.plugin.java.JavaPlugin;
import io.papermc.paper.entity.Leashable;
import net.fabricmc.api.ModInitializer;
public final class FastGhast extends JavaPlugin implements Listener
import static com.kasetoatz.fastghast.config.Config.load;
public class Fastghast implements ModInitializer
{
private static final double DEFAULT = 0.05;
private double SPEED;
@Override
public void onEnable()
public void onInitialize()
{
saveDefaultConfig();
SPEED = getConfig().getDouble("speed");
getServer().getPluginManager().registerEvents(this, this);
Bukkit.getScheduler().runTaskTimer(this, () -> {
getServer().getWorlds().forEach(world -> world.getEntities().forEach(entity -> {
if (entity instanceof Leashable leashed && leashed.isLeashed() && leashed.getLeashHolder() instanceof HappyGhast ghast && leashed.getLocation().distance(ghast.getLocation()) > 8) {
leashed.teleport(ghast.getLocation());
}
}));
}, 0, 1);
}
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);
}
}
}
@EventHandler
public void onEntityMount(EntityMountEvent event)
{
setSpeed(event.getMount(), SPEED);
}
@EventHandler
public void onEntityDismount(EntityDismountEvent event)
{
setSpeed(event.getDismounted(), DEFAULT);
load();
}
}

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,25 @@
{
"schemaVersion": 1,
"id": "fastghast",
"version": "${version}",
"name": "FastGhast",
"description": "",
"authors": [],
"contact": {},
"license": "MIT",
"icon": "assets/fastghast/icon.png",
"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.1'
main: com.kasetoatz.fastGhast.FastGhast
api-version: '1.21'