From 778e64282f1e09c6a139138b7bfff864cae682a5 Mon Sep 17 00:00:00 2001 From: Ellpeck Date: Wed, 8 Feb 2023 21:13:24 +0100 Subject: [PATCH] disallow some more blocks from being plant boosted, and added the ablility to add more --- .../java/de/ellpeck/naturesaura/ModConfig.java | 14 ++++++++++++++ .../naturesaura/chunk/effect/PlantBoostEffect.java | 12 +++++++----- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/src/main/java/de/ellpeck/naturesaura/ModConfig.java b/src/main/java/de/ellpeck/naturesaura/ModConfig.java index 8296dda2..94d63479 100644 --- a/src/main/java/de/ellpeck/naturesaura/ModConfig.java +++ b/src/main/java/de/ellpeck/naturesaura/ModConfig.java @@ -4,6 +4,7 @@ import de.ellpeck.naturesaura.api.NaturesAuraAPI; import de.ellpeck.naturesaura.api.aura.type.BasicAuraType; import de.ellpeck.naturesaura.api.misc.WeightedOre; import de.ellpeck.naturesaura.chunk.effect.OreSpawnEffect; +import de.ellpeck.naturesaura.chunk.effect.PlantBoostEffect; import net.minecraft.resources.ResourceLocation; import net.minecraftforge.common.ForgeConfigSpec; import net.minecraftforge.common.ForgeConfigSpec.ConfigValue; @@ -20,6 +21,7 @@ public final class ModConfig { public ConfigValue> auraTypeOverrides; public ConfigValue> additionalOres; public ConfigValue> oreExceptions; + public ConfigValue> plantBoostExceptions; public ConfigValue> additionalProjectiles; public ConfigValue fieldCreatorRange; public ConfigValue auraToRFRatio; @@ -66,6 +68,10 @@ public final class ModConfig { .comment("Blocks that are exempt from being recognized as generatable ores for the passive ore generation effect. Each entry needs to be formatted as modid:block[prop1=value1,...] where block state properties are optional") .translation("config." + NaturesAura.MOD_ID + ".oreExceptions") .defineList("oreExceptions", Collections.emptyList(), s -> true); + this.plantBoostExceptions = builder + .comment("Blocks that are exept from being fertilized by the plant boost effect. Each entry needs to be formatted as modid:block") + .translation("config." + NaturesAura.MOD_ID + ".plantBoostExceptions") + .defineList("plantBoostExceptions", Collections.emptyList(), s -> true); this.additionalProjectiles = builder .comment("Additional projectile types that are allowed to be consumed by the projectile generator. Each entry needs to be formatted as entity_registry_name->aura_amount") .translation("config." + NaturesAura.MOD_ID + ".additionalProjectiles") @@ -227,6 +233,14 @@ public final class ModConfig { NaturesAura.LOGGER.warn("Error parsing oreExceptions", e); } + try { + for (String s : this.plantBoostExceptions.get()) + PlantBoostEffect.EXCEPTIONS.add(Objects.requireNonNull(ForgeRegistries.BLOCKS.getValue(new ResourceLocation(s)))); + } catch (Exception e) { + NaturesAura.LOGGER.warn("Error parsing plantBoostExceptions", e); + + } + try { for (String s : this.additionalProjectiles.get()) { var split = s.split("->"); diff --git a/src/main/java/de/ellpeck/naturesaura/chunk/effect/PlantBoostEffect.java b/src/main/java/de/ellpeck/naturesaura/chunk/effect/PlantBoostEffect.java index fe0dded8..169b6ed5 100644 --- a/src/main/java/de/ellpeck/naturesaura/chunk/effect/PlantBoostEffect.java +++ b/src/main/java/de/ellpeck/naturesaura/chunk/effect/PlantBoostEffect.java @@ -17,14 +17,16 @@ import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.Items; import net.minecraft.world.level.Level; -import net.minecraft.world.level.block.Blocks; -import net.minecraft.world.level.block.BonemealableBlock; -import net.minecraft.world.level.block.DoublePlantBlock; -import net.minecraft.world.level.block.TallGrassBlock; +import net.minecraft.world.level.block.*; import net.minecraft.world.level.chunk.LevelChunk; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + public class PlantBoostEffect implements IDrainSpotEffect { + public static final Set EXCEPTIONS = new HashSet<>(List.of(Blocks.GRASS_BLOCK, Blocks.MOSS_BLOCK, Blocks.GLOW_LICHEN, Blocks.SMALL_DRIPLEAF, Blocks.BIG_DRIPLEAF, Blocks.BIG_DRIPLEAF_STEM)); public static final ResourceLocation NAME = new ResourceLocation(NaturesAura.MOD_ID, "plant_boost"); private int amount; @@ -75,7 +77,7 @@ public class PlantBoostEffect implements IDrainSpotEffect { var state = level.getBlockState(plantPos); var block = state.getBlock(); - if (block instanceof BonemealableBlock growable && !(block instanceof DoublePlantBlock) && !(block instanceof TallGrassBlock) && block != Blocks.GRASS_BLOCK && block != Blocks.MOSS_BLOCK) { + if (block instanceof BonemealableBlock growable && !PlantBoostEffect.EXCEPTIONS.contains(block) && !(block instanceof DoublePlantBlock) && !(block instanceof TallGrassBlock)) { if (growable.isValidBonemealTarget(level, plantPos, state, false)) { try { growable.performBonemeal((ServerLevel) level, level.random, plantPos, state);