Jump to content

[1.12] Connecting client stuck on login screen when reconnecting to custom-created dimension.


Recommended Posts

Posted

I have a simple mod intended as a server-side only mod that creates an additional dimension with id 2 using the existing DimensionType DimensionType.OVERWORLD. If a player disconnects after being transferred to this world any attempts to reconnect will result in what appears to be a client-side soft lock (The connection attempt can be cancelled by pressing the cancel button, but will never time-out by itself). If the player is disconnected only after being returned to the default world, they can connect again without any problems. If the server is shut down, the world folder deleted, and the server then started again, the player can also connect again.

 

Used server and MDK version: 1.12 - 14.21.1.2413
 

What I have tried to fix the issue:

- Use a Forge client to connect instead of a vanilla client.

- Try calling the function to move the player between worlds from a different event callback. (This failed because ServerChatEvent - which I tried to use - does not appear to catch any chat messages)

 

Other unwanted observed behaviour:

- After being transferred from one world to the other, an afterimage of the obsidian block and the redstone torch (see onInteract() in my code for context) are visible in the new world (desync).

 

 

My code:

 

QuestWorldsEventHandler.java

package usr.zyl.questworlds;

import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.init.Blocks;
import net.minecraft.item.Item;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.text.TextComponentString;
import net.minecraft.world.DimensionType;
import net.minecraft.world.WorldServer;
import net.minecraftforge.common.DimensionManager;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.ServerChatEvent;
import net.minecraftforge.event.entity.player.PlayerInteractEvent;
import net.minecraftforge.fml.common.FMLCommonHandler;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.Mod.EventHandler;
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.relauncher.Side;

@Mod(acceptableRemoteVersions = "*", modid = QuestWorldsEventHandler.MODID, version = QuestWorldsEventHandler.VERSION)
public class QuestWorldsEventHandler {

	public static final String MODID = "questworlds";
	public static final String VERSION = "1.0";
	private static QuestWorldsEventHandler questWorldsEventHandler;
	
	// DimensionType and dimension id reference (called "canyon" because I wanted to make a canyon lol)
	public static DimensionType canyonDimensionType;
	// Just aggressively try to get this id for now (because this is the only mod being run)
	public static final int canyonDimensionId = 2;
	
	public QuestWorldsEventHandler() {
	}
	
	@EventHandler
	public static void init(FMLInitializationEvent event) {
		if (FMLCommonHandler.instance().getEffectiveSide() == Side.SERVER) {
			questWorldsEventHandler = new QuestWorldsEventHandler();
			
			System.out.println("Got ID for our custom world: " + canyonDimensionId);
			DimensionManager.registerDimension(canyonDimensionId, DimensionType.getById(0));
			
			MinecraftForge.EVENT_BUS.register(questWorldsEventHandler);
		}
	}
	
	// Warp the player when he places a redstone torch on top of an obsidian block.
	@SubscribeEvent
	public void onInteract(PlayerInteractEvent event) {
		if (FMLCommonHandler.instance().getEffectiveSide() != Side.SERVER)
			return;
		if (event == null)
			return;
		if (EnumFacing.UP.equals(event.getFace())) {
			if (EnumHand.MAIN_HAND.equals(event.getHand())) {
				if (Item.getItemFromBlock(Blocks.REDSTONE_TORCH).equals(event.getItemStack().getItem())) {
					if (Blocks.OBSIDIAN.equals(event.getWorld().getBlockState(event.getPos()).getBlock())) {
						EntityPlayer ep = event.getEntityPlayer();
						if (ep instanceof EntityPlayerMP) {
							System.out.println("Warping!");
							ep.sendMessage(new TextComponentString("Warping!"));
							
							if (ep.dimension == 0) // If in overworld, warp to our dimension
								warpPlayerToDimension(ep, canyonDimensionId);
							else // If not in the overworld, warp to the overworld
								warpPlayerToDimension(ep, 0);
						}
					}
				}
			}
		}
	}
	
	// Alternative trigger. Unfortunately this never gets called for unknown reasons.
	@SubscribeEvent
	public void onChat(ServerChatEvent event) {
		if (event == null)
			return;
		EntityPlayerMP epmp = event.getPlayer();
		String text = event.getComponent().getUnformattedComponentText();
		System.out.print("Player \"" + event.getUsername() + "\" sent text: \"" + text + "\"");
		if (text.startsWith("/warp ")) {
			String number = text.substring(5, text.length());
			try {
				int dimensionId = Integer.valueOf(number);
				if (DimensionManager.isDimensionRegistered(dimensionId))
					warpPlayerToDimension(epmp, dimensionId);
			} catch (NumberFormatException ex) {}
		}
	}
	
	public static boolean warpPlayerToDimension(EntityPlayer ep, int dimension) {
		return warpPlayerToDimension(ep, dimension, ep.getPosition());
	}
	
	public static boolean warpPlayerToDimension(EntityPlayer ep, int dimension, BlockPos pos) {
		if (ep instanceof EntityPlayerMP) {
			EntityPlayerMP epmp = (EntityPlayerMP) ep;
			WorldServer ws = epmp.mcServer.getWorld(dimension);
			BlockPos top = ws.getTopSolidOrLiquidBlock(pos);
			epmp.mcServer.getPlayerList().transferPlayerToDimension(epmp, dimension, new SimpleTeleporter(ws));
			ep.motionX = 0;
			ep.motionY = 0;
			ep.motionZ = 0;
			ep.setPositionAndUpdate(top.getX() + 0.5, top.getY() + 2.5, top.getZ() + 0.5);
			return true;
		}
		return false;
	}
	
}

 

SimpleTeleporter.java

package usr.zyl.questworlds;

import net.minecraft.entity.Entity;
import net.minecraft.world.Teleporter;
import net.minecraft.world.WorldServer;

public class SimpleTeleporter extends Teleporter {

	public SimpleTeleporter(WorldServer worldServer) {
		super(worldServer);
	}

	@Override
	public void placeInPortal(Entity entityIn, float rotationYaw) {
	}	

	@Override
	public boolean placeInExistingPortal(Entity entityIn, float rotationYaw) {
		return true;
	}

	@Override
	public boolean makePortal(Entity entityIn) {
		return true;
	}
}

 

Any clues on what might be going wrong here?

Posted
4 hours ago, lukas2005 said:

why you have @Mod annotation on to of your EventHandler Class?

Because he is using that class as both his Mod class and his event handler class.

 

Quote

Any clues on what might be going wrong here?

I am pretty sure that you can not just create a Dimension on the server and expect the Client to be "Ok, I'm connecting to dimension 2. Oh that is similar to the overworld.

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Posted
18 hours ago, Animefan8888 said:

I am pretty sure that you can not just create a Dimension on the server and expect the Client to be "Ok, I'm connecting to dimension 2. Oh that is similar to the overworld.

I have seen servers running custom dimensions without the need of client-side mods before. Are there any pointers towards how to get that to work?

Posted (edited)

Before I abandon Forge, I'd really like to understand why exactly my approach is causing problems and what the common solution is (e.g. allowing client-side modding), because I cannot imagine to be the first person attempting to make custom dimensions with Forge. Transferring the player between dimensions does, after all, work. It is only that reconnecting to the custom-created one causes problems. I understand that I need to read code, but I would greatly appreciate if someone who has worked with this before can give me a helping hand. Thanks for the answers so far, by the way.

Edited by Zyl
Posted

Awesome! I hope the devs have interest in increasing modding options for servers that want to support vanilla clients.

 

For clarity, it might help to figure out what the client actually does use the DimensionType id for. The most important fact, however, is that the client never calls createChunkProvider().

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

    • Hi,  I'm using Forge 47.3.0 for Minecraft 1.20.1 I apologise if this is obvious I am very new to modding for Minecraft. I sucessfully made a mod that launched without errors or crashes (without it doing anything) but in order to add the features I need, I need to add "Custom Portal API [Forge]" as a dependency. However no matter the way I've tried to acheive this, it crashes. I am pretty sure it's not the way I'm putting it in the repositories, the dependencies or the way I'm refrencing it, as I've a hundred diffrent combinations and multiple Maven methods. And on all those diffrent variations I still get this crash: pastebin.com/UhumzZCZ Any tips would be invaluable as I've been loosing my mind over this!
    • Hi, i'm really having problems trying to set the texture to my custom item. I thought i'm doing everything correctly, but all i see is the missing texture block for my item. I am trying this for over a week now and getting really frustrated. The only time i could make the texture work, was when i used an older Forge version (52.0.1) for Minecraft (1.21.4). Was there a fundamental change for textures and models somewhere between versions that i'm missing? I started with Forge 54.1.0 and had this problem, so in my frustration i tried many things: Upgrading to Forge 54.1.1, created multiple new projects, workspaces, redownloaded everything and setting things up multiple times, as it was suggested in an older thread. Therea are no errors in the console logs, but maybe i'm blind, so i pasted the console logs to pastebin anyway: https://pastebin.com/zAM8RiUN The only time i see an error is when i change the models JSON file to an incorrect JSON which makes sense and that suggests to me it is actually reading the JSON file.   I set the github repository to public, i would be so thankful if anyone could take a look and tell me what i did wrong: https://github.com/xLorkin/teleport_pug_forge   As a note: i'm pretty new to modding, this is my first mod ever. But i'm used to programming. I had some up and downs, but through reading the documentation, using google and experimenting, i could solve all other problems. I only started modding for Minecraft because my son is such a big fan and wanted this mod.
    • Please read the FAQ (link in orange bar at top of page), and post logs as described there.
    • Hello fellow Minecrafters! I recently returned to Minecraft and realized I needed a wiki that displays basic information easily and had great user navigation. That’s why I decided to build: MinecraftSearch — a site by a Minecraft fan, for Minecraft fans. Key Features So Far Straight-to-the-Point Info: No extra fluff; just the essentials on items, mobs, recipes, loot and more. Clean & Intuitive Layout: Easy navigation so you spend less time scrolling and more time playing. Optimized Search: Search for anything—items, mobs, blocks—and get results instantly. What I’m Thinking of Adding More data/information: Catch chances for fishing rod, traveling villager trades, biomes info and a lot more. The website is still under development and need a lot more data added. Community Contributions: Potential for user-uploaded tips for items/mobs/blocks in the future. Feature Requests Welcome: Your ideas could shape how the wiki evolves! You can see my roadmap at the About page https://minecraftsearch.com/about I’d love for you to check out MinecraftSearch and see if it helps you find the info you need faster. Feedback is crucial—I want to develop this further based on what the community needs most, so please let me know what you think. Thanks, and happy crafting!
    • Instructions on how to install newer Java can be found in the FAQ
  • Topics

  • Who's Online (See full list)

    • There are no registered users currently online
×
×
  • Create New...

Important Information

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