Skip to content

Commit

Permalink
Merge from upstream
Browse files Browse the repository at this point in the history
  • Loading branch information
mcchampions committed Aug 8, 2024
2 parents 0ec914b + 6e1a7cf commit f840550
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,6 @@ public ToolUseHandler getItemHandler() {
return (e, tool, fortune, drops) -> {
Player p = e.getPlayer();
Block b = e.getBlock();

SlimefunItem sfItem = StorageCacheUtils.getSfItem(b.getLocation());
if (e.getPlayer().getGameMode() == GameMode.CREATIVE &&
(sfItem == null || sfItem.useVanillaBlockBreaking())) {
drops.addAll(b.getDrops(tool));
}
if (!p.isSneaking()) {
b.getWorld().createExplosion(b.getLocation(), 0);
SoundEffect.EXPLOSIVE_TOOL_EXPLODE_SOUND.playAt(b);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.xzavier0722.mc.plugin.slimefun4.storage.callback.IAsyncReadCallback;
import com.xzavier0722.mc.plugin.slimefun4.storage.controller.SlimefunBlockData;
import com.xzavier0722.mc.plugin.slimefun4.storage.util.StorageCacheUtils;
import io.github.bakedlibs.dough.protection.Interaction;
import io.github.thebusybiscuit.slimefun4.api.MinecraftVersion;
import io.github.thebusybiscuit.slimefun4.api.events.ExplosiveToolBreakBlocksEvent;
import io.github.thebusybiscuit.slimefun4.api.events.SlimefunBlockBreakEvent;
Expand All @@ -19,6 +20,7 @@
import io.github.thebusybiscuit.slimefun4.utils.compatibility.VersionedEnchantment;
import io.github.thebusybiscuit.slimefun4.utils.tags.SlimefunTag;
import org.bukkit.Bukkit;
import org.bukkit.GameMode;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
Expand Down Expand Up @@ -109,7 +111,7 @@ public void onBlockPlace(BlockPlaceEvent e) {
e.setCancelled(true);
} else {
if (e.getBlock().getBlockData() instanceof Rotatable rotatable
&& !(rotatable.getRotation() == BlockFace.UP || rotatable.getRotation() == BlockFace.DOWN)) {
&& !(rotatable.getRotation() == BlockFace.UP || rotatable.getRotation() == BlockFace.DOWN)) {
BlockFace rotation = null;

if (sfItem instanceof NotCardinallyRotatable && sfItem instanceof NotDiagonallyRotatable) {
Expand Down Expand Up @@ -163,11 +165,11 @@ public void onBlockBreak(BlockBreakEvent e) {
var heldItem = e.getPlayer().getInventory().getItemInMainHand();
var block = e.getBlock();
var blockData = StorageCacheUtils.getBlock(block.getLocation());
var sfItem = SlimefunItem.getById(blockData.getSfId());

// If there is a Slimefun Block here, call our BreakEvent and, if cancelled, cancel this event
// and return
if (blockData != null) {
var sfItem = SlimefunItem.getById(blockData.getSfId());
SlimefunBlockBreakEvent breakEvent =
new SlimefunBlockBreakEvent(e.getPlayer(), heldItem, e.getBlock(), sfItem);
Bukkit.getPluginManager().callEvent(breakEvent);
Expand All @@ -191,7 +193,7 @@ public void onBlockBreak(BlockBreakEvent e) {
checkForSensitiveBlockAbove(e.getPlayer(), e.getBlock(), heldItem);

if (blockData == null || blockData.isPendingRemove()) {
dropItems(e, drops);
dropItems(e, heldItem, block, sfItem, drops);
return;
}

Expand All @@ -210,7 +212,7 @@ public void onBlockBreak(BlockBreakEvent e) {
return;
}
e.setDropItems(true);
dropItems(e, drops);
dropItems(e, heldItem, block, sfItem, drops);
},
true);
return;
Expand All @@ -220,7 +222,7 @@ public void onBlockBreak(BlockBreakEvent e) {
if (e.isCancelled()) {
blockData.setPendingRemove(false);
}
dropItems(e, drops);
dropItems(e, heldItem, block, sfItem, drops);

// Checks for vanilla sensitive blocks everywhere
// checkForSensitiveBlocks(e.getBlock(), 0, e.isDropItems());
Expand Down Expand Up @@ -255,13 +257,20 @@ private void callBlockHandler(BlockBreakEvent e, ItemStack item, List<ItemStack>
}
}

private void dropItems(BlockBreakEvent e, List<ItemStack> drops) {
private void dropItems(
BlockBreakEvent e, ItemStack item, Block block, @Nullable SlimefunItem sfBlock, List<ItemStack> drops) {
if (!drops.isEmpty()) {
// Fixes #2560
if (e.isDropItems()) {
// Disable normal block drops
e.setDropItems(false);

// Fixes #4051
if (sfBlock == null) {
block.breakNaturally(item);
}

// The list only contains other drops, not those from the block itself, so we still need to handle those
for (ItemStack drop : drops) {
// Prevent null or air from being dropped
if (drop != null && drop.getType() != Material.AIR) {
Expand Down Expand Up @@ -304,7 +313,7 @@ private void checkForSensitiveBlockAbove(Player player, Block block, ItemStack i
sfItem.callItemHandler(
BlockBreakHandler.class, handler -> handler.onPlayerBreak(dummyEvent, item, drops));
controller.removeBlock(loc);
dropItems(dummyEvent, drops);
dropItems(dummyEvent, item, block, sfItem, drops);
} else {
blockData.setPendingRemove(true);
controller.loadBlockDataAsync(blockData, new IAsyncReadCallback<>() {
Expand All @@ -318,7 +327,7 @@ public void onResult(SlimefunBlockData result) {
sfItem.callItemHandler(
BlockBreakHandler.class, handler -> handler.onPlayerBreak(dummyEvent, item, drops));
controller.removeBlock(loc);
dropItems(dummyEvent, drops);
dropItems(dummyEvent, item, block, sfItem, drops);
}
});
}
Expand Down Expand Up @@ -367,12 +376,9 @@ private void checkForSensitiveBlocks(Block block, Integer count, boolean isDropI
* 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}
* @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}
*/
private boolean isSupported(BlockData blockData, Block block) {
if (Slimefun.getMinecraftVersion().isAtLeast(MinecraftVersion.MINECRAFT_1_19)) {
Expand Down

0 comments on commit f840550

Please sign in to comment.