274 lines
5.3 KiB
Markdown
274 lines
5.3 KiB
Markdown
---
|
|
title: Material Providers
|
|
type: docs
|
|
weight: 9
|
|
---
|
|
|
|
Les material providers déterminent quels blocs sont placés à chaque position pendant la génération du terrain.
|
|
|
|
**Package:** `com.hypixel.hytale.builtin.hytalegenerator.materialproviders`
|
|
|
|
## Concept de Material Provider
|
|
|
|
Les material providers sélectionnent les blocs selon le contexte :
|
|
|
|
```java
|
|
public interface MaterialProvider {
|
|
// Obtenir le bloc pour une position
|
|
BlockType getBlock(int x, int y, int z, MaterialContext context);
|
|
}
|
|
|
|
public class MaterialContext {
|
|
private Biome biome;
|
|
private float density;
|
|
private int surfaceHeight;
|
|
private int depth; // Profondeur sous la surface
|
|
private boolean underwater;
|
|
}
|
|
```
|
|
|
|
## Providers de Base
|
|
|
|
### SingleMaterialProvider
|
|
|
|
Retourne un seul type de bloc :
|
|
|
|
```yaml
|
|
Type: SingleMaterial
|
|
Block: stone
|
|
```
|
|
|
|
### DepthMaterialProvider
|
|
|
|
Change les blocs selon la profondeur :
|
|
|
|
```yaml
|
|
Type: DepthMaterial
|
|
Layers:
|
|
- Depth: 0
|
|
Block: grass_block
|
|
- Depth: 1
|
|
Block: dirt
|
|
- Depth: 4
|
|
Block: stone
|
|
```
|
|
|
|
```java
|
|
public class DepthMaterialProvider implements MaterialProvider {
|
|
private List<DepthLayer> layers;
|
|
|
|
public BlockType getBlock(int x, int y, int z, MaterialContext ctx) {
|
|
for (DepthLayer layer : layers) {
|
|
if (ctx.depth >= layer.minDepth) {
|
|
return layer.block;
|
|
}
|
|
}
|
|
return defaultBlock;
|
|
}
|
|
}
|
|
```
|
|
|
|
## Providers Basés sur les Biomes
|
|
|
|
### BiomeMaterialProvider
|
|
|
|
Sélectionne les matériaux selon le biome :
|
|
|
|
```yaml
|
|
Type: BiomeMaterial
|
|
Biomes:
|
|
forest:
|
|
Surface: grass_block
|
|
Subsurface: dirt
|
|
Stone: stone
|
|
desert:
|
|
Surface: sand
|
|
Subsurface: sandstone
|
|
Stone: sandstone
|
|
tundra:
|
|
Surface: snow_block
|
|
Subsurface: permafrost
|
|
Stone: stone
|
|
```
|
|
|
|
### BiomeSurfaceProvider
|
|
|
|
Provider spécifique à la surface :
|
|
|
|
```java
|
|
public class BiomeSurfaceProvider implements MaterialProvider {
|
|
private Map<String, SurfaceMaterials> biomeMaterials;
|
|
|
|
public BlockType getBlock(int x, int y, int z, MaterialContext ctx) {
|
|
SurfaceMaterials materials = biomeMaterials.get(ctx.biome.getId());
|
|
if (materials == null) {
|
|
materials = defaultMaterials;
|
|
}
|
|
|
|
if (ctx.depth == 0) {
|
|
return materials.surface;
|
|
} else if (ctx.depth < 4) {
|
|
return materials.subsurface;
|
|
} else {
|
|
return materials.stone;
|
|
}
|
|
}
|
|
}
|
|
```
|
|
|
|
## Providers Basés sur le Bruit
|
|
|
|
### NoiseMaterialProvider
|
|
|
|
Utilise le bruit pour la variation :
|
|
|
|
```yaml
|
|
Type: NoiseMaterial
|
|
Noise:
|
|
Scale: 0.1
|
|
Threshold: 0.5
|
|
Materials:
|
|
Above: stone
|
|
Below: granite
|
|
```
|
|
|
|
### GradientMaterialProvider
|
|
|
|
Mélange les matériaux selon une valeur :
|
|
|
|
```java
|
|
public class GradientMaterialProvider implements MaterialProvider {
|
|
private SimplexNoise noise;
|
|
private List<MaterialStop> stops;
|
|
|
|
public BlockType getBlock(int x, int y, int z, MaterialContext ctx) {
|
|
float value = noise.noise3D(x * 0.05f, y * 0.05f, z * 0.05f);
|
|
|
|
for (int i = stops.size() - 1; i >= 0; i--) {
|
|
if (value >= stops.get(i).threshold) {
|
|
return stops.get(i).block;
|
|
}
|
|
}
|
|
return defaultBlock;
|
|
}
|
|
}
|
|
```
|
|
|
|
## Providers Composites
|
|
|
|
### LayeredMaterialProvider
|
|
|
|
Empile plusieurs providers :
|
|
|
|
```yaml
|
|
Type: LayeredMaterial
|
|
Layers:
|
|
- Provider: bedrock_layer
|
|
MaxY: 5
|
|
- Provider: stone_layer
|
|
MaxY: 60
|
|
- Provider: surface_layer
|
|
MaxY: 256
|
|
```
|
|
|
|
### ConditionalMaterialProvider
|
|
|
|
Sélection conditionnelle de blocs :
|
|
|
|
```yaml
|
|
Type: ConditionalMaterial
|
|
Conditions:
|
|
- Condition:
|
|
Type: Underwater
|
|
Provider: sand_material
|
|
- Condition:
|
|
Type: NearCave
|
|
Distance: 2
|
|
Provider: cave_stone
|
|
- Default: default_material
|
|
```
|
|
|
|
## Providers Spéciaux
|
|
|
|
### OreMaterialProvider
|
|
|
|
Place des veines de minerai :
|
|
|
|
```yaml
|
|
Type: OreMaterial
|
|
Ores:
|
|
- Type: iron_ore
|
|
MinY: 0
|
|
MaxY: 64
|
|
Frequency: 0.02
|
|
Size: 9
|
|
- Type: diamond_ore
|
|
MinY: 0
|
|
MaxY: 16
|
|
Frequency: 0.001
|
|
Size: 4
|
|
```
|
|
|
|
### CaveMaterialProvider
|
|
|
|
Matériaux pour les surfaces de grottes :
|
|
|
|
```yaml
|
|
Type: CaveMaterial
|
|
Floor: gravel
|
|
Ceiling: stone
|
|
Walls: mossy_stone
|
|
WaterLevel: 10
|
|
WaterBlock: water
|
|
```
|
|
|
|
## Configuration
|
|
|
|
```yaml
|
|
# materialproviders/config.yaml
|
|
MaterialProviders:
|
|
default:
|
|
Type: BiomeMaterial
|
|
Biomes:
|
|
forest:
|
|
Surface: grass_block
|
|
Subsurface: dirt
|
|
Stone: stone
|
|
cave:
|
|
Type: CaveMaterial
|
|
Floor: gravel
|
|
Walls: stone
|
|
```
|
|
|
|
## Provider Personnalisé
|
|
|
|
```java
|
|
public class MyMaterialProvider implements MaterialProvider {
|
|
@Override
|
|
public BlockType getBlock(int x, int y, int z, MaterialContext ctx) {
|
|
// Logique de matériau personnalisée
|
|
if (ctx.underwater) {
|
|
return BlockTypes.SAND;
|
|
}
|
|
if (ctx.depth == 0) {
|
|
return BlockTypes.GRASS_BLOCK;
|
|
}
|
|
return BlockTypes.STONE;
|
|
}
|
|
}
|
|
|
|
// Enregistrer
|
|
materialRegistry.register("my_materials", new MyMaterialProvider());
|
|
```
|
|
|
|
## Bonnes Pratiques
|
|
|
|
{{< callout type="info" >}}
|
|
**Directives des Material Providers :**
|
|
- Utilisez des providers conscients des biomes pour la variété
|
|
- Superposez les providers pour des surfaces complexes
|
|
- Ajoutez du bruit pour une variation naturelle
|
|
- Considérez les cas spéciaux (sous l'eau, grottes)
|
|
- Testez les transitions de matériaux entre biomes
|
|
{{< /callout >}}
|