-
Notifications
You must be signed in to change notification settings - Fork 79
/
ModConfig.java
659 lines (530 loc) · 18.6 KB
/
ModConfig.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
package mod.chiselsandbits.config;
import java.io.File;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.EnumSet;
import java.util.HashSet;
import java.util.List;
import java.util.Map.Entry;
import java.util.Set;
import mod.chiselsandbits.core.ChiselsAndBits;
import mod.chiselsandbits.helpers.LocalStrings;
import mod.chiselsandbits.modes.ChiselMode;
import mod.chiselsandbits.modes.PositivePatternMode;
import mod.chiselsandbits.modes.TapeMeasureModes;
import mod.chiselsandbits.registry.ModRegistry;
import mod.chiselsandbits.render.chiseledblock.tesr.GfxRenderState.UseVBO;
import net.minecraft.launchwrapper.Launch;
import net.minecraftforge.common.config.ConfigCategory;
import net.minecraftforge.common.config.Configuration;
import net.minecraftforge.common.config.Property;
import net.minecraftforge.fml.client.event.ConfigChangedEvent;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
public class ModConfig extends Configuration
{
// automatic setting...
public boolean lowMemoryMode = false;
// file path...
final private File myPath;
// mod settings...
@Configured( category = "Integration Settings" )
public boolean ShowBitsInJEI;
@Configured( category = "Integration Settings" )
public boolean enableVivecraftCompatibility;
// @Configured( category = "Integration Settings" )
// public boolean enableMCMultipart;
@Configured( category = "Troubleshooting" )
public boolean enableAPITestingItem;
@Configured( category = "Troubleshooting" )
public boolean logTileErrors;
@Configured( category = "Client Settings" )
public boolean enableRightClickModeChange;
@Configured( category = "Client Settings" )
private boolean showUsage;
@Configured( category = "Client Settings" )
public boolean invertBitBagFullness;
@Configured( category = "Client Settings" )
public boolean enableChiselMode_Plane;
@Configured( category = "Client Settings" )
public boolean enableChiselMode_SameMaterial;
@Configured( category = "Client Settings" )
public boolean enableChiselMode_ConnectedPlane;
@Configured( category = "Client Settings" )
public boolean enableChiselMode_ConnectedMaterial;
@Configured( category = "Client Settings" )
public boolean enableChiselMode_Line;
@Configured( category = "Client Settings" )
public boolean enableChiselMode_SmallCube;
@Configured( category = "Client Settings" )
public boolean enableChiselMode_MediumCube;
@Configured( category = "Client Settings" )
public boolean enableChiselMode_LargeCube;
@Configured( category = "Client Settings" )
public boolean enableChiselMode_DrawnRegion;
@Configured( category = "Client Settings" )
public boolean enableChiselMode_Snap2;
@Configured( category = "Client Settings" )
public boolean enableChiselMode_Snap4;
@Configured( category = "Client Settings" )
public boolean enableChiselMode_Snap8;
@Configured( category = "Client Settings" )
public boolean enablePositivePatternMode_Additive;
@Configured( category = "Client Settings" )
public boolean enablePositivePatternMode_Impose;
@Configured( category = "Client Settings" )
public boolean enablePositivePatternMode_Placement;
@Configured( category = "Client Settings" )
public boolean enablePositivePatternMode_Replace;
@Configured( category = "Client Settings" )
public boolean enableTapeMeasure_Bit;
@Configured( category = "Client Settings" )
public boolean enableTapeMeasure_Block;
@Configured( category = "Client Settings" )
public boolean enableTapeMeasure_Distance;
@Configured( category = "Client Settings" )
public boolean enableToolbarIcons;
@Configured( category = "Client Settings" )
public boolean perChiselMode;
@Configured( category = "Client Settings" )
public boolean chatModeNotification;
@Configured( category = "Client Settings" )
public boolean itemNameModeDisplay;
@Configured( category = "Client Settings" )
public int creativeClipboardSize;
@Configured( category = "Client Settings" )
public boolean addBrokenBlocksToCreativeClipboard;
@Configured( category = "Client Settings" )
public boolean fluidBitsAreClickThrough;
@Configured( category = "Client Settings" )
public boolean persistCreativeClipboard;
@Configured( category = "Client Settings" )
public int maxUndoLevel;
@Configured( category = "Client Settings" )
public int maxTapeMeasures;
@Configured( category = "Client Settings" )
public boolean displayMeasuringTapeInChat;
@Configured( category = "Client Settings" )
public float radialMenuVolume;
@Configured( category = "Client Performance Settings" )
public static UseVBO useVBO;
@Configured( category = "Client Performance Settings" )
public int maxMillisecondsPerBlock = 10;
@Configured( category = "Client Performance Settings" )
public int maxMillisecondsUploadingPerFrame = 15;
@Configured( category = "Client Performance Settings" )
public int dynamicModelFaceCount;
@Configured( category = "Client Performance Settings" )
public int dynamicModelRange;
@Configured( category = "Client Performance Settings" )
public boolean dynamicModelMinimizeLatancy;
@Configured( category = "Client Performance Settings" )
public long minimizeLatancyMaxTime;
@Configured( category = "Client Performance Settings" )
public int dynamicMaxConcurrentTessalators;
@Configured( category = "Client Performance Settings" )
public boolean forceDynamicRenderer;
@Configured( category = "Client Performance Settings" )
public boolean defaultToDynamicRenderer;
@Configured( category = "Client Performance Settings" )
public boolean dynamicRenderFullChunksOnly;
@Configured( category = "Balance Settings" )
public boolean blacklistTickingBlocks;
@Configured( category = "Balance Settings" )
public boolean damageTools;
@Configured( category = "Crafting" )
public boolean enablePositivePrintCrafting;
@Configured( category = "Crafting" )
public boolean enableStackableCrafting;
@Configured( category = "Crafting" )
public boolean enableNegativePrintInversionCrafting;
@Configured( category = "Crafting" )
public boolean enableChiselCrafting;
@Configured( category = "Items" )
public boolean enableBitTank;
@Configured( category = "Items" )
public boolean enableBitBag;
@Configured( category = "Items" )
public boolean enableNegativePrint;
@Configured( category = "Items" )
public boolean enableMirrorPrint;
@Configured( category = "Items" )
public boolean enablePositivePrint;
@Configured( category = "Items" )
public boolean enableChisledBits;
@Configured( category = "Items" )
public boolean enableStoneChisel;
@Configured( category = "Items" )
public boolean enableIronChisel;
@Configured( category = "Items" )
public boolean enableGoldChisel;
@Configured( category = "Items" )
public boolean enableDiamondChisel;
@Configured( category = "Items" )
public boolean enableWoodenWrench;
@Configured( category = "Items" )
public boolean enableTapeMeasure;
@Configured( category = "Items" )
public boolean enableBitSaw;
@Configured( category = "Balance Settings" )
public boolean enableChiselToolHarvestCheck;
@Configured( category = "Balance Settings" )
public String enableChiselToolHarvestCheckTools;
@Configured( category = "Balance Settings" )
public boolean enableToolHarvestLevels;
@Configured( category = "Balance Settings" )
public boolean enableBitLightSource;
@Configured( category = "Balance Settings" )
public float bitLightPercentage;
@Configured( category = "Balance Settings" )
public boolean compatabilityMode;
@Configured( category = "Balance Settings" )
public double maxDrawnRegionSize;
@Configured( category = "Balance Settings" )
public int bagStackSize;
@Configured( category = "Balance Settings" )
public int stoneChiselUses;
@Configured( category = "Balance Settings" )
public int ironChiselUses;
@Configured( category = "Balance Settings" )
public int diamondChiselUses;
@Configured( category = "Balance Settings" )
public int goldChiselUses;
@Configured( category = "Balance Settings" )
public int wrenchUses;
@Configured( category = "Balance Settings" )
public int diamondSawUses;
@Configured( category = "Balance Settings" )
public boolean enableSetBitCommand;
@Configured( category = "Balance Settings" )
public boolean fullBlockCrafting;
// in game state
public boolean replaceingBits = false;
public boolean deobfuscatedEnvironment()
{
final Object deObf = Launch.blackboard.get( "fml.deobfuscatedEnvironment" );
return Boolean.valueOf( String.valueOf( deObf ) );
}
public boolean isEnabled(
final String className )
{
final Property p = get( "Enabled Blocks", className, true );
final boolean out = p.getBoolean( true );
if ( hasChanged() )
{
save();
}
return out;
}
private void setDefaults()
{
final long mem = Runtime.getRuntime().maxMemory() / ( 1024 * 1024 ); // mb
logTileErrors = false;
enableAPITestingItem = deobfuscatedEnvironment();
lowMemoryMode = mem < 1200;
enableChiselMode_SameMaterial = !ChiselMode.SAME_MATERIAL.isDisabled;
enableChiselMode_ConnectedMaterial = !ChiselMode.CONNECTED_MATERIAL.isDisabled;
enableChiselMode_ConnectedPlane = !ChiselMode.CONNECTED_PLANE.isDisabled;
enableChiselMode_LargeCube = !ChiselMode.CUBE_LARGE.isDisabled;
enableChiselMode_MediumCube = !ChiselMode.CUBE_MEDIUM.isDisabled;
enableChiselMode_SmallCube = !ChiselMode.CUBE_SMALL.isDisabled;
enableChiselMode_Line = !ChiselMode.LINE.isDisabled;
enableChiselMode_Plane = !ChiselMode.PLANE.isDisabled;
enableChiselMode_DrawnRegion = !ChiselMode.DRAWN_REGION.isDisabled;
enableChiselMode_Snap2 = !ChiselMode.SNAP2.isDisabled;
enableChiselMode_Snap4 = !ChiselMode.SNAP4.isDisabled;
enableChiselMode_Snap8 = !ChiselMode.SNAP8.isDisabled;
enablePositivePatternMode_Additive = !PositivePatternMode.ADDITIVE.isDisabled;
enablePositivePatternMode_Impose = !PositivePatternMode.IMPOSE.isDisabled;
enablePositivePatternMode_Placement = !PositivePatternMode.PLACEMENT.isDisabled;
enablePositivePatternMode_Replace = !PositivePatternMode.REPLACE.isDisabled;
enableTapeMeasure_Bit = !TapeMeasureModes.BIT.isDisabled;
enableTapeMeasure_Block = !TapeMeasureModes.BLOCK.isDisabled;
enableTapeMeasure_Distance = !TapeMeasureModes.DISTANCE.isDisabled;
displayMeasuringTapeInChat = false;
perChiselMode = true;
enableChiselCrafting = true;
fullBlockCrafting = true;
radialMenuVolume = 0.1f;
chatModeNotification = false;
itemNameModeDisplay = true;
enableToolbarIcons = true;
compatabilityMode = true;
maxDrawnRegionSize = 4;
bagStackSize = 512;
maxUndoLevel = 32;
maxTapeMeasures = 5;
// Dynamic models..
dynamicModelFaceCount = 40;
dynamicModelRange = 128;
dynamicModelMinimizeLatancy = true;
minimizeLatancyMaxTime = 100;
dynamicMaxConcurrentTessalators = 32; // in low memory this acts as 2.
forceDynamicRenderer = false;
defaultToDynamicRenderer = false;
dynamicRenderFullChunksOnly = true;
useVBO = UseVBO.AUTOMATIC;
showUsage = true;
invertBitBagFullness = false;
enableSetBitCommand = false;
damageTools = true;
blacklistTickingBlocks = true;
stoneChiselUses = 8384;
ironChiselUses = 293440;
diamondChiselUses = 796480;
goldChiselUses = 1024;
wrenchUses = 1888;
diamondSawUses = 7980;
enablePositivePrintCrafting = true;
enableStackableCrafting = true;
enableNegativePrintInversionCrafting = true;
enableChiselToolHarvestCheck = true;
enableToolHarvestLevels = true;
enableChiselToolHarvestCheckTools = "pickaxe,axe,shovel";
creativeClipboardSize = 32;
addBrokenBlocksToCreativeClipboard = true;
fluidBitsAreClickThrough = true;
persistCreativeClipboard = true;
enableRightClickModeChange = false;
enableBitTank = true;
enableBitLightSource = true;
bitLightPercentage = 6.25f;
enableBitBag = true;
enableNegativePrint = true;
enablePositivePrint = true;
enableMirrorPrint = true;
enableChisledBits = true;
enableStoneChisel = true;
enableIronChisel = true;
enableGoldChisel = true;
enableDiamondChisel = true;
enableWoodenWrench = true;
enableTapeMeasure = true;
enableBitSaw = true;
ShowBitsInJEI = false;
enableVivecraftCompatibility = false;
// enableMCMultipart = false;
}
public ModConfig(
final File path )
{
super( path );
myPath = path;
ChiselsAndBits.registerWithBus( this );
setDefaults();
populateSettings();
save();
}
@SuppressWarnings( { "unchecked", "rawtypes" } )
void populateSettings()
{
final Class<ModConfig> me = ModConfig.class;
final Set<Property> fields = new HashSet<Property>();
for ( final Field f : me.getDeclaredFields() )
{
final Configured c = f.getAnnotation( Configured.class );
if ( c != null )
{
try
{
Property p = null;
if ( f.getType() == long.class || f.getType() == Long.class )
{
final long defaultValue = f.getLong( this );
p = get( c.category(), f.getName(), (int) defaultValue );
final long value = p.getInt();
f.set( this, value );
}
else if ( f.getType() == String.class )
{
final String defaultValue = (String) f.get( this );
p = get( c.category(), f.getName(), defaultValue );
final String value = p.getString();
f.set( this, value );
}
else if ( f.getType() == int.class || f.getType() == Integer.class )
{
final int defaultValue = f.getInt( this );
p = get( c.category(), f.getName(), defaultValue );
final int value = p.getInt();
f.set( this, value );
}
else if ( f.getType() == float.class || f.getType() == Float.class )
{
final float defaultValue = f.getFloat( this );
p = get( c.category(), f.getName(), defaultValue );
final float value = (float) p.getDouble();
f.set( this, value );
}
else if ( f.getType() == double.class || f.getType() == Double.class )
{
final double defaultValue = f.getDouble( this );
p = get( c.category(), f.getName(), defaultValue );
final double value = p.getDouble();
f.set( this, value );
}
else if ( f.getType() == boolean.class || f.getType() == Boolean.class )
{
final boolean defaultValue = f.getBoolean( this );
p = get( c.category(), f.getName(), defaultValue );
final boolean value = p.getBoolean();
f.set( this, value );
}
else if ( Enum.class.isAssignableFrom( f.getType() ) )
{
final Class<? extends Enum> eClass = (Class<? extends Enum>) f.getType();
final Enum<?> defaultValue = (Enum<?>) f.get( this );
final EnumSet<?> options = EnumSet.allOf( eClass );
final String[] values = new String[options.size()];
int off = 0;
for ( final Object eo : options )
{
final Enum<?> exc = (Enum<?>) eo;
values[off++] = exc.name();
}
p = get( c.category(), f.getName(), defaultValue != null ? defaultValue.toString() : "", "", values );
final String value = p.getString();
for ( final Object eo : options )
{
final Enum<?> exc = (Enum<?>) eo;
if ( exc.name().equals( value ) )
{
f.set( this, eo );
}
}
}
if ( p != null )
{
p.setLanguageKey( ModRegistry.unlocalizedPrefix + "config." + f.getName() );
fields.add( p );
}
}
catch ( final IllegalArgumentException e )
{
// yar!
e.printStackTrace();
}
catch ( final IllegalAccessException e )
{
// yar!
e.printStackTrace();
}
}
}
// cleanup the config... remove junk...
for ( final String s : getCategoryNames() )
{
if ( s.equals( "enabled blocks" ) )
{
continue;
}
final ConfigCategory cc = getCategory( s );
final List<String> removeThis = new ArrayList<String>();
for ( final Entry<String, Property> e : cc.entrySet() )
{
if ( !fields.contains( e.getValue() ) )
{
removeThis.add( e.getKey() );
}
}
for ( final String g : removeThis )
{
cc.remove( g );
}
}
sync();
}
private void sync()
{
// sane bag sizes...
if ( bagStackSize < 64 )
{
bagStackSize = 64;
}
else if ( bagStackSize > 999999 )
{
bagStackSize = 999999;
}
// configure mode enums..
ChiselMode.SAME_MATERIAL.isDisabled = !enableChiselMode_SameMaterial;
ChiselMode.CONNECTED_MATERIAL.isDisabled = !enableChiselMode_ConnectedMaterial;
ChiselMode.CONNECTED_PLANE.isDisabled = !enableChiselMode_ConnectedPlane;
ChiselMode.CUBE_LARGE.isDisabled = !enableChiselMode_LargeCube;
ChiselMode.CUBE_MEDIUM.isDisabled = !enableChiselMode_MediumCube;
ChiselMode.CUBE_SMALL.isDisabled = !enableChiselMode_SmallCube;
ChiselMode.LINE.isDisabled = !enableChiselMode_Line;
ChiselMode.PLANE.isDisabled = !enableChiselMode_Plane;
ChiselMode.DRAWN_REGION.isDisabled = !enableChiselMode_DrawnRegion;
ChiselMode.SNAP2.isDisabled = !enableChiselMode_Snap2;
ChiselMode.SNAP4.isDisabled = !enableChiselMode_Snap4;
ChiselMode.SNAP8.isDisabled = !enableChiselMode_Snap8;
PositivePatternMode.ADDITIVE.isDisabled = !enablePositivePatternMode_Additive;
PositivePatternMode.IMPOSE.isDisabled = !enablePositivePatternMode_Impose;
PositivePatternMode.PLACEMENT.isDisabled = !enablePositivePatternMode_Placement;
PositivePatternMode.REPLACE.isDisabled = !enablePositivePatternMode_Replace;
TapeMeasureModes.BIT.isDisabled = !enableTapeMeasure_Bit;
TapeMeasureModes.BLOCK.isDisabled = !enableTapeMeasure_Block;
TapeMeasureModes.DISTANCE.isDisabled = !enableTapeMeasure_Distance;
}
@SubscribeEvent
public void onConfigChanged(
final ConfigChangedEvent.OnConfigChangedEvent eventArgs )
{
if ( eventArgs.getModID().equals( ChiselsAndBits.MODID ) )
{
populateSettings();
save();
}
}
@Override
public void save()
{
if ( hasChanged() )
{
super.save();
}
}
@Override
public Property get(
final String category,
final String key,
final String defaultValue,
final String comment,
final Property.Type type )
{
final Property prop = super.get( category, key, defaultValue, comment, type );
if ( prop != null && !category.equals( "Client Settings" ) && category.equals( "Client Performance" ) )
{
prop.setRequiresMcRestart( true );
}
return prop;
}
public void helpText(
final LocalStrings string,
final List<String> tooltip,
final String... variables )
{
if ( showUsage )
{
int varOffset = 0;
final String[] lines = string.getLocal().split( ";" );
for ( String a : lines )
{
while ( a.contains( "{}" ) && variables.length > varOffset )
{
final int offset = a.indexOf( "{}" );
if ( offset >= 0 )
{
final String pre = a.substring( 0, offset );
final String post = a.substring( offset + 2 );
a = new StringBuilder( pre ).append( variables[varOffset++] ).append( post ).toString();
}
}
tooltip.add( a );
}
}
}
public String getFilePath()
{
return myPath.getAbsolutePath();
}
}