116 lines
5.4 KiB
Java
116 lines
5.4 KiB
Java
/*
|
|
* Decompiled with CFR 0.152.
|
|
*
|
|
* Could not load the following classes:
|
|
* com.google.common.collect.ImmutableMap
|
|
* org.jspecify.annotations.Nullable
|
|
*/
|
|
package net.minecraft.client.renderer.blockentity;
|
|
|
|
import com.google.common.collect.ImmutableMap;
|
|
import com.mojang.blaze3d.vertex.PoseStack;
|
|
import java.util.Map;
|
|
import java.util.function.Supplier;
|
|
import net.minecraft.CrashReport;
|
|
import net.minecraft.CrashReportCategory;
|
|
import net.minecraft.ReportedException;
|
|
import net.minecraft.client.Camera;
|
|
import net.minecraft.client.gui.Font;
|
|
import net.minecraft.client.model.geom.EntityModelSet;
|
|
import net.minecraft.client.renderer.PlayerSkinRenderCache;
|
|
import net.minecraft.client.renderer.SubmitNodeCollector;
|
|
import net.minecraft.client.renderer.block.BlockRenderDispatcher;
|
|
import net.minecraft.client.renderer.blockentity.BlockEntityRenderer;
|
|
import net.minecraft.client.renderer.blockentity.BlockEntityRendererProvider;
|
|
import net.minecraft.client.renderer.blockentity.BlockEntityRenderers;
|
|
import net.minecraft.client.renderer.blockentity.state.BlockEntityRenderState;
|
|
import net.minecraft.client.renderer.entity.EntityRenderDispatcher;
|
|
import net.minecraft.client.renderer.entity.ItemRenderer;
|
|
import net.minecraft.client.renderer.feature.ModelFeatureRenderer;
|
|
import net.minecraft.client.renderer.item.ItemModelResolver;
|
|
import net.minecraft.client.renderer.state.CameraRenderState;
|
|
import net.minecraft.client.resources.model.MaterialSet;
|
|
import net.minecraft.server.packs.resources.ResourceManager;
|
|
import net.minecraft.server.packs.resources.ResourceManagerReloadListener;
|
|
import net.minecraft.world.level.block.entity.BlockEntity;
|
|
import net.minecraft.world.level.block.entity.BlockEntityType;
|
|
import net.minecraft.world.phys.Vec3;
|
|
import org.jspecify.annotations.Nullable;
|
|
|
|
public class BlockEntityRenderDispatcher
|
|
implements ResourceManagerReloadListener {
|
|
private Map<BlockEntityType<?>, BlockEntityRenderer<?, ?>> renderers = ImmutableMap.of();
|
|
private final Font font;
|
|
private final Supplier<EntityModelSet> entityModelSet;
|
|
private Vec3 cameraPos;
|
|
private final BlockRenderDispatcher blockRenderDispatcher;
|
|
private final ItemModelResolver itemModelResolver;
|
|
private final ItemRenderer itemRenderer;
|
|
private final EntityRenderDispatcher entityRenderer;
|
|
private final MaterialSet materials;
|
|
private final PlayerSkinRenderCache playerSkinRenderCache;
|
|
|
|
public BlockEntityRenderDispatcher(Font font, Supplier<EntityModelSet> entityModelSet, BlockRenderDispatcher blockRenderDispatcher, ItemModelResolver itemModelResolver, ItemRenderer itemRenderer, EntityRenderDispatcher entityRenderer, MaterialSet materials, PlayerSkinRenderCache playerSkinRenderCache) {
|
|
this.itemRenderer = itemRenderer;
|
|
this.itemModelResolver = itemModelResolver;
|
|
this.entityRenderer = entityRenderer;
|
|
this.font = font;
|
|
this.entityModelSet = entityModelSet;
|
|
this.blockRenderDispatcher = blockRenderDispatcher;
|
|
this.materials = materials;
|
|
this.playerSkinRenderCache = playerSkinRenderCache;
|
|
}
|
|
|
|
public <E extends BlockEntity, S extends BlockEntityRenderState> @Nullable BlockEntityRenderer<E, S> getRenderer(E blockEntity) {
|
|
return this.renderers.get(blockEntity.getType());
|
|
}
|
|
|
|
public <E extends BlockEntity, S extends BlockEntityRenderState> @Nullable BlockEntityRenderer<E, S> getRenderer(S state) {
|
|
return this.renderers.get(state.blockEntityType);
|
|
}
|
|
|
|
public void prepare(Camera camera) {
|
|
this.cameraPos = camera.position();
|
|
}
|
|
|
|
public <E extends BlockEntity, S extends BlockEntityRenderState> @Nullable S tryExtractRenderState(E blockEntity, float partialTicks, @Nullable ModelFeatureRenderer.CrumblingOverlay breakProgress) {
|
|
BlockEntityRenderer<E, E> renderer = this.getRenderer((S)((Object)blockEntity));
|
|
if (renderer == null) {
|
|
return null;
|
|
}
|
|
if (!blockEntity.hasLevel() || !blockEntity.getType().isValid(blockEntity.getBlockState())) {
|
|
return null;
|
|
}
|
|
if (!renderer.shouldRender(blockEntity, this.cameraPos)) {
|
|
return null;
|
|
}
|
|
Vec3 cameraPosition = this.cameraPos;
|
|
E state = renderer.createRenderState();
|
|
renderer.extractRenderState(blockEntity, state, partialTicks, cameraPosition, breakProgress);
|
|
return (S)state;
|
|
}
|
|
|
|
public <S extends BlockEntityRenderState> void submit(S state, PoseStack poseStack, SubmitNodeCollector submitNodeCollector, CameraRenderState camera) {
|
|
BlockEntityRenderer renderer = this.getRenderer(state);
|
|
if (renderer == null) {
|
|
return;
|
|
}
|
|
try {
|
|
renderer.submit(state, poseStack, submitNodeCollector, camera);
|
|
}
|
|
catch (Throwable t) {
|
|
CrashReport report = CrashReport.forThrowable(t, "Rendering Block Entity");
|
|
CrashReportCategory category = report.addCategory("Block Entity Details");
|
|
state.fillCrashReportCategory(category);
|
|
throw new ReportedException(report);
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public void onResourceManagerReload(ResourceManager resourceManager) {
|
|
BlockEntityRendererProvider.Context context = new BlockEntityRendererProvider.Context(this, this.blockRenderDispatcher, this.itemModelResolver, this.itemRenderer, this.entityRenderer, this.entityModelSet.get(), this.font, this.materials, this.playerSkinRenderCache);
|
|
this.renderers = BlockEntityRenderers.createEntityRenderers(context);
|
|
}
|
|
}
|
|
|