Jump to content

[1.7.10] Dimensional teleporting without any form of portal


nexusrightsi

Recommended Posts

Hello people,

 

I've been trying to figure out how to disable portal spawning from teleporting to my custom dimension, but till thus far I haven't made any progress with it. Recently I came across this forum thread http://www.minecraftforge.net/forum/index.php?topic=18493.0 where Delpi was so kind to help out someone with a similar problem with this code:

 

 

 

package clandoolittle.dimension_multiplyer.Common.Worlds.Teleporters;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
import java.util.Random;
import java.util.logging.Level;

import cpw.mods.fml.common.Loader;
import cpw.mods.fml.common.ModContainer;
import clandoolittle.dimension_multiplyer.Dimension_Multiplyer;
import clandoolittle.dimension_multiplyer.Common.Worlds.World.World_Properties;
import net.minecraft.block.Block;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.init.Blocks;
import net.minecraft.server.MinecraftServer;
import net.minecraft.util.Direction;
import net.minecraft.util.LongHashMap;
import net.minecraft.util.MathHelper;
import net.minecraft.world.ChunkCoordIntPair;
import net.minecraft.world.Teleporter;
import net.minecraft.world.World;
import net.minecraft.world.WorldServer;

public class MyTeleporter extends Teleporter {
   
    // Setup Variables
    public Dimension_Multiplyer instance = Dimension_Multiplyer.instance;

    // Setup Specific Variables
    private WorldServer worldserver;

    public MyTeleporter(WorldServer worldserver) {
        super(worldserver);
        
        // Setup Variables
        this.worldserver = worldserver;
        
    }

    // Move the Entity to the portal
    public void teleport(Entity entity, World world) {
       
        // Setup Variables
        EntityPlayerMP playerMP = (EntityPlayerMP) entity;
        
        // Get name of world
        String world_name = instance.world_manager().name(world.provider.dimensionId);
        
        // Set default location
        double dx = 0;
        double dy = 0;
        double dz = 0;
        
        // Check world_properties for spawn
        World_Properties world_property = instance.world_manager().world_properties().get(world.provider.dimensionId);

        if (world_property != null) {
           
            dx = world_property.spawn_x();
            dy = world_property.spawn_y();
            dz = world_property.spawn_z();
            
        }

        // check for zeros
        if (dx == 0 && dy == 0 && dz == 0) {
           
            // Set height to something big
            dy = 250;

            // Drop down until find solid
            while (world.getBlock((int) dx, (int) dy - 1, (int) dz).equals(Blocks.air) && dy > 0) {
               
                dy--;
                
            }

            // Last check if dy == 0
            if (dy == 0) {
               
                dy = 128;
                
            }
            
        }

        // Offset locations for accuracy
        dx = dx + 0.5d;
        dy = dy + 1.0d;
        dz = dz + 0.5d;
        entity.setPosition(dx, dy, dz);
        
        // Freeze motion
        entity.motionX = entity.motionY = entity.motionZ = 0.0D;
        entity.setPosition(dx, dy, dz);  // silly to do this multiple time,s but it kept offseting entity until this was done

        // Set Dimension
        if (entity.worldObj.provider.dimensionId != world.provider.dimensionId) {
           
            playerMP.mcServer.getConfigurationManager().transferPlayerToDimension(playerMP, world.provider.dimensionId, this);
            
        }

        entity.setPosition(dx, dy, dz); // silly to do this multiple time,s but it kept offseting entity until this was done
        // instance.logger.log(Level.INFO, "Teleported to " + world_name + ":" + dx + "/" + dy + "/" + dz);
    
    }

    // Override Default BS
    @Override
    public boolean placeInExistingPortal(Entity par1Entity, double par2, double par4, double par6, float par8)
    {
        return false;
    }

    @Override
    public void removeStalePortalLocations(long par1)
    {
    }

    @Override
    public void placeInPortal(Entity par1Entity, double par2, double par4, double par6, float par8)
    {
    }
    
}

 

 

 

Although there are some parts that I don't understand due to their responsive classes missing I guess?

 

public Dimension_Multiplyer instance = Dimension_Multiplyer.instance;

World_Properties world_property =

 

Both these classes seem to be missing and it would be helpful if anyone could explain this further to me so i'd understand the code a lot better.

Link to comment
Share on other sites

public Dimension_Multiplyer instance = Dimension_Multiplyer.instance;

 

Dimension_Multiplyer change to yours dimension class. in yours dimension class add:

public static Dimension_Multiplyer instance; 

or if you have construtor

public static Dimension_Multiplyer instance = new Dimension_Multiplyer(); 

 

World_Properties world_property =

Proprieties of dimesion created by Delpi

import clandoolittle.dimension_multiplyer.Common.Worlds.World.World_Properties;

Ask him what is inside;

 

Used only to get world spawn position in dimension;

If you want to keep position of player in dimension the same as now, remove code:

if (world_property != null) {
           
            dx = world_property.spawn_x();
            dy = world_property.spawn_y();
            dz = world_property.spawn_z();
            
        }

and make getter of position of player; Example =

dx = entity.posX;

 

Hope this helps you.

Link to comment
Share on other sites

Right, thank you!

 

So the Dimension_Multiplyr just takes the instance of your dimension.

 

Well, its kinda hard to reach Delpi since he doesn't respond to pm's. I just have to sit here and hope he'll eventually find this thread

 

Once again, thank you for the help. I'm sure that once I get the World_Properties part info that I'll be able to write my own code instead of using someone else their code. ^_^

Link to comment
Share on other sites

World_Properties is kinda useless: used to get spawn coordinates in dim. If you are working with dim that doesn't allow to respawn in, you don't need it.

switch dimension travelling to

 

case overworld:

open EntityPlayer class and find getters of spawn position (in 1.8 where i'm working its BlockPos)

 

case other dim, respawn not allowed:

keep player pos the same

 

case other dim, respawn allowed:

for this case i don't know. Wiew code of dim you're working with

Link to comment
Share on other sites

Got your message. 

 

I've been a way for a bit working on Dayz Scripts.

 

 

Please explain to me what you are doing and what exactly you need help with and I'll see what I can do.  Be warned, If you are using the code I shared for making portals, I completely rewrote the vanilla stuff so I could do some unusual things with it.

 

If all you want to do is stop portals from forming in your new dimension, there are two ways that I think are best:

  • Change the Teleport code so that instead of forming portals, it sends you to the spawn point of that dimension, which is what I think you are trying to do
  • Block people from creating a portal in the originating dimension in the first place.  Since you created the blocks that originate this, should be within what you know to do.

Long time Bukkit & Forge Programmer

Happy to try and help

Link to comment
Share on other sites

Got your message. 

 

I've been a way for a bit working on Dayz Scripts.

 

 

Please explain to me what you are doing and what exactly you need help with and I'll see what I can do.  Be warned, If you are using the code I shared for making portals, I completely rewrote the vanilla stuff so I could do some unusual things with it.

 

If all you want to do is stop portals from forming in your new dimension, there are two ways that I think are best:

  • Change the Teleport code so that instead of forming portals, it sends you to the spawn point of that dimension, which is what I think you are trying to do
  • Block people from creating a portal in the originating dimension in the first place.  Since you created the blocks that originate this, should be within what you know to do.

 

Well, you've pretty much got it all summed up already. All that I want to do is without the use of portals teleport from dimension to dimension. No portals being created in the custom dimension either. I've seen a different method of doing this, however it isn't as elegant as it just removes the obsidian blocks that the portal created. Which can result in death if being spawned in the wrong place.

 

I've already stopped players from making a portal to my custom dimension as they need to lay down on a bed and be fully asleep in order to get teleported. So, that part is down. The main issue is that when I try to teleport its glitches out by creating a portal and then suddenly not as in it(the portal) visually being there for a second and the next second it is gone, but also at that point you get teleported back to the players original coords before the player used the bed method to get teleported.

 

Its quite strange that it actually glitches out like this, I did test it on same dimension teleports where for instance the player gets teleported to its spawn point. Strangely enough it somewhat glitches out in a similar fashion as the other dimension teleport. It teleports the player for a second, and then glitches back to where the player originally was.

Link to comment
Share on other sites

I used this code

while testing my test world

 

 

EntityPlayerMP pl

  player to teleport

int id

  id of dimention

 

double xpos

double ypos

double zpos

  position to go to

 

 

private void tptoworld(EntityPlayerMP pl,int id,double xpos,double ypos, double zpos) {
	MinecraftServer mcServer = MinecraftServer.getServer();
	ServerConfigurationManager cm=pl.mcServer.getConfigurationManager();

	int oldid = pl.dimension;
	WorldServer worldserver = mcServer.worldServerForDimension(pl.dimension);
	pl.dimension = id;
	WorldServer worldserver1 = mcServer.worldServerForDimension(pl.dimension);

	pl.playerNetServerHandler.sendPacket(new S07PacketRespawn(pl.dimension, pl.worldObj.difficultySetting, pl.worldObj.getWorldInfo().getTerrainType(), pl.theItemInWorldManager.getGameType()));
	worldserver.removePlayerEntityDangerously(pl);
	pl.isDead = false;

	pl.setLocationAndAngles(xpos, ypos, zpos, pl.rotationYaw, pl.rotationPitch);
	worldserver1.spawnEntityInWorld(pl);
	worldserver1.updateEntityWithOptionalForce(pl, false);		
	pl.setWorld(worldserver1);

	WorldServer worldserverx = pl.getServerForPlayer();

	if (worldserver != null){
		worldserver.getPlayerManager().removePlayer(pl);
	}		
	worldserverx.getPlayerManager().addPlayer(pl);
	worldserverx.theChunkProviderServer.loadChunk((int)pl.posX >> 4, (int)pl.posZ >> 4);


	pl.playerNetServerHandler.setPlayerLocation(pl.posX, pl.posY, pl.posZ, pl.rotationYaw, pl.rotationPitch);
	pl.theItemInWorldManager.setWorld(worldserver1);
	cm.updateTimeAndWeatherForPlayer(pl, worldserver1);
	cm.syncPlayerInventory(pl);
	Iterator<PotionEffect> iterator = pl.getActivePotionEffects().iterator();

	while (iterator.hasNext()){
		PotionEffect potioneffect = iterator.next();
		pl.playerNetServerHandler.sendPacket(new S1DPacketEntityEffect(pl.getEntityId(), potioneffect));
	}
	FMLCommonHandler.instance().firePlayerChangedDimensionEvent(pl, oldid, id);
}

 

hope this helps, I extracted it all from minecraft code

 

Link to comment
Share on other sites

I used this code

while testing my test world

 

 

EntityPlayerMP pl

  player to teleport

int id

  id of dimention

 

double xpos

double ypos

double zpos

  position to go to

 

 

private void tptoworld(EntityPlayerMP pl,int id,double xpos,double ypos, double zpos) {
	MinecraftServer mcServer = MinecraftServer.getServer();
	ServerConfigurationManager cm=pl.mcServer.getConfigurationManager();

	int oldid = pl.dimension;
	WorldServer worldserver = mcServer.worldServerForDimension(pl.dimension);
	pl.dimension = id;
	WorldServer worldserver1 = mcServer.worldServerForDimension(pl.dimension);

	pl.playerNetServerHandler.sendPacket(new S07PacketRespawn(pl.dimension, pl.worldObj.difficultySetting, pl.worldObj.getWorldInfo().getTerrainType(), pl.theItemInWorldManager.getGameType()));
	worldserver.removePlayerEntityDangerously(pl);
	pl.isDead = false;

	pl.setLocationAndAngles(xpos, ypos, zpos, pl.rotationYaw, pl.rotationPitch);
	worldserver1.spawnEntityInWorld(pl);
	worldserver1.updateEntityWithOptionalForce(pl, false);		
	pl.setWorld(worldserver1);

	WorldServer worldserverx = pl.getServerForPlayer();

	if (worldserver != null){
		worldserver.getPlayerManager().removePlayer(pl);
	}		
	worldserverx.getPlayerManager().addPlayer(pl);
	worldserverx.theChunkProviderServer.loadChunk((int)pl.posX >> 4, (int)pl.posZ >> 4);


	pl.playerNetServerHandler.setPlayerLocation(pl.posX, pl.posY, pl.posZ, pl.rotationYaw, pl.rotationPitch);
	pl.theItemInWorldManager.setWorld(worldserver1);
	cm.updateTimeAndWeatherForPlayer(pl, worldserver1);
	cm.syncPlayerInventory(pl);
	Iterator<PotionEffect> iterator = pl.getActivePotionEffects().iterator();

	while (iterator.hasNext()){
		PotionEffect potioneffect = iterator.next();
		pl.playerNetServerHandler.sendPacket(new S1DPacketEntityEffect(pl.getEntityId(), potioneffect));
	}
	FMLCommonHandler.instance().firePlayerChangedDimensionEvent(pl, oldid, id);
}

 

hope this helps, I extracted it all from minecraft code

 

Cheers for the help, but do you reckon that I actually need packet sending in this code. It seems not likely but the code that you provided me with shows that in fact there is packet sending going on?

Link to comment
Share on other sites

the packet-handling is all done in the background by the methods called in the code i posted,

the code here is the code called by entering a portal with portal creation / searching removes and location provided

 

so you wont have to do anything other than what i provided

 

 

Link to comment
Share on other sites

Got distracted yesterday.  I'll send you something that will work tonight. 

 

I'm assuming you have a method trigger the teleportion and you know where you want them to land in the alternate dimension?

 

Is the landing spot dynamic or same spot everytime?

Long time Bukkit & Forge Programmer

Happy to try and help

Link to comment
Share on other sites

Ok, whatever method you are using to initiate a teleport, fire something like this.

 

 

 

 

new MyTeleporter(MinecraftServer.getServer().worldServerForDimension(target.worldObj.provider.dimensionId)).teleport(player, target.worldObj, target.posX, target.posY + 0.1d, target.posZ);

 

 

 

 

In this case, target is another player.  Its an admin command i have to warp around to different folks.

 

 

MyTeleporter Class

 

 

 

 

package clandoolittle.dimension_manager.Common.Worlds.Teleporters;

 

import java.util.ArrayList;

import java.util.Arrays;

import java.util.Iterator;

import java.util.List;

import java.util.Random;

import java.util.logging.Level;

 

import cpw.mods.fml.common.Loader;

import cpw.mods.fml.common.ModContainer;

 

import clandoolittle.dimension_manager.Dimension_Manager;

 

import net.minecraft.block.Block;

import net.minecraft.entity.Entity;

import net.minecraft.entity.player.EntityPlayer;

import net.minecraft.entity.player.EntityPlayerMP;

import net.minecraft.server.MinecraftServer;

import net.minecraft.util.Direction;

import net.minecraft.util.LongHashMap;

import net.minecraft.util.MathHelper;

import net.minecraft.world.ChunkCoordIntPair;

import net.minecraft.world.Teleporter;

import net.minecraft.world.World;

import net.minecraft.world.WorldServer;

 

public class MyTeleporter extends Teleporter {

 

    // Setup Variables

public Dimension_Manager instance = Dimension_Manager.instance;

 

    // Setup Specific Variables

    private WorldServer worldserver;

 

    public MyTeleporter(WorldServer worldserver) {

        super(worldserver);

       

        // Setup Variables

        this.worldserver = worldserver;

       

    }

 

// Move the Entity to the portal

    public void teleport(Entity entity, World world, double x, double y, double z) {

   

        // Setup Variables

        EntityPlayerMP playerMP = (EntityPlayerMP) entity;

       

        // Record player old location

        instance.functions_common().back_set(playerMP);

       

        // Freeze motion

        entity.motionX = entity.motionY = entity.motionZ = 0.0D;

        playerMP.fallDistance = 0;

       

        // Set position

        entity.setPosition(x, y, z);

       

        // Set Dimension

        if (entity.worldObj.provider.dimensionId != world.provider.dimensionId) playerMP.mcServer.getConfigurationManager().transferPlayerToDimension(playerMP, world.provider.dimensionId, this);

       

    }

 

    // Override Default BS

    @Override

    public boolean placeInExistingPortal(Entity par1Entity, double par2, double par4, double par6, float par8) {

   

        return false;

       

    }

 

    @Override

    public void removeStalePortalLocations(long par1) {

   

    }

 

    @Override

    public void placeInPortal(Entity par1Entity, double par2, double par4, double par6, float par8) {

   

    }

   

}

 

 

 

 

Translations of the above

  • Ignore the dimension manager thing.  Its just how I refer to my starting class to make things easy.
  • The 'instance.functions_common().back_set(playerMP);' just records where I jumped from, you don't need it



 

That is the easy way to do it if all you want to do is teleport to a set location based upon some trigger.

 

 

I've got another one for going to the spawn point in the main world.  You should be able to figure it out from the above.

 

 

 

 

package clandoolittle.dimension_manager.Common.Worlds.Teleporters;

 

import java.util.ArrayList;

import java.util.Arrays;

import java.util.Iterator;

import java.util.List;

import java.util.Random;

import java.util.logging.Level;

 

import clandoolittle.dimension_manager.Dimension_Manager;

 

import net.minecraft.block.Block;

import net.minecraft.entity.Entity;

import net.minecraft.entity.player.EntityPlayerMP;

import net.minecraft.server.MinecraftServer;

import net.minecraft.util.Direction;

import net.minecraft.util.LongHashMap;

import net.minecraft.util.MathHelper;

import net.minecraft.world.ChunkCoordIntPair;

import net.minecraft.world.Teleporter;

import net.minecraft.world.World;

import net.minecraft.world.WorldServer;

 

public class MyTeleporterSpawn extends Teleporter {

 

    // Setup Variables

    public Dimension_Manager instance = Dimension_Manager.instance;

 

    // Setup Specific Variables

    private WorldServer worldserver;

 

    public MyTeleporterSpawn(WorldServer worldserver) {

        super(worldserver);

       

        // Setup Variables

        this.worldserver = worldserver;

       

    }

 

    // Move the Entity to the portal

    public void teleport(Entity entity) {

   

        // Setup Variables

        EntityPlayerMP playerMP = (EntityPlayerMP) entity;

        World world = instance.functions_common().find_world(0);

       

        // Get teh spawn locations

        double dx = world.getWorldInfo().getSpawnX();

        double dy = world.getWorldInfo().getSpawnY();

        double dz = world.getWorldInfo().getSpawnZ();

       

        // Offset locations for accuracy

        dx = dx + 0.5d;

        dy = dy + 1.0d;

        dz = dz + 0.5d;

        //entity.setPosition(dx, dy, dz);

       

        // Record player old location

        instance.functions_common().back_set(playerMP);

       

        // Freeze motion

        playerMP.motionX = playerMP.motionY = playerMP.motionZ = 0.0D;

        playerMP.fallDistance = 0;

        playerMP.setLocationAndAngles(dx, dy, dz, entity.rotationYaw, entity.rotationPitch);  // silly to do this multiple time,s but it kept offseting entity until this was done

       

        // Set Dimension

        if (playerMP.worldObj.provider.dimensionId != 0 ) playerMP.mcServer.getConfigurationManager().transferPlayerToDimension(playerMP, world.provider.dimensionId, this);

        //if (entity.worldObj.provider.dimensionId != world.provider.dimensionId) playerMP.mcServer.getConfigurationManager().transferPlayerToDimension(playerMP, world.provider.dimensionId, this);

        //entity.setPosition(dx, dy, dz); // silly to do this multiple time,s but it kept offseting entity until this was done

        // instance.logger.log(Level.INFO, "Teleported to " + dx + "/" + dy + "/" + dz);

       

    }

 

    // Override Default BS

    @Override

    public boolean placeInExistingPortal(Entity par1Entity, double par2, double par4, double par6, float par8) {

   

        return false;

       

    }

 

    @Override

    public void removeStalePortalLocations(long par1) {

   

    }

 

    @Override

    public void placeInPortal(Entity par1Entity, double par2, double par4, double par6, float par8) {

   

    }

   

}

 

 

 

 

 

Let me know how it works out for you.

 

Long time Bukkit & Forge Programmer

Happy to try and help

Link to comment
Share on other sites

Well, the spot where they well get teleported to isn't determined just yet. Mainly because the teleport spot will be in a city, which I still have to code into the dimension.

 

Perhaps you could answer my next question, is there an easier way of creating a city without having to manually code the block locations yourself. I have heard about mods that use schematics, but wouldn't that just take like chunks out of the terain if it was being placed into a mountain for example?

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.