From d891e3b76fac0d28996600cba3824e005b47d73c Mon Sep 17 00:00:00 2001 From: Adrian Siekierka Date: Sat, 27 Nov 2021 10:43:41 +0100 Subject: [PATCH] Allow forbidding blocks from the default crop handler. --- common/buildcraft/BuildCraftCore.java | 2 ++ common/buildcraft/core/InterModComms.java | 14 ++++++++++++++ .../core/crops/CropHandlerPlantable.java | 13 +++++++++++-- 3 files changed, 27 insertions(+), 2 deletions(-) diff --git a/common/buildcraft/BuildCraftCore.java b/common/buildcraft/BuildCraftCore.java index 3386042c..aa93c16b 100644 --- a/common/buildcraft/BuildCraftCore.java +++ b/common/buildcraft/BuildCraftCore.java @@ -517,6 +517,8 @@ public class BuildCraftCore extends BuildCraftMod { CropManager.setDefaultHandler(new CropHandlerPlantable()); CropManager.registerHandler(new CropHandlerReeds()); + CropHandlerPlantable.forbidBlock(Blocks.reeds); + BuildCraftAPI.registerWorldProperty("replaceable", new WorldPropertyIsReplaceable()); BuildCraftAPI.registerWorldProperty("soft", new WorldPropertyIsSoft()); BuildCraftAPI.registerWorldProperty("wood", new WorldPropertyIsWood()); diff --git a/common/buildcraft/core/InterModComms.java b/common/buildcraft/core/InterModComms.java index 284ada06..08ca9248 100644 --- a/common/buildcraft/core/InterModComms.java +++ b/common/buildcraft/core/InterModComms.java @@ -13,6 +13,8 @@ import java.util.HashSet; import java.util.List; import java.util.Set; +import buildcraft.core.crops.CropHandlerPlantable; +import net.minecraft.block.Block; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagList; @@ -48,6 +50,8 @@ public final class InterModComms { processAssemblyRecipeRemoveIMC(event, m); } else if (m.key.equals("remove-refinery-recipe")) { processRefineryRecipeRemoveIMC(event, m); + } else if (m.key.equals("remove-plantable-block")) { + processPlantableBlockRemoveIMC(event, m); } else { for (IMCHandler h : handlers) { h.processIMCEvent(event, m); @@ -56,6 +60,16 @@ public final class InterModComms { } } + public static void processPlantableBlockRemoveIMC(IMCEvent event, IMCMessage msg) { + if (msg.isStringMessage()) { + Object blockObj = Block.blockRegistry.getObject(msg.getStringValue()); + if (blockObj instanceof Block) { + CropHandlerPlantable.forbidBlock((Block) blockObj); + } + BCLog.logger.info(String.format("Received a plantable block '%s' removal request from mod %s", msg.getStringValue(), msg.getSender())); + } + } + public static void processAssemblyRecipeRemoveIMC(IMCEvent event, IMCMessage msg) { if (msg.isStringMessage()) { AssemblyRecipeManager.INSTANCE.removeRecipe(msg.getStringValue()); diff --git a/common/buildcraft/core/crops/CropHandlerPlantable.java b/common/buildcraft/core/crops/CropHandlerPlantable.java index 3d632f69..710aba64 100644 --- a/common/buildcraft/core/crops/CropHandlerPlantable.java +++ b/common/buildcraft/core/crops/CropHandlerPlantable.java @@ -1,7 +1,10 @@ package buildcraft.core.crops; +import java.util.HashSet; import java.util.List; +import java.util.Set; +import com.google.common.collect.Sets; import net.minecraft.block.Block; import net.minecraft.block.BlockCrops; import net.minecraft.block.BlockDoublePlant; @@ -25,6 +28,12 @@ import buildcraft.core.lib.utils.BlockUtils; public class CropHandlerPlantable implements ICropHandler { + private static final Set FORBIDDEN_BLOCKS = new HashSet(); + + public static void forbidBlock(Block b) { + FORBIDDEN_BLOCKS.add(b); + } + @Override public boolean isSeed(ItemStack stack) { if (stack.getItem() instanceof IPlantable) { @@ -33,7 +42,7 @@ public class CropHandlerPlantable implements ICropHandler { if (stack.getItem() instanceof ItemBlock) { Block block = ((ItemBlock) stack.getItem()).field_150939_a; - if (block instanceof IPlantable && block != Blocks.reeds) { + if (block instanceof IPlantable && !FORBIDDEN_BLOCKS.contains(block)) { return true; } } @@ -63,7 +72,7 @@ public class CropHandlerPlantable implements ICropHandler { @Override public boolean isMature(IBlockAccess blockAccess, Block block, int meta, int x, int y, int z) { - if (block == null) { + if (block == null || FORBIDDEN_BLOCKS.contains(block)) { return false; } else if (block instanceof BlockTallGrass || block instanceof BlockMelon