Empeld
Empeld plugin documentation.
essentials.Prefabs.PrefabGenerator Class Reference

Helper class to place an arbitrary set of blocks with positions, and generate a prefab More...

Public Member Functions

 PrefabGenerator ()
 
 PrefabGenerator (Vector3i center)
 
void PlaceBlock (Vector3i pos, IBlock block)
 
void PlaceLabel (Vector3i pos, string label)
 
Prefab ToPrefab ()
 
Volume GetBounds ()
 
override string ToString ()
 

Properties

Vector3i Center [get, set]
 

Detailed Description

Helper class to place an arbitrary set of blocks with positions, and generate a prefab

Constructor & Destructor Documentation

◆ PrefabGenerator() [1/2]

essentials.Prefabs.PrefabGenerator.PrefabGenerator ( )
19  : this(Vector3i.Zero)
20  { }
A class representing a 3D coordinate of integers
Definition: Vector3i.cs:13
static readonly Vector3i Zero
Vector (0,0,0)
Definition: Vector3i.cs:59

◆ PrefabGenerator() [2/2]

essentials.Prefabs.PrefabGenerator.PrefabGenerator ( Vector3i  center)
23  {
24  this.Center = center;
25  }
Vector3i Center
Definition: PrefabGenerator.cs:16

Member Function Documentation

◆ GetBounds()

Volume essentials.Prefabs.PrefabGenerator.GetBounds ( )
58  {
59  return Volume.FromPointCloud(_prefabBlocks.Select(x => x.pos));
60  }
Represent a 3D axis-aligned volume
Definition: Volume.cs:10
static Volume FromPointCloud(IEnumerable< Vector3i > points)
From a set of Vector3i points, returns a volume that holds them all. Will have at least size-1 if it ...
Definition: Volume.cs:125

◆ PlaceBlock()

void essentials.Prefabs.PrefabGenerator.PlaceBlock ( Vector3i  pos,
IBlock  block 
)
28  {
29  _prefabBlocks.Add((pos, block.Id));
30  }
ushort Id
Id that represent the block type (usually hash of InternalName)
Definition: IBlock.cs:32

◆ PlaceLabel()

void essentials.Prefabs.PrefabGenerator.PlaceLabel ( Vector3i  pos,
string  label 
)
33  {
34  _labels.Add((pos, label));
35  }

◆ ToPrefab()

Prefab essentials.Prefabs.PrefabGenerator.ToPrefab ( )

Attribute: i

.pos - bounds.Point;

Attribute: prefabPt] = _prefabBlocks[i

.block;

Attribute: i

;

38  {
39  var bounds = this.GetBounds();
40  var prefab = new Prefab(bounds.Size, this.Center - bounds.Point);
41 
42  for (int i=0; i<_prefabBlocks.Count; i++)
43  {
44  Vector3i prefabPt = _prefabBlocks[i].pos - bounds.Point;
45  prefab[prefabPt] = _prefabBlocks[i].block;
46  }
47 
48  for (int i=0; i<_labels.Count; i++)
49  {
50  var label = _labels[i];
51  prefab.SetLabel(label.pos - bounds.Point, label.label);
52  }
53 
54  return prefab;
55  }
Volume GetBounds()
Definition: PrefabGenerator.cs:57
A class representing a 3D coordinate of integers
Definition: Vector3i.cs:13

◆ ToString()

override string essentials.Prefabs.PrefabGenerator.ToString ( )
63  {
64  return $"[Prefab Center={this.Center} Blocks={this._prefabBlocks.Count}]";
65  }

Property Documentation

◆ Center

Vector3i essentials.Prefabs.PrefabGenerator.Center
getset

The documentation for this class was generated from the following file: