Survivalcraft API 1.8.2.3 v1.8.2.3
Survivalcraft 2.4
载入中...
搜索中...
未找到
SubsystemBucketBlockBehavior.cs
浏览该文件的文档.
1using Engine;
3
4namespace Game {
7
9
10 public Random m_random = new();
11
12 public static string fName = "SubsystemBucketBlockBehavior";
13
20
21 public override int[] HandledBlocks => [
26 245,
27 251,
28 252,
29 129,
30 128
31 ];
32
33 public override bool OnUse(Ray3 ray, ComponentMiner componentMiner) {
34 IInventory inventory = componentMiner.Inventory;
35 int activeBlockValue = componentMiner.ActiveBlockValue;
36 int num = Terrain.ExtractContents(activeBlockValue);
37 if (num == m_emptyBucketBlockIndex) {
38 object obj = componentMiner.Raycast(ray, RaycastMode.Gathering);
39 if (obj is TerrainRaycastResult) {
40 CellFace cellFace = ((TerrainRaycastResult)obj).CellFace;
41 int cellValue = SubsystemTerrain.Terrain.GetCellValue(cellFace.X, cellFace.Y, cellFace.Z);
42 int num2 = Terrain.ExtractContents(cellValue);
43 int data = Terrain.ExtractData(cellValue);
44 Block block = BlocksManager.Blocks[num2];
45 int newBucketValue = 0;
46 if (block is WaterBlock
47 && FluidBlock.GetLevel(data) == 0) {
48 newBucketValue = m_waterBucketBlockIndex;
49 }
50 if (block is MagmaBlock
51 && FluidBlock.GetLevel(data) == 0) {
52 newBucketValue = m_magmaBucketBlockIndex;
53 }
54 if (newBucketValue == 0) {
55 return false;
56 }
57 int currentCount = inventory.GetSlotCount(inventory.ActiveSlotIndex);
58 if (currentCount > 1) {
59 inventory.RemoveSlotItems(inventory.ActiveSlotIndex, 1);
60 int acquireSlot = ComponentInventoryBase.FindAcquireSlotForItem(inventory, newBucketValue);
61 if (acquireSlot >= 0) {
62 inventory.AddSlotItems(acquireSlot, newBucketValue, 1);
63 SubsystemTerrain.DestroyCell(
64 0,
65 cellFace.X,
66 cellFace.Y,
67 cellFace.Z,
68 0,
69 false,
70 false
71 );
72 return true;
73 }
74 inventory.AddSlotItems(inventory.ActiveSlotIndex, activeBlockValue, 1);
76 }
77 else {
78 inventory.RemoveSlotItems(inventory.ActiveSlotIndex, currentCount);
79 if (inventory.GetSlotCount(inventory.ActiveSlotIndex) == 0) {
80 inventory.AddSlotItems(inventory.ActiveSlotIndex, newBucketValue, 1);
81 }
82 SubsystemTerrain.DestroyCell(
83 0,
84 cellFace.X,
85 cellFace.Y,
86 cellFace.Z,
87 0,
88 false,
89 false
90 );
91 return true;
92 }
93 }
94 else if (obj is BodyRaycastResult) {
96 int newBucketValue = m_milkBucketBlockIndex;
97 int currentCount = inventory.GetSlotCount(inventory.ActiveSlotIndex);
98 if (currentCount > 1) {
99 inventory.RemoveSlotItems(inventory.ActiveSlotIndex, 1);
100 int acquireSlot = ComponentInventoryBase.FindAcquireSlotForItem(inventory, newBucketValue);
101 if (acquireSlot < 0) {
104 Color.White,
105 true,
106 true
107 );
108 }
109 if (acquireSlot >= 0
110 && componentUdder != null
111 && componentUdder.Milk(componentMiner)) {
112 inventory.AddSlotItems(acquireSlot, newBucketValue, 1);
113 m_subsystemAudio.PlaySound("Audio/Milked", 1f, 0f, ray.Position, 2f, true);
114 return true;
115 }
116 inventory.AddSlotItems(inventory.ActiveSlotIndex, activeBlockValue, 1);
117 return false;
118 }
119 if (componentUdder != null
120 && componentUdder.Milk(componentMiner)) {
121 inventory.RemoveSlotItems(inventory.ActiveSlotIndex, currentCount);
122 if (inventory.GetSlotCount(inventory.ActiveSlotIndex) == 0) {
123 inventory.AddSlotItems(inventory.ActiveSlotIndex, m_milkBucketBlockIndex, 1);
124 }
125 m_subsystemAudio.PlaySound("Audio/Milked", 1f, 0f, ray.Position, 2f, true);
126 return true;
127 }
128 return false;
129 }
130 }
131 if (num == m_waterBucketBlockIndex
132 || num == m_magmaBucketBlockIndex) {
134 TerrainRaycastResult? terrainRaycastResult = componentMiner.Raycast<TerrainRaycastResult>(ray, RaycastMode.Interaction);
135 if (terrainRaycastResult.HasValue) {
136 int currentCount = inventory.GetSlotCount(inventory.ActiveSlotIndex);
137 if (currentCount > 1) {
138 inventory.RemoveSlotItems(inventory.ActiveSlotIndex, 1);
139 int newBucketValue = m_emptyBucketBlockIndex;
140 int acquireSlot = ComponentInventoryBase.FindAcquireSlotForItem(inventory, newBucketValue);
141 if (acquireSlot >= 0
142 && componentMiner.Place(terrainRaycastResult.Value, Terrain.MakeBlockValue(fluidValue))) {
143 inventory.AddSlotItems(acquireSlot, newBucketValue, 1);
144 }
145 else {
146 inventory.AddSlotItems(inventory.ActiveSlotIndex, activeBlockValue, 1);
149 Color.White,
150 true,
151 true
152 );
153 return false;
154 }
155 return true;
156 }
157 if (componentMiner.Place(terrainRaycastResult.Value, Terrain.MakeBlockValue(fluidValue))) {
158 inventory.RemoveSlotItems(inventory.ActiveSlotIndex, 1);
159 if (inventory.GetSlotCount(inventory.ActiveSlotIndex) == 0) {
161 }
162 return true;
163 }
164 }
165 }
166 switch (num) {
167 case 110:
168 case 245: return true;
169 case 251:
170 case 252: return true;
171 case 128:
172 case 129: {
173 TerrainRaycastResult? terrainRaycastResult3 = componentMiner.Raycast<TerrainRaycastResult>(ray, RaycastMode.Digging);
174 if (terrainRaycastResult3.HasValue) {
175 CellFace cellFace2 = terrainRaycastResult3.Value.CellFace;
176 int cellValue2 = SubsystemTerrain.Terrain.GetCellValue(cellFace2.X, cellFace2.Y, cellFace2.Z);
177 int num3 = Terrain.ExtractContents(cellValue2);
178 Block block2 = BlocksManager.Blocks[num3];
179 if (block2 is IPaintableBlock) {
180 Vector3 normal = CellFace.FaceToVector3(terrainRaycastResult3.Value.CellFace.Face);
181 Vector3 position = terrainRaycastResult3.Value.HitPoint();
182 int? num4 = num == 128 ? null : new int?(PaintBucketBlock.GetColor(Terrain.ExtractData(activeBlockValue)));
183 Color color = num4.HasValue ? SubsystemPalette.GetColor(SubsystemTerrain, num4) : new Color(128, 128, 128, 128);
184 int value6 = ((IPaintableBlock)block2).Paint(SubsystemTerrain, cellValue2, num4);
185 if (value6 != cellValue2) {
186 SubsystemTerrain.ChangeCell(cellFace2.X, cellFace2.Y, cellFace2.Z, value6);
187 componentMiner.DamageActiveTool(1);
188 m_subsystemAudio.PlayRandomSound(
189 "Audio/Paint",
190 0.4f,
191 m_random.Float(-0.1f, 0.1f),
193 2f,
194 true
195 );
196 m_subsystemParticles.AddParticleSystem(new PaintParticleSystem(SubsystemTerrain, position, normal, color));
197 }
198 }
199 return true;
200 }
201 break;
202 }
203 }
204 return false;
205 }
206
218 }
219}
Engine.Color Color
static int GetBlockIndex(string BlockName, bool throwIfNotFound=false)
通过方块名称来获取方块的Index
virtual void DisplaySmallMessage(string text, Color color, bool blinking, bool playNotificationSound)
static int FindAcquireSlotForItem(IInventory inventory, int value)
ComponentPlayer ComponentPlayer
ComponentCreature ComponentCreature
bool Place(TerrainRaycastResult raycastResult)
virtual object Raycast(Ray3 ray, RaycastMode mode, bool raycastTerrain=true, bool raycastBodies=true, bool raycastMovingBlocks=true, float? Reach=null)
发出射线检测,检测玩家点击到的目标
virtual void DamageActiveTool(int damageCount)
virtual bool Milk(ComponentMiner milker)
static int GetLevel(int data)
static string Get(string className, int key)
获取在当前语言类名键对应的字符串
static int GetColor(int data)
override bool OnUse(Ray3 ray, ComponentMiner componentMiner)
override void Load(ValuesDictionary valuesDictionary)
static int ExtractContents(int value)
static int MakeBlockValue(int contents)
static int ExtractData(int value)
Component FindComponent(Type type, string name, bool throwOnError)
ValuesDictionary ValuesDictionary
int RemoveSlotItems(int slotIndex, int count)
实际移除的数量
int GetSlotCount(int slotIndex)
void AddSlotItems(int slotIndex, int value, int count)
static Color White
Vector3 Position
定义 Ray3.cs:3
static Vector3 FaceToVector3(int face)