9
0
mirror of https://github.com/Xiao-MoMi/craft-engine.git synced 2026-01-04 15:41:38 +00:00

优化家具转换器

This commit is contained in:
XiaoMoMi
2025-04-16 16:10:42 +08:00
parent 290cead04f
commit e26773d5ee
4 changed files with 46 additions and 23 deletions

View File

@@ -159,15 +159,16 @@ block:
furniture:
# Automatically remove outdated furniture entities when a chunk is loaded.
remove-invalid-furniture-on-chunk-load:
handle-invalid-furniture-on-chunk-load:
# Enable/disable the cleanup system
enable: false
# - When EMPTY: Remove ALL invalid furniture entities
# - When POPULATED: Only remove specified furniture types
# Example for targeted removal:
# list: [ "xxx:invalid_furniture", "yyy:broken_sofa" ]
list:
# Removes the specified invalid furniture
remove:
- "xxx:invalid_furniture"
# Converts the invalid furniture to a valid one
convert:
"xxx:invalid_furniture": "xxx:valid_furniture"
# Hide technical entities used for storing furniture metadata.
# NOTE:
# - These are INVISIBLE entities used internally for tracking furniture states

View File

@@ -349,6 +349,20 @@ public class BukkitFurnitureManager extends AbstractFurnitureManager {
public void handleBaseEntityLoadEarly(ItemDisplay display) {
String id = display.getPersistentDataContainer().get(FURNITURE_KEY, PersistentDataType.STRING);
if (id == null) return;
// Remove the entity if it's not a valid furniture
if (Config.handleInvalidFurniture()) {
String mapped = Config.furnitureMappings().get(id);
if (mapped != null) {
if (mapped.isEmpty()) {
display.remove();
return;
} else {
id = mapped;
display.getPersistentDataContainer().set(FURNITURE_KEY, PersistentDataType.STRING, id);
}
}
}
Key key = Key.of(id);
Optional<CustomFurniture> optionalFurniture = furnitureById(key);
if (optionalFurniture.isPresent()) {
@@ -357,13 +371,6 @@ public class BukkitFurnitureManager extends AbstractFurnitureManager {
if (previous != null) return;
LoadedFurniture furniture = addNewFurniture(display, customFurniture, getAnchorType(display, customFurniture));
furniture.initializeColliders(); // safely do it here
return;
}
// Remove the entity if it's not a valid furniture
if (Config.removeInvalidFurniture()) {
if (Config.furnitureToRemove().isEmpty() || Config.furnitureToRemove().contains(id)) {
display.remove();
}
}
}