#backrooms
1 messages ยท Page 1 of 1 (latest)
Yea,
that'll spam the whole world with your schematic, right?
Yea
Its going to generate the backrooms
basically
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
alright
@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
alright, how could I implement this
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
kk
so this would also paste a schematic up to a certain distance when the player walks
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
Alright
Is there a place I can put the runnable?
Or is it strictly in OnEnable?
the only proper place is to use onEnable() in 99% of cases
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
alright
if you're confused about the () -> { ... } or the "this::doStuff" part, please read this: https://blog.jeff-media.com/understanding-lambdas-and-method-references/
I wrote this a year ago because I myself was quite confused about this notation at first
Thank you very much for your help,
Totally appreciate it
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
okay, please show your command code
you should be able to just move it into the scheduler thing quite easily
Yea, I did already
QUite easily
Something I found funny hwoever
sorry I don't understand what you're trying to say lol
aaah
it like doesnt generate the full thing
"screenshot imminent" means "there's a screenshot coming soon" lol
didnt know that lol
actually, this seems fine lol
its generating random shit
Thank you soo much
Man you saved me 5 days of work
Thank you
no problem :3
@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
well then your "location" logic is flawed
maybe ask in the "main thread" again, I cannot help you with any math stuff
Alright ty
So, how do I make a hashmap to check if the playter is in a new chunk
hey there tahd
ima do the Hashmap thing alex dw
ty
have you ever seen a HashMap?
btw i am making the bckrooms
No, not really, relatively new to Java
ok hold on
https://www.w3schools.com/java/java_hashmap.asp
This should be a pretty good resource
a hashmap maps two values together
e.g. Name -> Age
mfnalex -> 27
mfnalex's father -> 67
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)
Ok, should I set it as a varible?
and you have yourself something that will give you a boolean value on whether the player just entered a new chunk.
depends on your use for it
but I suggest having it in a controller class or so that only manages that HashMap
Im trying to check if a chunk is new to paste a schematic or not
you can do that with a cache, yes
Well how..
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
what if I want to check for all online players?
A HashMap can contain many key value pairs
you just do it for all players
manually?
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
hmm
Bukkit.getOnlinePlayers() gives you a collection of all online players ๐
yea
so like
hold on, I'll make you a better example
hi
alr
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
alright, also it says for me that example cache has to be publc voi
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
alright, ty,
Can I send you my code
I repurposed it
Sure
I meant a new class file, not a class inside a method
oh heh, i totally knew that ๐
Also the method should only tell you whether the player is or is not in a new chunk, you should keep it that way
Ok, ok
so
hol don
how might I implement it into the main class?
You create a new Cache for your main class and then call its methods from there when needed
ok
so public ChunkCache2() {
this.cache = new HashMap<>();
}
why not just create the map directly in the declaration?
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<>();
}
wait im kinda dumb, but will this work?
if(ChunkCache = true){
stuff here
}
@main heart
nvm
it wont
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
Im trying to call it but it doesn't seem to recognize the method
You cant do = true
It would set the thibg before the = to 'true'
You are using the class, not an object
so if it returns true?
Please learn how to use objects in java and then come back
Ill be here again tomorrow, gotta go now
@main heart
create a class that holds the WorldId, chunkX and ChunkY
How might I do it?
What exactly is this chunk cache supposed to do? It seems to just remember the last chuink a player was in
its supposed to keep track of if a player is in an old chunk or new chunk
so it can paste a schematic at a new chunk
instead of an old chunk
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
So how could I paste the schematics for chunks that are newly loaded?
like on first render
you want to paste in every new chunk thats generated?
new chunk near the player
"near" the player is going to depend on a lot of things. Render distance for one
A set distance
like 2-3 chunsk near the player
or 4-5 chunks
at random rotations
You don;t seem to understand how chunks load...
they are loaded by the server upto a radius about each player
yea..
16 chunk diameter I believe
ok
so 8 in each direction
Im trying to do the same thing with the schematics
when the world first loads there will be no players
except shorter
yea ik
wdym
what are your requirements for a chunk to be recognised as "new"
if no one has loaded it before.
so do ALL chunks that are generated get this schematic pasted in them?
basically, with my current code, without the chunk check, it fills up storage by spamming schematics for old chunks
as they are all new chunks
yep
so you want your schematic paste in every chunk basically, but not in chunks it's already been pasted in
yea
what is this about "near a player"?
Well I tried loading it in ALL loaded chunks, but my test server could not handle it
so i decided to take the player location
and paste it at that instead
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?
?
Sorry I was eating
I was eating sorry
The player requirement is in the code
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
Its the backrooms
Hence the name of this thread
no idea what backrooms is
An infinite maze with multiple levels for a tldr
if you want every chunk to have a backroom you should use the chunkloadevent
Thays too laggy
It crashes my test server
you schedule a task if event.isNewChunk()
If you are using AsyncWorldEdit it will manage teh workload
Still laggy
Player location based has worked best for me so far
I just wanted to check
if you want it pasted in every chunk then you need to use teh load event
Your way is not really going to work as you would need to track every chunk thats loaded across every session
Cant that be done with a cache?
Like the messages before this in the thread
@whole ermine or could I make it so it only pastes 1 time
For each Chunk?
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
Eh
Queuing it seems hard
Can I have an example of a queue system??
Also can I not implement a chunkLoad event into what I already have?
Like if(e.isNewChunk)
{
Runnable here
}
Uhhh
That has two queues. One to regen a list of blocks and one for Entities
you would implement one queue to fire your paste
Can you make me an example in my case??
I don't get it
not really. My IDE is not open and I'm watching smallville with my wife.
Alright
I'll try when I get home