-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCreatorAPI.cs
More file actions
212 lines (208 loc) · 8.6 KB
/
CreatorAPI.cs
File metadata and controls
212 lines (208 loc) · 8.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
using System;
using Engine;
using System.Collections.Generic;
using Game;
using GameEntitySystem;
using Engine.Graphics;
using System.Threading.Tasks;
using System.Threading;
namespace CreatorModAPI
{
public class CreatorAPI
{
public enum NumberPoint
{
One,
Two,
Three,
Four
}
public enum OnekeyType
{
Tree,
Build
}
public bool oldMainWidget = false;
/// <summary>
/// 空气识别
/// </summary>
public bool AirIdentify = false;
/// <summary>
/// 清理方块
/// </summary>
public bool ClearBlock = false;
/// <summary>
/// 超视距生成
/// </summary>
public bool UnLimitedOfCreate = false;
/// <summary>
/// 缓存开关
/// </summary>
public bool RevokeSwitch = false;
/// <summary>
/// 撤回缓存
/// </summary>
public ChunkData revokeData = null;
public List<Point3> Position { get; set; }
/// <summary>
/// 可设置多少个点
/// </summary>
public NumberPoint amountPoint = NumberPoint.Two;
/// <summary>
/// 设置到第几个点
/// </summary>
public NumberPoint numberPoint = NumberPoint.One;
/// <summary>
/// 选择生成方块处理方式
/// </summary>
public CreateBlockType CreateBlockType = CreateBlockType.Fast;
/* /// <summary>
/// 两点连线开关
/// </summary>
public bool twoPointsOfAttachment = false;*/
/// <summary>
/// 一键生成开关
/// </summary>
public bool oneKeyGeneration = false;
/// <summary>
/// 一键生成类型
/// </summary>
public OnekeyType onekeyType = OnekeyType.Build;
/// <summary>
/// 生成开关
/// </summary>
public bool launch = true;
/// <summary>
/// 粘贴旋转设置
/// </summary>
public bool pasteRotate = false;
/// <summary>
/// 粘贴限制设置
/// </summary>
public bool pasteLimit = false;
/// <summary>
/// 获取玩家
/// </summary>
public ComponentMiner componentMiner;
public PrimitivesRenderer3D primitivesRenderer3D;
public CreatorGenerationAlgorithm creatorGenerationAlgorithm;
public CreatorAPI(ComponentMiner componentMiner)
{
creatorGenerationAlgorithm = new CreatorGenerationAlgorithm();
this.componentMiner = componentMiner;
this.Position = new List<Point3>(4)
{
new Point3(0,-1,0),
new Point3(0,-1,0),
new Point3(0,-1,0),
new Point3(0,-1,0)
};
}
public void OnUse(TerrainRaycastResult terrainRaycastResult)
{
Point3 position = terrainRaycastResult.CellFace.Point;
ComponentPlayer Player = this.componentMiner.ComponentPlayer;
if (!OnTouch.Touch(this, position))
{
return;
}
int cellValue = GameManager.Project.FindSubsystem<SubsystemTerrain>(true).Terrain.GetCellValue(position.X, position.Y, position.Z);
int light = Terrain.ExtractLight(cellValue);
int data = Terrain.ExtractData(cellValue);
int contents = Terrain.ExtractContents(cellValue);
if (BlocksManager.Blocks[contents] != null)
{
if (numberPoint == NumberPoint.One)
{
this.Position[0] = position;
Player.ComponentGui.DisplaySmallMessage($"坐标1设置完成\n X:{position.X} ,Y:{position.Y} ,Z:{position.Z}\n方块ID : {contents}\n方块完整值 : {cellValue}\n特殊值一 : {light} , 特殊值二 : {data} \n", true, false);
if (amountPoint != numberPoint) numberPoint = NumberPoint.Two;
}
else if (numberPoint == NumberPoint.Two)
{
this.Position[1] = position;
Player.ComponentGui.DisplaySmallMessage($"坐标2设置完成\n X:{position.X} ,Y:{position.Y} ,Z:{position.Z}\n方块ID : {contents}\n方块完整值 : {cellValue}\n特殊值一 : {light} , 特殊值二 : {data}\n", true, false);
if (amountPoint == numberPoint) numberPoint = NumberPoint.One; else numberPoint = NumberPoint.Three;
}
else if (numberPoint == NumberPoint.Three)
{
this.Position[2] = position;
Player.ComponentGui.DisplaySmallMessage($"坐标3设置完成\n X:{position.X} ,Y:{position.Y} ,Z:{position.Z}\n方块ID : {contents}\n方块完整值 : {cellValue}\n特殊值一 : {light} , 特殊值二 : {data}\n", true, false);
if (amountPoint == numberPoint) numberPoint = NumberPoint.One; else numberPoint = NumberPoint.Four;
}
else if (numberPoint == NumberPoint.Four)
{
this.Position[3] = position;
Player.ComponentGui.DisplaySmallMessage($"坐标4设置完成\n X:{position.X} ,Y:{position.Y} ,Z:{position.Z}\n方块ID : {contents}\n方块完整值 : {cellValue}\n特殊值一 : {light} , 特殊值二 : {data}\n", true, false);
numberPoint = NumberPoint.One;
}
}
}
public void CreateBlock(int x, int y, int z, int value,ChunkData chunkData = null)
{
if (this.RevokeSwitch && this.revokeData != null && this.revokeData.GetChunk(x, y) == null) this.revokeData.CreateChunk(x, y,true);
switch (this.CreateBlockType)
{
case CreateBlockType.Fast:
SetBlock(x, y, z, value);
break;
case CreateBlockType.Normal:
GameManager.Project.FindSubsystem<SubsystemTerrain>(true).ChangeCell(x, y, z, value);
break;
case CreateBlockType.Catch:
chunkData.SetBlock(x,y,z,value);
break;
}
}
public void CreateBlock(Point3 point3, int value,ChunkData chunkData = null)
{
if (this.RevokeSwitch && this.revokeData != null && this.revokeData.GetChunk(point3.X, point3.Z) == null) this.revokeData.CreateChunk(point3.X,point3.Z,true);
switch (this.CreateBlockType)
{
case CreateBlockType.Fast:
SetBlock(point3.X, point3.Y, point3.Z, value);
break;
case CreateBlockType.Normal:
GameManager.Project.FindSubsystem<SubsystemTerrain>(true).ChangeCell(point3.X, point3.Y, point3.Z, value);
break;
case CreateBlockType.Catch:
chunkData.SetBlock(point3,value);
break;
}
}
public void SetBlock(int x, int y, int z, int value)
{
try
{
SubsystemTerrain subsystemTerrain = this.componentMiner.Project.FindSubsystem<SubsystemTerrain>(true);
if (subsystemTerrain.Terrain.IsCellValid(x, y, z))
{
TerrainChunk chunkAtCell = subsystemTerrain.Terrain.GetChunkAtCell(x, z);
if (chunkAtCell == null)
{
if (!this.UnLimitedOfCreate) return;
chunkAtCell = subsystemTerrain.Terrain.AllocateChunk(x >> 4, z >> 4);
while (chunkAtCell.ThreadState < TerrainChunkState.Valid)
subsystemTerrain.TerrainUpdater.UpdateChunkSingleStep(chunkAtCell, 15);
}
chunkAtCell.Cells[y + (x & 15) * 128 + (z & 15) * 128 * 16] = value;
chunkAtCell.ModificationCounter++;
if (this.UnLimitedOfCreate)
{
chunkAtCell.State = TerrainChunkState.Valid;
}
if (chunkAtCell.State > TerrainChunkState.InvalidLight)
{
chunkAtCell.State = TerrainChunkState.InvalidLight;
}
chunkAtCell.WasDowngraded = true;
//subsystemTerrain.m_modifiedCells[new Point3(x, y, z)] = true;
}
}
catch(Exception e)
{
Log.Error("快速生成发生错误:"+e.Message);
}
}
}
}