-
Notifications
You must be signed in to change notification settings - Fork 79
/
BlockChiseled.java
1252 lines (1118 loc) · 28.3 KB
/
BlockChiseled.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.chiseledblock;
import java.util.Collections;
import java.util.List;
import mod.chiselsandbits.api.IMultiStateBlock;
import mod.chiselsandbits.chiseledblock.data.BitCollisionIterator;
import mod.chiselsandbits.chiseledblock.data.BitLocation;
import mod.chiselsandbits.chiseledblock.data.VoxelBlob;
import mod.chiselsandbits.chiseledblock.data.VoxelBlobStateReference;
import mod.chiselsandbits.chiseledblock.data.VoxelNeighborRenderTracker;
import mod.chiselsandbits.chiseledblock.properties.UnlistedBlockStateID;
import mod.chiselsandbits.chiseledblock.properties.UnlistedVoxelBlob;
import mod.chiselsandbits.chiseledblock.properties.UnlistedVoxelNeighborState;
import mod.chiselsandbits.client.CreativeClipboardTab;
import mod.chiselsandbits.client.UndoTracker;
import mod.chiselsandbits.core.ChiselsAndBits;
import mod.chiselsandbits.core.ClientSide;
import mod.chiselsandbits.core.Log;
import mod.chiselsandbits.helpers.BitOperation;
import mod.chiselsandbits.helpers.ChiselToolType;
import mod.chiselsandbits.helpers.ExceptionNoTileEntity;
import mod.chiselsandbits.helpers.ModUtil;
import mod.chiselsandbits.items.ItemChiseledBit;
import net.minecraft.block.Block;
import net.minecraft.block.ITileEntityProvider;
import net.minecraft.block.SoundType;
import net.minecraft.block.material.Material;
import net.minecraft.block.properties.IProperty;
import net.minecraft.block.properties.PropertyBool;
import net.minecraft.block.state.BlockStateContainer;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.particle.ParticleManager;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.BlockRenderLayer;
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.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.RayTraceResult;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.Explosion;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.minecraft.world.WorldServer;
import net.minecraftforge.common.property.ExtendedBlockState;
import net.minecraftforge.common.property.IExtendedBlockState;
import net.minecraftforge.common.property.IUnlistedProperty;
import net.minecraftforge.fml.common.FMLCommonHandler;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
public class BlockChiseled extends Block implements ITileEntityProvider, IMultiStateBlock
{
private static final AxisAlignedBB BAD_AABB = new AxisAlignedBB( 0, Double.MIN_NORMAL, 0, 0, Double.MIN_NORMAL, 0 );
private static ThreadLocal<IBlockState> actingAs = new ThreadLocal<IBlockState>();
public static final IUnlistedProperty<VoxelNeighborRenderTracker> UProperty_VoxelNeighborState = new UnlistedVoxelNeighborState();
public static final IUnlistedProperty<VoxelBlobStateReference> UProperty_VoxelBlob = new UnlistedVoxelBlob();
public static final IUnlistedProperty<Integer> UProperty_Primary_BlockState = new UnlistedBlockStateID();
public static final PropertyBool LProperty_FullBlock = PropertyBool.create( "full_block" );
public final String name;
@Override
public Boolean isAABBInsideMaterial(
final World world,
final BlockPos pos,
final AxisAlignedBB bb,
final Material materialIn )
{
try
{
return sharedIsAABBInsideMaterial( getTileEntity( world, pos ), bb, materialIn );
}
catch ( final ExceptionNoTileEntity e )
{
Log.noTileError( e );
return null;
}
}
@Override
public Boolean isEntityInsideMaterial(
final IBlockAccess world,
final BlockPos pos,
final IBlockState iblockstate,
final Entity entity,
final double yToTest,
final Material materialIn,
final boolean testingHead )
{
try
{
return sharedIsEntityInsideMaterial( getTileEntity( world, pos ), pos, entity, yToTest, materialIn, testingHead );
}
catch ( final ExceptionNoTileEntity e )
{
Log.noTileError( e );
return null;
}
}
@Override
public boolean removedByPlayer(
final IBlockState state,
final World world,
final BlockPos pos,
final EntityPlayer player,
final boolean willHarvest )
{
if ( !willHarvest && ChiselsAndBits.getConfig().addBrokenBlocksToCreativeClipboard )
{
try
{
final TileEntityBlockChiseled tebc = getTileEntity( world, pos );
CreativeClipboardTab.addItem( tebc.getItemStack( player ) );
UndoTracker.getInstance().add( world, pos, tebc.getBlobStateReference(), new VoxelBlobStateReference( 0, 0 ) );
}
catch ( final ExceptionNoTileEntity e )
{
Log.noTileError( e );
}
}
return super.removedByPlayer( state, world, pos, player, willHarvest );
}
@Override
public boolean shouldCheckWeakPower(
final IBlockState state,
final IBlockAccess world,
final BlockPos pos,
final EnumFacing side )
{
return isNormalCube( state, world, pos );
}
@Override
public int getLightOpacity(
final IBlockState state,
final IBlockAccess world,
final BlockPos pos )
{
return isNormalCube( state, world, pos ) ? 255 : 0;
}
@Override
public boolean isNormalCube(
final IBlockState state,
final IBlockAccess world,
final BlockPos pos )
{
try
{
return getTileEntity( world, pos ).isNormalCube();
}
catch ( final ExceptionNoTileEntity e )
{
Log.noTileError( e );
return false;
}
}
@Override
public boolean isReplaceable(
final IBlockAccess worldIn,
final BlockPos pos )
{
try
{
return getTileEntity( worldIn, pos ).getBlob().filled() == 0;
}
catch ( final ExceptionNoTileEntity e )
{
Log.noTileError( e );
return super.isReplaceable( worldIn, pos );
}
}
@Override
public boolean doesSideBlockRendering(
final IBlockState state,
final IBlockAccess world,
final BlockPos pos,
final EnumFacing face )
{
try
{
return getTileEntity( world, pos ).isSideOpaque( face );
}
catch ( final ExceptionNoTileEntity e )
{
Log.noTileError( e );
return false;
}
}
public BlockChiseled(
final Material mat,
final String BlockName )
{
super( new SubMaterial( mat ) );
configureSound( mat );
// slippery ice...
if ( mat == Material.ICE || mat == Material.PACKED_ICE )
{
slipperiness = 0.98F;
}
setLightOpacity( 0 );
setHardness( 1 );
setHarvestLevel( "pickaxe", 0 );
name = BlockName;
setDefaultState( getDefaultState().withProperty( LProperty_FullBlock, false ) );
}
private void configureSound(
final Material mat )
{
if ( mat == Material.WOOD )
{
setSoundType( SoundType.WOOD );
}
else if ( mat == Material.ROCK )
{
setSoundType( SoundType.STONE );
}
else if ( mat == Material.IRON )
{
setSoundType( SoundType.METAL );
}
else if ( mat == Material.CLOTH )
{
setSoundType( SoundType.CLOTH );
}
else if ( mat == Material.ICE )
{
setSoundType( SoundType.GLASS );
}
else if ( mat == Material.PACKED_ICE )
{
setSoundType( SoundType.GLASS );
}
else if ( mat == Material.CLAY )
{
setSoundType( SoundType.GROUND );
}
else if ( mat == Material.GLASS )
{
setSoundType( SoundType.GLASS );
}
}
@Override
public int getMetaFromState(
IBlockState state )
{
return state.getValue( LProperty_FullBlock ) ? 1 : 0;
}
@Override
public IBlockState getStateFromMeta(
int meta )
{
return getDefaultState().withProperty( LProperty_FullBlock, meta == 1 );
}
@Override
public boolean canRenderInLayer(
final BlockRenderLayer layer )
{
return true;
}
static ExceptionNoTileEntity noTileEntity = new ExceptionNoTileEntity();
public static TileEntityBlockChiseled getTileEntity(
final TileEntity te ) throws ExceptionNoTileEntity
{
if ( te == null )
{
throw noTileEntity;
}
try
{
return (TileEntityBlockChiseled) te;
}
catch ( final ClassCastException e )
{
throw noTileEntity;
}
}
public static TileEntityBlockChiseled getTileEntity(
final IBlockAccess world,
final BlockPos pos ) throws ExceptionNoTileEntity
{
return getTileEntity( ModUtil.getTileEntitySafely( world, pos ) );
}
@Override
public float getAmbientOcclusionLightValue(
final IBlockState state )
{
return 1.0f;
}
@Override
public boolean isOpaqueCube(
final IBlockState state )
{
return state.getValue( LProperty_FullBlock );
}
@Override
public boolean isFullCube(
final IBlockState state )
{
return state.getValue( LProperty_FullBlock );
}
@Override
public IBlockState getExtendedState(
final IBlockState state,
final IBlockAccess world,
final BlockPos pos )
{
try
{
return getTileEntity( world, pos ).getRenderState( world );
}
catch ( final ExceptionNoTileEntity e )
{
Log.noTileError( e );
return state;
}
catch ( final Throwable err )
{
Log.logError( "Unable to get extended state...", err );
return state;
}
}
@Override
public void dropBlockAsItemWithChance(
final World worldIn,
final BlockPos pos,
final IBlockState state,
final float chance,
final int fortune )
{
try
{
spawnItemEntity( worldIn, pos, getTileEntity( worldIn, pos ).getItemStack( null ) );
}
catch ( final ExceptionNoTileEntity e )
{
Log.noTileError( e );
}
}
@Override
public void harvestBlock(
final World worldIn,
final EntityPlayer player,
final BlockPos pos,
final IBlockState state,
final TileEntity te,
final ItemStack stack )
{
try
{
spawnItemEntity( worldIn, pos, getTileEntity( te ).getItemStack( player ) );
}
catch ( final ExceptionNoTileEntity e )
{
Log.noTileError( e );
super.harvestBlock( worldIn, player, pos, state, (TileEntity) null, stack );
}
}
private void spawnItemEntity(
World worldIn,
BlockPos pos,
ItemStack itemStack )
{
if ( itemStack != null )
{
spawnAsEntity( worldIn, pos, itemStack );
}
}
@Override
public List<ItemStack> getDrops(
final IBlockAccess world,
final BlockPos pos,
final IBlockState state,
final int fortune )
{
try
{
return Collections.singletonList( getTileEntity( world, pos ).getItemStack( null ) );
}
catch ( final ExceptionNoTileEntity e )
{
Log.noTileError( e );
return Collections.emptyList();
}
}
@Override
public void onBlockPlacedBy(
final World worldIn,
final BlockPos pos,
final IBlockState state,
final EntityLivingBase placer,
final ItemStack stack )
{
try
{
if ( stack == null || placer == null || !stack.hasTagCompound() )
{
return;
}
final TileEntityBlockChiseled bc = getTileEntity( worldIn, pos );
int rotations = ModUtil.getRotations( placer, ModUtil.getSide( stack ) );
VoxelBlob blob = bc.getBlob();
while ( rotations-- > 0 )
{
blob = blob.spin( Axis.Y );
}
bc.setBlob( blob );
}
catch ( final ExceptionNoTileEntity e )
{
Log.noTileError( e );
}
}
@Override
public ItemStack getPickBlock(
final IBlockState state,
final RayTraceResult target,
final World world,
final BlockPos pos,
final EntityPlayer player )
{
try
{
return getPickBlock( target, pos, getTileEntity( world, pos ) );
}
catch ( final ExceptionNoTileEntity e )
{
Log.noTileError( e );
return null;
}
}
/**
* Client side method.
*/
private ChiselToolType getClientHeldTool()
{
return ClientSide.instance.getHeldToolType( EnumHand.MAIN_HAND );
}
public ItemStack getPickBlock(
final RayTraceResult target,
final BlockPos pos,
final TileEntityBlockChiseled te )
{
if ( te.getWorld() != null && te.getWorld().isRemote )
{
if ( getClientHeldTool() != null )
{
final VoxelBlob vb = te.getBlob();
final BitLocation bitLoc = new BitLocation( target, true, BitOperation.CHISEL );
final int itemBlock = vb.get( bitLoc.bitX, bitLoc.bitY, bitLoc.bitZ );
if ( itemBlock == 0 )
{
return null;
}
return ItemChiseledBit.createStack( itemBlock, 1, false );
}
return te.getItemStack( ClientSide.instance.getPlayer() );
}
return te.getItemStack( null );
}
@Override
protected BlockStateContainer createBlockState()
{
return new ExtendedBlockState( this, new IProperty[] { LProperty_FullBlock }, new IUnlistedProperty[] { UProperty_VoxelBlob, UProperty_Primary_BlockState, UProperty_VoxelNeighborState } );
}
@Override
public TileEntity createNewTileEntity(
final World worldIn,
final int meta )
{
return new TileEntityBlockChiseled();
}
@Override
public void breakBlock(
final World worldIn,
final BlockPos pos,
final IBlockState state )
{
try
{
final TileEntityBlockChiseled tebc = getTileEntity( worldIn, pos );
tebc.setNormalCube( false );
worldIn.checkLight( pos );
}
catch ( final ExceptionNoTileEntity e )
{
}
finally
{
super.breakBlock( worldIn, pos, state );
}
}
@Override
public boolean addLandingEffects(
final IBlockState state,
final WorldServer worldObj,
final BlockPos blockPosition,
final IBlockState iblockstate,
final EntityLivingBase entity,
final int numberOfParticles )
{
try
{
final IBlockState texture = getTileEntity( worldObj, blockPosition ).getBlockState( Blocks.STONE );
worldObj.spawnParticle( EnumParticleTypes.BLOCK_DUST, entity.posX, entity.posY, entity.posZ, numberOfParticles, 0.0D, 0.0D, 0.0D, 0.15000000596046448D, new int[] { ModUtil.getStateId( texture ) } );
return true;
}
catch ( final ExceptionNoTileEntity e )
{
Log.noTileError( e );
return false;
}
}
@Override
@SideOnly( Side.CLIENT )
public boolean addDestroyEffects(
final World world,
final BlockPos pos,
final ParticleManager effectRenderer )
{
try
{
final IBlockState state = getTileEntity( world, pos ).getBlockState( this );
return ClientSide.instance.addBlockDestroyEffects( world, pos, state, effectRenderer );
}
catch ( final ExceptionNoTileEntity e )
{
Log.noTileError( e );
}
return true;
}
@Override
@SideOnly( Side.CLIENT )
public boolean addHitEffects(
final IBlockState state,
final World world,
final RayTraceResult target,
final ParticleManager effectRenderer )
{
try
{
final BlockPos pos = target.getBlockPos();
final IBlockState bs = getTileEntity( world, pos ).getBlockState( this );
return ClientSide.instance.addHitEffects( world, target, bs, effectRenderer );
}
catch ( final ExceptionNoTileEntity e )
{
Log.noTileError( e );
return true;
}
}
@Override
public AxisAlignedBB getCollisionBoundingBox(
final IBlockState state,
final World worldIn,
final BlockPos pos )
{
AxisAlignedBB r = null;
try
{
for ( final AxisAlignedBB bb : getTileEntity( worldIn, pos ).getBoxes( BoxType.COLLISION ) )
{
if ( r == null )
{
r = bb;
}
else
{
r = r.union( bb );
}
}
}
catch ( final ExceptionNoTileEntity e )
{
Log.noTileError( e );
}
if ( r == null )
{
return BAD_AABB;
}
return r.offset( pos.getX(), pos.getY(), pos.getZ() );
}
@Override
public void addCollisionBoxToList(
final IBlockState state,
final World worldIn,
final BlockPos pos,
final AxisAlignedBB mask,
final List<AxisAlignedBB> list,
final Entity collidingEntity )
{
try
{
addCollisionBoxesToList( getTileEntity( worldIn, pos ), pos, mask, list, collidingEntity );
}
catch ( final ExceptionNoTileEntity e )
{
Log.noTileError( e );
}
}
public void addCollisionBoxesToList(
final TileEntityBlockChiseled te,
final BlockPos pos,
final AxisAlignedBB mask,
final List<AxisAlignedBB> list,
final Entity collidingEntity )
{
final AxisAlignedBB localMask = mask.offset( -pos.getX(), -pos.getY(), -pos.getZ() );
for ( final AxisAlignedBB bb : te.getBoxes( BoxType.COLLISION ) )
{
if ( bb.intersectsWith( localMask ) )
{
list.add( bb.offset( pos.getX(), pos.getY(), pos.getZ() ) );
}
}
}
/**
* this method dosn't use AxisAlignedBB internally to prevent GC thrashing.
*
* @param worldIn
* @param pos
*
* mask and list should be null if not looking for collisions
*
* @return if the method results in a non-full cube box.
*/
private AxisAlignedBB setBounds(
final TileEntityBlockChiseled tec,
final BlockPos pos,
final AxisAlignedBB mask,
final List<AxisAlignedBB> list,
final boolean includePosition )
{
boolean started = false;
float minX = 0.0f;
float minY = 0.0f;
float minZ = 0.0f;
float maxX = 1.0f;
float maxY = 1.0f;
float maxZ = 1.0f;
final VoxelBlob vb = tec.getBlob();
final BitCollisionIterator bi = new BitCollisionIterator();
while ( bi.hasNext() )
{
if ( bi.getNext( vb ) != 0 )
{
if ( started )
{
minX = Math.min( minX, bi.physicalX );
minY = Math.min( minY, bi.physicalY );
minZ = Math.min( minZ, bi.physicalZ );
maxX = Math.max( maxX, bi.physicalX + BitCollisionIterator.One16thf );
maxY = Math.max( maxY, bi.physicalYp1 );
maxZ = Math.max( maxZ, bi.physicalZp1 );
}
else
{
started = true;
minX = bi.physicalX;
minY = bi.physicalY;
minZ = bi.physicalZ;
maxX = bi.physicalX + BitCollisionIterator.One16thf;
maxY = bi.physicalYp1;
maxZ = bi.physicalZp1;
}
}
// VERY hackey collision extraction to do 2 bounding boxes, one
// for top and one for the bottom.
if ( list != null && started && ( bi.y == 8 || bi.y == VoxelBlob.dim_minus_one ) )
{
final AxisAlignedBB bb = new AxisAlignedBB(
(double) minX + pos.getX(),
(double) minY + pos.getY(),
(double) minZ + pos.getZ(),
(double) maxX + pos.getX(),
(double) maxY + pos.getY(),
(double) maxZ + pos.getZ() );
if ( mask.intersectsWith( bb ) )
{
list.add( bb );
}
started = false;
minX = 0.0f;
minY = 0.0f;
minZ = 0.0f;
maxX = 1.0f;
maxY = 1.0f;
maxZ = 1.0f;
}
}
if ( includePosition )
{
return new AxisAlignedBB(
(double) minX + pos.getX(),
(double) minY + pos.getY(),
(double) minZ + pos.getZ(),
(double) maxX + pos.getX(),
(double) maxY + pos.getY(),
(double) maxZ + pos.getZ() );
}
return new AxisAlignedBB(
minX,
minY,
minZ,
maxX,
maxY,
maxZ );
}
@Override
@Deprecated
public AxisAlignedBB getSelectedBoundingBox(
final IBlockState state,
final World worldIn,
final BlockPos pos )
{
try
{
return getSelectedBoundingBox( getTileEntity( worldIn, pos ), pos );
}
catch ( final ExceptionNoTileEntity e )
{
Log.noTileError( e );
}
return super.getSelectedBoundingBox( state, worldIn, pos );
}
public AxisAlignedBB getSelectedBoundingBox(
final TileEntityBlockChiseled tec,
final BlockPos pos )
{
return setBounds( tec, pos, null, null, true );
}
@Override
@Deprecated
public RayTraceResult collisionRayTrace(
final IBlockState blockState,
final World worldIn,
final BlockPos pos,
final Vec3d a,
final Vec3d b )
{
try
{
return collisionRayTrace( getTileEntity( worldIn, pos ), pos, a, b, worldIn.isRemote );
}
catch ( final ExceptionNoTileEntity e )
{
Log.noTileError( e );
}
return super.collisionRayTrace( blockState, worldIn, pos, a, b );
}
public RayTraceResult collisionRayTrace(
final TileEntityBlockChiseled tec,
final BlockPos pos,
final Vec3d a,
final Vec3d b,
final boolean realTest )
{
RayTraceResult br = null;
double lastDist = 0;
boolean occlusion = true;
if ( FMLCommonHandler.instance().getEffectiveSide().isClient() && tec.getWorld() != null && tec.getWorld().isRemote )
{
occlusion = !ChiselsAndBits.getConfig().fluidBitsAreClickThrough || ClientSide.instance.getHeldToolType( EnumHand.MAIN_HAND ) != null;
}
for ( final AxisAlignedBB box : tec.getBoxes( occlusion ? BoxType.OCCLUSION : BoxType.COLLISION ) )
{
final RayTraceResult r = rayTrace( pos, a, b, box );
if ( r != null )
{
final double xLen = a.xCoord - r.hitVec.xCoord;
final double yLen = a.yCoord - r.hitVec.yCoord;
final double zLen = a.zCoord - r.hitVec.zCoord;
final double thisDist = xLen * xLen + yLen * yLen + zLen * zLen;
if ( br == null || lastDist > thisDist && r != null )
{
lastDist = thisDist;
br = r;
}
}
}
return br;
}
@Override
@Deprecated
public float getBlockHardness(
final IBlockState state,
final World worldIn,
final BlockPos pos )
{
try
{
return getTileEntity( worldIn, pos ).getBlockInfo( this ).hardness;
}
catch ( final ExceptionNoTileEntity e )
{
Log.noTileError( e );
return super.getBlockHardness( state, worldIn, pos );
}
}
@Override
public float getExplosionResistance(
final World world,
final BlockPos pos,
final Entity exploder,
final Explosion explosion )
{
try
{
return getTileEntity( world, pos ).getBlockInfo( this ).explosionResistance;
}
catch ( final ExceptionNoTileEntity e )
{
Log.noTileError( e );
return super.getExplosionResistance( world, pos, exploder, explosion );
}
}
public static boolean replaceWithChisled(
final World world,
final BlockPos pos,
final IBlockState originalState,
final boolean triggerUpdate )
{
return replaceWithChisled( world, pos, originalState, 0, triggerUpdate );
}
@Override
public boolean canPlaceTorchOnTop(
final IBlockState state,
final IBlockAccess world,
final BlockPos pos )
{
return isSideSolid( state, world, pos, EnumFacing.UP );
}
@Override
public boolean isSideSolid(
final IBlockState base_state,
final IBlockAccess world,
final BlockPos pos,
final EnumFacing side )
{
try
{
return getTileEntity( world, pos ).isSideSolid( side );
}
catch ( final ExceptionNoTileEntity e )
{
Log.noTileError( e );
return false;
}
}
@Override
public boolean rotateBlock(
final World world,
final BlockPos pos,
final EnumFacing axis )
{
try
{
getTileEntity( world, pos ).rotateBlock( axis );
return true;
}
catch ( final ExceptionNoTileEntity e )
{
Log.noTileError( e );
return false;
}
}
public static boolean replaceWithChisled(
final World world,
final BlockPos pos,
final IBlockState originalState,
final int fragmentBlockStateID,
final boolean triggerUpdate )
{
IBlockState actingState = originalState;
Block target = originalState.getBlock();
final boolean isAir = world.isAirBlock( pos ) || actingState.getBlock().isReplaceable( world, pos );
if ( BlockBitInfo.supportsBlock( actingState ) || isAir )
{
BlockChiseled blk = ChiselsAndBits.getBlocks().getConversion( originalState );
int BlockID = ModUtil.getStateId( actingState );
if ( isAir )
{
actingState = ModUtil.getStateById( fragmentBlockStateID );
target = actingState.getBlock();
BlockID = ModUtil.getStateId( actingState );
blk = ChiselsAndBits.getBlocks().getConversion( actingState );
// its still air tho..
actingState = Blocks.AIR.getDefaultState();
}
if ( BlockID == 0 )
{
return false;
}
if ( blk != null && blk != target )
{
world.setBlockState( pos, blk.getDefaultState(), triggerUpdate ? 3 : 0 );