mirror of
https://github.com/GTNewHorizons/ForestryMC.git
synced 2026-11-20 20:12:19 +00:00
Merge pull request #1948 from ForestryMC/farm
Reintroduce the old-style farm and Rebalance electron tubes
This commit is contained in:
172 files changed
+4237
-1202
No files matched your search
+1
-1
Submodule lang updated: 017b0be913...c560d52707.
@@ -7,11 +7,17 @@ package forestry.api.circuits;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.util.text.translation.I18n;
|
||||
|
||||
public interface ICircuit {
|
||||
String getUID();
|
||||
|
||||
String getUnlocalizedName();
|
||||
|
||||
default String getLocalizedName(){
|
||||
return I18n.translateToLocal(getUnlocalizedName());
|
||||
}
|
||||
|
||||
boolean isCircuitable(Object tile);
|
||||
|
||||
void onInsertion(int slot, Object tile);
|
||||
|
||||
@@ -5,14 +5,16 @@
|
||||
******************************************************************************/
|
||||
package forestry.api.farming;
|
||||
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import com.google.common.collect.HashMultimap;
|
||||
import com.google.common.collect.Multimap;
|
||||
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
//TODO: Remove this class in 1.13
|
||||
@Deprecated
|
||||
public class Farmables {
|
||||
/**
|
||||
* Can be used to add IFarmables to some of the vanilla farm logics.
|
||||
|
||||
@@ -5,12 +5,14 @@
|
||||
******************************************************************************/
|
||||
package forestry.api.farming;
|
||||
|
||||
import forestry.api.core.IErrorLogicSource;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.Vec3i;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
|
||||
import forestry.api.core.IErrorLogicSource;
|
||||
|
||||
public interface IFarmHousing extends IErrorLogicSource {
|
||||
|
||||
BlockPos getCoords();
|
||||
@@ -33,10 +35,36 @@ public interface IFarmHousing extends IErrorLogicSource {
|
||||
* Will remove the appropriate germling from the farm's inventory.
|
||||
* It's up to the logic to only call this on a valid location.
|
||||
*
|
||||
* @deprecated TODO remove this method in 1.13
|
||||
*
|
||||
* @return true if planting was successful, false otherwise.
|
||||
*/
|
||||
@Deprecated
|
||||
boolean plantGermling(IFarmable farmable, World world, BlockPos pos);
|
||||
|
||||
/**
|
||||
* Callback for {@link IFarmLogic}s to plant a sapling, seed, germling, stem.
|
||||
* Will remove the appropriate germling from the farm's inventory.
|
||||
* It's up to the logic to only call this on a valid location.
|
||||
*
|
||||
* @return true if planting was successful, false otherwise.
|
||||
*/
|
||||
default boolean plantGermling(IFarmable farmable, World world, BlockPos pos, FarmDirection direction){
|
||||
return plantGermling(farmable, world, pos);
|
||||
}
|
||||
|
||||
default boolean isValidPlatform(World world, BlockPos pos){
|
||||
return false;
|
||||
}
|
||||
|
||||
default boolean isSquare(){
|
||||
return false;
|
||||
}
|
||||
|
||||
default boolean canPlantSoil(boolean manual){
|
||||
return true;
|
||||
}
|
||||
|
||||
/* INTERACTION WITH HATCHES */
|
||||
IFarmInventory getFarmInventory();
|
||||
|
||||
|
||||
@@ -27,4 +27,6 @@ public interface IFarmInventory {
|
||||
IInventory getResourcesInventory();
|
||||
|
||||
IInventory getFertilizerInventory();
|
||||
|
||||
|
||||
}
|
||||
@@ -8,39 +8,136 @@ 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;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
import forestry.api.core.ForestryAPI;
|
||||
|
||||
/**
|
||||
* The IFarmLogic is used by farm blocks and multi-blocks to cultivate and harvest crops and plants.
|
||||
*
|
||||
* Every farm block has only ony one logic a multi-block farm has four, one for every direction.
|
||||
*/
|
||||
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();
|
||||
|
||||
/**
|
||||
* @param hydrationModifier A modifier that depends on the weather and the biome of the farm.
|
||||
*
|
||||
* @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);
|
||||
|
||||
/**
|
||||
* Checks if the given stack is a resource or a soil that this logic uses to grow plants on or to create other
|
||||
* products like peat.
|
||||
*/
|
||||
boolean isAcceptedResource(ItemStack itemstack);
|
||||
|
||||
/**
|
||||
* Checks if the given stack is a germling (plantable sapling, seed, etc.) for any {@link IFarmable} of this farm.
|
||||
*/
|
||||
boolean isAcceptedGermling(ItemStack itemstack);
|
||||
|
||||
/**
|
||||
* Collects all items that are laying on the ground and are in the {@link IFarmHousing#getArea()} of the farm.
|
||||
*
|
||||
* @param world The world of the farm.
|
||||
* @param farmHousing The farm that uses this logic.
|
||||
*
|
||||
* @return A collection that contains all items that were collected.
|
||||
*/
|
||||
NonNullList<ItemStack> collect(World world, IFarmHousing farmHousing);
|
||||
|
||||
/**
|
||||
* Tries to cultivate one or more blocks at the given position and with the given extent.
|
||||
*
|
||||
* @param world The world of the farm.
|
||||
* @param farmHousing The farm that uses this logic.
|
||||
* @param pos The position at that the logic should start to cultivate.
|
||||
* @param direction The direction of the extension.
|
||||
* @param extent How many blocks this logic has to cultivate after it cultivated the block at the given position.
|
||||
* The positions of the next blocks are having a offset in the given direction.
|
||||
* @return True if the logic has cultivated any block.
|
||||
*/
|
||||
boolean cultivate(World world, IFarmHousing farmHousing, BlockPos pos, FarmDirection direction, int extent);
|
||||
|
||||
/**
|
||||
* Tries to harvest one or more blocks at the given position and with the given extent.
|
||||
*
|
||||
* @param world The world of the farm.
|
||||
* @param pos The position at that the logic should start to harvest.
|
||||
* @param direction The direction of the extension.
|
||||
* @param extent How many blocks this logic tries to harvest after it has tried to harvested the block at the given position.
|
||||
* The positions of the next blocks are having a offset in the given direction.
|
||||
* @return True if the logic has cultivated any block.
|
||||
*/
|
||||
Collection<ICrop> harvest(World world, BlockPos pos, FarmDirection direction, int extent);
|
||||
|
||||
IFarmLogic setManual(boolean manual);
|
||||
/**
|
||||
* Returns the {@link IFarmProperties} that created this logic.
|
||||
*
|
||||
* @since Forestry 5.8
|
||||
*
|
||||
* @return Returns the {@link IFarmProperties} that created this logic. Returns a fake instance from
|
||||
* {@link IFarmRegistry#createFakeInstance(IFarmLogic)} if the logic is older that Forestry 5.8.
|
||||
* TODO: Remove "default" from this method in 1.13
|
||||
*/
|
||||
default IFarmProperties getProperties(){
|
||||
return ForestryAPI.farmRegistry.createFakeInstance(this);
|
||||
}
|
||||
|
||||
void addSoil(ItemStack resource, IBlockState soilState, boolean hasMetaData);
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
ResourceLocation getTextureMap();
|
||||
/**
|
||||
* @deprecated Since Forestry 5.8 logic instances are created at the constructor of the {@link IFarmProperties} and
|
||||
* have a immutable manual state. TODO Remove this method in 1.13
|
||||
*/
|
||||
@Deprecated
|
||||
default IFarmLogic setManual(boolean manual){
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Use {@link IFarmRegistry#getProperties(String)} to get the {@link IFarmProperties} for the farm logic and register the soil
|
||||
* with {@link IFarmProperties#registerSoil(ItemStack, IBlockState, boolean)}.
|
||||
*/
|
||||
@Deprecated
|
||||
default void addSoil(ItemStack resource, IBlockState soilState, boolean hasMetaData){
|
||||
//
|
||||
}
|
||||
|
||||
default String getUnlocalizedName(){
|
||||
return "";
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Localized short, human-readable identifier used in the farm gui and in tooltips.
|
||||
*/
|
||||
String getName();
|
||||
|
||||
/* GUI ONLY */
|
||||
/**
|
||||
* @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)
|
||||
default ResourceLocation getTextureMap(){
|
||||
return TextureMap.LOCATION_BLOCKS_TEXTURE;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the itemStack that represents this farm logic. Used as an icon for the farm logic.
|
||||
*/
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
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 IFarmProperties {
|
||||
|
||||
/**
|
||||
* Can be used to register a {@link IBlockState} as a valid soil.
|
||||
*/
|
||||
default void registerSoil(ItemStack resource, IBlockState soilState){
|
||||
registerSoil(resource, soilState, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Can be used to register a {@link IBlockState} as a valid soil.
|
||||
*/
|
||||
void registerSoil(ItemStack resource, IBlockState soilState, boolean hasMetaData);
|
||||
|
||||
/**
|
||||
* Adds the {@link IFarmable}s that where registered with the given identifier.
|
||||
*/
|
||||
void registerFarmables(String identifier);
|
||||
|
||||
/**
|
||||
* @return true if the given block state is a valid soil state.
|
||||
*/
|
||||
boolean isAcceptedSoil(IBlockState blockState);
|
||||
|
||||
/**
|
||||
* @return true if the given stack is the {@link ItemStack} of a soil.
|
||||
*/
|
||||
boolean isAcceptedResource(ItemStack itemStack);
|
||||
|
||||
Collection<ISoil> getSoils();
|
||||
|
||||
Collection<IFarmable> getFarmables();
|
||||
|
||||
/**
|
||||
* Returns the instance of the manual or managed {@link IFarmLogic}.
|
||||
*/
|
||||
IFarmLogic getLogic(boolean manuel);
|
||||
}
|
||||
@@ -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;
|
||||
|
||||
@@ -14,15 +15,35 @@ public interface IFarmRegistry {
|
||||
|
||||
/**
|
||||
* Registers farming logic in registry under given identifier
|
||||
* @param identifier Valid identifiers: farmArboreal farmWheat farmGourd farmInfernal farmPoales farmSucculentes farmVegetables farmShroom
|
||||
* @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(String, IFarmProperties)}.
|
||||
*/
|
||||
void registerFarmLogic(String identifier, IFarmLogic logic);
|
||||
|
||||
@Deprecated
|
||||
void registerLogic(String identifier, IFarmLogic logic);
|
||||
|
||||
/**
|
||||
* Registers farming logic in registry
|
||||
* @since Forestry 5.8
|
||||
*/
|
||||
IFarmProperties registerLogic(String identifier, IFarmProperties 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
|
||||
*/
|
||||
IFarmProperties registerLogic(String identifier, BiFunction<IFarmProperties, Boolean, IFarmLogic> logicFactory, String... farmablesIdentifiers);
|
||||
|
||||
/**
|
||||
* Can be used to add IFarmables to some of the vanilla farm logics.
|
||||
* <p>
|
||||
* Identifiers: farmArboreal farmWheat farmGourd farmInfernal farmPoales farmSucculentes farmVegetables farmShroom
|
||||
* Identifiers: farmArboreal farmCrops farmGourd farmInfernal farmPoales farmSucculentes farmShroom
|
||||
*/
|
||||
void registerFarmables(String identifier, IFarmable... farmable);
|
||||
|
||||
@@ -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(IFarmProperties, 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,28 @@ public interface IFarmRegistry {
|
||||
* @return The value of the fertitlizer
|
||||
*/
|
||||
int getFertilizeValue(ItemStack itemStack);
|
||||
|
||||
/**
|
||||
* Returns a fake {@link IFarmProperties} that returns the given logic at {@link IFarmProperties#getLogic(boolean)}.
|
||||
*
|
||||
* @since Forestry 5.8
|
||||
* @deprecated Only for backwards comparability.
|
||||
*/
|
||||
@Deprecated
|
||||
IFarmProperties 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(IFarmProperties instance, boolean isManual, ISimpleFarmLogic simpleFarmLogic);
|
||||
|
||||
/**
|
||||
* @since Forestry 5.8
|
||||
*/
|
||||
@Nullable
|
||||
IFarmProperties getProperties(String identifier);
|
||||
|
||||
}
|
||||
@@ -20,8 +20,19 @@ public interface IFarmable {
|
||||
|
||||
/**
|
||||
* @return true if the block at the given location is a "sapling" for this type, i.e. a non-harvestable immature version of the crop.
|
||||
* @deprecated Since Forestry 5.8. Use the version below. TODO Remove this method in 1.13
|
||||
*/
|
||||
boolean isSaplingAt(World world, BlockPos pos);
|
||||
@Deprecated
|
||||
default boolean isSaplingAt(World world, BlockPos pos){
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return true if the block at the given location is a "sapling" for this type, i.e. a non-harvestable immature version of the crop.
|
||||
*/
|
||||
default boolean isSaplingAt(World world, BlockPos pos, IBlockState blockState){
|
||||
return isSaplingAt(world, pos);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return {@link ICrop} if the block at the given location is a harvestable and mature crop, null otherwise.
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
@@ -5,10 +5,11 @@
|
||||
******************************************************************************/
|
||||
@ParametersAreNonnullByDefault
|
||||
@MethodsReturnNonnullByDefault
|
||||
@API(apiVersion = "2.2.0", owner = "ForestryAPI|core", provides = "ForestryAPI|farming")
|
||||
@API(apiVersion = "5.8.0", owner = "ForestryAPI|core", provides = "ForestryAPI|farming")
|
||||
package forestry.api.farming;
|
||||
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
|
||||
import mcp.MethodsReturnNonnullByDefault;
|
||||
|
||||
import net.minecraftforge.fml.common.API;
|
||||
@@ -20,6 +20,7 @@ import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.particle.ParticleManager;
|
||||
import net.minecraft.client.renderer.texture.TextureMap;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.item.Item;
|
||||
@@ -40,8 +41,11 @@ import net.minecraft.util.math.Vec3d;
|
||||
import net.minecraft.world.IBlockAccess;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import com.mojang.authlib.GameProfile;
|
||||
|
||||
import net.minecraftforge.client.model.ModelLoader;
|
||||
import net.minecraftforge.fluids.FluidUtil;
|
||||
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
@@ -51,6 +55,8 @@ import forestry.api.core.ISpriteRegister;
|
||||
import forestry.api.core.IStateMapperRegister;
|
||||
import forestry.api.core.ITextureManager;
|
||||
import forestry.core.circuits.ISocketable;
|
||||
import forestry.core.owner.IOwnedTile;
|
||||
import forestry.core.owner.IOwnerHandler;
|
||||
import forestry.core.render.MachineParticleCallback;
|
||||
import forestry.core.render.MachineStateMapper;
|
||||
import forestry.core.render.ParticleHelper;
|
||||
@@ -70,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);
|
||||
@@ -82,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);
|
||||
}
|
||||
@@ -212,6 +215,22 @@ public class BlockBase<P extends Enum<P> & IBlockType & IStringSerializable> ext
|
||||
super.breakBlock(world, pos, state);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBlockPlacedBy(World world, BlockPos pos, IBlockState state, EntityLivingBase placer, ItemStack stack) {
|
||||
if (world.isRemote) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (placer instanceof EntityPlayer) {
|
||||
TileUtil.actOnTile(world, pos, IOwnedTile.class, tile -> {
|
||||
IOwnerHandler ownerHandler = tile.getOwnerHandler();
|
||||
EntityPlayer player = (EntityPlayer) placer;
|
||||
GameProfile gameProfile = player.getGameProfile();
|
||||
ownerHandler.setOwner(gameProfile);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public void init() {
|
||||
blockType.getMachineProperties().registerTileEntity();
|
||||
}
|
||||
|
||||
@@ -37,7 +37,7 @@ public abstract class Circuit implements ICircuit {
|
||||
|
||||
@Override
|
||||
public void addTooltip(List<String> list) {
|
||||
list.add(Translator.translateToLocal(getUnlocalizedName()));
|
||||
list.add(getLocalizedName());
|
||||
|
||||
int i = 1;
|
||||
while (true) {
|
||||
|
||||
@@ -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,31 +8,39 @@ 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 farmCerealManaged;
|
||||
public static ICircuit farmVegetableManaged;
|
||||
public static ICircuit farmCropsManaged;
|
||||
public static ICircuit farmPeatManaged;
|
||||
public static ICircuit farmSucculentManaged;
|
||||
public static ICircuit farmPoaleManaged;
|
||||
public static ICircuit farmFungal;
|
||||
public static ICircuit farmPoalesManaged;
|
||||
public static ICircuit farmInfernalManaged;
|
||||
public static ICircuit farmEnderManaged;
|
||||
public static ICircuit farmOrchidManaged;
|
||||
public static ICircuit farmGourdManaged;
|
||||
public static ICircuit farmCocoaManaged;
|
||||
|
||||
|
||||
public static ICircuit farmArborealManual;
|
||||
public static ICircuit farmOrchardManual;
|
||||
public static ICircuit farmShroomManual;
|
||||
public static ICircuit farmCerealManual;
|
||||
public static ICircuit farmVegetableManual;
|
||||
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;
|
||||
|
||||
@@ -53,7 +53,7 @@ public class GuiSolderingIron extends GuiForestry<ContainerSolderingIron> {
|
||||
if (recipe == null) {
|
||||
description = "(" + Translator.translateToLocal("for.gui.noeffect") + ")";
|
||||
} else {
|
||||
description = Translator.translateToLocal(recipe.getCircuit().getUnlocalizedName());
|
||||
description = recipe.getCircuit().getLocalizedName();
|
||||
}
|
||||
|
||||
int row = i * 20;
|
||||
|
||||
@@ -99,11 +99,17 @@ public class Config {
|
||||
|
||||
// Farm
|
||||
public static int farmSize = 2;
|
||||
public static float fertilizerModifier = 1.0F;
|
||||
public static boolean squareFarms = false;
|
||||
private static boolean enableExUtilEnderLily = true;
|
||||
private static boolean enableExUtilRedOrchid = true;
|
||||
private static boolean enableMagicalCropsSupport = true;
|
||||
|
||||
// Cultivation
|
||||
public static int planterExtend = 4;
|
||||
public static boolean ringFarms = true;
|
||||
public static int ringSize = 4;
|
||||
|
||||
// Mail
|
||||
public static boolean mailAlertEnabled = true;
|
||||
public static GuiMailboxInfo.XPosition mailAlertXPosition = GuiMailboxInfo.XPosition.LEFT;
|
||||
@@ -278,11 +284,16 @@ public class Config {
|
||||
}
|
||||
|
||||
farmSize = configCommon.getIntLocalized("tweaks.farms", "size", farmSize, 1, 3);
|
||||
fertilizerModifier = configCommon.getFloatLocalized("tweaks.farms", "fertilizer", fertilizerModifier, 0.1F, 5.0F);
|
||||
squareFarms = configCommon.getBooleanLocalized("tweaks.farms", "square", squareFarms);
|
||||
enableExUtilEnderLily = configCommon.getBooleanLocalized("tweaks.farms", "enderlily", enableExUtilEnderLily);
|
||||
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);
|
||||
|
||||
@@ -30,6 +30,7 @@ import forestry.core.items.ItemSolderingIron;
|
||||
import forestry.core.tiles.TileAnalyzer;
|
||||
import forestry.core.tiles.TileEscritoire;
|
||||
import forestry.core.tiles.TileNaturalistChest;
|
||||
import forestry.cultivation.tiles.TilePlanter;
|
||||
import forestry.database.tiles.TileDatabase;
|
||||
import forestry.energy.tiles.TileEngineBiogas;
|
||||
import forestry.energy.tiles.TileEngineElectric;
|
||||
@@ -101,6 +102,9 @@ public class GuiIdRegistry {
|
||||
//Sorting Module
|
||||
TileGeneticFilter.class,
|
||||
|
||||
//Cultivation Module
|
||||
TilePlanter.class,
|
||||
|
||||
//Greenhouse Module
|
||||
TileGreenhouse.class,
|
||||
TileClimatiser.class,
|
||||
|
||||
@@ -55,6 +55,7 @@ public class ItemRegistryCore extends ItemRegistry {
|
||||
public final ItemForestry sturdyCasing;
|
||||
public final ItemForestry hardenedCasing;
|
||||
public final ItemForestry impregnatedCasing;
|
||||
public final ItemForestry flexibleCasing;
|
||||
public final ItemStack gearBronze;
|
||||
public final ItemStack gearCopper;
|
||||
public final ItemStack gearTin;
|
||||
@@ -110,6 +111,7 @@ public class ItemRegistryCore extends ItemRegistry {
|
||||
sturdyCasing = registerItem(new ItemForestry(), "sturdy_machine");
|
||||
hardenedCasing = registerItem(new ItemForestry(), "hardened_machine");
|
||||
impregnatedCasing = registerItem(new ItemForestry(), "impregnated_casing");
|
||||
flexibleCasing = registerItem(new ItemForestry(), "flexible_casing");
|
||||
|
||||
craftingMaterial = registerItem(new ItemCraftingMaterial(), "crafting_material");
|
||||
|
||||
|
||||
@@ -12,6 +12,12 @@ package forestry.core.network.packets;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
import forestry.api.core.ILocatable;
|
||||
import forestry.core.network.ForestryPacket;
|
||||
import forestry.core.network.IForestryPacketClient;
|
||||
@@ -20,10 +26,6 @@ import forestry.core.network.IStreamableGui;
|
||||
import forestry.core.network.PacketBufferForestry;
|
||||
import forestry.core.network.PacketIdClient;
|
||||
import forestry.core.tiles.TileUtil;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
public class PacketGuiUpdate extends ForestryPacket implements IForestryPacketClient {
|
||||
private final BlockPos pos;
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package forestry.core.render;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.particle.Particle;
|
||||
@@ -157,6 +158,26 @@ public class ParticleRender {
|
||||
effectRenderer.addEffect(particle);
|
||||
}
|
||||
}
|
||||
|
||||
public static void addPortalFx(World world, BlockPos pos, Random rand){
|
||||
if (!shouldSpawnParticle(world)) {
|
||||
return;
|
||||
}
|
||||
|
||||
int j = rand.nextInt(2) * 2 - 1;
|
||||
int k = rand.nextInt(2) * 2 - 1;
|
||||
double xPos = (double)pos.getX() + 0.5D + 0.25D * (double)j;
|
||||
double yPos = (double)((float)pos.getY() + rand.nextFloat());
|
||||
double zPos = (double)pos.getZ() + 0.5D + 0.25D * (double)k;
|
||||
double xSpeed = (double)(rand.nextFloat() * (float)j);
|
||||
double ySpeed = ((double)rand.nextFloat() - 0.5D) * 0.125D;
|
||||
double zSpeed = (double)(rand.nextFloat() * (float)k);
|
||||
ParticleManager effectRenderer = Minecraft.getMinecraft().effectRenderer;
|
||||
Particle particle = effectRenderer.spawnEffectParticle(EnumParticleTypes.PORTAL.getParticleID(), xPos, yPos, zPos, xSpeed, ySpeed, zSpeed);
|
||||
if(particle != null){
|
||||
effectRenderer.addEffect(particle);
|
||||
}
|
||||
}
|
||||
|
||||
public static void addEntityBiodustFX(World world, double x, double y, double z){
|
||||
if (!shouldSpawnParticle(world)) {
|
||||
|
||||
@@ -78,4 +78,6 @@ public class OreDictUtil {
|
||||
public static final String DYE_YELLOW = "dyeYellow";
|
||||
public static final String DYE_BLUE = "dyeBlue";
|
||||
public static final String DYE_RED = "dyeRed";
|
||||
|
||||
public static final String SLIMEBALL = "slimeball";
|
||||
}
|
||||
@@ -10,11 +10,12 @@
|
||||
******************************************************************************/
|
||||
package forestry.core.utils;
|
||||
|
||||
import com.google.common.collect.AbstractIterator;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.Iterator;
|
||||
import java.util.Random;
|
||||
|
||||
import com.google.common.collect.AbstractIterator;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.Vec3i;
|
||||
|
||||
@@ -0,0 +1,132 @@
|
||||
package forestry.cultivation;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.Set;
|
||||
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
|
||||
import forestry.api.modules.ForestryModule;
|
||||
import forestry.core.ModuleCore;
|
||||
import forestry.core.circuits.EnumCircuitBoardType;
|
||||
import forestry.core.config.Constants;
|
||||
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;
|
||||
|
||||
@ForestryModule(containerID = Constants.MOD_ID, moduleID = ForestryModuleUids.CULTIVATION, name = "Cultivation", author = "Nedelosk", url = Constants.URL, unlocalizedDescription = "for.module.cultivation.description")
|
||||
public class ModuleCultivation extends BlankForestryModule {
|
||||
@Nullable
|
||||
private static BlockRegistryCultivation blocks;
|
||||
|
||||
public static BlockRegistryCultivation getBlocks() {
|
||||
Preconditions.checkState(blocks != null);
|
||||
return blocks;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerItemsAndBlocks() {
|
||||
blocks = new BlockRegistryCultivation();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<ResourceLocation> getDependencyUids() {
|
||||
return ImmutableSet.of(new ResourceLocation(Constants.MOD_ID, ForestryModuleUids.CORE),
|
||||
new ResourceLocation(Constants.MOD_ID, ForestryModuleUids.FARMING));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void doInit() {
|
||||
BlockRegistryCultivation blocks = getBlocks();
|
||||
|
||||
blocks.arboretum.init();
|
||||
blocks.farmCrops.init();
|
||||
blocks.farmMushroom.init();
|
||||
blocks.farmNether.init();
|
||||
blocks.farmGourd.init();
|
||||
blocks.farmEnder.init();
|
||||
//blocks.plantation.init();
|
||||
blocks.peatBog.init();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerRecipes() {
|
||||
BlockRegistryCultivation blocks = getBlocks();
|
||||
ItemRegistryCore coreItems = ModuleCore.getItems();
|
||||
|
||||
RecipeUtil.addRecipe("arboretum", blocks.arboretum,
|
||||
"GTG",
|
||||
"TCT",
|
||||
"GBG",
|
||||
'G', OreDictUtil.BLOCK_GLASS,
|
||||
'T', coreItems.tubes.get(EnumElectronTube.GOLD, 1),
|
||||
'C', coreItems.flexibleCasing,
|
||||
'B', coreItems.circuitboards.get(EnumCircuitBoardType.BASIC));
|
||||
|
||||
RecipeUtil.addRecipe("farm_crops", blocks.farmCrops,
|
||||
"GTG",
|
||||
"TCT",
|
||||
"GBG",
|
||||
'G', OreDictUtil.BLOCK_GLASS,
|
||||
'T', coreItems.tubes.get(EnumElectronTube.BRONZE, 1),
|
||||
'C', coreItems.flexibleCasing,
|
||||
'B', coreItems.circuitboards.get(EnumCircuitBoardType.BASIC));
|
||||
|
||||
RecipeUtil.addRecipe("peat_bog", blocks.peatBog,
|
||||
"GTG",
|
||||
"TCT",
|
||||
"GBG",
|
||||
'G', OreDictUtil.BLOCK_GLASS,
|
||||
'T', coreItems.tubes.get(EnumElectronTube.OBSIDIAN, 1),
|
||||
'C', coreItems.flexibleCasing,
|
||||
'B', coreItems.circuitboards.get(EnumCircuitBoardType.BASIC));
|
||||
|
||||
RecipeUtil.addRecipe("farm_mushroom", blocks.farmMushroom,
|
||||
"GTG",
|
||||
"TCT",
|
||||
"GBG",
|
||||
'G', OreDictUtil.BLOCK_GLASS,
|
||||
'T', coreItems.tubes.get(EnumElectronTube.APATITE, 1),
|
||||
'C', coreItems.flexibleCasing,
|
||||
'B', coreItems.circuitboards.get(EnumCircuitBoardType.BASIC));
|
||||
|
||||
RecipeUtil.addRecipe("farm_gourd", blocks.farmGourd,
|
||||
"GTG",
|
||||
"TCT",
|
||||
"GBG",
|
||||
'G', OreDictUtil.BLOCK_GLASS,
|
||||
'T', coreItems.tubes.get(EnumElectronTube.LAPIS, 1),
|
||||
'C', coreItems.flexibleCasing,
|
||||
'B', coreItems.circuitboards.get(EnumCircuitBoardType.BASIC));
|
||||
|
||||
RecipeUtil.addRecipe("farm_nether", blocks.farmNether,
|
||||
"GTG",
|
||||
"TCT",
|
||||
"GBG",
|
||||
'G', OreDictUtil.BLOCK_GLASS,
|
||||
'T', coreItems.tubes.get(EnumElectronTube.BLAZE, 1),
|
||||
'C', coreItems.flexibleCasing,
|
||||
'B', coreItems.circuitboards.get(EnumCircuitBoardType.BASIC));
|
||||
|
||||
RecipeUtil.addRecipe("farm_ender", blocks.farmEnder,
|
||||
"GTG",
|
||||
"TCT",
|
||||
"GBG",
|
||||
'G', OreDictUtil.BLOCK_GLASS,
|
||||
'T', coreItems.tubes.get(EnumElectronTube.ENDER, 1),
|
||||
'C', coreItems.flexibleCasing,
|
||||
'B', coreItems.circuitboards.get(EnumCircuitBoardType.BASIC));
|
||||
|
||||
for(BlockPlanter planter : getBlocks().getPlanters()){
|
||||
RecipeUtil.addShapelessRecipe(planter.blockType.getName() + "_manual_managed", planter.get(true), planter.get(false));
|
||||
RecipeUtil.addShapelessRecipe(planter.blockType.getName() + "_managed_manual", planter.get(false), planter.get(true));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,112 @@
|
||||
package forestry.cultivation.blocks;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
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.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.core.render.ParticleRender;
|
||||
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);
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
@Override
|
||||
public void randomDisplayTick(IBlockState stateIn, World worldIn, BlockPos pos, Random rand) {
|
||||
if(blockType == BlockTypePlanter.FARM_ENDER){
|
||||
for (int i = 0; i < 3; ++i) {
|
||||
ParticleRender.addPortalFx(worldIn, pos, rand);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@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
|
||||
public int damageDropped(IBlockState state) {
|
||||
return state.getValue(MANUAL) ? 1 : 0;
|
||||
}
|
||||
|
||||
@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){
|
||||
return stack.getMetadata() == 1;
|
||||
}
|
||||
|
||||
public ItemStack get(boolean isManual){
|
||||
return new ItemStack(this, 1, isManual ? 1 : 0);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
package forestry.cultivation.blocks;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import forestry.core.blocks.BlockRegistry;
|
||||
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;
|
||||
public final BlockPlanter farmGourd;
|
||||
public final BlockPlanter farmNether;
|
||||
public final BlockPlanter farmEnder;
|
||||
public final BlockPlanter peatBog;
|
||||
/*public final BlockPlanter plantation;*/
|
||||
|
||||
public BlockRegistryCultivation() {
|
||||
arboretum = new BlockPlanter(BlockTypePlanter.ARBORETUM);
|
||||
registerBlock(arboretum, new ItemBlockPlanter(arboretum), "arboretum");
|
||||
planters.add(arboretum);
|
||||
|
||||
farmCrops = new BlockPlanter(BlockTypePlanter.FARM_CROPS);
|
||||
registerBlock(farmCrops, new ItemBlockPlanter(farmCrops), "farm_crops");
|
||||
planters.add(farmCrops);
|
||||
|
||||
farmMushroom = new BlockPlanter(BlockTypePlanter.FARM_MUSHROOM);
|
||||
registerBlock(farmMushroom, new ItemBlockPlanter(farmMushroom), "farm_mushroom");
|
||||
planters.add(farmMushroom);
|
||||
|
||||
farmGourd = new BlockPlanter(BlockTypePlanter.FARM_GOURD);
|
||||
registerBlock(farmGourd, new ItemBlockPlanter(farmGourd), "farm_gourd");
|
||||
planters.add(farmGourd);
|
||||
|
||||
farmNether = new BlockPlanter(BlockTypePlanter.FARM_NETHER);
|
||||
registerBlock(farmNether, new ItemBlockPlanter(farmNether), "farm_nether");
|
||||
planters.add(farmNether);
|
||||
|
||||
farmEnder = new BlockPlanter(BlockTypePlanter.FARM_ENDER);
|
||||
registerBlock(farmEnder, new ItemBlockPlanter(farmEnder), "farm_ender");
|
||||
planters.add(farmEnder);
|
||||
|
||||
peatBog = new BlockPlanter(BlockTypePlanter.PEAT_POG);
|
||||
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,41 @@
|
||||
package forestry.cultivation.blocks;
|
||||
|
||||
import forestry.core.blocks.IBlockTypeCustom;
|
||||
import forestry.core.blocks.IMachineProperties;
|
||||
import forestry.cultivation.tiles.TileArboretum;
|
||||
import forestry.cultivation.tiles.TileBog;
|
||||
import forestry.cultivation.tiles.TileFarmCrops;
|
||||
import forestry.cultivation.tiles.TileFarmEnder;
|
||||
import forestry.cultivation.tiles.TileFarmGourd;
|
||||
import forestry.cultivation.tiles.TileFarmMushroom;
|
||||
import forestry.cultivation.tiles.TileFarmNether;
|
||||
import forestry.cultivation.tiles.TilePlanter;
|
||||
|
||||
public enum BlockTypePlanter implements IBlockTypeCustom {
|
||||
ARBORETUM(TileArboretum.class, "arboretum"),
|
||||
FARM_CROPS(TileFarmCrops.class, "farm_crop"),
|
||||
FARM_MUSHROOM(TileFarmMushroom.class, "farm_mushroom"),
|
||||
FARM_GOURD(TileFarmGourd.class, "farm_gourd"),
|
||||
FARM_NETHER(TileFarmNether.class, "farm_nether"),
|
||||
FARM_ENDER(TileFarmEnder.class, "farm_ender"),
|
||||
PEAT_POG(TileBog.class, "peat_bog"),
|
||||
|
||||
//TODO Add ic2 integration
|
||||
/*PLANTATION(TilePlantation.class, "plantation")*/;
|
||||
|
||||
private final IMachineProperties machineProperties;
|
||||
|
||||
BlockTypePlanter(Class<? extends TilePlanter> teClass, String name) {
|
||||
this.machineProperties = new PlanterProperties<>(teClass, name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IMachineProperties getMachineProperties() {
|
||||
return machineProperties;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return getMachineProperties().getName();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package forestry.cultivation.blocks;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
|
||||
import forestry.api.core.IModelManager;
|
||||
import forestry.core.blocks.MachineProperties;
|
||||
import forestry.core.utils.ItemStackUtil;
|
||||
import forestry.cultivation.tiles.TilePlanter;
|
||||
|
||||
public class PlanterProperties<T extends TilePlanter> extends MachineProperties<T> {
|
||||
|
||||
PlanterProperties(Class<T> teClass, String name) {
|
||||
super(teClass, name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerModel(Item item, IModelManager manager) {
|
||||
ResourceLocation itemNameFromRegistry = ItemStackUtil.getItemNameFromRegistry(item);
|
||||
Preconditions.checkNotNull(itemNameFromRegistry, "No registry name for item");
|
||||
String identifier = itemNameFromRegistry.getResourcePath();
|
||||
manager.registerItemModel(item, 0, identifier);
|
||||
manager.registerItemModel(item, 1, identifier);
|
||||
}
|
||||
}
|
||||
@@ -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,10 @@
|
||||
@ParametersAreNonnullByDefault
|
||||
@FieldsAreNonnullByDefault
|
||||
@MethodsReturnNonnullByDefault
|
||||
package forestry.cultivation.blocks;
|
||||
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
|
||||
import mcp.MethodsReturnNonnullByDefault;
|
||||
|
||||
import forestry.core.utils.FieldsAreNonnullByDefault;
|
||||
@@ -0,0 +1,50 @@
|
||||
package forestry.cultivation.gui;
|
||||
|
||||
import net.minecraft.entity.player.InventoryPlayer;
|
||||
|
||||
import forestry.core.gui.ContainerLiquidTanks;
|
||||
import forestry.core.gui.slots.SlotFiltered;
|
||||
import forestry.core.gui.slots.SlotLiquidIn;
|
||||
import forestry.core.gui.slots.SlotOutput;
|
||||
import forestry.core.network.packets.PacketGuiUpdate;
|
||||
import forestry.cultivation.inventory.InventoryPlanter;
|
||||
import forestry.cultivation.tiles.TilePlanter;
|
||||
|
||||
public class ContainerPlanter extends ContainerLiquidTanks<TilePlanter> {
|
||||
public ContainerPlanter(TilePlanter tileForestry, InventoryPlayer playerInventory) {
|
||||
super(tileForestry, playerInventory, 21, 110);
|
||||
|
||||
// Resources
|
||||
for (int i = 0; i < 2; i++) {
|
||||
for (int j = 0; j < 2; j++) {
|
||||
addSlotToContainer(new SlotFiltered(tile.getInternalInventory(), InventoryPlanter.SLOT_RESOURCES_1 + j + i * 2, 11 + j * 18, 65 + i * 18));
|
||||
}
|
||||
}
|
||||
|
||||
// Germlings
|
||||
for (int i = 0; i < 2; i++) {
|
||||
for (int j = 0; j < 2; j++) {
|
||||
addSlotToContainer(new SlotFiltered(tile.getInternalInventory(), InventoryPlanter.SLOT_GERMLINGS_1 + j + i * 2, 71 + j * 18, 65 + i * 18));
|
||||
}
|
||||
}
|
||||
|
||||
// Production
|
||||
for (int i = 0; i < 2; i++) {
|
||||
for (int j = 0; j < 2; j++) {
|
||||
addSlotToContainer(new SlotOutput(tile.getInternalInventory(), InventoryPlanter.SLOT_PRODUCTION_1 + j + i * 2, 131 + j * 18, 65 + i * 18));
|
||||
}
|
||||
}
|
||||
|
||||
// Fertilizer
|
||||
addSlotToContainer(new SlotFiltered(tile.getInternalInventory(), InventoryPlanter.SLOT_FERTILIZER, 83, 22));
|
||||
// Can Slot
|
||||
addSlotToContainer(new SlotLiquidIn(tile.getInternalInventory(), InventoryPlanter.SLOT_CAN, 178, 18));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void detectAndSendChanges() {
|
||||
super.detectAndSendChanges();
|
||||
PacketGuiUpdate packet = new PacketGuiUpdate(tile);
|
||||
sendPacketToListeners(packet);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
package forestry.cultivation.gui;
|
||||
|
||||
import net.minecraft.entity.player.InventoryPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.NonNullList;
|
||||
|
||||
import forestry.core.ModuleCore;
|
||||
import forestry.core.config.Constants;
|
||||
import forestry.core.gui.GuiForestryTitled;
|
||||
import forestry.core.gui.widgets.TankWidget;
|
||||
import forestry.cultivation.gui.widgets.GhostItemStackWidget;
|
||||
import forestry.cultivation.inventory.InventoryPlanter;
|
||||
import forestry.cultivation.tiles.TilePlanter;
|
||||
import forestry.farming.gui.FarmLedger;
|
||||
|
||||
public class GuiPlanter extends GuiForestryTitled<ContainerPlanter> {
|
||||
private final TilePlanter tile;
|
||||
|
||||
public GuiPlanter(TilePlanter tile, InventoryPlayer playerInventory) {
|
||||
super(Constants.TEXTURE_PATH_GUI + "/planter.png", new ContainerPlanter(tile, playerInventory), tile);
|
||||
this.tile = tile;
|
||||
this.xSize = 202;
|
||||
this.ySize = 192;
|
||||
|
||||
NonNullList<ItemStack> resourceStacks = tile.createResourceStacks();
|
||||
NonNullList<ItemStack> germlingStacks = tile.createGermlingStacks();
|
||||
NonNullList<ItemStack> productionStacks = tile.createProductionStacks();
|
||||
|
||||
widgetManager.add(new TankWidget(widgetManager, 178, 44, 0).setOverlayOrigin(xSize, 18));
|
||||
|
||||
// Resources
|
||||
for (int i = 0; i < 2; i++) {
|
||||
for (int j = 0; j < 2; j++) {
|
||||
int index = j + i * 2;
|
||||
if(resourceStacks.size() == 4) {
|
||||
widgetManager.add(new GhostItemStackWidget(widgetManager, 11 + j * 18, 65 + i * 18, resourceStacks.get(index), inventorySlots.getSlot(36 + InventoryPlanter.SLOT_RESOURCES_1 + index)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Germlings
|
||||
for (int i = 0; i < 2; i++) {
|
||||
for (int j = 0; j < 2; j++) {
|
||||
int index = j + i * 2;
|
||||
if(germlingStacks.size() == 4){
|
||||
widgetManager.add(new GhostItemStackWidget(widgetManager, 71 + j * 18, 65 + i * 18, germlingStacks.get(index), inventorySlots.getSlot(36 + InventoryPlanter.SLOT_GERMLINGS_1 + index)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Production
|
||||
for (int i = 0; i < 2; i++) {
|
||||
for (int j = 0; j < 2; j++) {
|
||||
int index = j + i * 2;
|
||||
if(productionStacks.size() == 4) {
|
||||
widgetManager.add(new GhostItemStackWidget(widgetManager, 131 + j * 18, 65 + i * 18, productionStacks.get(index), inventorySlots.getSlot(36 + InventoryPlanter.SLOT_PRODUCTION_1 + j + i * 2)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
widgetManager.add(new GhostItemStackWidget(widgetManager, 83, 22, new ItemStack(ModuleCore.getItems().fertilizerCompound), inventorySlots.getSlot(36 + InventoryPlanter.SLOT_FERTILIZER)));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void addLedgers() {
|
||||
addErrorLedger(tile);
|
||||
addClimateLedger(tile);
|
||||
ledgerManager.add(new FarmLedger(ledgerManager, tile.getFarmLedgerDelegate()));
|
||||
addOwnerLedger(tile);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void drawGuiContainerBackgroundLayer(float var1, int mouseX, int mouseY) {
|
||||
super.drawGuiContainerBackgroundLayer(var1, mouseX, mouseY);
|
||||
|
||||
// Fuel remaining
|
||||
int fertilizerRemain = tile.getStoredFertilizerScaled(16);
|
||||
if (fertilizerRemain > 0) {
|
||||
drawTexturedModalRect(guiLeft + 101, guiTop + 21 + 17 - fertilizerRemain, xSize, 17 - fertilizerRemain, 4, fertilizerRemain);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
@ParametersAreNonnullByDefault
|
||||
@FieldsAreNonnullByDefault
|
||||
@MethodsReturnNonnullByDefault
|
||||
package forestry.cultivation.gui;
|
||||
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
|
||||
import mcp.MethodsReturnNonnullByDefault;
|
||||
|
||||
import forestry.core.utils.FieldsAreNonnullByDefault;
|
||||
@@ -0,0 +1,69 @@
|
||||
package forestry.cultivation.gui.widgets;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.Locale;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.FontRenderer;
|
||||
import net.minecraft.client.renderer.GlStateManager;
|
||||
import net.minecraft.client.renderer.texture.TextureManager;
|
||||
import net.minecraft.inventory.Slot;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import forestry.api.farming.FarmDirection;
|
||||
import forestry.core.gui.tooltips.ToolTip;
|
||||
import forestry.core.gui.widgets.ItemStackWidget;
|
||||
import forestry.core.gui.widgets.WidgetManager;
|
||||
import forestry.core.render.ColourProperties;
|
||||
import forestry.core.utils.Translator;
|
||||
import forestry.cultivation.inventory.InventoryPlanter;
|
||||
|
||||
public class GhostItemStackWidget extends ItemStackWidget {
|
||||
private final Slot slot;
|
||||
public GhostItemStackWidget(WidgetManager widgetManager, int xPos, int yPos, ItemStack itemStack, Slot slot) {
|
||||
super(widgetManager, xPos, yPos, itemStack);
|
||||
this.slot = slot;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw(int startX, int startY) {
|
||||
if (!slot.getHasStack()) {
|
||||
super.draw(startX, startY);
|
||||
}
|
||||
GlStateManager.disableLighting();
|
||||
GlStateManager.disableDepth();
|
||||
GlStateManager.enableBlend();
|
||||
|
||||
String directionString = getDirectionString();
|
||||
if (!directionString.isEmpty()){
|
||||
FontRenderer fontRenderer = manager.minecraft.fontRenderer;
|
||||
fontRenderer.drawStringWithShadow(getDirectionString(), xPos + startX + 5, yPos + startY + 4, ColourProperties.INSTANCE.get("gui.screen"));
|
||||
}
|
||||
|
||||
GlStateManager.color(1.0F, 1.0F, 1.0F, 0.5F);
|
||||
|
||||
TextureManager textureManager = Minecraft.getMinecraft().getTextureManager();
|
||||
textureManager.bindTexture(manager.gui.textureFile);
|
||||
manager.gui.drawTexturedModalRect(xPos + startX, yPos + startY, 206, 0, 16, 16);
|
||||
|
||||
GlStateManager.disableBlend();
|
||||
GlStateManager.enableDepth();
|
||||
GlStateManager.enableLighting();
|
||||
}
|
||||
|
||||
private String getDirectionString(){
|
||||
if(slot.getSlotIndex() >= InventoryPlanter.SLOT_PRODUCTION_1 || slot.getSlotIndex() < InventoryPlanter.SLOT_RESOURCES_1 + InventoryPlanter.SLOT_RESOURCES_COUNT){
|
||||
return "";
|
||||
}
|
||||
int index = slot.getSlotIndex() % 4;
|
||||
FarmDirection direction = FarmDirection.values()[index];
|
||||
String directionString = direction.toString().toLowerCase(Locale.ENGLISH);
|
||||
return Translator.translateToLocal("for.gui.planter." + directionString);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public ToolTip getToolTip(int mouseX, int mouseY) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
@ParametersAreNonnullByDefault
|
||||
@FieldsAreNonnullByDefault
|
||||
@MethodsReturnNonnullByDefault
|
||||
package forestry.cultivation.gui.widgets;
|
||||
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
|
||||
import mcp.MethodsReturnNonnullByDefault;
|
||||
|
||||
import forestry.core.utils.FieldsAreNonnullByDefault;
|
||||
@@ -0,0 +1,219 @@
|
||||
package forestry.cultivation.inventory;
|
||||
|
||||
import java.util.Stack;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.NonNullList;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
import net.minecraftforge.fluids.FluidUtil;
|
||||
|
||||
import forestry.api.core.ForestryAPI;
|
||||
import forestry.api.farming.FarmDirection;
|
||||
import forestry.api.farming.IFarmLogic;
|
||||
import forestry.api.farming.IFarmable;
|
||||
import forestry.core.fluids.FluidHelper;
|
||||
import forestry.core.fluids.TankManager;
|
||||
import forestry.core.inventory.InventoryAdapterRestricted;
|
||||
import forestry.core.inventory.wrappers.InventoryMapper;
|
||||
import forestry.core.utils.InventoryUtil;
|
||||
import forestry.core.utils.SlotUtil;
|
||||
import forestry.cultivation.tiles.TilePlanter;
|
||||
import forestry.farming.multiblock.IFarmInventoryInternal;
|
||||
|
||||
public class InventoryPlanter extends InventoryAdapterRestricted implements IFarmInventoryInternal {
|
||||
public static final int SLOT_RESOURCES_1 = 0;
|
||||
public static final int SLOT_RESOURCES_COUNT = 4;
|
||||
public static final int SLOT_GERMLINGS_1 = 4;
|
||||
public static final int SLOT_GERMLINGS_COUNT = 4;
|
||||
public static final int SLOT_PRODUCTION_1 = 8;
|
||||
public static final int SLOT_PRODUCTION_COUNT = 4;
|
||||
|
||||
public static final int SLOT_FERTILIZER = 12;
|
||||
public static final int SLOT_FERTILIZER_COUNT = 1;
|
||||
public static final int SLOT_CAN = 13;
|
||||
public static final int SLOT_CAN_COUNT = 1;
|
||||
|
||||
public static final int SLOT_COUNT = SLOT_RESOURCES_COUNT + SLOT_GERMLINGS_COUNT + SLOT_PRODUCTION_COUNT + SLOT_FERTILIZER_COUNT + SLOT_CAN_COUNT;
|
||||
|
||||
private static final int FERTILIZER_MODIFIER = ForestryAPI.activeMode.getIntegerSetting("farms.fertilizer.modifier");
|
||||
|
||||
private final TilePlanter housing;
|
||||
|
||||
private final IInventory resourcesInventory;
|
||||
private final IInventory germlingsInventory;
|
||||
private final IInventory productInventory;
|
||||
private final IInventory fertilizerInventory;
|
||||
|
||||
public InventoryPlanter(TilePlanter housing) {
|
||||
super(SLOT_COUNT, "Items");
|
||||
this.housing = housing;
|
||||
|
||||
this.resourcesInventory = new InventoryMapper(this, SLOT_RESOURCES_1, SLOT_RESOURCES_COUNT);
|
||||
this.germlingsInventory = new InventoryMapper(this, SLOT_GERMLINGS_1, SLOT_GERMLINGS_COUNT);
|
||||
this.productInventory = new InventoryMapper(this, SLOT_PRODUCTION_1, SLOT_PRODUCTION_COUNT);
|
||||
this.fertilizerInventory = new InventoryMapper(this, SLOT_FERTILIZER, SLOT_FERTILIZER_COUNT);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canSlotAccept(int slotIndex, ItemStack itemStack) {
|
||||
if (SlotUtil.isSlotInRange(slotIndex, SLOT_FERTILIZER, SLOT_FERTILIZER_COUNT)) {
|
||||
return acceptsAsFertilizer(itemStack);
|
||||
} else if (SlotUtil.isSlotInRange(slotIndex, SLOT_GERMLINGS_1, SLOT_GERMLINGS_COUNT)) {
|
||||
return acceptsAsGermling(itemStack);
|
||||
} else if (SlotUtil.isSlotInRange(slotIndex, SLOT_RESOURCES_1, SLOT_RESOURCES_COUNT)) {
|
||||
return acceptsAsResource(itemStack);
|
||||
} else if (SlotUtil.isSlotInRange(slotIndex, SLOT_CAN, SLOT_CAN_COUNT)) {
|
||||
FluidStack fluid = FluidUtil.getFluidContained(itemStack);
|
||||
return fluid != null && housing.getTankManager().canFillFluidType(fluid);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canExtractItem(int slotIndex, ItemStack stack, EnumFacing side) {
|
||||
return SlotUtil.isSlotInRange(slotIndex, SLOT_PRODUCTION_1, SLOT_PRODUCTION_COUNT);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasResources(NonNullList<ItemStack> resources) {
|
||||
return InventoryUtil.contains(resourcesInventory, resources);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeResources(NonNullList<ItemStack> resources) {
|
||||
InventoryUtil.removeSets(resourcesInventory, 1, resources, null, false, true, false, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean acceptsAsGermling(ItemStack itemstack) {
|
||||
if (itemstack.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
IFarmLogic logic = housing.getFarmLogic();
|
||||
return logic.isAcceptedGermling(itemstack);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean acceptsAsResource(ItemStack itemstack) {
|
||||
if (itemstack.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
IFarmLogic logic = housing.getFarmLogic();
|
||||
return logic.isAcceptedResource(itemstack);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean acceptsAsFertilizer(ItemStack itemstack) {
|
||||
if (itemstack.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return ForestryAPI.farmRegistry.getFertilizeValue(itemstack) > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IInventory getProductInventory() {
|
||||
return productInventory;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IInventory getGermlingsInventory() {
|
||||
return germlingsInventory;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IInventory getResourcesInventory() {
|
||||
return resourcesInventory;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IInventory getFertilizerInventory() {
|
||||
return fertilizerInventory;
|
||||
}
|
||||
|
||||
public void drainCan(TankManager tankManager) {
|
||||
FluidHelper.drainContainers(tankManager, this, SLOT_CAN);
|
||||
}
|
||||
|
||||
public boolean plantGermling(IFarmable germling, EntityPlayer player, BlockPos pos) {
|
||||
for(FarmDirection direction : FarmDirection.values()){
|
||||
if(plantGermling(germling, player, pos, direction)){
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean plantGermling(IFarmable germling, EntityPlayer player, BlockPos pos, FarmDirection direction) {
|
||||
int index = direction.ordinal();
|
||||
ItemStack germlingStack = germlingsInventory.getStackInSlot(index);
|
||||
if (germlingStack.isEmpty() || !germling.isGermling(germlingStack)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (germling.plantSaplingAt(player, germlingStack, player.world, pos)) {
|
||||
germlingsInventory.decrStackSize(index, 1);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public void addProduce(ItemStack produce) {
|
||||
int added = InventoryUtil.addStack(productInventory, produce, true);
|
||||
produce.shrink(added);
|
||||
}
|
||||
|
||||
public void stowHarvest(Iterable<ItemStack> harvested, Stack<ItemStack> pendingProduce) {
|
||||
for (ItemStack harvest : harvested) {
|
||||
int added = InventoryUtil.addStack(productInventory, harvest, true);
|
||||
harvest.shrink(added);
|
||||
if (!harvest.isEmpty()) {
|
||||
pendingProduce.push(harvest);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean tryAddPendingProduce(Stack<ItemStack> pendingProduce) {
|
||||
IInventory productInventory = getProductInventory();
|
||||
|
||||
ItemStack next = pendingProduce.peek();
|
||||
boolean added = InventoryUtil.tryAddStack(productInventory, next, true, true);
|
||||
|
||||
if (added) {
|
||||
pendingProduce.pop();
|
||||
}
|
||||
|
||||
return added;
|
||||
}
|
||||
|
||||
public int getFertilizerValue() {
|
||||
ItemStack fertilizerStack = getStackInSlot(SLOT_FERTILIZER);
|
||||
if (fertilizerStack.isEmpty()) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int fertilizerValue = ForestryAPI.farmRegistry.getFertilizeValue(fertilizerStack);
|
||||
if (fertilizerValue > 0) {
|
||||
return fertilizerValue * FERTILIZER_MODIFIER;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
public boolean useFertilizer() {
|
||||
ItemStack fertilizer = getStackInSlot(SLOT_FERTILIZER);
|
||||
if (acceptsAsFertilizer(fertilizer)) {
|
||||
decrStackSize(SLOT_FERTILIZER, 1);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
@ParametersAreNonnullByDefault
|
||||
@FieldsAreNonnullByDefault
|
||||
@MethodsReturnNonnullByDefault
|
||||
package forestry.cultivation.inventory;
|
||||
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
|
||||
import mcp.MethodsReturnNonnullByDefault;
|
||||
|
||||
import forestry.core.utils.FieldsAreNonnullByDefault;
|
||||
@@ -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;
|
||||
@@ -0,0 +1,10 @@
|
||||
@ParametersAreNonnullByDefault
|
||||
@FieldsAreNonnullByDefault
|
||||
@MethodsReturnNonnullByDefault
|
||||
package forestry.cultivation;
|
||||
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
|
||||
import mcp.MethodsReturnNonnullByDefault;
|
||||
|
||||
import forestry.core.utils.FieldsAreNonnullByDefault;
|
||||
@@ -0,0 +1,42 @@
|
||||
package forestry.cultivation.tiles;
|
||||
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.init.Items;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.NonNullList;
|
||||
|
||||
public class TileArboretum extends TilePlanter {
|
||||
public TileArboretum() {
|
||||
super("farmArboreal");
|
||||
}
|
||||
|
||||
@Override
|
||||
public NonNullList<ItemStack> createGermlingStacks() {
|
||||
return createList(
|
||||
new ItemStack(Blocks.SAPLING),
|
||||
new ItemStack(Blocks.SAPLING, 1, 2),
|
||||
new ItemStack(Blocks.SAPLING, 1, 2),
|
||||
new ItemStack(Blocks.SAPLING)
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public NonNullList<ItemStack> createResourceStacks() {
|
||||
return createList(
|
||||
new ItemStack(Blocks.DIRT),
|
||||
new ItemStack(Blocks.DIRT),
|
||||
new ItemStack(Blocks.DIRT),
|
||||
new ItemStack(Blocks.DIRT)
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public NonNullList<ItemStack> createProductionStacks() {
|
||||
return createList(
|
||||
new ItemStack(Blocks.LOG),
|
||||
new ItemStack(Items.APPLE),
|
||||
new ItemStack(Items.APPLE),
|
||||
new ItemStack(Blocks.LOG)
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
package forestry.cultivation.tiles;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.NonNullList;
|
||||
|
||||
import forestry.core.ModuleCore;
|
||||
|
||||
public class TileBog extends TilePlanter {
|
||||
public TileBog() {
|
||||
super("farmPeat");
|
||||
}
|
||||
|
||||
@Override
|
||||
public NonNullList<ItemStack> createGermlingStacks() {
|
||||
return NonNullList.create();
|
||||
}
|
||||
|
||||
@Override
|
||||
public NonNullList<ItemStack> createResourceStacks() {
|
||||
return createList(
|
||||
new ItemStack(ModuleCore.getBlocks().bogEarth),
|
||||
new ItemStack(ModuleCore.getBlocks().bogEarth),
|
||||
new ItemStack(ModuleCore.getBlocks().bogEarth),
|
||||
new ItemStack(ModuleCore.getBlocks().bogEarth)
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public NonNullList<ItemStack> createProductionStacks() {
|
||||
return createList(
|
||||
new ItemStack(ModuleCore.getItems().peat),
|
||||
new ItemStack(ModuleCore.getItems().peat),
|
||||
new ItemStack(ModuleCore.getItems().peat),
|
||||
new ItemStack(ModuleCore.getItems().peat)
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
package forestry.cultivation.tiles;
|
||||
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.init.Items;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.NonNullList;
|
||||
|
||||
public class TileFarmCrops extends TilePlanter {
|
||||
public TileFarmCrops() {
|
||||
super("farmCrops");
|
||||
}
|
||||
|
||||
@Override
|
||||
public NonNullList<ItemStack> createGermlingStacks() {
|
||||
return createList(
|
||||
new ItemStack(Items.WHEAT_SEEDS),
|
||||
new ItemStack(Items.POTATO),
|
||||
new ItemStack(Items.CARROT),
|
||||
new ItemStack(Items.BEETROOT_SEEDS)
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public NonNullList<ItemStack> createResourceStacks() {
|
||||
return createList(
|
||||
new ItemStack(Blocks.DIRT),
|
||||
new ItemStack(Blocks.DIRT),
|
||||
new ItemStack(Blocks.DIRT),
|
||||
new ItemStack(Blocks.DIRT)
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public NonNullList<ItemStack> createProductionStacks() {
|
||||
return createList(
|
||||
new ItemStack(Items.WHEAT),
|
||||
new ItemStack(Items.POTATO),
|
||||
new ItemStack(Items.CARROT),
|
||||
new ItemStack(Items.BEETROOT)
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
package forestry.cultivation.tiles;
|
||||
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.init.Items;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.NonNullList;
|
||||
|
||||
public class TileFarmEnder extends TilePlanter {
|
||||
public TileFarmEnder() {
|
||||
super("farmEnder");
|
||||
}
|
||||
|
||||
@Override
|
||||
public NonNullList<ItemStack> createGermlingStacks() {
|
||||
return createList(
|
||||
new ItemStack(Blocks.CHORUS_FLOWER),
|
||||
new ItemStack(Blocks.CHORUS_FLOWER),
|
||||
new ItemStack(Blocks.CHORUS_FLOWER),
|
||||
new ItemStack(Blocks.CHORUS_FLOWER)
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public NonNullList<ItemStack> createResourceStacks() {
|
||||
return createList(
|
||||
new ItemStack(Blocks.END_STONE),
|
||||
new ItemStack(Blocks.END_STONE),
|
||||
new ItemStack(Blocks.END_STONE),
|
||||
new ItemStack(Blocks.END_STONE)
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public NonNullList<ItemStack> createProductionStacks() {
|
||||
return createList(
|
||||
new ItemStack(Blocks.CHORUS_FLOWER),
|
||||
new ItemStack(Items.CHORUS_FRUIT),
|
||||
new ItemStack(Items.CHORUS_FRUIT),
|
||||
new ItemStack(Blocks.CHORUS_FLOWER)
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
package forestry.cultivation.tiles;
|
||||
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.NonNullList;
|
||||
|
||||
public class TileFarmGourd extends TilePlanter {
|
||||
public TileFarmGourd() {
|
||||
super("farmGourd");
|
||||
}
|
||||
|
||||
@Override
|
||||
public NonNullList<ItemStack> createGermlingStacks() {
|
||||
return NonNullList.create();
|
||||
}
|
||||
|
||||
@Override
|
||||
public NonNullList<ItemStack> createResourceStacks() {
|
||||
return NonNullList.create();
|
||||
}
|
||||
|
||||
@Override
|
||||
public NonNullList<ItemStack> createProductionStacks() {
|
||||
return createList(
|
||||
new ItemStack(Blocks.MELON_BLOCK),
|
||||
new ItemStack(Blocks.PUMPKIN),
|
||||
new ItemStack(Blocks.PUMPKIN),
|
||||
new ItemStack(Blocks.MELON_BLOCK)
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
package forestry.cultivation.tiles;
|
||||
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.NonNullList;
|
||||
|
||||
public class TileFarmMushroom extends TilePlanter {
|
||||
public TileFarmMushroom() {
|
||||
super("farmShroom");
|
||||
}
|
||||
|
||||
@Override
|
||||
public NonNullList<ItemStack> createGermlingStacks() {
|
||||
return createList(
|
||||
new ItemStack(Blocks.RED_MUSHROOM),
|
||||
new ItemStack(Blocks.BROWN_MUSHROOM),
|
||||
new ItemStack(Blocks.BROWN_MUSHROOM),
|
||||
new ItemStack(Blocks.RED_MUSHROOM)
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public NonNullList<ItemStack> createResourceStacks() {
|
||||
return createList(
|
||||
new ItemStack(Blocks.MYCELIUM),
|
||||
new ItemStack(Blocks.DIRT, 1, 2),
|
||||
new ItemStack(Blocks.DIRT, 1, 2),
|
||||
new ItemStack(Blocks.MYCELIUM)
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public NonNullList<ItemStack> createProductionStacks() {
|
||||
return createList(
|
||||
new ItemStack(Blocks.RED_MUSHROOM),
|
||||
new ItemStack(Blocks.BROWN_MUSHROOM),
|
||||
new ItemStack(Blocks.BROWN_MUSHROOM),
|
||||
new ItemStack(Blocks.RED_MUSHROOM)
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
package forestry.cultivation.tiles;
|
||||
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.init.Items;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.NonNullList;
|
||||
|
||||
public class TileFarmNether extends TilePlanter {
|
||||
public TileFarmNether() {
|
||||
super("farmInfernal");
|
||||
}
|
||||
|
||||
@Override
|
||||
public NonNullList<ItemStack> createGermlingStacks() {
|
||||
return createList(
|
||||
new ItemStack(Items.NETHER_WART),
|
||||
new ItemStack(Items.NETHER_WART),
|
||||
new ItemStack(Items.NETHER_WART),
|
||||
new ItemStack(Items.NETHER_WART)
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public NonNullList<ItemStack> createResourceStacks() {
|
||||
return createList(
|
||||
new ItemStack(Blocks.SOUL_SAND),
|
||||
new ItemStack(Blocks.SOUL_SAND),
|
||||
new ItemStack(Blocks.SOUL_SAND),
|
||||
new ItemStack(Blocks.SOUL_SAND)
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public NonNullList<ItemStack> createProductionStacks() {
|
||||
return createList(
|
||||
new ItemStack(Items.NETHER_WART),
|
||||
new ItemStack(Items.NETHER_WART),
|
||||
new ItemStack(Items.NETHER_WART),
|
||||
new ItemStack(Items.NETHER_WART)
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package forestry.cultivation.tiles;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.NonNullList;
|
||||
|
||||
public class TilePlantation extends TilePlanter {
|
||||
|
||||
public TilePlantation() {
|
||||
super("farmRubber");
|
||||
}
|
||||
|
||||
@Override
|
||||
public NonNullList<ItemStack> createGermlingStacks() {
|
||||
return NonNullList.create();
|
||||
}
|
||||
|
||||
@Override
|
||||
public NonNullList<ItemStack> createResourceStacks() {
|
||||
return NonNullList.create();
|
||||
}
|
||||
|
||||
@Override
|
||||
public NonNullList<ItemStack> createProductionStacks() {
|
||||
return NonNullList.create();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,532 @@
|
||||
package forestry.cultivation.tiles;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.EnumMap;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Stack;
|
||||
|
||||
import net.minecraft.client.gui.inventory.GuiContainer;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.Container;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.NonNullList;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.Vec3i;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import net.minecraftforge.common.capabilities.Capability;
|
||||
import net.minecraftforge.fluids.FluidRegistry;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
import net.minecraftforge.fluids.capability.CapabilityFluidHandler;
|
||||
|
||||
import forestry.api.core.EnumHumidity;
|
||||
import forestry.api.core.EnumTemperature;
|
||||
import forestry.api.core.IErrorLogic;
|
||||
import forestry.api.farming.FarmDirection;
|
||||
import forestry.api.farming.ICrop;
|
||||
import forestry.api.farming.IFarmHousing;
|
||||
import forestry.api.farming.IFarmInventory;
|
||||
import forestry.api.farming.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;
|
||||
import forestry.core.fluids.ITankManager;
|
||||
import forestry.core.fluids.StandardTank;
|
||||
import forestry.core.fluids.TankManager;
|
||||
import forestry.core.network.IStreamableGui;
|
||||
import forestry.core.network.PacketBufferForestry;
|
||||
import forestry.core.owner.IOwnedTile;
|
||||
import forestry.core.owner.IOwnerHandler;
|
||||
import forestry.core.owner.OwnerHandler;
|
||||
import forestry.core.tiles.IClimatised;
|
||||
import forestry.core.tiles.ILiquidTankTile;
|
||||
import forestry.core.tiles.TilePowered;
|
||||
import forestry.core.utils.ClimateUtil;
|
||||
import forestry.core.utils.PlayerUtil;
|
||||
import forestry.core.utils.VectUtil;
|
||||
import forestry.cultivation.gui.ContainerPlanter;
|
||||
import forestry.cultivation.gui.GuiPlanter;
|
||||
import forestry.cultivation.inventory.InventoryPlanter;
|
||||
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.multiblock.FarmFertilizerManager;
|
||||
import forestry.farming.multiblock.FarmHydrationManager;
|
||||
|
||||
public abstract class TilePlanter extends TilePowered implements IFarmHousing, IClimatised, ILiquidTankTile, IOwnedTile, IStreamableGui {
|
||||
|
||||
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 String identifier;
|
||||
|
||||
private final FarmHydrationManager hydrationManager;
|
||||
private final FarmFertilizerManager fertilizerManager;
|
||||
private final InventoryPlanter inventory;
|
||||
private final TankManager tankManager;
|
||||
private final StandardTank resourceTank;
|
||||
private final OwnerHandler ownerHandler = new OwnerHandler();
|
||||
|
||||
private int platformHeight = -1;
|
||||
private Stage stage = Stage.CULTIVATE;
|
||||
private boolean isManual;
|
||||
private IFarmLogic logic;
|
||||
@Nullable
|
||||
private Vec3i offset;
|
||||
@Nullable
|
||||
private Vec3i area;
|
||||
|
||||
public void setManual(boolean manual) {
|
||||
isManual = manual;
|
||||
logic = FarmRegistry.getInstance().getProperties(identifier).getLogic(manual);
|
||||
}
|
||||
|
||||
protected TilePlanter(String identifier) {
|
||||
super(150, 1500);
|
||||
this.identifier = identifier;
|
||||
setManual(false);
|
||||
setInternalInventory(inventory = new InventoryPlanter(this));
|
||||
this.hydrationManager = new FarmHydrationManager(this);
|
||||
this.fertilizerManager = new FarmFertilizerManager();
|
||||
|
||||
this.resourceTank = new FilteredTank(Constants.PROCESSOR_TANK_CAPACITY).setFilters(FluidRegistry.WATER);
|
||||
|
||||
this.tankManager = new TankManager(this, resourceTank);
|
||||
setEnergyPerWorkCycle(10);
|
||||
setTicksPerWorkCycle(2);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPos(BlockPos posIn) {
|
||||
super.setPos(posIn);
|
||||
this.platformHeight = posIn.getY() - 2;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasWork() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void updateServerSide() {
|
||||
super.updateServerSide();
|
||||
hydrationManager.updateServer(world, getCoords());
|
||||
|
||||
if (updateOnInterval(20)) {
|
||||
inventory.drainCan(tankManager);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean workCycle() {
|
||||
if (targets.isEmpty() || updateOnInterval(10)) {
|
||||
setUpFarmlandTargets();
|
||||
}
|
||||
IErrorLogic errorLogic = getErrorLogic();
|
||||
|
||||
boolean hasFertilizer = fertilizerManager.maintainFertilizer(inventory);
|
||||
if (errorLogic.setCondition(!hasFertilizer, EnumErrorCode.NO_FERTILIZER)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!pendingProduce.isEmpty()) {
|
||||
boolean added = inventory.tryAddPendingProduce(pendingProduce);
|
||||
errorLogic.setCondition(!added, EnumErrorCode.NO_SPACE_INVENTORY);
|
||||
return added;
|
||||
}
|
||||
|
||||
// Cull queued crops.
|
||||
if (!pendingCrops.isEmpty()) {
|
||||
ICrop first = pendingCrops.get(0);
|
||||
if (cullCrop(first)) {
|
||||
pendingCrops.remove(0);
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// Cultivation and collection
|
||||
FarmWorkStatus farmWorkStatus = new FarmWorkStatus();
|
||||
|
||||
List<FarmDirection> farmDirections = Arrays.asList(FarmDirection.values());
|
||||
Collections.shuffle(farmDirections, world.rand);
|
||||
for (FarmDirection farmSide : farmDirections) {
|
||||
IFarmLogic logic = getFarmLogic(farmSide);
|
||||
|
||||
// Always try to collect windfall.
|
||||
if (collectWindfall()) {
|
||||
farmWorkStatus.didWork = true;
|
||||
}
|
||||
|
||||
List<FarmTarget> farmTargets = targets.get(farmSide);
|
||||
|
||||
if (stage == Stage.HARVEST) {
|
||||
Collection<ICrop> harvested = FarmHelper.harvestTargets(world, farmTargets, logic, Collections.emptySet());
|
||||
farmWorkStatus.didWork = !harvested.isEmpty();
|
||||
if (!harvested.isEmpty()) {
|
||||
pendingCrops.addAll(harvested);
|
||||
pendingCrops.sort(FarmHelper.TopDownICropComparator.INSTANCE);
|
||||
}
|
||||
} else if (stage == Stage.CULTIVATE) {
|
||||
farmWorkStatus = cultivateTargets(farmWorkStatus, farmTargets, farmSide);
|
||||
}
|
||||
|
||||
if (farmWorkStatus.didWork) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (stage == Stage.CULTIVATE) {
|
||||
errorLogic.setCondition(!farmWorkStatus.hasFarmland, EnumErrorCode.NO_FARMLAND);
|
||||
errorLogic.setCondition(!farmWorkStatus.hasFertilizer, EnumErrorCode.NO_FERTILIZER);
|
||||
errorLogic.setCondition(!farmWorkStatus.hasLiquid, EnumErrorCode.NO_LIQUID_FARM);
|
||||
}
|
||||
|
||||
// alternate between cultivation and harvest.
|
||||
stage = stage.next();
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NBTTagCompound writeToNBT(NBTTagCompound data) {
|
||||
data = super.writeToNBT(data);
|
||||
hydrationManager.writeToNBT(data);
|
||||
tankManager.writeToNBT(data);
|
||||
fertilizerManager.writeToNBT(data);
|
||||
ownerHandler.writeToNBT(data);
|
||||
data.setBoolean("isManual", isManual);
|
||||
return data;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFromNBT(NBTTagCompound data) {
|
||||
super.readFromNBT(data);
|
||||
hydrationManager.readFromNBT(data);
|
||||
tankManager.readFromNBT(data);
|
||||
fertilizerManager.readFromNBT(data);
|
||||
ownerHandler.readFromNBT(data);
|
||||
setManual(data.getBoolean("isManual"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeGuiData(PacketBufferForestry data) {
|
||||
tankManager.writeData(data);
|
||||
hydrationManager.writeData(data);
|
||||
fertilizerManager.writeData(data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readGuiData(PacketBufferForestry data) throws IOException {
|
||||
tankManager.readData(data);
|
||||
hydrationManager.readData(data);
|
||||
fertilizerManager.readData(data);
|
||||
}
|
||||
|
||||
private void setUpFarmlandTargets() {
|
||||
BlockPos targetStart = getCoords();
|
||||
BlockPos minPos = pos;
|
||||
BlockPos maxPos = pos;
|
||||
int size = 1;
|
||||
int extend = Config.planterExtend;
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
private boolean cullCrop(ICrop crop) {
|
||||
final int fertilizerConsumption = Math.round(logic.getFertilizerConsumption() * Config.fertilizerModifier * 2);
|
||||
|
||||
IErrorLogic errorLogic = getErrorLogic();
|
||||
|
||||
// Check fertilizer
|
||||
Boolean hasFertilizer = fertilizerManager.hasFertilizer(inventory, fertilizerConsumption);
|
||||
if (errorLogic.setCondition(!hasFertilizer, EnumErrorCode.NO_FERTILIZER)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Check water
|
||||
float hydrationModifier = hydrationManager.getHydrationModifier();
|
||||
int waterConsumption = logic.getWaterConsumption(hydrationModifier);
|
||||
FluidStack requiredLiquid = new FluidStack(FluidRegistry.WATER, waterConsumption);
|
||||
boolean hasLiquid = requiredLiquid.amount == 0 || hasLiquid(requiredLiquid);
|
||||
|
||||
if (errorLogic.setCondition(!hasLiquid, EnumErrorCode.NO_LIQUID_FARM)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
NonNullList<ItemStack> harvested = crop.harvest();
|
||||
if (harvested != null) {
|
||||
// Remove fertilizer and water
|
||||
fertilizerManager.removeFertilizer(inventory, fertilizerConsumption);
|
||||
removeLiquid(requiredLiquid);
|
||||
|
||||
inventory.stowHarvest(harvested, pendingProduce);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private boolean collectWindfall() {
|
||||
NonNullList<ItemStack> collected = logic.collect(world, this);
|
||||
if (collected.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (ItemStack produce : collected) {
|
||||
inventory.addProduce(produce);
|
||||
pendingProduce.push(produce);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private FarmWorkStatus cultivateTargets(FarmWorkStatus farmWorkStatus, List<FarmTarget> farmTargets, FarmDirection farmSide) {
|
||||
boolean hasFarmland = false;
|
||||
for (FarmTarget target : farmTargets) {
|
||||
if (target.getExtent() > 0) {
|
||||
hasFarmland = true;
|
||||
farmWorkStatus.hasFarmland = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (hasFarmland && !FarmHelper.isCycleCanceledByListeners(logic, farmSide, Collections.emptySet())) {
|
||||
final float hydrationModifier = hydrationManager.getHydrationModifier();
|
||||
final int fertilizerConsumption = Math.round(logic.getFertilizerConsumption() * Config.fertilizerModifier * 2);
|
||||
final int liquidConsumption = logic.getWaterConsumption(hydrationModifier);
|
||||
final FluidStack liquid = new FluidStack(FluidRegistry.WATER, liquidConsumption);
|
||||
|
||||
for (FarmTarget target : farmTargets) {
|
||||
// Check fertilizer and water
|
||||
if (!fertilizerManager.hasFertilizer(inventory, fertilizerConsumption)) {
|
||||
farmWorkStatus.hasFertilizer = false;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (liquid.amount > 0 && !hasLiquid(liquid)) {
|
||||
farmWorkStatus.hasLiquid = false;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (FarmHelper.cultivateTarget(world, this, target, logic, Collections.emptySet())) {
|
||||
// Remove fertilizer and water
|
||||
fertilizerManager.removeFertilizer(inventory, fertilizerConsumption);
|
||||
removeLiquid(liquid);
|
||||
|
||||
farmWorkStatus.didWork = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return farmWorkStatus;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockPos getCoords() {
|
||||
return pos;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Vec3i getArea() {
|
||||
if (area == null) {
|
||||
int basisArea = 5;
|
||||
if(Config.ringFarms){
|
||||
basisArea = basisArea + 1 + Config.ringSize * 2;
|
||||
}
|
||||
area = new Vec3i(basisArea + Config.planterExtend, 13, basisArea + Config.planterExtend);
|
||||
}
|
||||
return area;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Vec3i getOffset() {
|
||||
if (offset == null) {
|
||||
Vec3i area = getArea();
|
||||
offset = new Vec3i(-area.getX() / 2, -2, -area.getZ() / 2);
|
||||
}
|
||||
return offset;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean doWork() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasLiquid(FluidStack liquid) {
|
||||
FluidStack drained = resourceTank.drainInternal(liquid, false);
|
||||
return liquid.isFluidStackIdentical(drained);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeLiquid(FluidStack liquid) {
|
||||
resourceTank.drain(liquid.amount, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean plantGermling(IFarmable germling, World world, BlockPos pos) {
|
||||
EntityPlayer player = PlayerUtil.getFakePlayer(world, getOwnerHandler().getOwner());
|
||||
return player != null && inventory.plantGermling(germling, player, pos);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IOwnerHandler getOwnerHandler() {
|
||||
return ownerHandler;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean plantGermling(IFarmable farmable, World world, BlockPos pos, FarmDirection direction) {
|
||||
EntityPlayer player = PlayerUtil.getFakePlayer(world, getOwnerHandler().getOwner());
|
||||
return player != null && inventory.plantGermling(farmable, player, pos, direction);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isValidPlatform(World world, BlockPos pos) {
|
||||
return pos.getY() == platformHeight;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSquare() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canPlantSoil(boolean manual) {
|
||||
return !isManual;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IFarmInventory getFarmInventory() {
|
||||
return inventory;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setFarmLogic(FarmDirection direction, IFarmLogic logic) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void resetFarmLogic(FarmDirection direction) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public IFarmLogic getFarmLogic(FarmDirection direction) {
|
||||
return getFarmLogic();
|
||||
}
|
||||
|
||||
public IFarmLogic getFarmLogic() {
|
||||
return logic;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getStoredFertilizerScaled(int scale) {
|
||||
return fertilizerManager.getStoredFertilizerScaled(inventory, scale);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void invalidate() {
|
||||
super.invalidate();
|
||||
targets.clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
public NBTTagCompound getUpdateTag() {
|
||||
NBTTagCompound data = super.getUpdateTag();
|
||||
hydrationManager.writeToNBT(data);
|
||||
tankManager.writeToNBT(data);
|
||||
fertilizerManager.writeToNBT(data);
|
||||
return data;
|
||||
}
|
||||
|
||||
protected final BlockPos translateWithOffset(BlockPos pos, FarmDirection farmDirection, int step) {
|
||||
return VectUtil.scale(farmDirection.getFacing().getDirectionVec(), step).add(pos);
|
||||
}
|
||||
|
||||
@Override
|
||||
public GuiContainer getGui(EntityPlayer player, int data) {
|
||||
return new GuiPlanter(this, player.inventory);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Container getContainer(EntityPlayer player, int data) {
|
||||
return new ContainerPlanter(this, player.inventory);
|
||||
}
|
||||
|
||||
public IFarmLedgerDelegate getFarmLedgerDelegate() {
|
||||
return hydrationManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public EnumTemperature getTemperature() {
|
||||
return EnumTemperature.getFromValue(getExactTemperature());
|
||||
}
|
||||
|
||||
@Override
|
||||
public EnumHumidity getHumidity() {
|
||||
return EnumHumidity.getFromValue(getExactHumidity());
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getExactTemperature() {
|
||||
BlockPos coords = getCoordinates();
|
||||
return ClimateUtil.getTemperature(getWorldObj(), coords);
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getExactHumidity() {
|
||||
BlockPos coords = getCoordinates();
|
||||
return ClimateUtil.getHumidity(getWorldObj(), coords);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ITankManager getTankManager() {
|
||||
return tankManager;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean hasCapability(Capability<?> capability, @Nullable EnumFacing facing) {
|
||||
return capability == CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY || super.hasCapability(capability, facing);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public <T> T getCapability(Capability<T> capability, @Nullable EnumFacing facing) {
|
||||
if (capability == CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY) {
|
||||
return CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY.cast(getTankManager());
|
||||
}
|
||||
return super.getCapability(capability, facing);
|
||||
}
|
||||
|
||||
protected NonNullList<ItemStack> createList(ItemStack... stacks){
|
||||
return NonNullList.from(ItemStack.EMPTY, stacks);
|
||||
}
|
||||
|
||||
public abstract NonNullList<ItemStack> createGermlingStacks();
|
||||
|
||||
public abstract NonNullList<ItemStack> createResourceStacks();
|
||||
|
||||
public abstract NonNullList<ItemStack> createProductionStacks();
|
||||
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
@ParametersAreNonnullByDefault
|
||||
@FieldsAreNonnullByDefault
|
||||
@MethodsReturnNonnullByDefault
|
||||
package forestry.cultivation.tiles;
|
||||
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
|
||||
import mcp.MethodsReturnNonnullByDefault;
|
||||
|
||||
import forestry.core.utils.FieldsAreNonnullByDefault;
|
||||
@@ -328,7 +328,13 @@ public class ModuleFactory extends BlankForestryModule {
|
||||
"XXX",
|
||||
'#', new ItemStack(Items.REPEATER, 1, 0),
|
||||
'X', new ItemStack(Blocks.REDSTONE_ORE, 1, 0)});
|
||||
|
||||
RecipeManagers.fabricatorManager.addRecipe(ItemStack.EMPTY, Fluids.GLASS.getFluid(500), coreItems.flexibleCasing.getItemStack(), new Object[]{
|
||||
"#E#",
|
||||
"B B",
|
||||
"#E#",
|
||||
'#', OreDictUtil.INGOT_BRONZE,
|
||||
'B', OreDictUtil.SLIMEBALL,
|
||||
'E', "gemEmerald"});
|
||||
String[] dyes = {"dyeBlack", "dyeRed", "dyeGreen", "dyeBrown", "dyeBlue", "dyePurple", "dyeCyan", "dyeLightGray", "dyeGray", "dyePink", "dyeLime",
|
||||
"dyeYellow", "dyeLightBlue", "dyeMagenta", "dyeOrange", "dyeWhite"};
|
||||
|
||||
|
||||
@@ -1,42 +1,75 @@
|
||||
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.IFarmLogic;
|
||||
import forestry.api.farming.IFarmProperties;
|
||||
import forestry.api.farming.IFarmRegistry;
|
||||
import forestry.api.farming.IFarmable;
|
||||
import forestry.api.farming.ISimpleFarmLogic;
|
||||
import forestry.farming.logic.FakeFarmProperties;
|
||||
|
||||
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 IFarmProperties registerLogic(String identifier, IFarmProperties farmInstance) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IFarmProperties registerLogic(String identifier, BiFunction<IFarmProperties, Boolean, IFarmLogic> logicFactory, String... farmablesIdentifiers) {
|
||||
//Dummy-Implementation
|
||||
return null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public IFarmLogic createCropLogic(IFarmProperties instance, boolean isManual, ISimpleFarmLogic simpleFarmLogic) {
|
||||
//Dummy-Implementation
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IFarmProperties createFakeInstance(IFarmLogic logic) {
|
||||
return new FakeFarmProperties(logic);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerFertilizer(ItemStack itemStack, int value) {
|
||||
//Dummy-Implementation
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getFertilizeValue(ItemStack itemStack) {
|
||||
//Dummy-Implementation
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public IFarmProperties getProperties(String identifier) {
|
||||
//Dummy-Implementation
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -12,15 +12,62 @@ package forestry.farming;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
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.IFarmListener;
|
||||
import forestry.api.farming.IFarmLogic;
|
||||
import forestry.core.utils.TopDownBlockPosComparator;
|
||||
|
||||
public class FarmHelper {
|
||||
|
||||
public enum Stage {
|
||||
CULTIVATE, HARVEST;
|
||||
|
||||
public Stage next() {
|
||||
if (this == CULTIVATE) {
|
||||
return HARVEST;
|
||||
} else {
|
||||
return CULTIVATE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static class FarmWorkStatus {
|
||||
public boolean didWork = false;
|
||||
public boolean hasFarmland = false;
|
||||
public boolean hasFertilizer = true;
|
||||
public boolean hasLiquid = true;
|
||||
}
|
||||
|
||||
private static FarmDirection getLayoutDirection(FarmDirection farmSide) {
|
||||
switch (farmSide) {
|
||||
case NORTH:
|
||||
return FarmDirection.WEST;
|
||||
case WEST:
|
||||
return FarmDirection.SOUTH;
|
||||
case SOUTH:
|
||||
return FarmDirection.EAST;
|
||||
case EAST:
|
||||
return FarmDirection.NORTH;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static final ImmutableSet<Block> bricks = ImmutableSet.of(
|
||||
Blocks.BRICK_BLOCK,
|
||||
Blocks.STONEBRICK,
|
||||
@@ -38,7 +85,7 @@ public class FarmHelper {
|
||||
/**
|
||||
* @return the corner of the farm for the given side and layout. Returns null if the corner is not in a loaded chunk.
|
||||
*/
|
||||
public static BlockPos getFarmMultiblockCorner(BlockPos start, FarmDirection farmSide, FarmDirection layoutDirection, BlockPos minFarmCoord, BlockPos maxFarmCoord) {
|
||||
private static BlockPos getFarmMultiblockCorner(BlockPos start, FarmDirection farmSide, FarmDirection layoutDirection, BlockPos minFarmCoord, BlockPos maxFarmCoord) {
|
||||
BlockPos edge = getFarmMultiblockEdge(start, farmSide, maxFarmCoord, minFarmCoord);
|
||||
return getFarmMultiblockEdge(edge, getOpposite(layoutDirection), maxFarmCoord, minFarmCoord);
|
||||
}
|
||||
@@ -60,4 +107,137 @@ public class FarmHelper {
|
||||
throw new IllegalArgumentException("Invalid farm direction: " + direction);
|
||||
}
|
||||
}
|
||||
|
||||
public static void createTargets(World world, IFarmHousing farmHousing, Map<FarmDirection, List<FarmTarget>> targets, BlockPos targetStart, final int allowedExtent, final int farmSizeNorthSouth, final int farmSizeEastWest, BlockPos minFarmCoord, BlockPos maxFarmCoord) {
|
||||
for (FarmDirection farmSide : FarmDirection.values()) {
|
||||
|
||||
final int farmWidth;
|
||||
if (farmSide == FarmDirection.NORTH || farmSide == FarmDirection.SOUTH) {
|
||||
farmWidth = farmSizeEastWest;
|
||||
} else {
|
||||
farmWidth = farmSizeNorthSouth;
|
||||
}
|
||||
|
||||
// targets extend sideways in a pinwheel pattern around the farm, so they need to go a little extra distance
|
||||
final int targetMaxLimit = allowedExtent + farmWidth;
|
||||
|
||||
FarmDirection layoutDirection = getLayoutDirection(farmSide);
|
||||
|
||||
List<FarmTarget> farmSideTargets = new ArrayList<>();
|
||||
targets.put(farmSide, farmSideTargets);
|
||||
|
||||
BlockPos targetLocation = FarmHelper.getFarmMultiblockCorner(targetStart, farmSide, layoutDirection, minFarmCoord, maxFarmCoord);
|
||||
BlockPos firstLocation = targetLocation.offset(farmSide.getFacing());
|
||||
BlockPos firstGroundPosition = getGroundPosition(world, farmHousing, firstLocation);
|
||||
if (firstGroundPosition != null) {
|
||||
int groundHeight = firstGroundPosition.getY();
|
||||
|
||||
for (int i = 0; i < allowedExtent; i++) {
|
||||
targetLocation = targetLocation.offset(farmSide.getFacing());
|
||||
BlockPos groundLocation = new BlockPos(targetLocation.getX(), groundHeight, targetLocation.getZ());
|
||||
|
||||
if (!world.isBlockLoaded(groundLocation)) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (!farmHousing.isValidPlatform(world, groundLocation)) {
|
||||
break;
|
||||
}
|
||||
|
||||
int targetLimit = targetMaxLimit;
|
||||
if (!farmHousing.isSquare()) {
|
||||
targetLimit = targetMaxLimit - i - 1;
|
||||
}
|
||||
|
||||
FarmTarget target = new FarmTarget(targetLocation, layoutDirection, targetLimit);
|
||||
farmSideTargets.add(target);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static BlockPos getGroundPosition(World world, IFarmHousing farmHousing, BlockPos targetPosition) {
|
||||
if (!world.isBlockLoaded(targetPosition)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
for (int yOffset = 2; yOffset > -4; yOffset--) {
|
||||
BlockPos position = targetPosition.add(0, yOffset, 0);
|
||||
if (farmHousing.isValidPlatform(world, position)) {
|
||||
return position;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static boolean isCycleCanceledByListeners(IFarmLogic logic, FarmDirection direction, Iterable<IFarmListener> farmListeners) {
|
||||
for (IFarmListener listener : farmListeners) {
|
||||
if (listener.cancelTask(logic, direction)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static void setExtents(World world, IFarmHousing farmHousing, Map<FarmDirection, List<FarmTarget>> targets) {
|
||||
for (List<FarmTarget> targetsList : targets.values()) {
|
||||
if (!targetsList.isEmpty()) {
|
||||
BlockPos groundPosition = getGroundPosition(world, farmHousing, targetsList.get(0).getStart());
|
||||
|
||||
for (FarmTarget target : targetsList) {
|
||||
target.setExtentAndYOffset(world, groundPosition, farmHousing);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean cultivateTarget(World world, IFarmHousing farmHousing, FarmTarget target, IFarmLogic logic, Iterable<IFarmListener> farmListeners) {
|
||||
BlockPos targetPosition = target.getStart().add(0, target.getYOffset(), 0);
|
||||
if (logic.cultivate(world, farmHousing, targetPosition, target.getDirection(), target.getExtent())) {
|
||||
for (IFarmListener listener : farmListeners) {
|
||||
listener.hasCultivated(logic, targetPosition, target.getDirection(), target.getExtent());
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public static Collection<ICrop> harvestTargets(World world, List<FarmTarget> farmTargets, IFarmLogic logic, Iterable<IFarmListener> farmListeners) {
|
||||
for (FarmTarget target : farmTargets) {
|
||||
Collection<ICrop> harvested = harvestTarget(world, target, logic, farmListeners);
|
||||
if (!harvested.isEmpty()) {
|
||||
return harvested;
|
||||
}
|
||||
}
|
||||
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
public static Collection<ICrop> harvestTarget(World world, FarmTarget target, IFarmLogic logic, Iterable<IFarmListener> farmListeners) {
|
||||
BlockPos pos = target.getStart().add(0, target.getYOffset(), 0);
|
||||
Collection<ICrop> harvested = logic.harvest(world, pos, target.getDirection(), target.getExtent());
|
||||
if (!harvested.isEmpty()) {
|
||||
// Let event handlers know.
|
||||
for (IFarmListener listener : farmListeners) {
|
||||
listener.hasScheduledHarvest(harvested, logic, pos, target.getDirection(), target.getExtent());
|
||||
}
|
||||
}
|
||||
return harvested;
|
||||
}
|
||||
|
||||
public static class TopDownICropComparator implements Comparator<ICrop> {
|
||||
public static final TopDownICropComparator INSTANCE = new TopDownICropComparator();
|
||||
|
||||
private TopDownICropComparator() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compare(ICrop o1, ICrop o2) {
|
||||
return TopDownBlockPosComparator.INSTANCE.compare(o1.getPosition(), o2.getPosition());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,10 @@
|
||||
package forestry.farming;
|
||||
|
||||
import com.google.common.collect.HashMultimap;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.Multimap;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
@@ -14,6 +16,7 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Set;
|
||||
import java.util.function.BiFunction;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
@@ -21,6 +24,7 @@ import net.minecraftforge.common.config.Property;
|
||||
import net.minecraftforge.oredict.OreDictionary;
|
||||
|
||||
import forestry.api.farming.IFarmLogic;
|
||||
import forestry.api.farming.IFarmProperties;
|
||||
import forestry.api.farming.IFarmRegistry;
|
||||
import forestry.api.farming.IFarmable;
|
||||
import forestry.api.farming.ISimpleFarmLogic;
|
||||
@@ -28,25 +32,26 @@ import forestry.core.config.LocalizedConfiguration;
|
||||
import forestry.core.utils.ItemStackUtil;
|
||||
import forestry.core.utils.Log;
|
||||
import forestry.core.utils.Translator;
|
||||
import forestry.farming.logic.FakeFarmProperties;
|
||||
import forestry.farming.logic.FarmLogicSimple;
|
||||
import forestry.farming.logic.FarmProperties;
|
||||
|
||||
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, IFarmProperties> farmInstances = new HashMap<>();
|
||||
private FertilizerConfig fertilizer = FertilizerConfig.DUMMY;
|
||||
|
||||
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) {
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -60,13 +65,18 @@ public final class FarmRegistry implements IFarmRegistry {
|
||||
}
|
||||
|
||||
@Override
|
||||
public IFarmLogic createLogic(ISimpleFarmLogic simpleFarmLogic) {
|
||||
return new FarmLogicSimple(simpleFarmLogic);
|
||||
public IFarmLogic createCropLogic(IFarmProperties instance, boolean isManual, ISimpleFarmLogic simpleFarmLogic) {
|
||||
return new FarmLogicSimple(instance, isManual, simpleFarmLogic);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IFarmProperties createFakeInstance(IFarmLogic logic) {
|
||||
return new FakeFarmProperties(logic);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerFertilizer(ItemStack itemStack, int value) {
|
||||
if(itemStack == null || itemStack.isEmpty()){
|
||||
if(itemStack.isEmpty()){
|
||||
return;
|
||||
}
|
||||
fertilizers.put(itemStack, value);
|
||||
@@ -74,50 +84,113 @@ public final class FarmRegistry implements IFarmRegistry {
|
||||
|
||||
@Override
|
||||
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)) {
|
||||
return fertilizer.getValue();
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
return fertilizer.getFertilizeValue(itemStack);
|
||||
}
|
||||
|
||||
public void loadConfig(LocalizedConfiguration config) {
|
||||
List<String> defaultFertilizers = new ArrayList<>(getItemStrings());
|
||||
|
||||
@Override
|
||||
public IFarmProperties registerLogic(String identifier, IFarmProperties farmInstance) {
|
||||
farmInstances.put(identifier, farmInstance);
|
||||
return farmInstance;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IFarmProperties registerLogic(String identifier, BiFunction<IFarmProperties, Boolean, IFarmLogic> logicFactory, String... farmablesIdentifiers) {
|
||||
Set<String> identifiers = new HashSet<>(Arrays.asList(farmablesIdentifiers));
|
||||
identifiers.add(identifier);
|
||||
IFarmProperties instance = new FarmProperties(logicFactory, identifiers);
|
||||
farmInstances.put(identifier, instance);
|
||||
return instance;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public IFarmProperties getProperties(String identifier) {
|
||||
return farmInstances.get(identifier);
|
||||
}
|
||||
|
||||
void loadConfig(LocalizedConfiguration config) {
|
||||
Map<String, String> defaultEntries = getItemStrings();
|
||||
List<String> defaultFertilizers = new ArrayList<>(defaultEntries.values());
|
||||
Collections.sort(defaultFertilizers);
|
||||
String[] defaultSortedFertilizers = defaultFertilizers.toArray(new String[defaultFertilizers.size()]);
|
||||
Property fertilizerConf = config.get("fertilizers", "items", defaultSortedFertilizers, Translator.translateToLocal("for.config.farm.fertilizers.items"));
|
||||
Property property = config.get("fertilizers", "items", defaultSortedFertilizers, Translator.translateToLocal("for.config.farm.fertilizers.items"));
|
||||
|
||||
fertilizers.clear();
|
||||
String[] fertilizerList = fertilizerConf.getStringList();
|
||||
for (int i = 0; i < fertilizerList.length; i++) {
|
||||
try {
|
||||
String fertilizer = fertilizerList[i];
|
||||
String[] fertilizers = fertilizer.split(";");
|
||||
String itemName = fertilizers[0];
|
||||
if(itemName.equals("forestry:fertilizerCompound")){
|
||||
itemName = "forestry:fertilizer_compound";
|
||||
}
|
||||
ItemStack fertilizerItem = ItemStackUtil.parseItemStackString(itemName, OreDictionary.WILDCARD_VALUE);
|
||||
int fertilizerValue = Integer.parseInt(fertilizers[1]);
|
||||
registerFertilizer(fertilizerItem, fertilizerValue);
|
||||
} catch (Exception e) {
|
||||
Log.error("Forestry failed to parse a fertilizer entry at the farm config, at the position " + i + ".", e);
|
||||
ImmutableMap<ItemStack, Integer> fertilizerMap = checkConfig(property, defaultEntries);
|
||||
fertilizer = new FertilizerConfig(fertilizerMap);
|
||||
}
|
||||
|
||||
private ImmutableMap<ItemStack, Integer> checkConfig(Property property, Map<String, String> defaultEntries){
|
||||
String[] fertilizerList = property.getStringList();
|
||||
ImmutableMap.Builder<ItemStack, Integer> fertilizerMap = new ImmutableMap.Builder<>();
|
||||
Map<String, String> configEntries = parseConfig(fertilizerList, fertilizerMap);
|
||||
|
||||
List<String> newEntries = new ArrayList<>(Arrays.asList(fertilizerList));
|
||||
for(Entry<String, String> defaultEntry : defaultEntries.entrySet()){
|
||||
if(!configEntries.containsKey(defaultEntry.getKey())){
|
||||
newEntries.add(defaultEntry.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
if(newEntries.size() > fertilizerList.length){
|
||||
Collections.sort(newEntries);
|
||||
property.set(newEntries.toArray(new String[newEntries.size()]));
|
||||
return checkConfig(property, defaultEntries);
|
||||
}
|
||||
|
||||
return fertilizerMap.build();
|
||||
}
|
||||
|
||||
private Map<String, String> parseConfig(String[] fertilizerList, ImmutableMap.Builder<ItemStack, Integer> fertilizerMap){
|
||||
Map<String, String> configEntries = new HashMap<>();
|
||||
for(String entry : fertilizerList){
|
||||
String[] spited = entry.split(";");
|
||||
if(spited.length < 2){
|
||||
Log.error("Forestry failed to parse a entry of the fertilizer config.");
|
||||
continue;
|
||||
}
|
||||
String itemName = spited[0];
|
||||
ItemStack fertilizerItem = ItemStackUtil.parseItemStackString(itemName, OreDictionary.WILDCARD_VALUE);
|
||||
if(fertilizerItem == null || fertilizerItem.isEmpty()){
|
||||
Log.error("Forestry failed to parse a entry of the fertilizer config, because the item doesn't exists.");
|
||||
continue;
|
||||
}
|
||||
String value = spited[1];
|
||||
int fertilizerValue = Integer.parseInt(value);
|
||||
if(fertilizerValue > 0) {
|
||||
fertilizerMap.put(fertilizerItem, fertilizerValue);
|
||||
}
|
||||
configEntries.put(itemName, value);
|
||||
}
|
||||
return configEntries;
|
||||
}
|
||||
|
||||
private Set<String> getItemStrings() {
|
||||
Set<String> itemStrings = new HashSet<>(fertilizers.size());
|
||||
private Map<String, String> getItemStrings() {
|
||||
Map<String, String> itemStrings = new HashMap<>(fertilizers.size());
|
||||
for (Entry<ItemStack, Integer> itemStack : fertilizers.entrySet()) {
|
||||
String itemString = ItemStackUtil.getStringForItemStack(itemStack.getKey());
|
||||
itemString += ";" + itemStack.getValue();
|
||||
itemStrings.add(itemString);
|
||||
itemStrings.put(itemString, itemString + ";" + itemStack.getValue());
|
||||
}
|
||||
return itemStrings;
|
||||
}
|
||||
|
||||
private static class FertilizerConfig{
|
||||
private static final FertilizerConfig DUMMY = new FertilizerConfig(Collections.emptyMap());
|
||||
|
||||
private final Map<ItemStack, Integer> fertilizers;
|
||||
|
||||
private FertilizerConfig(Map<ItemStack, Integer> fertilizers) {
|
||||
this.fertilizers = fertilizers;
|
||||
}
|
||||
|
||||
private int getFertilizeValue(ItemStack itemStack) {
|
||||
for (Entry<ItemStack, Integer> fertilizer : fertilizers.entrySet()) {
|
||||
ItemStack fertilizerStack = fertilizer.getKey();
|
||||
if (ItemStackUtil.isIdenticalItem(fertilizerStack, itemStack)) {
|
||||
return fertilizer.getValue();
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -12,11 +12,11 @@ package forestry.farming;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import forestry.api.farming.FarmDirection;
|
||||
import forestry.api.farming.IFarmHousing;
|
||||
|
||||
public class FarmTarget {
|
||||
|
||||
@@ -49,7 +49,7 @@ public class FarmTarget {
|
||||
return direction;
|
||||
}
|
||||
|
||||
public void setExtentAndYOffset(World world, @Nullable BlockPos platformPosition) {
|
||||
public void setExtentAndYOffset(World world, @Nullable BlockPos platformPosition, IFarmHousing housing) {
|
||||
if (platformPosition == null) {
|
||||
extent = 0;
|
||||
return;
|
||||
@@ -60,8 +60,7 @@ public class FarmTarget {
|
||||
if (!world.isBlockLoaded(position)) {
|
||||
break;
|
||||
}
|
||||
IBlockState blockState = world.getBlockState(position);
|
||||
if (!FarmHelper.bricks.contains(blockState.getBlock())) {
|
||||
if (!housing.isValidPlatform(world, position)) {
|
||||
break;
|
||||
}
|
||||
position.move(getDirection().getFacing());
|
||||
|
||||
@@ -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.IFarmProperties;
|
||||
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;
|
||||
@@ -59,8 +63,9 @@ import forestry.farming.blocks.BlockRegistryFarming;
|
||||
import forestry.farming.blocks.EnumFarmBlockType;
|
||||
import forestry.farming.circuits.CircuitFarmLogic;
|
||||
import forestry.farming.logic.FarmLogicArboreal;
|
||||
import forestry.farming.logic.FarmLogicCereal;
|
||||
import forestry.farming.logic.FarmLogicCocoa;
|
||||
import forestry.farming.logic.FarmLogicCrops;
|
||||
import forestry.farming.logic.FarmLogicEnder;
|
||||
import forestry.farming.logic.FarmLogicGourd;
|
||||
import forestry.farming.logic.FarmLogicInfernal;
|
||||
import forestry.farming.logic.FarmLogicMushroom;
|
||||
@@ -68,13 +73,13 @@ import forestry.farming.logic.FarmLogicOrchard;
|
||||
import forestry.farming.logic.FarmLogicPeat;
|
||||
import forestry.farming.logic.FarmLogicReeds;
|
||||
import forestry.farming.logic.FarmLogicSucculent;
|
||||
import forestry.farming.logic.FarmLogicVegetable;
|
||||
import forestry.farming.logic.FarmableAgingCrop;
|
||||
import forestry.farming.logic.FarmableGE;
|
||||
import forestry.farming.logic.FarmableGourd;
|
||||
import forestry.farming.logic.FarmableStacked;
|
||||
import forestry.farming.logic.FarmableVanillaMushroom;
|
||||
import forestry.farming.logic.FarmableVanillaSapling;
|
||||
import forestry.farming.logic.farmables.FarmableAgingCrop;
|
||||
import forestry.farming.logic.farmables.FarmableChorus;
|
||||
import forestry.farming.logic.farmables.FarmableGE;
|
||||
import forestry.farming.logic.farmables.FarmableGourd;
|
||||
import forestry.farming.logic.farmables.FarmableStacked;
|
||||
import forestry.farming.logic.farmables.FarmableVanillaMushroom;
|
||||
import forestry.farming.logic.farmables.FarmableVanillaSapling;
|
||||
import forestry.farming.models.EnumFarmBlockTexture;
|
||||
import forestry.farming.proxy.ProxyFarming;
|
||||
import forestry.farming.tiles.TileFarmControl;
|
||||
@@ -129,7 +134,7 @@ public class ModuleFarming extends BlankForestryModule {
|
||||
registry.registerFarmables("farmArboreal", new FarmableGE());
|
||||
}
|
||||
|
||||
registry.registerFarmables("farmOrchard",
|
||||
registry.registerFarmables("farmCrops",
|
||||
new FarmableAgingCrop(new ItemStack(Items.WHEAT_SEEDS), Blocks.WHEAT, BlockCrops.AGE, 7, 0),
|
||||
new FarmableAgingCrop(new ItemStack(Items.POTATO), Blocks.POTATOES, BlockCrops.AGE, 7, 0),
|
||||
new FarmableAgingCrop(new ItemStack(Items.CARROT), Blocks.CARROTS, BlockCrops.AGE, 7, 0),
|
||||
@@ -141,8 +146,6 @@ public class ModuleFarming extends BlankForestryModule {
|
||||
IBlockState plantedRedMushroom = blocks.mushroom.getDefaultState().withProperty(BlockMushroom.VARIANT, BlockMushroom.MushroomType.RED);
|
||||
registry.registerFarmables("farmShroom", new FarmableVanillaMushroom(new ItemStack(Blocks.RED_MUSHROOM), plantedRedMushroom, Blocks.RED_MUSHROOM_BLOCK));
|
||||
|
||||
registry.registerFarmables("farmWheat", new FarmableAgingCrop(new ItemStack(Items.WHEAT_SEEDS), Blocks.WHEAT, BlockCrops.AGE, 7));
|
||||
|
||||
registry.registerFarmables("farmGourd", new FarmableGourd(new ItemStack(Items.PUMPKIN_SEEDS), Blocks.PUMPKIN_STEM, Blocks.PUMPKIN));
|
||||
registry.registerFarmables("farmGourd", new FarmableGourd(new ItemStack(Items.MELON_SEEDS), Blocks.MELON_STEM, Blocks.MELON_BLOCK));
|
||||
|
||||
@@ -152,9 +155,7 @@ public class ModuleFarming extends BlankForestryModule {
|
||||
|
||||
registry.registerFarmables("farmSucculentes", new FarmableStacked(new ItemStack(Blocks.CACTUS), Blocks.CACTUS, 3));
|
||||
|
||||
registry.registerFarmables("farmVegetables", new FarmableAgingCrop(new ItemStack(Items.POTATO), Blocks.POTATOES, BlockCrops.AGE, 7));
|
||||
registry.registerFarmables("farmVegetables", new FarmableAgingCrop(new ItemStack(Items.CARROT), Blocks.CARROTS, BlockCrops.AGE, 7));
|
||||
registry.registerFarmables("farmVegetables", new FarmableAgingCrop(new ItemStack(Items.BEETROOT_SEEDS), Blocks.BEETROOTS, BlockBeetroot.BEETROOT_AGE, 3));
|
||||
registry.registerFarmables("farmEnder", FarmableChorus.INSTANCE);
|
||||
|
||||
//Forestry fertilizer
|
||||
registry.registerFertilizer(new ItemStack(coreItems.fertilizerCompound, 1, OreDictionary.WILDCARD_VALUE), 500);
|
||||
@@ -188,30 +189,65 @@ 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.farmCerealManaged = new CircuitFarmLogic("managedCereal", new FarmLogicCereal());
|
||||
Circuits.farmVegetableManaged = new CircuitFarmLogic("managedVegetable", new FarmLogicVegetable());
|
||||
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.farmCerealManual = new CircuitFarmLogic("manualCereal", new FarmLogicCereal()).setManual();
|
||||
Circuits.farmVegetableManual = new CircuitFarmLogic("manualVegetable", new FarmLogicVegetable()).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();
|
||||
IFarmProperties arborealFarm = registry.registerLogic("farmArboreal", FarmLogicArboreal::new);
|
||||
IFarmProperties cropsFarm = registry.registerLogic("farmCrops", FarmLogicCrops::new);
|
||||
IFarmProperties mushroomFarm = registry.registerLogic("farmShroom", FarmLogicMushroom::new);
|
||||
IFarmProperties succulentFarm = registry.registerLogic("farmSucculent", FarmLogicSucculent::new);
|
||||
IFarmProperties peatFarm = registry.registerLogic("farmPeat", FarmLogicPeat::new);
|
||||
IFarmProperties infernalFarm = registry.registerLogic("farmInfernal", FarmLogicInfernal::new);
|
||||
IFarmProperties poalesFarm = registry.registerLogic("farmPoales", FarmLogicReeds::new);
|
||||
IFarmProperties orchardFarm = registry.registerLogic("farmOrchard", FarmLogicOrchard::new);
|
||||
IFarmProperties gourdFarm = registry.registerLogic("farmGourd", FarmLogicGourd::new);
|
||||
IFarmProperties cocoaFarm = registry.registerLogic("farmCocoa", FarmLogicCocoa::new);
|
||||
IFarmProperties enderFarm = registry.registerLogic("farmEnder", FarmLogicEnder::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("farmWheat",((CircuitFarmLogic)Circuits.farmCerealManaged).getFarmLogic());
|
||||
FarmRegistry.getInstance().registerFarmLogic("farmVegetables",((CircuitFarmLogic)Circuits.farmVegetableManaged).getFarmLogic());
|
||||
FarmRegistry.getInstance().registerFarmLogic("farmInfernal",((CircuitFarmLogic)Circuits.farmInfernalManaged).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.farmSucculentManaged = new CircuitFarmLogic("managedSucculent", succulentFarm, false);
|
||||
Circuits.farmSucculentManual = new CircuitFarmLogic("manualSucculent", succulentFarm, true);
|
||||
succulentFarm.registerSoil(new ItemStack(Blocks.SAND), Blocks.SAND.getDefaultState(),true);
|
||||
|
||||
Circuits.farmPoalesManaged = new CircuitFarmLogic("managedPoales", poalesFarm, false);
|
||||
Circuits.farmPoalesManual = new CircuitFarmLogic("manualPoales", poalesFarm, true);
|
||||
poalesFarm.registerSoil(new ItemStack(Blocks.SAND), Blocks.SAND.getDefaultState(),true);
|
||||
poalesFarm.registerSoil(new ItemStack(Blocks.DIRT), Blocks.DIRT.getDefaultState(),false);
|
||||
|
||||
Circuits.farmGourdManaged = new CircuitFarmLogic("managedGourd", gourdFarm, false);
|
||||
Circuits.farmGourdManual = new CircuitFarmLogic("manualGourd", gourdFarm, true);
|
||||
|
||||
Circuits.farmCocoaManaged = new CircuitFarmLogic("managedCocoa", cocoaFarm, false);
|
||||
Circuits.farmCocoaManual = new CircuitFarmLogic("manualCocoa", cocoaFarm, true);
|
||||
|
||||
Circuits.farmEnderManaged = new CircuitFarmLogic("managedEnder", enderFarm, false);
|
||||
Circuits.farmEnderManual = new CircuitFarmLogic("manualEnder", enderFarm, true);
|
||||
enderFarm.registerSoil(new ItemStack(Blocks.END_STONE), Blocks.END_STONE.getDefaultState());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -275,22 +311,32 @@ public class ModuleFarming extends BlankForestryModule {
|
||||
ICircuitLayout layoutManaged = ChipsetManager.circuitRegistry.getLayout("forestry.farms.managed");
|
||||
ICircuitLayout layoutManual = ChipsetManager.circuitRegistry.getLayout("forestry.farms.manual");
|
||||
|
||||
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.farmCerealManaged);
|
||||
ChipsetManager.solderManager.addRecipe(layoutManaged, coreItems.tubes.get(EnumElectronTube.IRON, 1), Circuits.farmVegetableManaged);
|
||||
ChipsetManager.solderManager.addRecipe(layoutManaged, coreItems.tubes.get(EnumElectronTube.BLAZE, 1), Circuits.farmInfernalManaged);
|
||||
ChipsetManager.solderManager.addRecipe(layoutManaged, coreItems.tubes.get(EnumElectronTube.APATITE, 1), Circuits.farmShroomManaged);
|
||||
if(layoutManaged == null || layoutManual == null){
|
||||
return;
|
||||
}
|
||||
|
||||
ChipsetManager.solderManager.addRecipe(layoutManual, coreItems.tubes.get(EnumElectronTube.COPPER, 1), Circuits.farmOrchardManual);
|
||||
ChipsetManager.solderManager.addRecipe(layoutManual, coreItems.tubes.get(EnumElectronTube.TIN, 1), Circuits.farmPeatManual);
|
||||
ChipsetManager.solderManager.addRecipe(layoutManual, coreItems.tubes.get(EnumElectronTube.BRONZE, 1), Circuits.farmCerealManual);
|
||||
ChipsetManager.solderManager.addRecipe(layoutManual, coreItems.tubes.get(EnumElectronTube.IRON, 1), Circuits.farmVegetableManual);
|
||||
ChipsetManager.solderManager.addRecipe(layoutManual, coreItems.tubes.get(EnumElectronTube.GOLD, 1), Circuits.farmSucculentManual);
|
||||
ChipsetManager.solderManager.addRecipe(layoutManual, coreItems.tubes.get(EnumElectronTube.DIAMOND, 1), Circuits.farmPoalesManual);
|
||||
ChipsetManager.solderManager.addRecipe(layoutManual, coreItems.tubes.get(EnumElectronTube.OBSIDIAN, 1), Circuits.farmGourdManual);
|
||||
ChipsetManager.solderManager.addRecipe(layoutManaged, coreItems.tubes.get(EnumElectronTube.GOLD, 1), Circuits.farmArborealManaged);
|
||||
ChipsetManager.solderManager.addRecipe(layoutManaged, coreItems.tubes.get(EnumElectronTube.COPPER, 1), Circuits.farmSucculentManaged);
|
||||
ChipsetManager.solderManager.addRecipe(layoutManaged, coreItems.tubes.get(EnumElectronTube.OBSIDIAN, 1), Circuits.farmPeatManaged);
|
||||
ChipsetManager.solderManager.addRecipe(layoutManaged, coreItems.tubes.get(EnumElectronTube.BRONZE, 1), Circuits.farmCropsManaged);
|
||||
ChipsetManager.solderManager.addRecipe(layoutManaged, coreItems.tubes.get(EnumElectronTube.BLAZE, 1), Circuits.farmInfernalManaged);
|
||||
ChipsetManager.solderManager.addRecipe(layoutManaged, coreItems.tubes.get(EnumElectronTube.TIN, 1), Circuits.farmPoalesManual);
|
||||
ChipsetManager.solderManager.addRecipe(layoutManaged, coreItems.tubes.get(EnumElectronTube.LAPIS, 1), Circuits.farmGourdManaged);
|
||||
ChipsetManager.solderManager.addRecipe(layoutManaged, coreItems.tubes.get(EnumElectronTube.APATITE, 1), Circuits.farmShroomManaged);
|
||||
ChipsetManager.solderManager.addRecipe(layoutManaged, coreItems.tubes.get(EnumElectronTube.DIAMOND, 1), Circuits.farmCocoaManaged);
|
||||
ChipsetManager.solderManager.addRecipe(layoutManaged, coreItems.tubes.get(EnumElectronTube.EMERALD, 1), Circuits.farmOrchardManaged);
|
||||
ChipsetManager.solderManager.addRecipe(layoutManaged, coreItems.tubes.get(EnumElectronTube.ENDER, 1), Circuits.farmEnderManaged);
|
||||
|
||||
ChipsetManager.solderManager.addRecipe(layoutManual, coreItems.tubes.get(EnumElectronTube.GOLD, 1), Circuits.farmArborealManual);
|
||||
ChipsetManager.solderManager.addRecipe(layoutManual, coreItems.tubes.get(EnumElectronTube.COPPER, 1), Circuits.farmSucculentManual);
|
||||
ChipsetManager.solderManager.addRecipe(layoutManual, coreItems.tubes.get(EnumElectronTube.OBSIDIAN, 1), Circuits.farmPeatManual);
|
||||
ChipsetManager.solderManager.addRecipe(layoutManual, coreItems.tubes.get(EnumElectronTube.BRONZE, 1), Circuits.farmCropsManual);
|
||||
ChipsetManager.solderManager.addRecipe(layoutManual, coreItems.tubes.get(EnumElectronTube.TIN, 1), Circuits.farmPoalesManual);
|
||||
ChipsetManager.solderManager.addRecipe(layoutManual, coreItems.tubes.get(EnumElectronTube.LAPIS, 1), Circuits.farmGourdManual);
|
||||
ChipsetManager.solderManager.addRecipe(layoutManual, coreItems.tubes.get(EnumElectronTube.APATITE, 1), Circuits.farmShroomManual);
|
||||
ChipsetManager.solderManager.addRecipe(layoutManual, coreItems.tubes.get(EnumElectronTube.LAPIS, 1), Circuits.farmCocoaManual);
|
||||
ChipsetManager.solderManager.addRecipe(layoutManual, coreItems.tubes.get(EnumElectronTube.DIAMOND, 1), Circuits.farmCocoaManual);
|
||||
ChipsetManager.solderManager.addRecipe(layoutManual, coreItems.tubes.get(EnumElectronTube.EMERALD, 1), Circuits.farmOrchardManual);
|
||||
ChipsetManager.solderManager.addRecipe(layoutManual, coreItems.tubes.get(EnumElectronTube.ENDER, 1), Circuits.farmEnderManual);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -15,6 +15,7 @@ import javax.annotation.Nullable;
|
||||
import forestry.api.farming.FarmDirection;
|
||||
import forestry.api.farming.IFarmHousing;
|
||||
import forestry.api.farming.IFarmLogic;
|
||||
import forestry.api.farming.IFarmProperties;
|
||||
import forestry.core.circuits.Circuit;
|
||||
|
||||
public class CircuitFarmLogic extends Circuit {
|
||||
@@ -22,15 +23,38 @@ public class CircuitFarmLogic extends Circuit {
|
||||
private final IFarmLogic logic;
|
||||
private boolean isManual = false;
|
||||
|
||||
public CircuitFarmLogic(String uid, IFarmProperties instance, boolean manual) {
|
||||
super(uid);
|
||||
this.logic = instance.getLogic(manual);
|
||||
}
|
||||
|
||||
public CircuitFarmLogic(String uid, IFarmLogic logic) {
|
||||
super(uid);
|
||||
this.logic = logic;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getUnlocalizedName() {
|
||||
return logic.getUnlocalizedName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getLocalizedName() {
|
||||
return logic.getName();
|
||||
}
|
||||
|
||||
/**
|
||||
* @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;
|
||||
|
||||
@@ -10,17 +10,19 @@
|
||||
******************************************************************************/
|
||||
package forestry.farming.gui;
|
||||
|
||||
import forestry.api.farming.FarmDirection;
|
||||
import forestry.api.farming.IFarmLogic;
|
||||
import forestry.core.gui.tooltips.ToolTip;
|
||||
import forestry.core.gui.widgets.Widget;
|
||||
import forestry.core.gui.widgets.WidgetManager;
|
||||
import forestry.farming.multiblock.IFarmControllerInternal;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.renderer.RenderItem;
|
||||
import net.minecraft.client.renderer.texture.TextureManager;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import forestry.api.farming.FarmDirection;
|
||||
import forestry.api.farming.IFarmLogic;
|
||||
import forestry.core.config.Config;
|
||||
import forestry.core.gui.tooltips.ToolTip;
|
||||
import forestry.core.gui.widgets.Widget;
|
||||
import forestry.core.gui.widgets.WidgetManager;
|
||||
import forestry.farming.multiblock.IFarmControllerInternal;
|
||||
|
||||
public class FarmLogicSlot extends Widget {
|
||||
|
||||
private final IFarmControllerInternal farmController;
|
||||
@@ -65,7 +67,7 @@ public class FarmLogicSlot extends Widget {
|
||||
public void refresh() {
|
||||
toolTip.clear();
|
||||
toolTip.add(getLogic().getName());
|
||||
toolTip.add("Fertilizer: " + getLogic().getFertilizerConsumption());
|
||||
toolTip.add("Fertilizer: " + Math.round(getLogic().getFertilizerConsumption() * Config.fertilizerModifier));
|
||||
toolTip.add("Water: " + getLogic().getWaterConsumption(farmController.getFarmLedgerDelegate().getHydrationModifier()));
|
||||
}
|
||||
};
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
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.IFarmLogic;
|
||||
import forestry.api.farming.IFarmProperties;
|
||||
import forestry.api.farming.IFarmable;
|
||||
import forestry.api.farming.ISoil;
|
||||
|
||||
public class FakeFarmProperties implements IFarmProperties {
|
||||
private final IFarmLogic logic;
|
||||
|
||||
public FakeFarmProperties(IFarmLogic logic) {
|
||||
this.logic = logic;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerFarmables(String identifier) {
|
||||
}
|
||||
|
||||
@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 Collection<ISoil> getSoils() {
|
||||
return Collections.emptySet();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<IFarmable> getFarmables() {
|
||||
return Collections.emptySet();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IFarmLogic getLogic(boolean manuel) {
|
||||
return logic;
|
||||
}
|
||||
}
|
||||
@@ -13,47 +13,87 @@ 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.IFarmLogic;
|
||||
import forestry.api.farming.IFarmProperties;
|
||||
import forestry.api.farming.IFarmable;
|
||||
import forestry.api.farming.ISoil;
|
||||
import forestry.core.utils.Translator;
|
||||
import forestry.core.utils.VectUtil;
|
||||
|
||||
public abstract class FarmLogic implements IFarmLogic {
|
||||
private final EntitySelectorFarm entitySelectorFarm = new EntitySelectorFarm(this);
|
||||
protected boolean isManual;
|
||||
protected final IFarmProperties properties;
|
||||
protected final boolean isManual;
|
||||
|
||||
public FarmLogic(IFarmProperties properties, boolean isManual) {
|
||||
this.properties = properties;
|
||||
this.isManual = isManual;
|
||||
}
|
||||
|
||||
protected Collection<IFarmable> getFarmables() {
|
||||
return properties.getFarmables();
|
||||
}
|
||||
|
||||
protected Collection<ISoil> getSoils() {
|
||||
return properties.getSoils();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
String unformatted = isManual ? "for.farm.grammar.manual" : "for.farm.grammar.managed";
|
||||
return Translator.translateToLocalFormatted(unformatted, Translator.translateToLocal(getUnlocalizedName()));
|
||||
}
|
||||
|
||||
@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);
|
||||
ICrop crop = getCrop(world, position);
|
||||
if (crop != null) {
|
||||
crops.push(crop);
|
||||
}
|
||||
}
|
||||
return crops;
|
||||
}
|
||||
|
||||
@Override
|
||||
public abstract ItemStack getIconItemStack();
|
||||
@Nullable
|
||||
protected ICrop getCrop(World world, BlockPos position) {
|
||||
if (world.isAirBlock(position)) {
|
||||
return null;
|
||||
}
|
||||
IBlockState blockState = world.getBlockState(position);
|
||||
for (IFarmable seed : getFarmables()) {
|
||||
ICrop crop = seed.getCropAt(world, position, blockState);
|
||||
if (crop != null) {
|
||||
return crop;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public abstract boolean isAcceptedWindfall(ItemStack stack);
|
||||
|
||||
@@ -96,6 +136,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,15 +158,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);
|
||||
}
|
||||
}
|
||||
|
||||
// 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,22 +31,29 @@ import net.minecraft.world.World;
|
||||
import forestry.api.farming.FarmDirection;
|
||||
import forestry.api.farming.ICrop;
|
||||
import forestry.api.farming.IFarmHousing;
|
||||
import forestry.api.farming.IFarmProperties;
|
||||
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);
|
||||
}
|
||||
|
||||
public FarmLogicArboreal() {
|
||||
super(new ItemStack(Blocks.DIRT), ModuleCore.getBlocks().humus.getDefaultState(), FarmRegistry.getInstance().getFarmables("farmArboreal"));
|
||||
@Nullable
|
||||
private List<IFarmable> farmables;
|
||||
|
||||
public FarmLogicArboreal(IFarmProperties properties, boolean isManual) {
|
||||
super(properties, isManual);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "Managed Arboretum";
|
||||
public List<IFarmable> getFarmables() {
|
||||
if (farmables == null) {
|
||||
this.farmables = new ArrayList<>(properties.getFarmables());
|
||||
}
|
||||
return farmables;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUnlocalizedName() {
|
||||
return "for.farm.arboretum";
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -73,7 +82,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 +101,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 +134,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);
|
||||
@@ -145,17 +156,17 @@ public class FarmLogicArboreal extends FarmLogicHomogeneous {
|
||||
BlockPos soilPosition = position.down();
|
||||
IBlockState soilState = world.getBlockState(soilPosition);
|
||||
if (isAcceptedSoil(soilState)) {
|
||||
return plantSapling(world, farmHousing, position);
|
||||
return plantSapling(world, farmHousing, position, direction);
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean plantSapling(World world, IFarmHousing farmHousing, BlockPos position) {
|
||||
private boolean plantSapling(World world, IFarmHousing farmHousing, BlockPos position, FarmDirection direction) {
|
||||
Collections.shuffle(farmables);
|
||||
for (IFarmable candidate : farmables) {
|
||||
if (farmHousing.plantGermling(candidate, world, position)) {
|
||||
for (IFarmable candidate : getFarmables()) {
|
||||
if (farmHousing.plantGermling(candidate, world, position, direction)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,37 +0,0 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2011-2014 SirSengir.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the GNU Lesser Public License v3
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.gnu.org/licenses/lgpl-3.0.txt
|
||||
*
|
||||
* Various Contributors including, but not limited to:
|
||||
* SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges
|
||||
******************************************************************************/
|
||||
package forestry.farming.logic;
|
||||
|
||||
import net.minecraft.init.Items;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import forestry.api.core.ForestryAPI;
|
||||
|
||||
public class FarmLogicCereal extends FarmLogicCrops {
|
||||
|
||||
public FarmLogicCereal() {
|
||||
super(ForestryAPI.farmRegistry.getFarmables("farmWheat"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
if (isManual) {
|
||||
return "Manual Farm";
|
||||
} else {
|
||||
return "Managed Farm";
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getIconItemStack() {
|
||||
return new ItemStack(Items.WHEAT);
|
||||
}
|
||||
}
|
||||
@@ -34,19 +34,25 @@ import net.minecraft.world.World;
|
||||
import forestry.api.farming.FarmDirection;
|
||||
import forestry.api.farming.ICrop;
|
||||
import forestry.api.farming.IFarmHousing;
|
||||
import forestry.api.farming.IFarmProperties;
|
||||
import forestry.api.farming.IFarmable;
|
||||
import forestry.farming.logic.farmables.FarmableCocoa;
|
||||
|
||||
public class FarmLogicCocoa extends FarmLogic {
|
||||
private final IFarmable cocoa = new FarmableCocoa();
|
||||
|
||||
public FarmLogicCocoa(IFarmProperties properties, boolean isManual) {
|
||||
super(properties, isManual);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getIconItemStack() {
|
||||
return new ItemStack(Items.DYE, 1, 3);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "Cocoa Plantation";
|
||||
public String getUnlocalizedName() {
|
||||
return "for.farm.cocoa";
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -73,11 +79,6 @@ public class FarmLogicCocoa extends FarmLogic {
|
||||
public boolean isAcceptedWindfall(ItemStack stack) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addSoil(ItemStack resource, IBlockState soilState, boolean hasMetaData) {
|
||||
// do nothing as soil is not managed by farm
|
||||
}
|
||||
|
||||
@Override
|
||||
public NonNullList<ItemStack> collect(World world, IFarmHousing farmHousing) {
|
||||
@@ -88,7 +89,6 @@ public class FarmLogicCocoa extends FarmLogic {
|
||||
|
||||
@Override
|
||||
public boolean cultivate(World world, IFarmHousing farmHousing, BlockPos pos, FarmDirection direction, int extent) {
|
||||
|
||||
if (!lastExtentsCultivation.containsKey(pos)) {
|
||||
lastExtentsCultivation.put(pos, 0);
|
||||
}
|
||||
@@ -99,7 +99,7 @@ public class FarmLogicCocoa extends FarmLogic {
|
||||
}
|
||||
|
||||
BlockPos position = translateWithOffset(pos.up(), direction, lastExtent);
|
||||
boolean result = tryPlantingCocoa(world, farmHousing, position);
|
||||
boolean result = tryPlantingCocoa(world, farmHousing, position, direction);
|
||||
|
||||
lastExtent++;
|
||||
lastExtentsCultivation.put(pos, lastExtent);
|
||||
@@ -128,14 +128,14 @@ public class FarmLogicCocoa extends FarmLogic {
|
||||
return crops;
|
||||
}
|
||||
|
||||
private boolean tryPlantingCocoa(World world, IFarmHousing farmHousing, BlockPos position) {
|
||||
private boolean tryPlantingCocoa(World world, IFarmHousing farmHousing, BlockPos position, FarmDirection farmDirection) {
|
||||
BlockPos.MutableBlockPos current = new BlockPos.MutableBlockPos(position);
|
||||
IBlockState blockState = world.getBlockState(current);
|
||||
while (isJungleTreeTrunk(blockState)) {
|
||||
for (EnumFacing direction : EnumFacing.HORIZONTALS) {
|
||||
BlockPos candidate = new BlockPos(current.getX() + direction.getFrontOffsetX(), current.getY(), current.getZ() + direction.getFrontOffsetZ());
|
||||
if (world.isAirBlock(candidate)) {
|
||||
return farmHousing.plantGermling(cocoa, world, candidate);
|
||||
return farmHousing.plantGermling(cocoa, world, candidate, farmDirection);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -10,39 +10,28 @@
|
||||
******************************************************************************/
|
||||
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;
|
||||
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.IFarmProperties;
|
||||
import forestry.api.farming.IFarmable;
|
||||
import forestry.core.utils.BlockUtil;
|
||||
|
||||
public abstract class FarmLogicCrops extends FarmLogicWatered {
|
||||
private final Iterable<IFarmable> seeds;
|
||||
public class FarmLogicCrops extends FarmLogicWatered {
|
||||
|
||||
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(IFarmProperties properties, boolean isManual) {
|
||||
super(properties, isManual);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAcceptedGermling(ItemStack itemstack) {
|
||||
for (IFarmable germling : seeds) {
|
||||
for (IFarmable germling : getFarmables()) {
|
||||
if (germling.isGermling(itemstack)) {
|
||||
return true;
|
||||
}
|
||||
@@ -52,7 +41,7 @@ public abstract class FarmLogicCrops extends FarmLogicWatered {
|
||||
|
||||
@Override
|
||||
public boolean isAcceptedWindfall(ItemStack itemstack) {
|
||||
for (IFarmable germling : seeds) {
|
||||
for (IFarmable germling : getFarmables()) {
|
||||
if (germling.isWindfall(itemstack)) {
|
||||
return true;
|
||||
}
|
||||
@@ -77,17 +66,17 @@ public abstract class FarmLogicCrops extends FarmLogicWatered {
|
||||
}
|
||||
|
||||
IBlockState groundState = world.getBlockState(position.down());
|
||||
if (isAcceptedGround(groundState)) {
|
||||
return trySetCrop(world, farmHousing, position);
|
||||
if (isAcceptedSoil(groundState)) {
|
||||
return trySetCrop(world, farmHousing, position, direction);
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean trySetCrop(World world, IFarmHousing farmHousing, BlockPos position) {
|
||||
for (IFarmable candidate : seeds) {
|
||||
if (farmHousing.plantGermling(candidate, world, position)) {
|
||||
private boolean trySetCrop(World world, IFarmHousing farmHousing, BlockPos position, FarmDirection direction) {
|
||||
for (IFarmable candidate : getFarmables()) {
|
||||
if (farmHousing.plantGermling(candidate, world, position, direction)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -96,20 +85,12 @@ public abstract class FarmLogicCrops extends FarmLogicWatered {
|
||||
}
|
||||
|
||||
@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;
|
||||
public ItemStack getIconItemStack() {
|
||||
return new ItemStack(Items.WHEAT);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUnlocalizedName() {
|
||||
return "for.farm.crops";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,154 @@
|
||||
package forestry.farming.logic;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
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.EnumFacing;
|
||||
import net.minecraft.util.NonNullList;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import forestry.api.farming.FarmDirection;
|
||||
import forestry.api.farming.ICrop;
|
||||
import forestry.api.farming.IFarmHousing;
|
||||
import forestry.api.farming.IFarmProperties;
|
||||
import forestry.api.farming.IFarmable;
|
||||
import forestry.core.utils.BlockUtil;
|
||||
import forestry.farming.logic.crops.CropDestroy;
|
||||
import forestry.farming.logic.farmables.FarmableChorus;
|
||||
|
||||
public class FarmLogicEnder extends FarmLogicHomogeneous {
|
||||
private static final Set<EnumFacing> VALID_DIRECTIONS = ImmutableSet.of(EnumFacing.UP, EnumFacing.NORTH, EnumFacing.SOUTH, EnumFacing.WEST, EnumFacing.EAST);
|
||||
private final IFarmable chorusFarmable;
|
||||
|
||||
public FarmLogicEnder(IFarmProperties properties, boolean isManual) {
|
||||
super(properties, isManual);
|
||||
chorusFarmable = FarmableChorus.INSTANCE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUnlocalizedName() {
|
||||
return "for.farm.ender";
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getIconItemStack() {
|
||||
return new ItemStack(Items.ENDER_EYE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getFertilizerConsumption() {
|
||||
return 20;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getWaterConsumption(float hydrationModifier) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NonNullList<ItemStack> collect(World world, IFarmHousing farmHousing) {
|
||||
NonNullList<ItemStack> products = produce;
|
||||
produce = collectEntityItems(world, farmHousing, true);
|
||||
return products;
|
||||
}
|
||||
|
||||
private final Map<BlockPos, Integer> lastExtentsHarvest = new HashMap<>();
|
||||
|
||||
@Override
|
||||
public Collection<ICrop> harvest(World world, BlockPos pos, FarmDirection direction, int extent) {
|
||||
if (!lastExtentsHarvest.containsKey(pos)) {
|
||||
lastExtentsHarvest.put(pos, 0);
|
||||
}
|
||||
|
||||
int lastExtent = lastExtentsHarvest.get(pos);
|
||||
if (lastExtent > extent) {
|
||||
lastExtent = 0;
|
||||
}
|
||||
|
||||
BlockPos position = translateWithOffset(pos.up(), direction, lastExtent);
|
||||
Collection<ICrop> crops = harvestBlocks(world, position);
|
||||
lastExtent++;
|
||||
lastExtentsHarvest.put(pos, lastExtent);
|
||||
|
||||
return crops;
|
||||
}
|
||||
|
||||
private Collection<ICrop> harvestBlocks(World world, BlockPos position) {
|
||||
if (world.isAirBlock(position)) {
|
||||
return Collections.emptySet();
|
||||
}
|
||||
|
||||
ICrop crop = getCrop(world, position);
|
||||
if (crop != null) {
|
||||
return Collections.singleton(crop);
|
||||
}
|
||||
|
||||
Stack<ICrop> crops = new Stack<>();
|
||||
Stack<ICrop> plants = new Stack<>();
|
||||
harvestBlock(world, position, EnumFacing.DOWN, plants, crops);
|
||||
//Remove all flowers before remove all plants
|
||||
if (!crops.isEmpty()) {
|
||||
return crops;
|
||||
}
|
||||
return plants;
|
||||
}
|
||||
|
||||
private boolean harvestBlock(World world, BlockPos pos, EnumFacing from, Stack<ICrop> plants, Stack<ICrop> flowers) {
|
||||
IBlockState blockState = world.getBlockState(pos);
|
||||
if (blockState.getBlock() == Blocks.CHORUS_FLOWER) {
|
||||
ICrop crop = chorusFarmable.getCropAt(world, pos, blockState);
|
||||
if (crop != null) {
|
||||
flowers.push(crop);
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
} else if (blockState.getBlock() == Blocks.CHORUS_PLANT) {
|
||||
boolean canHarvest = true;
|
||||
for (EnumFacing facing : VALID_DIRECTIONS) {
|
||||
if (facing == from) {
|
||||
continue;
|
||||
}
|
||||
canHarvest &= harvestBlock(world, pos.offset(facing), facing.getOpposite(), plants, flowers);
|
||||
}
|
||||
if (canHarvest) {
|
||||
plants.push(new CropDestroy(world, Blocks.CHORUS_PLANT.getDefaultState(), pos, null));
|
||||
}
|
||||
return canHarvest;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean maintainGermlings(World world, IFarmHousing farmHousing, BlockPos pos, FarmDirection direction, int extent) {
|
||||
for (int i = 0; i < extent; i++) {
|
||||
BlockPos position = translateWithOffset(pos, direction, i);
|
||||
IBlockState state = world.getBlockState(position);
|
||||
if (!world.isAirBlock(position) && !BlockUtil.isReplaceableBlock(state, world, position)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
BlockPos soilPos = position.down();
|
||||
IBlockState blockState = world.getBlockState(soilPos);
|
||||
if (!isAcceptedSoil(blockState)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (trySetCrop(world, farmHousing, position, direction)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -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.IFarmProperties;
|
||||
|
||||
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(IFarmProperties properties, boolean isManual) {
|
||||
super(properties, isManual);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -41,8 +32,8 @@ public class FarmLogicGourd extends FarmLogic {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "Gourd Farm";
|
||||
public String getUnlocalizedName() {
|
||||
return "for.farm.gourd";
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -79,27 +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;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addSoil(ItemStack resource, IBlockState soilState, boolean hasMetaData) {
|
||||
// do nothing as soil is not managed by farm
|
||||
|
||||
}
|
||||
}
|
||||
@@ -10,65 +10,29 @@
|
||||
******************************************************************************/
|
||||
package forestry.farming.logic;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import forestry.api.farming.FarmDirection;
|
||||
import forestry.api.farming.IFarmHousing;
|
||||
import forestry.api.farming.IFarmable;
|
||||
import forestry.core.utils.BlockUtil;
|
||||
import forestry.farming.FarmHelper;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.NonNullList;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public abstract class FarmLogicHomogeneous extends FarmLogic {
|
||||
|
||||
private final List<Soil> soils = new ArrayList<>();
|
||||
protected final List<IFarmable> farmables;
|
||||
import forestry.api.farming.FarmDirection;
|
||||
import forestry.api.farming.IFarmHousing;
|
||||
import forestry.api.farming.IFarmProperties;
|
||||
import forestry.api.farming.IFarmable;
|
||||
import forestry.api.farming.ISoil;
|
||||
import forestry.core.utils.BlockUtil;
|
||||
|
||||
public abstract class FarmLogicHomogeneous extends FarmLogicSoil {
|
||||
protected NonNullList<ItemStack> produce = NonNullList.create();
|
||||
|
||||
protected FarmLogicHomogeneous(ItemStack resource, IBlockState soilState, Collection<IFarmable> farmables) {
|
||||
addSoil(resource, soilState, false);
|
||||
this.farmables = new ArrayList<>(farmables);
|
||||
}
|
||||
|
||||
public void addSoil(ItemStack resource, IBlockState soilState, boolean hasMetaData){
|
||||
soils.add(new Soil(resource, soilState, hasMetaData));
|
||||
}
|
||||
|
||||
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(IFarmProperties properties, boolean isManual) {
|
||||
super(properties, isManual);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAcceptedGermling(ItemStack itemstack) {
|
||||
for (IFarmable germling : farmables) {
|
||||
for (IFarmable germling : getFarmables()) {
|
||||
if (germling.isGermling(itemstack)) {
|
||||
return true;
|
||||
}
|
||||
@@ -78,7 +42,7 @@ public abstract class FarmLogicHomogeneous extends FarmLogic {
|
||||
|
||||
@Override
|
||||
public boolean isAcceptedWindfall(ItemStack itemstack) {
|
||||
for (IFarmable germling : farmables) {
|
||||
for (IFarmable germling : getFarmables()) {
|
||||
if (germling.isWindfall(itemstack)) {
|
||||
return true;
|
||||
}
|
||||
@@ -86,40 +50,52 @@ public abstract class FarmLogicHomogeneous extends FarmLogic {
|
||||
return false;
|
||||
}
|
||||
|
||||
protected boolean trySetCrop(World world, IFarmHousing farmHousing, BlockPos position, FarmDirection direction) {
|
||||
for (IFarmable candidate : getFarmables()) {
|
||||
if (farmHousing.plantGermling(candidate, world, position, direction)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public 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);
|
||||
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 (FarmHelper.bricks.contains(soilState.getBlock())) {
|
||||
|
||||
if (farmHousing.isValidPlatform(world, pos)) {
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
if (isAcceptedSoil(soilState)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
BlockPos platformPosition = position.down();
|
||||
IBlockState platformState = world.getBlockState(platformPosition);
|
||||
if (!FarmHelper.bricks.contains(platformState.getBlock())) {
|
||||
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,19 +23,19 @@ import net.minecraft.world.World;
|
||||
import forestry.api.farming.FarmDirection;
|
||||
import forestry.api.farming.ICrop;
|
||||
import forestry.api.farming.IFarmHousing;
|
||||
import forestry.api.farming.IFarmProperties;
|
||||
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(IFarmProperties properties, boolean isManual) {
|
||||
super(properties, isManual);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "Managed Infernal Farm";
|
||||
public String getUnlocalizedName() {
|
||||
return "for.farm.infernal";
|
||||
}
|
||||
|
||||
@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);
|
||||
@@ -90,17 +92,7 @@ public class FarmLogicInfernal extends FarmLogicHomogeneous {
|
||||
BlockPos soilPosition = position.down();
|
||||
IBlockState soilState = world.getBlockState(soilPosition);
|
||||
if (isAcceptedSoil(soilState)) {
|
||||
return trySetCrop(world, farmHousing, position);
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean trySetCrop(World world, IFarmHousing farmHousing, BlockPos position) {
|
||||
for (IFarmable candidate : farmables) {
|
||||
if (farmHousing.plantGermling(candidate, world, position)) {
|
||||
return true;
|
||||
return trySetCrop(world, farmHousing, position, direction);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -15,23 +15,17 @@ 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.IFarmProperties;
|
||||
|
||||
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(IFarmProperties properties, boolean isManual) {
|
||||
super(properties, isManual);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
if (isManual) {
|
||||
return "Manual Shroom Farm";
|
||||
} else {
|
||||
return "Managed Shroom Farm";
|
||||
}
|
||||
public String getUnlocalizedName() {
|
||||
return "for.farm.shroom";
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -28,23 +28,23 @@ 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.IFarmProperties;
|
||||
import forestry.api.farming.IFarmable;
|
||||
import forestry.api.genetics.IFruitBearer;
|
||||
import forestry.core.ModuleCore;
|
||||
import forestry.core.tiles.TileUtil;
|
||||
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(IFarmProperties properties, boolean isManual) {
|
||||
super(properties, 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)) {
|
||||
@@ -63,8 +63,6 @@ public class FarmLogicOrchard extends FarmLogic {
|
||||
// traversalBlocksBuilder.add(grapeVine);
|
||||
// }
|
||||
// }
|
||||
|
||||
traversalBlocksBuilder.build();
|
||||
this.traversalBlocks = traversalBlocksBuilder.build();
|
||||
}
|
||||
|
||||
@@ -105,7 +103,6 @@ public class FarmLogicOrchard extends FarmLogic {
|
||||
|
||||
@Override
|
||||
public Collection<ICrop> harvest(World world, BlockPos pos, FarmDirection direction, int extent) {
|
||||
|
||||
if (!lastExtents.containsKey(pos)) {
|
||||
lastExtents.put(pos, 0);
|
||||
}
|
||||
@@ -129,13 +126,8 @@ public class FarmLogicOrchard extends FarmLogic {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "Orchard";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addSoil(ItemStack resource, IBlockState soilState, boolean hasMetaData) {
|
||||
// do nothing as soil is not managed by farm
|
||||
public String getUnlocalizedName() {
|
||||
return "for.farm.orchard";
|
||||
}
|
||||
|
||||
private Collection<ICrop> getHarvestBlocks(World world, BlockPos position) {
|
||||
@@ -145,7 +137,7 @@ public class FarmLogicOrchard extends FarmLogic {
|
||||
// Determine what type we want to harvest.
|
||||
IBlockState blockState = world.getBlockState(position);
|
||||
Block block = blockState.getBlock();
|
||||
if (!block.isWood(world, position) && !isBlockTraversable(blockState, traversalBlocks) && !isFruitBearer(world, position)) {
|
||||
if (!block.isWood(world, position) && !isBlockTraversable(blockState, traversalBlocks) && !isFruitBearer(world, position, blockState)) {
|
||||
return crops;
|
||||
}
|
||||
|
||||
@@ -192,11 +184,11 @@ public class FarmLogicOrchard extends FarmLogic {
|
||||
candidates.add(candidate);
|
||||
seen.add(candidate);
|
||||
}
|
||||
if (isFruitBearer(world, candidate)) {
|
||||
if (isFruitBearer(world, candidate, blockState)) {
|
||||
candidates.add(candidate);
|
||||
seen.add(candidate);
|
||||
|
||||
ICrop crop = getCrop(world, candidate);
|
||||
ICrop crop = getCropAt(world, candidate);
|
||||
if (crop != null) {
|
||||
crops.push(crop);
|
||||
}
|
||||
@@ -208,14 +200,14 @@ public class FarmLogicOrchard extends FarmLogic {
|
||||
return candidates;
|
||||
}
|
||||
|
||||
private boolean isFruitBearer(World world, BlockPos position) {
|
||||
private boolean isFruitBearer(World world, BlockPos position, IBlockState blockState) {
|
||||
IFruitBearer tile = TileUtil.getTile(world, position, IFruitBearer.class);
|
||||
if (tile != null) {
|
||||
return true;
|
||||
}
|
||||
|
||||
for (IFarmable farmable : farmables) {
|
||||
if (farmable.isSaplingAt(world, position)) {
|
||||
for (IFarmable farmable : getFarmables()) {
|
||||
if (farmable.isSaplingAt(world, position, blockState)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -234,8 +226,7 @@ public class FarmLogicOrchard extends FarmLogic {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private ICrop getCrop(World world, BlockPos position) {
|
||||
|
||||
private ICrop getCropAt(World world, BlockPos position) {
|
||||
IFruitBearer fruitBearer = TileUtil.getTile(world, position, IFruitBearer.class);
|
||||
|
||||
if (fruitBearer != null) {
|
||||
@@ -243,13 +234,7 @@ public class FarmLogicOrchard extends FarmLogic {
|
||||
return new CropFruit(world, position);
|
||||
}
|
||||
} else {
|
||||
IBlockState blockState = world.getBlockState(position);
|
||||
for (IFarmable seed : farmables) {
|
||||
ICrop crop = seed.getCropAt(world, position, blockState);
|
||||
if (crop != null) {
|
||||
return crop;
|
||||
}
|
||||
}
|
||||
return getCrop(world, position);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -21,23 +21,14 @@ import net.minecraft.world.World;
|
||||
|
||||
import forestry.api.farming.FarmDirection;
|
||||
import forestry.api.farming.ICrop;
|
||||
import forestry.api.farming.IFarmProperties;
|
||||
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(IFarmProperties properties, boolean isManual) {
|
||||
super(properties, isManual);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -46,12 +37,8 @@ public class FarmLogicPeat extends FarmLogicWatered {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
if (isManual) {
|
||||
return "Manual Peat Bog";
|
||||
} else {
|
||||
return "Managed Peat Bog";
|
||||
}
|
||||
public String getUnlocalizedName() {
|
||||
return "for.farm.peat";
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+10
-55
@@ -10,47 +10,32 @@
|
||||
******************************************************************************/
|
||||
package forestry.farming.logic;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Stack;
|
||||
|
||||
import forestry.farming.FarmRegistry;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.init.Items;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.NonNullList;
|
||||
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.IFarmProperties;
|
||||
import forestry.core.utils.BlockUtil;
|
||||
import forestry.plugins.PluginExtraUtilities;
|
||||
|
||||
public class FarmLogicExU extends FarmLogicHomogeneous {
|
||||
public class FarmLogicRedOrchid 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);
|
||||
}
|
||||
this.name = name;
|
||||
this.iconItem = iconItem;
|
||||
public FarmLogicRedOrchid(IFarmProperties properties, boolean isManual) {
|
||||
super(properties, isManual);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return name;
|
||||
public String getUnlocalizedName() {
|
||||
return "for.farm.orchid";
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getIconItemStack() {
|
||||
return new ItemStack(iconItem);
|
||||
return PluginExtraUtilities.orchidStack;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -68,25 +53,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++) {
|
||||
@@ -102,20 +68,9 @@ public class FarmLogicExU extends FarmLogicHomogeneous {
|
||||
continue;
|
||||
}
|
||||
|
||||
return trySetCrop(world, farmHousing, position);
|
||||
return trySetCrop(world, farmHousing, position, direction);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean trySetCrop(World world, IFarmHousing farmHousing, BlockPos position) {
|
||||
for (IFarmable candidate : farmables) {
|
||||
if (farmHousing.plantGermling(candidate, world, position)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -10,45 +10,19 @@
|
||||
******************************************************************************/
|
||||
package forestry.farming.logic;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Stack;
|
||||
|
||||
import forestry.api.farming.FarmDirection;
|
||||
import forestry.api.farming.ICrop;
|
||||
import forestry.api.farming.IFarmHousing;
|
||||
import forestry.api.farming.IFarmable;
|
||||
import forestry.core.utils.ItemStackUtil;
|
||||
import forestry.farming.FarmRegistry;
|
||||
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;
|
||||
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.IFarmProperties;
|
||||
|
||||
import forestry.api.core.ForestryAPI;
|
||||
import forestry.api.farming.FarmDirection;
|
||||
import forestry.api.farming.ICrop;
|
||||
import forestry.api.farming.IFarmHousing;
|
||||
import forestry.api.farming.IFarmable;
|
||||
import forestry.core.utils.ItemStackUtil;
|
||||
|
||||
public class FarmLogicReeds extends FarmLogic {
|
||||
|
||||
private final Collection<IFarmable> germlings = FarmRegistry.getInstance().getFarmables("farmPoales");
|
||||
private ArrayList<Soil> soils = new ArrayList<>();
|
||||
|
||||
|
||||
public FarmLogicReeds() {
|
||||
addSoil(new ItemStack(Blocks.SAND), Blocks.SAND.getDefaultState(),true);
|
||||
addSoil(new ItemStack(Blocks.DIRT), Blocks.DIRT.getDefaultState(),false);
|
||||
public class FarmLogicReeds extends FarmLogicSoil {
|
||||
public FarmLogicReeds(IFarmProperties properties, boolean isManual) {
|
||||
super(properties, isManual);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -57,17 +31,8 @@ public class FarmLogicReeds extends FarmLogic {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
if (isManual) {
|
||||
return "Manual Reed Farm";
|
||||
} else {
|
||||
return "Managed Reed Farm";
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addSoil(ItemStack resource, IBlockState soilState, boolean hasMetaData) {
|
||||
this.soils.add(new Soil(resource,soilState,hasMetaData));
|
||||
public String getUnlocalizedName() {
|
||||
return "for.farm.reed";
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -81,18 +46,12 @@ public class FarmLogicReeds extends FarmLogic {
|
||||
}
|
||||
|
||||
@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);
|
||||
|
||||
}
|
||||
|
||||
@@ -120,21 +79,4 @@ public class FarmLogicReeds extends FarmLogic {
|
||||
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,15 +25,18 @@ import net.minecraft.world.World;
|
||||
import forestry.api.farming.FarmDirection;
|
||||
import forestry.api.farming.ICrop;
|
||||
import forestry.api.farming.IFarmHousing;
|
||||
import forestry.api.farming.IFarmProperties;
|
||||
import forestry.core.utils.ItemStackUtil;
|
||||
import forestry.core.utils.Log;
|
||||
import forestry.farming.logic.crops.CropRubber;
|
||||
import forestry.plugins.PluginIC2;
|
||||
|
||||
public class FarmLogicRubber extends FarmLogic {
|
||||
|
||||
private boolean active = true;
|
||||
|
||||
public FarmLogicRubber() {
|
||||
public FarmLogicRubber(IFarmProperties properties, boolean isManual) {
|
||||
super(properties, 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;
|
||||
@@ -46,8 +49,8 @@ public class FarmLogicRubber extends FarmLogic {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "Rubber Plantation";
|
||||
public String getUnlocalizedName() {
|
||||
return "for.farm.rubber";
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -131,9 +134,4 @@ public class FarmLogicRubber extends FarmLogic {
|
||||
return crops;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addSoil(ItemStack resource, IBlockState soilState, boolean hasMetaData) {
|
||||
// do nothing as soil is not managed by farm
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,14 +1,16 @@
|
||||
package forestry.farming.logic;
|
||||
|
||||
import forestry.api.farming.ISimpleFarmLogic;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import forestry.api.farming.IFarmProperties;
|
||||
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(IFarmProperties instance, boolean isManual, ISimpleFarmLogic simpleLogic) {
|
||||
super(instance, isManual);
|
||||
this.simpleLogic = simpleLogic;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
package forestry.farming.logic;
|
||||
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import forestry.api.farming.IFarmProperties;
|
||||
|
||||
public abstract class FarmLogicSoil extends FarmLogic {
|
||||
|
||||
public FarmLogicSoil(IFarmProperties properties, boolean isManual) {
|
||||
super(properties, isManual);
|
||||
}
|
||||
|
||||
protected boolean isAcceptedSoil(IBlockState blockState) {
|
||||
return properties.isAcceptedSoil(blockState);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAcceptedResource(ItemStack itemStack) {
|
||||
return properties.isAcceptedResource(itemStack);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -10,52 +10,33 @@
|
||||
******************************************************************************/
|
||||
package forestry.farming.logic;
|
||||
|
||||
import java.util.ArrayList;
|
||||
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;
|
||||
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.core.utils.ItemStackUtil;
|
||||
import forestry.farming.FarmRegistry;
|
||||
|
||||
public class FarmLogicSucculent extends FarmLogic {
|
||||
|
||||
private final Collection<IFarmable> germlings = FarmRegistry.getInstance().getFarmables("farmSucculentes");
|
||||
private ArrayList<Soil> soils = new ArrayList<>();
|
||||
|
||||
public FarmLogicSucculent() {
|
||||
addSoil(new ItemStack(Blocks.SAND), Blocks.SAND.getDefaultState(),true);
|
||||
import forestry.api.farming.FarmDirection;
|
||||
import forestry.api.farming.IFarmHousing;
|
||||
import forestry.api.farming.IFarmProperties;
|
||||
import forestry.core.utils.ItemStackUtil;
|
||||
|
||||
public class FarmLogicSucculent extends FarmLogicSoil {
|
||||
public FarmLogicSucculent(IFarmProperties properties, boolean isManual) {
|
||||
super(properties, isManual);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public ItemStack getIconItemStack() {
|
||||
return new ItemStack(Items.DYE, 1, 2);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
if (isManual) {
|
||||
return "Manual Succulent Farm";
|
||||
} else {
|
||||
return "Managed Succulent Farm";
|
||||
}
|
||||
public String getUnlocalizedName() {
|
||||
return "for.farm.succulent";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addSoil(ItemStack resource, IBlockState soilState, boolean hasMetaData) {
|
||||
this.soils.add(new Soil(resource,soilState,hasMetaData));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getFertilizerConsumption() {
|
||||
return 10;
|
||||
@@ -65,20 +46,14 @@ public class FarmLogicSucculent extends FarmLogic {
|
||||
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
|
||||
@@ -105,21 +80,4 @@ public class FarmLogicSucculent extends FarmLogic {
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,38 +0,0 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2011-2014 SirSengir.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the GNU Lesser Public License v3
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.gnu.org/licenses/lgpl-3.0.txt
|
||||
*
|
||||
* Various Contributors including, but not limited to:
|
||||
* SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges
|
||||
******************************************************************************/
|
||||
package forestry.farming.logic;
|
||||
|
||||
import net.minecraft.init.Items;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import forestry.farming.FarmRegistry;
|
||||
|
||||
public class FarmLogicVegetable extends FarmLogicCrops {
|
||||
|
||||
public FarmLogicVegetable() {
|
||||
super(FarmRegistry.getInstance().getFarmables("farmVegetables"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getIconItemStack() {
|
||||
return new ItemStack(Items.CARROT);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
if (isManual) {
|
||||
return "Manual Vegetable Farm";
|
||||
} else {
|
||||
return "Managed Vegetable Farm";
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -10,40 +10,30 @@
|
||||
******************************************************************************/
|
||||
package forestry.farming.logic;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.NonNullList;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import net.minecraftforge.fluids.Fluid;
|
||||
import net.minecraftforge.fluids.FluidRegistry;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
|
||||
import forestry.api.farming.FarmDirection;
|
||||
import forestry.api.farming.IFarmHousing;
|
||||
import forestry.api.farming.IFarmProperties;
|
||||
import forestry.api.farming.ISoil;
|
||||
import forestry.core.utils.BlockUtil;
|
||||
import forestry.farming.FarmHelper;
|
||||
|
||||
public abstract class FarmLogicWatered extends FarmLogic {
|
||||
|
||||
|
||||
private final List<Soil> soils = new ArrayList<>();
|
||||
|
||||
public abstract class FarmLogicWatered extends FarmLogicSoil {
|
||||
private static final FluidStack STACK_WATER = new FluidStack(FluidRegistry.WATER, Fluid.BUCKET_VOLUME);
|
||||
|
||||
protected NonNullList<ItemStack> produce = NonNullList.create();
|
||||
|
||||
protected FarmLogicWatered(ItemStack resource, IBlockState ground) {
|
||||
addSoil(resource,ground,false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addSoil(ItemStack resource, IBlockState soilState, boolean hasMetaData) {
|
||||
soils.add(new Soil(resource,soilState,hasMetaData));
|
||||
public FarmLogicWatered(IFarmProperties properties, boolean isManual) {
|
||||
super(properties, isManual);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -56,31 +46,6 @@ public abstract class FarmLogicWatered extends FarmLogic {
|
||||
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;
|
||||
@@ -90,7 +55,6 @@ public abstract class FarmLogicWatered extends FarmLogic {
|
||||
|
||||
@Override
|
||||
public boolean cultivate(World world, IFarmHousing farmHousing, BlockPos pos, FarmDirection direction, int extent) {
|
||||
|
||||
if (maintainSoil(world, farmHousing, pos, direction, extent)) {
|
||||
return true;
|
||||
}
|
||||
@@ -99,42 +63,42 @@ public abstract class FarmLogicWatered extends FarmLogic {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (maintainCrops(world, farmHousing, pos.up(), direction, extent)) {
|
||||
return true;
|
||||
}
|
||||
return maintainCrops(world, farmHousing, pos.up(), direction, extent);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
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();
|
||||
IBlockState blockState = world.getBlockState(platformPosition);
|
||||
if (!FarmHelper.bricks.contains(blockState.getBlock())) {
|
||||
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());
|
||||
}
|
||||
}
|
||||
@@ -149,8 +113,7 @@ public abstract class FarmLogicWatered extends FarmLogic {
|
||||
BlockPos position = translateWithOffset(pos, direction, i);
|
||||
|
||||
BlockPos platformPosition = position.down();
|
||||
IBlockState blockState = world.getBlockState(platformPosition);
|
||||
if (!FarmHelper.bricks.contains(blockState.getBlock())) {
|
||||
if (!farmHousing.isValidPlatform(world, platformPosition)) {
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,91 @@
|
||||
package forestry.farming.logic;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.function.BiFunction;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import forestry.api.farming.IFarmLogic;
|
||||
import forestry.api.farming.IFarmProperties;
|
||||
import forestry.api.farming.IFarmable;
|
||||
import forestry.api.farming.ISoil;
|
||||
import forestry.farming.FarmRegistry;
|
||||
|
||||
public final class FarmProperties implements IFarmProperties {
|
||||
private final Set<ISoil> soils = new HashSet<>();
|
||||
private final Set<String> farmablesIdentifiers;
|
||||
private final IFarmLogic manualLogic;
|
||||
private final IFarmLogic managedLogic;
|
||||
|
||||
@Nullable
|
||||
private Collection<IFarmable> farmables;
|
||||
|
||||
public FarmProperties(BiFunction<IFarmProperties, Boolean, IFarmLogic> logicFactory, Set<String> farmablesIdentifiers) {
|
||||
this.farmablesIdentifiers = farmablesIdentifiers;
|
||||
this.manualLogic = logicFactory.apply(this, true);
|
||||
this.managedLogic = logicFactory.apply(this, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerFarmables(String identifier) {
|
||||
farmablesIdentifiers.add(identifier);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<IFarmable> getFarmables() {
|
||||
if (farmables == null) {
|
||||
farmables = farmablesIdentifiers.stream()
|
||||
.map(FarmRegistry.getInstance()::getFarmables)
|
||||
.flatMap(Collection::stream)
|
||||
.collect(Collectors.toSet());
|
||||
}
|
||||
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));
|
||||
}
|
||||
|
||||
@Override
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -1,93 +0,0 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2011-2014 SirSengir.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the GNU Lesser Public License v3
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.gnu.org/licenses/lgpl-3.0.txt
|
||||
*
|
||||
* Various Contributors including, but not limited to:
|
||||
* SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges
|
||||
******************************************************************************/
|
||||
package forestry.farming.logic;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.EnumActionResult;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.EnumHand;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import forestry.api.farming.ICrop;
|
||||
import forestry.api.farming.IFarmable;
|
||||
import forestry.core.network.packets.PacketFXSignal;
|
||||
import forestry.core.utils.ItemStackUtil;
|
||||
import forestry.core.utils.NetworkUtil;
|
||||
|
||||
public class FarmableSapling implements IFarmable {
|
||||
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, 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 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;
|
||||
}
|
||||
|
||||
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 isWindfall(ItemStack itemstack) {
|
||||
for (ItemStack drop : windfall) {
|
||||
if (drop.isItemEqual(itemstack)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
Executable → Regular
+1
-1
@@ -8,7 +8,7 @@
|
||||
* Various Contributors including, but not limited to:
|
||||
* SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges
|
||||
******************************************************************************/
|
||||
package forestry.farming.logic;
|
||||
package forestry.farming.logic.crops;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
+3
-2
@@ -8,9 +8,8 @@
|
||||
* Various Contributors including, but not limited to:
|
||||
* SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges
|
||||
******************************************************************************/
|
||||
package forestry.farming.logic;
|
||||
package forestry.farming.logic.crops;
|
||||
|
||||
import forestry.core.utils.BlockUtil;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.item.ItemStack;
|
||||
@@ -18,6 +17,8 @@ import net.minecraft.util.NonNullList;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import forestry.core.utils.BlockUtil;
|
||||
|
||||
public class CropBasicAgriCraft extends Crop {
|
||||
|
||||
private final IBlockState blockState;
|
||||
+5
-4
@@ -8,11 +8,8 @@
|
||||
* Various Contributors including, but not limited to:
|
||||
* SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges
|
||||
******************************************************************************/
|
||||
package forestry.farming.logic;
|
||||
package forestry.farming.logic.crops;
|
||||
|
||||
import forestry.core.config.Constants;
|
||||
import forestry.core.network.packets.PacketFXSignal;
|
||||
import forestry.core.utils.NetworkUtil;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.item.ItemStack;
|
||||
@@ -20,6 +17,10 @@ import net.minecraft.util.NonNullList;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import forestry.core.config.Constants;
|
||||
import forestry.core.network.packets.PacketFXSignal;
|
||||
import forestry.core.utils.NetworkUtil;
|
||||
|
||||
public class CropBasicGrowthCraft extends Crop {
|
||||
|
||||
private final IBlockState blockState;
|
||||
+5
-6
@@ -1,4 +1,4 @@
|
||||
package forestry.farming.logic;
|
||||
package forestry.farming.logic.crops;
|
||||
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
@@ -12,7 +12,6 @@ import net.minecraft.world.World;
|
||||
import net.minecraftforge.fml.common.Optional;
|
||||
|
||||
import forestry.plugins.PluginIC2;
|
||||
|
||||
import ic2.api.crops.ICropTile;
|
||||
|
||||
public class CropBasicIC2Crop extends Crop {
|
||||
@@ -35,19 +34,18 @@ 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.
|
||||
*/
|
||||
@Optional.Method(modid = PluginIC2.modId)
|
||||
public static boolean isIC2Crop(TileEntity tileEntity) {
|
||||
if (tileEntity instanceof ICropTile) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
return tileEntity instanceof ICropTile;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
@@ -68,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.
|
||||
*/
|
||||
@@ -0,0 +1,42 @@
|
||||
package forestry.farming.logic.crops;
|
||||
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.NonNullList;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import net.minecraftforge.event.ForgeEventFactory;
|
||||
|
||||
import forestry.core.network.packets.PacketFXSignal;
|
||||
import forestry.core.utils.NetworkUtil;
|
||||
|
||||
public class CropChorusFlower extends Crop {
|
||||
private static final IBlockState BLOCK_STATE = Blocks.CHORUS_FLOWER.getDefaultState();
|
||||
|
||||
public CropChorusFlower(World world, BlockPos position) {
|
||||
super(world, position);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isCrop(World world, BlockPos pos) {
|
||||
return world.getBlockState(pos).getBlock() == Blocks.CHORUS_FLOWER;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected NonNullList<ItemStack> harvestBlock(World world, BlockPos pos) {
|
||||
NonNullList<ItemStack> harvested = NonNullList.create();
|
||||
harvested.add(new ItemStack(Blocks.CHORUS_FLOWER));
|
||||
float chance = ForgeEventFactory.fireBlockHarvesting(harvested, world, pos, BLOCK_STATE, 0, 1.0F, false, null);
|
||||
|
||||
harvested.removeIf(next -> world.rand.nextFloat() > chance);
|
||||
|
||||
PacketFXSignal packet = new PacketFXSignal(PacketFXSignal.VisualFXType.BLOCK_BREAK, PacketFXSignal.SoundFXType.BLOCK_BREAK, pos, BLOCK_STATE);
|
||||
NetworkUtil.sendNetworkPacket(packet, pos, world);
|
||||
|
||||
world.setBlockToAir(pos);
|
||||
|
||||
return harvested;
|
||||
}
|
||||
}
|
||||
+34
-4
@@ -8,13 +8,11 @@
|
||||
* Various Contributors including, but not limited to:
|
||||
* SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges
|
||||
******************************************************************************/
|
||||
package forestry.farming.logic;
|
||||
package forestry.farming.logic.crops;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.Iterator;
|
||||
|
||||
import forestry.core.config.Constants;
|
||||
import forestry.core.network.packets.PacketFXSignal;
|
||||
import forestry.core.utils.NetworkUtil;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.item.ItemStack;
|
||||
@@ -22,16 +20,30 @@ 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 {
|
||||
|
||||
protected final IBlockState blockState;
|
||||
@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
|
||||
@@ -44,6 +56,24 @@ 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;
|
||||
}
|
||||
} else {
|
||||
dropIterator.remove();
|
||||
}
|
||||
}
|
||||
|
||||
PacketFXSignal packet = new PacketFXSignal(PacketFXSignal.VisualFXType.BLOCK_BREAK, PacketFXSignal.SoundFXType.BLOCK_BREAK, pos, blockState);
|
||||
NetworkUtil.sendNetworkPacket(packet, pos, world);
|
||||
+3
-3
@@ -1,4 +1,4 @@
|
||||
package forestry.farming.logic;
|
||||
package forestry.farming.logic.crops;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
@@ -37,8 +37,8 @@ public class CropDestroyDouble extends Crop {
|
||||
Block block = blockState.getBlock();
|
||||
Block blockUp = blockStateUp.getBlock();
|
||||
NonNullList<ItemStack> harvested = NonNullList.create();
|
||||
harvested.addAll(block.getDrops(world, pos, blockState, 0));
|
||||
harvested.addAll(blockUp.getDrops(world, pos.up(), blockStateUp, 0));
|
||||
block.getDrops(harvested, world, pos, blockState, 0);
|
||||
blockUp.getDrops(harvested, world, pos.up(), blockStateUp, 0);
|
||||
|
||||
PacketFXSignal packet = new PacketFXSignal(PacketFXSignal.VisualFXType.BLOCK_BREAK, PacketFXSignal.SoundFXType.BLOCK_BREAK, pos, blockState);
|
||||
NetworkUtil.sendNetworkPacket(packet, pos, world);
|
||||
Executable → Regular
+1
-1
@@ -8,7 +8,7 @@
|
||||
* Various Contributors including, but not limited to:
|
||||
* SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges
|
||||
******************************************************************************/
|
||||
package forestry.farming.logic;
|
||||
package forestry.farming.logic.crops;
|
||||
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.item.ItemStack;
|
||||
Executable → Regular
+1
-1
@@ -8,7 +8,7 @@
|
||||
* Various Contributors including, but not limited to:
|
||||
* SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges
|
||||
******************************************************************************/
|
||||
package forestry.farming.logic;
|
||||
package forestry.farming.logic.crops;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
Executable → Regular
+1
-1
@@ -8,7 +8,7 @@
|
||||
* Various Contributors including, but not limited to:
|
||||
* SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges
|
||||
******************************************************************************/
|
||||
package forestry.farming.logic;
|
||||
package forestry.farming.logic.crops;
|
||||
|
||||
import com.google.common.base.Optional;
|
||||
import com.google.common.collect.ImmutableCollection;
|
||||
@@ -0,0 +1,10 @@
|
||||
@ParametersAreNonnullByDefault
|
||||
@FieldsAreNonnullByDefault
|
||||
@MethodsReturnNonnullByDefault
|
||||
package forestry.farming.logic.crops;
|
||||
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
|
||||
import mcp.MethodsReturnNonnullByDefault;
|
||||
|
||||
import forestry.core.utils.FieldsAreNonnullByDefault;
|
||||
+10
-8
@@ -1,11 +1,9 @@
|
||||
package forestry.farming.logic;
|
||||
package forestry.farming.logic.farmables;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import forestry.api.farming.ICrop;
|
||||
import forestry.api.farming.IFarmable;
|
||||
import forestry.core.utils.BlockUtil;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.properties.IProperty;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
@@ -14,6 +12,11 @@ import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import forestry.api.farming.ICrop;
|
||||
import forestry.api.farming.IFarmable;
|
||||
import forestry.core.utils.BlockUtil;
|
||||
import forestry.farming.logic.crops.CropDestroy;
|
||||
|
||||
/**
|
||||
* For blocks that are harvestable once they are a certain age.
|
||||
*/
|
||||
@@ -42,8 +45,7 @@ public class FarmableAgingCrop implements IFarmable {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSaplingAt(World world, BlockPos pos) {
|
||||
IBlockState blockState = world.getBlockState(pos);
|
||||
public boolean isSaplingAt(World world, BlockPos pos, IBlockState blockState) {
|
||||
return blockState.getBlock() == cropBlock && blockState.getValue(ageProperty) <= minHarvestAge;
|
||||
}
|
||||
|
||||
@@ -59,7 +61,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
|
||||
+7
-6
@@ -1,14 +1,16 @@
|
||||
package forestry.farming.logic;
|
||||
package forestry.farming.logic.farmables;
|
||||
|
||||
import forestry.api.farming.ICrop;
|
||||
import forestry.api.farming.IFarmable;
|
||||
import forestry.core.utils.BlockUtil;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import forestry.api.farming.ICrop;
|
||||
import forestry.api.farming.IFarmable;
|
||||
import forestry.core.utils.BlockUtil;
|
||||
import forestry.farming.logic.crops.CropDestroy;
|
||||
|
||||
public abstract class FarmableBase implements IFarmable {
|
||||
protected final ItemStack germling;
|
||||
protected final IBlockState plantedState;
|
||||
@@ -23,8 +25,7 @@ public abstract class FarmableBase implements IFarmable {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSaplingAt(World world, BlockPos pos) {
|
||||
IBlockState blockState = world.getBlockState(pos);
|
||||
public boolean isSaplingAt(World world, BlockPos pos, IBlockState blockState) {
|
||||
return blockState.getBlock() == plantedState.getBlock() && blockState != matureState;
|
||||
}
|
||||
|
||||
+4
-2
@@ -8,14 +8,16 @@
|
||||
* Various Contributors including, but not limited to:
|
||||
* SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges
|
||||
******************************************************************************/
|
||||
package forestry.farming.logic;
|
||||
package forestry.farming.logic.farmables;
|
||||
|
||||
import forestry.api.farming.ICrop;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import forestry.api.farming.ICrop;
|
||||
import forestry.farming.logic.crops.CropBasicAgriCraft;
|
||||
|
||||
public class FarmableBasicAgricraft extends FarmableBase {
|
||||
public FarmableBasicAgricraft(ItemStack germling, IBlockState plantedState, IBlockState matureState, boolean replant) {
|
||||
super(germling, plantedState, matureState, replant);
|
||||
+1
-1
@@ -8,7 +8,7 @@
|
||||
* Various Contributors including, but not limited to:
|
||||
* SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges
|
||||
******************************************************************************/
|
||||
package forestry.farming.logic;
|
||||
package forestry.farming.logic.farmables;
|
||||
|
||||
//TODO GrowthCraft for 1.9
|
||||
public class FarmableBasicGrowthCraft {
|
||||
+2
-2
@@ -1,4 +1,4 @@
|
||||
package forestry.farming.logic;
|
||||
package forestry.farming.logic.farmables;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
@@ -13,8 +13,8 @@ import net.minecraftforge.fml.common.Optional;
|
||||
|
||||
import forestry.api.farming.ICrop;
|
||||
import forestry.api.farming.IFarmable;
|
||||
import forestry.farming.logic.crops.CropBasicIC2Crop;
|
||||
import forestry.plugins.PluginIC2;
|
||||
|
||||
import ic2.api.crops.ICropTile;
|
||||
|
||||
public class FarmableBasicIC2Crop implements IFarmable {
|
||||
@@ -0,0 +1,80 @@
|
||||
package forestry.farming.logic.farmables;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import net.minecraft.block.BlockChorusFlower;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.init.Items;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import forestry.api.farming.ICrop;
|
||||
import forestry.api.farming.IFarmable;
|
||||
import forestry.core.utils.BlockUtil;
|
||||
import forestry.farming.logic.crops.CropChorusFlower;
|
||||
|
||||
public class FarmableChorus implements IFarmable {
|
||||
public static final IFarmable INSTANCE = new FarmableChorus();
|
||||
|
||||
private final ItemStack germling;
|
||||
private final ItemStack fruit;
|
||||
|
||||
private FarmableChorus() {
|
||||
this.germling = new ItemStack(Blocks.CHORUS_FLOWER);
|
||||
this.fruit = new ItemStack(Items.CHORUS_FRUIT);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSaplingAt(World world, BlockPos pos, IBlockState blockState) {
|
||||
return blockState.getBlock() == Blocks.CHORUS_FLOWER;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public ICrop getCropAt(World world, BlockPos pos, IBlockState blockState) {
|
||||
if (blockState.getBlock() != Blocks.CHORUS_FLOWER) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (blockState.getValue(BlockChorusFlower.AGE) < 5) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return new CropChorusFlower(world, pos);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isGermling(ItemStack itemstack) {
|
||||
return ItemStack.areItemsEqual(germling, itemstack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isWindfall(ItemStack itemstack) {
|
||||
return ItemStack.areItemsEqual(fruit, itemstack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean plantSaplingAt(EntityPlayer player, ItemStack germling, World world, BlockPos pos) {
|
||||
if (!canPlace(world, pos)) {
|
||||
return false;
|
||||
}
|
||||
return BlockUtil.setBlockWithPlaceSound(world, pos, Blocks.CHORUS_FLOWER.getDefaultState());
|
||||
}
|
||||
|
||||
private boolean canPlace(World world, BlockPos position) {
|
||||
for (int x = -1; x <= 1; x++) {
|
||||
for (int z = -1; z <= 1; z++) {
|
||||
BlockPos offsetPosition = position.add(x, 0, z);
|
||||
IBlockState state = world.getBlockState(offsetPosition);
|
||||
if (state.getBlock() == Blocks.CHORUS_FLOWER || state.getBlock() == Blocks.CHORUS_PLANT) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
Loaded 100 of 172 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user