PaintingRenderer.java
net.minecraft.client.renderer.entity.PaintingRenderer
信息
- 全限定名:net.minecraft.client.renderer.entity.PaintingRenderer
- 类型:public class
- 包:net.minecraft.client.renderer.entity
- 源码路径:src/main/java/net/minecraft/client/renderer/entity/PaintingRenderer.java
- 起始行号:L27
- 继承:EntityRenderer<Painting,PaintingRenderState>
- 职责:
TODO
字段/常量
-
BACK_SPRITE_LOCATION- 类型:
Identifier - 修饰符:
private static final - 源码定位:
L28 - 说明:
TODO
- 类型:
-
paintingsAtlas- 类型:
TextureAtlas - 修饰符:
private final - 源码定位:
L29 - 说明:
TODO
- 类型:
内部类/嵌套类型
- 无
构造器
public PaintingRenderer(EntityRendererProvider.Context context) @ L31
- 构造器名:PaintingRenderer
- 源码定位:L31
- 修饰符:public
参数:
- context: EntityRendererProvider.Context
说明:
TODO
方法
下面的方法块按源码顺序生成。
public void submit(PaintingRenderState state, PoseStack poseStack, SubmitNodeCollector submitNodeCollector, CameraRenderState camera) @ L36
- 方法名:submit
- 源码定位:L36
- 返回类型:void
- 修饰符:public
参数:
- state: PaintingRenderState
- poseStack: PoseStack
- submitNodeCollector: SubmitNodeCollector
- camera: CameraRenderState
说明:
TODO
public PaintingRenderState createRenderState() @ L58
- 方法名:createRenderState
- 源码定位:L58
- 返回类型:PaintingRenderState
- 修饰符:public
参数:
- 无
说明:
TODO
public void extractRenderState(Painting entity, PaintingRenderState state, float partialTicks) @ L62
- 方法名:extractRenderState
- 源码定位:L62
- 返回类型:void
- 修饰符:public
参数:
- entity: Painting
- state: PaintingRenderState
- partialTicks: float
说明:
TODO
private void renderPainting(PoseStack poseStack, SubmitNodeCollector submitNodeCollector, RenderType renderType, int[] lightCoordsMap, int width, int height, TextureAtlasSprite front, TextureAtlasSprite back) @ L104
- 方法名:renderPainting
- 源码定位:L104
- 返回类型:void
- 修饰符:private
参数:
- poseStack: PoseStack
- submitNodeCollector: SubmitNodeCollector
- renderType: RenderType
- lightCoordsMap: int[]
- width: int
- height: int
- front: TextureAtlasSprite
- back: TextureAtlasSprite
说明:
TODO
private static void vertex(PoseStack.Pose pose, VertexConsumer buffer, float x, float y, float u, float v, float z, int nx, int ny, int nz, int lightCoords) @ L184
- 方法名:vertex
- 源码定位:L184
- 返回类型:void
- 修饰符:private static
参数:
- pose: PoseStack.Pose
- buffer: VertexConsumer
- x: float
- y: float
- u: float
- v: float
- z: float
- nx: int
- ny: int
- nz: int
- lightCoords: int
说明:
TODO
代码
@OnlyIn(Dist.CLIENT)
public class PaintingRenderer extends EntityRenderer<Painting, PaintingRenderState> {
private static final Identifier BACK_SPRITE_LOCATION = Identifier.withDefaultNamespace("back");
private final TextureAtlas paintingsAtlas;
public PaintingRenderer(EntityRendererProvider.Context context) {
super(context);
this.paintingsAtlas = context.getAtlas(AtlasIds.PAINTINGS);
}
public void submit(PaintingRenderState state, PoseStack poseStack, SubmitNodeCollector submitNodeCollector, CameraRenderState camera) {
PaintingVariant variant = state.variant;
if (variant != null) {
poseStack.pushPose();
poseStack.mulPose(Axis.YP.rotationDegrees(180 - state.direction.get2DDataValue() * 90));
TextureAtlasSprite frontSprite = this.paintingsAtlas.getSprite(variant.assetId());
TextureAtlasSprite backSprite = this.paintingsAtlas.getSprite(BACK_SPRITE_LOCATION);
this.renderPainting(
poseStack,
submitNodeCollector,
RenderTypes.entitySolidZOffsetForward(backSprite.atlasLocation()),
state.lightCoordsPerBlock,
variant.width(),
variant.height(),
frontSprite,
backSprite
);
poseStack.popPose();
super.submit(state, poseStack, submitNodeCollector, camera);
}
}
public PaintingRenderState createRenderState() {
return new PaintingRenderState();
}
public void extractRenderState(Painting entity, PaintingRenderState state, float partialTicks) {
super.extractRenderState(entity, state, partialTicks);
Direction direction = entity.getDirection();
PaintingVariant variant = entity.getVariant().value();
state.direction = direction;
state.variant = variant;
int width = variant.width();
int height = variant.height();
if (state.lightCoordsPerBlock.length != width * height) {
state.lightCoordsPerBlock = new int[width * height];
}
float offsetX = -width / 2.0F;
float offsetY = -height / 2.0F;
Level level = entity.level();
for (int segmentY = 0; segmentY < height; segmentY++) {
for (int segmentX = 0; segmentX < width; segmentX++) {
float segmentOffsetX = segmentX + offsetX + 0.5F;
float segmentOffsetY = segmentY + offsetY + 0.5F;
int x = entity.getBlockX();
int y = Mth.floor(entity.getY() + segmentOffsetY);
int z = entity.getBlockZ();
switch (direction) {
case NORTH:
x = Mth.floor(entity.getX() + segmentOffsetX);
break;
case WEST:
z = Mth.floor(entity.getZ() - segmentOffsetX);
break;
case SOUTH:
x = Mth.floor(entity.getX() - segmentOffsetX);
break;
case EAST:
z = Mth.floor(entity.getZ() + segmentOffsetX);
}
state.lightCoordsPerBlock[segmentX + segmentY * width] = LevelRenderer.getLightCoords(level, new BlockPos(x, y, z));
}
}
}
private void renderPainting(
PoseStack poseStack,
SubmitNodeCollector submitNodeCollector,
RenderType renderType,
int[] lightCoordsMap,
int width,
int height,
TextureAtlasSprite front,
TextureAtlasSprite back
) {
submitNodeCollector.submitCustomGeometry(poseStack, renderType, (pose, buffer) -> {
float offsetX = -width / 2.0F;
float offsetY = -height / 2.0F;
float edgeHalfWidth = 0.03125F;
float backU0 = back.getU0();
float backU1 = back.getU1();
float backV0 = back.getV0();
float backV1 = back.getV1();
float topBottomU0 = back.getU0();
float topBottomU1 = back.getU1();
float topBottomV0 = back.getV0();
float topBottomV1 = back.getV(0.0625F);
float leftRightU0 = back.getU0();
float leftRightU1 = back.getU(0.0625F);
float leftRightV0 = back.getV0();
float leftRightV1 = back.getV1();
double deltaU = 1.0 / width;
double deltaV = 1.0 / height;
for (int segmentX = 0; segmentX < width; segmentX++) {
for (int segmentY = 0; segmentY < height; segmentY++) {
float x0 = offsetX + (segmentX + 1);
float x1 = offsetX + segmentX;
float y0 = offsetY + (segmentY + 1);
float y1 = offsetY + segmentY;
int lightCoords = lightCoordsMap[segmentX + segmentY * width];
float frontU0 = front.getU((float)(deltaU * (width - segmentX)));
float frontU1 = front.getU((float)(deltaU * (width - (segmentX + 1))));
float frontV0 = front.getV((float)(deltaV * (height - segmentY)));
float frontV1 = front.getV((float)(deltaV * (height - (segmentY + 1))));
vertex(pose, buffer, x0, y1, frontU1, frontV0, -0.03125F, 0, 0, -1, lightCoords);
vertex(pose, buffer, x1, y1, frontU0, frontV0, -0.03125F, 0, 0, -1, lightCoords);
vertex(pose, buffer, x1, y0, frontU0, frontV1, -0.03125F, 0, 0, -1, lightCoords);
vertex(pose, buffer, x0, y0, frontU1, frontV1, -0.03125F, 0, 0, -1, lightCoords);
vertex(pose, buffer, x0, y0, backU1, backV0, 0.03125F, 0, 0, 1, lightCoords);
vertex(pose, buffer, x1, y0, backU0, backV0, 0.03125F, 0, 0, 1, lightCoords);
vertex(pose, buffer, x1, y1, backU0, backV1, 0.03125F, 0, 0, 1, lightCoords);
vertex(pose, buffer, x0, y1, backU1, backV1, 0.03125F, 0, 0, 1, lightCoords);
if (segmentY == height - 1) {
vertex(pose, buffer, x0, y0, topBottomU0, topBottomV0, -0.03125F, 0, 1, 0, lightCoords);
vertex(pose, buffer, x1, y0, topBottomU1, topBottomV0, -0.03125F, 0, 1, 0, lightCoords);
vertex(pose, buffer, x1, y0, topBottomU1, topBottomV1, 0.03125F, 0, 1, 0, lightCoords);
vertex(pose, buffer, x0, y0, topBottomU0, topBottomV1, 0.03125F, 0, 1, 0, lightCoords);
}
if (segmentY == 0) {
vertex(pose, buffer, x0, y1, topBottomU0, topBottomV0, 0.03125F, 0, -1, 0, lightCoords);
vertex(pose, buffer, x1, y1, topBottomU1, topBottomV0, 0.03125F, 0, -1, 0, lightCoords);
vertex(pose, buffer, x1, y1, topBottomU1, topBottomV1, -0.03125F, 0, -1, 0, lightCoords);
vertex(pose, buffer, x0, y1, topBottomU0, topBottomV1, -0.03125F, 0, -1, 0, lightCoords);
}
if (segmentX == width - 1) {
vertex(pose, buffer, x0, y0, leftRightU1, leftRightV0, 0.03125F, -1, 0, 0, lightCoords);
vertex(pose, buffer, x0, y1, leftRightU1, leftRightV1, 0.03125F, -1, 0, 0, lightCoords);
vertex(pose, buffer, x0, y1, leftRightU0, leftRightV1, -0.03125F, -1, 0, 0, lightCoords);
vertex(pose, buffer, x0, y0, leftRightU0, leftRightV0, -0.03125F, -1, 0, 0, lightCoords);
}
if (segmentX == 0) {
vertex(pose, buffer, x1, y0, leftRightU1, leftRightV0, -0.03125F, 1, 0, 0, lightCoords);
vertex(pose, buffer, x1, y1, leftRightU1, leftRightV1, -0.03125F, 1, 0, 0, lightCoords);
vertex(pose, buffer, x1, y1, leftRightU0, leftRightV1, 0.03125F, 1, 0, 0, lightCoords);
vertex(pose, buffer, x1, y0, leftRightU0, leftRightV0, 0.03125F, 1, 0, 0, lightCoords);
}
}
}
});
}
private static void vertex(PoseStack.Pose pose, VertexConsumer buffer, float x, float y, float u, float v, float z, int nx, int ny, int nz, int lightCoords) {
buffer.addVertex(pose, x, y, z).setColor(-1).setUv(u, v).setOverlay(OverlayTexture.NO_OVERLAY).setLight(lightCoords).setNormal(pose, nx, ny, nz);
}
}引用的其他类
-
- 引用位置:
参数
- 引用位置:
-
- 引用位置:
参数
- 引用位置:
-
- 引用位置:
方法调用 - 关联成员:
LevelRenderer.getLightCoords()
- 引用位置:
-
- 引用位置:
参数
- 引用位置:
-
- 引用位置:
继承
- 引用位置:
-
- 引用位置:
参数
- 引用位置:
-
- 引用位置:
参数/构造调用/返回值 - 关联成员:
PaintingRenderState()
- 引用位置:
-
- 引用位置:
参数
- 引用位置:
-
- 引用位置:
方法调用 - 关联成员:
RenderTypes.entitySolidZOffsetForward()
- 引用位置:
-
- 引用位置:
参数
- 引用位置:
-
- 引用位置:
字段
- 引用位置:
-
- 引用位置:
参数
- 引用位置:
-
- 引用位置:
构造调用 - 关联成员:
BlockPos()
- 引用位置:
-
- 引用位置:
字段/方法调用 - 关联成员:
Identifier.withDefaultNamespace()
- 引用位置:
-
- 引用位置:
方法调用 - 关联成员:
Mth.floor()
- 引用位置:
-
- 引用位置:
参数
- 引用位置: