#How to use `permutationToPlace`?

1 messages · Page 1 of 1 (latest)

hardy summit
#

In custom components in block, how do I use permutationToPlace in beforeOnPlayerPlace event.

My custom block has "block:part" state, I tried to place the block with a value of 'lower' of this state.

I tried to write like this, but this doesn't do anything. permutationToPlace don't have resolve().

const {block, permutationToPlace} = event;
permutationToPlace.withState('block:part', 'lower')
primal citrus
#

permutationBeingPlaced is read-only. The only thing you can generally do with the before events is set event.cancel to true.

You can cancel the event and then run the logic you want using system.run, or you can use the playerPlaceBlockAfterEvent instead and change the state then.

hardy summit
# primal citrus `permutationBeingPlaced` is read-only. The only thing you can generally do with ...

First, this is permutationToPlace not permutationBeingPaced.

Second, this isn't PlayerPlaceBlockBeforeEvent class, this is an event within the custom block components. I mentioned that.

So this is completely different on what you're talking about. So please read carefully.

Here it is:
https://learn.microsoft.com/en-us/minecraft/creator/scriptapi/minecraft/server/blockcomponentplayerplacebeforeevent?view=minecraft-bedrock-experimental

Contents of the @minecraft/server.BlockComponentPlayerPlaceBeforeEvent class.

primal citrus
# hardy summit First, this is `permutationToPlace` not `permutationBeingPaced`. Second, this i...

Ahh, sorry about that. Just woke up. I haven't used Custom Block components yet, but the documentation says:

The block permutation that will be placed if the event is not cancelled. If set to a different block permutation, that permutation will be placed instead.

Calling event.permutationToPlace.withState doesn't modify the permutation, it returns a new permutation object with that state set. So you need to do

const {block, permutationToPlace} = event;
event.permutationToPlace = permutationToPlace.withState('block:part', 'lower');
hardy summit
primal citrus