Jump to content

[1.7.2] Dimensional teleporting, without the portals


whiskeyfur

Recommended Posts

Gettin' a little tired of putting nether portals all over the place in the game when trying to /home. Since forgeessentials hasn't been worked on for a while I'm trying to code my own.

 

What is the best way to move an entity from one world to an another without creating those obsidian gateways?

Link to comment
Share on other sites

Unfortuntely I'm trying to avoid those portal all together. The code I'm doing this for is so the player can /home, do what he needs to, then /back to where he went.

 

In most cases, he certainly didn't have a nether portal near him when he left that dimension so... yea.

Link to comment
Share on other sites

That's smart, when the teleport happens just make a three for loops increasing the x, y, z like this.

 


for (int i = player.posX - 5; i < player.posX + 5; i++)
{
    for (int j = player.posY - 5; j < player.posX + 5; j++)
    { 
        for (int k = player.posZ - 5; k < player.posX + 5; k++)
        { 
               if (world.getBlock(i, j k) == Blocks.obsidian || world.getBlock(i, j k) == Blocks.portal)
               {
                       world.setBlockToAir(i, j, k);   
               }
        }
    }
}

Something like that.

Link to comment
Share on other sites

I understand that method would work, though I'm not a real big fan of it because it feels more like a hack than a solution. For example, if they happen to be standing on obsidian, like a lava lake turned obsidian from a firestone, then this'll end up deleting obsidian blocks that didn't come from a portal.

 

I'm looking at possibly grabbing the worldserver for their source and destination worlds and telling them to remove and add the player respectively, then update their position. I don't think this'll work but it's worth a shot.

 

//WorldServer start = DimensionManager.getWorld(plyr.dimension);
//start.getPlayerManager().removePlayer(plyr);

WorldServer overworld = DimensionManager.getWorld(0);
overworld.getPlayerManager().addPlayer(plyr);

ChunkCoordinates c = overworld.getSpawnPoint();
plyr.setPositionAndUpdate(c.posX, c.posY, c.posZ);

 

Edit: This was a fail.

Link to comment
Share on other sites

Create your own teleported class and a command to call it.  You will need to specify where to go in the destination dimension somehow.

 

Do you have some example code to show this? I've yet to see a way to get around making a portal in game without effectively recreating the CommandServerTP class.

Link to comment
Share on other sites

I can share one tonight.

 

The basics are you need your own command.  Assuming you know how to do that.

 

From it you call your teleported code.  The trick is to override the methods in such a way it only does what you want.

Long time Bukkit & Forge Programmer

Happy to try and help

Link to comment
Share on other sites

Here is something that works for me.  I've done it different ways, but you should be able to modify this to suit your purposes.

 

 

 

 

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)

    {

    }

   

}

 

 

 

 

Then setup a custom command to call it with something similar to this.

 

 

 

 

new MyTeleporter(minecraftserver.worldServerForDimension(world.provider.dimensionId)).teleport(target, world);

 

 

 

 

 

Let me know how it goes.

Long time Bukkit & Forge Programmer

Happy to try and help

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



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • They were already updated, and just to double check I even did a cleanup and fresh update from that same page. I'm quite sure drivers are not the problem here. 
    • i tried downloading the drivers but it says no AMD graphics hardware has been detected    
    • Update your AMD/ATI drivers - get the drivers from their website - do not update via system  
    • As the title says i keep on crashing on forge 1.20.1 even without any mods downloaded, i have the latest drivers (nvidia) and vanilla minecraft works perfectly fine for me logs: https://pastebin.com/5UR01yG9
    • Hello everyone, I'm making this post to seek help for my modded block, It's a special block called FrozenBlock supposed to take the place of an old block, then after a set amount of ticks, it's supposed to revert its Block State, Entity, data... to the old block like this :  The problem I have is that the system breaks when handling multi blocks (I tried some fix but none of them worked) :  The bug I have identified is that the function "setOldBlockFields" in the item's "setFrozenBlock" function gets called once for the 1st block of multiblock getting frozen (as it should), but gets called a second time BEFORE creating the first FrozenBlock with the data of the 1st block, hence giving the same data to the two FrozenBlock :   Old Block Fields set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=head] BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@73681674 BlockEntityData : id:"minecraft:bed",x:3,y:-60,z:-6} Old Block Fields set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=foot] BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@6d1aa3da BlockEntityData : {id:"minecraft:bed",x:2,y:-60,z:-6} Frozen Block Entity set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=foot] BlockPos{x=3, y=-60, z=-6} BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@6d1aa3da BlockEntityData : {id:"minecraft:bed",x:2,y:-60,z:-6} Frozen Block Entity set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=foot] BlockPos{x=2, y=-60, z=-6} BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@6d1aa3da BlockEntityData : {id:"minecraft:bed",x:2,y:-60,z:-6} here is the code inside my custom "freeze" item :    @Override     public @NotNull InteractionResult useOn(@NotNull UseOnContext pContext) {         if (!pContext.getLevel().isClientSide() && pContext.getHand() == InteractionHand.MAIN_HAND) {             BlockPos blockPos = pContext.getClickedPos();             BlockPos secondBlockPos = getMultiblockPos(blockPos, pContext.getLevel().getBlockState(blockPos));             if (secondBlockPos != null) {                 createFrozenBlock(pContext, secondBlockPos);             }             createFrozenBlock(pContext, blockPos);             return InteractionResult.SUCCESS;         }         return super.useOn(pContext);     }     public static void createFrozenBlock(UseOnContext pContext, BlockPos blockPos) {         BlockState oldState = pContext.getLevel().getBlockState(blockPos);         BlockEntity oldBlockEntity = oldState.hasBlockEntity() ? pContext.getLevel().getBlockEntity(blockPos) : null;         CompoundTag oldBlockEntityData = oldState.hasBlockEntity() ? oldBlockEntity.serializeNBT() : null;         if (oldBlockEntity != null) {             pContext.getLevel().removeBlockEntity(blockPos);         }         BlockState FrozenBlock = setFrozenBlock(oldState, oldBlockEntity, oldBlockEntityData);         pContext.getLevel().setBlockAndUpdate(blockPos, FrozenBlock);     }     public static BlockState setFrozenBlock(BlockState blockState, @Nullable BlockEntity blockEntity, @Nullable CompoundTag blockEntityData) {         BlockState FrozenBlock = BlockRegister.FROZEN_BLOCK.get().defaultBlockState();         ((FrozenBlock) FrozenBlock.getBlock()).setOldBlockFields(blockState, blockEntity, blockEntityData);         return FrozenBlock;     }  
  • Topics

×
×
  • Create New...

Important Information

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