@@ -106,11 +106,6 @@ public Light(UUID uuid, String name, Location location, LightType type, LightCha
106106 timeToFade --;
107107 length -= 100.0 / this .data .getTimeToFadeToBlack ();
108108 }
109- if (length < 0.1 ) {
110- off (new Color (0x000000 ));
111- timeToFade = 0 ;
112- length = 0.1 ;
113- }
114109 if (length > 100 ) {
115110 length = 100.0 ;
116111 }
@@ -119,34 +114,39 @@ public Light(UUID uuid, String name, Location location, LightType type, LightCha
119114 // do nothing if no movement or zooming needs to be happening
120115 return ;
121116 }
122- x = (x + multipliedSpeed ) % 100 ;
123- x2 = (x2 + secondaryMultipliedSpeed ) % 100 ;
124- lastLength = length ;
125- // do chroma gradient
126117 if (currentGradient != null && length > 0.1 ) {
127118 long gradientEndMillis = startTime + currentGradient .getEndTime ();
128119 long gradientStartMillis = startTime + currentGradient .getStartTime ();
129120 if (System .currentTimeMillis () < gradientEndMillis && System .currentTimeMillis () > gradientStartMillis ) {
130121 long fraction = System .currentTimeMillis () / gradientEndMillis ;
131122 color = currentGradient .getLerpType ().lerp (
132- currentGradient .getLerpType (),
133123 currentGradient .getStartColor (),
134124 currentGradient .getEndColor (),
135125 fraction ,
136126 currentGradient .getEasing ());
137127 marker .setColor (color );
138- marker .setDuration (DELAY +10 );
128+ marker .setDuration (DELAY +20 );
139129 marker .start (256 );
140130 }
141131 if (System .currentTimeMillis () > gradientEndMillis ) {
142132 currentGradient = null ;
143133 }
144134 }
135+ x = (x + multipliedSpeed ) % 100 ;
136+ x2 = (x2 + secondaryMultipliedSpeed ) % 100 ;
137+ // do chroma gradient
138+ if (length < 0.1 ) {
139+ off (new Color (0x000000 ));
140+ timeToFade = 0 ;
141+ length = 0.1 ;
142+ }
143+ lastLength = length ;
144+ double l = (length + this .data .getOnLength () * (color .getAlpha () / 255.0 ))/2 ;
145145
146146 // a (invisible) "ray", pointing towards the set pitch and yaw, length is set later
147147 Vector3D v = new Vector3D (Math .toRadians (this .location .getYaw ()), Math .toRadians (this .location .getPitch ())).normalize ();
148148 // make v the size of length
149- Vector3D v1 = v .scalarMultiply (getMaxLengthPercent ());
149+ Vector3D v1 = v .scalarMultiply (getMaxLengthPercent (l ));
150150 for (int i = 0 ; i < lasers .size (); i ++) {
151151 LaserWrapper laser = lasers .get (i );
152152 /*
@@ -161,9 +161,9 @@ x value that is separated evenly for each laser. This pattern is then moved (as
161161 Rotation r = new Rotation (v1 , this .data .getPatternData ().getRotation (), RotationConvention .FRAME_TRANSFORM );
162162 Rotation r2 = new Rotation (v1 , this .data .getSecondPatternData ().getRotation (), RotationConvention .FRAME_TRANSFORM );
163163 // apply first pattern (separated evenly for each laser) to our ray
164- Vector3D v2 = this .data .getPatternData ().getPattern ().apply (v1 , separated , r , this .data .getPatternData ().getPatternSizeMultiplier () * (length / 100 ));
164+ Vector3D v2 = this .data .getPatternData ().getPattern ().apply (v1 , separated , r , this .data .getPatternData ().getPatternSizeMultiplier () * (l / 100 ));
165165 // then apply second pattern to all lasers with the same x value
166- Vector3D v3 = this .data .getSecondPatternData ().getPattern ().apply (v1 , x2 , r2 , this .data .getSecondPatternData ().getPatternSizeMultiplier () * (length / 100 ));
166+ Vector3D v3 = this .data .getSecondPatternData ().getPattern ().apply (v1 , x2 , r2 , this .data .getSecondPatternData ().getPatternSizeMultiplier () * (l / 100 ));
167167 Vector3D v4 = getData ().getRingMovementData ().calculateMovement (zoomTime );
168168 Vector3D v5 = v1 .add (v4 ).add (v3 ).add (v2 );
169169
@@ -226,6 +226,7 @@ public void start() {
226226 */
227227 public void stop () {
228228 executorService .shutdownNow ();
229+ currentGradient = null ;
229230 }
230231
231232 /**
@@ -276,12 +277,14 @@ public void on(Color color, @Nullable JsonArray lightIDs, int duration, @Nullabl
276277 length = Math .max (data .getOnLength () * (color .getAlpha () / 255.0 ), 0.05 );
277278 isOn = true ;
278279 timeToFade = 0 ;
279- this .color = color ;
280280 this .duration = duration + 10 ;
281- marker .setLocation (loc );
282- marker .setColor (this .color );
283- marker .setDuration (this .duration );
284- marker .start (256 );
281+ if (currentGradient == null ) {
282+ this .color = color ;
283+ marker .setLocation (loc );
284+ marker .setColor (this .color );
285+ marker .setDuration (this .duration );
286+ marker .start (256 );
287+ }
285288 }
286289
287290 public void on (Color color ) {
@@ -327,12 +330,14 @@ public void flash(Color color, @Nullable JsonArray lightIDs, int duration, @Null
327330 length += (100 - data .getOnLength ()) / 3 ;
328331 timeToFade += 3 ;
329332 lasers .forEach (LaserWrapper ::changeColor );
330- this .color = color ;
331333 this .duration = duration + 10 ;
332- marker .setDuration (this .duration );
333- marker .setLocation (loc );
334- marker .setColor (this .color );
335- marker .start (256 );
334+ if (currentGradient == null ) {
335+ this .color = color ;
336+ marker .setLocation (loc );
337+ marker .setColor (this .color );
338+ marker .setDuration (this .duration );
339+ marker .start (256 );
340+ }
336341 } else {
337342 flashOff (color );
338343 }
@@ -356,12 +361,14 @@ public void flashOff(Color color, @Nullable JsonArray lightIDs, int duration, @N
356361 }
357362 on (color );
358363 flash (color );
359- this .color = color ;
360364 this .duration = duration + 10 ;
361- marker .setLocation (loc );
362- marker .setDuration (this .duration );
363- marker .setColor (this .color );
364- marker .start (256 );
365+ if (currentGradient == null ) {
366+ this .color = color ;
367+ marker .setLocation (loc );
368+ marker .setColor (this .color );
369+ marker .setDuration (this .duration );
370+ marker .start (256 );
371+ }
365372 timeToFade = data .getTimeToFadeToBlack ();
366373 }
367374
@@ -439,7 +446,7 @@ public void setSpeed(double multiplier) {
439446 run .run ();
440447 }
441448
442- private double getMaxLengthPercent () {
449+ private double getMaxLengthPercent (double length ) {
443450 return data .getMaxLength () * length / 100.0 ;
444451 }
445452
0 commit comments