Skip to content

Commit

Permalink
Fix empty custom data components being added when opening tater boxes
Browse files Browse the repository at this point in the history
  • Loading branch information
haykam821 authored and Patbox committed Nov 17, 2024
1 parent ef43074 commit 542d6e6
Showing 1 changed file with 15 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public ActionResult use(World world, PlayerEntity user, Hand hand) {
ItemStack stack = user.getStackInHand(hand);

if (!user.getWorld().isClient()) {
this.openTaterBox(world, (ServerPlayerEntity) user, stack, hand);
this.openTaterBox((ServerPlayerEntity) user, stack, hand);
}

return ActionResult.SUCCESS_SERVER;
Expand All @@ -76,15 +76,22 @@ public ActionResult use(World world, PlayerEntity user, Hand hand) {
@Override
public boolean onClicked(ItemStack stack, ItemStack otherStack, Slot slot, ClickType clickType, PlayerEntity player, StackReference cursorStackReference) {
if (clickType == ClickType.RIGHT && !player.getWorld().isClient()) {
this.openTaterBox(player.getWorld(), (ServerPlayerEntity) player, stack, null);
this.openTaterBox((ServerPlayerEntity) player, stack, null);
return true;
}

return false;
}

private void openTaterBox(World world, ServerPlayerEntity user, ItemStack stack, Hand hand) {
if (NEItems.canUseTaters(user) && stack.contains(NEDataComponentTypes.TATER_SELECTION)) {
private void openTaterBox(ServerPlayerEntity user, ItemStack stack, Hand hand) {
if (NEItems.canUseTaters(user)) {
this.migrateCollectedTaters(user, stack);
this.openTaterBoxUi(user, stack, hand);
}
}

private void migrateCollectedTaters(ServerPlayerEntity user, ItemStack stack) {
if (stack.contains(DataComponentTypes.CUSTOM_DATA)) {
stack.apply(DataComponentTypes.CUSTOM_DATA, NbtComponent.DEFAULT, customData -> {
if (!customData.contains(LEGACY_TATERS_KEY)) {
return customData;
Expand All @@ -105,7 +112,11 @@ private void openTaterBox(World world, ServerPlayerEntity user, ItemStack stack,
user.sendMessage(Text.translatable("text.nucleoid_extras.tater_box.updated"));
});
});
}
}

private void openTaterBoxUi(ServerPlayerEntity user, ItemStack stack, Hand hand) {
if (stack.contains(NEDataComponentTypes.TATER_SELECTION)) {
var state = PlayerLobbyState.get(user);
List<GuiElementInterface> taters = new ArrayList<>();

Expand Down

0 comments on commit 542d6e6

Please sign in to comment.