1212import com .mojang .blaze3d .platform .GlStateManager ;
1313import com .mojang .blaze3d .platform .TextureUtil ;
1414import com .mojang .blaze3d .systems .RenderSystem ;
15+ import com .mojang .brigadier .arguments .IntegerArgumentType ;
1516import com .mojang .brigadier .builder .ArgumentBuilder ;
1617import com .mojang .brigadier .builder .LiteralArgumentBuilder ;
1718import com .mojang .brigadier .builder .RequiredArgumentBuilder ;
@@ -91,7 +92,8 @@ public class VeinBuddyClient implements ClientModInitializer {
9192 private boolean change = true ;
9293 private int saveNumber = 0 ;
9394 private int changeNumber = 0 ;
94- private boolean showOutlines ;
95+ private boolean showOutlines = false ;
96+ private boolean render = true ;
9597
9698 private Set <Vec3i > selections = new ConcurrentSkipListSet <Vec3i >();
9799 private Map <Vec3i , Vec3i > selectionRanges = new ConcurrentHashMap <Vec3i , Vec3i >();
@@ -117,30 +119,30 @@ public class VeinBuddyClient implements ClientModInitializer {
117119 private int wallShaderProgram = 0 ;
118120 private int gridShaderProgram = 0 ;
119121
122+
120123 @ Override
121124 public void onInitializeClient () {
122- ClientLifecycleEvents .CLIENT_STARTED .register (client -> loadShaders () );
125+ ClientLifecycleEvents .CLIENT_STARTED .register (this :: loadShaders );
123126 ClientPlayConnectionEvents .JOIN .register ((handler , sender , client ) -> onStart (client ));
124- ClientTickEvents .END_CLIENT_TICK .register (client -> onTick (client ));
125- ClientTickEvents .END_CLIENT_TICK .register (client -> saveSelections (client ));
126- WorldRenderEvents .AFTER_TRANSLUCENT .register (context -> afterTranslucent (context ));
127- WorldRenderEvents .LAST .register (context -> wireframeOverlays (context ));
128-
129- LiteralArgumentBuilder <FabricClientCommandSource > clearAll = ClientCommandManager .literal ("clearAll" );
130- LiteralArgumentBuilder <FabricClientCommandSource > clearFar = ClientCommandManager .literal ("clearFar" );
131- LiteralArgumentBuilder <FabricClientCommandSource > clearNear = ClientCommandManager .literal ("clearNear" );
132- LiteralArgumentBuilder <FabricClientCommandSource > hideOutlines = ClientCommandManager .literal ("hideOutlines" );
133- LiteralArgumentBuilder <FabricClientCommandSource > showOutlines = ClientCommandManager .literal ("showOutlines" );
134- LiteralArgumentBuilder <FabricClientCommandSource > reload = ClientCommandManager .literal ("reload" );
135-
136- ClientCommandRegistrationCallback .EVENT .register ((dispatcher , registryAccess ) -> {
137- dispatcher .register (clearAll .executes (context -> onClearAll (context )));
138- dispatcher .register (clearFar .executes (context -> onClearFar (context )));
139- dispatcher .register (clearNear .executes (context -> onClearNear (context )));
140- dispatcher .register (hideOutlines .executes (context -> onHideOutlines (context )));
141- dispatcher .register (showOutlines .executes (context -> onShowOutlines (context )));
142- dispatcher .register (reload .executes (context -> onReload (context )));
143- });
127+ ClientTickEvents .END_CLIENT_TICK .register (this ::onTick );
128+ ClientTickEvents .END_CLIENT_TICK .register (this ::saveSelections );
129+ WorldRenderEvents .AFTER_TRANSLUCENT .register (this ::afterTranslucent );
130+ WorldRenderEvents .LAST .register (this ::wireframeOverlays );
131+
132+ ClientCommandRegistrationCallback .EVENT .register ((dispatcher , registryAccess ) -> dispatcher .register (
133+ ClientCommandManager .literal ("veinbuddy" )
134+ .then (ClientCommandManager .literal ("clearAll" ).executes (this ::onClearAll ))
135+ .then (ClientCommandManager .literal ("clearFar" ).executes (this ::onClearFar ))
136+ .then (ClientCommandManager .literal ("clearNear" ).executes (this ::onClearNear ))
137+ .then (ClientCommandManager .literal ("digRange" )
138+ .then (ClientCommandManager .argument ("x" , IntegerArgumentType .integer (1 , 10 ))
139+ .then (ClientCommandManager .argument ("y" , IntegerArgumentType .integer (1 , 10 ))
140+ .then (ClientCommandManager .argument ("z" , IntegerArgumentType .integer (1 , 10 ))
141+ .executes (this ::onDigRange )))))
142+ .then (ClientCommandManager .literal ("hideOutlines" ).executes (this ::onHideOutlines ))
143+ .then (ClientCommandManager .literal ("showOutlines" ).executes (this ::onShowOutlines ))
144+ .then (ClientCommandManager .literal ("toggleRender" ).executes (this ::onToggleRender ))
145+ ));
144146 }
145147
146148 private File getConfigFile (MinecraftClient client ) {
@@ -152,10 +154,10 @@ private File getSaveFile(MinecraftClient client) {
152154 if (null == serverInfo )
153155 return null ;
154156 String address = serverInfo .address ;
155- return new File (client .runDirectory , address + ".txt" );
157+ return new File (client .runDirectory , "data/veinbuddy/" + address + ".txt" );
156158 }
157159
158- private void loadShaders () {
160+ private void loadShaders (MinecraftClient client ) {
159161 int selectionVertexShader = loadShaderProgram ("selections" , ".vsh" , GL30 .GL_VERTEX_SHADER );
160162 int wallVertexShader = loadShaderProgram ("walls" , ".vsh" , GL30 .GL_VERTEX_SHADER );
161163 int gridVertexShader = loadShaderProgram ("grids" , ".vsh" , GL30 .GL_VERTEX_SHADER );
@@ -222,6 +224,7 @@ private void saveSelections(MinecraftClient client) {
222224 File saveFile = getSaveFile (client );
223225 if (null == saveFile )
224226 return ;
227+ saveFile .getParentFile ().mkdirs ();
225228 FileWriter fileWriter = new FileWriter (saveFile , false );
226229 fileWriter .write ("Version 2\n " );
227230 for (Vec3i selection : selections ) {
@@ -241,9 +244,10 @@ private void onStart(MinecraftClient client) {
241244 if (null != configFile ) {
242245 try {
243246 Scanner sc = new Scanner (configFile );
244- int digXRange = sc .nextInt ();
245- int digYRange = sc .nextInt ();
246- int digZRange = sc .nextInt ();
247+ int x = sc .nextInt ();
248+ int y = sc .nextInt ();
249+ int z = sc .nextInt ();
250+ digRange = new Vec3i (x , y , z );
247251 } catch (IOException e ) {
248252 System .out .println ("Mad!" );
249253 }
@@ -372,50 +376,38 @@ private int onShowOutlines(CommandContext<FabricClientCommandSource> ctx) {
372376 return 0 ;
373377 }
374378
375- private int onReload (CommandContext <FabricClientCommandSource > ctx ) {
376- selections = new ConcurrentSkipListSet <Vec3i >();
377- selectionWalls = new ConcurrentHashMap <Vec3i , WallGroup >();
378-
379- boundary = new ConcurrentSkipListSet <Vec3i >();
380- wallBlocks = new ConcurrentSkipListSet <Vec3i >();
381- wallBlockWalls = new ConcurrentHashMap <Vec3i , WallGroup >();
382- File saveFile = getSaveFile (mc );
379+ private int onToggleRender (CommandContext <FabricClientCommandSource > ctx ) {
380+ render = !render ;
381+ return 0 ;
382+ }
383383
384- if (null == saveFile )
385- return -1 ;
384+ private int onDigRange (CommandContext <FabricClientCommandSource > ctx ) {
385+ int x = IntegerArgumentType .getInteger (ctx , "x" );
386+ int y = IntegerArgumentType .getInteger (ctx , "y" );
387+ int z = IntegerArgumentType .getInteger (ctx , "z" );
388+ digRange = new Vec3i (x , y , z );
386389 try {
387- Scanner sc = new Scanner (saveFile );
388- sc .nextLine ();
389- while (sc .hasNext ()){
390- int x = sc .nextInt ();
391- int y = sc .nextInt ();
392- int z = sc .nextInt ();
393- int xRange = sc .nextInt ();
394- int yRange = sc .nextInt ();
395- int zRange = sc .nextInt ();
396- addSelection (new Vec3i (x , y , z ), new Vec3i (xRange , yRange , zRange ), true );
397- sc .nextLine ();
398- }
390+ File configFile = getConfigFile (mc );
391+ FileWriter fileWriter = new FileWriter (configFile , false );
392+ fileWriter .write (x + " " + y + " " + z + "\n " );
399393 } catch (IOException e ) {
400- System .out .println ("Bad !" );
394+ System .out .println ("Egad !" );
401395 }
402- updateWalls ();
403- refreshBuffer ();
404396
405397 return 0 ;
406398 }
407399
408400 private void onTick (MinecraftClient client ) {
409401 if (null == client .player ) return ;
410- if (null == mc .mouse ) return ;
411- if (null == mc .world ) return ;
402+ if (null == client .mouse ) return ;
403+ if (null == client .world ) return ;
412404 if (!(client .player .getInventory ().getMainHandStack ().getItem () instanceof PickaxeItem )) {
413405 pos = null ;
414406 posBlock = null ;
415407 selectionTicks = 0 ;
416408 return ;
417409 }
418- boolean rightClick = mc .mouse .wasRightButtonClicked ();
410+ boolean rightClick = client .mouse .wasRightButtonClicked ();
419411 Vec3d playerPos = client .player .getPos ().add (0.0f , 1.6f , 0.0f );
420412 Vec3d playerDir = client .player .getRotationVector ();
421413 if (!rightClick && 0 != selectionTicks && 10 > selectionTicks ) {
@@ -904,8 +896,6 @@ private void wireframeOverlays(WorldRenderContext ctx) {
904896 if (null == mc .player ) return ;
905897 if (null == posBlock && (!showOutlines || selections .isEmpty ())) return ;
906898
907- boolean render = false ;
908-
909899 Vec3d camPos = ctx .camera ().getPos ();
910900 MatrixStack stack = ctx .matrixStack ();
911901 stack .push ();
@@ -915,23 +905,19 @@ private void wireframeOverlays(WorldRenderContext ctx) {
915905 BufferBuilder buffer = tessellator .begin (VertexFormat .DrawMode .DEBUG_LINES , VertexFormats .POSITION_COLOR );
916906
917907 if (null != posBlock ){
918- render = true ;
919908 buildVerticesOutline (buffer , mat , posBlock );
920909 }
921910
922911 if (showOutlines && !selections .isEmpty ()) {
923- render = true ;
924912 for (Vec3i selection : selections ) {
925913 buildVerticesOutline (buffer , mat , selection );
926914 }
927915 }
928916
929- if (render ) {
930- RenderSystem .setShader (GameRenderer ::getPositionColorProgram );
931- RenderSystem .setShaderColor (1.0F , 1.0F , 1.0F , 1.0F );
917+ RenderSystem .setShader (GameRenderer ::getPositionColorProgram );
918+ RenderSystem .setShaderColor (1.0F , 1.0F , 1.0F , 1.0F );
932919
933- BufferRenderer .drawWithGlobalProgram (buffer .end ());
934- }
920+ BufferRenderer .drawWithGlobalProgram (buffer .end ());
935921
936922 stack .pop ();
937923 }
@@ -965,7 +951,7 @@ private void refreshBuffer() {
965951 }
966952
967953 private void afterTranslucent (WorldRenderContext ctx ) {
968- if (selections .isEmpty ()) return ;
954+ if (selections .isEmpty () || ! render ) return ;
969955
970956 Vec3d camPos = ctx .camera ().getPos ();
971957 Vector3f camVec = new Vector3f (-(float )camPos .getX (), -(float )camPos .getY (), -(float )camPos .getZ ());
@@ -992,7 +978,7 @@ private void afterTranslucent(WorldRenderContext ctx) {
992978
993979 GL30 .glUseProgram (selectionShaderProgram );
994980 GL30 .glUniformMatrix4fv (GL30 .glGetUniformLocation (selectionShaderProgram , "u_projection" ), false , mat );
995- GL30 .glDrawArrays (GL30 .GL_TRIANGLES , 0 , selectionBuffer .capacity () / 3 / 4 ); //3 floats per vertex, 4 bytes per float
981+ GL30 .glDrawArrays (GL30 .GL_TRIANGLES , 0 , selectionBuffer .capacity () / 3 / 4 ); //three floats per vertex, four bytes per float
996982 GL30 .glUseProgram (0 );
997983
998984 GL30 .glBindBuffer (GL30 .GL_ARRAY_BUFFER , wallVBO );
@@ -1002,7 +988,7 @@ private void afterTranslucent(WorldRenderContext ctx) {
1002988
1003989 GL30 .glUseProgram (wallShaderProgram );
1004990 GL30 .glUniformMatrix4fv (GL30 .glGetUniformLocation (wallShaderProgram , "u_projection" ), false , mat );
1005- GL30 .glDrawArrays (GL30 .GL_TRIANGLES , 0 , wallBuffer .capacity () / 3 / 4 ); //3 floats per vertex, 4 bytes per float
991+ GL30 .glDrawArrays (GL30 .GL_TRIANGLES , 0 , wallBuffer .capacity () / 3 / 4 ); //three floats per vertex, four bytes per float
1006992 GL30 .glUseProgram (0 );
1007993
1008994 GL30 .glBindBuffer (GL30 .GL_ARRAY_BUFFER , gridVBO );
@@ -1012,7 +998,7 @@ private void afterTranslucent(WorldRenderContext ctx) {
1012998
1013999 GL30 .glUseProgram (gridShaderProgram );
10141000 GL30 .glUniformMatrix4fv (GL30 .glGetUniformLocation (gridShaderProgram , "u_projection" ), false , mat );
1015- GL30 .glDrawArrays (GL30 .GL_LINES , 0 , gridBuffer .capacity () / 3 / 4 ); //3 vertices per vertex, 4 bytes per float
1001+ GL30 .glDrawArrays (GL30 .GL_LINES , 0 , gridBuffer .capacity () / 3 / 4 ); //three vertices per vertex, four bytes per float
10161002 GL30 .glUseProgram (0 );
10171003
10181004 updateBuffers = false ;
0 commit comments