1using System.Globalization;
72 point2.Value.X - point.Value.X + 1,
73 point2.Value.Y - point.Value.Y + 1,
74 point2.Value.Z - point.Value.Z + 1
83 Vector3 min =
new(Position.X +
Box.Left, Position.Y +
Box.Top, Position.Z +
Box.Near);
84 Vector3 max =
new(Position.X +
Box.Right, Position.Y +
Box.Bottom, Position.Z +
Box.Far);
85 if (extendToFillCells) {
86 min.X = MathF.Floor(min.
X);
87 min.Y = MathF.Floor(min.
Y);
88 min.Z = MathF.Floor(min.
Z);
89 max.X = MathF.Ceiling(max.
X);
90 max.Y = MathF.Ceiling(max.
Y);
91 max.Z = MathF.Ceiling(max.
Z);
97 Blocks.RemoveAll(b => b.Offset == offset);
126 public DynamicArray<IMovingBlockSet>
m_result = [];
155 IEnumerable<MovingBlock> blocks,
158 bool testCollision) {
161 StartPosition = position,
162 TargetPosition = targetPosition,
164 Acceleration = acceleration,
166 Smoothness = smoothness,
169 Blocks = blocks.ToList(),
172 for (
int i = 0; i < movingBlockSet.
Blocks.Count; i++) {
173 movingBlockSet.
Blocks[i].MovingBlockSet = movingBlockSet;
178 "OnMovingBlockSetAdded",
180 loader.OnMovingBlockSetAdded(ref movingBlockSet,
this, ref testCollision, out
bool doNotAdd);
190 if (movingBlockSet.
Stop) {
198 return movingBlockSet;
206 "OnMovingBlockSetRemoved",
208 loader.OnMovingBlockSetRemoved(movingBlockSet2,
this);
212 movingBlockSet2.RemainCounter = 4;
218 if (!movingBlockSet.
Stop
220 result.Add(movingBlockSet);
227 if (movingBlockSet.
Id ==
id
228 && Equals(movingBlockSet.
Tag, tag)) {
229 return movingBlockSet;
240 float num =
float.MaxValue;
251 && num2.Value < num) {
253 movingBlockSet = item1;
257 catch (Exception e) {
258 Log.
Error($
"Moving Blocks raycast error{e}");
260 if (movingBlockSet !=
null) {
261 float distance =
float.MaxValue;
263 int rightCollisionBoxIndex = -1;
266 int blockValue = movingBlock.
Value;
277 out
int collisionBoxIndex,
281 && dist.Value < distance
282 && (action ==
null || action(blockValue, dist.Value))) {
283 distance = dist.Value;
284 rightMovingBlock = movingBlock;
285 rightCollisionBoxIndex = collisionBoxIndex;
286 rightNearestBox = nearestBox;
291 value.Distance = distance == float.MaxValue ? num : distance;
292 value.MovingBlockSet = movingBlockSet;
293 value.MovingBlock = rightMovingBlock;
294 value.CollisionBoxIndex = rightCollisionBoxIndex;
295 value.BlockBoundingBox = rightNearestBox;
306 "OnMovingBlockSetUpdate",
308 loader.OnMovingBlockSetUpdate(movingBlockSet,
this, pass, out
bool skipVanilla);
320 if (chunkAtCell ==
null
324 movingBlockSet.Speed += movingBlockSet.Acceleration *
m_subsystemTime.GameTimeDelta;
325 if (movingBlockSet.
Drag != 0f) {
326 movingBlockSet.Speed *= MathF.Pow(1f - movingBlockSet.
Drag,
m_subsystemTime.GameTimeDelta);
332 float num4 = num2 * num3;
335 float x2 = m_subsystemTime.GameTimeDelta > 0f ? 0.95f / m_subsystemTime.GameTimeDelta : 0f;
343 movingBlockSet.CurrentVelocity = num5 / num * (movingBlockSet.TargetPosition - movingBlockSet.
Position);
344 movingBlockSet.Position += movingBlockSet.CurrentVelocity *
m_subsystemTime.GameTimeDelta;
346 movingBlockSet.Stop =
false;
349 if (movingBlockSet.
Stop) {
351 movingBlockSet.Position.X = MathF.Ceiling(movingBlockSet.
Position.
X);
353 else if (vector.
X > 0f) {
354 movingBlockSet.Position.X = MathF.Floor(movingBlockSet.
Position.
X);
357 movingBlockSet.Position.Y = MathF.Ceiling(movingBlockSet.
Position.
Y);
359 else if (vector.
Y > 0f) {
360 movingBlockSet.Position.Y = MathF.Floor(movingBlockSet.
Position.
Y);
363 movingBlockSet.Position.Z = MathF.Ceiling(movingBlockSet.
Position.
Z);
365 else if (vector.
Z > 0f) {
366 movingBlockSet.Position.Z = MathF.Floor(movingBlockSet.
Position.
Z);
369 if (movingBlockSet.
Stop || flag) {
399 for (
int i = 0; i <
Buffers.Count; i++) {
401 Vector3 viewPosition = camera.ViewPosition;
402 Vector3 vector =
new(MathF.Floor(viewPosition.
X), 0f, MathF.Floor(viewPosition.
Z));
407 m_shader.GetParameter(
"u_origin").SetValue(vector.
XZ);
408 m_shader.GetParameter(
"u_viewProjectionMatrix").SetValue(value);
409 m_shader.GetParameter(
"u_viewPosition").SetValue(camera.ViewPosition);
410 m_shader.GetParameter(
"u_texture").SetValue(buffer.Texture);
414 m_shader.GetParameter(
"u_fogBottomTopDensity")
417 m_shader.GetParameter(
"u_alphaThreshold").SetValue(0.5f);
424 buffer.IndexBuffer.IndicesCount
439 float value3 = value9.GetValue<
float>(
"Speed");
440 float value4 = value9.GetValue<
float>(
"Acceleration");
441 float value5 = value9.GetValue<
float>(
"Drag");
443 string value7 = value9.GetValue<
string>(
"Id",
null);
444 object value8 = value9.GetValue<
object>(
"Tag",
null);
445 List<MovingBlock> list = [];
446 string[] array = value9.GetValue<
string>(
"Blocks").Split([
';'], StringSplitOptions.RemoveEmptyEntries);
447 foreach (
string obj2
in array) {
449 string[] array2 = obj2.Split([
','], StringSplitOptions.RemoveEmptyEntries);
473 valuesDictionary.SetValue(
"MovingBlockSets", valuesDictionary2);
477 valuesDictionary2.SetValue(num.ToString(CultureInfo.InvariantCulture), valuesDictionary3);
478 valuesDictionary3.SetValue(
"Position", movingBlockSet.
Position);
479 valuesDictionary3.SetValue(
"TargetPosition", movingBlockSet.
TargetPosition);
480 valuesDictionary3.SetValue(
"Speed", movingBlockSet.
Speed);
481 valuesDictionary3.SetValue(
"Acceleration", movingBlockSet.
Acceleration);
482 valuesDictionary3.SetValue(
"Drag", movingBlockSet.
Drag);
484 valuesDictionary3.SetValue(
"Smoothness", movingBlockSet.
Smoothness);
486 if (movingBlockSet.
Id !=
null) {
487 valuesDictionary3.SetValue(
"Id", movingBlockSet.
Id);
489 if (movingBlockSet.
Tag !=
null) {
490 valuesDictionary3.SetValue(
"Tag", movingBlockSet.
Tag);
492 StringBuilder stringBuilder =
new();
495 stringBuilder.Append(
',');
497 stringBuilder.Append(
',');
499 stringBuilder.Append(
',');
501 stringBuilder.Append(
';');
503 valuesDictionary3.SetValue(
"Blocks", stringBuilder.ToString());
525 for (
int i = 0; i <
m_result.Count; i++) {
526 if (
m_result.Array[i] != movingBlockSet) {
527 movingBlockSet.Stop =
true;
542 for (
int i = point.
X; i < point2.
X; i++) {
543 for (
int j = point.
Z; j < point2.
Z; j++) {
544 for (
int k = point.
Y; k < point2.
Y; k++) {
555 point.X = movingBlockSet.CurrentVelocity.X > 0f
558 point.Y = movingBlockSet.CurrentVelocity.Y > 0f
561 point.Z = movingBlockSet.CurrentVelocity.Z > 0f
569 int num = point.Y + p.
Y;
582 for (
int i = 0; i < x; i++) {
583 for (
int j = 0; j < x; j++) {
589 for (
int k = 0; k < point2.X + 2; k++) {
590 for (
int l = 0; l < point2.Z + 2; l++) {
591 int x2 = k + p.X + point.X - 1;
592 int z = l + p.Z + point.Z - 1;
596 for (
int m = 0; m < point2.Y + 2; m++) {
598 int y = m + p.Y + point.Y - 1;
610 m_blockGeometryGenerator.Terrain.SeasonHumidity = terrain.
SeasonHumidity;
612 int x3 = block.Offset.X - p.X + 1;
613 int num3 = block.Offset.Y - p.Y + 1;
614 int z2 = block.Offset.Z - p.Z + 1;
623 for (
int n = 1; n < point2.X + 1; n++) {
624 for (
int num4 = 1; num4 < point2.Y + 1; num4++) {
625 for (
int num5 = 1; num5 < point2.Z + 1; num5++) {
645 movingBlockSet.GeometryGenerationPosition = point;
671 return b1.Min.Z < b2.
Max.
Z;
678 if (movingBlock ==
null) {
679 throw new NullReferenceException(
"Moving Block Set cannot be null when stop block movement!");
694 catch (Exception ex) {
695 Log.
Error($
"Add terrain block when moving blocks stop error: {ex}");
bool Intersection(Vector3 point)
static readonly BlendState AlphaBlend
static readonly DepthStencilState Default
static void DrawIndexed(PrimitiveType primitiveType, Shader shader, VertexBuffer vertexBuffer, IndexBuffer indexBuffer, int startIndex, int indicesCount)
static readonly RasterizerState CullCounterClockwiseScissor
static SamplerState PointClamp
static void Error(object message)
static uint NextPowerOf2(uint x)
static int Min(int x1, int x2)
static float Saturate(float x)
static string ConvertToString(object value)
static object ConvertFromString(Type type, string data)
void GenerateTerrainVertices(BlockGeometryGenerator generator, TerrainGeometry geometry, int value, int x, int y, int z)
生成地形顶点(用于绘制放置的方块)
virtual int GetShadowStrength(int value)
virtual ? float Raycast(Ray3 ray, SubsystemTerrain subsystemTerrain, int value, bool useInteractionBoxes, out int nearestBoxIndex, out BoundingBox nearestBox)
BoundingFrustum ViewFrustum
static object Get(Type type, string name)
IMovingBlockSet MovingBlockSet
static int SetShadowStrength(int data, int shadowStrength)
BoundingBox BoundingBox(bool extendToFillCells)
Point3 GeometryGenerationPosition
List< MovingBlock > Blocks
void TerrainCollision(MovingBlockSet movingBlockSet)
bool m_noDropOnMovingBlockStopped
override void Load(ValuesDictionary valuesDictionary)
DynamicArray< IMovingBlockSet > m_result
static bool ExclusiveBoxIntersection(BoundingBox b1, BoundingBox b2)
Action< IMovingBlockSet, Point3 > CollidedWithTerrain
virtual void AddTerrainBlock(int x, int y, int z, int value, MovingBlock movingBlock)
static int[] m_drawOrders
IMovingBlockSet AddMovingBlockSet(Vector3 position, Vector3 targetPosition, float speed, float acceleration, float drag, Vector2 smoothness, IEnumerable< MovingBlock > blocks, string id, object tag, bool testCollision)
IMovingBlockSet FindMovingBlocks(string id, object tag)
virtual void Draw(Camera camera, int drawOrder)
MovingBlocksRaycastResult? Raycast(Vector3 start, Vector3 end, bool extendToFillCells, Func< int, float, bool > action=null)
void GenerateGeometry(MovingBlockSet movingBlockSet)
List< MovingBlockSet > m_removing
SubsystemTerrain m_subsystemTerrain
SubsystemSky m_subsystemSky
void MovingBlocksCollision(MovingBlockSet movingBlockSet)
BlockGeometryGenerator m_blockGeometryGenerator
List< MovingBlockSet > m_stopped
void RemoveMovingBlockSet(IMovingBlockSet movingBlockSet)
DynamicArray< TerrainChunkGeometry.Buffer > Buffers
static DynamicArray< TerrainVertex > m_vertexList
override void Save(ValuesDictionary valuesDictionary)
SubsystemAnimatedTextures m_subsystemAnimatedTextures
void FindMovingBlocks(BoundingBox boundingBox, bool extendToFillCells, DynamicArray< IMovingBlockSet > result)
virtual void Update(float dt)
Action< IMovingBlockSet > Stopped
static DynamicArray< int > m_tmpIndices
List< IMovingBlockSet > MovingBlockSets
bool m_canGenerateGeometry
virtual void DrawMovingBlockSet(Camera camera, MovingBlockSet movingBlockSet)
SubsystemTime m_subsystemTime
List< MovingBlockSet > m_movingBlockSets
virtual void ClearGeometry()
static int ExtractTemperature(int value)
static int ExtractContents(int value)
virtual int GetCellValue(int x, int y, int z)
static int ToCell(float x)
static int ExtractLight(int value)
static int ExtractHumidity(int value)
virtual int GetShaftValue(int x, int z)
static int ReplaceLight(int value, int light)
static int MakeBlockValue(int contents)
static void CompileDrawSubsets(TerrainGeometry[] chunkSliceGeometries, DynamicArray< TerrainChunkGeometry.Buffer > buffers, Func< TerrainVertex, TerrainVertex > vertexTransform=null)
ValuesDictionary ValuesDictionary
static void HookAction(string HookName, Func< ModLoader, bool > action)
执行Hook
BoundingBox BoundingBox(bool extendToFillCells)
List< MovingBlock > Blocks
void SetBlock(Point3 offset, int value)
static Matrix CreateTranslation(float x, float y, float z)
static Point3 Floor(Vector3 v)
static Point3 Min(Point3 p, int v)
static Point3 Max(Point3 p, int v)
static Point3 Ceiling(Vector3 v)
float? Intersection(BoundingBox box)
static readonly Vector2 Zero
static Vector3 Normalize(Vector3 v)
static readonly Vector3 Zero
static float Distance(Vector3 v1, Vector3 v2)
static Vector3 Max(Vector3 v, float f)
static Vector3 Min(Vector3 v, float f)