Expose all possible block data states (#11958)
This commit is contained in:
@ -1,5 +1,6 @@
|
|||||||
package org.bukkit.block;
|
package org.bukkit.block;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
import org.bukkit.Keyed;
|
import org.bukkit.Keyed;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
@ -120,6 +121,7 @@ import org.bukkit.inventory.ItemType;
|
|||||||
import org.jetbrains.annotations.ApiStatus;
|
import org.jetbrains.annotations.ApiStatus;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
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
|
* While this API is in a public interface, it is not intended for use by
|
||||||
@ -169,6 +171,15 @@ public interface BlockType extends Keyed, Translatable, net.kyori.adventure.tran
|
|||||||
@Override
|
@Override
|
||||||
B createBlockData();
|
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
|
* Creates a new {@link BlockData} instance for this block type, with all
|
||||||
* properties initialized to unspecified defaults, except for those provided
|
* properties initialized to unspecified defaults, except for those provided
|
||||||
@ -3480,6 +3491,14 @@ public interface BlockType extends Keyed, Translatable, net.kyori.adventure.tran
|
|||||||
@NotNull
|
@NotNull
|
||||||
BlockData createBlockData();
|
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
|
* Creates a new {@link BlockData} instance for this block type, with all
|
||||||
* properties initialized to unspecified defaults, except for those provided
|
* properties initialized to unspecified defaults, except for those provided
|
||||||
|
|||||||
@ -3,7 +3,9 @@ package org.bukkit.craftbukkit.block;
|
|||||||
import com.google.common.base.Preconditions;
|
import com.google.common.base.Preconditions;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
import java.util.Collection;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
|
import com.google.common.collect.ImmutableList;
|
||||||
import net.minecraft.core.BlockPos;
|
import net.minecraft.core.BlockPos;
|
||||||
import net.minecraft.core.registries.Registries;
|
import net.minecraft.core.registries.Registries;
|
||||||
import net.minecraft.world.InteractionHand;
|
import net.minecraft.world.InteractionHand;
|
||||||
@ -147,6 +149,16 @@ public class CraftBlockType<B extends BlockData> implements BlockType.Typed<B>,
|
|||||||
return this.createBlockData((String) null);
|
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
|
@Override
|
||||||
public B createBlockData(Consumer<? super B> consumer) {
|
public B createBlockData(Consumer<? super B> consumer) {
|
||||||
B data = this.createBlockData();
|
B data = this.createBlockData();
|
||||||
|
|||||||
Reference in New Issue
Block a user