How to set a portal exit location

Discussion in 'Plugin Development' started by Nax, Jun 12, 2014.

Thread Status:
Not open for further replies.
  1. Offline

    Nax

    I'm trying to create a plugin that lets players use a scroll to create a portal that takes them to a set location. I'm having some trouble figuring out how to create an exit portal at a specified location and connect it to the portal that they created using the scroll. Any help would be appreciated!
     
  2. Offline

    Mrawesomecookie

    CraftBukkit/NMS does it automaticly
    This is from the net.minecraft.server.BlockPortal class
    Show Spoiler

    Code:java
    1. public void a(World world, int i, int j, int k, Entity entity) {
    2. if ((entity.vehicle != null) || (entity.passenger != null))
    3. return;
    4. EntityPortalEnterEvent event = new EntityPortalEnterEvent(
    5. entity.getBukkitEntity(), new Location(world.getWorld(), i, j,
    6. k));
    7. world.getServer().getPluginManager().callEvent(event);
    8.  
    9. entity.ah();
    10. }


    And from the net.minecraft.server.Entity class

    Show Spoiler


    Code:java
    1. public void ah() {
    2. if (this.portalCooldown > 0) {
    3. this.portalCooldown = ai();
    4. } else {
    5. double d0 = this.lastX - this.locX;
    6. double d1 = this.lastZ - this.locZ;
    7.  
    8. if ((!(this.world.isStatic)) && (!(this.ao))) {
    9. this.ar = Direction.a(d0, d1);
    10. }
    11.  
    12. this.ao = true;
    13. }
    14.  
    15. }




    Show Spoiler

    Code:java
    1. public void C() {
    2. this.world.methodProfiler.a("entityBaseTick");
    3. if ((this.vehicle != null) && (this.vehicle.dead)) {
    4. this.vehicle = null;
    5. }
    6.  
    7. this.P = this.Q;
    8. this.lastX = this.locX;
    9. this.lastY = this.locY;
    10. this.lastZ = this.locZ;
    11. this.lastPitch = this.pitch;
    12. this.lastYaw = this.yaw;
    13.  
    14. if ((!(this.world.isStatic)) && (this.world instanceof WorldServer)) {
    15. this.world.methodProfiler.a("portal");
    16. MinecraftServer minecraftserver = ((WorldServer) this.world)
    17. .getMinecraftServer();
    18.  
    19. int i = D();
    20. if (this.ao) {
    21. if (this.vehicle == null)
    22. if (this.ap++ >= i) {
    23. this.ap = i;
    24. this.portalCooldown = ai();
    25. byte b0;
    26. byte b0;
    27. if (this.world.worldProvider.dimension == -1)
    28. b0 = 0;
    29. else {
    30. b0 = -1;
    31. }
    32.  
    33. b(b0);
    34. }
    35.  
    36. this.ao = false;
    37. } else {
    38. if (this.ap > 0) {
    39. this.ap -= 4;
    40. }
    41.  
    42. if (this.ap < 0) {
    43. this.ap = 0;
    44. }
    45. }
    46.  
    47. if (this.portalCooldown > 0) {
    48. this.portalCooldown -= 1;
    49. }
    50.  
    51. this.world.methodProfiler.b();
    52. }
    53.  
    54. if ((isSprinting()) && (!(M()))) {
    55. int j = MathHelper.floor(this.locX);
    56.  
    57. int i = MathHelper.floor(this.locY - 0.2000000029802322D
    58. - this.height);
    59. int k = MathHelper.floor(this.locZ);
    60. Block block = this.world.getType(j, i, k);
    61.  
    62. if (block.getMaterial() != Material.AIR) {
    63. this.world.addParticle("blockcrack_" + Block.b(block) + "_"
    64. + this.world.getData(j, i, k),
    65. this.locX + (this.random.nextFloat() - 0.5D)
    66. * this.width, this.boundingBox.b + 0.1D,
    67. this.locZ + (this.random.nextFloat() - 0.5D)
    68. * this.width, -this.motX * 4.0D, 1.5D,
    69. -this.motZ * 4.0D);
    70. }
    71. }
    72.  
    73. N();
    74. if (this.world.isStatic)
    75. this.fireTicks = 0;
    76. else if (this.fireTicks > 0) {
    77. if (this.fireProof) {
    78. this.fireTicks -= 4;
    79. if (this.fireTicks < 0)
    80. this.fireTicks = 0;
    81. } else {
    82. if (this.fireTicks % 20 == 0) {
    83. damageEntity(DamageSource.BURN, 1.0F);
    84. }
    85.  
    86. this.fireTicks -= 1;
    87. }
    88. }
    89.  
    90. if (P()) {
    91. E();
    92. this.fallDistance *= 0.5F;
    93. }
    94.  
    95. if (this.locY < -64.0D) {
    96. G();
    97. }
    98.  
    99. if (!(this.world.isStatic)) {
    100. a(0, this.fireTicks > 0);
    101. }
    102.  
    103. this.justCreated = false;
    104. this.world.methodProfiler.b();
    105. }



    You would want to use reflect/etc.. and force a event.
     
  3. Offline

    Nax

    Is there a way to do it through the metadata of a block representing the portal created by the player? I don't completely understand metadata yet, and was just curious.
     
Thread Status:
Not open for further replies.

Share This Page