Skip to content

Implement Timefall - #17

Open
SpaceNerden wants to merge 11 commits into
TraceLTRC:masterfrom
SpaceNerden:Timefall
Open

Implement Timefall#17
SpaceNerden wants to merge 11 commits into
TraceLTRC:masterfrom
SpaceNerden:Timefall

Conversation

@SpaceNerden

Copy link
Copy Markdown
Contributor

No description provided.

@SpaceNerden

Copy link
Copy Markdown
Contributor Author

This branch is also on latest now

@dlee13

dlee13 commented Sep 1, 2023

Copy link
Copy Markdown
Collaborator

I have a couple of thoughts regarding this item. First, it's going to be called Timefalleroni since it's a Kronii item. Second, I think that we should make it more general by simulating several random ticks in a small area around the player rather than just converting all of the copper. Also, it's going to always consume the item when you use it. And itemStack already points to the item. Call itemStack.subtract() instead of event.getItem().setAmount(0).

I just checked and Klin's version was called Timefalleronii. I'm not sure which name we want to go with. Need to go rewatch Kronii's streams and find out whether her items ended with -eroni or -eronii.

@SpaceNerden

Copy link
Copy Markdown
Contributor Author

Yeah, that sounds good to me. How many ticks/block should it be?
A lone copper block has a 64/1125 (5.7%) chance to oxidize per random tick, if I'm not mistaken. It goes way lower once other copper blocks are within 4 blocks. 10 ticks maybe?

Will do the itemstack.subtract().

@dlee13

dlee13 commented Sep 1, 2023

Copy link
Copy Markdown
Collaborator

For now, we don't really have to think about the random tick chance. We can kind of just loosely simulate it and call Block::randomTick on a bunch of randomly selected blocks in the area. To decide how many random ticks to do, let's consider how big the affected area should be. Do we wanna keep it as 5 blocks cubed? And then maybe do like half the number of blocks in that area or something. Or maybe a third. The recipe is extremely cheap, so it's not a big deal if players have to use more of them.

@SpaceNerden

Copy link
Copy Markdown
Contributor Author

5 block cubed is like... Not much if you have to space the blocks around because it still has to go through the pre-oxidation phase.

The minimum for 8 blocks in 3 dimentions is a 6x6x6 cube. I just drew on pen and paper though, didn't actually test in Minecraft. The most efficient one is apparently a 10x6 though.

@dlee13

dlee13 commented Sep 1, 2023

Copy link
Copy Markdown
Collaborator

This won't require the blocks to be spaced though. Since we'll be calling Block::randomTick, random tick chance will be disregarded and the blocks could be tightly packed.

@SpaceNerden

Copy link
Copy Markdown
Contributor Author

If I'm reading this correctly the random tick only puts the block at pre-oxidization

In Java Edition, when a random tick is given, a copper block has a 64⁄1125 chance to enter a state called pre-oxidation. This means a copper block enters pre-oxidation after approximately 20 minutes.

In pre-oxidation, the copper block searches its nearby non-waxed copper blocks for a distance of 4 blocks taxicab distance. If there is any copper block that has a lower oxidation level, then the pre-oxidation ends, meaning that this copper block does not weather.

Though tbh it still oxidizes anyway because of the sheer number of (called) random ticks, and we can just set an arbitrary number and let the players spam it. Maybe even automation is possible?

@dlee13

dlee13 commented Sep 4, 2023

Copy link
Copy Markdown
Collaborator

Yeah, it's fine to make players spam it. We'll reimplement it like how I described.

@SpaceNerden

Copy link
Copy Markdown
Contributor Author

Same AoE? (5x5x5)

@dlee13

dlee13 commented Sep 4, 2023

Copy link
Copy Markdown
Collaborator

For now, yes. It's easy to change later if we want to.

Instead of oxidizing copper blocks by 1 level, random tick a random tickable block x (25) times.
@SpaceNerden

Copy link
Copy Markdown
Contributor Author

So I implemented the changes and it seems like copper blocks are really not oxidizing when together. When separated, they oxidize as normal. Trees and seeds grow wonderfully though.

One concern I have is that when I use the item, it takes a second to delete the placed block and complete the function. Not sure if the whole server freezes during this but if so, I'd like to know if there's a way to "asynchronously" (not freeze the server) run it.

P.S. I didn't push yet because internet went out last night and now I'm at school :dum:

@SpaceNerden

Copy link
Copy Markdown
Contributor Author

One concern I have is that when I use the item, it takes a second to delete the placed block and complete the function. Not sure if the whole server freezes during this but if so, I'd like to know if there's a way to "asynchronously" (not freeze the server) run it.

Though it could just be my laptop's power saving clocking down my cpu.

@dlee13

dlee13 commented Sep 8, 2023

Copy link
Copy Markdown
Collaborator

I don't understand what placed block you're referring to that has to be deleted. I have an idea of how I would implement this, and your implementation is probably different. So I'll wait for you to push it and we can deal with your concern after I review it.

@SpaceNerden

Copy link
Copy Markdown
Contributor Author

Yep, thankfully it's earlier dismissal today.

The block I'm talking about is the placed powdered snow the bucket places before it's removed by presumably paper. I'll send a video of it when I push.

@dlee13

dlee13 commented Sep 8, 2023

Copy link
Copy Markdown
Collaborator

Holy moly, those nested loops... It's no wonder the server freezes when you run all that in a single tick. Sorry for being blunt, but this implementation is whack.

@SpaceNerden

Copy link
Copy Markdown
Contributor Author

Oh yeah, I know. Credit to klin for the nested for loops lol

But how else would I do it? Get all coords of the blocks in a 5x5x5 and random tick it off the thread? ScheduledTask perhaps?

@dlee13

dlee13 commented Sep 8, 2023

Copy link
Copy Markdown
Collaborator

Also, now that I'm actually reviewing it, I don't understand why we are changing the powder snow bucket into an empty bucket only to remove it in the end.

The implementation should be:
Make a bitset to keep track of visited block keys. Start a loop for 25 times. Get a random int. Since it's 5 blocks cubed, the random int has to be less than 125. Check the bitset for whether the random int has been set. If it has been set, continue the loop. If it's unset, set it. Do some math to get an x, y, and z component out of the random int. Add those components to the origin block position and random tick the block, Continue the loop.

@SpaceNerden

Copy link
Copy Markdown
Contributor Author

So this is why math is important for programming huh.

I'll try to find that formula and implement it today.

And are we fine with not deleting the item and just returning the bucket?

@dlee13

dlee13 commented Sep 8, 2023

Copy link
Copy Markdown
Collaborator

If we return the bucket, that makes the recipe even cheaper. But yeah, it's ok.

Also, I've just noticed that you had changed the loop bounds into -5 to 5 which makes the area of effect 10 x 10 x 10. Thus the nested loops run 25,000 iterations.

Comment thread src/main/java/xyz/holocons/mc/holoitemsrevamp/enchantment/Timefall.java Outdated
@SpaceNerden

Copy link
Copy Markdown
Contributor Author

At this point I might rip the copypaste from klin and roll my own.

Also, any starting searches for the math you mentioned above?

@dlee13

dlee13 commented Sep 8, 2023

Copy link
Copy Markdown
Collaborator

Think about how you make a 3-dimensional array into a linear array. Now we want the reverse.

https://stackoverflow.com/a/34363187

@SpaceNerden

Copy link
Copy Markdown
Contributor Author

I don't like math >.>

One side effect of checking random tickability and not re-rolling is that the hit rate is quite low. It took 2 whole hotbars to grow an oak tree out of a 4x7 sapling field.

@dlee13

dlee13 commented Sep 9, 2023

Copy link
Copy Markdown
Collaborator

Good, this is the implementation I was going for. Now that we have the basis for it, we can just adjust the numbers to make the hit rate more reasonable. I will be outside through the beginning of the day. After I get back, I'll do some testing.

@dlee13

dlee13 commented Sep 10, 2023

Copy link
Copy Markdown
Collaborator

Try this and let me know what you think.

@SpaceNerden

Copy link
Copy Markdown
Contributor Author

It's... Okay? Maybe if it was stackable and you could just walk up to a patch of dirt, spam the whole hotbar and get a respectable patch of grass. Right now it takes like 2 hotbars to get 5 grass conversions.

Copper though, is still quite bad. I think we won't be able to do anything about that because of the pre-oxidization thing. Growing trees is more economical via bone meal. If I were to use this in the server to grow or oxidize something, I'd rather use the bone blocks for bone meal and spread the copper apart and wait.

Lava generation though, that's a lot faster. Wiki says 20m for a cauldron, got my first on ~1-1.5 hotbars.

I think this item as is will be more for HD than the regular player.

@dlee13

dlee13 commented Sep 11, 2023

Copy link
Copy Markdown
Collaborator

You were right about the mechanics of copper oxidation. You can improve the chances of successful random ticking though by placing fully oxidized blocks around the copper that you're trying to oxidize. A pattern like the following is good:
X = copper
O = oxidized copper

XOOOX
OOOOO
OOOOO
OOOOO
XOOOX

As long as we're using powder snow bucket to represent the item, we can't do anything about it being unstackable. However, we could make each bucket have multiple uses. Maybe we should make the powder snow bucket have a low random chance of converting to an empty bucket.

@SpaceNerden

Copy link
Copy Markdown
Contributor Author

One random thought, what about placing blocks to extend the range, such as lightning rods? It would need to have a limit but it might be a nice mechanic.

Alternatively, we just have it decrease durability, if that's possible with a bucket.

@SpaceNerden

Copy link
Copy Markdown
Contributor Author

And also, why is the center on the player and not the placed block?

@dlee13

dlee13 commented Sep 14, 2023

Copy link
Copy Markdown
Collaborator

Items have to have ItemMeta that implements the Damageable interface to use vanilla durability mechanics, and buckets do not.

Conversely, why do we want to have the center on the clicked block rather than on the player? It seems unintuitive to me if it's not centered on the player. Also, centering on the clicked block requires that the player clicks a block to activate the ability. I have changed it so the player could also click air.

@SpaceNerden

Copy link
Copy Markdown
Contributor Author

Well, how about this gets merged and we review this item once we get feedback? I feel like we're going to be wasting time chasing perfection especially since we have a lot of items left to go

@dlee13

dlee13 commented Sep 19, 2023

Copy link
Copy Markdown
Collaborator

OK yeah, I agree.

@SpaceNerden

Copy link
Copy Markdown
Contributor Author

Converting to draft until #27 gets merged and I finish the writeup on the changes

@SpaceNerden
SpaceNerden marked this pull request as draft September 19, 2023 20:24
@dlee13

dlee13 commented Sep 20, 2023

Copy link
Copy Markdown
Collaborator

We also need to check what the correct naming scheme is supposed to be by reviewing Kronii's streams.

@SpaceNerden

Copy link
Copy Markdown
Contributor Author

Marking this as ready, we just need to check the naming scheme

@SpaceNerden
SpaceNerden marked this pull request as ready for review October 20, 2023 21:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants