1using System.Globalization;
21 public static string fName =
"SubsystemFurnitureBlockBehavior";
53 if (furnitureDesign !=
null
55 return furnitureDesign;
85 if (furnitureDesign !=
null) {
86 return furnitureDesign;
88 List<FurnitureDesign> list = design.
ListChain();
97 if (num >= list.Count) {
105 if (num != list.Count) {
106 throw new InvalidOperationException(
"public error.");
114 Dictionary<Point3, int> valuesDictionary =
new();
119 bool designedFromExistingFurniture =
false;
122 furnitureDesign =
GetDesign(designIndex);
123 if (furnitureDesign ==
null) {
127 design = furnitureDesign.
Clone();
128 design.LinkedDesign =
null;
130 designedFromExistingFurniture =
true;
131 valuesDictionary.Add(start.
Point, startValue);
134 Stack<Point3> val =
new();
135 val.Push(start.
Point);
136 HashSet<Point3> scannedPoints = [];
137 while (val.Count > 0) {
139 if (valuesDictionary.ContainsKey(key)
150 if (chunkAtCell ==
null
156 if (key.
X < point.
X) {
159 if (key.
Y < point.
Y) {
162 if (key.
Z < point.
Z) {
165 if (key.
X > point2.
X) {
168 if (key.
Y > point2.
Y) {
171 if (key.
Z > point2.
Z) {
180 valuesDictionary[key] = cellValue;
181 Point3 p1 =
new(key.X - 1, key.
Y, key.
Z);
182 if (scannedPoints.Add(p1)) {
185 Point3 p2 =
new(key.X + 1, key.
Y, key.
Z);
186 if (scannedPoints.Add(p2)) {
189 Point3 p3 =
new(key.
X, key.Y - 1, key.
Z);
190 if (scannedPoints.Add(p3)) {
193 Point3 p4 =
new(key.
X, key.Y + 1, key.
Z);
194 if (scannedPoints.Add(p4)) {
197 Point3 p5 =
new(key.
X, key.
Y, key.Z - 1);
198 if (scannedPoints.Add(p5)) {
201 Point3 p6 =
new(key.
X, key.
Y, key.Z + 1);
202 if (scannedPoints.Add(p6)) {
207 if (valuesDictionary.Count == 0) {
212 Point3 point3 = point2 - point;
214 int[] array =
new int[num2 * num2 * num2];
215 foreach (KeyValuePair<Point3, int> item
in valuesDictionary) {
216 Point3 point4 = item.Key - point;
217 array[point4.X + point4.Y * num2 + point4.Z * num2 * num2] = item.Value;
224 Point3 delta =
new((point5.X - location.
X) / 2, -location.
Y, (point5.Z - location.
Z) / 2);
230 delegate(
bool result) {
233 if (design ==
null) {
237 bool destroyDesignBlocks = m_subsystemGameInfo.WorldSettings.GameMode != 0;
243 int num3 = Math.Clamp(design.
Resolution, 4, 8);
246 int toolDamageCount = 1;
248 "OnFurnitureDesigned",
250 modLoader.OnFurnitureDesigned(
252 designedFromExistingFurniture,
254 ref destroyDesignBlocks,
264 if (durabilityRemains < toolDamageCount) {
274 if (destroyDesignBlocks) {
275 foreach (KeyValuePair<Point3, int> item2
in valuesDictionary) {
288 componentMiner.
Poke(
false);
289 for (
int i = 0; i < 3; i++) {
292 delegate { m_subsystemSoundMaterials.PlayImpactSound(startValue, new Vector3(start.Point), 1f); }
296 componentMiner.ComponentCreature.PlayerStats.FurnitureItemsMade += num3;
309 HashSet<Point3> hashSet = [];
310 List<Point3> list = [
new(x, y, z)];
312 while (num < list.Count
314 Point3 item = list[num++];
315 if (!hashSet.Add(item)) {
338 list.Add(
new Point3(item.
X - 1, item.
Y, item.
Z));
339 list.Add(
new Point3(item.
X + 1, item.
Y, item.
Z));
340 list.Add(
new Point3(item.
X, item.
Y - 1, item.
Z));
341 list.Add(
new Point3(item.
X, item.
Y + 1, item.
Z));
342 list.Add(
new Point3(item.
X, item.
Y, item.
Z - 1));
343 list.Add(
new Point3(item.
X, item.
Y, item.
Z + 1));
361 while (
FurnitureSets.FirstOrDefault(fs => fs.Name == name) !=
null) {
363 name = num > 0 ? name + num.ToString(CultureInfo.InvariantCulture) : name;
365 FurnitureSet furnitureSet =
new() { Name = name, ImportedFrom = importedFrom };
372 furnitureSetDesign.FurnitureSet =
null;
387 item.FurnitureSet = furnitureSet;
396 List<FurnitureDesign> list = [];
397 foreach (KeyValuePair<string, object> item2
in valuesDictionary) {
398 int index =
int.Parse(item2.Key, CultureInfo.InvariantCulture);
400 FurnitureDesign item =
new(index, subsystemTerrain, valuesDictionary2);
413 valuesDictionary.SetValue(design.
Index.ToString(CultureInfo.InvariantCulture), design.
Save());
417 public override void OnBlockAdded(
int value,
int oldValue,
int x,
int y,
int z) {
422 public override void OnBlockRemoved(
int value,
int newValue,
int x,
int y,
int z) {
442 List<Point3> list = [];
444 if (key.
X >= chunk.Origin.X
445 && key.
X < chunk.Origin.X + 16
446 && key.
Z >= chunk.Origin.Y
447 && key.
Z < chunk.Origin.Y + 16) {
451 foreach (
Point3 item
in list) {
472 base.Load(valuesDictionary);
485 string value2 = item2.GetValue<
string>(
"Name");
486 string value3 = item2.GetValue<
string>(
"ImportedFrom",
null);
487 string value4 = item2.GetValue<
string>(
"Indices");
489 FurnitureSet furnitureSet =
new() { Name = value2, ImportedFrom = value3 };
491 int[] array2 = array;
492 foreach (
int num
in array2) {
504 base.Save(valuesDictionary);
507 valuesDictionary.SetValue(
"FurnitureDesigns", valuesDictionary2);
510 valuesDictionary.SetValue(
"FurnitureSets", valuesDictionary3);
514 valuesDictionary3.SetValue(num.ToString(CultureInfo.InvariantCulture), valuesDictionary4);
515 valuesDictionary4.SetValue(
"Name", furnitureSet.
Name);
517 valuesDictionary4.SetValue(
"ImportedFrom", furnitureSet.
ImportedFrom);
523 valuesDictionary4.SetValue(
"Indices", value);
530 design.Index = index;
531 design.m_terrainUseCount = 0;
562 if (design !=
null) {
563 design.m_gcUsed =
true;
571 while (linkedDesign !=
null
573 linkedDesign.m_gcUsed =
true;
597 if ((num == 18 || num == 92)
613 if (design ==
null) {
616 List<FireParticleSystem> list = [];
618 if (torchPoints.Length != 0) {
620 for (
int i = 0; i < array.Length; i++) {
622 float num = (boundingBox.
Size().X + boundingBox.
Size().
Y + boundingBox.
Size().
Z) / 3f;
623 float size = Math.Clamp(1.5f * num, 0.1f, 1f);
626 list.Add(fireParticleSystem);
629 if (list.Count > 0) {
637 item.IsStopped =
true;
static int Max(int x1, int x2)
static void QueueTimeDelayedExecution(double time, Action action)
static double FrameStartTime
virtual bool CanBlockBeBuiltIntoFurniture(int value)
virtual int GetDamage(int value)
virtual int GetDurability(int value)
ComponentBody ComponentBody
virtual void DisplaySmallMessage(string text, Color color, bool blinking, bool playNotificationSound)
ComponentPlayer ComponentPlayer
ComponentCreature ComponentCreature
virtual void Poke(bool forceRestart)
virtual void DamageActiveTool(int damageCount)
ComponentGui ComponentGui
ContainerWidget GuiWidget
static void ShowDialog(ContainerWidget parentWidget, Dialog dialog)
static bool GetIsTop(int data)
static int GetLevel(int data)
static int GetRotation(int data)
static int SetDesignIndex(int data, int designIndex, int shadowStrengthFactor, bool isLightEmitter)
static int GetDesignIndex(int data)
FurnitureInteractionMode InteractionMode
List< FurnitureDesign > ListChain()
bool CompareChain(FurnitureDesign other)
BoundingBox[] GetTorchPoints(int rotation)
FurnitureDesign LinkedDesign
void SetValues(int resolution, int[] values)
int m_loadTimeLinkedDesignIndex
void Rotate(int axis, int steps)
static string Get(string className, int key)
获取在当前语言类名键对应的字符串
SubsystemTerrain SubsystemTerrain
void MoveFurnitureSet(FurnitureSet furnitureSet, int move)
override void Load(ValuesDictionary valuesDictionary)
override void OnBlockGenerated(int value, int x, int y, int z, bool isLoaded)
SubsystemSoundMaterials m_subsystemSoundMaterials
override int[] HandledBlocks
static List< FurnitureDesign > LoadFurnitureDesigns(SubsystemTerrain subsystemTerrain, ValuesDictionary valuesDictionary)
IEnumerable< FurnitureDesign > GetFurnitureSetDesigns(FurnitureSet furnitureSet)
void SwitchToNextState(int x, int y, int z, bool playSound)
static bool IsValueDisallowed(int value)
FurnitureDesign[] m_furnitureDesigns
SubsystemPickables m_subsystemPickables
void GarbageCollectDesigns()
void RemoveTerrainFurniture(int value)
void AddParticleSystems(int value, int x, int y, int z)
FurnitureSet NewFurnitureSet(string name, string importedFrom)
ReadOnlyList< FurnitureSet > FurnitureSets
override void OnChunkDiscarding(TerrainChunk chunk)
void GarbageCollectDesigns(ReadOnlyList< ScannedItemData > allExistingItems)
static bool IsValueAllowed(int value)
List< FurnitureSet > m_furnitureSets
override void OnBlockRemoved(int value, int newValue, int x, int y, int z)
FurnitureDesign FindMatchingDesignChain(FurnitureDesign design)
SubsystemGameInfo m_subsystemGameInfo
FurnitureDesign GetDesign(int index)
Dictionary< Point3, List< FireParticleSystem > > m_particleSystemsByCell
override void OnBlockAdded(int value, int oldValue, int x, int y, int z)
SubsystemAudio m_subsystemAudio
void AddTerrainFurniture(int value)
override void OnBlockModified(int value, int oldValue, int x, int y, int z)
void AddDesign(int index, FurnitureDesign design)
FurnitureDesign TryAddDesignChain(FurnitureDesign design, bool garbageCollectIfNeeded)
FurnitureDesign FindMatchingDesign(FurnitureDesign design)
FurnitureDesign TryAddDesign(FurnitureDesign design)
static void SaveFurnitureDesigns(ValuesDictionary valuesDictionary, ICollection< FurnitureDesign > designs)
SubsystemItemsScanner m_subsystemItemsScanner
void ScanDesign(CellFace start, Vector3 direction, ComponentMiner componentMiner)
const int MaxFurnitureSetNameLength
override void Save(ValuesDictionary valuesDictionary)
void DeleteFurnitureSet(FurnitureSet furnitureSet)
SubsystemParticles m_subsystemParticles
void AddToFurnitureSet(FurnitureDesign design, FurnitureSet furnitureSet)
void RemoveParticleSystems(int x, int y, int z)
override bool OnInteract(TerrainRaycastResult raycastResult, ComponentMiner componentMiner)
static int ExtractContents(int value)
static int ReplaceData(int value, int data)
static int MakeBlockValue(int contents)
static int ExtractData(int value)
ValuesDictionary ValuesDictionary
static void HookAction(string HookName, Func< ModLoader, bool > action)
执行Hook
static readonly Vector3 UnitY
static int Vector3ToFace(Vector3 v, int maxFace=5)
static int OppositeFace(int face)