Jump to content
  • Home
  • Files
  • Docs
  • Merch
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
  • [1.12.2] Custom IChunkLoader
1.13 Update Notes for Mod Creators
Sign in to follow this  
Followers 0
the4naves

[1.12.2] Custom IChunkLoader

By the4naves, June 18 in Modder Support

  • Reply to this topic
  • Start new topic

Recommended Posts

the4naves    0

the4naves

the4naves    0

  • Tree Puncher
  • the4naves
  • Members
  • 0
  • 11 posts
Posted June 18 (edited)

So long story short, I need to be able to return any chunk I want when the game requests to load a chunk (Ex: Game requests chunk at (5, -3), I return the chunk at say, (2, 7), then display that chunk at (5, -3)).

Looking through the source code, it seems the way to do this would be to utilize a custom IChunkLoader, and/or IChunkProvider (NOTE: I do NOT mean IChunkGenerator. From what I understand, the chunk generator used to be called the chunk provider, but that serves a completely different purpose now), however there doesn't seem to be any way to access instances of these classes (Or at least the classes that implement them) other than reflection and a custom WorldProvider in a custom dimension, as all fields I could find were private or protected.

So before I go along with my reflection route, is there an easier/intended way of doing this, and are the classes I've found even the correct ones?

I've done a fair amount of research, but no one seems to have an answer.

Edited June 18 by the4naves
Ease of Reading
  • Quote

Share this post


Link to post
Share on other sites

diesieben07    6671

diesieben07

diesieben07    6671

  • Reality Controller
  • diesieben07
  • Forum Team
  • 6671
  • 45584 posts
Posted June 18

Do you want the chunks to actually be mirrors of each other? i.e. if player places a block in one, it's also placed in another?

  • Quote

Share this post


Link to post
Share on other sites

the4naves    0

the4naves

the4naves    0

  • Tree Puncher
  • the4naves
  • Members
  • 0
  • 11 posts
Posted June 18 (edited)

In essence, yes, though the approach I'm going for is more simply overriding, for example, the loadChunk() method in IChunkLoader. (Or similer)

So in other words, I'd like to "trick" the game into thinking the Chunks I give it when it requests them are the actual world.

For placing blocks, maybe sounds and mob AI, those will probably need more overrides, most likely overriding the methods to get a block in the world, along others, but I can address those later.

In the best case scenario I would just like to be able to provide my own subclasses to be used instead of the vanilla ones.

Edited June 18 by the4naves
Extra info
  • Quote

Share this post


Link to post
Share on other sites

diesieben07    6671

diesieben07

diesieben07    6671

  • Reality Controller
  • diesieben07
  • Forum Team
  • 6671
  • 45584 posts
Posted June 19

First, some terminology:

  • IChunkGenerator: Generates new chunks, implementations exist for overworld, nether, etc.
  • IChunkLoader: Loads existing chunks from disk, only implementation is AnvilChunkLoader and it's expected to be the only one in many places.
  • IChunkProvider: Basically manages a world's chunks in memory. Will use IChunkLoader to load existing ones from disk and IChunkGenerator to generate new ones.

I still think it's a bad idea to have the same Chunk object at two different places. Firstly, because Chunk has built in x and z coordinates and also because Chunks hold TileEntities, which store their absolute block coordinates (not chunk relative).

What you need to do is either have a very custom Chunk implementation which mirrors some other chunk or give up on mirroring and just return a copy at the time of request.

  • Quote

Share this post


Link to post
Share on other sites

the4naves    0

the4naves

the4naves    0

  • Tree Puncher
  • the4naves
  • Members
  • 0
  • 11 posts
Posted June 19

To your first point, I do mostly agree, I think having the same Chunk loaded in multiple places at the same time could cause all kinds of problems, but what I'm planning on doing shouldn't ever create a situation like that.

To give some context, I'm trying to create a "world wrap" effect, where the world loops infinitely in a specific direction (Generation can be handled by tile-able noise). To do this, there will be an invisible "border" that will teleport you to the other side when you touch it. To prevent the game from having to suddenly load a bunch of chunks and to prevent structures you've build from suddenly popping in, as you approach the border, the game should load chunks on the other side, and provide them to the chunk provider in lieu of what is actually near you.

So I suppose a custom chunk could simply mirror the chunks it needs to, but a custom chunk loader/maybe a provider seems cleaner and might be better for performance.

  • Quote

Share this post


Link to post
Share on other sites

diesieben07    6671

diesieben07

diesieben07    6671

  • Reality Controller
  • diesieben07
  • Forum Team
  • 6671
  • 45584 posts
Posted June 19

And then someone places a chunkloader somewhere and your assumption breaks.

Or, even simpler, there are two people on the server.

  • Quote

Share this post


Link to post
Share on other sites

the4naves    0

the4naves

the4naves    0

  • Tree Puncher
  • the4naves
  • Members
  • 0
  • 11 posts
Posted June 19

But wouldn't you get that anyway in vanilla with two players, or a player and a chunk loader in the same area?

  • Quote

Share this post


Link to post
Share on other sites

diesieben07    6671

diesieben07

diesieben07    6671

  • Reality Controller
  • diesieben07
  • Forum Team
  • 6671
  • 45584 posts
Posted June 19
4 minutes ago, the4naves said:

But wouldn't you get that anyway in vanilla with two players, or a player and a chunk loader in the same area?

Yes. But vanilla does not try to load the same chunk in two places.

  • Quote

Share this post


Link to post
Share on other sites

the4naves    0

the4naves

the4naves    0

  • Tree Puncher
  • the4naves
  • Members
  • 0
  • 11 posts
Posted June 19

Ok, so I've looked into the source code a bit more, and it looks like everything I'm trying to do could be accomplished by overriding the WorldClient and by the looks of it WorldServer classes. (Subclasses of World)

The Minecraft class keeps a public instance of WorldClient (Yay no reflection), and it seems to only be set in loadWorld(). Forge seems to have the job of loading worlds, and when doing so calls launchIntegratedServer(), which starts the server. I'm not sure overriding WorldServer is required though.

Is there a forge event or something similar that fires on world load I could hook into to replace the world with my own subclass? (The subclass would copy over the info from the existing one if needed)

Thanks for your help.

  • 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 0
Go To Topic Listing



  • Recently Browsing

    No registered users viewing this page.

  • Posts

    • yegor
      [1.12.2] Transparent armor not rendering properly.

      By yegor · Posted 1 hour ago

      In my mod I have transparent armor which I created with an "ArmorSlime" class, which extends ItemArmor. The item texture for my armor is slightly transparent and it renders correctly, even in item frames.   The armor model uses a slightly transparent texture, which works on the player model, but when I place the armor on an armor stand, it is rendered fully opaque.   Is this a mod issue, or an issue with minecraft itself? Is there a solution?  
    • yegor
      moving topic to just modding support

      By yegor · Posted 1 hour ago

      Moved
    • J0WAY
      [1.12.2] How do i make it so my sword renders in my mobs hand?.

      By J0WAY · Posted 1 hour ago

      Okay, But my main problem is why won't my sword spawn on my mob because i did just change it to the vanilla code and it still doesn't work.  
    • thedarkcolour
      [1.14] Patching method with coremod in TreeFeature causes IncompatibleClassChangeError

      By thedarkcolour · Posted 3 hours ago

      https://github.com/thedarkcolour/Future-MC/tree/1.14
    • Draco18s
      [1.14] layout of a modpack

      By Draco18s · Posted 4 hours ago

      I'm pretty sure I've left some comments on his videos about the mistakes he's perpetuating, but its not like anyone reads those.
  • Topics

    • yegor
      0
      [1.12.2] Transparent armor not rendering properly.

      By yegor
      Started 1 hour ago

    • yegor
      0
      moving topic to just modding support

      By yegor
      Started 1 hour ago

    • J0WAY
      2
      [1.12.2] How do i make it so my sword renders in my mobs hand?.

      By J0WAY
      Started 6 hours ago

    • thedarkcolour
      15
      [1.14] Patching method with coremod in TreeFeature causes IncompatibleClassChangeError

      By thedarkcolour
      Started 21 hours ago

    • JetCobblestone
      4
      [1.14] layout of a modpack

      By JetCobblestone
      Started 9 hours ago

  • Who's Online (See full list)

    • J0WAY
    • DaemonUmbra
    • Jvramegared
    • Altimus
    • Kermos_the_Wise
    • xieao
    • thedarkcolour
    • thinkverse
    • darielernesto11
  • All Activity
  • Home
  • Mod Developer Central
  • Modder Support
  • [1.12.2] Custom IChunkLoader
  • Theme
  • Contact Us
  • Discord

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