@@ -33,65 +33,72 @@ export type LiquidContainer = {
3333 customData ?: null | CustomData ;
3434} ;
3535
36- export const decode = ( reader : BinaryReader ) : LiquidContainer => {
37- const result : LiquidContainer = {
38- canAddTo : reader . boolean ( ) ,
39- canRemoveFrom : reader . boolean ( ) ,
40- contentLevel : reader . int ( ) ,
41- hasContent : reader . boolean ( ) ,
42- isCustom : reader . boolean ( ) ,
43- presetHash : reader . uInt ( )
44- } ;
45-
46- /* Get custom data */
47- const isNull = reader . boolean ( ) ;
48- if ( isNull ) {
49- result . customData = null ;
50- } else {
51- const customData = {
52- color : {
53- r : reader . float ( ) ,
54- g : reader . float ( ) ,
55- b : reader . float ( ) ,
56- a : reader . float ( )
57- } ,
58- isConsumableThroughSkin : reader . boolean ( ) ,
59- visualDataHash : reader . uInt ( )
60- } ;
61-
62- /* Get the effects array. */
63- const effectsLength = reader . uInt ( ) ;
64- const effects : Effect [ ] = [ ] ;
65- for ( let index = 0 ; index < effectsLength ; ++ index ) {
66- /* Skip effect if is null. */
67- const isNull = reader . boolean ( ) ;
68- if ( isNull ) {
69- effects . push ( null ) ;
70- continue ;
36+ export const decode = ( reader : BinaryReader , version : number ) : LiquidContainer => {
37+ const component : LiquidContainer = { } ;
38+
39+ if ( version >= 1 ) component . canAddTo = reader . boolean ( ) ;
40+
41+ if ( version >= 1 ) component . canRemoveFrom = reader . boolean ( ) ;
42+
43+ if ( version >= 1 ) component . contentLevel = reader . int ( ) ;
44+
45+ if ( version >= 1 ) component . hasContent = reader . boolean ( ) ;
46+
47+ if ( version >= 1 ) component . isCustom = reader . boolean ( ) ;
48+
49+ if ( version >= 1 ) component . presetHash = reader . uInt ( ) ;
50+
51+ if ( version >= 1 ) {
52+ /* Get custom data */
53+ const isNull = reader . boolean ( ) ;
54+ if ( isNull ) {
55+ component . customData = null ;
56+ } else {
57+ const customData = {
58+ color : {
59+ r : reader . float ( ) ,
60+ g : reader . float ( ) ,
61+ b : reader . float ( ) ,
62+ a : reader . float ( )
63+ } ,
64+ isConsumableThroughSkin : reader . boolean ( ) ,
65+ visualDataHash : reader . uInt ( )
66+ } ;
67+
68+ /* Get the effects array. */
69+ const effectsLength = reader . uInt ( ) ;
70+ const effects : Effect [ ] = [ ] ;
71+ for ( let index = 0 ; index < effectsLength ; ++ index ) {
72+ /* Skip effect if is null. */
73+ const isNull = reader . boolean ( ) ;
74+ if ( isNull ) {
75+ effects . push ( null ) ;
76+ continue ;
77+ }
78+
79+ effects . push ( {
80+ hash : reader . uInt ( ) ,
81+ strengthMultiplier : reader . float ( )
82+ } ) ;
7183 }
7284
73- effects . push ( {
74- hash : reader . uInt ( ) ,
75- strengthMultiplier : reader . float ( )
76- } ) ;
77- }
85+ /* Get the food chunks array. */
86+ const foodChunksLength = reader . uInt ( ) ;
87+ const foodChunks : FoodChunk [ ] = [ ] ;
88+ for ( let index = 0 ; index < foodChunksLength ; ++ index ) {
89+ foodChunks . push ( reader . uInt ( ) ) ;
90+ }
7891
79- /* Get the food chunks array. */
80- const foodChunksLength = reader . uInt ( ) ;
81- const foodChunks : FoodChunk [ ] = [ ] ;
82- for ( let index = 0 ; index < foodChunksLength ; ++ index ) {
83- foodChunks . push ( reader . uInt ( ) ) ;
92+ /* Append custom data to result. */
93+ component . customData = {
94+ ...customData ,
95+ effects,
96+ foodChunks
97+ } ;
8498 }
85-
86- /* Append custom data to result. */
87- result . customData = {
88- ...customData ,
89- effects,
90- foodChunks
91- } ;
9299 }
93100
94- return result ;
101+ return component ;
95102} ;
96103
97104export const encode = ( {
0 commit comments