-
Notifications
You must be signed in to change notification settings - Fork 79
/
ClientSide.java
1545 lines (1323 loc) · 49.4 KB
/
ClientSide.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
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
package mod.chiselsandbits.core;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.util.HashMap;
import java.util.Random;
import java.util.concurrent.TimeUnit;
import javax.annotation.Nonnull;
import org.lwjgl.input.Keyboard;
import org.lwjgl.input.Mouse;
import org.lwjgl.opengl.GL11;
import com.google.common.base.Stopwatch;
import mod.chiselsandbits.api.APIExceptions.CannotBeChiseled;
import mod.chiselsandbits.api.IBitAccess;
import mod.chiselsandbits.api.IBitBrush;
import mod.chiselsandbits.api.ItemType;
import mod.chiselsandbits.bittank.BlockBitTank;
import mod.chiselsandbits.bittank.TileEntityBitTank;
import mod.chiselsandbits.bittank.TileEntitySpecialRenderBitTank;
import mod.chiselsandbits.chiseledblock.BlockBitInfo;
import mod.chiselsandbits.chiseledblock.BlockChiseled;
import mod.chiselsandbits.chiseledblock.ItemBlockChiseled;
import mod.chiselsandbits.chiseledblock.NBTBlobConverter;
import mod.chiselsandbits.chiseledblock.TileEntityBlockChiseled;
import mod.chiselsandbits.chiseledblock.TileEntityBlockChiseledTESR;
import mod.chiselsandbits.chiseledblock.data.BitIterator;
import mod.chiselsandbits.chiseledblock.data.BitLocation;
import mod.chiselsandbits.chiseledblock.data.IntegerBox;
import mod.chiselsandbits.chiseledblock.data.VoxelBlob;
import mod.chiselsandbits.chiseledblock.data.VoxelBlobStateReference;
import mod.chiselsandbits.chiseledblock.iterators.ChiselIterator;
import mod.chiselsandbits.chiseledblock.iterators.ChiselTypeIterator;
import mod.chiselsandbits.client.BlockColorChisled;
import mod.chiselsandbits.client.CreativeClipboardTab;
import mod.chiselsandbits.client.ItemColorBits;
import mod.chiselsandbits.client.ItemColorChisled;
import mod.chiselsandbits.client.ItemColorPatterns;
import mod.chiselsandbits.client.ModConflictContext;
import mod.chiselsandbits.client.RenderHelper;
import mod.chiselsandbits.client.TapeMeasures;
import mod.chiselsandbits.client.UndoTracker;
import mod.chiselsandbits.client.gui.ChiselsAndBitsMenu;
import mod.chiselsandbits.client.gui.SpriteIconPositioning;
import mod.chiselsandbits.commands.JsonModelExport;
import mod.chiselsandbits.helpers.BitOperation;
import mod.chiselsandbits.helpers.ChiselModeManager;
import mod.chiselsandbits.helpers.ChiselToolType;
import mod.chiselsandbits.helpers.LocalStrings;
import mod.chiselsandbits.helpers.ModUtil;
import mod.chiselsandbits.helpers.VoxelRegionSrc;
import mod.chiselsandbits.integration.mcmultipart.MCMultipartProxy;
import mod.chiselsandbits.interfaces.IItemScrollWheel;
import mod.chiselsandbits.interfaces.IPatternItem;
import mod.chiselsandbits.items.ItemChisel;
import mod.chiselsandbits.items.ItemChiseledBit;
import mod.chiselsandbits.modes.ChiselMode;
import mod.chiselsandbits.modes.IToolMode;
import mod.chiselsandbits.modes.PositivePatternMode;
import mod.chiselsandbits.modes.TapeMeasureModes;
import mod.chiselsandbits.network.NetworkRouter;
import mod.chiselsandbits.network.packets.PacketChisel;
import mod.chiselsandbits.network.packets.PacketRotateVoxelBlob;
import mod.chiselsandbits.network.packets.PacketSetColor;
import mod.chiselsandbits.network.packets.PacketSuppressInteraction;
import mod.chiselsandbits.registry.ModItems;
import mod.chiselsandbits.render.SmartModelManager;
import mod.chiselsandbits.render.chiseledblock.tesr.ChisledBlockRenderChunkTESR;
import net.minecraft.block.Block;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.Minecraft;
import net.minecraft.client.audio.PositionedSoundRecord;
import net.minecraft.client.gui.GuiIngame;
import net.minecraft.client.gui.ScaledResolution;
import net.minecraft.client.particle.Particle;
import net.minecraft.client.particle.ParticleManager;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.renderer.ItemMeshDefinition;
import net.minecraft.client.renderer.block.model.IBakedModel;
import net.minecraft.client.renderer.block.model.ModelBakery;
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
import net.minecraft.client.renderer.texture.TextureMap;
import net.minecraft.client.renderer.texture.TextureUtil;
import net.minecraft.client.resources.IResource;
import net.minecraft.client.settings.GameSettings;
import net.minecraft.client.settings.KeyBinding;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.SoundEvents;
import net.minecraft.item.EnumDyeColor;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumFacing.Axis;
import net.minecraft.util.EnumHand;
import net.minecraft.util.EnumParticleTypes;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.SoundCategory;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.RayTraceResult;
import net.minecraft.world.World;
import net.minecraftforge.client.ClientCommandHandler;
import net.minecraftforge.client.event.DrawBlockHighlightEvent;
import net.minecraftforge.client.event.MouseEvent;
import net.minecraftforge.client.event.RenderGameOverlayEvent;
import net.minecraftforge.client.event.RenderGameOverlayEvent.ElementType;
import net.minecraftforge.client.event.RenderWorldLastEvent;
import net.minecraftforge.client.event.TextureStitchEvent;
import net.minecraftforge.client.model.ModelLoader;
import net.minecraftforge.client.settings.IKeyConflictContext;
import net.minecraftforge.client.settings.KeyConflictContext;
import net.minecraftforge.event.entity.player.PlayerInteractEvent.RightClickBlock;
import net.minecraftforge.fml.client.registry.ClientRegistry;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.common.gameevent.TickEvent;
import net.minecraftforge.fml.common.gameevent.TickEvent.Phase;
import net.minecraftforge.fml.common.gameevent.TickEvent.Type;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
public class ClientSide
{
private static final Random RANDOM = new Random();
public static final ClientSide instance = new ClientSide();
private final HashMap<IToolMode, SpriteIconPositioning> chiselModeIcons = new HashMap<IToolMode, SpriteIconPositioning>();
private KeyBinding rotateCCW;
private KeyBinding rotateCW;
private KeyBinding undo;
private KeyBinding redo;
private KeyBinding modeMenu;
private KeyBinding addToClipboard;
private KeyBinding pickBit;
private Stopwatch rotateTimer;
final public TapeMeasures tapeMeasures = new TapeMeasures();
public void preinit(
final ChiselsAndBits mod )
{
ChiselsAndBits.registerWithBus( new SmartModelManager() );
registerModels();
}
public void init(
final ChiselsAndBits chiselsandbits )
{
ClientRegistry.bindTileEntitySpecialRenderer( TileEntityBlockChiseledTESR.class, new ChisledBlockRenderChunkTESR() );
ClientRegistry.bindTileEntitySpecialRenderer( TileEntityBitTank.class, new TileEntitySpecialRenderBitTank() );
for ( final ChiselMode mode : ChiselMode.values() )
{
mode.binding = registerKeybind( mode.string.toString(), 0, "itemGroup.chiselsandbits", ModConflictContext.HOLDING_CHISEL );
}
for ( final PositivePatternMode mode : PositivePatternMode.values() )
{
mode.binding = registerKeybind( mode.string.toString(), 0, "itemGroup.chiselsandbits", ModConflictContext.HOLDING_POSTIVEPATTERN );
}
for ( final TapeMeasureModes mode : TapeMeasureModes.values() )
{
mode.binding = registerKeybind( mode.string.toString(), 0, "itemGroup.chiselsandbits", ModConflictContext.HOLDING_TAPEMEASURE );
}
modeMenu = registerKeybind( "mod.chiselsandbits.other.mode", 56, "itemGroup.chiselsandbits", ModConflictContext.HOLDING_MENUITEM );
rotateCCW = registerKeybind( "mod.chiselsandbits.other.rotate.ccw", 0, "itemGroup.chiselsandbits", ModConflictContext.HOLDING_ROTATEABLE );
rotateCW = registerKeybind( "mod.chiselsandbits.other.rotate.cw", 0, "itemGroup.chiselsandbits", ModConflictContext.HOLDING_ROTATEABLE );
pickBit = registerKeybind( "mod.chiselsandbits.other.pickbit", 0, "itemGroup.chiselsandbits", ModConflictContext.HOLDING_ROTATEABLE );
undo = registerKeybind( "mod.chiselsandbits.other.undo", 0, "itemGroup.chiselsandbits", KeyConflictContext.IN_GAME );
redo = registerKeybind( "mod.chiselsandbits.other.redo", 0, "itemGroup.chiselsandbits", KeyConflictContext.IN_GAME );
addToClipboard = registerKeybind( "mod.chiselsandbits.other.add_to_clipboard", 0, "itemGroup.chiselsandbits", KeyConflictContext.IN_GAME );
ChiselsAndBits.registerWithBus( instance );
ClientCommandHandler.instance.registerCommand( new JsonModelExport() );
}
private KeyBinding registerKeybind(
final String bindingName,
final int defaultKey,
final String groupName,
final IKeyConflictContext context )
{
final KeyBinding kb = new KeyBinding( bindingName, context, defaultKey, groupName );
ClientRegistry.registerKeyBinding( kb );
return kb;
}
public void postinit(
final ChiselsAndBits mod )
{
final ModItems modItems = ChiselsAndBits.getItems();
if ( modItems.itemBlockBit != null )
{
Minecraft.getMinecraft().getItemColors().registerItemColorHandler( new ItemColorBits(), modItems.itemBlockBit );
}
if ( modItems.itemPositiveprint != null )
{
Minecraft.getMinecraft().getItemColors().registerItemColorHandler( new ItemColorPatterns(), modItems.itemPositiveprint );
}
if ( modItems.itemNegativeprint != null )
{
Minecraft.getMinecraft().getItemColors().registerItemColorHandler( new ItemColorPatterns(), modItems.itemNegativeprint );
}
if ( modItems.itemMirrorprint != null )
{
Minecraft.getMinecraft().getItemColors().registerItemColorHandler( new ItemColorPatterns(), modItems.itemMirrorprint );
}
for ( final BlockChiseled blk : ChiselsAndBits.getBlocks().getConversions().values() )
{
final Item item = Item.getItemFromBlock( blk );
Minecraft.getMinecraft().getItemColors().registerItemColorHandler( new ItemColorChisled(), item );
Minecraft.getMinecraft().getBlockColors().registerBlockColorHandler( new BlockColorChisled(), blk );
}
}
public void registerModels()
{
final String modId = ChiselsAndBits.MODID;
final ModItems modItems = ChiselsAndBits.getItems();
registerMesh( modItems.itemChiselStone, 0, new ModelResourceLocation( new ResourceLocation( modId, "chisel_stone" ), "inventory" ) );
registerMesh( modItems.itemChiselIron, 0, new ModelResourceLocation( new ResourceLocation( modId, "chisel_iron" ), "inventory" ) );
registerMesh( modItems.itemChiselGold, 0, new ModelResourceLocation( new ResourceLocation( modId, "chisel_gold" ), "inventory" ) );
registerMesh( modItems.itemChiselDiamond, 0, new ModelResourceLocation( new ResourceLocation( modId, "chisel_diamond" ), "inventory" ) );
registerMesh( modItems.itemBitBag, 0, new ModelResourceLocation( new ResourceLocation( modId, "bit_bag" ), "inventory" ) );
registerMesh( modItems.itemWrench, 0, new ModelResourceLocation( new ResourceLocation( modId, "wrench_wood" ), "inventory" ) );
registerMesh( modItems.itemBitSawDiamond, 0, new ModelResourceLocation( new ResourceLocation( modId, "bitsaw_diamond" ), "inventory" ) );
registerMesh( modItems.itemTapeMeasure, 0, new ModelResourceLocation( new ResourceLocation( modId, "tape_measure" ), "inventory" ) );
if ( modItems.itemPositiveprint != null )
{
ModelBakery.registerItemVariants( modItems.itemPositiveprint, new ResourceLocation( modId, "positiveprint" ), new ResourceLocation( modId, "positiveprint_written" ) );
ModelLoader.setCustomMeshDefinition( modItems.itemPositiveprint, new ItemMeshDefinition() {
@Override
public ModelResourceLocation getModelLocation(
final ItemStack stack )
{
return new ModelResourceLocation( new ResourceLocation( modId, modItems.itemPositiveprint.isWritten( stack ) ? "positiveprint_written_preview" : "positiveprint" ), "inventory" );
}
} );
}
if ( modItems.itemNegativeprint != null )
{
ModelBakery.registerItemVariants( modItems.itemNegativeprint, new ResourceLocation( modId, "negativeprint" ), new ResourceLocation( modId, "negativeprint_written" ) );
ModelLoader.setCustomMeshDefinition( modItems.itemNegativeprint, new ItemMeshDefinition() {
@Override
public ModelResourceLocation getModelLocation(
final ItemStack stack )
{
return new ModelResourceLocation( new ResourceLocation( modId, modItems.itemNegativeprint.isWritten( stack ) ? "negativeprint_written_preview" : "negativeprint" ), "inventory" );
}
} );
}
if ( modItems.itemMirrorprint != null )
{
ModelBakery.registerItemVariants( modItems.itemMirrorprint, new ResourceLocation( modId, "mirrorprint" ), new ResourceLocation( modId, "mirrorprint_written" ) );
ModelLoader.setCustomMeshDefinition( modItems.itemMirrorprint, new ItemMeshDefinition() {
@Override
public ModelResourceLocation getModelLocation(
final ItemStack stack )
{
return new ModelResourceLocation( new ResourceLocation( modId, modItems.itemMirrorprint.isWritten( stack ) ? "mirrorprint_written_preview" : "mirrorprint" ), "inventory" );
}
} );
}
if ( modItems.itemBlockBit != null )
{
ModelLoader.setCustomMeshDefinition( modItems.itemBlockBit, new ItemMeshDefinition() {
@Override
public ModelResourceLocation getModelLocation(
final ItemStack stack )
{
return new ModelResourceLocation( new ResourceLocation( modId, "block_bit" ), "inventory" );
}
} );
}
for ( final BlockChiseled blk : ChiselsAndBits.getBlocks().getConversions().values() )
{
final Item item = Item.getItemFromBlock( blk );
registerMesh( item, 0, new ModelResourceLocation( new ResourceLocation( modId, "block_chiseled" ), "inventory" ) );
}
final BlockBitTank bitTank = ChiselsAndBits.getBlocks().blockBitTank;
final Item bitTankItem = Item.getItemFromBlock( bitTank );
final ModelResourceLocation bittank_item = new ModelResourceLocation( new ResourceLocation( modId, "bittank" ), "inventory" );
registerMesh( bitTankItem, 0, bittank_item );
}
private void registerMesh(
final Item item,
final int meta,
final ModelResourceLocation loctaion )
{
if ( item != null )
{
ModelLoader.setCustomModelResourceLocation( item, meta, loctaion );
}
}
public static TextureAtlasSprite undoIcon;
public static TextureAtlasSprite redoIcon;
public static TextureAtlasSprite trashIcon;
public static TextureAtlasSprite swapIcon;
public static TextureAtlasSprite placeIcon;
@SubscribeEvent
void registerIconTextures(
final TextureStitchEvent.Pre ev )
{
final TextureMap map = ev.getMap();
swapIcon = map.registerSprite( new ResourceLocation( "chiselsandbits", "icons/swap" ) );
placeIcon = map.registerSprite( new ResourceLocation( "chiselsandbits", "icons/place" ) );
undoIcon = map.registerSprite( new ResourceLocation( "chiselsandbits", "icons/undo" ) );
redoIcon = map.registerSprite( new ResourceLocation( "chiselsandbits", "icons/redo" ) );
trashIcon = map.registerSprite( new ResourceLocation( "chiselsandbits", "icons/trash" ) );
for ( final ChiselMode mode : ChiselMode.values() )
{
loadIcon( map, mode );
}
for ( final PositivePatternMode mode : PositivePatternMode.values() )
{
loadIcon( map, mode );
}
for ( final TapeMeasureModes mode : TapeMeasureModes.values() )
{
loadIcon( map, mode );
}
}
void loadIcon(
final TextureMap map,
final IToolMode mode )
{
final SpriteIconPositioning sip = new SpriteIconPositioning();
final ResourceLocation sprite = new ResourceLocation( "chiselsandbits", "icons/" + mode.name().toLowerCase() );
final ResourceLocation png = new ResourceLocation( "chiselsandbits", "textures/icons/" + mode.name().toLowerCase() + ".png" );
sip.sprite = map.registerSprite( sprite );
try
{
final IResource iresource = Minecraft.getMinecraft().getResourceManager().getResource( png );
final BufferedImage bi = TextureUtil.readBufferedImage( iresource.getInputStream() );
int bottom = 0;
int right = 0;
sip.left = bi.getWidth();
sip.top = bi.getHeight();
for ( int x = 0; x < bi.getWidth(); x++ )
{
for ( int y = 0; y < bi.getHeight(); y++ )
{
final int color = bi.getRGB( x, y );
final int a = color >> 24 & 0xff;
if ( a > 0 )
{
sip.left = Math.min( sip.left, x );
right = Math.max( right, x );
sip.top = Math.min( sip.top, y );
bottom = Math.max( bottom, y );
}
}
}
sip.height = bottom - sip.top + 1;
sip.width = right - sip.left + 1;
sip.left /= bi.getWidth();
sip.width /= bi.getWidth();
sip.top /= bi.getHeight();
sip.height /= bi.getHeight();
}
catch ( final IOException e )
{
sip.height = 1;
sip.width = 1;
sip.left = 0;
sip.top = 0;
}
chiselModeIcons.put( mode, sip );
}
public SpriteIconPositioning getIconForMode(
final IToolMode mode )
{
return chiselModeIcons.get( mode );
}
@SubscribeEvent
public void onRenderGUI(
final RenderGameOverlayEvent.Post event )
{
final ChiselToolType tool = getHeldToolType( lastHand );
final ElementType type = event.getType();
if ( type == ElementType.ALL && tool != null && tool.hasMenu() )
{
final boolean wasVisible = ChiselsAndBitsMenu.instance.isVisible();
if ( modeMenu.isKeyDown() )
{
ChiselsAndBitsMenu.instance.actionUsed = false;
ChiselsAndBitsMenu.instance.raiseVisibility();
}
else
{
if ( !ChiselsAndBitsMenu.instance.actionUsed )
{
if ( ChiselsAndBitsMenu.instance.switchTo != null )
{
ClientSide.instance.playRadialMenu();
ChiselModeManager.changeChiselMode( tool, ChiselModeManager.getChiselMode( getPlayer(), tool, EnumHand.MAIN_HAND ), ChiselsAndBitsMenu.instance.switchTo );
}
if ( ChiselsAndBitsMenu.instance.doAction != null )
{
ClientSide.instance.playRadialMenu();
switch ( ChiselsAndBitsMenu.instance.doAction )
{
case REPLACE_TOGGLE:
ChiselsAndBits.getConfig().replaceingBits = !ChiselsAndBits.getConfig().replaceingBits;
ReflectionWrapper.instance.clearHighlightedStack();
break;
case UNDO:
UndoTracker.getInstance().undo();
break;
case REDO:
UndoTracker.getInstance().redo();
break;
case BLACK:
case BLUE:
case BROWN:
case CYAN:
case GRAY:
case GREEN:
case LIGHT_BLUE:
case LIME:
case MAGENTA:
case ORANGE:
case PINK:
case PURPLE:
case RED:
case SILVER:
case WHITE:
case YELLOW:
final PacketSetColor setColor = new PacketSetColor();
setColor.type = getHeldToolType( EnumHand.MAIN_HAND );
setColor.newColor = EnumDyeColor.valueOf( ChiselsAndBitsMenu.instance.doAction.name() );
setColor.chatNotification = ChiselsAndBits.getConfig().chatModeNotification;
NetworkRouter.instance.sendToServer( setColor );
ReflectionWrapper.instance.clearHighlightedStack();
break;
}
}
}
ChiselsAndBitsMenu.instance.actionUsed = true;
ChiselsAndBitsMenu.instance.decreaseVisibility();
}
if ( ChiselsAndBitsMenu.instance.isVisible() )
{
final ScaledResolution res = event.getResolution();
ChiselsAndBitsMenu.instance.configure( res.getScaledWidth(), res.getScaledHeight() );
if ( wasVisible == false )
{
ChiselsAndBitsMenu.instance.mc.inGameHasFocus = false;
ChiselsAndBitsMenu.instance.mc.mouseHelper.ungrabMouseCursor();
}
if ( ChiselsAndBitsMenu.instance.mc.inGameHasFocus )
{
KeyBinding.unPressAllKeys();
}
final int k1 = Mouse.getX() * res.getScaledWidth() / ChiselsAndBitsMenu.instance.mc.displayWidth;
final int l1 = res.getScaledHeight() - Mouse.getY() * res.getScaledHeight() / ChiselsAndBitsMenu.instance.mc.displayHeight - 1;
net.minecraftforge.client.ForgeHooksClient.drawScreen( ChiselsAndBitsMenu.instance, k1, l1, event.getPartialTicks() );
}
else
{
if ( wasVisible )
{
ChiselsAndBitsMenu.instance.mc.setIngameFocus();
}
}
}
if ( undo.isPressed() )
{
UndoTracker.getInstance().undo();
}
if ( redo.isPressed() )
{
UndoTracker.getInstance().redo();
}
if ( addToClipboard.isPressed() )
{
final Minecraft mc = Minecraft.getMinecraft();
if ( mc.objectMouseOver != null && mc.objectMouseOver.typeOfHit == RayTraceResult.Type.BLOCK )
{
try
{
final IBitAccess access = ChiselsAndBits.getApi().getBitAccess( mc.theWorld, mc.objectMouseOver.getBlockPos() );
final ItemStack is = access.getBitsAsItem( null, ItemType.CHISLED_BLOCK, false );
CreativeClipboardTab.addItem( is );
}
catch ( final CannotBeChiseled e )
{
// nope.
}
}
}
if ( pickBit.isPressed() )
{
final Minecraft mc = Minecraft.getMinecraft();
if ( mc.objectMouseOver != null && mc.objectMouseOver.typeOfHit == RayTraceResult.Type.BLOCK )
{
try
{
final BitLocation bl = new BitLocation( mc.objectMouseOver, true, BitOperation.CHISEL );
final IBitAccess access = ChiselsAndBits.getApi().getBitAccess( mc.theWorld, bl.getBlockPos() );
final IBitBrush brush = access.getBitAt( bl.getBitX(), bl.getBitY(), bl.getBitZ() );
if ( brush != null )
{
final ItemStack is = brush.getItemStack( 1 );
if ( is != null )
{
doPick( is );
}
}
}
catch ( final CannotBeChiseled e )
{
// nope.
}
}
}
if ( type == ElementType.HOTBAR && ChiselsAndBits.getConfig().enableToolbarIcons )
{
final Minecraft mc = Minecraft.getMinecraft();
final ScaledResolution res = event.getResolution();
if ( !mc.thePlayer.isSpectator() )
{
final GuiIngame sc = mc.ingameGUI;
for ( int slot = 0; slot < 9; ++slot )
{
final ItemStack stack = mc.thePlayer.inventory.mainInventory.get( slot );
if ( stack != null && stack.getItem() instanceof ItemChisel )
{
final ChiselToolType toolType = getToolTypeForItemm( stack );
IToolMode mode = toolType.getMode( stack );
if ( !ChiselsAndBits.getConfig().perChiselMode && tool == ChiselToolType.CHISEL )
{
mode = ChiselModeManager.getChiselMode( mc.thePlayer, ChiselToolType.CHISEL, lastHand );
}
final int x = res.getScaledWidth() / 2 - 90 + slot * 20 + 2;
final int y = res.getScaledHeight() - 16 - 3;
GlStateManager.color( 1, 1, 1, 1.0f );
Minecraft.getMinecraft().getTextureManager().bindTexture( TextureMap.LOCATION_BLOCKS_TEXTURE );
final TextureAtlasSprite sprite = chiselModeIcons.get( mode ) == null ? getMissingIcon() : chiselModeIcons.get( mode ).sprite;
GlStateManager.enableBlend();
sc.drawTexturedModalRect( x + 1, y + 1, sprite, 8, 8 );
GlStateManager.disableBlend();
}
}
}
}
}
public void playRadialMenu()
{
final float volume = ChiselsAndBits.getConfig().radialMenuVolume;
if ( volume >= 0.0001f )
{
final PositionedSoundRecord psr = new PositionedSoundRecord( SoundEvents.UI_BUTTON_CLICK, SoundCategory.MASTER, volume, 1.0f, getPlayer().getPosition() );
Minecraft.getMinecraft().getSoundHandler().playSound( psr );
}
}
private boolean doPick(
final @Nonnull ItemStack result )
{
final EntityPlayer player = getPlayer();
for ( int x = 0; x < 9; x++ )
{
final ItemStack stack = player.inventory.getStackInSlot( x );
if ( stack != null && stack.isItemEqual( result ) && ItemStack.areItemStackTagsEqual( stack, result ) )
{
player.inventory.currentItem = x;
return true;
}
}
if ( !player.capabilities.isCreativeMode )
{
return false;
}
int slot = player.inventory.getFirstEmptyStack();
if ( slot < 0 || slot >= 9 )
{
slot = player.inventory.currentItem;
}
// update inventory..
player.inventory.setInventorySlotContents( slot, result );
player.inventory.currentItem = slot;
// update server...
final int j = player.inventoryContainer.inventorySlots.size() - 9 + player.inventory.currentItem;
Minecraft.getMinecraft().playerController.sendSlotPacket( player.inventory.getStackInSlot( player.inventory.currentItem ), j );
return true;
}
public ChiselToolType getHeldToolType(
final EnumHand enumHand )
{
final EntityPlayer player = getPlayer();
if ( player == null )
{
return null;
}
final ItemStack is = player.getHeldItem( enumHand );
return getToolTypeForItemm( is );
}
private ChiselToolType getToolTypeForItemm(
final ItemStack is )
{
if ( is != null && is.getItem() instanceof ItemChisel )
{
return ChiselToolType.CHISEL;
}
if ( is != null && is.getItem() instanceof ItemChiseledBit )
{
return ChiselToolType.BIT;
}
if ( is != null && is.getItem() == ChiselsAndBits.getItems().itemTapeMeasure )
{
return ChiselToolType.TAPEMEASURE;
}
if ( is != null && is.getItem() == ChiselsAndBits.getItems().itemPositiveprint )
{
return ChiselToolType.POSITIVEPATTERN;
}
if ( is != null && is.getItem() == ChiselsAndBits.getItems().itemNegativeprint )
{
return ChiselToolType.NEGATIVEPATTERN;
}
if ( is != null && is.getItem() == ChiselsAndBits.getItems().itemMirrorprint )
{
return ChiselToolType.MIRRORPATTERN;
}
return null;
}
@SubscribeEvent
public void drawingInteractionPrevention(
final RightClickBlock pie )
{
if ( pie.getWorld() != null && pie.getWorld().isRemote )
{
final ChiselToolType tool = getHeldToolType( pie.getHand() );
final IToolMode chMode = ChiselModeManager.getChiselMode( getPlayer(), tool, pie.getHand() );
final BitLocation other = getStartPos();
if ( ( chMode == ChiselMode.DRAWN_REGION || tool == ChiselToolType.TAPEMEASURE ) && other != null )
{
// this handles the client side, but the server side will fire
// separately.
pie.setCanceled( true );
}
}
}
@SubscribeEvent
public void interaction(
final TickEvent.ClientTickEvent event )
{
// used to prevent hyper chisels.. its actually far worse then you might
// think...
if ( event.side == Side.CLIENT && event.type == Type.CLIENT && event.phase == Phase.START && !Minecraft.getMinecraft().gameSettings.keyBindAttack.isKeyDown() )
{
ItemChisel.resetDelay();
}
if ( !getToolKey().isKeyDown() )
{
if ( loopDeath )
{
if ( drawStart != null )
{
drawStart = null;
lastHand = EnumHand.MAIN_HAND;
}
lastTool = ChiselToolType.CHISEL;
}
else
{
loopDeath = true;
}
}
else
{
loopDeath = false;
}
if ( rotateCCW.isKeyDown() )
{
if ( rotateTimer == null || rotateTimer.elapsed( TimeUnit.MILLISECONDS ) > 200 )
{
rotateTimer = Stopwatch.createStarted();
final PacketRotateVoxelBlob p = new PacketRotateVoxelBlob();
p.rotationDirection = 1;
NetworkRouter.instance.sendToServer( p );
}
}
if ( rotateCW.isKeyDown() )
{
if ( rotateTimer == null || rotateTimer.elapsed( TimeUnit.MILLISECONDS ) > 200 )
{
rotateTimer = Stopwatch.createStarted();
final PacketRotateVoxelBlob p = new PacketRotateVoxelBlob();
p.rotationDirection = -1;
NetworkRouter.instance.sendToServer( p );
}
}
for ( final ChiselMode mode : ChiselMode.values() )
{
final KeyBinding kb = (KeyBinding) mode.binding;
if ( kb.isKeyDown() )
{
final ChiselToolType tool = getHeldToolType( lastHand );
if ( tool.isBitOrChisel() )
{
ChiselModeManager.changeChiselMode( tool, ChiselModeManager.getChiselMode( getPlayer(), tool, lastHand ), mode );
}
}
}
for ( final PositivePatternMode mode : PositivePatternMode.values() )
{
final KeyBinding kb = (KeyBinding) mode.binding;
if ( kb.isKeyDown() )
{
final ChiselToolType tool = getHeldToolType( lastHand );
if ( tool == ChiselToolType.POSITIVEPATTERN )
{
ChiselModeManager.changeChiselMode( tool, ChiselModeManager.getChiselMode( getPlayer(), tool, lastHand ), mode );
}
}
}
for ( final TapeMeasureModes mode : TapeMeasureModes.values() )
{
final KeyBinding kb = (KeyBinding) mode.binding;
if ( kb.isKeyDown() )
{
final ChiselToolType tool = getHeldToolType( lastHand );
if ( tool == ChiselToolType.TAPEMEASURE )
{
ChiselModeManager.changeChiselMode( tool, ChiselModeManager.getChiselMode( getPlayer(), tool, lastHand ), mode );
}
}
}
}
boolean wasDrawing = false;
@SubscribeEvent
@SideOnly( Side.CLIENT )
public void drawHighlight(
final RenderWorldLastEvent event )
{
ChiselToolType tool = getHeldToolType( lastHand );
final IToolMode chMode = ChiselModeManager.getChiselMode( getPlayer(), tool, lastHand );
if ( chMode == ChiselMode.DRAWN_REGION )
{
tool = lastTool;
}
tapeMeasures.setPreviewMeasure( null, null, chMode, null );
if ( tool != null && tool == ChiselToolType.TAPEMEASURE )
{
final EntityPlayer player = getPlayer();
final RayTraceResult mop = Minecraft.getMinecraft().objectMouseOver;
final World theWorld = player.worldObj;
if ( mop != null && mop.typeOfHit == RayTraceResult.Type.BLOCK )
{
final BitLocation location = new BitLocation( mop, true, BitOperation.CHISEL );
if ( theWorld.getWorldBorder().contains( location.blockPos ) )
{
final BitLocation other = getStartPos();
if ( other != null )
{
tapeMeasures.setPreviewMeasure( other, location, chMode, getPlayer().getHeldItem( lastHand ) );
if ( !getToolKey().isKeyDown() )
{
tapeMeasures.addMeasure( other, location, chMode, getPlayer().getHeldItem( lastHand ) );
drawStart = null;
lastHand = EnumHand.MAIN_HAND;
}
}
}
}
}
tapeMeasures.render( event.getPartialTicks() );
final boolean isDrawing = ( chMode == ChiselMode.DRAWN_REGION || tool == ChiselToolType.TAPEMEASURE ) && getStartPos() != null;
if ( isDrawing != wasDrawing )
{
wasDrawing = isDrawing;
final PacketSuppressInteraction packet = new PacketSuppressInteraction();
packet.newSetting = isDrawing;
NetworkRouter.instance.sendToServer( packet );
}
}
@SubscribeEvent
@SideOnly( Side.CLIENT )
public void drawHighlight(
final DrawBlockHighlightEvent event )
{
ChiselToolType tool = getHeldToolType( lastHand );
final IToolMode chMode = ChiselModeManager.getChiselMode( getPlayer(), tool, lastHand );
if ( chMode == ChiselMode.DRAWN_REGION )
{
tool = lastTool;
}
if ( tool != null && tool.isBitOrChisel() && chMode != null )
{
final EntityPlayer player = event.getPlayer();
final float partialTicks = event.getPartialTicks();
final RayTraceResult mop = Minecraft.getMinecraft().objectMouseOver;
final World theWorld = player.worldObj;
if ( mop == null || mop.typeOfHit != RayTraceResult.Type.BLOCK )
{
return;
}
boolean showBox = false;
if ( mop.typeOfHit == RayTraceResult.Type.BLOCK )
{
final BitLocation location = new BitLocation( mop, true, getLastBitOperation( player, lastHand, getPlayer().getHeldItem( lastHand ) ) );
if ( theWorld.getWorldBorder().contains( location.blockPos ) )
{
// this logic originated in the vanilla bounding box...
final IBlockState state = theWorld.getBlockState( location.blockPos );
final boolean isChisel = getDrawnTool() == ChiselToolType.CHISEL;
final boolean isBit = getHeldToolType( EnumHand.MAIN_HAND ) == ChiselToolType.BIT;
final TileEntityBlockChiseled data = ModUtil.getChiseledTileEntity( theWorld, location.blockPos, false );
final VoxelRegionSrc region = new VoxelRegionSrc( theWorld, location.blockPos, 1 );
final VoxelBlob vb = data != null ? data.getBlob() : new VoxelBlob();
if ( isChisel && data == null )
{
showBox = true;
vb.fill( 1 );
}
final BitLocation other = getStartPos();
if ( chMode == ChiselMode.DRAWN_REGION && other != null )
{
final ChiselIterator oneEnd = ChiselTypeIterator.create( VoxelBlob.dim, location.bitX, location.bitY, location.bitZ, VoxelBlob.NULL_BLOB, ChiselMode.SINGLE, EnumFacing.UP, tool == ChiselToolType.BIT );
final ChiselIterator otherEnd = ChiselTypeIterator.create( VoxelBlob.dim, other.bitX, other.bitY, other.bitZ, VoxelBlob.NULL_BLOB, ChiselMode.SINGLE, EnumFacing.UP, tool == ChiselToolType.BIT );
final AxisAlignedBB a = oneEnd.getBoundingBox( VoxelBlob.NULL_BLOB, false ).offset( location.blockPos.getX(), location.blockPos.getY(), location.blockPos.getZ() );
final AxisAlignedBB b = otherEnd.getBoundingBox( VoxelBlob.NULL_BLOB, false ).offset( other.blockPos.getX(), other.blockPos.getY(), other.blockPos.getZ() );
final AxisAlignedBB bb = a.union( b );
final double maxChiseSize = ChiselsAndBits.getConfig().maxDrawnRegionSize + 0.001;
if ( bb.maxX - bb.minX <= maxChiseSize && bb.maxY - bb.minY <= maxChiseSize && bb.maxZ - bb.minZ <= maxChiseSize )
{
RenderHelper.drawSelectionBoundingBoxIfExists( bb, BlockPos.ORIGIN, player, partialTicks, false );
if ( !getToolKey().isKeyDown() )
{
final PacketChisel pc = new PacketChisel( getLastBitOperation( player, lastHand, player.getHeldItem( lastHand ) ), location, other,
EnumFacing.UP,
ChiselMode.DRAWN_REGION, lastHand );
if ( pc.doAction( getPlayer() ) > 0 )
{
NetworkRouter.instance.sendToServer( pc );
ClientSide.placeSound( theWorld, location.blockPos, 0 );
}
drawStart = null;
lastHand = EnumHand.MAIN_HAND;
lastTool = ChiselToolType.CHISEL;
}
}
}
else
{
final TileEntity te = theWorld.getTileEntity( location.blockPos );
boolean isBitBlock = te instanceof TileEntityBlockChiseled;
final boolean isBlockSupported = BlockBitInfo.supportsBlock( state );
if ( !( isBitBlock || isBlockSupported ) )
{
final TileEntityBlockChiseled tebc = ModUtil.getChiseledTileEntity( theWorld, location.blockPos, false );
if ( tebc != null )
{
final VoxelBlob vx = tebc.getBlob();
if ( vx.get( location.bitX, location.bitY, location.bitZ ) != 0 )
{
isBitBlock = true;
}
}
}
if ( theWorld.isAirBlock( location.blockPos ) || isBitBlock || isBlockSupported )
{
final ChiselIterator i = ChiselTypeIterator.create( VoxelBlob.dim, location.bitX, location.bitY, location.bitZ, region, ChiselMode.castMode( chMode ), mop.sideHit, !isChisel );
final AxisAlignedBB bb = i.getBoundingBox( vb, isChisel );
RenderHelper.drawSelectionBoundingBoxIfExists( bb, location.blockPos, player, partialTicks, false );
showBox = false;
}
else if ( isBit )
{
final VoxelBlob j = new VoxelBlob();