Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions build-data/paper.at
Original file line number Diff line number Diff line change
Expand Up @@ -625,6 +625,10 @@ public net.minecraft.world.level.dimension.end.EnderDragonFight spawnNewGateway(
public net.minecraft.world.level.entity.PersistentEntitySectionManager ensureChunkQueuedForLoad(J)V
public net.minecraft.world.level.entity.PersistentEntitySectionManager permanentStorage
public net.minecraft.world.level.gamerules.GameRules rules
public net.minecraft.world.level.levelgen.blockpredicates.CombiningPredicate predicates
public net.minecraft.world.level.levelgen.blockpredicates.MatchingBlocksPredicate blocks
public net.minecraft.world.level.levelgen.blockpredicates.MatchingFluidsPredicate fluids
public net.minecraft.world.level.levelgen.blockpredicates.StateTestingPredicate offset
public net.minecraft.world.level.levelgen.material.MaterialRuleContext context
public net.minecraft.world.level.levelgen.structure.StructurePiece SHAPE_CHECK_BLOCKS
public net.minecraft.world.level.levelgen.structure.placement.AbstractSpreadingStructurePlacement exclusionZone
Expand Down
2 changes: 2 additions & 0 deletions paper-api/.checkstyle/ignored_directories.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ paper-api/src/main/java/io/papermc/paper/block/
paper-api/src/main/java/io/papermc/paper/block/bed/
paper-api/src/main/java/io/papermc/paper/block/fluid/
paper-api/src/main/java/io/papermc/paper/block/fluid/type/
paper-api/src/main/java/io/papermc/paper/block/stateprovider/
paper-api/src/main/java/io/papermc/paper/brigadier/
paper-api/src/main/java/io/papermc/paper/chat/
paper-api/src/main/java/io/papermc/paper/command/
Expand All @@ -47,6 +48,7 @@ paper-api/src/main/java/io/papermc/paper/datacomponent/item/
paper-api/src/main/java/io/papermc/paper/datacomponent/item/attribute/
paper-api/src/main/java/io/papermc/paper/datacomponent/item/blocksattacks/
paper-api/src/main/java/io/papermc/paper/datacomponent/item/consumable/
paper-api/src/main/java/io/papermc/paper/datacomponent/item/blocktransformer/
paper-api/src/main/java/io/papermc/paper/datapack/
paper-api/src/main/java/io/papermc/paper/dialog/
paper-api/src/main/java/io/papermc/paper/enchantments/
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package io.papermc.paper.registry.keys;

import static net.kyori.adventure.key.Key.key;

import io.papermc.paper.annotation.GeneratedClass;
import io.papermc.paper.datacomponent.item.blocktransformer.BlockTransformer;
import io.papermc.paper.registry.RegistryKey;
import io.papermc.paper.registry.TypedKey;
import net.kyori.adventure.key.Key;
import org.jspecify.annotations.NullMarked;

/**
* Vanilla keys for {@link RegistryKey#BLOCK_TRANSFORMER}.
*
* @apiNote The fields provided here are a direct representation of
* what is available from the vanilla game source. They may be
* changed (including removals) on any Minecraft version
* bump, so cross-version compatibility is not provided on the
* same level as it is on most of the other API.
*/
@SuppressWarnings({
"unused",
"SpellCheckingInspection"
})
@NullMarked
@GeneratedClass
public final class BlockTransformerKeys {
/**
* {@code minecraft:axe}
*
* @apiNote This field is version-dependant and may be removed in future Minecraft versions
*/
public static final TypedKey<BlockTransformer> AXE = create(key("axe"));

/**
* {@code minecraft:hoe}
*
* @apiNote This field is version-dependant and may be removed in future Minecraft versions
*/
public static final TypedKey<BlockTransformer> HOE = create(key("hoe"));

/**
* {@code minecraft:shovel}
*
* @apiNote This field is version-dependant and may be removed in future Minecraft versions
*/
public static final TypedKey<BlockTransformer> SHOVEL = create(key("shovel"));

private BlockTransformerKeys() {
}

/**
* Creates a typed key for {@link BlockTransformer} in the registry {@code minecraft:block_transformer}.
*
* @param key the value's key in the registry
* @return a new typed key
*/
public static TypedKey<BlockTransformer> create(final Key key) {
return TypedKey.create(RegistryKey.BLOCK_TRANSFORMER, key);
}
}
Original file line number Diff line number Diff line change
@@ -1,24 +1,66 @@
package io.papermc.paper.block;

import io.papermc.paper.annotation.MinecraftVersionDependent;
import io.papermc.paper.registry.set.RegistryKeySet;
import java.util.List;
import org.bukkit.block.BlockFace;
import org.bukkit.block.BlockType;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.Contract;
import org.jspecify.annotations.NullMarked;
import org.jspecify.annotations.Nullable;

@NullMarked
@MinecraftVersionDependent
@ApiStatus.NonExtendable
public interface BlockPredicate {

static Builder predicate() {
@Contract(value = "_ -> new", pure = true)
static MatchesBlocks matchesBlocks(final @Nullable RegistryKeySet<BlockType> blocks) {
return predicate().blocks(blocks).build();
}

@Contract(value = "_, _ -> new", pure = true)
static MatchesDirection matchesDirection(final BlockFace direction, final @Nullable RegistryKeySet<BlockType> blocks) {
record MatchesDirectionPredicateImpl(@Nullable RegistryKeySet<BlockType> blocks, @Nullable BlockFace direction)
implements MatchesDirection {
}
return new MatchesDirectionPredicateImpl(blocks, direction);
}

@Contract(value = "_ -> new", pure = true)
static AnyOf anyOf(final List<BlockPredicate> predicates) {
return () -> List.copyOf(predicates);
}

@Contract(value = "_ -> new", pure = true)
static AnyOf anyOf(final BlockPredicate... predicates) {
return anyOf(List.of(predicates));
}

@Contract(value = "_ -> new", pure = true)
static AllOf allOf(final List<BlockPredicate> predicates) {
return () -> List.copyOf(predicates);
}

@Contract(value = "_ -> new", pure = true)
static AllOf allOf(final BlockPredicate... predicates) {
return allOf(List.of(predicates));
}

static DirectionalBuilder predicate() {
//<editor-fold desc="implementations" defaultstate="collapsed">
record BlockPredicateImpl(@Nullable RegistryKeySet<BlockType> blocks) implements BlockPredicate {
record MatchesBlocksPredicateImpl(@Nullable RegistryKeySet<BlockType> blocks) implements MatchesBlocks {
}

record MatchesDirectionPredicateImpl(@Nullable RegistryKeySet<BlockType> blocks, @Nullable BlockFace direction)
implements MatchesDirection {
}

class BuilderImpl implements Builder {
class BuilderImpl implements DirectionalBuilder {

private @Nullable RegistryKeySet<BlockType> blocks;
private @Nullable BlockFace direction;

@Override
public Builder blocks(final @Nullable RegistryKeySet<BlockType> blocks) {
Expand All @@ -27,22 +69,62 @@ public Builder blocks(final @Nullable RegistryKeySet<BlockType> blocks) {
}

@Override
public BlockPredicate build() {
return new BlockPredicateImpl(this.blocks);
public DirectionalBuilder direction(final @Nullable BlockFace direction) {
this.direction = direction;
return this;
}

@Override
public MatchesBlocks build() {
return this.direction == null
? new MatchesBlocksPredicateImpl(this.blocks)
: new MatchesDirectionPredicateImpl(this.blocks, this.direction);
}
}
//</editor-fold>
return new BuilderImpl();
}

@Nullable RegistryKeySet<BlockType> blocks();
@ApiStatus.NonExtendable
interface MatchesBlocks extends BlockPredicate {

@Nullable RegistryKeySet<BlockType> blocks();
}

@ApiStatus.NonExtendable
interface MatchesDirection extends MatchesBlocks {

@Override
@Nullable RegistryKeySet<BlockType> blocks();

@Nullable BlockFace direction();
}

@ApiStatus.NonExtendable
interface DirectionalBuilder extends Builder {

@Contract(value = "_ -> this", mutates = "this")
DirectionalBuilder direction(@Nullable BlockFace direction);
}

@ApiStatus.NonExtendable
interface Builder {

@Contract(value = "_ -> this", mutates = "this")
Builder blocks(@Nullable RegistryKeySet<BlockType> blocks);

BlockPredicate build();
MatchesBlocks build();
}

@ApiStatus.NonExtendable
interface AnyOf extends BlockPredicate {

List<BlockPredicate> predicates();
}

@ApiStatus.NonExtendable
interface AllOf extends BlockPredicate {

List<BlockPredicate> predicates();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package io.papermc.paper.block.fluid;

import io.papermc.paper.annotation.MinecraftVersionDependent;
import io.papermc.paper.block.BlockPredicate;
import io.papermc.paper.registry.set.RegistryKeySet;
import org.bukkit.Fluid;
import org.bukkit.block.BlockFace;
import org.jetbrains.annotations.ApiStatus;
import org.jspecify.annotations.NullMarked;

@NullMarked
@MinecraftVersionDependent
@ApiStatus.NonExtendable
public interface FluidPredicate extends BlockPredicate {

static MatchesBlocks matchesFluids(final RegistryKeySet<Fluid> fluids) {
record MatchesBlocksPredicateImpl(RegistryKeySet<Fluid> fluids) implements MatchesBlocks {
}
return new MatchesBlocksPredicateImpl(fluids);
}

static MatchesDirection matchesDirection(final BlockFace direction, final RegistryKeySet<Fluid> fluids) {
record MatchesDirectionPredicateImpl(RegistryKeySet<Fluid> fluids, BlockFace direction)
implements MatchesDirection {
}
return new MatchesDirectionPredicateImpl(fluids, direction);
}

@ApiStatus.NonExtendable
interface MatchesBlocks extends FluidPredicate {

RegistryKeySet<Fluid> fluids();
}

@ApiStatus.NonExtendable
interface MatchesDirection extends MatchesBlocks {

BlockFace direction();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
package io.papermc.paper.block.stateprovider;

import io.papermc.paper.block.BlockPredicate;
import io.papermc.paper.registry.set.RegistryKeySet;
import java.util.List;
import org.bukkit.block.BlockFace;
import org.bukkit.block.BlockType;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.Contract;
import org.jetbrains.annotations.Unmodifiable;
import org.jspecify.annotations.Nullable;

@ApiStatus.NonExtendable
public interface BlockStateProvider {

/**
* Creates a simple provider that always returns the default state of the given block type.
*
* @param blockType block type to provide
* @return a simple block state provider
*/
@Contract(value = "_ -> new", pure = true)
static SimpleBlockStateProvider simple(final BlockType blockType) {
//<editor-fold desc="implementations" defaultstate="collapsed">
record SimpleProviderImpl(BlockType blockType) implements SimpleBlockStateProvider {
}
//</editor-fold>
return new SimpleProviderImpl(blockType);
}

/**
* Creates a provider that copies properties from the current block into the given target block type.
*
* @param blockType target block type
* @return a copy-properties block state provider
*/
@Contract(value = "_ -> new", pure = true)
static CopyPropertiesBlockStateProvider copyPropertiesFrom(final BlockType blockType) {
//<editor-fold desc="implementations" defaultstate="collapsed">
record CopyPropertiesProviderImpl(BlockType blockType) implements CopyPropertiesBlockStateProvider {
}
//</editor-fold>
return new CopyPropertiesProviderImpl(blockType);
}

/**
* Creates a provider that chooses a random block from the provided set.
*
* @param blocks candidate blocks
* @return a random block state provider
*/
@Contract(value = "_ -> new", pure = true)
static RandomBlockStateProvider randomBlock(final RegistryKeySet<BlockType> blocks) {
//<editor-fold desc="implementations" defaultstate="collapsed">
record RandomBlockProviderImpl(RegistryKeySet<BlockType> blocks) implements RandomBlockStateProvider {
}
//</editor-fold>
return new RandomBlockProviderImpl(blocks);
}

/**
* Creates a provider that applies a random rotation to the output of another provider.
*
* @param stateProvider source provider
* @return a rotated block state provider
*/
@Contract(value = "_ -> new", pure = true)
static RotatedBlockStateProvider rotated(final BlockStateProvider stateProvider) {
return rotated(stateProvider, null);
}

/**
* Creates a provider that rotates the output of another provider with an optional forced direction.
*
* @param stateProvider source provider
* @param direction direction to force, or null for random direction
* @return a rotated block state provider
*/
@Contract(value = "_, _ -> new", pure = true)
static RotatedBlockStateProvider rotated(final BlockStateProvider stateProvider, final @Nullable BlockFace direction) {
//<editor-fold desc="implementations" defaultstate="collapsed">
record RotatedBlockProviderImpl(BlockStateProvider stateProvider, @Nullable BlockFace direction) implements RotatedBlockStateProvider {
}
//</editor-fold>
return new RotatedBlockProviderImpl(stateProvider, direction);
}

/**
* Creates a rule-based provider using the given rules and no fallback provider.
*
* @param rules rule list
* @return a rule-based block state provider
*/
@Contract(value = "_ -> new", pure = true)
static RuleBasedBlockStateProvider ruleBased(final List<RuleBasedBlockStateProvider.Rule> rules) {
return ruleBased(null, rules);
}

/**
* Creates a rule-based provider using the given fallback and rules.
*
* @param fallback fallback provider when no rule matches
* @param rules rule list
* @return a rule-based block state provider
*/
@Contract(value = "_, _ -> new", pure = true)
static RuleBasedBlockStateProvider ruleBased(final @Nullable BlockStateProvider fallback, final List<RuleBasedBlockStateProvider.Rule> rules) {
//<editor-fold desc="implementations" defaultstate="collapsed">
record RuleBasedProviderImpl(@Nullable BlockStateProvider fallback, @Unmodifiable List<RuleBasedBlockStateProvider.Rule> rules)
implements RuleBasedBlockStateProvider {
RuleBasedProviderImpl {
rules = List.copyOf(rules);
}
}
//</editor-fold>
return new RuleBasedProviderImpl(fallback, rules);
}

/**
* Creates a rule used by {@link #ruleBased(List)} and {@link #ruleBased(BlockStateProvider, List)}.
*
* @param ifTrue predicate that must match
* @param thenProvide provider to use when the predicate matches
* @return an immutable rule
*/
@Contract(value = "_, _ -> new", pure = true)
static RuleBasedBlockStateProvider.Rule rule(final BlockPredicate ifTrue, final BlockStateProvider thenProvide) {
return new RuleBasedBlockStateProvider.Rule(ifTrue, thenProvide);
}
}
Loading
Loading