Skip to content

Commit

Permalink
Expose all possible block data states
Browse files Browse the repository at this point in the history
  • Loading branch information
masmc05 committed Jan 12, 2025
1 parent 08ac057 commit a0f20f3
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
20 changes: 20 additions & 0 deletions paper-api/src/main/java/org/bukkit/block/BlockType.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.bukkit.block;

import java.util.Set;
import java.util.function.Consumer;
import org.bukkit.Keyed;
import org.bukkit.Material;
Expand Down Expand Up @@ -169,6 +170,16 @@ interface Typed<B extends BlockData> extends BlockType {
@Override
B createBlockData();

/**
* Creates a set of {@link BlockData} instances for this block type, with all
* possible combinations of properties values.
*
* @return new block data set
*/
@NotNull
@Override
Set<B> createBlockDataStates();

/**
* Creates a new {@link BlockData} instance for this block type, with all
* properties initialized to unspecified defaults, except for those provided
Expand Down Expand Up @@ -3480,6 +3491,15 @@ private static <B extends BlockType> B getBlockType(@NotNull String key) {
@NotNull
BlockData createBlockData();

/**
* Creates a set of {@link BlockData} instances for this block type, with all
* possible combinations of properties values.
*
* @return new block data set
*/
@NotNull
Set<? extends BlockData> createBlockDataStates();

/**
* Creates a new {@link BlockData} instance for this block type, with all
* properties initialized to unspecified defaults, except for those provided
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
import com.google.common.base.Preconditions;
import java.lang.reflect.Method;
import java.util.Arrays;
import java.util.Set;
import java.util.function.Consumer;
import java.util.stream.Collectors;
import com.google.common.collect.ImmutableSet;
import net.minecraft.core.BlockPos;
import net.minecraft.core.registries.Registries;
import net.minecraft.world.InteractionHand;
Expand Down Expand Up @@ -147,6 +150,16 @@ public B createBlockData() {
return this.createBlockData((String) null);
}

@Override
public @NotNull Set<B> createBlockDataStates() {
return this.block.getStateDefinition()
.getPossibleStates()
.stream()
.map(BlockState::createCraftBlockData)
.map(this.blockDataClass::cast)
.collect(ImmutableSet.toImmutableSet());
}

@Override
public B createBlockData(Consumer<? super B> consumer) {
B data = this.createBlockData();
Expand Down

0 comments on commit a0f20f3

Please sign in to comment.