New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Nether Portal Jumping & Creation Code #2162
Conversation
@@ -295,7 +295,7 @@ eDimension StringToDimension(const AString & a_DimensionString) | |||
{ | |||
// First try decoding as a number | |||
int res; | |||
if (!StringToInteger(a_DimensionString, res)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, I got a few of these wrong.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm going to manually apply this patch to master, because its an important fix.
Please try to use the same coding style. We use a space after all commas, and a space around pointer and reference declarations ( |
Okay, I'll go back through as I move it to a new file. |
{ | ||
if (m_FoundPortal) | ||
{ | ||
m_PortalLoc = m_PortalLoc; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I doubt this is needed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch, thanks.
Okay, I think I got it compliant with the coding convention in bad47a8, except maybe local variable names, I don't know what the convention is for those. I didn't see any commas without spaces, though, so I'm probably looking at the wrong commas? |
m_ReadyToChangeWorlds = false; | ||
MoveToWorld(m_NewWorld, false, m_NewWorldPosition); | ||
return true; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This block deserves a comment above it explaining what it is doing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think a simple /* If a move to another world was scheduled via ScheduleMoveToWorld(), move the entity now. */
would have been enough. This is too wordy and still doesn't explain much. Also note that comments inside functions shouldn't use the doxy-comment format (/**
), only comments above declarations should use it.
Also the m_ReadyToChangeWorlds
is a somewhat misleading name, m_IsWorldChangeScheduled
might have been better.
What's the preferred way to convert between Vector types, e.g. from Vector3i to a Vector3d? |
I don't think there's any preference. There's a simple copy-constructor provided within the vector template, and for converting to a |
Okay. I think I've fixed the convention errors. |
m_Dir = 0; | ||
m_Position = a_DestPosition; | ||
m_PortalLoc = a_DestPosition.Floor(); | ||
m_MaxY = a_MaxY; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These should go in the initialization section of the constructor
Alright, I just refactored m_Dir to use a Direction type which is either X or Y (I considered NORTH_SOUTH and EAST_WEST, but that didn't seem to map to the code as well). |
Is there any chance you could get this rebased onto current master and squashed into a single commit? |
Sure thing. Done. |
I think this is merge-worthy. Opinions? |
@@ -530,6 +535,11 @@ class cEntity | |||
eEntityType m_EntityType; | |||
|
|||
cWorld * m_World; | |||
|
|||
/// State variables for ScheduleMoveToWorld. | |||
bool m_IsWorldChangeScheduled = false; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't this be initialized in the construcor? That is where we usualy initialize member variables right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And also /** */
for comment style.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, it should be initialized in the constructor. For the comment, there was a previous block of several comments there that were triple slashes, so I changed the whole block in the commit I just now pushed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, sorry for the comment style, we couldn't decide on the format beforehands, so one half of the code uses ///
and the other half uses /** */
. We've since then decided to use the latter, but didn't fix the former yet. Good call about replacing them all.
Apart from the question I have about the |
Please add yourself to the contributors file. |
virtual bool OnAllChunksAvailable(void) override; | ||
virtual void OnDisabled(void) override; | ||
|
||
enum Direction |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe enum class Direction
?
Looks like it's ready for merge |
Nether Portal Jumping & Creation Code
After almost a month I finally updated my MCServer and tried this, and I noticed that when teleporting to an portal I get teleported 1 block next to it. That probably isn't intended right? You're supposed to teleport in another portal. EDIT: |
Also, you get teleported instantly but I think this is another issue |
That's only in creative gamemode right? Because in vanilla you also get teleported instantly in creative mode. |
m_World->GetChunkBlockTypes(a_ChunkX, a_ChunkZ, blocks); | ||
|
||
// Iterate through all of the blocks in the chunk | ||
for (unsigned int i = 0; i < cChunkDef::NumBlocks; i++) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking at this again, shouldn't this be i += 2
as suggested by @madmaxoft here? It would speed up the search for a nether portal by quite allot since it wouldn't have to check every block in the chunk.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because of the way the chunks are stored (XZY?), doing i+2 here would result in a pattern that skips every other row. Note that it's iterating from 0 to NumBlocks, not 0 to 16 each axis - this results in a speedup in not having to call CoordinateToIndex.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would have been possible to have two loops, the inner one iterating over the 256 blocks in a single Y slice, and the outer one iterating over Y slices, skipping 2 slices out of each 3:
for (unsigned y = 0; y < cChunkDef::Height; y += 3)
{
unsigned BaseY = cChunkDef::Width * cChunkDef::Width * y;
for (unsigned i = 0; i < 256; i++)
{
// Check block at index [BaseY + i]
}
}
I tested this, I can not get back to the world from the nether trough the portal. Used the FAQ for creating a nether world. |
That's probably because you haven't configured the world linking in the world.ini. The FAQ only describes how you can generate such a world. |
Yes, this is a problem. You have to stand right in the portal to teleport. in vanilla you only need partial contact with the portal. Also, you are getting damage for travelling to the nether |
This is to do with lack of bounding box detection in MCS at the present. |
That was intended, but can be changed easily. |
I think it should be changed, because I got teleported in the portal frame once. It could also be possible to be teleported inside a wall if the portal is next to it. |
I'm not sure you can since it places the portal in a 3x4x5 empty space, so there's always air on either side of the portal. But I can change it anyway. |
But if I build a portal against a wall then there isn't an empty space around it. ^^ |
Oh, that's true. I hadn't thought about manually created portals. I will change that & the Y limit and make a PR after #2237 is closed. Having multiple forks is so much effort. |
Per #1856, this code implements a portal scanner which finds and creates nether portals when entities move between the overworld and the nether.
It also changes dae9e579#diff-97bcf8a96a22aec81982926aa1462363R298 because StringToInteger returns true if the conversion was successful. I think.