@@ -2,21 +2,21 @@ var ItemTransportingHelper = {
22 PipeTiles : {
33 // connection types are registred with render connections
44 } ,
5-
5+
66 PipeParams : {
77 // params like friction are stored here
88 } ,
9-
9+
1010 TransportingDenied : {
1111 // TODO: add all blocks
1212 } ,
13-
13+
1414 BasicItemContainers : {
1515 54 : true ,
1616 61 : true ,
1717 62 : true
1818 } ,
19-
19+
2020 registerItemPipe : function ( pipe , type , params ) {
2121 this . PipeTiles [ pipe ] = type ;
2222 if ( ! params ) {
@@ -27,32 +27,32 @@ var ItemTransportingHelper = {
2727 }
2828 this . PipeParams [ pipe ] = params ;
2929 } ,
30-
30+
3131 isPipe : function ( block ) {
3232 return this . PipeTiles [ block ] ;
3333 } ,
34-
34+
3535 canPipesConnect : function ( pipe1 , pipe2 ) {
3636 var type1 = this . PipeTiles [ pipe1 ] || ITEM_PIPE_CONNECTION_ANY ;
3737 var type2 = this . PipeTiles [ pipe2 ] || ITEM_PIPE_CONNECTION_ANY ;
38- return ( type1 == type2 && type1 != ITEM_PIPE_CONNECTION_WOOD )
38+ return ( type1 == type2 && type1 != ITEM_PIPE_CONNECTION_WOOD )
3939 || ( type1 == ITEM_PIPE_CONNECTION_ANY || type2 == ITEM_PIPE_CONNECTION_ANY )
4040 || ( type1 == ITEM_PIPE_CONNECTION_STONE && type2 != ITEM_PIPE_CONNECTION_COBBLE )
4141 || ( type2 == ITEM_PIPE_CONNECTION_STONE && type1 != ITEM_PIPE_CONNECTION_COBBLE )
4242 || ( type1 == ITEM_PIPE_CONNECTION_COBBLE && type2 != ITEM_PIPE_CONNECTION_STONE )
4343 || ( type2 == ITEM_PIPE_CONNECTION_COBBLE && type1 != ITEM_PIPE_CONNECTION_STONE ) ;
4444 } ,
45-
45+
4646 canTransportTo : function ( pipe , x , y , z ) {
4747 var block = World . getBlock ( x , y , z ) . id ;
4848 if ( this . BasicItemContainers [ block ] )
49- return true ;
49+ return true ;
5050 if ( block > 4096 && ! this . TransportingDenied [ block ] ) {
5151 return ( ! this . isPipe ( block ) && TileEntity . isTileEntityBlock ( block ) ) || this . canPipesConnect ( block , pipe ) ;
5252 }
5353 return false ;
5454 } ,
55-
55+
5656 findNearbyContainers : function ( position ) {
5757 var directions = [
5858 { x : - 1 , y : 0 , z : 0 } ,
@@ -75,7 +75,7 @@ var ItemTransportingHelper = {
7575 }
7676 return possibleDirs ;
7777 } ,
78-
78+
7979 findBasicDirections : function ( pipe , position , direction , checkBackwardDirection ) {
8080 var directions = [
8181 { x : - 1 , y : 0 , z : 0 } ,
@@ -97,7 +97,7 @@ var ItemTransportingHelper = {
9797 }
9898 return possibleDirs ;
9999 } ,
100-
100+
101101 filterDirections : function ( listOfDirs , itemDirection ) {
102102 var resultDirs = [ ] ;
103103 for ( var i in listOfDirs ) {
@@ -108,14 +108,14 @@ var ItemTransportingHelper = {
108108 }
109109 return resultDirs ;
110110 } ,
111-
111+
112112 getPathData : function ( transportedItem , item , position , direction ) {
113113 position = {
114114 x : Math . floor ( position . x ) ,
115115 y : Math . floor ( position . y ) ,
116116 z : Math . floor ( position . z ) ,
117117 } ;
118-
118+
119119 // cache block start
120120 var cachedData = TransportingCache . getInfo ( position . x , position . y , position . z ) ;
121121 if ( ! cachedData ) {
@@ -140,7 +140,7 @@ var ItemTransportingHelper = {
140140 TransportingCache . registerInfo ( position . x , position . y , position . z , cachedData ) ;
141141 }
142142 // cache block end
143-
143+
144144 var resultDirs = this . filterDirections ( cachedData . possibleDirs , direction ) ;
145145 var acceleration = 0 ;
146146 if ( cachedData . tileEntity ) {
@@ -151,7 +151,7 @@ var ItemTransportingHelper = {
151151 acceleration = cachedData . tileEntity . getItemAcceleration ( transportedItem , cachedData . possibleDirs , item , direction , resultDirs ) ;
152152 }
153153 }
154-
154+
155155 return {
156156 inPipe : cachedData . inPipe ,
157157 directions : resultDirs ,
@@ -177,28 +177,28 @@ var TransportingItem = new GameObject("bcTransportingItem", {
177177 count : 0 ,
178178 data : 0
179179 } ;
180-
180+
181181 this . inPipeFlag = false ;
182-
182+
183183 this . animation = null ;
184-
184+
185185 /* setup pathfinding */
186186 this . target = null ;
187187 this . velocity = .05 ;
188188 this . acceleration = .0 ;
189189 this . friction = .0 ;
190190 this . direction = {
191- x : 0 ,
192- y : 0 ,
191+ x : 0 ,
192+ y : 0 ,
193193 z : 0
194194 } ;
195-
195+
196196 } ,
197-
197+
198198 loaded : function ( ) {
199199 this . reloadAnimation ( ) ;
200200 } ,
201-
201+
202202 update : function ( ) {
203203 if ( this . move ( ) ) {
204204 this . pathfind ( ) ;
@@ -208,52 +208,49 @@ var TransportingItem = new GameObject("bcTransportingItem", {
208208 }
209209 this . moveAnimation ( ) ;
210210 } ,
211-
211+
212212 destroySelf : function ( ) {
213213 if ( this . animation ) {
214214 this . animation . destroy ( ) ;
215215 }
216216 this . destroy ( ) ;
217217 } ,
218-
219218
220-
221-
222219 /* basics */
223-
220+
224221 setPosition : function ( x , y , z ) {
225222 this . pos = {
226223 x : x ,
227224 y : y ,
228225 z : z
229226 } ;
230227 } ,
231-
228+
232229 setItem : function ( id , count , data ) {
233230 this . item = {
234231 id : id ,
235- count : count ,
232+ count : count ,
236233 data : data
237234 } ;
238- if ( id > 0 ) {
235+ if ( id != 0 ) {
239236 this . reloadAnimation ( ) ;
240237 }
241238 } ,
242-
239+
243240 setItemSource : function ( item ) {
244241 this . item = item || { id : 0 , count : 0 , data : 0 } ;
245242 this . reloadAnimation ( ) ;
246243 } ,
247-
244+
248245 drop : function ( ) {
249246 this . destroySelf ( ) ;
250- if ( this . item && this . item . id > 0 && this . item . count > 0 ) {
247+ if ( this . item && this . item . id != 0 && this . item . count > 0 ) {
251248 var item = World . drop ( this . pos . x , this . pos . y , this . pos . z , this . item . id , this . item . count , this . item . data ) ;
252249 Entity . setVelocity ( item , this . direction . x * this . velocity * 1.5 , this . direction . y * this . velocity * 1.5 , this . direction . z * this . velocity * 1.5 )
253250 }
254251 this . setItem ( 0 , 0 , 0 ) ;
255252 } ,
256-
253+
257254 validate : function ( ) {
258255 if ( ! this . item || this . item . count <= 0 ) {
259256 this . destroySelf ( ) ;
@@ -272,17 +269,16 @@ var TransportingItem = new GameObject("bcTransportingItem", {
272269 z : this . pos . z - delta . z ,
273270 } ;
274271 } ,
275-
276-
272+
277273 /* animation */
278-
274+
279275 reloadAnimation : function ( ) {
280-
276+
281277 if ( this . animation ) {
282278 this . animation . destroy ( ) ;
283279 }
284280 this . animation = new Animation . Item ( this . pos . x , this . pos . y , this . pos . z ) ;
285-
281+
286282 var modelCount = 1 ;
287283 if ( this . item . count > 1 ) {
288284 modelCount = 2 ;
@@ -293,7 +289,7 @@ var TransportingItem = new GameObject("bcTransportingItem", {
293289 if ( this . item . count > 56 ) {
294290 modelCount = 4 ;
295291 }
296-
292+
297293 this . animation . describeItem ( {
298294 id : this . item . id ,
299295 count : modelCount ,
@@ -303,22 +299,21 @@ var TransportingItem = new GameObject("bcTransportingItem", {
303299 } ) ;
304300 this . animation . load ( ) ;
305301 } ,
306-
302+
307303 moveAnimation : function ( ) {
308304 this . animation . setPos ( this . pos . x , this . pos . y , this . pos . z ) ;
309305 } ,
310-
311-
306+
312307 /* pathfinding */
313-
308+
314309 setTarget : function ( x , y , z ) {
315310 this . target = {
316311 x : Math . floor ( x ) + .5 || 0 ,
317312 y : Math . floor ( y ) + .5 || 0 ,
318313 z : Math . floor ( z ) + .5 || 0 ,
319314 } ;
320315 } ,
321-
316+
322317 move : function ( ) {
323318 this . velocity = Math . min ( .5 , Math . max ( .02 , this . velocity + this . acceleration - this . friction || 0 ) ) ;
324319 if ( this . target && this . velocity ) {
@@ -341,27 +336,27 @@ var TransportingItem = new GameObject("bcTransportingItem", {
341336 }
342337 return true ;
343338 } ,
344-
345-
339+
340+
346341 addItemToContainer : function ( container ) {
347342 if ( this . item . count <= 0 ) {
348343 return ;
349344 }
350-
345+
351346 // Native TileEntity
352347 if ( container . getType && container . getSize ) {
353348 let size = container . getSize ( ) ;
354349 for ( var i = 0 ; i < size ; i ++ ) {
355350 var slot = container . getSlot ( i ) ;
356351 if ( slot . id == 0 || slot . id == this . item . id && slot . data == this . item . data ) {
357- var maxstack = slot . id > 0 ? Item . getMaxStack ( slot . id ) : 64 ;
352+ var maxstack = slot . id != 0 ? Item . getMaxStack ( slot . id ) : 64 ;
358353 var add = Math . min ( maxstack - slot . count , this . item . count ) ;
359354 this . item . count -= add ;
360355 container . setSlot ( i , this . item . id , slot . count + add , this . item . data ) ;
361356 }
362357 }
363358 }
364-
359+
365360 // TileEntity
366361 else {
367362 var tileEntity = container . tileEntity ;
@@ -385,33 +380,33 @@ var TransportingItem = new GameObject("bcTransportingItem", {
385380 for ( var i in slots ) {
386381 var slot = container . getSlot ( slots [ i ] ) ;
387382 if ( slot . id == 0 || slot . id == this . item . id && slot . data == this . item . data ) {
388- var maxstack = slot . id > 0 ? Item . getMaxStack ( slot . id ) : 64 ;
383+ var maxstack = slot . id != 0 ? Item . getMaxStack ( slot . id ) : 64 ;
389384 var add = Math . min ( maxstack - slot . count , this . item . count ) ;
390385 this . item . count -= add ;
391386 slot . count += add ;
392387 slot . id = this . item . id ;
393388 slot . data = this . item . data ;
394389 }
395390 }
396-
391+
397392 container . validateAll ( ) ;
398393 }
399394 } ,
400-
395+
401396 pathfind : function ( ) {
402397 if ( this . dropFlag ) {
403398 this . drop ( ) ;
404399 return ;
405400 }
406-
401+
407402 var pathdata = ItemTransportingHelper . getPathData ( this , this . item , this . pos , this . direction ) ;
408403 var directions = pathdata . directions ;
409404 var dir = directions [ parseInt ( directions . length * Math . random ( ) ) ] ;
410-
405+
411406 this . acceleration = pathdata . acceleration ;
412407 this . friction = pathdata . friction ;
413-
414- if ( pathdata . inPipe ) {
408+
409+ if ( pathdata . inPipe ) {
415410 if ( ! dir ) {
416411 dir = this . direction ;
417412 this . dropFlag = true ;
@@ -433,7 +428,7 @@ var TransportingItem = new GameObject("bcTransportingItem", {
433428 this . drop ( ) ;
434429 }
435430 }
436-
431+
437432 if ( dir ) {
438433 this . target = {
439434 x : Math . floor ( this . pos . x ) + .5 + dir . x ,
0 commit comments