|
26 | 26 |
|
27 | 27 | import com.flowpowered.math.vector.Vector3d; |
28 | 28 | import com.flowpowered.math.vector.Vector3i; |
| 29 | +import de.bluecolored.bluemap.core.logger.Logger; |
29 | 30 | import de.bluecolored.bluemap.core.map.TextureGallery; |
30 | 31 | import de.bluecolored.bluemap.core.map.TileMetaConsumer; |
31 | 32 | import de.bluecolored.bluemap.core.map.hires.block.BlockStateModelRenderer; |
@@ -58,80 +59,84 @@ public void render(World world, Vector3i modelMin, Vector3i modelMax, TileModel |
58 | 59 | } |
59 | 60 |
|
60 | 61 | public void render(World world, Vector3i modelMin, Vector3i modelMax, TileModel tileModel, TileMetaConsumer tileMetaConsumer) { |
61 | | - Vector3i min = modelMin.max(renderSettings.getMinPos()); |
62 | | - Vector3i max = modelMax.min(renderSettings.getMaxPos()); |
63 | | - Vector3i modelAnchor = new Vector3i(modelMin.getX(), 0, modelMin.getZ()); |
| 62 | + try { |
| 63 | + Vector3i min = modelMin.max(renderSettings.getMinPos()); |
| 64 | + Vector3i max = modelMax.min(renderSettings.getMaxPos()); |
| 65 | + Vector3i modelAnchor = new Vector3i(modelMin.getX(), 0, modelMin.getZ()); |
64 | 66 |
|
65 | | - // render blocks |
66 | | - BlockStateModelRenderer blockRenderer = threadLocalBlockRenderer.get(); |
67 | | - EntityModelRenderer entityRenderer = threadLocalEntityRenderer.get(); |
| 67 | + // render blocks |
| 68 | + BlockStateModelRenderer blockRenderer = threadLocalBlockRenderer.get(); |
| 69 | + EntityModelRenderer entityRenderer = threadLocalEntityRenderer.get(); |
68 | 70 |
|
69 | | - int maxHeight, minY, maxY; |
70 | | - double topBlockLight; |
71 | | - Color columnColor = new Color(), blockColor = new Color(); |
72 | | - BlockNeighborhood block = new BlockNeighborhood(new Block(world, 0, 0, 0), resourcePack, renderSettings, world.getDimensionType()); |
73 | | - TileModelView tileModelView = new TileModelView(tileModel); |
| 71 | + int maxHeight, minY, maxY; |
| 72 | + double topBlockLight; |
| 73 | + Color columnColor = new Color(), blockColor = new Color(); |
| 74 | + BlockNeighborhood block = new BlockNeighborhood(new Block(world, 0, 0, 0), resourcePack, renderSettings, world.getDimensionType()); |
| 75 | + TileModelView tileModelView = new TileModelView(tileModel); |
74 | 76 |
|
75 | | - int x, y, z; |
76 | | - for (x = modelMin.getX(); x <= modelMax.getX(); x++){ |
77 | | - for (z = modelMin.getZ(); z <= modelMax.getZ(); z++){ |
| 77 | + int x, y, z; |
| 78 | + for (x = modelMin.getX(); x <= modelMax.getX(); x++) { |
| 79 | + for (z = modelMin.getZ(); z <= modelMax.getZ(); z++) { |
78 | 80 |
|
79 | | - maxHeight = Integer.MIN_VALUE; |
80 | | - topBlockLight = 0; |
| 81 | + maxHeight = Integer.MIN_VALUE; |
| 82 | + topBlockLight = 0; |
81 | 83 |
|
82 | | - columnColor.set(0, 0, 0, 0, true); |
| 84 | + columnColor.set(0, 0, 0, 0, true); |
83 | 85 |
|
84 | | - if (renderSettings.isInsideRenderBoundaries(x, z)) { |
85 | | - Chunk chunk = world.getChunkAtBlock(x, z); |
86 | | - minY = Math.max(min.getY(), chunk.getMinY(x, z)); |
87 | | - maxY = Math.min(max.getY(), chunk.getMaxY(x, z)); |
| 86 | + if (renderSettings.isInsideRenderBoundaries(x, z)) { |
| 87 | + Chunk chunk = world.getChunkAtBlock(x, z); |
| 88 | + minY = Math.max(min.getY(), chunk.getMinY(x, z)); |
| 89 | + maxY = Math.min(max.getY(), chunk.getMaxY(x, z)); |
88 | 90 |
|
89 | | - for (y = maxY; y >= minY; y--) { |
90 | | - if (x == -1743 && y == 64 && z == 1393) |
91 | | - System.out.println(); |
| 91 | + for (y = maxY; y >= minY; y--) { |
| 92 | + if (x == -1743 && y == 64 && z == 1393) |
| 93 | + System.out.println(); |
92 | 94 |
|
93 | | - block.set(x, y, z); |
94 | | - if (!block.isInsideRenderBounds()) continue; |
| 95 | + block.set(x, y, z); |
| 96 | + if (!block.isInsideRenderBounds()) continue; |
95 | 97 |
|
96 | | - tileModelView.initialize(); |
| 98 | + tileModelView.initialize(); |
97 | 99 |
|
98 | | - blockRenderer.render(block, tileModelView, blockColor); |
| 100 | + blockRenderer.render(block, tileModelView, blockColor); |
99 | 101 |
|
100 | | - //update topBlockLight |
101 | | - topBlockLight = Math.max(topBlockLight, block.getBlockLightLevel() * (1 - columnColor.a)); |
| 102 | + //update topBlockLight |
| 103 | + topBlockLight = Math.max(topBlockLight, block.getBlockLightLevel() * (1 - columnColor.a)); |
102 | 104 |
|
103 | | - // move block-model to correct position |
104 | | - tileModelView.translate(x - modelAnchor.getX(), y - modelAnchor.getY(), z - modelAnchor.getZ()); |
| 105 | + // move block-model to correct position |
| 106 | + tileModelView.translate(x - modelAnchor.getX(), y - modelAnchor.getY(), z - modelAnchor.getZ()); |
105 | 107 |
|
106 | | - //update color and height (only if not 100% translucent) |
107 | | - if (blockColor.a > 0) { |
108 | | - if (maxHeight < y) maxHeight = y; |
109 | | - columnColor.underlay(blockColor.premultiplied()); |
110 | | - } |
| 108 | + //update color and height (only if not 100% translucent) |
| 109 | + if (blockColor.a > 0) { |
| 110 | + if (maxHeight < y) maxHeight = y; |
| 111 | + columnColor.underlay(blockColor.premultiplied()); |
| 112 | + } |
111 | 113 |
|
112 | | - if (renderSettings.isRenderTopOnly() && blockColor.a > 0.999 && block.getProperties().isCulling()) |
113 | | - break; |
| 114 | + if (renderSettings.isRenderTopOnly() && blockColor.a > 0.999 && block.getProperties().isCulling()) |
| 115 | + break; |
| 116 | + } |
114 | 117 | } |
115 | | - } |
116 | 118 |
|
117 | | - if (maxHeight == Integer.MIN_VALUE) |
118 | | - maxHeight = 0; |
| 119 | + if (maxHeight == Integer.MIN_VALUE) |
| 120 | + maxHeight = 0; |
119 | 121 |
|
120 | | - tileMetaConsumer.set(x, z, columnColor, maxHeight, (int) topBlockLight); |
| 122 | + tileMetaConsumer.set(x, z, columnColor, maxHeight, (int) topBlockLight); |
| 123 | + } |
121 | 124 | } |
122 | | - } |
123 | | - |
124 | | - // render entities |
125 | | - world.iterateEntities(min.getX(), min.getZ(), max.getX(), max.getZ(), entity -> { |
126 | | - Vector3d pos = entity.getPos(); |
127 | | - block.set(pos.getFloorX(), pos.getFloorY(), pos.getFloorZ()); |
128 | | - entityRenderer.render(entity, block, tileModelView.initialize()); |
129 | | - tileModelView.translate( |
130 | | - (float) pos.getX() - modelAnchor.getX(), |
131 | | - (float) pos.getY() - modelAnchor.getY(), |
132 | | - (float) pos.getZ() - modelAnchor.getZ() |
133 | | - ); |
134 | | - }); |
135 | 125 |
|
| 126 | + // render entities |
| 127 | + world.iterateEntities(min.getX(), min.getZ(), max.getX(), max.getZ(), entity -> { |
| 128 | + Vector3d pos = entity.getPos(); |
| 129 | + block.set(pos.getFloorX(), pos.getFloorY(), pos.getFloorZ()); |
| 130 | + entityRenderer.render(entity, block, tileModelView.initialize()); |
| 131 | + tileModelView.translate( |
| 132 | + (float) pos.getX() - modelAnchor.getX(), |
| 133 | + (float) pos.getY() - modelAnchor.getY(), |
| 134 | + (float) pos.getZ() - modelAnchor.getZ() |
| 135 | + ); |
| 136 | + }); |
| 137 | + } catch (MaxCapacityReachedException ex) { |
| 138 | + Logger.global.noFloodWarning("max-capacity-reached", |
| 139 | + "One or more map-tiles are too complex to be completed: " + ex); |
| 140 | + } |
136 | 141 | } |
137 | 142 | } |
0 commit comments