From 84b20a0a16809388204f042d2c0485675d6620fb Mon Sep 17 00:00:00 2001 From: TheRealWormbo Date: Thu, 30 Nov 2023 19:00:09 +0100 Subject: [PATCH] Add composting support (fixes #4263) --- .../fabric/FabricCommonInitializer.java | 2 ++ .../botania/forge/ForgeCommonInitializer.java | 2 ++ .../common/handler/CompostingData.java | 31 +++++++++++++++++++ 3 files changed, 35 insertions(+) create mode 100644 Xplat/src/main/java/vazkii/botania/common/handler/CompostingData.java diff --git a/Fabric/src/main/java/vazkii/botania/fabric/FabricCommonInitializer.java b/Fabric/src/main/java/vazkii/botania/fabric/FabricCommonInitializer.java index 7dd415f55f..6ad31fdf36 100644 --- a/Fabric/src/main/java/vazkii/botania/fabric/FabricCommonInitializer.java +++ b/Fabric/src/main/java/vazkii/botania/fabric/FabricCommonInitializer.java @@ -30,6 +30,7 @@ import net.fabricmc.fabric.api.networking.v1.ServerPlayConnectionEvents; import net.fabricmc.fabric.api.object.builder.v1.entity.FabricDefaultAttributeRegistry; import net.fabricmc.fabric.api.object.builder.v1.entity.MinecartComparatorLogicRegistry; +import net.fabricmc.fabric.api.registry.CompostingChanceRegistry; import net.fabricmc.fabric.api.registry.FlattenableBlockRegistry; import net.fabricmc.fabric.api.registry.FuelRegistry; import net.fabricmc.fabric.api.registry.TillableBlockRegistry; @@ -125,6 +126,7 @@ public void onInitialize() { registryInit(); PaintableData.init(); + CompostingData.init(CompostingChanceRegistry.INSTANCE::add); DefaultCorporeaMatchers.init(); PatchouliAPI.get().registerMultiblock(BuiltInRegistries.BLOCK.getKey(BotaniaBlocks.alfPortal), AlfheimPortalBlockEntity.MULTIBLOCK.get()); diff --git a/Forge/src/main/java/vazkii/botania/forge/ForgeCommonInitializer.java b/Forge/src/main/java/vazkii/botania/forge/ForgeCommonInitializer.java index 943c5a9d72..d8a7e559c5 100644 --- a/Forge/src/main/java/vazkii/botania/forge/ForgeCommonInitializer.java +++ b/Forge/src/main/java/vazkii/botania/forge/ForgeCommonInitializer.java @@ -27,6 +27,7 @@ import net.minecraft.world.item.*; import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.Blocks; +import net.minecraft.world.level.block.ComposterBlock; import net.minecraft.world.level.block.entity.AbstractFurnaceBlockEntity; import net.minecraft.world.level.block.entity.BlockEntity; import net.minecraft.world.level.block.state.BlockState; @@ -147,6 +148,7 @@ public void commonSetup(FMLCommonSetupEvent evt) { evt.enqueueWork(BotaniaBlocks::addDispenserBehaviours); BotaniaBlocks.addAxeStripping(); PaintableData.init(); + CompostingData.init((itemLike, chance) -> ComposterBlock.COMPOSTABLES.putIfAbsent(itemLike.asItem(), (float) chance)); DefaultCorporeaMatchers.init(); PatchouliAPI.get().registerMultiblock(BuiltInRegistries.BLOCK.getKey(BotaniaBlocks.alfPortal), AlfheimPortalBlockEntity.MULTIBLOCK.get()); diff --git a/Xplat/src/main/java/vazkii/botania/common/handler/CompostingData.java b/Xplat/src/main/java/vazkii/botania/common/handler/CompostingData.java new file mode 100644 index 0000000000..904f8c62d6 --- /dev/null +++ b/Xplat/src/main/java/vazkii/botania/common/handler/CompostingData.java @@ -0,0 +1,31 @@ +package vazkii.botania.common.handler; + +import net.minecraft.world.item.DyeColor; +import net.minecraft.world.level.ItemLike; + +import vazkii.botania.common.block.BotaniaBlocks; +import vazkii.botania.common.item.BotaniaItems; + +import java.util.function.BiConsumer; + +public class CompostingData { + public static void init(BiConsumer registrationMethod) { + // common vanilla composting chances: + final float chanceLowest = 0.3f; + final float chanceLow = 0.5f; + final float chanceMid = 0.65f; + final float chanceHigh = 0.85f; + // unused here: final float chanceHighest = 1.0f; + + // see https://github.com/VazkiiMods/Botania/issues/4263#issuecomment-1529130978 + for (final var dyeColor : DyeColor.values()) { + registrationMethod.accept(BotaniaItems.getPetal(dyeColor), chanceLowest); + registrationMethod.accept(BotaniaBlocks.getPetalBlock(dyeColor), chanceLow); + registrationMethod.accept(BotaniaBlocks.getFlower(dyeColor), chanceMid); + registrationMethod.accept(BotaniaBlocks.getDoubleFlower(dyeColor), chanceMid); + registrationMethod.accept(BotaniaBlocks.getMushroom(dyeColor), chanceMid); + } + + registrationMethod.accept(BotaniaBlocks.cellBlock, chanceHigh); + } +}