Delay registration of various client settings until the client is fully initialized.
This commit is contained in:
@@ -11,7 +11,6 @@ import com.google.common.base.Preconditions;
|
||||
|
||||
import net.fabricmc.api.EnvType;
|
||||
import net.fabricmc.api.Environment;
|
||||
import net.fabricmc.fabric.api.client.rendereregistry.v1.BlockEntityRendererRegistry;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.entity.BlockEntityType;
|
||||
import net.minecraft.util.Identifier;
|
||||
@@ -19,6 +18,7 @@ import net.minecraft.util.registry.Registry;
|
||||
|
||||
import appeng.api.features.AEFeature;
|
||||
import appeng.block.AEBaseTileBlock;
|
||||
import appeng.bootstrap.components.BlockEntityRendererComponent;
|
||||
import appeng.bootstrap.components.ITileEntityRegistrationComponent;
|
||||
import appeng.bootstrap.definitions.TileEntityDefinition;
|
||||
import appeng.core.AppEng;
|
||||
@@ -115,7 +115,8 @@ public class BlockEntityBuilder<T extends AEBaseBlockEntity> {
|
||||
@Environment(EnvType.CLIENT)
|
||||
private void buildClient() {
|
||||
if (tileEntityRendering.tileEntityRenderer != null) {
|
||||
BlockEntityRendererRegistry.INSTANCE.register(type, tileEntityRendering.tileEntityRenderer);
|
||||
factory.addBootstrapComponent(
|
||||
new BlockEntityRendererComponent<>(type, tileEntityRendering.tileEntityRenderer));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
package appeng.bootstrap.components;
|
||||
|
||||
import java.util.function.Function;
|
||||
|
||||
import net.fabricmc.fabric.api.client.rendereregistry.v1.BlockEntityRendererRegistry;
|
||||
import net.minecraft.block.entity.BlockEntity;
|
||||
import net.minecraft.block.entity.BlockEntityType;
|
||||
import net.minecraft.client.render.block.entity.BlockEntityRenderDispatcher;
|
||||
import net.minecraft.client.render.block.entity.BlockEntityRenderer;
|
||||
|
||||
/**
|
||||
* Registers a block entity renderer for a given block entity type. This must
|
||||
* occur late in the client's initialization, since the constructors of our
|
||||
* block entity renderers rely on the client being fully initialized.
|
||||
*/
|
||||
public class BlockEntityRendererComponent<T extends BlockEntity> implements IClientSetupComponent {
|
||||
|
||||
private final BlockEntityType<T> type;
|
||||
|
||||
private final Function<BlockEntityRenderDispatcher, BlockEntityRenderer<T>> renderer;
|
||||
|
||||
public BlockEntityRendererComponent(BlockEntityType<T> type,
|
||||
Function<BlockEntityRenderDispatcher, BlockEntityRenderer<T>> renderer) {
|
||||
this.type = type;
|
||||
this.renderer = renderer;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setup() {
|
||||
BlockEntityRendererRegistry.INSTANCE.register(type, renderer);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -13,6 +13,7 @@ import javax.annotation.Nonnull;
|
||||
|
||||
import net.fabricmc.api.EnvType;
|
||||
import net.fabricmc.api.Environment;
|
||||
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientLifecycleEvents;
|
||||
import net.fabricmc.fabric.api.client.keybinding.v1.KeyBindingHelper;
|
||||
import net.fabricmc.fabric.api.client.model.ModelLoadingRegistry;
|
||||
import net.fabricmc.fabric.api.client.particle.v1.ParticleFactoryRegistry;
|
||||
@@ -184,7 +185,9 @@ public final class AppEngClient extends AppEngBase {
|
||||
|
||||
ModelsReloadCallback.EVENT.register(this::onModelsReloaded);
|
||||
|
||||
callDeferredBootstrapComponents(IClientSetupComponent.class, IClientSetupComponent::setup);
|
||||
ClientLifecycleEvents.CLIENT_STARTED.register(client -> {
|
||||
callDeferredBootstrapComponents(IClientSetupComponent.class, IClientSetupComponent::setup);
|
||||
});
|
||||
registerModelProviders();
|
||||
registerParticleRenderers();
|
||||
registerEntityRenderers();
|
||||
|
||||
Reference in New Issue
Block a user