From 901d594768727c40b73b6a15b1a1f58f204df9d2 Mon Sep 17 00:00:00 2001 From: Anuken Date: Mon, 23 Aug 2021 20:27:01 -0400 Subject: [PATCH] Prevent server sound ear destruction / Particle effect rand param --- core/src/mindustry/core/NetClient.java | 4 +-- .../entities/effect/ParticleEffect.java | 25 ++++++++++--- .../world/blocks/production/Fracker.java | 36 ------------------- .../world/blocks/production/SolidPump.java | 15 ++++++-- 4 files changed, 35 insertions(+), 45 deletions(-) diff --git a/core/src/mindustry/core/NetClient.java b/core/src/mindustry/core/NetClient.java index a73db1295d..38946a8331 100644 --- a/core/src/mindustry/core/NetClient.java +++ b/core/src/mindustry/core/NetClient.java @@ -164,14 +164,14 @@ public class NetClient implements ApplicationListener{ public static void sound(Sound sound, float volume, float pitch, float pan){ if(sound == null) return; - sound.play(volume * Core.settings.getInt("sfxvol") / 100f, pitch, pan); + sound.play(Mathf.clamp(volume, 0, 2f) * Core.settings.getInt("sfxvol") / 100f, pitch, pan); } @Remote(variants = Variant.both, unreliable = true) public static void soundAt(Sound sound, float x, float y, float volume, float pitch){ if(sound == null) return; - sound.at(x, y, pitch, volume); + sound.at(x, y, pitch, Mathf.clamp(volume, 0, 2f)); } @Remote(variants = Variant.both, unreliable = true) diff --git a/core/src/mindustry/entities/effect/ParticleEffect.java b/core/src/mindustry/entities/effect/ParticleEffect.java index 2b8fd4e52d..0efbaefcbf 100644 --- a/core/src/mindustry/entities/effect/ParticleEffect.java +++ b/core/src/mindustry/entities/effect/ParticleEffect.java @@ -4,14 +4,19 @@ import arc.*; import arc.graphics.*; import arc.graphics.g2d.*; import arc.math.*; +import arc.math.geom.*; import arc.util.*; import mindustry.entities.*; import mindustry.graphics.*; /** The most essential effect class. Can create particles in various shapes. */ public class ParticleEffect extends Effect{ + private static final Rand rand = new Rand(); + private static final Vec2 rv = new Vec2(); + public Color colorFrom = Color.white.cpy(), colorTo = Color.white.cpy(); public int particles = 6; + public boolean randLength = true; public float cone = 180f, length = 20f, baseLength = 0f; /** Particle size/length/radius interpolation. */ public Interp interp = Interp.linear; @@ -57,15 +62,25 @@ public class ParticleEffect extends Effect{ Lines.stroke(interp.apply(strokeFrom, strokeTo, rawfin)); float len = interp.apply(lenFrom, lenTo, rawfin); - Angles.randLenVectors(e.id, particles, length * fin + baseLength, e.rotation, cone, (x, y) -> { + rand.setSeed(e.id); + for(int i = 0; i < particles; i++){ + float l = length * fin + baseLength; + rv.trns(e.rotation + rand.range(cone), !randLength ? l : rand.random(l)); + float x = rv.x, y = rv.y; + Lines.lineAngle(ox + x, oy + y, Mathf.angle(x, y), len); - Drawf.light(ox + x, oy + y, len * lightScl, lightColor, lightOpacity* Draw.getColor().a); - }); + Drawf.light(ox + x, oy + y, len * lightScl, lightColor, lightOpacity * Draw.getColor().a); + } }else{ - Angles.randLenVectors(e.id, particles, length * fin + baseLength, e.rotation, cone, (x, y) -> { + rand.setSeed(e.id); + for(int i = 0; i < particles; i++){ + float l = length * fin + baseLength; + rv.trns(e.rotation + rand.range(cone), !randLength ? l : rand.random(l)); + float x = rv.x, y = rv.y; + Draw.rect(tex, ox + x, oy + y, rad, rad, e.rotation + offset + e.time * spin); Drawf.light(ox + x, oy + y, rad * lightScl, lightColor, lightOpacity * Draw.getColor().a); - }); + } } } } diff --git a/core/src/mindustry/world/blocks/production/Fracker.java b/core/src/mindustry/world/blocks/production/Fracker.java index 81c314b128..b174c50c28 100644 --- a/core/src/mindustry/world/blocks/production/Fracker.java +++ b/core/src/mindustry/world/blocks/production/Fracker.java @@ -1,19 +1,12 @@ package mindustry.world.blocks.production; -import arc.graphics.g2d.*; import arc.math.*; -import mindustry.annotations.Annotations.*; import mindustry.gen.*; -import mindustry.graphics.*; import mindustry.world.meta.*; public class Fracker extends SolidPump{ public float itemUseTime = 100f; - public @Load("@-liquid") TextureRegion liquidRegion; - public @Load("@-rotator") TextureRegion rotatorRegion; - public @Load("@-top") TextureRegion topRegion; - public Fracker(String name){ super(name); hasItems = true; @@ -30,33 +23,9 @@ public class Fracker extends SolidPump{ stats.add(Stat.productionTime, itemUseTime / 60f, StatUnit.seconds); } - @Override - public boolean outputsItems(){ - return false; - } - - @Override - public TextureRegion[] icons(){ - return new TextureRegion[]{region, rotatorRegion, topRegion}; - } - public class FrackerBuild extends SolidPumpBuild{ public float accumulator; - @Override - public void drawCracks(){} - - @Override - public void draw(){ - Draw.rect(region, x, y); - super.drawCracks(); - - Drawf.liquid(liquidRegion, x, y, liquids.get(result) / liquidCapacity, result.color); - - Drawf.spinSprite(rotatorRegion, x, y, pumpTime); - Draw.rect(topRegion, x, y); - } - @Override public void updateTile(){ if(consValid()){ @@ -73,10 +42,5 @@ public class Fracker extends SolidPump{ dumpLiquid(result); } } - - @Override - public float typeLiquid(){ - return liquids.get(result); - } } } diff --git a/core/src/mindustry/world/blocks/production/SolidPump.java b/core/src/mindustry/world/blocks/production/SolidPump.java index 2459b44b64..277621162f 100644 --- a/core/src/mindustry/world/blocks/production/SolidPump.java +++ b/core/src/mindustry/world/blocks/production/SolidPump.java @@ -68,6 +68,11 @@ public class SolidPump extends Pump{ return sum > 0.00001f; } + @Override + public boolean outputsItems(){ + return false; + } + @Override protected boolean canPump(Tile tile){ return tile != null && !tile.floor().isLiquid; @@ -85,10 +90,16 @@ public class SolidPump extends Pump{ public float validTiles; public float lastPump; + + @Override + public void drawCracks(){} + @Override public void draw(){ Draw.rect(region, x, y); - Drawf.liquid(liquidRegion, x, y, liquids.total() / liquidCapacity, liquids.current().color); + super.drawCracks(); + + Drawf.liquid(liquidRegion, x, y, liquids.get(result) / liquidCapacity, result.color); Drawf.spinSprite(rotatorRegion, x, y, pumpTime * rotateSpeed); Draw.rect(topRegion, x, y); } @@ -133,7 +144,7 @@ public class SolidPump extends Pump{ } public float typeLiquid(){ - return liquids.total(); + return liquids.get(result); } } }