diff --git a/pom.xml b/pom.xml index e49822b..4b1c61c 100644 --- a/pom.xml +++ b/pom.xml @@ -114,7 +114,7 @@ com.github.Slimefun Slimefun4 - 2c4f886 + d191599 provided diff --git a/src/main/java/dev/sefiraat/netheopoiesis/Purification.java b/src/main/java/dev/sefiraat/netheopoiesis/Purification.java index 281f923..ca742a9 100644 --- a/src/main/java/dev/sefiraat/netheopoiesis/Purification.java +++ b/src/main/java/dev/sefiraat/netheopoiesis/Purification.java @@ -9,8 +9,8 @@ import org.bukkit.block.Block; import javax.annotation.Nonnull; -import java.util.HashMap; import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; public class Purification { @@ -53,23 +53,27 @@ public class Purification { private static Purification instance; - private final Map purificationModifiers = new HashMap<>(); - private final Map chunkValues = new HashMap<>(); + private final Map purificationModifiers = new ConcurrentHashMap<>(); + private final Map chunkValues = new ConcurrentHashMap<>(); public Purification() { Preconditions.checkArgument(instance == null, "Cannot create a new instance of Purification"); instance = this; - Bukkit.getScheduler().runTaskTimer(Netheopoiesis.getInstance(), this::collateChunkValues, 1, 100); + Bukkit.getScheduler().runTaskTimerAsynchronously(Netheopoiesis.getInstance(), this::collateChunkValues, 1, 100); } private void collateChunkValues() { chunkValues.clear(); for (Map.Entry entry : purificationModifiers.entrySet()) { - final BlockPosition blockPosition = entry.getKey(); - final ChunkPosition chunkPosition = new ChunkPosition(blockPosition.getChunk()); - final int currentValue = chunkValues.getOrDefault(chunkPosition, 0); + final BlockPosition blockPos = entry.getKey(); + final ChunkPosition chunkPos = new ChunkPosition( + blockPos.getWorld(), + blockPos.getChunkX(), + blockPos.getChunkZ() + ); + final int currentValue = chunkValues.getOrDefault(chunkPos, 0); final int newValue = currentValue + entry.getValue(); - chunkValues.put(chunkPosition, newValue); + chunkValues.put(chunkPos, newValue); } } diff --git a/src/main/java/dev/sefiraat/netheopoiesis/api/items/DroppingSeed.java b/src/main/java/dev/sefiraat/netheopoiesis/api/items/DroppingSeed.java index 971a097..cde6450 100644 --- a/src/main/java/dev/sefiraat/netheopoiesis/api/items/DroppingSeed.java +++ b/src/main/java/dev/sefiraat/netheopoiesis/api/items/DroppingSeed.java @@ -4,7 +4,9 @@ import io.github.bakedlibs.dough.collections.RandomizedSet; import io.github.thebusybiscuit.slimefun4.api.items.SlimefunItemStack; import me.mrCookieSlime.CSCoreLibPlugin.Configuration.Config; +import me.mrCookieSlime.Slimefun.api.BlockStorage; import org.bukkit.Location; +import org.bukkit.Material; import org.bukkit.inventory.ItemStack; import javax.annotation.Nonnull; @@ -19,6 +21,9 @@ */ public class DroppingSeed extends NetherSeed { + private static final String WITHER_KEY = "wither_chance"; + private static final int WITHER_CHANCE = 5; + private final RandomizedSet stacksToDrop = new RandomizedSet<>(); private double chance = 0.1; @@ -32,6 +37,19 @@ public void onTickFullyGrown(Location location, NetherSeed seed, Config data) { double randomChance = ThreadLocalRandom.current().nextDouble(); if (randomChance <= chance) { location.getWorld().dropItem(location, this.stacksToDrop.getRandom()); + updateGrowthStage(location, 1); + final String currentChance = BlockStorage.getLocationInfo(location, WITHER_KEY); + if (currentChance == null) { + BlockStorage.addBlockInfo(location, WITHER_KEY, String.valueOf(WITHER_CHANCE)); + } else { + final int currentChanceInt = Integer.parseInt(currentChance); + if (ThreadLocalRandom.current().nextInt(101) < currentChanceInt) { + location.getBlock().setType(Material.AIR); + BlockStorage.clearBlockInfo(location); + } else { + BlockStorage.addBlockInfo(location, WITHER_KEY, String.valueOf(currentChanceInt + WITHER_CHANCE)); + } + } } } diff --git a/src/main/java/dev/sefiraat/netheopoiesis/implementation/Groups.java b/src/main/java/dev/sefiraat/netheopoiesis/implementation/Groups.java index e67c392..5d9b87b 100644 --- a/src/main/java/dev/sefiraat/netheopoiesis/implementation/Groups.java +++ b/src/main/java/dev/sefiraat/netheopoiesis/implementation/Groups.java @@ -104,6 +104,8 @@ private Groups() { static { final Netheopoiesis plugin = Netheopoiesis.getInstance(); + SEEDS.setCrossAddonItemGroup(true); + // Slimefun Registry MAIN.register(plugin); CRAFTING.register(plugin); diff --git a/src/main/java/dev/sefiraat/netheopoiesis/implementation/Items.java b/src/main/java/dev/sefiraat/netheopoiesis/implementation/Items.java index f5122c0..225d88c 100644 --- a/src/main/java/dev/sefiraat/netheopoiesis/implementation/Items.java +++ b/src/main/java/dev/sefiraat/netheopoiesis/implementation/Items.java @@ -602,7 +602,7 @@ null, new ItemStack(Material.BEACON), null new DroppingSeed(Stacks.GRAINY_SEED) .addDrop(new ItemStack(Material.REDSTONE), 1) - .setTriggerChance(0.05) + .setTriggerChance(0.01) .setGrowth(new Growth(GrowthStages.VINEY_RED, Placements.ALL, 1, 0.09)) .addBreedingPair(Stacks.PURIFICATION_SEED.getItemId(), Stacks.PURIFICATION_SEED.getItemId(), 0.1, 0.2) .addFlavourProfile(0, 0, 0, 1, 1) @@ -610,7 +610,7 @@ null, new ItemStack(Material.BEACON), null new DroppingSeed(Stacks.STRINGY_SEED) .addDrop(new ItemStack(Material.STRING), 1) - .setTriggerChance(0.05) + .setTriggerChance(0.01) .setGrowth(new Growth(GrowthStages.VINEY_GREEN, Placements.ALL, 1, 0.09)) .addBreedingPair(Stacks.PURIFICATION_SEED.getItemId(), Stacks.PURIFICATION_SEED.getItemId(), 0.1, 0.2) .addFlavourProfile(0, 1, 1, 0, 0) @@ -621,7 +621,7 @@ null, new ItemStack(Material.BEACON), null .addDrop(new ItemStack(Material.TALL_GRASS), 2) .addDrop(new ItemStack(Material.SEAGRASS), 1) .addDrop(new ItemStack(Material.TALL_SEAGRASS), 1) - .setTriggerChance(0.05) + .setTriggerChance(0.01) .setGrowth(new Growth(GrowthStages.VINEY_GREEN, Placements.ALL, 1, 0.09)) .addBreedingPair(Stacks.SPINDLE_SEED.getItemId(), Stacks.STRINGY_SEED.getItemId(), 0.1, 0.2) .addFlavourProfile(2, 0, 0, 0, 0) @@ -629,7 +629,7 @@ null, new ItemStack(Material.BEACON), null new DroppingSeed(Stacks.COBBLED_SEED) .addDrop(new ItemStack(Material.COBBLESTONE), 1) - .setTriggerChance(0.05) + .setTriggerChance(0.01) .setGrowth(new Growth(GrowthStages.VINEY_PURPLE, Placements.ALL, 1, 0.09)) .addBreedingPair(Stacks.SPINDLE_SEED.getItemId(), Stacks.GRAINY_SEED.getItemId(), 0.1, 0.2) .addFlavourProfile(0, 0, 1, 1, 0) @@ -744,7 +744,7 @@ null, new ItemStack(Material.BEACON), null .addDrop(new ItemStack(Material.MELON_SEEDS), 1) .addDrop(new ItemStack(Material.BEETROOT_SEEDS), 1) .addDrop(new ItemStack(Material.PUMPKIN_SEEDS), 1) - .setTriggerChance(0.05) + .setTriggerChance(0.01) .setGrowth(new Growth(GrowthStages.FUNGAL_YELLOW, Placements.PURIFIED_AND_UP, 2, 0.08)) .addBreedingPair(Stacks.SMOOTH_SEED.getItemId(), Stacks.GRASS_SEED.getItemId(), 0.05, 0.2) .addFlavourProfile(2, 1, 0, 1, 0) @@ -816,7 +816,7 @@ null, new ItemStack(Material.BEACON), null .addDrop(new ItemStack(Material.GREEN_DYE), 1) .addDrop(new ItemStack(Material.RED_DYE), 1) .addDrop(new ItemStack(Material.BLACK_DYE), 1) - .setTriggerChance(0.1) + .setTriggerChance(0.01) .setGrowth(new Growth(GrowthStages.VINEY_CYAN, Placements.VORACIOUS_AND_UP, 8, 0.06)) .addBreedingPair(Stacks.SPIRIT_SEED.getItemId(), Stacks.SPIRIT_SEED.getItemId(), 0.05, 0.2) .addFlavourProfile(4, 2, 2, 0, 0) @@ -826,7 +826,7 @@ null, new ItemStack(Material.BEACON), null .addDrop(new ItemStack(Material.GLOW_LICHEN), 1) .addDrop(new ItemStack(Material.GLOW_BERRIES), 1) .addDrop(new ItemStack(Material.GLOW_INK_SAC), 1) - .setTriggerChance(0.08) + .setTriggerChance(0.01) .setGrowth(new Growth(GrowthStages.FUNGAL_RED, Placements.VORACIOUS_AND_UP, 8, 0.06)) .addBreedingPair(Stacks.SPIRIT_SEED.getItemId(), Stacks.SPIRIT_SEED.getItemId(), 0.05, 0.2) .addFlavourProfile(0, 0, 4, 0, 4) @@ -863,7 +863,7 @@ null, new ItemStack(Material.BEACON), null new DroppingSeed(Stacks.PRISMATIC_SEED) .addDrop(new ItemStack(Material.PRISMARINE_SHARD), 2) .addDrop(new ItemStack(Material.PRISMARINE_CRYSTALS), 1) - .setTriggerChance(0.05) + .setTriggerChance(0.005) .setGrowth(new Growth(GrowthStages.SPIKEY_GREEN, Placements.VORACIOUS_AND_UP, 9, 0.06)) .addBreedingPair(Stacks.RAINBOW_SEED.getItemId(), Stacks.SPLINTERED_SEED.getItemId(), 0.1, 0.15) .addFlavourProfile(0, 0, 8, 0, 0) @@ -1004,7 +1004,7 @@ null, new ItemStack(Material.BEACON), null new DroppingSeed(Stacks.TREASURED_SEED) .addDrop(new ItemStack(Material.HEART_OF_THE_SEA), 1) .addDrop(new ItemStack(Material.NAUTILUS_SHELL), 9) - .setTriggerChance(0.01) + .setTriggerChance(0.001) .setGrowth(new Growth(GrowthStages.SPIKEY_GREEN, Placements.BEACH_BIOME, 15, 0.06)) .addBreedingPair(Stacks.BEACH_SEED.getItemId(), Stacks.SHINY_SEED.getItemId(), 0.1, 0.5) .addFlavourProfile(4, 4, 4, 4, 4) diff --git a/src/main/java/dev/sefiraat/netheopoiesis/implementation/flora/PurificationSeed.java b/src/main/java/dev/sefiraat/netheopoiesis/implementation/flora/PurificationSeed.java index 39a5b4c..65545d4 100644 --- a/src/main/java/dev/sefiraat/netheopoiesis/implementation/flora/PurificationSeed.java +++ b/src/main/java/dev/sefiraat/netheopoiesis/implementation/flora/PurificationSeed.java @@ -65,6 +65,12 @@ public void onTickFullyGrown(Location location, NetherSeed seed, Config data) { final double randomZ = ThreadLocalRandom.current().nextInt(-3, 4); // For loop to make sure the purification can creep up and down. + final Location spreadLocation = location.clone().add(randomX, randomY, randomZ); + + if (!WorldUtils.chunkLoaded(spreadLocation)) { + return; + } + final Block block = location.clone().add(randomX, randomY, randomZ).getBlock(); if (materials.contains(block.getType()) && ProtectionUtils.hasPermission(getOwner(location), block, Interaction.BREAK_BLOCK) diff --git a/src/main/java/dev/sefiraat/netheopoiesis/utils/WorldUtils.java b/src/main/java/dev/sefiraat/netheopoiesis/utils/WorldUtils.java index 5202edf..3817533 100644 --- a/src/main/java/dev/sefiraat/netheopoiesis/utils/WorldUtils.java +++ b/src/main/java/dev/sefiraat/netheopoiesis/utils/WorldUtils.java @@ -112,4 +112,14 @@ public static Location randomLocation(@Nonnull Location centreLocation, int rang public static Location centre(@Nonnull Location location) { return location.clone().add(0.5, 0.5, 0.5); } + + /** + * Checks if the chunk is loaded using location (doesn't load the chunk) + * @param location The location to check + * @return True if the chunk is loaded. + */ + public static boolean chunkLoaded(@Nonnull Location location) { + return location.getWorld().isChunkLoaded(location.getBlockX() / 16, location.getBlockZ() / 16); + } + }