mirror of
https://github.com/Xiao-MoMi/craft-engine.git
synced 2025-12-19 15:09:15 +00:00
优化座椅机制
This commit is contained in:
@@ -646,7 +646,7 @@ public abstract class AbstractBlockManager extends AbstractModelGenerator implem
|
||||
// 绑定行为
|
||||
for (ImmutableBlockState state : states) {
|
||||
if (isEntityBlock) {
|
||||
state.setBlockEntityType(entityBlockBehavior.blockEntityType());
|
||||
state.setBlockEntityType(entityBlockBehavior.blockEntityType(state));
|
||||
}
|
||||
state.setBehavior(blockBehavior);
|
||||
int internalId = state.customBlockState().registryId();
|
||||
|
||||
@@ -19,7 +19,7 @@ import java.util.concurrent.Callable;
|
||||
public abstract class BlockBehavior {
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T extends BlockBehavior> Optional<T> getAs(Class<T> tClass) {
|
||||
public <T> Optional<T> getAs(Class<T> tClass) {
|
||||
if (tClass.isInstance(this)) {
|
||||
return Optional.of((T) this);
|
||||
}
|
||||
|
||||
@@ -7,12 +7,15 @@ import net.momirealms.craftengine.core.block.entity.tick.BlockEntityTicker;
|
||||
import net.momirealms.craftengine.core.world.BlockPos;
|
||||
import net.momirealms.craftengine.core.world.CEWorld;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@ApiStatus.Experimental
|
||||
public interface EntityBlockBehavior {
|
||||
|
||||
<T extends BlockEntity> BlockEntityType<T> blockEntityType();
|
||||
@Nullable
|
||||
<T extends BlockEntity> BlockEntityType<T> blockEntityType(ImmutableBlockState state);
|
||||
|
||||
@Nullable
|
||||
BlockEntity createBlockEntity(BlockPos pos, ImmutableBlockState state);
|
||||
|
||||
default <T extends BlockEntity> BlockEntityTicker<T> createSyncBlockEntityTicker(CEWorld level, ImmutableBlockState state, BlockEntityType<T> blockEntityType) {
|
||||
|
||||
@@ -2,5 +2,5 @@ package net.momirealms.craftengine.core.block.entity;
|
||||
|
||||
import net.momirealms.craftengine.core.util.Key;
|
||||
|
||||
public record BlockEntityType<T extends BlockEntity>(Key id, BlockEntity.Factory<T> factory) {
|
||||
public record BlockEntityType<T extends BlockEntity>(Key id) {
|
||||
}
|
||||
|
||||
@@ -9,4 +9,5 @@ public final class BlockEntityTypeKeys {
|
||||
public static final Key SIMPLE_STORAGE = Key.of("craftengine:simple_storage");
|
||||
public static final Key SIMPLE_PARTICLE = Key.of("craftengine:simple_particle");
|
||||
public static final Key WALL_TORCH_PARTICLE = Key.of("craftengine:wall_torch_particle");
|
||||
public static final Key SEAT = Key.of("craftengine:seat");
|
||||
}
|
||||
|
||||
@@ -8,8 +8,8 @@ import net.momirealms.craftengine.core.util.ResourceKey;
|
||||
|
||||
public abstract class BlockEntityTypes {
|
||||
|
||||
public static <T extends BlockEntity> BlockEntityType<T> register(Key id, BlockEntity.Factory<T> factory) {
|
||||
BlockEntityType<T> type = new BlockEntityType<>(id, factory);
|
||||
public static <T extends BlockEntity> BlockEntityType<T> register(Key id) {
|
||||
BlockEntityType<T> type = new BlockEntityType<>(id);
|
||||
((WritableRegistry<BlockEntityType<?>>) BuiltInRegistries.BLOCK_ENTITY_TYPE)
|
||||
.register(ResourceKey.create(Registries.BLOCK_ENTITY_TYPE.location(), id), type);
|
||||
return type;
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package net.momirealms.craftengine.core.block.properties.type;
|
||||
|
||||
public enum DoorHinge {
|
||||
LEFT, RIGHT
|
||||
LEFT,
|
||||
RIGHT
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package net.momirealms.craftengine.core.block.properties.type;
|
||||
|
||||
public enum DoubleBlockHalf {
|
||||
UPPER, LOWER
|
||||
LOWER,
|
||||
UPPER
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package net.momirealms.craftengine.core.block.properties.type;
|
||||
|
||||
public enum SingleBlockHalf {
|
||||
TOP, BOTTOM
|
||||
BOTTOM,
|
||||
TOP
|
||||
}
|
||||
|
||||
@@ -70,7 +70,7 @@ public abstract class AbstractFurnitureManager implements FurnitureManager {
|
||||
this.byId.clear();
|
||||
}
|
||||
|
||||
protected abstract HitBox defaultHitBox();
|
||||
protected abstract HitBoxConfig defaultHitBox();
|
||||
|
||||
protected abstract FurnitureElement.Builder furnitureElementBuilder();
|
||||
|
||||
@@ -154,7 +154,7 @@ public abstract class AbstractFurnitureManager implements FurnitureManager {
|
||||
}
|
||||
|
||||
// add hitboxes
|
||||
List<HitBox> hitboxes = ResourceConfigUtils.parseConfigAsList(placementArguments.get("hitboxes"), HitBoxTypes::fromMap);
|
||||
List<HitBoxConfig> hitboxes = ResourceConfigUtils.parseConfigAsList(placementArguments.get("hitboxes"), HitBoxTypes::fromMap);
|
||||
if (hitboxes.isEmpty() && externalModel.isEmpty()) {
|
||||
hitboxes = List.of(defaultHitBox());
|
||||
}
|
||||
@@ -165,7 +165,7 @@ public abstract class AbstractFurnitureManager implements FurnitureManager {
|
||||
placements.put(anchorType, new CustomFurniture.Placement(
|
||||
anchorType,
|
||||
elements.toArray(new FurnitureElement[0]),
|
||||
hitboxes.toArray(new HitBox[0]),
|
||||
hitboxes.toArray(new HitBoxConfig[0]),
|
||||
ResourceConfigUtils.getOrDefault(ruleSection.get("rotation"), o -> RotationRule.valueOf(o.toString().toUpperCase(Locale.ENGLISH)), RotationRule.ANY),
|
||||
ResourceConfigUtils.getOrDefault(ruleSection.get("alignment"), o -> AlignmentRule.valueOf(o.toString().toUpperCase(Locale.ENGLISH)), AlignmentRule.CENTER),
|
||||
externalModel,
|
||||
@@ -175,7 +175,7 @@ public abstract class AbstractFurnitureManager implements FurnitureManager {
|
||||
placements.put(anchorType, new CustomFurniture.Placement(
|
||||
anchorType,
|
||||
elements.toArray(new FurnitureElement[0]),
|
||||
hitboxes.toArray(new HitBox[0]),
|
||||
hitboxes.toArray(new HitBoxConfig[0]),
|
||||
RotationRule.ANY,
|
||||
AlignmentRule.CENTER,
|
||||
externalModel,
|
||||
|
||||
@@ -1,15 +1,16 @@
|
||||
package net.momirealms.craftengine.core.entity.furniture;
|
||||
|
||||
import net.momirealms.craftengine.core.entity.seat.SeatConfig;
|
||||
import org.joml.Vector3f;
|
||||
|
||||
public abstract class AbstractHitBox implements HitBox {
|
||||
protected final Seat[] seats;
|
||||
public abstract class AbstractHitBoxConfig implements HitBoxConfig {
|
||||
protected final SeatConfig[] seats;
|
||||
protected final Vector3f position;
|
||||
protected final boolean canUseItemOn;
|
||||
protected final boolean blocksBuilding;
|
||||
protected final boolean canBeHitByProjectile;
|
||||
|
||||
public AbstractHitBox(Seat[] seats, Vector3f position, boolean canUseItemOn, boolean blocksBuilding, boolean canBeHitByProjectile) {
|
||||
public AbstractHitBoxConfig(SeatConfig[] seats, Vector3f position, boolean canUseItemOn, boolean blocksBuilding, boolean canBeHitByProjectile) {
|
||||
this.seats = seats;
|
||||
this.position = position;
|
||||
this.canUseItemOn = canUseItemOn;
|
||||
@@ -18,7 +19,7 @@ public abstract class AbstractHitBox implements HitBox {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Seat[] seats() {
|
||||
public SeatConfig[] seats() {
|
||||
return this.seats;
|
||||
}
|
||||
|
||||
@@ -51,7 +51,7 @@ public interface CustomFurniture {
|
||||
|
||||
record Placement(AnchorType anchorType,
|
||||
FurnitureElement[] elements,
|
||||
HitBox[] hitBoxes,
|
||||
HitBoxConfig[] hitBoxConfigs,
|
||||
RotationRule rotationRule,
|
||||
AlignmentRule alignmentRule,
|
||||
Optional<ExternalModel> externalModel,
|
||||
|
||||
@@ -1,12 +1,10 @@
|
||||
package net.momirealms.craftengine.core.entity.furniture;
|
||||
|
||||
import net.momirealms.craftengine.core.entity.player.Player;
|
||||
import net.momirealms.craftengine.core.util.Key;
|
||||
import net.momirealms.craftengine.core.world.WorldPosition;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.joml.Vector3f;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
|
||||
public interface Furniture {
|
||||
@@ -18,32 +16,30 @@ public interface Furniture {
|
||||
|
||||
void destroy();
|
||||
|
||||
void destroyColliders();
|
||||
|
||||
void destroySeats();
|
||||
|
||||
Optional<Seat> findFirstAvailableSeat(int targetEntityId);
|
||||
|
||||
boolean removeOccupiedSeat(Vector3f seat);
|
||||
|
||||
default boolean removeOccupiedSeat(Seat seat) {
|
||||
return this.removeOccupiedSeat(seat.offset());
|
||||
}
|
||||
|
||||
boolean tryOccupySeat(Seat seat);
|
||||
|
||||
UUID uuid();
|
||||
|
||||
int baseEntityId();
|
||||
|
||||
@NotNull AnchorType anchorType();
|
||||
@Nullable
|
||||
HitBox hitBoxByEntityId(int id);
|
||||
|
||||
@NotNull Key id();
|
||||
@Nullable HitBoxPart hitBoxPartByEntityId(int id);
|
||||
|
||||
@NotNull CustomFurniture config();
|
||||
@NotNull
|
||||
AnchorType anchorType();
|
||||
|
||||
@NotNull
|
||||
Key id();
|
||||
|
||||
@NotNull
|
||||
CustomFurniture config();
|
||||
|
||||
boolean hasExternalModel();
|
||||
|
||||
void spawnSeatEntityForPlayer(Player player, Seat seat);
|
||||
|
||||
FurnitureExtraData extraData();
|
||||
|
||||
void setExtraData(FurnitureExtraData extraData);
|
||||
|
||||
@@ -15,8 +15,6 @@ import java.util.Optional;
|
||||
public interface FurnitureManager extends Manageable {
|
||||
Key FURNITURE_KEY = Key.of("craftengine:furniture_id");
|
||||
Key FURNITURE_EXTRA_DATA_KEY = Key.of("craftengine:furniture_extra_data");
|
||||
Key FURNITURE_SEAT_BASE_ENTITY_KEY = Key.of("craftengine:seat_to_base_entity");
|
||||
Key FURNITURE_SEAT_VECTOR_3F_KEY = Key.of("craftengine:seat_vector");
|
||||
Key FURNITURE_COLLISION = Key.of("craftengine:collision");
|
||||
|
||||
String FURNITURE_ADMIN_NODE = "craftengine.furniture.admin";
|
||||
|
||||
@@ -1,33 +1,19 @@
|
||||
package net.momirealms.craftengine.core.entity.furniture;
|
||||
|
||||
import net.momirealms.craftengine.core.util.Key;
|
||||
import net.momirealms.craftengine.core.world.WorldPosition;
|
||||
import net.momirealms.craftengine.core.world.collision.AABB;
|
||||
import org.joml.Quaternionf;
|
||||
import org.joml.Vector3f;
|
||||
import net.momirealms.craftengine.core.entity.seat.Seat;
|
||||
import net.momirealms.craftengine.core.entity.seat.SeatOwner;
|
||||
import net.momirealms.craftengine.core.world.EntityHitResult;
|
||||
import net.momirealms.craftengine.core.world.Vec3d;
|
||||
|
||||
import java.util.function.BiConsumer;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Supplier;
|
||||
import java.util.Optional;
|
||||
|
||||
public interface HitBox {
|
||||
public interface HitBox extends SeatOwner {
|
||||
|
||||
Key type();
|
||||
Seat<HitBox>[] seats();
|
||||
|
||||
void initPacketsAndColliders(int[] entityId, WorldPosition position, Quaternionf conjugated,
|
||||
BiConsumer<Object, Boolean> packets, Consumer<Collider> collider, BiConsumer<Integer, AABB> aabb);
|
||||
Optional<EntityHitResult> clip(Vec3d min, Vec3d max);
|
||||
|
||||
void initShapeForPlacement(double x, double y, double z, float yaw, Quaternionf conjugated, Consumer<AABB> aabbs);
|
||||
HitBoxPart[] parts();
|
||||
|
||||
int[] acquireEntityIds(Supplier<Integer> entityIdSupplier);
|
||||
|
||||
Seat[] seats();
|
||||
|
||||
Vector3f position();
|
||||
|
||||
boolean blocksBuilding();
|
||||
|
||||
boolean canBeHitByProjectile();
|
||||
|
||||
boolean canUseItemOn();
|
||||
HitBoxConfig config();
|
||||
}
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
package net.momirealms.craftengine.core.entity.furniture;
|
||||
|
||||
import net.momirealms.craftengine.core.entity.seat.SeatConfig;
|
||||
import net.momirealms.craftengine.core.util.Key;
|
||||
import net.momirealms.craftengine.core.world.WorldPosition;
|
||||
import net.momirealms.craftengine.core.world.collision.AABB;
|
||||
import org.joml.Quaternionf;
|
||||
import org.joml.Vector3f;
|
||||
|
||||
import java.util.function.BiConsumer;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public interface HitBoxConfig {
|
||||
|
||||
Key type();
|
||||
|
||||
void initPacketsAndColliders(int[] entityId, WorldPosition position, Quaternionf conjugated,
|
||||
BiConsumer<Object, Boolean> packets, Consumer<Collider> collider, Consumer<HitBoxPart> aabb);
|
||||
|
||||
void initShapeForPlacement(double x, double y, double z, float yaw, Quaternionf conjugated, Consumer<AABB> aabbs);
|
||||
|
||||
int[] acquireEntityIds(Supplier<Integer> entityIdSupplier);
|
||||
|
||||
SeatConfig[] seats();
|
||||
|
||||
Vector3f position();
|
||||
|
||||
boolean blocksBuilding();
|
||||
|
||||
boolean canBeHitByProjectile();
|
||||
|
||||
boolean canUseItemOn();
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
package net.momirealms.craftengine.core.entity.furniture;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public interface HitBoxConfigFactory {
|
||||
|
||||
HitBoxConfig create(Map<String, Object> arguments);
|
||||
}
|
||||
@@ -1,23 +0,0 @@
|
||||
package net.momirealms.craftengine.core.entity.furniture;
|
||||
|
||||
import net.momirealms.craftengine.core.util.ResourceConfigUtils;
|
||||
|
||||
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(ResourceConfigUtils.getAsVector3f(split[0], "seats"), 0, false);
|
||||
return new Seat(ResourceConfigUtils.getAsVector3f(split[0], "seats"), Float.parseFloat(split[1]), true);
|
||||
})
|
||||
.toArray(Seat[]::new);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package net.momirealms.craftengine.core.entity.furniture;
|
||||
|
||||
import net.momirealms.craftengine.core.world.Vec3d;
|
||||
import net.momirealms.craftengine.core.world.collision.AABB;
|
||||
|
||||
public record HitBoxPart(int entityId, AABB aabb, Vec3d pos) {
|
||||
}
|
||||
@@ -16,14 +16,14 @@ public class HitBoxTypes {
|
||||
public static final Key HAPPY_GHAST = Key.of("minecraft:happy_ghast");
|
||||
public static final Key CUSTOM = Key.of("minecraft:custom");
|
||||
|
||||
public static void register(Key key, HitBoxFactory factory) {
|
||||
((WritableRegistry<HitBoxFactory>) BuiltInRegistries.HITBOX_FACTORY)
|
||||
public static void register(Key key, HitBoxConfigFactory factory) {
|
||||
((WritableRegistry<HitBoxConfigFactory>) BuiltInRegistries.HITBOX_FACTORY)
|
||||
.register(ResourceKey.create(Registries.HITBOX_FACTORY.location(), key), factory);
|
||||
}
|
||||
|
||||
public static HitBox fromMap(Map<String, Object> arguments) {
|
||||
public static HitBoxConfig fromMap(Map<String, Object> arguments) {
|
||||
Key type = Optional.ofNullable(arguments.get("type")).map(String::valueOf).map(Key::of).orElse(HitBoxTypes.INTERACTION);
|
||||
HitBoxFactory factory = BuiltInRegistries.HITBOX_FACTORY.getValue(type);
|
||||
HitBoxConfigFactory factory = BuiltInRegistries.HITBOX_FACTORY.getValue(type);
|
||||
if (factory == null) {
|
||||
throw new LocalizedResourceConfigException("warning.config.furniture.hitbox.invalid_type", type.toString());
|
||||
}
|
||||
|
||||
@@ -1,23 +0,0 @@
|
||||
package net.momirealms.craftengine.core.entity.furniture;
|
||||
|
||||
import org.joml.Vector3f;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
public record Seat(Vector3f offset, float yaw, boolean limitPlayerRotation) {
|
||||
|
||||
@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;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int result = Objects.hashCode(offset);
|
||||
result = 31 * result + Float.hashCode(yaw);
|
||||
result = 31 * result + Boolean.hashCode(limitPlayerRotation);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package net.momirealms.craftengine.core.entity.seat;
|
||||
|
||||
import net.momirealms.craftengine.core.entity.player.Player;
|
||||
import net.momirealms.craftengine.core.world.WorldPosition;
|
||||
|
||||
public interface Seat<O extends SeatOwner> {
|
||||
|
||||
O owner();
|
||||
|
||||
SeatConfig config();
|
||||
|
||||
boolean isOccupied();
|
||||
|
||||
void destroy();
|
||||
|
||||
boolean spawnSeat(Player player, WorldPosition source);
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
package net.momirealms.craftengine.core.entity.seat;
|
||||
|
||||
import net.momirealms.craftengine.core.util.MiscUtils;
|
||||
import net.momirealms.craftengine.core.util.ResourceConfigUtils;
|
||||
import org.joml.Vector3f;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public record SeatConfig(Vector3f position, float yRot, boolean limitPlayerRotation) {
|
||||
|
||||
public static SeatConfig[] fromObj(Object config) {
|
||||
if (config instanceof List<?>) {
|
||||
List<String> seats = MiscUtils.getAsStringList(config);
|
||||
return seats.stream()
|
||||
.map(arg -> {
|
||||
String[] split = arg.split(" ");
|
||||
if (split.length == 1) return new SeatConfig(ResourceConfigUtils.getAsVector3f(split[0], "seats"), 0, false);
|
||||
return new SeatConfig(ResourceConfigUtils.getAsVector3f(split[0], "seats"), Float.parseFloat(split[1]), true);
|
||||
})
|
||||
.toArray(SeatConfig[]::new);
|
||||
} else if (config != null) {
|
||||
String arg = config.toString();
|
||||
String[] split = arg.split(" ");
|
||||
if (split.length == 1) return new SeatConfig[] {new SeatConfig(ResourceConfigUtils.getAsVector3f(split[0], "seats"), 0, false)};
|
||||
return new SeatConfig[] {new SeatConfig(ResourceConfigUtils.getAsVector3f(split[0], "seats"), Float.parseFloat(split[1]), true)};
|
||||
} else {
|
||||
return new SeatConfig[0];
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
package net.momirealms.craftengine.core.entity.seat;
|
||||
|
||||
import net.momirealms.craftengine.core.plugin.Manageable;
|
||||
import net.momirealms.craftengine.core.util.Key;
|
||||
|
||||
public interface SeatManager extends Manageable {
|
||||
Key SEAT_KEY = Key.of("craftengine:seat");
|
||||
Key SEAT_EXTRA_DATA_KEY = Key.of("craftengine:seat_extra_data");
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
package net.momirealms.craftengine.core.entity.seat;
|
||||
|
||||
import net.momirealms.sparrow.nbt.CompoundTag;
|
||||
|
||||
public interface SeatOwner {
|
||||
|
||||
void saveCustomData(CompoundTag data);
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
package net.momirealms.craftengine.core.item;
|
||||
|
||||
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
|
||||
import net.momirealms.craftengine.core.entity.player.Player;
|
||||
import net.momirealms.craftengine.core.plugin.context.ContextHolder;
|
||||
import net.momirealms.craftengine.core.plugin.context.parameter.DirectContextParameters;
|
||||
import net.momirealms.craftengine.core.plugin.text.minimessage.*;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public class NetworkItemBuildContext extends ItemBuildContext {
|
||||
|
||||
public NetworkItemBuildContext(@Nullable Player player, @NotNull ContextHolder contexts) {
|
||||
super(player, contexts);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static NetworkItemBuildContext empty() {
|
||||
return new NetworkItemBuildContext(null, ContextHolder.empty());
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static NetworkItemBuildContext of(@Nullable Player player, @NotNull ContextHolder contexts) {
|
||||
return new NetworkItemBuildContext(player, contexts);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static NetworkItemBuildContext of(@Nullable Player player, @NotNull ContextHolder.Builder builder) {
|
||||
if (player != null) builder.withParameter(DirectContextParameters.PLAYER, player);
|
||||
return new NetworkItemBuildContext(player, builder.build());
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static NetworkItemBuildContext of(@Nullable Player player) {
|
||||
if (player == null) return new NetworkItemBuildContext(null, ContextHolder.empty());
|
||||
return new NetworkItemBuildContext(player, new ContextHolder(Map.of(DirectContextParameters.PLAYER, () -> player)));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
protected TagResolver[] getInternalTagResolvers() {
|
||||
return new TagResolver[]{ShiftTag.INSTANCE, ImageTag.INSTANCE, new I18NTag(this), new L10NTag(this), new NamedArgumentTag(this),
|
||||
new PlaceholderTag(this), new ExpressionTag(this), new GlobalVariableTag(this)};
|
||||
}
|
||||
}
|
||||
@@ -4,6 +4,7 @@ import net.momirealms.craftengine.core.advancement.AdvancementManager;
|
||||
import net.momirealms.craftengine.core.block.BlockManager;
|
||||
import net.momirealms.craftengine.core.entity.furniture.FurnitureManager;
|
||||
import net.momirealms.craftengine.core.entity.projectile.ProjectileManager;
|
||||
import net.momirealms.craftengine.core.entity.seat.SeatManager;
|
||||
import net.momirealms.craftengine.core.font.FontManager;
|
||||
import net.momirealms.craftengine.core.item.ItemManager;
|
||||
import net.momirealms.craftengine.core.item.recipe.RecipeManager;
|
||||
@@ -76,6 +77,7 @@ public abstract class CraftEngine implements Plugin {
|
||||
protected CompatibilityManager compatibilityManager;
|
||||
protected GlobalVariableManager globalVariableManager;
|
||||
protected ProjectileManager projectileManager;
|
||||
protected SeatManager seatManager;
|
||||
|
||||
private final PluginTaskRegistry preLoadTaskRegistry = new PluginTaskRegistry();
|
||||
private final PluginTaskRegistry postLoadTaskRegistry = new PluginTaskRegistry();
|
||||
@@ -151,6 +153,7 @@ public abstract class CraftEngine implements Plugin {
|
||||
this.packManager.reload();
|
||||
this.advancementManager.reload();
|
||||
this.projectileManager.reload();
|
||||
this.seatManager.reload();
|
||||
if (reloadRecipe) {
|
||||
this.recipeManager.reload();
|
||||
}
|
||||
@@ -229,6 +232,7 @@ public abstract class CraftEngine implements Plugin {
|
||||
this.fontManager.delayedInit();
|
||||
this.vanillaLootManager.delayedInit();
|
||||
this.advancementManager.delayedInit();
|
||||
this.seatManager.delayedInit();
|
||||
this.compatibilityManager.onDelayedEnable();
|
||||
// reload the plugin
|
||||
try {
|
||||
@@ -263,6 +267,7 @@ public abstract class CraftEngine implements Plugin {
|
||||
if (this.guiManager != null) this.guiManager.disable();
|
||||
if (this.soundManager != null) this.soundManager.disable();
|
||||
if (this.vanillaLootManager != null) this.vanillaLootManager.disable();
|
||||
if (this.seatManager != null) this.seatManager.disable();
|
||||
if (this.translationManager != null) this.translationManager.disable();
|
||||
if (this.globalVariableManager != null) this.globalVariableManager.disable();
|
||||
if (this.projectileManager != null) this.projectileManager.disable();
|
||||
|
||||
@@ -9,10 +9,7 @@ import net.momirealms.craftengine.core.plugin.context.Context;
|
||||
import net.momirealms.craftengine.core.plugin.context.number.NumberProvider;
|
||||
import net.momirealms.craftengine.core.plugin.context.number.NumberProviders;
|
||||
import net.momirealms.craftengine.core.plugin.context.parameter.DirectContextParameters;
|
||||
import net.momirealms.craftengine.core.plugin.context.selector.PlayerSelector;
|
||||
import net.momirealms.craftengine.core.plugin.context.selector.PlayerSelectors;
|
||||
import net.momirealms.craftengine.core.util.Key;
|
||||
import net.momirealms.craftengine.core.util.ResourceConfigUtils;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@@ -68,7 +68,7 @@ public sealed interface ComponentProvider extends Function<Context, Component>
|
||||
if (context instanceof PlayerOptionalContext playerContext) {
|
||||
Player player = playerContext.player();
|
||||
if (player != null) {
|
||||
String content = TranslationManager.instance().miniMessageTranslation(this.key, player.locale());
|
||||
String content = TranslationManager.instance().miniMessageTranslation(this.key, player.selectedLocale());
|
||||
if (content == null) {
|
||||
return Component.text(this.key);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
package net.momirealms.craftengine.core.plugin.text.minimessage;
|
||||
|
||||
import net.kyori.adventure.text.minimessage.ParsingException;
|
||||
import net.kyori.adventure.text.minimessage.tag.Tag;
|
||||
import net.kyori.adventure.text.minimessage.tag.resolver.ArgumentQueue;
|
||||
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
|
||||
import net.momirealms.craftengine.core.plugin.context.Context;
|
||||
import net.momirealms.craftengine.core.plugin.context.PlayerOptionalContext;
|
||||
import net.momirealms.craftengine.core.plugin.locale.TranslationManager;
|
||||
import net.momirealms.craftengine.core.util.AdventureHelper;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
public class L10NTag implements TagResolver {
|
||||
private final Context context;
|
||||
|
||||
public L10NTag(Context context) {
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable Tag resolve(@NotNull String name, @NotNull ArgumentQueue arguments, @NotNull net.kyori.adventure.text.minimessage.Context ctx) throws ParsingException {
|
||||
if (!this.has(name)) {
|
||||
return null;
|
||||
}
|
||||
Locale locale = null;
|
||||
if (this.context instanceof PlayerOptionalContext playerOptionalContext && playerOptionalContext.isPlayerPresent()) {
|
||||
locale = playerOptionalContext.player().selectedLocale();
|
||||
}
|
||||
String i18nKey = arguments.popOr("No argument l10n key provided").toString();
|
||||
String translation = TranslationManager.instance().miniMessageTranslation(i18nKey, locale);
|
||||
return Tag.selfClosingInserting(AdventureHelper.miniMessage().deserialize(translation, this.context.tagResolvers()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean has(@NotNull String name) {
|
||||
return "l10n".equals(name);
|
||||
}
|
||||
}
|
||||
@@ -5,7 +5,7 @@ import net.momirealms.craftengine.core.block.behavior.BlockBehaviorFactory;
|
||||
import net.momirealms.craftengine.core.block.entity.BlockEntityType;
|
||||
import net.momirealms.craftengine.core.block.entity.render.element.BlockEntityElementConfigFactory;
|
||||
import net.momirealms.craftengine.core.block.properties.PropertyFactory;
|
||||
import net.momirealms.craftengine.core.entity.furniture.HitBoxFactory;
|
||||
import net.momirealms.craftengine.core.entity.furniture.HitBoxConfigFactory;
|
||||
import net.momirealms.craftengine.core.item.ItemDataModifierFactory;
|
||||
import net.momirealms.craftengine.core.item.behavior.ItemBehaviorFactory;
|
||||
import net.momirealms.craftengine.core.item.equipment.EquipmentFactory;
|
||||
@@ -76,7 +76,7 @@ public class BuiltInRegistries {
|
||||
public static final Registry<ConditionFactory<PathContext>> PATH_MATCHER_FACTORY = createConstantBoundRegistry(Registries.PATH_MATCHER_FACTORY, 16);
|
||||
public static final Registry<ResolutionFactory> RESOLUTION_FACTORY = createConstantBoundRegistry(Registries.RESOLUTION_FACTORY, 16);
|
||||
public static final Registry<CustomSmithingTransformRecipe.ItemDataProcessor.ProcessorFactory> SMITHING_RESULT_PROCESSOR_FACTORY = createConstantBoundRegistry(Registries.SMITHING_RESULT_PROCESSOR_FACTORY, 16);
|
||||
public static final Registry<HitBoxFactory> HITBOX_FACTORY = createConstantBoundRegistry(Registries.HITBOX_FACTORY, 16);
|
||||
public static final Registry<HitBoxConfigFactory> HITBOX_FACTORY = createConstantBoundRegistry(Registries.HITBOX_FACTORY, 16);
|
||||
public static final Registry<ResourcePackHostFactory> RESOURCE_PACK_HOST_FACTORY = createConstantBoundRegistry(Registries.RESOURCE_PACK_HOST_FACTORY, 16);
|
||||
public static final Registry<FunctionFactory<PlayerOptionalContext>> EVENT_FUNCTION_FACTORY = createConstantBoundRegistry(Registries.EVENT_FUNCTION_FACTORY, 128);
|
||||
public static final Registry<ConditionFactory<PlayerOptionalContext>> EVENT_CONDITION_FACTORY = createConstantBoundRegistry(Registries.EVENT_CONDITION_FACTORY, 128);
|
||||
|
||||
@@ -5,7 +5,7 @@ import net.momirealms.craftengine.core.block.behavior.BlockBehaviorFactory;
|
||||
import net.momirealms.craftengine.core.block.entity.BlockEntityType;
|
||||
import net.momirealms.craftengine.core.block.entity.render.element.BlockEntityElementConfigFactory;
|
||||
import net.momirealms.craftengine.core.block.properties.PropertyFactory;
|
||||
import net.momirealms.craftengine.core.entity.furniture.HitBoxFactory;
|
||||
import net.momirealms.craftengine.core.entity.furniture.HitBoxConfigFactory;
|
||||
import net.momirealms.craftengine.core.item.ItemDataModifierFactory;
|
||||
import net.momirealms.craftengine.core.item.behavior.ItemBehaviorFactory;
|
||||
import net.momirealms.craftengine.core.item.equipment.EquipmentFactory;
|
||||
@@ -78,7 +78,7 @@ public class Registries {
|
||||
public static final ResourceKey<Registry<ConditionFactory<PathContext>>> PATH_MATCHER_FACTORY = ResourceKey.create(ROOT_REGISTRY, Key.withDefaultNamespace("path_matcher_factory"));
|
||||
public static final ResourceKey<Registry<ResolutionFactory>> RESOLUTION_FACTORY = ResourceKey.create(ROOT_REGISTRY, Key.withDefaultNamespace("resolution_factory"));
|
||||
public static final ResourceKey<Registry<CustomSmithingTransformRecipe.ItemDataProcessor.ProcessorFactory>> SMITHING_RESULT_PROCESSOR_FACTORY = ResourceKey.create(ROOT_REGISTRY, Key.withDefaultNamespace("smithing_result_processor_factory"));
|
||||
public static final ResourceKey<Registry<HitBoxFactory>> HITBOX_FACTORY = ResourceKey.create(ROOT_REGISTRY, Key.withDefaultNamespace("hitbox_factory"));
|
||||
public static final ResourceKey<Registry<HitBoxConfigFactory>> HITBOX_FACTORY = ResourceKey.create(ROOT_REGISTRY, Key.withDefaultNamespace("hitbox_factory"));
|
||||
public static final ResourceKey<Registry<ResourcePackHostFactory>> RESOURCE_PACK_HOST_FACTORY = ResourceKey.create(ROOT_REGISTRY, Key.withDefaultNamespace("resource_pack_host_factory"));
|
||||
public static final ResourceKey<Registry<FunctionFactory<PlayerOptionalContext>>> EVENT_FUNCTION_FACTORY = ResourceKey.create(ROOT_REGISTRY, Key.withDefaultNamespace("event_function_factory"));
|
||||
public static final ResourceKey<Registry<ConditionFactory<PlayerOptionalContext>>> EVENT_CONDITION_FACTORY = ResourceKey.create(ROOT_REGISTRY, Key.withDefaultNamespace("event_condition_factory"));
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package net.momirealms.craftengine.core.world.chunk.serialization;
|
||||
|
||||
import net.momirealms.craftengine.core.block.ImmutableBlockState;
|
||||
import net.momirealms.craftengine.core.block.behavior.EntityBlockBehavior;
|
||||
import net.momirealms.craftengine.core.block.entity.BlockEntity;
|
||||
import net.momirealms.craftengine.core.block.entity.BlockEntityType;
|
||||
import net.momirealms.craftengine.core.plugin.logger.Debugger;
|
||||
@@ -14,6 +15,7 @@ import net.momirealms.sparrow.nbt.ListTag;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
public final class DefaultBlockEntitySerializer {
|
||||
|
||||
@@ -41,9 +43,14 @@ public final class DefaultBlockEntitySerializer {
|
||||
BlockPos pos = BlockEntity.readPosAndVerify(data, chunk.chunkPos());
|
||||
ImmutableBlockState blockState = chunk.getBlockState(pos);
|
||||
if (blockState.blockEntityType() == type) {
|
||||
BlockEntity blockEntity = type.factory().create(pos, blockState);
|
||||
blockEntity.loadCustomData(data);
|
||||
blockEntities.add(blockEntity);
|
||||
Optional<EntityBlockBehavior> entityBlockBehavior = blockState.behavior().getAs(EntityBlockBehavior.class);
|
||||
if (entityBlockBehavior.isPresent()) {
|
||||
BlockEntity blockEntity = entityBlockBehavior.get().createBlockEntity(pos, blockState);
|
||||
if (blockEntity != null) {
|
||||
blockEntity.loadCustomData(data);
|
||||
blockEntities.add(blockEntity);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user