Skip to content

Conversation

@tillpp
Copy link
Contributor

@tillpp tillpp commented Dec 7, 2025

Now you can regenerate Health! 🥳

This follows #965 :

  1. every 5 seconds you gain one heart for the price of 0.25 energy.
  2. You spawn with an empty stomach.
  3. You can eat food to regenerate energy.

Things I also implemented:

  • onUse Event that gets triggered when an item is used (right clicked)
  • Eat Callback for onUse, that lets you define how much food should be restored. Like this:
.{
	.texture = "apple.png",
	.onUse = .{
		.type = .eat,
		.food = 0.5,
	},
}

Sped up gif:
appleEating2online-video-cutter com-ezgif com-optimize

@tillpp
Copy link
Contributor Author

tillpp commented Dec 7, 2025

Request for label

@codemob-dev codemob-dev moved this to Low Priority in PRs to review Dec 7, 2025
Copy link
Member

@IntegratedQuantum IntegratedQuantum left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As I said in #1939 (comment):
There should be no passive healing, instead healing should require an accessory. So please remove the temporary healing implementation and reimplement it with accessories once we have them.

@tillpp
Copy link
Contributor Author

tillpp commented Dec 8, 2025

As I said in #1939 (comment):

That PR isnt mine. I dont read review of other peoples PR.
And especially not closed ones.
Can't expect me to read all review comments of closed PRs of other people.

@IntegratedQuantum
Copy link
Member

That PR isnt mine. I dont read review of other peoples PR.

When implementing a feature it's always a good idea to check if someone else already made a PR, to prevent repeating the same mistakes.

@tillpp
Copy link
Contributor Author

tillpp commented Dec 11, 2025

That PR isnt mine. I dont read review of other peoples PR.

When implementing a feature it's always a good idea to check if someone else already made a PR, to prevent repeating the same mistakes.

The PR was also not named after food/eating or something similar

@tillpp
Copy link
Contributor Author

tillpp commented Dec 15, 2025

A shame that the regeneration has to be removed,
cause it felt really good. Slow steady healing that doesnt benefits you during a fight.

for anyone who wants to add it yourself locally:
this was the code in User being executed from User.update

pub fn regenerateHealth(self: *User) void {
		const healthRegenTime = main.timestamp();
		if(self.lastHealthRegenTime.durationTo(healthRegenTime).toSeconds() > 5 and self.player.energy > 0 and self.player.health < self.player.maxHealth) {
			// give 1 Health every 5 seconds
			main.items.Inventory.Sync.addHealth(1, .heal, .server, self.id);

			// but take only 1/4 food for it.
			main.items.Inventory.Sync.addEnergy(-0.25, .server, self.id);
			self.lastHealthRegenTime = healthRegenTime;
		}
	}

@tillpp
Copy link
Contributor Author

tillpp commented Dec 17, 2025

Request for Review

@IntegratedQuantum
Copy link
Member

Request for Review

Request for patience, you are already in my email queue, writing this doesn't make it go any faster.

@tillpp
Copy link
Contributor Author

tillpp commented Dec 18, 2025

Ah ok, just thought you might have forgotten that this exist

_ = tooltip.swapRemove(tooltip.items.len - 1);
}
self.tooltip = tooltip.toOwnedSlice();
self.onUse = blk: {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Callbacks should be registered after everything else, to allow it to reference other items or blocks.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

turns out to be more complex then for blocks, since blocks have an array of zon elements, but Item don't.
I only see ugly ways to implement this, like storing the zon in the BaseItem until everything is finished and then parsing the callbacks

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

did it the ugly way with a finalize() function and storing .zon object

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't like this hack. We shouldn't mix runtime and loadtime data in one struct.
Can you please use the same method as for blocks by aggregating all the item zons in a hashmap?

@IntegratedQuantum
Copy link
Member

Ah ok, just thought you might have forgotten that this exists

You can make that assumption if you don't hear from me for a week and I did review newer PRs in that time and it isn't the week before the release.

@tillpp
Copy link
Contributor Author

tillpp commented Dec 18, 2025

skipping id 12 and using id 13 instead in sync, because i saw your new PR using 12 now #2415
useItem = 13

Sync.ServerSide.executeCommand(.{.addHealth = .{.target = userId, .health = health, .cause = cause}}, null);
}
}
pub fn useItem(source: Command.InventoryAndSlot, side: Side) void {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this function is only used on the client, it should only exist in ClientSide.

if(stack.amount < 1)
return .ignored;

const previous = if(side == .server) user.?.player.energy else main.game.Player.super.energy;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please check that user is not null, because in fact in this PR you added code that passes null for this (see comment above)

}
}

pub fn useItem(_: main.Window.Key.Modifiers) bool {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please avoid boolean return values or parameters (unless it's immediately obvious from the name what they mean which is not the case here). I'd suggest to just use the callback result.

@IntegratedQuantum
Copy link
Member

also please rebase after the recent merge of sweet stuff #2417

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: In review

Development

Successfully merging this pull request may close these issues.

2 participants