> For the complete documentation index, see [llms.txt](https://docs.aethercube.fr/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.aethercube.fr/developers/fr/plugins/exemple-skyglass.md). Agents can also search and read this documentation through its [MCP server](https://docs.aethercube.fr/~gitbook/mcp).

# Exemple : Skyglass

Cette page parcourt un plugin complet du dépôt, du `plugin.yml` jusqu'au content pack. Elle sert à celles et ceux qui écrivent un plugin et veulent voir comment les morceaux s'assemblent.

Skyglass est un plugin d'exemple du dépôt, dans `game-server/examples/skyglass/`. Il est petit, environ 23 Kio en jar, et touche toute la surface de contenu : un objet, une créature, une entrée d'apparition, un fond de chargement, un shader de terrain, un effet d'écran, des modèles, des icônes et des clips.

| Élément           | Identifiant                                                                              |
| ----------------- | ---------------------------------------------------------------------------------------- |
| Objet             | `skyglass:drift_shard`, « Driftglass Shard »                                             |
| Créature          | `skyglass:keel_drifter`, « Keel Drifter », construite à partir de `aethercube:ambermoth` |
| Fond              | `skyglass:isles`                                                                         |
| Effet d'écran     | `skyglass:updraft`                                                                       |
| Shader de terrain | Un reflet sur les surfaces au-dessus de y = 84, à son maximum vers y = 120               |

| Commande             | Effet                                                                    | Permission                        |
| -------------------- | ------------------------------------------------------------------------ | --------------------------------- |
| `/drifter`           | Fait apparaître un Keel Drifter quatre blocs devant toi.                 | `skyglass.drifter`, opérateurs    |
| `/updraft [on\|off]` | Affiche ou retire l'updraft sur ton écran, avec un fondu de 1,5 seconde. | `skyglass.updraft`, tout le monde |

## Organisation

```
examples/skyglass/
├── build.gradle.kts
├── src/main/java/com/velyorix/examples/skyglass/
│   ├── Skyglass.java            le plugin
│   └── SkyglassContent.java     les définitions de l'objet et de la créature
├── src/main/resources/
│   ├── plugin.yml
│   ├── config.yml
│   └── content/                 le content pack
│       ├── pack.json
│       ├── models/              drift_shard/, keel_drifter/ (model.json et .vox)
│       ├── icons/drift_shard.png
│       ├── backdrops/isles.png
│       ├── animations/          cinq clips
│       ├── data/                item_models.json, entity_models.json, animations.json
│       └── shaders/             terrain.wgsl, updraft.wgsl
├── src/test/java/...            tests du pack et du plugin
└── tools/make_art.py            régénère les images
```

## `plugin.yml`

```yaml
name: Skyglass
version: 1.0.0
main: com.velyorix.examples.skyglass.Skyglass
api-version: "1.0"
author: Aethercube
description: Driftglass from the keels of the floating isles, and the Keel Drifters that graze beneath them. An example plugin with a content pack.
load: POSTWORLD
permissions:
  skyglass.drifter:
    description: Spawn a Keel Drifter in front of you
    default: op
  skyglass.updraft:
    description: Show or clear the updraft screen effect
    default: true
commands:
  drifter:
    description: Spawns a Keel Drifter a few blocks in front of you
    usage: /drifter
    permission: skyglass.drifter
  updraft:
    description: Shows or clears the updraft screen effect on your screen
    usage: /updraft [on|off]
    permission: skyglass.updraft
```

## `config.yml`

```yaml
loading-backdrop: true
drifter-spawn-weight: 2
```

`loading-backdrop` fait du `skyglass:isles` du pack le fond de chargement du serveur. `drifter-spawn-weight` est le poids d'apparition naturelle dans `aethercube:aether_isles`. `0` coupe l'apparition.

## Le contenu, en code

`SkyglassContent` contient les identifiants et construit les définitions. L'objet :

```java
public static ItemDefinition driftShard() {
    return new ItemDefinition(
                    DRIFT_SHARD,
                    "item.skyglass.drift_shard",
                    Rarity.RARE,
                    ItemCategory.MATERIAL,
                    99,
                    "skyglass:drift_shard", // modèle : models/drift_shard du pack
                    "skyglass:drift_shard", // icône : icons/drift_shard.png du pack
                    -1,
                    Set.of(),
                    Set.of(),
                    Map.of("value", "12"))
            .withText("Driftglass Shard", "A sliver of an isle's keel. Set down, it still leans upward.");
}
```

La créature est construite à partir de son archétype, l'ambermoth. Elle change la boîte, les statistiques, la vitesse, la vue, l'expérience et les butins, et rend la créature passive :

```java
public static CreatureDefinition keelDrifter(CreatureDefinition archetype) {
    CombatStats base = archetype.stats();
    CombatStats stats = new CombatStats(
            16f, 16f, 0f, 1f,
            base.criticalChance(), base.criticalMultiplier(), base.attackSpeed(), base.movementSpeed(),
            base.resistanceFire(), base.resistanceIce(), base.resistanceLightning(), base.resistancePoison());
    return archetype.toBuilder()
            .key(KEEL_DRIFTER)
            .name("Keel Drifter")
            .size(1.1f, 1.0f)
            .model("skyglass:keel_drifter") // models/keel_drifter du pack
            .stats(stats)
            .speeds(1.0, 1.6)
            .sight(12)
            .experience(18)
            .drops(List.of(new CreatureDefinition.Drop(DRIFT_SHARD, 1, 2, 0.75)))
            .disposition(CreatureDefinition.Disposition.PASSIVE)
            .build();
}
```

## `onEnable`

```java
@Override
public void onEnable() {
    // L'objet et le type de créature. Les deux doivent être enregistrés avant le démarrage du réseau, donc ici.
    getServer().items().register(this, SkyglassContent.driftShard());
    CreatureDefinition archetype = getServer()
            .creatures()
            .get(SkyglassContent.ARCHETYPE)
            .orElseThrow(() -> new IllegalStateException(SkyglassContent.ARCHETYPE + " is not registered"));
    getServer().creatures().register(this, SkyglassContent.keelDrifter(archetype));

    // Une vision rare dans les îles. Les entrées d'apparition ne sont pas sauvegardées : on les ajoute à chaque démarrage.
    int weight = getConfig().getInt("drifter-spawn-weight", 2);
    if (weight > 0) {
        if (getServer().biomes().get(SkyglassContent.ISLES_BIOME).isPresent()) {
            getServer().biomes().addSpawn(
                    this,
                    SkyglassContent.ISLES_BIOME,
                    new SpawnEntry(SkyglassContent.KEEL_DRIFTER, Math.min(weight, 1000), 1, 2));
        } else {
            getLogger().warn("no biome {}: the Keel Drifter will not spawn naturally", SkyglassContent.ISLES_BIOME);
        }
    }

    // Le fond du pack sur l'écran de chargement, en gardant tout le reste de ce que le serveur a réglé.
    if (getConfig().getBoolean("loading-backdrop", true)) {
        var screens = getServer().loadingScreens();
        screens.setDefaults(screens.defaults().toBuilder()
                .backdrop(SkyglassContent.BACKDROP)
                .build());
    }

    registerCommand("drifter", this::drifter);
    registerCommand("updraft", this::updraft);
}
```

Le plugin n'enregistre jamais son content pack. Le serveur trouve `content/pack.json` dans le jar et enregistre le pack au chargement du plugin.

## Les commandes

`/drifter` retrouve l'entité et le monde du joueur, calcule un point 4 blocs devant et 1 bloc plus haut, et fait apparaître la créature sur le thread de simulation, là où les commandes tournent déjà :

```java
private CommandResult drifter(CommandContext c) {
    Player player = c.player().orElse(null);
    if (player == null) {
        return CommandResult.error("Only a player can call a Keel Drifter.");
    }
    Entity body = player.entity();
    if (body == null) {
        return CommandResult.error("You are not in the world yet.");
    }
    World world = getServer().world(body.world()).orElse(null);
    if (world == null) {
        return CommandResult.error("Your world is not loaded.");
    }
    Vector3 at = inFront(body.position(), body.yaw());
    getServer().creatures().spawn(SkyglassContent.KEEL_DRIFTER, world, at.x(), at.y(), at.z());
    return CommandResult.ok("A Keel Drifter drifts in.");
}
```

`/updraft` vérifie que le pack s'est bien chargé, parce que `show` lève une exception pour un effet qu'aucun pack ne déclare :

```java
private CommandResult updraft(CommandContext c) {
    Player player = c.player().orElse(null);
    if (player == null) {
        return CommandResult.error("Only a player has a screen.");
    }
    if (!getServer().contentPacks().screenEffects().contains(SkyglassContent.UPDRAFT)) {
        return CommandResult.error("The Skyglass pack is not loaded on this server.");
    }
    boolean on = !c.has(0) || c.bool(0);
    getServer().screenEffects().show(player, on ? UPDRAFT_ON : UPDRAFT_OFF);
    return CommandResult.ok(on ? "The updraft rises." : "The updraft settles.");
}
```

Les deux valeurs d'effet sont construites une seule fois :

```java
static final ScreenEffect UPDRAFT_ON = ScreenEffect.builder()
        .effect(SkyglassContent.UPDRAFT)
        .intensity(0.8f)
        .params(1.0f)       // params[0].x du shader : la force
        .fadeSeconds(1.5f)
        .build();

static final ScreenEffect UPDRAFT_OFF =
        ScreenEffect.builder().effect("").fadeSeconds(1.5f).build();
```

## Le pack

`content/pack.json` déclare ce que le pack ajoute :

```json
{
  "format": 1,
  "namespace": "skyglass",
  "name": "Skyglass",
  "version": "1.0.0",
  "description": "Driftglass from the keels of the floating isles, and the creatures that graze on light beneath them.",
  "backdrops": { "isles": { "file": "backdrops/isles.png", "place": "The Skyglass Isles" } },
  "terrain_shader": "shaders/terrain.wgsl",
  "screen_effects": { "updraft": "shaders/updraft.wgsl" }
}
```

Les fichiers de `data/` relient les modèles à l'objet et à la créature, et les clips aux états.

`data/item_models.json` donne à l'objet son modèle et le socket par lequel il est tenu :

```json
{ "version": 1, "items": { "skyglass:drift_shard": { "model": "skyglass:drift_shard", "socket": "right_hand_upright" } } }
```

`data/entity_models.json` donne à la créature son modèle :

```json
{ "version": 1, "entities": { "skyglass:keel_drifter": "skyglass:keel_drifter" } }
```

`data/animations.json` relie les clips aux états :

```json
{
  "version": 1,
  "models": {
    "skyglass:drift_shard": { "idle": "animations/shard_bob.json" },
    "skyglass:keel_drifter": {
      "idle": "animations/drifter_idle.json",
      "walk": "animations/drifter_drift.json",
      "fly": "animations/drifter_drift.json",
      "hit": "animations/drifter_hit.json",
      "death": "animations/drifter_death.json"
    }
  }
}
```

Les fichiers `models/*/model.json`, les shaders et les clips sont présentés dans les pages sur les [content packs](https://docs.aethercube.fr/developers/fr/content-packs/vue-d-ensemble.md) : [Modèles](https://docs.aethercube.fr/developers/fr/content-packs/modeles.md), [Animations](https://docs.aethercube.fr/developers/fr/content-packs/animations.md) et [Shaders](https://docs.aethercube.fr/developers/fr/content-packs/shaders.md).

## Compiler et lancer

```sh
cd game-server
./gradlew :examples:skyglass:jar
cp examples/skyglass/build/libs/skyglass-*.jar /chemin/vers/mon-serveur/plugins/
```

Démarre le serveur, connecte-toi, et essaie :

```
/drifter
/updraft
/updraft off
/give <toi> skyglass:drift_shard 5
```

`./gradlew :examples:skyglass:check` lance les tests. Ils construisent le pack avec le builder de packs du serveur lui-même, donc un pack cassé fait échouer le build.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.aethercube.fr/developers/fr/plugins/exemple-skyglass.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
