immortius / chunkbychunk

Minecraft mod in which you unlock the world chunk by chunk
Other
17 stars 5 forks source link

Multiple per-person chunk system #75

Open SkytraceXLSU opened 1 year ago

SkytraceXLSU commented 1 year ago

Is it possible to create a world where each player can generate their own chunks, similar to a skyblock, when they join the server?

If yes, how can I achieve this?

If not, what can I do? I've considered using a mod that creates separate worlds for each player, but I haven't found a mod that meets my needs.

Thank you.

immortius commented 1 year ago

This overlaps a bit with the suggestions in #50

Currently there is nothing natively in chunk by chunk to start players with a chunk spawner, or to give them ownership over their spawned chunks. There may be other mods that provide the ability to start players with specific items which would address the first point - perhaps with some way of randomising their initial spawn location. Otherwise there is a big body of work in setting up a full system in this space, perhaps integrated with other mods that provide support for establishing parties. I'm not willing to commit to that at the moment though.

SkytraceXLSU commented 1 year ago

yes thx I alraedy find with kubeJS all work correctly but need to be oped for execute /chunkbychunk:spawnChunk ~ ~ ~ and I don't find in kubeJS how to oped and deoped :/ but its work

ServerEvents.commandRegistry(event => { const { commands: Commands } = event; event.register( Commands.literal('chunkcreate') //.requires(source => source.hasPermission(2)) .executes(ctx => { const player = ctx.getSource().getPlayer();

        const minRange = -10000; 
        const maxRange = 10000; 

        const targetX = Math.floor(Math.random() * (maxRange - minRange + 1) + minRange);
        const targetY = 300
        const targetZ = Math.floor(Math.random() * (maxRange - minRange + 1) + minRange);
        player.server.runCommand(`/op ${player.getName()}`);
        player.setPosition(targetX, targetY, targetZ);
        player.server.runCommand(`/effect give @p minecraft:resistance 25 255`);
        player.runCommand(`/chunkbychunk:spawnChunk ~ ~ ~`);
        player.server.runCommand(`/deop ${player.getName()}`);
        return 1;
    })
);

});

RaeTheGit commented 5 months ago

I feel I'm handling the same issue as this one. I also went for the KubeJS route. I defined a global array with a bunch of spawn coords and want to spawn in a 3x3 of chunks enforced to plains biome around the player to ensure they get some trees and can easily get to safety if spawned on water due to the enforced coords. This is what I've got so far:

PlayerEvents.loggedIn(event => {
  // is it their first join?
  if (!event.player.stages.has('pSpawnIDX')) {
    let sPDATA = event.server.persistentData;
    let thisPlayer = event.entity.username;

    // if it's the first player joining, initialise index counter
    if (!sPDATA.spawnIndex) sPDATA.spawnIndex = 0;

    // get the coords set at current index position
    let spawnSet = global.spawnCoords[sPDATA.spawnIndex];
    let spawnX = spawnSet[0];
    let spawnZ = spawnSet[1];

    // tp the player to their coords, spawn in 3x3 chunks
    event.server.runCommandSilent(`teleport ${thisPlayer} ${spawnX} 300 ${spawnZ}`);
    event.server.runCommandSilent(`effect give ${thisPlayer} minecraft:resistance 25 255`);

    const spawnOffsets = [0, -16, +16];
    for (const thisOffsetX of spawnOffsets) {
      for (const thisOffsetZ of spawnOffsets) {
        let trueX = spawnX + thisOffsetX;
        let trueZ = spawnZ + thisOffsetZ;
        event.server.runCommand(`execute as ${thisPlayer} run chunkbychunk:spawnThemedChunk plains ${(trueX)} 0 ${(trueZ)}`);

      }
    }
    // set player spawnpoint, bring indices up to date
    [...]
  }
});

For some reason, only the command in the first iteration of the for-loop is successful. Is the spawnChunk command limited to one per tick? do I need to add delays between the iterations? Or is there another reason why the first iteration succeeds but the other 8 commands fail? Unfortunately I also couldn't find a method to un-silence the spawnChunk command to get a better hint on why it's failing.

immortius commented 5 months ago

Hmm, there's no rate limit on the commands (they add the chunks to the queue of chunks to spawn, so won't do it immediately but it should happen fairly quickly). I gave your script a quick test (with some tweaks given it is a code fragment) and it looks to work ok, although I would note that the plains theme doesn't prevent ocean spawns (since biomes are applied after heightmap is generated).

RaeTheGit commented 5 months ago

Hmm, thanks for the heads up on the heightmap matter even though I've no idea how to solve that. In playtesting of my pack I noticed there (often) is up to a couple seconds delay between issuing the command or clicking the chunk spawner and the chunks actually appearing which led me to the theory there might be a phase where followup spawn requests would get ignored and made me wait for a while to see if the additional chunks would appear, but to no avail.

So for now I'm out of ideas why it doesn't work for me, particularly since it works for you :(