ECS Party | The Bag#2989
Conversation
|
Ahhh! i already have an ECS14 , not pushed tho |
HEy! all ECS parts are related to the big chunky #2652 ! notice for example how PlayerComponent is not part of the ECS series: #2889 even though its ECS related, because it's not 2652 related! Or PVP #2890 is also not part of the series, even though it is ECS related! because its not 2652 related! all ECS parts are intended to be related to 2652 If you could have handled a 4k PR i would have put all ECS parts into this one PR so name change requested! |
|
Also: please include screenshots when adding something visual |
|
|
||
| user.spawnPos = playerData.get(?Vec3d, "playerSpawnPos", null); | ||
|
|
||
| if (main.entity.components.@"cubyz:bag".server.get(user.id) == null) { |
There was a problem hiding this comment.
could you move this into initPlayer?
to make it more consistent with the other player related components (@"cubyz:model")
or do it the other way around, having the default model loaded where the bag is loaded,
Maybe this is a pattern that will occur so often, that it would make sense to have some kind of general main.entity.server.initNewPlayer functionality.
| }; | ||
|
|
||
| const TakeFromPlayerBag = struct { // MARK: TakeFromPlayerBag | ||
| dest: InventoryAndSlot, |
There was a problem hiding this comment.
Can you maybe use here the Inventories as the destinations, with a putItemsInto.
Currently this does not change really anything but would stop us from later needing to refactor this if needed.
I also thought maybe we want shift clicking in general to have the hand as a fallback?
|
|
||
| const topItem = self.inventory.peek(0); | ||
| const shouldRenderStackSizeText = topItem.item.stackSize() > 1; | ||
| if (shouldRenderStackSizeText) { |
There was a problem hiding this comment.
from here a lot is just copy from itemslot. I know they have key differences but maybe we want to generlize something here? Like a itemStackInformation we can render on top?
There was a problem hiding this comment.
I decided to move part of the rendering code to items.zig
Oh sorry, I renamed it to avoid the name conflicts :P |
https://discord.com/channels/443805812390100992/574185221939789855/1498398538424651817 |
In the PR!!!
what does this have to do with a Party? |
| var remainingAmount = @min(self.amount, bag.peek(0).amount); | ||
| const item = bag.peek(0).item; | ||
| outer: for (self.destinations.inventories) |inv| { | ||
| for (inv._items, 0..) |itemStack, slot| { | ||
| if (remainingAmount == 0) break :outer; | ||
| if (itemStack.item != .null and !std.meta.eql(itemStack.item, item)) continue; | ||
|
|
||
| const amount = @min(remainingAmount, item.stackSize() - itemStack.amount); | ||
| remainingAmount -= amount; | ||
|
|
||
| ctx.execute(.{.takeFromBag = .{.source = bag, .dest = .{.inv = inv, .slot = @intCast(slot)}, .amount = amount}}); | ||
| } | ||
| } |
There was a problem hiding this comment.
why did you not just use the putItemsInto? you would just need to expand the Provider (in a fast done not complete tested version) this is how the Provider would look like:
const Provider = union(enum) {
move: InventoryAndSlot,
create: Item,
fromBag: *BagInventory,
pub fn getBaseOperation(provider: Provider, dest: InventoryAndSlot, amount: u16) sync.Command.BaseOperation {
return switch (provider) {
.move => |slot| .{.move = .{
.dest = dest,
.amount = amount,
.source = slot,
}},
.create => |item| .{.create = .{
.dest = dest,
.amount = amount,
.item = item,
}},
.fromBag => |bag| .{.takeFromBag = .{
.dest = dest,
.source = bag,
.amount = amount,
}},
};
}
pub fn getItem(provider: Provider) Item {
return switch (provider) {
.move => |slot| slot.ref().item,
.create => |item| item,
.fromBag => |bag| bag.peek(0).item,
};
}
};
maybe I am not seeing a different problem?
There was a problem hiding this comment.
In my current code I stop depositing when the item changes.
It's a birthday party for the ECS: The first actual ECS feature that lands :P |
NOOOO! |
|
when dragging over the bag you take from it but also put things into the selected itemslots 2026-04-28.21-41-57.mp4this is I think a more simple example to the general problem. It seems the taking is done on release even if you are not hovering over the bag anymore 2026-04-28.21-46-00.mp4 |
|
Another thing I noted. When having for example a |
|
Tooltip is blocked by #2527 |
| for (inv._items, 0..) |itemStack, slot| { | ||
| if (remainingAmount == 0) break :outer; | ||
| if (itemStack.item != .null and !std.meta.eql(itemStack.item, item)) continue; | ||
| if (!std.meta.eql(bag.peek(0).item, item)) continue; |
There was a problem hiding this comment.
could you not break here? this will never change after it once becomes true
| outer: for (self.destinations.inventories) |inv| { | ||
| for (inv._items, 0..) |itemStack, slot| { | ||
| if (remainingAmount == 0) break :outer; | ||
| if (itemStack.item != .null and !std.meta.eql(itemStack.item, item)) continue; | ||
| if (!std.meta.eql(bag.peek(0).item, item)) continue; | ||
|
|
||
| const amount = @min(remainingAmount, item.stackSize() - itemStack.amount); | ||
| remainingAmount -= amount; | ||
|
|
||
| ctx.execute(.{.takeFromBag = .{.source = bag, .dest = .{.inv = inv, .slot = @intCast(slot)}, .amount = amount}}); |
There was a problem hiding this comment.
in general this does not match the behavior we want for inventory -> inventories.
I would still suggest to just use putItemsInto and add there the if(!std.meta.eql(provider.getItem(), item)) break behavior
There was a problem hiding this comment.
I decided to instead precalculate the amount here.
|
Wait, so the bag can hold 120 STACKS of items??? |
| amount +|= stack.amount; | ||
| } | ||
| amount = @min(amount, self.amount); | ||
| std.debug.assert(self.destinations.putItemsInto(ctx, amount, .{.bag = bag}) == 0); |
There was a problem hiding this comment.
this would mean, you crash the game if the amount doesn't fit into the destinations. I would say just ignore the return value
There was a problem hiding this comment.
Oh right, I wasn't thinking
Wunka
left a comment
There was a problem hiding this comment.
I really like it!
The most that the amount which is shown is stack independent and instead item driven
Since it exists now, I decided to put the relevant stuff into the ECS and following the pattern: Anything remotely related to the ECS gets the ECS label and number in the title :P <img width="2560" height="1413" alt="Screenshot at 2026-04-28 21-19-39" src="https://github.com/user-attachments/assets/3f176c86-9408-4c3f-b49d-791be39c83a4" /> Remaining work: - [x] make an issue for the missing inventory actions (right clicking, shift clicking) - [x] display the capacity fixes PixelGuys#73
Since it exists now, I decided to put the relevant stuff into the ECS and following the pattern: Anything remotely related to the ECS gets the ECS label and number in the title :P
Remaining work:
fixes #73