mirror of
https://github.com/exituser/Brewery.git
synced 2026-09-17 07:49:03 +00:00
Minimal Particles config option & optimizations
This commit is contained in:
@@ -101,9 +101,9 @@ public class BCauldron {
|
||||
if (state > 0) {
|
||||
state--;
|
||||
}
|
||||
if (BConfig.enableCauldronParticles) {
|
||||
if (BConfig.enableCauldronParticles && !BConfig.minimalParticles) {
|
||||
// Few little sparks and lots of water splashes. Offset by 0.2 in x and z
|
||||
block.getWorld().spawnParticle(Particle.SPELL_INSTANT, particleLocation,3, 0.2, 0, 0.2);
|
||||
block.getWorld().spawnParticle(Particle.SPELL_INSTANT, particleLocation,2, 0.2, 0, 0.2);
|
||||
block.getWorld().spawnParticle(Particle.WATER_SPLASH, particleLocation, 10, 0.2, 0, 0.2);
|
||||
}
|
||||
}
|
||||
@@ -238,6 +238,20 @@ public class BCauldron {
|
||||
|
||||
public void cookEffect() {
|
||||
if (BUtil.isChunkLoaded(block) && LegacyUtil.isCauldronHeatsource(block.getRelative(BlockFace.DOWN))) {
|
||||
Color color = getParticleColor();
|
||||
// Colorable spirally spell, 0 count enables color instead of the offset variables
|
||||
// Configurable RGB color. The last parameter seems to control the hue and motion, but i couldn't find
|
||||
// how exactly in the client code. 1025 seems to be the best for color brightness and upwards motion
|
||||
block.getWorld().spawnParticle(Particle.SPELL_MOB, getRandParticleLoc(), 0,
|
||||
((double) color.getRed()) / 255.0,
|
||||
((double) color.getGreen()) / 255.0,
|
||||
((double) color.getBlue()) / 255.0,
|
||||
1025.0);
|
||||
|
||||
if (BConfig.minimalParticles) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (particleRandom.nextFloat() > 0.85) {
|
||||
// Dark pixely smoke cloud at 0.4 random in x and z
|
||||
// 0 count enables direction, send to y = 1 with speed 0.09
|
||||
@@ -247,17 +261,9 @@ public class BCauldron {
|
||||
// A Water Splash with 0.2 offset in x and z
|
||||
block.getWorld().spawnParticle(Particle.WATER_SPLASH, particleLocation, 1, 0.2, 0, 0.2);
|
||||
}
|
||||
Color color = getParticleColor();
|
||||
// Colorable spirally spell, 0 count enables color instead of the offset variables
|
||||
// Configurable RGB color. 1025 seems to be the best for color brightness and upwards motion
|
||||
block.getWorld().spawnParticle(Particle.SPELL_MOB, getRandParticleLoc(), 0,
|
||||
((double) color.getRed()) / 255.0,
|
||||
((double) color.getGreen()) / 255.0,
|
||||
((double) color.getBlue()) / 255.0,
|
||||
1025.0);
|
||||
|
||||
if (P.use1_13 && particleRandom.nextFloat() > 0.4) {
|
||||
// Two hovering pixely dust clouds, a bit offset with DustOptions to give some color and size
|
||||
// Two hovering pixely dust clouds, a bit offset and with DustOptions to give some color and size
|
||||
block.getWorld().spawnParticle(Particle.REDSTONE, particleLocation, 2, 0.15, 0.2, 0.15, new Particle.DustOptions(color, 1.5f));
|
||||
}
|
||||
}
|
||||
@@ -345,12 +351,52 @@ public class BCauldron {
|
||||
return particleColor;
|
||||
}
|
||||
|
||||
public static void processNextCookEffects() {
|
||||
/*public static void processCookEffects() {
|
||||
if (!BConfig.enableCauldronParticles) return;
|
||||
int size = bcauldrons.size();
|
||||
if (size <= 0) {
|
||||
return;
|
||||
}
|
||||
final int skipSize = PARTICLEPAUSE - 1 + (BConfig.minimalParticles ? 20 : 0);
|
||||
|
||||
int skip = particleRandom.nextInt(skipSize);
|
||||
if (skip >= size) {
|
||||
return;
|
||||
}
|
||||
|
||||
Iterator<BCauldron> cauldronsIter = bcauldrons.values().iterator();
|
||||
while (cauldronsIter.hasNext()) {
|
||||
BCauldron cauldron = cauldronsIter.next();
|
||||
if (skip == 0) {
|
||||
cauldron.cookEffect();
|
||||
skip = skipSize;
|
||||
} else {
|
||||
skip--;
|
||||
}
|
||||
}
|
||||
}*/
|
||||
|
||||
public static void processCookEffects() {
|
||||
if (!BConfig.enableCauldronParticles) return;
|
||||
if (bcauldrons.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
final float chance = 1f / PARTICLEPAUSE;
|
||||
|
||||
for (BCauldron cauldron : bcauldrons.values()) {
|
||||
if (particleRandom.nextFloat() < chance) {
|
||||
cauldron.cookEffect();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void old_processNextCookEffects() {
|
||||
if (!BConfig.enableCauldronParticles) return;
|
||||
int size = bcauldrons.size();
|
||||
if (size <= 0) {
|
||||
return;
|
||||
}
|
||||
int useParticlePause = PARTICLEPAUSE;
|
||||
|
||||
// The Particle Delay is reduced every time, independent on how many cauldrons are processed
|
||||
// If it did not reach zero as we process all cauldrons, skip some tasks
|
||||
@@ -358,17 +404,17 @@ public class BCauldron {
|
||||
if (particleCauldron >= size) {
|
||||
if (particleDelay <= 0) {
|
||||
particleCauldron = 0;
|
||||
particleDelay = PARTICLEPAUSE;
|
||||
particleDelay = useParticlePause;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// Decide how many cauldrons to process this time
|
||||
int cauldronsToProcess;
|
||||
if (size < PARTICLEPAUSE) {
|
||||
if (size < useParticlePause) {
|
||||
cauldronsToProcess = 1;
|
||||
} else {
|
||||
cauldronsToProcess = (int) Math.ceil((float) size / (float) PARTICLEPAUSE);
|
||||
cauldronsToProcess = (int) Math.ceil((float) size / (float) useParticlePause);
|
||||
}
|
||||
|
||||
Iterator<BCauldron> cauldronsIter = bcauldrons.values().iterator();
|
||||
@@ -383,7 +429,7 @@ public class BCauldron {
|
||||
if (particleDelay <= 0) {
|
||||
// Processing all cauldrons took as long as the delay, start over right away
|
||||
particleCauldron = 0;
|
||||
particleDelay = PARTICLEPAUSE;
|
||||
particleDelay = useParticlePause;
|
||||
}
|
||||
return;
|
||||
}
|
||||
@@ -516,7 +562,7 @@ public class BCauldron {
|
||||
* Recalculate the Cauldron Particle Recipe
|
||||
*/
|
||||
public static void reload() {
|
||||
for (BCauldron cauldron : BCauldron.bcauldrons.values()) {
|
||||
for (BCauldron cauldron : bcauldrons.values()) {
|
||||
cauldron.particleRecipe = null;
|
||||
cauldron.particleColor = null;
|
||||
if (BConfig.enableCauldronParticles) {
|
||||
|
||||
@@ -23,6 +23,9 @@ import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.event.HandlerList;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.math.MathContext;
|
||||
import java.math.RoundingMode;
|
||||
import java.sql.SQLException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
@@ -517,10 +520,25 @@ public class P extends JavaPlugin {
|
||||
|
||||
}
|
||||
|
||||
private int ticks = 0;
|
||||
private double times = 0;
|
||||
|
||||
public class CauldronParticles implements Runnable {
|
||||
@Override
|
||||
public void run() {
|
||||
BCauldron.processNextCookEffects();
|
||||
if (BConfig.minimalParticles && BCauldron.particleRandom.nextFloat() > 0.5f) {
|
||||
return;
|
||||
}
|
||||
long t1 = System.nanoTime();
|
||||
BCauldron.processCookEffects();
|
||||
long t2 = System.nanoTime();
|
||||
times += (t2 - t1) / 1000.0;
|
||||
ticks++;
|
||||
if (ticks == BCauldron.PARTICLEPAUSE) {
|
||||
ticks = 0;
|
||||
P.p.log("Particles: ~ " + BigDecimal.valueOf(times / BCauldron.PARTICLEPAUSE).round(new MathContext(5, RoundingMode.HALF_UP)) + "µs");
|
||||
times = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -65,6 +65,7 @@ public class BConfig {
|
||||
// Cauldron
|
||||
public static boolean useOffhandForCauldron;
|
||||
public static boolean enableCauldronParticles;
|
||||
public static boolean minimalParticles;
|
||||
|
||||
//BPlayer
|
||||
public static Map<Material, Integer> drainItems = new HashMap<>();// DrainItem Material and Strength
|
||||
@@ -250,6 +251,7 @@ public class BConfig {
|
||||
enableEncode = config.getBoolean("enableEncode", false);
|
||||
openEverywhere = config.getBoolean("openLargeBarrelEverywhere", false);
|
||||
enableCauldronParticles = P.use1_9 && config.getBoolean("enableCauldronParticles", false);
|
||||
minimalParticles = config.getBoolean("minimalParticles", false);
|
||||
useOffhandForCauldron = config.getBoolean("useOffhandForCauldron", false);
|
||||
loadDataAsync = config.getBoolean("loadDataAsync", true);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user