9
0
mirror of https://github.com/Xiao-MoMi/craft-engine.git synced 2025-12-31 21:06:31 +00:00

为家具添加自定义掉落物位置

This commit is contained in:
XiaoMoMi
2025-05-09 02:34:23 +08:00
parent ef1caaa05a
commit 81cf2055e4
5 changed files with 26 additions and 6 deletions

View File

@@ -263,7 +263,7 @@ public final class CraftEngineFurniture {
@Nullable net.momirealms.craftengine.core.entity.player.Player player,
boolean dropLoot,
boolean playSound) {
Location location = loadedFurniture.location();
Location location = loadedFurniture.dropLocation();
loadedFurniture.destroy();
LootTable<ItemStack> lootTable = (LootTable<ItemStack>) loadedFurniture.config().lootTable();
Vec3d vec3d = LocationUtils.toVec3d(location);

View File

@@ -124,6 +124,8 @@ public class BukkitFurnitureManager extends AbstractFurnitureManager {
AnchorType anchorType = AnchorType.valueOf(entry.getKey().toUpperCase(Locale.ENGLISH));
Map<String, Object> placementArguments = MiscUtils.castToMap(entry.getValue(), true);
Optional<Vector3f> optionalLootSpawnOffset = Optional.ofNullable(placementArguments.get("loot-spawn-offset")).map(it -> MiscUtils.getAsVector3f(it, "loot-spawn-offset"));
// furniture display elements
List<FurnitureElement> elements = new ArrayList<>();
List<Map<String, Object>> elementConfigs = (List<Map<String, Object>>) placementArguments.getOrDefault("elements", List.of());
@@ -178,7 +180,8 @@ public class BukkitFurnitureManager extends AbstractFurnitureManager {
hitboxes.toArray(new HitBox[0]),
rotationRule,
alignmentRule,
externalModel
externalModel,
optionalLootSpawnOffset
));
} else {
placements.put(anchorType, new CustomFurniture.Placement(
@@ -186,7 +189,8 @@ public class BukkitFurnitureManager extends AbstractFurnitureManager {
hitboxes.toArray(new HitBox[0]),
RotationRule.ANY,
AlignmentRule.CENTER,
externalModel
externalModel,
optionalLootSpawnOffset
));
}
}

View File

@@ -75,9 +75,9 @@ public class LoadedFurniture implements Furniture {
} catch (Exception e) {
CraftEngine.instance().logger().warn("Failed to load external model for furniture " + id, e);
}
hasExternalModel = true;
this.hasExternalModel = true;
} else {
hasExternalModel = false;
this.hasExternalModel = false;
}
float yaw = this.location.getYaw();
@@ -176,6 +176,17 @@ public class LoadedFurniture implements Furniture {
return baseEntity().isValid();
}
@NotNull
public Location dropLocation() {
Optional<Vector3f> dropOffset = config().getPlacement(this.anchorType).dropOffset();
if (dropOffset.isEmpty()) {
return location();
}
Quaternionf conjugated = QuaternionUtils.toQuaternionf(0, Math.toRadians(180 - this.location.getYaw()), 0).conjugate();
Vector3f offset = conjugated.transform(new Vector3f(dropOffset.get()));
return new Location(this.location.getWorld(), this.location.getX() + offset.x, this.location.getY() + offset.y, this.location.getZ() - offset.z);
}
@Override
public void destroy() {
if (!isValid()) {