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

Piston Body from Piston Head #3885

Open
mosemister opened this issue Aug 25, 2023 · 0 comments
Open

Piston Body from Piston Head #3885

mosemister opened this issue Aug 25, 2023 · 0 comments
Labels
status: needs triage This label is automatically applied to new issues and pull requests to indicate they require triage type: feature request A feature request

Comments

@mosemister
Copy link
Member

mosemister commented Aug 25, 2023

Is this request specific to one implementation of Sponge?

No

Sponge Version

1.16.5-8.1.0-RC1357

What are you requesting?

Currently Sponge's org.spongepowered.api.block.entity.Piston can be either a piston head, piston body or sticky piston body. If the Piston is the head then I would love to be able to access the BlockState of the piston.

Looking at the fields, there is a field known as blockState which fufils this so should be a easy scenario of exporting this.

Code example

public void onEvent(NotifyNeighborBlockEvent event){
        Optional<Piston> opPiston = event.cause().first(Piston.class);
        if (opPiston.isEmpty()) {
            return;
        }
        Piston piston = opPiston.get();
        
}

The problem with the current block()?

Currently there is already a method of Piston#block() provides the movingState rather then the body of the piston.

This is fine for what im doing until the piston retracts, where the block taking over the head position. so this block() returns that block ... which means i cant get piston data.

Whats wrong with the current blockstate()?

Currently there is a method of Piston.blockstate() which returns a Mutable where you should be able to get()

However

This happens

java.util.NoSuchElementException: Could not retrieve value for key 'SpongeKey{key=sponge:block_state, elementType=interface org.spongepowered.api.block.BlockState}'
	at org.spongepowered.api.data.value.ValueContainer.lambda$requireValue$1(ValueContainer.java:186) ~[ValueContainer.class:1.16.5-8.1.0-RC1357]
	at java.util.Optional.orElseThrow(Optional.java:408) ~[?:?]
	at org.spongepowered.api.data.value.ValueContainer.requireValue(ValueContainer.java:186) ~[ValueContainer.class:1.16.5-8.1.0-RC1357]
	at org.spongepowered.api.block.entity.Piston.blockState(Piston.java:46) ~[Piston.class:1.16.5-8.1.0-RC1357]

And personally I haven't looked at if this block state is what im after

Why not Piston#get?

This seems to get the data of the movingStore rather then the BlockState

@mosemister mosemister added status: needs triage This label is automatically applied to new issues and pull requests to indicate they require triage type: feature request A feature request labels Aug 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: needs triage This label is automatically applied to new issues and pull requests to indicate they require triage type: feature request A feature request
Projects
None yet
Development

No branches or pull requests

1 participant