mirror of
https://github.com/p2r3/bareiron.git
synced 2025-10-02 07:35:08 +02:00
improve block placement checks
This commit is contained in:
@@ -523,8 +523,13 @@ int cs_useItemOn (int client_fd) {
|
|||||||
|
|
||||||
// check if the block's placement conditions are met
|
// check if the block's placement conditions are met
|
||||||
if (
|
if (
|
||||||
!(x == player->x && (y == player->y || y == player->y + 1) && z == player->z) &&
|
!( // player is not in the way
|
||||||
(getBlockAt(x, y, z) == B_air) &&
|
!isPassableBlock(block) &&
|
||||||
|
x == player->x &&
|
||||||
|
(y == player->y || y == player->y + 1) &&
|
||||||
|
z == player->z
|
||||||
|
) &&
|
||||||
|
isReplaceableBlock(getBlockAt(x, y, z)) &&
|
||||||
(!isColumnBlock(block) || getBlockAt(x, y - 1, z) != B_air)
|
(!isColumnBlock(block) || getBlockAt(x, y - 1, z) != B_air)
|
||||||
) {
|
) {
|
||||||
// decrease item amount in selected slot
|
// decrease item amount in selected slot
|
||||||
|
@@ -435,7 +435,6 @@ uint8_t isInstantlyMined (PlayerData *player, uint8_t block) {
|
|||||||
|
|
||||||
// Checks whether the given block has to have something beneath it
|
// Checks whether the given block has to have something beneath it
|
||||||
uint8_t isColumnBlock (uint8_t block) {
|
uint8_t isColumnBlock (uint8_t block) {
|
||||||
|
|
||||||
return (
|
return (
|
||||||
block == B_snow ||
|
block == B_snow ||
|
||||||
block == B_moss_carpet ||
|
block == B_moss_carpet ||
|
||||||
@@ -445,20 +444,29 @@ uint8_t isColumnBlock (uint8_t block) {
|
|||||||
block == B_sand ||
|
block == B_sand ||
|
||||||
block == B_torch
|
block == B_torch
|
||||||
);
|
);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Checks whether the given block is non-solid
|
||||||
uint8_t isPassableBlock (uint8_t block) {
|
uint8_t isPassableBlock (uint8_t block) {
|
||||||
|
|
||||||
return (
|
return (
|
||||||
block == B_air ||
|
block == B_air ||
|
||||||
block == B_water ||
|
block == B_water ||
|
||||||
|
block == B_snow ||
|
||||||
block == B_moss_carpet ||
|
block == B_moss_carpet ||
|
||||||
block == B_short_grass ||
|
block == B_short_grass ||
|
||||||
block == B_dead_bush ||
|
block == B_dead_bush ||
|
||||||
block == B_torch
|
block == B_torch
|
||||||
);
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Checks whether the given block can be replaced by another block
|
||||||
|
uint8_t isReplaceableBlock (uint8_t block) {
|
||||||
|
return (
|
||||||
|
block == B_air ||
|
||||||
|
block == B_water ||
|
||||||
|
block == B_short_grass ||
|
||||||
|
block == B_snow
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
void handlePlayerAction (PlayerData *player, int action, short x, short y, short z) {
|
void handlePlayerAction (PlayerData *player, int action, short x, short y, short z) {
|
||||||
|
Reference in New Issue
Block a user