Added Particles to boiling Cauldrons

This commit is contained in:
Sn0wStorm 2020-11-06 13:59:36 +01:00
parent c8a7a56ab9
commit 3d9309e2d9
17 changed files with 216 additions and 10 deletions

View File

@ -6,7 +6,7 @@
Find the Project Page on [Spigot](https://www.spigotmc.org/resources/brewery.3082/) or [Bukkit](https://dev.bukkit.org/projects/brewery)
Also see [Wiki](https://github.com/DieReicheErethons/Brewery/wiki) | [Releases](https://github.com/DieReicheErethons/Brewery/releases) | [Changelog](https://github.com/DieReicheErethons/Brewery/wiki/changelog)
Also see [Wiki](https://github.com/DieReicheErethons/Brewery/wiki) | [Releases](https://github.com/DieReicheErethons/Brewery/releases) | [Changelog](https://github.com/DieReicheErethons/Brewery/wiki/changelog) | [Commits](https://github.com/DieReicheErethons/Brewery/commits/master)
### Maven

View File

@ -117,7 +117,7 @@
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>1.16.3-R0.1-SNAPSHOT</version>
<version>1.16.4-R0.1-SNAPSHOT</version>
<scope>provided</scope>
<exclusions>
<exclusion>

View File

@ -49,6 +49,9 @@ drainItems:
# Zeit (in Tagen) die Trunkenheitsdaten nach offlinegehen eines Spielers im Speicher verbleiben, um z.B. Kater-Effekte anzuwenden. [7]
hangoverDays: 7
# Partikel steigen von Kesseln auf wenn sie Zutaten und eine Feuerquelle haben [true]
enableCauldronParticles: true
# Ob das craften und das benutzen des Trank-Versiegelungs-Tisches aktiviert ist (2 Flaschen über 4 Holz) [true, true]
craftSealingTable: true
enableSealingTable: true

View File

@ -49,6 +49,9 @@ drainItems:
# Time (in days) that drunkeness-data stays in memory after a player goes offline, to apply hangover etc. [7]
hangoverDays: 7
# Show Particles over Cauldrons when they have ingredients and a heat source. [true]
enableCauldronParticles: true
# If crafting and using of the Brew Sealing Table is enabled (2 Bottles over 4 Planks) [true, true]
craftSealingTable: true
enableSealingTable: true

View File

@ -50,6 +50,9 @@ drainItems:
# Temps (en jours) pour que les données d'ivresse restent sauvergardées lorsque le joueur est déconnecté, pour appliquer les effets. [7]
hangoverDays: 7
# Show Particles over Cauldrons when they have ingredients and a heat source. [true]
enableCauldronParticles: true
# If crafting and using of the Brew Sealing Table is enabled (2 Bottles over 4 Planks) [true, true]
craftSealingTable: true
enableSealingTable: true

View File

@ -49,6 +49,9 @@ drainItems:
# Tempo in giorni che la sbronza resta in memoria dopo che il giocatore va offline, cioè il tempo per cui i postumi della sbornia durano. [7]
hangoverDays: 7
# Show Particles over Cauldrons when they have ingredients and a heat source. [true]
enableCauldronParticles: true
# If crafting and using of the Brew Sealing Table is enabled (2 Bottles over 4 Planks) [true, true]
craftSealingTable: true
enableSealingTable: true

View File

@ -49,6 +49,9 @@ drainItems:
# Zeit (in Tagen) die Trunkenheitsdaten nach offlinegehen eines Spielers im Speicher verbleiben, um z.B. Kater-Effekte anzuwenden. [7]
hangoverDays: 7
# Partikel steigen von Kesseln auf wenn sie Zutaten und eine Feuerquelle haben [true]
enableCauldronParticles: true
# Ob das craften und das benutzen des Trank-Versiegelungs-Tisches aktiviert ist (2 Flaschen über 4 Holz) [true, true]
craftSealingTable: true
enableSealingTable: true

View File

@ -49,6 +49,9 @@ drainItems:
# Time (in days) that drunkeness-data stays in memory after a player goes offline, to apply hangover etc. [7]
hangoverDays: 7
# Show Particles over Cauldrons when they have ingredients and a heat source. [true]
enableCauldronParticles: true
# If crafting and using of the Brew Sealing Table is enabled (2 Bottles over 4 Planks) [true, true]
craftSealingTable: true
enableSealingTable: true

View File

@ -49,6 +49,9 @@ drainItems:
# Time (in days) that drunkeness-data stays in memory after a player goes offline, to apply hangover etc. [7]
hangoverDays: 7
# Show Particles over Cauldrons when they have ingredients and a heat source. [true]
enableCauldronParticles: true
# If crafting and using of the Brew Sealing Table is enabled (2 Bottles over 4 Planks) [true, true]
craftSealingTable: true
enableSealingTable: true

View File

@ -50,6 +50,9 @@ drainItems:
# Temps (en jours) pour que les données d'ivresse restent sauvergardées lorsque le joueur est déconnecté, pour appliquer les effets. [7]
hangoverDays: 7
# Show Particles over Cauldrons when they have ingredients and a heat source. [true]
enableCauldronParticles: true
# If crafting and using of the Brew Sealing Table is enabled (2 Bottles over 4 Planks) [true, true]
craftSealingTable: true
enableSealingTable: true

View File

@ -49,6 +49,9 @@ drainItems:
# Tempo in giorni che la sbronza resta in memoria dopo che il giocatore va offline, cioè il tempo per cui i postumi della sbornia durano. [7]
hangoverDays: 7
# Show Particles over Cauldrons when they have ingredients and a heat source. [true]
enableCauldronParticles: true
# If crafting and using of the Brew Sealing Table is enabled (2 Bottles over 4 Planks) [true, true]
craftSealingTable: true
enableSealingTable: true

View File

@ -51,6 +51,9 @@ drainItems:
# 最大玩家下线记忆时长(单位为天). 饮酒的记忆保持时间, 便于计算宿醉.[7]
hangoverDays: 7
# Show Particles over Cauldrons when they have ingredients and a heat source. [true]
enableCauldronParticles: true
# If crafting and using of the Brew Sealing Table is enabled (2 Bottles over 4 Planks) [true, true]
craftSealingTable: true
enableSealingTable: true

View File

@ -7,7 +7,9 @@ import com.dre.brewery.recipe.RecipeItem;
import com.dre.brewery.utility.BUtil;
import com.dre.brewery.utility.LegacyUtil;
import org.bukkit.Effect;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.Particle;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.block.data.BlockData;
@ -19,24 +21,28 @@ import org.bukkit.inventory.EquipmentSlot;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.Nullable;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
import java.util.*;
public class BCauldron {
public static final byte EMPTY = 0, SOME = 1, FULL = 2;
public static final int PARTICLEPAUSE = 15;
public static Random particleRandom = new Random();
private static int particleCauldron;
private static int particleDelay;
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 Particle particle = Particle.CLOUD;
private BIngredients ingredients = new BIngredients();
private final Block block;
private int state = 0;
private boolean changed = false;
private Location particleLocation;
public BCauldron(Block block) {
this.block = block;
particleLocation = block.getLocation().add(0.5, 0.8, 0.5);
}
// loading from file
@ -44,11 +50,12 @@ public class BCauldron {
this.block = block;
this.state = state;
this.ingredients = ingredients;
particleLocation = block.getLocation().add(0.5, 0.8, 0.5);
}
public void onUpdate() {
// Check if fire still alive
if (!BUtil.isChunkLoaded(block) || LegacyUtil.isFireForCauldron(block.getRelative(BlockFace.DOWN))) {
if (!BUtil.isChunkLoaded(block) || LegacyUtil.isCauldronHeatsource(block.getRelative(BlockFace.DOWN))) {
// add a minute to cooking time
state++;
if (changed) {
@ -71,6 +78,12 @@ public class BCauldron {
if (state > 0) {
state--;
}
if (BConfig.enableCauldronParticles) {
//block.getWorld().spawnParticle(Particle.SPELL_INSTANT, getRandomized(),0, -0.5 + particleRandom.nextFloat(), 1, -0.5 + particleRandom.nextFloat());
block.getWorld().spawnParticle(Particle.SPELL_INSTANT, particleLocation,3, 0.2, 0, 0.2);
//block.getWorld().spawnParticle(Particle.REDSTONE, pLoc1, 15, 0.5, 0.4, 0.5, new Particle.DustOptions(Color.GREEN, 12f));
block.getWorld().spawnParticle(Particle.WATER_SPLASH, particleLocation, 10, 0.2, 0, 0.2);
}
}
/**
@ -198,6 +211,123 @@ public class BCauldron {
}
}
public void createParticlePackets() {
try {
} catch (Exception ignored) {}
}
double test = 0;
public void cookEffect() {
long time1 = System.nanoTime();
if (BUtil.isChunkLoaded(block) && LegacyUtil.isCauldronHeatsource(block.getRelative(BlockFace.DOWN))) {
time1 = System.nanoTime() - time1;
long time2 = System.nanoTime();
//block.getWorld().spawnParticle(particle, pLoc1, 2, 0.2, 1, 0.2, 0);
//block.getWorld().spigot().playEffect(pLoc1, effect, 0, 0, 0.2F, 0, 0.2F, 0, 8, 15);
time2 = System.nanoTime() - time2;
long time3 = System.nanoTime();
//block.getWorld().spawnParticle(Particle.CAMPFIRE_COSY_SMOKE, pLoc1, 0, 0.01, 1, 0.01, 0.05);
//block.getWorld().spawnParticle(Particle.WATER_SPLASH, getRandomized(), 1, 0.1, 0, 0.1, 0.005);
if (particleRandom.nextFloat() > 0.75) {
block.getWorld().spawnParticle(Particle.CLOUD, getRandomized(), 0, 0, 1, 0, 0.07);
//block.getWorld().spawnParticle(Particle.REDSTONE, pLoc2, 3, 0.3, 0, 0.3, 10, new Particle.DustOptions(Color.BLUE, 1));
//block.getWorld().spawnParticle(Particle.SPELL_INSTANT, getRandomized(), 0, 0, 1, 0, 0.005);
}
if (particleRandom.nextFloat() > 0.2) {
block.getWorld().spawnParticle(Particle.WATER_SPLASH, particleLocation, 1, 0.2, 0, 0.2);
}
block.getWorld().spawnParticle(Particle.SPELL_MOB, getRandomized(), 0, 180.0/255.0, 40.0/255.0, 1.0/255.0, 1025.0);
//block.getWorld().playEffect(pLoc1, Effect.);
//block.getWorld().spigot().playEffect(pLoc2, Effect.SPELL, 0, 0, 0.2F, 0.2F, 0.2F, 0, 2, 25);
time3 = System.nanoTime() - time3;
//P.p.log("Time: 1: " + time1 + " 2: " + time2 + " 3: " + time3);
//block.getWorld().spigot().playEffect(block.getLocation().add(0.5, 1, 0.5), Effect.COLOURED_DUST, 0, 1, 0.3F, 0.5F, 0.3F, 0, 5, 15);
//block.getWorld().spigot().playEffect(block.getLocation().add(0.5, 0.5, 0.5), Effect.PARTICLE_SMOKE, 0, 0, 0.3F, 0.5F, 0.3F, 0, 8, 20);
//test+=1;
//P.p.log(test + "");
//test = 512.0;
}
}
public Location getRandomized() {
return new Location(particleLocation.getWorld(), particleLocation.getX() + (particleRandom.nextDouble() * 0.8) - 0.4, particleLocation.getY(), particleLocation.getZ() + (particleRandom.nextDouble() * 0.8) - 0.4);
}
// Item Crack
// Block Dust
// FAlling dust
// CAmpfire
// Explosion normal
// Water Splash
// Spell Mob
// Spell Witch
// CLoud
public static void cookEffects() {
if (!BConfig.enableCauldronParticles) return;
int size = bcauldrons.size();
if (size <= 0) {
return;
}
// 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 = PARTICLEPAUSE;
}
return;
}
// Decide how many cauldrons to process this time
int cauldronsToProcess;
if (size < PARTICLEPAUSE) {
cauldronsToProcess = 1;
} else {
cauldronsToProcess = (int) Math.ceil((float) size / (float) PARTICLEPAUSE);
}
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 = PARTICLEPAUSE;
}
return;
}
cauldronsIter.next().cookEffect();
cauldronsToProcess--;
particleCauldron++;
}
}
/*public static void cookEffects() {
int size = bcauldrons.size();
if (size <= 0) {
return;
}
int numCauldrons = Math.max(size / 40, 1);
Random r = new Random();
while (numCauldrons > 0) {
bcauldrons.get(r.nextInt(size)).cookEffect();
numCauldrons--;
}
}*/
public static void clickCauldron(PlayerInteractEvent event) {
Material materialInHand = event.getMaterial();
ItemStack item = event.getItem();
@ -248,7 +378,7 @@ public class BCauldron {
// Check if fire alive below cauldron when adding ingredients
Block down = clickedBlock.getRelative(BlockFace.DOWN);
if (LegacyUtil.isFireForCauldron(down)) {
if (LegacyUtil.isCauldronHeatsource(down)) {
event.setCancelled(true);
boolean handSwap = false;

View File

@ -18,6 +18,7 @@ import org.bstats.bukkit.Metrics;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.command.CommandSender;
import org.bukkit.command.PluginCommand;
import org.bukkit.configuration.file.FileConfiguration;
@ -33,6 +34,7 @@ public class P extends JavaPlugin {
public static boolean debug;
public static boolean useUUID;
public static boolean useNBT;
public boolean hasSpigot;
public static boolean use1_9;
public static boolean use1_11;
public static boolean use1_13;
@ -67,6 +69,13 @@ public class P extends JavaPlugin {
use1_13 = !v.matches("(^|.*[^.\\d])1\\.1[0-2]([^\\d].*|$)") && !v.matches("(^|.*[^.\\d])1\\.[0-9]([^\\d].*|$)");
use1_14 = !v.matches("(^|.*[^.\\d])1\\.1[0-3]([^\\d].*|$)") && !v.matches("(^|.*[^.\\d])1\\.[0-9]([^\\d].*|$)");
try {
Class c = World.Spigot.class;
hasSpigot = true;
} catch (LinkageError e) {
hasSpigot = false;
}
//MC 1.13 uses a different NBT API than the newer versions..
// We decide here which to use, the new or the old or none at all
if (LegacyUtil.initNbt()) {
@ -129,6 +138,10 @@ public class P extends JavaPlugin {
p.getServer().getScheduler().runTaskTimer(p, new BreweryRunnable(), 650, 1200);
p.getServer().getScheduler().runTaskTimer(p, new DrunkRunnable(), 120, 120);
if (use1_9) {
p.getServer().getScheduler().runTaskTimer(p, new CauldronParticles(), 1, 1);
}
if (BConfig.updateCheck) {
try {
p.getServer().getScheduler().runTaskLaterAsynchronously(p, new UpdateChecker(), 135);
@ -473,4 +486,11 @@ public class P extends JavaPlugin {
}
public class CauldronParticles implements Runnable {
@Override
public void run() {
BCauldron.cookEffects();
}
}
}

View File

@ -64,6 +64,7 @@ public class BConfig {
// Cauldron
public static boolean useOffhandForCauldron;
public static boolean enableCauldronParticles;
//BPlayer
public static Map<Material, Integer> drainItems = new HashMap<>();// DrainItem Material and Strength
@ -246,6 +247,7 @@ public class BConfig {
alwaysShowAlc = config.getBoolean("alwaysShowAlc", false);
enableEncode = config.getBoolean("enableEncode", false);
openEverywhere = config.getBoolean("openLargeBarrelEverywhere", false);
enableCauldronParticles = P.use1_9 && config.getBoolean("enableCauldronParticles", false);
useOffhandForCauldron = config.getBoolean("useOffhandForCauldron", false);
loadDataAsync = config.getBoolean("loadDataAsync", true);

View File

@ -7,7 +7,9 @@ import com.dre.brewery.recipe.BRecipe;
import com.dre.brewery.recipe.Ingredient;
import com.dre.brewery.recipe.RecipeItem;
import com.dre.brewery.utility.BUtil;
import org.bukkit.Effect;
import org.bukkit.Material;
import org.bukkit.Particle;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
@ -15,6 +17,7 @@ import org.bukkit.command.ConsoleCommandSender;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.scheduler.BukkitRunnable;
import org.jetbrains.annotations.NotNull;
import java.util.ArrayList;
@ -163,12 +166,33 @@ public class CommandListener implements CommandExecutor {
return true;
}
private Runnable r;
private int pos = 0;
public void cmdHelp(CommandSender sender, String[] args) {
int page = 1;
if (args.length > 1) {
BCauldron.particle = Particle.valueOf(args[1]);
if (BCauldron.particle != null) {
p.msg(sender, "Effekt: " + BCauldron.particle.name());
} else {
BCauldron.particle = Particle.REDSTONE;
}
page = p.parseInt(args[1]);
}
r = new Runnable() {
@Override
public void run() {
pos++;
if (pos >= Particle.values().length) {
pos = 0;
}
BCauldron.particle = Particle.values()[pos];
sender.sendMessage("Particle: " + BCauldron.particle.name());
}
};
P.p.getServer().getScheduler().runTaskTimer(P.p, r, 100, 100);
ArrayList<String> commands = getCommands(sender);

View File

@ -111,7 +111,7 @@ public class LegacyUtil {
return type.name().endsWith("SIGN") || (!P.use1_13 && type == SIGN_POST);
}
public static boolean isFireForCauldron(Block block) {
public static boolean isCauldronHeatsource(Block block) {
Material type = block.getType();
return type != null && (type == Material.FIRE || type == SOUL_FIRE || type == MAGMA_BLOCK || litCampfire(block) || isLava(type));
}