Posted August 12, 20214 yr 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; } }
August 12, 20214 yr 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?
August 12, 20214 yr try to use a custom ITeleporter, if the game freezes, wait until the game crashes and post the debug log
August 12, 20214 yr 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.