Jump to content
  • Home
  • Files
  • Docs
Topics
  • All Content

  • This Topic
  • This Forum

  • Advanced Search
  • Existing user? Sign In  

    Sign In



    • Not recommended on shared computers


    • Forgot your password?

  • Sign Up
  • All Activity
  • Home
  • Mod Developer Central
  • Modder Support
  • (Custom Bed) Player Lies on Wrong Place
Currently Supported: 1.16.X (Latest) and 1.15.X (LTS)
Sign in to follow this  
Followers 2
JanneSoon

(Custom Bed) Player Lies on Wrong Place

By JanneSoon, August 29, 2018 in Modder Support

  • Reply to this topic
  • Start new topic

Recommended Posts

JanneSoon    1

JanneSoon

JanneSoon    1

  • Tree Puncher
  • JanneSoon
  • Members
  • 1
  • 21 posts
Posted August 29, 2018 (edited)

Hello. Trying to add a custom bed. All is working, but player lies on wrong place when sleep on it, as you can see in the video below:

The white bed is the vanilla bed. Other beds are the bed that i add.

It's not a huge problem, but i want to fix this. Thanks for incoming answers.

It's on MC 1.12.2, Forge 2758

Edited August 29, 2018 by JanneSoon
  • Quote

Share this post


Link to post
Share on other sites

JanneSoon    1

JanneSoon

JanneSoon    1

  • Tree Puncher
  • JanneSoon
  • Members
  • 1
  • 21 posts
Posted August 29, 2018 (edited)

Forgot to add, here is the base bed class and the bed parts classes: part1 part2

if needed, the class that base bed class extends: https://github.com/JanneSoon/HarshenUniverse/blob/master/src/main/java/kenijey/harshenuniverse/base/BaseHarshenFacedBlock.java

Edited August 29, 2018 by JanneSoon
  • Quote

Share this post


Link to post
Share on other sites

Zetko    1

Zetko

Zetko    1

  • Tree Puncher
  • Zetko
  • Members
  • 1
  • 13 posts
Posted August 29, 2018 (edited)

I suspect the problem is that the sleep location depends on which part of the bed you click. You could test that by right-clicking on the bottom and the head part of the bed and see if your sleeping position changes.

 

This is probably because both your parts of the bed are facing in the same direction, and you are offsetting the sleeping position in the same direction both times as both parts of the bed extend BaseBloodyBed.

 

73.			pos = pos.offset((EnumFacing)state.getValue(FACING));
.
.
.
82.			net.minecraft.world.WorldProvider.WorldSleepResult sleepResult = worldIn.provider.canSleepAt(playerIn, pos);

 

I think you should try disabling the offset on the head part of the bed and see if that fixes your problem.

 

You should also look at the vanilla code for a bed, it offsets the position only when the block is the bottom bed.

if (state.getValue(PART) != BlockBed.EnumPartType.HEAD) {
	pos = pos.offset((EnumFacing)state.getValue(FACING));
	state = worldIn.getBlockState(pos);

	if (state.getBlock() != this) {
		return true;
	}
}

net.minecraft.world.WorldProvider.WorldSleepResult sleepResult = worldIn.provider.canSleepAt(playerIn, pos);

 

Edited August 29, 2018 by Zetko
  • Quote

Share this post


Link to post
Share on other sites

JanneSoon    1

JanneSoon

JanneSoon    1

  • Tree Puncher
  • JanneSoon
  • Members
  • 1
  • 21 posts
Posted August 30, 2018
16 hours ago, Zetko said:

I suspect the problem is that the sleep location depends on which part of the bed you click. You could test that by right-clicking on the bottom and the head part of the bed and see if your sleeping position changes.

 

This is probably because both your parts of the bed are facing in the same direction, and you are offsetting the sleeping position in the same direction both times as both parts of the bed extend BaseBloodyBed.

 


73.			pos = pos.offset((EnumFacing)state.getValue(FACING));
.
.
.
82.			net.minecraft.world.WorldProvider.WorldSleepResult sleepResult = worldIn.provider.canSleepAt(playerIn, pos);

 

I think you should try disabling the offset on the head part of the bed and see if that fixes your problem.

 

You should also look at the vanilla code for a bed, it offsets the position only when the block is the bottom bed.


if (state.getValue(PART) != BlockBed.EnumPartType.HEAD) {
	pos = pos.offset((EnumFacing)state.getValue(FACING));
	state = worldIn.getBlockState(pos);

	if (state.getBlock() != this) {
		return true;
	}
}

net.minecraft.world.WorldProvider.WorldSleepResult sleepResult = worldIn.provider.canSleepAt(playerIn, pos);

 

Thank you for your help. See the commit i did just now: https://github.com/JanneSoon/HarshenUniverse/commit/3675f103a9b507afff3dcbc752a54ba18cc9746a

The lying position changes when try to sleep from the bottom part, you're right. But it's still buggy, the sleeping place still not correct, not exactly on the bed.

You also said that direction shouldn't be same with both parts. But on vanilla bed, both parts' facing is same? While looking to vanilla bed's both parts, only "part" value changes, rest is same (minecraft:bed, facing:)

  • Quote

Share this post


Link to post
Share on other sites

Zetko    1

Zetko

Zetko    1

  • Tree Puncher
  • Zetko
  • Members
  • 1
  • 13 posts
Posted August 30, 2018 (edited)

You should keep the bed part facing the same as in the vanilla bed, sorry if I confused you. I was only pointing this out because you were offsetting in both parts of the bed in the facing direction. 

 

I looked through your code and I don't see the offset code. Could you please point me where it is?

Did you delete it?

Edited August 30, 2018 by Zetko
  • Quote

Share this post


Link to post
Share on other sites

JanneSoon    1

JanneSoon

JanneSoon    1

  • Tree Puncher
  • JanneSoon
  • Members
  • 1
  • 21 posts
Posted August 30, 2018
2 hours ago, Zetko said:

You should keep the bed part facing the same as in the vanilla bed, sorry if I confused you. I was only pointing this out because you were offsetting in both parts of the bed in the facing direction. 

 

I looked through your code and I don't see the offset code. Could you please point me where it is?

Did you delete it?

I just made a commit after reading your first comment, and shared the link of that commit in the last comment. Nothing else. And i don't understand what you mean by offset code :S

About the first sentence, i already did it same as in the vanilla bed? Sorry if i'm stupid at some point.

  • Quote

Share this post


Link to post
Share on other sites

Zetko    1

Zetko

Zetko    1

  • Tree Puncher
  • Zetko
  • Members
  • 1
  • 13 posts
Posted August 30, 2018 (edited)

So, let's start again:

 

In your BaseBloodyBed class, you should offset the sleeping position in the FACING direction if the block you right-clicked on is an instance of BloodyBed. 

 

Then try to sleep again and tell me what happens.

 

Edited August 30, 2018 by Zetko
  • Quote

Share this post


Link to post
Share on other sites

Zetko    1

Zetko

Zetko    1

  • Tree Puncher
  • Zetko
  • Members
  • 1
  • 13 posts
Posted August 30, 2018

You should add a version of the vanilla bed offset code between lines 68 and 69 of your BaseBloodyBed class.

 

The vanilla offset code:

if (state.getValue(PART) != BlockBed.EnumPartType.HEAD) {
	pos = pos.offset((EnumFacing)state.getValue(FACING));
	state = worldIn.getBlockState(pos);

	if (state.getBlock() != this) {
		return true;
	}
}

net.minecraft.world.WorldProvider.WorldSleepResult sleepResult = worldIn.provider.canSleepAt(playerIn, pos);

 

  • Quote

Share this post


Link to post
Share on other sites

JanneSoon    1

JanneSoon

JanneSoon    1

  • Tree Puncher
  • JanneSoon
  • Members
  • 1
  • 21 posts
Posted August 30, 2018
3 minutes ago, Zetko said:

You should add a version of the vanilla bed offset code between lines 68 and 69 of your BaseBloodyBed class.

 

The vanilla offset code:


if (state.getValue(PART) != BlockBed.EnumPartType.HEAD) {
	pos = pos.offset((EnumFacing)state.getValue(FACING));
	state = worldIn.getBlockState(pos);

	if (state.getBlock() != this) {
		return true;
	}
}

net.minecraft.world.WorldProvider.WorldSleepResult sleepResult = worldIn.provider.canSleepAt(playerIn, pos);

 

Yes i understood you, and i did it in this commit. Please take a look. Because it's still the same, not working :(

  • Quote

Share this post


Link to post
Share on other sites

Zetko    1

Zetko

Zetko    1

  • Tree Puncher
  • Zetko
  • Members
  • 1
  • 13 posts
Posted August 30, 2018

Is there a difference if you right-click on the leg and head part of the bed? Could you record it?

  • Quote

Share this post


Link to post
Share on other sites

JanneSoon    1

JanneSoon

JanneSoon    1

  • Tree Puncher
  • JanneSoon
  • Members
  • 1
  • 21 posts
Posted August 30, 2018
11 minutes ago, Zetko said:

Is there a difference if you right-click on the leg and head part of the bed? Could you record it?

I tested, and no, theres no difference. BUT with out that code that i committed about 10 mins ago, the place is different.

But the weird point is, the place that player lies, is getting insane after i sleep on any vanilla bed in the world. Isn't it weird?

  • Quote

Share this post


Link to post
Share on other sites

Zetko    1

Zetko

Zetko    1

  • Tree Puncher
  • Zetko
  • Members
  • 1
  • 13 posts
Posted August 30, 2018

Could you try creating a new BlockPos between lines 63 and 64, before you offset it, like this:

BlockPos pos = pos;

That might be the problem.

  • Quote

Share this post


Link to post
Share on other sites

JanneSoon    1

JanneSoon

JanneSoon    1

  • Tree Puncher
  • JanneSoon
  • Members
  • 1
  • 21 posts
Posted August 30, 2018
14 minutes ago, Zetko said:

Could you try creating a new BlockPos between lines 63 and 64, before you offset it, like this:


BlockPos pos = pos;

That might be the problem.

You mean this, right? (image)

If so, it didn't work too. :(

And it didn't fix the insane place bug that happens after lay on the vanilla bed then get up.

To explain this bug more:

I create a new world, place my custom beds, then try to sleep on them(only to lay on) the player lays on just 1 block away from the bed. So, pretty close to be fixed. But when i place a vanilla bed, right click then leave the bed, then try to lay on my custom bed, player lays bit more away (about 2-3 blocks).

asd.PNG

  • Quote

Share this post


Link to post
Share on other sites

Zetko    1

Zetko

Zetko    1

  • Tree Puncher
  • Zetko
  • Members
  • 1
  • 13 posts
Posted August 30, 2018 (edited)

Could you change 

if (state.getBlock() != HarshenBlocks.BLOODY_BED_HEAD)
{
	return true;
}

into this:

if (!(state.getBlock() instanceof this))
{
	return true;
}

 

Tell me if it works.

Edited August 31, 2018 by Zetko
  • Quote

Share this post


Link to post
Share on other sites

Zetko    1

Zetko

Zetko    1

  • Tree Puncher
  • Zetko
  • Members
  • 1
  • 13 posts
Posted August 30, 2018

Also, extend BlockHorizontal instead of BaseHarshenFacedBlock because trySleep() checks if the block is an instance of BlockHorizontal.

  • Quote

Share this post


Link to post
Share on other sites

JanneSoon    1

JanneSoon

JanneSoon    1

  • Tree Puncher
  • JanneSoon
  • Members
  • 1
  • 21 posts
Posted August 31, 2018
21 hours ago, Zetko said:

Could you change 


if (state.getBlock() != HarshenBlocks.BLOODY_BED_HEAD)
{
	return true;
}

into this:


if (state.getBlock() != this)
{
	return true;
}

 

Tell me if it works.

I did this too. nothing different. But... Sleeping from the bottom part is different than the head part. It's 1 block away different. But placing is still not correct

  • Quote

Share this post


Link to post
Share on other sites

JanneSoon    1

JanneSoon

JanneSoon    1

  • Tree Puncher
  • JanneSoon
  • Members
  • 1
  • 21 posts
Posted August 31, 2018 (edited)
20 hours ago, Zetko said:

Also, extend BlockHorizontal instead of BaseHarshenFacedBlock because trySleep() checks if the block is an instance of BlockHorizontal.

Yes, but i can sleep on the bed. If the check would fail, i couldn't. 

Oh my god, wait, it fixed the amazing placing bug! Now i can sleep actually on the bed, but only on the head part. If i right click on the bottom part, player lays 1 block away. And i can fix it, gonna just put a check for if its the bottom part so sleeping position will be changed into head part's pos. I don't really know but it's amazing!

Edited August 31, 2018 by JanneSoon
  • Quote

Share this post


Link to post
Share on other sites

JanneSoon    1

JanneSoon

JanneSoon    1

  • Tree Puncher
  • JanneSoon
  • Members
  • 1
  • 21 posts
Posted August 31, 2018

Thank you a lot @zetko! Extending BlockHorizontal class solved the solution!

  • Quote

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  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.

    • Insert image from URL
×
  • Desktop
  • Tablet
  • Phone
Sign in to follow this  
Followers 2
Go To Topic Listing



  • Recently Browsing

    No registered users viewing this page.

  • Posts

    • diesieben07
      Forge Not Opening

      By diesieben07 · Posted 13 minutes ago

      Also post the debug.log.
    • diesieben07
      [1.16.4]NullPointerException when using registered custom features

      By diesieben07 · Posted 14 minutes ago

      Show this class: McbbsWikiBiomeMaker.makeMcbbsWikiNormalBiome
    • diesieben07
      Detect recover an entity right click

      By diesieben07 · Posted 20 minutes ago

      Really old Minecraft versions are no longer supported on this forum. Please update to a modern version of Minecraft to receive support.
    • diesieben07
      how to make and .smd file parser for forge

      By diesieben07 · Posted 23 minutes ago

      You need to write a renderer for it.
    • diesieben07
      [1.16.4] Get IChunk World / get current World for the overworld.

      By diesieben07 · Posted 24 minutes ago

      What's the context? If you only have an IChunk (not a Chunk) you are likely in world generation, which does not have a world yet.
  • Topics

    • myrqn
      3
      Forge Not Opening

      By myrqn
      Started 3 hours ago

    • QWERTY 52 38
      1
      [1.16.4]NullPointerException when using registered custom features

      By QWERTY 52 38
      Started 1 hour ago

    • ElpisII
      1
      Detect recover an entity right click

      By ElpisII
      Started 2 hours ago

    • bouwmeester2003
      4
      how to make and .smd file parser for forge

      By bouwmeester2003
      Started December 8, 2018

    • MistyMarshes
      1
      [1.16.4] Get IChunk World / get current World for the overworld.

      By MistyMarshes
      Started 5 hours ago

  • Who's Online (See full list)

    • Ohmlolgg
    • kolbixbro
    • tf2_mandeokyi
    • CaelTheQuail
    • CookieLukas
    • diesieben07
    • S-Spirit
    • PauJM02
    • Thorius
  • All Activity
  • Home
  • Mod Developer Central
  • Modder Support
  • (Custom Bed) Player Lies on Wrong Place
  • Theme

Copyright © 2019 ForgeDevelopment LLC · Ads by Longitude Ads LLC Powered by Invision Community