diff --git a/src/main/java/carpet/script/utils/ShapeDispatcher.java b/src/main/java/carpet/script/utils/ShapeDispatcher.java index 00e51f5f..f3064c4a 100644 --- a/src/main/java/carpet/script/utils/ShapeDispatcher.java +++ b/src/main/java/carpet/script/utils/ShapeDispatcher.java @@ -546,14 +546,13 @@ public class ShapeDispatcher super.init(options); from = vecFromValue(options.get("from")); to = vecFromValue(options.get("to")); - if (from.equals(to)) throw new InternalExpressionException("Box dimensions are invalid - cannot draw a zero-size boxes"); } @Override public Consumer alternative() { ParticleEffect particle = replacementParticle(); - double density = Math.max(2.0, from.distanceTo(to) /50) / (a+0.1); + double density = Math.max(2.0, from.distanceTo(to) /50/ (a+0.1)) ; return p -> { if (p.dimension == shapeDimension) @@ -629,7 +628,6 @@ public class ShapeDispatcher super.init(options); from = vecFromValue(options.get("from")); to = vecFromValue(options.get("to")); - if (from.equals(to)) throw new InternalExpressionException("Line dimensions are invalid - cannot draw a zero-length lines"); } @Override @@ -1276,13 +1274,33 @@ public class ShapeDispatcher public static int drawParticleLine(List players, ParticleEffect particle, Vec3d from, Vec3d to, double density) { - if (isStraight(from, to, density)) return drawOptimizedParticleLine(players, particle, from, to, density); - double lineLengthSq = from.squaredDistanceTo(to); - if (lineLengthSq == 0) return 0; - Vec3d incvec = to.subtract(from).multiply(2*density/MathHelper.sqrt(lineLengthSq)); + double distance = from.squaredDistanceTo(to); + if (distance == 0) return 0; int pcount = 0; + if (distance < 100) + { + Random rand = players.get(0).getServerWorld().random; + int particles = (int)(distance/density)+1; + Vec3d towards = to.subtract(from); + for (int i = 0; i < particles; i++) + { + Vec3d at = from.add(towards.multiply( rand.nextDouble())); + for (ServerPlayerEntity player : players) + { + player.getServerWorld().spawnParticles(player, particle, true, + at.x, at.y, at.z, 1, + 0.0, 0.0, 0.0, 0.0); + pcount ++; + } + } + return pcount; + } + + if (isStraight(from, to, density)) return drawOptimizedParticleLine(players, particle, from, to, density); + Vec3d incvec = to.subtract(from).multiply(2*density/MathHelper.sqrt(distance)); + for (Vec3d delta = new Vec3d(0.0,0.0,0.0); - delta.lengthSquared() if (!global_running, return()); show_activity = (p~'holds':0 == 'redstone_torch'); yval = setup:'plot_center':1+16; + base_update = global_update_interval; + random_component = ceil(0.4*base_update); + duration_max = ceil(1.5*base_update); in_dimension( setup:'plot_dimension', l(sx, sy, sz) = setup:'source_center'; l(px, py, pz) = setup:'plot_center'; @@ -160,10 +164,10 @@ __chunk_visualizer_tick(p) -> l(cached_status, expiry) = global_status_cache:source_pos; changed = (status != cached_status); if ( changed || (expiry < now), - global_status_cache:source_pos = l(status, now+100+floor(rand(40))); + global_status_cache:source_pos = l(status, now+base_update+floor(rand(random_component))); bpos = l(dx/2, yval, dz/2); bcol = global_chunk_colors:status:((dx+dz)%2); - shapes += l('box', 150, 'from', bpos, 'to', bpos + l(0.5,0,0.5), + shapes += l('box', duration_max, 'from', bpos, 'to', bpos + l(0.5,0,0.5), 'color', 0xffffff00, 'fill', bcol+128, 'follow', p, 'snap', 'xz'); if (changed, pbcol = global_chunk_colors:cached_status:((dx+dz)%2);