Skip to content

Commit

Permalink
feat: basic function of leaves
Browse files Browse the repository at this point in the history
  • Loading branch information
smartcmd committed Jul 9, 2024
1 parent 4dbba1b commit daf6e37
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 67 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package org.allaymc.server.block.component.leaves;

import org.allaymc.api.block.BlockBehavior;
import org.allaymc.api.block.data.BlockStateWithPos;
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;

/**
* Allay Project 2024/7/10
*
* @author daoge_cmd
*/
public class BlockLeavesBaseComponentImpl extends BlockBaseComponentImpl {

public BlockLeavesBaseComponentImpl(BlockType<? extends BlockBehavior> blockType) {
super(blockType);
}

@Override
public ItemStack[] getDrops(BlockStateWithPos blockState, ItemStack usedItem) {
if (usedItem.getItemType() == ItemTypes.SHEARS_TYPE) {
return new ItemStack[]{blockState.blockState().toItemStack()};
}
// TODO: Drop saplings
// https://minecraft.fandom.com/zh/wiki/%E6%A0%91%E5%8F%B6#%E8%8E%B7%E5%8F%96
return Utils.EMPTY_ITEM_STACK_ARRAY;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import lombok.experimental.UtilityClass;
import org.allaymc.api.block.interfaces.*;
import org.allaymc.api.block.interfaces.glass.BlockGlassBehavior;
import org.allaymc.api.block.interfaces.leaves.*;
import org.allaymc.api.block.interfaces.shulkerbox.*;
import org.allaymc.api.block.interfaces.stairs.*;
import org.allaymc.api.block.interfaces.torch.*;
Expand All @@ -21,6 +22,7 @@
import org.allaymc.server.block.component.craftingtable.BlockCraftingTableBaseComponentImpl;
import org.allaymc.server.block.component.glass.BlockGlassBaseComponentImpl;
import org.allaymc.server.block.component.grassblock.BlockGrassBlockBaseComponentImpl;
import org.allaymc.server.block.component.leaves.BlockLeavesBaseComponentImpl;
import org.allaymc.server.block.component.sand.BlockSandBaseComponentImpl;
import org.allaymc.server.block.component.shulkerbox.BlockShulkerBoxBaseComponentImpl;
import org.allaymc.server.block.component.stairs.BlockStairsBaseComponentImpl;
Expand All @@ -35,6 +37,63 @@
@SuppressWarnings("unused")
@UtilityClass
public final class BlockTypeInitializer {
public static void initLeaves() {
BlockTypes.ACACIA_LEAVES_TYPE = BlockTypeBuilder
.builder(BlockAcaciaLeavesBehavior.class)
.vanillaBlock(VanillaBlockId.ACACIA_LEAVES)
.setProperties(VanillaBlockPropertyTypes.PERSISTENT_BIT, VanillaBlockPropertyTypes.UPDATE_BIT)
.setBlockBaseComponentSupplier(BlockLeavesBaseComponentImpl::new)
.build();
BlockTypes.AZALEA_LEAVES_TYPE = BlockTypeBuilder
.builder(BlockAzaleaLeavesBehavior.class)
.vanillaBlock(VanillaBlockId.AZALEA_LEAVES)
.setProperties(VanillaBlockPropertyTypes.PERSISTENT_BIT, VanillaBlockPropertyTypes.UPDATE_BIT)
.setBlockBaseComponentSupplier(BlockLeavesBaseComponentImpl::new)
.build();
BlockTypes.BIRCH_LEAVES_TYPE = BlockTypeBuilder
.builder(BlockBirchLeavesBehavior.class)
.vanillaBlock(VanillaBlockId.BIRCH_LEAVES)
.setProperties(VanillaBlockPropertyTypes.PERSISTENT_BIT, VanillaBlockPropertyTypes.UPDATE_BIT)
.setBlockBaseComponentSupplier(BlockLeavesBaseComponentImpl::new)
.build();
BlockTypes.CHERRY_LEAVES_TYPE = BlockTypeBuilder
.builder(BlockCherryLeavesBehavior.class)
.vanillaBlock(VanillaBlockId.CHERRY_LEAVES)
.setProperties(VanillaBlockPropertyTypes.PERSISTENT_BIT, VanillaBlockPropertyTypes.UPDATE_BIT)
.setBlockBaseComponentSupplier(BlockLeavesBaseComponentImpl::new)
.build();
BlockTypes.DARK_OAK_LEAVES_TYPE = BlockTypeBuilder
.builder(BlockDarkOakLeavesBehavior.class)
.vanillaBlock(VanillaBlockId.DARK_OAK_LEAVES)
.setProperties(VanillaBlockPropertyTypes.PERSISTENT_BIT, VanillaBlockPropertyTypes.UPDATE_BIT)
.setBlockBaseComponentSupplier(BlockLeavesBaseComponentImpl::new)
.build();
BlockTypes.JUNGLE_LEAVES_TYPE = BlockTypeBuilder
.builder(BlockJungleLeavesBehavior.class)
.vanillaBlock(VanillaBlockId.JUNGLE_LEAVES)
.setProperties(VanillaBlockPropertyTypes.PERSISTENT_BIT, VanillaBlockPropertyTypes.UPDATE_BIT)
.setBlockBaseComponentSupplier(BlockLeavesBaseComponentImpl::new)
.build();
BlockTypes.MANGROVE_LEAVES_TYPE = BlockTypeBuilder
.builder(BlockMangroveLeavesBehavior.class)
.vanillaBlock(VanillaBlockId.MANGROVE_LEAVES)
.setProperties(VanillaBlockPropertyTypes.PERSISTENT_BIT, VanillaBlockPropertyTypes.UPDATE_BIT)
.setBlockBaseComponentSupplier(BlockLeavesBaseComponentImpl::new)
.build();
BlockTypes.OAK_LEAVES_TYPE = BlockTypeBuilder
.builder(BlockOakLeavesBehavior.class)
.vanillaBlock(VanillaBlockId.OAK_LEAVES)
.setProperties(VanillaBlockPropertyTypes.PERSISTENT_BIT, VanillaBlockPropertyTypes.UPDATE_BIT)
.setBlockBaseComponentSupplier(BlockLeavesBaseComponentImpl::new)
.build();
BlockTypes.SPRUCE_LEAVES_TYPE = BlockTypeBuilder
.builder(BlockSpruceLeavesBehavior.class)
.vanillaBlock(VanillaBlockId.SPRUCE_LEAVES)
.setProperties(VanillaBlockPropertyTypes.PERSISTENT_BIT, VanillaBlockPropertyTypes.UPDATE_BIT)
.setBlockBaseComponentSupplier(BlockLeavesBaseComponentImpl::new)
.build();
}

public static void initGravel() {
BlockTypes.GRAVEL_TYPE = BlockTypeBuilder
.builder(BlockGravelBehavior.class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import org.allaymc.api.item.interfaces.egg.*;
import org.allaymc.api.item.interfaces.helmet.*;
import org.allaymc.api.item.interfaces.hoe.*;
import org.allaymc.api.item.interfaces.leaves.ItemAcaciaLeavesStack;
import org.allaymc.api.item.interfaces.leggings.*;
import org.allaymc.api.item.interfaces.pickaxe.*;
import org.allaymc.api.item.interfaces.shovel.*;
Expand Down Expand Up @@ -1124,199 +1125,137 @@ public static void initAir() {
.build();
}

public static void initChainmailHelmet() {
public static void initHelmets() {
ItemTypes.CHAINMAIL_HELMET_TYPE = ItemTypeBuilder
.builder(ItemChainmailHelmetStack.class)
.vanillaItem(VanillaItemId.CHAINMAIL_HELMET)
.addComponent(ItemArmorBaseComponentImpl::new, ItemArmorBaseComponentImpl.class)
.build();
}

public static void initDiamondHelmet() {
ItemTypes.DIAMOND_HELMET_TYPE = ItemTypeBuilder
.builder(ItemDiamondHelmetStack.class)
.vanillaItem(VanillaItemId.DIAMOND_HELMET)
.addComponent(ItemArmorBaseComponentImpl::new, ItemArmorBaseComponentImpl.class)
.build();
}

public static void initGoldenHelmet() {
ItemTypes.GOLDEN_HELMET_TYPE = ItemTypeBuilder
.builder(ItemGoldenHelmetStack.class)
.vanillaItem(VanillaItemId.GOLDEN_HELMET)
.addComponent(ItemArmorBaseComponentImpl::new, ItemArmorBaseComponentImpl.class)
.build();
}

public static void initIronHelmet() {
ItemTypes.IRON_HELMET_TYPE = ItemTypeBuilder
.builder(ItemIronHelmetStack.class)
.vanillaItem(VanillaItemId.IRON_HELMET)
.addComponent(ItemArmorBaseComponentImpl::new, ItemArmorBaseComponentImpl.class)
.build();
}

public static void initLeatherHelmet() {
ItemTypes.LEATHER_HELMET_TYPE = ItemTypeBuilder
.builder(ItemLeatherHelmetStack.class)
.vanillaItem(VanillaItemId.LEATHER_HELMET)
.addComponent(ItemArmorBaseComponentImpl::new, ItemArmorBaseComponentImpl.class)
.build();
}

public static void initNetheriteHelmet() {
ItemTypes.NETHERITE_HELMET_TYPE = ItemTypeBuilder
.builder(ItemNetheriteHelmetStack.class)
.vanillaItem(VanillaItemId.NETHERITE_HELMET)
.addComponent(ItemArmorBaseComponentImpl::new, ItemArmorBaseComponentImpl.class)
.build();
}

public static void initTurtleHelmet() {
ItemTypes.TURTLE_HELMET_TYPE = ItemTypeBuilder
.builder(ItemTurtleHelmetStack.class)
.vanillaItem(VanillaItemId.TURTLE_HELMET)
.addComponent(ItemArmorBaseComponentImpl::new, ItemArmorBaseComponentImpl.class)
.build();
}

public static void initChainmailChestplate() {

public static void initChestplates() {
ItemTypes.CHAINMAIL_CHESTPLATE_TYPE = ItemTypeBuilder
.builder(ItemChainmailChestplateStack.class)
.vanillaItem(VanillaItemId.CHAINMAIL_CHESTPLATE)
.addComponent(ItemArmorBaseComponentImpl::new, ItemArmorBaseComponentImpl.class)
.build();
}

public static void initDiamondChestplate() {
ItemTypes.DIAMOND_CHESTPLATE_TYPE = ItemTypeBuilder
.builder(ItemDiamondChestplateStack.class)
.vanillaItem(VanillaItemId.DIAMOND_CHESTPLATE)
.addComponent(ItemArmorBaseComponentImpl::new, ItemArmorBaseComponentImpl.class)
.build();
}

public static void initGoldenChestplate() {
ItemTypes.GOLDEN_CHESTPLATE_TYPE = ItemTypeBuilder
.builder(ItemGoldenChestplateStack.class)
.vanillaItem(VanillaItemId.GOLDEN_CHESTPLATE)
.addComponent(ItemArmorBaseComponentImpl::new, ItemArmorBaseComponentImpl.class)
.build();
}

public static void initIronChestplate() {
ItemTypes.IRON_CHESTPLATE_TYPE = ItemTypeBuilder
.builder(ItemIronChestplateStack.class)
.vanillaItem(VanillaItemId.IRON_CHESTPLATE)
.addComponent(ItemArmorBaseComponentImpl::new, ItemArmorBaseComponentImpl.class)
.build();
}

public static void initLeatherChestplate() {
ItemTypes.LEATHER_CHESTPLATE_TYPE = ItemTypeBuilder
.builder(ItemLeatherChestplateStack.class)
.vanillaItem(VanillaItemId.LEATHER_CHESTPLATE)
.addComponent(ItemArmorBaseComponentImpl::new, ItemArmorBaseComponentImpl.class)
.build();
}

public static void initNetheriteChestplate() {
ItemTypes.NETHERITE_CHESTPLATE_TYPE = ItemTypeBuilder
.builder(ItemNetheriteChestplateStack.class)
.vanillaItem(VanillaItemId.NETHERITE_CHESTPLATE)
.addComponent(ItemArmorBaseComponentImpl::new, ItemArmorBaseComponentImpl.class)
.build();
}

public static void initChainmailLeggings() {
public static void initLeggings() {
ItemTypes.CHAINMAIL_LEGGINGS_TYPE = ItemTypeBuilder
.builder(ItemChainmailLeggingsStack.class)
.vanillaItem(VanillaItemId.CHAINMAIL_LEGGINGS)
.addComponent(ItemArmorBaseComponentImpl::new, ItemArmorBaseComponentImpl.class)
.build();
}

public static void initDiamondLeggings() {
ItemTypes.DIAMOND_LEGGINGS_TYPE = ItemTypeBuilder
.builder(ItemDiamondLeggingsStack.class)
.vanillaItem(VanillaItemId.DIAMOND_LEGGINGS)
.addComponent(ItemArmorBaseComponentImpl::new, ItemArmorBaseComponentImpl.class)
.build();
}

public static void initGoldenLeggings() {
ItemTypes.GOLDEN_LEGGINGS_TYPE = ItemTypeBuilder
.builder(ItemGoldenLeggingsStack.class)
.vanillaItem(VanillaItemId.GOLDEN_LEGGINGS)
.addComponent(ItemArmorBaseComponentImpl::new, ItemArmorBaseComponentImpl.class)
.build();
}

public static void initIronLeggings() {
ItemTypes.IRON_LEGGINGS_TYPE = ItemTypeBuilder
.builder(ItemIronLeggingsStack.class)
.vanillaItem(VanillaItemId.IRON_LEGGINGS)
.addComponent(ItemArmorBaseComponentImpl::new, ItemArmorBaseComponentImpl.class)
.build();
}

public static void initLeatherLeggings() {
ItemTypes.LEATHER_LEGGINGS_TYPE = ItemTypeBuilder
.builder(ItemLeatherLeggingsStack.class)
.vanillaItem(VanillaItemId.LEATHER_LEGGINGS)
.addComponent(ItemArmorBaseComponentImpl::new, ItemArmorBaseComponentImpl.class)
.build();
}

public static void initNetheriteLeggings() {
ItemTypes.NETHERITE_LEGGINGS_TYPE = ItemTypeBuilder
.builder(ItemNetheriteLeggingsStack.class)
.vanillaItem(VanillaItemId.NETHERITE_LEGGINGS)
.addComponent(ItemArmorBaseComponentImpl::new, ItemArmorBaseComponentImpl.class)
.build();
}

public static void initChainmailBoots() {
public static void initBoots() {
ItemTypes.CHAINMAIL_BOOTS_TYPE = ItemTypeBuilder
.builder(ItemChainmailBootsStack.class)
.vanillaItem(VanillaItemId.CHAINMAIL_BOOTS)
.addComponent(ItemArmorBaseComponentImpl::new, ItemArmorBaseComponentImpl.class)
.build();
}

public static void initDiamondBoots() {
ItemTypes.DIAMOND_BOOTS_TYPE = ItemTypeBuilder
.builder(ItemDiamondBootsStack.class)
.vanillaItem(VanillaItemId.DIAMOND_BOOTS)
.addComponent(ItemArmorBaseComponentImpl::new, ItemArmorBaseComponentImpl.class)
.build();
}

public static void initGoldenBoots() {
ItemTypes.GOLDEN_BOOTS_TYPE = ItemTypeBuilder
.builder(ItemGoldenBootsStack.class)
.vanillaItem(VanillaItemId.GOLDEN_BOOTS)
.addComponent(ItemArmorBaseComponentImpl::new, ItemArmorBaseComponentImpl.class)
.build();
}

public static void initIronBoots() {
ItemTypes.IRON_BOOTS_TYPE = ItemTypeBuilder
.builder(ItemIronBootsStack.class)
.vanillaItem(VanillaItemId.IRON_BOOTS)
.addComponent(ItemArmorBaseComponentImpl::new, ItemArmorBaseComponentImpl.class)
.build();
}

public static void initLeatherBoots() {
ItemTypes.LEATHER_BOOTS_TYPE = ItemTypeBuilder
.builder(ItemLeatherBootsStack.class)
.vanillaItem(VanillaItemId.LEATHER_BOOTS)
.addComponent(ItemArmorBaseComponentImpl::new, ItemArmorBaseComponentImpl.class)
.build();
}

public static void initNetheriteBoots() {
ItemTypes.NETHERITE_BOOTS_TYPE = ItemTypeBuilder
.builder(ItemNetheriteBootsStack.class)
.vanillaItem(VanillaItemId.NETHERITE_BOOTS)
Expand Down

0 comments on commit daf6e37

Please sign in to comment.