Working with portals in additional worlds, The bukkit style!

Discussion in 'Plugin Development' started by CorrieKay, Dec 2, 2012.

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

    CorrieKay

    So ive posted a thread before about working with nether portals in additional worlds, but it never really got the responses that i needed. Fortunately for me, i checked out how exactly the portal was created and was able to discern from bukkit code that the EntityPortalEnterEvent would do it for me, as long as the toLocation wasnt null. So i checked out how NMS did it. I found this method.

    Basically, it sets the location x and z to 1/8th if youre going from world to nether, and x8 from nether to world.

    Now, the problem is that i got it working. it was pretty simple, actually, heres my method

    Code:
        @EventHandler
        public void onPortalEnter(PlayerPortalEvent event){
            World w = event.getPlayer().getWorld();
            World parent = getParentWorld(w);
            World toWorld;
            double ratio = 0;
            if(!(parent.getName().equals("badlands")))return;
            if(w.getEnvironment() == Environment.NORMAL){
                ratio = 0.125;
                toWorld = getNether(w);
            } else if(w.getEnvironment() == Environment.NETHER){
                ratio = 8.0;
                toWorld = getParentWorld(w);
            } else {
                return;
            }
            Location from = event.getFrom();
            Location finalLoc = new Location(toWorld,from.getX()*ratio,from.getY(),from.getZ()*ratio);
            event.setTo(finalLoc);
        }
    
    However, for some reason when i tested it today, it wasnt working very well.

    I think the problem is, the search and create radii are way too high. i would portal through to the nether, and it would find a location way far away from the location, but still within the search radius. Then when i portaled back, it would teleport me to a different portal. I figure its just not finding the original portal, and creating a new one at the location in which the other portal was found, overworld-side. That would explain it, but why the heck cant it find the original portal, yet the original portal could find it in the nether? :'(
     
  2. Offline

    turelis

    This might be complete nonsense to you but I went with a different method of teleporting.

    IF your not too worried with having a single portal on a chunk you can use something like:

    PlayerPortalEvent triggers, Method gets the current players standing chuck x and z, and their world.
    This then looks into a list of objects like such a construct as below to find the one that makes the three Froms:

    fromX
    fromZ
    fromWorld

    sendToWorld
    sendToX
    sendToY
    sendToZ
    sendToRot
    sendToPitch

    This then returns the object requested and use use the Teleport method to send it to that world and those 3 cords, with the play at that rotation, and that pitch / yaw
     
Thread Status:
Not open for further replies.

Share This Page