make the planter robot handle any IPlantable item/block and sugarcane, fixes #2370
This commit is contained in:
parent
7d9892bc13
commit
39410dc5af
1 changed files with 48 additions and 18 deletions
|
@ -12,24 +12,25 @@ import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
|
||||||
import net.minecraft.block.Block;
|
import net.minecraft.block.Block;
|
||||||
import net.minecraft.block.BlockDirt;
|
import net.minecraft.init.Blocks;
|
||||||
import net.minecraft.block.BlockGrass;
|
import net.minecraft.item.ItemBlock;
|
||||||
import net.minecraft.item.ItemSeeds;
|
import net.minecraft.item.ItemReed;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.nbt.NBTTagCompound;
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
|
|
||||||
|
import net.minecraftforge.common.IPlantable;
|
||||||
|
import net.minecraftforge.common.util.ForgeDirection;
|
||||||
|
|
||||||
import buildcraft.api.boards.RedstoneBoardRobot;
|
import buildcraft.api.boards.RedstoneBoardRobot;
|
||||||
import buildcraft.api.boards.RedstoneBoardRobotNBT;
|
import buildcraft.api.boards.RedstoneBoardRobotNBT;
|
||||||
import buildcraft.api.core.BlockIndex;
|
import buildcraft.api.core.BlockIndex;
|
||||||
import buildcraft.api.core.BuildCraftAPI;
|
|
||||||
import buildcraft.api.robots.AIRobot;
|
import buildcraft.api.robots.AIRobot;
|
||||||
import buildcraft.api.robots.EntityRobotBase;
|
import buildcraft.api.robots.EntityRobotBase;
|
||||||
import buildcraft.core.inventory.filters.ArrayStackFilter;
|
import buildcraft.core.inventory.filters.ArrayStackFilter;
|
||||||
import buildcraft.core.inventory.filters.ArrayStackOrListFilter;
|
import buildcraft.core.inventory.filters.ArrayStackOrListFilter;
|
||||||
import buildcraft.core.inventory.filters.CompositeFilter;
|
import buildcraft.core.inventory.filters.CompositeFilter;
|
||||||
import buildcraft.core.inventory.filters.IStackFilter;
|
import buildcraft.core.inventory.filters.IStackFilter;
|
||||||
import buildcraft.core.inventory.filters.OreStackFilter;
|
|
||||||
import buildcraft.core.robots.AIRobotFetchAndEquipItemStack;
|
import buildcraft.core.robots.AIRobotFetchAndEquipItemStack;
|
||||||
import buildcraft.core.robots.AIRobotGotoBlock;
|
import buildcraft.core.robots.AIRobotGotoBlock;
|
||||||
import buildcraft.core.robots.AIRobotGotoRandomGroundBlock;
|
import buildcraft.core.robots.AIRobotGotoRandomGroundBlock;
|
||||||
|
@ -42,7 +43,7 @@ import buildcraft.silicon.statements.ActionRobotFilter;
|
||||||
|
|
||||||
public class BoardRobotPlanter extends RedstoneBoardRobot {
|
public class BoardRobotPlanter extends RedstoneBoardRobot {
|
||||||
|
|
||||||
private IStackFilter stackFilter = new CompositeFilter(new OreStackFilter("treeSapling"), new SeedFilter());
|
private IStackFilter stackFilter = new CompositeFilter(new PlantableFilter(), new ReedFilter());
|
||||||
private BlockIndex blockFound;
|
private BlockIndex blockFound;
|
||||||
|
|
||||||
public BoardRobotPlanter(EntityRobotBase iRobot) {
|
public BoardRobotPlanter(EntityRobotBase iRobot) {
|
||||||
|
@ -81,25 +82,40 @@ public class BoardRobotPlanter extends RedstoneBoardRobot {
|
||||||
startDelegateAI(new AIRobotFetchAndEquipItemStack(robot, stackFilter));
|
startDelegateAI(new AIRobotFetchAndEquipItemStack(robot, stackFilter));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (robot.getHeldItem().getItem() instanceof ItemSeeds) {
|
final ItemStack itemStack = robot.getHeldItem();
|
||||||
startDelegateAI(new AIRobotSearchBlock(robot, new IBlockFilter() {
|
IBlockFilter blockFilter;
|
||||||
|
if (itemStack.getItem() instanceof ItemReed) {
|
||||||
|
blockFilter = new IBlockFilter() {
|
||||||
@Override
|
@Override
|
||||||
public boolean matches(World world, int x, int y, int z) {
|
public boolean matches(World world, int x, int y, int z) {
|
||||||
return BuildCraftAPI.isFarmlandProperty.get(world, x, y, z)
|
return world.getBlock(x, y, z).canSustainPlant(world, x, y, z, ForgeDirection.UP, (IPlantable) Blocks.reeds)
|
||||||
|
&& world.getBlock(x, y, z) != Blocks.reeds
|
||||||
&& !robot.getRegistry().isTaken(new ResourceIdBlock(x, y, z))
|
&& !robot.getRegistry().isTaken(new ResourceIdBlock(x, y, z))
|
||||||
&& isAirAbove(world, x, y, z);
|
&& isAirAbove(world, x, y, z);
|
||||||
}
|
}
|
||||||
}));
|
};
|
||||||
} else {
|
} else if (itemStack.getItem() instanceof ItemBlock) {
|
||||||
startDelegateAI(new AIRobotGotoRandomGroundBlock(robot, 100, new IBlockFilter() {
|
final Block plantBlock = ((ItemBlock) itemStack.getItem()).field_150939_a;
|
||||||
|
blockFilter = new IBlockFilter() {
|
||||||
@Override
|
@Override
|
||||||
public boolean matches(World world, int x, int y, int z) {
|
public boolean matches(World world, int x, int y, int z) {
|
||||||
Block b = robot.worldObj.getBlock(x, y, z);
|
return world.getBlock(x, y, z).canSustainPlant(world, x, y, z, ForgeDirection.UP, (IPlantable) plantBlock)
|
||||||
|
&& world.getBlock(x, y, z) != plantBlock
|
||||||
return b instanceof BlockDirt || b instanceof BlockGrass;
|
&& !robot.getRegistry().isTaken(new ResourceIdBlock(x, y, z))
|
||||||
|
&& isAirAbove(world, x, y, z);
|
||||||
}
|
}
|
||||||
}, robot.getZoneToWork()));
|
};
|
||||||
|
} else {
|
||||||
|
blockFilter = new IBlockFilter() {
|
||||||
|
@Override
|
||||||
|
public boolean matches(World world, int x, int y, int z) {
|
||||||
|
return world.getBlock(x, y, z).canSustainPlant(world, x, y, z, ForgeDirection.UP, (IPlantable) itemStack.getItem())
|
||||||
|
&& !robot.getRegistry().isTaken(new ResourceIdBlock(x, y, z))
|
||||||
|
&& isAirAbove(world, x, y, z);
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
startDelegateAI(new AIRobotSearchBlock(robot, blockFilter));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -124,6 +140,7 @@ public class BoardRobotPlanter extends RedstoneBoardRobot {
|
||||||
}
|
}
|
||||||
|
|
||||||
blockFound = gotoBlock.blockFound;
|
blockFound = gotoBlock.blockFound;
|
||||||
|
gotoBlock.path.removeLast();
|
||||||
startDelegateAI(new AIRobotGotoBlock(robot, gotoBlock.path));
|
startDelegateAI(new AIRobotGotoBlock(robot, gotoBlock.path));
|
||||||
} else {
|
} else {
|
||||||
startDelegateAI(new AIRobotGotoSleep(robot));
|
startDelegateAI(new AIRobotGotoSleep(robot));
|
||||||
|
@ -137,10 +154,23 @@ public class BoardRobotPlanter extends RedstoneBoardRobot {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class SeedFilter implements IStackFilter {
|
private static class PlantableFilter implements IStackFilter {
|
||||||
@Override
|
@Override
|
||||||
public boolean matches(ItemStack stack) {
|
public boolean matches(ItemStack stack) {
|
||||||
return stack.getItem() instanceof ItemSeeds;
|
if (stack.getItem() instanceof IPlantable) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (stack.getItem() instanceof ItemBlock && ((ItemBlock) stack.getItem()).field_150939_a instanceof IPlantable) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class ReedFilter implements IStackFilter {
|
||||||
|
@Override
|
||||||
|
public boolean matches(ItemStack stack) {
|
||||||
|
return stack.getItem() instanceof ItemReed;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue