mirror of
https://github.com/GTNewHorizons/ForestryMC.git
synced 2026-11-27 23:33:00 +00:00
Improve Farm Logic System and add ring farm layout
This commit is contained in:
1 parent
521514f3d2
commit
10fec50457
53 files changed
+1019
-534
No files matched your search
@@ -10,11 +10,7 @@
|
||||
******************************************************************************/
|
||||
package forestry.farming.logic;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Stack;
|
||||
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.init.Items;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.NonNullList;
|
||||
@@ -22,33 +18,20 @@ import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import forestry.api.farming.FarmDirection;
|
||||
import forestry.api.farming.ICrop;
|
||||
import forestry.api.farming.IFarmHousing;
|
||||
import forestry.api.farming.IFarmInstance;
|
||||
import forestry.api.farming.IFarmable;
|
||||
import forestry.core.utils.BlockUtil;
|
||||
import forestry.farming.FarmRegistry;
|
||||
|
||||
public class FarmLogicCrops extends FarmLogicWatered {
|
||||
private final Iterable<IFarmable> seeds;
|
||||
|
||||
public FarmLogicCrops() {
|
||||
this(FarmRegistry.getInstance().getFarmables("farmCrops"));
|
||||
}
|
||||
|
||||
protected FarmLogicCrops(Iterable<IFarmable> seeds) {
|
||||
super(new ItemStack(Blocks.DIRT), Blocks.FARMLAND.getDefaultState());
|
||||
|
||||
this.seeds = seeds;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAcceptedGround(IBlockState blockState) {
|
||||
return super.isAcceptedGround(blockState) || blockState.getBlock() == Blocks.FARMLAND;
|
||||
public FarmLogicCrops(IFarmInstance instance, boolean isManual) {
|
||||
super(instance, isManual);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAcceptedGermling(ItemStack itemstack) {
|
||||
for (IFarmable germling : seeds) {
|
||||
for (IFarmable germling : getFarmables()) {
|
||||
if (germling.isGermling(itemstack)) {
|
||||
return true;
|
||||
}
|
||||
@@ -58,7 +41,7 @@ public class FarmLogicCrops extends FarmLogicWatered {
|
||||
|
||||
@Override
|
||||
public boolean isAcceptedWindfall(ItemStack itemstack) {
|
||||
for (IFarmable germling : seeds) {
|
||||
for (IFarmable germling : getFarmables()) {
|
||||
if (germling.isWindfall(itemstack)) {
|
||||
return true;
|
||||
}
|
||||
@@ -83,7 +66,7 @@ public class FarmLogicCrops extends FarmLogicWatered {
|
||||
}
|
||||
|
||||
IBlockState groundState = world.getBlockState(position.down());
|
||||
if (isAcceptedGround(groundState)) {
|
||||
if (isAcceptedSoil(groundState)) {
|
||||
return trySetCrop(world, farmHousing, position, direction);
|
||||
}
|
||||
}
|
||||
@@ -92,7 +75,7 @@ public class FarmLogicCrops extends FarmLogicWatered {
|
||||
}
|
||||
|
||||
private boolean trySetCrop(World world, IFarmHousing farmHousing, BlockPos position, FarmDirection direction) {
|
||||
for (IFarmable candidate : seeds) {
|
||||
for (IFarmable candidate : getFarmables()) {
|
||||
if (farmHousing.plantGermling(candidate, world, position, direction)) {
|
||||
return true;
|
||||
}
|
||||
@@ -101,23 +84,6 @@ public class FarmLogicCrops extends FarmLogicWatered {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<ICrop> harvest(World world, BlockPos pos, FarmDirection direction, int extent) {
|
||||
Stack<ICrop> crops = new Stack<>();
|
||||
for (int i = 0; i < extent; i++) {
|
||||
BlockPos position = translateWithOffset(pos.up(), direction, i);
|
||||
IBlockState blockState = world.getBlockState(position);
|
||||
for (IFarmable seed : seeds) {
|
||||
ICrop crop = seed.getCropAt(world, position, blockState);
|
||||
if (crop != null) {
|
||||
crops.push(crop);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return crops;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getIconItemStack() {
|
||||
return new ItemStack(Items.WHEAT);
|
||||
|
||||
Reference in new issue
Block a user