Skip to content

Commit

Permalink
Merge from upstream
Browse files Browse the repository at this point in the history
  • Loading branch information
mcchampions committed Jan 13, 2025
2 parents 23c7998 + 5fcccb8 commit eb965cc
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 26 deletions.
11 changes: 10 additions & 1 deletion src/main/java/city/norain/slimefun4/utils/StringUtil.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package city.norain.slimefun4.utils;

import io.github.thebusybiscuit.slimefun4.api.items.SlimefunItem;
import org.bukkit.inventory.ItemStack;

public class StringUtil {
Expand All @@ -8,6 +9,14 @@ public static String itemStackToString(ItemStack item) {
return "null";
}

return String.format("ItemStack (type=%s, amount=%d)", item.getType(), item.getAmount());
SlimefunItem sfItem = SlimefunItem.getByItem(item);

if (sfItem != null) {
return String.format(
"ItemStack [sfId=%s (Addon=%s)] (type=%s, amount=%d)",
sfItem.getId(), sfItem.getAddon().getName(), item.getType(), item.getAmount());
} else {
return String.format("ItemStack (type=%s, amount=%d)", item.getType(), item.getAmount());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -112,27 +112,9 @@ public void onBlockPlace(BlockPlaceEvent e) {
e.setCancelled(true);
} else {
Block block = e.getBlock();
if (block.getBlockData() instanceof Rotatable rotatable
&& !(rotatable.getRotation() == BlockFace.UP || rotatable.getRotation() == BlockFace.DOWN)) {
BlockFace rotation = null;

if (sfItem instanceof NotCardinallyRotatable && sfItem instanceof NotDiagonallyRotatable) {
rotation = BlockFace.NORTH;
} else if (sfItem instanceof NotRotatable notRotatable) {
rotation = notRotatable.getRotation();
} else if (sfItem instanceof NotCardinallyRotatable notRotatable) {
rotation = notRotatable.getRotation(Location.normalizeYaw(
e.getPlayer().getLocation().getYaw()));
} else if (sfItem instanceof NotDiagonallyRotatable notRotatable) {
rotation = notRotatable.getRotation(Location.normalizeYaw(
e.getPlayer().getLocation().getYaw()));
}

if (rotation != null) {
rotatable.setRotation(rotation);
block.setBlockData(rotatable);
}
}
optimizePlacement(sfItem, block, e.getPlayer().getLocation());

SlimefunBlockPlaceEvent placeEvent = new SlimefunBlockPlaceEvent(e.getPlayer(), item, block, sfItem);
Bukkit.getPluginManager().callEvent(placeEvent);

Expand All @@ -156,7 +138,6 @@ public void onBlockPlace(BlockPlaceEvent e) {
.getBlockDataController()
.createBlock(block.getLocation(), sfItem.getId());
}

sfItem.callItemHandler(BlockPlaceHandler.class, handler -> handler.onPlayerPlace(e));
}
}
Expand Down Expand Up @@ -354,10 +335,8 @@ public void onResult(SlimefunBlockData result) {
* 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
* @param block The {@link Block} in question
* @param count The amount of times this has been recursively called
*/
/*
private void checkForSensitiveBlocks(Block block, Integer count, boolean isDropItems) {
Expand Down Expand Up @@ -408,4 +387,27 @@ private static int getBonusDropsWithFortune(@Nullable ItemStack item, Block b) {

return amount;
}

// 美化可旋转类 (如头颅) 物品放置
private static void optimizePlacement(SlimefunItem sfItem, Block block, Location l) {
if (block.getBlockData() instanceof Rotatable rotatable
&& !(rotatable.getRotation() == BlockFace.UP || rotatable.getRotation() == BlockFace.DOWN)) {
BlockFace rotation = null;

if (sfItem instanceof NotCardinallyRotatable && sfItem instanceof NotDiagonallyRotatable) {
rotation = BlockFace.NORTH;
} else if (sfItem instanceof NotRotatable notRotatable) {
rotation = notRotatable.getRotation();
} else if (sfItem instanceof NotCardinallyRotatable notRotatable) {
rotation = notRotatable.getRotation(Location.normalizeYaw(l.getYaw()));
} else if (sfItem instanceof NotDiagonallyRotatable notRotatable) {
rotation = notRotatable.getRotation(Location.normalizeYaw(l.getYaw()));
}

if (rotation != null) {
rotatable.setRotation(rotation);
block.setBlockData(rotatable);
}
}
}
}

0 comments on commit eb965cc

Please sign in to comment.