Skip to content

Commit

Permalink
Expose all possible block data states (#11958)
Browse files Browse the repository at this point in the history
  • Loading branch information
masmc05 authored Jan 12, 2025
1 parent 50c2c59 commit 3709150
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
19 changes: 19 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.Collection;
import java.util.function.Consumer;
import org.bukkit.Keyed;
import org.bukkit.Material;
Expand Down Expand Up @@ -120,6 +121,7 @@
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.annotations.Unmodifiable;

/**
* While this API is in a public interface, it is not intended for use by
Expand Down Expand Up @@ -169,6 +171,15 @@ interface Typed<B extends BlockData> extends BlockType {
@Override
B createBlockData();

/**
* Creates a collection of {@link BlockData} instances for this block type, with all
* possible combinations of properties values.
*
* @return new block data collection
*/
@Override
@Unmodifiable @NotNull Collection<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,14 @@ private static <B extends BlockType> B getBlockType(@NotNull String key) {
@NotNull
BlockData createBlockData();

/**
* Creates a collection of {@link BlockData} instances for this block type, with all
* possible combinations of properties values.
*
* @return new block data collection
*/
@Unmodifiable @NotNull Collection<? 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,9 @@
import com.google.common.base.Preconditions;
import java.lang.reflect.Method;
import java.util.Arrays;
import java.util.Collection;
import java.util.function.Consumer;
import com.google.common.collect.ImmutableList;
import net.minecraft.core.BlockPos;
import net.minecraft.core.registries.Registries;
import net.minecraft.world.InteractionHand;
Expand Down Expand Up @@ -147,6 +149,16 @@ public B createBlockData() {
return this.createBlockData((String) null);
}

@Override
public @NotNull Collection<B> createBlockDataStates() {
final ImmutableList<BlockState> possibleStates = this.block.getStateDefinition().getPossibleStates();
final ImmutableList.Builder<B> builder = ImmutableList.builderWithExpectedSize(possibleStates.size());
for (final BlockState possibleState : possibleStates) {
builder.add(this.blockDataClass.cast(possibleState.createCraftBlockData()));
}
return builder.build();
}

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

0 comments on commit 3709150

Please sign in to comment.