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

Since there's no cooldown the player will go on a constant loop on changing dimensions since the player is inside the block. Here's what I have:


My portal block:
 

    @Override
    public void entityInside(BlockState blockState, Level level, BlockPos blockPos, Entity entity)
    {
        if(entity.isOnPortalCooldown()) {
            entity.setPortalCooldown();
        }

        if(!entity.isOnPortalCooldown() && entity instanceof LivingEntity) {
            if (!level.isClientSide())
            {
                if (!entity.isCrouching())
                {
                    MinecraftServer server = level.getServer();

                    if (server != null)
                    {
                        if (level.dimension() == DimensionsSTLCON.XENOSPHERE_KEY)
                        {
                            ServerLevel overWorld = server.getLevel(Level.OVERWORLD);
                            if (overWorld != null)
                            {
                                entity.changeDimension(overWorld, new XenosphereTeleporter(blockPos, false));
                            }
                        }
                        else
                        {
                            ServerLevel serverLevel = server.getLevel(DimensionsSTLCON.XENOSPHERE_KEY);
                            if (serverLevel != null)
                            {
                                entity.changeDimension(serverLevel, new XenosphereTeleporter(blockPos, true));
                            }
                        }
                    }
                }
            }
        }
    }

 

And my teleporter:
 

public class XenosphereTeleporter implements ITeleporter
{
    public static BlockPos thisPos = BlockPos.ZERO;
    public static boolean insideDimension = true;

    public XenosphereTeleporter(BlockPos pos, boolean insideDim)
    {
        thisPos = pos;
        insideDimension = insideDim;
    }

    @Override
    public Entity placeEntity(Entity entity, ServerLevel currentWorld, ServerLevel destinationWorld,
                              float yaw, Function<Boolean, Entity> repositionEntity)
    {
        entity = repositionEntity.apply(false);
        int y = 69;

        if (!insideDimension)
        {
            y = thisPos.getY();
        }

        BlockPos destinationPos = new BlockPos(thisPos.getX(), y, thisPos.getZ());

        int tries = 0;
        while ((destinationWorld.getBlockState(destinationPos).getMaterial() != Material.AIR) &&
                !destinationWorld.getBlockState(destinationPos).canBeReplaced(Fluids.WATER) &&
                destinationWorld.getBlockState(destinationPos.above()).getMaterial() != Material.AIR &&
                !destinationWorld.getBlockState(destinationPos.above()).canBeReplaced(Fluids.WATER) && tries < 25)
        {
            destinationPos = destinationPos.above(2);
            tries++;
        }

        entity.teleportTo(destinationPos.getX(), destinationPos.getY(), destinationPos.getZ());

        if (insideDimension)
        {
            boolean doSetBlock = true;
            for (BlockPos checkPos : BlockPos.betweenClosed(destinationPos.below(10).west(10).south(10), destinationPos.above(10).east(10).north(10)))
            {
                if (destinationWorld.getBlockState(checkPos).getBlock() instanceof XenosphereTeleporterBlock)
                {
                    doSetBlock = false;
                    break;
                }
            }
            if (doSetBlock)
            {
                destinationWorld.setBlock(destinationPos, BlocksSTLCON.XENOSPHERE_PORTAL.get().defaultBlockState(), 3);
            }
        }

        return entity;
    }
}

 

I've tried several ways but no luck, unfortunately, and ideas?

 

15 hours ago, Feroov said:

I've tried several ways but no luck, unfortunately, and ideas?

You need to call `Entity#setPortalCooldown` twice: once when the entity is within the portal with a cooldown, and once when the entity is teleported by the portal. The first check prevents the entity from being teleported back if they haven't left the portal for a certain period of time. The second is for actually telling the entity that is has been teleported, and that it should verify the first check. You've currently only got the first check in place, which won't do anything on its own. You need to also set the cooldown after the entity has been teleported.

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.