返回提交历史
Modified
content/blocks/磁涌扩展仓库.hjson
+2
-1
Modified
content/blocks/磁铜压缩仓库.hjson
+2
-1
Modified
mod.hjson
+1
-1
Added
scripts/blocks/核心共享仓库.js
+173
-0
Modified
scripts/main.js
+1
-0
XFEstudio/MCIndustry
修复部分闪退问题
aa1686e
代码差异
5 个文件
+179
-3
@@ -1,12 +1,13 @@
1
1
type: StorageBlock
2
2
name: 磁涌扩展仓库
3
description: 以磁涌合金稳定超高密度储存空间的后期仓库,每种物资均拥有独立储存空间。
3
description: 以磁涌合金稳定跨区域核心连接,在任意位置共享核心物品并大幅提高每种物品的存储上限。
4
4
5
5
size: 4
6
6
health: 4200
7
7
itemCapacity: 120000
8
8
separateItemCapacity: true
9
9
coreMerge: false
10
update: true
10
11
11
12
category: effect
12
13
requirements: [
@@ -1,12 +1,13 @@
1
1
type: StorageBlock
2
2
name: 磁铜压缩仓库
3
description: 利用磁铜约束场将不同物资分别压缩存放的大型仓库,每种物资均拥有独立储存空间。
3
description: 利用磁铜约束场远程连接本队核心,在任意位置共享核心物品并提高每种物品的存储上限。
4
4
5
5
size: 2
6
6
health: 1300
7
7
itemCapacity: 40000
8
8
separateItemCapacity: true
9
9
coreMerge: false
10
update: true
10
11
11
12
category: effect
12
13
requirements: [
@@ -2,6 +2,6 @@
2
2
name:磁铜工业
3
3
author:XFEstudio
4
4
"description":"[purple]磁铜工业,适合度过前期,以及为后期增加各类工厂工业制造模块,方便传输,增加新炮塔及工厂,全工业基于磁铜,持续测试中"
5
version:"2.55"
5
version:"2.60"
6
6
minGameVersion:136
7
7
}
@@ -0,0 +1,173 @@
1
// 远程仓库不能使用原版 StorageBlock 的 coreMerge:
2
// 原版只会把与核心直接相邻的仓库加入核心容量。
3
// 此脚本按队伍重新计算“核心 + 相邻原版仓库 + 全部远程仓库”的每种物品容量,
4
// 并让远程仓库直接引用核心的 ItemModule。
5
6
const remoteStorageBlocks = [];
7
let refreshingRemoteStorage = false;
8
let lastRefreshTick = -1;
9
10
function isRemoteStorage(build){
11
return build != null && (
12
build.block == remoteStorageBlocks[0] ||
13
build.block == remoteStorageBlocks[1]
14
);
15
}
16
17
function vanillaCoreCapacity(cores){
18
let capacity = 0;
19
20
for(let i = 0; i < cores.size; i++){
21
const core = cores.get(i);
22
capacity += core.block.itemCapacity;
23
24
for(let j = 0; j < core.proximity.size; j++){
25
const near = core.proximity.get(j);
26
if(near instanceof StorageBlock.StorageBuild &&
27
near.block.coreMerge &&
28
(near.linkedCore == core || near.linkedCore == null)){
29
capacity += near.block.itemCapacity;
30
}
31
}
32
}
33
34
return capacity;
35
}
36
37
function refreshRemoteStorage(excluded, force){
38
if(refreshingRemoteStorage || Vars.state == null || Vars.state.isMenu()){
39
return;
40
}
41
42
const tick = Math.floor(Time.time);
43
if(!force && tick == lastRefreshTick){
44
return;
45
}
46
47
refreshingRemoteStorage = true;
48
lastRefreshTick = tick;
49
50
try{
51
const extraByTeam = [];
52
const warehouses = [];
53
54
Groups.build.each(cons(build => {
55
if(build != excluded && isRemoteStorage(build)){
56
const teamId = build.team.id;
57
extraByTeam[teamId] =
58
(extraByTeam[teamId] == null ? 0 : extraByTeam[teamId]) +
59
build.block.itemCapacity;
60
warehouses.push(build);
61
}
62
}));
63
64
for(let teamId = 0; teamId < Team.all.length; teamId++){
65
const team = Team.all[teamId];
66
const cores = team.cores();
67
if(cores == null || cores.size == 0){
68
continue;
69
}
70
71
const totalCapacity = vanillaCoreCapacity(cores) +
72
(extraByTeam[team.id] == null ? 0 : extraByTeam[team.id]);
73
74
for(let i = 0; i < cores.size; i++){
75
cores.get(i).storageCapacity = totalCapacity;
76
}
77
78
// 与原版核心仓库容量下降时一致,移除扩展仓库后截断超出的物品。
79
const sharedItems = cores.get(0).items;
80
const allItems = Vars.content.items();
81
for(let i = 0; i < allItems.size; i++){
82
const item = allItems.get(i);
83
if(sharedItems.get(item) > totalCapacity){
84
sharedItems.set(item, totalCapacity);
85
}
86
}
87
}
88
89
for(let i = 0; i < warehouses.length; i++){
90
const warehouse = warehouses[i];
91
const core = warehouse.team.core();
92
if(core != null){
93
warehouse.linkedCore = core;
94
warehouse.items = core.items;
95
}else{
96
warehouse.linkedCore = null;
97
}
98
}
99
}finally{
100
refreshingRemoteStorage = false;
101
}
102
}
103
104
function installRemoteStorage(block){
105
block.update = true;
106
block.coreMerge = false;
107
108
block.buildType = prov(() => extend(
109
StorageBlock.StorageBuild,
110
block,
111
{
112
placed(){
113
this.super$placed();
114
refreshRemoteStorage(null, true);
115
},
116
117
onRemoved(){
118
this.super$onRemoved();
119
refreshRemoteStorage(this, true);
120
},
121
122
changeTeam(next){
123
if(this.team == next){
124
return;
125
}
126
this.super$changeTeam(next);
127
refreshRemoteStorage(null, true);
128
},
129
130
updateTile(){
131
// 每秒兜底同步一次,以覆盖核心重建、占领和其他仓库变化。
132
// Rhino 会优先把 Building.timer 解析为 Interval 字段,
133
// 因此必须直接调用 Interval.get,不能调用同名 Java 方法。
134
if(this.timer.get(0, 60)){
135
refreshRemoteStorage(null, false);
136
}
137
}
138
}
139
));
140
}
141
142
Events.on(ContentInitEvent, cons(() => {
143
remoteStorageBlocks.length = 0;
144
remoteStorageBlocks.push(
145
Vars.content.getByName(
146
ContentType.block,
147
modName + "-磁铜压缩仓库"
148
)
149
);
150
remoteStorageBlocks.push(
151
Vars.content.getByName(
152
ContentType.block,
153
modName + "-磁涌扩展仓库"
154
)
155
);
156
157
for(let i = 0; i < remoteStorageBlocks.length; i++){
158
const block = remoteStorageBlocks[i];
159
if(block == null){
160
Log.err("找不到远程核心仓库内容,索引:" + i);
161
continue;
162
}
163
installRemoteStorage(block);
164
}
165
}));
166
167
Events.on(WorldLoadEvent, cons(() => {
168
refreshRemoteStorage(null, true);
169
}));
170
171
Events.on(CoreChangeEvent, cons(() => {
172
refreshRemoteStorage(null, true);
173
}));
@@ -1,6 +1,7 @@
1
1
2
2
require("blocks/磁驱传输器");
3
3
require("blocks/磁铜传送带");
4
require("blocks/核心共享仓库");
4
5
require("units/辅助型UAV");
5
6
6
7
this.window = this;