This commit is contained in:
2026-01-20 20:33:59 +01:00
commit b16a40e431
583 changed files with 87339 additions and 0 deletions

View File

@@ -0,0 +1,220 @@
---
title: Prefabs
type: docs
weight: 5
---
Les prefabs sont des structures pré-construites qui peuvent être placées pendant la génération de monde, comme des bâtiments, des ruines et des donjons.
**Package:** `com.hypixel.hytale.server.worldgen.prefab`
## Système de Prefabs
Le système de prefabs gère le placement des structures :
```java
public class PrefabPlacer {
// Placer un prefab à une position
public boolean place(Prefab prefab, World world, Vector3i position);
// Vérifier si un prefab peut être placé
public boolean canPlace(Prefab prefab, World world, Vector3i position);
// Trouver une position valide pour un prefab
public Vector3i findPlacement(Prefab prefab, World world, int chunkX, int chunkZ);
}
```
## Définition de Prefab
```yaml
# prefabs/village_house.yaml
Type: Prefab
Id: village_house
Size: [7, 5, 9]
Origin: [3, 0, 4]
Palette:
W: oak_planks
S: stone_bricks
G: glass_pane
D: oak_door
A: air
Structure:
- "SSSSSSS"
- "SWWGWWS"
- "SWWAWWS"
- "SWWDWWS"
- "SSSSSSS"
# ... plus de couches
PlacementRules:
RequiresSolidGround: true
MinGroundLevel: 60
MaxGroundLevel: 100
AllowedBiomes: [plains, forest]
```
## Classe Prefab
```java
public class Prefab {
private String id;
private Vector3i size;
private Vector3i origin;
private Map<Character, BlockType> palette;
private List<String[]> structure;
private PlacementRules rules;
// Obtenir le bloc à une position relative
public BlockType getBlock(int x, int y, int z);
// Obtenir la taille
public Vector3i getSize();
// Vérifier les règles de placement
public boolean canPlace(World world, Vector3i position);
}
```
## Règles de Placement
```java
public class PlacementRules {
private boolean requiresSolidGround;
private int minGroundLevel;
private int maxGroundLevel;
private Set<String> allowedBiomes;
private float spacing;
private int maxSlope;
public boolean evaluate(World world, Vector3i position) {
// Vérifier le niveau du sol
if (position.y < minGroundLevel || position.y > maxGroundLevel) {
return false;
}
// Vérifier le biome
Biome biome = world.getBiome(position.x, position.z);
if (!allowedBiomes.contains(biome.getId())) {
return false;
}
// Vérifier le sol solide
if (requiresSolidGround && !hasSolidGround(world, position)) {
return false;
}
return true;
}
}
```
## Placement de Structure
```java
public class StructurePlacer {
public void placeStructure(Prefab prefab, World world, Vector3i position, Rotation rotation) {
Vector3i size = prefab.getSize();
for (int y = 0; y < size.y; y++) {
for (int z = 0; z < size.z; z++) {
for (int x = 0; x < size.x; x++) {
BlockType block = prefab.getBlock(x, y, z);
if (block != null && block != BlockTypes.AIR) {
Vector3i rotated = rotate(x, y, z, rotation, size);
Vector3i worldPos = position.add(rotated);
world.setBlock(worldPos, block);
}
}
}
}
}
}
```
## Support de Rotation
```java
public enum Rotation {
NONE(0),
CW_90(90),
CW_180(180),
CW_270(270);
public Vector3i rotate(Vector3i pos, Vector3i size) {
switch (this) {
case NONE:
return pos;
case CW_90:
return new Vector3i(size.z - pos.z - 1, pos.y, pos.x);
case CW_180:
return new Vector3i(size.x - pos.x - 1, pos.y, size.z - pos.z - 1);
case CW_270:
return new Vector3i(pos.z, pos.y, size.x - pos.x - 1);
}
return pos;
}
}
```
## Variantes de Prefabs
Support pour des variantes aléatoires :
```yaml
# prefabs/tree_oak.yaml
Type: PrefabGroup
Id: tree_oak
Variants:
- prefabs/tree_oak_small
- prefabs/tree_oak_medium
- prefabs/tree_oak_large
Weights: [0.5, 0.35, 0.15]
```
## Intégration à la Génération
```java
public class PrefabGenerator {
private List<PrefabConfig> configs;
public void generatePrefabs(GenerationContainer container, int chunkX, int chunkZ) {
for (PrefabConfig config : configs) {
if (random.nextFloat() < config.frequency) {
Vector3i position = findValidPosition(config.prefab, container, chunkX, chunkZ);
if (position != null) {
Rotation rotation = Rotation.values()[random.nextInt(4)];
placePrefab(config.prefab, container, position, rotation);
}
}
}
}
}
```
## Spawners d'Entités
Les prefabs peuvent inclure des points de spawn d'entités :
```yaml
# prefabs/dungeon_room.yaml
Type: Prefab
Id: dungeon_room
EntitySpawns:
- Type: skeleton
Position: [5, 1, 5]
Count: 2
- Type: chest
Position: [7, 1, 7]
LootTable: dungeon_loot
```
## Bonnes Pratiques
{{< callout type="info" >}}
**Directives des Prefabs :**
- Utilisez des palettes pour une substitution de blocs facile
- Définissez des règles de placement claires
- Supportez la rotation pour la variété
- Incluez des variantes pour la diversité visuelle
- Considérez les performances avec les structures complexes
{{< /callout >}}