Survivalcraft API 1.8.2.3 v1.8.2.3
Survivalcraft 2.4
载入中...
搜索中...
未找到
ComponentDispenser.cs
浏览该文件的文档.
1using Engine;
4
5namespace Game {
8
10
12
14
16
17 public virtual void Dispense() {
18 int data = Terrain.ExtractData(m_componentBlockEntity.BlockValue);
19 int direction = DispenserBlock.GetDirection(data);
21 int num = 0;
22 int slotValue;
23 while (true) {
24 if (num < SlotsCount) {
25 slotValue = GetSlotValue(num);
26 int slotCount = GetSlotCount(num);
27 if (slotValue != 0
28 && slotCount > 0
30 break;
31 }
32 num++;
33 continue;
34 }
35 return;
36 }
38 "DispenserChooseItemToDispense",
39 loader => {
40 loader.DispenserChooseItemToDispense(this, ref num, ref slotValue, out bool chosen);
41 return chosen;
42 }
43 );
44 if (num >= 0) //投掷的Slot
45 {
46 int num2 = 1;
47 for (int i = 0; i < num2 && GetSlotCount(num) > 0; i++) {
48 int itemDispense = DispenseItem(m_componentBlockEntity.Position, direction, slotValue, mode);
49 try {
50 RemoveSlotItems(num, itemDispense);
51 }
52 catch (Exception e) {
53 Log.Error(e.ToString());
54 }
55 }
56 }
57 }
58
59 public override void Load(ValuesDictionary valuesDictionary, IdToEntityMap idToEntityMap) {
60 base.Load(valuesDictionary, idToEntityMap);
61 m_subsystemTerrain = Project.FindSubsystem<SubsystemTerrain>(true);
62 m_subsystemAudio = Project.FindSubsystem<SubsystemAudio>(true);
63 m_subsystemPickables = Project.FindSubsystem<SubsystemPickables>(true);
66 m_componentBlockEntity.m_inventoryToGatherPickable = this;
67 }
68
69 public virtual int DispenseItem(Vector3 point, int face, int value, DispenserBlock.Mode mode) {
70 Vector3 vector = CellFace.FaceToVector3(face);
71 Vector3 position = new Vector3(point.X + 0.5f, point.Y + 0.5f, point.Z + 0.5f) + 0.6f * vector;
72 int removeSlotCount = 1;
73 //投掷物品
74 if (mode == DispenserBlock.Mode.Dispense) {
75 float s = 1.8f;
76 Pickable pickable = m_subsystemPickables.CreatePickable(value, 1, position, s * (vector + m_random.Vector3(0.2f)), null, Entity);
78 "OnDispenserDispensePickable",
79 loader => {
80 loader.OnDispenserDispensePickable(this, ref pickable, ref removeSlotCount);
81 return false;
82 }
83 );
84 if (pickable != null) {
85 m_subsystemPickables.AddPickable(pickable);
86 m_subsystemAudio.PlaySound("Audio/DispenserDispense", 1f, 0f, new Vector3(position.X, position.Y, position.Z), 3f, true);
87 return removeSlotCount;
88 }
89 return 0;
90 }
91 //发射物品
92 float s2 = m_random.Float(39f, 41f);
93 bool canFireProjectile = m_subsystemProjectiles.CanFireProjectile(value, position, vector, null, out Vector3 position2);
94 bool canDispensePickable = true;
95 Projectile projectile = m_subsystemProjectiles.CreateProjectile(
96 value,
97 position2,
98 s2 * (vector + m_random.Vector3(0.025f) + new Vector3(0f, 0.05f, 0f)),
100 null
101 );
102 projectile.Creator = this;
103 projectile.OwnerEntity = Entity;
105 "OnDispenserShoot",
106 loader => {
107 loader.OnDispenserShoot(this, ref projectile, ref canDispensePickable, ref removeSlotCount);
108 return false;
109 }
110 );
111 if (canFireProjectile) {
112 if (projectile != null) {
113 m_subsystemProjectiles.FireProjectileFast(projectile);
114 m_subsystemAudio.PlaySound("Audio/DispenserShoot", 1f, 0f, new Vector3(position.X, position.Y, position.Z), 4f, true);
115 return removeSlotCount;
116 }
117 return 0;
118 }
119 if (canDispensePickable) {
120 return DispenseItem(point, face, value, DispenserBlock.Mode.Dispense);
121 }
122 return 0;
123 }
124 }
125}
Engine.Vector3 Vector3
static void Error(object message)
定义 Log.cs:80
virtual bool CanBeFiredByDispenser(int value)
SubsystemPickables m_subsystemPickables
virtual int DispenseItem(Vector3 point, int face, int value, DispenserBlock.Mode mode)
ComponentBlockEntity m_componentBlockEntity
SubsystemProjectiles m_subsystemProjectiles
override void Load(ValuesDictionary valuesDictionary, IdToEntityMap idToEntityMap)
virtual int GetSlotCount(int slotIndex)
virtual int GetSlotValue(int slotIndex)
virtual int RemoveSlotItems(int slotIndex, int count)
实际移除的数量
static Mode GetMode(int data)
static int GetDirection(int data)
static int ExtractContents(int value)
static int ExtractData(int value)
ValuesDictionary ValuesDictionary
static void HookAction(string HookName, Func< ModLoader, bool > action)
执行Hook
static readonly Vector3 Zero
static Vector3 FaceToVector3(int face)