mirror of
https://github.com/StarWishsama/Slimefun4.git
synced 2024-09-19 19:25:48 +00:00
Fixed vanilla sensitive blocks
This commit is contained in:
parent
7a65ea940a
commit
6a4b1fe794
@ -10,10 +10,13 @@ import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
|
||||
import io.github.thebusybiscuit.slimefun4.api.MinecraftVersion;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.block.BlockState;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
@ -170,6 +173,8 @@ public class BlockListener implements Listener {
|
||||
callBlockHandler(e, item, drops, sfItem);
|
||||
|
||||
dropItems(e, drops);
|
||||
|
||||
checkForSensitiveBlocks(e.getBlock(), 0, e.isDropItems());
|
||||
}
|
||||
}
|
||||
|
||||
@ -283,6 +288,59 @@ public class BlockListener implements Listener {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This method checks recursively for any sensitive blocks
|
||||
* that are no longer supported due to this block breaking
|
||||
*
|
||||
* @param block
|
||||
* The {@link Block} in question
|
||||
* @param count
|
||||
* The amount of times this has been recursively called
|
||||
*/
|
||||
@ParametersAreNonnullByDefault
|
||||
private void checkForSensitiveBlocks(Block block, Integer count, boolean isDropItems) {
|
||||
if (count >= Bukkit.getServer().getMaxChainedNeighborUpdates()) {
|
||||
return;
|
||||
}
|
||||
|
||||
BlockState state = block.getState();
|
||||
block.setType(Material.AIR, false);
|
||||
for (BlockFace face : CARDINAL_BLOCKFACES) {
|
||||
if (!isSupported(block.getRelative(face).getBlockData(), block.getRelative(face))) {
|
||||
Block relative = block.getRelative(face);
|
||||
if (!isDropItems) {
|
||||
for (ItemStack drop : relative.getDrops()) {
|
||||
block.getWorld().dropItemNaturally(relative.getLocation(), drop);
|
||||
}
|
||||
}
|
||||
checkForSensitiveBlocks(relative, ++count, isDropItems);
|
||||
}
|
||||
}
|
||||
block.setBlockData(state.getBlockData(), false);
|
||||
state.update(true, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* This method checks if the {@link BlockData} would be
|
||||
* supported at the given {@link Block}.
|
||||
*
|
||||
* @param blockData
|
||||
* The {@link BlockData} to check
|
||||
* @param block
|
||||
* The {@link Block} the {@link BlockData} would be at
|
||||
* @return
|
||||
* Whether the {@link BlockData} would be supported at the given {@link Block}
|
||||
*/
|
||||
@ParametersAreNonnullByDefault
|
||||
private boolean isSupported(BlockData blockData, Block block) {
|
||||
if (Slimefun.getMinecraftVersion().isAtLeast(MinecraftVersion.MINECRAFT_1_19)) {
|
||||
return blockData.isSupported(block);
|
||||
} else {
|
||||
// TODO: Make 1.16-1.18 version. BlockData::isSupported is 1.19+.
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
private int getBonusDropsWithFortune(@Nullable ItemStack item, @Nonnull Block b) {
|
||||
int amount = 1;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user