Skip to content

Commit 47e8a67

Browse files
Merge pull request #13 from mineprogramming/world-load-pipe-drop-fix
World load pipe drop fix
2 parents ca1df1b + 3ff543e commit 47e8a67

File tree

3 files changed

+24
-8
lines changed

3 files changed

+24
-8
lines changed

make.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"info": {
44
"name": "BuildCraft PE",
55
"author": "Nikolay Savenko",
6-
"version": "1.0.1",
6+
"version": "1.0.3",
77
"description": "Port of PC version of BuildCraft"
88
},
99
"api": "CoreEngine"

src/dev/core/pipe/item/travelingItem/TravelingItem.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,11 @@ class TravelingItem {
115115
this.destroy(true);
116116
return;
117117
}
118-
118+
const tileEntity = World.getTileEntity(x, y, z, this.blockSource);
119+
if (tileEntity?.__initialized === false) {
120+
this.cooldown = ITEM_COOLDOWN_TIME;
121+
return;
122+
}
119123

120124
if (this.modifyByPipe()) {
121125
this.destroy();
@@ -132,8 +136,11 @@ class TravelingItem {
132136
}
133137

134138
this.networkEntity.getClients().setupDistancePolicy(x, y, z, this.blockSource.getDimension(), 32);
135-
if (this.itemMover.findNewMoveVector(this.blockSource)) {
139+
const findResult = this.itemMover.findNewMoveVector(this.blockSource);
140+
if (findResult > 0) {
136141
this.updateMoveData();
142+
} else if (findResult < 0) {
143+
this.cooldown = ITEM_COOLDOWN_TIME;
137144
} else {
138145
this.destroy(true);
139146
return;

src/dev/core/pipe/item/travelingItem/TravelingItemMover.ts

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,11 @@ class TravelingItemMover {
9797
this.coords = this.coordsToFixed(newCoords);
9898
}
9999

100-
public findNewMoveVector(region: BlockSource): boolean {
100+
public findNewMoveVector(region: BlockSource): number {
101101
var relativePaths = this.getRelativePaths(region);
102+
if (relativePaths === null) {
103+
return -1;
104+
}
102105
const nextPipes = this.filterPaths(relativePaths, region);
103106
const keys = Object.keys(nextPipes);
104107

@@ -110,10 +113,10 @@ class TravelingItemMover {
110113
this.prevCoords = this.Coords;
111114
this.updateMoveSpeed(region);
112115
this.updateCoordsTime();
113-
return true;
116+
return 1;
114117
}
115118

116-
return false;
119+
return 0;
117120
}
118121

119122
/**
@@ -150,9 +153,9 @@ class TravelingItemMover {
150153
}
151154

152155
/**
153-
* @returns {object} which looks like {"sideIndex": pipeClass | container}
156+
* @returns {object} which looks like {"sideIndex": pipeClass | container} or null if chunk unloaded
154157
*/
155-
private getRelativePaths(region: BlockSource): object {
158+
private getRelativePaths(region: BlockSource): object | null {
156159
const targets = {};
157160
for (let i = 0; i < 6; i++) {
158161
const backVectorIndex = World.getInverseBlockSide(this.moveVectorIndex);
@@ -161,6 +164,9 @@ class TravelingItemMover {
161164
const curY = this.AbsoluteCoords.y;
162165
const curZ = this.AbsoluteCoords.z;
163166
const { x, y, z } = World.getRelativeCoords(curX, curY, curZ, i);
167+
168+
if (!region.isChunkLoadedAt(x, z)) return null;
169+
164170
const pipeBlockID = region.getBlockId(x, y, z);
165171
const pipeBlockData = region.getBlockData(x, y, z);
166172
const relativePipeClass = PipeIdMap.getClassById(pipeBlockID);
@@ -170,6 +176,9 @@ class TravelingItemMover {
170176
continue;
171177
}
172178

179+
let tile = TileEntity.getTileEntity(x, y, z, region);
180+
if (tile?.__initialized === false) return null;
181+
173182
const storage = StorageInterface.getStorage(region, x, y, z);
174183
if (this.isValidStorage(storage, World.getInverseBlockSide(i)) && !currentConnector?.hasBlacklistBlockID(pipeBlockID, pipeBlockData)) {
175184
targets[i] = storage;

0 commit comments

Comments
 (0)