Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reimplement ItemStack Obfuscation #11817

Open
wants to merge 18 commits into
base: main
Choose a base branch
from
Open

Conversation

Owen1212055
Copy link
Member

@Owen1212055 Owen1212055 commented Dec 25, 2024

Due to the amount of changes to items in the past updates, the previous configuration for obfuscation does not really fit today's representation of items.
This reimplements ItemStack obfuscation in a way that is built in mind to support the new 1.21.4 ItemModel format.

The following data components are obfuscated by default when enabled:

DataComponents.MAX_STACK_SIZE,
DataComponents.MAX_DAMAGE,
DataComponents.DAMAGE,
DataComponents.UNBREAKABLE,
DataComponents.CUSTOM_NAME,
DataComponents.ITEM_NAME,
DataComponents.LORE,
DataComponents.RARITY,
DataComponents.ENCHANTMENTS,
DataComponents.CAN_PLACE_ON,
DataComponents.CAN_BREAK,
DataComponents.ATTRIBUTE_MODIFIERS,
DataComponents.HIDE_ADDITIONAL_TOOLTIP,
DataComponents.HIDE_TOOLTIP,
DataComponents.REPAIR_COST,
DataComponents.USE_REMAINDER,
DataComponents.FOOD,
DataComponents.DAMAGE_RESISTANT
DataComponents.TOOL,
DataComponents.ENCHANTABLE,
DataComponents.REPAIRABLE,
DataComponents.GLIDER,
DataComponents.TOOLTIP_STYLE,
DataComponents.DEATH_PROTECTION,
DataComponents.STORED_ENCHANTMENTS,
DataComponents.MAP_ID,
DataComponents.POTION_CONTENTS,
DataComponents.SUSPICIOUS_STEW_EFFECTS,
DataComponents.WRITABLE_BOOK_CONTENT,
DataComponents.WRITTEN_BOOK_CONTENT,
DataComponents.CUSTOM_DATA,
DataComponents.ENTITY_DATA,
DataComponents.BUCKET_ENTITY_DATA,
DataComponents.BLOCK_ENTITY_DATA,
DataComponents.INSTRUMENT,
DataComponents.OMINOUS_BOTTLE_AMPLIFIER,
DataComponents.JUKEBOX_PLAYABLE,
DataComponents.LODESTONE_TRACKER,
DataComponents.FIREWORKS,
DataComponents.NOTE_BLOCK_SOUND,
DataComponents.BEES,
DataComponents.LOCK,
DataComponents.CONTAINER_LOOT

Unlike before, obfuscation for data components can now be configured on a per item model basis. So for example, items with the elytra item model will not obfuscate their damage component in order for their item model to properly read the damage value.

    items:
      all-models:
        also-obfuscate: []
        dont-obfuscate:
        - minecraft:lodestone_tracker
        sanitize-count: true
      enable-item-obfuscation: false
      model-overrides:
        minecraft:elytra:
          also-obfuscate: []
          dont-obfuscate:
          - minecraft:damage
          sanitize-count: true

Default Obfuscation Behavior

Patched data component values are either DROPPED or SANITIZED.
Most values are dropped, unless certain behavior restricts them from being just dropped.

Dropping (standard)

Dropping occurs when the type can be freely removed from the item without any visual/behavioral changes.
Examples:

  • diamond_sword[max_damage=10] -> diamond_sword
    • Drop the modified value, (uses the original MC value)
  • dirt[max_damage=10] -> dirt
    • Dirt doesnt use max damage, we can drop it

Sanitizing

Certain components have serious behavior changes when dropped. So these types are instead mutated.
For example:

  • minecraft:diamond_sword[enchantments={levels:{"minecraft:sharpness":1, "minecraft:unbreaking":1}}] -> minecraft:diamond_sword[enchantments={levels:{"minecraft:frost_walker":1}}]
    • Enchantments now get obfuscated, but in order to retain their glint, we send a dummy enchantment.
      (when configured)
  • minecraft:compass[lodestone_tracker={target: {dimension: "minecraft:overworld", pos: [I; 117, 160, -518]}}] -> minecraft:compass[lodestone_tracker={tracked: 0b}]
    • Retain the glow effect by keeping a dummy lodestone tracker

Tradeoff

The issue with this new system is that new types cannot be added, only removed/mutated.

Finally

Please provide any feedback on this new system, as this is a bit different and want to make sure that it is the best for people migrating from the old system. And additionally which new components people would like obfuscated by default.😄


Download the paperclip jar for this pull request: paper-11817.zip

@Owen1212055 Owen1212055 added the build-pr-jar Enables a workflow to build Paperclip jars on the pull request. label Dec 25, 2024
@Owen1212055 Owen1212055 requested a review from a team as a code owner December 25, 2024 04:28
@kennytv kennytv added the type: feature Request for a new Feature. label Dec 25, 2024
@MiniDigger
Copy link
Member

(needs docs PR)

@Owen1212055
Copy link
Member Author

This implementation has been dramatically simplified, and now supports dropping components. So for example, unbreaking is now hidden.

@Owen1212055
Copy link
Member Author

PaperMC/docs#515

@lynxplay lynxplay force-pushed the feat/component-obfuscation branch 2 times, most recently from 96734a2 to 4dd11f8 Compare January 3, 2025 19:29
Owen1212055 and others added 18 commits January 7, 2025 20:59
This general principal is that there is no mutation of the patched map, only swapping of the valid values.

Additional work will need to be done to support hiding enchantments whilst keeping the glint, as we either have to append an enchantment, or need to add a glint override.. which kinda defeats the purpose above. Cant add a vanilla enchantment because those can be removed! Further investigation needed.
@lynxplay lynxplay force-pushed the feat/component-obfuscation branch from 16dbb25 to 99aedfe Compare January 7, 2025 20:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
build-pr-jar Enables a workflow to build Paperclip jars on the pull request. type: feature Request for a new Feature.
Projects
Status: Awaiting final testing
Development

Successfully merging this pull request may close these issues.

5 participants