mirror of
https://github.com/GTNewHorizons/ForestryMC.git
synced 2026-11-22 12:59:44 +00:00
Fix #1186 Begin farm cleanup and testing
This commit is contained in:
1 parent
1707573f7d
commit
afbde2d735
64 files changed
+1055
-1424
No files matched your search
@@ -5,8 +5,10 @@
|
||||
******************************************************************************/
|
||||
package forestry.api.farming;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import com.google.common.collect.HashMultimap;
|
||||
import com.google.common.collect.Multimap;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
public class Farmables {
|
||||
/**
|
||||
@@ -14,6 +16,7 @@ public class Farmables {
|
||||
*
|
||||
* Identifiers: farmArboreal farmWheat farmGourd farmInfernal farmPoales farmSucculentes farmVegetables farmShroom
|
||||
*/
|
||||
public static HashMap<String, Collection<IFarmable>> farmables = new HashMap<>();
|
||||
@Nonnull
|
||||
public static final Multimap<String, IFarmable> farmables = HashMultimap.create();
|
||||
|
||||
}
|
||||
@@ -21,9 +21,6 @@ public interface IFarmHousing extends IErrorLogicSource {
|
||||
|
||||
Vec3i getOffset();
|
||||
|
||||
/** Must not be named "getWorld" to avoid SpecialSource issue https://github.com/md-5/SpecialSource/issues/12 */
|
||||
World getWorldObj();
|
||||
|
||||
/**
|
||||
* @return true if any work was done, false otherwise.
|
||||
*/
|
||||
|
||||
@@ -8,8 +8,9 @@ package forestry.api.farming;
|
||||
import java.util.Collection;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
@@ -24,11 +25,11 @@ public interface IFarmLogic {
|
||||
|
||||
boolean isAcceptedGermling(ItemStack itemstack);
|
||||
|
||||
Collection<ItemStack> collect();
|
||||
Collection<ItemStack> collect(World world, IFarmHousing farmHousing);
|
||||
|
||||
boolean cultivate(BlockPos pos, FarmDirection direction, int extent);
|
||||
boolean cultivate(World world, IFarmHousing farmHousing, BlockPos pos, FarmDirection direction, int extent);
|
||||
|
||||
Collection<ICrop> harvest(BlockPos pos, FarmDirection direction, int extent);
|
||||
Collection<ICrop> harvest(World world, BlockPos pos, FarmDirection direction, int extent);
|
||||
|
||||
IFarmLogic setManual(boolean manual);
|
||||
|
||||
|
||||
@@ -5,6 +5,9 @@
|
||||
******************************************************************************/
|
||||
package forestry.api.farming;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
@@ -23,7 +26,8 @@ public interface IFarmable {
|
||||
/**
|
||||
* @return {@link ICrop} if the block at the given location is a harvestable and mature crop, null otherwise.
|
||||
*/
|
||||
ICrop getCropAt(World world, BlockPos pos);
|
||||
@Nullable
|
||||
ICrop getCropAt(World world, BlockPos pos, IBlockState blockState);
|
||||
|
||||
/**
|
||||
* @return true if the item is a valid germling (plantable sapling, seed, etc.) for this type.
|
||||
|
||||
@@ -63,6 +63,7 @@ import forestry.core.config.Constants;
|
||||
import forestry.core.genetics.SpeciesRoot;
|
||||
import forestry.core.tiles.TileUtil;
|
||||
import forestry.core.utils.BlockUtil;
|
||||
import forestry.core.utils.GeneticsUtil;
|
||||
|
||||
public class TreeRoot extends SpeciesRoot implements ITreeRoot {
|
||||
|
||||
@@ -153,6 +154,7 @@ public class TreeRoot extends SpeciesRoot implements ITreeRoot {
|
||||
|
||||
@Override
|
||||
public ITree getMember(ItemStack itemstack) {
|
||||
itemstack = GeneticsUtil.convertSaplingToGeneticEquivalent(itemstack);
|
||||
if (!isMember(itemstack)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -39,8 +39,8 @@ import forestry.api.multiblock.MultiblockManager;
|
||||
import forestry.api.recipes.RecipeManagers;
|
||||
import forestry.api.storage.ICrateRegistry;
|
||||
import forestry.api.storage.StorageManager;
|
||||
import forestry.core.blocks.BlockBogEarth;
|
||||
import forestry.core.blocks.BlockRegistryCore;
|
||||
import forestry.core.blocks.BlockSoil;
|
||||
import forestry.core.blocks.EnumResourceType;
|
||||
import forestry.core.circuits.CircuitRegistry;
|
||||
import forestry.core.circuits.SolderManager;
|
||||
@@ -155,8 +155,8 @@ public class PluginCore extends BlankForestryPlugin {
|
||||
crateRegistry.registerCrateUsingOreDict(items.ingotBronze);
|
||||
|
||||
// forestry blocks
|
||||
crateRegistry.registerCrate(blocks.soil.get(BlockSoil.SoilType.HUMUS, 1));
|
||||
crateRegistry.registerCrate(blocks.soil.get(BlockSoil.SoilType.BOG_EARTH, 1));
|
||||
crateRegistry.registerCrate(blocks.humus);
|
||||
crateRegistry.registerCrate(blocks.bogEarth.get(BlockBogEarth.SoilType.BOG_EARTH, 1));
|
||||
|
||||
// vanilla items
|
||||
crateRegistry.registerCrate(Items.WHEAT);
|
||||
@@ -313,26 +313,26 @@ public class PluginCore extends BlankForestryPlugin {
|
||||
// Humus
|
||||
int humusCompostAmount = ForestryAPI.activeMode.getIntegerSetting("recipe.output.humus.compost");
|
||||
if (humusCompostAmount > 0) {
|
||||
ItemStack humus = blocks.soil.get(BlockSoil.SoilType.HUMUS, humusCompostAmount);
|
||||
ItemStack humus = new ItemStack(blocks.humus, humusCompostAmount);
|
||||
RecipeUtil.addRecipe(humus, "###", "#X#", "###", '#', Blocks.DIRT, 'X', items.fertilizerBio);
|
||||
}
|
||||
|
||||
int humusFertilizerAmount = ForestryAPI.activeMode.getIntegerSetting("recipe.output.humus.fertilizer");
|
||||
if (humusFertilizerAmount > 0) {
|
||||
ItemStack humus = blocks.soil.get(BlockSoil.SoilType.HUMUS, humusFertilizerAmount);
|
||||
ItemStack humus = new ItemStack(blocks.humus, humusFertilizerAmount);
|
||||
RecipeUtil.addRecipe(humus, "###", "#X#", "###", '#', Blocks.DIRT, 'X', items.fertilizerCompound);
|
||||
}
|
||||
|
||||
// Bog earth
|
||||
int bogEarthOutputBucket = ForestryAPI.activeMode.getIntegerSetting("recipe.output.bogearth.bucket");
|
||||
if (bogEarthOutputBucket > 0) {
|
||||
ItemStack bogEarth = blocks.soil.get(BlockSoil.SoilType.BOG_EARTH, bogEarthOutputBucket);
|
||||
ItemStack bogEarth = blocks.bogEarth.get(BlockBogEarth.SoilType.BOG_EARTH, bogEarthOutputBucket);
|
||||
RecipeUtil.addRecipe(bogEarth, "#Y#", "YXY", "#Y#", '#', Blocks.DIRT, 'X', Items.WATER_BUCKET, 'Y', "sand");
|
||||
}
|
||||
|
||||
int bogEarthOutputCan = ForestryAPI.activeMode.getIntegerSetting("recipe.output.bogearth.can");
|
||||
if (bogEarthOutputCan > 0) {
|
||||
ItemStack bogEarth = blocks.soil.get(BlockSoil.SoilType.BOG_EARTH, bogEarthOutputCan);
|
||||
ItemStack bogEarth = blocks.bogEarth.get(BlockBogEarth.SoilType.BOG_EARTH, bogEarthOutputCan);
|
||||
ItemStack canWater = PluginFluids.items.getContainer(EnumContainerType.CAN, Fluids.WATER).getItemStack();
|
||||
ItemStack waxCapsuleWater = PluginFluids.items.getContainer(EnumContainerType.CAPSULE, Fluids.WATER).getItemStack();
|
||||
ItemStack refractoryWater = PluginFluids.items.getContainer(EnumContainerType.REFRACTORY, Fluids.WATER).getItemStack();
|
||||
|
||||
@@ -0,0 +1,198 @@
|
||||
/*******************************************************************************
|
||||
* 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.core.blocks;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.SoundType;
|
||||
import net.minecraft.block.material.Material;
|
||||
import net.minecraft.block.properties.PropertyInteger;
|
||||
import net.minecraft.block.state.BlockStateContainer;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.creativetab.CreativeTabs;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.IStringSerializable;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.IBlockAccess;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import net.minecraftforge.common.IPlantable;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
import forestry.api.core.IItemModelRegister;
|
||||
import forestry.api.core.IModelManager;
|
||||
import forestry.core.CreativeTabForestry;
|
||||
import forestry.core.PluginCore;
|
||||
import forestry.core.config.Constants;
|
||||
|
||||
/**
|
||||
* bog earth, which becomes peat
|
||||
*/
|
||||
public class BlockBogEarth extends Block implements IItemModelRegister, IBlockWithMeta {
|
||||
private static final int maturityDelimiter = 3; //maturity at which bogEarth becomes peat
|
||||
public static final PropertyInteger MATURITY = PropertyInteger.create("maturity", 0, maturityDelimiter);
|
||||
|
||||
public enum SoilType implements IStringSerializable {
|
||||
BOG_EARTH("bog_earth"),
|
||||
PEAT("peat");
|
||||
|
||||
@Nonnull
|
||||
private final String name;
|
||||
|
||||
SoilType(@Nonnull String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public static SoilType fromMaturity(int maturity) {
|
||||
if (maturity >= maturityDelimiter) {
|
||||
return PEAT;
|
||||
} else {
|
||||
return BOG_EARTH;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public BlockBogEarth() {
|
||||
super(Material.GROUND);
|
||||
setTickRandomly(true);
|
||||
setHardness(0.5f);
|
||||
setSoundType(SoundType.GROUND);
|
||||
setCreativeTab(CreativeTabForestry.tabForestry);
|
||||
|
||||
setDefaultState(this.blockState.getBaseState().withProperty(MATURITY, 0));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMetaFromState(IBlockState state) {
|
||||
return state.getValue(MATURITY);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IBlockState getStateFromMeta(int meta) {
|
||||
return getDefaultState().withProperty(MATURITY, meta);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected BlockStateContainer createBlockState() {
|
||||
return new BlockStateContainer(this, MATURITY);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int tickRate(World world) {
|
||||
return 500;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ItemStack> getDrops(IBlockAccess world, BlockPos pos, IBlockState state, int fortune) {
|
||||
List<ItemStack> ret = new ArrayList<>();
|
||||
|
||||
Integer maturity = state.getValue(MATURITY);
|
||||
SoilType type = SoilType.fromMaturity(maturity);
|
||||
|
||||
if (type == SoilType.PEAT) {
|
||||
ret.add(PluginCore.items.peat.getItemStack());
|
||||
ret.add(new ItemStack(Blocks.DIRT));
|
||||
} else {
|
||||
ret.add(new ItemStack(this, 1, SoilType.BOG_EARTH.ordinal()));
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateTick(World world, BlockPos pos, IBlockState state, Random rand) {
|
||||
if (world.isRemote || world.rand.nextInt(13) != 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
Integer maturity = state.getValue(MATURITY);
|
||||
SoilType type = SoilType.fromMaturity(maturity);
|
||||
|
||||
if (type == SoilType.BOG_EARTH) {
|
||||
if (isMoistened(world, pos)) {
|
||||
world.setBlockState(pos, state.withProperty(MATURITY, maturity + 1), Constants.FLAG_BLOCK_SYNCH);
|
||||
world.markBlockRangeForRenderUpdate(pos, pos);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean isMoistened(World world, BlockPos pos) {
|
||||
for (BlockPos.MutableBlockPos waterPos : BlockPos.getAllInBoxMutable(pos.add(-2, -2, -2), pos.add(2, 2, 2))) {
|
||||
IBlockState blockState = world.getBlockState(waterPos);
|
||||
Block block = blockState.getBlock();
|
||||
if (block == Blocks.WATER || block == Blocks.FLOWING_WATER) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canSustainPlant(IBlockState state, IBlockAccess world, BlockPos pos, EnumFacing direction, IPlantable plantable) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canSilkHarvest(World world, BlockPos pos, IBlockState state, EntityPlayer player) {
|
||||
return false;
|
||||
}
|
||||
|
||||
public static SoilType getTypeFromState(IBlockState state) {
|
||||
Integer maturity = state.getValue(MATURITY);
|
||||
return SoilType.fromMaturity(maturity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getSubBlocks(Item item, CreativeTabs par2CreativeTabs, List<ItemStack> itemList) {
|
||||
itemList.add(new ItemStack(this, 1, 0));
|
||||
}
|
||||
|
||||
/* MODELS */
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void registerModel(Item item, IModelManager manager) {
|
||||
manager.registerItemModel(item, 0, "soil/bog");
|
||||
manager.registerItemModel(item, 1, "soil/bog");
|
||||
manager.registerItemModel(item, 2, "soil/bog");
|
||||
manager.registerItemModel(item, 3, "soil/peat");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getNameFromMeta(int meta) {
|
||||
SoilType type = SoilType.fromMaturity(meta);
|
||||
return type.getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int damageDropped(IBlockState state) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public ItemStack get(SoilType soilType, int amount) {
|
||||
return new ItemStack(this, amount, soilType.ordinal());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,154 @@
|
||||
package forestry.core.blocks;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockLog;
|
||||
import net.minecraft.block.IGrowable;
|
||||
import net.minecraft.block.SoundType;
|
||||
import net.minecraft.block.material.Material;
|
||||
import net.minecraft.block.properties.PropertyInteger;
|
||||
import net.minecraft.block.state.BlockStateContainer;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.creativetab.CreativeTabs;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.IBlockAccess;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import net.minecraftforge.common.EnumPlantType;
|
||||
import net.minecraftforge.common.IPlantable;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
import forestry.api.core.IItemModelRegister;
|
||||
import forestry.api.core.IModelManager;
|
||||
import forestry.core.CreativeTabForestry;
|
||||
import forestry.core.config.Constants;
|
||||
|
||||
public class BlockHumus extends Block implements IItemModelRegister {
|
||||
private static final int degradeDelimiter = 3;
|
||||
public static final PropertyInteger DEGRADE = PropertyInteger.create("degrade", 0, degradeDelimiter); // degradation level of humus
|
||||
|
||||
public BlockHumus() {
|
||||
super(Material.GROUND);
|
||||
setTickRandomly(true);
|
||||
setHardness(0.5f);
|
||||
setSoundType(SoundType.GROUND);
|
||||
setCreativeTab(CreativeTabForestry.tabForestry);
|
||||
|
||||
setDefaultState(this.blockState.getBaseState().withProperty(DEGRADE, 0));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMetaFromState(IBlockState state) {
|
||||
return state.getValue(DEGRADE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IBlockState getStateFromMeta(int meta) {
|
||||
return getDefaultState().withProperty(DEGRADE, meta);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected BlockStateContainer createBlockState() {
|
||||
return new BlockStateContainer(this, DEGRADE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int damageDropped(IBlockState state) {
|
||||
return state.getValue(DEGRADE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int tickRate(World world) {
|
||||
return 500;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ItemStack> getDrops(IBlockAccess world, BlockPos pos, IBlockState state, int fortune) {
|
||||
return Collections.singletonList(new ItemStack(Blocks.DIRT));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateTick(World world, BlockPos pos, IBlockState state, Random rand) {
|
||||
if (world.isRemote || world.rand.nextInt(140) != 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (isEnrooted(world, pos)) {
|
||||
degradeSoil(world, pos);
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean isEnrooted(World world, BlockPos pos) {
|
||||
for (int i = -1; i < 2; i++) {
|
||||
for (int j = -1; j < 2; j++) {
|
||||
if (i == 0 && j == 0) {
|
||||
continue; // We are not returning true if we are the base of a sapling.
|
||||
}
|
||||
BlockPos blockPos = pos.add(i, 1, j);
|
||||
IBlockState state = world.getBlockState(blockPos);
|
||||
Block block = state.getBlock();
|
||||
if (block instanceof BlockLog || block instanceof IGrowable) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* If a tree or sapling is in the vicinity, there is a chance, that the soil will degrade.
|
||||
*/
|
||||
private static void degradeSoil(World world, final BlockPos pos) {
|
||||
IBlockState blockState = world.getBlockState(pos);
|
||||
|
||||
int degrade = blockState.getValue(DEGRADE);
|
||||
degrade++;
|
||||
|
||||
if (degrade >= degradeDelimiter) {
|
||||
world.setBlockState(pos, Blocks.SAND.getDefaultState(), Constants.FLAG_BLOCK_SYNCH);
|
||||
} else {
|
||||
world.setBlockState(pos, blockState.withProperty(DEGRADE, degrade), Constants.FLAG_BLOCK_SYNCH);
|
||||
}
|
||||
world.markBlockRangeForRenderUpdate(pos, pos);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canSustainPlant(IBlockState state, IBlockAccess world, BlockPos pos, EnumFacing direction, IPlantable plantable) {
|
||||
EnumPlantType plantType = plantable.getPlantType(world, pos);
|
||||
if (plantType != EnumPlantType.Crop && plantType != EnumPlantType.Plains) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canSilkHarvest(World world, BlockPos pos, IBlockState state, EntityPlayer player) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getSubBlocks(Item item, CreativeTabs par2CreativeTabs, List<ItemStack> itemList) {
|
||||
itemList.add(new ItemStack(this));
|
||||
}
|
||||
|
||||
/* MODELS */
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void registerModel(Item item, IModelManager manager) {
|
||||
manager.registerItemModel(item, 0, "soil/humus");
|
||||
manager.registerItemModel(item, 1, "soil/humus");
|
||||
manager.registerItemModel(item, 2, "soil/humus");
|
||||
manager.registerItemModel(item, 3, "soil/humus");
|
||||
}
|
||||
}
|
||||
@@ -19,7 +19,8 @@ import forestry.core.items.ItemBlockForestry;
|
||||
public class BlockRegistryCore extends BlockRegistry {
|
||||
public final BlockCore analyzer;
|
||||
public final BlockCore escritoire;
|
||||
public final BlockSoil soil;
|
||||
public final BlockBogEarth bogEarth;
|
||||
public final BlockHumus humus;
|
||||
public final BlockResourceOre resources;
|
||||
public final BlockResourceStorage resourceStorage;
|
||||
|
||||
@@ -30,10 +31,13 @@ public class BlockRegistryCore extends BlockRegistry {
|
||||
escritoire = new BlockCore(BlockTypeCoreTesr.ESCRITOIRE);
|
||||
registerBlock(escritoire, new ItemBlockForestry<>(escritoire), "escritoire");
|
||||
|
||||
soil = new BlockSoil();
|
||||
registerBlock(soil, new ItemBlockForestry(soil), "soil");
|
||||
soil.setHarvestLevel("shovel", 0, soil.getStateFromMeta(0));
|
||||
soil.setHarvestLevel("shovel", 0, soil.getStateFromMeta(1));
|
||||
bogEarth = new BlockBogEarth();
|
||||
registerBlock(bogEarth, new ItemBlockForestry<>(bogEarth), "bogEarth");
|
||||
bogEarth.setHarvestLevel("shovel", 0);
|
||||
|
||||
humus = new BlockHumus();
|
||||
registerBlock(humus, new ItemBlockForestry<>(humus), "humus");
|
||||
humus.setHarvestLevel("shovel", 0);
|
||||
|
||||
resources = new BlockResourceOre();
|
||||
registerBlock(resources, new ItemBlockForestry(resources), "resources");
|
||||
|
||||
@@ -1,296 +0,0 @@
|
||||
/*******************************************************************************
|
||||
* 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.core.blocks;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockLog;
|
||||
import net.minecraft.block.IGrowable;
|
||||
import net.minecraft.block.SoundType;
|
||||
import net.minecraft.block.material.Material;
|
||||
import net.minecraft.block.properties.PropertyEnum;
|
||||
import net.minecraft.block.state.BlockStateContainer;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.creativetab.CreativeTabs;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.IStringSerializable;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.IBlockAccess;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import net.minecraftforge.common.EnumPlantType;
|
||||
import net.minecraftforge.common.IPlantable;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
import forestry.api.core.IItemModelRegister;
|
||||
import forestry.api.core.IModelManager;
|
||||
import forestry.core.CreativeTabForestry;
|
||||
import forestry.core.PluginCore;
|
||||
import forestry.core.config.Constants;
|
||||
|
||||
/**
|
||||
* Humus, bog earth, peat
|
||||
*/
|
||||
public class BlockSoil extends Block implements IItemModelRegister, IBlockWithMeta {
|
||||
private static final PropertyEnum<SoilType> SOIL = PropertyEnum.create("soil", SoilType.class);
|
||||
|
||||
public enum SoilType implements IStringSerializable {
|
||||
HUMUS("humus"),
|
||||
BOG_EARTH("bog_earth"),
|
||||
PEAT("peat");
|
||||
|
||||
@Nonnull
|
||||
private final String name;
|
||||
|
||||
SoilType(@Nonnull String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
}
|
||||
|
||||
private static final int degradeDelimiter = 3;
|
||||
|
||||
public BlockSoil() {
|
||||
super(Material.GROUND);
|
||||
setTickRandomly(true);
|
||||
setHardness(0.5f);
|
||||
setSoundType(SoundType.GROUND);
|
||||
setCreativeTab(CreativeTabForestry.tabForestry);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMetaFromState(IBlockState state) {
|
||||
return state.getValue(SOIL).ordinal();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IBlockState getStateFromMeta(int meta) {
|
||||
return getDefaultState().withProperty(SOIL, SoilType.values()[meta]);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected BlockStateContainer createBlockState() {
|
||||
return new BlockStateContainer(this, SOIL);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int tickRate(World world) {
|
||||
return 500;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ItemStack> getDrops(IBlockAccess world, BlockPos pos, IBlockState state, int fortune) {
|
||||
ArrayList<ItemStack> ret = new ArrayList<>();
|
||||
|
||||
SoilType type = state.getValue(SOIL);
|
||||
|
||||
if (type == SoilType.PEAT) {
|
||||
ret.add(PluginCore.items.peat.getItemStack());
|
||||
ret.add(new ItemStack(Blocks.DIRT));
|
||||
} else if (type == SoilType.HUMUS) {
|
||||
ret.add(new ItemStack(Blocks.DIRT));
|
||||
} else {
|
||||
ret.add(new ItemStack(this, 1, SoilType.BOG_EARTH.ordinal()));
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateTick(World world, BlockPos pos, IBlockState state, Random rand) {
|
||||
if (world.isRemote) {
|
||||
return;
|
||||
}
|
||||
|
||||
SoilType type = state.getValue(SOIL);
|
||||
|
||||
if (type == SoilType.HUMUS) {
|
||||
updateTickHumus(world, pos);
|
||||
} else if (type == SoilType.BOG_EARTH) {
|
||||
updateTickBogEarth(world, pos);
|
||||
}
|
||||
}
|
||||
|
||||
private static void updateTickHumus(World world, BlockPos pos) {
|
||||
if (isEnrooted(world, pos)) {
|
||||
degradeSoil(world, pos);
|
||||
}
|
||||
}
|
||||
|
||||
private static void updateTickBogEarth(World world, BlockPos pos) {
|
||||
if (isMoistened(world, pos)) {
|
||||
matureBog(world, pos);
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean isEnrooted(World world, BlockPos pos) {
|
||||
for (int i = -1; i < 2; i++) {
|
||||
for (int j = -1; j < 2; j++) {
|
||||
BlockPos blockPos = pos.add(i, 1, j);
|
||||
IBlockState state = world.getBlockState(blockPos);
|
||||
Block block = state.getBlock();
|
||||
if (block instanceof BlockLog || block instanceof IGrowable) {
|
||||
// We are not returning true if we are the base of a sapling.
|
||||
return !(i == 0 && j == 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* If a tree or sapling is in the vicinity, there is a chance, that the soil will degrade.
|
||||
*/
|
||||
private static void degradeSoil(World world, final BlockPos pos) {
|
||||
|
||||
if (world.rand.nextInt(140) != 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
IBlockState blockState = world.getBlockState(pos);
|
||||
Block block = blockState.getBlock();
|
||||
int meta = block.getMetaFromState(blockState);
|
||||
|
||||
// Unpack first
|
||||
int type = meta & 0x03;
|
||||
int grade = meta >> 2;
|
||||
|
||||
// Increment (de)gradation
|
||||
grade++;
|
||||
|
||||
// Repackage in format TTGG
|
||||
meta = grade << 2 | type;
|
||||
|
||||
if (grade >= degradeDelimiter) {
|
||||
world.setBlockState(pos, Blocks.SAND.getDefaultState(), Constants.FLAG_BLOCK_SYNCH);
|
||||
} else {
|
||||
world.setBlockState(pos, block.getStateFromMeta(meta), Constants.FLAG_BLOCK_SYNCH);
|
||||
}
|
||||
world.markBlockRangeForRenderUpdate(pos, pos);
|
||||
}
|
||||
|
||||
private static boolean isMoistened(World world, BlockPos pos) {
|
||||
|
||||
for (int i = -2; i < 3; i++) {
|
||||
for (int j = -2; j < 3; j++) {
|
||||
Block block = world.getBlockState(new BlockPos(pos.getX() + i, pos.getY(), pos.getZ() + j)).getBlock();
|
||||
if (block == Blocks.WATER || block == Blocks.FLOWING_WATER) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private static void matureBog(World world, final BlockPos pos) {
|
||||
|
||||
if (world.rand.nextInt(13) != 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
IBlockState blockState = world.getBlockState(pos);
|
||||
Block block = blockState.getBlock();
|
||||
int meta = block.getMetaFromState(blockState);
|
||||
|
||||
// Unpack first
|
||||
|
||||
int type = meta & 0x03;
|
||||
int maturity = meta >> 2;
|
||||
|
||||
if (maturity >= degradeDelimiter) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Increment (de)gradation
|
||||
maturity++;
|
||||
|
||||
meta = maturity << 2 | type;
|
||||
world.setBlockState(pos, block.getStateFromMeta(meta), Constants.FLAG_BLOCK_SYNCH);
|
||||
world.markBlockRangeForRenderUpdate(pos, pos);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canSustainPlant(IBlockState state, IBlockAccess world, BlockPos pos, EnumFacing direction, IPlantable plantable) {
|
||||
EnumPlantType plantType = plantable.getPlantType(world, pos);
|
||||
if (plantType != EnumPlantType.Crop && plantType != EnumPlantType.Plains) {
|
||||
return false;
|
||||
}
|
||||
|
||||
SoilType type = world.getBlockState(pos).getValue(SOIL);
|
||||
|
||||
return type == SoilType.HUMUS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canSilkHarvest(World world, BlockPos pos, IBlockState state, EntityPlayer player) {
|
||||
return false;
|
||||
}
|
||||
|
||||
public static SoilType getTypeFromState(IBlockState state) {
|
||||
return state.getValue(SOIL);
|
||||
}
|
||||
|
||||
public static SoilType getTypeFromMeta(int meta) {
|
||||
int type = meta & 0x03;
|
||||
int maturity = meta >> 2;
|
||||
|
||||
if (type == 1) {
|
||||
if (maturity < degradeDelimiter) {
|
||||
return SoilType.BOG_EARTH;
|
||||
} else {
|
||||
return SoilType.PEAT;
|
||||
}
|
||||
} else {
|
||||
return SoilType.HUMUS;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getSubBlocks(Item item, CreativeTabs par2CreativeTabs, List<ItemStack> itemList) {
|
||||
itemList.add(new ItemStack(this, 1, 0));
|
||||
itemList.add(new ItemStack(this, 1, 1));
|
||||
}
|
||||
|
||||
/* MODELS */
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void registerModel(Item item, IModelManager manager) {
|
||||
manager.registerItemModel(item, 0, "soil/humus");
|
||||
manager.registerItemModel(item, 1, "soil/bog");
|
||||
manager.registerItemModel(item, 2, "soil/peat");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getNameFromMeta(int meta) {
|
||||
SoilType type = getTypeFromMeta(meta);
|
||||
return type.getName();
|
||||
}
|
||||
|
||||
public ItemStack get(SoilType soilType, int amount) {
|
||||
return new ItemStack(this, amount, soilType.ordinal());
|
||||
}
|
||||
}
|
||||
@@ -18,6 +18,7 @@ import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockHorizontal;
|
||||
import net.minecraft.block.BlockOldLog;
|
||||
import net.minecraft.block.BlockPlanks;
|
||||
import net.minecraft.block.BlockStaticLiquid;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.item.Item;
|
||||
@@ -112,7 +113,8 @@ public abstract class BlockUtil {
|
||||
}
|
||||
|
||||
public static boolean isReplaceableBlock(IBlockState blockState, World world, BlockPos pos) {
|
||||
return blockState.getBlock().isReplaceable(world, pos);
|
||||
Block block = blockState.getBlock();
|
||||
return block.isReplaceable(world, pos) && !(block instanceof BlockStaticLiquid);
|
||||
}
|
||||
|
||||
public static RayTraceResult collisionRayTrace(@Nonnull BlockPos pos, @Nonnull Vec3d startVec, @Nonnull Vec3d endVec, @Nonnull AxisAlignedBB bounds) {
|
||||
|
||||
@@ -185,6 +185,10 @@ public class GeneticsUtil {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (TreeManager.treeRoot.isMember(foreign)) {
|
||||
return foreign;
|
||||
}
|
||||
|
||||
IIndividual tree = getGeneticEquivalent(foreign);
|
||||
if (!(tree instanceof ITree)) {
|
||||
return null;
|
||||
|
||||
@@ -34,7 +34,7 @@ import forestry.apiculture.PluginApiculture;
|
||||
import forestry.apiculture.items.ItemRegistryApiculture;
|
||||
import forestry.core.PluginCore;
|
||||
import forestry.core.PluginFluids;
|
||||
import forestry.core.blocks.BlockSoil;
|
||||
import forestry.core.blocks.BlockBogEarth;
|
||||
import forestry.core.circuits.Circuit;
|
||||
import forestry.core.circuits.CircuitLayout;
|
||||
import forestry.core.circuits.EnumCircuitBoardType;
|
||||
@@ -332,14 +332,14 @@ public class PluginFactory extends BlankForestryPlugin {
|
||||
"#",
|
||||
'#', "pulpWood");
|
||||
RecipeManagers.carpenterManager.addRecipe(5, Fluids.WATER.getFluid(1000), null,
|
||||
PluginCore.blocks.soil.get(BlockSoil.SoilType.HUMUS, 9),
|
||||
new ItemStack(PluginCore.blocks.humus, 9),
|
||||
"###",
|
||||
"#X#",
|
||||
"###",
|
||||
'#', Blocks.DIRT,
|
||||
'X', PluginCore.items.mulch);
|
||||
RecipeManagers.carpenterManager.addRecipe(5, Fluids.WATER.getFluid(1000), null,
|
||||
PluginCore.blocks.soil.get(BlockSoil.SoilType.BOG_EARTH, 8),
|
||||
PluginCore.blocks.bogEarth.get(BlockBogEarth.SoilType.BOG_EARTH, 8),
|
||||
"#X#",
|
||||
"XYX", "#X#",
|
||||
'#', Blocks.DIRT,
|
||||
|
||||
@@ -10,7 +10,6 @@
|
||||
******************************************************************************/
|
||||
package forestry.farming;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
@@ -57,8 +56,7 @@ public class FarmTarget {
|
||||
BlockPos.MutableBlockPos position = new BlockPos.MutableBlockPos(platformPosition);
|
||||
for (extent = 0; extent < limit; extent++) {
|
||||
IBlockState blockState = world.getBlockState(position);
|
||||
Block platform = blockState.getBlock();
|
||||
if (!FarmHelper.bricks.contains(platform)) {
|
||||
if (!FarmHelper.bricks.contains(blockState.getBlock())) {
|
||||
break;
|
||||
}
|
||||
position.offsetMutable(getDirection().getFacing());
|
||||
|
||||
@@ -10,24 +10,23 @@
|
||||
******************************************************************************/
|
||||
package forestry.farming;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.regex.MatchResult;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockBeetroot;
|
||||
import net.minecraft.block.BlockCarrot;
|
||||
import net.minecraft.block.BlockCrops;
|
||||
import net.minecraft.block.BlockNetherWart;
|
||||
import net.minecraft.block.BlockPotato;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.init.Items;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
||||
import net.minecraftforge.client.event.TextureStitchEvent;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.fml.common.SidedProxy;
|
||||
import net.minecraftforge.fml.common.event.FMLInterModComms.IMCMessage;
|
||||
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
||||
import net.minecraftforge.fml.common.registry.GameRegistry;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
@@ -39,16 +38,13 @@ import forestry.api.circuits.CircuitSocketType;
|
||||
import forestry.api.circuits.ICircuitLayout;
|
||||
import forestry.api.core.ForestryAPI;
|
||||
import forestry.api.farming.Farmables;
|
||||
import forestry.api.farming.IFarmable;
|
||||
import forestry.core.PluginCore;
|
||||
import forestry.core.circuits.Circuit;
|
||||
import forestry.core.circuits.CircuitLayout;
|
||||
import forestry.core.config.Constants;
|
||||
import forestry.core.items.EnumElectronTube;
|
||||
import forestry.core.recipes.RecipeUtil;
|
||||
import forestry.core.utils.IMCUtil;
|
||||
import forestry.core.utils.ItemStackUtil;
|
||||
import forestry.core.utils.Log;
|
||||
import forestry.farming.blocks.BlockMushroom;
|
||||
import forestry.farming.blocks.BlockRegistryFarming;
|
||||
import forestry.farming.blocks.EnumFarmBlockType;
|
||||
import forestry.farming.circuits.CircuitFarmLogic;
|
||||
@@ -57,16 +53,14 @@ import forestry.farming.logic.FarmLogicCereal;
|
||||
import forestry.farming.logic.FarmLogicCocoa;
|
||||
import forestry.farming.logic.FarmLogicGourd;
|
||||
import forestry.farming.logic.FarmLogicInfernal;
|
||||
import forestry.farming.logic.FarmLogicMushroom;
|
||||
import forestry.farming.logic.FarmLogicOrchard;
|
||||
import forestry.farming.logic.FarmLogicPeat;
|
||||
import forestry.farming.logic.FarmLogicReeds;
|
||||
import forestry.farming.logic.FarmLogicShroom;
|
||||
import forestry.farming.logic.FarmLogicSucculent;
|
||||
import forestry.farming.logic.FarmLogicVegetable;
|
||||
import forestry.farming.logic.FarmableBasicFruit;
|
||||
import forestry.farming.logic.FarmableAgingCrop;
|
||||
import forestry.farming.logic.FarmableGE;
|
||||
import forestry.farming.logic.FarmableGenericCrop;
|
||||
import forestry.farming.logic.FarmableGenericSapling;
|
||||
import forestry.farming.logic.FarmableGourd;
|
||||
import forestry.farming.logic.FarmableStacked;
|
||||
import forestry.farming.logic.FarmableVanillaMushroom;
|
||||
@@ -101,41 +95,38 @@ public class PluginFarming extends BlankForestryPlugin {
|
||||
public void preInit() {
|
||||
MinecraftForge.EVENT_BUS.register(this);
|
||||
|
||||
Farmables.farmables.put("farmArboreal", new ArrayList<>());
|
||||
Farmables.farmables.get("farmArboreal").add(new FarmableVanillaSapling());
|
||||
Farmables.farmables.put("farmArboreal", new FarmableVanillaSapling());
|
||||
if (ForestryAPI.enabledPlugins.contains(ForestryPluginUids.ARBORICULTURE)) {
|
||||
Farmables.farmables.get("farmArboreal").add(new FarmableGE());
|
||||
Farmables.farmables.put("farmArboreal", new FarmableGE());
|
||||
}
|
||||
|
||||
Farmables.farmables.put("farmOrchard", new ArrayList<>());
|
||||
Farmables.farmables.get("farmOrchard").add(new FarmableBasicFruit(Blocks.WHEAT, 7));
|
||||
Farmables.farmables.get("farmOrchard").add(new FarmableBasicFruit(Blocks.POTATOES, 7));
|
||||
Farmables.farmables.get("farmOrchard").add(new FarmableBasicFruit(Blocks.CARROTS, 7));
|
||||
|
||||
Farmables.farmables.put("farmShroom", new ArrayList<>());
|
||||
Farmables.farmables.get("farmShroom").add(new FarmableVanillaMushroom(Blocks.BROWN_MUSHROOM, 0));
|
||||
Farmables.farmables.get("farmShroom").add(new FarmableVanillaMushroom(Blocks.RED_MUSHROOM, 0));
|
||||
Farmables.farmables.putAll("farmOrchard", Arrays.asList(
|
||||
new FarmableAgingCrop(new ItemStack(Items.WHEAT_SEEDS), Blocks.WHEAT, BlockCrops.AGE, 7),
|
||||
new FarmableAgingCrop(new ItemStack(Items.POTATO), Blocks.POTATOES, BlockPotato.AGE, 7),
|
||||
new FarmableAgingCrop(new ItemStack(Items.CARROT), Blocks.CARROTS, BlockCarrot.AGE, 7),
|
||||
new FarmableAgingCrop(new ItemStack(Items.BEETROOT_SEEDS), Blocks.BEETROOTS, BlockBeetroot.BEETROOT_AGE, 3)
|
||||
));
|
||||
|
||||
Farmables.farmables.put("farmWheat", new ArrayList<>());
|
||||
Farmables.farmables.get("farmWheat").add(new FarmableGenericCrop(new ItemStack(Items.WHEAT_SEEDS), Blocks.WHEAT, 7));
|
||||
IBlockState plantedBrownMushroom = blocks.mushroom.getDefaultState().withProperty(BlockMushroom.VARIANT, BlockMushroom.MushroomType.BROWN);
|
||||
Farmables.farmables.put("farmShroom", new FarmableVanillaMushroom(new ItemStack(Blocks.BROWN_MUSHROOM), plantedBrownMushroom, Blocks.BROWN_MUSHROOM_BLOCK));
|
||||
|
||||
Farmables.farmables.put("farmGourd", new ArrayList<>());
|
||||
Farmables.farmables.get("farmGourd").add(
|
||||
new FarmableGourd(new ItemStack(Items.PUMPKIN_SEEDS), new ItemStack(Blocks.PUMPKIN_STEM), new ItemStack(Blocks.PUMPKIN)));
|
||||
Farmables.farmables.get("farmGourd").add(new FarmableGourd(new ItemStack(Items.MELON_SEEDS), new ItemStack(Blocks.MELON_STEM), new ItemStack(Blocks.MELON_BLOCK)));
|
||||
IBlockState plantedRedMushroom = blocks.mushroom.getDefaultState().withProperty(BlockMushroom.VARIANT, BlockMushroom.MushroomType.RED);
|
||||
Farmables.farmables.put("farmShroom", new FarmableVanillaMushroom(new ItemStack(Blocks.RED_MUSHROOM), plantedRedMushroom, Blocks.RED_MUSHROOM_BLOCK));
|
||||
|
||||
Farmables.farmables.put("farmInfernal", new ArrayList<>());
|
||||
Farmables.farmables.get("farmInfernal").add(new FarmableGenericCrop(new ItemStack(Items.NETHER_WART), Blocks.NETHER_WART, 3));
|
||||
Farmables.farmables.put("farmWheat", new FarmableAgingCrop(new ItemStack(Items.WHEAT_SEEDS), Blocks.WHEAT, BlockCrops.AGE, 7));
|
||||
|
||||
Farmables.farmables.put("farmPoales", new ArrayList<>());
|
||||
Farmables.farmables.get("farmPoales").add(new FarmableStacked(Blocks.REEDS, 3, 0));
|
||||
Farmables.farmables.put("farmGourd", new FarmableGourd(new ItemStack(Items.PUMPKIN_SEEDS), Blocks.PUMPKIN_STEM, Blocks.PUMPKIN));
|
||||
Farmables.farmables.put("farmGourd", new FarmableGourd(new ItemStack(Items.MELON_SEEDS), Blocks.MELON_STEM, Blocks.MELON_BLOCK));
|
||||
|
||||
Farmables.farmables.put("farmSucculentes", new ArrayList<>());
|
||||
Farmables.farmables.get("farmSucculentes").add(new FarmableStacked(Blocks.CACTUS, 3, 0));
|
||||
Farmables.farmables.put("farmInfernal", new FarmableAgingCrop(new ItemStack(Items.NETHER_WART), Blocks.NETHER_WART, BlockNetherWart.AGE, 3));
|
||||
|
||||
Farmables.farmables.put("farmVegetables", new ArrayList<>());
|
||||
Farmables.farmables.get("farmVegetables").add(new FarmableGenericCrop(new ItemStack(Items.POTATO), Blocks.POTATOES, 7));
|
||||
Farmables.farmables.get("farmVegetables").add(new FarmableGenericCrop(new ItemStack(Items.CARROT), Blocks.CARROTS, 7));
|
||||
Farmables.farmables.put("farmPoales", new FarmableStacked(new ItemStack(Items.REEDS), Blocks.REEDS, 3));
|
||||
|
||||
Farmables.farmables.put("farmSucculentes", new FarmableStacked(new ItemStack(Blocks.CACTUS), Blocks.CACTUS, 3));
|
||||
|
||||
Farmables.farmables.put("farmVegetables", new FarmableAgingCrop(new ItemStack(Items.POTATO), Blocks.POTATOES, BlockPotato.AGE, 7));
|
||||
Farmables.farmables.put("farmVegetables", new FarmableAgingCrop(new ItemStack(Items.CARROT), Blocks.CARROTS, BlockCarrot.AGE, 7));
|
||||
Farmables.farmables.put("farmVegetables", new FarmableAgingCrop(new ItemStack(Items.BEETROOT_SEEDS), Blocks.BEETROOTS, BlockBeetroot.BEETROOT_AGE, 3));
|
||||
|
||||
proxy.initializeModels();
|
||||
|
||||
@@ -161,123 +152,23 @@ public class PluginFarming extends BlankForestryPlugin {
|
||||
GameRegistry.registerTileEntity(TileFarmValve.class, "forestry.FarmValve");
|
||||
GameRegistry.registerTileEntity(TileFarmControl.class, "forestry.FarmControl");
|
||||
|
||||
Circuit.farmArborealManaged = new CircuitFarmLogic("managedArboreal", FarmLogicArboreal.class);
|
||||
Circuit.farmShroomManaged = new CircuitFarmLogic("managedShroom", FarmLogicShroom.class);
|
||||
Circuit.farmPeatManaged = new CircuitFarmLogic("managedPeat", FarmLogicPeat.class);
|
||||
Circuit.farmCerealManaged = new CircuitFarmLogic("managedCereal", FarmLogicCereal.class);
|
||||
Circuit.farmVegetableManaged = new CircuitFarmLogic("managedVegetable", FarmLogicVegetable.class);
|
||||
Circuit.farmInfernalManaged = new CircuitFarmLogic("managedInfernal", FarmLogicInfernal.class);
|
||||
Circuit.farmArborealManaged = new CircuitFarmLogic("managedArboreal", new FarmLogicArboreal());
|
||||
Circuit.farmShroomManaged = new CircuitFarmLogic("managedShroom", new FarmLogicMushroom());
|
||||
Circuit.farmPeatManaged = new CircuitFarmLogic("managedPeat", new FarmLogicPeat());
|
||||
Circuit.farmCerealManaged = new CircuitFarmLogic("managedCereal", new FarmLogicCereal());
|
||||
Circuit.farmVegetableManaged = new CircuitFarmLogic("managedVegetable", new FarmLogicVegetable());
|
||||
Circuit.farmInfernalManaged = new CircuitFarmLogic("managedInfernal", new FarmLogicInfernal());
|
||||
|
||||
Circuit.farmPeatManual = new CircuitFarmLogic("manualPeat", FarmLogicPeat.class).setManual();
|
||||
Circuit.farmShroomManual = new CircuitFarmLogic("manualShroom", FarmLogicShroom.class).setManual();
|
||||
Circuit.farmCerealManual = new CircuitFarmLogic("manualCereal", FarmLogicCereal.class).setManual();
|
||||
Circuit.farmVegetableManual = new CircuitFarmLogic("manualVegetable", FarmLogicVegetable.class).setManual();
|
||||
Circuit.farmSucculentManual = new CircuitFarmLogic("manualSucculent", FarmLogicSucculent.class).setManual();
|
||||
Circuit.farmPoalesManual = new CircuitFarmLogic("manualPoales", FarmLogicReeds.class).setManual();
|
||||
Circuit.farmGourdManual = new CircuitFarmLogic("manualGourd", FarmLogicGourd.class).setManual();
|
||||
Circuit.farmCocoaManual = new CircuitFarmLogic("manualCocoa", FarmLogicCocoa.class).setManual();
|
||||
Circuit.farmPeatManual = new CircuitFarmLogic("manualPeat", new FarmLogicPeat()).setManual();
|
||||
Circuit.farmShroomManual = new CircuitFarmLogic("manualShroom", new FarmLogicMushroom()).setManual();
|
||||
Circuit.farmCerealManual = new CircuitFarmLogic("manualCereal", new FarmLogicCereal()).setManual();
|
||||
Circuit.farmVegetableManual = new CircuitFarmLogic("manualVegetable", new FarmLogicVegetable()).setManual();
|
||||
Circuit.farmSucculentManual = new CircuitFarmLogic("manualSucculent", new FarmLogicSucculent()).setManual();
|
||||
Circuit.farmPoalesManual = new CircuitFarmLogic("manualPoales", new FarmLogicReeds()).setManual();
|
||||
Circuit.farmGourdManual = new CircuitFarmLogic("manualGourd", new FarmLogicGourd()).setManual();
|
||||
Circuit.farmCocoaManual = new CircuitFarmLogic("manualCocoa", new FarmLogicCocoa()).setManual();
|
||||
|
||||
Circuit.farmOrchardManual = new CircuitFarmLogic("manualOrchard", FarmLogicOrchard.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean processIMCMessage(IMCMessage message) {
|
||||
|
||||
if (message.key.equals("add-farmable-sapling")) {
|
||||
String[] tokens = message.getStringValue().split("@");
|
||||
String errormsg = IMCUtil.getInvalidIMCMessageText(message);
|
||||
if (tokens.length != 2) {
|
||||
Log.warning(errormsg);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!Farmables.farmables.containsKey(tokens[0])) {
|
||||
Log.warning("%s For non-existent farm %s.", errormsg, tokens[0]);
|
||||
return true;
|
||||
}
|
||||
|
||||
Collection<IFarmable> farmables = Farmables.farmables.get(tokens[0]);
|
||||
|
||||
String itemString = tokens[1];
|
||||
|
||||
Matcher matcher = Pattern.compile("(.+?)\\.(-?[0-9][0-9]?)(?:\\.(.+?)\\.(-?[0-9][0-9]?))?").matcher(itemString);
|
||||
if (!matcher.matches()) {
|
||||
Log.warning("%s For farm '%s': unable to parse string.", errormsg, tokens[0]);
|
||||
return true;
|
||||
}
|
||||
|
||||
MatchResult matchResult = matcher.toMatchResult();
|
||||
String saplingString = matchResult.group(1);
|
||||
String saplingMetaString = matchResult.group(2);
|
||||
String windfallString = matchResult.group(3);
|
||||
String windfallMetaString = matchResult.group(4);
|
||||
|
||||
try {
|
||||
Block sapling = ItemStackUtil.getBlockFromRegistry(saplingString);
|
||||
if (sapling == null) {
|
||||
throw new IllegalArgumentException("can't find block for " + saplingString);
|
||||
}
|
||||
int saplingMeta = Integer.parseInt(saplingMetaString);
|
||||
|
||||
if (windfallString == null) {
|
||||
farmables.add(new FarmableGenericSapling(sapling, saplingMeta));
|
||||
} else {
|
||||
Item windfall = ItemStackUtil.getItemFromRegistry(windfallString);
|
||||
if (windfall == null) {
|
||||
throw new IllegalArgumentException("can't find item for " + windfallString);
|
||||
}
|
||||
|
||||
ItemStack windfallStack = new ItemStack(windfall, 1, Integer.parseInt(windfallMetaString));
|
||||
|
||||
farmables.add(new FarmableGenericSapling(sapling, saplingMeta, windfallStack));
|
||||
}
|
||||
} catch (IllegalArgumentException e) {
|
||||
Log.warning("%s for farm '%s'", errormsg, tokens[0], e.getMessage());
|
||||
}
|
||||
return true;
|
||||
|
||||
} else if (message.key.equals("add-farmable-crop")) {
|
||||
|
||||
String[] tokens = message.getStringValue().split("@");
|
||||
String errormsg = IMCUtil.getInvalidIMCMessageText(message);
|
||||
if (tokens.length != 2) {
|
||||
Log.warning(errormsg);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!Farmables.farmables.containsKey(tokens[0])) {
|
||||
Log.warning("%s For non-existent farm %s.", errormsg, tokens[0]);
|
||||
return true;
|
||||
}
|
||||
|
||||
String[] items = tokens[1].split("[\\.]+");
|
||||
if (items.length != 4) {
|
||||
Log.warning("%s For farm '%s': id definitions did not match.", errormsg, tokens[0]);
|
||||
return true;
|
||||
}
|
||||
|
||||
try {
|
||||
Item seed = ItemStackUtil.getItemFromRegistry(items[0]);
|
||||
if (seed == null) {
|
||||
throw new IllegalArgumentException("can't find item for " + items[0]);
|
||||
}
|
||||
Block crop = ItemStackUtil.getBlockFromRegistry(items[2]);
|
||||
if (crop == null) {
|
||||
throw new IllegalArgumentException("can't find block for " + items[2]);
|
||||
}
|
||||
|
||||
Farmables.farmables.get(tokens[0]).add(
|
||||
new FarmableGenericCrop(new ItemStack(seed, 1, Integer.parseInt(items[1])),
|
||||
crop,
|
||||
Integer.parseInt(items[3])));
|
||||
} catch (IllegalArgumentException e) {
|
||||
Log.warning("%s for farm '%s': %s", errormsg, tokens[0], e.getMessage());
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
Circuit.farmOrchardManual = new CircuitFarmLogic("manualOrchard", new FarmLogicOrchard());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -10,24 +10,26 @@
|
||||
******************************************************************************/
|
||||
package forestry.farming.blocks;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Random;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockBush;
|
||||
import net.minecraft.block.BlockDirt;
|
||||
import net.minecraft.block.IGrowable;
|
||||
import net.minecraft.block.properties.PropertyBool;
|
||||
import net.minecraft.block.properties.PropertyEnum;
|
||||
import net.minecraft.block.state.BlockStateContainer;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.creativetab.CreativeTabs;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.IStringSerializable;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.RayTraceResult;
|
||||
import net.minecraft.world.IBlockAccess;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.gen.feature.WorldGenBigMushroom;
|
||||
@@ -38,15 +40,28 @@ import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
import forestry.api.core.IItemModelRegister;
|
||||
import forestry.api.core.IModelManager;
|
||||
import forestry.core.blocks.IBlockWithMeta;
|
||||
import forestry.core.config.Constants;
|
||||
|
||||
public class BlockMushroom extends BlockBush implements IItemModelRegister, IGrowable, IBlockWithMeta {
|
||||
public class BlockMushroom extends BlockBush implements IItemModelRegister, IGrowable {
|
||||
|
||||
public static final PropertyEnum<MushroomType> MUSHROOM = PropertyEnum.create("mushroom", MushroomType.class);
|
||||
public static final PropertyEnum<MushroomType> VARIANT = PropertyEnum.create("mushroom", MushroomType.class);
|
||||
public static final PropertyBool MATURE = PropertyBool.create("mature");
|
||||
|
||||
public enum MushroomType implements IStringSerializable {
|
||||
BROWN, RED;
|
||||
BROWN {
|
||||
@Override
|
||||
public ItemStack getDrop() {
|
||||
return new ItemStack(Blocks.BROWN_MUSHROOM);
|
||||
}
|
||||
},
|
||||
RED {
|
||||
@Override
|
||||
public ItemStack getDrop() {
|
||||
return new ItemStack(Blocks.RED_MUSHROOM);
|
||||
}
|
||||
};
|
||||
|
||||
public abstract ItemStack getDrop();
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
@@ -55,30 +70,28 @@ public class BlockMushroom extends BlockBush implements IItemModelRegister, IGro
|
||||
}
|
||||
|
||||
private final WorldGenerator[] generators;
|
||||
private final ItemStack[] drops;
|
||||
|
||||
public BlockMushroom() {
|
||||
setHardness(0.0f);
|
||||
this.generators = new WorldGenerator[]{new WorldGenBigMushroom(Blocks.BROWN_MUSHROOM_BLOCK), new WorldGenBigMushroom(Blocks.RED_MUSHROOM_BLOCK)};
|
||||
this.drops = new ItemStack[]{new ItemStack(Blocks.BROWN_MUSHROOM), new ItemStack(Blocks.RED_MUSHROOM)};
|
||||
setCreativeTab(null);
|
||||
setDefaultState(this.blockState.getBaseState().withProperty(MUSHROOM, MushroomType.BROWN));
|
||||
setDefaultState(this.blockState.getBaseState().withProperty(VARIANT, MushroomType.BROWN).withProperty(MATURE, false));
|
||||
setTickRandomly(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected BlockStateContainer createBlockState() {
|
||||
return new BlockStateContainer(this, MUSHROOM);
|
||||
return new BlockStateContainer(this, VARIANT, MATURE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMetaFromState(IBlockState state) {
|
||||
return state.getValue(MUSHROOM).ordinal();
|
||||
return state.getValue(VARIANT).ordinal() | ((state.getValue(MATURE) ? 1 : 0) << 2);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IBlockState getStateFromMeta(int meta) {
|
||||
return getDefaultState().withProperty(MUSHROOM, MushroomType.values()[meta]);
|
||||
return getDefaultState().withProperty(VARIANT, MushroomType.values()[meta % 2]).withProperty(MATURE, (meta >> 2) == 1);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -89,13 +102,8 @@ public class BlockMushroom extends BlockBush implements IItemModelRegister, IGro
|
||||
// / DROPS
|
||||
@Override
|
||||
public List<ItemStack> getDrops(IBlockAccess world, BlockPos pos, IBlockState state, int fortune) {
|
||||
List<ItemStack> ret = new ArrayList<>();
|
||||
|
||||
MushroomType type = getTypeFromMeta(state.getBlock().getMetaFromState(state));
|
||||
|
||||
ret.add(drops[type.ordinal()]);
|
||||
|
||||
return ret;
|
||||
MushroomType type = state.getValue(VARIANT);
|
||||
return Collections.singletonList(type.getDrop());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -120,39 +128,23 @@ public class BlockMushroom extends BlockBush implements IItemModelRegister, IGro
|
||||
|
||||
@Override
|
||||
public void updateTick(World world, BlockPos pos, IBlockState state, Random rand) {
|
||||
if (world.isRemote) {
|
||||
if (world.isRemote || rand.nextInt(2) != 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
IBlockState blockState = world.getBlockState(pos);
|
||||
Block block = blockState.getBlock();
|
||||
int meta = block.getMetaFromState(blockState);
|
||||
MushroomType type = getTypeFromMeta(meta);
|
||||
int maturity = meta >> 2;
|
||||
|
||||
tickGermling(world, pos.getX(), pos.getY(), pos.getZ(), rand, type, maturity);
|
||||
}
|
||||
|
||||
private void tickGermling(World world, int i, int j, int k, Random random, MushroomType type, int maturity) {
|
||||
|
||||
int lightvalue = world.getLight(new BlockPos(i, j + 1, k));
|
||||
|
||||
if (random.nextInt(2) != 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (maturity != 3) {
|
||||
maturity = 3;
|
||||
int matX = maturity << 2;
|
||||
int meta = matX | type.ordinal();
|
||||
world.setBlockState(new BlockPos(i, j, k), world.getBlockState(new BlockPos(i, j, k)).getBlock().getStateFromMeta(meta), Constants.FLAG_BLOCK_SYNCH);
|
||||
} else if (lightvalue <= 7) {
|
||||
generateTree(world, new BlockPos(i, j, k), world.getBlockState(new BlockPos(i, j, k)), random);
|
||||
if (!blockState.getValue(MATURE)) {
|
||||
world.setBlockState(pos, blockState.withProperty(MATURE, true), Constants.FLAG_BLOCK_SYNCH);
|
||||
} else {
|
||||
int lightValue1 = world.getLightFromNeighbors(pos.up());
|
||||
if (lightValue1 <= 7) {
|
||||
generateGiantMushroom(world, pos, blockState, rand);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void generateTree(World world, BlockPos pos, IBlockState state, Random rand) {
|
||||
MushroomType type = state.getValue(MUSHROOM);
|
||||
|
||||
public void generateGiantMushroom(World world, BlockPos pos, IBlockState state, Random rand) {
|
||||
MushroomType type = state.getValue(VARIANT);
|
||||
|
||||
world.setBlockToAir(pos);
|
||||
if (!generators[type.ordinal()].generate(world, rand, pos)) {
|
||||
@@ -161,12 +153,7 @@ public class BlockMushroom extends BlockBush implements IItemModelRegister, IGro
|
||||
}
|
||||
|
||||
public void grow(World worldIn, BlockPos pos, IBlockState state, Random rand) {
|
||||
this.generateTree(worldIn, pos, state, rand);
|
||||
}
|
||||
|
||||
public static MushroomType getTypeFromMeta(int meta) {
|
||||
meta %= MushroomType.values().length;
|
||||
return MushroomType.values()[meta];
|
||||
this.generateGiantMushroom(worldIn, pos, state, rand);
|
||||
}
|
||||
|
||||
/* ICONS */
|
||||
@@ -200,8 +187,12 @@ public class BlockMushroom extends BlockBush implements IItemModelRegister, IGro
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getNameFromMeta(int meta) {
|
||||
MushroomType type = getTypeFromMeta(meta);
|
||||
return type.getName();
|
||||
public ItemStack getPickBlock(IBlockState state, RayTraceResult target, World world, BlockPos pos, EntityPlayer player) {
|
||||
return state.getValue(VARIANT).getDrop();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int damageDropped(IBlockState state) {
|
||||
return state.getValue(VARIANT).ordinal();
|
||||
}
|
||||
}
|
||||
@@ -17,12 +17,12 @@ import forestry.core.circuits.Circuit;
|
||||
|
||||
public class CircuitFarmLogic extends Circuit {
|
||||
|
||||
private final Class<? extends IFarmLogic> logicClass;
|
||||
private final IFarmLogic logic;
|
||||
private boolean isManual = false;
|
||||
|
||||
public CircuitFarmLogic(String uid, Class<? extends IFarmLogic> logicClass) {
|
||||
public CircuitFarmLogic(String uid, IFarmLogic logic) {
|
||||
super(uid, false);
|
||||
this.logicClass = logicClass;
|
||||
this.logic = logic;
|
||||
setLimit(4);
|
||||
}
|
||||
|
||||
@@ -50,13 +50,6 @@ public class CircuitFarmLogic extends Circuit {
|
||||
return;
|
||||
}
|
||||
|
||||
IFarmLogic logic;
|
||||
try {
|
||||
logic = logicClass.getConstructor(IFarmHousing.class).newInstance(housing);
|
||||
} catch (ReflectiveOperationException ex) {
|
||||
throw new RuntimeException("Failed to instantiate logic of class " + logicClass.getName() + ": " + ex.getMessage(), ex);
|
||||
}
|
||||
|
||||
logic.setManual(isManual);
|
||||
|
||||
housing.setFarmLogic(FarmDirection.values()[slot], logic);
|
||||
|
||||
@@ -13,18 +13,15 @@ package forestry.farming.logic;
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.Collection;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import forestry.api.farming.ICrop;
|
||||
import forestry.core.config.Constants;
|
||||
|
||||
public abstract class Crop implements ICrop {
|
||||
|
||||
protected final World world;
|
||||
private final World world;
|
||||
protected final BlockPos position;
|
||||
|
||||
protected Crop(World world, BlockPos position) {
|
||||
@@ -32,39 +29,18 @@ public abstract class Crop implements ICrop {
|
||||
this.position = position;
|
||||
}
|
||||
|
||||
protected final void setBlock(BlockPos position, IBlockState blockState) {
|
||||
world.setBlockState(position, blockState, Constants.FLAG_BLOCK_SYNCH);
|
||||
}
|
||||
protected abstract boolean isCrop(World world, BlockPos pos);
|
||||
|
||||
@Deprecated
|
||||
protected final void setBlock(BlockPos position, Block block, int meta) {
|
||||
setBlock(position, block.getStateFromMeta(meta));
|
||||
}
|
||||
|
||||
protected final Block getBlock(BlockPos position) {
|
||||
return getBlockState(position).getBlock();
|
||||
}
|
||||
|
||||
protected final IBlockState getBlockState(BlockPos position) {
|
||||
return world.getBlockState(position);
|
||||
}
|
||||
|
||||
protected final int getBlockMeta(BlockPos position) {
|
||||
return getBlock(position).getMetaFromState(getBlockState(position));
|
||||
}
|
||||
|
||||
protected abstract boolean isCrop(BlockPos pos);
|
||||
|
||||
protected abstract Collection<ItemStack> harvestBlock(BlockPos pos);
|
||||
protected abstract Collection<ItemStack> harvestBlock(World world, BlockPos pos);
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public Collection<ItemStack> harvest() {
|
||||
if (!isCrop(position)) {
|
||||
if (!isCrop(world, position)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return harvestBlock(position);
|
||||
return harvestBlock(world, position);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -14,6 +14,7 @@ import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
@@ -24,34 +25,33 @@ import forestry.core.proxy.Proxies;
|
||||
|
||||
public class CropBasicAgriCraft extends Crop {
|
||||
|
||||
private final Block block;
|
||||
private final int meta;
|
||||
private final IBlockState blockState;
|
||||
|
||||
public CropBasicAgriCraft(World world, Block block, int meta, BlockPos position) {
|
||||
public CropBasicAgriCraft(World world, IBlockState blockState, BlockPos position) {
|
||||
super(world, position);
|
||||
this.block = block;
|
||||
this.meta = meta;
|
||||
this.blockState = blockState;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isCrop(BlockPos pos) {
|
||||
return getBlock(pos) == block && getBlockMeta(pos) == meta;
|
||||
protected boolean isCrop(World world, BlockPos pos) {
|
||||
return world.getBlockState(pos) == blockState;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Collection<ItemStack> harvestBlock(BlockPos pos) {
|
||||
List<ItemStack> harvest = block.getDrops(world, pos, block.getStateFromMeta(meta), 0);
|
||||
protected Collection<ItemStack> harvestBlock(World world, BlockPos pos) {
|
||||
Block block = blockState.getBlock();
|
||||
List<ItemStack> harvest = block.getDrops(world, pos, blockState, 0);
|
||||
if (harvest.size() > 1) {
|
||||
harvest.remove(1); //AgriCraft returns cropsticks in 0, seeds in 1 in getDrops, removing since harvesting doesn't return them.
|
||||
}
|
||||
harvest.remove(0);
|
||||
Proxies.common.addBlockDestroyEffects(world, pos, Blocks.MELON_BLOCK.getDefaultState());
|
||||
world.setBlockState(pos, getBlock(pos).getDefaultState(), Constants.FLAG_BLOCK_SYNCH);
|
||||
world.setBlockState(pos, block.getDefaultState(), Constants.FLAG_BLOCK_SYNCH);
|
||||
return harvest;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return String.format("CropBasicAgriCraft [ position: [ %s ]; block: %s; meta: %s ]", position.toString(), block.getUnlocalizedName(), meta);
|
||||
return String.format("CropBasicAgriCraft [ position: [ %s ]; block: %s ]", position.toString(), blockState);
|
||||
}
|
||||
}
|
||||
@@ -14,6 +14,7 @@ import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
@@ -23,39 +24,38 @@ import forestry.core.proxy.Proxies;
|
||||
|
||||
public class CropBasicGrowthCraft extends Crop {
|
||||
|
||||
private final Block block;
|
||||
private final int meta;
|
||||
private final IBlockState blockState;
|
||||
private final boolean isRice;
|
||||
private final boolean isGrape;
|
||||
|
||||
public CropBasicGrowthCraft(World world, Block block, int meta, BlockPos position, boolean isRice, boolean isGrape) {
|
||||
public CropBasicGrowthCraft(World world, IBlockState blockState, BlockPos position, boolean isRice, boolean isGrape) {
|
||||
super(world, position);
|
||||
this.block = block;
|
||||
this.meta = meta;
|
||||
this.blockState = blockState;
|
||||
this.isRice = isRice;
|
||||
this.isGrape = isGrape;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isCrop(BlockPos pos) {
|
||||
return getBlock(pos) == block && getBlockMeta(pos) == meta;
|
||||
protected boolean isCrop(World world, BlockPos pos) {
|
||||
return world.getBlockState(pos) == blockState;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Collection<ItemStack> harvestBlock(BlockPos pos) {
|
||||
List<ItemStack> harvest = block.getDrops(world, pos, block.getStateFromMeta(meta), 0);
|
||||
protected Collection<ItemStack> harvestBlock(World world, BlockPos pos) {
|
||||
Block block = blockState.getBlock();
|
||||
List<ItemStack> harvest = block.getDrops(world, pos, blockState, 0);
|
||||
if (harvest.size() > 1) {
|
||||
harvest.remove(0); //Hops have rope as first drop.
|
||||
}
|
||||
Proxies.common.addBlockDestroyEffects(world, pos, block.getDefaultState());
|
||||
Proxies.common.addBlockDestroyEffects(world, pos, blockState);
|
||||
if (isGrape) {
|
||||
world.setBlockToAir(pos);
|
||||
|
||||
} else {
|
||||
world.setBlockState(pos, block.getDefaultState(), Constants.FLAG_BLOCK_SYNCH);
|
||||
}
|
||||
|
||||
if (isRice) {
|
||||
// TODO: GrowthCraft for MC 1.9. Don't use meta, get the actual block state.
|
||||
world.setBlockState(pos.down(), block.getStateFromMeta(7), Constants.FLAG_BLOCK_SYNCH);
|
||||
}
|
||||
|
||||
@@ -64,6 +64,6 @@ public class CropBasicGrowthCraft extends Crop {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return String.format("CropBasicGrowthCraft [ position: [ %s ]; block: %s; meta: %s ]", position.toString(), block.getUnlocalizedName(), meta);
|
||||
return String.format("CropBasicGrowthCraft [ position: [ %s ]; block: %s ]", position.toString(), blockState);
|
||||
}
|
||||
}
|
||||
@@ -1,51 +0,0 @@
|
||||
/*******************************************************************************
|
||||
* 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 java.util.Collection;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import forestry.core.proxy.Proxies;
|
||||
|
||||
public class CropBlock extends Crop {
|
||||
|
||||
protected final Block block;
|
||||
protected final int meta;
|
||||
|
||||
public CropBlock(World world, Block block, int meta, BlockPos position) {
|
||||
super(world, position);
|
||||
this.block = block;
|
||||
this.meta = meta;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isCrop(BlockPos pos) {
|
||||
return getBlock(pos) == block && getBlockMeta(pos) == meta;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Collection<ItemStack> harvestBlock(BlockPos pos) {
|
||||
Collection<ItemStack> harvested = block.getDrops(world, pos, block.getStateFromMeta(meta), 0);
|
||||
Proxies.common.addBlockDestroyEffects(world, pos, block.getDefaultState());
|
||||
// Block.breakBlock() is called by vanilla itself, removing TEs.
|
||||
world.setBlockToAir(pos);
|
||||
return harvested;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return String.format("CropBlock [ position: [ %s ]; block: %s; meta: %s ]", position.toString(), block.getUnlocalizedName(), meta);
|
||||
}
|
||||
}
|
||||
+23
-13
@@ -10,9 +10,11 @@
|
||||
******************************************************************************/
|
||||
package forestry.farming.logic;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.Collection;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
@@ -20,32 +22,40 @@ import net.minecraft.world.World;
|
||||
import forestry.core.config.Constants;
|
||||
import forestry.core.proxy.Proxies;
|
||||
|
||||
public class CropBasicFruit extends Crop {
|
||||
public class CropDestroy extends Crop {
|
||||
|
||||
private final Block block;
|
||||
private final int meta;
|
||||
protected final IBlockState blockState;
|
||||
@Nullable
|
||||
protected final IBlockState replantState;
|
||||
|
||||
public CropBasicFruit(World world, Block block, int meta, BlockPos position) {
|
||||
public CropDestroy(World world, IBlockState blockState, BlockPos position, @Nullable IBlockState replantState) {
|
||||
super(world, position);
|
||||
this.block = block;
|
||||
this.meta = meta;
|
||||
this.blockState = blockState;
|
||||
this.replantState = replantState;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isCrop(BlockPos pos) {
|
||||
return getBlock(pos) == block && getBlockMeta(pos) == meta;
|
||||
protected boolean isCrop(World world, BlockPos pos) {
|
||||
return world.getBlockState(pos) == blockState;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Collection<ItemStack> harvestBlock(BlockPos pos) {
|
||||
Collection<ItemStack> harvested = block.getDrops(world, pos, block.getStateFromMeta(meta), 0);
|
||||
Proxies.common.addBlockDestroyEffects(world, pos, block.getDefaultState());
|
||||
world.setBlockState(pos, block.getDefaultState(), Constants.FLAG_BLOCK_SYNCH);
|
||||
protected Collection<ItemStack> harvestBlock(World world, BlockPos pos) {
|
||||
Block block = blockState.getBlock();
|
||||
Collection<ItemStack> harvested = block.getDrops(world, pos, blockState, 0);
|
||||
Proxies.common.addBlockDestroyEffects(world, pos, blockState);
|
||||
|
||||
if (replantState != null) {
|
||||
world.setBlockState(pos, replantState, Constants.FLAG_BLOCK_SYNCH);
|
||||
} else {
|
||||
world.setBlockToAir(pos);
|
||||
}
|
||||
|
||||
return harvested;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return String.format("CropBasicFruit [ position: [ %s ]; block: %s; meta: %s ]", position.toString(), block.getUnlocalizedName(), meta);
|
||||
return String.format("CropDestroy [ position: [ %s ]; block: %s ]", position.toString(), blockState);
|
||||
}
|
||||
}
|
||||
@@ -10,9 +10,10 @@
|
||||
******************************************************************************/
|
||||
package forestry.farming.logic;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
@@ -29,7 +30,7 @@ public class CropFruit extends Crop {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isCrop(BlockPos pos) {
|
||||
protected boolean isCrop(World world, BlockPos pos) {
|
||||
TileEntity tile = world.getTileEntity(pos);
|
||||
if (!(tile instanceof IFruitBearer)) {
|
||||
return false;
|
||||
@@ -46,14 +47,14 @@ public class CropFruit extends Crop {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Collection<ItemStack> harvestBlock(BlockPos pos) {
|
||||
protected Collection<ItemStack> harvestBlock(World world, BlockPos pos) {
|
||||
TileEntity tile = world.getTileEntity(pos);
|
||||
if (!(tile instanceof IFruitBearer)) {
|
||||
return new ArrayList<>();
|
||||
return Collections.emptySet();
|
||||
}
|
||||
|
||||
Proxies.common.sendFXSignal(PacketFXSignal.VisualFXType.BLOCK_DESTROY, PacketFXSignal.SoundFXType.LEAF, world, pos,
|
||||
getBlock(pos).getDefaultState());
|
||||
IBlockState blockState = world.getBlockState(pos);
|
||||
Proxies.common.sendFXSignal(PacketFXSignal.VisualFXType.BLOCK_DESTROY, PacketFXSignal.SoundFXType.LEAF, world, pos, blockState);
|
||||
return ((IFruitBearer) tile).pickFruit(null);
|
||||
}
|
||||
|
||||
|
||||
@@ -15,13 +15,15 @@ import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import forestry.core.PluginCore;
|
||||
import forestry.core.blocks.BlockSoil;
|
||||
import forestry.core.blocks.BlockBogEarth;
|
||||
import forestry.core.config.Constants;
|
||||
import forestry.core.proxy.Proxies;
|
||||
|
||||
public class CropPeat extends Crop {
|
||||
@@ -31,24 +33,25 @@ public class CropPeat extends Crop {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isCrop(BlockPos pos) {
|
||||
Block block = getBlock(pos);
|
||||
if (!(block instanceof BlockSoil)) {
|
||||
protected boolean isCrop(World world, BlockPos pos) {
|
||||
Block block = world.getBlockState(pos).getBlock();
|
||||
if (!(block instanceof BlockBogEarth)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
BlockSoil blockSoil = (BlockSoil) block;
|
||||
BlockSoil.SoilType soilType = BlockSoil.getTypeFromMeta(getBlockMeta(pos));
|
||||
return soilType == BlockSoil.SoilType.PEAT;
|
||||
IBlockState blockState = world.getBlockState(pos);
|
||||
BlockBogEarth.SoilType soilType = BlockBogEarth.getTypeFromState(blockState);
|
||||
return soilType == BlockBogEarth.SoilType.PEAT;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Collection<ItemStack> harvestBlock(BlockPos pos) {
|
||||
protected Collection<ItemStack> harvestBlock(World world, BlockPos pos) {
|
||||
List<ItemStack> drops = new ArrayList<>();
|
||||
drops.add(PluginCore.items.peat.getItemStack());
|
||||
|
||||
Proxies.common.addBlockDestroyEffects(world, pos, getBlock(pos).getDefaultState());
|
||||
setBlock(pos, Blocks.DIRT.getDefaultState());
|
||||
IBlockState blockState = world.getBlockState(pos);
|
||||
Proxies.common.addBlockDestroyEffects(world, pos, blockState);
|
||||
world.setBlockState(pos, Blocks.DIRT.getDefaultState(), Constants.FLAG_BLOCK_SYNCH);
|
||||
return drops;
|
||||
}
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@ package forestry.farming.logic;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
@@ -22,18 +22,19 @@ import forestry.core.config.Constants;
|
||||
import forestry.core.proxy.Proxies;
|
||||
import forestry.plugins.compat.PluginIC2;
|
||||
|
||||
public class CropRubber extends CropBlock {
|
||||
public class CropRubber extends CropDestroy {
|
||||
|
||||
public CropRubber(World world, Block block, int meta, BlockPos position) {
|
||||
super(world, block, meta, position);
|
||||
public CropRubber(World world, IBlockState blockState, BlockPos position) {
|
||||
//TODO IC2 for 1.9: check that this is setting the right state for replanting.
|
||||
super(world, blockState, position, blockState.getBlock().getDefaultState());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Collection<ItemStack> harvestBlock(BlockPos pos) {
|
||||
protected Collection<ItemStack> harvestBlock(World world, BlockPos pos) {
|
||||
Collection<ItemStack> harvested = new ArrayList<>();
|
||||
harvested.add(PluginIC2.resin.copy());
|
||||
Proxies.common.addBlockDestroyEffects(world, pos, block.getDefaultState());
|
||||
world.setBlockState(pos, block.getStateFromMeta(meta + 6), Constants.FLAG_BLOCK_SYNCH);
|
||||
Proxies.common.addBlockDestroyEffects(world, pos, blockState);
|
||||
world.setBlockState(pos, replantState, Constants.FLAG_BLOCK_SYNCH);
|
||||
return harvested;
|
||||
}
|
||||
|
||||
|
||||
@@ -33,29 +33,19 @@ import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
import forestry.api.farming.FarmDirection;
|
||||
import forestry.api.farming.IFarmHousing;
|
||||
import forestry.api.farming.IFarmLogic;
|
||||
import forestry.core.config.Constants;
|
||||
import forestry.core.entities.EntitySelector;
|
||||
import forestry.core.utils.VectUtil;
|
||||
|
||||
public abstract class FarmLogic implements IFarmLogic {
|
||||
private final EntitySelectorFarm entitySelectorFarm = new EntitySelectorFarm(this);
|
||||
protected final IFarmHousing housing;
|
||||
protected boolean isManual;
|
||||
|
||||
protected FarmLogic(IFarmHousing housing) {
|
||||
this.housing = housing;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FarmLogic setManual(boolean flag) {
|
||||
isManual = flag;
|
||||
return this;
|
||||
}
|
||||
|
||||
protected World getWorld() {
|
||||
return housing.getWorldObj();
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
@Override
|
||||
public ResourceLocation getTextureMap() {
|
||||
@@ -86,18 +76,14 @@ public abstract class FarmLogic implements IFarmLogic {
|
||||
protected final boolean isWaterSourceBlock(World world, BlockPos position) {
|
||||
IBlockState blockState = world.getBlockState(position);
|
||||
Block block = blockState.getBlock();
|
||||
return block == Blocks.WATER && block.getMetaFromState(blockState) == 0;
|
||||
return block == Blocks.WATER;
|
||||
}
|
||||
|
||||
protected final BlockPos translateWithOffset(BlockPos pos, FarmDirection farmDirection, int step) {
|
||||
return VectUtil.scale(farmDirection.getFacing().getDirectionVec(), step).add(pos);
|
||||
}
|
||||
|
||||
protected final void setBlock(BlockPos position, Block block, int meta) {
|
||||
getWorld().setBlockState(position, block.getStateFromMeta(meta), Constants.FLAG_BLOCK_SYNCH_AND_UPDATE);
|
||||
}
|
||||
|
||||
private AxisAlignedBB getHarvestBox(IFarmHousing farmHousing, boolean toWorldHeight) {
|
||||
private static AxisAlignedBB getHarvestBox(World world, IFarmHousing farmHousing, boolean toWorldHeight) {
|
||||
BlockPos coords = farmHousing.getCoords();
|
||||
Vec3i area = farmHousing.getArea();
|
||||
Vec3i offset = farmHousing.getOffset();
|
||||
@@ -107,16 +93,16 @@ public abstract class FarmLogic implements IFarmLogic {
|
||||
|
||||
int maxY = max.getY();
|
||||
if (toWorldHeight) {
|
||||
maxY = getWorld().getHeight();
|
||||
maxY = world.getHeight();
|
||||
}
|
||||
|
||||
return new AxisAlignedBB(min.getX(), min.getY(), min.getZ(), max.getX(), maxY, max.getZ());
|
||||
}
|
||||
|
||||
protected List<ItemStack> collectEntityItems(boolean toWorldHeight) {
|
||||
AxisAlignedBB harvestBox = getHarvestBox(housing, toWorldHeight);
|
||||
protected List<ItemStack> collectEntityItems(World world, IFarmHousing farmHousing, boolean toWorldHeight) {
|
||||
AxisAlignedBB harvestBox = getHarvestBox(world, farmHousing, toWorldHeight);
|
||||
|
||||
List<EntityItem> entityItems = housing.getWorldObj().getEntitiesWithinAABB(entitySelectorFarm.getEntityClass(), harvestBox, entitySelectorFarm);
|
||||
List<EntityItem> entityItems = world.getEntitiesWithinAABB(entitySelectorFarm.getEntityClass(), harvestBox, entitySelectorFarm);
|
||||
List<ItemStack> stacks = new ArrayList<>();
|
||||
for (EntityItem entity : entityItems) {
|
||||
ItemStack contained = entity.getEntityItem();
|
||||
|
||||
@@ -10,7 +10,6 @@
|
||||
******************************************************************************/
|
||||
package forestry.farming.logic;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
@@ -21,7 +20,6 @@ import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.Stack;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.item.Item;
|
||||
@@ -38,31 +36,16 @@ import forestry.api.farming.ICrop;
|
||||
import forestry.api.farming.IFarmHousing;
|
||||
import forestry.api.farming.IFarmable;
|
||||
import forestry.core.PluginCore;
|
||||
import forestry.core.blocks.BlockSoil;
|
||||
|
||||
public class FarmLogicArboreal extends FarmLogicHomogeneous {
|
||||
private static final int BRANCH_RANGE = 20;
|
||||
|
||||
public FarmLogicArboreal(IFarmHousing housing, ItemStack resource, ItemStack ground, Iterable<IFarmable> germlings) {
|
||||
super(housing, resource, ground, germlings);
|
||||
public FarmLogicArboreal(ItemStack resource, IBlockState ground, Collection<IFarmable> germlings) {
|
||||
super(resource, ground, germlings);
|
||||
}
|
||||
|
||||
public FarmLogicArboreal(IFarmHousing housing) {
|
||||
super(housing, new ItemStack(Blocks.DIRT), PluginCore.blocks.soil.get(BlockSoil.SoilType.HUMUS, 1), Farmables.farmables.get("farmArboreal"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAcceptedSoil(@Nonnull ItemStack soil) {
|
||||
if (super.isAcceptedSoil(soil)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
Block block = Block.getBlockFromItem(soil.getItem());
|
||||
if (!(block instanceof BlockSoil)) {
|
||||
return false;
|
||||
}
|
||||
BlockSoil blockSoil = (BlockSoil) block;
|
||||
return BlockSoil.getTypeFromMeta(soil.getItemDamage()) == BlockSoil.SoilType.HUMUS;
|
||||
public FarmLogicArboreal() {
|
||||
super(new ItemStack(Blocks.DIRT), PluginCore.blocks.humus.getDefaultState(), Farmables.farmables.get("farmArboreal"));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -87,16 +70,16 @@ public class FarmLogicArboreal extends FarmLogicHomogeneous {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<ItemStack> collect() {
|
||||
public Collection<ItemStack> collect(World world, IFarmHousing farmHousing) {
|
||||
Collection<ItemStack> products = produce;
|
||||
produce = collectEntityItems(true);
|
||||
produce = collectEntityItems(world, farmHousing, true);
|
||||
return products;
|
||||
}
|
||||
|
||||
private final Map<BlockPos, Integer> lastExtentsHarvest = new HashMap<>();
|
||||
|
||||
@Override
|
||||
public Collection<ICrop> harvest(BlockPos pos, FarmDirection direction, int extent) {
|
||||
public Collection<ICrop> harvest(World world, BlockPos pos, FarmDirection direction, int extent) {
|
||||
|
||||
if (!lastExtentsHarvest.containsKey(pos)) {
|
||||
lastExtentsHarvest.put(pos, 0);
|
||||
@@ -108,43 +91,39 @@ public class FarmLogicArboreal extends FarmLogicHomogeneous {
|
||||
}
|
||||
|
||||
BlockPos position = translateWithOffset(pos.up(), direction, lastExtent);
|
||||
Collection<ICrop> crops = getHarvestBlocks(position);
|
||||
Collection<ICrop> crops = getHarvestBlocks(world, position);
|
||||
lastExtent++;
|
||||
lastExtentsHarvest.put(pos, lastExtent);
|
||||
|
||||
return crops;
|
||||
}
|
||||
|
||||
private Collection<ICrop> getHarvestBlocks(BlockPos position) {
|
||||
|
||||
World world = getWorld();
|
||||
|
||||
private Collection<ICrop> getHarvestBlocks(World world, BlockPos position) {
|
||||
Set<BlockPos> seen = new HashSet<>();
|
||||
Stack<ICrop> crops = new Stack<>();
|
||||
|
||||
IBlockState blockState = world.getBlockState(position);
|
||||
// Determine what type we want to harvest.
|
||||
IFarmable germling = null;
|
||||
for (IFarmable germl : germlings) {
|
||||
ICrop crop = germl.getCropAt(world, position);
|
||||
if (crop == null) {
|
||||
continue;
|
||||
for (IFarmable germl : farmables) {
|
||||
ICrop crop = germl.getCropAt(world, position, blockState);
|
||||
if (crop != null) {
|
||||
crops.push(crop);
|
||||
seen.add(position);
|
||||
germling = germl;
|
||||
break;
|
||||
}
|
||||
|
||||
crops.push(crop);
|
||||
seen.add(position);
|
||||
germling = germl;
|
||||
break;
|
||||
}
|
||||
|
||||
if (germling == null) {
|
||||
return crops;
|
||||
}
|
||||
|
||||
List<BlockPos> candidates = processHarvestBlock(germling, crops, seen, position, position);
|
||||
List<BlockPos> candidates = processHarvestBlock(world, germling, crops, seen, position, position);
|
||||
List<BlockPos> temp = new ArrayList<>();
|
||||
while (!candidates.isEmpty()) {
|
||||
for (BlockPos candidate : candidates) {
|
||||
temp.addAll(processHarvestBlock(germling, crops, seen, position, candidate));
|
||||
temp.addAll(processHarvestBlock(world, germling, crops, seen, position, candidate));
|
||||
}
|
||||
candidates.clear();
|
||||
candidates.addAll(temp);
|
||||
@@ -154,10 +133,7 @@ public class FarmLogicArboreal extends FarmLogicHomogeneous {
|
||||
return crops;
|
||||
}
|
||||
|
||||
private List<BlockPos> processHarvestBlock(IFarmable germling, Stack<ICrop> crops, Set<BlockPos> seen, BlockPos start, BlockPos position) {
|
||||
|
||||
World world = getWorld();
|
||||
|
||||
private static List<BlockPos> processHarvestBlock(World world, IFarmable germling, Stack<ICrop> crops, Set<BlockPos> seen, BlockPos start, BlockPos position) {
|
||||
List<BlockPos> candidates = new ArrayList<>();
|
||||
|
||||
// Get additional candidates to return
|
||||
@@ -180,7 +156,8 @@ public class FarmLogicArboreal extends FarmLogicHomogeneous {
|
||||
continue;
|
||||
}
|
||||
|
||||
ICrop crop = germling.getCropAt(world, candidate);
|
||||
IBlockState blockState = world.getBlockState(position);
|
||||
ICrop crop = germling.getCropAt(world, candidate, blockState);
|
||||
if (crop != null) {
|
||||
crops.push(crop);
|
||||
candidates.add(candidate);
|
||||
@@ -194,31 +171,25 @@ public class FarmLogicArboreal extends FarmLogicHomogeneous {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean maintainGermlings(BlockPos pos, FarmDirection direction, int extent) {
|
||||
|
||||
World world = getWorld();
|
||||
|
||||
protected boolean maintainGermlings(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.isAirBlock(position)) {
|
||||
BlockPos soilPosition = position.down();
|
||||
IBlockState soilState = world.getBlockState(soilPosition);
|
||||
Block soilBlock = soilState.getBlock();
|
||||
ItemStack soilBelow = soilBlock.getPickBlock(soilState, null, world, soilPosition, null);
|
||||
if (isAcceptedSoil(soilBelow)) {
|
||||
return plantSapling(position);
|
||||
if (isAcceptedSoil(soilState)) {
|
||||
return plantSapling(world, farmHousing, position);
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean plantSapling(BlockPos position) {
|
||||
World world = getWorld();
|
||||
Collections.shuffle(germlings);
|
||||
for (IFarmable candidate : germlings) {
|
||||
if (housing.plantGermling(candidate, world, position)) {
|
||||
private boolean plantSapling(World world, IFarmHousing farmHousing, BlockPos position) {
|
||||
Collections.shuffle(farmables);
|
||||
for (IFarmable candidate : farmables) {
|
||||
if (farmHousing.plantGermling(candidate, world, position)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,12 +17,11 @@ import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
import forestry.api.farming.Farmables;
|
||||
import forestry.api.farming.IFarmHousing;
|
||||
|
||||
public class FarmLogicCereal extends FarmLogicCrops {
|
||||
|
||||
public FarmLogicCereal(IFarmHousing housing) {
|
||||
super(housing, Farmables.farmables.get("farmWheat"));
|
||||
public FarmLogicCereal() {
|
||||
super(Farmables.farmables.get("farmWheat"));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -38,13 +38,8 @@ import forestry.api.farming.IFarmHousing;
|
||||
import forestry.api.farming.IFarmable;
|
||||
|
||||
public class FarmLogicCocoa extends FarmLogic {
|
||||
|
||||
private final IFarmable cocoa = new FarmableCocoa();
|
||||
|
||||
public FarmLogicCocoa(IFarmHousing housing) {
|
||||
super(housing);
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public Item getItem() {
|
||||
@@ -82,14 +77,14 @@ public class FarmLogicCocoa extends FarmLogic {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<ItemStack> collect() {
|
||||
public Collection<ItemStack> collect(World world, IFarmHousing farmHousing) {
|
||||
return null;
|
||||
}
|
||||
|
||||
private final Map<BlockPos, Integer> lastExtentsCultivation = new HashMap<>();
|
||||
|
||||
@Override
|
||||
public boolean cultivate(BlockPos pos, FarmDirection direction, int extent) {
|
||||
public boolean cultivate(World world, IFarmHousing farmHousing, BlockPos pos, FarmDirection direction, int extent) {
|
||||
|
||||
if (!lastExtentsCultivation.containsKey(pos)) {
|
||||
lastExtentsCultivation.put(pos, 0);
|
||||
@@ -101,7 +96,7 @@ public class FarmLogicCocoa extends FarmLogic {
|
||||
}
|
||||
|
||||
BlockPos position = translateWithOffset(pos.add(0, 1, 0), direction, lastExtent);
|
||||
boolean result = tryPlantingCocoa(position);
|
||||
boolean result = tryPlantingCocoa(world, farmHousing, position);
|
||||
|
||||
lastExtent++;
|
||||
lastExtentsCultivation.put(pos, lastExtent);
|
||||
@@ -112,7 +107,7 @@ public class FarmLogicCocoa extends FarmLogic {
|
||||
private final Map<BlockPos, Integer> lastExtentsHarvest = new HashMap<>();
|
||||
|
||||
@Override
|
||||
public Collection<ICrop> harvest(BlockPos pos, FarmDirection direction, int extent) {
|
||||
public Collection<ICrop> harvest(World world, BlockPos pos, FarmDirection direction, int extent) {
|
||||
if (!lastExtentsHarvest.containsKey(pos)) {
|
||||
lastExtentsHarvest.put(pos, 0);
|
||||
}
|
||||
@@ -123,17 +118,14 @@ public class FarmLogicCocoa extends FarmLogic {
|
||||
}
|
||||
|
||||
BlockPos position = translateWithOffset(pos.add(0, 1, 0), direction, lastExtent);
|
||||
Collection<ICrop> crops = getHarvestBlocks(position);
|
||||
Collection<ICrop> crops = getHarvestBlocks(world, position);
|
||||
lastExtent++;
|
||||
lastExtentsHarvest.put(pos, lastExtent);
|
||||
|
||||
return crops;
|
||||
}
|
||||
|
||||
private boolean tryPlantingCocoa(BlockPos position) {
|
||||
|
||||
World world = getWorld();
|
||||
|
||||
private boolean tryPlantingCocoa(World world, IFarmHousing farmHousing, BlockPos position) {
|
||||
BlockPos.MutableBlockPos current = new BlockPos.MutableBlockPos(position);
|
||||
IBlockState blockState = world.getBlockState(current);
|
||||
Block block = blockState.getBlock();
|
||||
@@ -142,7 +134,7 @@ public class FarmLogicCocoa extends FarmLogic {
|
||||
for (EnumFacing direction : EnumFacing.HORIZONTALS) {
|
||||
BlockPos candidate = new BlockPos(current.getX() + direction.getFrontOffsetX(), current.getY(), current.getZ() + direction.getFrontOffsetZ());
|
||||
if (world.isAirBlock(candidate)) {
|
||||
return housing.plantGermling(cocoa, world, candidate);
|
||||
return farmHousing.plantGermling(cocoa, world, candidate);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -158,18 +150,18 @@ public class FarmLogicCocoa extends FarmLogic {
|
||||
return false;
|
||||
}
|
||||
|
||||
private Collection<ICrop> getHarvestBlocks(BlockPos position) {
|
||||
private Collection<ICrop> getHarvestBlocks(World world, BlockPos position) {
|
||||
|
||||
Set<BlockPos> seen = new HashSet<>();
|
||||
Stack<ICrop> crops = new Stack<>();
|
||||
|
||||
// Determine what type we want to harvest.
|
||||
IBlockState blockState = getWorld().getBlockState(position);
|
||||
IBlockState blockState = world.getBlockState(position);
|
||||
Block block = blockState.getBlock();
|
||||
|
||||
ICrop crop = null;
|
||||
if (!block.isWood(getWorld(), position)) {
|
||||
crop = cocoa.getCropAt(getWorld(), position);
|
||||
if (!block.isWood(world, position)) {
|
||||
crop = cocoa.getCropAt(world, position, blockState);
|
||||
if (crop == null) {
|
||||
return crops;
|
||||
}
|
||||
@@ -179,11 +171,11 @@ public class FarmLogicCocoa extends FarmLogic {
|
||||
crops.add(crop);
|
||||
}
|
||||
|
||||
List<BlockPos> candidates = processHarvestBlock(crops, seen, position, position);
|
||||
List<BlockPos> candidates = processHarvestBlock(world, crops, seen, position, position);
|
||||
List<BlockPos> temp = new ArrayList<>();
|
||||
while (!candidates.isEmpty() && crops.size() < 20) {
|
||||
for (BlockPos candidate : candidates) {
|
||||
temp.addAll(processHarvestBlock(crops, seen, position, candidate));
|
||||
temp.addAll(processHarvestBlock(world, crops, seen, position, candidate));
|
||||
}
|
||||
candidates.clear();
|
||||
candidates.addAll(temp);
|
||||
@@ -194,10 +186,7 @@ public class FarmLogicCocoa extends FarmLogic {
|
||||
return crops;
|
||||
}
|
||||
|
||||
private List<BlockPos> processHarvestBlock(Stack<ICrop> crops, Set<BlockPos> seen, BlockPos start, BlockPos position) {
|
||||
|
||||
World world = getWorld();
|
||||
|
||||
private List<BlockPos> processHarvestBlock(World world, Stack<ICrop> crops, Set<BlockPos> seen, BlockPos start, BlockPos position) {
|
||||
List<BlockPos> candidates = new ArrayList<>();
|
||||
|
||||
// Get additional candidates to return
|
||||
@@ -220,14 +209,13 @@ public class FarmLogicCocoa extends FarmLogic {
|
||||
continue;
|
||||
}
|
||||
|
||||
ICrop crop = cocoa.getCropAt(world, candidate);
|
||||
IBlockState blockState = world.getBlockState(candidate);
|
||||
Block block = blockState.getBlock();
|
||||
ICrop crop = cocoa.getCropAt(world, candidate, blockState);
|
||||
if (crop != null) {
|
||||
crops.push(crop);
|
||||
candidates.add(candidate);
|
||||
seen.add(candidate);
|
||||
} else if (block.isWood(world, candidate)) {
|
||||
} else if (blockState.getBlock().isWood(world, candidate)) {
|
||||
candidates.add(candidate);
|
||||
seen.add(candidate);
|
||||
}
|
||||
|
||||
@@ -10,38 +10,34 @@
|
||||
******************************************************************************/
|
||||
package forestry.farming.logic;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.Collection;
|
||||
import java.util.Stack;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import net.minecraftforge.oredict.OreDictionary;
|
||||
|
||||
import forestry.api.farming.FarmDirection;
|
||||
import forestry.api.farming.ICrop;
|
||||
import forestry.api.farming.IFarmHousing;
|
||||
import forestry.api.farming.IFarmable;
|
||||
import forestry.core.utils.BlockUtil;
|
||||
import forestry.core.utils.ItemStackUtil;
|
||||
|
||||
public abstract class FarmLogicCrops extends FarmLogicWatered {
|
||||
private static final ItemStack farmland = new ItemStack(Blocks.FARMLAND, 1, OreDictionary.WILDCARD_VALUE);
|
||||
private final Iterable<IFarmable> seeds;
|
||||
|
||||
protected FarmLogicCrops(IFarmHousing housing, Iterable<IFarmable> seeds) {
|
||||
super(housing, new ItemStack(Blocks.DIRT), new ItemStack(Blocks.FARMLAND));
|
||||
protected FarmLogicCrops(Iterable<IFarmable> seeds) {
|
||||
super(new ItemStack(Blocks.DIRT), Blocks.FARMLAND.getDefaultState());
|
||||
|
||||
this.seeds = seeds;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAcceptedGround(ItemStack itemStack) {
|
||||
return super.isAcceptedGround(itemStack) || ItemStackUtil.isIdenticalItem(farmland, itemStack);
|
||||
public boolean isAcceptedGround(@Nonnull IBlockState blockState) {
|
||||
return super.isAcceptedGround(blockState) || blockState.getBlock() == Blocks.FARMLAND;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -65,17 +61,14 @@ public abstract class FarmLogicCrops extends FarmLogicWatered {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<ItemStack> collect() {
|
||||
public Collection<ItemStack> collect(World world, IFarmHousing farmHousing) {
|
||||
Collection<ItemStack> products = produce;
|
||||
produce = collectEntityItems(false);
|
||||
produce = collectEntityItems(world, farmHousing, false);
|
||||
return products;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean maintainCrops(BlockPos pos, FarmDirection direction, int extent) {
|
||||
|
||||
World world = getWorld();
|
||||
|
||||
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);
|
||||
IBlockState state = world.getBlockState(position);
|
||||
@@ -83,28 +76,18 @@ public abstract class FarmLogicCrops extends FarmLogicWatered {
|
||||
continue;
|
||||
}
|
||||
|
||||
BlockPos soilPosition = position.down();
|
||||
IBlockState blockState = world.getBlockState(soilPosition);
|
||||
Block block = blockState.getBlock();
|
||||
ItemStack below = block.getPickBlock(blockState, null, world, soilPosition, null);
|
||||
if (ground.getItem() != below.getItem()) {
|
||||
continue;
|
||||
IBlockState groundState = world.getBlockState(position.down());
|
||||
if (isAcceptedGround(groundState)) {
|
||||
return trySetCrop(world, farmHousing, position);
|
||||
}
|
||||
if (below.getItemDamage() <= 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
return trySetCrop(position);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean trySetCrop(BlockPos position) {
|
||||
World world = getWorld();
|
||||
|
||||
private boolean trySetCrop(World world, IFarmHousing farmHousing, BlockPos position) {
|
||||
for (IFarmable candidate : seeds) {
|
||||
if (housing.plantGermling(candidate, world, position)) {
|
||||
if (farmHousing.plantGermling(candidate, world, position)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -113,16 +96,16 @@ public abstract class FarmLogicCrops extends FarmLogicWatered {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<ICrop> harvest(BlockPos pos, FarmDirection direction, int extent) {
|
||||
World world = getWorld();
|
||||
|
||||
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.add(0, 1, 0), direction, i);
|
||||
IBlockState blockState = world.getBlockState(position);
|
||||
for (IFarmable seed : seeds) {
|
||||
ICrop crop = seed.getCropAt(world, position);
|
||||
ICrop crop = seed.getCropAt(world, position, blockState);
|
||||
if (crop != null) {
|
||||
crops.push(crop);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,7 +13,6 @@ package forestry.farming.logic;
|
||||
import java.util.Collection;
|
||||
import java.util.Stack;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.init.Items;
|
||||
@@ -34,8 +33,8 @@ import forestry.core.utils.BlockUtil;
|
||||
|
||||
public class FarmLogicEnder extends FarmLogicHomogeneous {
|
||||
|
||||
public FarmLogicEnder(IFarmHousing housing) {
|
||||
super(housing, new ItemStack(Blocks.END_STONE), new ItemStack(Blocks.END_STONE), Farmables.farmables.get("farmEnder"));
|
||||
public FarmLogicEnder() {
|
||||
super(new ItemStack(Blocks.END_STONE), Blocks.END_STONE.getDefaultState(), Farmables.farmables.get("farmEnder"));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -60,21 +59,21 @@ public class FarmLogicEnder extends FarmLogicHomogeneous {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<ItemStack> collect() {
|
||||
public Collection<ItemStack> collect(World world, IFarmHousing farmHousing) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<ICrop> harvest(BlockPos pos, FarmDirection direction, int extent) {
|
||||
World world = getWorld();
|
||||
|
||||
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);
|
||||
for (IFarmable farmable : germlings) {
|
||||
ICrop crop = farmable.getCropAt(world, position);
|
||||
IBlockState blockState = world.getBlockState(position);
|
||||
for (IFarmable farmable : farmables) {
|
||||
ICrop crop = farmable.getCropAt(world, position, blockState);
|
||||
if (crop != null) {
|
||||
crops.push(crop);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -84,9 +83,7 @@ public class FarmLogicEnder extends FarmLogicHomogeneous {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean maintainGermlings(BlockPos pos, FarmDirection direction, int extent) {
|
||||
World world = getWorld();
|
||||
|
||||
protected boolean maintainGermlings(World world, IFarmHousing farmHousing, BlockPos pos, FarmDirection direction, int extent) {
|
||||
for (int i = 0; i < extent; i++) {
|
||||
BlockPos position = translateWithOffset(pos, direction, i);
|
||||
IBlockState state = world.getBlockState(position);
|
||||
@@ -96,23 +93,19 @@ public class FarmLogicEnder extends FarmLogicHomogeneous {
|
||||
|
||||
BlockPos soilPos = position.down();
|
||||
IBlockState blockState = world.getBlockState(soilPos);
|
||||
Block block = blockState.getBlock();
|
||||
ItemStack below = block.getPickBlock(blockState, null, world, soilPos, null);
|
||||
if (!isAcceptedSoil(below)) {
|
||||
if (!isAcceptedSoil(blockState)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
return trySetCrop(position);
|
||||
return trySetCrop(world, farmHousing, position);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean trySetCrop(BlockPos position) {
|
||||
World world = getWorld();
|
||||
|
||||
for (IFarmable candidate : germlings) {
|
||||
if (housing.plantGermling(candidate, world, position)) {
|
||||
private boolean trySetCrop(World world, IFarmHousing farmHousing, BlockPos position) {
|
||||
for (IFarmable candidate : farmables) {
|
||||
if (farmHousing.plantGermling(candidate, world, position)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,6 +13,7 @@ package forestry.farming.logic;
|
||||
import java.util.Collection;
|
||||
import java.util.Stack;
|
||||
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.init.Items;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
@@ -32,8 +33,7 @@ public class FarmLogicGourd extends FarmLogic {
|
||||
|
||||
private final IFarmable[] seeds;
|
||||
|
||||
public FarmLogicGourd(IFarmHousing housing) {
|
||||
super(housing);
|
||||
public FarmLogicGourd() {
|
||||
Collection<IFarmable> farmables = Farmables.farmables.get("farmGourd");
|
||||
seeds = farmables.toArray(new IFarmable[farmables.size()]);
|
||||
}
|
||||
@@ -75,26 +75,26 @@ public class FarmLogicGourd extends FarmLogic {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<ItemStack> collect() {
|
||||
public Collection<ItemStack> collect(World world, IFarmHousing farmHousing) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean cultivate(BlockPos pos, FarmDirection direction, int extent) {
|
||||
public boolean cultivate(World world, IFarmHousing farmHousing, BlockPos pos, FarmDirection direction, int extent) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<ICrop> harvest(BlockPos pos, FarmDirection direction, int extent) {
|
||||
World world = getWorld();
|
||||
|
||||
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.add(0, 1, 0), direction, i);
|
||||
IBlockState blockState = world.getBlockState(position);
|
||||
for (IFarmable seed : seeds) {
|
||||
ICrop crop = seed.getCropAt(world, position);
|
||||
ICrop crop = seed.getCropAt(world, position, blockState);
|
||||
if (crop != null) {
|
||||
crops.push(crop);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,9 +12,9 @@ package forestry.farming.logic;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
@@ -24,29 +24,24 @@ import forestry.api.farming.FarmDirection;
|
||||
import forestry.api.farming.IFarmHousing;
|
||||
import forestry.api.farming.IFarmable;
|
||||
import forestry.core.utils.BlockUtil;
|
||||
import forestry.core.utils.ItemStackUtil;
|
||||
import forestry.farming.FarmHelper;
|
||||
|
||||
public abstract class FarmLogicHomogeneous extends FarmLogic {
|
||||
|
||||
private final ItemStack resource;
|
||||
private final ItemStack soilBlock;
|
||||
protected final List<IFarmable> germlings;
|
||||
private final IBlockState soilState;
|
||||
protected final List<IFarmable> farmables;
|
||||
|
||||
List<ItemStack> produce = new ArrayList<>();
|
||||
|
||||
protected FarmLogicHomogeneous(IFarmHousing housing, ItemStack resource, ItemStack soilBlock, Iterable<IFarmable> germlings) {
|
||||
super(housing);
|
||||
protected FarmLogicHomogeneous(ItemStack resource, @Nonnull IBlockState soilState, Collection<IFarmable> farmables) {
|
||||
this.resource = resource;
|
||||
this.soilBlock = soilBlock;
|
||||
this.germlings = new ArrayList<>();
|
||||
for (IFarmable germling : germlings) {
|
||||
this.germlings.add(germling);
|
||||
}
|
||||
this.soilState = soilState;
|
||||
this.farmables = new ArrayList<>(farmables);
|
||||
}
|
||||
|
||||
protected boolean isAcceptedSoil(@Nonnull ItemStack itemStack) {
|
||||
return ItemStackUtil.isIdenticalItem(soilBlock, itemStack);
|
||||
protected boolean isAcceptedSoil(@Nonnull IBlockState blockState) {
|
||||
return soilState.getBlock() == blockState.getBlock();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -56,7 +51,7 @@ public abstract class FarmLogicHomogeneous extends FarmLogic {
|
||||
|
||||
@Override
|
||||
public boolean isAcceptedGermling(ItemStack itemstack) {
|
||||
for (IFarmable germling : germlings) {
|
||||
for (IFarmable germling : farmables) {
|
||||
if (germling.isGermling(itemstack)) {
|
||||
return true;
|
||||
}
|
||||
@@ -66,7 +61,7 @@ public abstract class FarmLogicHomogeneous extends FarmLogic {
|
||||
|
||||
@Override
|
||||
public boolean isAcceptedWindfall(ItemStack itemstack) {
|
||||
for (IFarmable germling : germlings) {
|
||||
for (IFarmable germling : farmables) {
|
||||
if (germling.isWindfall(itemstack)) {
|
||||
return true;
|
||||
}
|
||||
@@ -75,56 +70,48 @@ public abstract class FarmLogicHomogeneous extends FarmLogic {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean cultivate(BlockPos pos, FarmDirection direction, int extent) {
|
||||
public boolean cultivate(World world, IFarmHousing farmHousing, BlockPos pos, FarmDirection direction, int extent) {
|
||||
|
||||
if (maintainSoil(pos, direction, extent)) {
|
||||
if (maintainSoil(world, farmHousing, pos, direction, extent)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return maintainGermlings(pos.add(0, 1, 0), direction, extent);
|
||||
return maintainGermlings(world, farmHousing, pos.add(0, 1, 0), direction, extent);
|
||||
}
|
||||
|
||||
private boolean maintainSoil(BlockPos pos, FarmDirection direction, int extent) {
|
||||
private boolean maintainSoil(World world, IFarmHousing farmHousing, BlockPos pos, FarmDirection direction, int extent) {
|
||||
ItemStack[] resources = new ItemStack[]{resource};
|
||||
if (!housing.getFarmInventory().hasResources(resources)) {
|
||||
if (!farmHousing.getFarmInventory().hasResources(resources)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
World world = getWorld();
|
||||
|
||||
for (int i = 0; i < extent; i++) {
|
||||
BlockPos position = translateWithOffset(pos, direction, i);
|
||||
IBlockState blockState1 = world.getBlockState(position);
|
||||
Block soil = blockState1.getBlock();
|
||||
IBlockState soilState = world.getBlockState(position);
|
||||
|
||||
if (FarmHelper.bricks.contains(soil)) {
|
||||
if (FarmHelper.bricks.contains(soilState.getBlock())) {
|
||||
break;
|
||||
}
|
||||
|
||||
IBlockState soilState = world.getBlockState(position);
|
||||
Block soilBlock = soilState.getBlock();
|
||||
ItemStack soilStack = soilBlock.getPickBlock(soilState, null, world, position, null);
|
||||
if (isAcceptedSoil(soilStack)) {
|
||||
if (isAcceptedSoil(soilState)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
BlockPos platformPosition = position.down();
|
||||
IBlockState blockState = world.getBlockState(platformPosition);
|
||||
Block platformBlock = blockState.getBlock();
|
||||
|
||||
if (!FarmHelper.bricks.contains(platformBlock)) {
|
||||
IBlockState platformState = world.getBlockState(platformPosition);
|
||||
if (!FarmHelper.bricks.contains(platformState.getBlock())) {
|
||||
break;
|
||||
}
|
||||
|
||||
produce.addAll(BlockUtil.getBlockDrops(world, position));
|
||||
|
||||
setBlock(position, ItemStackUtil.getBlock(this.soilBlock), this.soilBlock.getItemDamage());
|
||||
housing.getFarmInventory().removeResources(resources);
|
||||
world.setBlockState(position, this.soilState);
|
||||
farmHousing.getFarmInventory().removeResources(resources);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
protected abstract boolean maintainGermlings(BlockPos pos, FarmDirection direction, int extent);
|
||||
protected abstract boolean maintainGermlings(World world, IFarmHousing farmHousing, BlockPos pos, FarmDirection direction, int extent);
|
||||
}
|
||||
@@ -13,7 +13,6 @@ package forestry.farming.logic;
|
||||
import java.util.Collection;
|
||||
import java.util.Stack;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.init.Items;
|
||||
@@ -34,8 +33,8 @@ import forestry.core.utils.BlockUtil;
|
||||
|
||||
public class FarmLogicInfernal extends FarmLogicHomogeneous {
|
||||
|
||||
public FarmLogicInfernal(IFarmHousing housing) {
|
||||
super(housing, new ItemStack(Blocks.SOUL_SAND), new ItemStack(Blocks.SOUL_SAND), Farmables.farmables.get("farmInfernal"));
|
||||
public FarmLogicInfernal() {
|
||||
super(new ItemStack(Blocks.SOUL_SAND), Blocks.SOUL_SAND.getDefaultState(), Farmables.farmables.get("farmInfernal"));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -60,21 +59,21 @@ public class FarmLogicInfernal extends FarmLogicHomogeneous {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<ItemStack> collect() {
|
||||
public Collection<ItemStack> collect(World world, IFarmHousing farmHousing) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<ICrop> harvest(BlockPos pos, FarmDirection direction, int extent) {
|
||||
World world = getWorld();
|
||||
|
||||
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.add(0, 1, 0), direction, i);
|
||||
for (IFarmable farmable : germlings) {
|
||||
ICrop crop = farmable.getCropAt(world, position);
|
||||
IBlockState blockState = world.getBlockState(position);
|
||||
for (IFarmable farmable : farmables) {
|
||||
ICrop crop = farmable.getCropAt(world, position, blockState);
|
||||
if (crop != null) {
|
||||
crops.push(crop);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -84,9 +83,7 @@ public class FarmLogicInfernal extends FarmLogicHomogeneous {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean maintainGermlings(BlockPos pos, FarmDirection direction, int extent) {
|
||||
World world = getWorld();
|
||||
|
||||
protected boolean maintainGermlings(World world, IFarmHousing farmHousing, BlockPos pos, FarmDirection direction, int extent) {
|
||||
for (int i = 0; i < extent; i++) {
|
||||
BlockPos position = translateWithOffset(pos, direction, i);
|
||||
IBlockState blockState = world.getBlockState(position);
|
||||
@@ -96,23 +93,17 @@ public class FarmLogicInfernal extends FarmLogicHomogeneous {
|
||||
|
||||
BlockPos soilPosition = position.down();
|
||||
IBlockState soilState = world.getBlockState(soilPosition);
|
||||
Block soilBlock = soilState.getBlock();
|
||||
ItemStack soilStack = soilBlock.getPickBlock(soilState, null, world, soilPosition, null);
|
||||
if (!isAcceptedSoil(soilStack)) {
|
||||
continue;
|
||||
if (isAcceptedSoil(soilState)) {
|
||||
return trySetCrop(world, farmHousing, position);
|
||||
}
|
||||
|
||||
return trySetCrop(position);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean trySetCrop(BlockPos position) {
|
||||
World world = getWorld();
|
||||
|
||||
for (IFarmable candidate : germlings) {
|
||||
if (housing.plantGermling(candidate, world, position)) {
|
||||
private boolean trySetCrop(World world, IFarmHousing farmHousing, BlockPos position) {
|
||||
for (IFarmable candidate : farmables) {
|
||||
if (farmHousing.plantGermling(candidate, world, position)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
Executable → Regular
+5
-4
@@ -16,6 +16,7 @@ import java.util.Collection;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
@@ -23,10 +24,10 @@ import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
import forestry.api.farming.Farmables;
|
||||
import forestry.api.farming.IFarmHousing;
|
||||
|
||||
public class FarmLogicShroom extends FarmLogicArboreal {
|
||||
public class FarmLogicMushroom extends FarmLogicArboreal {
|
||||
|
||||
public FarmLogicShroom(IFarmHousing housing) {
|
||||
super(housing, new ItemStack(Blocks.MYCELIUM), new ItemStack(Blocks.MYCELIUM), Farmables.farmables.get("farmShroom"));
|
||||
public FarmLogicMushroom() {
|
||||
super(new ItemStack(Blocks.MYCELIUM), Blocks.MYCELIUM.getDefaultState(), Farmables.farmables.get("farmShroom"));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -55,7 +56,7 @@ public class FarmLogicShroom extends FarmLogicArboreal {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<ItemStack> collect() {
|
||||
public Collection<ItemStack> collect(World world, IFarmHousing farmHousing) {
|
||||
Collection<ItemStack> products = produce;
|
||||
produce = new ArrayList<>();
|
||||
return products;
|
||||
@@ -45,8 +45,7 @@ public class FarmLogicOrchard extends FarmLogic {
|
||||
private final HashMap<BlockPos, Integer> lastExtents = new HashMap<>();
|
||||
private final ImmutableList<Block> traversalBlocks;
|
||||
|
||||
public FarmLogicOrchard(IFarmHousing housing) {
|
||||
super(housing);
|
||||
public FarmLogicOrchard() {
|
||||
this.farmables = Farmables.farmables.get("farmOrchard");
|
||||
|
||||
ImmutableList.Builder<Block> traversalBlocksBuilder = ImmutableList.builder();
|
||||
@@ -97,17 +96,17 @@ public class FarmLogicOrchard extends FarmLogic {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<ItemStack> collect() {
|
||||
public Collection<ItemStack> collect(World world, IFarmHousing farmHousing) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean cultivate(BlockPos pos, FarmDirection direction, int extent) {
|
||||
public boolean cultivate(World world, IFarmHousing farmHousing, BlockPos pos, FarmDirection direction, int extent) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<ICrop> harvest(BlockPos pos, FarmDirection direction, int extent) {
|
||||
public Collection<ICrop> harvest(World world, BlockPos pos, FarmDirection direction, int extent) {
|
||||
|
||||
if (!lastExtents.containsKey(pos)) {
|
||||
lastExtents.put(pos, 0);
|
||||
@@ -119,7 +118,7 @@ public class FarmLogicOrchard extends FarmLogic {
|
||||
}
|
||||
|
||||
BlockPos position = translateWithOffset(pos.up(), direction, lastExtent);
|
||||
Collection<ICrop> crops = getHarvestBlocks(position);
|
||||
Collection<ICrop> crops = getHarvestBlocks(world, position);
|
||||
lastExtent++;
|
||||
lastExtents.put(pos, lastExtent);
|
||||
|
||||
@@ -137,13 +136,10 @@ public class FarmLogicOrchard extends FarmLogic {
|
||||
return "Orchard";
|
||||
}
|
||||
|
||||
private Collection<ICrop> getHarvestBlocks(BlockPos position) {
|
||||
|
||||
private Collection<ICrop> getHarvestBlocks(World world, BlockPos position) {
|
||||
Set<BlockPos> seen = new HashSet<>();
|
||||
Stack<ICrop> crops = new Stack<>();
|
||||
|
||||
World world = getWorld();
|
||||
|
||||
// Determine what type we want to harvest.
|
||||
IBlockState blockState = world.getBlockState(position);
|
||||
Block block = blockState.getBlock();
|
||||
@@ -151,11 +147,11 @@ public class FarmLogicOrchard extends FarmLogic {
|
||||
return crops;
|
||||
}
|
||||
|
||||
List<BlockPos> candidates = processHarvestBlock(crops, seen, position, position);
|
||||
List<BlockPos> candidates = processHarvestBlock(world, crops, seen, position, position);
|
||||
List<BlockPos> temp = new ArrayList<>();
|
||||
while (!candidates.isEmpty() && crops.size() < 20) {
|
||||
for (BlockPos candidate : candidates) {
|
||||
temp.addAll(processHarvestBlock(crops, seen, position, candidate));
|
||||
temp.addAll(processHarvestBlock(world, crops, seen, position, candidate));
|
||||
}
|
||||
candidates.clear();
|
||||
candidates.addAll(temp);
|
||||
@@ -165,9 +161,7 @@ public class FarmLogicOrchard extends FarmLogic {
|
||||
return crops;
|
||||
}
|
||||
|
||||
private List<BlockPos> processHarvestBlock(Stack<ICrop> crops, Set<BlockPos> seen, BlockPos start, BlockPos position) {
|
||||
World world = getWorld();
|
||||
|
||||
private List<BlockPos> processHarvestBlock(World world, Stack<ICrop> crops, Set<BlockPos> seen, BlockPos start, BlockPos position) {
|
||||
List<BlockPos> candidates = new ArrayList<>();
|
||||
|
||||
// Get additional candidates to return
|
||||
@@ -247,8 +241,9 @@ public class FarmLogicOrchard extends FarmLogic {
|
||||
return new CropFruit(world, position);
|
||||
}
|
||||
} else {
|
||||
IBlockState blockState = world.getBlockState(position);
|
||||
for (IFarmable seed : farmables) {
|
||||
ICrop crop = seed.getCropAt(world, position);
|
||||
ICrop crop = seed.getCropAt(world, position, blockState);
|
||||
if (crop != null) {
|
||||
return crop;
|
||||
}
|
||||
|
||||
@@ -25,30 +25,23 @@ import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
import forestry.api.farming.FarmDirection;
|
||||
import forestry.api.farming.ICrop;
|
||||
import forestry.api.farming.IFarmHousing;
|
||||
import forestry.core.PluginCore;
|
||||
import forestry.core.blocks.BlockSoil;
|
||||
import forestry.core.blocks.BlockBogEarth;
|
||||
|
||||
public class FarmLogicPeat extends FarmLogicWatered {
|
||||
private static final ItemStack bogEarth = PluginCore.blocks.soil.get(BlockSoil.SoilType.BOG_EARTH, 1);
|
||||
private static final ItemStack bogEarth = PluginCore.blocks.bogEarth.get(BlockBogEarth.SoilType.BOG_EARTH, 1);
|
||||
|
||||
public FarmLogicPeat(IFarmHousing housing) {
|
||||
super(housing, bogEarth, bogEarth);
|
||||
public FarmLogicPeat() {
|
||||
super(bogEarth, PluginCore.blocks.bogEarth.getDefaultState());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAcceptedGround(ItemStack itemStack) {
|
||||
if (super.isAcceptedGround(itemStack)) {
|
||||
public boolean isAcceptedGround(IBlockState blockState) {
|
||||
if (super.isAcceptedGround(blockState)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
Block block = Block.getBlockFromItem(itemStack.getItem());
|
||||
if (!(block instanceof BlockSoil)) {
|
||||
return false;
|
||||
}
|
||||
BlockSoil blockSoil = (BlockSoil) block;
|
||||
BlockSoil.SoilType soilType = BlockSoil.getTypeFromMeta(itemStack.getItemDamage());
|
||||
return soilType == BlockSoil.SoilType.BOG_EARTH || soilType == BlockSoil.SoilType.PEAT;
|
||||
return blockState.getBlock() == PluginCore.blocks.bogEarth;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -76,21 +69,19 @@ public class FarmLogicPeat extends FarmLogicWatered {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<ICrop> harvest(BlockPos pos, FarmDirection direction, int extent) {
|
||||
World world = getWorld();
|
||||
|
||||
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, direction, i);
|
||||
IBlockState blockState = world.getBlockState(position);
|
||||
Block block = blockState.getBlock();
|
||||
if (!(block instanceof BlockSoil)) {
|
||||
if (!(block instanceof BlockBogEarth)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
BlockSoil.SoilType soilType = BlockSoil.getTypeFromState(blockState);
|
||||
BlockBogEarth.SoilType soilType = BlockBogEarth.getTypeFromState(blockState);
|
||||
|
||||
if (soilType == BlockSoil.SoilType.PEAT) {
|
||||
if (soilType == BlockBogEarth.SoilType.PEAT) {
|
||||
crops.push(new CropPeat(world, position));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,6 +13,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.Item;
|
||||
@@ -31,14 +32,7 @@ import forestry.api.farming.IFarmable;
|
||||
import forestry.core.utils.ItemStackUtil;
|
||||
|
||||
public class FarmLogicReeds extends FarmLogic {
|
||||
|
||||
private final IFarmable[] germlings;
|
||||
|
||||
public FarmLogicReeds(IFarmHousing housing) {
|
||||
super(housing);
|
||||
Collection<IFarmable> farmables = Farmables.farmables.get("farmPoales");
|
||||
germlings = farmables.toArray(new IFarmable[farmables.size()]);
|
||||
}
|
||||
private final Collection<IFarmable> germlings = Farmables.farmables.get("farmPoales");
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
@@ -89,26 +83,26 @@ public class FarmLogicReeds extends FarmLogic {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<ItemStack> collect() {
|
||||
public Collection<ItemStack> collect(World world, IFarmHousing farmHousing) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean cultivate(BlockPos pos, FarmDirection direction, int extent) {
|
||||
public boolean cultivate(World world, IFarmHousing farmHousing, BlockPos pos, FarmDirection direction, int extent) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<ICrop> harvest(BlockPos pos, FarmDirection direction, int extent) {
|
||||
World world = getWorld();
|
||||
|
||||
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.add(0, 1, 0), direction, i);
|
||||
IBlockState blockState = world.getBlockState(position);
|
||||
for (IFarmable seed : germlings) {
|
||||
ICrop crop = seed.getCropAt(world, position);
|
||||
ICrop crop = seed.getCropAt(world, position, blockState);
|
||||
if (crop != null) {
|
||||
crops.push(crop);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,8 +41,7 @@ public class FarmLogicRubber extends FarmLogic {
|
||||
|
||||
private boolean inActive;
|
||||
|
||||
public FarmLogicRubber(IFarmHousing housing) {
|
||||
super(housing);
|
||||
public FarmLogicRubber() {
|
||||
if (PluginIC2.rubberWood == null || PluginIC2.resin == null) {
|
||||
Log.warning("Failed to init a farm logic %s since IC2 was not found", getClass().getName());
|
||||
inActive = true;
|
||||
@@ -90,19 +89,19 @@ public class FarmLogicRubber extends FarmLogic {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<ItemStack> collect() {
|
||||
public Collection<ItemStack> collect(World world, IFarmHousing farmHousing) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean cultivate(BlockPos pos, FarmDirection direction, int extent) {
|
||||
public boolean cultivate(World world, IFarmHousing farmHousing, BlockPos pos, FarmDirection direction, int extent) {
|
||||
return false;
|
||||
}
|
||||
|
||||
private final Map<BlockPos, Integer> lastExtents = new HashMap<>();
|
||||
|
||||
@Override
|
||||
public Collection<ICrop> harvest(BlockPos pos, FarmDirection direction, int extent) {
|
||||
public Collection<ICrop> harvest(World world, BlockPos pos, FarmDirection direction, int extent) {
|
||||
if (inActive) {
|
||||
return null;
|
||||
}
|
||||
@@ -117,20 +116,17 @@ public class FarmLogicRubber extends FarmLogic {
|
||||
}
|
||||
|
||||
BlockPos position = translateWithOffset(pos.add(0, 1, 0), direction, lastExtent);
|
||||
Collection<ICrop> crops = getHarvestBlocks(position);
|
||||
Collection<ICrop> crops = getHarvestBlocks(world, position);
|
||||
lastExtent++;
|
||||
lastExtents.put(pos, lastExtent);
|
||||
|
||||
return crops;
|
||||
}
|
||||
|
||||
private Collection<ICrop> getHarvestBlocks(BlockPos position) {
|
||||
|
||||
private Collection<ICrop> getHarvestBlocks(World world, BlockPos position) {
|
||||
Set<BlockPos> seen = new HashSet<>();
|
||||
Stack<ICrop> crops = new Stack<>();
|
||||
|
||||
World world = getWorld();
|
||||
|
||||
// Determine what type we want to harvest.
|
||||
IBlockState blockState = world.getBlockState(position);
|
||||
Block block = blockState.getBlock();
|
||||
@@ -140,14 +136,14 @@ public class FarmLogicRubber extends FarmLogic {
|
||||
|
||||
int meta = block.getMetaFromState(blockState);
|
||||
if (meta >= 2 && meta <= 5) {
|
||||
crops.push(new CropRubber(getWorld(), block, meta, position));
|
||||
crops.push(new CropDestroy(world, blockState, position, null));
|
||||
}
|
||||
|
||||
List<BlockPos> candidates = processHarvestBlock(crops, seen, position);
|
||||
List<BlockPos> candidates = processHarvestBlock(world, crops, seen, position);
|
||||
List<BlockPos> temp = new ArrayList<>();
|
||||
while (!candidates.isEmpty() && crops.size() < 100) {
|
||||
for (BlockPos candidate : candidates) {
|
||||
temp.addAll(processHarvestBlock(crops, seen, candidate));
|
||||
temp.addAll(processHarvestBlock(world, crops, seen, candidate));
|
||||
}
|
||||
candidates.clear();
|
||||
candidates.addAll(temp);
|
||||
@@ -157,9 +153,7 @@ public class FarmLogicRubber extends FarmLogic {
|
||||
return crops;
|
||||
}
|
||||
|
||||
private List<BlockPos> processHarvestBlock(Stack<ICrop> crops, Set<BlockPos> seen, BlockPos position) {
|
||||
World world = getWorld();
|
||||
|
||||
private List<BlockPos> processHarvestBlock(World world, Stack<ICrop> crops, Set<BlockPos> seen, BlockPos position) {
|
||||
List<BlockPos> candidates = new ArrayList<>();
|
||||
|
||||
// Get additional candidates to return
|
||||
@@ -179,7 +173,7 @@ public class FarmLogicRubber extends FarmLogic {
|
||||
if (ItemStackUtil.equals(block, PluginIC2.rubberWood)) {
|
||||
int meta = block.getMetaFromState(blockState);
|
||||
if (meta >= 2 && meta <= 5) {
|
||||
crops.push(new CropRubber(world, block, meta, candidate));
|
||||
crops.push(new CropRubber(world, blockState, candidate));
|
||||
}
|
||||
candidates.add(candidate);
|
||||
seen.add(candidate);
|
||||
|
||||
@@ -13,6 +13,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.Item;
|
||||
@@ -31,14 +32,7 @@ import forestry.api.farming.IFarmable;
|
||||
import forestry.core.utils.ItemStackUtil;
|
||||
|
||||
public class FarmLogicSucculent extends FarmLogic {
|
||||
|
||||
private final IFarmable[] germlings;
|
||||
|
||||
public FarmLogicSucculent(IFarmHousing housing) {
|
||||
super(housing);
|
||||
Collection<IFarmable> farmables = Farmables.farmables.get("farmSucculentes");
|
||||
germlings = farmables.toArray(new IFarmable[farmables.size()]);
|
||||
}
|
||||
private final Collection<IFarmable> germlings = Farmables.farmables.get("farmSucculentes");
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
@@ -95,26 +89,26 @@ public class FarmLogicSucculent extends FarmLogic {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<ItemStack> collect() {
|
||||
public Collection<ItemStack> collect(World world, IFarmHousing farmHousing) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean cultivate(BlockPos pos, FarmDirection direction, int extent) {
|
||||
public boolean cultivate(World world, IFarmHousing farmHousing, BlockPos pos, FarmDirection direction, int extent) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<ICrop> harvest(BlockPos pos, FarmDirection direction, int extent) {
|
||||
World world = getWorld();
|
||||
|
||||
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 : germlings) {
|
||||
ICrop crop = seed.getCropAt(world, position);
|
||||
ICrop crop = seed.getCropAt(world, position, blockState);
|
||||
if (crop != null) {
|
||||
crops.push(crop);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,12 +17,11 @@ import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
import forestry.api.farming.Farmables;
|
||||
import forestry.api.farming.IFarmHousing;
|
||||
|
||||
public class FarmLogicVegetable extends FarmLogicCrops {
|
||||
|
||||
public FarmLogicVegetable(IFarmHousing housing) {
|
||||
super(housing, Farmables.farmables.get("farmVegetables"));
|
||||
public FarmLogicVegetable() {
|
||||
super(Farmables.farmables.get("farmVegetables"));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -10,11 +10,11 @@
|
||||
******************************************************************************/
|
||||
package forestry.farming.logic;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.item.ItemStack;
|
||||
@@ -27,20 +27,18 @@ import forestry.api.farming.FarmDirection;
|
||||
import forestry.api.farming.IFarmHousing;
|
||||
import forestry.core.fluids.Fluids;
|
||||
import forestry.core.utils.BlockUtil;
|
||||
import forestry.core.utils.ItemStackUtil;
|
||||
import forestry.farming.FarmHelper;
|
||||
|
||||
public abstract class FarmLogicWatered extends FarmLogic {
|
||||
|
||||
protected final ItemStack ground;
|
||||
protected final IBlockState ground;
|
||||
private final ItemStack resource;
|
||||
|
||||
private static final FluidStack STACK_WATER = Fluids.WATER.getFluid(1000);
|
||||
|
||||
List<ItemStack> produce = new ArrayList<>();
|
||||
protected List<ItemStack> produce = new ArrayList<>();
|
||||
|
||||
protected FarmLogicWatered(IFarmHousing housing, ItemStack resource, ItemStack ground) {
|
||||
super(housing);
|
||||
protected FarmLogicWatered(ItemStack resource, @Nonnull IBlockState ground) {
|
||||
this.ground = ground;
|
||||
this.resource = resource;
|
||||
}
|
||||
@@ -55,8 +53,8 @@ public abstract class FarmLogicWatered extends FarmLogic {
|
||||
return (int) (20 * hydrationModifier);
|
||||
}
|
||||
|
||||
protected boolean isAcceptedGround(ItemStack ground) {
|
||||
return ItemStackUtil.isIdenticalItem(this.ground, ground);
|
||||
protected boolean isAcceptedGround(IBlockState ground) {
|
||||
return this.ground.getBlock() == ground.getBlock();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -65,86 +63,76 @@ public abstract class FarmLogicWatered extends FarmLogic {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<ItemStack> collect() {
|
||||
public Collection<ItemStack> collect(World world, IFarmHousing farmHousing) {
|
||||
Collection<ItemStack> products = produce;
|
||||
produce = new ArrayList<>();
|
||||
return products;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean cultivate(BlockPos pos, FarmDirection direction, int extent) {
|
||||
public boolean cultivate(World world, IFarmHousing farmHousing, BlockPos pos, FarmDirection direction, int extent) {
|
||||
|
||||
if (maintainSoil(pos, direction, extent)) {
|
||||
if (maintainSoil(world, farmHousing, pos, direction, extent)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!isManual && maintainWater(pos, direction, extent)) {
|
||||
if (!isManual && maintainWater(world, farmHousing, pos, direction, extent)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (maintainCrops(pos.add(0, 1, 0), direction, extent)) {
|
||||
if (maintainCrops(world, farmHousing, pos.add(0, 1, 0), direction, extent)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean maintainSoil(BlockPos pos, FarmDirection direction, int extent) {
|
||||
|
||||
World world = getWorld();
|
||||
private boolean maintainSoil(World world, IFarmHousing farmHousing, BlockPos pos, FarmDirection direction, int extent) {
|
||||
ItemStack[] resources = new ItemStack[]{resource};
|
||||
|
||||
for (int i = 0; i < extent; i++) {
|
||||
BlockPos position = translateWithOffset(pos, direction, i);
|
||||
IBlockState state = world.getBlockState(position);
|
||||
Block soil = state.getBlock();
|
||||
|
||||
ItemStack soilStack = soil.getPickBlock(state, null, world, position, null);
|
||||
if (isAcceptedGround(soilStack) || !housing.getFarmInventory().hasResources(resources)) {
|
||||
if (isAcceptedGround(state) || isWaterSourceBlock(world, position) || !farmHousing.getFarmInventory().hasResources(resources)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
BlockPos platformPosition = position.down();
|
||||
IBlockState blockState = world.getBlockState(platformPosition);
|
||||
Block platformBlock = blockState.getBlock();
|
||||
if (!FarmHelper.bricks.contains(platformBlock)) {
|
||||
if (!FarmHelper.bricks.contains(blockState.getBlock())) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (!soil.isAir(state, world, platformPosition) && !BlockUtil.isReplaceableBlock(state, world, platformPosition)) {
|
||||
produce.addAll(BlockUtil.getBlockDrops(getWorld(), position));
|
||||
if (!BlockUtil.isReplaceableBlock(state, world, platformPosition)) {
|
||||
produce.addAll(BlockUtil.getBlockDrops(world, position));
|
||||
world.setBlockToAir(position);
|
||||
return trySetSoil(position);
|
||||
return trySetSoil(world, farmHousing, position);
|
||||
}
|
||||
|
||||
if (isManual || isWaterSourceBlock(world, position)) {
|
||||
continue;
|
||||
}
|
||||
if (!isManual) {
|
||||
if (trySetWater(world, farmHousing, position)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (trySetWater(world, position)) {
|
||||
return true;
|
||||
return trySetSoil(world, farmHousing, position);
|
||||
}
|
||||
|
||||
return trySetSoil(position);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean maintainWater(BlockPos pos, FarmDirection direction, int extent) {
|
||||
private boolean maintainWater(World world, IFarmHousing farmHousing, BlockPos pos, FarmDirection direction, int extent) {
|
||||
// Still not done, check water then
|
||||
World world = getWorld();
|
||||
for (int i = 0; i < extent; i++) {
|
||||
BlockPos position = translateWithOffset(pos, direction, i);
|
||||
|
||||
BlockPos platformPosition = position.down();
|
||||
IBlockState blockState = world.getBlockState(platformPosition);
|
||||
Block platformBlock = blockState.getBlock();
|
||||
if (!FarmHelper.bricks.contains(platformBlock)) {
|
||||
if (!FarmHelper.bricks.contains(blockState.getBlock())) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (trySetWater(world, position)) {
|
||||
if (trySetWater(world, farmHousing, position)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -152,32 +140,32 @@ public abstract class FarmLogicWatered extends FarmLogic {
|
||||
return false;
|
||||
}
|
||||
|
||||
protected boolean maintainCrops(BlockPos pos, FarmDirection direction, int extent) {
|
||||
protected boolean maintainCrops(World world, IFarmHousing farmHousing, BlockPos pos, FarmDirection direction, int extent) {
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean trySetSoil(BlockPos position) {
|
||||
private boolean trySetSoil(World world, IFarmHousing farmHousing, BlockPos position) {
|
||||
ItemStack[] resources = new ItemStack[]{resource};
|
||||
if (!housing.getFarmInventory().hasResources(resources)) {
|
||||
if (!farmHousing.getFarmInventory().hasResources(resources)) {
|
||||
return false;
|
||||
}
|
||||
setBlock(position, ItemStackUtil.getBlock(ground), ground.getItemDamage());
|
||||
housing.getFarmInventory().removeResources(resources);
|
||||
world.setBlockState(position, ground);
|
||||
farmHousing.getFarmInventory().removeResources(resources);
|
||||
return true;
|
||||
}
|
||||
|
||||
private boolean trySetWater(World world, BlockPos position) {
|
||||
private boolean trySetWater(World world, IFarmHousing farmHousing, BlockPos position) {
|
||||
if (isWaterSourceBlock(world, position) || !canPlaceWater(world, position)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!housing.hasLiquid(STACK_WATER)) {
|
||||
if (!farmHousing.hasLiquid(STACK_WATER)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
produce.addAll(BlockUtil.getBlockDrops(world, position));
|
||||
setBlock(position, Blocks.WATER, 0);
|
||||
housing.removeLiquid(STACK_WATER);
|
||||
world.setBlockState(position, Blocks.WATER.getDefaultState());
|
||||
farmHousing.removeLiquid(STACK_WATER);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,78 @@
|
||||
package forestry.farming.logic;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.properties.IProperty;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import forestry.api.farming.ICrop;
|
||||
import forestry.api.farming.IFarmable;
|
||||
|
||||
/**
|
||||
* For blocks that are harvestable once they are a certain aga.
|
||||
*/
|
||||
public class FarmableAgingCrop implements IFarmable {
|
||||
protected final ItemStack germling;
|
||||
protected final Block cropBlock;
|
||||
protected final IProperty<Integer> ageProperty;
|
||||
protected final int minHarvestAge;
|
||||
@Nullable
|
||||
protected final Integer replantAge;
|
||||
|
||||
public FarmableAgingCrop(ItemStack germling, Block cropBlock, IProperty<Integer> ageProperty, int minHarvestAge) {
|
||||
this(germling, cropBlock, ageProperty, minHarvestAge, null);
|
||||
}
|
||||
|
||||
public FarmableAgingCrop(ItemStack germling, Block cropBlock, IProperty<Integer> ageProperty, int minHarvestAge, @Nullable Integer replantAge) {
|
||||
this.germling = germling;
|
||||
this.cropBlock = cropBlock;
|
||||
this.ageProperty = ageProperty;
|
||||
this.minHarvestAge = minHarvestAge;
|
||||
this.replantAge = replantAge;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSaplingAt(World world, BlockPos pos) {
|
||||
IBlockState blockState = world.getBlockState(pos);
|
||||
return blockState.getBlock() == cropBlock && blockState.getValue(ageProperty) < minHarvestAge;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ICrop getCropAt(World world, BlockPos pos, IBlockState blockState) {
|
||||
if (blockState.getBlock() != cropBlock) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (blockState.getValue(ageProperty) < minHarvestAge) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (replantAge != null) {
|
||||
IBlockState replantState = cropBlock.getDefaultState().withProperty(ageProperty, replantAge);
|
||||
return new CropDestroy(world, blockState, pos, replantState);
|
||||
} else {
|
||||
return new CropDestroy(world, blockState, pos, null);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isGermling(ItemStack itemstack) {
|
||||
return ItemStack.areItemsEqual(germling, itemstack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean plantSaplingAt(EntityPlayer player, ItemStack germling, World world, BlockPos pos) {
|
||||
IBlockState plantedState = cropBlock.getDefaultState().withProperty(ageProperty, 0);
|
||||
return world.setBlockState(pos, plantedState);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isWindfall(ItemStack itemstack) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
package forestry.farming.logic;
|
||||
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import forestry.api.farming.ICrop;
|
||||
import forestry.api.farming.IFarmable;
|
||||
import forestry.core.config.Constants;
|
||||
|
||||
public abstract class FarmableBase implements IFarmable {
|
||||
protected final ItemStack germling;
|
||||
protected final IBlockState plantedState;
|
||||
protected final IBlockState matureState;
|
||||
protected final boolean replant;
|
||||
|
||||
public FarmableBase(ItemStack germling, IBlockState plantedState, IBlockState matureState, boolean replant) {
|
||||
this.germling = germling;
|
||||
this.plantedState = plantedState;
|
||||
this.matureState = matureState;
|
||||
this.replant = replant;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSaplingAt(World world, BlockPos pos) {
|
||||
IBlockState blockState = world.getBlockState(pos);
|
||||
return blockState.getBlock() == plantedState.getBlock() && blockState != matureState;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ICrop getCropAt(World world, BlockPos pos, IBlockState blockState) {
|
||||
if (blockState != matureState) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (replant) {
|
||||
return new CropDestroy(world, blockState, pos, plantedState);
|
||||
} else {
|
||||
return new CropDestroy(world, blockState, pos, null);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isGermling(ItemStack itemstack) {
|
||||
return ItemStack.areItemsEqual(germling, itemstack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean plantSaplingAt(EntityPlayer player, ItemStack germling, World world, BlockPos pos) {
|
||||
return world.setBlockState(pos, plantedState, Constants.FLAG_BLOCK_SYNCH);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isWindfall(ItemStack itemstack) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -10,61 +10,23 @@
|
||||
******************************************************************************/
|
||||
package forestry.farming.logic;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import forestry.api.farming.ICrop;
|
||||
import forestry.api.farming.IFarmable;
|
||||
import forestry.core.config.Constants;
|
||||
import forestry.core.utils.ItemStackUtil;
|
||||
|
||||
public class FarmableBasicAgricraft implements IFarmable {
|
||||
|
||||
private final Block block;
|
||||
private final int matureMeta;
|
||||
|
||||
public FarmableBasicAgricraft(Block block, int matureMeta) {
|
||||
this.block = block;
|
||||
this.matureMeta = matureMeta;
|
||||
public class FarmableBasicAgricraft extends FarmableBase {
|
||||
public FarmableBasicAgricraft(ItemStack germling, IBlockState plantedState, IBlockState matureState, boolean replant) {
|
||||
super(germling, plantedState, matureState, replant);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSaplingAt(World world, BlockPos pos) {
|
||||
return world.getBlockState(pos).getBlock() == this.block;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ICrop getCropAt(World world, BlockPos pos) {
|
||||
IBlockState blockState = world.getBlockState(pos);
|
||||
Block block = blockState.getBlock();
|
||||
if (block != this.block) {
|
||||
public ICrop getCropAt(World world, BlockPos pos, IBlockState blockState) {
|
||||
if (blockState != matureState) {
|
||||
return null;
|
||||
}
|
||||
|
||||
int blockMetadata = block.getMetaFromState(blockState);
|
||||
if (blockMetadata != matureMeta) {
|
||||
return null;
|
||||
}
|
||||
return new CropBasicAgriCraft(world, this.block, matureMeta, pos);
|
||||
return new CropBasicAgriCraft(world, blockState, pos);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isGermling(ItemStack itemstack) {
|
||||
return ItemStackUtil.equals(block, itemstack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isWindfall(ItemStack itemstack) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean plantSaplingAt(EntityPlayer player, ItemStack germling, World world, BlockPos pos) {
|
||||
return world.setBlockState(pos, block.getDefaultState(), Constants.FLAG_BLOCK_SYNCH);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,68 +0,0 @@
|
||||
/*******************************************************************************
|
||||
* 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.Block;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import forestry.api.farming.ICrop;
|
||||
import forestry.api.farming.IFarmable;
|
||||
import forestry.core.config.Constants;
|
||||
import forestry.core.utils.ItemStackUtil;
|
||||
|
||||
public class FarmableBasicFruit implements IFarmable {
|
||||
|
||||
private final Block block;
|
||||
private final int matureMeta;
|
||||
|
||||
public FarmableBasicFruit(Block block, int matureMeta) {
|
||||
this.block = block;
|
||||
this.matureMeta = matureMeta;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSaplingAt(World world, BlockPos pos) {
|
||||
return world.getBlockState(pos).getBlock() == block;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ICrop getCropAt(World world, BlockPos pos) {
|
||||
IBlockState blockState = world.getBlockState(pos);
|
||||
Block block = blockState.getBlock();
|
||||
if (block != this.block) {
|
||||
return null;
|
||||
}
|
||||
if (block.getMetaFromState(blockState) != matureMeta) {
|
||||
return null;
|
||||
}
|
||||
return new CropBasicFruit(world, this.block, matureMeta, pos);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isGermling(ItemStack itemstack) {
|
||||
return ItemStackUtil.equals(block, itemstack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean plantSaplingAt(EntityPlayer player, ItemStack germling, World world, BlockPos pos) {
|
||||
return world.setBlockState(pos, block.getDefaultState(), Constants.FLAG_BLOCK_SYNCH);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isWindfall(ItemStack itemstack) {
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -10,19 +10,9 @@
|
||||
******************************************************************************/
|
||||
package forestry.farming.logic;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import forestry.api.farming.ICrop;
|
||||
import forestry.api.farming.IFarmable;
|
||||
import forestry.core.config.Constants;
|
||||
import forestry.core.utils.ItemStackUtil;
|
||||
|
||||
public class FarmableBasicGrowthCraft implements IFarmable {
|
||||
//TODO GrowthCraft for 1.9
|
||||
public class FarmableBasicGrowthCraft {
|
||||
} /*implements IFarmable {
|
||||
|
||||
private final Block block;
|
||||
private final int matureMeta;
|
||||
@@ -36,11 +26,6 @@ public class FarmableBasicGrowthCraft implements IFarmable {
|
||||
this.isGrape = isGrape;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSaplingAt(World world, BlockPos pos) {
|
||||
return world.getBlockState(pos).getBlock() == block;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ICrop getCropAt(World world, BlockPos pos) {
|
||||
IBlockState blockState = world.getBlockState(pos);
|
||||
@@ -70,3 +55,4 @@ public class FarmableBasicGrowthCraft implements IFarmable {
|
||||
}
|
||||
|
||||
}
|
||||
*/
|
||||
@@ -10,9 +10,7 @@
|
||||
******************************************************************************/
|
||||
package forestry.farming.logic;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockCocoa;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.init.Items;
|
||||
@@ -21,49 +19,19 @@ import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import forestry.api.farming.ICrop;
|
||||
import forestry.api.farming.IFarmable;
|
||||
import forestry.core.utils.BlockUtil;
|
||||
|
||||
public class FarmableCocoa implements IFarmable {
|
||||
public class FarmableCocoa extends FarmableAgingCrop {
|
||||
|
||||
private static final Block COCOA_PLANT = Blocks.COCOA;
|
||||
public static final Item COCOA_SEED = Items.DYE;
|
||||
public static final int COCOA_META = 3;
|
||||
|
||||
@Override
|
||||
public boolean isSaplingAt(World world, BlockPos pos) {
|
||||
return world.getBlockState(pos).getBlock() == COCOA_PLANT;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ICrop getCropAt(World world, BlockPos pos) {
|
||||
IBlockState blockState = world.getBlockState(pos);
|
||||
Block block = blockState.getBlock();
|
||||
if (block != COCOA_PLANT) {
|
||||
return null;
|
||||
}
|
||||
int meta = block.getMetaFromState(blockState);
|
||||
if (blockState.getValue(BlockCocoa.AGE) < 2) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return new CropBlock(world, block, meta, pos);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isGermling(ItemStack itemstack) {
|
||||
return itemstack.getItem() == COCOA_SEED && itemstack.getItemDamage() == COCOA_META;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isWindfall(ItemStack itemstack) {
|
||||
return false;
|
||||
public FarmableCocoa() {
|
||||
super(new ItemStack(COCOA_SEED, 1, COCOA_META), Blocks.COCOA, BlockCocoa.AGE, 2, 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean plantSaplingAt(EntityPlayer player, ItemStack germling, World world, BlockPos pos) {
|
||||
return BlockUtil.tryPlantCocoaPod(world, pos);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -14,17 +14,15 @@ import net.minecraft.block.Block;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.EnumActionResult;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.EnumHand;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import forestry.api.arboriculture.IAlleleTreeSpecies;
|
||||
import forestry.api.arboriculture.ITree;
|
||||
import forestry.api.arboriculture.TreeManager;
|
||||
import forestry.api.farming.ICrop;
|
||||
import forestry.api.farming.IFarmable;
|
||||
import forestry.arboriculture.PluginArboriculture;
|
||||
import forestry.arboriculture.genetics.TreeGenome;
|
||||
import forestry.core.utils.GeneticsUtil;
|
||||
|
||||
public class FarmableGE implements IFarmable {
|
||||
|
||||
@@ -40,26 +38,29 @@ public class FarmableGE implements IFarmable {
|
||||
}
|
||||
|
||||
@Override
|
||||
public ICrop getCropAt(World world, BlockPos pos) {
|
||||
IBlockState blockState = world.getBlockState(pos);
|
||||
public ICrop getCropAt(World world, BlockPos pos, IBlockState blockState) {
|
||||
Block block = blockState.getBlock();
|
||||
|
||||
if (!block.isWood(world, pos)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return new CropBlock(world, block, block.getMetaFromState(blockState), pos);
|
||||
return new CropDestroy(world, blockState, pos, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean plantSaplingAt(EntityPlayer player, ItemStack germling, World world, BlockPos pos) {
|
||||
return germling.copy().onItemUse(player, world, pos.down(), EnumHand.MAIN_HAND, EnumFacing.UP, 0, 0, 0) == EnumActionResult.SUCCESS;
|
||||
ITree tree = TreeManager.treeRoot.getMember(germling);
|
||||
if (tree == null) {
|
||||
return false;
|
||||
}
|
||||
return TreeManager.treeRoot.plantSapling(world, tree, player.getGameProfile(), pos);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isGermling(ItemStack itemstack) {
|
||||
IAlleleTreeSpecies tree = TreeGenome.getSpecies(itemstack);
|
||||
return tree != null;
|
||||
itemstack = GeneticsUtil.convertSaplingToGeneticEquivalent(itemstack);
|
||||
return TreeManager.treeRoot.isMember(itemstack);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -22,64 +22,42 @@ import net.minecraft.world.World;
|
||||
|
||||
import forestry.api.farming.ICrop;
|
||||
import forestry.api.farming.IFarmable;
|
||||
import forestry.core.utils.ItemStackUtil;
|
||||
|
||||
public class FarmableGenericSapling implements IFarmable {
|
||||
|
||||
protected final Block sapling;
|
||||
private final int saplingMeta;
|
||||
protected final ItemStack germling;
|
||||
protected final IBlockState plantedState;
|
||||
private final boolean replant;
|
||||
private final ItemStack[] windfall;
|
||||
|
||||
public FarmableGenericSapling(Block sapling, int saplingMeta, ItemStack... windfall) {
|
||||
this.sapling = sapling;
|
||||
this.saplingMeta = saplingMeta;
|
||||
public FarmableGenericSapling(ItemStack germling, IBlockState plantedState, boolean replant, ItemStack... windfall) {
|
||||
this.germling = germling;
|
||||
this.plantedState = plantedState;
|
||||
this.replant = replant;
|
||||
this.windfall = windfall;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSaplingAt(World world, BlockPos pos) {
|
||||
|
||||
if (world.isAirBlock(pos)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
IBlockState blockState = world.getBlockState(pos);
|
||||
Block block = blockState.getBlock();
|
||||
if (block == sapling) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (saplingMeta >= 0) {
|
||||
return block.getMetaFromState(blockState) == saplingMeta;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
|
||||
return world.getBlockState(pos).getBlock() == plantedState.getBlock();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ICrop getCropAt(World world, BlockPos pos) {
|
||||
IBlockState blockState = world.getBlockState(pos);
|
||||
public ICrop getCropAt(World world, BlockPos pos, IBlockState blockState) {
|
||||
Block block = blockState.getBlock();
|
||||
if (!block.isWood(world, pos)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return new CropBlock(world, block, block.getMetaFromState(blockState), pos);
|
||||
if (replant) {
|
||||
return new CropDestroy(world, blockState, pos, plantedState);
|
||||
} else {
|
||||
return new CropDestroy(world, blockState, pos, null);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isGermling(ItemStack itemstack) {
|
||||
|
||||
if (!ItemStackUtil.equals(sapling, itemstack)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (saplingMeta >= 0) {
|
||||
return itemstack.getItemDamage() == saplingMeta;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
return ItemStack.areItemsEqual(germling, itemstack);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -19,16 +19,14 @@ import net.minecraft.world.World;
|
||||
|
||||
import forestry.api.farming.ICrop;
|
||||
import forestry.api.farming.IFarmable;
|
||||
import forestry.core.config.Constants;
|
||||
import forestry.core.utils.ItemStackUtil;
|
||||
|
||||
public class FarmableGourd implements IFarmable {
|
||||
|
||||
private final ItemStack seed;
|
||||
private final ItemStack stem;
|
||||
private final ItemStack fruit;
|
||||
private final Block stem;
|
||||
private final Block fruit;
|
||||
|
||||
public FarmableGourd(ItemStack seed, ItemStack stem, ItemStack fruit) {
|
||||
public FarmableGourd(ItemStack seed, Block stem, Block fruit) {
|
||||
this.seed = seed;
|
||||
this.stem = stem;
|
||||
this.fruit = fruit;
|
||||
@@ -36,35 +34,22 @@ public class FarmableGourd implements IFarmable {
|
||||
|
||||
@Override
|
||||
public boolean isSaplingAt(World world, BlockPos pos) {
|
||||
if (world.isAirBlock(pos)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return ItemStackUtil.equals(world.getBlockState(pos).getBlock(), stem);
|
||||
IBlockState blockState = world.getBlockState(pos);
|
||||
return blockState.getBlock() == stem;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ICrop getCropAt(World world, BlockPos pos) {
|
||||
if (world.isAirBlock(pos)) {
|
||||
public ICrop getCropAt(World world, BlockPos pos, IBlockState blockState) {
|
||||
if (blockState.getBlock() != fruit) {
|
||||
return null;
|
||||
}
|
||||
|
||||
IBlockState blockState = world.getBlockState(pos);
|
||||
Block block = blockState.getBlock();
|
||||
if (!ItemStackUtil.equals(block, fruit)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (block.getMetaFromState(blockState) != fruit.getItemDamage()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return new CropBlock(world, ItemStackUtil.getBlock(fruit), fruit.getItemDamage(), pos);
|
||||
return new CropDestroy(world, blockState, pos, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isGermling(ItemStack itemstack) {
|
||||
return seed.isItemEqual(itemstack);
|
||||
return ItemStack.areItemsEqual(itemstack, seed);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -74,7 +59,7 @@ public class FarmableGourd implements IFarmable {
|
||||
|
||||
@Override
|
||||
public boolean plantSaplingAt(EntityPlayer player, ItemStack germling, World world, BlockPos pos) {
|
||||
return world.setBlockState(pos, ItemStackUtil.getBlock(stem).getDefaultState(), Constants.FLAG_BLOCK_SYNCH);
|
||||
return world.setBlockState(pos, stem.getDefaultState());
|
||||
}
|
||||
|
||||
}
|
||||
Executable → Regular
+3
-45
@@ -10,7 +10,6 @@
|
||||
******************************************************************************/
|
||||
package forestry.farming.logic;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
@@ -20,55 +19,14 @@ import net.minecraft.util.EnumHand;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import forestry.api.farming.ICrop;
|
||||
import forestry.api.farming.IFarmable;
|
||||
|
||||
public class FarmableGenericCrop implements IFarmable {
|
||||
|
||||
private final ItemStack seed;
|
||||
private final Block block;
|
||||
private final int mature;
|
||||
public class FarmableHandPlanted extends FarmableBase {
|
||||
private final ItemStack[] windfall;
|
||||
|
||||
public FarmableGenericCrop(ItemStack seed, Block block, int mature, ItemStack... windfall) {
|
||||
this.seed = seed;
|
||||
this.block = block;
|
||||
this.mature = mature;
|
||||
public FarmableHandPlanted(ItemStack seed, IBlockState plantedState, IBlockState matureState, boolean replant, ItemStack... windfall) {
|
||||
super(seed, plantedState, matureState, replant);
|
||||
this.windfall = windfall;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSaplingAt(World world, BlockPos pos) {
|
||||
return world.getBlockState(pos).getBlock() == block;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ICrop getCropAt(World world, BlockPos pos) {
|
||||
IBlockState blockState = world.getBlockState(pos);
|
||||
Block block = blockState.getBlock();
|
||||
if (block != this.block) {
|
||||
return null;
|
||||
}
|
||||
if (block.getMetaFromState(blockState) != mature) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return new CropBlock(world, this.block, mature, pos);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isGermling(ItemStack itemstack) {
|
||||
if (seed.getItem() != itemstack.getItem()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (seed.getItemDamage() >= 0) {
|
||||
return seed.getItemDamage() == itemstack.getItemDamage();
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean plantSaplingAt(EntityPlayer player, ItemStack germling, World world, BlockPos pos) {
|
||||
return germling.copy().onItemUse(player, world, pos.down(), EnumHand.MAIN_HAND, EnumFacing.UP, 0, 0, 0) == EnumActionResult.SUCCESS;
|
||||
@@ -11,6 +11,7 @@
|
||||
package forestry.farming.logic;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
@@ -18,48 +19,48 @@ import net.minecraft.world.World;
|
||||
|
||||
import forestry.api.farming.ICrop;
|
||||
import forestry.api.farming.IFarmable;
|
||||
import forestry.core.config.Constants;
|
||||
import forestry.core.utils.ItemStackUtil;
|
||||
|
||||
public class FarmableStacked implements IFarmable {
|
||||
protected final ItemStack germling;
|
||||
protected final Block cropBlock;
|
||||
protected final int matureHeight;
|
||||
|
||||
private final Block block;
|
||||
private final int matureHeight;
|
||||
private final int matureMeta;
|
||||
|
||||
public FarmableStacked(Block block, int matureHeight, int matureMeta) {
|
||||
this.block = block;
|
||||
public FarmableStacked(ItemStack germling, Block cropBlock, int matureHeight) {
|
||||
this.germling = germling;
|
||||
this.cropBlock = cropBlock;
|
||||
this.matureHeight = matureHeight;
|
||||
this.matureMeta = matureMeta;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSaplingAt(World world, BlockPos pos) {
|
||||
return world.getBlockState(pos).getBlock() == block;
|
||||
IBlockState blockState = world.getBlockState(pos);
|
||||
return blockState.getBlock() == cropBlock;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ICrop getCropAt(World world, BlockPos pos) {
|
||||
BlockPos cropPos = new BlockPos(pos.getX(), pos.getY() + matureHeight - 1, pos.getZ());
|
||||
if (world.getBlockState(cropPos).getBlock() != block) {
|
||||
public ICrop getCropAt(World world, BlockPos pos, IBlockState blockState) {
|
||||
BlockPos cropPos = pos.add(0, matureHeight - 1, 0);
|
||||
blockState = world.getBlockState(cropPos);
|
||||
if (blockState.getBlock() != cropBlock) {
|
||||
return null;
|
||||
}
|
||||
return new CropBlock(world, block, matureMeta, cropPos);
|
||||
|
||||
return new CropDestroy(world, blockState, cropPos, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isGermling(ItemStack itemstack) {
|
||||
return ItemStackUtil.equals(block, itemstack);
|
||||
return ItemStack.areItemsEqual(germling, itemstack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean plantSaplingAt(EntityPlayer player, ItemStack germling, World world, BlockPos pos) {
|
||||
return world.setBlockState(pos, block.getDefaultState(), Constants.FLAG_BLOCK_SYNCH);
|
||||
IBlockState plantedState = cropBlock.getDefaultState();
|
||||
return world.setBlockState(pos, plantedState);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isWindfall(ItemStack itemstack) {
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -12,49 +12,26 @@ package forestry.farming.logic;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import forestry.api.farming.ICrop;
|
||||
import forestry.core.config.Constants;
|
||||
import forestry.core.proxy.Proxies;
|
||||
import forestry.core.utils.ItemStackUtil;
|
||||
import forestry.farming.PluginFarming;
|
||||
|
||||
public class FarmableVanillaMushroom extends FarmableGenericSapling {
|
||||
public class FarmableVanillaMushroom extends FarmableBase {
|
||||
private final Block hugeMushroomBlock;
|
||||
|
||||
public FarmableVanillaMushroom(Block sapling, int saplingMeta) {
|
||||
super(sapling, saplingMeta);
|
||||
public FarmableVanillaMushroom(ItemStack mushroom, IBlockState plantedMushroom, Block hugeMushroomBlock) {
|
||||
super(mushroom, plantedMushroom, hugeMushroomBlock.getDefaultState(), false);
|
||||
this.hugeMushroomBlock = hugeMushroomBlock;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ICrop getCropAt(World world, BlockPos pos) {
|
||||
IBlockState blockState = world.getBlockState(pos);
|
||||
Block block = blockState.getBlock();
|
||||
|
||||
if (block != Blocks.BROWN_MUSHROOM_BLOCK && block != Blocks.RED_MUSHROOM_BLOCK) {
|
||||
public ICrop getCropAt(World world, BlockPos pos, IBlockState blockState) {
|
||||
if (blockState.getBlock() != hugeMushroomBlock) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return new CropBlock(world, block, block.getMetaFromState(blockState), pos);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isGermling(ItemStack itemstack) {
|
||||
return ItemStackUtil.equals(sapling, itemstack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean plantSaplingAt(EntityPlayer player, ItemStack germling, World world, BlockPos pos) {
|
||||
int meta = 0;
|
||||
if (ItemStackUtil.equals(Blocks.RED_MUSHROOM, germling)) {
|
||||
meta = 1;
|
||||
}
|
||||
|
||||
Proxies.common.addBlockPlaceEffects(world, pos, Blocks.BROWN_MUSHROOM.getDefaultState());
|
||||
return world.setBlockState(pos, PluginFarming.blocks.mushroom.getStateFromMeta(meta), Constants.FLAG_BLOCK_SYNCH_AND_UPDATE);
|
||||
return new CropDestroy(world, blockState, pos, null);
|
||||
}
|
||||
}
|
||||
@@ -15,9 +15,9 @@ import net.minecraft.init.Blocks;
|
||||
import net.minecraft.init.Items;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.EnumActionResult;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.EnumHand;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import forestry.api.arboriculture.ITree;
|
||||
@@ -30,7 +30,7 @@ import forestry.plugins.ForestryPluginUids;
|
||||
public class FarmableVanillaSapling extends FarmableGenericSapling {
|
||||
|
||||
public FarmableVanillaSapling() {
|
||||
super(Blocks.SAPLING, -1, new ItemStack(Items.APPLE), new ItemStack(FarmableCocoa.COCOA_SEED, 1, FarmableCocoa.COCOA_META));
|
||||
super(new ItemStack(Blocks.SAPLING), Blocks.SAPLING.getDefaultState(), false, new ItemStack(Items.APPLE), new ItemStack(FarmableCocoa.COCOA_SEED, 1, FarmableCocoa.COCOA_META));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -23,7 +23,6 @@ import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.Stack;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
@@ -47,6 +46,7 @@ import forestry.api.core.ForestryAPI;
|
||||
import forestry.api.core.IErrorLogic;
|
||||
import forestry.api.farming.FarmDirection;
|
||||
import forestry.api.farming.ICrop;
|
||||
import forestry.api.farming.IFarmHousing;
|
||||
import forestry.api.farming.IFarmInventory;
|
||||
import forestry.api.farming.IFarmListener;
|
||||
import forestry.api.farming.IFarmLogic;
|
||||
@@ -493,7 +493,7 @@ public class FarmController extends RectangularMultiblockControllerBase implemen
|
||||
List<FarmTarget> farmTargets = targets.get(farmSide);
|
||||
|
||||
if (stage == Stage.HARVEST) {
|
||||
Collection<ICrop> harvested = harvestTargets(farmTargets, logic, farmListeners);
|
||||
Collection<ICrop> harvested = harvestTargets(worldObj, farmTargets, logic, farmListeners);
|
||||
farmWorkStatus.didWork = !harvested.isEmpty();
|
||||
if (!harvested.isEmpty()) {
|
||||
pendingCrops.addAll(harvested);
|
||||
@@ -571,8 +571,7 @@ public class FarmController extends RectangularMultiblockControllerBase implemen
|
||||
}
|
||||
|
||||
IBlockState blockState = world.getBlockState(groundLocation);
|
||||
Block platform = blockState.getBlock();
|
||||
if (!FarmHelper.bricks.contains(platform)) {
|
||||
if (!FarmHelper.bricks.contains(blockState.getBlock())) {
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -588,8 +587,7 @@ public class FarmController extends RectangularMultiblockControllerBase implemen
|
||||
for (int yOffset = 2; yOffset > -4; yOffset--) {
|
||||
BlockPos position = targetPosition.add(0, yOffset, 0);
|
||||
IBlockState blockState = world.getBlockState(position);
|
||||
Block ground = blockState.getBlock();
|
||||
if (FarmHelper.bricks.contains(ground)) {
|
||||
if (FarmHelper.bricks.contains(blockState.getBlock())) {
|
||||
return position;
|
||||
}
|
||||
}
|
||||
@@ -648,7 +646,7 @@ public class FarmController extends RectangularMultiblockControllerBase implemen
|
||||
continue;
|
||||
}
|
||||
|
||||
if (cultivateTarget(target, logic, farmListeners)) {
|
||||
if (cultivateTarget(worldObj, this, target, logic, farmListeners)) {
|
||||
// Remove fertilizer and water
|
||||
fertilizerManager.removeFertilizer(fertilizerConsumption);
|
||||
removeLiquid(liquid);
|
||||
@@ -664,9 +662,9 @@ public class FarmController extends RectangularMultiblockControllerBase implemen
|
||||
return farmWorkStatus;
|
||||
}
|
||||
|
||||
private static boolean cultivateTarget(FarmTarget target, IFarmLogic logic, Iterable<IFarmListener> farmListeners) {
|
||||
private static boolean cultivateTarget(World world, IFarmHousing farmHousing, FarmTarget target, IFarmLogic logic, Iterable<IFarmListener> farmListeners) {
|
||||
BlockPos targetPosition = target.getStart().add(0, target.getYOffset(), 0);
|
||||
if (logic.cultivate(targetPosition, target.getDirection(), target.getExtent())) {
|
||||
if (logic.cultivate(world, farmHousing, targetPosition, target.getDirection(), target.getExtent())) {
|
||||
for (IFarmListener listener : farmListeners) {
|
||||
listener.hasCultivated(logic, targetPosition, target.getDirection(), target.getExtent());
|
||||
}
|
||||
@@ -676,10 +674,10 @@ public class FarmController extends RectangularMultiblockControllerBase implemen
|
||||
return false;
|
||||
}
|
||||
|
||||
private static Collection<ICrop> harvestTargets(List<FarmTarget> farmTargets, IFarmLogic logic, Iterable<IFarmListener> farmListeners) {
|
||||
private static Collection<ICrop> harvestTargets(World world, List<FarmTarget> farmTargets, IFarmLogic logic, Iterable<IFarmListener> farmListeners) {
|
||||
if (farmTargets != null) {
|
||||
for (FarmTarget target : farmTargets) {
|
||||
Collection<ICrop> harvested = harvestTarget(target, logic, farmListeners);
|
||||
Collection<ICrop> harvested = harvestTarget(world, target, logic, farmListeners);
|
||||
if (!harvested.isEmpty()) {
|
||||
return harvested;
|
||||
}
|
||||
@@ -689,9 +687,9 @@ public class FarmController extends RectangularMultiblockControllerBase implemen
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
private static Collection<ICrop> harvestTarget(FarmTarget target, IFarmLogic logic, Iterable<IFarmListener> farmListeners) {
|
||||
BlockPos pos = new BlockPos(target.getStart().getX(), target.getStart().getX() + target.getYOffset(), target.getStart().getZ());
|
||||
Collection<ICrop> harvested = logic.harvest(pos, target.getDirection(), target.getExtent());
|
||||
private static Collection<ICrop> harvestTarget(World world, FarmTarget target, IFarmLogic logic, Iterable<IFarmListener> farmListeners) {
|
||||
BlockPos pos = target.getStart().add(0, target.getYOffset(), 0);
|
||||
Collection<ICrop> harvested = logic.harvest(world, pos, target.getDirection(), target.getExtent());
|
||||
if (harvested == null || harvested.isEmpty()) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
@@ -705,8 +703,7 @@ public class FarmController extends RectangularMultiblockControllerBase implemen
|
||||
}
|
||||
|
||||
private boolean collectWindfall(IFarmLogic logic) {
|
||||
|
||||
Collection<ItemStack> collected = logic.collect();
|
||||
Collection<ItemStack> collected = logic.collect(worldObj, this);
|
||||
if (collected == null || collected.size() <= 0) {
|
||||
return false;
|
||||
}
|
||||
@@ -808,7 +805,7 @@ public class FarmController extends RectangularMultiblockControllerBase implemen
|
||||
|
||||
@Override
|
||||
public void resetFarmLogic(FarmDirection direction) {
|
||||
setFarmLogic(direction, new FarmLogicArboreal(this));
|
||||
setFarmLogic(direction, new FarmLogicArboreal());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -23,7 +23,6 @@ import net.minecraftforge.oredict.OreDictionary;
|
||||
|
||||
import forestry.api.apiculture.FlowerManager;
|
||||
import forestry.api.core.ForestryAPI;
|
||||
import forestry.api.farming.Farmables;
|
||||
import forestry.api.recipes.RecipeManagers;
|
||||
import forestry.api.storage.BackpackManager;
|
||||
import forestry.core.PluginCore;
|
||||
@@ -33,9 +32,6 @@ import forestry.core.recipes.RecipeUtil;
|
||||
import forestry.core.utils.ItemStackUtil;
|
||||
import forestry.core.utils.Log;
|
||||
import forestry.core.utils.ModUtil;
|
||||
import forestry.farming.logic.FarmableBasicFruit;
|
||||
import forestry.farming.logic.FarmableGenericCrop;
|
||||
import forestry.farming.logic.FarmableGenericSapling;
|
||||
import forestry.plugins.BlankForestryPlugin;
|
||||
import forestry.plugins.ForestryPlugin;
|
||||
import forestry.plugins.ForestryPluginUids;
|
||||
@@ -111,7 +107,8 @@ public class PluginBiomesOPlenty extends BlankForestryPlugin {
|
||||
}
|
||||
|
||||
if (ForestryAPI.enabledPlugins.contains(ForestryPluginUids.FARMING) && saplings != null && persimmon != null) {
|
||||
Farmables.farmables.get("farmArboreal").add(new FarmableGenericSapling(saplings, 15, persimmon));
|
||||
//TODO BoP for 1.9: Add farmables
|
||||
// Farmables.farmables.put("farmArboreal", new FarmableGenericSapling(saplings, 15, persimmon));
|
||||
}
|
||||
|
||||
Block boPTurnip = GameRegistry.findBlock(BoP, "turnip");
|
||||
@@ -119,13 +116,15 @@ public class PluginBiomesOPlenty extends BlankForestryPlugin {
|
||||
Item boPTurnipSeeds = GameRegistry.findItem(BoP, "turnipSeeds");
|
||||
ItemStack boPTurnipSeedStack = new ItemStack(boPTurnipSeeds, 1, 0);
|
||||
if (boPTurnipSeeds != null) {
|
||||
Farmables.farmables.get("farmVegetables").add(new FarmableGenericCrop(boPTurnipSeedStack, boPTurnip, 7));
|
||||
//TODO BoP for 1.9: Add farmable saplings
|
||||
// Farmables.farmables.get("farmVegetables").add(new FarmableHandPlanted(boPTurnipSeedStack, boPTurnip, 7));
|
||||
if (ForestryAPI.enabledPlugins.contains(ForestryPluginUids.FACTORY)) {
|
||||
RecipeManagers.squeezerManager.addRecipe(10, new ItemStack[]{boPTurnipSeedStack}, Fluids.SEED_OIL.getFluid(amount));
|
||||
}
|
||||
}
|
||||
|
||||
Farmables.farmables.get("farmOrchard").add(new FarmableBasicFruit(boPTurnip, 7));
|
||||
//TODO BoP for 1.9: Add farmables
|
||||
// Farmables.farmables.get("farmOrchard").add(new FarmableBase(boPTurnip, 7));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -229,7 +229,7 @@ public class PluginIC2 extends BlankForestryPlugin {
|
||||
// if (waterCell != null) {
|
||||
// int bogEarthOutputCan = ForestryAPI.activeMode.getIntegerSetting("recipe.output.bogearth.can");
|
||||
// if (bogEarthOutputCan > 0) {
|
||||
// ItemStack bogEarthCan = PluginCore.blocks.soil.get(BlockSoil.SoilType.BOG_EARTH, bogEarthOutputCan);
|
||||
// ItemStack bogEarthCan = PluginCore.blocks.soil.get(BlockBogEarth.SoilType.BOG_EARTH, bogEarthOutputCan);
|
||||
// RecipeUtil.addRecipe(bogEarthCan, "#Y#", "YXY", "#Y#", '#', Blocks.DIRT, 'X', waterCell, 'Y', "sand");
|
||||
// }
|
||||
// }
|
||||
|
||||
@@ -23,7 +23,6 @@ import net.minecraftforge.fml.common.registry.GameRegistry;
|
||||
import net.minecraftforge.oredict.OreDictionary;
|
||||
|
||||
import forestry.api.core.ForestryAPI;
|
||||
import forestry.api.farming.Farmables;
|
||||
import forestry.api.fuels.FuelManager;
|
||||
import forestry.api.fuels.MoistenerFuel;
|
||||
import forestry.api.recipes.RecipeManagers;
|
||||
@@ -35,7 +34,6 @@ import forestry.core.fluids.Fluids;
|
||||
import forestry.core.recipes.RecipeUtil;
|
||||
import forestry.core.utils.ItemStackUtil;
|
||||
import forestry.core.utils.ModUtil;
|
||||
import forestry.farming.logic.FarmableGenericCrop;
|
||||
import forestry.plugins.BlankForestryPlugin;
|
||||
import forestry.plugins.ForestryPlugin;
|
||||
import forestry.plugins.ForestryPluginUids;
|
||||
@@ -224,8 +222,9 @@ public class PluginNatura extends BlankForestryPlugin {
|
||||
|
||||
if (ForestryAPI.enabledPlugins.contains(ForestryPluginUids.FARMING)) {
|
||||
Block cropBlock = GameRegistry.findBlock(NATURA, "N Crops");
|
||||
Farmables.farmables.get("farmWheat").add(new FarmableGenericCrop(seedBarley, cropBlock, 3));
|
||||
Farmables.farmables.get("farmWheat").add(new FarmableGenericCrop(seedCotton, cropBlock, 8));
|
||||
//TODO: Natura for 1.9
|
||||
// Farmables.farmables.get("farmWheat").add(new FarmableHandPlanted(seedBarley, cropBlock, 3));
|
||||
// Farmables.farmables.get("farmWheat").add(new FarmableHandPlanted(seedCotton, cropBlock, 8));
|
||||
}
|
||||
|
||||
List<ItemStack> berries = new ArrayList<>();
|
||||
|
||||
Reference in new issue
Block a user