From 3ee2355b2d851de96cd3bf6b96eae92a441ea780 Mon Sep 17 00:00:00 2001 From: shedaniel Date: Thu, 11 Aug 2022 19:05:55 +0800 Subject: [PATCH] [ci skip] Add LiquidBlock.arch$getFluid and fix MixinFoodPropertiesBuilder (#316) --- .../injected/InjectedBucketItemExtension.java | 19 ++++++++++ .../InjectedLiquidBlockExtension.java | 30 +++++++++++++++ .../hooks/fluid/LiquidBlockHooks.java | 38 +++++++++++++++++++ .../architectury/mixin/inject/MixinBlock.java | 19 ++++++++++ .../mixin/inject/MixinBucketItem.java | 19 ++++++++++ .../mixin/inject/MixinEntityType.java | 19 ++++++++++ .../architectury/mixin/inject/MixinFluid.java | 19 ++++++++++ .../inject/MixinFoodPropertiesBuilder.java | 28 ++++++++++++++ .../mixin/inject/MixinGameEvent.java | 19 ++++++++++ .../architectury/mixin/inject/MixinItem.java | 19 ++++++++++ .../mixin/inject/MixinLiquidBlock.java | 28 ++++++++++++++ .../resources/architectury-common.mixins.json | 2 + .../main/resources/architectury.common.json | 3 ++ .../fluid/fabric/LiquidBlockHooksImpl.java | 30 +++++++++++++++ .../mixin/fabric/LiquidBlockAccessor.java | 31 +++++++++++++++ .../main/resources/architectury.mixins.json | 1 + .../fluid/forge/LiquidBlockHooksImpl.java | 29 ++++++++++++++ 17 files changed, 353 insertions(+) create mode 100644 common/src/main/java/dev/architectury/extensions/injected/InjectedLiquidBlockExtension.java create mode 100644 common/src/main/java/dev/architectury/hooks/fluid/LiquidBlockHooks.java create mode 100644 common/src/main/java/dev/architectury/mixin/inject/MixinFoodPropertiesBuilder.java create mode 100644 common/src/main/java/dev/architectury/mixin/inject/MixinLiquidBlock.java create mode 100644 fabric/src/main/java/dev/architectury/hooks/fluid/fabric/LiquidBlockHooksImpl.java create mode 100644 fabric/src/main/java/dev/architectury/mixin/fabric/LiquidBlockAccessor.java create mode 100644 forge/src/main/java/dev/architectury/hooks/fluid/forge/LiquidBlockHooksImpl.java diff --git a/common/src/main/java/dev/architectury/extensions/injected/InjectedBucketItemExtension.java b/common/src/main/java/dev/architectury/extensions/injected/InjectedBucketItemExtension.java index 52656234..6db4d88d 100644 --- a/common/src/main/java/dev/architectury/extensions/injected/InjectedBucketItemExtension.java +++ b/common/src/main/java/dev/architectury/extensions/injected/InjectedBucketItemExtension.java @@ -1,3 +1,22 @@ +/* + * This file is part of architectury. + * Copyright (C) 2020, 2021, 2022 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.extensions.injected; import dev.architectury.hooks.fluid.FluidBucketHooks; diff --git a/common/src/main/java/dev/architectury/extensions/injected/InjectedLiquidBlockExtension.java b/common/src/main/java/dev/architectury/extensions/injected/InjectedLiquidBlockExtension.java new file mode 100644 index 00000000..330d1d08 --- /dev/null +++ b/common/src/main/java/dev/architectury/extensions/injected/InjectedLiquidBlockExtension.java @@ -0,0 +1,30 @@ +/* + * This file is part of architectury. + * Copyright (C) 2020, 2021, 2022 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.extensions.injected; + +import dev.architectury.hooks.fluid.LiquidBlockHooks; +import net.minecraft.world.level.block.LiquidBlock; +import net.minecraft.world.level.material.FlowingFluid; + +public interface InjectedLiquidBlockExtension { + default FlowingFluid arch$getFluid() { + return LiquidBlockHooks.getFluid((LiquidBlock) this); + } +} diff --git a/common/src/main/java/dev/architectury/hooks/fluid/LiquidBlockHooks.java b/common/src/main/java/dev/architectury/hooks/fluid/LiquidBlockHooks.java new file mode 100644 index 00000000..49e04e6b --- /dev/null +++ b/common/src/main/java/dev/architectury/hooks/fluid/LiquidBlockHooks.java @@ -0,0 +1,38 @@ +/* + * This file is part of architectury. + * Copyright (C) 2020, 2021, 2022 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.fluid; + +import dev.architectury.injectables.annotations.ExpectPlatform; +import net.minecraft.world.level.block.LiquidBlock; +import net.minecraft.world.level.material.FlowingFluid; + +public final class LiquidBlockHooks { + /** + * Returns the fluid contained in the liquid block. + * This requires special handling since forge defers the fiuid. + * + * @param block the liquid block + * @return the fluid contained in the liquid block + */ + @ExpectPlatform + public static FlowingFluid getFluid(LiquidBlock block) { + throw new AssertionError(); + } +} diff --git a/common/src/main/java/dev/architectury/mixin/inject/MixinBlock.java b/common/src/main/java/dev/architectury/mixin/inject/MixinBlock.java index 341a292f..78001554 100644 --- a/common/src/main/java/dev/architectury/mixin/inject/MixinBlock.java +++ b/common/src/main/java/dev/architectury/mixin/inject/MixinBlock.java @@ -1,3 +1,22 @@ +/* + * This file is part of architectury. + * Copyright (C) 2020, 2021, 2022 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.inject; import dev.architectury.extensions.injected.InjectedBlockExtension; diff --git a/common/src/main/java/dev/architectury/mixin/inject/MixinBucketItem.java b/common/src/main/java/dev/architectury/mixin/inject/MixinBucketItem.java index fba02eea..3808e4d5 100644 --- a/common/src/main/java/dev/architectury/mixin/inject/MixinBucketItem.java +++ b/common/src/main/java/dev/architectury/mixin/inject/MixinBucketItem.java @@ -1,3 +1,22 @@ +/* + * This file is part of architectury. + * Copyright (C) 2020, 2021, 2022 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.inject; import dev.architectury.extensions.injected.InjectedBucketItemExtension; diff --git a/common/src/main/java/dev/architectury/mixin/inject/MixinEntityType.java b/common/src/main/java/dev/architectury/mixin/inject/MixinEntityType.java index b4536433..cfe3e3f9 100644 --- a/common/src/main/java/dev/architectury/mixin/inject/MixinEntityType.java +++ b/common/src/main/java/dev/architectury/mixin/inject/MixinEntityType.java @@ -1,3 +1,22 @@ +/* + * This file is part of architectury. + * Copyright (C) 2020, 2021, 2022 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.inject; import dev.architectury.extensions.injected.InjectedEntityTypeExtension; diff --git a/common/src/main/java/dev/architectury/mixin/inject/MixinFluid.java b/common/src/main/java/dev/architectury/mixin/inject/MixinFluid.java index 4782fb3a..378d8401 100644 --- a/common/src/main/java/dev/architectury/mixin/inject/MixinFluid.java +++ b/common/src/main/java/dev/architectury/mixin/inject/MixinFluid.java @@ -1,3 +1,22 @@ +/* + * This file is part of architectury. + * Copyright (C) 2020, 2021, 2022 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.inject; import dev.architectury.extensions.injected.InjectedFluidExtension; diff --git a/common/src/main/java/dev/architectury/mixin/inject/MixinFoodPropertiesBuilder.java b/common/src/main/java/dev/architectury/mixin/inject/MixinFoodPropertiesBuilder.java new file mode 100644 index 00000000..13dad400 --- /dev/null +++ b/common/src/main/java/dev/architectury/mixin/inject/MixinFoodPropertiesBuilder.java @@ -0,0 +1,28 @@ +/* + * This file is part of architectury. + * Copyright (C) 2020, 2021, 2022 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.inject; + +import dev.architectury.extensions.injected.InjectedFoodPropertiesBuilderExtension; +import net.minecraft.world.food.FoodProperties; +import org.spongepowered.asm.mixin.Mixin; + +@Mixin(FoodProperties.Builder.class) +public class MixinFoodPropertiesBuilder implements InjectedFoodPropertiesBuilderExtension { +} diff --git a/common/src/main/java/dev/architectury/mixin/inject/MixinGameEvent.java b/common/src/main/java/dev/architectury/mixin/inject/MixinGameEvent.java index 84fbda0e..a71fc894 100644 --- a/common/src/main/java/dev/architectury/mixin/inject/MixinGameEvent.java +++ b/common/src/main/java/dev/architectury/mixin/inject/MixinGameEvent.java @@ -1,3 +1,22 @@ +/* + * This file is part of architectury. + * Copyright (C) 2020, 2021, 2022 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.inject; import dev.architectury.extensions.injected.InjectedGameEventExtension; diff --git a/common/src/main/java/dev/architectury/mixin/inject/MixinItem.java b/common/src/main/java/dev/architectury/mixin/inject/MixinItem.java index 1ef8b53a..4b2a34bc 100644 --- a/common/src/main/java/dev/architectury/mixin/inject/MixinItem.java +++ b/common/src/main/java/dev/architectury/mixin/inject/MixinItem.java @@ -1,3 +1,22 @@ +/* + * This file is part of architectury. + * Copyright (C) 2020, 2021, 2022 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.inject; import dev.architectury.extensions.injected.InjectedItemExtension; diff --git a/common/src/main/java/dev/architectury/mixin/inject/MixinLiquidBlock.java b/common/src/main/java/dev/architectury/mixin/inject/MixinLiquidBlock.java new file mode 100644 index 00000000..f518a514 --- /dev/null +++ b/common/src/main/java/dev/architectury/mixin/inject/MixinLiquidBlock.java @@ -0,0 +1,28 @@ +/* + * This file is part of architectury. + * Copyright (C) 2020, 2021, 2022 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.inject; + +import dev.architectury.extensions.injected.InjectedLiquidBlockExtension; +import net.minecraft.world.level.block.LiquidBlock; +import org.spongepowered.asm.mixin.Mixin; + +@Mixin(LiquidBlock.class) +public class MixinLiquidBlock implements InjectedLiquidBlockExtension { +} diff --git a/common/src/main/resources/architectury-common.mixins.json b/common/src/main/resources/architectury-common.mixins.json index a8d49c96..76b27514 100644 --- a/common/src/main/resources/architectury-common.mixins.json +++ b/common/src/main/resources/architectury-common.mixins.json @@ -10,8 +10,10 @@ "inject.MixinBucketItem", "inject.MixinEntityType", "inject.MixinFluid", + "inject.MixinFoodPropertiesBuilder", "inject.MixinGameEvent", "inject.MixinItem", + "inject.MixinLiquidBlock", "MixinLightningBolt" ], "injectors": { diff --git a/common/src/main/resources/architectury.common.json b/common/src/main/resources/architectury.common.json index 7682f1c8..a6d0c93c 100644 --- a/common/src/main/resources/architectury.common.json +++ b/common/src/main/resources/architectury.common.json @@ -21,6 +21,9 @@ ], "net/minecraft/class_4174$class_4175": [ "dev/architectury/extensions/injected/InjectedFoodPropertiesBuilderExtension" + ], + "net/minecraft/class_2404": [ + "dev/architectury/extensions/injected/InjectedLiquidBlockExtension" ] } } \ No newline at end of file diff --git a/fabric/src/main/java/dev/architectury/hooks/fluid/fabric/LiquidBlockHooksImpl.java b/fabric/src/main/java/dev/architectury/hooks/fluid/fabric/LiquidBlockHooksImpl.java new file mode 100644 index 00000000..aad798d0 --- /dev/null +++ b/fabric/src/main/java/dev/architectury/hooks/fluid/fabric/LiquidBlockHooksImpl.java @@ -0,0 +1,30 @@ +/* + * This file is part of architectury. + * Copyright (C) 2020, 2021, 2022 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.fluid.fabric; + +import dev.architectury.mixin.fabric.LiquidBlockAccessor; +import net.minecraft.world.level.block.LiquidBlock; +import net.minecraft.world.level.material.FlowingFluid; + +public class LiquidBlockHooksImpl { + public static FlowingFluid getFluid(LiquidBlock block) { + return ((LiquidBlockAccessor) block).getFluid(); + } +} diff --git a/fabric/src/main/java/dev/architectury/mixin/fabric/LiquidBlockAccessor.java b/fabric/src/main/java/dev/architectury/mixin/fabric/LiquidBlockAccessor.java new file mode 100644 index 00000000..48cb8b43 --- /dev/null +++ b/fabric/src/main/java/dev/architectury/mixin/fabric/LiquidBlockAccessor.java @@ -0,0 +1,31 @@ +/* + * This file is part of architectury. + * Copyright (C) 2020, 2021, 2022 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 net.minecraft.world.level.block.LiquidBlock; +import net.minecraft.world.level.material.FlowingFluid; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.gen.Accessor; + +@Mixin(LiquidBlock.class) +public interface LiquidBlockAccessor { + @Accessor("fluid") + FlowingFluid getFluid(); +} diff --git a/fabric/src/main/resources/architectury.mixins.json b/fabric/src/main/resources/architectury.mixins.json index 0a6c3dba..0674327c 100644 --- a/fabric/src/main/resources/architectury.mixins.json +++ b/fabric/src/main/resources/architectury.mixins.json @@ -24,6 +24,7 @@ "BucketItemAccessor", "ExplosionPreInvoker", "HorseTameInvoker", + "LiquidBlockAccessor", "LivingDeathInvoker", "MixinBaseSpawner", "MixinBlockItem", diff --git a/forge/src/main/java/dev/architectury/hooks/fluid/forge/LiquidBlockHooksImpl.java b/forge/src/main/java/dev/architectury/hooks/fluid/forge/LiquidBlockHooksImpl.java new file mode 100644 index 00000000..f5f7bb63 --- /dev/null +++ b/forge/src/main/java/dev/architectury/hooks/fluid/forge/LiquidBlockHooksImpl.java @@ -0,0 +1,29 @@ +/* + * This file is part of architectury. + * Copyright (C) 2020, 2021, 2022 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.fluid.forge; + +import net.minecraft.world.level.block.LiquidBlock; +import net.minecraft.world.level.material.FlowingFluid; + +public class LiquidBlockHooksImpl { + public static FlowingFluid getFluid(LiquidBlock block) { + return block.getFluid(); + } +}