mirror of
https://github.com/DieReicheErethons/Brewery.git
synced 2025-01-25 21:41:19 +01:00
Particle Cleanup
This commit is contained in:
parent
c91e441eab
commit
7319bca59d
@ -26,8 +26,6 @@ public class BCauldron {
|
|||||||
public static final byte EMPTY = 0, SOME = 1, FULL = 2;
|
public static final byte EMPTY = 0, SOME = 1, FULL = 2;
|
||||||
public static final int PARTICLEPAUSE = 15;
|
public static final int PARTICLEPAUSE = 15;
|
||||||
public static Random particleRandom = new Random();
|
public static Random particleRandom = new Random();
|
||||||
private static int particleCauldron;
|
|
||||||
private static int particleDelay;
|
|
||||||
private static Set<UUID> plInteracted = new HashSet<>(); // Interact Event helper
|
private static Set<UUID> plInteracted = new HashSet<>(); // Interact Event helper
|
||||||
public static Map<Block, BCauldron> bcauldrons = new HashMap<>(); // All active cauldrons. Mapped to their block for fast retrieve
|
public static Map<Block, BCauldron> bcauldrons = new HashMap<>(); // All active cauldrons. Mapped to their block for fast retrieve
|
||||||
|
|
||||||
@ -351,31 +349,6 @@ public class BCauldron {
|
|||||||
return particleColor;
|
return particleColor;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*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() {
|
public static void processCookEffects() {
|
||||||
if (!BConfig.enableCauldronParticles) return;
|
if (!BConfig.enableCauldronParticles) return;
|
||||||
if (bcauldrons.isEmpty()) {
|
if (bcauldrons.isEmpty()) {
|
||||||
@ -390,55 +363,6 @@ public class BCauldron {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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
|
|
||||||
particleDelay--;
|
|
||||||
if (particleCauldron >= size) {
|
|
||||||
if (particleDelay <= 0) {
|
|
||||||
particleCauldron = 0;
|
|
||||||
particleDelay = useParticlePause;
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Decide how many cauldrons to process this time
|
|
||||||
int cauldronsToProcess;
|
|
||||||
if (size < useParticlePause) {
|
|
||||||
cauldronsToProcess = 1;
|
|
||||||
} else {
|
|
||||||
cauldronsToProcess = (int) Math.ceil((float) size / (float) useParticlePause);
|
|
||||||
}
|
|
||||||
|
|
||||||
Iterator<BCauldron> cauldronsIter = bcauldrons.values().iterator();
|
|
||||||
int currentPos = 0;
|
|
||||||
for (; currentPos < particleCauldron; currentPos++) {
|
|
||||||
cauldronsIter.next();
|
|
||||||
}
|
|
||||||
|
|
||||||
while (cauldronsToProcess > 0) {
|
|
||||||
if (particleCauldron >= size) {
|
|
||||||
// We reached the end of the Cauldron list
|
|
||||||
if (particleDelay <= 0) {
|
|
||||||
// Processing all cauldrons took as long as the delay, start over right away
|
|
||||||
particleCauldron = 0;
|
|
||||||
particleDelay = useParticlePause;
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
cauldronsIter.next().cookEffect();
|
|
||||||
cauldronsToProcess--;
|
|
||||||
particleCauldron++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void clickCauldron(PlayerInteractEvent event) {
|
public static void clickCauldron(PlayerInteractEvent event) {
|
||||||
Material materialInHand = event.getMaterial();
|
Material materialInHand = event.getMaterial();
|
||||||
ItemStack item = event.getItem();
|
ItemStack item = event.getItem();
|
||||||
|
@ -23,9 +23,6 @@ import org.bukkit.configuration.file.FileConfiguration;
|
|||||||
import org.bukkit.event.HandlerList;
|
import org.bukkit.event.HandlerList;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
import java.math.BigDecimal;
|
|
||||||
import java.math.MathContext;
|
|
||||||
import java.math.RoundingMode;
|
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
@ -520,25 +517,14 @@ public class P extends JavaPlugin {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private int ticks = 0;
|
|
||||||
private double times = 0;
|
|
||||||
|
|
||||||
public class CauldronParticles implements Runnable {
|
public class CauldronParticles implements Runnable {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
|
if (!BConfig.enableCauldronParticles) return;
|
||||||
if (BConfig.minimalParticles && BCauldron.particleRandom.nextFloat() > 0.5f) {
|
if (BConfig.minimalParticles && BCauldron.particleRandom.nextFloat() > 0.5f) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
long t1 = System.nanoTime();
|
|
||||||
BCauldron.processCookEffects();
|
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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user