-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: implement wheat seed drops & dirt drop
- Loading branch information
Showing
8 changed files
with
144 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
...ava/org/allaymc/server/block/component/doubleplant/BlockDoublePlantBaseComponentImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package org.allaymc.server.block.component.doubleplant; | ||
|
||
import org.allaymc.api.block.BlockBehavior; | ||
import org.allaymc.api.block.component.annotation.RequireBlockProperty; | ||
import org.allaymc.api.block.property.type.BlockPropertyType; | ||
import org.allaymc.api.block.type.BlockState; | ||
import org.allaymc.api.block.type.BlockType; | ||
import org.allaymc.api.data.VanillaBlockPropertyTypes; | ||
import org.allaymc.api.item.ItemStack; | ||
import org.allaymc.api.item.type.ItemTypes; | ||
import org.allaymc.api.utils.Utils; | ||
import org.allaymc.server.block.component.common.BlockBaseComponentImpl; | ||
|
||
import java.util.concurrent.ThreadLocalRandom; | ||
|
||
/** | ||
* Allay Project 2024/6/15 | ||
* | ||
* @author daoge_cmd | ||
*/ | ||
@RequireBlockProperty(type = BlockPropertyType.Type.ENUM, name = "double_plant_type") | ||
@RequireBlockProperty(type = BlockPropertyType.Type.BOOLEAN, name = "upper_block_bit") | ||
public class BlockDoublePlantBaseComponentImpl extends BlockBaseComponentImpl { | ||
public BlockDoublePlantBaseComponentImpl(BlockType<? extends BlockBehavior> blockType) { | ||
super(blockType); | ||
} | ||
|
||
// TODO: block update | ||
|
||
@Override | ||
public ItemStack[] getDrops(BlockState blockState, ItemStack usedItem) { | ||
var plantType = blockState.getPropertyValue(VanillaBlockPropertyTypes.DOUBLE_PLANT_TYPE); | ||
return switch (plantType) { | ||
case FERN, GRASS -> { | ||
var rand = ThreadLocalRandom.current(); | ||
if (rand.nextInt(8) == 0) { | ||
yield new ItemStack[]{ItemTypes.WHEAT_SEEDS_TYPE.createItemStack()}; | ||
} | ||
yield Utils.EMPTY_ITEM_STACK_ARRAY; | ||
} | ||
default -> super.getDrops(blockState, usedItem); | ||
}; | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
.../java/org/allaymc/server/block/component/grassblock/BlockGrassBlockBaseComponentImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package org.allaymc.server.block.component.grassblock; | ||
|
||
import org.allaymc.api.block.BlockBehavior; | ||
import org.allaymc.api.block.type.BlockState; | ||
import org.allaymc.api.block.type.BlockType; | ||
import org.allaymc.api.item.ItemStack; | ||
import org.allaymc.api.item.type.ItemTypes; | ||
import org.allaymc.server.block.component.common.BlockBaseComponentImpl; | ||
|
||
/** | ||
* Allay Project 2024/6/15 | ||
* | ||
* @author daoge_cmd | ||
*/ | ||
public class BlockGrassBlockBaseComponentImpl extends BlockBaseComponentImpl { | ||
public BlockGrassBlockBaseComponentImpl(BlockType<? extends BlockBehavior> blockType) { | ||
super(blockType); | ||
} | ||
|
||
@Override | ||
public ItemStack[] getDrops(BlockState blockState, ItemStack usedItem) { | ||
return new ItemStack[]{ItemTypes.DIRT_TYPE.createItemStack()}; | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
...in/java/org/allaymc/server/block/component/tallgrass/BlockTallgrassBaseComponentImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package org.allaymc.server.block.component.tallgrass; | ||
|
||
import org.allaymc.api.block.BlockBehavior; | ||
import org.allaymc.api.block.type.BlockState; | ||
import org.allaymc.api.block.type.BlockType; | ||
import org.allaymc.api.item.ItemStack; | ||
import org.allaymc.api.item.type.ItemTypes; | ||
import org.allaymc.api.utils.Utils; | ||
import org.allaymc.server.block.component.common.BlockBaseComponentImpl; | ||
|
||
import java.util.concurrent.ThreadLocalRandom; | ||
|
||
/** | ||
* Allay Project 2024/6/15 | ||
* | ||
* @author daoge_cmd | ||
*/ | ||
public class BlockTallgrassBaseComponentImpl extends BlockBaseComponentImpl { | ||
public BlockTallgrassBaseComponentImpl(BlockType<? extends BlockBehavior> blockType) { | ||
super(blockType); | ||
} | ||
|
||
@Override | ||
public ItemStack[] getDrops(BlockState blockState, ItemStack usedItem) { | ||
var rand = ThreadLocalRandom.current(); | ||
// 有1/8的几率掉落种子 | ||
if (rand.nextInt(8) == 0) { | ||
return new ItemStack[]{ItemTypes.WHEAT_SEEDS_TYPE.createItemStack()}; | ||
} | ||
return Utils.EMPTY_ITEM_STACK_ARRAY; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters