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

Finish implementing WireAttachmentData. #1934

Merged
merged 2 commits into from
Jul 3, 2018
Merged

Conversation

JBYoshi
Copy link
Member

@JBYoshi JBYoshi commented Jun 6, 2018

WireAttachmentData was partially implemented some time back. This should finish it.

Test code: (Drop this into a plugin. source should be a Player.)

        source.getLocation().setBlock(BlockTypes.REDSTONE_WIRE.getDefaultState());
        ImmutableWireAttachmentData blockData = source.getLocation().getBlock().withExtendedProperties(source.getLocation())
                .get(ImmutableWireAttachmentData.class).get();
        source.sendMessage(Text.of("state: ", DataFormats.JSON.write(blockData.toContainer())));

        WireAttachmentData data = Sponge.getDataManager().getManipulatorBuilder(WireAttachmentData.class).get().create();
        data.set(Keys.WIRE_ATTACHMENT_NORTH, WireAttachmentTypes.SIDE);
        data.set(Keys.WIRE_ATTACHMENT_SOUTH, WireAttachmentTypes.UP);
        source.sendMessage(Text.of("individual set: ", DataFormats.JSON.write(data.toContainer())));

        data = Sponge.getDataManager().getManipulatorBuilder(WireAttachmentData.class).get().create();
        Map<Direction, WireAttachmentType> map = new HashMap<>();
        map.put(Direction.NORTH, WireAttachmentTypes.NONE);
        map.put(Direction.SOUTH, WireAttachmentTypes.SIDE);
        map.put(Direction.EAST, WireAttachmentTypes.UP);
        // skip west
        map.put(Direction.SOUTH_SOUTHEAST, WireAttachmentTypes.UP); // fake value
        data.set(Keys.WIRE_ATTACHMENTS, map);
        source.sendMessage(Text.of("bulk set: ", DataFormats.JSON.write(data.toContainer())));

@JBYoshi JBYoshi requested a review from gabizou as a code owner June 6, 2018 22:02
@JBYoshi JBYoshi added system: data status: needs review a code review is needed version: 1.12 (u) API: 7 (unsupported since May 21st 2021) labels Jun 6, 2018
@gabizou gabizou mentioned this pull request Jun 6, 2018

private Map<Direction, WireAttachmentType> wireAttachmentMap;

public SpongeWireAttachementData(Map<Direction, WireAttachmentType> attachmentMap) {
public SpongeWireAttachmentData() {
this(ImmutableMap.of(Direction.NORTH, WireAttachmentTypes.NONE,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This map can be stored in final static field and referenced here.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

@parlough parlough added status: ready to merge This PR is ready to be merged and removed status: needs review a code review is needed labels Jun 28, 2018
@parlough parlough merged commit 6af67f7 into stable-7 Jul 3, 2018
parlough pushed a commit to parlough/SpongeCommon that referenced this pull request Jul 3, 2018
* Finish implementing WireAttachmentData.

* Save the default values as a constant.
@JBYoshi JBYoshi deleted the impl/wire-attachment-data branch July 3, 2018 04:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: ready to merge This PR is ready to be merged system: data version: 1.12 (u) API: 7 (unsupported since May 21st 2021)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants