Allow forbidding blocks from the default crop handler.

This commit is contained in:
Adrian Siekierka 2021-11-27 10:43:41 +01:00
parent f4a4efce06
commit d891e3b76f
3 changed files with 27 additions and 2 deletions

View file

@ -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());

View file

@ -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());

View file

@ -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<Block> FORBIDDEN_BLOCKS = new HashSet<Block>();
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