BlockEntityWithBoundingBoxRenderer.java
net.minecraft.client.renderer.blockentity.BlockEntityWithBoundingBoxRenderer
信息
- 全限定名:net.minecraft.client.renderer.blockentity.BlockEntityWithBoundingBoxRenderer
- 类型:public class
- 包:net.minecraft.client.renderer.blockentity
- 源码路径:src/main/java/net/minecraft/client/renderer/blockentity/BlockEntityWithBoundingBoxRenderer.java
- 起始行号:L28
- 实现:BlockEntityRenderer<T,BlockEntityWithBoundingBoxRenderState>
- 职责:
TODO
字段/常量
STRUCTURE_VOIDS_COLOR- 类型:
int - 修饰符:
public static final - 源码定位:
L30 - 说明:
TODO
- 类型:
内部类/嵌套类型
- 无
构造器
- 无
方法
下面的方法块按源码顺序生成。
public BlockEntityWithBoundingBoxRenderState createRenderState() @ L32
- 方法名:createRenderState
- 源码定位:L32
- 返回类型:BlockEntityWithBoundingBoxRenderState
- 修饰符:public
参数:
- 无
说明:
TODO
public void extractRenderState(T blockEntity, BlockEntityWithBoundingBoxRenderState state, float partialTicks, Vec3 cameraPosition, ModelFeatureRenderer.CrumblingOverlay breakProgress) @ L36
- 方法名:extractRenderState
- 源码定位:L36
- 返回类型:void
- 修饰符:public
参数:
- blockEntity: T
- state: BlockEntityWithBoundingBoxRenderState
- partialTicks: float
- cameraPosition: Vec3
- breakProgress: ModelFeatureRenderer.CrumblingOverlay
说明:
TODO
public static <T extends BlockEntity &BoundingBoxRenderable> void extract(T blockEntity, BlockEntityWithBoundingBoxRenderState state) @ L47
- 方法名:extract
- 源码定位:L47
- 返回类型:<T extends BlockEntity &BoundingBoxRenderable> void
- 修饰符:public static
参数:
- blockEntity: T
- state: BlockEntityWithBoundingBoxRenderState
说明:
TODO
public void submit(BlockEntityWithBoundingBoxRenderState state, PoseStack poseStack, SubmitNodeCollector submitNodeCollector, CameraRenderState camera) @ L86
- 方法名:submit
- 源码定位:L86
- 返回类型:void
- 修饰符:public
参数:
- state: BlockEntityWithBoundingBoxRenderState
- poseStack: PoseStack
- submitNodeCollector: SubmitNodeCollector
- camera: CameraRenderState
说明:
TODO
private void renderInvisibleBlocks(BlockEntityWithBoundingBoxRenderState state, BlockPos localPos, Vec3i size) @ L108
- 方法名:renderInvisibleBlocks
- 源码定位:L108
- 返回类型:void
- 修饰符:private
参数:
- state: BlockEntityWithBoundingBoxRenderState
- localPos: BlockPos
- size: Vec3i
说明:
TODO
private void renderStructureVoids(BlockEntityWithBoundingBoxRenderState state, BlockPos startingPosition, Vec3i size) @ L143
- 方法名:renderStructureVoids
- 源码定位:L143
- 返回类型:void
- 修饰符:private
参数:
- state: BlockEntityWithBoundingBoxRenderState
- startingPosition: BlockPos
- size: Vec3i
说明:
TODO
public boolean shouldRenderOffScreen() @ L171
- 方法名:shouldRenderOffScreen
- 源码定位:L171
- 返回类型:boolean
- 修饰符:public
参数:
- 无
说明:
TODO
public int getViewDistance() @ L176
- 方法名:getViewDistance
- 源码定位:L176
- 返回类型:int
- 修饰符:public
参数:
- 无
说明:
TODO
代码
@OnlyIn(Dist.CLIENT)
public class BlockEntityWithBoundingBoxRenderer<T extends BlockEntity & BoundingBoxRenderable>
implements BlockEntityRenderer<T, BlockEntityWithBoundingBoxRenderState> {
public static final int STRUCTURE_VOIDS_COLOR = ARGB.colorFromFloat(0.2F, 0.75F, 0.75F, 1.0F);
public BlockEntityWithBoundingBoxRenderState createRenderState() {
return new BlockEntityWithBoundingBoxRenderState();
}
public void extractRenderState(
T blockEntity,
BlockEntityWithBoundingBoxRenderState state,
float partialTicks,
Vec3 cameraPosition,
ModelFeatureRenderer.@Nullable CrumblingOverlay breakProgress
) {
BlockEntityRenderer.super.extractRenderState(blockEntity, state, partialTicks, cameraPosition, breakProgress);
extract(blockEntity, state);
}
public static <T extends BlockEntity & BoundingBoxRenderable> void extract(T blockEntity, BlockEntityWithBoundingBoxRenderState state) {
LocalPlayer player = Minecraft.getInstance().player;
state.isVisible = player.canUseGameMasterBlocks() || player.isSpectator();
state.box = blockEntity.getRenderableBox();
state.mode = blockEntity.renderMode();
BlockPos pos = state.box.localPos();
Vec3i size = state.box.size();
BlockPos entityPos = state.blockPos;
BlockPos startingPos = entityPos.offset(pos);
if (state.isVisible && blockEntity.getLevel() != null && state.mode == BoundingBoxRenderable.Mode.BOX_AND_INVISIBLE_BLOCKS) {
state.invisibleBlocks = new BlockEntityWithBoundingBoxRenderState.InvisibleBlockType[size.getX() * size.getY() * size.getZ()];
for (int x = 0; x < size.getX(); x++) {
for (int y = 0; y < size.getY(); y++) {
for (int z = 0; z < size.getZ(); z++) {
int index = z * size.getX() * size.getY() + y * size.getX() + x;
BlockState blockState = blockEntity.getLevel().getBlockState(startingPos.offset(x, y, z));
if (blockState.isAir()) {
state.invisibleBlocks[index] = BlockEntityWithBoundingBoxRenderState.InvisibleBlockType.AIR;
} else if (blockState.is(Blocks.STRUCTURE_VOID)) {
state.invisibleBlocks[index] = BlockEntityWithBoundingBoxRenderState.InvisibleBlockType.STRUCTURE_VOID;
} else if (blockState.is(Blocks.BARRIER)) {
state.invisibleBlocks[index] = BlockEntityWithBoundingBoxRenderState.InvisibleBlockType.BARRIER;
} else if (blockState.is(Blocks.LIGHT)) {
state.invisibleBlocks[index] = BlockEntityWithBoundingBoxRenderState.InvisibleBlockType.LIGHT;
}
}
}
}
} else {
state.invisibleBlocks = null;
}
if (state.isVisible) {
}
state.structureVoids = null;
}
public void submit(BlockEntityWithBoundingBoxRenderState state, PoseStack poseStack, SubmitNodeCollector submitNodeCollector, CameraRenderState camera) {
if (state.isVisible) {
BoundingBoxRenderable.Mode mode = state.mode;
if (mode != BoundingBoxRenderable.Mode.NONE) {
BoundingBoxRenderable.RenderableBox box = state.box;
BlockPos pos = box.localPos();
Vec3i size = box.size();
if (size.getX() >= 1 && size.getY() >= 1 && size.getZ() >= 1) {
float lineAlpha = 1.0F;
float lineRGB = 0.9F;
BlockPos far = pos.offset(size);
Gizmos.cuboid(
new AABB(pos.getX(), pos.getY(), pos.getZ(), far.getX(), far.getY(), far.getZ()).move(state.blockPos),
GizmoStyle.stroke(ARGB.colorFromFloat(1.0F, 0.9F, 0.9F, 0.9F)),
true
);
this.renderInvisibleBlocks(state, pos, size);
}
}
}
}
private void renderInvisibleBlocks(BlockEntityWithBoundingBoxRenderState state, BlockPos localPos, Vec3i size) {
if (state.invisibleBlocks != null) {
BlockPos entityPos = state.blockPos;
BlockPos startingPos = entityPos.offset(localPos);
for (int x = 0; x < size.getX(); x++) {
for (int y = 0; y < size.getY(); y++) {
for (int z = 0; z < size.getZ(); z++) {
int index = z * size.getX() * size.getY() + y * size.getX() + x;
BlockEntityWithBoundingBoxRenderState.InvisibleBlockType invisibleBlockType = state.invisibleBlocks[index];
if (invisibleBlockType != null) {
float scale = invisibleBlockType == BlockEntityWithBoundingBoxRenderState.InvisibleBlockType.AIR ? 0.05F : 0.0F;
double renderX0 = startingPos.getX() + x + 0.45F - scale;
double renderY0 = startingPos.getY() + y + 0.45F - scale;
double renderZ0 = startingPos.getZ() + z + 0.45F - scale;
double renderX1 = startingPos.getX() + x + 0.55F + scale;
double renderY1 = startingPos.getY() + y + 0.55F + scale;
double renderZ1 = startingPos.getZ() + z + 0.55F + scale;
AABB aabb = new AABB(renderX0, renderY0, renderZ0, renderX1, renderY1, renderZ1);
if (invisibleBlockType == BlockEntityWithBoundingBoxRenderState.InvisibleBlockType.AIR) {
Gizmos.cuboid(aabb, GizmoStyle.stroke(ARGB.colorFromFloat(1.0F, 0.5F, 0.5F, 1.0F)));
} else if (invisibleBlockType == BlockEntityWithBoundingBoxRenderState.InvisibleBlockType.STRUCTURE_VOID) {
Gizmos.cuboid(aabb, GizmoStyle.stroke(ARGB.colorFromFloat(1.0F, 1.0F, 0.75F, 0.75F)));
} else if (invisibleBlockType == BlockEntityWithBoundingBoxRenderState.InvisibleBlockType.BARRIER) {
Gizmos.cuboid(aabb, GizmoStyle.stroke(-65536));
} else if (invisibleBlockType == BlockEntityWithBoundingBoxRenderState.InvisibleBlockType.LIGHT) {
Gizmos.cuboid(aabb, GizmoStyle.stroke(-256));
}
}
}
}
}
}
}
private void renderStructureVoids(BlockEntityWithBoundingBoxRenderState state, BlockPos startingPosition, Vec3i size) {
if (state.structureVoids != null) {
DiscreteVoxelShape shape = new BitSetDiscreteVoxelShape(size.getX(), size.getY(), size.getZ());
for (int x = 0; x < size.getX(); x++) {
for (int y = 0; y < size.getY(); y++) {
for (int z = 0; z < size.getZ(); z++) {
int index = z * size.getX() * size.getY() + y * size.getX() + x;
if (state.structureVoids[index]) {
shape.fill(x, y, z);
}
}
}
}
shape.forAllFaces((direction, xx, yx, zx) -> {
float scale = 0.48F;
float x0 = xx + startingPosition.getX() + 0.5F - 0.48F;
float y0 = yx + startingPosition.getY() + 0.5F - 0.48F;
float z0 = zx + startingPosition.getZ() + 0.5F - 0.48F;
float x1 = xx + startingPosition.getX() + 0.5F + 0.48F;
float y1 = yx + startingPosition.getY() + 0.5F + 0.48F;
float z1 = zx + startingPosition.getZ() + 0.5F + 0.48F;
Gizmos.rect(new Vec3(x0, y0, z0), new Vec3(x1, y1, z1), direction, GizmoStyle.fill(STRUCTURE_VOIDS_COLOR));
});
}
}
@Override
public boolean shouldRenderOffScreen() {
return true;
}
@Override
public int getViewDistance() {
return 96;
}
}引用的其他类
-
- 引用位置:
参数
- 引用位置:
-
- 引用位置:
方法调用 - 关联成员:
Minecraft.getInstance()
- 引用位置:
-
- 引用位置:
参数
- 引用位置:
-
- 引用位置:
实现
- 引用位置:
-
BlockEntityWithBoundingBoxRenderState
- 引用位置:
参数/构造调用/返回值 - 关联成员:
BlockEntityWithBoundingBoxRenderState()
- 引用位置:
-
- 引用位置:
参数
- 引用位置:
-
- 引用位置:
参数
- 引用位置:
-
- 引用位置:
参数
- 引用位置:
-
- 引用位置:
参数
- 引用位置:
-
- 引用位置:
方法调用 - 关联成员:
GizmoStyle.fill(), GizmoStyle.stroke()
- 引用位置:
-
- 引用位置:
方法调用 - 关联成员:
Gizmos.cuboid(), Gizmos.rect()
- 引用位置:
-
- 引用位置:
方法调用 - 关联成员:
ARGB.colorFromFloat()
- 引用位置:
-
- 引用位置:
返回值
- 引用位置:
-
- 引用位置:
返回值
- 引用位置:
-
- 引用位置:
构造调用 - 关联成员:
AABB()
- 引用位置:
-
- 引用位置:
参数/构造调用 - 关联成员:
Vec3()
- 引用位置:
-
- 引用位置:
构造调用 - 关联成员:
BitSetDiscreteVoxelShape()
- 引用位置: