Empeld
Empeld plugin documentation.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events
essentials.Prefabs.Prefab Class Reference

A subset of blocks within a world, that creates an existing entity Able to save and load from disk, clone pieces of the world, etc More...

Inheritance diagram for essentials.Prefabs.Prefab:
essentials.Prefabs.IPrefab essentials.Prefabs.IReadonlyPrefab

Public Member Functions

 Prefab (int width, int length, int height, Vector3i center)
 Creates a new instance of a prefab with the given width, length, and height More...
 
 Prefab (int width, int length, int height)
 Creates a new prefab More...
 
 Prefab (Size3i size, Vector3i center)
 Creates a new prefab More...
 
 Prefab (Size3i size)
 Creates a new prefab More...
 
void Save (Stream stream)
 Save prefab data to a stream (eg file) More...
 
void Clear (ushort id)
 Clear the prefab space with a specific block id More...
 
void Clear ()
 Clear the prefab space with empty block (id 0) More...
 
void Merge (IReadonlyPrefab src, Vector3i pos)
 Merge one prefab into self More...
 

Static Public Member Functions

static Prefab Load (Stream stream)
 Load prefab data from a data stream More...
 

Properties

int Width [get]
 Gets the width of the prefab More...
 
int Length [get]
 Gets the lenght of the prefab More...
 
int Height [get]
 Gets the height of the prefab More...
 
Size3i Size [get]
 Gets the size of the prefab (width, length, height) More...
 
Vector3i Center [get]
 Gets the relative center coordinate of the prefab (Not world coord) More...
 
- Properties inherited from essentials.Prefabs.IReadonlyPrefab
int Width [get]
 The width of the prefab More...
 
int Length [get]
 The length of the prefab More...
 
int Height [get]
 The height of the prefab More...
 
Size3i Size [get]
 The size of the prefab (width, length, height) More...
 
Vector3i Center [get]
 The relative center coordinate of the prefab More...
 

Detailed Description

A subset of blocks within a world, that creates an existing entity Able to save and load from disk, clone pieces of the world, etc

Constructor & Destructor Documentation

essentials.Prefabs.Prefab.Prefab ( int  width,
int  length,
int  height,
Vector3i  center 
)

Creates a new instance of a prefab with the given width, length, and height

Parameters
widthWidth.
lengthLength.
heightHeight.
centerCenter.

Attribute: width*length*height

;

79  {
80  this.InjectDependencies();
81 
82  _width = width;
83  _length = length;
84  _height = height;
85  _center = center;
86  _blocks = new ushort[width*length*height];
87  }
essentials.Prefabs.Prefab.Prefab ( int  width,
int  length,
int  height 
)

Creates a new prefab

Parameters
widthWidth.
lengthLength.
heightHeight.
96  :this(width, length, height, Vector3i.Zero)
97  {}
A class representing a 3D coordinate of integers
Definition: Vector3i.cs:13
static readonly Vector3i Zero
Vector (0,0,0)
Definition: Vector3i.cs:59
essentials.Prefabs.Prefab.Prefab ( Size3i  size,
Vector3i  center 
)

Creates a new prefab

Parameters
sizeSize.
centerCenter.
105  :this(size.Width, size.Length, size.Height, center)
106  {}
int Height
Definition: Size3i.cs:7
int Width
Definition: Size3i.cs:7
int Length
Definition: Size3i.cs:7
essentials.Prefabs.Prefab.Prefab ( Size3i  size)

Creates a new prefab

Parameters
sizeSize.
113  :this(size.Width, size.Length, size.Height, Vector3i.Zero)
114  {}
int Height
Definition: Size3i.cs:7
int Width
Definition: Size3i.cs:7
int Length
Definition: Size3i.cs:7
A class representing a 3D coordinate of integers
Definition: Vector3i.cs:13
static readonly Vector3i Zero
Vector (0,0,0)
Definition: Vector3i.cs:59

Member Function Documentation

void essentials.Prefabs.Prefab.Clear ( ushort  id)

Clear the prefab space with a specific block id

Parameters
idIdentifier.

Attribute: i

= id;

208  {
209  for (int i=0; i<_blocks.Length; ++i)
210  {
211  _blocks[i] = id;
212  }
213  }
void essentials.Prefabs.Prefab.Clear ( )

Clear the prefab space with empty block (id 0)

219  {
220  Clear(0);
221  }
void Clear()
Clear the prefab space with empty block (id 0)
Definition: Prefab.cs:218
static Prefab essentials.Prefabs.Prefab.Load ( Stream  stream)
static

Load prefab data from a data stream

Parameters
streamStream.

Attribute: i

= reader.ReadUInt16();

Attribute: pos

= data;

123  {
124  var reader = new BinaryReader(stream);
125  string magic = reader.ReadString();
126  if (magic != MAGIC)
127  {
128  throw new FileLoadException("Invalid magic");
129  }
130 
131  byte version = reader.ReadByte();
132  if (version != 0)
133  {
134  throw new FileLoadException("Invalid version");
135  }
136 
137  int width = reader.ReadInt32();
138  int length = reader.ReadInt32();
139  int height = reader.ReadInt32();
140  int cX = reader.ReadInt32();
141  int cY = reader.ReadInt32();
142  int cZ = reader.ReadInt32();
143 
144  var prefab = new Prefab(width, length, height, new Vector3i(cX,cY,cZ));
145  for (int i=0; i<width*length*height; ++i)
146  {
147  prefab._blocks[i] = reader.ReadUInt16();
148  }
149 
150  if (stream.Length > stream.Position) //Backwards compat
151  {
152  //There's metadata!
153  int labelCount = reader.ReadInt32();
154  for (int i=0; i<labelCount; ++i)
155  {
156  Vector3i pos;
157  pos.X = reader.ReadInt32();
158  pos.Y = reader.ReadInt32();
159  pos.Z = reader.ReadInt32();
160  string data = reader.ReadString();
161  prefab._labels[pos] = data;
162  }
163  }
164 
165  return prefab;
166  }
static readonly Vector3i
All directions, including diagnols
Definition: Vector3i.cs:111
Prefab(int width, int length, int height, Vector3i center)
Creates a new instance of a prefab with the given width, length, and height
Definition: Prefab.cs:78
int Y
The Y coordinate
Definition: Vector3i.cs:23
A class representing a 3D coordinate of integers
Definition: Vector3i.cs:13
int X
The X coordinate
Definition: Vector3i.cs:18
int Z
The Z coordinate
Definition: Vector3i.cs:28
void essentials.Prefabs.Prefab.Merge ( IReadonlyPrefab  src,
Vector3i  pos 
)

Merge one prefab into self

Parameters
srcSource.
posPosition.

Attribute: myPos] = src[x,y,z

;

229  {
230  for (int x=0; x<src.Width; ++x)
231  {
232  for (int y=0; y<src.Length; ++y)
233  {
234  for (int z=0; z<src.Height; ++z)
235  {
236  Vector3i myPos = new Vector3i(x,y,z) - src.Center + pos;
237  if (myPos.X >= 0 && myPos.X < _width
238  && myPos.Y >= 0 && myPos.Y < _length
239  && myPos.Z >= 0 && myPos.Z < _height)
240  {
241  this[myPos] = src[x,y,z];
242  }
243  }
244  }
245  }
246  }
static readonly Vector3i
All directions, including diagnols
Definition: Vector3i.cs:111
int Y
The Y coordinate
Definition: Vector3i.cs:23
A class representing a 3D coordinate of integers
Definition: Vector3i.cs:13
int X
The X coordinate
Definition: Vector3i.cs:18
int Z
The Z coordinate
Definition: Vector3i.cs:28
void essentials.Prefabs.Prefab.Save ( Stream  stream)

Save prefab data to a stream (eg file)

Parameters
streamStream.

Attribute: i

);

173  {
174  var writer = new BinaryWriter(stream);
175  writer.Write(MAGIC);
176  writer.Write((byte)0);
177 
178  writer.Write(_width);
179  writer.Write(_length);
180  writer.Write(_height);
181 
182  writer.Write(_center.X);
183  writer.Write(_center.Y);
184  writer.Write(_center.Z);
185 
186  for (int i=0; i<_width*_length*_height; ++i)
187  writer.Write(_blocks[i]);
188 
189  writer.Write((int)this._labels.Count);
190  foreach(var label in this._labels)
191  {
192  writer.Write(label.Key.X);
193  writer.Write(label.Key.Y);
194  writer.Write(label.Key.Z);
195  writer.Write(label.Value);
196  }
197  }
int Y
The Y coordinate
Definition: Vector3i.cs:23
int X
The X coordinate
Definition: Vector3i.cs:18
int Z
The Z coordinate
Definition: Vector3i.cs:28

Property Documentation

Vector3i essentials.Prefabs.Prefab.Center
get

Gets the relative center coordinate of the prefab (Not world coord)

The center.

int essentials.Prefabs.Prefab.Height
get

Gets the height of the prefab

The height.

int essentials.Prefabs.Prefab.Length
get

Gets the lenght of the prefab

The length.

Size3i essentials.Prefabs.Prefab.Size
get

Gets the size of the prefab (width, length, height)

The size.

int essentials.Prefabs.Prefab.Width
get

Gets the width of the prefab

The width.


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