Jump to content

[SOLVED] [1.16.2] Player isn't teleported when he sneak


Recommended Posts

Posted (edited)

Hi everybody !

 

I have a problem with my custom event's code...

 

@SubscribeEvent
public static void onShiftInElevator(InputEvent.KeyInputEvent event) {
    LivingEntity player = Minecraft.getInstance().player;
    World world = player.getEntityWorld();
    if (event.getKey() == GLFW_KEY_LEFT_SHIFT) {
        if (world.getBlockState(player.func_233580_cy_().add(0, -1, 0)).getBlock() == (ModBlocks.ELEVATOR_BLOCK.get())) {
            boolean finish = false;
            double checkY = -1;
            while(!finish && checkY > -11) {
                checkY--;
                if (world.getBlockState(player.func_233580_cy_().add(0, checkY, 0)).getBlock() == (ModBlocks.ELEVATOR_BLOCK.get())) {
                    player.sendMessage(ITextComponent.func_244388_a("Test"), player.getUniqueID());
                    player.setPositionAndUpdate(player.getPosX(), player.getPosY()+checkY+1, player.getPosZ());
                    finish = true;
                }
            }
        }
    }
}

I want that when the player sneak on the ModBlocks.ELEVATOR_BLOCK, he is teleported to the next same block below him.

I tried this code, and the message "Test" (line 12) appear, but the player still not move...

 

Please, can anybody help me to fix it ????

Thanks a lot !

Edited by Korantin

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



×
×
  • Create New...

Important Information

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