From 6e0a758d1f028f98f1e77d2b35b6bb7a39492561 Mon Sep 17 00:00:00 2001 From: vemerion Date: Sun, 4 Jul 2021 20:09:43 +0200 Subject: [PATCH] Change to use Forge milk This commit removes Create's fluid milk, and changes things to instead use the milk fluid already provided by Forge. This makes the mod more compatible with other mods. I also added an event subscriber to the MissingMappings event in the AllFluids class, to convert already existing Create milk to Forge milk so that players don't lose any stored milk. Note: I did not update language files and remove textures to reflect the fact that Create's milk to longer existsMissingMappings, so right now there are some unused resources that can be cleaned up. --- .../create/recipes/emptying/milk_bucket.json | 2 +- .../data/forge/tags/fluids/milk.json | 7 ----- .../java/com/simibubi/create/AllFluids.java | 26 ++++++++++++++----- src/main/java/com/simibubi/create/Create.java | 3 +++ .../fluids/actors/GenericItemFilling.java | 3 ++- .../data/recipe/EmptyingRecipeGen.java | 3 ++- .../neapolitan/emptying/milk_bottle.json | 4 +-- 7 files changed, 30 insertions(+), 18 deletions(-) delete mode 100644 src/generated/resources/data/forge/tags/fluids/milk.json diff --git a/src/generated/resources/data/create/recipes/emptying/milk_bucket.json b/src/generated/resources/data/create/recipes/emptying/milk_bucket.json index be95f4c33..a0b818a50 100644 --- a/src/generated/resources/data/create/recipes/emptying/milk_bucket.json +++ b/src/generated/resources/data/create/recipes/emptying/milk_bucket.json @@ -10,7 +10,7 @@ "item": "minecraft:bucket" }, { - "fluid": "create:milk", + "fluid": "minecraft:milk", "amount": 1000 } ] diff --git a/src/generated/resources/data/forge/tags/fluids/milk.json b/src/generated/resources/data/forge/tags/fluids/milk.json deleted file mode 100644 index 6860027e8..000000000 --- a/src/generated/resources/data/forge/tags/fluids/milk.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "replace": false, - "values": [ - "create:flowing_milk", - "create:milk" - ] -} \ No newline at end of file diff --git a/src/main/java/com/simibubi/create/AllFluids.java b/src/main/java/com/simibubi/create/AllFluids.java index 12a881022..c8c13b8bb 100644 --- a/src/main/java/com/simibubi/create/AllFluids.java +++ b/src/main/java/com/simibubi/create/AllFluids.java @@ -19,9 +19,14 @@ import net.minecraft.util.math.BlockPos; import net.minecraft.world.IBlockDisplayReader; import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.OnlyIn; -import net.minecraftforge.common.Tags; +import net.minecraftforge.common.ForgeMod; +import net.minecraftforge.event.RegistryEvent; +import net.minecraftforge.event.RegistryEvent.MissingMappings.Mapping; +import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.fluids.FluidAttributes; import net.minecraftforge.fluids.ForgeFlowingFluid; +import net.minecraftforge.fml.common.Mod.EventBusSubscriber; +import net.minecraftforge.fml.common.Mod.EventBusSubscriber.Bus; public class AllFluids { @@ -37,11 +42,6 @@ public class AllFluids { .tag(AllTags.forgeFluidTag("tea")) .register(); - public static final FluidEntry MILK = REGISTRATE.virtualFluid("milk") - .lang(f -> "fluid.create.milk", "Milk") - .tag(Tags.Fluids.MILK) - .register(); - public static final FluidEntry HONEY = REGISTRATE.standardFluid("honey", NoColorFluidAttributes::new) .lang(f -> "fluid.create.honey", "Honey") @@ -116,5 +116,19 @@ public class AllFluids { } } + + @EventBusSubscriber(modid = Create.ID, bus = Bus.FORGE) + public static class MissingMappingsSubscriber { + + @SubscribeEvent + public static void missingMappings(RegistryEvent.MissingMappings event) { + for (Mapping mapping : event.getMappings(Create.ID)) { + if (mapping.key.getPath().equals("milk")) + mapping.remap(ForgeMod.MILK.get()); + else if (mapping.key.getPath().equals("flowing_milk")) + mapping.remap(ForgeMod.FLOWING_MILK.get()); + } + } + } } diff --git a/src/main/java/com/simibubi/create/Create.java b/src/main/java/com/simibubi/create/Create.java index b44b6b13b..8b81243de 100644 --- a/src/main/java/com/simibubi/create/Create.java +++ b/src/main/java/com/simibubi/create/Create.java @@ -41,6 +41,7 @@ import net.minecraft.util.SoundEvent; import net.minecraft.world.gen.feature.Feature; import net.minecraft.world.gen.placement.Placement; import net.minecraftforge.api.distmarker.Dist; +import net.minecraftforge.common.ForgeMod; import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.event.world.BiomeLoadingEvent; import net.minecraftforge.eventbus.api.EventPriority; @@ -107,6 +108,8 @@ public class Create { DistExecutor.unsafeRunWhenOn(Dist.CLIENT, () -> () -> CreateClient.addClientListeners(forgeEventBus, modEventBus)); + + ForgeMod.enableMilkFluid(); } public static void init(final FMLCommonSetupEvent event) { diff --git a/src/main/java/com/simibubi/create/content/contraptions/fluids/actors/GenericItemFilling.java b/src/main/java/com/simibubi/create/content/contraptions/fluids/actors/GenericItemFilling.java index 271378b4d..81e462df4 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/fluids/actors/GenericItemFilling.java +++ b/src/main/java/com/simibubi/create/content/contraptions/fluids/actors/GenericItemFilling.java @@ -13,6 +13,7 @@ import net.minecraft.item.MilkBucketItem; import net.minecraft.potion.PotionUtils; import net.minecraft.potion.Potions; import net.minecraft.world.World; +import net.minecraftforge.common.ForgeMod; import net.minecraftforge.common.util.LazyOptional; import net.minecraftforge.fluids.FluidStack; import net.minecraftforge.fluids.capability.CapabilityFluidHandler; @@ -105,7 +106,7 @@ public class GenericItemFilling { private static boolean canFillBucketInternally(FluidStack availableFluid) { return availableFluid.getFluid() - .isEquivalentTo(AllFluids.MILK.get().getFlowingFluid()); + .isEquivalentTo(ForgeMod.MILK.get()); } public static ItemStack fillItem(World world, int requiredAmount, ItemStack stack, FluidStack availableFluid) { diff --git a/src/main/java/com/simibubi/create/foundation/data/recipe/EmptyingRecipeGen.java b/src/main/java/com/simibubi/create/foundation/data/recipe/EmptyingRecipeGen.java index 9df7864d4..c0c94dad6 100644 --- a/src/main/java/com/simibubi/create/foundation/data/recipe/EmptyingRecipeGen.java +++ b/src/main/java/com/simibubi/create/foundation/data/recipe/EmptyingRecipeGen.java @@ -6,6 +6,7 @@ import com.simibubi.create.AllRecipeTypes; import net.minecraft.data.DataGenerator; import net.minecraft.item.Items; +import net.minecraftforge.common.ForgeMod; public class EmptyingRecipeGen extends ProcessingRecipeGen { @@ -27,7 +28,7 @@ public class EmptyingRecipeGen extends ProcessingRecipeGen { MILK_BUCKET = create("milk_bucket", b -> b .require(Items.MILK_BUCKET) - .output(AllFluids.MILK.get(), 1000) + .output(ForgeMod.MILK.get(), 1000) .output(Items.BUCKET)) ; diff --git a/src/main/resources/data/create/recipes/compat/neapolitan/emptying/milk_bottle.json b/src/main/resources/data/create/recipes/compat/neapolitan/emptying/milk_bottle.json index f4785b681..6248dee4b 100644 --- a/src/main/resources/data/create/recipes/compat/neapolitan/emptying/milk_bottle.json +++ b/src/main/resources/data/create/recipes/compat/neapolitan/emptying/milk_bottle.json @@ -16,8 +16,8 @@ "item": "minecraft:glass_bottle" }, { - "fluid": "create:milk", + "fluid": "minecraft:milk", "amount": 250 } ] -} \ No newline at end of file +}