31
31
import static org .lwjgl .opengl .GL11 .glPushMatrix ;
32
32
import static org .lwjgl .opengl .GL11 .glViewport ;
33
33
34
- import java .util .Collection ;
35
- import java .util .HashSet ;
36
- import java .util .Set ;
37
34
import java .util .function .Consumer ;
38
35
39
36
import net .minecraft .block .Block ;
47
44
import net .minecraft .tileentity .TileEntity ;
48
45
import net .minecraft .util .MovingObjectPosition ;
49
46
import net .minecraft .util .Vec3 ;
50
- import net .minecraft .world .World ;
51
47
import net .minecraftforge .client .ForgeHooksClient ;
52
48
53
49
import org .lwjgl .opengl .GL12 ;
54
50
import org .lwjgl .util .glu .GLU ;
55
51
import org .lwjgl .util .vector .Vector3f ;
56
52
53
+ import com .gtnewhorizon .gtnhlib .util .CoordinatePacker ;
54
+
57
55
import bartworks .common .blocks .BWBlocksGlass ;
58
56
import blockrenderer6343 .BlockRenderer6343 ;
59
- import blockrenderer6343 .api .utils .BlockPosition ;
60
57
import blockrenderer6343 .api .utils .Position ;
61
58
import blockrenderer6343 .api .utils .PositionedRect ;
62
59
import blockrenderer6343 .api .utils .Size ;
63
60
import blockrenderer6343 .client .utils .ProjectionUtils ;
64
61
import blockrenderer6343 .client .world .TrackedDummyWorld ;
65
62
import codechicken .lib .vec .Vector3 ;
66
63
import gregtech .common .render .GTRendererBlock ;
64
+ import it .unimi .dsi .fastutil .longs .LongOpenHashSet ;
65
+ import it .unimi .dsi .fastutil .longs .LongSet ;
67
66
68
67
/**
69
68
* Created with IntelliJ IDEA.
75
74
public abstract class WorldSceneRenderer {
76
75
77
76
// you have to place blocks in the world before use
78
- public final World world ;
77
+ public final TrackedDummyWorld world ;
79
78
// the Blocks which this renderer needs to render
80
- public final Set < BlockPosition > renderedBlocks = new HashSet <> ();
79
+ public final LongSet renderedBlocks = new LongOpenHashSet ();
81
80
private Consumer <WorldSceneRenderer > beforeRender ;
82
81
private Consumer <WorldSceneRenderer > onRender ;
83
82
private Consumer <MovingObjectPosition > onLookingAt ;
@@ -88,7 +87,7 @@ public abstract class WorldSceneRenderer {
88
87
private Vector3f worldUp = new Vector3f (0 , 1 , 0 );
89
88
private boolean renderAllFaces = false ;
90
89
91
- public WorldSceneRenderer (World world ) {
90
+ public WorldSceneRenderer (TrackedDummyWorld world ) {
92
91
this .world = world ;
93
92
}
94
93
@@ -102,7 +101,7 @@ public WorldSceneRenderer setOnWorldRender(Consumer<WorldSceneRenderer> callback
102
101
return this ;
103
102
}
104
103
105
- public WorldSceneRenderer addRenderedBlocks (Collection < BlockPosition > blocks ) {
104
+ public WorldSceneRenderer addRenderedBlocks (LongSet blocks ) {
106
105
if (blocks != null ) {
107
106
this .renderedBlocks .addAll (blocks );
108
107
}
@@ -277,8 +276,11 @@ protected void drawWorld() {
277
276
tessellator .startDrawingQuads ();
278
277
try {
279
278
tessellator .setBrightness (15 << 20 | 15 << 4 );
280
- for (BlockPosition pos : renderedBlocks ) {
281
- Block block = world .getBlock (pos .x , pos .y , pos .z );
279
+ for (long pos : renderedBlocks ) {
280
+ int x = CoordinatePacker .unpackX (pos );
281
+ int y = CoordinatePacker .unpackY (pos );
282
+ int z = CoordinatePacker .unpackZ (pos );
283
+ Block block = world .getBlock (x , y , z );
282
284
if (block .equals (Blocks .air )) continue ;
283
285
284
286
RenderBlocks bufferBuilder = new RenderBlocks ();
@@ -289,25 +291,19 @@ protected void drawWorld() {
289
291
// this mod cannot render renderpass = 1 blocks for now
290
292
bufferBuilder .renderStandardBlockWithColorMultiplier (
291
293
block ,
292
- pos . x ,
293
- pos . y ,
294
- pos . z ,
295
- bwGlass .getColor (world .getBlockMetadata (pos . x , pos . y , pos . z ))[0 ] / 255f ,
296
- bwGlass .getColor (world .getBlockMetadata (pos . x , pos . y , pos . z ))[1 ] / 255f ,
297
- bwGlass .getColor (world .getBlockMetadata (pos . x , pos . y , pos . z ))[2 ] / 255f );
294
+ x ,
295
+ y ,
296
+ z ,
297
+ bwGlass .getColor (world .getBlockMetadata (x , y , z ))[0 ] / 255f ,
298
+ bwGlass .getColor (world .getBlockMetadata (x , y , z ))[1 ] / 255f ,
299
+ bwGlass .getColor (world .getBlockMetadata (x , y , z ))[2 ] / 255f );
298
300
} else if (BlockRenderer6343 .isGTLoaded ) {
299
- if (!GTRendererBlock .INSTANCE .renderWorldBlock (
300
- world ,
301
- pos .x ,
302
- pos .y ,
303
- pos .z ,
304
- block ,
305
- block .getRenderType (),
306
- bufferBuilder )) {
307
- bufferBuilder .renderBlockByRenderType (block , pos .x , pos .y , pos .z );
301
+ if (!GTRendererBlock .INSTANCE
302
+ .renderWorldBlock (world , x , y , z , block , block .getRenderType (), bufferBuilder )) {
303
+ bufferBuilder .renderBlockByRenderType (block , x , y , z );
308
304
}
309
305
} else {
310
- bufferBuilder .renderBlockByRenderType (block , pos . x , pos . y , pos . z );
306
+ bufferBuilder .renderBlockByRenderType (block , x , y , z );
311
307
}
312
308
}
313
309
if (onRender != null ) {
@@ -327,12 +323,15 @@ protected void drawWorld() {
327
323
for (int pass = 0 ; pass < 2 ; pass ++) {
328
324
ForgeHooksClient .setRenderPass (pass );
329
325
int finalPass = pass ;
330
- renderedBlocks .forEach (blockPosition -> {
326
+ renderedBlocks .forEach (pos -> {
327
+ int x = CoordinatePacker .unpackX (pos );
328
+ int y = CoordinatePacker .unpackY (pos );
329
+ int z = CoordinatePacker .unpackZ (pos );
331
330
setDefaultPassRenderState (finalPass );
332
- TileEntity tile = world .getTileEntity (blockPosition . x , blockPosition . y , blockPosition . z );
331
+ TileEntity tile = world .getTileEntity (x , y , z );
333
332
if (tile != null && tesr .hasSpecialRenderer (tile )) {
334
333
if (tile .shouldRenderInPass (finalPass )) {
335
- tesr .renderTileEntityAt (tile , blockPosition . x , blockPosition . y , blockPosition . z , 0 );
334
+ tesr .renderTileEntityAt (tile , x , y , z , 0 );
336
335
}
337
336
}
338
337
});
@@ -363,6 +362,6 @@ public MovingObjectPosition rayTrace(Vector3f lookVec) {
363
362
(lookVec .x + startPos .xCoord ),
364
363
(lookVec .y + startPos .yCoord ),
365
364
(lookVec .z + startPos .zCoord ));
366
- return (( TrackedDummyWorld ) this .world ). rayTraceBlockswithTargetMap (startPos , endPos , renderedBlocks );
365
+ return this .world . rayTraceBlocksWithTargetMap (startPos , endPos , renderedBlocks );
367
366
}
368
367
}
0 commit comments