Advertisement
Guest User

Untitled

a guest
Apr 29th, 2013
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 17.48 KB | None | 0 0
  1. import java.util.ArrayList;
  2. import java.util.Iterator;
  3. import java.util.List;
  4. import java.util.Random;
  5. import net.minecraft.block.Block;
  6. import net.minecraft.entity.Entity;
  7. import net.minecraft.util.Direction;
  8. import net.minecraft.util.LongHashMap;
  9. import net.minecraft.util.MathHelper;
  10. import net.minecraft.world.ChunkCoordIntPair;
  11. import net.minecraft.world.PortalPosition;
  12. import net.minecraft.world.Teleporter;
  13. import net.minecraft.world.WorldServer;
  14.  
  15. public class MpsTeleporter extends Teleporter
  16. {
  17. private final WorldServer worldServerInstance;
  18.  
  19. /** A private Random() function in Teleporter */
  20. private final Random random;
  21. private final LongHashMap field_85191_c = new LongHashMap();
  22. private final List field_85190_d = new ArrayList();
  23.  
  24. public MpsTeleporter(WorldServer par1WorldServer)
  25. {
  26. super(par1WorldServer);
  27. this.worldServerInstance = par1WorldServer;
  28. this.random = new Random(par1WorldServer.getSeed());
  29. }
  30.  
  31. /**
  32. * Place an entity in a nearby portal, creating one if necessary.
  33. */
  34. public void placeInPortal(Entity par1Entity, double par2, double par4, double par6, float par8)
  35. {
  36. if (this.worldServerInstance.provider.dimensionId != 1)
  37. {
  38. if (!this.placeInExistingPortal(par1Entity, par2, par4, par6, par8))
  39. {
  40. this.makePortal(par1Entity);
  41. this.placeInExistingPortal(par1Entity, par2, par4, par6, par8);
  42. }
  43. }
  44. else
  45. {
  46. int i = MathHelper.floor_double(par1Entity.posX);
  47. int j = MathHelper.floor_double(par1Entity.posY) - 1;
  48. int k = MathHelper.floor_double(par1Entity.posZ);
  49. byte b0 = 1;
  50. byte b1 = 0;
  51.  
  52. for (int l = -2; l <= 2; ++l)
  53. {
  54. for (int i1 = -2; i1 <= 2; ++i1)
  55. {
  56. for (int j1 = -1; j1 < 3; ++j1)
  57. {
  58. int k1 = i + i1 * b0 + l * b1;
  59. int l1 = j + j1;
  60. int i2 = k + i1 * b1 - l * b0;
  61. boolean flag = j1 < 0;
  62. this.worldServerInstance.setBlock(k1, l1, i2, flag ? MainBlock.zenBlock.blockID : 0);
  63. }
  64. }
  65. }
  66.  
  67. par1Entity.setLocationAndAngles((double)i, (double)j, (double)k, par1Entity.rotationYaw, 0.0F);
  68. par1Entity.motionX = par1Entity.motionY = par1Entity.motionZ = 0.0D;
  69. }
  70. }
  71.  
  72. /**
  73. * Place an entity in a nearby portal which already exists.
  74. */
  75. public boolean placeInExistingPortal(Entity par1Entity, double par2, double par4, double par6, float par8)
  76. {
  77. short short1 = 128;
  78. double d3 = -1.0D;
  79. int i = 0;
  80. int j = 0;
  81. int k = 0;
  82. int l = MathHelper.floor_double(par1Entity.posX);
  83. int i1 = MathHelper.floor_double(par1Entity.posZ);
  84. long j1 = ChunkCoordIntPair.chunkXZ2Int(l, i1);
  85. boolean flag = true;
  86. double d4;
  87. int k1;
  88.  
  89. if (this.field_85191_c.containsItem(j1))
  90. {
  91. PortalPosition portalposition = (PortalPosition)this.field_85191_c.getValueByKey(j1);
  92. d3 = 0.0D;
  93. i = portalposition.posX;
  94. j = portalposition.posY;
  95. k = portalposition.posZ;
  96. portalposition.field_85087_d = this.worldServerInstance.getTotalWorldTime();
  97. flag = false;
  98. }
  99. else
  100. {
  101. for (k1 = l - short1; k1 <= l + short1; ++k1)
  102. {
  103. double d5 = (double)k1 + 0.5D - par1Entity.posX;
  104.  
  105. for (int l1 = i1 - short1; l1 <= i1 + short1; ++l1)
  106. {
  107. double d6 = (double)l1 + 0.5D - par1Entity.posZ;
  108.  
  109. for (int i2 = this.worldServerInstance.getActualHeight() - 1; i2 >= 0; --i2)
  110. {
  111. if (this.worldServerInstance.getBlockId(k1, i2, l1) == MpsPortalBlock.mPortal.blockID)
  112. {
  113. while (this.worldServerInstance.getBlockId(k1, i2 - 1, l1) == MpsPortalBlock.mPortal.blockID)
  114. {
  115. --i2;
  116. }
  117.  
  118. d4 = (double)i2 + 0.5D - par1Entity.posY;
  119. double d7 = d5 * d5 + d4 * d4 + d6 * d6;
  120.  
  121. if (d3 < 0.0D || d7 < d3)
  122. {
  123. d3 = d7;
  124. i = k1;
  125. j = i2;
  126. k = l1;
  127. }
  128. }
  129. }
  130. }
  131. }
  132. }
  133.  
  134. if (d3 >= 0.0D)
  135. {
  136. if (flag)
  137. {
  138. this.field_85191_c.add(j1, new PortalPosition(this, i, j, k, this.worldServerInstance.getTotalWorldTime()));
  139. this.field_85190_d.add(Long.valueOf(j1));
  140. }
  141.  
  142. double d8 = (double)i + 0.5D;
  143. double d9 = (double)j + 0.5D;
  144. d4 = (double)k + 0.5D;
  145. int j2 = -1;
  146.  
  147. if (this.worldServerInstance.getBlockId(i - 1, j, k) == MpsPortalBlock.mPortal.blockID)
  148. {
  149. j2 = 2;
  150. }
  151.  
  152. if (this.worldServerInstance.getBlockId(i + 1, j, k) == MpsPortalBlock.mPortal.blockID)
  153. {
  154. j2 = 0;
  155. }
  156.  
  157. if (this.worldServerInstance.getBlockId(i, j, k - 1) == MpsPortalBlock.mPortal.blockID)
  158. {
  159. j2 = 3;
  160. }
  161.  
  162. if (this.worldServerInstance.getBlockId(i, j, k + 1) == MpsPortalBlock.mPortal.blockID)
  163. {
  164. j2 = 1;
  165. }
  166.  
  167. int k2 = par1Entity.func_82148_at();
  168.  
  169. if (j2 > -1)
  170. {
  171. int l2 = Direction.field_71578_g[j2];
  172. int i3 = Direction.offsetX[j2];
  173. int j3 = Direction.offsetZ[j2];
  174. int k3 = Direction.offsetX[l2];
  175. int l3 = Direction.offsetZ[l2];
  176. boolean flag1 = !this.worldServerInstance.isAirBlock(i + i3 + k3, j, k + j3 + l3) || !this.worldServerInstance.isAirBlock(i + i3 + k3, j + 1, k + j3 + l3);
  177. boolean flag2 = !this.worldServerInstance.isAirBlock(i + i3, j, k + j3) || !this.worldServerInstance.isAirBlock(i + i3, j + 1, k + j3);
  178.  
  179. if (flag1 && flag2)
  180. {
  181. j2 = Direction.footInvisibleFaceRemap[j2];
  182. l2 = Direction.footInvisibleFaceRemap[l2];
  183. i3 = Direction.offsetX[j2];
  184. j3 = Direction.offsetZ[j2];
  185. k3 = Direction.offsetX[l2];
  186. l3 = Direction.offsetZ[l2];
  187. k1 = i - k3;
  188. d8 -= (double)k3;
  189. int i4 = k - l3;
  190. d4 -= (double)l3;
  191. flag1 = !this.worldServerInstance.isAirBlock(k1 + i3 + k3, j, i4 + j3 + l3) || !this.worldServerInstance.isAirBlock(k1 + i3 + k3, j + 1, i4 + j3 + l3);
  192. flag2 = !this.worldServerInstance.isAirBlock(k1 + i3, j, i4 + j3) || !this.worldServerInstance.isAirBlock(k1 + i3, j + 1, i4 + j3);
  193. }
  194.  
  195. float f1 = 0.5F;
  196. float f2 = 0.5F;
  197.  
  198. if (!flag1 && flag2)
  199. {
  200. f1 = 1.0F;
  201. }
  202. else if (flag1 && !flag2)
  203. {
  204. f1 = 0.0F;
  205. }
  206. else if (flag1 && flag2)
  207. {
  208. f2 = 0.0F;
  209. }
  210.  
  211. d8 += (double)((float)k3 * f1 + f2 * (float)i3);
  212. d4 += (double)((float)l3 * f1 + f2 * (float)j3);
  213. float f3 = 0.0F;
  214. float f4 = 0.0F;
  215. float f5 = 0.0F;
  216. float f6 = 0.0F;
  217.  
  218. if (j2 == k2)
  219. {
  220. f3 = 1.0F;
  221. f4 = 1.0F;
  222. }
  223. else if (j2 == Direction.footInvisibleFaceRemap[k2])
  224. {
  225. f3 = -1.0F;
  226. f4 = -1.0F;
  227. }
  228. else if (j2 == Direction.enderEyeMetaToDirection[k2])
  229. {
  230. f5 = 1.0F;
  231. f6 = -1.0F;
  232. }
  233. else
  234. {
  235. f5 = -1.0F;
  236. f6 = 1.0F;
  237. }
  238.  
  239. double d10 = par1Entity.motionX;
  240. double d11 = par1Entity.motionZ;
  241. par1Entity.motionX = d10 * (double)f3 + d11 * (double)f6;
  242. par1Entity.motionZ = d10 * (double)f5 + d11 * (double)f4;
  243. par1Entity.rotationYaw = par8 - (float)(k2 * 90) + (float)(j2 * 90);
  244. }
  245. else
  246. {
  247. par1Entity.motionX = par1Entity.motionY = par1Entity.motionZ = 0.0D;
  248. }
  249.  
  250. par1Entity.setLocationAndAngles(d8, d9, d4, par1Entity.rotationYaw, par1Entity.rotationPitch);
  251. return true;
  252. }
  253. else
  254. {
  255. return false;
  256. }
  257. }
  258.  
  259. public boolean makePortal(Entity par1Entity)
  260. {
  261. byte b0 = 16;
  262. double d0 = -1.0D;
  263. int i = MathHelper.floor_double(par1Entity.posX);
  264. int j = MathHelper.floor_double(par1Entity.posY);
  265. int k = MathHelper.floor_double(par1Entity.posZ);
  266. int l = i;
  267. int i1 = j;
  268. int j1 = k;
  269. int k1 = 0;
  270. int l1 = this.random.nextInt(4);
  271. int i2;
  272. double d1;
  273. double d2;
  274. int j2;
  275. int k2;
  276. int l2;
  277. int i3;
  278. int j3;
  279. int k3;
  280. int l3;
  281. int i4;
  282. int j4;
  283. int k4;
  284. double d3;
  285. double d4;
  286.  
  287. for (i2 = i - b0; i2 <= i + b0; ++i2)
  288. {
  289. d1 = (double)i2 + 0.5D - par1Entity.posX;
  290.  
  291. for (j2 = k - b0; j2 <= k + b0; ++j2)
  292. {
  293. d2 = (double)j2 + 0.5D - par1Entity.posZ;
  294. label274:
  295.  
  296. for (k2 = this.worldServerInstance.getActualHeight() - 1; k2 >= 0; --k2)
  297. {
  298. if (this.worldServerInstance.isAirBlock(i2, k2, j2))
  299. {
  300. while (k2 > 0 && this.worldServerInstance.isAirBlock(i2, k2 - 1, j2))
  301. {
  302. --k2;
  303. }
  304.  
  305. for (i3 = l1; i3 < l1 + 4; ++i3)
  306. {
  307. l2 = i3 % 2;
  308. k3 = 1 - l2;
  309.  
  310. if (i3 % 4 >= 2)
  311. {
  312. l2 = -l2;
  313. k3 = -k3;
  314. }
  315.  
  316. for (j3 = 0; j3 < 3; ++j3)
  317. {
  318. for (i4 = 0; i4 < 4; ++i4)
  319. {
  320. for (l3 = -1; l3 < 4; ++l3)
  321. {
  322. k4 = i2 + (i4 - 1) * l2 + j3 * k3;
  323. j4 = k2 + l3;
  324. int l4 = j2 + (i4 - 1) * k3 - j3 * l2;
  325.  
  326. if (l3 < 0 && !this.worldServerInstance.getBlockMaterial(k4, j4, l4).isSolid() || l3 >= 0 && !this.worldServerInstance.isAirBlock(k4, j4, l4))
  327. {
  328. continue label274;
  329. }
  330. }
  331. }
  332. }
  333.  
  334. d4 = (double)k2 + 0.5D - par1Entity.posY;
  335. d3 = d1 * d1 + d4 * d4 + d2 * d2;
  336.  
  337. if (d0 < 0.0D || d3 < d0)
  338. {
  339. d0 = d3;
  340. l = i2;
  341. i1 = k2;
  342. j1 = j2;
  343. k1 = i3 % 4;
  344. }
  345. }
  346. }
  347. }
  348. }
  349. }
  350.  
  351. if (d0 < 0.0D)
  352. {
  353. for (i2 = i - b0; i2 <= i + b0; ++i2)
  354. {
  355. d1 = (double)i2 + 0.5D - par1Entity.posX;
  356.  
  357. for (j2 = k - b0; j2 <= k + b0; ++j2)
  358. {
  359. d2 = (double)j2 + 0.5D - par1Entity.posZ;
  360. label222:
  361.  
  362. for (k2 = this.worldServerInstance.getActualHeight() - 1; k2 >= 0; --k2)
  363. {
  364. if (this.worldServerInstance.isAirBlock(i2, k2, j2))
  365. {
  366. while (k2 > 0 && this.worldServerInstance.isAirBlock(i2, k2 - 1, j2))
  367. {
  368. --k2;
  369. }
  370.  
  371. for (i3 = l1; i3 < l1 + 2; ++i3)
  372. {
  373. l2 = i3 % 2;
  374. k3 = 1 - l2;
  375.  
  376. for (j3 = 0; j3 < 4; ++j3)
  377. {
  378. for (i4 = -1; i4 < 4; ++i4)
  379. {
  380. l3 = i2 + (j3 - 1) * l2;
  381. k4 = k2 + i4;
  382. j4 = j2 + (j3 - 1) * k3;
  383.  
  384. if (i4 < 0 && !this.worldServerInstance.getBlockMaterial(l3, k4, j4).isSolid() || i4 >= 0 && !this.worldServerInstance.isAirBlock(l3, k4, j4))
  385. {
  386. continue label222;
  387. }
  388. }
  389. }
  390.  
  391. d4 = (double)k2 + 0.5D - par1Entity.posY;
  392. d3 = d1 * d1 + d4 * d4 + d2 * d2;
  393.  
  394. if (d0 < 0.0D || d3 < d0)
  395. {
  396. d0 = d3;
  397. l = i2;
  398. i1 = k2;
  399. j1 = j2;
  400. k1 = i3 % 2;
  401. }
  402. }
  403. }
  404. }
  405. }
  406. }
  407. }
  408.  
  409. int i5 = l;
  410. int j5 = i1;
  411. j2 = j1;
  412. int k5 = k1 % 2;
  413. int l5 = 1 - k5;
  414.  
  415. if (k1 % 4 >= 2)
  416. {
  417. k5 = -k5;
  418. l5 = -l5;
  419. }
  420.  
  421. boolean flag;
  422.  
  423. if (d0 < 0.0D)
  424. {
  425. if (i1 < 70)
  426. {
  427. i1 = 70;
  428. }
  429.  
  430. if (i1 > this.worldServerInstance.getActualHeight() - 10)
  431. {
  432. i1 = this.worldServerInstance.getActualHeight() - 10;
  433. }
  434.  
  435. j5 = i1;
  436.  
  437. for (k2 = -1; k2 <= 1; ++k2)
  438. {
  439. for (i3 = 1; i3 < 3; ++i3)
  440. {
  441. for (l2 = -1; l2 < 3; ++l2)
  442. {
  443. k3 = i5 + (i3 - 1) * k5 + k2 * l5;
  444. j3 = j5 + l2;
  445. i4 = j2 + (i3 - 1) * l5 - k2 * k5;
  446. flag = l2 < 0;
  447. this.worldServerInstance.setBlock(k3, j3, i4, flag ? MainBlock.zenBlock.blockID : 0);
  448. }
  449. }
  450. }
  451. }
  452.  
  453. for (k2 = 0; k2 < 4; ++k2)
  454. {
  455. for (i3 = 0; i3 < 4; ++i3)
  456. {
  457. for (l2 = -1; l2 < 4; ++l2)
  458. {
  459. k3 = i5 + (i3 - 1) * k5;
  460. j3 = j5 + l2;
  461. i4 = j2 + (i3 - 1) * l5;
  462. flag = i3 == 0 || i3 == 3 || l2 == -1 || l2 == 3;
  463. this.worldServerInstance.setBlock(k3, j3, i4, flag ? MainBlock.zenBlock.blockID : MpsPortalBlock.mPortal.blockID, 0, 2);
  464. }
  465. }
  466.  
  467. for (i3 = 0; i3 < 4; ++i3)
  468. {
  469. for (l2 = -1; l2 < 4; ++l2)
  470. {
  471. k3 = i5 + (i3 - 1) * k5;
  472. j3 = j5 + l2;
  473. i4 = j2 + (i3 - 1) * l5;
  474. this.worldServerInstance.notifyBlocksOfNeighborChange(k3, j3, i4, this.worldServerInstance.getBlockId(k3, j3, i4));
  475. }
  476. }
  477. }
  478.  
  479. return true;
  480. }
  481.  
  482. public void func_85189_a(long par1)
  483. {
  484. if (par1 % 100L == 0L)
  485. {
  486. Iterator iterator = this.field_85190_d.iterator();
  487. long j = par1 - 600L;
  488.  
  489. while (iterator.hasNext())
  490. {
  491. Long olong = (Long)iterator.next();
  492. PortalPosition portalposition = (PortalPosition)this.field_85191_c.getValueByKey(olong.longValue());
  493.  
  494. if (portalposition == null || portalposition.field_85087_d < j)
  495. {
  496. iterator.remove();
  497. this.field_85191_c.remove(olong.longValue());
  498. }
  499. }
  500. }
  501. }
  502. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement