Paper icon indicating copy to clipboard operation
Paper copied to clipboard

More MemoryKey API

Open Machine-Maker opened this issue 4 years ago • 16 comments

So I added a bunch more of the memory keys. Pretty sure I tested one of every type to ensure the conversions were working correctly.

Only ones I didn't add keys for, are the ones without a clear bukkit equivalent class to its type. These are the nms classes I didn't know of a bukkit equivalent for:

  • PositionTracker
  • WalkTarget
  • DamageSource (1.19.4 should make adding API for this nicer)
  • Path (just needs a slight re-work of paper's path api impl)

Machine-Maker avatar May 10 '21 02:05 Machine-Maker

Interesting approach. Thanks for adding that, thought of adding it myself. Had a simpler not finished approach here: https://github.com/WeepingMC/Weeper/pull/1/files

yannicklamprecht avatar May 10 '21 16:05 yannicklamprecht

Taking a look at your method, I can simplify mine more, by removing the need for multiple List and Set converters.

Idk what the best way to do it is, have a big chain of instanceof checks, or the way I did it. I didn’t really want to add a ton of instanceof checks just cause I think it’s ugly.

Also, I see you used Vector for BlockPosition. Didn’t think of that, is that what should be used as the Bukkit equivalent of BlockPos? I just did a world-less location.

Machine-Maker avatar May 10 '21 17:05 Machine-Maker

Vector would probably be preferred, allowing Locations without a world was a mistake

electronicboy avatar May 10 '21 17:05 electronicboy

Yeah the instance of chain is ugly but a good min diff solution.

The preferred thing I like to do is an enhanced switch with Pattern matching but this is out of scope because the feature is not even out of preview state. 😢

  return switch (object){
            case GlobalPos globalPos -> fromNms(globalPos);
            case Long longValue -> longValue;
            case UUID uuid -> uuid;
            case Boolean booleanValue -> booleanValue;
            default -> throw new UnsupportedOperationException("Do not know how to map " + object);
        }

So under that condition I'm fine with that map. Your way it is much more extendable.

yannicklamprecht avatar May 10 '21 18:05 yannicklamprecht

Yeah, pattern matching would be nice. Gonna be a while before Paper gets that though... :laughing:

Machine-Maker avatar May 10 '21 20:05 Machine-Maker

Ok, made some changes to this.

Machine-Maker avatar May 11 '21 19:05 Machine-Maker

Yeah, pattern matching would be nice. Gonna be a while before Paper gets that though... 😆

A day later and everything has changed. 🤣

yannicklamprecht avatar May 12 '21 23:05 yannicklamprecht

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Aug 19 '21 12:08 stale[bot]

Bad stale bot. :D

yannicklamprecht avatar Aug 19 '21 15:08 yannicklamprecht

Rebased and reworked a bit. Much cleaner, but I still think this is the way to go over big pattern matching chains.

Machine-Maker avatar Nov 04 '21 01:11 Machine-Maker

Rebased for 1.18.1

Machine-Maker avatar Dec 24 '21 20:12 Machine-Maker

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Feb 23 '22 07:02 stale[bot]

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Apr 24 '22 21:04 stale[bot]

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Jul 02 '22 00:07 stale[bot]

Rebased for 1.19. Mojang added Unit memory types, I just used Void, not sure there's a point it adding a Unit enum.

Machine-Maker avatar Jul 04 '22 00:07 Machine-Maker

Rebased with all new memory types

Machine-Maker avatar Feb 23 '23 21:02 Machine-Maker