9
0
mirror of https://github.com/Xiao-MoMi/craft-engine.git synced 2025-12-27 02:49:15 +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

@@ -17,6 +17,7 @@ items:
place: minecraft:block.bamboo_wood.place
placement:
ground:
loot-spawn-offset: 0.5,0.5,0
rules:
# ANY / FOUR / EIGHT / SIXTEEN / NORTH / EAST / WEST / SOUTH
rotation: FOUR
@@ -61,6 +62,7 @@ items:
place: minecraft:block.lantern.place
placement:
ground:
loot-spawn-offset: 0,0.2,0
rules:
rotation: ANY
alignment: QUARTER
@@ -111,6 +113,7 @@ items:
place: minecraft:block.bamboo_wood.place
placement:
ground:
loot-spawn-offset: 0,0.4,0
rules:
rotation: ANY
alignment: ANY

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()) {

View File

@@ -4,6 +4,7 @@ import net.momirealms.craftengine.core.loot.LootTable;
import net.momirealms.craftengine.core.util.Key;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.joml.Vector3f;
import java.util.EnumMap;
import java.util.Optional;
@@ -60,6 +61,7 @@ public class CustomFurniture {
HitBox[] hitBoxes,
RotationRule rotationRule,
AlignmentRule alignmentRule,
Optional<ExternalModel> externalModel) {
Optional<ExternalModel> externalModel,
Optional<Vector3f> dropOffset) {
}
}