2014-05-02 21:31:20 +02:00
|
|
|
/*******************************************************************************
|
2014-08-07 08:29:25 +02:00
|
|
|
* Copyright (c) 2011-2014 SirSengir.
|
|
|
|
|
* All rights reserved. This program and the accompanying materials
|
|
|
|
|
* are made available under the terms of the GNU Lesser Public License v3
|
|
|
|
|
* which accompanies this distribution, and is available at
|
2014-08-07 02:56:58 -07:00
|
|
|
* http://www.gnu.org/licenses/lgpl-3.0.txt
|
2015-01-26 22:26:21 -08:00
|
|
|
*
|
2014-08-07 08:29:25 +02:00
|
|
|
* Various Contributors including, but not limited to:
|
|
|
|
|
* SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges
|
2014-05-02 21:31:20 +02:00
|
|
|
******************************************************************************/
|
|
|
|
|
package forestry.farming.logic;
|
|
|
|
|
|
2015-01-26 22:26:21 -08:00
|
|
|
import java.util.ArrayList;
|
|
|
|
|
|
2015-02-08 13:29:28 -08:00
|
|
|
import net.minecraft.block.Block;
|
2015-01-26 22:26:21 -08:00
|
|
|
import net.minecraft.item.ItemStack;
|
|
|
|
|
import net.minecraft.world.World;
|
|
|
|
|
|
|
|
|
|
import net.minecraftforge.common.util.ForgeDirection;
|
|
|
|
|
|
2014-05-02 21:31:20 +02:00
|
|
|
import forestry.api.farming.IFarmHousing;
|
|
|
|
|
import forestry.api.farming.IFarmable;
|
2014-10-05 03:26:00 -07:00
|
|
|
import forestry.core.utils.BlockUtil;
|
2014-05-02 21:31:20 +02:00
|
|
|
import forestry.core.utils.StackUtils;
|
2014-12-19 23:16:15 -08:00
|
|
|
import forestry.core.vect.Vect;
|
2015-01-17 15:51:25 -08:00
|
|
|
import forestry.core.vect.VectUtil;
|
2015-02-08 13:29:28 -08:00
|
|
|
import forestry.farming.gadgets.StructureLogicFarm;
|
2015-01-17 15:51:25 -08:00
|
|
|
|
2014-10-05 03:26:00 -07:00
|
|
|
public abstract class FarmLogicHomogeneous extends FarmLogic {
|
2014-05-02 21:31:20 +02:00
|
|
|
|
|
|
|
|
protected final ItemStack[] resource;
|
2015-02-08 13:29:28 -08:00
|
|
|
protected final ItemStack soilBlock;
|
2014-05-02 21:31:20 +02:00
|
|
|
protected final IFarmable[] germlings;
|
|
|
|
|
|
|
|
|
|
ArrayList<ItemStack> produce = new ArrayList<ItemStack>();
|
|
|
|
|
|
2015-02-08 13:29:28 -08:00
|
|
|
public FarmLogicHomogeneous(IFarmHousing housing, ItemStack[] resource, ItemStack soilBlock, IFarmable[] germlings) {
|
2014-05-02 21:31:20 +02:00
|
|
|
super(housing);
|
|
|
|
|
this.resource = resource;
|
2015-02-08 13:29:28 -08:00
|
|
|
this.soilBlock = soilBlock;
|
2014-05-02 21:31:20 +02:00
|
|
|
this.germlings = germlings;
|
|
|
|
|
}
|
|
|
|
|
|
2015-02-08 13:29:28 -08:00
|
|
|
public boolean isAcceptedSoil(ItemStack itemStack) {
|
|
|
|
|
return StackUtils.isIdenticalItem(soilBlock, itemStack);
|
2014-10-05 03:26:00 -07:00
|
|
|
}
|
|
|
|
|
|
2014-05-02 21:31:20 +02:00
|
|
|
@Override
|
|
|
|
|
public boolean isAcceptedResource(ItemStack itemstack) {
|
|
|
|
|
return resource[0].isItemEqual(itemstack);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public boolean isAcceptedGermling(ItemStack itemstack) {
|
2015-01-26 22:26:21 -08:00
|
|
|
for (IFarmable germling : germlings) {
|
|
|
|
|
if (germling.isGermling(itemstack)) {
|
2014-05-02 21:31:20 +02:00
|
|
|
return true;
|
2015-01-26 22:26:21 -08:00
|
|
|
}
|
|
|
|
|
}
|
2014-05-02 21:31:20 +02:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public boolean isWindfall(ItemStack itemstack) {
|
2015-01-26 22:26:21 -08:00
|
|
|
for (IFarmable germling : germlings) {
|
|
|
|
|
if (germling.isWindfall(itemstack)) {
|
2014-05-02 21:31:20 +02:00
|
|
|
return true;
|
2015-01-26 22:26:21 -08:00
|
|
|
}
|
|
|
|
|
}
|
2014-05-02 21:31:20 +02:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public boolean cultivate(int x, int y, int z, ForgeDirection direction, int extent) {
|
|
|
|
|
|
2015-01-26 22:26:21 -08:00
|
|
|
if (maintainSoil(x, y, z, direction, extent)) {
|
2014-05-02 21:31:20 +02:00
|
|
|
return true;
|
2015-01-26 22:26:21 -08:00
|
|
|
}
|
2014-05-02 21:31:20 +02:00
|
|
|
|
2015-01-26 22:26:21 -08:00
|
|
|
if (maintainGermlings(x, y + 1, z, direction, extent)) {
|
2014-05-02 21:31:20 +02:00
|
|
|
return true;
|
2015-01-26 22:26:21 -08:00
|
|
|
}
|
2014-05-02 21:31:20 +02:00
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private boolean maintainSoil(int x, int yGround, int z, ForgeDirection direction, int extent) {
|
2015-01-26 22:26:21 -08:00
|
|
|
if (!housing.hasResources(resource)) {
|
2014-05-02 21:31:20 +02:00
|
|
|
return false;
|
2015-01-26 22:26:21 -08:00
|
|
|
}
|
2014-05-02 21:31:20 +02:00
|
|
|
|
2015-01-17 15:51:25 -08:00
|
|
|
World world = getWorld();
|
|
|
|
|
|
2014-10-05 03:26:00 -07:00
|
|
|
for (int i = 0; i < extent; i++) {
|
2014-05-02 21:31:20 +02:00
|
|
|
Vect position = translateWithOffset(x, yGround, z, direction, i);
|
2015-02-08 13:29:28 -08:00
|
|
|
Block soil = VectUtil.getBlock(world, position);
|
2014-05-02 21:31:20 +02:00
|
|
|
|
2015-02-08 13:29:28 -08:00
|
|
|
if (StructureLogicFarm.bricks.contains(soil)) {
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ItemStack soilStack = VectUtil.getAsItemStack(world, position);
|
|
|
|
|
if (isAcceptedSoil(soilStack) || !canBreakSoil(world, position)) {
|
2014-10-05 03:26:00 -07:00
|
|
|
continue;
|
2015-01-26 22:26:21 -08:00
|
|
|
}
|
2014-10-05 03:26:00 -07:00
|
|
|
|
2015-02-08 13:29:28 -08:00
|
|
|
Vect platformPosition = position.add(0, -1, 0);
|
|
|
|
|
Block platformBlock = VectUtil.getBlock(world, platformPosition);
|
|
|
|
|
|
|
|
|
|
if (!StructureLogicFarm.bricks.contains(platformBlock)) {
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2015-01-17 15:51:25 -08:00
|
|
|
produce.addAll(BlockUtil.getBlockDrops(world, position));
|
2014-10-05 03:26:00 -07:00
|
|
|
|
2015-02-08 13:29:28 -08:00
|
|
|
setBlock(position, StackUtils.getBlock(soilBlock), soilBlock.getItemDamage());
|
2014-05-02 21:31:20 +02:00
|
|
|
housing.removeResources(resource);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected abstract boolean maintainGermlings(int x, int ySaplings, int z, ForgeDirection direction, int extent);
|
|
|
|
|
}
|