generate method
Widget
generate(
- Context context
)
Implementation
@override
Widget generate(Context context) {
final page = Score(Entity.Player(distance: Range.to(8)), pageScore);
final reset = [
Kill(
Entity(
type: Entities.item,
nbt: {
'Item': {
'tag': {
'objd': {'gui': true}
},
},
},
),
),
...itemActions(),
Teleport.entity(
Entity(
type: Entities.item,
tags: ['objd_gui_dropitem'],
),
to: Entity.Player(
distance: Range.to(8),
),
),
Clear(
Entity.All(distance: Range.to(20)),
Item('#${context.packId}:all', nbt: {
'objd': {'gui': true}
}),
),
File.execute(
'$path/reset_gui${index}',
child: For.of(setItems()),
),
If(Condition.not(page & index), then: [
File.execute(
'$path/clear$index',
child: For.of(clear()),
),
])
];
final s = Score(Entity.Player(distance: Range.to(8)), countScore);
Data getItemCount;
var isPlayer = false;
switch (container) {
case GuiContainer.inventory:
{
isPlayer = true;
getItemCount =
Data.get(Entity.Self(), path: 'Inventory[].tag.objd.gui');
break;
}
case GuiContainer.enderchest:
{
isPlayer = true;
getItemCount =
Data.get(Entity.Self(), path: 'EnderItems[].tag.objd.gui');
break;
}
case GuiContainer.minecart:
{
getItemCount = Data.get(Entity.Self(), path: 'Items[].tag.objd.gui');
break;
}
default:
getItemCount = Data.get(Location.here(), path: 'Items[].tag.objd.gui');
}
var children = <Widget>[
s,
s.setToCondition(Condition.data(getItemCount)),
If(s & 0, then: [
File.execute(
'$path/reset_gui${index}',
create: false,
),
]),
If(Condition.not(s & _slots.length), then: [
File.execute(
'$path/actions${index}',
child: For.of(reset),
),
]),
];
for (var slot in _slots) {
if (slot.countScore != null) {
children.add(If(slot.countScore! > 0, then: [
Builder((c) {
if (isPlayer) {
print(
'WARNING! Currently you can\'t modify the data of a player. The count of the slot ${slot.slot?.slot} cannot be modified!',
);
}
if (container == GuiContainer.inventory) {
return Data.fromScore(
Entity.Self(),
path: 'Inventory[{"Slot":${slot.slot?.id}b }].Count',
score: slot.countScore,
);
}
if (container == GuiContainer.enderchest) {
return Data.fromScore(
Entity.Self(),
path: 'EnderItems[{"Slot":${slot.slot?.id}b }].Count',
score: slot.countScore,
);
}
if (container == GuiContainer.minecart) {
return Data.fromScore(
Entity.Self(),
path: 'Items[{"Slot":${slot.slot?.id}b }].Count',
score: slot.countScore,
);
}
return Data.fromScore(
Location.here(),
path: 'Items[{"Slot":${slot.slot?.id}b }].Count',
score: slot.countScore,
);
})
]));
}
}
return For.of(children);
}