diff --git a/common/src/main/java/dev/architectury/hooks/item/food/FoodPropertiesHooks.java b/common/src/main/java/dev/architectury/hooks/item/food/FoodPropertiesHooks.java new file mode 100644 index 00000000..58709777 --- /dev/null +++ b/common/src/main/java/dev/architectury/hooks/item/food/FoodPropertiesHooks.java @@ -0,0 +1,37 @@ +/* + * This file is part of architectury. + * Copyright (C) 2020, 2021 architectury + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +package dev.architectury.hooks.item.food; + +import me.shedaniel.architectury.annotations.ExpectPlatform; +import net.minecraft.world.effect.MobEffectInstance; +import net.minecraft.world.food.FoodProperties; + +import java.util.function.Supplier; + +public final class FoodPropertiesHooks { + private FoodPropertiesHooks() { + } + + @ExpectPlatform + public static void effect(FoodProperties.Builder builder, + Supplier effectSupplier, float chance) { + throw new AssertionError(); + } +} diff --git a/fabric/src/main/java/dev/architectury/hooks/item/food/fabric/FoodPropertiesHooksImpl.java b/fabric/src/main/java/dev/architectury/hooks/item/food/fabric/FoodPropertiesHooksImpl.java new file mode 100644 index 00000000..3b9c116e --- /dev/null +++ b/fabric/src/main/java/dev/architectury/hooks/item/food/fabric/FoodPropertiesHooksImpl.java @@ -0,0 +1,33 @@ +/* + * This file is part of architectury. + * Copyright (C) 2020, 2021 architectury + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +package dev.architectury.hooks.item.food.fabric; + +import net.minecraft.world.effect.MobEffectInstance; +import net.minecraft.world.food.FoodProperties; + +import java.util.function.Supplier; + +public class FoodPropertiesHooksImpl { + public static void effect(FoodProperties.Builder builder, + Supplier effectSupplier, float chance) { + // Fabric doesn't have deferred registration, so the mob effect should always be available anyway + builder.effect(effectSupplier.get(), chance); + } +} diff --git a/forge/src/main/java/me/shedaniel/architectury/hooks/forge/FoodPropertiesHooksImpl.java b/forge/src/main/java/me/shedaniel/architectury/hooks/forge/FoodPropertiesHooksImpl.java new file mode 100644 index 00000000..665e85e7 --- /dev/null +++ b/forge/src/main/java/me/shedaniel/architectury/hooks/forge/FoodPropertiesHooksImpl.java @@ -0,0 +1,33 @@ +/* + * This file is part of architectury. + * Copyright (C) 2020, 2021 architectury + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +package me.shedaniel.architectury.hooks.forge; + +import net.minecraft.world.effect.MobEffectInstance; +import net.minecraft.world.food.FoodProperties; + +import java.util.function.Supplier; + +public class FoodPropertiesHooksImpl { + @SuppressWarnings("unchecked") + public static void effect(FoodProperties.Builder builder, + Supplier effectSupplier, float chance) { + builder.effect((Supplier) effectSupplier, chance); + } +} \ No newline at end of file diff --git a/testmod-common/src/main/java/dev/architectury/test/registry/TestRegistries.java b/testmod-common/src/main/java/dev/architectury/test/registry/TestRegistries.java index 00702053..55c0326b 100644 --- a/testmod-common/src/main/java/dev/architectury/test/registry/TestRegistries.java +++ b/testmod-common/src/main/java/dev/architectury/test/registry/TestRegistries.java @@ -19,17 +19,22 @@ package dev.architectury.test.registry; +import dev.architectury.hooks.item.food.FoodPropertiesHooks; import dev.architectury.hooks.level.entity.EntityHooks; import dev.architectury.registry.block.BlockProperties; import dev.architectury.registry.registries.DeferredRegister; import dev.architectury.registry.registries.RegistrySupplier; +import dev.architectury.test.TestMod; import dev.architectury.test.entity.TestEntity; import dev.architectury.test.registry.objects.EquippableTickingItem; import dev.architectury.test.tab.TestCreativeTabs; -import dev.architectury.test.TestMod; import net.minecraft.core.BlockPos; import net.minecraft.core.Registry; +import net.minecraft.world.effect.MobEffect; +import net.minecraft.world.effect.MobEffectCategory; +import net.minecraft.world.effect.MobEffectInstance; import net.minecraft.world.entity.EntityType; +import net.minecraft.world.food.FoodProperties; import net.minecraft.world.item.BlockItem; import net.minecraft.world.item.Item; import net.minecraft.world.level.BlockGetter; @@ -45,11 +50,20 @@ public class TestRegistries { public static final DeferredRegister ITEMS = DeferredRegister.create(TestMod.MOD_ID, Registry.ITEM_REGISTRY); public static final DeferredRegister BLOCKS = DeferredRegister.create(TestMod.MOD_ID, Registry.BLOCK_REGISTRY); public static final DeferredRegister> ENTITY_TYPES = DeferredRegister.create(TestMod.MOD_ID, Registry.ENTITY_TYPE_REGISTRY); + public static final DeferredRegister MOB_EFFECTS = DeferredRegister.create(TestMod.MOD_ID, Registry.MOB_EFFECT_REGISTRY); + + public static final RegistrySupplier TEST_EFFECT = MOB_EFFECTS.register("test_effect", () -> + new MobEffect(MobEffectCategory.NEUTRAL, 0x123456) {}); public static final RegistrySupplier TEST_ITEM = ITEMS.register("test_item", () -> new Item(new Item.Properties().tab(TestCreativeTabs.TEST_TAB))); public static final RegistrySupplier TEST_EQUIPPABLE = ITEMS.register("test_eqippable", () -> new EquippableTickingItem(new Item.Properties().tab(TestCreativeTabs.TEST_TAB))); + public static final RegistrySupplier TEST_EDIBLE = ITEMS.register("test_edible", () -> { + FoodProperties.Builder fpBuilder = new FoodProperties.Builder().nutrition(8).saturationMod(0.8F).meat(); + FoodPropertiesHooks.effect(fpBuilder, () -> new MobEffectInstance(TEST_EFFECT.get(), 100), 1); + return new Item(new Item.Properties().tab(TestCreativeTabs.TEST_TAB).food(fpBuilder.build())); + }); public static final RegistrySupplier TEST_BLOCK = BLOCKS.register("test_block", () -> new Block(BlockProperties.copy(Blocks.STONE))); @@ -70,6 +84,7 @@ public class TestRegistries { public static final RegistrySupplier> TEST_ENTITY = ENTITY_TYPES.register("test_entity", () -> TestEntity.TYPE); public static void initialize() { + MOB_EFFECTS.register(); BLOCKS.register(); ITEMS.register(); ENTITY_TYPES.register();