Survivalcraft API 1.8.2.3 v1.8.2.3
Survivalcraft 2.4
载入中...
搜索中...
未找到
WireDomainElectricElement.cs
浏览该文件的文档.
1using Engine;
2
3namespace Game {
5 public float m_voltage;
6
7 public WireDomainElectricElement(SubsystemElectricity subsystemElectricity, IEnumerable<CellFace> cellFaces) : base(
8 subsystemElectricity,
9 cellFaces
10 ) { }
11
12 public override float GetOutputVoltage(int face) => m_voltage;
13
14 public override bool Simulate() {
15 float voltage = m_voltage;
16 int num = 0;
17 foreach (ElectricConnection connection in Connections) {
18 if (connection.ConnectorType != ElectricConnectorType.Output
19 && connection.NeighborConnectorType != 0) {
20 num |= (int)MathF.Round(connection.NeighborElectricElement.GetOutputVoltage(connection.NeighborConnectorFace) * 15f);
21 }
22 }
23 m_voltage = num / 15f;
24 return m_voltage != voltage;
25 }
26
27 public override void OnNeighborBlockChanged(CellFace cellFace, int neighborX, int neighborY, int neighborZ) {
28 int cellValue = SubsystemElectricity.SubsystemTerrain.Terrain.GetCellValue(cellFace.X, cellFace.Y, cellFace.Z);
29 int num = Terrain.ExtractContents(cellValue);
30 if (!(BlocksManager.Blocks[num] is WireBlock)) {
31 return;
32 }
33 int wireFacesBitmask = WireBlock.GetWireFacesBitmask(cellValue);
34 int num2 = wireFacesBitmask;
35 if (WireBlock.WireExistsOnFace(cellValue, cellFace.Face)) {
36 Point3 point = CellFace.FaceToPoint3(cellFace.Face);
37 int cellValue2 = SubsystemElectricity.SubsystemTerrain.Terrain.GetCellValue(
38 cellFace.X - point.X,
39 cellFace.Y - point.Y,
40 cellFace.Z - point.Z
41 );
43 if (block.IsFaceNonAttachable(SubsystemElectricity.SubsystemTerrain, cellFace.Face, cellValue2, cellValue)) {
44 num2 &= ~(1 << cellFace.Face);
45 }
46 }
47 if (num2 == 0) {
48 SubsystemElectricity.SubsystemTerrain.DestroyCell(
49 0,
50 cellFace.X,
51 cellFace.Y,
52 cellFace.Z,
53 0,
54 false,
55 false
56 );
57 }
58 else if (num2 != wireFacesBitmask) {
59 int newValue = WireBlock.SetWireFacesBitmask(cellValue, num2);
60 SubsystemElectricity.SubsystemTerrain.DestroyCell(
61 0,
62 cellFace.X,
63 cellFace.Y,
64 cellFace.Z,
65 newValue,
66 false,
67 false
68 );
69 }
70 }
71 }
72}
virtual bool IsFaceNonAttachable(SubsystemTerrain subsystemTerrain, int face, int value, int attachBlockValue)
ElectricConnectorType ConnectorType
ElectricConnectorType NeighborConnectorType
SubsystemElectricity SubsystemElectricity
virtual float GetOutputVoltage(int face)
ElectricElement(SubsystemElectricity subsystemElectricity, IEnumerable< CellFace > cellFaces)
List< ElectricConnection > Connections
static int ExtractContents(int value)
static bool WireExistsOnFace(int value, int face)
static int SetWireFacesBitmask(int value, int bitmask)
static int GetWireFacesBitmask(int value)
override void OnNeighborBlockChanged(CellFace cellFace, int neighborX, int neighborY, int neighborZ)
WireDomainElectricElement(SubsystemElectricity subsystemElectricity, IEnumerable< CellFace > cellFaces)
static Point3 FaceToPoint3(int face)