From 51a1d1bf7f7e5123bcb92135874e578d83272a69 Mon Sep 17 00:00:00 2001 From: ybw0014 Date: Wed, 20 Nov 2024 11:13:22 -0800 Subject: [PATCH] feat: onExplode customization on EnergyNetProvider --- .../core/attributes/EnergyNetProvider.java | 19 +++++++++++++++++++ .../core/networks/energy/EnergyNet.java | 5 +---- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/attributes/EnergyNetProvider.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/attributes/EnergyNetProvider.java index 10dafe4d4b..37b558a4b8 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/attributes/EnergyNetProvider.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/attributes/EnergyNetProvider.java @@ -3,9 +3,11 @@ import javax.annotation.Nonnull; import org.bukkit.Location; +import org.bukkit.Material; import io.github.thebusybiscuit.slimefun4.core.networks.energy.EnergyNet; import io.github.thebusybiscuit.slimefun4.core.networks.energy.EnergyNetComponentType; +import io.github.thebusybiscuit.slimefun4.implementation.Slimefun; import io.github.thebusybiscuit.slimefun4.implementation.items.electric.AbstractEnergyProvider; import io.github.thebusybiscuit.slimefun4.implementation.items.electric.reactors.Reactor; @@ -63,4 +65,21 @@ default boolean willExplode(@Nonnull Location l, @Nonnull Config data) { return false; } + /** + * This method determines what happens when the {@link Location} of + * this {@link EnergyNetProvider} is going to explode. + *
+ * Note: This method is called async. + * The actual block is still there but the Slimefun block data is removed. + * + * @param l + * The {@link Location} of this {@link EnergyNetProvider} + */ + default void onExplode(@Nonnull Location l) { + Slimefun.runSync(() -> { + l.getBlock().setType(Material.LAVA); + l.getWorld().createExplosion(l, 0F, false); + }); + } + } diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/networks/energy/EnergyNet.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/networks/energy/EnergyNet.java index cb7c2c910c..1b0bf1ce53 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/networks/energy/EnergyNet.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/networks/energy/EnergyNet.java @@ -254,10 +254,7 @@ private int tickAllGenerators(@Nonnull LongConsumer timings) { explodedBlocks.add(loc); BlockStorage.clearBlockInfo(loc); - Slimefun.runSync(() -> { - loc.getBlock().setType(Material.LAVA); - loc.getWorld().createExplosion(loc, 0F, false); - }); + provider.onExplode(loc); } else { supply = NumberUtils.flowSafeAddition(supply, energy); }