mirror of
https://github.com/GTNewHorizons/ForestryMC.git
synced 2026-11-26 06:43:05 +00:00
101 lines
2.9 KiB
Java
Executable File
101 lines
2.9 KiB
Java
Executable File
/*******************************************************************************
|
|
* 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
|
|
* http://www.gnu.org/licenses/lgpl-3.0.txt
|
|
*
|
|
* Various Contributors including, but not limited to:
|
|
* SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges
|
|
******************************************************************************/
|
|
package forestry.farming.logic;
|
|
|
|
import net.minecraft.block.state.IBlockState;
|
|
import net.minecraft.init.Items;
|
|
import net.minecraft.item.ItemStack;
|
|
import net.minecraft.util.NonNullList;
|
|
import net.minecraft.util.math.BlockPos;
|
|
import net.minecraft.world.World;
|
|
|
|
import forestry.api.farming.FarmDirection;
|
|
import forestry.api.farming.IFarmHousing;
|
|
import forestry.api.farming.IFarmProperties;
|
|
import forestry.api.farming.IFarmable;
|
|
import forestry.core.utils.BlockUtil;
|
|
|
|
public class FarmLogicCrops extends FarmLogicWatered {
|
|
|
|
public FarmLogicCrops(IFarmProperties properties, boolean isManual) {
|
|
super(properties, isManual);
|
|
}
|
|
|
|
@Override
|
|
public boolean isAcceptedGermling(ItemStack itemstack) {
|
|
for (IFarmable germling : getFarmables()) {
|
|
if (germling.isGermling(itemstack)) {
|
|
return true;
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
|
|
@Override
|
|
public boolean isAcceptedWindfall(ItemStack itemstack) {
|
|
for (IFarmable germling : getFarmables()) {
|
|
if (germling.isWindfall(itemstack)) {
|
|
return true;
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
|
|
@Override
|
|
public NonNullList<ItemStack> collect(World world, IFarmHousing farmHousing) {
|
|
NonNullList<ItemStack> products = produce;
|
|
produce = collectEntityItems(world, farmHousing, false);
|
|
return products;
|
|
}
|
|
|
|
@Override
|
|
protected boolean maintainCrops(World world, IFarmHousing farmHousing, BlockPos pos, FarmDirection direction, int extent) {
|
|
for (int i = 0; i < extent; i++) {
|
|
BlockPos position = translateWithOffset(pos, direction, i);
|
|
if(!world.isBlockLoaded(position)){
|
|
break;
|
|
}
|
|
|
|
IBlockState state = world.getBlockState(position);
|
|
if (!world.isAirBlock(position) && !BlockUtil.isReplaceableBlock(state, world, position)) {
|
|
continue;
|
|
}
|
|
|
|
IBlockState groundState = world.getBlockState(position.down());
|
|
if (isAcceptedSoil(groundState)) {
|
|
return trySetCrop(world, farmHousing, position, direction);
|
|
}
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
private boolean trySetCrop(World world, IFarmHousing farmHousing, BlockPos position, FarmDirection direction) {
|
|
for (IFarmable candidate : getFarmables()) {
|
|
if (farmHousing.plantGermling(candidate, world, position, direction)) {
|
|
return true;
|
|
}
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
@Override
|
|
public ItemStack getIconItemStack() {
|
|
return new ItemStack(Items.WHEAT);
|
|
}
|
|
|
|
@Override
|
|
public String getUnlocalizedName() {
|
|
return "for.farm.crops";
|
|
}
|
|
}
|