Survivalcraft API 1.8.2.3 v1.8.2.3
Survivalcraft 2.4
载入中...
搜索中...
未找到
WireThroughBlock.cs
浏览该文件的文档.
1using Engine;
2
3namespace Game {
6
8
9 public WireThroughBlock(int wiredTextureSlot, int unwiredTextureSlot) {
10 m_wiredTextureSlot = wiredTextureSlot;
11 m_unwiredTextureSlot = unwiredTextureSlot;
12 }
13
14 public ElectricElement CreateElectricElement(SubsystemElectricity subsystemElectricity, int value, int x, int y, int z) => null;
15
17 int value,
18 int face,
19 int connectorFace,
20 int x,
21 int y,
22 int z) {
23 int wiredFace = GetWiredFace(Terrain.ExtractData(value));
24 if ((face == wiredFace || face == CellFace.OppositeFace(wiredFace))
25 && connectorFace == CellFace.OppositeFace(face)) {
26 return ElectricConnectorType.InputOutput;
27 }
28 return null;
29 }
30
31 public int GetConnectionMask(int value) => int.MaxValue;
32
33 public int GetConnectedWireFacesMask(int value, int face) {
34 int wiredFace = GetWiredFace(Terrain.ExtractData(value));
35 if (wiredFace == face
36 || CellFace.OppositeFace(wiredFace) == face) {
37 return (1 << wiredFace) | (1 << CellFace.OppositeFace(wiredFace));
38 }
39 return 0;
40 }
41
42 public override int GetFaceTextureSlot(int face, int value) {
43 int wiredFace = GetWiredFace(Terrain.ExtractData(value));
44 if (wiredFace == face
45 || CellFace.OppositeFace(wiredFace) == face) {
46 return m_wiredTextureSlot;
47 }
49 }
50
51 public override BlockPlacementData GetPlacementValue(SubsystemTerrain subsystemTerrain,
52 ComponentMiner componentMiner,
53 int value,
54 TerrainRaycastResult raycastResult) {
56 float num = float.NegativeInfinity;
57 int wiredFace = 0;
58 for (int i = 0; i < 6; i++) {
59 float num2 = Vector3.Dot(CellFace.FaceToVector3(i), forward);
60 if (num2 > num) {
61 num = num2;
62 wiredFace = i;
63 }
64 }
65 BlockPlacementData result = default;
66 result.Value = Terrain.MakeBlockValue(BlockIndex, 0, SetWiredFace(0, wiredFace));
67 result.CellFace = raycastResult.CellFace;
68 return result;
69 }
70
71 public static int GetWiredFace(int data) {
72 if ((data & 3) == 0) {
73 return 0;
74 }
75 if ((data & 3) == 1) {
76 return 1;
77 }
78 return 4;
79 }
80
81 public static int SetWiredFace(int data, int wiredFace) {
82 data &= -4;
83 switch (wiredFace) {
84 case 0:
85 case 2: return data;
86 case 1:
87 case 3: return data | 1;
88 default: return data | 2;
89 }
90 }
91 }
92}
int BlockIndex
定义 Block.cs:6
ComponentCreatureModel ComponentCreatureModel
ComponentCreature ComponentCreature
static int MakeBlockValue(int contents)
static int ExtractData(int value)
static int SetWiredFace(int data, int wiredFace)
static int GetWiredFace(int data)
WireThroughBlock(int wiredTextureSlot, int unwiredTextureSlot)
override int GetFaceTextureSlot(int face, int value)
override BlockPlacementData GetPlacementValue(SubsystemTerrain subsystemTerrain, ComponentMiner componentMiner, int value, TerrainRaycastResult raycastResult)
方块放置方向
ElectricConnectorType? GetConnectorType(SubsystemTerrain terrain, int value, int face, int connectorFace, int x, int y, int z)
int GetConnectedWireFacesMask(int value, int face)
ElectricElement CreateElectricElement(SubsystemElectricity subsystemElectricity, int value, int x, int y, int z)
static Matrix CreateFromQuaternion(Quaternion quaternion)
Vector3 Forward
static float Dot(Vector3 v1, Vector3 v2)
static int OppositeFace(int face)
static Vector3 FaceToVector3(int face)