mirror of
https://github.com/Xiao-MoMi/craft-engine.git
synced 2026-01-04 15:41:38 +00:00
@@ -8,5 +8,13 @@ public enum EquipmentSlot {
|
||||
BODY,
|
||||
MAIN_HAND,
|
||||
OFF_HAND,
|
||||
SADDLE
|
||||
SADDLE;
|
||||
|
||||
public boolean isHand() {
|
||||
return this == MAIN_HAND || this == OFF_HAND;
|
||||
}
|
||||
|
||||
public boolean isPlayerArmor() {
|
||||
return this == HEAD || this == CHEST || this == LEGS || this == FEET;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
package net.momirealms.craftengine.core.entity.furniture;
|
||||
|
||||
import org.joml.Vector3f;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
public abstract class AbstractSeat implements Seat {
|
||||
protected final Vector3f offset;
|
||||
protected final float yaw;
|
||||
|
||||
public AbstractSeat(Vector3f offset, float yaw) {
|
||||
this.offset = offset;
|
||||
this.yaw = yaw;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Vector3f offset() {
|
||||
return offset;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float yaw() {
|
||||
return yaw;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (!(o instanceof AbstractSeat seat)) return false;
|
||||
return Float.compare(yaw, seat.yaw()) == 0 && offset.equals(seat.offset());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int result = Objects.hash(offset);
|
||||
result = 31 * result + Float.hashCode(yaw);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@@ -13,11 +13,7 @@ public interface HitBoxFactory {
|
||||
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.getAsVector3f(split[0], "seats"), 0, false);
|
||||
return new Seat(MiscUtils.getAsVector3f(split[0], "seats"), Float.parseFloat(split[1]), true);
|
||||
})
|
||||
.map(SeatType::fromString)
|
||||
.toArray(Seat[]::new);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,23 +1,14 @@
|
||||
package net.momirealms.craftengine.core.entity.furniture;
|
||||
|
||||
import net.momirealms.craftengine.core.entity.player.Player;
|
||||
import net.momirealms.craftengine.core.entity.seat.SeatEntity;
|
||||
import org.joml.Vector3f;
|
||||
|
||||
import java.util.Objects;
|
||||
public interface Seat {
|
||||
|
||||
public record Seat(Vector3f offset, float yaw, boolean limitPlayerRotation) {
|
||||
SeatEntity spawn(Player player, Furniture furniture);
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (!(o instanceof Seat seat)) return false;
|
||||
return Float.compare(yaw, seat.yaw) == 0 && Objects.equals(offset, seat.offset) && limitPlayerRotation == seat.limitPlayerRotation;
|
||||
}
|
||||
Vector3f offset();
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int result = Objects.hashCode(offset);
|
||||
result = 31 * result + Float.hashCode(yaw);
|
||||
result = 31 * result + Boolean.hashCode(limitPlayerRotation);
|
||||
return result;
|
||||
}
|
||||
float yaw();
|
||||
}
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
package net.momirealms.craftengine.core.entity.furniture;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface SeatFactory {
|
||||
|
||||
Seat create(List<String> args);
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
package net.momirealms.craftengine.core.entity.furniture;
|
||||
|
||||
import net.momirealms.craftengine.core.plugin.locale.LocalizedResourceConfigException;
|
||||
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.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class SeatType {
|
||||
public static final Key SIT = Key.of("craftengine:sit");
|
||||
public static final Key LAY = Key.of("craftengine:lay");
|
||||
public static final Key CRAWL = Key.of("craftengine:crawl");
|
||||
|
||||
public static void register(Key key, SeatFactory factory) {
|
||||
Holder.Reference<SeatFactory> holder = ((WritableRegistry<SeatFactory>) BuiltInRegistries.SEAT_FACTORY)
|
||||
.registerForHolder(new ResourceKey<>(Registries.SEAT_FACTORY.location(), key));
|
||||
holder.bindValue(factory);
|
||||
}
|
||||
|
||||
public static Seat fromString(String s) {
|
||||
int lastSpaceIndex = s.lastIndexOf(' ');
|
||||
|
||||
Key type = SIT;
|
||||
SeatFactory factory;
|
||||
String numericPart;
|
||||
|
||||
if (lastSpaceIndex != -1) {
|
||||
numericPart = s.substring(lastSpaceIndex + 1);
|
||||
try {
|
||||
Float.parseFloat(numericPart);
|
||||
} catch (NumberFormatException e) {
|
||||
type = Key.withDefaultNamespace(numericPart, "craftengine");
|
||||
s = s.substring(0, lastSpaceIndex);
|
||||
lastSpaceIndex = s.lastIndexOf(' ');
|
||||
}
|
||||
}
|
||||
|
||||
List<String> split = new ArrayList<>();
|
||||
int start = 0;
|
||||
while (lastSpaceIndex != -1) {
|
||||
split.add(s.substring(start, lastSpaceIndex));
|
||||
start = lastSpaceIndex + 1;
|
||||
lastSpaceIndex = s.indexOf(' ', start);
|
||||
}
|
||||
if (start < s.length()) {
|
||||
split.add(s.substring(start));
|
||||
}
|
||||
|
||||
factory = BuiltInRegistries.SEAT_FACTORY.getValue(type);
|
||||
if (factory == null) {
|
||||
throw new LocalizedResourceConfigException("warning.config.furniture.seat.invalid_type", type.toString());
|
||||
}
|
||||
return factory.create(split);
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,7 @@ package net.momirealms.craftengine.core.entity.player;
|
||||
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.momirealms.craftengine.core.entity.AbstractEntity;
|
||||
import net.momirealms.craftengine.core.entity.seat.SeatEntity;
|
||||
import net.momirealms.craftengine.core.item.Item;
|
||||
import net.momirealms.craftengine.core.plugin.context.CooldownData;
|
||||
import net.momirealms.craftengine.core.plugin.network.NetWorkUser;
|
||||
@@ -140,4 +141,8 @@ public abstract class Player extends AbstractEntity implements NetWorkUser {
|
||||
public abstract void clearPotionEffects();
|
||||
|
||||
public abstract CooldownData cooldown();
|
||||
|
||||
public abstract void setSeat(SeatEntity seatEntity);
|
||||
|
||||
public abstract SeatEntity seat();
|
||||
}
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
package net.momirealms.craftengine.core.entity.seat;
|
||||
|
||||
import net.momirealms.craftengine.core.entity.furniture.Furniture;
|
||||
import net.momirealms.craftengine.core.entity.player.Player;
|
||||
import net.momirealms.craftengine.core.plugin.network.EntityPacketHandler;
|
||||
import net.momirealms.craftengine.core.plugin.network.NetWorkUser;
|
||||
import org.joml.Vector3f;
|
||||
|
||||
public interface SeatEntity extends EntityPacketHandler {
|
||||
|
||||
void add(NetWorkUser to);
|
||||
|
||||
void dismount(Player player);
|
||||
|
||||
void onDismount(Player player);
|
||||
|
||||
void event(Player player, Object event);
|
||||
|
||||
void destroy();
|
||||
|
||||
boolean destroyed();
|
||||
|
||||
Furniture furniture();
|
||||
|
||||
Vector3f vector3f();
|
||||
|
||||
int playerID();
|
||||
}
|
||||
@@ -4,7 +4,7 @@ import it.unimi.dsi.fastutil.ints.IntList;
|
||||
|
||||
public interface EntityPacketHandler {
|
||||
|
||||
default boolean handleEntitiesRemove(IntList entityIds) {
|
||||
default boolean handleEntitiesRemove(NetWorkUser user, IntList entityIds) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -19,4 +19,10 @@ public interface EntityPacketHandler {
|
||||
|
||||
default void handleMove(NetWorkUser user, NMSPacketEvent event, Object packet) {
|
||||
}
|
||||
|
||||
default void handleSetEquipment(NetWorkUser user, ByteBufPacketEvent event, Object slots) {
|
||||
}
|
||||
|
||||
default void handleContainerSetSlot(NetWorkUser user, NMSPacketEvent event, Object packet) {
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ 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.entity.furniture.SeatFactory;
|
||||
import net.momirealms.craftengine.core.item.behavior.ItemBehaviorFactory;
|
||||
import net.momirealms.craftengine.core.item.recipe.CustomSmithingTransformRecipe;
|
||||
import net.momirealms.craftengine.core.item.recipe.RecipeFactory;
|
||||
@@ -68,6 +69,7 @@ public class BuiltInRegistries {
|
||||
public static final Registry<FunctionFactory<PlayerOptionalContext>> EVENT_FUNCTION_FACTORY = createRegistry(Registries.EVENT_FUNCTION_FACTORY);
|
||||
public static final Registry<ConditionFactory<PlayerOptionalContext>> EVENT_CONDITION_FACTORY = createRegistry(Registries.EVENT_CONDITION_FACTORY);
|
||||
public static final Registry<PlayerSelectorFactory<?>> PLAYER_SELECTOR_FACTORY = createRegistry(Registries.PLAYER_SELECTOR_FACTORY);
|
||||
public static final Registry<SeatFactory> SEAT_FACTORY = createRegistry(Registries.SEAT_FACTORY);
|
||||
|
||||
private static <T> Registry<T> createRegistry(ResourceKey<? extends Registry<T>> key) {
|
||||
return new MappedRegistry<>(key);
|
||||
|
||||
@@ -4,6 +4,7 @@ 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.entity.furniture.SeatFactory;
|
||||
import net.momirealms.craftengine.core.item.behavior.ItemBehaviorFactory;
|
||||
import net.momirealms.craftengine.core.item.recipe.CustomSmithingTransformRecipe;
|
||||
import net.momirealms.craftengine.core.item.recipe.RecipeFactory;
|
||||
@@ -69,4 +70,5 @@ public class Registries {
|
||||
public static final ResourceKey<Registry<FunctionFactory<PlayerOptionalContext>>> EVENT_FUNCTION_FACTORY = new ResourceKey<>(ROOT_REGISTRY, Key.withDefaultNamespace("event_function_factory"));
|
||||
public static final ResourceKey<Registry<ConditionFactory<PlayerOptionalContext>>> EVENT_CONDITION_FACTORY = new ResourceKey<>(ROOT_REGISTRY, Key.withDefaultNamespace("event_condition_factory"));
|
||||
public static final ResourceKey<Registry<PlayerSelectorFactory<?>>> PLAYER_SELECTOR_FACTORY = new ResourceKey<>(ROOT_REGISTRY, Key.withDefaultNamespace("player_selector"));
|
||||
public static final ResourceKey<Registry<SeatFactory>> SEAT_FACTORY = new ResourceKey<>(ROOT_REGISTRY, Key.withDefaultNamespace("seat_factory"));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user