Conversation
|
If you'd prefer I can rebase onto the 1.21 branch and target that. Let me know. Edit: I have also rebased onto 1.21, I can cherry-pick any revisions from here onto there and it should be ready to go. |
|
I've only just noticed that indentation is buggered. |
vectorwing
left a comment
There was a problem hiding this comment.
Alright, I did a first pass over the code, and found a few inconsistencies.
The code works when testing locally, and I can see you fixed the issue where the Stove won't spill its contents when blocked while unlit, which is good.
I can do a second pass after the current comments are addressed. 👍
| super.stepOn(level, pos, state, entity); | ||
| } | ||
|
|
||
| protected void burnEntitySteppingOnStove(Level level, BlockPos pos, BlockState state, Entity entity) { |
There was a problem hiding this comment.
Not sure if this method needs to be separate, as it contains almost all of the code that would go into stepOn.
There was a problem hiding this comment.
In the original version of the code, the base.stepOn() was invoked at the end of the method, but I wanted to use early-return pattern to make this method easier to read.
To keep the order of invocation the same and use early return pattern, I had to extract this method
| inventoryChanged(); | ||
| return true; | ||
| private void addSmokeParticles() { | ||
| assert this.level != null; |
There was a problem hiding this comment.
particleTick has access to the client level, so passing it to this method would eliminate the need for this assert. Also, IIRC, assert actually throws an exception when it's null; perhaps just returning early would be best in such cases.
There was a problem hiding this comment.
assertions are not enabled by default
the assertion is here to make it clear to developers reading the code that the method must only be invoked in contexts where the level is definitely not null
| } | ||
|
|
||
| private void cookAndOutputItems() { | ||
| assert this.level != null; |
There was a problem hiding this comment.
assert should be avoided in production code, as it throws exceptions on fail.
Here, it may be better to just return when null instead.
There was a problem hiding this comment.
Assertions are not enabled by default
Edit: I verified this, assert false didn't throw any exception at runtime
of course, passing a null value to the level parameter of whatever function needs it would probably cause an exception, but the point of the assertion is to ensure that this.level is actually never null because developers know they must only call the function when this.level is definitely not null
As previous: this is primarily to signal to developers reading the code that the method must be invoked only when the level is definitely not null
|
I added a tiny change to the Stove, where it makes a sound when placing items on the grill. That might cause a small conflict, sorry about that. 😅 |
e.g. don't burn items!
cd04864 to
b71082d
Compare
|
Ready for second pass |
There was a problem hiding this comment.
Second pass done. Aside from a comment and a quick question, everything here seems in order. You managed to organize one of the oldest bits of code in FD, it's looking pretty tidy! 👍
I think we're ready for a merge. I can address the comment below on my own later, unless you'd like to.
|
|
||
| if (heldStack.canPerformAction(ToolActions.SHOVEL_DIG)) { | ||
| if (!level.isClientSide()) { | ||
| level.levelEvent(null, 1009, pos, 0); |
There was a problem hiding this comment.
For level events, it would be more readable if we used the LevelEvent static fields directly, so that others reading the code know that 1009 is SOUND_EXTINGUISH_FIRE.
|
|
||
| var newState = state.setValue(LIT, false); | ||
| level.setBlock(pos, newState, 11); | ||
| level.gameEvent(GameEvent.BLOCK_CHANGE, pos, GameEvent.Context.of(entity, newState)); |
There was a problem hiding this comment.
Question: why is this game event being sent twice?
| return tryToPlaceFoodItem(state, level, pos, player, hand, hit); | ||
| } | ||
|
|
||
| protected InteractionResult tryToIgnite(BlockState state, Level level, BlockPos pos, Player player, InteractionHand hand, BlockHitResult hit) { |
There was a problem hiding this comment.
Igniting currently lacks the gameEvent call, so it doesn't trigger sculk sensors. Might be worth adding here too.
specifically, send all sounds from the server, don't play any local sounds
since extinguish does already
No description provided.