-
-
Notifications
You must be signed in to change notification settings - Fork 44
/
PatchWorld.java
1001 lines (859 loc) · 31.6 KB
/
PatchWorld.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 me.nallar.patched.world;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
import com.google.common.collect.ImmutableSetMultimap;
import javassist.is.faulty.ThreadLocals;
import me.nallar.tickthreading.Log;
import me.nallar.tickthreading.collections.ForcedChunksRedirectMap;
import me.nallar.tickthreading.minecraft.TickThreading;
import me.nallar.tickthreading.minecraft.entitylist.EntityList;
import me.nallar.tickthreading.minecraft.entitylist.LoadedTileEntityList;
import me.nallar.tickthreading.patcher.Declare;
import net.minecraft.block.Block;
import net.minecraft.crash.CrashReport;
import net.minecraft.crash.CrashReportCategory;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityTracker;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.profiler.Profiler;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.util.MathHelper;
import net.minecraft.util.ReportedException;
import net.minecraft.util.Vec3;
import net.minecraft.world.ChunkCoordIntPair;
import net.minecraft.world.World;
import net.minecraft.world.WorldProvider;
import net.minecraft.world.WorldServer;
import net.minecraft.world.WorldSettings;
import net.minecraft.world.chunk.Chunk;
import net.minecraft.world.chunk.storage.AnvilChunkLoader;
import net.minecraft.world.gen.ChunkProviderServer;
import net.minecraft.world.storage.ISaveHandler;
import net.minecraftforge.common.DimensionManager;
import net.minecraftforge.common.ForgeChunkManager;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.entity.EntityJoinWorldEvent;
import org.cliffc.high_scale_lib.NonBlockingHashMapLong;
@SuppressWarnings ("unchecked")
public abstract class PatchWorld extends World {
private int forcedUpdateCount;
@Declare
public ThreadLocal<Boolean> inPlaceEvent_;
@Declare
public org.cliffc.high_scale_lib.NonBlockingHashMapLong<Integer> redstoneBurnoutMap_;
@Declare
public Set<Entity> unloadedEntitySet_;
@Declare
public Set<TileEntity> tileEntityRemovalSet_;
@Declare
public com.google.common.collect.ImmutableSetMultimap<ChunkCoordIntPair, ForgeChunkManager.Ticket> forcedChunks_;
@Declare
public int tickCount_;
private boolean warnedWrongList;
@Declare
public int dimensionId_;
private String cachedName;
@Declare
public boolean multiverseWorld_;
@Declare
public int originalDimension_;
@Declare
public boolean unloaded_;
@Declare
public Chunk emptyChunk_;
public void construct() {
tickCount = rand.nextInt(240); // So when different worlds do every N tick actions,
// they won't all happen at the same time even if the worlds loaded at the same time
tileEntityRemovalSet = new HashSet<TileEntity>();
unloadedEntitySet = new HashSet<Entity>();
redstoneBurnoutMap = new NonBlockingHashMapLong<Integer>();
if (dimensionId == 0) {
dimensionId = provider.dimensionId;
}
}
public PatchWorld(ISaveHandler par1ISaveHandler, String par2Str, WorldProvider par3WorldProvider, WorldSettings par4WorldSettings, Profiler par5Profiler) {
super(par1ISaveHandler, par2Str, par3WorldProvider, par4WorldSettings, par5Profiler);
}
@Override
@Declare
public boolean onClient() {
return isRemote;
}
@Override
@Declare
public void setDimension(int dimensionId) {
WorldProvider provider = this.provider;
this.dimensionId = dimensionId;
if (provider.dimensionId != dimensionId) {
try {
DimensionManager.registerDimension(dimensionId, provider.dimensionId);
} catch (Throwable t) {
Log.warning("Failed to register corrected dimension ID with DimensionManager", t);
}
originalDimension = provider.dimensionId;
multiverseWorld = true;
provider.dimensionId = dimensionId;
}
cachedName = null;
Log.fine("Set dimension ID for " + this.getName());
if (TickThreading.instance.getManager(this) != null) {
Log.severe("Set corrected dimension too late!");
}
}
@Override
@Declare
public int getDimension() {
return dimensionId;
}
@Override
@Declare
public String getName() {
String name = cachedName;
if (name != null) {
return name;
}
int dimensionId = getDimension();
if (multiverseWorld) {
name = worldInfo.getWorldName();
if (name.startsWith("world_")) {
name = name.substring(6);
}
} else {
name = provider.getDimensionName();
}
cachedName = name = (name + '/' + dimensionId + (isRemote ? "-r" : ""));
return name;
}
@Override
public boolean isBlockNormalCube(int x, int y, int z) {
int id = getBlockIdWithoutLoad(x, y, z);
if (id == -1) {
return false;
}
Block block = Block.blocksList[id];
return block != null && block.isBlockNormalCube(this, x, y, z);
}
@Override
public void removeEntity(Entity entity) {
if (entity == null) {
return;
}
try {
if (entity.riddenByEntity != null) {
entity.riddenByEntity.mountEntity(null);
}
if (entity.ridingEntity != null) {
entity.mountEntity(null);
}
entity.setDead();
// The next instanceof, somehow, seems to throw NPEs. I don't even. :(
// http://pastebin.com/zqDPsUjz
if (entity instanceof EntityPlayer) {
if (playerEntities == null) {
// The world has been unloaded and cleaned already, so we can't remove the player entity.
return;
}
this.playerEntities.remove(entity);
this.updateAllPlayersSleepingFlag();
}
} catch (Exception e) {
Log.severe("Exception removing a player entity", e);
}
}
@Override
public int getBlockId(int x, int y, int z) {
if (x >= -30000000 && z >= -30000000 && x < 30000000 && z < 30000000 && y >= 0 && y < 256) {
try {
return getChunkFromChunkCoords(x >> 4, z >> 4).getBlockID(x & 15, y, z & 15);
} catch (Throwable t) {
Log.severe("Exception getting block ID in " + Log.pos(this, x, y, z), t);
}
}
return 0;
}
@Override
@Declare
public int getBlockIdWithoutLoad(int x, int y, int z) {
if (x >= -30000000 && z >= -30000000 && x < 30000000 && z < 30000000 && y >= 0 && y < 256) {
try {
Chunk chunk = ((ChunkProviderServer) chunkProvider).getChunkIfExists(x >> 4, z >> 4);
return chunk == null ? -1 : chunk.getBlockID(x & 15, y, z & 15);
} catch (Throwable t) {
Log.severe("Exception getting block ID in " + Log.pos(this, x, y, z), t);
}
}
return 0;
}
@Override
public Chunk getChunkFromChunkCoords(int x, int z) {
return chunkProvider.provideChunk(x, z);
}
@Override
@Declare
public Chunk getChunkFromChunkCoordsWithLoad(int x, int z) {
return chunkProvider.loadChunk(x, z);
}
@Override
@Declare
public int getBlockIdWithLoad(int x, int y, int z) {
if (y >= 256) {
return 0;
} else {
return chunkProvider.loadChunk(x >> 4, z >> 4).getBlockID(x & 15, y, z & 15);
}
}
@Override
public EntityPlayer getClosestPlayer(double x, double y, double z, double maxRange) {
double closestRange = Double.MAX_VALUE;
EntityPlayer target = null;
for (EntityPlayer playerEntity : (Iterable<EntityPlayer>) this.playerEntities) {
if (!playerEntity.capabilities.disableDamage && playerEntity.isEntityAlive()) {
double distanceSq = playerEntity.getDistanceSq(x, y, z);
if ((maxRange < 0.0D || distanceSq < (maxRange * maxRange)) && (distanceSq < closestRange)) {
closestRange = distanceSq;
target = playerEntity;
}
}
}
return target;
}
@SuppressWarnings ("ConstantConditions")
@Override
public EntityPlayer getClosestVulnerablePlayer(double x, double y, double z, double maxRange) {
double closestRange = Double.MAX_VALUE;
EntityPlayer target = null;
for (EntityPlayer playerEntity : (Iterable<EntityPlayer>) this.playerEntities) {
if (!playerEntity.capabilities.disableDamage && playerEntity.isEntityAlive()) {
double distanceSq = playerEntity.getDistanceSq(x, y, z);
double effectiveMaxRange = maxRange;
if (playerEntity.isSneaking()) {
effectiveMaxRange = maxRange * 0.800000011920929D;
}
if (playerEntity.getHasActivePotion()) {
float var18 = playerEntity.func_82243_bO();
if (var18 < 0.1F) {
var18 = 0.1F;
}
effectiveMaxRange *= (double) (0.7F * var18);
}
if ((maxRange < 0.0D || distanceSq < (effectiveMaxRange * effectiveMaxRange)) && (distanceSq < closestRange)) {
closestRange = distanceSq;
target = playerEntity;
}
}
}
return target;
}
@Override
public EntityPlayer getPlayerEntityByName(String name) {
for (EntityPlayer player : (Iterable<EntityPlayer>) playerEntities) {
if (name.equals(player.username)) {
return player;
}
}
return null;
}
@Override
protected void notifyBlockOfNeighborChange(int x, int y, int z, int par4) {
if (!this.editingBlocks && !this.isRemote) {
int var5 = this.getBlockIdWithoutLoad(x, y, z);
Block var6 = var5 < 1 ? null : Block.blocksList[var5];
if (var6 != null) {
try {
var6.onNeighborBlockChange(this, x, y, z, par4);
} catch (Throwable t) {
Log.severe("Exception while updating block neighbours " + Log.pos(this, x, y, z), t);
}
}
}
}
@Override
public ImmutableSetMultimap<ChunkCoordIntPair, ForgeChunkManager.Ticket> getPersistentChunks() {
return forcedChunks == null ? ForcedChunksRedirectMap.emptyMap : forcedChunks;
}
@Override
public TileEntity getBlockTileEntity(int x, int y, int z) {
if (y >= 256) {
return null;
} else {
Chunk chunk = this.getChunkFromChunkCoords(x >> 4, z >> 4);
return chunk == null ? null : chunk.getChunkBlockTileEntity(x & 15, y, z & 15);
}
}
@Override
@Declare
public TileEntity getTEWithoutLoad(int x, int y, int z) {
if (y >= 256) {
return null;
} else {
Chunk chunk = ((ChunkProviderServer) this.chunkProvider).getChunkIfExists(x >> 4, z >> 4);
return chunk == null ? null : chunk.getChunkBlockTileEntity(x & 15, y, z & 15);
}
}
@Override
@Declare
public TileEntity getTEWithLoad(int x, int y, int z) {
if (y >= 256) {
return null;
} else {
return chunkProvider.loadChunk(x >> 4, z >> 4).getChunkBlockTileEntity(x & 15, y, z & 15);
}
}
@Override
public void updateEntityWithOptionalForce(Entity entity, boolean notForced) {
int x = MathHelper.floor_double(entity.posX);
int z = MathHelper.floor_double(entity.posZ);
boolean periodicUpdate = forcedUpdateCount++ % 19 == 0;
Boolean isForced_ = entity.isForced;
if (isForced_ == null || periodicUpdate) {
entity.isForced = isForced_ = getPersistentChunks().containsKey(new ChunkCoordIntPair(x >> 4, z >> 4));
}
boolean isForced = isForced_;
Boolean canUpdate_ = entity.canUpdate;
if (canUpdate_ == null || periodicUpdate) {
byte range = isForced ? (byte) 0 : 48;
entity.canUpdate = canUpdate_ = !notForced || this.checkChunksExist(x - range, 0, z - range, x + range, 0, z + range);
} else if (canUpdate_) {
entity.canUpdate = canUpdate_ = !notForced || chunkExists(x >> 4, z >> 4);
}
boolean canUpdate = canUpdate_;
if (canUpdate) {
entity.lastTickPosX = entity.posX;
entity.lastTickPosY = entity.posY;
entity.lastTickPosZ = entity.posZ;
entity.prevRotationYaw = entity.rotationYaw;
entity.prevRotationPitch = entity.rotationPitch;
if (notForced && entity.addedToChunk) {
if (entity.ridingEntity != null) {
entity.updateRidden();
} else {
++entity.ticksExisted;
entity.onUpdate();
}
}
this.theProfiler.startSection("chunkCheck");
if (Double.isNaN(entity.posX) || Double.isInfinite(entity.posX)) {
entity.posX = entity.lastTickPosX;
}
if (Double.isNaN(entity.posY) || Double.isInfinite(entity.posY)) {
entity.posY = entity.lastTickPosY;
}
if (Double.isNaN(entity.posZ) || Double.isInfinite(entity.posZ)) {
entity.posZ = entity.lastTickPosZ;
}
if (Double.isNaN((double) entity.rotationPitch) || Double.isInfinite((double) entity.rotationPitch)) {
entity.rotationPitch = entity.prevRotationPitch;
}
if (Double.isNaN((double) entity.rotationYaw) || Double.isInfinite((double) entity.rotationYaw)) {
entity.rotationYaw = entity.prevRotationYaw;
}
int cX = MathHelper.floor_double(entity.posX / 16.0D);
int cY = MathHelper.floor_double(entity.posY / 16.0D);
int cZ = MathHelper.floor_double(entity.posZ / 16.0D);
if (!entity.addedToChunk || entity.chunkCoordX != cX || entity.chunkCoordY != cY || entity.chunkCoordZ != cZ) {
if (entity.addedToChunk) {
Chunk chunk = getChunkIfExists(entity.chunkCoordX, entity.chunkCoordZ);
if (chunk != null) {
chunk.removeEntityAtIndex(entity, entity.chunkCoordY);
}
}
Chunk chunk = getChunkIfExists(cX, cZ);
if (chunk != null) {
entity.addedToChunk = true;
chunk.addEntity(entity);
} else {
entity.addedToChunk = false;
}
}
this.theProfiler.endSection();
if (notForced && entity.addedToChunk && entity.riddenByEntity != null) {
if (!entity.riddenByEntity.isDead && entity.riddenByEntity.ridingEntity == entity) {
this.updateEntity(entity.riddenByEntity);
} else {
entity.riddenByEntity.ridingEntity = null;
entity.riddenByEntity = null;
}
}
}
}
@Override
public void addLoadedEntities(List par1List) {
EntityTracker entityTracker = null;
//noinspection RedundantCast
if (((Object) this instanceof WorldServer)) {
entityTracker = ((WorldServer) (Object) this).getEntityTracker();
}
for (int var2 = 0; var2 < par1List.size(); ++var2) {
Entity entity = (Entity) par1List.get(var2);
if (MinecraftForge.EVENT_BUS.post(new EntityJoinWorldEvent(entity, this))) {
par1List.remove(var2--);
} else if (entityTracker == null || !entityTracker.isTracking(entity.entityId)) {
loadedEntityList.add(entity);
this.obtainEntitySkin(entity);
}
}
}
@Override
@Declare
public boolean hasCollidingBoundingBoxes(Entity par1Entity, AxisAlignedBB par2AxisAlignedBB) {
List collidingBoundingBoxes = (List) ThreadLocals.collidingBoundingBoxes.get();
collidingBoundingBoxes.clear();
int minX = MathHelper.floor_double(par2AxisAlignedBB.minX);
int maxX = MathHelper.floor_double(par2AxisAlignedBB.maxX + 1.0D);
int minY = MathHelper.floor_double(par2AxisAlignedBB.minY);
int maxY = MathHelper.floor_double(par2AxisAlignedBB.maxY + 1.0D);
int minZ = MathHelper.floor_double(par2AxisAlignedBB.minZ);
int maxZ = MathHelper.floor_double(par2AxisAlignedBB.maxZ + 1.0D);
int ystart = ((minY - 1) < 0) ? 0 : (minY - 1);
for (int chunkx = (minX >> 4); chunkx <= ((maxX - 1) >> 4); chunkx++) {
int cx = chunkx << 4;
for (int chunkz = (minZ >> 4); chunkz <= ((maxZ - 1) >> 4); chunkz++) {
Chunk chunk = this.getChunkIfExists(chunkx, chunkz);
if (chunk == null) {
continue;
}
// Compute ranges within chunk
int cz = chunkz << 4;
int xstart = (minX < cx) ? cx : minX;
int xend = (maxX < (cx + 16)) ? maxX : (cx + 16);
int zstart = (minZ < cz) ? cz : minZ;
int zend = (maxZ < (cz + 16)) ? maxZ : (cz + 16);
// Loop through blocks within chunk
for (int x = xstart; x < xend; x++) {
for (int z = zstart; z < zend; z++) {
for (int y = ystart; y < maxY; y++) {
int blkid = chunk.getBlockID(x - cx, y, z - cz);
if (blkid > 0) {
Block block = Block.blocksList[blkid];
if (block != null) {
block.addCollidingBlockToList(this, x, y, z, par2AxisAlignedBB, collidingBoundingBoxes, par1Entity);
}
if (!collidingBoundingBoxes.isEmpty()) {
return true;
}
}
}
}
}
}
}
double var14 = 0.25D;
List<Entity> var16 = this.getEntitiesWithinAABBExcludingEntity(par1Entity, par2AxisAlignedBB.expand(var14, var14, var14), 100);
for (Entity aVar16 : var16) {
AxisAlignedBB var13 = aVar16.getBoundingBox();
if (var13 != null && var13.intersectsWith(par2AxisAlignedBB)) {
return true;
}
var13 = par1Entity.getCollisionBox(aVar16);
if (var13 != null && var13.intersectsWith(par2AxisAlignedBB)) {
return true;
}
}
return false;
}
@Override
@Declare
public List getCollidingBoundingBoxes(Entity par1Entity, AxisAlignedBB par2AxisAlignedBB, int limit) {
List collidingBoundingBoxes = (List) ThreadLocals.collidingBoundingBoxes.get();
collidingBoundingBoxes.clear();
int var3 = MathHelper.floor_double(par2AxisAlignedBB.minX);
int var4 = MathHelper.floor_double(par2AxisAlignedBB.maxX + 1.0D);
int var5 = MathHelper.floor_double(par2AxisAlignedBB.minY);
int var6 = MathHelper.floor_double(par2AxisAlignedBB.maxY + 1.0D);
int var7 = MathHelper.floor_double(par2AxisAlignedBB.minZ);
int var8 = MathHelper.floor_double(par2AxisAlignedBB.maxZ + 1.0D);
int ystart = ((var5 - 1) < 0) ? 0 : (var5 - 1);
for (int chunkx = (var3 >> 4); chunkx <= ((var4 - 1) >> 4); chunkx++) {
int cx = chunkx << 4;
for (int chunkz = (var7 >> 4); chunkz <= ((var8 - 1) >> 4); chunkz++) {
Chunk chunk = this.getChunkIfExists(chunkx, chunkz);
if (chunk == null) {
continue;
}
// Compute ranges within chunk
int cz = chunkz << 4;
// Compute ranges within chunk
int xstart = (var3 < cx) ? cx : var3;
int xend = (var4 < (cx + 16)) ? var4 : (cx + 16);
int zstart = (var7 < cz) ? cz : var7;
int zend = (var8 < (cz + 16)) ? var8 : (cz + 16);
// Loop through blocks within chunk
for (int x = xstart; x < xend; x++) {
for (int z = zstart; z < zend; z++) {
for (int y = ystart; y < var6; y++) {
int blkid = chunk.getBlockID(x - cx, y, z - cz);
if (blkid > 0) {
Block block = Block.blocksList[blkid];
if (block != null) {
block.addCollidingBlockToList(this, x, y, z, par2AxisAlignedBB, collidingBoundingBoxes, par1Entity);
if (collidingBoundingBoxes.size() > limit) {
return collidingBoundingBoxes;
}
}
}
}
}
}
}
}
double var14 = 0.25D;
List<Entity> var16 = this.getEntitiesWithinAABBExcludingEntity(par1Entity, par2AxisAlignedBB.expand(var14, var14, var14), limit);
for (Entity aVar16 : var16) {
AxisAlignedBB var13 = aVar16.getBoundingBox();
if (var13 != null && var13.intersectsWith(par2AxisAlignedBB)) {
collidingBoundingBoxes.add(var13);
}
var13 = par1Entity.getCollisionBox(aVar16);
if (var13 != null && var13.intersectsWith(par2AxisAlignedBB)) {
collidingBoundingBoxes.add(var13);
}
}
return collidingBoundingBoxes;
}
@Override
public List getCollidingBoundingBoxes(Entity par1Entity, AxisAlignedBB par2AxisAlignedBB) {
return getCollidingBoundingBoxes(par1Entity, par2AxisAlignedBB, 2000);
}
@Override
public void addTileEntity(Collection tileEntities) {
List dest = scanningTileEntities ? addedTileEntityList : loadedTileEntityList;
for (TileEntity tileEntity : (Iterable<TileEntity>) tileEntities) {
try {
tileEntity.validate();
} catch (Throwable t) {
Log.severe("Tile Entity " + tileEntity + " failed to validate, it will be ignored.", t);
}
if (tileEntity.canUpdate()) {
dest.add(tileEntity);
}
}
}
@Override
@Declare
public List getEntitiesWithinAABBExcludingEntity(Entity par1Entity, AxisAlignedBB par2AxisAlignedBB, int limit) {
List entitiesWithinAABBExcludingEntity = (List) ThreadLocals.entitiesWithinAABBExcludingEntity.get();
entitiesWithinAABBExcludingEntity.clear();
int minX = MathHelper.floor_double((par2AxisAlignedBB.minX - MAX_ENTITY_RADIUS) / 16.0D);
int maxX = MathHelper.floor_double((par2AxisAlignedBB.maxX + MAX_ENTITY_RADIUS) / 16.0D);
int minZ = MathHelper.floor_double((par2AxisAlignedBB.minZ - MAX_ENTITY_RADIUS) / 16.0D);
int maxZ = MathHelper.floor_double((par2AxisAlignedBB.maxZ + MAX_ENTITY_RADIUS) / 16.0D);
for (int x = minX; x <= maxX; ++x) {
for (int z = minZ; z <= maxZ; ++z) {
Chunk chunk = getChunkIfExists(x, z);
if (chunk != null) {
chunk.getEntitiesWithinAABBForEntity(par1Entity, par2AxisAlignedBB, entitiesWithinAABBExcludingEntity, limit);
}
}
}
return entitiesWithinAABBExcludingEntity;
}
@Override
public List getEntitiesWithinAABBExcludingEntity(Entity par1Entity, AxisAlignedBB par2AxisAlignedBB) {
List entitiesWithinAABBExcludingEntity = (List) ThreadLocals.entitiesWithinAABBExcludingEntity.get();
entitiesWithinAABBExcludingEntity.clear();
int var3 = MathHelper.floor_double((par2AxisAlignedBB.minX - MAX_ENTITY_RADIUS) / 16.0D);
int var4 = MathHelper.floor_double((par2AxisAlignedBB.maxX + MAX_ENTITY_RADIUS) / 16.0D);
int var5 = MathHelper.floor_double((par2AxisAlignedBB.minZ - MAX_ENTITY_RADIUS) / 16.0D);
int var6 = MathHelper.floor_double((par2AxisAlignedBB.maxZ + MAX_ENTITY_RADIUS) / 16.0D);
for (int var7 = var3; var7 <= var4; ++var7) {
for (int var8 = var5; var8 <= var6; ++var8) {
Chunk chunk = getChunkIfExists(var7, var8);
if (chunk != null) {
chunk.getEntitiesWithinAABBForEntity(par1Entity, par2AxisAlignedBB, entitiesWithinAABBExcludingEntity);
}
}
}
return entitiesWithinAABBExcludingEntity;
}
@Override
public int countEntities(Class entityType) {
if (loadedEntityList instanceof EntityList) {
return ((EntityList) this.loadedEntityList).manager.getEntityCount(entityType);
}
int count = 0;
for (Entity e : (Iterable<Entity>) this.loadedEntityList) {
if (entityType.isAssignableFrom(e.getClass())) {
++count;
}
}
return count;
}
@Override
public boolean checkChunksExist(int minX, int minY, int minZ, int maxX, int maxY, int maxZ) {
return minY <= 255 && maxY >= 0 && ((ChunkProviderServer) chunkProvider).chunksExist(minX >> 4, minZ >> 4, maxX >> 4, maxZ >> 4);
}
@Override
public void unloadEntities(List entitiesToUnload) {
for (Entity entity : (Iterable<Entity>) entitiesToUnload) {
if (!(entity instanceof EntityPlayerMP)) {
unloadedEntitySet.add(entity);
}
}
}
@Override
public void updateEntities() {
this.theProfiler.startSection("entities");
this.theProfiler.startSection("global");
int var1;
Entity var2;
CrashReport var4;
CrashReportCategory var5;
for (var1 = 0; var1 < this.weatherEffects.size(); ++var1) {
var2 = (Entity) this.weatherEffects.get(var1);
try {
++var2.ticksExisted;
var2.onUpdate();
} catch (Throwable var6) {
var4 = CrashReport.makeCrashReport(var6, "Ticking entity");
var5 = var4.makeCategory("Entity being ticked");
var2.func_85029_a(var5);
throw new ReportedException(var4);
}
if (var2.isDead) {
this.weatherEffects.remove(var1--);
}
}
this.theProfiler.endStartSection("remove");
int var3;
int var13;
if (this.loadedEntityList instanceof EntityList) {
((EntityList) this.loadedEntityList).manager.batchRemoveEntities(unloadedEntitySet);
} else {
this.loadedEntityList.removeAll(this.unloadedEntitySet);
for (Entity entity : unloadedEntitySet) {
var3 = entity.chunkCoordX;
var13 = entity.chunkCoordZ;
if (entity.addedToChunk) {
Chunk chunk = getChunkIfExists(var3, var13);
if (chunk != null) {
chunk.removeEntity(entity);
}
}
releaseEntitySkin(entity);
}
}
this.unloadedEntitySet.clear();
this.theProfiler.endStartSection("regular");
boolean shouldTickThreadingTick = true;
if (this.loadedEntityList instanceof EntityList) {
((EntityList) this.loadedEntityList).manager.doTick();
shouldTickThreadingTick = false;
} else {
for (var1 = 0; var1 < this.loadedEntityList.size(); ++var1) {
var2 = (Entity) this.loadedEntityList.get(var1);
if (var2.ridingEntity != null) {
if (!var2.ridingEntity.isDead && var2.ridingEntity.riddenByEntity == var2) {
continue;
}
var2.ridingEntity.riddenByEntity = null;
var2.ridingEntity = null;
}
this.theProfiler.startSection("tick");
if (!var2.isDead) {
try {
this.updateEntity(var2);
} catch (Throwable var7) {
var4 = CrashReport.makeCrashReport(var7, "Ticking entity");
var5 = var4.makeCategory("Entity being ticked");
var2.func_85029_a(var5);
throw new ReportedException(var4);
}
}
this.theProfiler.endSection();
this.theProfiler.startSection("remove");
if (var2.isDead) {
var3 = var2.chunkCoordX;
var13 = var2.chunkCoordZ;
if (var2.addedToChunk) {
Chunk chunk = getChunkIfExists(var3, var13);
if (chunk != null) {
chunk.removeEntity(var2);
}
}
this.loadedEntityList.remove(var1--);
this.releaseEntitySkin(var2);
}
this.theProfiler.endSection();
}
}
this.theProfiler.endStartSection("tileEntities");
if (this.loadedEntityList instanceof EntityList) {
if (shouldTickThreadingTick) {
((EntityList) this.loadedEntityList).manager.doTick();
}
} else {
this.scanningTileEntities = true;
Iterator var14 = this.loadedTileEntityList.iterator();
while (var14.hasNext()) {
TileEntity var9 = (TileEntity) var14.next();
if (!var9.isInvalid() && var9.func_70309_m() && this.blockExists(var9.xCoord, var9.yCoord, var9.zCoord)) {
try {
var9.updateEntity();
} catch (Throwable var8) {
var4 = CrashReport.makeCrashReport(var8, "Ticking tile entity");
var5 = var4.makeCategory("Tile entity being ticked");
var9.func_85027_a(var5);
throw new ReportedException(var4);
}
}
if (var9.isInvalid()) {
var14.remove();
Chunk var11 = this.getChunkIfExists(var9.xCoord >> 4, var9.zCoord >> 4);
if (var11 != null) {
var11.cleanChunkBlockTileEntity(var9.xCoord & 15, var9.yCoord, var9.zCoord & 15);
}
}
}
}
this.theProfiler.endStartSection("removingTileEntities");
if (!this.tileEntityRemovalSet.isEmpty()) {
if (loadedTileEntityList instanceof LoadedTileEntityList) {
((LoadedTileEntityList) loadedTileEntityList).manager.batchRemoveTileEntities(tileEntityRemovalSet);
} else {
if (!warnedWrongList && loadedTileEntityList.getClass() != ArrayList.class) {
Log.severe("TickThreading's replacement loaded tile entity list has been replaced by one from another mod!\n" +
"Class: " + loadedTileEntityList.getClass() + ", toString(): " + loadedTileEntityList);
warnedWrongList = true;
}
for (TileEntity tile : tileEntityRemovalSet) {
tile.onChunkUnload();
}
this.loadedTileEntityList.removeAll(tileEntityRemovalSet);
}
tileEntityRemovalSet.clear();
}
this.scanningTileEntities = false;
this.theProfiler.endStartSection("pendingTileEntities");
if (!this.addedTileEntityList.isEmpty()) {
for (TileEntity te : (Iterable<TileEntity>) this.addedTileEntityList) {
if (te.isInvalid()) {
Chunk var15 = this.getChunkIfExists(te.xCoord >> 4, te.zCoord >> 4);
if (var15 != null) {
var15.cleanChunkBlockTileEntity(te.xCoord & 15, te.yCoord, te.zCoord & 15);
}
} else {
if (!this.loadedTileEntityList.contains(te)) {
this.loadedTileEntityList.add(te);
}
}
}
this.addedTileEntityList.clear();
}
this.theProfiler.endSection();
this.theProfiler.endSection();
}
@Override
public boolean isBlockProvidingPowerTo(int par1, int par2, int par3, int par4) {
int id = this.getBlockIdWithoutLoad(par1, par2, par3);
return id > 0 && Block.blocksList[id].isProvidingStrongPower(this, par1, par2, par3, par4);
}
@Override
public boolean isBlockIndirectlyProvidingPowerTo(int x, int y, int z, int direction) {
int id = this.getBlockIdWithoutLoad(x, y, z);
if (id < 1) {
return false;
}
Block block = Block.blocksList[id];
return block != null && ((block.isBlockNormalCube(this, x, y, z) && this.isBlockGettingPowered(x, y, z)) || block.isProvidingWeakPower(this, x, y, z, direction));
}
@Override
@Declare
public Chunk getChunkIfExists(int x, int z) {
Chunk chunk = chunkProvider.provideChunk(x, z);
return chunk == emptyChunk ? null : chunk;
}
@Override
@Declare
public Chunk getChunkFromBlockCoordsIfExists(int x, int z) {
return this.getChunkIfExists(x >> 4, z >> 4);
}
@Override
public void markTileEntityForDespawn(TileEntity tileEntity) {
tileEntityRemovalSet.add(tileEntity);
}
@Override
@Declare
public void setBlockTileEntityWithoutValidate(int x, int y, int z, TileEntity tileEntity) {
if (tileEntity == null || tileEntity.isInvalid()) {
return;
}
if (tileEntity.canUpdate()) {
(scanningTileEntities ? addedTileEntityList : loadedTileEntityList).add(tileEntity);
}
Chunk chunk = getChunkFromChunkCoords(x >> 4, z >> 4);
if (chunk != null) {
chunk.setChunkBlockTileEntityWithoutValidate(x & 15, y, z & 15, tileEntity);
}
}
@Override
@Declare
public boolean setBlockAndMetadataWithUpdateWithoutValidate(int x, int y, int z, int id, int meta, boolean update) {
if (x >= -30000000 && z >= -30000000 && x < 30000000 && z < 30000000 && y >= 0 && y < 256) {
Chunk chunk = this.getChunkFromChunkCoords(x >> 4, z >> 4);
if (!chunk.setBlockIDWithMetadataWithoutValidate(x & 15, y, z & 15, id, meta)) {
return false;
}
this.theProfiler.startSection("checkLight");
this.updateAllLightTypes(x, y, z);
this.theProfiler.endSection();
if (update) {
this.markBlockForUpdate(x, y, z);
}
return true;
}
return false;
}
@Override
@Declare
public boolean isChunkSavedPopulated(int x, int z) {
return ((AnvilChunkLoader) ((WorldServer) (Object) this).theChunkProviderServer.currentChunkLoader).isChunkSavedPopulated(x, z);
}
private static double center(double a, double b) {
return ((a - b) / 2) + b;
}
private static boolean isBroken(double a) {
return Double.isNaN(a) || Double.isInfinite(a);
}
@Override
public float getBlockDensity(Vec3 start, AxisAlignedBB target) {
if (isBroken(target.minX) || isBroken(target.maxX) ||
isBroken(target.minY) || isBroken(target.maxY) ||
isBroken(target.minZ) || isBroken(target.maxZ) ||
isBroken(start.xCoord) || isBroken(start.yCoord) || isBroken(start.zCoord) ||
target.getAverageEdgeLength() > 10) {
return 0.5f;
}
Vec3 center = getWorldVec3Pool().getVecFromPool(center(target.maxX, target.minX), center(target.maxY, target.minY), center(target.maxZ, target.minZ));
if (start.squareDistanceTo(center) > 1000 || !chunkExists(((int) center.xCoord) >> 4, ((int) center.zCoord) >> 4)) {
return 0.5f;
}
double dX = 1.0D / ((target.maxX - target.minX) * 2.0D + 1.0D);
double dY = 1.0D / ((target.maxY - target.minY) * 2.0D + 1.0D);
double dZ = 1.0D / ((target.maxZ - target.minZ) * 2.0D + 1.0D);
dX = dX > 0.02 ? dX : 0.02;
dY = dY > 0.02 ? dY : 0.02;
dZ = dZ > 0.02 ? dZ : 0.02;
int hit = 0;
int noHit = 0;
for (float var11 = 0.0F; var11 <= 1.0F; var11 = (float) ((double) var11 + dX)) {
for (float var12 = 0.0F; var12 <= 1.0F; var12 = (float) ((double) var12 + dY)) {
for (float var13 = 0.0F; var13 <= 1.0F; var13 = (float) ((double) var13 + dZ)) {
double x = target.minX + (target.maxX - target.minX) * (double) var11;
double y = target.minY + (target.maxY - target.minY) * (double) var12;
double z = target.minZ + (target.maxZ - target.minZ) * (double) var13;
if (this.rayTraceBlocks(center.setComponents(x, y, z), start) == null) {
++hit;
}
++noHit;
}
}
}
return (float) hit / (float) noHit;
}