mirror of
https://github.com/Xiao-MoMi/craft-engine.git
synced 2025-12-30 20:39:10 +00:00
refactor furniture framework
This commit is contained in:
@@ -0,0 +1,60 @@
|
||||
package net.momirealms.craftengine.core.entity.furniture;
|
||||
|
||||
import net.momirealms.craftengine.core.util.Key;
|
||||
import org.joml.Quaternionf;
|
||||
import org.joml.Vector3f;
|
||||
|
||||
public abstract class AbstractFurnitureElement implements FurnitureElement {
|
||||
private final Key item;
|
||||
private final Billboard billboard;
|
||||
private final ItemDisplayContext transform;
|
||||
private final Vector3f scale;
|
||||
private final Vector3f translation;
|
||||
private final Vector3f offset;
|
||||
private final Quaternionf rotation;
|
||||
|
||||
public AbstractFurnitureElement(Key item, Billboard billboard, ItemDisplayContext transform, Vector3f scale, Vector3f translation, Vector3f offset, Quaternionf rotation) {
|
||||
this.billboard = billboard;
|
||||
this.transform = transform;
|
||||
this.scale = scale;
|
||||
this.translation = translation;
|
||||
this.item = item;
|
||||
this.rotation = rotation;
|
||||
this.offset = offset;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Quaternionf rotation() {
|
||||
return rotation;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Key item() {
|
||||
return item;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Billboard billboard() {
|
||||
return billboard;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemDisplayContext transform() {
|
||||
return transform;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Vector3f scale() {
|
||||
return scale;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Vector3f translation() {
|
||||
return translation;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Vector3f position() {
|
||||
return offset;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package net.momirealms.craftengine.core.entity.furniture;
|
||||
|
||||
public abstract class AbstractHitBox implements HitBox {
|
||||
protected final Seat[] seats;
|
||||
|
||||
public AbstractHitBox(Seat[] seats) {
|
||||
this.seats = seats;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Seat[] seats() {
|
||||
return seats;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
package net.momirealms.craftengine.core.entity.furniture;
|
||||
|
||||
import org.joml.Vector3f;
|
||||
|
||||
public class Collider {
|
||||
private final Vector3f position;
|
||||
private final double width;
|
||||
private final double height;
|
||||
private final boolean canBeHitByProjectile;
|
||||
|
||||
public Collider(boolean canBeHitByProjectile, double height, Vector3f position, double width) {
|
||||
this.canBeHitByProjectile = canBeHitByProjectile;
|
||||
this.height = height;
|
||||
this.position = position;
|
||||
this.width = width;
|
||||
}
|
||||
|
||||
public boolean canBeHitByProjectile() {
|
||||
return canBeHitByProjectile;
|
||||
}
|
||||
|
||||
public double height() {
|
||||
return height;
|
||||
}
|
||||
|
||||
public Vector3f position() {
|
||||
return position;
|
||||
}
|
||||
|
||||
public double width() {
|
||||
return width;
|
||||
}
|
||||
}
|
||||
@@ -11,6 +11,7 @@ public class CustomFurniture {
|
||||
private final Key id;
|
||||
private final FurnitureSettings settings;
|
||||
private final EnumMap<AnchorType, Placement> placements;
|
||||
private final AnchorType anyType;
|
||||
@Nullable
|
||||
private final LootTable<?> lootTable;
|
||||
|
||||
@@ -22,6 +23,7 @@ public class CustomFurniture {
|
||||
this.settings = settings;
|
||||
this.placements = placements;
|
||||
this.lootTable = lootTable;
|
||||
this.anyType = placements.keySet().stream().findFirst().orElse(null);
|
||||
}
|
||||
|
||||
public Key id() {
|
||||
@@ -42,7 +44,7 @@ public class CustomFurniture {
|
||||
}
|
||||
|
||||
public AnchorType getAnyPlacement() {
|
||||
return placements.keySet().stream().findFirst().orElse(null);
|
||||
return this.anyType;
|
||||
}
|
||||
|
||||
public boolean isAllowedPlacement(AnchorType anchorType) {
|
||||
@@ -55,19 +57,25 @@ public class CustomFurniture {
|
||||
|
||||
public static class Placement {
|
||||
private final FurnitureElement[] elements;
|
||||
private final HitBox[] hitbox;
|
||||
private final HitBox[] hitboxes;
|
||||
private final Collider[] colliders;
|
||||
private final RotationRule rotationRule;
|
||||
private final AlignmentRule alignmentRule;
|
||||
|
||||
public Placement(FurnitureElement[] elements, HitBox[] hitbox, RotationRule rotationRule, AlignmentRule alignmentRule) {
|
||||
public Placement(FurnitureElement[] elements, HitBox[] hitboxes, Collider[] colliders, RotationRule rotationRule, AlignmentRule alignmentRule) {
|
||||
this.elements = elements;
|
||||
this.hitbox = hitbox;
|
||||
this.hitboxes = hitboxes;
|
||||
this.colliders = colliders;
|
||||
this.rotationRule = rotationRule;
|
||||
this.alignmentRule = alignmentRule;
|
||||
}
|
||||
|
||||
public HitBox[] hitbox() {
|
||||
return hitbox;
|
||||
public HitBox[] hitboxes() {
|
||||
return hitboxes;
|
||||
}
|
||||
|
||||
public Collider[] colliders() {
|
||||
return colliders;
|
||||
}
|
||||
|
||||
public FurnitureElement[] elements() {
|
||||
|
||||
@@ -4,50 +4,22 @@ import net.momirealms.craftengine.core.util.Key;
|
||||
import org.joml.Quaternionf;
|
||||
import org.joml.Vector3f;
|
||||
|
||||
public class FurnitureElement {
|
||||
private final Key item;
|
||||
private final Billboard billboard;
|
||||
private final ItemDisplayContext transform;
|
||||
private final Vector3f scale;
|
||||
private final Vector3f translation;
|
||||
private final Vector3f offset;
|
||||
private final Quaternionf rotation;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public FurnitureElement(Key item, Billboard billboard, ItemDisplayContext transform, Vector3f scale, Vector3f translation, Vector3f offset, Quaternionf rotation) {
|
||||
this.billboard = billboard;
|
||||
this.transform = transform;
|
||||
this.scale = scale;
|
||||
this.translation = translation;
|
||||
this.item = item;
|
||||
this.rotation = rotation;
|
||||
this.offset = offset;
|
||||
}
|
||||
public interface FurnitureElement {
|
||||
Quaternionf rotation();
|
||||
|
||||
public Quaternionf rotation() {
|
||||
return rotation;
|
||||
}
|
||||
Key item();
|
||||
|
||||
public Key item() {
|
||||
return item;
|
||||
}
|
||||
Billboard billboard();
|
||||
|
||||
public Billboard billboard() {
|
||||
return billboard;
|
||||
}
|
||||
ItemDisplayContext transform();
|
||||
|
||||
public ItemDisplayContext transform() {
|
||||
return transform;
|
||||
}
|
||||
Vector3f scale();
|
||||
|
||||
public Vector3f scale() {
|
||||
return scale;
|
||||
}
|
||||
Vector3f translation();
|
||||
|
||||
public Vector3f translation() {
|
||||
return translation;
|
||||
}
|
||||
Vector3f position();
|
||||
|
||||
public Vector3f offset() {
|
||||
return offset;
|
||||
}
|
||||
void addSpawnPackets(int entityId, double x, double y, double z, float yaw, Consumer<Object> packets);
|
||||
}
|
||||
|
||||
@@ -1,33 +1,14 @@
|
||||
package net.momirealms.craftengine.core.entity.furniture;
|
||||
|
||||
import org.joml.Vector3f;
|
||||
import net.momirealms.craftengine.core.util.Key;
|
||||
|
||||
public class HitBox {
|
||||
private final Vector3f position;
|
||||
private final Vector3f size;
|
||||
private final Seat[] seats;
|
||||
private final boolean responsive;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public HitBox(Vector3f position, Vector3f size, Seat[] seats, boolean responsive) {
|
||||
this.position = position;
|
||||
this.size = size;
|
||||
this.seats = seats;
|
||||
this.responsive = responsive;
|
||||
}
|
||||
public interface HitBox {
|
||||
|
||||
public boolean responsive() {
|
||||
return responsive;
|
||||
}
|
||||
Key type();
|
||||
|
||||
public Seat[] seats() {
|
||||
return seats;
|
||||
}
|
||||
void addSpawnPackets(int entityId, double x, double y, double z, float yaw, Consumer<Object> packets);
|
||||
|
||||
public Vector3f offset() {
|
||||
return position;
|
||||
}
|
||||
|
||||
public Vector3f size() {
|
||||
return size;
|
||||
}
|
||||
Seat[] seats();
|
||||
}
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
package net.momirealms.craftengine.core.entity.furniture;
|
||||
|
||||
import net.momirealms.craftengine.core.util.MiscUtils;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public interface HitBoxFactory {
|
||||
|
||||
HitBox create(Map<String, Object> arguments);
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
static Seat[] getSeats(Map<String, Object> arguments) {
|
||||
List<String> seats = (List<String>) arguments.getOrDefault("seats", List.of());
|
||||
return seats.stream()
|
||||
.map(arg -> {
|
||||
String[] split = arg.split(" ");
|
||||
if (split.length == 1) return new Seat(MiscUtils.getVector3f(split[0]), 0, false);
|
||||
return new Seat(MiscUtils.getVector3f(split[0]), Float.parseFloat(split[1]), true);
|
||||
})
|
||||
.toArray(Seat[]::new);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
package net.momirealms.craftengine.core.entity.furniture;
|
||||
|
||||
import net.momirealms.craftengine.core.registry.BuiltInRegistries;
|
||||
import net.momirealms.craftengine.core.registry.Holder;
|
||||
import net.momirealms.craftengine.core.registry.Registries;
|
||||
import net.momirealms.craftengine.core.registry.WritableRegistry;
|
||||
import net.momirealms.craftengine.core.util.Key;
|
||||
import net.momirealms.craftengine.core.util.ResourceKey;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
public class HitBoxTypes {
|
||||
public static final Key INTERACTION = Key.of("minecraft:interaction");
|
||||
public static final Key SHULKER = Key.of("minecraft:shulker");
|
||||
|
||||
public static void register(Key key, HitBoxFactory factory) {
|
||||
Holder.Reference<HitBoxFactory> holder = ((WritableRegistry<HitBoxFactory>) BuiltInRegistries.HITBOX_FACTORY)
|
||||
.registerForHolder(new ResourceKey<>(Registries.HITBOX_FACTORY.location(), key));
|
||||
holder.bindValue(factory);
|
||||
}
|
||||
|
||||
public static HitBox fromMap(Map<String, Object> arguments) {
|
||||
Key type = Optional.ofNullable((String) arguments.get("type")).map(Key::of).orElse(HitBoxTypes.INTERACTION);
|
||||
HitBoxFactory factory = BuiltInRegistries.HITBOX_FACTORY.getValue(type);
|
||||
if (factory == null) {
|
||||
throw new IllegalArgumentException("Unknown hitbox type: " + type);
|
||||
}
|
||||
return factory.create(arguments);
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,6 @@
|
||||
package net.momirealms.craftengine.core.plugin.locale;
|
||||
|
||||
import net.momirealms.craftengine.core.pack.Pack;
|
||||
import net.momirealms.craftengine.core.plugin.Plugin;
|
||||
import net.momirealms.craftengine.core.util.Key;
|
||||
|
||||
import java.nio.file.Path;
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package net.momirealms.craftengine.core.plugin.locale;
|
||||
|
||||
import net.momirealms.craftengine.core.block.BlockStateParser;
|
||||
import net.momirealms.craftengine.core.block.BlockStateVariantProvider;
|
||||
import net.momirealms.craftengine.core.block.CustomBlock;
|
||||
import net.momirealms.craftengine.core.block.ImmutableBlockState;
|
||||
import net.momirealms.craftengine.core.plugin.CraftEngine;
|
||||
|
||||
@@ -3,7 +3,6 @@ package net.momirealms.craftengine.core.plugin.locale;
|
||||
import net.kyori.adventure.key.Key;
|
||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||
import net.kyori.adventure.translation.Translator;
|
||||
import net.momirealms.craftengine.core.plugin.CraftEngine;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
@@ -3,6 +3,7 @@ package net.momirealms.craftengine.core.registry;
|
||||
import net.momirealms.craftengine.core.block.CustomBlock;
|
||||
import net.momirealms.craftengine.core.block.behavior.BlockBehaviorFactory;
|
||||
import net.momirealms.craftengine.core.block.properties.PropertyFactory;
|
||||
import net.momirealms.craftengine.core.entity.furniture.HitBoxFactory;
|
||||
import net.momirealms.craftengine.core.item.behavior.ItemBehaviorFactory;
|
||||
import net.momirealms.craftengine.core.item.recipe.CustomSmithingTransformRecipe;
|
||||
import net.momirealms.craftengine.core.item.recipe.RecipeFactory;
|
||||
@@ -45,6 +46,7 @@ public class BuiltInRegistries {
|
||||
public static final Registry<PathMatcherFactory> PATH_MATCHER_FACTORY = createRegistry(Registries.PATH_MATCHER_FACTORY);
|
||||
public static final Registry<ResolutionFactory> RESOLUTION_FACTORY = createRegistry(Registries.RESOLUTION_FACTORY);
|
||||
public static final Registry<CustomSmithingTransformRecipe.ItemDataProcessor.Factory> SMITHING_RESULT_PROCESSOR_FACTORY = createRegistry(Registries.SMITHING_RESULT_PROCESSOR_FACTORY);
|
||||
public static final Registry<HitBoxFactory> HITBOX_FACTORY = createRegistry(Registries.HITBOX_FACTORY);
|
||||
|
||||
private static <T> Registry<T> createRegistry(ResourceKey<? extends Registry<T>> key) {
|
||||
return new MappedRegistry<>(key);
|
||||
|
||||
@@ -3,6 +3,7 @@ package net.momirealms.craftengine.core.registry;
|
||||
import net.momirealms.craftengine.core.block.CustomBlock;
|
||||
import net.momirealms.craftengine.core.block.behavior.BlockBehaviorFactory;
|
||||
import net.momirealms.craftengine.core.block.properties.PropertyFactory;
|
||||
import net.momirealms.craftengine.core.entity.furniture.HitBoxFactory;
|
||||
import net.momirealms.craftengine.core.item.behavior.ItemBehaviorFactory;
|
||||
import net.momirealms.craftengine.core.item.recipe.CustomSmithingTransformRecipe;
|
||||
import net.momirealms.craftengine.core.item.recipe.RecipeFactory;
|
||||
@@ -46,4 +47,5 @@ public class Registries {
|
||||
public static final ResourceKey<Registry<PathMatcherFactory>> PATH_MATCHER_FACTORY = new ResourceKey<>(ROOT_REGISTRY, Key.withDefaultNamespace("path_matcher_factory"));
|
||||
public static final ResourceKey<Registry<ResolutionFactory>> RESOLUTION_FACTORY = new ResourceKey<>(ROOT_REGISTRY, Key.withDefaultNamespace("resolution_factory"));
|
||||
public static final ResourceKey<Registry<CustomSmithingTransformRecipe.ItemDataProcessor.Factory>> SMITHING_RESULT_PROCESSOR_FACTORY = new ResourceKey<>(ROOT_REGISTRY, Key.withDefaultNamespace("smithing_result_processor_factory"));
|
||||
public static final ResourceKey<Registry<HitBoxFactory>> HITBOX_FACTORY = new ResourceKey<>(ROOT_REGISTRY, Key.withDefaultNamespace("hitbox_factory"));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user