-
Notifications
You must be signed in to change notification settings - Fork 4
/
Block.java
1369 lines (1169 loc) · 62 KB
/
Block.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 net.minecraft.block;
import java.util.Iterator;
import java.util.List;
import java.util.Random;
import com.comze_instancelabs.client.InstanceMain;
import net.minecraft.block.material.MapColor;
import net.minecraft.block.material.Material;
import net.minecraft.block.properties.IProperty;
import net.minecraft.block.state.BlockState;
import net.minecraft.block.state.IBlockState;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.enchantment.EnchantmentHelper;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.item.EntityXPOrb;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemStack;
import net.minecraft.stats.StatList;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.util.BlockPos;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumWorldBlockLayer;
import net.minecraft.util.MovingObjectPosition;
import net.minecraft.util.ObjectIntIdentityMap;
import net.minecraft.util.RegistryNamespacedDefaultedByKey;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.StatCollector;
import net.minecraft.util.Vec3;
import net.minecraft.world.Explosion;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
public class Block {
/** ResourceLocation for the Air block */
private static final ResourceLocation AIR_ID = new ResourceLocation("air");
public static final RegistryNamespacedDefaultedByKey blockRegistry = new RegistryNamespacedDefaultedByKey(AIR_ID);
public static final ObjectIntIdentityMap BLOCK_STATE_IDS = new ObjectIntIdentityMap();
private CreativeTabs displayOnCreativeTab;
public static final Block.SoundType soundTypeStone = new Block.SoundType("stone", 1.0F, 1.0F);
/** the wood sound type */
public static final Block.SoundType soundTypeWood = new Block.SoundType("wood", 1.0F, 1.0F);
/** the gravel sound type */
public static final Block.SoundType soundTypeGravel = new Block.SoundType("gravel", 1.0F, 1.0F);
public static final Block.SoundType soundTypeGrass = new Block.SoundType("grass", 1.0F, 1.0F);
public static final Block.SoundType soundTypePiston = new Block.SoundType("stone", 1.0F, 1.0F);
public static final Block.SoundType soundTypeMetal = new Block.SoundType("stone", 1.0F, 1.5F);
public static final Block.SoundType soundTypeGlass = new Block.SoundType("stone", 1.0F, 1.0F) {
private static final String __OBFID = "CL_00000200";
public String getBreakSound() {
return "dig.glass";
}
public String getPlaceSound() {
return "step.stone";
}
};
public static final Block.SoundType soundTypeCloth = new Block.SoundType("cloth", 1.0F, 1.0F);
public static final Block.SoundType soundTypeSand = new Block.SoundType("sand", 1.0F, 1.0F);
public static final Block.SoundType soundTypeSnow = new Block.SoundType("snow", 1.0F, 1.0F);
public static final Block.SoundType soundTypeLadder = new Block.SoundType("ladder", 1.0F, 1.0F) {
private static final String __OBFID = "CL_00000201";
public String getBreakSound() {
return "dig.wood";
}
};
public static final Block.SoundType soundTypeAnvil = new Block.SoundType("anvil", 0.3F, 1.0F) {
private static final String __OBFID = "CL_00000202";
public String getBreakSound() {
return "dig.stone";
}
public String getPlaceSound() {
return "random.anvil_land";
}
};
public static final Block.SoundType SLIME_SOUND = new Block.SoundType("slime", 1.0F, 1.0F) {
private static final String __OBFID = "CL_00002133";
public String getBreakSound() {
return "mob.slime.big";
}
public String getPlaceSound() {
return "mob.slime.big";
}
public String getStepSound() {
return "mob.slime.small";
}
};
protected boolean fullBlock;
/** How much light is subtracted for going through this block */
protected int lightOpacity;
protected boolean translucent;
/** Amount of light emitted */
protected int lightValue;
/**
* Flag if block should use the brightest neighbor light value as its own
*/
protected boolean useNeighborBrightness;
/** Indicates how many hits it takes to break a block. */
protected float blockHardness;
protected float blockResistance;
protected boolean enableStats = true;
/**
* Flags whether or not this block is of a type that needs random ticking. Ref-counted by
* ExtendedBlockStorage in order to broadly cull a chunk from the random chunk update list for
* efficiency's sake.
*/
protected boolean needsRandomTick;
/** true if the Block contains a Tile Entity */
protected boolean isBlockContainer;
protected double minX;
protected double minY;
protected double minZ;
protected double maxX;
protected double maxY;
protected double maxZ;
/** Sound of stepping on the block */
public Block.SoundType stepSound;
public float blockParticleGravity;
protected final Material blockMaterial;
/**
* Determines how much velocity is maintained while moving on top of this block
*/
public float slipperiness;
protected final BlockState blockState;
private IBlockState defaultBlockState;
private String unlocalizedName;
private static final String __OBFID = "CL_00000199";
public static int getIdFromBlock(Block blockIn) {
return blockRegistry.getIDForObject(blockIn);
}
/**
* Get a unique ID for the given BlockState, containing both BlockID and metadata
*/
public static int getStateId(IBlockState state) {
return getIdFromBlock(state.getBlock()) + (state.getBlock().getMetaFromState(state) << 12);
}
public static Block getBlockById(int id) {
return (Block) blockRegistry.getObjectById(id);
}
/**
* Get a BlockState by it's ID (see getStateId)
*/
public static IBlockState getStateById(int id) {
int var1 = id & 4095;
int var2 = id >> 12 & 15;
return getBlockById(var1).getStateFromMeta(var2);
}
public static Block getBlockFromItem(Item itemIn) {
return itemIn instanceof ItemBlock ? ((ItemBlock) itemIn).getBlock() : null;
}
public static Block getBlockFromName(String name) {
ResourceLocation var1 = new ResourceLocation(name);
if (blockRegistry.containsKey(var1)) {
return (Block) blockRegistry.getObject(var1);
} else {
try {
return (Block) blockRegistry.getObjectById(Integer.parseInt(name));
} catch (NumberFormatException var3) {
return null;
}
}
}
public boolean isFullBlock() {
return this.fullBlock;
}
public int getLightOpacity() {
return this.lightOpacity;
}
public boolean isTranslucent() {
return this.translucent;
}
public int getLightValue() {
return this.lightValue;
}
/**
* Should block use the brightest neighbor light value as its own
*/
public boolean getUseNeighborBrightness() {
return this.useNeighborBrightness;
}
/**
* Get a material of block
*/
public Material getMaterial() {
return this.blockMaterial;
}
/**
* Get the MapColor for this Block and the given BlockState
*/
public MapColor getMapColor(IBlockState state) {
return this.getMaterial().getMaterialMapColor();
}
/**
* Convert the given metadata into a BlockState for this Block
*/
public IBlockState getStateFromMeta(int meta) {
return this.getDefaultState();
}
/**
* Convert the BlockState into the correct metadata value
*/
public int getMetaFromState(IBlockState state) {
if (state != null && !state.getPropertyNames().isEmpty()) {
throw new IllegalArgumentException("Don\'t know how to convert " + state + " back into data...");
} else {
return 0;
}
}
/**
* Get the actual Block state of this Block at the given position. This applies properties not
* visible in the metadata, such as fence connections.
*/
public IBlockState getActualState(IBlockState state, IBlockAccess worldIn, BlockPos pos) {
return state;
}
protected Block(Material materialIn) {
this.stepSound = soundTypeStone;
this.blockParticleGravity = 1.0F;
this.slipperiness = 0.6F;
this.blockMaterial = materialIn;
this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F);
this.fullBlock = this.isOpaqueCube();
this.lightOpacity = this.isOpaqueCube() ? 255 : 0;
this.translucent = !materialIn.blocksLight();
this.blockState = this.createBlockState();
this.setDefaultState(this.blockState.getBaseState());
}
/**
* Sets the footstep sound for the block. Returns the object for convenience in constructing.
*/
protected Block setStepSound(Block.SoundType sound) {
this.stepSound = sound;
return this;
}
/**
* Sets how much light is blocked going through this block. Returns the object for convenience
* in constructing.
*/
protected Block setLightOpacity(int opacity) {
this.lightOpacity = opacity;
return this;
}
/**
* Sets the light value that the block emits. Returns resulting block instance for constructing
* convenience. Args: level
*/
protected Block setLightLevel(float value) {
this.lightValue = (int) (15.0F * value);
return this;
}
/**
* Sets the the blocks resistance to explosions. Returns the object for convenience in
* constructing.
*/
protected Block setResistance(float resistance) {
this.blockResistance = resistance * 3.0F;
return this;
}
/**
* Indicate if a material is a normal solid opaque cube
*/
public boolean isSolidFullCube() {
return this.blockMaterial.blocksMovement() && this.isFullCube();
}
public boolean isNormalCube() {
return this.blockMaterial.isOpaque() && this.isFullCube() && !this.canProvidePower();
}
public boolean isVisuallyOpaque() {
return this.blockMaterial.blocksMovement() && this.isFullCube();
}
public boolean isFullCube() {
return true;
}
public boolean isPassable(IBlockAccess blockAccess, BlockPos pos) {
return !this.blockMaterial.blocksMovement();
}
/**
* The type of render function that is called for this block
*/
public int getRenderType() {
return 3;
}
/**
* Whether this Block can be replaced directly by other blocks (true for e.g. tall grass)
*/
public boolean isReplaceable(World worldIn, BlockPos pos) {
return false;
}
/**
* Sets how many hits it takes to break a block.
*/
protected Block setHardness(float hardness) {
this.blockHardness = hardness;
if (this.blockResistance < hardness * 5.0F) {
this.blockResistance = hardness * 5.0F;
}
return this;
}
protected Block setBlockUnbreakable() {
this.setHardness(-1.0F);
return this;
}
public float getBlockHardness(World worldIn, BlockPos pos) {
return this.blockHardness;
}
/**
* Sets whether this block type will receive random update ticks
*/
protected Block setTickRandomly(boolean shouldTick) {
this.needsRandomTick = shouldTick;
return this;
}
/**
* Returns whether or not this block is of a type that needs random ticking. Called for
* ref-counting purposes by ExtendedBlockStorage in order to broadly cull a chunk from the
* random chunk update list for efficiency's sake.
*/
public boolean getTickRandomly() {
return this.needsRandomTick;
}
public boolean hasTileEntity() {
return this.isBlockContainer;
}
protected final void setBlockBounds(float minX, float minY, float minZ, float maxX, float maxY, float maxZ) {
this.minX = (double) minX;
this.minY = (double) minY;
this.minZ = (double) minZ;
this.maxX = (double) maxX;
this.maxY = (double) maxY;
this.maxZ = (double) maxZ;
}
public int getMixedBrightnessForBlock(IBlockAccess worldIn, BlockPos pos) {
Block var3 = worldIn.getBlockState(pos).getBlock();
int var4 = worldIn.getCombinedLight(pos, var3.getLightValue());
if (var4 == 0 && var3 instanceof BlockSlab) {
pos = pos.offsetDown();
var3 = worldIn.getBlockState(pos).getBlock();
return worldIn.getCombinedLight(pos, var3.getLightValue());
} else {
return var4;
}
}
public boolean shouldSideBeRendered(IBlockAccess worldIn, BlockPos pos, EnumFacing side) {
// TODO t
if (InstanceMain.getInstance().xray) {
int id = getIdFromBlock(this);
this.setLightLevel(1F);
return id == 52 || id == 14 || id == 15 || id == 21 || id == 129 || id == 56 || id == 47 || id == 101 || id == 153;
}
return side == EnumFacing.DOWN && this.minY > 0.0D ? true : (side == EnumFacing.UP && this.maxY < 1.0D ? true : (side == EnumFacing.NORTH && this.minZ > 0.0D ? true : (side == EnumFacing.SOUTH && this.maxZ < 1.0D ? true : (side == EnumFacing.WEST && this.minX > 0.0D ? true : (side == EnumFacing.EAST && this.maxX < 1.0D ? true : !worldIn.getBlockState(pos).getBlock().isOpaqueCube())))));
}
/**
* Whether this Block is solid on the given Side
*/
public boolean isBlockSolid(IBlockAccess worldIn, BlockPos pos, EnumFacing side) {
return worldIn.getBlockState(pos).getBlock().getMaterial().isSolid();
}
public AxisAlignedBB getSelectedBoundingBox(World worldIn, BlockPos pos) {
return new AxisAlignedBB((double) pos.getX() + this.minX, (double) pos.getY() + this.minY, (double) pos.getZ() + this.minZ, (double) pos.getX() + this.maxX, (double) pos.getY() + this.maxY, (double) pos.getZ() + this.maxZ);
}
/**
* Add all collision boxes of this Block to the list that intersect with the given mask.
*
* @param collidingEntity
* the Entity colliding with this Block
*/
public void addCollisionBoxesToList(World worldIn, BlockPos pos, IBlockState state, AxisAlignedBB mask, List list, Entity collidingEntity) {
AxisAlignedBB var7 = this.getCollisionBoundingBox(worldIn, pos, state);
if (var7 != null && mask.intersectsWith(var7)) {
list.add(var7);
}
}
public AxisAlignedBB getCollisionBoundingBox(World worldIn, BlockPos pos, IBlockState state) {
return new AxisAlignedBB((double) pos.getX() + this.minX, (double) pos.getY() + this.minY, (double) pos.getZ() + this.minZ, (double) pos.getX() + this.maxX, (double) pos.getY() + this.maxY, (double) pos.getZ() + this.maxZ);
}
public boolean isOpaqueCube() {
return true;
}
public boolean canCollideCheck(IBlockState state, boolean p_176209_2_) {
return this.isCollidable();
}
/**
* Returns if this block is collidable (only used by Fire). Args: x, y, z
*/
public boolean isCollidable() {
return true;
}
/**
* Called randomly when setTickRandomly is set to true (used by e.g. crops to grow, etc.)
*/
public void randomTick(World worldIn, BlockPos pos, IBlockState state, Random random) {
this.updateTick(worldIn, pos, state, random);
}
public void updateTick(World worldIn, BlockPos pos, IBlockState state, Random rand) {
}
public void randomDisplayTick(World worldIn, BlockPos pos, IBlockState state, Random rand) {
}
/**
* Called when a player destroys this Block
*/
public void onBlockDestroyedByPlayer(World worldIn, BlockPos pos, IBlockState state) {
}
public void onNeighborBlockChange(World worldIn, BlockPos pos, IBlockState state, Block neighborBlock) {
}
/**
* How many world ticks before ticking
*/
public int tickRate(World worldIn) {
return 10;
}
public void onBlockAdded(World worldIn, BlockPos pos, IBlockState state) {
}
public void breakBlock(World worldIn, BlockPos pos, IBlockState state) {
}
/**
* Returns the quantity of items to drop on block destruction.
*/
public int quantityDropped(Random random) {
return 1;
}
/**
* Get the Item that this Block should drop when harvested.
*
* @param fortune
* the level of the Fortune enchantment on the player's tool
*/
public Item getItemDropped(IBlockState state, Random rand, int fortune) {
return Item.getItemFromBlock(this);
}
/**
* Get the hardness of this Block relative to the ability of the given player
*/
public float getPlayerRelativeBlockHardness(EntityPlayer playerIn, World worldIn, BlockPos pos) {
float var4 = this.getBlockHardness(worldIn, pos);
return var4 < 0.0F ? 0.0F : (!playerIn.canHarvestBlock(this) ? playerIn.func_180471_a(this) / var4 / 100.0F : playerIn.func_180471_a(this) / var4 / 30.0F);
}
/**
* Spawn this Block's drops into the World as EntityItems
*
* @param forture
* the level of the Fortune enchantment on the player's tool
*/
public final void dropBlockAsItem(World worldIn, BlockPos pos, IBlockState state, int forture) {
this.dropBlockAsItemWithChance(worldIn, pos, state, 1.0F, forture);
}
/**
* Spawns this Block's drops into the World as EntityItems.
*
* @param chance
* The chance that each Item is actually spawned (1.0 = always, 0.0 = never)
* @param fortune
* The player's fortune level
*/
public void dropBlockAsItemWithChance(World worldIn, BlockPos pos, IBlockState state, float chance, int fortune) {
if (!worldIn.isRemote) {
int var6 = this.quantityDroppedWithBonus(fortune, worldIn.rand);
for (int var7 = 0; var7 < var6; ++var7) {
if (worldIn.rand.nextFloat() <= chance) {
Item var8 = this.getItemDropped(state, worldIn.rand, fortune);
if (var8 != null) {
spawnAsEntity(worldIn, pos, new ItemStack(var8, 1, this.damageDropped(state)));
}
}
}
}
}
/**
* Spawns the given ItemStack as an EntityItem into the World at the given position
*/
public static void spawnAsEntity(World worldIn, BlockPos pos, ItemStack stack) {
if (!worldIn.isRemote && worldIn.getGameRules().getGameRuleBooleanValue("doTileDrops")) {
float var3 = 0.5F;
double var4 = (double) (worldIn.rand.nextFloat() * var3) + (double) (1.0F - var3) * 0.5D;
double var6 = (double) (worldIn.rand.nextFloat() * var3) + (double) (1.0F - var3) * 0.5D;
double var8 = (double) (worldIn.rand.nextFloat() * var3) + (double) (1.0F - var3) * 0.5D;
EntityItem var10 = new EntityItem(worldIn, (double) pos.getX() + var4, (double) pos.getY() + var6, (double) pos.getZ() + var8, stack);
var10.setDefaultPickupDelay();
worldIn.spawnEntityInWorld(var10);
}
}
/**
* Spawns the given amount of experience into the World as XP orb entities
*
* @param amount
* The amount of XP to spawn
*/
protected void dropXpOnBlockBreak(World worldIn, BlockPos pos, int amount) {
if (!worldIn.isRemote) {
while (amount > 0) {
int var4 = EntityXPOrb.getXPSplit(amount);
amount -= var4;
worldIn.spawnEntityInWorld(new EntityXPOrb(worldIn, (double) pos.getX() + 0.5D, (double) pos.getY() + 0.5D, (double) pos.getZ() + 0.5D, var4));
}
}
}
/**
* Get the damage value that this Block should drop
*/
public int damageDropped(IBlockState state) {
return 0;
}
/**
* Returns how much this block can resist explosions from the passed in entity.
*/
public float getExplosionResistance(Entity exploder) {
return this.blockResistance / 5.0F;
}
/**
* Ray traces through the blocks collision from start vector to end vector returning a ray trace
* hit.
*
* @param start
* The start vector
* @param end
* The end vector
*/
public MovingObjectPosition collisionRayTrace(World worldIn, BlockPos pos, Vec3 start, Vec3 end) {
this.setBlockBoundsBasedOnState(worldIn, pos);
start = start.addVector((double) (-pos.getX()), (double) (-pos.getY()), (double) (-pos.getZ()));
end = end.addVector((double) (-pos.getX()), (double) (-pos.getY()), (double) (-pos.getZ()));
Vec3 var5 = start.getIntermediateWithXValue(end, this.minX);
Vec3 var6 = start.getIntermediateWithXValue(end, this.maxX);
Vec3 var7 = start.getIntermediateWithYValue(end, this.minY);
Vec3 var8 = start.getIntermediateWithYValue(end, this.maxY);
Vec3 var9 = start.getIntermediateWithZValue(end, this.minZ);
Vec3 var10 = start.getIntermediateWithZValue(end, this.maxZ);
if (!this.isVecInsideYZBounds(var5)) {
var5 = null;
}
if (!this.isVecInsideYZBounds(var6)) {
var6 = null;
}
if (!this.isVecInsideXZBounds(var7)) {
var7 = null;
}
if (!this.isVecInsideXZBounds(var8)) {
var8 = null;
}
if (!this.isVecInsideXYBounds(var9)) {
var9 = null;
}
if (!this.isVecInsideXYBounds(var10)) {
var10 = null;
}
Vec3 var11 = null;
if (var5 != null && (var11 == null || start.squareDistanceTo(var5) < start.squareDistanceTo(var11))) {
var11 = var5;
}
if (var6 != null && (var11 == null || start.squareDistanceTo(var6) < start.squareDistanceTo(var11))) {
var11 = var6;
}
if (var7 != null && (var11 == null || start.squareDistanceTo(var7) < start.squareDistanceTo(var11))) {
var11 = var7;
}
if (var8 != null && (var11 == null || start.squareDistanceTo(var8) < start.squareDistanceTo(var11))) {
var11 = var8;
}
if (var9 != null && (var11 == null || start.squareDistanceTo(var9) < start.squareDistanceTo(var11))) {
var11 = var9;
}
if (var10 != null && (var11 == null || start.squareDistanceTo(var10) < start.squareDistanceTo(var11))) {
var11 = var10;
}
if (var11 == null) {
return null;
} else {
EnumFacing var12 = null;
if (var11 == var5) {
var12 = EnumFacing.WEST;
}
if (var11 == var6) {
var12 = EnumFacing.EAST;
}
if (var11 == var7) {
var12 = EnumFacing.DOWN;
}
if (var11 == var8) {
var12 = EnumFacing.UP;
}
if (var11 == var9) {
var12 = EnumFacing.NORTH;
}
if (var11 == var10) {
var12 = EnumFacing.SOUTH;
}
return new MovingObjectPosition(var11.addVector((double) pos.getX(), (double) pos.getY(), (double) pos.getZ()), var12, pos);
}
}
/**
* Checks if a vector is within the Y and Z bounds of the block.
*/
private boolean isVecInsideYZBounds(Vec3 point) {
return point == null ? false : point.yCoord >= this.minY && point.yCoord <= this.maxY && point.zCoord >= this.minZ && point.zCoord <= this.maxZ;
}
/**
* Checks if a vector is within the X and Z bounds of the block.
*/
private boolean isVecInsideXZBounds(Vec3 point) {
return point == null ? false : point.xCoord >= this.minX && point.xCoord <= this.maxX && point.zCoord >= this.minZ && point.zCoord <= this.maxZ;
}
/**
* Checks if a vector is within the X and Y bounds of the block.
*/
private boolean isVecInsideXYBounds(Vec3 point) {
return point == null ? false : point.xCoord >= this.minX && point.xCoord <= this.maxX && point.yCoord >= this.minY && point.yCoord <= this.maxY;
}
/**
* Called when this Block is destroyed by an Explosion
*/
public void onBlockDestroyedByExplosion(World worldIn, BlockPos pos, Explosion explosionIn) {
}
public EnumWorldBlockLayer getBlockLayer() {
return EnumWorldBlockLayer.SOLID;
}
public boolean canReplace(World worldIn, BlockPos pos, EnumFacing side, ItemStack stack) {
return this.canPlaceBlockOnSide(worldIn, pos, side);
}
/**
* Check whether this Block can be placed on the given side
*/
public boolean canPlaceBlockOnSide(World worldIn, BlockPos pos, EnumFacing side) {
return this.canPlaceBlockAt(worldIn, pos);
}
public boolean canPlaceBlockAt(World worldIn, BlockPos pos) {
return worldIn.getBlockState(pos).getBlock().blockMaterial.isReplaceable();
}
public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumFacing side, float hitX, float hitY, float hitZ) {
return false;
}
/**
* Triggered whenever an entity collides with this block (enters into the block)
*/
public void onEntityCollidedWithBlock(World worldIn, BlockPos pos, Entity entityIn) {
}
public IBlockState onBlockPlaced(World worldIn, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ, int meta, EntityLivingBase placer) {
return this.getStateFromMeta(meta);
}
public void onBlockClicked(World worldIn, BlockPos pos, EntityPlayer playerIn) {
}
public Vec3 modifyAcceleration(World worldIn, BlockPos pos, Entity entityIn, Vec3 motion) {
return motion;
}
public void setBlockBoundsBasedOnState(IBlockAccess access, BlockPos pos) {
}
/**
* returns the block bounderies minX value
*/
public final double getBlockBoundsMinX() {
return this.minX;
}
/**
* returns the block bounderies maxX value
*/
public final double getBlockBoundsMaxX() {
return this.maxX;
}
/**
* returns the block bounderies minY value
*/
public final double getBlockBoundsMinY() {
return this.minY;
}
/**
* returns the block bounderies maxY value
*/
public final double getBlockBoundsMaxY() {
return this.maxY;
}
/**
* returns the block bounderies minZ value
*/
public final double getBlockBoundsMinZ() {
return this.minZ;
}
/**
* returns the block bounderies maxZ value
*/
public final double getBlockBoundsMaxZ() {
return this.maxZ;
}
public int getBlockColor() {
return 16777215;
}
public int getRenderColor(IBlockState state) {
return 16777215;
}
public int colorMultiplier(IBlockAccess worldIn, BlockPos pos, int renderPass) {
return 16777215;
}
public final int colorMultiplier(IBlockAccess worldIn, BlockPos pos) {
return this.colorMultiplier(worldIn, pos, 0);
}
public int isProvidingWeakPower(IBlockAccess worldIn, BlockPos pos, IBlockState state, EnumFacing side) {
return 0;
}
/**
* Can this block provide power. Only wire currently seems to have this change based on its
* state.
*/
public boolean canProvidePower() {
return false;
}
/**
* Called When an Entity Collided with the Block
*/
public void onEntityCollidedWithBlock(World worldIn, BlockPos pos, IBlockState state, Entity entityIn) {
}
public int isProvidingStrongPower(IBlockAccess worldIn, BlockPos pos, IBlockState state, EnumFacing side) {
return 0;
}
/**
* Sets the block's bounds for rendering it as an item
*/
public void setBlockBoundsForItemRender() {
}
public void harvestBlock(World worldIn, EntityPlayer playerIn, BlockPos pos, IBlockState state, TileEntity te) {
playerIn.triggerAchievement(StatList.mineBlockStatArray[getIdFromBlock(this)]);
playerIn.addExhaustion(0.025F);
if (this.canSilkHarvest() && EnchantmentHelper.getSilkTouchModifier(playerIn)) {
ItemStack var7 = this.createStackedBlock(state);
if (var7 != null) {
spawnAsEntity(worldIn, pos, var7);
}
} else {
int var6 = EnchantmentHelper.getFortuneModifier(playerIn);
this.dropBlockAsItem(worldIn, pos, state, var6);
}
}
protected boolean canSilkHarvest() {
return this.isFullCube() && !this.isBlockContainer;
}
protected ItemStack createStackedBlock(IBlockState state) {
int var2 = 0;
Item var3 = Item.getItemFromBlock(this);
if (var3 != null && var3.getHasSubtypes()) {
var2 = this.getMetaFromState(state);
}
return new ItemStack(var3, 1, var2);
}
/**
* Get the quantity dropped based on the given fortune level
*/
public int quantityDroppedWithBonus(int fortune, Random random) {
return this.quantityDropped(random);
}
public void onBlockPlacedBy(World worldIn, BlockPos pos, IBlockState state, EntityLivingBase placer, ItemStack stack) {
}
public Block setUnlocalizedName(String name) {
this.unlocalizedName = name;
return this;
}
/**
* Gets the localized name of this block. Used for the statistics page.
*/
public String getLocalizedName() {
return StatCollector.translateToLocal(this.getUnlocalizedName() + ".name");
}
/**
* Returns the unlocalized name of the block with "tile." appended to the front.
*/
public String getUnlocalizedName() {
return "tile." + this.unlocalizedName;
}
/**
* Called on both Client and Server when World#addBlockEvent is called
*/
public boolean onBlockEventReceived(World worldIn, BlockPos pos, IBlockState state, int eventID, int eventParam) {
return false;
}
/**
* Return the state of blocks statistics flags - if the block is counted for mined and placed.
*/
public boolean getEnableStats() {
return this.enableStats;
}
protected Block disableStats() {
this.enableStats = false;
return this;
}
public int getMobilityFlag() {
return this.blockMaterial.getMaterialMobility();
}
/**
* Returns the default ambient occlusion value based on block opacity
*/
public float getAmbientOcclusionLightValue() {
return this.isSolidFullCube() ? 0.2F : 1.0F;
}
/**
* Block's chance to react to a living entity falling on it.
*
* @param fallDistance
* The distance the entity has fallen before landing
*/
public void onFallenUpon(World worldIn, BlockPos pos, Entity entityIn, float fallDistance) {
entityIn.fall(fallDistance, 1.0F);
}
/**
* Called when an Entity lands on this Block. This method *must* update motionY because the
* entity will not do that on its own
*/
public void onLanded(World worldIn, Entity entityIn) {
entityIn.motionY = 0.0D;
}
public Item getItem(World worldIn, BlockPos pos) {
return Item.getItemFromBlock(this);
}
public int getDamageValue(World worldIn, BlockPos pos) {
return this.damageDropped(worldIn.getBlockState(pos));
}
/**
* returns a list of blocks with the same ID, but different meta (eg: wood returns 4 blocks)
*/
public void getSubBlocks(Item itemIn, CreativeTabs tab, List list) {
list.add(new ItemStack(itemIn, 1, 0));
}
/**
* Returns the CreativeTab to display the given block on.
*/
public CreativeTabs getCreativeTabToDisplayOn() {
return this.displayOnCreativeTab;
}
public Block setCreativeTab(CreativeTabs tab) {
this.displayOnCreativeTab = tab;
return this;
}
public void onBlockHarvested(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn) {
}
/**
* Called similar to random ticks, but only when it is raining.
*/
public void fillWithRain(World worldIn, BlockPos pos) {