mirror of
https://github.com/GTNewHorizons/ForestryMC.git
synced 2026-11-21 04:22:32 +00:00
Improve Farm Logic System and add ring farm layout
This commit is contained in:
1 parent
521514f3d2
commit
10fec50457
53 files changed
+1019
-534
No files matched your search
@@ -61,6 +61,10 @@ public interface IFarmHousing extends IErrorLogicSource {
|
||||
return false;
|
||||
}
|
||||
|
||||
default boolean canPlantSoil(boolean manual){
|
||||
return true;
|
||||
}
|
||||
|
||||
/* INTERACTION WITH HATCHES */
|
||||
IFarmInventory getFarmInventory();
|
||||
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
package forestry.api.farming;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
/**
|
||||
* @since Forestry 5.8
|
||||
*/
|
||||
public interface IFarmInstance {
|
||||
|
||||
default void registerSoil(ItemStack resource, IBlockState soilState){
|
||||
registerSoil(resource, soilState, false);
|
||||
}
|
||||
|
||||
void registerSoil(ItemStack resource, IBlockState soilState, boolean hasMetaData);
|
||||
|
||||
boolean isAcceptedSoil(IBlockState blockState);
|
||||
|
||||
boolean isAcceptedResource(ItemStack itemStack);
|
||||
|
||||
String getIdentifier();
|
||||
|
||||
Collection<ISoil> getSoils();
|
||||
|
||||
Collection<IFarmable> getFarmables();
|
||||
|
||||
IFarmLogic getLogic(boolean manuel);
|
||||
}
|
||||
@@ -8,6 +8,7 @@ package forestry.api.farming;
|
||||
import java.util.Collection;
|
||||
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.client.renderer.texture.TextureMap;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.NonNullList;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
@@ -17,10 +18,20 @@ import net.minecraft.world.World;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
import forestry.api.core.ForestryAPI;
|
||||
|
||||
public interface IFarmLogic {
|
||||
|
||||
/**
|
||||
* @return The amount of fertilizer that the {@link IFarmHousing} automatically removes after this logic cultivated
|
||||
* a block or harvested a crop.
|
||||
*/
|
||||
int getFertilizerConsumption();
|
||||
|
||||
/**
|
||||
* @return The amount of water that the {@link IFarmHousing} automatically removes after this logic cultivated
|
||||
* a block or harvested a crop.
|
||||
*/
|
||||
int getWaterConsumption(float hydrationModifier);
|
||||
|
||||
boolean isAcceptedResource(ItemStack itemstack);
|
||||
@@ -33,20 +44,50 @@ public interface IFarmLogic {
|
||||
|
||||
Collection<ICrop> harvest(World world, BlockPos pos, FarmDirection direction, int extent);
|
||||
|
||||
IFarmLogic setManual(boolean manual);
|
||||
/**
|
||||
* @deprecated Since Forestry 5.8 logic instances are created at the constructor of the {@link IFarmInstance} and
|
||||
* have a immutable manual state. TODO Remove this method in 1.13
|
||||
*/
|
||||
@Deprecated
|
||||
default IFarmLogic setManual(boolean manual){
|
||||
return this;
|
||||
}
|
||||
|
||||
void addSoil(ItemStack resource, IBlockState soilState, boolean hasMetaData);
|
||||
/**
|
||||
* @since Forestry 5.8
|
||||
*
|
||||
* @return Returns the {@link IFarmInstance} that created this logic. Returns a fake instance from
|
||||
* {@link IFarmRegistry#createFakeInstance(IFarmLogic)} if the logic is older that Forestry 5.8.
|
||||
*/
|
||||
default IFarmInstance getInstance(){
|
||||
return ForestryAPI.farmRegistry.createFakeInstance(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Use {@link IFarmRegistry#getFarm(String)} to get the soil container for the farm logic and register the soil
|
||||
* with {@link IFarmInstance#registerSoil(ItemStack, IBlockState, boolean)}.
|
||||
*/
|
||||
@Deprecated
|
||||
default void addSoil(ItemStack resource, IBlockState soilState, boolean hasMetaData){
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* @return A short localized name for this logic.
|
||||
*/
|
||||
String getName();
|
||||
|
||||
/* GUI ONLY */
|
||||
|
||||
/**
|
||||
* @deprecated TODO remove this method in 1.13
|
||||
* @deprecated No longer needed because mc always uses the same map for blocks and items.
|
||||
* TODO remove this method in 1.13
|
||||
*/
|
||||
@Deprecated
|
||||
@SideOnly(Side.CLIENT)
|
||||
ResourceLocation getTextureMap();
|
||||
default ResourceLocation getTextureMap(){
|
||||
return TextureMap.LOCATION_BLOCKS_TEXTURE;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the itemStack that represents this farm logic. Used as an icon for the farm logic.
|
||||
|
||||
@@ -7,6 +7,7 @@ package forestry.api.farming;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.Collection;
|
||||
import java.util.function.BiFunction;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
@@ -16,9 +17,29 @@ public interface IFarmRegistry {
|
||||
* Registers farming logic in registry under given identifier
|
||||
* @param identifier Valid identifiers: farmArboreal farmCrops farmGourd farmInfernal farmPoales farmSucculentes farmShroom
|
||||
* @param logic corresponding instance of logic
|
||||
*
|
||||
* @deprecated Since Forestry 5.8. Use {@link #registerLogic(String, BiFunction, String...)} or
|
||||
* {@link #registerLogic(IFarmInstance)}.
|
||||
*/
|
||||
void registerFarmLogic(String identifier, IFarmLogic logic);
|
||||
|
||||
@Deprecated
|
||||
void registerLogic(String identifier, IFarmLogic logic);
|
||||
|
||||
/**
|
||||
* Registers farming logic in registry
|
||||
* @since Forestry 5.8
|
||||
*/
|
||||
IFarmInstance registerLogic(IFarmInstance farmInstance);
|
||||
|
||||
/**
|
||||
* Registers farming logic in registry under given identifier
|
||||
*
|
||||
* @param identifier Valid identifiers: farmArboreal farmCrops farmGourd farmInfernal farmPoales farmSucculentes farmShroom
|
||||
* @param logicFactory factory that creates the corresponding instance of logic
|
||||
* @param farmablesIdentifiers Identifiers: farmArboreal farmCrops farmGourd farmInfernal farmPoales farmSucculentes farmShroom
|
||||
* @since Forestry 5.8
|
||||
*/
|
||||
IFarmInstance registerLogic(String identifier, BiFunction<IFarmInstance, Boolean, IFarmLogic> logicFactory, String... farmablesIdentifiers);
|
||||
|
||||
/**
|
||||
* Can be used to add IFarmables to some of the vanilla farm logics.
|
||||
* <p>
|
||||
@@ -32,14 +53,18 @@ public interface IFarmRegistry {
|
||||
* Can be used to create a simple version of a farm logic, like the vanilla vegetable or wheat farm logic.
|
||||
*
|
||||
* @return Null if the farming plugin is not active.
|
||||
*
|
||||
* @deprecated Since Forestry 5.8. Use {@link #createCropLogic(IFarmInstance, boolean, ISimpleFarmLogic)} instead.
|
||||
*/
|
||||
@Nullable
|
||||
IFarmLogic createLogic(ISimpleFarmLogic simpleFarmLogic);
|
||||
@Deprecated
|
||||
default IFarmLogic createLogic(ISimpleFarmLogic simpleFarmLogic){
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param itemStack
|
||||
* @param value The value of the fertitlizer.The value of the forestry fertelizer is 500.
|
||||
* @param value The value of the fertitlizer. The value of the forestry fertelizer is 500.
|
||||
*/
|
||||
void registerFertilizer(ItemStack itemStack, int value);
|
||||
|
||||
@@ -47,5 +72,32 @@ public interface IFarmRegistry {
|
||||
* @return The value of the fertitlizer
|
||||
*/
|
||||
int getFertilizeValue(ItemStack itemStack);
|
||||
|
||||
/**
|
||||
* Returns a fake {@link IFarmInstance} that returns the given logic at {@link IFarmInstance#getLogic(boolean)}.
|
||||
*
|
||||
* @since Forestry 5.8
|
||||
* @deprecated Only for backwards comparability.
|
||||
*/
|
||||
@Deprecated
|
||||
IFarmInstance createFakeInstance(IFarmLogic logic);
|
||||
|
||||
/**
|
||||
* Can be used to create a simple version of a farm logic, like the vanilla vegetable or wheat farm logic.
|
||||
*
|
||||
* @return Null if the farming plugin is not active.
|
||||
*/
|
||||
@Nullable
|
||||
IFarmLogic createCropLogic(IFarmInstance instance, boolean isManual, ISimpleFarmLogic simpleFarmLogic);
|
||||
|
||||
/**
|
||||
*
|
||||
* @param identifier
|
||||
* @return
|
||||
*
|
||||
* @since Forestry 5.8
|
||||
*/
|
||||
@Nullable
|
||||
IFarmInstance getFarm(String identifier);
|
||||
|
||||
}
|
||||
@@ -8,7 +8,9 @@ package forestry.api.farming;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
/**
|
||||
* A simple version of the IFarmLogic.
|
||||
* A simple version of the IFarmLogic.
|
||||
*
|
||||
* @apiNote TODO Remove this in 1.13
|
||||
*/
|
||||
public interface ISimpleFarmLogic {
|
||||
|
||||
@@ -16,7 +18,11 @@ public interface ISimpleFarmLogic {
|
||||
* @return the itemStack that represents this farm logic. Used as an icon for the farm logic.
|
||||
*/
|
||||
ItemStack getIconItemStack();
|
||||
|
||||
|
||||
/**
|
||||
* @deprecated Since 5.8
|
||||
*/
|
||||
@Deprecated
|
||||
Iterable<IFarmable> getSeeds();
|
||||
|
||||
String getName();
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
package forestry.api.farming;
|
||||
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
/**
|
||||
* @since Forestry 5.8
|
||||
*/
|
||||
public interface ISoil {
|
||||
|
||||
ItemStack getResource();
|
||||
|
||||
IBlockState getSoilState();
|
||||
|
||||
boolean hasMetaData();
|
||||
}
|
||||
@@ -76,7 +76,6 @@ public class BlockBase<P extends Enum<P> & IBlockType & IStringSerializable> ext
|
||||
public final P blockType;
|
||||
|
||||
private final ParticleHelper.Callback particleCallback;
|
||||
protected final BlockStateContainer blockState;
|
||||
|
||||
public BlockBase(P blockType, Material material) {
|
||||
super(material);
|
||||
@@ -88,9 +87,7 @@ public class BlockBase<P extends Enum<P> & IBlockType & IStringSerializable> ext
|
||||
this.hasCustom = blockType instanceof IBlockTypeCustom;
|
||||
this.lightOpacity = (!hasTESR && !hasCustom) ? 255 : 0;
|
||||
|
||||
this.blockState = this.createBlockState();
|
||||
IBlockState state = this.blockState.getBaseState().withProperty(FACING, EnumFacing.NORTH);
|
||||
this.setDefaultState(state);
|
||||
this.setDefaultState(blockState.getBaseState().withProperty(FACING, EnumFacing.NORTH));
|
||||
|
||||
particleCallback = new MachineParticleCallback<>(this, blockType);
|
||||
}
|
||||
|
||||
@@ -77,11 +77,7 @@ public class CircuitRegistry implements ICircuitRegistry {
|
||||
@Override
|
||||
@Nullable
|
||||
public ICircuitLayout getLayout(String uid) {
|
||||
if (layoutMap.containsKey(uid)) {
|
||||
return layoutMap.get(uid);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
return layoutMap.getOrDefault(uid, null);
|
||||
}
|
||||
|
||||
/* CIRCUITS */
|
||||
|
||||
@@ -8,29 +8,38 @@ public class Circuits {
|
||||
public static ICircuit energyElectricEfficiency1;
|
||||
public static ICircuit energyElectricBoost1;
|
||||
public static ICircuit energyElectricBoost2;
|
||||
|
||||
public static ICircuit farmArborealManaged;
|
||||
public static ICircuit farmOrchardManaged;
|
||||
public static ICircuit farmShroomManaged;
|
||||
public static ICircuit farmCropsManaged;
|
||||
public static ICircuit farmPeatManaged;
|
||||
public static ICircuit farmSucculentManaged;
|
||||
public static ICircuit farmPoaleManaged;
|
||||
public static ICircuit farmFungal;
|
||||
public static ICircuit farmInfernalManaged;
|
||||
public static ICircuit farmEnderManaged;
|
||||
public static ICircuit farmOrchidManaged;
|
||||
public static ICircuit farmGourdManaged;
|
||||
|
||||
|
||||
public static ICircuit farmArborealManual;
|
||||
public static ICircuit farmOrchardManual;
|
||||
public static ICircuit farmShroomManual;
|
||||
public static ICircuit farmCropsManual;
|
||||
public static ICircuit farmPeatManual;
|
||||
public static ICircuit farmSucculentManual;
|
||||
public static ICircuit farmPoalesManual;
|
||||
public static ICircuit farmInfernalManual;
|
||||
public static ICircuit farmEnderManual;
|
||||
public static ICircuit farmOrchidManual;
|
||||
public static ICircuit farmGourdManual;
|
||||
public static ICircuit farmCocoaManual;
|
||||
public static ICircuit farmOrchardManual;
|
||||
public static ICircuit farmRubberManual;
|
||||
public static ICircuit farmEnderManaged;
|
||||
public static ICircuit farmOrchidManaged;
|
||||
|
||||
public static ICircuit machineSpeedUpgrade1;
|
||||
public static ICircuit machineSpeedUpgrade2;
|
||||
public static ICircuit machineEfficiencyUpgrade1;
|
||||
|
||||
public static ICircuit climatiserTemperature1;
|
||||
public static ICircuit climatiserTemperature2;
|
||||
public static ICircuit climatiserHumidity1;
|
||||
|
||||
@@ -102,6 +102,11 @@ public class Config {
|
||||
private static boolean enableExUtilRedOrchid = true;
|
||||
private static boolean enableMagicalCropsSupport = true;
|
||||
|
||||
// Cultivation
|
||||
public static int planterExtend = 4;
|
||||
public static boolean ringFarms = false;
|
||||
public static int ringSize = 4;
|
||||
|
||||
// Mail
|
||||
public static boolean mailAlertEnabled = true;
|
||||
public static GuiMailboxInfo.XPosition mailAlertXPosition = GuiMailboxInfo.XPosition.LEFT;
|
||||
@@ -266,6 +271,10 @@ public class Config {
|
||||
enableExUtilRedOrchid = configCommon.getBooleanLocalized("tweaks.farms", "redorchid", enableExUtilRedOrchid);
|
||||
enableMagicalCropsSupport = configCommon.getBooleanLocalized("tweaks.farms", "magicalcrops", enableMagicalCropsSupport);
|
||||
|
||||
planterExtend = configCommon.getIntLocalized("tweaks.cultivation", "extend", planterExtend, 1, 15);
|
||||
ringFarms = configCommon.getBooleanLocalized("tweaks.cultivation", "ring", ringFarms);
|
||||
ringSize = configCommon.getIntLocalized("tweaks.cultivation", "ring_size", ringSize, 1, 8);
|
||||
|
||||
CapsuleFluidPickup = configCommon.getBooleanLocalized("tweaks", "capsule", CapsuleFluidPickup);
|
||||
|
||||
climateSourceRange = configCommon.getIntLocalized("tweaks.greenhouse", "range", climateSourceRange, 9, 270);
|
||||
|
||||
@@ -18,6 +18,7 @@ import forestry.core.items.EnumElectronTube;
|
||||
import forestry.core.items.ItemRegistryCore;
|
||||
import forestry.core.recipes.RecipeUtil;
|
||||
import forestry.core.utils.OreDictUtil;
|
||||
import forestry.cultivation.blocks.BlockPlanter;
|
||||
import forestry.cultivation.blocks.BlockRegistryCultivation;
|
||||
import forestry.modules.BlankForestryModule;
|
||||
import forestry.modules.ForestryModuleUids;
|
||||
@@ -113,5 +114,10 @@ public class ModuleCultivation extends BlankForestryModule {
|
||||
'G', OreDictUtil.BLOCK_GLASS,
|
||||
'W', Items.NETHER_WART,
|
||||
'A', blocks.arboretum);
|
||||
|
||||
for(BlockPlanter planter : getBlocks().getPlanters()){
|
||||
RecipeUtil.addRecipe(planter.blockType.getName() + "_manual_managed", planter.get(true), "# ", " ", " ", '#', planter.get(false));
|
||||
RecipeUtil.addRecipe(planter.blockType.getName() + "_managed_manual", planter.get(false), "# ", " ", " ", '#', planter.get(true));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,17 +1,102 @@
|
||||
package forestry.cultivation.blocks;
|
||||
|
||||
import net.minecraft.block.material.Material;
|
||||
import net.minecraft.block.properties.PropertyBool;
|
||||
import net.minecraft.block.state.BlockStateContainer;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.creativetab.CreativeTabs;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagByte;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.BlockRenderLayer;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.EnumHand;
|
||||
import net.minecraft.util.NonNullList;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import net.minecraftforge.client.model.ModelLoader;
|
||||
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
import forestry.core.blocks.BlockBase;
|
||||
import forestry.cultivation.tiles.TilePlanter;
|
||||
|
||||
public class BlockPlanter extends BlockBase<BlockTypePlanter> {
|
||||
public static final PropertyBool MANUAL = PropertyBool.create("manual");
|
||||
|
||||
public BlockPlanter(BlockTypePlanter blockType) {
|
||||
super(blockType, Material.WOOD);
|
||||
this.setDefaultState(blockState.getBaseState().withProperty(FACING, EnumFacing.NORTH).withProperty(MANUAL, false));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected BlockStateContainer createBlockState() {
|
||||
return new BlockStateContainer(this, FACING, MANUAL);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IBlockState getStateFromMeta(int meta) {
|
||||
int facing = meta & 7;
|
||||
return getDefaultState().withProperty(FACING, EnumFacing.fromAngle(facing)).withProperty(MANUAL, (meta & 8) == 8);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMetaFromState(IBlockState state) {
|
||||
if(state.getValue(MANUAL)){
|
||||
return state.getValue(FACING).ordinal();
|
||||
}
|
||||
return 8 + state.getValue(FACING).ordinal();
|
||||
}
|
||||
|
||||
@Override
|
||||
public TileEntity createTileEntity(World world, IBlockState state) {
|
||||
TileEntity tile = super.createNewTileEntity(world, 0);
|
||||
if(tile instanceof TilePlanter){
|
||||
TilePlanter planter = (TilePlanter) tile;
|
||||
planter.setManual(state.getValue(MANUAL));
|
||||
}
|
||||
return tile;
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void registerStateMapper() {
|
||||
ModelLoader.setCustomStateMapper(this, new PlanterStateMapper());
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockRenderLayer getBlockLayer() {
|
||||
return BlockRenderLayer.CUTOUT;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IBlockState getStateForPlacement(World world, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ, int meta, EntityLivingBase placer, EnumHand hand) {
|
||||
ItemStack stack = placer.getHeldItem(hand);
|
||||
return getDefaultState().withProperty(MANUAL, isManual(stack));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getSubBlocks(CreativeTabs itemIn, NonNullList<ItemStack> items) {
|
||||
for(byte i = 0;i < 2;i++){
|
||||
items.add(get(i == 1));
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean isManual(ItemStack stack){
|
||||
NBTTagCompound tagCompound = stack.getTagCompound();
|
||||
if(tagCompound != null){
|
||||
return tagCompound.getBoolean("Manual");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public ItemStack get(boolean isManual){
|
||||
ItemStack stack = new ItemStack(this);
|
||||
stack.setTagInfo("Manual", new NBTTagByte((byte) (isManual ? 1 : 0)));
|
||||
return stack;
|
||||
}
|
||||
}
|
||||
@@ -1,9 +1,14 @@
|
||||
package forestry.cultivation.blocks;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import forestry.core.blocks.BlockRegistry;
|
||||
import forestry.core.items.ItemBlockForestry;
|
||||
import forestry.cultivation.items.ItemBlockPlanter;
|
||||
|
||||
public class BlockRegistryCultivation extends BlockRegistry {
|
||||
private Set<BlockPlanter> planters = new HashSet<>();
|
||||
|
||||
public final BlockPlanter arboretum;
|
||||
public final BlockPlanter farmCrops;
|
||||
public final BlockPlanter farmMushroom;
|
||||
@@ -14,18 +19,33 @@ public class BlockRegistryCultivation extends BlockRegistry {
|
||||
|
||||
public BlockRegistryCultivation() {
|
||||
arboretum = new BlockPlanter(BlockTypePlanter.ARBORETUM);
|
||||
registerBlock(arboretum, new ItemBlockForestry<>(arboretum), "arboretum");
|
||||
registerBlock(arboretum, new ItemBlockPlanter(arboretum), "arboretum");
|
||||
planters.add(arboretum);
|
||||
|
||||
farmCrops = new BlockPlanter(BlockTypePlanter.FARM_CROPS);
|
||||
registerBlock(farmCrops, new ItemBlockForestry<>(farmCrops), "farm_crops");
|
||||
registerBlock(farmCrops, new ItemBlockPlanter(farmCrops), "farm_crops");
|
||||
planters.add(farmCrops);
|
||||
|
||||
farmMushroom = new BlockPlanter(BlockTypePlanter.FARM_MUSHROOM);
|
||||
registerBlock(farmMushroom, new ItemBlockForestry<>(farmMushroom), "farm_mushroom");
|
||||
registerBlock(farmMushroom, new ItemBlockPlanter(farmMushroom), "farm_mushroom");
|
||||
planters.add(farmMushroom);
|
||||
|
||||
farmGourd = new BlockPlanter(BlockTypePlanter.FARM_GOURD);
|
||||
registerBlock(farmGourd, new ItemBlockForestry<>(farmGourd), "farm_gourd");
|
||||
registerBlock(farmGourd, new ItemBlockPlanter(farmGourd), "farm_gourd");
|
||||
planters.add(farmGourd);
|
||||
|
||||
farmNether = new BlockPlanter(BlockTypePlanter.FARM_NETHER);
|
||||
registerBlock(farmNether, new ItemBlockForestry<>(farmNether), "farm_nether");
|
||||
registerBlock(farmNether, new ItemBlockPlanter(farmNether), "farm_nether");
|
||||
planters.add(farmNether);
|
||||
|
||||
peatBog = new BlockPlanter(BlockTypePlanter.PEAT_POG);
|
||||
registerBlock(peatBog, new ItemBlockForestry<>(peatBog), "peat_bog");
|
||||
registerBlock(peatBog, new ItemBlockPlanter(peatBog), "peat_bog");
|
||||
planters.add(peatBog);
|
||||
/* plantation = new BlockPlanter(BlockTypePlanter.PLANTATION);
|
||||
registerBlock(plantation, new ItemBlockForestry<>(plantation), "plantation");*/
|
||||
}
|
||||
|
||||
public Set<BlockPlanter> getPlanters() {
|
||||
return planters;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
package forestry.cultivation.blocks;
|
||||
|
||||
import com.google.common.collect.Maps;
|
||||
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.properties.IProperty;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
import forestry.core.blocks.BlockBase;
|
||||
import forestry.core.render.ForestryStateMapper;
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public class PlanterStateMapper extends ForestryStateMapper {
|
||||
|
||||
@Override
|
||||
public Map<IBlockState, ModelResourceLocation> putStateModelLocations(Block block) {
|
||||
for (EnumFacing facing : EnumFacing.values()) {
|
||||
if (facing == EnumFacing.DOWN || facing == EnumFacing.UP) {
|
||||
continue;
|
||||
}
|
||||
for(boolean manual : new boolean[]{false, true}) {
|
||||
IBlockState state = block.getDefaultState().withProperty(BlockBase.FACING, facing).withProperty(BlockPlanter.MANUAL, manual);
|
||||
LinkedHashMap<IProperty<?>, Comparable<?>> properties = Maps.newLinkedHashMap(state.getProperties());
|
||||
properties.remove(BlockPlanter.MANUAL);
|
||||
ResourceLocation blockLocation = Block.REGISTRY.getNameForObject(block);
|
||||
String s = String.format("%s:%s", blockLocation.getResourceDomain(), blockLocation.getResourcePath());
|
||||
mapStateModelLocations.put(state, new ModelResourceLocation(s, getPropertyString(properties)));
|
||||
}
|
||||
}
|
||||
|
||||
return this.mapStateModelLocations;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package forestry.cultivation.items;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import forestry.core.items.ItemBlockForestry;
|
||||
import forestry.core.utils.Translator;
|
||||
import forestry.cultivation.blocks.BlockPlanter;
|
||||
|
||||
public class ItemBlockPlanter extends ItemBlockForestry<BlockPlanter> {
|
||||
|
||||
public ItemBlockPlanter(BlockPlanter block) {
|
||||
super(block);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getItemStackDisplayName(ItemStack stack) {
|
||||
return Translator.translateToLocalFormatted("tile.for.planter." + (BlockPlanter.isManual(stack) ? "manual" : "managed"), super.getItemStackDisplayName(stack));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
@ParametersAreNonnullByDefault
|
||||
@FieldsAreNonnullByDefault
|
||||
@MethodsReturnNonnullByDefault
|
||||
package forestry.cultivation.items;
|
||||
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
|
||||
import mcp.MethodsReturnNonnullByDefault;
|
||||
|
||||
import forestry.core.utils.FieldsAreNonnullByDefault;
|
||||
@@ -2,11 +2,10 @@ package forestry.cultivation.tiles;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import forestry.api.farming.IFarmLogic;
|
||||
|
||||
public class TilePlantation extends TilePlanter {
|
||||
public TilePlantation(IFarmLogic logic) {
|
||||
super(logic);
|
||||
|
||||
public TilePlantation() {
|
||||
super("farmRubber");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -33,6 +33,7 @@ import forestry.api.farming.IFarmHousing;
|
||||
import forestry.api.farming.IFarmInventory;
|
||||
import forestry.api.farming.IFarmLogic;
|
||||
import forestry.api.farming.IFarmable;
|
||||
import forestry.core.config.Config;
|
||||
import forestry.core.config.Constants;
|
||||
import forestry.core.errors.EnumErrorCode;
|
||||
import forestry.core.fluids.FilteredTank;
|
||||
@@ -64,12 +65,10 @@ import forestry.farming.multiblock.FarmHydrationManager;
|
||||
|
||||
public abstract class TilePlanter extends TilePowered implements IFarmHousing, IClimatised, ILiquidTankTile, IOwnedTile, IStreamableGui {
|
||||
|
||||
private final static int ALLOWED_EXTENT = 4;
|
||||
|
||||
private final Map<FarmDirection, List<FarmTarget>> targets = new EnumMap<>(FarmDirection.class);
|
||||
private final Stack<ItemStack> pendingProduce = new Stack<>();
|
||||
private final List<ICrop> pendingCrops = new LinkedList<>();
|
||||
private final IFarmLogic logic;
|
||||
private final String identifier;
|
||||
|
||||
private final FarmHydrationManager hydrationManager;
|
||||
private final FarmFertilizerManager fertilizerManager;
|
||||
@@ -80,19 +79,23 @@ public abstract class TilePlanter extends TilePowered implements IFarmHousing, I
|
||||
|
||||
private int platformHeight = -1;
|
||||
private Stage stage = Stage.CULTIVATE;
|
||||
private boolean isManual;
|
||||
private IFarmLogic logic;
|
||||
@Nullable
|
||||
private Vec3i offset;
|
||||
@Nullable
|
||||
private Vec3i area;
|
||||
|
||||
public TilePlanter(String identifier) {
|
||||
this(FarmRegistry.getInstance().getFarmLogic(identifier));
|
||||
public void setManual(boolean manual) {
|
||||
isManual = manual;
|
||||
logic = FarmRegistry.getInstance().getFarm(identifier).getLogic(manual);
|
||||
}
|
||||
|
||||
protected TilePlanter(IFarmLogic logic) {
|
||||
protected TilePlanter(String identifier) {
|
||||
super(150, 1500);
|
||||
this.identifier = identifier;
|
||||
setManual(false);
|
||||
setInternalInventory(inventory = new InventoryPlanter(this));
|
||||
this.logic = logic;
|
||||
this.hydrationManager = new FarmHydrationManager(this);
|
||||
this.fertilizerManager = new FarmFertilizerManager();
|
||||
|
||||
@@ -203,6 +206,7 @@ public abstract class TilePlanter extends TilePowered implements IFarmHousing, I
|
||||
tankManager.writeToNBT(data);
|
||||
fertilizerManager.writeToNBT(data);
|
||||
ownerHandler.writeToNBT(data);
|
||||
data.setBoolean("isManual", isManual);
|
||||
return data;
|
||||
}
|
||||
|
||||
@@ -213,6 +217,7 @@ public abstract class TilePlanter extends TilePowered implements IFarmHousing, I
|
||||
tankManager.readFromNBT(data);
|
||||
fertilizerManager.readFromNBT(data);
|
||||
ownerHandler.readFromNBT(data);
|
||||
setManual(data.getBoolean("isManual"));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -231,8 +236,20 @@ public abstract class TilePlanter extends TilePowered implements IFarmHousing, I
|
||||
|
||||
private void setUpFarmlandTargets() {
|
||||
BlockPos targetStart = getCoords();
|
||||
BlockPos minPos = pos;
|
||||
BlockPos maxPos = pos;
|
||||
int size = 1;
|
||||
int extend = Config.planterExtend;
|
||||
|
||||
FarmHelper.createTargets(world, this, targets, targetStart, ALLOWED_EXTENT, 1, 1, pos, pos);
|
||||
if(Config.ringFarms){
|
||||
int ringSize = Config.ringSize;
|
||||
minPos = pos.add(-ringSize, 0 , -ringSize);
|
||||
maxPos = pos.add(ringSize, 0, ringSize);
|
||||
size = 1 + ringSize * 2;
|
||||
extend--;
|
||||
}
|
||||
|
||||
FarmHelper.createTargets(world, this, targets, targetStart, extend, size, size, minPos, maxPos);
|
||||
FarmHelper.setExtents(world, this, targets);
|
||||
}
|
||||
|
||||
@@ -331,7 +348,11 @@ public abstract class TilePlanter extends TilePowered implements IFarmHousing, I
|
||||
@Override
|
||||
public Vec3i getArea() {
|
||||
if (area == null) {
|
||||
area = new Vec3i(7 + ALLOWED_EXTENT * 2, 13, 7 + ALLOWED_EXTENT * 2);
|
||||
int basisArea = 5;
|
||||
if(Config.ringFarms){
|
||||
basisArea = basisArea + 1 + Config.ringSize * 2;
|
||||
}
|
||||
area = new Vec3i(basisArea + Config.planterExtend, 13, basisArea + Config.planterExtend);
|
||||
}
|
||||
return area;
|
||||
}
|
||||
@@ -388,6 +409,11 @@ public abstract class TilePlanter extends TilePowered implements IFarmHousing, I
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canPlantSoil(boolean manual) {
|
||||
return !isManual;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IFarmInventory getFarmInventory() {
|
||||
return inventory;
|
||||
|
||||
@@ -1,42 +1,76 @@
|
||||
package forestry.farming;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.function.BiFunction;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import forestry.api.farming.IFarmInstance;
|
||||
import forestry.api.farming.IFarmLogic;
|
||||
import forestry.api.farming.IFarmRegistry;
|
||||
import forestry.api.farming.IFarmable;
|
||||
import forestry.api.farming.ISimpleFarmLogic;
|
||||
import forestry.farming.logic.FakeFarmInstance;
|
||||
|
||||
public class DummyFarmRegistry implements IFarmRegistry {
|
||||
|
||||
@Override
|
||||
public void registerFarmLogic(String identifier, IFarmLogic logic) {
|
||||
|
||||
public void registerLogic(String identifier, IFarmLogic logic) {
|
||||
//Dummy-Implementation
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerFarmables(String identifier, IFarmable... farmable) {
|
||||
//Dummy-Implementation
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<IFarmable> getFarmables(String identifier) {
|
||||
//Dummy-Implementation
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IFarmLogic createLogic(ISimpleFarmLogic simpleFarmLogic) {
|
||||
public IFarmInstance registerLogic(IFarmInstance farmInstance) {
|
||||
//Dummy-Implementation
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IFarmInstance registerLogic(String identifier, BiFunction<IFarmInstance, Boolean, IFarmLogic> logicFactory, String... farmablesIdentifiers) {
|
||||
//Dummy-Implementation
|
||||
return null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public IFarmLogic createCropLogic(IFarmInstance instance, boolean isManual, ISimpleFarmLogic simpleFarmLogic) {
|
||||
//Dummy-Implementation
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IFarmInstance createFakeInstance(IFarmLogic logic) {
|
||||
return new FakeFarmInstance(logic);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerFertilizer(ItemStack itemStack, int value) {
|
||||
//Dummy-Implementation
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getFertilizeValue(ItemStack itemStack) {
|
||||
//Dummy-Implementation
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public IFarmInstance getFarm(String identifier) {
|
||||
//Dummy-Implementation
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -3,6 +3,7 @@ package forestry.farming;
|
||||
import com.google.common.collect.HashMultimap;
|
||||
import com.google.common.collect.Multimap;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
@@ -14,12 +15,15 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Set;
|
||||
import java.util.function.BiFunction;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import net.minecraftforge.common.config.Property;
|
||||
import net.minecraftforge.oredict.OreDictionary;
|
||||
|
||||
import forestry.api.farming.IFarmInstance;
|
||||
import forestry.api.farming.IFarmLogic;
|
||||
import forestry.api.farming.IFarmRegistry;
|
||||
import forestry.api.farming.IFarmable;
|
||||
@@ -28,6 +32,8 @@ import forestry.core.config.LocalizedConfiguration;
|
||||
import forestry.core.utils.ItemStackUtil;
|
||||
import forestry.core.utils.Log;
|
||||
import forestry.core.utils.Translator;
|
||||
import forestry.farming.logic.FakeFarmInstance;
|
||||
import forestry.farming.logic.FarmInstance;
|
||||
import forestry.farming.logic.FarmLogicSimple;
|
||||
|
||||
public final class FarmRegistry implements IFarmRegistry {
|
||||
@@ -35,18 +41,17 @@ public final class FarmRegistry implements IFarmRegistry {
|
||||
private static final FarmRegistry INSTANCE = new FarmRegistry();
|
||||
private final Multimap<String, IFarmable> farmables = HashMultimap.create();
|
||||
private final Map<ItemStack, Integer> fertilizers = new LinkedHashMap<>();
|
||||
private final Map<String, IFarmLogic> logics = new HashMap<String, IFarmLogic>();
|
||||
private final Map<String, IFarmLogic> logics = new HashMap<>();
|
||||
private final Map<String, IFarmInstance> farmInstances = new HashMap<>();
|
||||
|
||||
public static FarmRegistry getInstance() {
|
||||
return INSTANCE;
|
||||
}
|
||||
|
||||
public void registerFarmLogic(String identifier, IFarmLogic logic) {
|
||||
logics.put(identifier, logic);
|
||||
}
|
||||
|
||||
public IFarmLogic getFarmLogic(String identifier) {
|
||||
return logics.get(identifier);
|
||||
@Override
|
||||
@Deprecated
|
||||
public void registerLogic(String identifier, IFarmLogic logic) {
|
||||
logics.put(identifier, logic);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -60,13 +65,18 @@ public final class FarmRegistry implements IFarmRegistry {
|
||||
}
|
||||
|
||||
@Override
|
||||
public IFarmLogic createLogic(ISimpleFarmLogic simpleFarmLogic) {
|
||||
return new FarmLogicSimple(simpleFarmLogic);
|
||||
public IFarmLogic createCropLogic(IFarmInstance instance, boolean isManual, ISimpleFarmLogic simpleFarmLogic) {
|
||||
return new FarmLogicSimple(instance, isManual, simpleFarmLogic);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IFarmInstance createFakeInstance(IFarmLogic logic) {
|
||||
return new FakeFarmInstance(logic);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerFertilizer(ItemStack itemStack, int value) {
|
||||
if(itemStack == null || itemStack.isEmpty()){
|
||||
if(itemStack.isEmpty()){
|
||||
return;
|
||||
}
|
||||
fertilizers.put(itemStack, value);
|
||||
@@ -76,16 +86,36 @@ public final class FarmRegistry implements IFarmRegistry {
|
||||
public int getFertilizeValue(ItemStack itemStack) {
|
||||
for (Entry<ItemStack, Integer> fertilizer : fertilizers.entrySet()) {
|
||||
ItemStack fertilizerStack = fertilizer.getKey();
|
||||
if (itemStack.getItem() == fertilizerStack.getItem()
|
||||
&& (fertilizerStack.getItemDamage() == itemStack.getItemDamage()
|
||||
|| fertilizerStack.getItemDamage() == OreDictionary.WILDCARD_VALUE)) {
|
||||
if (ItemStackUtil.isIdenticalItem(fertilizerStack, itemStack)) {
|
||||
return fertilizer.getValue();
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
public void loadConfig(LocalizedConfiguration config) {
|
||||
|
||||
@Override
|
||||
public IFarmInstance registerLogic(IFarmInstance farmInstance) {
|
||||
farmInstances.put(farmInstance.getIdentifier(), farmInstance);
|
||||
return farmInstance;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IFarmInstance registerLogic(String identifier, BiFunction<IFarmInstance, Boolean, IFarmLogic> logicFactory, String... farmablesIdentifiers) {
|
||||
Set<String> fIdentifiers = new HashSet<>(Arrays.asList(farmablesIdentifiers));
|
||||
fIdentifiers.add(identifier);
|
||||
Collection<IFarmable> farmablesSet = fIdentifiers.stream().map(farmables::get).flatMap(Collection::stream).collect(Collectors.toSet());
|
||||
IFarmInstance instance = new FarmInstance(identifier, logicFactory, farmablesSet);
|
||||
farmInstances.put(identifier, instance);
|
||||
return instance;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public IFarmInstance getFarm(String identifier) {
|
||||
return farmInstances.get(identifier);
|
||||
}
|
||||
|
||||
void loadConfig(LocalizedConfiguration config) {
|
||||
List<String> defaultFertilizers = new ArrayList<>(getItemStrings());
|
||||
Collections.sort(defaultFertilizers);
|
||||
String[] defaultSortedFertilizers = defaultFertilizers.toArray(new String[defaultFertilizers.size()]);
|
||||
@@ -102,6 +132,9 @@ public final class FarmRegistry implements IFarmRegistry {
|
||||
itemName = "forestry:fertilizer_compound";
|
||||
}
|
||||
ItemStack fertilizerItem = ItemStackUtil.parseItemStackString(itemName, OreDictionary.WILDCARD_VALUE);
|
||||
if(fertilizerItem == null){
|
||||
continue;
|
||||
}
|
||||
int fertilizerValue = Integer.parseInt(fertilizers[1]);
|
||||
registerFertilizer(fertilizerItem, fertilizerValue);
|
||||
} catch (Exception e) {
|
||||
|
||||
@@ -19,6 +19,7 @@ import java.util.List;
|
||||
|
||||
import net.minecraft.block.BlockBeetroot;
|
||||
import net.minecraft.block.BlockCrops;
|
||||
import net.minecraft.block.BlockDirt;
|
||||
import net.minecraft.block.BlockNetherWart;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.init.Blocks;
|
||||
@@ -42,9 +43,12 @@ import forestry.api.circuits.ChipsetManager;
|
||||
import forestry.api.circuits.CircuitSocketType;
|
||||
import forestry.api.circuits.ICircuitLayout;
|
||||
import forestry.api.core.ForestryAPI;
|
||||
import forestry.api.farming.IFarmInstance;
|
||||
import forestry.api.farming.IFarmRegistry;
|
||||
import forestry.api.modules.ForestryModule;
|
||||
import forestry.core.ModuleCore;
|
||||
import forestry.core.blocks.BlockBogEarth;
|
||||
import forestry.core.blocks.BlockRegistryCore;
|
||||
import forestry.core.circuits.CircuitLayout;
|
||||
import forestry.core.circuits.Circuits;
|
||||
import forestry.core.config.Config;
|
||||
@@ -181,29 +185,56 @@ public class ModuleFarming extends BlankForestryModule {
|
||||
GameRegistry.registerTileEntity(TileFarmValve.class, "forestry.FarmValve");
|
||||
GameRegistry.registerTileEntity(TileFarmControl.class, "forestry.FarmControl");
|
||||
|
||||
Circuits.farmArborealManaged = new CircuitFarmLogic("managedArboreal", new FarmLogicArboreal());
|
||||
Circuits.farmShroomManaged = new CircuitFarmLogic("managedShroom", new FarmLogicMushroom());
|
||||
Circuits.farmPeatManaged = new CircuitFarmLogic("managedPeat", new FarmLogicPeat());
|
||||
Circuits.farmCropsManaged = new CircuitFarmLogic("managedCrops", new FarmLogicCrops());
|
||||
Circuits.farmInfernalManaged = new CircuitFarmLogic("managedInfernal", new FarmLogicInfernal());
|
||||
IFarmRegistry registry = FarmRegistry.getInstance();
|
||||
BlockRegistryCore coreBlocks = ModuleCore.getBlocks();
|
||||
|
||||
Circuits.farmPeatManual = new CircuitFarmLogic("manualPeat", new FarmLogicPeat()).setManual();
|
||||
Circuits.farmShroomManual = new CircuitFarmLogic("manualShroom", new FarmLogicMushroom()).setManual();
|
||||
Circuits.farmCropsManual = new CircuitFarmLogic("manualCrops", new FarmLogicCrops()).setManual();
|
||||
Circuits.farmSucculentManual = new CircuitFarmLogic("manualSucculent", new FarmLogicSucculent()).setManual();
|
||||
Circuits.farmPoalesManual = new CircuitFarmLogic("manualPoales", new FarmLogicReeds()).setManual();
|
||||
Circuits.farmGourdManual = new CircuitFarmLogic("manualGourd", new FarmLogicGourd()).setManual();
|
||||
Circuits.farmCocoaManual = new CircuitFarmLogic("manualCocoa", new FarmLogicCocoa()).setManual();
|
||||
IFarmInstance arborealFarm = registry.registerLogic("farmArboreal", FarmLogicArboreal::new);
|
||||
IFarmInstance cropsFarm = registry.registerLogic("farmCrops", FarmLogicCrops::new);
|
||||
IFarmInstance mushroomFarm = registry.registerLogic("farmShroom", FarmLogicMushroom::new);
|
||||
IFarmInstance succulentFarm = registry.registerLogic("farmSucculent", FarmLogicSucculent::new);
|
||||
IFarmInstance peatFarm = registry.registerLogic("farmPeat", FarmLogicPeat::new);
|
||||
IFarmInstance infernalFarm = registry.registerLogic("farmInfernal", FarmLogicInfernal::new);
|
||||
IFarmInstance poalesFarm = registry.registerLogic("farmPoales", FarmLogicReeds::new);
|
||||
IFarmInstance orchardFarm = registry.registerLogic("farmOrchard", FarmLogicOrchard::new);
|
||||
IFarmInstance gourdFarm = registry.registerLogic("farmGourd", FarmLogicGourd::new);
|
||||
IFarmInstance cocoaFarm = registry.registerLogic("farmCocoa", FarmLogicCocoa::new);
|
||||
|
||||
Circuits.farmOrchardManual = new CircuitFarmLogic("manualOrchard", new FarmLogicOrchard());
|
||||
Circuits.farmArborealManaged = new CircuitFarmLogic("managedArboreal", arborealFarm, false);
|
||||
Circuits.farmArborealManual = new CircuitFarmLogic("manualArboreal", arborealFarm, true);
|
||||
arborealFarm.registerSoil(new ItemStack(Blocks.DIRT), coreBlocks.humus.getDefaultState());
|
||||
arborealFarm.registerSoil(new ItemStack(coreBlocks.humus), coreBlocks.humus.getDefaultState());
|
||||
|
||||
// Make Forestry farming logics accessible to plugins via FarmRegistry
|
||||
FarmRegistry.getInstance().registerFarmLogic("farmArboreal",((CircuitFarmLogic)Circuits.farmArborealManaged).getFarmLogic());
|
||||
FarmRegistry.getInstance().registerFarmLogic("farmShroom",((CircuitFarmLogic)Circuits.farmShroomManaged).getFarmLogic());
|
||||
FarmRegistry.getInstance().registerFarmLogic("farmCrops",((CircuitFarmLogic)Circuits.farmCropsManaged).getFarmLogic());
|
||||
FarmRegistry.getInstance().registerFarmLogic("farmInfernal",((CircuitFarmLogic)Circuits.farmInfernalManaged).getFarmLogic());
|
||||
FarmRegistry.getInstance().registerFarmLogic("farmGourd", ((CircuitFarmLogic)Circuits.farmGourdManual).getFarmLogic());
|
||||
FarmRegistry.getInstance().registerFarmLogic("farmPeat", ((CircuitFarmLogic)Circuits.farmPeatManaged).getFarmLogic());
|
||||
Circuits.farmShroomManaged = new CircuitFarmLogic("managedShroom", mushroomFarm, false);
|
||||
Circuits.farmShroomManual = new CircuitFarmLogic("manualShroom", mushroomFarm, true);
|
||||
mushroomFarm.registerSoil(new ItemStack(Blocks.MYCELIUM), Blocks.MYCELIUM.getDefaultState());
|
||||
mushroomFarm.registerSoil(new ItemStack(Blocks.DIRT, 1, 2),
|
||||
Blocks.DIRT.getDefaultState().withProperty(BlockDirt.VARIANT, BlockDirt.DirtType.PODZOL), true);
|
||||
|
||||
Circuits.farmPeatManaged = new CircuitFarmLogic("managedPeat", peatFarm, false);
|
||||
Circuits.farmPeatManual = new CircuitFarmLogic("manualPeat", peatFarm, true);
|
||||
peatFarm.registerSoil(coreBlocks.bogEarth.get(BlockBogEarth.SoilType.BOG_EARTH, 1), coreBlocks.bogEarth.getDefaultState());
|
||||
|
||||
Circuits.farmCropsManaged = new CircuitFarmLogic("managedCrops", cropsFarm, false);
|
||||
Circuits.farmCropsManual = new CircuitFarmLogic("manualCrops", cropsFarm, true);
|
||||
cropsFarm.registerSoil(new ItemStack(Blocks.DIRT), Blocks.FARMLAND.getDefaultState());
|
||||
|
||||
Circuits.farmInfernalManaged = new CircuitFarmLogic("managedInfernal", infernalFarm, false);
|
||||
Circuits.farmInfernalManual = new CircuitFarmLogic("manualInfernal", infernalFarm, true);
|
||||
infernalFarm.registerSoil(new ItemStack(Blocks.SOUL_SAND), Blocks.SOUL_SAND.getDefaultState());
|
||||
|
||||
Circuits.farmOrchardManaged = new CircuitFarmLogic("managedOrchard", orchardFarm, false);
|
||||
Circuits.farmOrchardManual = new CircuitFarmLogic("manualOrchard", orchardFarm, true);
|
||||
|
||||
Circuits.farmSucculentManual = new CircuitFarmLogic("manualSucculent", succulentFarm, true);
|
||||
succulentFarm.registerSoil(new ItemStack(Blocks.SAND), Blocks.SAND.getDefaultState(),true);
|
||||
|
||||
Circuits.farmPoalesManual = new CircuitFarmLogic("manualPoales", poalesFarm, true).setManual();
|
||||
poalesFarm.registerSoil(new ItemStack(Blocks.SAND), Blocks.SAND.getDefaultState(),true);
|
||||
poalesFarm.registerSoil(new ItemStack(Blocks.DIRT), Blocks.DIRT.getDefaultState(),false);
|
||||
|
||||
Circuits.farmGourdManual = new CircuitFarmLogic("manualGourd", gourdFarm, true).setManual();
|
||||
|
||||
Circuits.farmCocoaManual = new CircuitFarmLogic("manualCocoa", cocoaFarm, true).setManual();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -267,6 +298,10 @@ public class ModuleFarming extends BlankForestryModule {
|
||||
ICircuitLayout layoutManaged = ChipsetManager.circuitRegistry.getLayout("forestry.farms.managed");
|
||||
ICircuitLayout layoutManual = ChipsetManager.circuitRegistry.getLayout("forestry.farms.manual");
|
||||
|
||||
if(layoutManaged == null || layoutManual == null){
|
||||
return;
|
||||
}
|
||||
|
||||
ChipsetManager.solderManager.addRecipe(layoutManaged, coreItems.tubes.get(EnumElectronTube.COPPER, 1), Circuits.farmArborealManaged);
|
||||
ChipsetManager.solderManager.addRecipe(layoutManaged, coreItems.tubes.get(EnumElectronTube.TIN, 1), Circuits.farmPeatManaged);
|
||||
ChipsetManager.solderManager.addRecipe(layoutManaged, coreItems.tubes.get(EnumElectronTube.BRONZE, 1), Circuits.farmCropsManaged);
|
||||
|
||||
@@ -14,6 +14,7 @@ import javax.annotation.Nullable;
|
||||
|
||||
import forestry.api.farming.FarmDirection;
|
||||
import forestry.api.farming.IFarmHousing;
|
||||
import forestry.api.farming.IFarmInstance;
|
||||
import forestry.api.farming.IFarmLogic;
|
||||
import forestry.core.circuits.Circuit;
|
||||
|
||||
@@ -22,15 +23,28 @@ public class CircuitFarmLogic extends Circuit {
|
||||
private final IFarmLogic logic;
|
||||
private boolean isManual = false;
|
||||
|
||||
public CircuitFarmLogic(String uid, IFarmInstance instance, boolean manual) {
|
||||
super(uid);
|
||||
this.logic = instance.getLogic(manual);
|
||||
}
|
||||
|
||||
public CircuitFarmLogic(String uid, IFarmLogic logic) {
|
||||
super(uid);
|
||||
this.logic = logic;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @deprecated TODO: Remove this method in 1.13
|
||||
*/
|
||||
@Deprecated
|
||||
public IFarmLogic getFarmLogic() {
|
||||
return logic;
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated TODO: Remove this method in 1.13
|
||||
*/
|
||||
@Deprecated
|
||||
public CircuitFarmLogic setManual() {
|
||||
isManual = true;
|
||||
return this;
|
||||
|
||||
@@ -0,0 +1,54 @@
|
||||
package forestry.farming.logic;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import forestry.api.farming.IFarmInstance;
|
||||
import forestry.api.farming.IFarmLogic;
|
||||
import forestry.api.farming.IFarmable;
|
||||
import forestry.api.farming.ISoil;
|
||||
|
||||
public class FakeFarmInstance implements IFarmInstance {
|
||||
private final IFarmLogic logic;
|
||||
|
||||
public FakeFarmInstance(IFarmLogic logic) {
|
||||
this.logic = logic;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerSoil(ItemStack resource, IBlockState soilState, boolean hasMetaData) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAcceptedSoil(IBlockState blockState) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAcceptedResource(ItemStack itemStack) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getIdentifier() {
|
||||
return "farmFake";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<ISoil> getSoils() {
|
||||
return Collections.emptySet();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<IFarmable> getFarmables() {
|
||||
return Collections.emptySet();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IFarmLogic getLogic(boolean manuel) {
|
||||
return logic;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
package forestry.farming.logic;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.function.BiFunction;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import forestry.api.farming.IFarmInstance;
|
||||
import forestry.api.farming.IFarmLogic;
|
||||
import forestry.api.farming.IFarmable;
|
||||
import forestry.api.farming.ISoil;
|
||||
|
||||
public final class FarmInstance implements IFarmInstance {
|
||||
private final Set<ISoil> soils = new HashSet<>();
|
||||
private final Collection<IFarmable> farmables;
|
||||
private final IFarmLogic manualLogic;
|
||||
private final IFarmLogic managedLogic;
|
||||
private final String identifier;
|
||||
|
||||
public FarmInstance(String identifier, BiFunction<IFarmInstance, Boolean, IFarmLogic> logicFactory, Collection<IFarmable> farmables) {
|
||||
this.identifier = identifier;
|
||||
this.farmables = farmables;
|
||||
this.manualLogic = logicFactory.apply(this, true);
|
||||
this.managedLogic = logicFactory.apply(this, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<IFarmable> getFarmables() {
|
||||
return farmables;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IFarmLogic getLogic(boolean manuel) {
|
||||
return manuel ? manualLogic : managedLogic;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerSoil(ItemStack resource, IBlockState soilState, boolean hasMetaData) {
|
||||
soils.add(new Soil(resource, soilState, hasMetaData));
|
||||
}
|
||||
|
||||
public boolean isAcceptedSoil(IBlockState ground) {
|
||||
for (ISoil soil : soils) {
|
||||
IBlockState soilState = soil.getSoilState();
|
||||
Block soilBlock = soilState.getBlock();
|
||||
Block block = ground.getBlock();
|
||||
if (soilState.getBlock() == ground.getBlock()) {
|
||||
if (!soil.hasMetaData() || block.getMetaFromState(ground) == soilBlock.getMetaFromState(soilState)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAcceptedResource(ItemStack itemstack) {
|
||||
for (ISoil soil : soils) {
|
||||
ItemStack resource = soil.getResource();
|
||||
if (resource.isItemEqual(itemstack)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<ISoil> getSoils() {
|
||||
return soils;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getIdentifier() {
|
||||
return identifier;
|
||||
}
|
||||
}
|
||||
@@ -13,48 +13,73 @@ package forestry.farming.logic;
|
||||
import com.google.common.base.Predicate;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Stack;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.client.renderer.texture.TextureMap;
|
||||
import net.minecraft.entity.item.EntityItem;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.NonNullList;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.math.AxisAlignedBB;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.Vec3i;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
import forestry.api.farming.FarmDirection;
|
||||
import forestry.api.farming.ICrop;
|
||||
import forestry.api.farming.IFarmHousing;
|
||||
import forestry.api.farming.IFarmInstance;
|
||||
import forestry.api.farming.IFarmLogic;
|
||||
import forestry.api.farming.IFarmable;
|
||||
import forestry.api.farming.ISoil;
|
||||
import forestry.core.utils.VectUtil;
|
||||
|
||||
public abstract class FarmLogic implements IFarmLogic {
|
||||
private final EntitySelectorFarm entitySelectorFarm = new EntitySelectorFarm(this);
|
||||
protected boolean isManual;
|
||||
protected final IFarmInstance instance;
|
||||
protected final boolean isManual;
|
||||
|
||||
public FarmLogic(IFarmInstance instance, boolean isManual) {
|
||||
this.instance = instance;
|
||||
this.isManual = isManual;
|
||||
}
|
||||
|
||||
protected Collection<IFarmable> getFarmables() {
|
||||
return instance.getFarmables();
|
||||
}
|
||||
|
||||
protected Collection<ISoil> getSoils() {
|
||||
return instance.getSoils();
|
||||
}
|
||||
|
||||
@Override
|
||||
public FarmLogic setManual(boolean flag) {
|
||||
isManual = flag;
|
||||
return this;
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
@Override
|
||||
public ResourceLocation getTextureMap() {
|
||||
return TextureMap.LOCATION_BLOCKS_TEXTURE;
|
||||
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);
|
||||
if (world.isAirBlock(position)) {
|
||||
continue;
|
||||
}
|
||||
IBlockState blockState = world.getBlockState(position);
|
||||
for (IFarmable seed : getFarmables()) {
|
||||
ICrop crop = seed.getCropAt(world, position, blockState);
|
||||
if (crop != null) {
|
||||
crops.push(crop);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return crops;
|
||||
}
|
||||
|
||||
@Override
|
||||
public abstract ItemStack getIconItemStack();
|
||||
|
||||
public abstract boolean isAcceptedWindfall(ItemStack stack);
|
||||
|
||||
protected final boolean isWaterSourceBlock(World world, BlockPos position) {
|
||||
@@ -96,6 +121,12 @@ public abstract class FarmLogic implements IFarmLogic {
|
||||
return stacks;
|
||||
}
|
||||
|
||||
// for debugging
|
||||
@Override
|
||||
public String toString() {
|
||||
return getName();
|
||||
}
|
||||
|
||||
private static class EntitySelectorFarm implements Predicate<EntityItem> {
|
||||
private final FarmLogic farmLogic;
|
||||
|
||||
@@ -112,20 +143,9 @@ public abstract class FarmLogic implements IFarmLogic {
|
||||
if (entity.getEntityData().getBoolean("PreventRemoteMovement")) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
ItemStack contained = entity.getItem();
|
||||
return farmLogic.isAcceptedGermling(contained) || farmLogic.isAcceptedWindfall(contained);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addSoil(ItemStack resource, IBlockState soilState, boolean hasMetaData) {
|
||||
// do nothing as soil is not managed by farm
|
||||
}
|
||||
|
||||
// for debugging
|
||||
@Override
|
||||
public String toString() {
|
||||
return getName();
|
||||
}
|
||||
}
|
||||
@@ -11,10 +11,12 @@
|
||||
package forestry.farming.logic;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.Stack;
|
||||
@@ -29,17 +31,21 @@ import net.minecraft.world.World;
|
||||
import forestry.api.farming.FarmDirection;
|
||||
import forestry.api.farming.ICrop;
|
||||
import forestry.api.farming.IFarmHousing;
|
||||
import forestry.api.farming.IFarmInstance;
|
||||
import forestry.api.farming.IFarmable;
|
||||
import forestry.core.ModuleCore;
|
||||
import forestry.farming.FarmRegistry;
|
||||
|
||||
public class FarmLogicArboreal extends FarmLogicHomogeneous {
|
||||
public FarmLogicArboreal(ItemStack resource, IBlockState ground, Collection<IFarmable> germlings) {
|
||||
super(resource, ground, germlings);
|
||||
|
||||
private List<IFarmable> farmables;
|
||||
|
||||
public FarmLogicArboreal(IFarmInstance instance, boolean isManual) {
|
||||
super(instance, isManual);
|
||||
this.farmables = new ArrayList<>(instance.getFarmables());
|
||||
}
|
||||
|
||||
public FarmLogicArboreal() {
|
||||
super(new ItemStack(Blocks.DIRT), ModuleCore.getBlocks().humus.getDefaultState(), FarmRegistry.getInstance().getFarmables("farmArboreal"));
|
||||
@Override
|
||||
public List<IFarmable> getFarmables() {
|
||||
return farmables;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -73,7 +79,6 @@ public class FarmLogicArboreal extends FarmLogicHomogeneous {
|
||||
|
||||
@Override
|
||||
public Collection<ICrop> harvest(World world, BlockPos pos, FarmDirection direction, int extent) {
|
||||
|
||||
if (!lastExtentsHarvest.containsKey(pos)) {
|
||||
lastExtentsHarvest.put(pos, 0);
|
||||
}
|
||||
@@ -93,7 +98,7 @@ public class FarmLogicArboreal extends FarmLogicHomogeneous {
|
||||
|
||||
private Collection<ICrop> harvestBlocks(World world, BlockPos position) {
|
||||
// Determine what type we want to harvest.
|
||||
IFarmable farmable = getFarmableForBlock(world, position, farmables);
|
||||
IFarmable farmable = getFarmableForBlock(world, position, getFarmables());
|
||||
if (farmable == null) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
@@ -126,6 +131,9 @@ public class FarmLogicArboreal extends FarmLogicHomogeneous {
|
||||
|
||||
@Nullable
|
||||
private static IFarmable getFarmableForBlock(World world, BlockPos position, Collection<IFarmable> farmables) {
|
||||
if (world.isAirBlock(position)) {
|
||||
return null;
|
||||
}
|
||||
IBlockState blockState = world.getBlockState(position);
|
||||
for (IFarmable farmable : farmables) {
|
||||
ICrop crop = farmable.getCropAt(world, position, blockState);
|
||||
@@ -154,7 +162,7 @@ public class FarmLogicArboreal extends FarmLogicHomogeneous {
|
||||
|
||||
private boolean plantSapling(World world, IFarmHousing farmHousing, BlockPos position, FarmDirection direction) {
|
||||
Collections.shuffle(farmables);
|
||||
for (IFarmable candidate : farmables) {
|
||||
for (IFarmable candidate : getFarmables()) {
|
||||
if (farmHousing.plantGermling(candidate, world, position, direction)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -34,12 +34,17 @@ import net.minecraft.world.World;
|
||||
import forestry.api.farming.FarmDirection;
|
||||
import forestry.api.farming.ICrop;
|
||||
import forestry.api.farming.IFarmHousing;
|
||||
import forestry.api.farming.IFarmInstance;
|
||||
import forestry.api.farming.IFarmable;
|
||||
import forestry.farming.logic.farmables.FarmableCocoa;
|
||||
|
||||
public class FarmLogicCocoa extends FarmLogic {
|
||||
private final IFarmable cocoa = new FarmableCocoa();
|
||||
|
||||
public FarmLogicCocoa(IFarmInstance instance, boolean isManual) {
|
||||
super(instance, isManual);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getIconItemStack() {
|
||||
return new ItemStack(Items.DYE, 1, 3);
|
||||
|
||||
@@ -10,11 +10,7 @@
|
||||
******************************************************************************/
|
||||
package forestry.farming.logic;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Stack;
|
||||
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.init.Items;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.NonNullList;
|
||||
@@ -22,33 +18,20 @@ import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import forestry.api.farming.FarmDirection;
|
||||
import forestry.api.farming.ICrop;
|
||||
import forestry.api.farming.IFarmHousing;
|
||||
import forestry.api.farming.IFarmInstance;
|
||||
import forestry.api.farming.IFarmable;
|
||||
import forestry.core.utils.BlockUtil;
|
||||
import forestry.farming.FarmRegistry;
|
||||
|
||||
public class FarmLogicCrops extends FarmLogicWatered {
|
||||
private final Iterable<IFarmable> seeds;
|
||||
|
||||
public FarmLogicCrops() {
|
||||
this(FarmRegistry.getInstance().getFarmables("farmCrops"));
|
||||
}
|
||||
|
||||
protected FarmLogicCrops(Iterable<IFarmable> seeds) {
|
||||
super(new ItemStack(Blocks.DIRT), Blocks.FARMLAND.getDefaultState());
|
||||
|
||||
this.seeds = seeds;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAcceptedGround(IBlockState blockState) {
|
||||
return super.isAcceptedGround(blockState) || blockState.getBlock() == Blocks.FARMLAND;
|
||||
public FarmLogicCrops(IFarmInstance instance, boolean isManual) {
|
||||
super(instance, isManual);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAcceptedGermling(ItemStack itemstack) {
|
||||
for (IFarmable germling : seeds) {
|
||||
for (IFarmable germling : getFarmables()) {
|
||||
if (germling.isGermling(itemstack)) {
|
||||
return true;
|
||||
}
|
||||
@@ -58,7 +41,7 @@ public class FarmLogicCrops extends FarmLogicWatered {
|
||||
|
||||
@Override
|
||||
public boolean isAcceptedWindfall(ItemStack itemstack) {
|
||||
for (IFarmable germling : seeds) {
|
||||
for (IFarmable germling : getFarmables()) {
|
||||
if (germling.isWindfall(itemstack)) {
|
||||
return true;
|
||||
}
|
||||
@@ -83,7 +66,7 @@ public class FarmLogicCrops extends FarmLogicWatered {
|
||||
}
|
||||
|
||||
IBlockState groundState = world.getBlockState(position.down());
|
||||
if (isAcceptedGround(groundState)) {
|
||||
if (isAcceptedSoil(groundState)) {
|
||||
return trySetCrop(world, farmHousing, position, direction);
|
||||
}
|
||||
}
|
||||
@@ -92,7 +75,7 @@ public class FarmLogicCrops extends FarmLogicWatered {
|
||||
}
|
||||
|
||||
private boolean trySetCrop(World world, IFarmHousing farmHousing, BlockPos position, FarmDirection direction) {
|
||||
for (IFarmable candidate : seeds) {
|
||||
for (IFarmable candidate : getFarmables()) {
|
||||
if (farmHousing.plantGermling(candidate, world, position, direction)) {
|
||||
return true;
|
||||
}
|
||||
@@ -101,23 +84,6 @@ public class FarmLogicCrops extends FarmLogicWatered {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<ICrop> harvest(World world, BlockPos pos, FarmDirection direction, int extent) {
|
||||
Stack<ICrop> crops = new Stack<>();
|
||||
for (int i = 0; i < extent; i++) {
|
||||
BlockPos position = translateWithOffset(pos.up(), direction, i);
|
||||
IBlockState blockState = world.getBlockState(position);
|
||||
for (IFarmable seed : seeds) {
|
||||
ICrop crop = seed.getCropAt(world, position, blockState);
|
||||
if (crop != null) {
|
||||
crops.push(crop);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return crops;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getIconItemStack() {
|
||||
return new ItemStack(Items.WHEAT);
|
||||
|
||||
@@ -10,12 +10,7 @@
|
||||
******************************************************************************/
|
||||
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.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.NonNullList;
|
||||
@@ -23,22 +18,17 @@ import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import forestry.api.farming.FarmDirection;
|
||||
import forestry.api.farming.ICrop;
|
||||
import forestry.api.farming.IFarmHousing;
|
||||
import forestry.api.farming.IFarmable;
|
||||
import forestry.api.farming.IFarmInstance;
|
||||
import forestry.core.utils.BlockUtil;
|
||||
import forestry.farming.FarmRegistry;
|
||||
|
||||
public class FarmLogicExU extends FarmLogicHomogeneous {
|
||||
|
||||
private final String name;
|
||||
private final Item iconItem;
|
||||
|
||||
public FarmLogicExU(String name, Item iconItem, Block soil, String farmablesKey) {
|
||||
super(new ItemStack(soil), soil.getDefaultState(), FarmRegistry.getInstance().getFarmables(farmablesKey));
|
||||
if (soil.equals(Blocks.REDSTONE_ORE)) {
|
||||
super.addSoil(new ItemStack(Blocks.LIT_REDSTONE_ORE), Blocks.LIT_REDSTONE_ORE.getDefaultState(), false);
|
||||
}
|
||||
public FarmLogicExU(IFarmInstance instance, boolean isManual, String name, Item iconItem) {
|
||||
super(instance, isManual);
|
||||
this.name = name;
|
||||
this.iconItem = iconItem;
|
||||
}
|
||||
@@ -68,25 +58,6 @@ public class FarmLogicExU extends FarmLogicHomogeneous {
|
||||
return NonNullList.create();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<ICrop> harvest(World world, BlockPos pos, FarmDirection direction, int extent) {
|
||||
Stack<ICrop> crops = new Stack<>();
|
||||
for (int i = 0; i < extent; i++) {
|
||||
BlockPos position = translateWithOffset(pos.up(), direction, i);
|
||||
IBlockState blockState = world.getBlockState(position);
|
||||
for (IFarmable farmable : farmables) {
|
||||
ICrop crop = farmable.getCropAt(world, position, blockState);
|
||||
if (crop != null) {
|
||||
crops.push(crop);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
return crops;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean maintainGermlings(World world, IFarmHousing farmHousing, BlockPos pos, FarmDirection direction, int extent) {
|
||||
for (int i = 0; i < extent; i++) {
|
||||
|
||||
@@ -10,10 +10,6 @@
|
||||
******************************************************************************/
|
||||
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.ItemStack;
|
||||
import net.minecraft.util.NonNullList;
|
||||
@@ -21,18 +17,13 @@ import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import forestry.api.farming.FarmDirection;
|
||||
import forestry.api.farming.ICrop;
|
||||
import forestry.api.farming.IFarmHousing;
|
||||
import forestry.api.farming.IFarmable;
|
||||
import forestry.farming.FarmRegistry;
|
||||
import forestry.api.farming.IFarmInstance;
|
||||
|
||||
public class FarmLogicGourd extends FarmLogic {
|
||||
|
||||
private final IFarmable[] seeds;
|
||||
|
||||
public FarmLogicGourd() {
|
||||
Collection<IFarmable> farmables = FarmRegistry.getInstance().getFarmables("farmGourd");
|
||||
seeds = farmables.toArray(new IFarmable[farmables.size()]);
|
||||
public FarmLogicGourd(IFarmInstance instance, boolean isManual) {
|
||||
super(instance, isManual);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -79,21 +70,4 @@ public class FarmLogicGourd extends FarmLogic {
|
||||
public boolean cultivate(World world, IFarmHousing farmHousing, BlockPos pos, FarmDirection direction, int extent) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<ICrop> harvest(World world, BlockPos pos, FarmDirection direction, int extent) {
|
||||
Stack<ICrop> crops = new Stack<>();
|
||||
for (int i = 0; i < extent; i++) {
|
||||
BlockPos position = translateWithOffset(pos.up(), direction, i);
|
||||
IBlockState blockState = world.getBlockState(position);
|
||||
for (IFarmable seed : seeds) {
|
||||
ICrop crop = seed.getCropAt(world, position, blockState);
|
||||
if (crop != null) {
|
||||
crops.push(crop);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return crops;
|
||||
}
|
||||
}
|
||||
@@ -10,11 +10,6 @@
|
||||
******************************************************************************/
|
||||
package forestry.farming.logic;
|
||||
|
||||
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.NonNullList;
|
||||
@@ -23,47 +18,21 @@ import net.minecraft.world.World;
|
||||
|
||||
import forestry.api.farming.FarmDirection;
|
||||
import forestry.api.farming.IFarmHousing;
|
||||
import forestry.api.farming.IFarmInstance;
|
||||
import forestry.api.farming.IFarmable;
|
||||
import forestry.api.farming.ISoil;
|
||||
import forestry.core.utils.BlockUtil;
|
||||
|
||||
public abstract class FarmLogicHomogeneous extends FarmLogicSoil {
|
||||
protected final List<IFarmable> farmables;
|
||||
|
||||
protected NonNullList<ItemStack> produce = NonNullList.create();
|
||||
|
||||
protected FarmLogicHomogeneous(ItemStack resource, IBlockState soilState, Collection<IFarmable> farmables) {
|
||||
addSoil(resource, soilState, false);
|
||||
this.farmables = new ArrayList<>(farmables);
|
||||
}
|
||||
|
||||
protected boolean isAcceptedSoil(IBlockState blockState) {
|
||||
for(Soil soil : soils){
|
||||
IBlockState soilState = soil.getSoilState();
|
||||
Block soilBlock = soilState.getBlock();
|
||||
Block block = blockState.getBlock();
|
||||
if(soilState.getBlock() == blockState.getBlock()){
|
||||
if(!soil.hasMetaData() || block.getMetaFromState(blockState) == soilBlock.getMetaFromState(soilState)){
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAcceptedResource(ItemStack itemstack) {
|
||||
for(Soil soil : soils){
|
||||
ItemStack resource = soil.getResource();
|
||||
if(resource.isItemEqual(itemstack)){
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
public FarmLogicHomogeneous(IFarmInstance instance, boolean isManual) {
|
||||
super(instance, isManual);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAcceptedGermling(ItemStack itemstack) {
|
||||
for (IFarmable germling : farmables) {
|
||||
for (IFarmable germling : getFarmables()) {
|
||||
if (germling.isGermling(itemstack)) {
|
||||
return true;
|
||||
}
|
||||
@@ -73,7 +42,7 @@ public abstract class FarmLogicHomogeneous extends FarmLogicSoil {
|
||||
|
||||
@Override
|
||||
public boolean isAcceptedWindfall(ItemStack itemstack) {
|
||||
for (IFarmable germling : farmables) {
|
||||
for (IFarmable germling : getFarmables()) {
|
||||
if (germling.isWindfall(itemstack)) {
|
||||
return true;
|
||||
}
|
||||
@@ -81,18 +50,8 @@ public abstract class FarmLogicHomogeneous extends FarmLogicSoil {
|
||||
return false;
|
||||
}
|
||||
|
||||
protected boolean trySetCrop(World world, IFarmHousing farmHousing, BlockPos position, FarmDirection direction, boolean shuffle) {
|
||||
for (IFarmable candidate : farmables) {
|
||||
if (farmHousing.plantGermling(candidate, world, position, direction)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
protected boolean trySetCrop(World world, IFarmHousing farmHousing, BlockPos position, FarmDirection direction) {
|
||||
for (IFarmable candidate : farmables) {
|
||||
for (IFarmable candidate : getFarmables()) {
|
||||
if (farmHousing.plantGermling(candidate, world, position, direction)) {
|
||||
return true;
|
||||
}
|
||||
@@ -103,37 +62,43 @@ public abstract class FarmLogicHomogeneous extends FarmLogicSoil {
|
||||
|
||||
@Override
|
||||
public boolean cultivate(World world, IFarmHousing farmHousing, BlockPos pos, FarmDirection direction, int extent) {
|
||||
return maintainSoil(world, farmHousing, pos, direction, extent) ||
|
||||
maintainGermlings(world, farmHousing, pos.up(), direction, extent);
|
||||
if(isManual){
|
||||
|
||||
}
|
||||
return maintainSoil(world, farmHousing, pos, direction, extent) || maintainGermlings(world, farmHousing, pos.up(), direction, extent);
|
||||
}
|
||||
|
||||
private boolean maintainSoil(World world, IFarmHousing farmHousing, BlockPos pos, FarmDirection direction, int extent) {
|
||||
for(Soil soil : soils){
|
||||
if(!farmHousing.canPlantSoil(isManual)){
|
||||
return false;
|
||||
}
|
||||
|
||||
for (ISoil soil : getSoils()) {
|
||||
NonNullList<ItemStack> resources = NonNullList.create();
|
||||
resources.add(soil.getResource());
|
||||
if (!farmHousing.getFarmInventory().hasResources(resources)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
for (int i = 0; i < extent; i++) {
|
||||
BlockPos position = translateWithOffset(pos, direction, i);
|
||||
IBlockState soilState = world.getBlockState(position);
|
||||
|
||||
|
||||
if (farmHousing.isValidPlatform(world, pos)) {
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
if (isAcceptedSoil(soilState)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
BlockPos platformPosition = position.down();
|
||||
if (!farmHousing.isValidPlatform(world, platformPosition)) {
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
produce.addAll(BlockUtil.getBlockDrops(world, position));
|
||||
|
||||
|
||||
BlockUtil.setBlockWithPlaceSound(world, position, soil.getSoilState());
|
||||
farmHousing.getFarmInventory().removeResources(resources);
|
||||
return true;
|
||||
|
||||
@@ -14,7 +14,6 @@ import java.util.Collection;
|
||||
import java.util.Stack;
|
||||
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.init.Items;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.NonNullList;
|
||||
@@ -24,14 +23,14 @@ import net.minecraft.world.World;
|
||||
import forestry.api.farming.FarmDirection;
|
||||
import forestry.api.farming.ICrop;
|
||||
import forestry.api.farming.IFarmHousing;
|
||||
import forestry.api.farming.IFarmInstance;
|
||||
import forestry.api.farming.IFarmable;
|
||||
import forestry.core.utils.BlockUtil;
|
||||
import forestry.farming.FarmRegistry;
|
||||
|
||||
public class FarmLogicInfernal extends FarmLogicHomogeneous {
|
||||
|
||||
public FarmLogicInfernal() {
|
||||
super(new ItemStack(Blocks.SOUL_SAND), Blocks.SOUL_SAND.getDefaultState(), FarmRegistry.getInstance().getFarmables("farmInfernal"));
|
||||
public FarmLogicInfernal(IFarmInstance instance, boolean isManual) {
|
||||
super(instance, isManual);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -64,8 +63,11 @@ public class FarmLogicInfernal extends FarmLogicHomogeneous {
|
||||
Stack<ICrop> crops = new Stack<>();
|
||||
for (int i = 0; i < extent; i++) {
|
||||
BlockPos position = translateWithOffset(pos.up(), direction, i);
|
||||
if (world.isAirBlock(pos)) {
|
||||
continue;
|
||||
}
|
||||
IBlockState blockState = world.getBlockState(position);
|
||||
for (IFarmable farmable : farmables) {
|
||||
for (IFarmable farmable : getFarmables()) {
|
||||
ICrop crop = farmable.getCropAt(world, position, blockState);
|
||||
if (crop != null) {
|
||||
crops.push(crop);
|
||||
|
||||
@@ -15,14 +15,13 @@ import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.NonNullList;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import forestry.api.core.ForestryAPI;
|
||||
import forestry.api.farming.IFarmHousing;
|
||||
import forestry.api.farming.IFarmInstance;
|
||||
|
||||
public class FarmLogicMushroom extends FarmLogicArboreal {
|
||||
|
||||
public FarmLogicMushroom() {
|
||||
super(new ItemStack(Blocks.MYCELIUM), Blocks.MYCELIUM.getDefaultState(), ForestryAPI.farmRegistry.getFarmables("farmShroom"));
|
||||
addSoil(new ItemStack(Blocks.DIRT, 1, 2), Blocks.DIRT.getStateFromMeta(2), true);
|
||||
public FarmLogicMushroom(IFarmInstance instance, boolean isManual) {
|
||||
super(instance, isManual);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -28,10 +28,10 @@ import net.minecraft.util.NonNullList;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import forestry.api.core.ForestryAPI;
|
||||
import forestry.api.farming.FarmDirection;
|
||||
import forestry.api.farming.ICrop;
|
||||
import forestry.api.farming.IFarmHousing;
|
||||
import forestry.api.farming.IFarmInstance;
|
||||
import forestry.api.farming.IFarmable;
|
||||
import forestry.api.genetics.IFruitBearer;
|
||||
import forestry.core.ModuleCore;
|
||||
@@ -40,12 +40,11 @@ import forestry.farming.logic.crops.CropFruit;
|
||||
|
||||
public class FarmLogicOrchard extends FarmLogic {
|
||||
|
||||
private final Collection<IFarmable> farmables;
|
||||
private final HashMap<BlockPos, Integer> lastExtents = new HashMap<>();
|
||||
private final ImmutableList<Block> traversalBlocks;
|
||||
|
||||
public FarmLogicOrchard() {
|
||||
this.farmables = ForestryAPI.farmRegistry.getFarmables("farmOrchard");
|
||||
public FarmLogicOrchard(IFarmInstance instance, boolean isManual) {
|
||||
super(instance, isManual);
|
||||
|
||||
ImmutableList.Builder<Block> traversalBlocksBuilder = ImmutableList.builder();
|
||||
// if (ForestryAPI.enabledModules.contains(new ResourceLocation(Constants.MOD_ID, ForestryModuleUids.AGRICRAFT) || ForestryAPI.enabledModules.contains(new ResourceLocation(Constants.MOD_ID, ForestryModuleUids.INDUSTRIALCRAFT)) {
|
||||
@@ -64,8 +63,6 @@ public class FarmLogicOrchard extends FarmLogic {
|
||||
// traversalBlocksBuilder.add(grapeVine);
|
||||
// }
|
||||
// }
|
||||
|
||||
traversalBlocksBuilder.build();
|
||||
this.traversalBlocks = traversalBlocksBuilder.build();
|
||||
}
|
||||
|
||||
@@ -209,7 +206,7 @@ public class FarmLogicOrchard extends FarmLogic {
|
||||
return true;
|
||||
}
|
||||
|
||||
for (IFarmable farmable : farmables) {
|
||||
for (IFarmable farmable : getFarmables()) {
|
||||
if (farmable.isSaplingAt(world, position)) {
|
||||
return true;
|
||||
}
|
||||
@@ -238,7 +235,7 @@ public class FarmLogicOrchard extends FarmLogic {
|
||||
}
|
||||
} else {
|
||||
IBlockState blockState = world.getBlockState(position);
|
||||
for (IFarmable seed : farmables) {
|
||||
for (IFarmable seed : getFarmables()) {
|
||||
ICrop crop = seed.getCropAt(world, position, blockState);
|
||||
if (crop != null) {
|
||||
return crop;
|
||||
|
||||
@@ -21,24 +21,14 @@ import net.minecraft.world.World;
|
||||
|
||||
import forestry.api.farming.FarmDirection;
|
||||
import forestry.api.farming.ICrop;
|
||||
import forestry.api.farming.IFarmInstance;
|
||||
import forestry.core.ModuleCore;
|
||||
import forestry.core.blocks.BlockBogEarth;
|
||||
import forestry.farming.logic.crops.CropPeat;
|
||||
|
||||
public class FarmLogicPeat extends FarmLogicWatered {
|
||||
private static final ItemStack bogEarth = ModuleCore.getBlocks().bogEarth.get(BlockBogEarth.SoilType.BOG_EARTH, 1);
|
||||
|
||||
public FarmLogicPeat() {
|
||||
super(bogEarth, ModuleCore.getBlocks().bogEarth.getDefaultState());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAcceptedGround(IBlockState blockState) {
|
||||
if (super.isAcceptedGround(blockState)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return blockState.getBlock() == ModuleCore.getBlocks().bogEarth;
|
||||
public FarmLogicPeat(IFarmInstance instance, boolean isManual) {
|
||||
super(instance, isManual);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -10,11 +10,6 @@
|
||||
******************************************************************************/
|
||||
package forestry.farming.logic;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Stack;
|
||||
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.init.Items;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.NonNullList;
|
||||
@@ -22,18 +17,12 @@ import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import forestry.api.farming.FarmDirection;
|
||||
import forestry.api.farming.ICrop;
|
||||
import forestry.api.farming.IFarmHousing;
|
||||
import forestry.api.farming.IFarmable;
|
||||
import forestry.farming.FarmRegistry;
|
||||
import forestry.api.farming.IFarmInstance;
|
||||
|
||||
public class FarmLogicReeds extends FarmLogicSoil {
|
||||
private final Collection<IFarmable> germlings = FarmRegistry.getInstance().getFarmables("farmPoales");
|
||||
|
||||
|
||||
public FarmLogicReeds() {
|
||||
addSoil(new ItemStack(Blocks.SAND), Blocks.SAND.getDefaultState(),true);
|
||||
addSoil(new ItemStack(Blocks.DIRT), Blocks.DIRT.getDefaultState(),false);
|
||||
public FarmLogicReeds(IFarmInstance instance, boolean isManual) {
|
||||
super(instance, isManual);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -61,18 +50,12 @@ public class FarmLogicReeds extends FarmLogicSoil {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAcceptedResource(ItemStack itemstack) {
|
||||
public boolean isAcceptedResource(ItemStack itemStack) {
|
||||
if (isManual) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for(Soil soil : soils){
|
||||
ItemStack resource = soil.getResource();
|
||||
if(resource.isItemEqual(itemstack)){
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
return super.isAcceptedResource(itemStack);
|
||||
|
||||
}
|
||||
|
||||
@@ -100,21 +83,4 @@ public class FarmLogicReeds extends FarmLogicSoil {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<ICrop> harvest(World world, BlockPos pos, FarmDirection direction, int extent) {
|
||||
Stack<ICrop> crops = new Stack<>();
|
||||
for (int i = 0; i < extent; i++) {
|
||||
BlockPos position = translateWithOffset(pos.up(), direction, i);
|
||||
IBlockState blockState = world.getBlockState(position);
|
||||
for (IFarmable seed : germlings) {
|
||||
ICrop crop = seed.getCropAt(world, position, blockState);
|
||||
if (crop != null) {
|
||||
crops.push(crop);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return crops;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -25,6 +25,7 @@ import net.minecraft.world.World;
|
||||
import forestry.api.farming.FarmDirection;
|
||||
import forestry.api.farming.ICrop;
|
||||
import forestry.api.farming.IFarmHousing;
|
||||
import forestry.api.farming.IFarmInstance;
|
||||
import forestry.core.utils.ItemStackUtil;
|
||||
import forestry.core.utils.Log;
|
||||
import forestry.farming.logic.crops.CropRubber;
|
||||
@@ -34,7 +35,8 @@ public class FarmLogicRubber extends FarmLogic {
|
||||
|
||||
private boolean active = true;
|
||||
|
||||
public FarmLogicRubber() {
|
||||
public FarmLogicRubber(IFarmInstance instance, boolean isManual) {
|
||||
super(instance, isManual);
|
||||
if (PluginIC2.rubberWood == null || PluginIC2.resin == null) {
|
||||
Log.warning("Failed to init a farm logic {} since IC2 rubber wood or resin were not found", getClass().getName());
|
||||
active = false;
|
||||
@@ -131,5 +133,5 @@ public class FarmLogicRubber extends FarmLogic {
|
||||
|
||||
return crops;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -1,14 +1,16 @@
|
||||
package forestry.farming.logic;
|
||||
|
||||
import forestry.api.farming.ISimpleFarmLogic;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import forestry.api.farming.IFarmInstance;
|
||||
import forestry.api.farming.ISimpleFarmLogic;
|
||||
|
||||
public class FarmLogicSimple extends FarmLogicCrops {
|
||||
|
||||
protected final ISimpleFarmLogic simpleLogic;
|
||||
|
||||
public FarmLogicSimple(ISimpleFarmLogic simpleLogic) {
|
||||
super(simpleLogic.getSeeds());
|
||||
private final ISimpleFarmLogic simpleLogic;
|
||||
|
||||
public FarmLogicSimple(IFarmInstance instance, boolean isManual, ISimpleFarmLogic simpleLogic) {
|
||||
super(instance, isManual);
|
||||
this.simpleLogic = simpleLogic;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,20 +1,23 @@
|
||||
package forestry.farming.logic;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
public abstract class FarmLogicSoil extends FarmLogic {
|
||||
protected final Set<Soil> soils = new HashSet<>();
|
||||
import forestry.api.farming.IFarmInstance;
|
||||
|
||||
public FarmLogicSoil() {
|
||||
public abstract class FarmLogicSoil extends FarmLogic {
|
||||
|
||||
public FarmLogicSoil(IFarmInstance instance, boolean isManual) {
|
||||
super(instance, isManual);
|
||||
}
|
||||
|
||||
protected boolean isAcceptedSoil(IBlockState blockState) {
|
||||
return instance.isAcceptedSoil(blockState);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addSoil(ItemStack resource, IBlockState soilState, boolean hasMetaData) {
|
||||
soils.add(new Soil(resource,soilState,hasMetaData));
|
||||
public boolean isAcceptedResource(ItemStack itemStack) {
|
||||
return instance.isAcceptedResource(itemStack);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -10,10 +10,6 @@
|
||||
******************************************************************************/
|
||||
package forestry.farming.logic;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Stack;
|
||||
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.init.Items;
|
||||
import net.minecraft.item.ItemStack;
|
||||
@@ -22,19 +18,15 @@ import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import forestry.api.farming.FarmDirection;
|
||||
import forestry.api.farming.ICrop;
|
||||
import forestry.api.farming.IFarmHousing;
|
||||
import forestry.api.farming.IFarmable;
|
||||
import forestry.api.farming.IFarmInstance;
|
||||
import forestry.core.utils.ItemStackUtil;
|
||||
import forestry.farming.FarmRegistry;
|
||||
|
||||
public class FarmLogicSucculent extends FarmLogicSoil {
|
||||
private final Collection<IFarmable> germlings = FarmRegistry.getInstance().getFarmables("farmSucculentes");
|
||||
|
||||
public FarmLogicSucculent() {
|
||||
addSoil(new ItemStack(Blocks.SAND), Blocks.SAND.getDefaultState(),true);
|
||||
public FarmLogicSucculent(IFarmInstance instance, boolean isManual) {
|
||||
super(instance, isManual);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public ItemStack getIconItemStack() {
|
||||
return new ItemStack(Items.DYE, 1, 2);
|
||||
@@ -48,7 +40,7 @@ public class FarmLogicSucculent extends FarmLogicSoil {
|
||||
return "Managed Succulent Farm";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int getFertilizerConsumption() {
|
||||
return 10;
|
||||
@@ -58,20 +50,14 @@ public class FarmLogicSucculent extends FarmLogicSoil {
|
||||
public int getWaterConsumption(float hydrationModifier) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean isAcceptedResource(ItemStack itemstack) {
|
||||
public boolean isAcceptedResource(ItemStack itemStack) {
|
||||
if (isManual) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for(Soil soil : soils){
|
||||
ItemStack resource = soil.getResource();
|
||||
if(resource.isItemEqual(itemstack)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
return super.isAcceptedResource(itemStack);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -98,21 +84,4 @@ public class FarmLogicSucculent extends FarmLogicSoil {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<ICrop> harvest(World world, BlockPos pos, FarmDirection direction, int extent) {
|
||||
Stack<ICrop> crops = new Stack<>();
|
||||
for (int i = 0; i < extent; i++) {
|
||||
BlockPos position = translateWithOffset(pos.up(), direction, i);
|
||||
IBlockState blockState = world.getBlockState(position);
|
||||
for (IFarmable seed : germlings) {
|
||||
ICrop crop = seed.getCropAt(world, position, blockState);
|
||||
if (crop != null) {
|
||||
crops.push(crop);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return crops;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -10,7 +10,6 @@
|
||||
******************************************************************************/
|
||||
package forestry.farming.logic;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.item.ItemStack;
|
||||
@@ -24,6 +23,8 @@ import net.minecraftforge.fluids.FluidStack;
|
||||
|
||||
import forestry.api.farming.FarmDirection;
|
||||
import forestry.api.farming.IFarmHousing;
|
||||
import forestry.api.farming.IFarmInstance;
|
||||
import forestry.api.farming.ISoil;
|
||||
import forestry.core.utils.BlockUtil;
|
||||
|
||||
public abstract class FarmLogicWatered extends FarmLogicSoil {
|
||||
@@ -31,8 +32,8 @@ public abstract class FarmLogicWatered extends FarmLogicSoil {
|
||||
|
||||
protected NonNullList<ItemStack> produce = NonNullList.create();
|
||||
|
||||
protected FarmLogicWatered(ItemStack resource, IBlockState ground) {
|
||||
addSoil(resource,ground,false);
|
||||
public FarmLogicWatered(IFarmInstance instance, boolean isManual) {
|
||||
super(instance, isManual);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -45,31 +46,6 @@ public abstract class FarmLogicWatered extends FarmLogicSoil {
|
||||
return (int) (20 * hydrationModifier);
|
||||
}
|
||||
|
||||
protected boolean isAcceptedGround(IBlockState ground) {
|
||||
for(Soil soil : soils){
|
||||
IBlockState soilState = soil.getSoilState();
|
||||
Block soilBlock = soilState.getBlock();
|
||||
Block block = ground.getBlock();
|
||||
if(soilState.getBlock() == ground.getBlock()){
|
||||
if(!soil.hasMetaData() || block.getMetaFromState(ground) == soilBlock.getMetaFromState(soilState)){
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAcceptedResource(ItemStack itemstack) {
|
||||
for(Soil soil : soils){
|
||||
ItemStack resource = soil.getResource();
|
||||
if(resource.isItemEqual(itemstack)){
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NonNullList<ItemStack> collect(World world, IFarmHousing farmHousing) {
|
||||
NonNullList<ItemStack> products = produce;
|
||||
@@ -79,7 +55,6 @@ public abstract class FarmLogicWatered extends FarmLogicSoil {
|
||||
|
||||
@Override
|
||||
public boolean cultivate(World world, IFarmHousing farmHousing, BlockPos pos, FarmDirection direction, int extent) {
|
||||
|
||||
if (maintainSoil(world, farmHousing, pos, direction, extent)) {
|
||||
return true;
|
||||
}
|
||||
@@ -93,33 +68,37 @@ public abstract class FarmLogicWatered extends FarmLogicSoil {
|
||||
}
|
||||
|
||||
private boolean maintainSoil(World world, IFarmHousing farmHousing, BlockPos pos, FarmDirection direction, int extent) {
|
||||
for (Soil soil : soils) {
|
||||
if(!farmHousing.canPlantSoil(isManual)){
|
||||
return false;
|
||||
}
|
||||
|
||||
for (ISoil soil : getSoils()) {
|
||||
NonNullList<ItemStack> resources = NonNullList.create();
|
||||
resources.add(soil.getResource());
|
||||
|
||||
for (int i = 0; i < extent; i++) {
|
||||
BlockPos position = translateWithOffset(pos, direction, i);
|
||||
IBlockState state = world.getBlockState(position);
|
||||
if (isAcceptedGround(state) || isWaterSourceBlock(world, position) || !farmHousing.getFarmInventory().hasResources(resources)) {
|
||||
if (isAcceptedSoil(state) || isWaterSourceBlock(world, position) || !farmHousing.getFarmInventory().hasResources(resources)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
BlockPos platformPosition = position.down();
|
||||
if (!farmHousing.isValidPlatform(world, platformPosition)) {
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
if (!BlockUtil.isReplaceableBlock(state, world, position)) {
|
||||
produce.addAll(BlockUtil.getBlockDrops(world, position));
|
||||
world.setBlockToAir(position);
|
||||
return trySetSoil(world, farmHousing, position, soil.getResource(), soil.getSoilState());
|
||||
}
|
||||
|
||||
|
||||
if (!isManual) {
|
||||
if (trySetWater(world, farmHousing, position)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
return trySetSoil(world, farmHousing, position, soil.getResource(), soil.getSoilState());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,28 +1,30 @@
|
||||
package forestry.farming.logic;
|
||||
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
class Soil {
|
||||
private final ItemStack resource;
|
||||
private final IBlockState soilState;
|
||||
private final boolean hasMetaData;
|
||||
|
||||
public Soil(ItemStack resource, IBlockState soilState, boolean hasMetaData) {
|
||||
this.resource = resource;
|
||||
this.soilState = soilState;
|
||||
this.hasMetaData = hasMetaData;
|
||||
}
|
||||
|
||||
public ItemStack getResource() {
|
||||
return resource;
|
||||
}
|
||||
|
||||
public IBlockState getSoilState() {
|
||||
return soilState;
|
||||
}
|
||||
|
||||
public boolean hasMetaData() {
|
||||
return this.hasMetaData;
|
||||
}
|
||||
package forestry.farming.logic;
|
||||
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import forestry.api.farming.ISoil;
|
||||
|
||||
class Soil implements ISoil {
|
||||
private final ItemStack resource;
|
||||
private final IBlockState soilState;
|
||||
private final boolean hasMetaData;
|
||||
|
||||
public Soil(ItemStack resource, IBlockState soilState, boolean hasMetaData) {
|
||||
this.resource = resource;
|
||||
this.soilState = soilState;
|
||||
this.hasMetaData = hasMetaData;
|
||||
}
|
||||
|
||||
public ItemStack getResource() {
|
||||
return resource;
|
||||
}
|
||||
|
||||
public IBlockState getSoilState() {
|
||||
return soilState;
|
||||
}
|
||||
|
||||
public boolean hasMetaData() {
|
||||
return this.hasMetaData;
|
||||
}
|
||||
}
|
||||
@@ -34,6 +34,7 @@ public class CropBasicIC2Crop extends Crop {
|
||||
|
||||
/**
|
||||
* Check if there is an instance of ICropTile.
|
||||
*
|
||||
* @param tileEntity tile entity to be checked.
|
||||
* @return true if there is an IC2 crop and false otherwise.
|
||||
*/
|
||||
@@ -44,6 +45,7 @@ public class CropBasicIC2Crop extends Crop {
|
||||
|
||||
/**
|
||||
* Check if an IC2 crop is ready to be harvested.
|
||||
*
|
||||
* @param tileEntity tile entity to be checked.
|
||||
* @return true if crop size is optimal for harvest and false otherwise.
|
||||
*/
|
||||
@@ -64,6 +66,7 @@ public class CropBasicIC2Crop extends Crop {
|
||||
/**
|
||||
* This function takes care of everything related to the harvesting of the
|
||||
* crop meaning it will calculate the drops and also do setSizeAfterHarvest().
|
||||
*
|
||||
* @param tileEntity tile entity to be checked.
|
||||
* @return list containing the drops.
|
||||
*/
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
package forestry.farming.logic.crops;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.Iterator;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
@@ -19,8 +20,11 @@ import net.minecraft.util.NonNullList;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import net.minecraftforge.event.ForgeEventFactory;
|
||||
|
||||
import forestry.core.config.Constants;
|
||||
import forestry.core.network.packets.PacketFXSignal;
|
||||
import forestry.core.utils.ItemStackUtil;
|
||||
import forestry.core.utils.NetworkUtil;
|
||||
|
||||
public class CropDestroy extends Crop {
|
||||
@@ -29,10 +33,17 @@ public class CropDestroy extends Crop {
|
||||
@Nullable
|
||||
protected final IBlockState replantState;
|
||||
|
||||
protected final ItemStack germling;
|
||||
|
||||
public CropDestroy(World world, IBlockState blockState, BlockPos position, @Nullable IBlockState replantState) {
|
||||
this(world, blockState, position, replantState, ItemStack.EMPTY);
|
||||
}
|
||||
|
||||
public CropDestroy(World world, IBlockState blockState, BlockPos position, @Nullable IBlockState replantState, ItemStack germling) {
|
||||
super(world, position);
|
||||
this.blockState = blockState;
|
||||
this.replantState = replantState;
|
||||
this.germling = germling;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -45,6 +56,22 @@ public class CropDestroy extends Crop {
|
||||
Block block = blockState.getBlock();
|
||||
NonNullList<ItemStack> harvested = NonNullList.create();
|
||||
harvested.addAll(block.getDrops(world, pos, blockState, 0));
|
||||
float chance = ForgeEventFactory.fireBlockHarvesting(harvested, world, pos, blockState, 0, 1.0F, false, null);
|
||||
|
||||
boolean removedSeed = germling.isEmpty();
|
||||
Iterator<ItemStack> dropIterator = harvested.iterator();
|
||||
while (dropIterator.hasNext()) {
|
||||
ItemStack next = dropIterator.next();
|
||||
if (world.rand.nextFloat() <= chance) {
|
||||
if (!removedSeed && ItemStackUtil.isIdenticalItem(next, germling)) {
|
||||
next.shrink(1);
|
||||
if (next.isEmpty()) {
|
||||
dropIterator.remove();
|
||||
}
|
||||
removedSeed = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
PacketFXSignal packet = new PacketFXSignal(PacketFXSignal.VisualFXType.BLOCK_BREAK, PacketFXSignal.SoundFXType.BLOCK_BREAK, pos, blockState);
|
||||
NetworkUtil.sendNetworkPacket(packet, pos, world);
|
||||
|
||||
@@ -62,7 +62,7 @@ public class FarmableAgingCrop implements IFarmable {
|
||||
}
|
||||
|
||||
IBlockState replantState = getReplantState(blockState);
|
||||
return new CropDestroy(world, blockState, pos, replantState);
|
||||
return new CropDestroy(world, blockState, pos, replantState, germling);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
|
||||
@@ -29,66 +29,66 @@ import forestry.core.utils.NetworkUtil;
|
||||
import forestry.farming.logic.crops.CropDestroy;
|
||||
|
||||
public class FarmableSapling implements IFarmable {
|
||||
protected final ItemStack germling;
|
||||
protected final boolean ignoreMetadata;
|
||||
protected final Block saplingBlock;
|
||||
protected final ItemStack[] windfall;
|
||||
protected final ItemStack germling;
|
||||
protected final boolean ignoreMetadata;
|
||||
protected final Block saplingBlock;
|
||||
protected final ItemStack[] windfall;
|
||||
|
||||
public FarmableSapling(final ItemStack germling, final ItemStack[] windfall) {
|
||||
this(germling, windfall, true);
|
||||
}
|
||||
public FarmableSapling(final ItemStack germling, final ItemStack[] windfall) {
|
||||
this(germling, windfall, true);
|
||||
}
|
||||
|
||||
public FarmableSapling(final ItemStack germling, final ItemStack[] windfall, boolean addSubItems) {
|
||||
this.germling = germling;
|
||||
this.windfall = windfall;
|
||||
this.saplingBlock = ItemStackUtil.getBlock(germling);
|
||||
this.ignoreMetadata = addSubItems;
|
||||
}
|
||||
public FarmableSapling(final ItemStack germling, final ItemStack[] windfall, boolean addSubItems) {
|
||||
this.germling = germling;
|
||||
this.windfall = windfall;
|
||||
this.saplingBlock = ItemStackUtil.getBlock(germling);
|
||||
this.ignoreMetadata = addSubItems;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean plantSaplingAt(EntityPlayer player, ItemStack germling, World world, BlockPos pos) {
|
||||
ItemStack copy = germling.copy();
|
||||
player.setHeldItem(EnumHand.MAIN_HAND, copy);
|
||||
EnumActionResult actionResult = copy.onItemUse(player, world, pos.down(), EnumHand.MAIN_HAND, EnumFacing.UP, 0, 0, 0);
|
||||
player.setHeldItem(EnumHand.MAIN_HAND, ItemStack.EMPTY);
|
||||
if (actionResult == EnumActionResult.SUCCESS) {
|
||||
PacketFXSignal packet = new PacketFXSignal(PacketFXSignal.SoundFXType.BLOCK_PLACE, pos, Blocks.SAPLING.getDefaultState());
|
||||
NetworkUtil.sendNetworkPacket(packet, pos, world);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@Override
|
||||
public boolean plantSaplingAt(EntityPlayer player, ItemStack germling, World world, BlockPos pos) {
|
||||
ItemStack copy = germling.copy();
|
||||
player.setHeldItem(EnumHand.MAIN_HAND, copy);
|
||||
EnumActionResult actionResult = copy.onItemUse(player, world, pos.down(), EnumHand.MAIN_HAND, EnumFacing.UP, 0, 0, 0);
|
||||
player.setHeldItem(EnumHand.MAIN_HAND, ItemStack.EMPTY);
|
||||
if (actionResult == EnumActionResult.SUCCESS) {
|
||||
PacketFXSignal packet = new PacketFXSignal(PacketFXSignal.SoundFXType.BLOCK_PLACE, pos, Blocks.SAPLING.getDefaultState());
|
||||
NetworkUtil.sendNetworkPacket(packet, pos, world);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSaplingAt(World world, BlockPos pos) {
|
||||
return world.getBlockState(pos).getBlock() == this.saplingBlock;
|
||||
}
|
||||
@Override
|
||||
public boolean isSaplingAt(World world, BlockPos pos) {
|
||||
return world.getBlockState(pos).getBlock() == this.saplingBlock;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ICrop getCropAt(World world, BlockPos pos, IBlockState blockState) {
|
||||
Block block = blockState.getBlock();
|
||||
if (!block.isWood(world, pos)) {
|
||||
return null;
|
||||
}
|
||||
@Override
|
||||
public ICrop getCropAt(World world, BlockPos pos, IBlockState blockState) {
|
||||
Block block = blockState.getBlock();
|
||||
if (!block.isWood(world, pos)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return new CropDestroy(world, blockState, pos, null);
|
||||
}
|
||||
return new CropDestroy(world, blockState, pos, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isGermling(ItemStack itemstack) {
|
||||
if (ignoreMetadata) {
|
||||
return ItemStack.areItemsEqual(germling, new ItemStack((itemstack.getItem())));
|
||||
}
|
||||
return ItemStack.areItemsEqual(germling, itemstack);
|
||||
}
|
||||
@Override
|
||||
public boolean isGermling(ItemStack itemstack) {
|
||||
if (ignoreMetadata) {
|
||||
return ItemStack.areItemsEqual(germling, new ItemStack((itemstack.getItem())));
|
||||
}
|
||||
return ItemStack.areItemsEqual(germling, itemstack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isWindfall(ItemStack itemstack) {
|
||||
for (ItemStack drop : windfall) {
|
||||
if (drop.isItemEqual(itemstack)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@Override
|
||||
public boolean isWindfall(ItemStack itemstack) {
|
||||
for (ItemStack drop : windfall) {
|
||||
if (drop.isItemEqual(itemstack)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -5,5 +5,6 @@ package forestry.farming.logic;
|
||||
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
|
||||
import forestry.core.utils.FieldsAreNonnullByDefault;
|
||||
import mcp.MethodsReturnNonnullByDefault;
|
||||
import mcp.MethodsReturnNonnullByDefault;
|
||||
|
||||
import forestry.core.utils.FieldsAreNonnullByDefault;
|
||||
@@ -30,8 +30,8 @@ import forestry.core.fluids.ITankManager;
|
||||
import forestry.core.inventory.FakeInventoryAdapter;
|
||||
import forestry.core.inventory.IInventoryAdapter;
|
||||
import forestry.core.multiblock.FakeMultiblockController;
|
||||
import forestry.farming.FarmRegistry;
|
||||
import forestry.farming.gui.IFarmLedgerDelegate;
|
||||
import forestry.farming.logic.FarmLogicArboreal;
|
||||
|
||||
public class FakeFarmController extends FakeMultiblockController implements IFarmControllerInternal {
|
||||
public static final FakeFarmController instance = new FakeFarmController();
|
||||
@@ -87,7 +87,7 @@ public class FakeFarmController extends FakeMultiblockController implements IFar
|
||||
|
||||
@Override
|
||||
public IFarmLogic getFarmLogic(FarmDirection direction) {
|
||||
return new FarmLogicArboreal();
|
||||
return FarmRegistry.getInstance().getFarm("farmArboreal").getLogic(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -74,9 +74,9 @@ import forestry.core.utils.Translator;
|
||||
import forestry.farming.FarmHelper;
|
||||
import forestry.farming.FarmHelper.FarmWorkStatus;
|
||||
import forestry.farming.FarmHelper.Stage;
|
||||
import forestry.farming.FarmRegistry;
|
||||
import forestry.farming.FarmTarget;
|
||||
import forestry.farming.gui.IFarmLedgerDelegate;
|
||||
import forestry.farming.logic.FarmLogicArboreal;
|
||||
import forestry.farming.tiles.TileFarmGearbox;
|
||||
import forestry.farming.tiles.TileFarmPlain;
|
||||
|
||||
@@ -630,7 +630,7 @@ public class FarmController extends RectangularMultiblockControllerBase implemen
|
||||
|
||||
@Override
|
||||
public void resetFarmLogic(FarmDirection direction) {
|
||||
setFarmLogic(direction, new FarmLogicArboreal());
|
||||
setFarmLogic(direction, FarmRegistry.getInstance().getFarm("farmArboreal").getLogic(false));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -16,6 +16,7 @@ import java.util.function.Consumer;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.properties.IProperty;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.init.Items;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
@@ -26,6 +27,8 @@ import forestry.api.circuits.ChipsetManager;
|
||||
import forestry.api.circuits.ICircuit;
|
||||
import forestry.api.circuits.ICircuitLayout;
|
||||
import forestry.api.core.ForestryAPI;
|
||||
import forestry.api.farming.IFarmInstance;
|
||||
import forestry.api.farming.IFarmRegistry;
|
||||
import forestry.api.modules.ForestryModule;
|
||||
import forestry.core.ModuleCore;
|
||||
import forestry.core.circuits.Circuits;
|
||||
@@ -61,17 +64,19 @@ public class PluginExtraUtilities extends BlankForestryModule {
|
||||
@Override
|
||||
public void doInit() {
|
||||
if (Config.isExUtilRedOrchidEnabled()) {
|
||||
registerExPlant("Orchid", "redorchid", "Red Orchid", Blocks.REDSTONE_ORE, circuit -> Circuits.farmOrchidManaged = circuit);
|
||||
registerExPlant("Orchid", "redorchid", "Red Orchid", circuit -> Circuits.farmOrchidManaged = circuit, Blocks.REDSTONE_ORE, Blocks.LIT_REDSTONE_ORE);
|
||||
}
|
||||
|
||||
if (Config.isExUtilEnderLilyEnabled()) {
|
||||
registerExPlant("Ender", "enderlilly", "Ender Lily", Blocks.END_STONE, circuit -> Circuits.farmEnderManaged = circuit);
|
||||
registerExPlant("Ender", "enderlilly", "Ender Lily", circuit -> Circuits.farmEnderManaged = circuit, Blocks.END_STONE);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerRecipes() {
|
||||
if (!ForestryAPI.enabledModules.contains(new ResourceLocation(Constants.MOD_ID, ForestryModuleUids.FARMING))) return;
|
||||
if (!ForestryAPI.enabledModules.contains(new ResourceLocation(Constants.MOD_ID, ForestryModuleUids.FARMING))) {
|
||||
return;
|
||||
}
|
||||
if(Circuits.farmEnderManaged != null) {
|
||||
ICircuitLayout layoutManaged = ChipsetManager.circuitRegistry.getLayout("forestry.farms.managed");
|
||||
ChipsetManager.solderManager.addRecipe(layoutManaged, ModuleCore.getItems().tubes.get(EnumElectronTube.ENDER, 1), Circuits.farmEnderManaged);
|
||||
@@ -82,22 +87,28 @@ public class PluginExtraUtilities extends BlankForestryModule {
|
||||
}
|
||||
}
|
||||
|
||||
private void registerExPlant(String id, String itemResourceName, String itemName, Block soil, Consumer<ICircuit> assignTo) {
|
||||
private void registerExPlant(String id, String itemResourceName, String itemName, Consumer<ICircuit> assignTo, Block... soils) {
|
||||
Block plantBlock = ForgeRegistries.BLOCKS.getValue(new ResourceLocation(ExU, itemResourceName));
|
||||
Item plantItem = Item.getItemFromBlock(plantBlock);
|
||||
if(plantBlock == Blocks.AIR) {
|
||||
Log.error("Could not find {} block.", itemName);
|
||||
} else if (plantItem == null) {
|
||||
} else if (plantItem == Items.AIR) {
|
||||
Log.error("Could not find {} item.", itemName);
|
||||
} else {
|
||||
IProperty<Integer> growthProperty = BlockUtil.getProperty(plantBlock, "growth", Integer.class);
|
||||
if (growthProperty == null) {
|
||||
Log.error("Could not find the growth property of {}.", itemName);
|
||||
} else {
|
||||
IFarmRegistry registry = FarmRegistry.getInstance();
|
||||
int harvestAge = Collections.max(growthProperty.getAllowedValues());
|
||||
int replantAge = plantBlock.getDefaultState().getValue(growthProperty);
|
||||
FarmRegistry.getInstance().registerFarmables(itemName, new FarmableAgingCrop(new ItemStack(plantItem), plantBlock, growthProperty, harvestAge, replantAge));
|
||||
assignTo.accept(new CircuitFarmLogic("managed" + id, new FarmLogicExU("Managed " + itemName + " Farm", plantItem, soil, itemName)));
|
||||
registry.registerFarmables(itemName, new FarmableAgingCrop(new ItemStack(plantItem), plantBlock, growthProperty, harvestAge, replantAge));
|
||||
|
||||
IFarmInstance instance = registry.registerLogic("farm" + id, (i, m) -> new FarmLogicExU(i, m, (m ? "Manual " : "Managed ") + itemName + " Farm", plantItem), itemName);
|
||||
for(Block soil : soils) {
|
||||
instance.registerSoil(new ItemStack(soil), soil.getDefaultState());
|
||||
}
|
||||
assignTo.accept(new CircuitFarmLogic("managed" + id, instance, false));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,6 +31,7 @@ import forestry.api.circuits.ChipsetManager;
|
||||
import forestry.api.circuits.CircuitSocketType;
|
||||
import forestry.api.circuits.ICircuitLayout;
|
||||
import forestry.api.core.ForestryAPI;
|
||||
import forestry.api.farming.IFarmInstance;
|
||||
import forestry.api.fuels.EngineBronzeFuel;
|
||||
import forestry.api.fuels.FuelManager;
|
||||
import forestry.api.modules.ForestryModule;
|
||||
@@ -116,7 +117,9 @@ public class PluginIC2 extends BlankForestryModule {
|
||||
rubber = IC2Items.getItem("crafting", "rubber");
|
||||
fertilizer = IC2Items.getItem("crop_res","fertilizer");
|
||||
|
||||
Circuits.farmRubberManual = new CircuitFarmLogic("manualRubber", new FarmLogicRubber());
|
||||
IFarmInstance rubberFarm = FarmRegistry.getInstance().registerLogic("farmRubber", FarmLogicRubber::new);
|
||||
|
||||
Circuits.farmRubberManual = new CircuitFarmLogic("manualRubber", rubberFarm, true);
|
||||
|
||||
ICircuitLayout layoutEngineTin = new CircuitLayout("engine.tin", CircuitSocketType.ELECTRIC_ENGINE);
|
||||
ChipsetManager.circuitRegistry.registerLayout(layoutEngineTin);
|
||||
|
||||
@@ -33,7 +33,7 @@ import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
||||
import net.minecraftforge.fml.common.registry.ForgeRegistries;
|
||||
|
||||
import forestry.api.core.ForestryAPI;
|
||||
import forestry.api.farming.IFarmLogic;
|
||||
import forestry.api.farming.IFarmInstance;
|
||||
import forestry.api.fuels.FuelManager;
|
||||
import forestry.api.fuels.MoistenerFuel;
|
||||
import forestry.api.modules.ForestryModule;
|
||||
@@ -266,8 +266,10 @@ public class PluginNatura extends BlankForestryModule {
|
||||
*/
|
||||
@Override
|
||||
public void postInit() {
|
||||
IFarmLogic farmArboreal = FarmRegistry.getInstance().getFarmLogic("farmArboreal");
|
||||
farmArboreal.addSoil(new ItemStack(Blocks.NETHERRACK), Blocks.NETHERRACK.getDefaultState(), false);
|
||||
IFarmInstance farmArboreal = FarmRegistry.getInstance().getFarm("managedArboreal");
|
||||
if(farmArboreal != null) {
|
||||
farmArboreal.registerSoil(new ItemStack(Blocks.NETHERRACK), Blocks.NETHERRACK.getDefaultState(), false);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user