View difference between Paste ID: kpHeHYDb and 8RaqLAA2
SHOW: | | - or go back to the newest paste.
1
// Block Code
2
public class BlockDimPortal extends BlockPortal
3
{
4
	public void onNeighborBlockChange(World world, BlockPos pos, IBlockState state, Block neighborBlock)
5
	{
6
		EnumFacing.Axis axis = (EnumFacing.Axis) state.getValue(AXIS);
7
		BlockDimPortal.Size size;
8
9
		if (axis == EnumFacing.Axis.X)
10
		{
11
			size = new BlockDimPortal.Size(world, pos, EnumFacing.Axis.X);
12
13
			if (!size.isValidPortal() || size.amountOfPortals < size.sizeXZ * size.sizeY)
14
			{
15
				world.setBlockState(pos, Blocks.air.getDefaultState());
16
			}
17
		}
18
		else if (axis == EnumFacing.Axis.Z)
19
		{
20
			size = new BlockDimPortal.Size(world, pos, EnumFacing.Axis.Z);
21
22
			if (!size.isValidPortal() || size.amountOfPortals < size.sizeXZ * size.sizeY)
23
			{
24
				world.setBlockState(pos, Blocks.air.getDefaultState());
25
			}
26
		}
27
	}
28
29
	@SideOnly(Side.CLIENT)
30
	public void randomDisplayTick(World world, BlockPos pos, IBlockState state, Random rand)
31
	{
32
        	if (rand.nextInt(100) == 0)
33
        	{
34
        		world.playSound((double)pos.getX() + 0.5D, (double)pos.getY() + 0.5D, (double)pos.getZ() + 0.5D, 
35
			"portal.portal", 0.75F, rand.nextFloat() * 0.1F + 1.2F, false);
36
        	}
37
38
		for (int i = 0; i < 4; ++i)
39
		{
40
			double d0 = (double) ((float) pos.getX() + rand.nextFloat());
41
			double d1 = (double) ((float) pos.getY() + rand.nextFloat());
42
			double d2 = (double) ((float) pos.getZ() + rand.nextFloat());
43
			double d3 = ((double) rand.nextFloat() - 0.5D) * 0.5D;
44
			double d4 = ((double) rand.nextFloat() - 0.5D) * 0.5D;
45
			double d5 = ((double) rand.nextFloat() - 0.5D) * 0.5D;
46
			int j = rand.nextInt(2) * 2 - 1;
47
48
			if (world.getBlockState(pos.west()).getBlock() != this && world.getBlockState(pos.east()).getBlock()
49
			!= this)
50
			{
51
				d0 = (double) pos.getX() + 0.5D + 0.25D * (double) j;
52
				d3 = (double) (rand.nextFloat() * 2.0F * (float) j);
53
			}
54
			else
55
			{
56
				d2 = (double) pos.getZ() + 0.5D + 0.25D * (double) j;
57
				d5 = (double) (rand.nextFloat() * 2.0F * (float) j);
58
			}
59
60
			EntityDimPortalFX entitydimportalfx = new EntityDimPortalFX(world, x, y, z, vx, vy, vz);
61
			FMLClientHandler.instance().getClient().effectRenderer.addEffect(entityfx);
62
		}
63
	}
64
65
	public void onEntityCollidedWithBlock(World world, BlockPos pos, IBlockState state, Entity entity)
66
	{
67
		if (entity.ridingEntity == null && entity.riddenByEntity == null && !world.isRemote)
68
		{
69
			Dim.teleportEntityToDimension(entity, Dim.getDimensionId(), new
70
			TeleporterDim(MinecraftServer.getServer().worldServerForDimension(Dim.getDimensionId())));
71
		}
72
	}
73
74
	public void updateTick(World world, BlockPos pos, IBlockState state, Random rand) {}
75
76
	public boolean func_176548_d(World world, BlockPos pos)
77
	{
78
		BlockDimPortal.Size size = new BlockDimPortal.Size(world, pos, EnumFacing.Axis.X);
79
80
		if (size.isValidPortal() && size.amountOfPortals == 0)
81
		{
82
			size.createPortalBlocks();
83
			return true;
84
		}
85
		else
86
		{
87
			BlockDimPortal.Size size1 = new BlockDimPortal.Size(world, pos, EnumFacing.Axis.Z);
88
89
			if (size1.isValidPortal() && size.amountOfPortals == 0)
90
			{
91
				size.createPortalBlocks();
92
				return true;
93
			}
94
			else
95
			{
96
				return false;
97
			}
98
		}
99
	}
100
101
	public static class Size
102
	{
103
		private final World world;
104
		private final EnumFacing.Axis axis;
105
		private final EnumFacing south_west;
106
		private final EnumFacing north_east;
107
		private int amountOfPortals = 0;
108
		private BlockPos blockpos;
109
		private int sizeY;
110
		private int sizeXZ;
111
112
		public Size(World world, BlockPos blockpos, EnumFacing.Axis enumfacingAxis)
113
		{
114
			this.world = world;
115
			this.axis = enumfacingAxis;
116
117
			if (enumfacingAxis == EnumFacing.Axis.X)
118
			{
119
				this.north_east = EnumFacing.EAST;
120
				this.south_west = EnumFacing.WEST;
121
			}
122
			else
123
			{
124
				this.north_east = EnumFacing.NORTH;
125
				this.south_west = EnumFacing.SOUTH;
126
			}
127
128
			for (BlockPos blockpos1 = blockpos; blockpos.getY() > blockpos1.getY() - 21 && blockpos.getY() > 0 &&
129
			this.isBlockAllowed(world.getBlockState(blockpos.down()).getBlock()); blockpos = blockpos.down())
130
			{
131
				;
132
			}
133
134
			int i = this.getPortalXZSize(blockpos, this.north_east) - 1;
135
136
			if (i >= 0)
137
			{
138
				this.blockpos = blockpos.offset(this.north_east, i);
139
				this.sizeXZ = this.getPortalXZSize(this.blockpos, this.south_west);
140
141
				if (this.sizeXZ < 2 || this.sizeXZ > 21)
142
				{
143
					this.blockpos = null;
144
					this.sizeXZ = 0;
145
				}
146
			}
147
148
			if (this.blockpos != null)
149
			{
150
				this.sizeY = this.getPortalHeight();
151
			}
152
		}
153
154
		protected int getPortalXZSize(BlockPos blockspos, EnumFacing enumfacing)
155
		{
156
			int i;
157
158
			for (i = 0; i < 22; ++i)
159
			{
160
				BlockPos blockpos1 = blockspos.offset(enumfacing, i);
161
162
				if (!this.isBlockAllowed(this.world.getBlockState(blockpos1).getBlock()) ||
163
				this.world.getBlockState(blockpos1.down()).getBlock() != Blocks.quartz_block)
164
				{
165
					break;
166
				}
167
			}
168
169
			Block block = this.world.getBlockState(blockspos.offset(enumfacing, i)).getBlock();
170
			return block == Blocks.quartz_block ? i : 0;
171
		}
172
173
		protected int getPortalHeight()
174
		{
175
			int i;
176
			label56:
177
178
			for (this.sizeY = 0; this.sizeY < 21; ++this.sizeY)
179
			{
180
				for (i = 0; i < this.sizeXZ; ++i)
181
				{
182
					BlockPos blockpos = this.blockpos.offset(this.south_west, i).up(this.sizeY);
183
					Block block = this.world.getBlockState(blockpos).getBlock();
184
185
					if (!this.isBlockAllowed(block))
186
					{
187
						break label56;
188
					}
189
190
					if (block == DimBlocks.dim_portal)
191
					{
192
						++this.amountOfPortals;
193
					}
194
195
					if (i == 0)
196
					{
197
						block = this.world.getBlockState(blockpos.offset(this.north_east)).getBlock();
198
199
						if (block != Blocks.quartz_block)
200
						{
201
							break label56;
202
						}
203
					}
204
					else if (i == this.sizeXZ - 1)
205
					{
206
						block = this.world.getBlockState(blockpos.offset(this.south_west)).getBlock();
207
208
						if (block != Blocks.quartz_block)
209
						{
210
							break label56;
211
						}
212
					}
213
				}
214
			}
215
216
			for (i = 0; i < this.sizeXZ; ++i)
217
			{
218
				if (this.world.getBlockState(this.blockpos.offset(this.south_west, i).up(this.sizeY)).getBlock()
219
				!= Blocks.quartz_block)
220
				{
221
					this.sizeY = 0;
222
					break;
223
				}
224
			}
225
226
			if (this.sizeY <= 21 && this.sizeY >= 3)
227
			{
228
				return this.sizeY;
229
			}
230
			else
231
			{
232
				this.blockpos = null;
233
				this.sizeXZ = 0;
234
				this.sizeY = 0;
235
				return 0;
236
			}
237
		}
238
239
		protected boolean isBlockAllowed(Block block)
240
		{
241
			return block.getMaterial() == Material.air || block == Blocks.water || block == Blocks.flowing_water ||
242
			block == DimBlocks.dim_portal;
243
		}
244
245
		public boolean isValidPortal()
246
		{
247
			return this.blockpos != null && this.sizeXZ >= 2 && this.sizeXZ <= 21 && this.sizeY >= 3 && this.sizeY
248
			<= 21;
249
		}
250
251
		public void createPortalBlocks()
252
		{
253
			for (int i = 0; i < this.sizeXZ; ++i)
254
			{
255
				BlockPos blockpos = this.blockpos.offset(this.south_west, i);
256
257
				for (int j = 0; j < this.sizeY; ++j)
258
				{
259
					this.world.setBlockState(blockpos.up(j),
260
					DimBlocks.dim_portal.getDefaultState().withProperty(BlockPortal.AXIS, this.axis), 2);
261
				}
262
			}
263
		}
264
	}
265
}
266
	// Code from Main Class to teleport entity
267
268
	public static void teleportEntityToDimension(Entity entity, int dimensionId, Teleporter teleporter)
269
	{
270
		if (!entity.worldObj.isRemote && !entity.isDead)
271
		{
272
			entity.worldObj.theProfiler.startSection("changeDimension");
273
			MinecraftServer minecraftserver = MinecraftServer.getServer();
274
			int j = entity.dimension;
275
			WorldServer worldserver = minecraftserver.worldServerForDimension(j);
276
			WorldServer worldserver1 = minecraftserver.worldServerForDimension(dimensionId);
277
			entity.dimension = dimensionId;
278
279
			if (j == dimensionId)
280
			{
281
				worldserver1 = minecraftserver.worldServerForDimension(0);
282
				entity.dimension = 0;
283
			}
284
285
			entity.worldObj.removeEntity(entity);
286
			entity.isDead = false;
287
			entity.worldObj.theProfiler.startSection("reposition");
288
			minecraftserver.getConfigurationManager().transferEntityToWorld(entity, j, worldserver, worldserver1,
289
			teleporter);
290
			entity.worldObj.theProfiler.endStartSection("reloading");
291
			Entity entity1 = EntityList.createEntityByName(EntityList.getEntityString(entity), worldserver1);
292
293
			if (entity1 != null)
294
			{
295
				entity1.copyDataFromOld(entity);
296
297
				if (j == dimensionId)
298
				{
299
					BlockPos blockpos = entity.worldObj
300
					.getTopSolidOrLiquidBlock(worldserver1.getSpawnPoint());
301
					entity1.moveToBlockPosAndAngles(blockpos, entity1.rotationYaw, entity1.rotationPitch);
302
				}
303
304
				worldserver1.spawnEntityInWorld(entity1);
305
			}
306
307
			entity.isDead = true;
308
			entity.worldObj.theProfiler.endSection();
309
			worldserver.resetUpdateEntityTick();
310
			worldserver1.resetUpdateEntityTick();
311
			entity.worldObj.theProfiler.endSection();
312
		}
313
	}
314
315
// Teleport Code
316
317
public class TeleporterDim extends Teleporter
318
{
319
	private WorldServer worldServerInstance;
320
	private final Random random;
321
	private final LongHashMap destinationCoordinateCache = new LongHashMap();
322
	private final List destinationCoordinateKeys = Lists.newArrayList();
323
324
	public TeleporterDim(WorldServer world)
325
	{
326
		super(world);
327
		this.worldServerInstance = world;
328
		this.worldServerInstance.customTeleporters.add(this);
329
		this.random = new Random(world.getSeed());
330
	}
331
332
	public void placeInPortal(Entity entity, float rotationYaw)
333
	{
334
		if (this.worldServerInstance.provider.getDimensionId() != 1)
335
		{
336
			if (!this.placeInExistingPortal(entity, rotationYaw))
337
			{
338
				this.makePortal(entity);
339
				this.placeInExistingPortal(entity, rotationYaw);
340
			}
341
		}
342
		else
343
		{
344
			int i = MathHelper.floor_double(entity.posX);
345
			int j = MathHelper.floor_double(entity.posY) - 1;
346
			int k = MathHelper.floor_double(entity.posZ);
347
			byte b0 = 1;
348
			byte b1 = 0;
349
350
			for (int l = -2; l <= 2; ++l)
351
			{
352
				for (int i1 = -2; i1 <= 2; ++i1)
353
				{
354
					for (int j1 = -1; j1 < 3; ++j1)
355
					{
356
						int k1 = i + i1 * b0 + l * b1;
357
						int l1 = j + j1;
358
						int i2 = k + i1 * b1 - l * b0;
359
						boolean flag = j1 < 0;
360
						this.worldServerInstance.setBlockState(new BlockPos(k1, l1, i2), flag ? Blocks.quartz_block.getDefaultState() : Blocks.air.getDefaultState());
361
					}
362
				}
363
			}
364
365
			entity.setLocationAndAngles((double) i, (double) j, (double) k, entity.rotationYaw, 0.0F);
366
			entity.motionX = entity.motionY = entity.motionZ = 0.0D;
367
		}
368
	}
369
370
	public boolean placeInExistingPortal(Entity entity, float f)
371
	{
372
		boolean flag = true;
373
		double d0 = -1.0D;
374
		int i = MathHelper.floor_double(entity.posX);
375
		int j = MathHelper.floor_double(entity.posZ);
376
		boolean flag1 = true;
377
		Object object = BlockPos.ORIGIN;
378
		long k = ChunkCoordIntPair.chunkXZ2Int(i, j);
379
380
		if (this.destinationCoordinateCache.containsItem(k))
381
		{
382
			TeleporterDim.PortalPosition portalposition = (TeleporterDim.PortalPosition)
383
			this.destinationCoordinateCache.getValueByKey(k);
384
			d0 = 0.0D;
385
			object = portalposition;
386
			portalposition.lastUpdateTime = this.worldServerInstance.getTotalWorldTime();
387
			flag1 = false;
388
		}
389
		else
390
		{
391
			BlockPos blockpos4 = new BlockPos(entity);
392
393
			for (int l = -128; l <= 128; ++l)
394
			{
395
				BlockPos blockpos1;
396
397
				for (int i1 = -128; i1 <= 128; ++i1)
398
				{
399
					for (BlockPos blockpos = blockpos4.add(l, this.worldServerInstance.getActualHeight() - 1
400
					- blockpos4.getY(), i1); blockpos.getY() >= 0; blockpos = blockpos1)
401
					{
402
						blockpos1 = blockpos.down();
403
404
						if (this.worldServerInstance.getBlockState(blockpos).getBlock() ==
405
						DimBlocks.dim_portal)
406
						{
407
							while (this.worldServerInstance.getBlockState(blockpos1 
408
							blockpos.down()).getBlock() == DimBlocks.dim_portal)
409
							{
410
								blockpos = blockpos1;
411
							}
412
413
							double d1 = blockpos.distanceSq(blockpos4);
414
415
							if (d0 < 0.0D || d1 < d0)
416
							{
417
								d0 = d1;
418
								object = blockpos;
419
							}
420
						}
421
					}
422
				}
423
			}
424
		}
425
426
		if (d0 >= 0.0D)
427
		{
428
			if (flag1)
429
			{
430
				this.destinationCoordinateCache.add(k, new TeleporterDim.PortalPosition((BlockPos) object,
431
				this.worldServerInstance.getTotalWorldTime()));
432
				this.destinationCoordinateKeys.add(Long.valueOf(k));
433
			}
434
435
			double d4 = (double) ((BlockPos) object).getX() + 0.5D;
436
			double d5 = (double) ((BlockPos) object).getY() + 0.5D;
437
			double d6 = (double) ((BlockPos) object).getZ() + 0.5D;
438
			EnumFacing enumfacing = null;
439
440
			if (this.worldServerInstance.getBlockState(((BlockPos) object).west()).getBlock() ==
441
			DimBlocks.dim_portal)
442
			{
443
				enumfacing = EnumFacing.NORTH;
444
			}
445
446
			if (this.worldServerInstance.getBlockState(((BlockPos) object).east()).getBlock() ==
447
			DimBlocks.dim_portal)
448
			{
449
				enumfacing = EnumFacing.SOUTH;
450
			}
451
452
			if (this.worldServerInstance.getBlockState(((BlockPos) object).north()).getBlock() ==
453
			DimBlocks.dim_portal)
454
			{
455
				enumfacing = EnumFacing.EAST;
456
			}
457
458
			if (this.worldServerInstance.getBlockState(((BlockPos) object).south()).getBlock() ==
459
			DimBlocks.dim_portal)
460
			{
461
				enumfacing = EnumFacing.WEST;
462
			}
463
464
			EnumFacing enumfacing1 = EnumFacing.getHorizontal(entity.getTeleportDirection());
465
466
			if (enumfacing != null)
467
			{
468
				EnumFacing enumfacing2 = enumfacing.rotateYCCW();
469
				BlockPos blockpos2 = ((BlockPos) object).offset(enumfacing);
470
				boolean flag2 = this.isAirBlock(blockpos2);
471
				boolean flag3 = this.isAirBlock(blockpos2.offset(enumfacing));
472
473
				if (flag3 && flag2)
474
				{
475
					object = ((BlockPos) object).offset(enumfacing2);
476
					enumfacing = enumfacing.getOpposite();
477
					enumfacing2 = enumfacing2.getOpposite();
478
					BlockPos blockpos3 = ((BlockPos) object).offset(enumfacing);
479
					flag2 = this.isAirBlock(blockpos3);
480
					flag3 = this.isAirBlock(blockpos3.offset(enumfacing2));
481
				}
482
483
				float f6 = 0.5F;
484
				float f1 = 0.5F;
485
486
				if (!flag3 && flag2)
487
				{
488
					f6 = 1.0F;
489
				}
490
				else if (flag3 && !flag2)
491
				{
492
					f6 = 0.0F;
493
				}
494
				else if (flag3)
495
				{
496
					f1 = 0.0F;
497
				}
498
499
                d4 = (double)((BlockPos)object).getX() + 0.5D;
500
                d5 = (double)((BlockPos)object).getY() + 0.5D;
501
                d6 = (double)((BlockPos)object).getZ() + 0.5D;
502
                d4 += (double)((float)enumfacing2.getFrontOffsetX() * f6 + (float)enumfacing.getFrontOffsetX() * f1);
503
                d6 += (double)((float)enumfacing2.getFrontOffsetZ() * f6 + (float)enumfacing.getFrontOffsetZ() * f1);
504
                float f2 = 0.0F;
505
                float f3 = 0.0F;
506
                float f4 = 0.0F;
507
                float f5 = 0.0F;
508
509
                if (enumfacing == enumfacing1)
510
                {
511
                    f2 = 1.0F;
512
                    f3 = 1.0F;
513
                }
514
                else if (enumfacing == enumfacing1.getOpposite())
515
				{
516
					f2 = -1.0F;
517
					f3 = -1.0F;
518
				}
519
				else if (enumfacing == enumfacing1.rotateY())
520
				{
521
					f4 = 1.0F;
522
					f5 = -1.0F;
523
				}
524
				else
525
				{
526
					f4 = -1.0F;
527
					f5 = 1.0F;
528
				}
529
530
				double d2 = entity.motionX;
531
				double d3 = entity.motionZ;
532
				entity.motionX = d2 * (double) f2 + d3 * (double) f5;
533
				entity.motionZ = d2 * (double) f4 + d3 * (double) f3;
534
				entity.rotationYaw = f - (float) (enumfacing1.getHorizontalIndex() * 90) + (float)
535
				(enumfacing.getHorizontalIndex() * 90);
536
			}
537
			else
538
			{
539
				entity.motionX = entity.motionY = entity.motionZ = 0.0D;
540
			}
541
542
			entity.setLocationAndAngles(d4, d5, d6, entity.rotationYaw, entity.rotationPitch);
543
			return true;
544
		}
545
		else
546
		{
547
			return false;
548
		}
549
	}
550
551
	private boolean isAirBlock(BlockPos pos)
552
	{
553
		return !this.worldServerInstance.isAirBlock(pos) || !this.worldServerInstance.isAirBlock(pos.up());
554
	}
555
556
	public boolean makePortal(Entity entity)
557
	{
558
		byte b0 = 16;
559
		double d0 = -1.0D;
560
		int i = MathHelper.floor_double(entity.posX);
561
		int j = MathHelper.floor_double(entity.posY);
562
		int k = MathHelper.floor_double(entity.posZ);
563
		int l = i;
564
		int i1 = j;
565
		int j1 = k;
566
		int k1 = 0;
567
		int l1 = this.random.nextInt(4);
568
		int i2;
569
		double d1;
570
		int k2;
571
		double d2;
572
		int i3;
573
		int j3;
574
		int k3;
575
		int l3;
576
		int i4;
577
		int j4;
578
		int k4;
579
		int l4;
580
		int i5;
581
		double d3;
582
		double d4;
583
584
		for (i2 = i - b0; i2 <= i + b0; ++i2)
585
		{
586
			d1 = (double) i2 + 0.5D - entity.posX;
587
588
			for (k2 = k - b0; k2 <= k + b0; ++k2)
589
			{
590
				d2 = (double) k2 + 0.5D - entity.posZ;
591
				label271:
592
593
				for (i3 = this.worldServerInstance.getActualHeight() - 1; i3 >= 0; --i3)
594
				{
595
					if (this.worldServerInstance.isAirBlock(new BlockPos(i2, i3, k2)))
596
					{
597
						while (i3 > 0 && this.worldServerInstance.isAirBlock(new BlockPos(i2, i3 - 1,
598
						k2)))
599
						{
600
							--i3;
601
						}
602
603
						for (j3 = l1; j3 < l1 + 4; ++j3)
604
						{
605
							k3 = j3 % 2;
606
							l3 = 1 - k3;
607
608
							if (j3 % 4 >= 2)
609
							{
610
								k3 = -k3;
611
								l3 = -l3;
612
							}
613
614
							for (i4 = 0; i4 < 3; ++i4)
615
							{
616
								for (j4 = 0; j4 < 4; ++j4)
617
								{
618
									for (k4 = -1; k4 < 4; ++k4)
619
									{
620
										l4 = i2 + (j4 - 1) * k3 + i4 * l3;
621
										i5 = i3 + k4;
622
										int j5 = k2 + (j4 - 1) * l3 - i4 * k3;
623
624
										if (k4 < 0 &&
625
								!this.worldServerInstance.getBlockState(new BlockPos(l4, i5,
626
								j5)).getBlock().getMaterial().isSolid() || k4 >= 0 &&
627
								!this.worldServerInstance.isAirBlock(new BlockPos(l4, i5, j5)))
628
										{
629
											continue label271;
630
										}
631
									}
632
								}
633
							}
634
635
							d3 = (double) i3 + 0.5D - entity.posY;
636
							d4 = d1 * d1 + d3 * d3 + d2 * d2;
637
638
							if (d0 < 0.0D || d4 < d0)
639
							{
640
								d0 = d4;
641
								l = i2;
642
								i1 = i3;
643
								j1 = k2;
644
								k1 = j3 % 4;
645
							}
646
						}
647
					}
648
				}
649
			}
650
		}
651
652
		if (d0 < 0.0D)
653
		{
654
			for (i2 = i - b0; i2 <= i + b0; ++i2)
655
			{
656
				d1 = (double) i2 + 0.5D - entity.posX;
657
658
				for (k2 = k - b0; k2 <= k + b0; ++k2)
659
				{
660
					d2 = (double) k2 + 0.5D - entity.posZ;
661
					label219:
662
663
					for (i3 = this.worldServerInstance.getActualHeight() - 1; i3 >= 0; --i3)
664
					{
665
						if (this.worldServerInstance.isAirBlock(new BlockPos(i2, i3, k2)))
666
						{
667
							while (i3 > 0 && this.worldServerInstance.isAirBlock(new BlockPos(i2, i3
668
							- 1, k2)))
669
							{
670
								--i3;
671
							}
672
673
							for (j3 = l1; j3 < l1 + 2; ++j3)
674
							{
675
								k3 = j3 % 2;
676
								l3 = 1 - k3;
677
678
								for (i4 = 0; i4 < 4; ++i4)
679
								{
680
									for (j4 = -1; j4 < 4; ++j4)
681
									{
682
										k4 = i2 + (i4 - 1) * k3;
683
										l4 = i3 + j4;
684
										i5 = k2 + (i4 - 1) * l3;
685
686
										if (j4 < 0 &&
687
								!this.worldServerInstance.getBlockState(new BlockPos(k4, l4,
688
								i5)).getBlock().getMaterial().isSolid() || j4 >= 0 &&
689
								!this.worldServerInstance.isAirBlock(new BlockPos(k4, l4, i5)))
690
										{
691
											continue label219;
692
										}
693
									}
694
								}
695
696
								d3 = (double) i3 + 0.5D - entity.posY;
697
								d4 = d1 * d1 + d3 * d3 + d2 * d2;
698
699
								if (d0 < 0.0D || d4 < d0)
700
								{
701
									d0 = d4;
702
									l = i2;
703
									i1 = i3;
704
									j1 = k2;
705
									k1 = j3 % 2;
706
								}
707
							}
708
						}
709
					}
710
				}
711
			}
712
		}
713
714
		int k5 = l;
715
		int j2 = i1;
716
		k2 = j1;
717
		int l5 = k1 % 2;
718
		int l2 = 1 - l5;
719
720
		if (k1 % 4 >= 2)
721
		{
722
			l5 = -l5;
723
			l2 = -l2;
724
		}
725
726
		if (d0 < 0.0D)
727
		{
728
			i1 = MathHelper.clamp_int(i1, 70, this.worldServerInstance.getActualHeight() - 10);
729
			j2 = i1;
730
731
			for (i3 = -1; i3 <= 1; ++i3)
732
			{
733
				for (j3 = 1; j3 < 3; ++j3)
734
				{
735
					for (k3 = -1; k3 < 3; ++k3)
736
					{
737
						l3 = k5 + (j3 - 1) * l5 + i3 * l2;
738
						i4 = j2 + k3;
739
						j4 = k2 + (j3 - 1) * l2 - i3 * l5;
740
						boolean flag = k3 < 0;
741
						this.worldServerInstance.setBlockState(new BlockPos(l3, i4, j4), flag ?
742
						Blocks.quartz_block.getDefaultState() : Blocks.air.getDefaultState());
743
					}
744
				}
745
			}
746
		}
747
748
		IBlockState iblockstate = DimBlocks.dim_portal.getDefaultState().withProperty(BlockPortal.AXIS, l5 != 0 ?
749
		EnumFacing.Axis.X : EnumFacing.Axis.Z);
750
751
		for (j3 = 0; j3 < 4; ++j3)
752
		{
753
			for (k3 = 0; k3 < 4; ++k3)
754
			{
755
				for (l3 = -1; l3 < 4; ++l3)
756
				{
757
					i4 = k5 + (k3 - 1) * l5;
758
					j4 = j2 + l3;
759
					k4 = k2 + (k3 - 1) * l2;
760
					boolean flag1 = k3 == 0 || k3 == 3 || l3 == -1 || l3 == 3;
761
					this.worldServerInstance.setBlockState(new BlockPos(i4, j4, k4), flag1 ?
762
					Blocks.quartz_block.getDefaultState() : iblockstate, 2);
763
				}
764
			}
765
766
			for (k3 = 0; k3 < 4; ++k3)
767
			{
768
				for (l3 = -1; l3 < 4; ++l3)
769
				{
770
					i4 = k5 + (k3 - 1) * l5;
771
					j4 = j2 + l3;
772
					k4 = k2 + (k3 - 1) * l2;
773
					this.worldServerInstance.notifyNeighborsOfStateChange(new BlockPos(i4, j4, k4),
774
					this.worldServerInstance.getBlockState(new BlockPos(i4, j4, k4)).getBlock());
775
				}
776
			}
777
		}
778
779
		return true;
780
	}
781
782
	/**
783
	 * called periodically to remove out-of-date portal locations from the cache list. Argument par1 is a
784
	 * WorldServer.getTotalWorldTime() value.
785
	 */
786
	public void removeStalePortalLocations(long totalWorldTime)
787
	{
788
		if (totalWorldTime % 100L == 0L)
789
		{
790
			Iterator iterator = this.destinationCoordinateKeys.iterator();
791
			long j = totalWorldTime - 600L;
792
793
			while (iterator.hasNext())
794
			{
795
				Long olong = (Long) iterator.next();
796
				TeleporterDim.PortalPosition portalposition = (TeleporterDim.PortalPosition)
797
				this.destinationCoordinateCache.getValueByKey(olong.longValue());
798
799
				if (portalposition == null || portalposition.lastUpdateTime < j)
800
				{
801
					iterator.remove();
802
					this.destinationCoordinateCache.remove(olong.longValue());
803
				}
804
			}
805
		}
806
	}
807
808
	public class PortalPosition extends BlockPos
809
	{
810
		public long lastUpdateTime;
811
812
		public PortalPosition(BlockPos pos, long worldTime)
813
		{
814
			super(pos.getX(), pos.getY(), pos.getZ());
815
			this.lastUpdateTime = worldTime;
816
		}
817
	}
818
}