mirror of
https://github.com/Xiao-MoMi/craft-engine.git
synced 2025-12-26 18:39:20 +00:00
支持注册固定的方块实体渲染
This commit is contained in:
@@ -7,8 +7,6 @@ import it.unimi.dsi.fastutil.ints.Int2IntOpenHashMap;
|
||||
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
|
||||
import it.unimi.dsi.fastutil.ints.IntArrayList;
|
||||
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
|
||||
import net.momirealms.craftengine.bukkit.block.entity.renderer.BukkitBlockEntityElement;
|
||||
import net.momirealms.craftengine.bukkit.item.BukkitItemManager;
|
||||
import net.momirealms.craftengine.bukkit.nms.FastNMS;
|
||||
import net.momirealms.craftengine.bukkit.plugin.BukkitCraftEngine;
|
||||
import net.momirealms.craftengine.bukkit.plugin.injector.BlockGenerator;
|
||||
@@ -25,10 +23,7 @@ import net.momirealms.craftengine.bukkit.util.RegistryUtils;
|
||||
import net.momirealms.craftengine.bukkit.util.TagUtils;
|
||||
import net.momirealms.craftengine.core.block.*;
|
||||
import net.momirealms.craftengine.core.block.behavior.EmptyBlockBehavior;
|
||||
import net.momirealms.craftengine.core.block.entity.render.BlockEntityElement;
|
||||
import net.momirealms.craftengine.core.block.parser.BlockStateParser;
|
||||
import net.momirealms.craftengine.core.entity.Billboard;
|
||||
import net.momirealms.craftengine.core.entity.ItemDisplayContext;
|
||||
import net.momirealms.craftengine.core.plugin.config.StringKeyConstructor;
|
||||
import net.momirealms.craftengine.core.plugin.locale.LocalizedResourceConfigException;
|
||||
import net.momirealms.craftengine.core.registry.BuiltInRegistries;
|
||||
@@ -689,20 +684,4 @@ public final class BukkitBlockManager extends AbstractBlockManager {
|
||||
}
|
||||
return FastNMS.INSTANCE.method$Registry$getValue(MBuiltInRegistries.BLOCK, KeyUtils.toResourceLocation(id)) != MBlocks.AIR;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected BlockEntityElement createBlockEntityElement(Map<String, Object> arguments) {
|
||||
Key itemId = Key.of(ResourceConfigUtils.requireNonEmptyStringOrThrow(arguments.get("item"), ""));
|
||||
return new BukkitBlockEntityElement(
|
||||
LazyReference.lazyReference(() -> BukkitItemManager.instance().createWrappedItem(itemId, null)),
|
||||
ResourceConfigUtils.getAsVector3f(arguments.getOrDefault("scale", 1f), "scale"),
|
||||
ResourceConfigUtils.getAsVector3f(arguments.getOrDefault("position", 0.5f), "position"),
|
||||
ResourceConfigUtils.getAsVector3f(arguments.get("translation"), "translation"),
|
||||
ResourceConfigUtils.getAsFloat(arguments.getOrDefault("pitch", 0f), "pitch"),
|
||||
ResourceConfigUtils.getAsFloat(arguments.getOrDefault("yaw", 0f), "yaw"),
|
||||
ResourceConfigUtils.getAsQuaternionf(arguments.getOrDefault("rotation", 0f), "rotation"),
|
||||
ItemDisplayContext.valueOf(arguments.getOrDefault("display-context", "none").toString().toUpperCase(Locale.ROOT)),
|
||||
Billboard.valueOf(arguments.getOrDefault("billboard", "fixed").toString().toUpperCase(Locale.ROOT))
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,106 +0,0 @@
|
||||
package net.momirealms.craftengine.bukkit.block.entity.renderer;
|
||||
|
||||
import net.momirealms.craftengine.bukkit.entity.data.ItemDisplayEntityData;
|
||||
import net.momirealms.craftengine.core.block.entity.render.BlockEntityElement;
|
||||
import net.momirealms.craftengine.core.entity.Billboard;
|
||||
import net.momirealms.craftengine.core.entity.ItemDisplayContext;
|
||||
import net.momirealms.craftengine.core.item.Item;
|
||||
import net.momirealms.craftengine.core.util.LazyReference;
|
||||
import org.joml.Quaternionf;
|
||||
import org.joml.Vector3f;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class BukkitBlockEntityElement implements BlockEntityElement {
|
||||
private final LazyReference<List<Object>> lazyMetadataPacket;
|
||||
private final LazyReference<Item<?>> item;
|
||||
private final Vector3f scale;
|
||||
private final Vector3f position;
|
||||
private final Vector3f translation;
|
||||
private final float xRot;
|
||||
private final float yRot;
|
||||
private final Quaternionf rotation;
|
||||
private final ItemDisplayContext displayContext;
|
||||
private final Billboard billboard;
|
||||
|
||||
public BukkitBlockEntityElement(LazyReference<Item<?>> item,
|
||||
Vector3f scale,
|
||||
Vector3f position,
|
||||
Vector3f translation,
|
||||
float xRot,
|
||||
float yRot,
|
||||
Quaternionf rotation,
|
||||
ItemDisplayContext displayContext,
|
||||
Billboard billboard) {
|
||||
this.item = item;
|
||||
this.scale = scale;
|
||||
this.position = position;
|
||||
this.translation = translation;
|
||||
this.xRot = xRot;
|
||||
this.yRot = yRot;
|
||||
this.rotation = rotation;
|
||||
this.displayContext = displayContext;
|
||||
this.billboard = billboard;
|
||||
this.lazyMetadataPacket = LazyReference.lazyReference(() -> {
|
||||
List<Object> dataValues = new ArrayList<>();
|
||||
ItemDisplayEntityData.DisplayedItem.addEntityDataIfNotDefaultValue(item.get().getLiteralObject(), dataValues);
|
||||
ItemDisplayEntityData.Scale.addEntityDataIfNotDefaultValue(this.scale, dataValues);
|
||||
ItemDisplayEntityData.RotationLeft.addEntityDataIfNotDefaultValue(this.rotation, dataValues);
|
||||
ItemDisplayEntityData.BillboardConstraints.addEntityDataIfNotDefaultValue(this.billboard.id(), dataValues);
|
||||
ItemDisplayEntityData.Translation.addEntityDataIfNotDefaultValue(this.translation, dataValues);
|
||||
ItemDisplayEntityData.DisplayType.addEntityDataIfNotDefaultValue(this.displayContext.id(), dataValues);
|
||||
return dataValues;
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public Item<?> item() {
|
||||
return this.item.get();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Vector3f scale() {
|
||||
return this.scale;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Vector3f translation() {
|
||||
return this.translation;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Vector3f position() {
|
||||
return this.position;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float yRot() {
|
||||
return this.yRot;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float xRot() {
|
||||
return this.xRot;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Billboard billboard() {
|
||||
return billboard;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemDisplayContext displayContext() {
|
||||
return displayContext;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Quaternionf rotation() {
|
||||
return rotation;
|
||||
}
|
||||
|
||||
@Override
|
||||
public LazyReference<List<Object>> metadataValues() {
|
||||
return this.lazyMetadataPacket;
|
||||
}
|
||||
}
|
||||
@@ -1,48 +1,22 @@
|
||||
package net.momirealms.craftengine.bukkit.block.entity.renderer;
|
||||
|
||||
import it.unimi.dsi.fastutil.ints.IntArrayList;
|
||||
import it.unimi.dsi.fastutil.ints.IntList;
|
||||
import net.momirealms.craftengine.bukkit.api.BukkitAdaptors;
|
||||
import net.momirealms.craftengine.bukkit.nms.FastNMS;
|
||||
import net.momirealms.craftengine.bukkit.plugin.reflection.minecraft.CoreReflections;
|
||||
import net.momirealms.craftengine.bukkit.plugin.reflection.minecraft.MEntityTypes;
|
||||
import net.momirealms.craftengine.core.block.entity.render.BlockEntityElement;
|
||||
import net.momirealms.craftengine.bukkit.plugin.user.BukkitServerPlayer;
|
||||
import net.momirealms.craftengine.core.block.entity.render.BlockEntityRenderer;
|
||||
import net.momirealms.craftengine.core.block.entity.render.BlockEntityRendererConfig;
|
||||
import net.momirealms.craftengine.core.block.entity.render.element.BlockEntityElement;
|
||||
import net.momirealms.craftengine.core.entity.player.Player;
|
||||
import net.momirealms.craftengine.core.world.BlockPos;
|
||||
import org.joml.Vector3f;
|
||||
|
||||
import java.lang.ref.WeakReference;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
public class BukkitBlockEntityRenderer extends BlockEntityRenderer {
|
||||
private final Object cachedSpawnPacket;
|
||||
private final Object cachedDespawnPacket;
|
||||
private final BlockEntityElement[] elements;
|
||||
private final WeakReference<Object> chunkHolder;
|
||||
|
||||
public BukkitBlockEntityRenderer(WeakReference<Object> chunkHolder,
|
||||
BlockEntityRendererConfig config,
|
||||
BlockPos pos) {
|
||||
public BukkitBlockEntityRenderer(WeakReference<Object> chunkHolder, BlockEntityElement[] elements) {
|
||||
this.chunkHolder = chunkHolder;
|
||||
BlockEntityElement[] elements = config.elements();
|
||||
IntList ids = new IntArrayList(elements.length);
|
||||
List<Object> spawnPackets = new ArrayList<>(elements.length);
|
||||
for (BlockEntityElement element : elements) {
|
||||
int entityId = CoreReflections.instance$Entity$ENTITY_COUNTER.incrementAndGet();
|
||||
Vector3f position = element.position();
|
||||
spawnPackets.add(FastNMS.INSTANCE.constructor$ClientboundAddEntityPacket(
|
||||
entityId, UUID.randomUUID(), pos.x() + position.x, pos.y() + position.y, pos.z() + position.z,
|
||||
element.xRot(), element.yRot(), MEntityTypes.ITEM_DISPLAY, 0, CoreReflections.instance$Vec3$Zero, 0
|
||||
));
|
||||
spawnPackets.add(FastNMS.INSTANCE.constructor$ClientboundSetEntityDataPacket(
|
||||
entityId, element.metadataValues().get()
|
||||
));
|
||||
ids.add(entityId);
|
||||
}
|
||||
this.cachedSpawnPacket = FastNMS.INSTANCE.constructor$ClientboundBundlePacket(spawnPackets);
|
||||
this.cachedDespawnPacket = FastNMS.INSTANCE.constructor$ClientboundRemoveEntitiesPacket(ids);
|
||||
this.elements = elements;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -50,10 +24,10 @@ public class BukkitBlockEntityRenderer extends BlockEntityRenderer {
|
||||
List<Object> players = FastNMS.INSTANCE.method$ChunkHolder$getPlayers(this.chunkHolder.get());
|
||||
if (players.isEmpty()) return;
|
||||
for (Object player : players) {
|
||||
FastNMS.INSTANCE.method$ServerPlayerConnection$send(
|
||||
FastNMS.INSTANCE.field$Player$connection(player),
|
||||
this.cachedDespawnPacket
|
||||
);
|
||||
org.bukkit.entity.Player bkPlayer = FastNMS.INSTANCE.method$ServerPlayer$getBukkitEntity(player);
|
||||
BukkitServerPlayer serverPlayer = BukkitAdaptors.adapt(bkPlayer);
|
||||
if (serverPlayer == null) continue;
|
||||
despawn(serverPlayer);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -62,20 +36,43 @@ public class BukkitBlockEntityRenderer extends BlockEntityRenderer {
|
||||
List<Object> players = FastNMS.INSTANCE.method$ChunkHolder$getPlayers(this.chunkHolder.get());
|
||||
if (players.isEmpty()) return;
|
||||
for (Object player : players) {
|
||||
FastNMS.INSTANCE.method$ServerPlayerConnection$send(
|
||||
FastNMS.INSTANCE.field$Player$connection(player),
|
||||
this.cachedSpawnPacket
|
||||
);
|
||||
org.bukkit.entity.Player bkPlayer = FastNMS.INSTANCE.method$ServerPlayer$getBukkitEntity(player);
|
||||
BukkitServerPlayer serverPlayer = BukkitAdaptors.adapt(bkPlayer);
|
||||
if (serverPlayer == null) continue;
|
||||
spawn(serverPlayer);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update() {
|
||||
List<Object> players = FastNMS.INSTANCE.method$ChunkHolder$getPlayers(this.chunkHolder.get());
|
||||
if (players.isEmpty()) return;
|
||||
for (Object player : players) {
|
||||
org.bukkit.entity.Player bkPlayer = FastNMS.INSTANCE.method$ServerPlayer$getBukkitEntity(player);
|
||||
BukkitServerPlayer serverPlayer = BukkitAdaptors.adapt(bkPlayer);
|
||||
if (serverPlayer == null) continue;
|
||||
update(serverPlayer);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(Player player) {
|
||||
for (BlockEntityElement element : this.elements) {
|
||||
element.update(player);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void spawn(Player player) {
|
||||
player.sendPacket(this.cachedSpawnPacket, false);
|
||||
for (BlockEntityElement element : this.elements) {
|
||||
element.spawn(player);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void despawn(Player player) {
|
||||
player.sendPacket(this.cachedDespawnPacket, false);
|
||||
for (BlockEntityElement element : this.elements) {
|
||||
element.despawn(player);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
package net.momirealms.craftengine.bukkit.block.entity.renderer.element;
|
||||
|
||||
import net.momirealms.craftengine.core.block.entity.render.element.BlockEntityElementConfigs;
|
||||
|
||||
public class BukkitBlockEntityElementConfigs extends BlockEntityElementConfigs {
|
||||
|
||||
static {
|
||||
register(ITEM_DISPLAY, ItemDisplayBlockEntityElementConfig.FACTORY);
|
||||
}
|
||||
|
||||
public static void init() {
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
package net.momirealms.craftengine.bukkit.block.entity.renderer.element;
|
||||
|
||||
import it.unimi.dsi.fastutil.ints.IntList;
|
||||
import net.momirealms.craftengine.bukkit.nms.FastNMS;
|
||||
import net.momirealms.craftengine.bukkit.plugin.reflection.minecraft.CoreReflections;
|
||||
import net.momirealms.craftengine.bukkit.plugin.reflection.minecraft.MEntityTypes;
|
||||
import net.momirealms.craftengine.core.block.entity.render.element.BlockEntityElement;
|
||||
import net.momirealms.craftengine.core.entity.player.Player;
|
||||
import net.momirealms.craftengine.core.world.BlockPos;
|
||||
import org.joml.Vector3f;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
public class ItemDisplayBlockEntityElement implements BlockEntityElement {
|
||||
private final Object cachedSpawnPacket;
|
||||
private final Object cachedDespawnPacket;
|
||||
|
||||
public ItemDisplayBlockEntityElement(ItemDisplayBlockEntityElementConfig config, BlockPos pos) {
|
||||
int entityId = CoreReflections.instance$Entity$ENTITY_COUNTER.incrementAndGet();
|
||||
Vector3f position = config.position();
|
||||
this.cachedSpawnPacket = FastNMS.INSTANCE.constructor$ClientboundBundlePacket(List.of(
|
||||
FastNMS.INSTANCE.constructor$ClientboundAddEntityPacket(
|
||||
entityId, UUID.randomUUID(), pos.x() + position.x, pos.y() + position.y, pos.z() + position.z,
|
||||
config.xRot(), config.yRot(), MEntityTypes.ITEM_DISPLAY, 0, CoreReflections.instance$Vec3$Zero, 0
|
||||
),
|
||||
FastNMS.INSTANCE.constructor$ClientboundSetEntityDataPacket(
|
||||
entityId, config.metadataValues().get()
|
||||
)
|
||||
));
|
||||
this.cachedDespawnPacket = FastNMS.INSTANCE.constructor$ClientboundRemoveEntitiesPacket(IntList.of(entityId));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void despawn(Player player) {
|
||||
player.sendPacket(this.cachedDespawnPacket, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void spawn(Player player) {
|
||||
player.sendPacket(this.cachedSpawnPacket, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(Player player) {
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,131 @@
|
||||
package net.momirealms.craftengine.bukkit.block.entity.renderer.element;
|
||||
|
||||
import net.momirealms.craftengine.bukkit.entity.data.ItemDisplayEntityData;
|
||||
import net.momirealms.craftengine.bukkit.item.BukkitItemManager;
|
||||
import net.momirealms.craftengine.core.block.entity.render.element.BlockEntityElement;
|
||||
import net.momirealms.craftengine.core.block.entity.render.element.BlockEntityElementConfig;
|
||||
import net.momirealms.craftengine.core.block.entity.render.element.BlockEntityElementConfigFactory;
|
||||
import net.momirealms.craftengine.core.entity.Billboard;
|
||||
import net.momirealms.craftengine.core.entity.ItemDisplayContext;
|
||||
import net.momirealms.craftengine.core.item.Item;
|
||||
import net.momirealms.craftengine.core.util.Key;
|
||||
import net.momirealms.craftengine.core.util.LazyReference;
|
||||
import net.momirealms.craftengine.core.util.ResourceConfigUtils;
|
||||
import net.momirealms.craftengine.core.world.BlockPos;
|
||||
import org.joml.Quaternionf;
|
||||
import org.joml.Vector3f;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
|
||||
public class ItemDisplayBlockEntityElementConfig implements BlockEntityElementConfig<ItemDisplayBlockEntityElement> {
|
||||
public static final Factory FACTORY = new Factory();
|
||||
private final LazyReference<List<Object>> lazyMetadataPacket;
|
||||
private final LazyReference<Item<?>> item;
|
||||
private final Vector3f scale;
|
||||
private final Vector3f position;
|
||||
private final Vector3f translation;
|
||||
private final float xRot;
|
||||
private final float yRot;
|
||||
private final Quaternionf rotation;
|
||||
private final ItemDisplayContext displayContext;
|
||||
private final Billboard billboard;
|
||||
|
||||
public ItemDisplayBlockEntityElementConfig(LazyReference<Item<?>> item,
|
||||
Vector3f scale,
|
||||
Vector3f position,
|
||||
Vector3f translation,
|
||||
float xRot,
|
||||
float yRot,
|
||||
Quaternionf rotation,
|
||||
ItemDisplayContext displayContext,
|
||||
Billboard billboard) {
|
||||
this.item = item;
|
||||
this.scale = scale;
|
||||
this.position = position;
|
||||
this.translation = translation;
|
||||
this.xRot = xRot;
|
||||
this.yRot = yRot;
|
||||
this.rotation = rotation;
|
||||
this.displayContext = displayContext;
|
||||
this.billboard = billboard;
|
||||
this.lazyMetadataPacket = LazyReference.lazyReference(() -> {
|
||||
List<Object> dataValues = new ArrayList<>();
|
||||
ItemDisplayEntityData.DisplayedItem.addEntityDataIfNotDefaultValue(item.get().getLiteralObject(), dataValues);
|
||||
ItemDisplayEntityData.Scale.addEntityDataIfNotDefaultValue(this.scale, dataValues);
|
||||
ItemDisplayEntityData.RotationLeft.addEntityDataIfNotDefaultValue(this.rotation, dataValues);
|
||||
ItemDisplayEntityData.BillboardConstraints.addEntityDataIfNotDefaultValue(this.billboard.id(), dataValues);
|
||||
ItemDisplayEntityData.Translation.addEntityDataIfNotDefaultValue(this.translation, dataValues);
|
||||
ItemDisplayEntityData.DisplayType.addEntityDataIfNotDefaultValue(this.displayContext.id(), dataValues);
|
||||
return dataValues;
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemDisplayBlockEntityElement create(BlockPos pos) {
|
||||
return new ItemDisplayBlockEntityElement(this, pos);
|
||||
}
|
||||
|
||||
public Item<?> item() {
|
||||
return this.item.get();
|
||||
}
|
||||
|
||||
public Vector3f scale() {
|
||||
return this.scale;
|
||||
}
|
||||
|
||||
public Vector3f translation() {
|
||||
return this.translation;
|
||||
}
|
||||
|
||||
public Vector3f position() {
|
||||
return this.position;
|
||||
}
|
||||
|
||||
public float yRot() {
|
||||
return this.yRot;
|
||||
}
|
||||
|
||||
public float xRot() {
|
||||
return this.xRot;
|
||||
}
|
||||
|
||||
public Billboard billboard() {
|
||||
return billboard;
|
||||
}
|
||||
|
||||
public ItemDisplayContext displayContext() {
|
||||
return displayContext;
|
||||
}
|
||||
|
||||
public Quaternionf rotation() {
|
||||
return rotation;
|
||||
}
|
||||
|
||||
public LazyReference<List<Object>> metadataValues() {
|
||||
return this.lazyMetadataPacket;
|
||||
}
|
||||
|
||||
public static class Factory implements BlockEntityElementConfigFactory {
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public <E extends BlockEntityElement> BlockEntityElementConfig<E> create(Map<String, Object> arguments) {
|
||||
// todo item should not be null
|
||||
Key itemId = Key.of(ResourceConfigUtils.requireNonEmptyStringOrThrow(arguments.get("item"), ""));
|
||||
return (BlockEntityElementConfig<E>) new ItemDisplayBlockEntityElementConfig(
|
||||
LazyReference.lazyReference(() -> BukkitItemManager.instance().createWrappedItem(itemId, null)),
|
||||
ResourceConfigUtils.getAsVector3f(arguments.getOrDefault("scale", 1f), "scale"),
|
||||
ResourceConfigUtils.getAsVector3f(arguments.getOrDefault("position", 0.5f), "position"),
|
||||
ResourceConfigUtils.getAsVector3f(arguments.get("translation"), "translation"),
|
||||
ResourceConfigUtils.getAsFloat(arguments.getOrDefault("pitch", 0f), "pitch"),
|
||||
ResourceConfigUtils.getAsFloat(arguments.getOrDefault("yaw", 0f), "yaw"),
|
||||
ResourceConfigUtils.getAsQuaternionf(arguments.getOrDefault("rotation", 0f), "rotation"),
|
||||
ItemDisplayContext.valueOf(arguments.getOrDefault("display-context", "none").toString().toUpperCase(Locale.ROOT)),
|
||||
Billboard.valueOf(arguments.getOrDefault("billboard", "fixed").toString().toUpperCase(Locale.ROOT))
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -5,6 +5,7 @@ import net.momirealms.craftengine.bukkit.advancement.BukkitAdvancementManager;
|
||||
import net.momirealms.craftengine.bukkit.api.event.CraftEngineReloadEvent;
|
||||
import net.momirealms.craftengine.bukkit.block.BukkitBlockManager;
|
||||
import net.momirealms.craftengine.bukkit.block.behavior.BukkitBlockBehaviors;
|
||||
import net.momirealms.craftengine.bukkit.block.entity.renderer.element.BukkitBlockEntityElementConfigs;
|
||||
import net.momirealms.craftengine.bukkit.entity.furniture.BukkitFurnitureManager;
|
||||
import net.momirealms.craftengine.bukkit.entity.furniture.hitbox.BukkitHitBoxTypes;
|
||||
import net.momirealms.craftengine.bukkit.entity.projectile.BukkitProjectileManager;
|
||||
@@ -189,6 +190,7 @@ public class BukkitCraftEngine extends CraftEngine {
|
||||
BukkitBlockBehaviors.init();
|
||||
BukkitItemBehaviors.init();
|
||||
BukkitHitBoxTypes.init();
|
||||
BukkitBlockEntityElementConfigs.init();
|
||||
PacketConsumers.initEntities(RegistryUtils.currentEntityTypeRegistrySize());
|
||||
super.packManager = new BukkitPackManager(this);
|
||||
super.senderFactory = new BukkitSenderFactory(this);
|
||||
|
||||
@@ -4,7 +4,7 @@ import net.momirealms.craftengine.bukkit.block.entity.renderer.BukkitBlockEntity
|
||||
import net.momirealms.craftengine.bukkit.nms.FastNMS;
|
||||
import net.momirealms.craftengine.bukkit.util.LightUtils;
|
||||
import net.momirealms.craftengine.core.block.entity.render.BlockEntityRenderer;
|
||||
import net.momirealms.craftengine.core.block.entity.render.BlockEntityRendererConfig;
|
||||
import net.momirealms.craftengine.core.block.entity.render.element.BlockEntityElement;
|
||||
import net.momirealms.craftengine.core.plugin.config.Config;
|
||||
import net.momirealms.craftengine.core.util.SectionPosUtils;
|
||||
import net.momirealms.craftengine.core.world.*;
|
||||
@@ -45,11 +45,11 @@ public class BukkitCEWorld extends CEWorld {
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockEntityRenderer createBlockEntityRenderer(BlockEntityRendererConfig config, BlockPos pos) {
|
||||
public BlockEntityRenderer createBlockEntityRenderer(BlockEntityElement[] elements, BlockPos pos) {
|
||||
Object serverLevel = this.world.serverWorld();
|
||||
Object chunkSource = FastNMS.INSTANCE.method$ServerLevel$getChunkSource(serverLevel);
|
||||
long chunkKey = ChunkPos.asLong(pos.x() >> 4, pos.z() >> 4);
|
||||
Object chunkHolder = FastNMS.INSTANCE.method$ServerChunkCache$getVisibleChunkIfPresent(chunkSource, chunkKey);
|
||||
return new BukkitBlockEntityRenderer(new WeakReference<>(chunkHolder), config, pos);
|
||||
return new BukkitBlockEntityRenderer(new WeakReference<>(chunkHolder), elements);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,8 +4,9 @@ import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import it.unimi.dsi.fastutil.ints.Int2IntOpenHashMap;
|
||||
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
|
||||
import net.momirealms.craftengine.core.block.entity.render.BlockEntityElement;
|
||||
import net.momirealms.craftengine.core.block.entity.render.BlockEntityRendererConfig;
|
||||
import net.momirealms.craftengine.core.block.entity.render.element.BlockEntityElement;
|
||||
import net.momirealms.craftengine.core.block.entity.render.element.BlockEntityElementConfig;
|
||||
import net.momirealms.craftengine.core.block.entity.render.element.BlockEntityElementConfigs;
|
||||
import net.momirealms.craftengine.core.block.properties.Properties;
|
||||
import net.momirealms.craftengine.core.block.properties.Property;
|
||||
import net.momirealms.craftengine.core.loot.LootTable;
|
||||
@@ -168,8 +169,6 @@ public abstract class AbstractBlockManager extends AbstractModelGenerator implem
|
||||
|
||||
protected abstract CustomBlock.Builder platformBuilder(Key id);
|
||||
|
||||
protected abstract BlockEntityElement createBlockEntityElement(Map<String, Object> arguments);
|
||||
|
||||
public class BlockParser implements ConfigParser {
|
||||
public static final String[] CONFIG_SECTION_NAME = new String[]{"blocks", "block"};
|
||||
|
||||
@@ -225,7 +224,7 @@ public abstract class AbstractBlockManager extends AbstractModelGenerator implem
|
||||
// 获取原版外观的注册表id
|
||||
int appearanceId = pluginFormattedBlockStateToRegistryId(ResourceConfigUtils.requireNonEmptyStringOrThrow(
|
||||
stateSection.get("state"), "warning.config.block.state.missing_state"));
|
||||
Optional<BlockEntityRendererConfig> blockEntityRenderer = parseBlockEntityRender(stateSection.get("entity-renderer"));
|
||||
Optional<BlockEntityElementConfig<? extends BlockEntityElement>[]> blockEntityRenderer = parseBlockEntityRender(stateSection.get("entity-renderer"));
|
||||
|
||||
// 为原版外观赋予外观模型并检查模型冲突
|
||||
this.arrangeModelForStateAndVerify(appearanceId, ResourceConfigUtils.get(stateSection, "model", "models"));
|
||||
@@ -299,11 +298,12 @@ public abstract class AbstractBlockManager extends AbstractModelGenerator implem
|
||||
return appearances;
|
||||
}
|
||||
|
||||
private Optional<BlockEntityRendererConfig> parseBlockEntityRender(Object arguments) {
|
||||
@SuppressWarnings("unchecked")
|
||||
private Optional<BlockEntityElementConfig<? extends BlockEntityElement>[]> parseBlockEntityRender(Object arguments) {
|
||||
if (arguments == null) return Optional.empty();
|
||||
List<BlockEntityElement> elements = ResourceConfigUtils.parseConfigAsList(arguments, AbstractBlockManager.this::createBlockEntityElement);
|
||||
if (elements.isEmpty()) return Optional.empty();
|
||||
return Optional.of(new BlockEntityRendererConfig(elements.toArray(new BlockEntityElement[0])));
|
||||
List<BlockEntityElementConfig<? extends BlockEntityElement>> blockEntityElementConfigs = ResourceConfigUtils.parseConfigAsList(arguments, BlockEntityElementConfigs::fromMap);
|
||||
if (blockEntityElementConfigs.isEmpty()) return Optional.empty();
|
||||
return Optional.of(blockEntityElementConfigs.toArray(new BlockEntityElementConfig[0]));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
@@ -86,7 +86,7 @@ public abstract class AbstractCustomBlock implements CustomBlock {
|
||||
state.setSettings(blockStateVariant.settings());
|
||||
state.setVanillaBlockState(BlockRegistryMirror.stateByRegistryId(stateId));
|
||||
state.setCustomBlockState(BlockRegistryMirror.stateByRegistryId(blockStateVariant.internalRegistryId()));
|
||||
blockStateAppearance.blockEntityRenderer().ifPresent(state::setEntityRenderer);
|
||||
blockStateAppearance.blockEntityRenderer().ifPresent(state::setRenderers);
|
||||
}
|
||||
|
||||
// double check if there's any invalid state
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
package net.momirealms.craftengine.core.block;
|
||||
|
||||
import net.momirealms.craftengine.core.block.entity.render.BlockEntityRendererConfig;
|
||||
import net.momirealms.craftengine.core.block.entity.render.element.BlockEntityElement;
|
||||
import net.momirealms.craftengine.core.block.entity.render.element.BlockEntityElementConfig;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
public record BlockStateAppearance(int stateRegistryId, Optional<BlockEntityRendererConfig> blockEntityRenderer) {
|
||||
public record BlockStateAppearance(int stateRegistryId, Optional<BlockEntityElementConfig<? extends BlockEntityElement>[]> blockEntityRenderer) {
|
||||
public static final BlockStateAppearance INVALID = new BlockStateAppearance(-1, Optional.empty());
|
||||
|
||||
public boolean isInvalid() {
|
||||
|
||||
@@ -4,7 +4,8 @@ import it.unimi.dsi.fastutil.objects.Reference2ObjectArrayMap;
|
||||
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.block.entity.render.BlockEntityRendererConfig;
|
||||
import net.momirealms.craftengine.core.block.entity.render.element.BlockEntityElement;
|
||||
import net.momirealms.craftengine.core.block.entity.render.element.BlockEntityElementConfig;
|
||||
import net.momirealms.craftengine.core.block.entity.tick.BlockEntityTicker;
|
||||
import net.momirealms.craftengine.core.block.properties.Property;
|
||||
import net.momirealms.craftengine.core.entity.player.Player;
|
||||
@@ -32,7 +33,7 @@ public final class ImmutableBlockState extends BlockStateHolder {
|
||||
private BlockSettings settings;
|
||||
private BlockEntityType<? extends BlockEntity> blockEntityType;
|
||||
@Nullable
|
||||
private BlockEntityRendererConfig renderer;
|
||||
private BlockEntityElementConfig<? extends BlockEntityElement>[] renderers;
|
||||
|
||||
ImmutableBlockState(
|
||||
Holder<CustomBlock> owner,
|
||||
@@ -69,13 +70,12 @@ public final class ImmutableBlockState extends BlockStateHolder {
|
||||
return this == EmptyBlock.STATE;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public BlockEntityRendererConfig entityRenderer() {
|
||||
return this.renderer;
|
||||
public BlockEntityElementConfig<? extends BlockEntityElement>[] renderers() {
|
||||
return renderers;
|
||||
}
|
||||
|
||||
public void setEntityRenderer(@Nullable BlockEntityRendererConfig rendererConfig) {
|
||||
this.renderer = rendererConfig;
|
||||
public void setRenderers(BlockEntityElementConfig<? extends BlockEntityElement>[] renderers) {
|
||||
this.renderers = renderers;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -98,7 +98,7 @@ public final class ImmutableBlockState extends BlockStateHolder {
|
||||
}
|
||||
|
||||
public boolean hasBlockEntityRenderer() {
|
||||
return this.renderer != null;
|
||||
return this.renderers != null;
|
||||
}
|
||||
|
||||
public BlockStateWrapper customBlockState() {
|
||||
|
||||
@@ -1,32 +0,0 @@
|
||||
package net.momirealms.craftengine.core.block.entity.render;
|
||||
|
||||
import net.momirealms.craftengine.core.entity.Billboard;
|
||||
import net.momirealms.craftengine.core.entity.ItemDisplayContext;
|
||||
import net.momirealms.craftengine.core.item.Item;
|
||||
import net.momirealms.craftengine.core.util.LazyReference;
|
||||
import org.joml.Quaternionf;
|
||||
import org.joml.Vector3f;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface BlockEntityElement {
|
||||
Item<?> item();
|
||||
|
||||
Vector3f scale();
|
||||
|
||||
Vector3f translation();
|
||||
|
||||
Vector3f position();
|
||||
|
||||
float yRot();
|
||||
|
||||
float xRot();
|
||||
|
||||
Billboard billboard();
|
||||
|
||||
ItemDisplayContext displayContext();
|
||||
|
||||
Quaternionf rotation();
|
||||
|
||||
LazyReference<List<Object>> metadataValues();
|
||||
}
|
||||
@@ -8,7 +8,11 @@ public abstract class BlockEntityRenderer {
|
||||
|
||||
public abstract void despawn();
|
||||
|
||||
public abstract void update();
|
||||
|
||||
public abstract void spawn(Player player);
|
||||
|
||||
public abstract void despawn(Player player);
|
||||
|
||||
public abstract void update(Player player);
|
||||
}
|
||||
|
||||
@@ -1,4 +0,0 @@
|
||||
package net.momirealms.craftengine.core.block.entity.render;
|
||||
|
||||
public record BlockEntityRendererConfig(BlockEntityElement[] elements) {
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package net.momirealms.craftengine.core.block.entity.render.element;
|
||||
|
||||
import net.momirealms.craftengine.core.entity.player.Player;
|
||||
|
||||
public interface BlockEntityElement {
|
||||
|
||||
void spawn(Player player);
|
||||
|
||||
void despawn(Player player);
|
||||
|
||||
void update(Player player);
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
package net.momirealms.craftengine.core.block.entity.render.element;
|
||||
|
||||
import net.momirealms.craftengine.core.world.BlockPos;
|
||||
|
||||
public interface BlockEntityElementConfig<E extends BlockEntityElement> {
|
||||
|
||||
E create(BlockPos pos);
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
package net.momirealms.craftengine.core.block.entity.render.element;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
@FunctionalInterface
|
||||
public interface BlockEntityElementConfigFactory {
|
||||
|
||||
<E extends BlockEntityElement> BlockEntityElementConfig<E> create(Map<String, Object> args);
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
package net.momirealms.craftengine.core.block.entity.render.element;
|
||||
|
||||
import net.momirealms.craftengine.core.plugin.locale.LocalizedResourceConfigException;
|
||||
import net.momirealms.craftengine.core.registry.BuiltInRegistries;
|
||||
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 BlockEntityElementConfigs {
|
||||
public static final Key ITEM_DISPLAY = Key.of("craftengine:item_display");
|
||||
public static final Key TEXT_DISPLAY = Key.of("craftengine:text_display");
|
||||
|
||||
public static void register(Key key, BlockEntityElementConfigFactory type) {
|
||||
((WritableRegistry<BlockEntityElementConfigFactory>) BuiltInRegistries.BLOCK_ENTITY_ELEMENT_TYPE)
|
||||
.register(ResourceKey.create(Registries.BLOCK_ENTITY_ELEMENT_TYPE.location(), key), type);
|
||||
}
|
||||
|
||||
public static <E extends BlockEntityElement> BlockEntityElementConfig<E> fromMap(Map<String, Object> arguments) {
|
||||
Key type = Optional.ofNullable(arguments.get("type")).map(String::valueOf).map(Key::of).orElse(ITEM_DISPLAY);
|
||||
BlockEntityElementConfigFactory factory = BuiltInRegistries.BLOCK_ENTITY_ELEMENT_TYPE.getValue(type);
|
||||
if (factory == null) {
|
||||
// todo 发送消息
|
||||
throw new LocalizedResourceConfigException("", type.toString());
|
||||
}
|
||||
return factory.create(arguments);
|
||||
}
|
||||
}
|
||||
@@ -35,7 +35,10 @@ public final class LegacyRecipeTypes {
|
||||
public static final Key SMITHING_TRIM = Key.of("smithing_trim");
|
||||
public static final Key DECORATED_POT_RECIPE = Key.of("crafting_decorated_pot");
|
||||
|
||||
public static void register() {
|
||||
public static void init() {
|
||||
}
|
||||
|
||||
static {
|
||||
register(SHAPED_RECIPE, new LegacyRecipe.Type(LegacyShapedRecipe::read));
|
||||
register(SHAPELESS_RECIPE, new LegacyRecipe.Type(LegacyShapelessRecipe::read));
|
||||
register(ARMOR_DYE, new LegacyRecipe.Type(LegacyCustomRecipe::read));
|
||||
|
||||
@@ -15,7 +15,10 @@ public final class RecipeDisplayTypes {
|
||||
public static final Key STONECUTTER = Key.of("stonecutter");
|
||||
public static final Key SMITHING = Key.of("smithing");
|
||||
|
||||
public static void register() {
|
||||
public static void init() {
|
||||
}
|
||||
|
||||
static {
|
||||
register(CRAFTING_SHAPELESS, new RecipeDisplay.Type(ShapelessCraftingRecipeDisplay::read));
|
||||
register(CRAFTING_SHAPED, new RecipeDisplay.Type(ShapedCraftingRecipeDisplay::read));
|
||||
register(FURNACE, new RecipeDisplay.Type(FurnaceRecipeDisplay::read));
|
||||
|
||||
@@ -18,7 +18,10 @@ public final class SlotDisplayTypes {
|
||||
public static final Key WITH_REMAINDER = Key.of("with_remainder");
|
||||
public static final Key COMPOSITE = Key.of("composite");
|
||||
|
||||
public static void register() {
|
||||
public static void init() {
|
||||
}
|
||||
|
||||
static {
|
||||
register(EMPTY, new SlotDisplay.Type(EmptySlotDisplay::read));
|
||||
register(ANY_FUEL, new SlotDisplay.Type(AnyFuelDisplay::read));
|
||||
register(ITEM, new SlotDisplay.Type(ItemSlotDisplay::read));
|
||||
|
||||
@@ -102,9 +102,9 @@ public abstract class CraftEngine implements Plugin {
|
||||
}
|
||||
|
||||
protected void onPluginLoad() {
|
||||
RecipeDisplayTypes.register();
|
||||
SlotDisplayTypes.register();
|
||||
LegacyRecipeTypes.register();
|
||||
RecipeDisplayTypes.init();
|
||||
SlotDisplayTypes.init();
|
||||
LegacyRecipeTypes.init();
|
||||
((Logger) LogManager.getRootLogger()).addFilter(new LogFilter());
|
||||
((Logger) LogManager.getRootLogger()).addFilter(new DisconnectLogFilter());
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@ import net.momirealms.craftengine.core.util.ResourceConfigUtils;
|
||||
import java.util.Map;
|
||||
|
||||
public class ExpressionNumberProvider implements NumberProvider {
|
||||
public static final FactoryImpl FACTORY = new FactoryImpl();
|
||||
public static final Factory FACTORY = new Factory();
|
||||
private final String expr;
|
||||
|
||||
public ExpressionNumberProvider(String expr) {
|
||||
@@ -52,7 +52,7 @@ public class ExpressionNumberProvider implements NumberProvider {
|
||||
return this.expr;
|
||||
}
|
||||
|
||||
public static class FactoryImpl implements NumberProviderFactory {
|
||||
public static class Factory implements NumberProviderFactory {
|
||||
|
||||
@Override
|
||||
public NumberProvider create(Map<String, Object> arguments) {
|
||||
|
||||
@@ -9,7 +9,7 @@ import net.momirealms.craftengine.core.util.ResourceConfigUtils;
|
||||
import java.util.Map;
|
||||
|
||||
public class FixedNumberProvider implements NumberProvider {
|
||||
public static final FactoryImpl FACTORY = new FactoryImpl();
|
||||
public static final Factory FACTORY = new Factory();
|
||||
private final double value;
|
||||
|
||||
public FixedNumberProvider(double value) {
|
||||
@@ -35,7 +35,7 @@ public class FixedNumberProvider implements NumberProvider {
|
||||
return new FixedNumberProvider(value);
|
||||
}
|
||||
|
||||
public static class FactoryImpl implements NumberProviderFactory {
|
||||
public static class Factory implements NumberProviderFactory {
|
||||
|
||||
@Override
|
||||
public NumberProvider create(Map<String, Object> arguments) {
|
||||
|
||||
@@ -10,8 +10,7 @@ import java.util.Random;
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
|
||||
public class GaussianNumberProvider implements NumberProvider {
|
||||
public static final FactoryImpl FACTORY = new FactoryImpl();
|
||||
|
||||
public static final Factory FACTORY = new Factory();
|
||||
private final double min;
|
||||
private final double max;
|
||||
private final double mean;
|
||||
@@ -83,7 +82,7 @@ public class GaussianNumberProvider implements NumberProvider {
|
||||
return stdDev;
|
||||
}
|
||||
|
||||
public static class FactoryImpl implements NumberProviderFactory {
|
||||
public static class Factory implements NumberProviderFactory {
|
||||
|
||||
@Override
|
||||
public NumberProvider create(Map<String, Object> arguments) {
|
||||
|
||||
@@ -8,7 +8,7 @@ import net.momirealms.craftengine.core.util.ResourceConfigUtils;
|
||||
import java.util.Map;
|
||||
|
||||
public class UniformNumberProvider implements NumberProvider {
|
||||
public static final FactoryImpl FACTORY = new FactoryImpl();
|
||||
public static final Factory FACTORY = new Factory();
|
||||
private final NumberProvider min;
|
||||
private final NumberProvider max;
|
||||
|
||||
@@ -45,7 +45,7 @@ public class UniformNumberProvider implements NumberProvider {
|
||||
return NumberProviders.UNIFORM;
|
||||
}
|
||||
|
||||
public static class FactoryImpl implements NumberProviderFactory {
|
||||
public static class Factory implements NumberProviderFactory {
|
||||
|
||||
@Override
|
||||
public NumberProvider create(Map<String, Object> arguments) {
|
||||
|
||||
@@ -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.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.item.ItemDataModifierFactory;
|
||||
@@ -87,6 +88,7 @@ public class BuiltInRegistries {
|
||||
public static final Registry<ItemUpdaterType<?>> ITEM_UPDATER_TYPE = createConstantBoundRegistry(Registries.ITEM_UPDATER_TYPE, 16);
|
||||
public static final Registry<NetworkCodec<FriendlyByteBuf, ? extends ModPacket>> MOD_PACKET = createConstantBoundRegistry(Registries.MOD_PACKET, 16);
|
||||
public static final Registry<BlockEntityType<?>> BLOCK_ENTITY_TYPE = createConstantBoundRegistry(Registries.BLOCK_ENTITY_TYPE, 128);
|
||||
public static final Registry<BlockEntityElementConfigFactory> BLOCK_ENTITY_ELEMENT_TYPE = createConstantBoundRegistry(Registries.BLOCK_ENTITY_ELEMENT_TYPE, 16);
|
||||
|
||||
private static <T> Registry<T> createConstantBoundRegistry(ResourceKey<? extends Registry<T>> key, int expectedSize) {
|
||||
return new ConstantBoundRegistry<>(key, expectedSize);
|
||||
|
||||
@@ -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.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.item.ItemDataModifierFactory;
|
||||
@@ -89,4 +90,5 @@ public class Registries {
|
||||
public static final ResourceKey<Registry<ItemUpdaterType<?>>> ITEM_UPDATER_TYPE = ResourceKey.create(ROOT_REGISTRY, Key.withDefaultNamespace("item_updater_type"));
|
||||
public static final ResourceKey<Registry<NetworkCodec<FriendlyByteBuf, ? extends ModPacket>>> MOD_PACKET = ResourceKey.create(ROOT_REGISTRY, Key.withDefaultNamespace("mod_packet_type"));
|
||||
public static final ResourceKey<Registry<BlockEntityType<?>>> BLOCK_ENTITY_TYPE = ResourceKey.create(ROOT_REGISTRY, Key.withDefaultNamespace("block_entity_type"));
|
||||
public static final ResourceKey<Registry<BlockEntityElementConfigFactory>> BLOCK_ENTITY_ELEMENT_TYPE = ResourceKey.create(ROOT_REGISTRY, Key.withDefaultNamespace("block_entity_element_type"));
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ import it.unimi.dsi.fastutil.objects.ReferenceOpenHashSet;
|
||||
import net.momirealms.craftengine.core.block.ImmutableBlockState;
|
||||
import net.momirealms.craftengine.core.block.entity.BlockEntity;
|
||||
import net.momirealms.craftengine.core.block.entity.render.BlockEntityRenderer;
|
||||
import net.momirealms.craftengine.core.block.entity.render.BlockEntityRendererConfig;
|
||||
import net.momirealms.craftengine.core.block.entity.render.element.BlockEntityElement;
|
||||
import net.momirealms.craftengine.core.block.entity.tick.TickingBlockEntity;
|
||||
import net.momirealms.craftengine.core.plugin.CraftEngine;
|
||||
import net.momirealms.craftengine.core.plugin.config.Config;
|
||||
@@ -220,5 +220,5 @@ public abstract class CEWorld {
|
||||
this.isTickingBlockEntities = false;
|
||||
}
|
||||
|
||||
public abstract BlockEntityRenderer createBlockEntityRenderer(BlockEntityRendererConfig config, BlockPos pos);
|
||||
public abstract BlockEntityRenderer createBlockEntityRenderer(BlockEntityElement[] elements, BlockPos pos);
|
||||
}
|
||||
|
||||
@@ -5,7 +5,8 @@ import net.momirealms.craftengine.core.block.EmptyBlock;
|
||||
import net.momirealms.craftengine.core.block.ImmutableBlockState;
|
||||
import net.momirealms.craftengine.core.block.entity.BlockEntity;
|
||||
import net.momirealms.craftengine.core.block.entity.render.BlockEntityRenderer;
|
||||
import net.momirealms.craftengine.core.block.entity.render.BlockEntityRendererConfig;
|
||||
import net.momirealms.craftengine.core.block.entity.render.element.BlockEntityElement;
|
||||
import net.momirealms.craftengine.core.block.entity.render.element.BlockEntityElementConfig;
|
||||
import net.momirealms.craftengine.core.block.entity.tick.*;
|
||||
import net.momirealms.craftengine.core.entity.player.Player;
|
||||
import net.momirealms.craftengine.core.plugin.logger.Debugger;
|
||||
@@ -103,9 +104,13 @@ public class CEChunk {
|
||||
}
|
||||
|
||||
public void addBlockEntityRenderer(BlockPos pos, ImmutableBlockState state) {
|
||||
BlockEntityRendererConfig config = state.entityRenderer();
|
||||
if (config != null) {
|
||||
BlockEntityRenderer renderer = this.world.createBlockEntityRenderer(config, pos);
|
||||
BlockEntityElementConfig<? extends BlockEntityElement>[] renderers = state.renderers();
|
||||
if (renderers != null && renderers.length > 0) {
|
||||
BlockEntityElement[] elements = new BlockEntityElement[renderers.length];
|
||||
for (int i = 0; i < elements.length; i++) {
|
||||
elements[i] = renderers[i].create(pos);
|
||||
}
|
||||
BlockEntityRenderer renderer = this.world.createBlockEntityRenderer(elements, pos);
|
||||
renderer.spawn();
|
||||
try {
|
||||
this.renderLock.writeLock().lock();
|
||||
|
||||
Reference in New Issue
Block a user