Files
Documentation/content/world/worldgen/generation-patterns.fr.md
2026-01-20 20:33:59 +01:00

329 lines
6.1 KiB
Markdown

---
title: Patterns de Génération
type: docs
weight: 11
---
Les patterns de génération fournissent des algorithmes réutilisables pour créer des caractéristiques de terrain, des structures et des décorations.
**Packages:**
- `com.hypixel.hytale.builtin.hytalegenerator.patterns`
- `com.hypixel.hytale.builtin.hytalegenerator.fields`
## Système de Patterns
Les patterns encapsulent la logique de génération :
```java
public interface GenerationPattern {
// Appliquer le pattern au conteneur
void apply(GenerationContainer container, PatternContext context);
}
public class PatternContext {
private Vector3i origin;
private int size;
private Random random;
private Map<String, Object> parameters;
}
```
## Patterns Intégrés
### SpherePattern
Crée des formations sphériques :
```yaml
Type: SpherePattern
Radius: 5
Block: stone
Hollow: false
```
```java
public class SpherePattern implements GenerationPattern {
private float radius;
private BlockType block;
private boolean hollow;
public void apply(GenerationContainer container, PatternContext ctx) {
int r = (int) radius;
for (int dx = -r; dx <= r; dx++) {
for (int dy = -r; dy <= r; dy++) {
for (int dz = -r; dz <= r; dz++) {
float dist = (float) Math.sqrt(dx*dx + dy*dy + dz*dz);
if (dist <= radius && (!hollow || dist > radius - 1)) {
container.setBlock(
ctx.origin.x + dx,
ctx.origin.y + dy,
ctx.origin.z + dz,
block
);
}
}
}
}
}
}
```
### CylinderPattern
Crée des formations cylindriques :
```yaml
Type: CylinderPattern
Radius: 4
Height: 10
Block: stone
Hollow: true
```
### ArchPattern
Crée des formations d'arches :
```yaml
Type: ArchPattern
Width: 8
Height: 6
Thickness: 2
Block: stone
```
### SpirePattern
Crée des formes de flèche/stalagmite :
```yaml
Type: SpirePattern
BaseRadius: 3
Height: 15
TaperRate: 0.2
Block: stone
```
## Génération par Champs
Les champs génèrent des valeurs à travers l'espace 2D ou 3D :
### NoiseField
```java
public class NoiseField implements Field2D {
private SimplexNoise noise;
private float scale;
private int octaves;
public float getValue(int x, int z) {
return noise.noise2D(x * scale, z * scale);
}
}
```
### GradientField
```java
public class GradientField implements Field2D {
private Vector2f direction;
private float scale;
public float getValue(int x, int z) {
return (x * direction.x + z * direction.y) * scale;
}
}
```
### VoronoiField
```java
public class VoronoiField implements Field2D {
private List<Vector2i> points;
public float getValue(int x, int z) {
float minDist = Float.MAX_VALUE;
for (Vector2i point : points) {
float dist = (float) Math.sqrt(
(x - point.x) * (x - point.x) +
(z - point.y) * (z - point.y)
);
minDist = Math.min(minDist, dist);
}
return minDist;
}
}
```
## Patterns Composites
### RepeatPattern
Répète un pattern dans une grille :
```yaml
Type: RepeatPattern
Pattern: pillar_pattern
SpacingX: 10
SpacingZ: 10
Count: 16
```
### ScatterPattern
Place des patterns à des positions aléatoires :
```yaml
Type: ScatterPattern
Pattern: boulder_pattern
Density: 0.05
MinSpacing: 5
```
### ConditionalPattern
Applique un pattern selon des conditions :
```yaml
Type: ConditionalPattern
Pattern: snow_cap
Condition:
Type: HeightAbove
Height: 100
```
## Patterns de Terrain
### RiverPattern
Creuse des canaux de rivière :
```java
public class RiverPattern implements GenerationPattern {
private List<Vector2f> path;
private float width;
private float depth;
public void apply(GenerationContainer container, PatternContext ctx) {
for (Vector2f point : path) {
carveRiverSection(container, point, width, depth);
}
}
}
```
### CliffPattern
Crée des formations de falaises :
```yaml
Type: CliffPattern
Height: 20
Steepness: 0.9
NoiseScale: 0.1
```
### TerracePattern
Crée un terrain en terrasses :
```yaml
Type: TerracePattern
TerraceHeight: 5
TerraceCount: 4
Smoothing: 0.3
```
## Patterns de Décoration
### ClusterPattern
Crée des groupes de blocs :
```yaml
Type: ClusterPattern
Block: flower_red
Size: 3-7
Density: 0.8
```
### VeinPattern
Crée des veines de minerai :
```yaml
Type: VeinPattern
Block: iron_ore
Length: 10-20
Branching: 0.3
```
### LayerPattern
Crée des couches horizontales :
```yaml
Type: LayerPattern
Layers:
- Block: grass_block
Thickness: 1
- Block: dirt
Thickness: 3
- Block: stone
Thickness: -1 # Remplir le reste
```
## Configuration
```yaml
# patterns/config.yaml
Patterns:
boulder:
Type: SpherePattern
Radius: 2-4
Block: stone
tree_trunk:
Type: CylinderPattern
Radius: 1
Height: 5-10
Block: oak_log
crystal_cluster:
Type: ClusterPattern
Block: crystal
Size: 3-8
```
## Pattern Personnalisé
```java
public class MyPattern implements GenerationPattern {
@Override
public void apply(GenerationContainer container, PatternContext ctx) {
// Logique de génération personnalisée
int size = ctx.parameters.getInt("size", 5);
for (int i = 0; i < size; i++) {
int x = ctx.origin.x + ctx.random.nextInt(size);
int z = ctx.origin.z + ctx.random.nextInt(size);
int y = container.getHeight(x, z);
container.setBlock(x, y + 1, z, BlockTypes.STONE);
}
}
}
// Enregistrer
patternRegistry.register("my_pattern", new MyPattern());
```
## Bonnes Pratiques
{{< callout type="info" >}}
**Directives des Patterns :**
- Utilisez les patterns pour une logique de génération réutilisable
- Combinez les patterns avec les champs pour la variété
- Testez les patterns à différentes échelles
- Considérez les performances avec les patterns complexes
- Documentez clairement les paramètres des patterns
{{< /callout >}}