#help-development

1 messages ยท Page 2287 of 1

flat leaf
#

you can set block data

#

but things like chests still won't have, for instance, items in the block inventory

#

and containers also use NBT to lock

noble lantern
#

ohh nbt for tile entities

flat leaf
#

yeah sorry that's what I meant

noble lantern
#

thought you meant like stone

#

was like huh lmao

#

You should just be able to get the NBT block on generation no?

flat leaf
#

you can set NBT data through NMS or even worldedit's API but you're not supposed to directly set blocks through the world during generation

#

what I currently tried was telling a scheduler to set the block's NBT a tick later and it technically works but it haults the whole server until the chunk is generated

#

which is really bad

noble lantern
#

idea

#

keep a referance to those locations

#

generate al lour chunks, and when a player goes nearby you generate chest contents

#

this is how vanilla mc does it

#

Go in spectator, try and open a chest far away

#

"Loot not generated" will show up

flat leaf
#

well chests have loottables, they generated once you open them

#

but afaik the loot tables are also stored in NBT

#

thing is these chunks only really generated when the player is near

noble lantern
#

Indeed but as far as this goes there not a lot of ther ways to handle it

flat leaf
#

i guess I could wait till they're really near but I still feel like there'd be a way to slow down the server if you're using, say, an elytra and travelling really fast

noble lantern
#

Theres a command to give you a placeable dungeon chest, and i know you directly apply NB directly when giving that item

Wouldnt see why it would be different for chunk generation, set nbtdata on generate

zenith gate
#

lol tell me about it, I wasn't thinking, I forgot I could totatly use a runnable inside the interact of the item.

noble lantern
#

one sec

#

lemme look

#

Yep it did that but its oooold code

#

back when the chunk populator method was populate()

#

but its still same principle, on generation of the block apply the data or fill container

flat leaf
#

every time a chunk generates where NBT needs to be set and I run the code to set it, the server stalls for a good 5-10 seconds

#

I think the reason is that when running it on the main thread, I have to get an instance of the chunk and that means it has to wait until the chunk generates since worldgen is on another thread

lime moat
#

I'm trying to make all the logs spawn at the same chance... this system previously used HashMap

#

A lot of stuff is probably wrong, so any guidance would help so, so much!

noble lantern
flat leaf
#

I can't even manually set the block inventories either if I wanted to just handle containers

#

I'm not using an event, this is a chunkgenerator

#

in generateSurface()

#

meaning I have to set block types with the ChunkData object it gives me instead of directly going through the world

noble lantern
#

hmm

zenith gate
#

this should work in onEnabled right?

Player player = (Player) Bukkit.getOnlinePlayers();
        new BukkitRunnable() {
            @Override
            public void run() {
                Player.Spigot spigot = player.spigot();
                spigot.sendMessage(ChatMessageType.ACTION_BAR,
                        new TextComponent("โค" + ChatColor.RED + "" + ChatColor.BOLD + Math.round(player.getHealth()) + " " +
                                ChatColor.AQUA + "\uD83E\uDDEA" + ChatColor.BOLD + Mana.getPlayerMana(player)));

            }


        }.runTaskTimer(Wired.getPlugin(), 0,5);
noble lantern
#

you may have better luck using the chunk populate event (Might not be called that)

#

Since those give you direct access to Block

noble lantern
noble lantern
#

oh wait thats a timer

#

nvm

#

yeah itll work

lime moat
#

but now I'm just using a list so I'm dumbfounded

noble lantern
#

ores is a list?

flat leaf
noble lantern
#

It should be really lightweight all your doing is setting block data

flat leaf
#

oh you mean literally hook onto the event

noble lantern
#

yee

flat leaf
#

hmmm

noble lantern
#

it gives you direct access to block

lime moat
#

This is the HashMap system which works fine: java int x1 = -114, y1 = 62, z1 = -55; Location loc1 = new Location(Bukkit.getWorld("world"), x1, y1, z1); int x2 = -102, y2 = 52, z2 = -67; Location loc2 = new Location(Bukkit.getWorld("world"), x2, y2, z2); Map<BlockData, Double> ores = new HashMap<>(); ores.put(Bukkit.createBlockData(Material.COAL_BLOCK), 0.15); // 15% ores.put(Bukkit.createBlockData(Material.IRON_ORE), 0.15); // 15% ores.put(Bukkit.createBlockData(Material.GOLD_ORE), 0.05); // 5% ores.put(Bukkit.createBlockData(Material.REDSTONE_ORE), 0.04); // 5% ores.put(Bukkit.createBlockData(Material.DIAMOND_ORE), 0.03); // 3% Cuboid.fillCuboid(loc1, loc2, Bukkit.createBlockData(Material.STONE), ores);

noble lantern
#

and your rly not making a world gen

flat leaf
#

that seems kinda gross but that may work

noble lantern
#

indeed it is slightly gross

lime moat
#

I just need to make basically the same system to work with a normal list so they have all the same chance of spawning

noble lantern
#

But its fine since your only doing one thing

#

if you were generating blocks in that event like a mountain

#

then oof

flat leaf
#

yeah no I can just save in a list the blocks that need their NBT saved and handle it in the event later

noble lantern
flat leaf
#

that should theoretically work

lime moat
#

I have really no clue what else to do and I've been guided on this journey :P

noble lantern
#

you can just set it in there directly

#

unless thats not exactly what your asking

#

i assume your just asking how to iterate through it

lime moat
#

It may be, but by chance could you give me an example of how I would use it in my instance? I'm so lost with this :P

noble lantern
#

I mean its relatively simple

#

you change ores to a List of BlockData

From there you change your put(BlockData, float) method to add(Bukkit.createBlockData(. . .));

And then you iterate over it like so

for (BlockData blockData : ores) {

}

lime moat
#

I currently have this with my fill: java if (woods != null && woods.size() > 0) { // picking random ore BlockData blockData = woods.get(random.nextInt(woods.size())); int i = 0; for (BlockData blockdata : woods) { if (random.nextDouble() <= entry.getValue()) { loc1.getWorld().getBlockAt(x, y, z).setBlockData(entry.getKey()); } // guess failed. Use base. else { loc1.getWorld().getBlockAt(x, y, z).setBlockData(base); } // break loop, we've done our work. break; } }

#
                        int x1 = -89, y1 = 62, z1 = -81;
                        Location loc1 = new Location(Bukkit.getWorld("world"), x1, y1, z1);
                        int x2 = -77, y2 = 52, z2 = -93;
                        Location loc2 = new Location(Bukkit.getWorld("world"), x2, y2, z2);
                        List<BlockData> woods = new ArrayList<>();
                        woods.add(Bukkit.createBlockData(Material.SPRUCE_LOG)); // 12.5%
                        woods.add(Bukkit.createBlockData(Material.BIRCH_LOG)); // 12.5%
                        woods.add(Bukkit.createBlockData(Material.JUNGLE_LOG)); // 12.5%
                        woods.add(Bukkit.createBlockData(Material.ACACIA_LOG)); // 12.5%
                        woods.add(Bukkit.createBlockData(Material.DARK_OAK_LOG)); // 12.5%
                        woods.add(Bukkit.createBlockData(Material.CRIMSON_STEM)); // 12.5%
                        woods.add(Bukkit.createBlockData(Material.WARPED_STEM)); // 12.5%
                        Cuboid.woodfill(loc1, loc2, Bukkit.createBlockData(Material.OAK_LOG), woods);``` and this in the command
#

Now, what would I do in these two lines? ๐Ÿ˜… java if (random.nextDouble() <= entry.getValue()) { loc1.getWorld().getBlockAt(x, y, z).setBlockData(entry.getKey());

noble lantern
#

oooops

#

sec

#

for (int x = 0; x <= (ores.size() - 1); x++) {
ores.get(x);
}

#

you can use x as the iteration count/index getting for the List

#

all lists start at 0 (I assume you know that, and hence why you -1 from size())

#

if you dont you get a IOB error (indexoutofbounds)

lime moat
noble lantern
#

also

#

make sure you do a isEmpty() check before-hand if the values ever bcome non-hardocded

#

not that it will rly matter but its decent to catch that

lime moat
#

Line 37 is what I changed

noble lantern
#

yes but your still using entry.getKey() which is prolly screaming red in your ide

#

How did you manage to write all this without knowing how to do this lmao

lime moat
#

Heh, lots and lots of help n googling, so now I need to remove java if (random.nextDouble() <= woods.getValue()) { loc1.getWorld().getBlockAt(x, y, z).setBlockData(entry.getKey()); and throw ores.get(x); in the place?

noble lantern
#

yep just remove the if, keep the body of the if and replace with List#get

#

Also is there any reason for you using block data to set blocks?

#

I feel like Material may suit you better unless you do plan on setting block data later on, then disreguard that part

lime moat
#

I'll try it on the server now! :D

shadow zinc
#

How can I power a piston with code?

quaint mantle
#
((Piston) block).setExtended(true);
shadow zinc
#

no way its that easy

quaint mantle
#

Ok

shadow zinc
#

you're talking garbage

quaint mantle
#

Check again

lime moat
shadow zinc
#

its not going to be any different?

shadow zinc
#

yeah that doesnt work

quaint mantle
#

How so

shadow zinc
#

it updates the texture

#

it doesnt actually extend or push any blocks

noble lantern
shadow zinc
#

yes

#

otherwise its texture wouldn't update?

quaint mantle
#

He means did you update the state

noble lantern
#

not necesarily

lime moat
noble lantern
#
final Piston piston = (Piston) block.getBlockData();
piston.setExtended(true);
block.setBlockData(piston);
shadow zinc
#
                            //For piston
                            if (data instanceof org.bukkit.block.data.type.Piston piston) {
                                //extend piston
                                if (cachedData.cachedRedstoneActivity.get(block) > 0) {
                                    piston.setExtended(true);
                                    block.setBlockData(piston);
                                    continue;
                                }
                                continue;
                            }```
noble lantern
#

yeah like that, your code you sent above didnt have it

shadow zinc
#

that was an example showing setpowered doesnt exist

quaint mantle
#

I dont think it would return a clone of getBlockData

noble lantern
#

setExtended

noble lantern
quaint mantle
#

Doesnt change anything

shadow zinc
quaint mantle
#

Wtf

shadow zinc
#

you tell me

#

if that worked

noble lantern
#

tf

shadow zinc
#

i mean it might push the block

#

let me check

quaint mantle
#

Shitty client

shadow zinc
#

sure

noble lantern
#

yeah has to be client issue

#

that is no way possible on vanilla

quaint mantle
#

Stupid fabric

noble lantern
#

unless your textures are corrupted

shadow zinc
#

doesnt push the block

noble lantern
#

oh thats fabric?

shadow zinc
#

thats not client right?

noble lantern
quaint mantle
noble lantern
#

i didnt mean to say that

quaint mantle
#

but maybe his client is doing some sort of optimization

noble lantern
#

idk why idid

#

i mean to say just block state in world lol

#

however

#

he may need to do that too

#

just for that client

flat leaf
#

nah I don't think it's the client

#

I'm pretty sure setExtended just sets an NBT value

#

that's my best guess

noble lantern
#

yep

#

thats right

#

just checked

flat leaf
#

and that makes the block look proper when the block for the piston stem gets created

noble lantern
quaint mantle
#

Shit game

flat leaf
#

the actual logic for creating the extension block and moving it is not there

#

an API request could maybe be made but idk it just kinda is what it is

shadow zinc
#

bruh am I going to have to remove the block and set it one forwards

flat leaf
#

speaking of NBT though I really wish there was an API in bukkit to set NBT

noble lantern
#

got it!!!

#

Cast Piston

#

to Powerable

flat leaf
noble lantern
#

there you go ๐Ÿ™‚

flat leaf
#

yeah that probably works

shadow zinc
#

lol no

#

its not a powerable

noble lantern
#

or the block data to Powerable

#

try that instead

shadow zinc
#

i mean i got an instance check

#

it doesnt fly

flat leaf
noble lantern
#

Might as well try it

flat leaf
#

but man things like this make Bukkit in general pain to use sometimes

shadow zinc
#

okay

#

for you

noble lantern
#

thats the most recent thread i can find

#

from 2020

#

so hopefully it still works

flat leaf
noble lantern
#

as long as your using maven at least

flat leaf
#

so if you are using mojang mappings (which you really should be, they're great) it will not be called .a

noble lantern
#

spigot dont care for gradle users :((

flat leaf
#

f

#

why not just use maven

noble lantern
#

no one has converted special source plugin from maven to gradle and it suuucks

#

cause me like gradle

flat leaf
#

understandable

#

well yeah that's unfortunate

#

having mappings is great

shadow zinc
#

everyones favourite error

#

java.lang.RuntimeException: java.lang.ClassCastException: class org.bukkit.craftbukkit.v1_19_R1.block.impl.CraftPiston cannot be cast to class org.bukkit.block.data.AnaloguePowerable (org.bukkit.craftbukkit.v1_19_R1.block.impl.CraftPiston and org.bukkit.block.data.AnaloguePowerable are in unnamed module of loader java.net.URLClassLoader @5c29bfd)

noble lantern
#

yeah anytime i wanna do mappings i typically convert my project back to maven lmao

shadow zinc
#

oof

#

wrong one

noble lantern
#

@shadow zinc read article i sent

shadow zinc
#

ik

flat leaf
#

fun too to see what the community guessed right with their mappings and what is completely different

#

like tile entities actually being called block entities by mojang is very jarring

#

but makes more sense of course

noble lantern
#

i dont get why mojang just doesnt publicize theyre API

#

are they scared cause its so shit?

shadow zinc
#

yeah same thing

#

i'll read the article

flat leaf
#

wdym API

shadow zinc
#

even tho I have read it

noble lantern
#

IE the API mojang themselves use to make the game

noble lantern
#

If you did you would of told us you tried NMS

shadow zinc
#

oh yeah, I've tried NMS

flat leaf
#

I mean as far as I know there's no API, just the source code

#

which we basically have access to now except not really

#

Minecraft is probably the closest thing to actually being open source right now but not quite

#

we have names for everything, just not the actual original .java files

noble lantern
noble lantern
#

thats gonna be your only option now i beileve

flat leaf
#

obfuscating in this case was really just not saving names of stuff when compiling

shadow zinc
#

idk some weird article I found, problem is all of these things are for no remapped

#

so a or b meaning nothing to me

flat leaf
#

the logic is still all the same, we still have to decompile everything

noble lantern
#

those are update methods

flat leaf
#

it's just that now when we do decompile minecraft we can get the names of everything back

noble lantern
#

that mirrors methods from the server jar

#

it would make alllll this server shit so much easier

#

and the mirror jar is just empty code methods

#

and set scope to provided

flat leaf
#

I mean mojang doesn't really have an API like bukkit, there's no reason to

#

they very frequently change the structure of lots of parts of Minecraft

shadow zinc
flat leaf
#

which is a good thing, Minecraft has far exceeded its original planned scope and was designed by a swedish dude in his off time originally

noble lantern
#

I would assume they have a basic event system and NBT handler though

#

and those would likely not change very often

#

cause its like core minecraft for those

flat leaf
#

they have NBT handling shit in NMS

noble lantern
flat leaf
#

and they don't necessarily need an event system but they do have sorts of events systems in minecraft's code

#

the reason we don't use any of that shit though is because it's not meant to be used as an API as it's just the game's code

#

so they change stuff around often

noble lantern
flat leaf
#

the point of Bukkit is to have one uniform API that wraps around minecraft and deals with what changes in the background without the developer having to know or really care

noble lantern
#

mojang could just like

#

write good code

#

so they dont need rewrites every week

#

:))

shadow zinc
noble lantern
#

and call its update methods

flat leaf
#

all I will say is I do not envy Mojang developing a voxel game in Java

#

Java would be my absolute last choice for something so memory intensive

noble lantern
#

it might be named differently than BlockPiston in remapped tho

shadow zinc
#

of ffs why isnt it remapped

noble lantern
shadow zinc
#

a b c die

noble lantern
#

but most devs leave mem leaks all over the place

#

especially in games

flat leaf
#

sure but the core structure of java is lacking for memory intensive applications

noble lantern
#

its 10x harder to try and avoid mem leaks

flat leaf
#

like afaik you can't allocate complex structures to the stack... like what

#

if I'm wrong on that correct me but I could never fucking find out how

noble lantern
#

explain complex structures?

#

Wym by that? Like large complicated objects?

flat leaf
#

basically being able to put objects on the stack

shadow zinc
#

why isn't it remapped?

flat leaf
#

C# has structs which are like objects but immutable

shadow zinc
#

is this something I did?

flat leaf
#

and you can lay out a struct using other value types like primitives and other custom structs

noble lantern
flat leaf
#

and they are automatically put on the stack instead of having to go on the heap and be managed and eventually garbage collected

shadow zinc
#

im using gradle

#

so I had to do some stuff

#

im using paper weight too

noble lantern
#

yeah youll need maven for remapped

#

theres prolly a way in gradle

#

but im not that good

shadow zinc
#

I mean most of my stuff is remapped

#

never had problems until now

flat leaf
flat leaf
#

I far prefer C#'s way of handling this still but that's at least better than not being able to put anything other than primitives on the stack at all

noble lantern
#

Yeah im sure long running things are added to the stack more than likely

#

like socket instances and theyre values likely get shoved to stack while short lived things like threads and what not run through heap

Just my best editmate tho

flat leaf
#

I just hate how much is delegated to be part of the magic internals of the JVM instead of up to the developer to control

#

especially since how the JVM behaves is not necessarily always guaranteed depending on what JVM you're using

noble lantern
#

Seems like the comunity has a few different answers for this ngl

#

i wonder if its possible to create your own JVM

flat leaf
#

sure it is

noble lantern
#

and make java stack based instead of heap based

#

prolly a lot of work

#

too much

#

ide rather write a mc server jar from scratch

flat leaf
#

probably a waste of time but sure you can, all the JVM does is interpret the byte code and tell the computer how to run it

noble lantern
#

yep, imma google that now i wonder if its been done

flat leaf
#

but the stack should be delegated for smaller objects that aren't necessarily supposed to change

#

no need to create a thousand small objects a second that only get used immediately just for them to all clog the garbage collector

noble lantern
#

im boutta make my own programming language

flat leaf
#

actually usually you want long running objects to go on the heap

#

the stack only has so much space

#

it's usually short lived stuff you want to go on the stack

noble lantern
#

so stack wouldnt work for large complex voxels then no?

#

cause typically those voxels could be long lived

#

eg loaded chunks

flat leaf
#

usually you put stuff on the stack while, say, doing a ton of calculations in a loop

#

if you're trying to store data in some sort of structure while iterating over every block in a chunk you don't need to make an object

#

that structure you put on the stack is automatically freed as soon as the current iteration ends

#

instead of having to go through the GC

noble lantern
#

ahh i see was just about to say doesnt the gc replicate that haha

#

TBF the GC has gotten rly good over the years

#

compared to when mc first came out

flat leaf
#

could also be useful when, say, sending information to the GPU in a certain way

#

yeah no modern java versions are much better at it

noble lantern
#

i actually dont think MC interacts with gpu much

flat leaf
#

well it does, minecraft just doesn't do many intensive graphical calculations

#

because it's a simple block game

#

it would still be stupid to render on the CPU

noble lantern
#

Honestly cpu bound games are weird

#

Rust is cpu bound

flat leaf
#

it's moreso that Minecraft just spends way more time per frame on actual calculation instead of graphical calculation

noble lantern
#

and thats a full fledged AAA 3d game

flat leaf
#

basically your cpu is doing more work comparatively to your GPU

noble lantern
#

: ' |

#

someone should shoot notch for not making the code async ngl

flat leaf
#

multithreading is used very frequently throughout Minecraft's code, I think vanilla even does world gen on another thread

#

but you can't make everything on another thread

noble lantern
#

yeah it does but theres still a bunch of stuff handled on main

IIRC entities and stuff is all on main

flat leaf
#

sounds like a fun time to deal with race conditions and making the code look horrible because you now have to synchronize every thread when passing data between threads

#

multithreading also has diminishing returns to a point, CPUs only have so many cores/threads

noble lantern
#

well you would just do processing async

#

and then call back to main thread

noble lantern
#

been playing with that lately

#

rly fun

flat leaf
#

the issue is that when running something on another thread there is zero guarantee as to what the main thread is doing

#

so to exchange any sort of data you have to basically pause both threads at a point that is appropriate and exchange information like a hand shake

buoyant viper
#

when the ticker is 5 secodns ahead of the rendering thread

#

๐Ÿ˜Ž

noble lantern
#

public static int playerBalance;

#

CompletableFuture.runAsync(() -> playerBalance++);

#

ez

flat leaf
#

now access that from two threads at once

noble lantern
#

redis could possible work maybe as a middle man

flat leaf
#

I don't even think it's necessarily guaranteed what actually happens when you just access an int that is being written to currently

buoyant viper
#

TIL the search bar in the creative inventory in 1.8 only fits 15 chars, so i cant search for items such as "heavy_weighted_pressure_plate" :(

noble lantern
#

last*

flat leaf
#

in C# you use a lock

#

or C# may have types like the Atomic types, not sure

buoyant viper
#

in java u have the oh so wonderful synchronized keyword

#

(i have never used that in my life)

noble lantern
#

i have

#

its pretty useful

#

Object#wait

#

and Object#notify make use of it

#

you can make makeshift callback functions with all those methods

#

useful for multithreading too but i stoped using it

#

too annoying

#

but basically synchronized (object) just locks the object to the main thread when calling and allows you to execute things on main inside the block

flat leaf
#

ah so synchronized is basically like the lock keyword in C#

noble lantern
#

yep!

#

in fact

#

the argument name in javadocs is literally named lock

#

haha

flat leaf
#

and can be used pretty much exactly like it

flat leaf
#

makes sense

noble lantern
#

Would be useful if you handle data management on main thread

flat leaf
#

I am a little more familiar with C#'s threading systems over java's as usually I don't have to do much fucky shit in minecraft plugins

noble lantern
#

i actually need to make a async storage access system and thats gonna suck ngl

buoyant viper
#

for as different as Java and C# are, theyre basically the same language when it comes to writing code

flat leaf
#

yeah they're pretty similar

noble lantern
#

im debating on not caching from db and always pulling from mongodb

#

or redis

buoyant viper
#

except ones PascalCase and ones camelCase

flat leaf
#

I am far far more familiar with the internal workings of C# over java though

#

as I have just made more projects with it

#

like audio shit pretty much guarantees you will be doing some threading

#

but audio programming is fun

buoyant viper
#

usually need to thread audio in java too iirc

flat leaf
#

well yeah you need to thread audio in every language, you simply have to feed to much data to do audio along with everything else

buoyant viper
#

true

#

lol

#

i realized that after i sent it

flat leaf
#

audio is fucking crazy

#

like imagine if we had to generated 44.1 thousand frames a second for a game

#

obviously there is far more calculation to be done in a game but still

buoyant viper
#

a small price to pay for high FPS gameplay

flat leaf
#

lmfao

#

I feel like we couldn't even see a refresh rate past like 5000hz

noble lantern
#

omg wtf

#

bro

flat leaf
#

or like 1000hz

noble lantern
#

ez

#

thats so easy to share between wtf

buoyant viper
#

cant even count++

#

smh

noble lantern
#

smh

#

imagine

#

useless as shit

#

now i gotta make a whole different workaround for my multithreaded for loop counters

#

Wait so could you use volatile to say save player data accross threads?

ivory sleet
#

Yo

#

What are ya doing

noble lantern
#

Oh thats right i pinged you lmao

ivory sleet
#

Ye

noble lantern
#

i think the guys gone now

ivory sleet
#

I was sleeping then

#

A nice

noble lantern
#

but whats the name of the protocol thingy minecraft uses?

#

Like the actual data type transferred

#

i remember you telling me one time

ivory sleet
#

TCP?

noble lantern
#

Not TCP, i was talking about how i handle my socket data in JSON, and you mentioned something else that MC uses

#

someone else was doing the same thing

ivory sleet
#

NBT and SNBT?

#

Oh wait

shadow zinc
#

anyone got an idea how to remap gradle

noble lantern
#

I feel like it was named something else other than those hmm

#

it was a weird word

ivory sleet
#

I mean they just write their data in raw bytes if thats what you mean

noble lantern
noble lantern
shadow zinc
#

all I want is to power a piston ffs

#

but no

zenith gate
#

My recipe is being shown in the recipe book, But I cant actually craft the item, the result shows the correct as well as all of the items, what could be causing something like this? I get no errors either.

shadow zinc
#

it just wont happen

ivory sleet
#

I mean you have their abstraction on top of netty

#

With a buncch of utility methods for encoding and decoding data types to raw bytes

ivory sleet
#

But thatโ€™d add the paper api to your classpath

#

Which you might not want

shadow zinc
ivory sleet
#

Because paper isnt spigot

shadow zinc
#

so?

noble lantern
shadow zinc
#

does it break anything?

noble lantern
#

also conclure i learned the hard ware not calling join() with runAsync + work stealing

noble lantern
#

If you use paper methods on a spigot server youll get errors

shadow zinc
#

why?

#

bruh

#

okay

#

so

#

im stuffed?

ivory sleet
noble lantern
#

nah it was like one word

#

it was a rly weird word too

#

maybe someone else said it hmm

noble lantern
#

you could use spigot remapping website to display version specific method names for mojang

Theres a website that does it

lost matrix
ivory sleet
#

screamingscandals

#

or sth

lost matrix
ivory sleet
#

ah sandals

noble lantern
# ivory sleet How are you saving?

Im gonna have a class on main thread that has just a basic data handler class with calls to MongoDB

As well as a hashmap ofc to cash PlayerData POJO classes

I think the queue thing likely would work better for me maybe

noble lantern
lost matrix
#

screamingscandals would sound a bit dubious

noble lantern
#

i was even thinking in my head i bet smile knows the site

ivory sleet
#

But anyway burchard you only want to yse volatile when absolutely necessary since any volatile write ensures a flush of local registries

noble lantern
#

so definatly dont use it in player data objects

#

got it

ivory sleet
#

Well

lost matrix
#

volatile prevents caching on the cpu layer caches.

ivory sleet
#

^

noble lantern
#

Hold one let me write out my data handler rq and come back with my question

#

gimme like 5 mins

lost matrix
#

It also does not ensure atomicity

ivory sleet
#

You could if you wanna be very optimized use a varhandle or atomic field updater

noble lantern
#

just gonna psueodo code

lost matrix
ivory sleet
#

It has methods to do so

#

But on its own it doesnt

#

Well

#

What the fuck am I saying

#

I mean AtomicReference and AtomicFieldUpdater for instance

#

Not volatile itself

#

But volatile is a crucial part if you want to actually perform atomicity correctly

#

Or well memory fences as well with var handles work just as good

lost matrix
#

Ok so it doesnt. It just makes sure that all threads have the same representation and nobody uses a locally cached version

ivory sleet
#

But you need the memory ordering effect guarantee to avoid indeterminacy

noble lantern
#

okay im back

#

?paste

undone axleBOT
noble lantern
#

This class would be on the main thread, except for the Optional<PlayerData> which will be async get from MongoDB: https://paste.md-5.net/gozuwitela.cs

Don't roast me its just pseudo code lmao

And the POJO player data class would be like this: https://paste.md-5.net/akaxaligut.cpp

And when a processing thread wants player data they would get the instance of PlayerDataFactory and call get(uuid) (Like said pseudo code don't roast me for the current design pls)

#

my current method of handling it would just be calling synchroniced on the PlayerDataFactory instance and handling data get/insert there

ivory sleet
#

Wait

shadow zinc
#

ffs should I just use maven?

noble lantern
#

but for some reason it feels wrong

shadow zinc
#

I want to die ngl

noble lantern
shadow zinc
#

gradle aint worth it

noble lantern
#

unless smile knows how to do special source for gradle

ivory sleet
#

PlayerDataFactory is used across multiple threads for both reads and writes?

noble lantern
shadow zinc
#

hmm

noble lantern
#

and runs on main

shadow zinc
#

I should wait then

#

Until smile gets on

ivory sleet
#

Yes but?

noble lantern
#

but mongodb requests (First data load) are on a work stealing thread

ivory sleet
#

Is it used over more threads than that?

noble lantern
#

Well it would be used by threads from the work stealing pool

The threads would get a static instance (Or DI instance) of that class and call get()

#

sec

ivory sleet
#

Cause usually

#

You have some sort of repository class

#

Which is basically a map, sometimes responsible for instantiating the underlying objects as well

#

So factory + map

#

And that class might often very well be used across multiple threads

shadow zinc
#

if thats alright, I don't want to ping anyone

noble lantern
#

It would get used like this in a sense

#

my code is more abstracted than that

#

runAsync is a CompletableFuture wrapper

ivory sleet
#

Okay

#

But do you ever write to the PlayerDataFactory

#

From other threads

noble lantern
#

only change variables inside PlayerData value retrieved from get, so i think yes?

#

No actual mongodb writing

#

just cache write

#

like playerMoney += 500; or some shit like that

#

It writes to mongodb every 5 mins on a diff future for cached PlayerData in the map

#

and onStop

ivory sleet
#

So how do you put the player DTOs in the map in the first place?

noble lantern
#

When the player logs in, validated with oauth2, and sends theyre JWT with UUID it will be loaded on first login

#

ie onConnect

ivory sleet
#

Isnt that on another thread?

noble lantern
#

Indeed it would be

#

so i would call loadData(uuid) onOpen

ivory sleet
#

But yeah I dont understand why you need that blocking queue as well?

crude heron
#

Hey does anyone know how to add effects on Monsters?

noble lantern
#

well i assumed it was needed for data to be safe accross threads

ivory sleet
#

No

#

Let me try to explain

#

In Java

#

Theres a memory model

noble lantern
#

like what if on thread does playerData.money += 50

i dont think it gets updated without the volatile keyword

ivory sleet
#

Normally we have whats called plain read and write

noble lantern
#

kk

noble lantern
ivory sleet
#

Which is normals reads and writes to variables

#

But when we do multi threaded stuff we need certain guarantees

crude heron
noble lantern
ivory sleet
#

//one thread
var i = 3;
var j = 1;

//other thread
var a = i;
var b = j;

#

what are the possible values after both threads have executed?

noble lantern
ivory sleet
#

Assuming they run concurrently

shadow zinc
#

Are there any generators for maven?

#

like minecrell?

noble lantern
#

thread 2 would generate an exception wouldnt it no

#

unless it runs after thread 1?

shadow zinc
#

Can I use maven and gradle simultaneously?

noble lantern
frosty tinsel
#

I think so

shadow zinc
#

ooo

ivory sleet
#

burchard assume that it would become 0

#

Now guess x)

#

Hint there are 4 outcomes

noble lantern
#

wtf

#

im having a hard time thinking of one LMAO

#

if theyre both ran at the same time at least

ivory sleet
#

a = 0
b = 0

a = 3
b = 0

a = 0
b = 1

a = 3
b = 1

#

All four outcomes are possible

noble lantern
#

so basically no consistency between threads

ivory sleet
#

Yes

#

Because

#

var i = 3
var j = 1

can be re ordered to

var j = 1
var i = 3

#

And same guess for a and b

#

That wont alter the behaviour of the program as you can see (assuming its a single thread)

noble lantern
#

Yeah but it would lead to values you dont really want in a sense

ivory sleet
#

Yep

noble lantern
#

Like i dont want one thread spending a players money, while another thread also does it

shadow zinc
#

so build is gradle, package is maven?

ivory sleet
#

We are coming to that part soon burchard

noble lantern
#

okay okay x)

ivory sleet
#

So basically we use volatile as by the means of preventing this type of reordering

noble lantern
#

If you want remapped maven is likely easiest way to go about it

shadow zinc
#

so I need to create a plugin.yml now?

noble lantern
#

no just a pom.xml

shadow zinc
#

but there are no generators?

noble lantern
#

convert your gradle to pom (Striaghtforward process) and then add special source

#

Its pretty easy

#

gradle imports are

groupId:artifact:version

noble lantern
#

just multitasking

ivory sleet
#

when we prevent re ordering we get somewhat of a determinacy we can safely rely on

shadow zinc
#

how tf do you convert gradle to pom?

ivory sleet
#

This is crucial when you want to read and write concurrently

#

Now assume we do have some ordering constraints

#

Then we can apply whats called atomicity

noble lantern
shadow zinc
#

i got my pom

#

its from another project of mine

noble lantern
ivory sleet
#

Yes

noble lantern
#

DIdnt fully understand them though

noble lantern
ivory sleet
#

So you know how incrementing a variable is multiple operations right?

shadow zinc
noble lantern
ivory sleet
#

like you gotta load the variable, perform the incrementation and then put the result back into the variable

noble lantern
#

yep

ivory sleet
#

necessarily just the thread local staxk

noble lantern
ivory sleet
#

Stack *

#

But ye

noble lantern
#

here ill get you it

ivory sleet
#

Anywa

noble lantern
#

?paste

undone axleBOT
noble lantern
#

your properties tags needs a java.version variable

ivory sleet
#

When variables can guarantee visibility we can perform a compare and swap when we want to perform operations that base themselves on old values

#

basically when we have performed the incrementation you check whether or not the old value was changed

noble lantern
#

Just constantly checking for new values?

ivory sleet
#

Yes in principle

#

If the value was changed

#

Then we perform the incrementation again

#

And so on

#

If it wasnt

#

Then put the result into the variable

#

For this to work across multiple threads we need volatility

#

Since we want up to date and accurate reads and writes

#

AtomicInteger, AtomicReference provide methods that allow you to do this

#

updateAndGet, getAndUpdate

#

for AtomicInteger you have incrementAndGet, getAndIncrement

#

etc

#

So you dont havr to implement that shit

#

And for maps

#

You have ConcurrentHashMap

noble lantern
#

I dont think ill be doing any Incrementing on values

#

mainly division, multiplution, some addtion but not incrementals and substractions

ivory sleet
#

Yeah

noble lantern
#

always thought it was for something else

ivory sleet
#

Lol well it performs atomicity on a map

noble lantern
#

Would the atomicity also carry over to the objects inside said map?

ivory sleet
#

assuming you use for instance putIfAbsent, computeIfAbsent, compute etc

noble lantern
#

Yeah i always use putIfAbsent on my regular maps

ivory sleet
#

Ugh wym

noble lantern
ivory sleet
#

it guarantees atomicity on the map, not the variables of the values in the map

noble lantern
#

yep thats what i was asking :p

ivory sleet
#

That you need to fix yourself Im afraid of

#

Ye

noble lantern
#

oh fr

ivory sleet
#

But in simple terms, you go woth AtomicReference etc

#

and provide some convenience methods with your DTO maybe

#

void add(int delta){
moneyReference.getAndUpdate(old -> old+delta)
}

noble lantern
#

would create a wrapper method called setAndUpdate around a ConcurrentHashMap work?

Ie where you get object from hashmap, edit that object and then update/re-insert it into the map?

I see under the hood, this is similar to what things like AtomicInteger does

ivory sleet
#

yeah

noble lantern
#

So my variables inside player data w-

#

oh that way would work?

ivory sleet
#

Yes

#

You can even setup a unit test to prove that it works

noble lantern
#

and i wouldnt need any transforms to my actual pojo class? I can still just use raw BigInteger?

#

and other keywords instead of atomics

ivory sleet
#

Youโ€™d have to use AtomicReference then

#

But in principle same story

noble lantern
#

I wonder how gson parses those ๐Ÿค”

#

if possible

ivory sleet
#

For the map

#

You probably dont need to do anything special

#

Like

#

If you just putIfAbsent or use put

noble lantern
#

i see, let me write something out rq

#

i think i understand

ivory sleet
#

To populate DTOs that are yet not contained

#

But remember

#

You only need atomicity when multiple threads reads and writes to a variable

noble lantern
#

Yeah theyres gonna be lots

#

Every request is handled async

#

and players can send a bunch of diffeerent requests that would alter theyre player data significantly

#

and some things take heavy math calculations

#

so sometimes a request could hang for a few seconds

ivory sleet
#

What I recommend you to do is sth like

noble lantern
#

and if a player sends a request like spend money before that one finishes it would cause an issue

That was mainly my main concern and main thought worry when kaing the async socket system

ivory sleet
#

onSomeThread(()->{
result = heavyCalculation() //if you are not dependent on old values
dto.add(result);
}

#

rather than dto.update(old -> heavyCalculation()+old);

#

But the latter might be necessary if u r dependent on old values

#

But yeah

#

You also need to add some checks

#

Then

#

To make sure the money cant go negative when performing an update

noble lantern
noble lantern
#

sec stil writing this out

ivory sleet
#

No burchard

#

Sometimes youโ€™re not dependent

#

Like lets say all you do is adding a number

#

Then you dont care

#

But if you wanna square the old value and take the second derivative of the old value or sth weird then you need to perform an explicit update

#

Anywah theres much more to it if you wanna get real, but this should be enough for you to create a model that is scalable enough

#

Id thoโ€ฆ recommend unit testing

#

Especially the multi threaded stuff

shadow zinc
#

Can I get some help shadowing minimessages?

ivory sleet
#

To make sure you got it right

shadow zinc
#

their docs don't supply any examples

granite burrow
#

hey I got a question is there a way to show the crafting recipe in a GUI without it being clickable? I tried to disable the clicks that a player does when they are in the GUI I made, however all this does it stop them from clicking in the crafting inventory I made.

They are still able to take out any items that are in the crafting gird by double clicking with a similar item, and can add to that item by right clicking the item onto the similar item in the GUI

ivory sleet
#

(:

noble lantern
#

the subclass there would just be shown how its used

#

ik im prolly doing a lot of uncesary gets im not using

#

but its just psuedo code mainly

#

ill abstractify it once i get it work

Ill have to learn how to unit test lmfao

ivory sleet
#

Well ye

#

Uh

ivory sleet
#

Use updateAndGet

#

just using get and then set isnt exactly the same

noble lantern
#

oh its a functional interface for that method

#

hell yeah

ivory sleet
#

Ye

#

Same goes for the lap

#

Map

granite burrow
undone axleBOT
noble lantern
#

I dont need ConcurrentHashMap tho do i

#

since im pretty much extensively checking?

granite burrow
noble lantern
#

or use it just to be safe

#

all good

ivory sleet
#

well

#

You could just use map.put(uuid,data)

noble lantern
#

oh yeah

#

forgot that overwrites

ivory sleet
#

In this case ๐Ÿ™‚

granite burrow
ivory sleet
#

But overall atomicity is very scenario specific

noble lantern
#

now the main issue is just seeing how these parse against gson

Idk this does seems pretty good and looks like itll work

#

it will be easy to test once its stup

ivory sleet
#

I have written a unit test that showcases how you might wanna test it

noble lantern
granite burrow
noble lantern
#

that lots complex asf, ill definatly look into it haha

#

idk why unit tests always scary to me

noble lantern
ivory sleet
#

Yeah

#

Gonna fetch some breakfast cya

granite burrow
noble lantern
#

so can you just if clickSlot == those cancel?

noble lantern
#

prolly would of never figured it out and i prolly would of went to like redis or something ๐Ÿ’€

granite burrow
# noble lantern so can you just if clickSlot == those cancel?

the code I sent works for stopping the items from getting left clicked or right clicked out, however, if you shift right click a item into the crafting gird it will remove the item and if you double click the item it will give you all of that item.

noble lantern
#

for shift clicking and canceling destination slot someone asked that earlier

#

youll need packets to get destination slot of shift clicks sadly, and then cancel upon those

#

As for double clicking

#

thats a thing?

#

i know shift double click is

granite burrow
#

yeah just clicking fast inside of a gui should stack all similar items up to their max stacking point

noble lantern
#

hmm

#

i wonder if an event for that exists

#

oh also you wanna cancel inventory drag event btw

#

cause i bet dragging breaks your gui too

granite burrow
#

I solved that issue by just adding in extra attributes to the items that are in the fake crafting menu I make. but the shift clicking items from your inventory will still make them disappear :/

granite burrow
noble lantern
#

but after you cancel double clicks

#

do you cann player#updateInventory?

#

call****

granite burrow
#

I do not, do I need to?

noble lantern
#

"do you can" lmao

#

sometimes you might need to

#

bukkit api sucks for that

#

try and see if it fixes it

#

lmk if it doesnt

granite burrow
#

alright let me remove my fix and test that out, that may fix the shfit clicking too, who knows ๐Ÿ˜„

noble lantern
#

shift clicking sadly needs the weird work around

#

unless your shifting clicking directly on the disallowed slot

#

idk why theres no getTargetSlot method

granite burrow
noble lantern
#

one more thing

#

Bukkit.getSchedular().runTask(() -> p.updateInventroy());

#

sorry

#

forgot to mention run it one tick later

granite burrow
noble lantern
#

sec lemme find the article

#

hot link ^

granite burrow
noble lantern
#

sadness, was worth a shot

granite burrow
#

Its weird that when shift clicking the item just disappears though.

noble lantern
#

sometimes that method can fix some weird behavious with inventories

#

Its likely just because its a custom inventory

#

so the functionalities fucked a little

granite burrow
#

ah yeah prob

granite burrow
# noble lantern well shift clicking and getting destination slot needs NMS/Packets

I found a non NMS work around, in my inventory click event I have this code:

        if (e.getClickedInventory().getType() == InventoryType.PLAYER) {
            if (e.getAction() == InventoryAction.MOVE_TO_OTHER_INVENTORY) {
                e.setCancelled(true);
            }
            return;
        }

basically what it does it check if the player shift clicks an item and if they do, it stops them, if they don't then they don't care about that inventory. However, I do wish that spigot had a InventoryAction.Double_Click since it doesn't seem to exist anywhere

EDIT:
๐Ÿคฆโ€โ™‚๏ธ I think its called "COLLECT_TO_CURSOR"

shadow zinc
#

I need help, why am I getting this for maven ```[ERROR] Failed to parse plugin descriptor for net.kyori:adventure-api:4.11.0 (/home/user
/.m2/repository/net/kyori/adventure-api/4.11.0/adventure-api-4.11.0.jar): No plugin descriptor found at META-INF/maven/plugin.xml -> [Help 1]

#

this is my shadow part

#
                <groupId>net.kyori</groupId>
                <artifactId>adventure-api</artifactId>
                <version>4.11.0</version>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>shade</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>```
noble lantern
#

why is it wrapped in plugin tags

#

isnt kyori a dependency

lost matrix
shadow zinc
#

oh fuck

#

look

#

maven

#

it aint it for me

lost matrix
#

I see

shadow zinc
#

oh

#

and

#

actually

#

special sauce

#

for gradle

#

you know a way?

lost matrix
#
 <dependency>
    <groupId>net.kyori</groupId>
    <artifactId>adventure-api</artifactId>
    <version>4.11.0</version>
 </dependency>
lost matrix
shadow zinc
#

I was using it

#

but it didnt remap everything

lost matrix
shadow zinc
#

yeah maybe, but fixing isnt really an option now

granite burrow
#

So that fixes the two issues with, shift clicking and double clicking.

However, I also ran into an issue where you can right click the item into the slot if you right click the slot enough times it will bypass the event being cancelled

Video of the event running even though its clearly cancelled

shadow zinc
#

apparently maven is better

#

so

lost matrix
shadow zinc
#

well its going to be more of pain for me if I use gradle tbh

#

can I do this?

lost matrix
granite burrow
shadow zinc
lost matrix
shadow zinc
#

its got gradle all over it

#

its not happy that I deleted the build.kts

lost matrix
#

Dont use the title as an identity...

noble lantern
#

oh oops

#

i totally missed that when looking over that

granite burrow
lost matrix
lost matrix
#

Create a RecipeViewManager that contains a Set<Inventory>
When you open a view for a player you simply add it to the manager.
Then on the close event you remove it from the manager.

#

RecipeViewManager is a singleton like every other manager class

lost matrix
ashen quest
#

https://youtu.be/AVVQAU3lWZo?t=341
How can I code this thing (@5:41)

It makes it look like you are about to fall into the void but its just a trap

I Became a literal god on the Lifesteal Minecraft 1.18 SMP by exploiting its plugin...

Keep up with me on social media
โ˜…join the community on discord - https://discord.gg/SQqkenRwx4
โ˜…stalk me on twitter โžฃใ€Ž @ashswagin ใ€
โ˜…follow my twitch โžฃใ€Ž https://www.twitch.tv/ashswagin ใ€

THANKS TO THE PLUGIN DEVS FOR HELPING ME do this :- Abyss Development ...

โ–ถ Play video
ashen quest
#

why

ashen quest
#

Ooh

#

well is it usable now

#

also is it from the API or do I need nms?

lost matrix
#

What exactly are you referring to?

granite burrow
ashen quest
lost matrix
ashen quest
#

the way spigot fakes its ores for anti xray

granite burrow
lost matrix
# granite burrow 1.18.1

Inventories are fully server authoritative. If you properly cancel the event then nothing can happen.

granite burrow
ashen quest
#

I need nms right

lost matrix
lost matrix
shadow zinc
#

Burchard you lied to me

#

Maven doesnt generate plugin.ymls

#

why would it?

#

sfsdfdsgdrf

ashen quest
noble lantern
#

i said the intellij plugin did

shadow zinc
#

you insinuated it

#

regardless

noble lantern
#

i didnt?

#

even then

#

why is plugin.yml a big deal

#

that shouldnt change when switching to mappings

shadow zinc
#

I never had a plugin.yml

#

it was generated by minecrell

#

do I need to make it manually now?

noble lantern
#

never heard of minecrell

#

yes all plugins need a plugin.yml

shadow zinc
#

.......

noble lantern
#

this is why we dont use libraries like that

shadow zinc
#

are there any generators?

noble lantern
#

That way we know how to make a barebone plugin

shadow zinc
#

I've done it before for my neosurvival

noble lantern
#

it goes in /resources

shadow zinc
#

I feel like a teenage girl that just got cut off her allowance

noble lantern
#

(Considering your projects setup like that)

#

lmao

ashen quest
noble lantern
ashen quest
#

oh

noble lantern
#

I suggested that plugin to him earlier

granite burrow
ashen quest
#

why do u need a gen for that

noble lantern
#

happens alot when i go to bed after debugging a bunch of shiz and i start up the next day forgetting any leftover debug shiz

shadow zinc
#

I'm going to decompile my old jar and grab the plugin.yml from that

#

ik

#

ik

noble lantern
#

there you go

#

big brain

shadow zinc
#

ikr

#

so smart

granite burrow
lost matrix
noble lantern
#

oh god

#

i do that a lot

#

ill write out some code in a random project to show to someone

#

and i forget its there lmfao

#

in fact there code in one of my projects doing that rn

#

forgot which one tho

#

enjoy smiles

lost matrix
shadow zinc
#

He actually does a good job at explaining tbh

noble lantern
#

indeed but mans comes out with some shit i could only dream of sometimes

shadow zinc
#

Lol

#

looks like me too

#

anyways

#

why cant I find my plugin.yml in the decompiled classes?

noble lantern
#

should be right when you unzip it

shadow zinc
noble lantern
#

if the plugin was built correctly i will look like this

shadow zinc
#

just a bad decompiler?

noble lantern
#

just use winrar

#

or any unzipping aplication

#

jar files are zip files

shadow zinc
#

bruh

#

you are a wizard

noble lantern
#

im literally the dumbest person in this channel, but thank you

shadow zinc
#

-100 self confidence

shadow zinc
#

for version:

#

again, I've always had my allowance, the real world is a bitch

noble lantern
#

wth is neoPerformance version

#

can i get some context

shadow zinc
#

I remember you could put some tag in the plugin.yml to grab the version

#

neoperformance is just the name of my crappy plugin

noble lantern
#

ahh

#

uhm

#

${version}

#

but thats maven

#

nvm u on maven

#

make sure you use the plugins i sent earlier

#

or that placeholder wont work iirc

shadow zinc
#

is that minecraft development?

noble lantern
#

no its called filtering

#

just as long as thats true for your resources dir it should parse fine

#

which it should be cause i sent you that entire chunk earlier

shadow zinc
#

ah

#

yep

#

thanks

noble lantern
#

just - the binary-resources dir bc that for my own plugin

shadow zinc
noble lantern
#

send the plugin.yml you have

shadow zinc
#
name: NeoPerformance
version: '${version}'
main: com.neomechanical.neoperformance.NeoPerformance
load: STARTUP
authors:
  - NeoDevs
prefix: NeoPerformance
commands:
  neoperformance:
    description: Show server performance
    aliases:
      - np
      - performance
    permission: neoperformance.admin
    usage: /neoperformance
api-version: 1.13
default-permission: op```
noble lantern
#

When you unzip the jar

#

where is your plugin.yml

shadow zinc
#

root

onyx shale
#

have a feeling this isnt ur project right?