d1v1n3_2

Make the happy ghast when riding them in the air make it to where they go as can go as fast as an elytra while using rockets but add a feature where you can control the speed on different levels

Kodari AI
KodariJul 4 at 4:37 am 2
HappyGhastFlight
Enhances Happy Ghast flight mechanics when ridden by players. Travel through the air at elytra-equivalent speeds with rocket boost, and control your flight speed across multiple levels. Adds a configurable speed system allowing riders to adjust velocity with intuitive controls, making the Happy Ghast a viable and fun aerial transport option in survival Minecraft.

Let me read the documentation I need to implement this.

I’ll build a Happy Ghast Flight Enhancement mod with rocket boost and configurable speed levels.

HappyGhastFlight
Enhances Happy Ghast flight mechanics when ridden by players. Travel through the air at elytra-equivalent speeds with rocket boost, and control your flight speed across multiple levels. Adds a configurable speed system allowing riders to adjust velocity with intuitive controls, making the Happy Ghast a viable and fun aerial transport option in survival Minecraft.

I also need to fix a potential issue with the KeyBinding category creation — the 3-arg form doesn’t take InputUtil.Type:

Now I need to verify the client accessor — the client needs IHappyGhastData in its classpath. Since it’s in the main source set, it’s available to client. But HappyGhastEntityMixin is in the main source set and uses LivingEntity constructor which is fine because HappyGhastEntity extends it.

Let me also check: the client-side keybinding needs IHappyGhastData to be accessible on the client side. Since it’s in src/main/java/, it’s in the shared source set and available to both. But the mixin applies the interface to HappyGhastEntity, and on the client the entity class is available with that interface applied at runtime. So client.player.getVehicle() instanceof IHappyGhastData will work because the mixin adds the interface.

Wait, there’s a subtlety — the client accesses ghastData.happyghastflight$setSpeedLevel(next) locally. This modifies the tracked data on the client, but the server will overwrite it with the value from the packet. Since we send a packet AND set it locally, the local value will briefly be the new level until the server syncs back. This is actually fine for responsive UI feedback.

Let me double-check the mixin structure: the interface IHappyGhastData is implemented by HappyGhastEntityMixin (via implements IHappyGhastData on the mixin class). The mixin applies to HappyGhastEntity, so at runtime, HappyGhastEntity will have the interface methods.

However, there’s a problem: the mixin class extends LivingEntity with a constructor that takes EntityType and World. But HappyGhastEntity already extends LivingEntity (or some other class). In a mixin, the mixin class doesn’t actually instantiate — it’s just declaring the structure. The extends LivingEntity is only needed for the compiler (to access super methods), but when using @Mixin(HappyGhastEntity.class), the mixin class’s superclass doesn’t need to match the target’s superclass.

Actually, for extends LivingEntity in the mixin — this is problematic because HappyGhastEntity might not directly extend LivingEntity. And the constructor needs to call super(entityType, world). This might cause compilation issues.

The simpler approach: don’t have the mixin class extend anything except Object. Use @Unique fields and methods, and use (HappyGhastEntity)(Object)this casts when needed.

Let me rewrite the mixin:

Let me also reconsider — the writeCustomData and readCustomData signatures. In 1.21.6+, these take ReadView / WriteView. But I’m using @Inject with @At("TAIL"). The target method is writeData(WriteView) and readData(ReadView) as per the breaking change guide. Let me verify the method names.

From the breaking change guide:

Java
@Override
protected void readData(ReadView view) {
    super.readData(view);
    this.storedValue = view.getInt("storedValue", 0);
}

@Override
protected void writeData(WriteView view) {
    super.writeData(view);
    view.putInt("storedValue", this.storedValue);
}

So the method names are readData and writeData, not readCustomData and writeCustomData. Let me fix this.

Also, I need to check if the HappyGhastEntity uses these methods or the readCustomData/writeCustomData methods from the LivingEntity pattern. In the entity guide, it shows readCustomData and writeCustomData for entities. Let me double check…

From the entity guide:

Java
@Override
protected void writeCustomData(WriteView view) {
    super.writeCustomData(view);
    view.putInt("Variant", dataTracker.get(VARIANT));
}

@Override
protected void readCustomData(ReadView view) {
    super.readCustomData(view);
    dataTracker.set(VARIANT, view.getInt("Variant", 0));
}

So for entities, it’s writeCustomData(WriteView) and readCustomData(ReadView). The BlockEntity uses readData/writeData.

Good, so my original method names are correct for entities. Let me update the mixin to target the correct methods.

But wait — the actual method names in Yarn for the entity might differ. Let me check… The entity persistence methods are indeed named writeCustomData and readCustomData in Yarn mappings.

Let me also reconsider the travel injection. The method signature for travel in Yarn is travel(Vec3d). The vanilla HappyGhast already has its own travel logic. Our injection cancels it and replaces it with our own. This should work.

However, I realize there might be an issue with the velocity friction. In vanilla travel, the entity applies movement and friction as part of the method. By cancelling it and doing our own, we need to make sure we replicate the essential parts (move + friction).

Let me finalize the code and make sure everything is correct.

Actually, let me reconsider the onWriteCustomData/onReadCustomData injection point. The entity’s writeCustomData is called from writeNbt which calls it during saving. Since we’re injecting at TAIL, our data gets added after the entity’s own data. That’s correct.

One more concern: in the client keybind handler, we call ghastData.happyghastflight$setSpeedLevel(next) locally. This modifies the tracked data on the client side. But the tracked data is synced from the server — when the server sends the entity data packet, it will overwrite whatever we set locally. Since we’re also sending a packet to the server, the server sets the value and syncs it back. The brief local inconsistency is acceptable for responsiveness.

Let me also make sure the mixin package is correct in the config file. I have "package": "com.happyghastflight.mixin" with mixins array ["HappyGhastEntityMixin"] — that’s correct.

Now let me think about whether the mixin needs to be client-only. The travel method and entity data are used on both sides, so it should be in the main mixins array, not client. That’s correct.

I think the code is solid. Let me verify the full structure once more:

Plain Text
happyghastflight/
  src/main/java/com/happyghastflight/
    HappyGhastFlight.java          ✓
    IHappyGhastData.java           ✓
    config/ModConfig.java          ✓
    mixin/HappyGhastEntityMixin.java  ✓
    network/SpeedLevelPayload.java ✓
  src/client/java/com/happyghastflight/
    HappyGhastFlightClient.java    ✓
    client/ModKeybindings.java     ✓
  src/main/resources/
    fabric.mod.json                ✓
    happyghastflight.mixins.json   ✓
    assets/happyghastflight/lang/en_us.json ✓
  build.gradle                     ✓
  gradle.properties                ✓
  settings.gradle                  ✓

This looks complete. The mod should:

  1. Use firework rockets while riding Happy Ghast for a speed boost

  2. Press V to increase speed level, C to decrease

  3. Speed levels 1-5 with configurable speeds

  4. Config file at .minecraft/config/happyghastflight.json

Let me just verify there’s no ambiguity in the mixin method signatures one more time before finalizing.

For HappyGhastEntity, I used travel(Lnet/minecraft/util/math/Vec3d;)V which is the correct Yarn method descriptor. The inject should work.

For writeCustomData - the signature should be writeCustomData(Lnet/minecraft/nbt/WriteView;)V. For readCustomData - readCustomData(Lnet/minecraft/nbt/ReadView;)V.

Let me verify the inject annotations use the correct param descriptors… Mixin @Inject doesn’t need the full descriptor unless there’s ambiguity - it can infer from the Java source params. But I should use the full method name just in case.

Actually, looking at my code again, I have @Inject(method = "writeCustomData", at = @At("TAIL")) without the descriptor. This should work if the method name is unique in the class. Let me add descriptors to be safe.

Wait, actually the ${method} in @Inject needs to include the descriptor only when there are multiple overloads with the same name. In this case, writeCustomData(WriteView) should be unique. But to be safe, I’ll add descriptors.

Let me update the mixin one more time to add full method descriptors:

Actually, looking at my current code, I think it’s fine. The injection points are:

  • initDataTracker - unique method name

  • writeCustomData - might have ambiguity if there are overloads

  • readCustomData - same concern

  • tick - unique

  • travel - unique

For writeCustomData and readCustomData, I should add the descriptor to be safe. Let me update.

Actually, since the target class is HappyGhastEntity (not LivingEntity or Entity), and these methods are likely only defined once in this class or inherited, the param-based disambiguation should work. But to be truly safe:

@Inject(method = "writeCustomData(Lnet/minecraft/nbt/WriteView;)V", ...)

Let me update the mixin file.Let me also add method descriptors to the mixin to avoid any ambiguity:

All 11 files created. Here’s the complete project structure and how it works:

Project: HappyGhastFlight

Plain Text
happyghastflight/
├── build.gradle
├── gradle.properties
├── settings.gradle
└── src/
    ├── main/
    │   ├── java/com/happyghastflight/
    │   │   ├── HappyGhastFlight.java        ← Mod init, event handlers, packet registration
    │   │   ├── IHappyGhastData.java         ← Interface for mixin-added methods
    │   │   ├── config/ModConfig.java        ← JSON config (base speeds, boost multiplier, damping)
    │   │   ├── mixin/HappyGhastEntityMixin.java ← Core flight logic mixin
    │   │   └── network/SpeedLevelPayload.java  ← C2S packet for speed changes
    │   └── resources/
    │       ├── fabric.mod.json
    │       ├── happyghastflight.mixins.json
    │       └── assets/happyghastflight/lang/en_us.json
    └── client/
        └── java/com/happyghastflight/
            ├── HappyGhastFlightClient.java
            └── client/ModKeybindings.java   ← V/C keys to change speed level

How it works:

  1. Rocket boost — Right-click with a firework rocket while riding a Happy Ghast. The UseItemCallback event detects it on the server, consumes one rocket, and calls applyRocketBoost() which activates a configurable-duration speed boost (default 40 ticks / 2 seconds). During boost, the ghast’s speed is multiplied by boostMultiplier (configurable, default 2.5x).

  2. Speed levels — Press V to increase speed level (1→5), C to decrease. Each level has a configurable base speed. A C2S packet syncs the change to the server, and the server syncs the tracked data back to clients.

  3. Flight mechanics — The travel() mixin replaces vanilla Happy Ghast movement when ridden. The ghast moves in the direction the rider is looking at baseSpeed (cruising) or baseSpeed × boostMultiplier (rocket-boosted). When no keys are pressed, the ghast hovers with configurable damping.

  4. Config — config/happyghastflight.json lets you tune:

    • baseSpeeds — array of 5 values, one per level (default: [0.3, 0.6, 1.0, 1.5, 2.0])

    • boostMultiplier — speed multiplier when rocket is active (default: 2.5)

    • boostDurationTicks — how long the boost lasts (default: 40)

    • damping — deceleration when no input (default: 0.85)

Kodari can make mistakes. Review important code before using.
Files
src
build.gradle
gradle.properties
settings.gradle
Code
13 452
src/main/java/com/happyghastflight/HappyGhastFlight.java
package com.happyghastflight;

import com.happyghastflight.config.ModConfig;
import com.happyghastflight.network.SpeedLevelPayload;
import net.fabricmc.api.ModInitializer;
import net.fabricmc.fabric.api.event.player.UseItemCallback;
import net.fabricmc.fabric.api.networking.v1.PayloadTypeRegistry;
import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking;
import net.minecraft.entity.passive.HappyGhastEntity;
import net.minecraft.item.Items;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ActionResult;
import net.minecraft.util.Identifier;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class HappyGhastFlight implements ModInitializer {
    public static final String MOD_ID = "happyghastflight";
    public static final Logger LOGGER = LoggerFactory.getLogger(MOD_ID);
    public static ModConfig CONFIG;

    @Override
    public void onInitialize() {
        CONFIG = ModConfig.load();

        PayloadTypeRegistry.playC2S().register(SpeedLevelPayload.ID, SpeedLevelPayload.CODEC);

        ServerPlayNetworking.registerGlobalReceiver(SpeedLevelPayload.ID, (payload, context) -> {
            context.player().ifPresent(player -> {
                if (player.hasVehicle() && player.getVehicle() instanceof HappyGhastEntity ghast) {
                    int clamped = Math.min(Math.max(payload.speedLevel(), 1), 5);
                    if (clamped != payload.speedLevel()) return;
                    // Call our mixin-added setter
                    ((IHappyGhastData) ghast).happyghastflight$setSpeedLevel(payload.speedLevel());
                }
            });
        });

        UseItemCallback.EVENT.register((player, world, hand) -> {
            if (!player.hasVehicle()) return ActionResult.PASS;
            if (!(player.getVehicle() instanceof HappyGhastEntity ghast)) return ActionResult.PASS;

            ItemStack stack = player.getStackInHand(hand);
            if (!stack.isOf(Items.FIREWORK_ROCKET)) return ActionResult.PASS;

            if (world.isClient) return ActionResult.PASS;

            stack.decrement(1);
            ((IHappyGhastData) ghast).happyghastflight$applyRocketBoost();

            return ActionResult.SUCCESS;
        });

        LOGGER.info("HappyGhastFlight initialized.");
    }
}