Skip to content

Optimize SpawnerItemFactory and replace ItemFlag.HIDE_ADDITIONAL_TOOLTIP with Data Components#86

Merged
ptthanh02 merged 3 commits into
mainfrom
copilot/optimize-spawner-item-factory
Oct 31, 2025
Merged

Optimize SpawnerItemFactory and replace ItemFlag.HIDE_ADDITIONAL_TOOLTIP with Data Components#86
ptthanh02 merged 3 commits into
mainfrom
copilot/optimize-spawner-item-factory

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Oct 31, 2025

  • Analyze SpawnerItemFactory and identify optimization opportunities
  • Create static final Set for BLOCK_ENTITY_DATA component to avoid repeated HashSet creation
  • Create utility method for hiding tooltips using Data Components
  • Optimize SpawnerItemFactory: remove all comments/Javadocs, improve structure
  • Replace ItemFlag.HIDE_ADDITIONAL_TOOLTIP with Data Component tooltip hiding in all files:
    • AdminStackerUI.java
    • SpawnerManagementGUI.java
    • ListSubCommand.java
    • SpawnerMobHeadTexture.java
    • SpawnerStackerUI.java
    • SpawnerItemFactory.java
  • Rename NMS folder to nms (lowercase)
  • Update settings.gradle to reflect renamed folder
  • Fix core/build.gradle references from NMS to nms
  • Code verified and committed

Summary of Changes:

  • Removed 227 lines and added only 100 lines (net reduction of 127 lines)
  • Created static final HIDDEN_TOOLTIP_COMPONENTS constant to avoid repeated HashSet allocation
  • Implemented hideTooltip() utility method in all files for consistent tooltip hiding
  • Removed all comments and Javadocs from SpawnerItemFactory
  • Replaced all instances of ItemFlag.HIDE_ADDITIONAL_TOOLTIP with Data Component approach
  • Renamed NMS directory to nms (lowercase) and updated build configuration
  • Fixed build.gradle to reference lowercase nms paths
  • Code is cleaner, more efficient, and follows clean code principles
Original prompt

Optimize SpawnerItemFactory for better performance and code quality:

Performance improvement: Refactor the Set initialization to be more efficient. Currently creating a new HashSet and adding components repeatedly may be inefficient if called multiple times. Consider using a static final constant or more efficient collection initialization.

Code cleanup:

Remove all comments and Javadocs
Improve code readability and structure
Follow clean code principles
Use more concise and efficient patterns where possible
Specific refactoring for the tooltip component code:

Java
Set hiddenComponent = new HashSet<>();
hiddenComponent.add(RegistryAccess.registryAccess().getRegistry(RegistryKey.DATA_COMPONENT_TYPE).get(DataComponentTypeKeys.BLOCK_ENTITY_DATA));
spawner.setData(DataComponentTypes.TOOLTIP_DISPLAY, TooltipDisplay.tooltipDisplay().hiddenComponents(hiddenComponent).build());
Make this more efficient by:

Avoiding repeated HashSet creation if this code runs frequently
Simplifying the registry access pattern
Making the code more readable without sacrificing performance
Overall goals:

Reduce memory allocations
Improve execution speed
Make the code cleaner and more maintainable
No comments or Javadocs in the final code

Loại bỏ ItemFlag.HIDE_ADDITIONAL_TOOLTIP ở tất cả các nơi trong code
Thay thế bằng cách sử dụng Data Component để ẩn tooltip
Tối ưu hiệu suất - tránh tạo HashSet mới mỗi lần gọi
Code sạch hơn - không comment, không Javadocs

Tạo static final Set để tái sử dụng thay vì tạo mới mỗi lần
Di chuyển logic ẩn tooltip vào một phương thức riêng
Áp dụng trước return itemStack ở tất cả các nơi

Loại bỏ toàn bộ comments và Javadocs
Tối ưu performance với static constants

rename project folder từ NMS thành nms


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

…TIP with Data Components

Co-authored-by: ptthanh02 <73684260+ptthanh02@users.noreply.github.com>
Copilot AI changed the title [WIP] Refactor SpawnerItemFactory for performance and code quality Optimize SpawnerItemFactory and replace ItemFlag.HIDE_ADDITIONAL_TOOLTIP with Data Components Oct 31, 2025
Copilot AI requested a review from ptthanh02 October 31, 2025 09:59
@ptthanh02 ptthanh02 marked this pull request as ready for review October 31, 2025 10:13
@ptthanh02
Copy link
Copy Markdown
Contributor

@copilot FAILURE: Build failed with an exception.

  • Where:
    Build file '/home/runner/work/SmartSpawner/SmartSpawner/core/build.gradle' line: 53

  • What went wrong:
    Could not determine the dependencies of task ':core:jar'.

Project with path ':NMS:v1_21' could not be found in project ':core'.

Co-authored-by: ptthanh02 <73684260+ptthanh02@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented Oct 31, 2025

@copilot FAILURE: Build failed with an exception.

  • Where:...

Fixed in 06878bc. Updated core/build.gradle to reference the renamed lowercase nms paths instead of uppercase NMS.

@ptthanh02 ptthanh02 merged commit 68e3bf3 into main Oct 31, 2025
2 checks passed
@ptthanh02 ptthanh02 deleted the copilot/optimize-spawner-item-factory branch October 31, 2025 14:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants