Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

I'm attempting to create a portal to my custom dimension, but Minecraft freezes on the "Loading Terrain" screen whenever I enter. However, when I use commands to go to my dimension, it works fine.

I searched through Minecraft's libraries and decided to use a slightly modified version of the end portal's code for my portal, but when I debugged the mod, I noticed that my onEntityCollision method, which contains the code to switch dimensions, runs over and over. I believe this is what leads to the game becoming overloaded each time I use the portal. How would I go about fixing this?

 

The portal class:

package com.justinb.ramwal.blocks;

import com.justinb.ramwal.init.BlockInit;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.entity.Entity;
import net.minecraft.item.ItemStack;
import net.minecraft.util.Direction;
import net.minecraft.util.RegistryKey;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.registry.Registry;
import net.minecraft.world.IBlockReader;
import net.minecraft.world.IWorld;
import net.minecraft.world.World;
import net.minecraft.world.server.ServerWorld;

public class LemonPortalBlock extends Block {
    public LemonPortalBlock(Properties properties) {
        super(properties);
    }

    public BlockState updatePostPlacement(BlockState stateIn, Direction facing, BlockState facingState, IWorld worldIn, BlockPos currentPos, BlockPos facingPos) {
        return !isValidSpawn(currentPos, (World) worldIn) ? BlockInit.LEMONPORTAL.get().getDefaultState() : super.updatePostPlacement(stateIn, facing, facingState, worldIn, currentPos, facingPos);
    }

    public void onEntityCollision(BlockState state, World worldIn, BlockPos pos, Entity entityIn) {
        if (worldIn instanceof ServerWorld && !entityIn.isPassenger() && !entityIn.isBeingRidden() && entityIn.canChangeDimension()) {
            RegistryKey<World> dim = RegistryKey.getOrCreateKey(Registry.WORLD_KEY, new ResourceLocation("ramwal:lemondimension"));
            RegistryKey<World> registrykey = worldIn.getDimensionKey() == dim ? World.OVERWORLD : dim;
            ServerWorld serverworld = ((ServerWorld)worldIn).getServer().getWorld(registrykey);

            if (serverworld == null) {
                return;
            }

            entityIn.changeDimension(serverworld);
        }
    }

    public ItemStack getItem(IBlockReader worldIn, BlockPos pos, BlockState state) {
        return ItemStack.EMPTY;
    }

    public static boolean isValidSpawn(BlockPos pos, World worldIn) {
        for (int i = 2; i <= 5; i++)
            if (!(worldIn.getBlockState(pos.offset(Direction.byIndex(i))).getBlock() == BlockInit.GLITCH.get())) return false;
        return true;
    }
}

 

  • Author

If I change the ResourceLocation in the RegistryKey to anything else, serverworld ends up being null, so I'm assuming that the RegistryKey is correct. What am I missing?

try to use a custom ITeleporter,
if the game freezes,
wait until the game crashes and post the debug log

 

  • Author

That worked, thank you!

For anyone with the same issue, here is my code:

onEntityCollision method:

public void onEntityCollision(BlockState state, World worldIn, BlockPos pos, Entity entityIn) {
        if (worldIn instanceof ServerWorld && !entityIn.isPassenger() && !entityIn.isBeingRidden() && entityIn.canChangeDimension()) {
            RegistryKey<World> dim = RegistryKey.getOrCreateKey(Registry.WORLD_KEY, new ResourceLocation("ramwal:lemondimension"));
            RegistryKey<World> registrykey = worldIn.getDimensionKey() == dim ? World.OVERWORLD : dim;
            ServerWorld serverworld = ((ServerWorld)worldIn).getServer().getWorld(registrykey);

            if (serverworld == null) {
                return;
            }

            entityIn.changeDimension(serverworld, new ModTeleporter());
        }
    }

 

ModTeleporter class:

package com.justinb.ramwal.inherited;

import net.minecraft.entity.Entity;
import net.minecraft.world.server.ServerWorld;
import net.minecraftforge.common.util.ITeleporter;

import java.util.function.Function;

public class ModTeleporter implements ITeleporter {
    @Override
    public Entity placeEntity(Entity entity, ServerWorld currentWorld, ServerWorld destWorld, float yaw, Function<Boolean, Entity> repositionEntity)
    {
        return repositionEntity.apply(false);
    }
}

 

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...

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.