Skip to content
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

Merged
merged 1 commit into from Jun 10, 2015
Merged

Conversation

lkolbly
Copy link
Contributor

@lkolbly lkolbly commented May 29, 2015

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.

@@ -295,7 +295,7 @@ eDimension StringToDimension(const AString & a_DimensionString)
{
// First try decoding as a number
int res;
if (!StringToInteger(a_DimensionString, res))
Copy link
Member

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.

Copy link
Member

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.

@madmaxoft
Copy link
Member

Please try to use the same coding style. We use a space after all commas, and a space around pointer and reference declarations (cWorld * a_World etc.) There's too many of these to report each one. Unfortunately the basic stylechecking script cannot detect these reliably, so you'll need to do it by hand.

@lkolbly
Copy link
Contributor Author

lkolbly commented May 29, 2015

Okay, I'll go back through as I move it to a new file.

{
if (m_FoundPortal)
{
m_PortalLoc = m_PortalLoc;
Copy link
Member

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, thanks.

@lkolbly
Copy link
Contributor Author

lkolbly commented May 30, 2015

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;
}
Copy link
Member

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.

Copy link
Member

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.

@lkolbly
Copy link
Contributor Author

lkolbly commented May 30, 2015

What's the preferred way to convert between Vector types, e.g. from Vector3i to a Vector3d?

@madmaxoft
Copy link
Member

I don't think there's any preference. There's a simple copy-constructor provided within the vector template, and for converting to a Vector3i there's also the Floor() function defined on the class (Ceil() is missing right now, but could be added with minimal effort).

@lkolbly
Copy link
Contributor Author

lkolbly commented Jun 2, 2015

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;
Copy link
Member

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

@lkolbly
Copy link
Contributor Author

lkolbly commented Jun 6, 2015

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).

@madmaxoft
Copy link
Member

Is there any chance you could get this rebased onto current master and squashed into a single commit?

@lkolbly
Copy link
Contributor Author

lkolbly commented Jun 8, 2015

Sure thing. Done.

@madmaxoft
Copy link
Member

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;
Copy link
Member

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?

Copy link
Member

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.

Copy link
Contributor Author

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.

Copy link
Member

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.

@NiLSPACE
Copy link
Member

NiLSPACE commented Jun 9, 2015

Apart from the question I have about the m_IsWorldChangeScheduled initialization it looks really good.

@ghost
Copy link

ghost commented Jun 9, 2015

Please add yourself to the contributors file.

virtual bool OnAllChunksAvailable(void) override;
virtual void OnDisabled(void) override;

enum Direction
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe enum class Direction?

@sphinxc0re
Copy link
Contributor

Looks like it's ready for merge

madmaxoft added a commit that referenced this pull request Jun 10, 2015
Nether Portal Jumping & Creation Code
@madmaxoft madmaxoft merged commit d436a71 into cuberite:master Jun 10, 2015
@NiLSPACE
Copy link
Member

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:
I also noticed that if I create a portal on the top of the nether, go through it, and then go back in the portal I get teleported to the top of the nether. Vanilla doesn't allow this to happen.

@sphinxc0re
Copy link
Contributor

Also, you get teleported instantly but I think this is another issue

@NiLSPACE
Copy link
Member

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++)
Copy link
Member

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.

Copy link
Contributor Author

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.

Copy link
Member

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]
  }
}

@ghost
Copy link

ghost commented Jun 13, 2015

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.

@NiLSPACE
Copy link
Member

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.

@sphinxc0re
Copy link
Contributor

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

@tigerw
Copy link
Member

tigerw commented Jun 13, 2015

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.

This is to do with lack of bounding box detection in MCS at the present.

@lkolbly
Copy link
Contributor Author

lkolbly commented Jun 13, 2015

@NiLSPACE

... and I noticed that when teleporting to an portal I get teleported 1 block next to it.

That was intended, but can be changed easily.

@NiLSPACE
Copy link
Member

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.

@lkolbly
Copy link
Contributor Author

lkolbly commented Jun 13, 2015

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.

@NiLSPACE
Copy link
Member

But if I build a portal against a wall then there isn't an empty space around it. ^^

@lkolbly
Copy link
Contributor Author

lkolbly commented Jun 13, 2015

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants