#backrooms

1 messages ยท Page 1 of 1 (latest)

vernal plank
#

hi

gray linden
#

hi, so

#

you want to paste a schematic basically "all the time", like every tick?

gray linden
#

that'll spam the whole world with your schematic, right?

vernal plank
#

Its going to generate the backrooms

#

basically

gray linden
#

no idea what backrooms are, but - if you want to run something all the time, you don't want to use any events or commands, you want to schedule a runnable that runs every tick

#

and you want it to loop over all online players

#

gimme a sec, I'll send you a short example

vernal plank
#

alright

gray linden
#
    @Override
    public void onEnable() {
        Bukkit.getScheduler().runTaskTimer(this, () -> {
            for(Player player : Bukkit.getOnlinePlayers()) {
                System.out.println(player.getName() + " is currently in the following world: " + player.getWorld().getName());
            }
        }, 1, 1);
    }
#

this would simply print out "mfnalex is in world world", "anotherPlayer is in world world_nether" etc every tick

#

so yeah, this runs for every player, every tick

vernal plank
#

alright, how could I implement this

gray linden
#

note that it already defined the "player" variable in the for loop

#

well you could just replace the System.out.println(...) thing with your "paste schematic" stuff

vernal plank
#

kk

vernal plank
gray linden
#

that depends on what location you put into the "paste" method of WorldEdit, ofc

#

I really think you should start with something more easy

#

e.g. make a command called /testpaste

#

and that will paste the schematic every time you run the command, at the desired distance

#

when you got that working, you can move it into the scheduler thing

#

it's way easier to do things step by step

vernal plank
#

Alright

vernal plank
#

Or is it strictly in OnEnable?

gray linden
#

the only proper place is to use onEnable() in 99% of cases

vernal plank
#

Alright

#

Tysm

gray linden
#

if you think it gets too large, you can just move it into your own method

#

for example:

#
    @Override
    public void onEnable() {
        Bukkit.getScheduler().runTaskTimer(this, () -> {
            System.out.println("First line of code");
            System.out.println("Second line of code");
            System.out.println("Third line of code");
            System.out.println("Fourth line of code");
            System.out.println("Fifth line of code");
            System.out.println("Sixth line of code");
            System.out.println("Seventh line of code");
        }, 1, 1);
    }

This is a bad idea

#
    @Override
    public void onEnable() {
        Bukkit.getScheduler().runTaskTimer(this, this::doStuff, 1, 1);
    }

    private void doStuff() {
        System.out.println("First line of code");
        System.out.println("Second line of code");
        System.out.println("Third line of code");
        System.out.println("Fourth line of code");
        System.out.println("Fifth line of code");
        System.out.println("Sixth line of code");
        System.out.println("Seventh line of code");
    }
#

this is a better idea

vernal plank
#

alright

gray linden
#

I wrote this a year ago because I myself was quite confused about this notation at first

vernal plank
#

Totally appreciate it

gray linden
#

np, that's what this discord is for ๐Ÿ™‚

#

but please listen to my advice to do steps one after another

#

first, just create a simple command that places your schematic next to the player who ran the command

#

when you got that working, then you can make it run every tick for every player

vernal plank
#

Ok @gray linden

#

it worked with the ommand

#

command

gray linden
#

okay, please show your command code

#

you should be able to just move it into the scheduler thing quite easily

vernal plank
#

QUite easily

gray linden
#

ah ok

#

so everything's working now?

vernal plank
#

Something I found funny hwoever

vernal plank
#

screenshot imminent

gray linden
#

sorry I don't understand what you're trying to say lol

gray linden
#

aaah

vernal plank
#

it like doesnt generate the full thing

gray linden
#

"screenshot imminent" means "there's a screenshot coming soon" lol

vernal plank
#

so confuse

#

xdd

gray linden
vernal plank
#

its generating random shit

vernal plank
#

Man you saved me 5 days of work

#

Thank you

gray linden
#

no problem :3

vernal plank
#

@gray linden , here comes the errors lol

#

It seems the schematic is running away from the user

#

Like the bottom and top are good

#

but the corridors

#

etc

#

are like running away lol

gray linden
#

well then your "location" logic is flawed

#

maybe ask in the "main thread" again, I cannot help you with any math stuff

vernal plank
#

Alright ty

vernal plank
#

So, how do I make a hashmap to check if the playter is in a new chunk

main heart
#

hey there tahd

vernal plank
#

Hi

main heart
#

ima do the Hashmap thing alex dw

vernal plank
main heart
#

have you ever seen a HashMap?

vernal plank
#

btw i am making the bckrooms

vernal plank
main heart
#

ok hold on

#

https://www.w3schools.com/java/java_hashmap.asp
This should be a pretty good resource

gray linden
#

a hashmap maps two values together

#

e.g. Name -> Age
mfnalex -> 27
mfnalex's father -> 67

main heart
#

basically what you do is you take the UUID of the player as a key and a Chunk as the value, then each tick you check whether map.get(uuid).equals(Bukkit.getPlayer(uuid).getLocation().getChunk)

vernal plank
#

Ok, should I set it as a varible?

main heart
#

and you have yourself something that will give you a boolean value on whether the player just entered a new chunk.

main heart
#

but I suggest having it in a controller class or so that only manages that HashMap

vernal plank
main heart
#

you can do that with a cache, yes

vernal plank
main heart
#

you make a HashMap<UUID, Chunk>, preferably somewhere where you can easily access it.

#

then you can put the uuids of the players you wanna check in there and link it to their current chunk with the put() method in the map

#

then you have a current and up to date view of what chunk a player is in

vernal plank
main heart
#

you just do it for all players

vernal plank
main heart
#

you would have an init() method that puts the uuid and chunk of each player in the map

#

and then maybe whenever another player joins you would add them

vernal plank
#

hmm

main heart
#

Bukkit.getOnlinePlayers() gives you a collection of all online players ๐Ÿ™‚

main heart
vernal plank
#

oh

#

lmao

#

ok

main heart
#

hold on, I'll make you a better example

vernal plank
#

hi

main heart
#

one second

#

there ya go. I hope that clears up a few of the HashMap functionalities

vernal plank
#

alr

main heart
#

the checkForNewChunk method will check whether the player is registered, if not the key value pair will be added and false will be returned. if the player is registered the old chunk will be checked against the current chunk of the player and true or false will be returned accordingly, updating the value for the player if they are in fact in a new chunk

vernal plank
main heart
#

the name of the class has to be used for constructors

#

my class was named "ExampleCache"

#

yours would be different

#

for example "ChunkCache"

#

but I do suggest having it in its own class

#

Ive gotta go, I hope that cleared it up a bit

vernal plank
#

Can I send you my code

#

I repurposed it

main heart
#

Sure

main heart
#

I meant a new class file, not a class inside a method

vernal plank
main heart
#

Also the method should only tell you whether the player is or is not in a new chunk, you should keep it that way

vernal plank
main heart
#

You create a new Cache for your main class and then call its methods from there when needed

vernal plank
#

ok

vernal plank
main heart
#

Not sure what you mean

#

A new ChunkCache object

gray linden
#
public class MyClass {
  private final Map<String,Object> myMap;
  
  public MyClass() {
    this.myMap = new HashMap<>();
  }
}

The above will work, but this is cleaner:

public class MyClass {
  private final Map<String,Object> myMap = new HashMap<>();
}
main heart
#

Could do that, not really a difference

#

Maybe a bit more readble tho, yeah

vernal plank
#

if(ChunkCache = true){

stuff here

}

#

@main heart

#

nvm

#

it wont

main heart
#

You can call the method to check whether a player is in a new chunk on an object of the ChunkCache, not the class directly. Unless you make everything static that is

vernal plank
main heart
#

You cant do = true

#

It would set the thibg before the = to 'true'

#

You are using the class, not an object

vernal plank
main heart
#

Please learn how to use objects in java and then come back

vernal plank
#

Pretty dumb lmao

#

figured it out

main heart
#

Ill be here again tomorrow, gotta go now

vernal plank
#

@main heart

whole ermine
#

create a class that holds the WorldId, chunkX and ChunkY

vernal plank
whole ermine
#

What exactly is this chunk cache supposed to do? It seems to just remember the last chuink a player was in

vernal plank
#

so it can paste a schematic at a new chunk

#

instead of an old chunk

whole ermine
#

if a player moves to any chunk it's going to be "new"

#

even if he moves one block left, into a new chunk, then moves back

vernal plank
#

like on first render

whole ermine
#

you want to paste in every new chunk thats generated?

vernal plank
whole ermine
#

"near" the player is going to depend on a lot of things. Render distance for one

vernal plank
#

like 2-3 chunsk near the player

#

or 4-5 chunks

#

at random rotations

whole ermine
#

You don;t seem to understand how chunks load...

#

they are loaded by the server upto a radius about each player

vernal plank
#

yea..

whole ermine
#

16 chunk diameter I believe

vernal plank
whole ermine
#

so 8 in each direction

vernal plank
whole ermine
#

when the world first loads there will be no players

vernal plank
#

except shorter

whole ermine
#

so no one to paste any schematics near

#

what do you class as a "new" chunk?

vernal plank
whole ermine
#

what are your requirements for a chunk to be recognised as "new"

vernal plank
whole ermine
#

so do ALL chunks that are generated get this schematic pasted in them?

vernal plank
whole ermine
#

as they are all new chunks

vernal plank
whole ermine
#

so you want your schematic paste in every chunk basically, but not in chunks it's already been pasted in

whole ermine
#

what is this about "near a player"?

vernal plank
#

so i decided to take the player location

#

and paste it at that instead

whole ermine
#

if every chunk is new (at some point) and the schematic shoudl be paste, where is teh player requirement?

#

What exactly is this schematic you want to paste?

#

?

vernal plank
#

Sorry I was eating

vernal plank
vernal plank
#

Specifically the runnable

#

It is supposed to take any new chunk that hasn't been loaded before near the player

#

And paste the schematic on it.

#

@whole ermine

vernal plank
#

Hence the name of this thread

whole ermine
#

no idea what backrooms is

vernal plank
whole ermine
#

if you want every chunk to have a backroom you should use the chunkloadevent

vernal plank
#

It crashes my test server

whole ermine
#

you schedule a task if event.isNewChunk()

#

If you are using AsyncWorldEdit it will manage teh workload

vernal plank
#

Player location based has worked best for me so far

#

I just wanted to check

whole ermine
#

if you want it pasted in every chunk then you need to use teh load event

vernal plank
#

If the player has entered or gotten close to a new chunk

#

Run my runnable code

whole ermine
#

Your way is not really going to work as you would need to track every chunk thats loaded across every session

vernal plank
#

Like the messages before this in the thread

#

@whole ermine or could I make it so it only pastes 1 time

#

For each Chunk?

whole ermine
#

thats why I'm saying to use the loadevent

#

it marks each chunk load as new or not

#

all you have to do is sort how you paste your schematic

#

you could even setup a queue system so you can delay each paste

vernal plank
#

Queuing it seems hard

whole ermine
#

its not that hard. I implement a queue system in my explosion regen plugin

#

sec

vernal plank
#

Also can I not implement a chunkLoad event into what I already have?

#

Like if(e.isNewChunk)
{
Runnable here
}

whole ermine
#

That has two queues. One to regen a list of blocks and one for Entities

#

you would implement one queue to fire your paste

vernal plank
#

I don't get it

whole ermine
#

not really. My IDE is not open and I'm watching smallville with my wife.

vernal plank
#

I'll try when I get home