MapRenderer.java
net.minecraft.client.renderer.MapRenderer
信息
- 全限定名:net.minecraft.client.renderer.MapRenderer
- 类型:public class
- 包:net.minecraft.client.renderer
- 源码路径:src/main/java/net/minecraft/client/renderer/MapRenderer.java
- 起始行号:L22
- 职责:
TODO
字段/常量
-
MAP_Z_OFFSET- 类型:
float - 修饰符:
private static final - 源码定位:
L23 - 说明:
TODO
- 类型:
-
DECORATION_Z_OFFSET- 类型:
float - 修饰符:
private static final - 源码定位:
L24 - 说明:
TODO
- 类型:
-
WIDTH- 类型:
int - 修饰符:
public static final - 源码定位:
L25 - 说明:
TODO
- 类型:
-
HEIGHT- 类型:
int - 修饰符:
public static final - 源码定位:
L26 - 说明:
TODO
- 类型:
-
decorationSprites- 类型:
TextureAtlas - 修饰符:
private final - 源码定位:
L27 - 说明:
TODO
- 类型:
-
mapTextureManager- 类型:
MapTextureManager - 修饰符:
private final - 源码定位:
L28 - 说明:
TODO
- 类型:
内部类/嵌套类型
- 无
构造器
public MapRenderer(AtlasManager atlasManager, MapTextureManager mapTextureManager) @ L30
- 构造器名:MapRenderer
- 源码定位:L30
- 修饰符:public
参数:
- atlasManager: AtlasManager
- mapTextureManager: MapTextureManager
说明:
TODO
方法
下面的方法块按源码顺序生成。
public void render(MapRenderState mapRenderState, PoseStack poseStack, SubmitNodeCollector submitNodeCollector, boolean showOnlyFrame, int lightCoords) @ L35
- 方法名:render
- 源码定位:L35
- 返回类型:void
- 修饰符:public
参数:
- mapRenderState: MapRenderState
- poseStack: PoseStack
- submitNodeCollector: SubmitNodeCollector
- showOnlyFrame: boolean
- lightCoords: int
说明:
TODO
public void extractRenderState(MapId mapId, MapItemSavedData mapData, MapRenderState mapRenderState) @ L83
- 方法名:extractRenderState
- 源码定位:L83
- 返回类型:void
- 修饰符:public
参数:
- mapId: MapId
- mapData: MapItemSavedData
- mapRenderState: MapRenderState
说明:
TODO
private MapRenderState.MapDecorationRenderState extractDecorationRenderState(MapDecoration decoration) @ L92
- 方法名:extractDecorationRenderState
- 源码定位:L92
- 返回类型:MapRenderState.MapDecorationRenderState
- 修饰符:private
参数:
- decoration: MapDecoration
说明:
TODO
代码
@OnlyIn(Dist.CLIENT)
public class MapRenderer {
private static final float MAP_Z_OFFSET = -0.01F;
private static final float DECORATION_Z_OFFSET = -0.001F;
public static final int WIDTH = 128;
public static final int HEIGHT = 128;
private final TextureAtlas decorationSprites;
private final MapTextureManager mapTextureManager;
public MapRenderer(AtlasManager atlasManager, MapTextureManager mapTextureManager) {
this.decorationSprites = atlasManager.getAtlasOrThrow(AtlasIds.MAP_DECORATIONS);
this.mapTextureManager = mapTextureManager;
}
public void render(MapRenderState mapRenderState, PoseStack poseStack, SubmitNodeCollector submitNodeCollector, boolean showOnlyFrame, int lightCoords) {
submitNodeCollector.submitCustomGeometry(poseStack, RenderTypes.text(mapRenderState.texture), (pose, buffer) -> {
buffer.addVertex(pose, 0.0F, 128.0F, -0.01F).setColor(-1).setUv(0.0F, 1.0F).setLight(lightCoords);
buffer.addVertex(pose, 128.0F, 128.0F, -0.01F).setColor(-1).setUv(1.0F, 1.0F).setLight(lightCoords);
buffer.addVertex(pose, 128.0F, 0.0F, -0.01F).setColor(-1).setUv(1.0F, 0.0F).setLight(lightCoords);
buffer.addVertex(pose, 0.0F, 0.0F, -0.01F).setColor(-1).setUv(0.0F, 0.0F).setLight(lightCoords);
});
int count = 0;
for (MapRenderState.MapDecorationRenderState decoration : mapRenderState.decorations) {
if (!showOnlyFrame || decoration.renderOnFrame) {
poseStack.pushPose();
poseStack.translate(decoration.x / 2.0F + 64.0F, decoration.y / 2.0F + 64.0F, -0.02F);
poseStack.mulPose(Axis.ZP.rotationDegrees(decoration.rot * 360 / 16.0F));
poseStack.scale(4.0F, 4.0F, 3.0F);
poseStack.translate(-0.125F, 0.125F, 0.0F);
TextureAtlasSprite atlasSprite = decoration.atlasSprite;
if (atlasSprite != null) {
float z = count * -0.001F;
submitNodeCollector.submitCustomGeometry(poseStack, RenderTypes.text(atlasSprite.atlasLocation()), (pose, buffer) -> {
buffer.addVertex(pose, -1.0F, 1.0F, z).setColor(-1).setUv(atlasSprite.getU0(), atlasSprite.getV0()).setLight(lightCoords);
buffer.addVertex(pose, 1.0F, 1.0F, z).setColor(-1).setUv(atlasSprite.getU1(), atlasSprite.getV0()).setLight(lightCoords);
buffer.addVertex(pose, 1.0F, -1.0F, z).setColor(-1).setUv(atlasSprite.getU1(), atlasSprite.getV1()).setLight(lightCoords);
buffer.addVertex(pose, -1.0F, -1.0F, z).setColor(-1).setUv(atlasSprite.getU0(), atlasSprite.getV1()).setLight(lightCoords);
});
poseStack.popPose();
}
if (decoration.name != null) {
Font font = Minecraft.getInstance().font;
float width = font.width(decoration.name);
float scale = Mth.clamp(25.0F / width, 0.0F, 6.0F / 9.0F);
poseStack.pushPose();
poseStack.translate(decoration.x / 2.0F + 64.0F - width * scale / 2.0F, decoration.y / 2.0F + 64.0F + 4.0F, -0.025F);
poseStack.scale(scale, scale, -1.0F);
poseStack.translate(0.0F, 0.0F, 0.1F);
submitNodeCollector.order(1)
.submitText(
poseStack, 0.0F, 0.0F, decoration.name.getVisualOrderText(), false, Font.DisplayMode.NORMAL, lightCoords, -1, Integer.MIN_VALUE, 0
);
poseStack.popPose();
}
count++;
}
}
}
public void extractRenderState(MapId mapId, MapItemSavedData mapData, MapRenderState mapRenderState) {
mapRenderState.texture = this.mapTextureManager.prepareMapTexture(mapId, mapData);
mapRenderState.decorations.clear();
for (MapDecoration decoration : mapData.getDecorations()) {
mapRenderState.decorations.add(this.extractDecorationRenderState(decoration));
}
}
private MapRenderState.MapDecorationRenderState extractDecorationRenderState(MapDecoration decoration) {
MapRenderState.MapDecorationRenderState state = new MapRenderState.MapDecorationRenderState();
state.atlasSprite = this.decorationSprites.getSprite(decoration.getSpriteLocation());
state.x = decoration.x();
state.y = decoration.y();
state.rot = decoration.rot();
state.name = decoration.name().orElse(null);
state.renderOnFrame = decoration.renderOnFrame();
return state;
}
}引用的其他类
-
- 引用位置:
参数
- 引用位置:
-
- 引用位置:
方法调用 - 关联成员:
Minecraft.getInstance()
- 引用位置:
-
- 引用位置:
参数
- 引用位置:
-
- 引用位置:
方法调用 - 关联成员:
RenderTypes.text()
- 引用位置:
-
- 引用位置:
参数/方法调用/构造调用/返回值 - 关联成员:
MapDecorationRenderState(), MapRenderState.MapDecorationRenderState()
- 引用位置:
-
- 引用位置:
字段
- 引用位置:
-
- 引用位置:
参数/字段
- 引用位置:
-
- 引用位置:
参数
- 引用位置:
-
- 引用位置:
方法调用 - 关联成员:
Mth.clamp()
- 引用位置:
-
- 引用位置:
参数
- 引用位置:
-
- 引用位置:
参数
- 引用位置:
-
- 引用位置:
参数
- 引用位置: