Sponge
Sponge copied to clipboard
Piston Body from Piston Head
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