From b682f3d9b7f81abcb5d265fa742ab41dd2c9001a Mon Sep 17 00:00:00 2001 From: Leo40Git <7997354+Leo40Git@users.noreply.github.com> Date: Thu, 1 Jul 2021 12:27:35 +0300 Subject: [PATCH 1/6] Allow adding supplied effects to FoodProperties --- .../hooks/FoodPropertiesBuilderAccess.java | 28 +++++++++ .../hooks/FoodPropertiesHooks.java | 36 +++++++++++ .../impl/fabric/FoodPropertiesAccess.java | 30 ++++++++++ .../mixin/fabric/MixinFoodProperties.java | 59 +++++++++++++++++++ .../fabric/MixinFoodPropertiesBuilder.java | 51 ++++++++++++++++ .../main/resources/architectury.mixins.json | 2 + 6 files changed, 206 insertions(+) create mode 100644 common/src/main/java/me/shedaniel/architectury/hooks/FoodPropertiesBuilderAccess.java create mode 100644 common/src/main/java/me/shedaniel/architectury/hooks/FoodPropertiesHooks.java create mode 100644 fabric/src/main/java/me/shedaniel/architectury/impl/fabric/FoodPropertiesAccess.java create mode 100644 fabric/src/main/java/me/shedaniel/architectury/mixin/fabric/MixinFoodProperties.java create mode 100644 fabric/src/main/java/me/shedaniel/architectury/mixin/fabric/MixinFoodPropertiesBuilder.java diff --git a/common/src/main/java/me/shedaniel/architectury/hooks/FoodPropertiesBuilderAccess.java b/common/src/main/java/me/shedaniel/architectury/hooks/FoodPropertiesBuilderAccess.java new file mode 100644 index 00000000..e0f0c85e --- /dev/null +++ b/common/src/main/java/me/shedaniel/architectury/hooks/FoodPropertiesBuilderAccess.java @@ -0,0 +1,28 @@ +/* + * 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; + +import net.minecraft.world.effect.MobEffectInstance; + +import java.util.function.Supplier; + +public interface FoodPropertiesBuilderAccess { + void effect(Supplier effectSupplier, float chance); +} diff --git a/common/src/main/java/me/shedaniel/architectury/hooks/FoodPropertiesHooks.java b/common/src/main/java/me/shedaniel/architectury/hooks/FoodPropertiesHooks.java new file mode 100644 index 00000000..6a7ee679 --- /dev/null +++ b/common/src/main/java/me/shedaniel/architectury/hooks/FoodPropertiesHooks.java @@ -0,0 +1,36 @@ +/* + * 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; + +import net.minecraft.world.effect.MobEffectInstance; +import net.minecraft.world.food.FoodProperties; +import org.jetbrains.annotations.NotNull; + +import java.util.function.Supplier; + +public final class FoodPropertiesHooks { + private FoodPropertiesHooks() { + } + + public static void effect(@NotNull FoodProperties.Builder builder, + @NotNull Supplier effectSupplier, float chance) { + ((FoodPropertiesBuilderAccess) builder).effect(effectSupplier, chance); + } +} diff --git a/fabric/src/main/java/me/shedaniel/architectury/impl/fabric/FoodPropertiesAccess.java b/fabric/src/main/java/me/shedaniel/architectury/impl/fabric/FoodPropertiesAccess.java new file mode 100644 index 00000000..7493b68b --- /dev/null +++ b/fabric/src/main/java/me/shedaniel/architectury/impl/fabric/FoodPropertiesAccess.java @@ -0,0 +1,30 @@ +/* + * 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.impl.fabric; + +import com.mojang.datafixers.util.Pair; +import net.minecraft.world.effect.MobEffectInstance; + +import java.util.List; +import java.util.function.Supplier; + +public interface FoodPropertiesAccess { + void setSuppliedEffects(List, Float>> list); +} diff --git a/fabric/src/main/java/me/shedaniel/architectury/mixin/fabric/MixinFoodProperties.java b/fabric/src/main/java/me/shedaniel/architectury/mixin/fabric/MixinFoodProperties.java new file mode 100644 index 00000000..ff541e1b --- /dev/null +++ b/fabric/src/main/java/me/shedaniel/architectury/mixin/fabric/MixinFoodProperties.java @@ -0,0 +1,59 @@ +/* + * 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.mixin.fabric; + +import com.mojang.datafixers.util.Pair; +import dev.architectury.impl.fabric.FoodPropertiesAccess; +import net.minecraft.world.effect.MobEffectInstance; +import net.minecraft.world.food.FoodProperties; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Unique; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; + +import java.util.ArrayList; +import java.util.List; +import java.util.function.Supplier; + +@Mixin(FoodProperties.class) +public class MixinFoodProperties implements FoodPropertiesAccess { + @Unique + private List, Float>> suppliedEffects; + @Unique + private List> suppliedEffectCache; + + @Override + public void setSuppliedEffects(List, Float>> list) { + this.suppliedEffects = list; + suppliedEffectCache = null; + } + + @Inject(method = "getEffects", at = @At("RETURN")) + private void addSuppliedEffects(CallbackInfoReturnable>> cir) { + if (suppliedEffectCache == null) { + suppliedEffectCache = new ArrayList<>(); + for (Pair, Float> suppliedEffect : suppliedEffects) { + suppliedEffectCache.add(suppliedEffect.mapFirst(Supplier::get)); + } + } + cir.getReturnValue().addAll(suppliedEffectCache); + } +} diff --git a/fabric/src/main/java/me/shedaniel/architectury/mixin/fabric/MixinFoodPropertiesBuilder.java b/fabric/src/main/java/me/shedaniel/architectury/mixin/fabric/MixinFoodPropertiesBuilder.java new file mode 100644 index 00000000..453920db --- /dev/null +++ b/fabric/src/main/java/me/shedaniel/architectury/mixin/fabric/MixinFoodPropertiesBuilder.java @@ -0,0 +1,51 @@ +/* + * 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.mixin.fabric; + +import com.mojang.datafixers.util.Pair; +import dev.architectury.hooks.item.FoodPropertiesBuilderAccess; +import dev.architectury.impl.fabric.FoodPropertiesAccess; +import net.minecraft.world.effect.MobEffectInstance; +import net.minecraft.world.food.FoodProperties; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Unique; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; + +import java.util.ArrayList; +import java.util.function.Supplier; + +@Mixin(FoodProperties.Builder.class) +public class MixinFoodPropertiesBuilder implements FoodPropertiesBuilderAccess { + @Unique + private final ArrayList, Float>> suppliedEffects + = new ArrayList<>(); + + @Override + public void effect(Supplier effectSupplier, float chance) { + suppliedEffects.add(Pair.of(effectSupplier, chance)); + } + + @Inject(method = "build", at = @At("RETURN")) + public void passSuppliedEffectsToProps(CallbackInfoReturnable cir) { + ((FoodPropertiesAccess) cir.getReturnValue()).setSuppliedEffects(suppliedEffects); + } +} diff --git a/fabric/src/main/resources/architectury.mixins.json b/fabric/src/main/resources/architectury.mixins.json index 7bd53999..341f8b29 100644 --- a/fabric/src/main/resources/architectury.mixins.json +++ b/fabric/src/main/resources/architectury.mixins.json @@ -34,6 +34,8 @@ "MixinEntityCollisionContext", "MixinExplosion", "MixinFarmBlock", + "MixinFoodProperties", + "MixinFoodPropertiesBuilder", "MixinFurnaceResultSlot", "MixinInventory", "MixinItemEntity", From 1d10df6bb32898fea5057c36c8e5b6ef315bf51a Mon Sep 17 00:00:00 2001 From: Leo40Git <7997354+Leo40Git@users.noreply.github.com> Date: Thu, 1 Jul 2021 14:00:24 +0300 Subject: [PATCH 2/6] Make Fabric impl way simpler Yeet NonNull annotations --- .../hooks/FoodPropertiesBuilderAccess.java | 28 --------- .../hooks/FoodPropertiesHooks.java | 11 ++-- .../item/fabric/FoodPropertiesHooksImpl.java | 14 +++++ .../impl/fabric/FoodPropertiesAccess.java | 30 ---------- .../mixin/fabric/MixinFoodProperties.java | 59 ------------------- .../fabric/MixinFoodPropertiesBuilder.java | 51 ---------------- .../main/resources/architectury.mixins.json | 2 - 7 files changed, 20 insertions(+), 175 deletions(-) delete mode 100644 common/src/main/java/me/shedaniel/architectury/hooks/FoodPropertiesBuilderAccess.java create mode 100644 fabric/src/main/java/me/shedaniel/architectury/hooks/item/fabric/FoodPropertiesHooksImpl.java delete mode 100644 fabric/src/main/java/me/shedaniel/architectury/impl/fabric/FoodPropertiesAccess.java delete mode 100644 fabric/src/main/java/me/shedaniel/architectury/mixin/fabric/MixinFoodProperties.java delete mode 100644 fabric/src/main/java/me/shedaniel/architectury/mixin/fabric/MixinFoodPropertiesBuilder.java diff --git a/common/src/main/java/me/shedaniel/architectury/hooks/FoodPropertiesBuilderAccess.java b/common/src/main/java/me/shedaniel/architectury/hooks/FoodPropertiesBuilderAccess.java deleted file mode 100644 index e0f0c85e..00000000 --- a/common/src/main/java/me/shedaniel/architectury/hooks/FoodPropertiesBuilderAccess.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * 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; - -import net.minecraft.world.effect.MobEffectInstance; - -import java.util.function.Supplier; - -public interface FoodPropertiesBuilderAccess { - void effect(Supplier effectSupplier, float chance); -} diff --git a/common/src/main/java/me/shedaniel/architectury/hooks/FoodPropertiesHooks.java b/common/src/main/java/me/shedaniel/architectury/hooks/FoodPropertiesHooks.java index 6a7ee679..24546b40 100644 --- a/common/src/main/java/me/shedaniel/architectury/hooks/FoodPropertiesHooks.java +++ b/common/src/main/java/me/shedaniel/architectury/hooks/FoodPropertiesHooks.java @@ -19,18 +19,19 @@ package dev.architectury.hooks.item; +import dev.architectury.injectables.annotations.ExpectPlatform; import net.minecraft.world.effect.MobEffectInstance; import net.minecraft.world.food.FoodProperties; -import org.jetbrains.annotations.NotNull; import java.util.function.Supplier; public final class FoodPropertiesHooks { private FoodPropertiesHooks() { } - - public static void effect(@NotNull FoodProperties.Builder builder, - @NotNull Supplier effectSupplier, float chance) { - ((FoodPropertiesBuilderAccess) builder).effect(effectSupplier, chance); + + @ExpectPlatform + public static void effect(FoodProperties.Builder builder, + Supplier effectSupplier, float chance) { + throw new AssertionError(); } } diff --git a/fabric/src/main/java/me/shedaniel/architectury/hooks/item/fabric/FoodPropertiesHooksImpl.java b/fabric/src/main/java/me/shedaniel/architectury/hooks/item/fabric/FoodPropertiesHooksImpl.java new file mode 100644 index 00000000..e18e9bb3 --- /dev/null +++ b/fabric/src/main/java/me/shedaniel/architectury/hooks/item/fabric/FoodPropertiesHooksImpl.java @@ -0,0 +1,14 @@ +package dev.architectury.hooks.item.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/fabric/src/main/java/me/shedaniel/architectury/impl/fabric/FoodPropertiesAccess.java b/fabric/src/main/java/me/shedaniel/architectury/impl/fabric/FoodPropertiesAccess.java deleted file mode 100644 index 7493b68b..00000000 --- a/fabric/src/main/java/me/shedaniel/architectury/impl/fabric/FoodPropertiesAccess.java +++ /dev/null @@ -1,30 +0,0 @@ -/* - * 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.impl.fabric; - -import com.mojang.datafixers.util.Pair; -import net.minecraft.world.effect.MobEffectInstance; - -import java.util.List; -import java.util.function.Supplier; - -public interface FoodPropertiesAccess { - void setSuppliedEffects(List, Float>> list); -} diff --git a/fabric/src/main/java/me/shedaniel/architectury/mixin/fabric/MixinFoodProperties.java b/fabric/src/main/java/me/shedaniel/architectury/mixin/fabric/MixinFoodProperties.java deleted file mode 100644 index ff541e1b..00000000 --- a/fabric/src/main/java/me/shedaniel/architectury/mixin/fabric/MixinFoodProperties.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * 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.mixin.fabric; - -import com.mojang.datafixers.util.Pair; -import dev.architectury.impl.fabric.FoodPropertiesAccess; -import net.minecraft.world.effect.MobEffectInstance; -import net.minecraft.world.food.FoodProperties; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Unique; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; - -import java.util.ArrayList; -import java.util.List; -import java.util.function.Supplier; - -@Mixin(FoodProperties.class) -public class MixinFoodProperties implements FoodPropertiesAccess { - @Unique - private List, Float>> suppliedEffects; - @Unique - private List> suppliedEffectCache; - - @Override - public void setSuppliedEffects(List, Float>> list) { - this.suppliedEffects = list; - suppliedEffectCache = null; - } - - @Inject(method = "getEffects", at = @At("RETURN")) - private void addSuppliedEffects(CallbackInfoReturnable>> cir) { - if (suppliedEffectCache == null) { - suppliedEffectCache = new ArrayList<>(); - for (Pair, Float> suppliedEffect : suppliedEffects) { - suppliedEffectCache.add(suppliedEffect.mapFirst(Supplier::get)); - } - } - cir.getReturnValue().addAll(suppliedEffectCache); - } -} diff --git a/fabric/src/main/java/me/shedaniel/architectury/mixin/fabric/MixinFoodPropertiesBuilder.java b/fabric/src/main/java/me/shedaniel/architectury/mixin/fabric/MixinFoodPropertiesBuilder.java deleted file mode 100644 index 453920db..00000000 --- a/fabric/src/main/java/me/shedaniel/architectury/mixin/fabric/MixinFoodPropertiesBuilder.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * 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.mixin.fabric; - -import com.mojang.datafixers.util.Pair; -import dev.architectury.hooks.item.FoodPropertiesBuilderAccess; -import dev.architectury.impl.fabric.FoodPropertiesAccess; -import net.minecraft.world.effect.MobEffectInstance; -import net.minecraft.world.food.FoodProperties; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Unique; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; - -import java.util.ArrayList; -import java.util.function.Supplier; - -@Mixin(FoodProperties.Builder.class) -public class MixinFoodPropertiesBuilder implements FoodPropertiesBuilderAccess { - @Unique - private final ArrayList, Float>> suppliedEffects - = new ArrayList<>(); - - @Override - public void effect(Supplier effectSupplier, float chance) { - suppliedEffects.add(Pair.of(effectSupplier, chance)); - } - - @Inject(method = "build", at = @At("RETURN")) - public void passSuppliedEffectsToProps(CallbackInfoReturnable cir) { - ((FoodPropertiesAccess) cir.getReturnValue()).setSuppliedEffects(suppliedEffects); - } -} diff --git a/fabric/src/main/resources/architectury.mixins.json b/fabric/src/main/resources/architectury.mixins.json index 341f8b29..7bd53999 100644 --- a/fabric/src/main/resources/architectury.mixins.json +++ b/fabric/src/main/resources/architectury.mixins.json @@ -34,8 +34,6 @@ "MixinEntityCollisionContext", "MixinExplosion", "MixinFarmBlock", - "MixinFoodProperties", - "MixinFoodPropertiesBuilder", "MixinFurnaceResultSlot", "MixinInventory", "MixinItemEntity", From 62dbfbd3b996f586fe4dccd762d9b549ae5547c8 Mon Sep 17 00:00:00 2001 From: Leo40Git <7997354+Leo40Git@users.noreply.github.com> Date: Thu, 1 Jul 2021 14:04:36 +0300 Subject: [PATCH 3/6] oops, forgot license --- .../item/fabric/FoodPropertiesHooksImpl.java | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/fabric/src/main/java/me/shedaniel/architectury/hooks/item/fabric/FoodPropertiesHooksImpl.java b/fabric/src/main/java/me/shedaniel/architectury/hooks/item/fabric/FoodPropertiesHooksImpl.java index e18e9bb3..db82cf0c 100644 --- a/fabric/src/main/java/me/shedaniel/architectury/hooks/item/fabric/FoodPropertiesHooksImpl.java +++ b/fabric/src/main/java/me/shedaniel/architectury/hooks/item/fabric/FoodPropertiesHooksImpl.java @@ -1,3 +1,22 @@ +/* + * 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.fabric; import net.minecraft.world.effect.MobEffectInstance; From b7c5a106c1ec063e60895ecaf7790599d3744456 Mon Sep 17 00:00:00 2001 From: Leo40Git <7997354+Leo40Git@users.noreply.github.com> Date: Thu, 1 Jul 2021 15:13:49 +0300 Subject: [PATCH 4/6] Repackaging and such --- .../me/shedaniel/architectury/hooks/FoodPropertiesHooks.java | 4 ++-- .../hooks/{item => }/fabric/FoodPropertiesHooksImpl.java | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) rename fabric/src/main/java/me/shedaniel/architectury/hooks/{item => }/fabric/FoodPropertiesHooksImpl.java (96%) diff --git a/common/src/main/java/me/shedaniel/architectury/hooks/FoodPropertiesHooks.java b/common/src/main/java/me/shedaniel/architectury/hooks/FoodPropertiesHooks.java index 24546b40..ec19278e 100644 --- a/common/src/main/java/me/shedaniel/architectury/hooks/FoodPropertiesHooks.java +++ b/common/src/main/java/me/shedaniel/architectury/hooks/FoodPropertiesHooks.java @@ -17,9 +17,9 @@ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -package dev.architectury.hooks.item; +package me.shedaniel.architectury.hooks; -import dev.architectury.injectables.annotations.ExpectPlatform; +import me.shedaniel.architectury.annotations.ExpectPlatform; import net.minecraft.world.effect.MobEffectInstance; import net.minecraft.world.food.FoodProperties; diff --git a/fabric/src/main/java/me/shedaniel/architectury/hooks/item/fabric/FoodPropertiesHooksImpl.java b/fabric/src/main/java/me/shedaniel/architectury/hooks/fabric/FoodPropertiesHooksImpl.java similarity index 96% rename from fabric/src/main/java/me/shedaniel/architectury/hooks/item/fabric/FoodPropertiesHooksImpl.java rename to fabric/src/main/java/me/shedaniel/architectury/hooks/fabric/FoodPropertiesHooksImpl.java index db82cf0c..f6f916f5 100644 --- a/fabric/src/main/java/me/shedaniel/architectury/hooks/item/fabric/FoodPropertiesHooksImpl.java +++ b/fabric/src/main/java/me/shedaniel/architectury/hooks/fabric/FoodPropertiesHooksImpl.java @@ -17,7 +17,7 @@ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -package dev.architectury.hooks.item.fabric; +package me.shedaniel.architectury.hooks.fabric; import net.minecraft.world.effect.MobEffectInstance; import net.minecraft.world.food.FoodProperties; From b644d103fa6306dd048af459b5e31efaf7dc410d Mon Sep 17 00:00:00 2001 From: Leo40Git <7997354+Leo40Git@users.noreply.github.com> Date: Thu, 1 Jul 2021 15:16:23 +0300 Subject: [PATCH 5/6] Forge implementation --- .../hooks/FoodPropertiesHooks.java | 2 +- .../hooks/fabric/FoodPropertiesHooksImpl.java | 2 +- .../hooks/forge/FoodPropertiesHooksImpl.java | 32 +++++++++++++++++++ 3 files changed, 34 insertions(+), 2 deletions(-) create mode 100644 forge/src/main/java/me/shedaniel/architectury/hooks/forge/FoodPropertiesHooksImpl.java diff --git a/common/src/main/java/me/shedaniel/architectury/hooks/FoodPropertiesHooks.java b/common/src/main/java/me/shedaniel/architectury/hooks/FoodPropertiesHooks.java index ec19278e..14283518 100644 --- a/common/src/main/java/me/shedaniel/architectury/hooks/FoodPropertiesHooks.java +++ b/common/src/main/java/me/shedaniel/architectury/hooks/FoodPropertiesHooks.java @@ -31,7 +31,7 @@ public final class FoodPropertiesHooks { @ExpectPlatform public static void effect(FoodProperties.Builder builder, - Supplier effectSupplier, float chance) { + Supplier effectSupplier, float chance) { throw new AssertionError(); } } diff --git a/fabric/src/main/java/me/shedaniel/architectury/hooks/fabric/FoodPropertiesHooksImpl.java b/fabric/src/main/java/me/shedaniel/architectury/hooks/fabric/FoodPropertiesHooksImpl.java index f6f916f5..f9141e60 100644 --- a/fabric/src/main/java/me/shedaniel/architectury/hooks/fabric/FoodPropertiesHooksImpl.java +++ b/fabric/src/main/java/me/shedaniel/architectury/hooks/fabric/FoodPropertiesHooksImpl.java @@ -26,7 +26,7 @@ import java.util.function.Supplier; public class FoodPropertiesHooksImpl { public static void effect(FoodProperties.Builder builder, - Supplier effectSupplier, float chance) { + 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..8e33cdbf --- /dev/null +++ b/forge/src/main/java/me/shedaniel/architectury/hooks/forge/FoodPropertiesHooksImpl.java @@ -0,0 +1,32 @@ +/* + * 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 { + public static void effect(FoodProperties.Builder builder, + Supplier effectSupplier, float chance) { + builder.effect(effectSupplier, chance); + } +} From f019deb81510b21bb43832eeb79cbdca46c52a52 Mon Sep 17 00:00:00 2001 From: Leo40Git <7997354+Leo40Git@users.noreply.github.com> Date: Thu, 1 Jul 2021 15:52:49 +0300 Subject: [PATCH 6/6] Testmod Restore variance --- .../architectury/hooks/FoodPropertiesHooks.java | 2 +- .../hooks/fabric/FoodPropertiesHooksImpl.java | 2 +- .../hooks/forge/FoodPropertiesHooksImpl.java | 5 +++-- .../test/registry/TestRegistries.java | 15 +++++++++++++++ 4 files changed, 20 insertions(+), 4 deletions(-) diff --git a/common/src/main/java/me/shedaniel/architectury/hooks/FoodPropertiesHooks.java b/common/src/main/java/me/shedaniel/architectury/hooks/FoodPropertiesHooks.java index 14283518..ec19278e 100644 --- a/common/src/main/java/me/shedaniel/architectury/hooks/FoodPropertiesHooks.java +++ b/common/src/main/java/me/shedaniel/architectury/hooks/FoodPropertiesHooks.java @@ -31,7 +31,7 @@ public final class FoodPropertiesHooks { @ExpectPlatform public static void effect(FoodProperties.Builder builder, - Supplier effectSupplier, float chance) { + Supplier effectSupplier, float chance) { throw new AssertionError(); } } diff --git a/fabric/src/main/java/me/shedaniel/architectury/hooks/fabric/FoodPropertiesHooksImpl.java b/fabric/src/main/java/me/shedaniel/architectury/hooks/fabric/FoodPropertiesHooksImpl.java index f9141e60..f6f916f5 100644 --- a/fabric/src/main/java/me/shedaniel/architectury/hooks/fabric/FoodPropertiesHooksImpl.java +++ b/fabric/src/main/java/me/shedaniel/architectury/hooks/fabric/FoodPropertiesHooksImpl.java @@ -26,7 +26,7 @@ import java.util.function.Supplier; public class FoodPropertiesHooksImpl { public static void effect(FoodProperties.Builder builder, - Supplier effectSupplier, float chance) { + 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 index 8e33cdbf..e9662118 100644 --- a/forge/src/main/java/me/shedaniel/architectury/hooks/forge/FoodPropertiesHooksImpl.java +++ b/forge/src/main/java/me/shedaniel/architectury/hooks/forge/FoodPropertiesHooksImpl.java @@ -25,8 +25,9 @@ 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(effectSupplier, chance); + Supplier effectSupplier, float chance) { + builder.effect((Supplier) effectSupplier, chance); } } diff --git a/testmod-common/src/main/java/me/shedaniel/architectury/test/registry/TestRegistries.java b/testmod-common/src/main/java/me/shedaniel/architectury/test/registry/TestRegistries.java index 65c7483d..e8d6dc4a 100644 --- a/testmod-common/src/main/java/me/shedaniel/architectury/test/registry/TestRegistries.java +++ b/testmod-common/src/main/java/me/shedaniel/architectury/test/registry/TestRegistries.java @@ -20,6 +20,7 @@ package me.shedaniel.architectury.test.registry; import me.shedaniel.architectury.hooks.EntityHooks; +import me.shedaniel.architectury.hooks.FoodPropertiesHooks; import me.shedaniel.architectury.registry.BlockProperties; import me.shedaniel.architectury.registry.DeferredRegister; import me.shedaniel.architectury.registry.RegistrySupplier; @@ -29,7 +30,11 @@ import me.shedaniel.architectury.test.registry.objects.EquippableTickingItem; import me.shedaniel.architectury.test.tab.TestCreativeTabs; 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();