From 3d9309e2d9a1ee0b522b5486c425ff6b415e7d32 Mon Sep 17 00:00:00 2001 From: Sn0wStorm Date: Fri, 6 Nov 2020 13:59:36 +0100 Subject: [PATCH] Added Particles to boiling Cauldrons --- README.md | 2 +- pom.xml | 2 +- resources/config/v12/de/config.yml | 3 + resources/config/v12/en/config.yml | 3 + resources/config/v12/fr/config.yml | 3 + resources/config/v12/it/config.yml | 3 + resources/config/v13/de/config.yml | 3 + resources/config/v13/en/config.yml | 3 + resources/config/v13/es/config.yml | 3 + resources/config/v13/fr/config.yml | 3 + resources/config/v13/it/config.yml | 3 + resources/config/v13/zh/config.yml | 3 + src/com/dre/brewery/BCauldron.java | 144 +++++++++++++++++- src/com/dre/brewery/P.java | 20 +++ src/com/dre/brewery/filedata/BConfig.java | 2 + .../brewery/listeners/CommandListener.java | 24 +++ src/com/dre/brewery/utility/LegacyUtil.java | 2 +- 17 files changed, 216 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 7a8a36f..d8fa754 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/pom.xml b/pom.xml index ff0ad00..a6242b4 100644 --- a/pom.xml +++ b/pom.xml @@ -117,7 +117,7 @@ org.spigotmc spigot-api - 1.16.3-R0.1-SNAPSHOT + 1.16.4-R0.1-SNAPSHOT provided diff --git a/resources/config/v12/de/config.yml b/resources/config/v12/de/config.yml index 003bde4..7e94427 100644 --- a/resources/config/v12/de/config.yml +++ b/resources/config/v12/de/config.yml @@ -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 diff --git a/resources/config/v12/en/config.yml b/resources/config/v12/en/config.yml index 9258e09..8ef694e 100644 --- a/resources/config/v12/en/config.yml +++ b/resources/config/v12/en/config.yml @@ -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 diff --git a/resources/config/v12/fr/config.yml b/resources/config/v12/fr/config.yml index f956880..c203a61 100644 --- a/resources/config/v12/fr/config.yml +++ b/resources/config/v12/fr/config.yml @@ -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 diff --git a/resources/config/v12/it/config.yml b/resources/config/v12/it/config.yml index 331bbf8..7963916 100644 --- a/resources/config/v12/it/config.yml +++ b/resources/config/v12/it/config.yml @@ -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 diff --git a/resources/config/v13/de/config.yml b/resources/config/v13/de/config.yml index cf24d8c..2f69cfd 100644 --- a/resources/config/v13/de/config.yml +++ b/resources/config/v13/de/config.yml @@ -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 diff --git a/resources/config/v13/en/config.yml b/resources/config/v13/en/config.yml index 9479649..12224c1 100644 --- a/resources/config/v13/en/config.yml +++ b/resources/config/v13/en/config.yml @@ -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 diff --git a/resources/config/v13/es/config.yml b/resources/config/v13/es/config.yml index 0c39956..454d37c 100644 --- a/resources/config/v13/es/config.yml +++ b/resources/config/v13/es/config.yml @@ -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 diff --git a/resources/config/v13/fr/config.yml b/resources/config/v13/fr/config.yml index 0bf2ddc..e86a903 100644 --- a/resources/config/v13/fr/config.yml +++ b/resources/config/v13/fr/config.yml @@ -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 diff --git a/resources/config/v13/it/config.yml b/resources/config/v13/it/config.yml index c70b5ef..2c073ba 100644 --- a/resources/config/v13/it/config.yml +++ b/resources/config/v13/it/config.yml @@ -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 diff --git a/resources/config/v13/zh/config.yml b/resources/config/v13/zh/config.yml index 6f8c78a..6daad7e 100644 --- a/resources/config/v13/zh/config.yml +++ b/resources/config/v13/zh/config.yml @@ -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 diff --git a/src/com/dre/brewery/BCauldron.java b/src/com/dre/brewery/BCauldron.java index 2f99aa6..87e3ee2 100644 --- a/src/com/dre/brewery/BCauldron.java +++ b/src/com/dre/brewery/BCauldron.java @@ -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 plInteracted = new HashSet<>(); // Interact Event helper public static Map 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 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; diff --git a/src/com/dre/brewery/P.java b/src/com/dre/brewery/P.java index 2225367..70f2da7 100644 --- a/src/com/dre/brewery/P.java +++ b/src/com/dre/brewery/P.java @@ -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(); + } + } + } diff --git a/src/com/dre/brewery/filedata/BConfig.java b/src/com/dre/brewery/filedata/BConfig.java index e54b32a..c4a3a33 100644 --- a/src/com/dre/brewery/filedata/BConfig.java +++ b/src/com/dre/brewery/filedata/BConfig.java @@ -64,6 +64,7 @@ public class BConfig { // Cauldron public static boolean useOffhandForCauldron; + public static boolean enableCauldronParticles; //BPlayer public static Map 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); diff --git a/src/com/dre/brewery/listeners/CommandListener.java b/src/com/dre/brewery/listeners/CommandListener.java index 3b2117d..6f13c32 100644 --- a/src/com/dre/brewery/listeners/CommandListener.java +++ b/src/com/dre/brewery/listeners/CommandListener.java @@ -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 commands = getCommands(sender); diff --git a/src/com/dre/brewery/utility/LegacyUtil.java b/src/com/dre/brewery/utility/LegacyUtil.java index 21ca991..50420f9 100644 --- a/src/com/dre/brewery/utility/LegacyUtil.java +++ b/src/com/dre/brewery/utility/LegacyUtil.java @@ -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)); }