O
O
OneDeus2022-03-17 11:38:38
Java
OneDeus, 2022-03-17 11:38:38

Is there a way to merge the classes?

Is it possible to somehow combine these classes for more compact code?

public class Farm {

    public static final Block BLUEBERRY_VINE = registerBlockWithoutBlockItem("blueberry_vine",
            new BlueberryVine(FabricBlockSettings.copy(Blocks.SWEET_BERRY_BUSH).nonOpaque()), ItemGroup.GROUPS);

    public static final Block STRAWBERRY_VINE = registerBlockWithoutBlockItem("strawberry_vine",
            new StrawberryVine(FabricBlockSettings.copy(Blocks.SWEET_BERRY_BUSH).nonOpaque()), ItemGroup.GROUPS);

    public static final Block RASPBERRIES_VINE = registerBlockWithoutBlockItem("raspberries_vine",
            new RaspberriesVine(FabricBlockSettings.copy(Blocks.SWEET_BERRY_BUSH).nonOpaque()), ItemGroup.GROUPS);

    private static Block registerBlock(String name, Block block, ItemGroup group) {
        registerBlockItem(name, block, group);
        return Registry.register(Registry.BLOCK, new Identifier(NEVADA.MOD_ID, name), block);
    }

    private static Item registerBlockItem(String name, Block block, ItemGroup group) {
        return Registry.register(Registry.ITEM, new Identifier(NEVADA.MOD_ID, name),
                new BlockItem(block, new FabricItemSettings().group(group)));
    }

    private static Block registerBlockWithoutBlockItem(String name, Block block, ItemGroup[] groups) {
        return Registry.register(Registry.BLOCK, new Identifier(NEVADA.MOD_ID, name), block);
    }

    public static void registerLamps() {
        System.out.println();
    }
}

public class Food {
    public static final Item LOLLIPOP = registerItem("lollipop",
            new Item(new FabricItemSettings().group(ItemGroup.FOOD).food(net.tutorialsbykaupenjoe.tutorialmod.item.custom.FoodComponents.LOLLIPOP)));

    public static final Item CUP_COFFEE = registerItem("cup_coffee",
            new HoneyBottleItem(new FabricItemSettings().group(ItemGroup.FOOD).maxCount(16).food(net.tutorialsbykaupenjoe.tutorialmod.item.custom.FoodComponents.COFFEE_I)));

    public static final Item CUP_FLAT_COFFEE = registerItem("cup_flat_coffee",
            new HoneyBottleItem(new FabricItemSettings().group(ItemGroup.FOOD).maxCount(16).food(net.tutorialsbykaupenjoe.tutorialmod.item.custom.FoodComponents.COFFEE_I)));

    public static final Item CUP_EXPRESSO_COFFEE = registerItem("cup_expresso_coffee",
            new HoneyBottleItem(new FabricItemSettings().group(ItemGroup.FOOD).maxCount(16).food(net.tutorialsbykaupenjoe.tutorialmod.item.custom.FoodComponents.COFFEE_II)));

    public static final Item CUP_AMERICANO_COFFEE = registerItem("cup_americano_coffee",
            new HoneyBottleItem(new FabricItemSettings().group(ItemGroup.FOOD).maxCount(16).food(net.tutorialsbykaupenjoe.tutorialmod.item.custom.FoodComponents.COFFEE_II)));

    public static final Item CUP_CAPPUCCINO_COFFEE = registerItem("cup_cappuccino_coffee",
            new HoneyBottleItem(new FabricItemSettings().group(ItemGroup.FOOD).maxCount(16).food(net.tutorialsbykaupenjoe.tutorialmod.item.custom.FoodComponents.COFFEE_III)));

    public static final Item CUP_GOLD_COFFEE = registerItem("cup_gold_coffee",
            new HoneyBottleItem(new FabricItemSettings().group(ItemGroup.FOOD).maxCount(16).food(net.tutorialsbykaupenjoe.tutorialmod.item.custom.FoodComponents.COFFEE_IV)));

    public static final Item TOAST_CHERRY = registerItem("toast_cherry",
            new Item(new FabricItemSettings().group(ItemGroup.FOOD).food(net.tutorialsbykaupenjoe.tutorialmod.item.custom.FoodComponents.SNACK)));

    public static final Item TOAST_CHOCOLATE = registerItem("toast_chocolate",
            new Item(new FabricItemSettings().group(ItemGroup.FOOD).food(net.tutorialsbykaupenjoe.tutorialmod.item.custom.FoodComponents.SNACK)));

    public static final Item TOAST_EGG = registerItem("toast_egg",
            new Item(new FabricItemSettings().group(ItemGroup.FOOD).food(net.tutorialsbykaupenjoe.tutorialmod.item.custom.FoodComponents.SNACK)));

    public static final Item TOAST_FRIED = registerItem("toast_fried",
            new Item(new FabricItemSettings().group(ItemGroup.FOOD).food(net.tutorialsbykaupenjoe.tutorialmod.item.custom.FoodComponents.SNACK)));

    public static final Item TOAST_JAM = registerItem("toast_jam",
            new Item(new FabricItemSettings().group(ItemGroup.FOOD).food(net.tutorialsbykaupenjoe.tutorialmod.item.custom.FoodComponents.SNACK)));

    public static final Item TOAST_TOASTED = registerItem("toast_toasted",
            new Item(new FabricItemSettings().group(ItemGroup.FOOD).food(net.tutorialsbykaupenjoe.tutorialmod.item.custom.FoodComponents.SNACK)));

    public static final Item WAFER = registerItem("wafer",
            new Item(new FabricItemSettings().group(ItemGroup.FOOD).food(net.tutorialsbykaupenjoe.tutorialmod.item.custom.FoodComponents.SNACK)));

    public static final Item WAFER_STRAWBERRIES = registerItem("wafer_strawberries",
            new Item(new FabricItemSettings().group(ItemGroup.FOOD).food(net.tutorialsbykaupenjoe.tutorialmod.item.custom.FoodComponents.SNACK)));

    public static final Item EGGPLANT = registerItem("eggplant",
            new Item(new FabricItemSettings().group(ItemGroup.FOOD).food(net.tutorialsbykaupenjoe.tutorialmod.item.custom.FoodComponents.VEGETABLES)));

    public static final Item CHERRY = registerItem("cherry",
            new Item(new FabricItemSettings().group(ItemGroup.FOOD).food(net.tutorialsbykaupenjoe.tutorialmod.item.custom.FoodComponents.VEGETABLES)));

    public static final Item BANANA = registerItem("banana",
            new Item(new FabricItemSettings().group(ItemGroup.FOOD).food(net.tutorialsbykaupenjoe.tutorialmod.item.custom.FoodComponents.VEGETABLES)));

    public static final Item BLUEBERRY = registerItem("blueberry",
            new AliasedBlockItem(Farm.BLUEBERRY_VINE, new FabricItemSettings().group(ItemGroup.FOOD).food(net.tutorialsbykaupenjoe.tutorialmod.item.custom.FoodComponents.VEGETABLES)));

    public static final Item STRAWBERRY = registerItem("strawberry",
            new AliasedBlockItem(Farm.STRAWBERRY_VINE, new FabricItemSettings().group(ItemGroup.FOOD).food(net.tutorialsbykaupenjoe.tutorialmod.item.custom.FoodComponents.VEGETABLES)));

    public static final Item RASPBERRIES = registerItem("raspberries",
            new AliasedBlockItem(Farm.RASPBERRIES_VINE, new FabricItemSettings().group(ItemGroup.FOOD).food(net.tutorialsbykaupenjoe.tutorialmod.item.custom.FoodComponents.VEGETABLES)));

    public static final Item TOMATO = registerItem("tomato",
            new Item(new FabricItemSettings().group(ItemGroup.FOOD).food(net.tutorialsbykaupenjoe.tutorialmod.item.custom.FoodComponents.VEGETABLES)));

    public static final Item PINEAPPLE = registerItem("pineapple",
            new Item(new FabricItemSettings().group(ItemGroup.FOOD).food(net.tutorialsbykaupenjoe.tutorialmod.item.custom.FoodComponents.VEGETABLES)));

    public static final Item CORN = registerItem("corn",
            new Item(new FabricItemSettings().group(ItemGroup.FOOD).food(net.tutorialsbykaupenjoe.tutorialmod.item.custom.FoodComponents.VEGETABLES)));

    public static final Item PEPPER = registerItem("pepper",
            new Item(new FabricItemSettings().group(ItemGroup.FOOD).food(net.tutorialsbykaupenjoe.tutorialmod.item.custom.FoodComponents.VEGETABLES)));

    public static final Item LEMON = registerItem("lemon",
            new Item(new FabricItemSettings().group(ItemGroup.FOOD).food(net.tutorialsbykaupenjoe.tutorialmod.item.custom.FoodComponents.VEGETABLES)));

    private static Item registerItem(String name, Item item) {
        return Registry.register(Registry.ITEM, new Identifier(NEVADA.MOD_ID, name), item);
    }

    public static void registerFood() {
        System.out.println("Registering Mod Items for " + NEVADA.MOD_ID);
    }
}

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
Michael, 2022-03-17
@Akela_wolf

What is there to unite? What do these classes have in common?

4
4auka DomamaN, 2022-03-23
@dmn_202_01

No. How do I know this is minecraft? Well, each class is responsible separately for its component, Item is responsible for the item (ItemStack for the stack), Block is responsible for the block. Each class describes its own object.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question