Skip to content

Commit

Permalink
feat: implement slab (#540)
Browse files Browse the repository at this point in the history
  • Loading branch information
smartcmd authored Jan 13, 2025
1 parent a4a96a1 commit 792255c
Show file tree
Hide file tree
Showing 22 changed files with 653 additions and 559 deletions.
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,12 @@ Unless otherwise specified, any version comparison below is the comparison of se
- (API) Added `BlockGrowEvent` which will be called when crops grow.
- (API) Added two overloads `LightService#getInternalLight(Vector3ic)` and `LightService#getSkyLight(Vector3ic)`, they
have the same functionality as `LightService#getXXXLight(int, int, int)`.
- (API) Implemented beacon block, and several related interfaces are added to api module.
- (API) `BlockContainer#getBlockPos` and `BlockContainer#setBlockPos` now return/require `Position3ic` instead of
`Vector3ic`, this enables us to get the dimension information of a `BlockContainer`.
- (API) Implemented brewing stand, and several related interfaces & objects including `BlockEntityBrewingStand`, `BrewingStandContainer`,
`Registries#POTION_MIX_RECIPES`, `PotionMixRecipe` are added to api module. See commit history for more details.
- (API) Implemented slab, and several related interfaces are added to api module.
- (API) Introduced `BlockBaseComponent#combine` method which is used by slab. For the details of this method, see the javadoc.
- (API) Implemented brewing stand, and several related interfaces & objects including `BlockEntityBrewingStand`,
`BrewingStandContainer`, `Registries#POTION_MIX_RECIPES`, `PotionMixRecipe` are added to api module. See commit
history for more details.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,10 @@ default boolean canRandomUpdate() {
}

/**
* Try to place a block.
* Try to place a block at the specified position and with optional placement info.
* <p>
* When this method is called, the caller ensures that the current block in `placeBlockPos`
* is a block that has REPLACEABLE tag.
*
* @param dimension The dimension where the block is placed.
* @param blockState The block that is being placed.
Expand All @@ -80,6 +83,23 @@ default boolean canRandomUpdate() {
*/
boolean place(Dimension dimension, BlockState blockState, Vector3ic placeBlockPos, PlayerInteractInfo placementInfo);

/**
* Try to combine a block with another block which is already in the dimension and does not have REPLACEABLE tag.
* <p>
* This method is used by slab blocks for example. Two slab blocks can be combined to one double slab blocks.
* In most cases two blocks cannot be combined, so the default implementation just return {@code false}.
*
* @param dimension The dimension where the block is placed.
* @param blockState The block that is going to be combined with another block which is already in the dimension.
* @param combineBlockPos The pos of the block that is being combined with.
* @param placementInfo The player placement info, can be {@code null}.
*
* @return {@code true} if the block is combined successfully, {@code false} if failed.
*/
default boolean combine(Dimension dimension, BlockState blockState, Vector3ic combineBlockPos, PlayerInteractInfo placementInfo) {
return false;
}

/**
* Called when place a block.
* <p>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package org.allaymc.api.block.component;

import org.allaymc.api.block.type.BlockType;

/**
* @author daoge_cmd
*/
public interface BlockDoubleSlabBaseComponent extends BlockBaseComponent {
/**
* Get the single slab block type.
*
* @return the single slab block type.
*/
BlockType<?> getSingleSlabBlockType();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package org.allaymc.api.block.component;

import org.allaymc.api.block.type.BlockType;

/**
* @author daoge_cmd
*/
public interface BlockSlabBaseComponent extends BlockBaseComponent {
/**
* Get the double slab block type.
*
* @return the double slab block type.
*/
BlockType<?> getDoubleSlabBlockType();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package org.allaymc.api.block.interfaces;

import org.allaymc.api.block.component.BlockOxidationComponent;

public interface BlockCopperSlabBehavior extends BlockSlabBehavior, BlockOxidationComponent {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package org.allaymc.api.block.interfaces;

import org.allaymc.api.block.component.BlockOxidationComponent;

public interface BlockDoubleCopperSlabBehavior extends BlockDoubleSlabBehavior, BlockOxidationComponent {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package org.allaymc.api.block.interfaces;

import org.allaymc.api.block.BlockBehavior;
import org.allaymc.api.block.component.BlockDoubleSlabBaseComponent;

public interface BlockDoubleSlabBehavior extends BlockBehavior, BlockDoubleSlabBaseComponent {
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.allaymc.api.block.interfaces;

import org.allaymc.api.block.BlockBehavior;
import org.allaymc.api.block.component.BlockSlabBaseComponent;

public interface BlockSlabBehavior extends BlockBehavior {
public interface BlockSlabBehavior extends BlockBehavior, BlockSlabBaseComponent {
}
Loading

0 comments on commit 792255c

Please sign in to comment.