Worked on farming drone idea
This commit is contained in:
parent
60ed9836a2
commit
c27baf4d65
8 changed files with 268 additions and 2 deletions
47
src/dark/api/farm/CropAutomationHandler.java
Normal file
47
src/dark/api/farm/CropAutomationHandler.java
Normal file
|
@ -0,0 +1,47 @@
|
|||
package dark.api.farm;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import dark.core.helpers.Pair;
|
||||
|
||||
/** Tracks a list of all crops that can be auto farmed. Does some guessing on block to avoid having
|
||||
* each mod register all its crops
|
||||
*
|
||||
* @author DarkGuardsman */
|
||||
public class CropAutomationHandler
|
||||
{
|
||||
//TODO handle special cases
|
||||
public static HashMap<Pair<Integer, Integer>, Pair<Integer, Integer>> cropList = new HashMap<Pair<Integer, Integer>, Pair<Integer, Integer>>();
|
||||
public static HashMap<Object, Class<? extends ICropHandler>> specialCropCases = new HashMap<Object, Class<? extends ICropHandler>>();
|
||||
|
||||
static
|
||||
{
|
||||
//TODO add some items here but leave most of the work to some of the sub methods that will ID and upload all crop like blocks
|
||||
}
|
||||
|
||||
public void addCrop(ItemStack stack, int level, int time)
|
||||
{
|
||||
if (stack != null)
|
||||
{
|
||||
Pair<Integer, Integer> par = new Pair<Integer, Integer>(stack.itemID, stack.getItemDamage());
|
||||
Pair<Integer, Integer> par2 = new Pair<Integer, Integer>(level, time);
|
||||
if (!cropList.containsKey(par))
|
||||
{
|
||||
cropList.put(par, par2);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean isAllowedCrop(ItemStack stack)
|
||||
{
|
||||
return stack != null && cropList.containsKey(new Pair<Integer, Integer>(stack.itemID, stack.getItemDamage()));
|
||||
}
|
||||
|
||||
/** Called after all mods/blocks have loaded to auto sort threw blocks looking for anything that
|
||||
* might be close to decayable matter */
|
||||
public static void triggerPostBlockAddition()
|
||||
{
|
||||
//TODO parse the list of blocks and auto add all crop blocks.
|
||||
}
|
||||
}
|
30
src/dark/api/farm/ICropHandler.java
Normal file
30
src/dark/api/farm/ICropHandler.java
Normal file
|
@ -0,0 +1,30 @@
|
|||
package dark.api.farm;
|
||||
|
||||
import dark.farmtech.machines.farmer.EntityFarmDrone;
|
||||
import universalelectricity.core.vector.Vector3;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
/** Special case handling for crops so the farm automatons know to do a few extra steps to care for and harvest
|
||||
* a crop block
|
||||
*
|
||||
* @author DarkGuardsman */
|
||||
public interface ICropHandler
|
||||
{
|
||||
/** Called per block each update of the farming box. Used to manage anything from calling the
|
||||
* drone to harvest, water, or to fertilise the crop */
|
||||
public void onCareUpdate(EntityFarmDrone drone, World world, Vector3 pos);
|
||||
|
||||
/** Called before the drone harvests the crop
|
||||
*
|
||||
* @return true to keep harvesting */
|
||||
public boolean preHarvest(EntityFarmDrone drone, World world, Vector3 pos);
|
||||
|
||||
/** Called as the crop is being harvest but right before its actually removed from the world
|
||||
*
|
||||
* @return true to finish harvesting */
|
||||
public boolean onHarvest(EntityFarmDrone drone, World world, Vector3 pos);
|
||||
|
||||
/** Called after the crop has been removed */
|
||||
public void postHarvest(EntityFarmDrone drone, World world, Vector3 pos);
|
||||
}
|
|
@ -25,16 +25,16 @@ import cpw.mods.fml.common.event.FMLPostInitializationEvent;
|
|||
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
|
||||
import cpw.mods.fml.common.network.NetworkMod;
|
||||
import dark.api.farm.DecayMatterList;
|
||||
import dark.api.farm.CropAutomationHandler;
|
||||
import dark.core.BlockRegistry;
|
||||
import dark.core.BlockRegistry.BlockData;
|
||||
import dark.core.DarkMain;
|
||||
import dark.core.items.ItemBlockHolder;
|
||||
import dark.farmtech.machines.BlockFarmSoil;
|
||||
import dark.farmtech.blocks.BlockFarmSoil;
|
||||
import dark.prefab.ModPrefab;
|
||||
|
||||
@Mod(modid = FarmTech.MOD_ID, name = FarmTech.MOD_NAME, version = DarkMain.VERSION, dependencies = "after:DarkCore", useMetadata = true)
|
||||
@NetworkMod(channels = { FarmTech.CHANNEL }, clientSideRequired = true, serverSideRequired = false, packetHandler = PacketManager.class)
|
||||
|
||||
public class FarmTech extends ModPrefab
|
||||
{
|
||||
|
||||
|
@ -87,6 +87,7 @@ public class FarmTech extends ModPrefab
|
|||
super.postInit(event);
|
||||
proxy.postInit();
|
||||
DecayMatterList.triggerPostBlockAddition();
|
||||
CropAutomationHandler.triggerPostBlockAddition();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
6
src/dark/farmtech/machines/farmer/BlockFarmBox.java
Normal file
6
src/dark/farmtech/machines/farmer/BlockFarmBox.java
Normal file
|
@ -0,0 +1,6 @@
|
|||
package dark.farmtech.machines.farmer;
|
||||
|
||||
public class BlockFarmBox
|
||||
{
|
||||
|
||||
}
|
44
src/dark/farmtech/machines/farmer/CropHandler.java
Normal file
44
src/dark/farmtech/machines/farmer/CropHandler.java
Normal file
|
@ -0,0 +1,44 @@
|
|||
package dark.farmtech.machines.farmer;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.world.World;
|
||||
import universalelectricity.core.vector.Vector3;
|
||||
import dark.api.farm.ICropHandler;
|
||||
|
||||
public class CropHandler implements ICropHandler
|
||||
{
|
||||
ItemStack blockStack;
|
||||
|
||||
public CropHandler(ItemStack blockStack)
|
||||
{
|
||||
this.blockStack = blockStack;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCareUpdate(EntityFarmDrone drone, World world, Vector3 pos)
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean preHarvest(EntityFarmDrone drone, World world, Vector3 pos)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onHarvest(EntityFarmDrone drone, World world, Vector3 pos)
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void postHarvest(EntityFarmDrone drone, World world, Vector3 pos)
|
||||
{
|
||||
// TODO Grab items and place into drop instead of letting fall to the ground
|
||||
|
||||
}
|
||||
|
||||
}
|
23
src/dark/farmtech/machines/farmer/CropHandlerCactus.java
Normal file
23
src/dark/farmtech/machines/farmer/CropHandlerCactus.java
Normal file
|
@ -0,0 +1,23 @@
|
|||
package dark.farmtech.machines.farmer;
|
||||
|
||||
import universalelectricity.core.vector.Vector3;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public class CropHandlerCactus extends CropHandler
|
||||
{
|
||||
|
||||
public CropHandlerCactus(ItemStack blockStack)
|
||||
{
|
||||
super(blockStack);
|
||||
// TODO Auto-generated constructor stub
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean preHarvest(EntityFarmDrone drone, World world, Vector3 pos)
|
||||
{
|
||||
// TODO check if the cactus is the lowest then harvest the block above it
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
90
src/dark/farmtech/machines/farmer/EntityFarmDrone.java
Normal file
90
src/dark/farmtech/machines/farmer/EntityFarmDrone.java
Normal file
|
@ -0,0 +1,90 @@
|
|||
package dark.farmtech.machines.farmer;
|
||||
|
||||
import net.minecraft.entity.EntityLiving;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.world.World;
|
||||
import universalelectricity.core.block.IElectricalStorage;
|
||||
|
||||
public class EntityFarmDrone extends EntityLiving implements IElectricalStorage
|
||||
{
|
||||
/** Battery energy level */
|
||||
private float energy = 0;
|
||||
/** Running cost of drone */
|
||||
private float wattPerTick = 0.1f;
|
||||
/** current inv slots of the drone */
|
||||
private int slots = 1;
|
||||
/** Drone inv */
|
||||
public ItemStack[] inv = new ItemStack[3];
|
||||
|
||||
TileEntityFarmBox home;
|
||||
|
||||
public EntityFarmDrone(World par1World)
|
||||
{
|
||||
super(par1World);
|
||||
this.energy = 10;
|
||||
}
|
||||
|
||||
public EntityFarmDrone(World world, TileEntityFarmBox tileController)
|
||||
{
|
||||
this(world);
|
||||
this.home = tileController;
|
||||
}
|
||||
|
||||
/** Get the amount of time it takes the drone to get home. Used by AI logic to stop work and
|
||||
* return home for recharge */
|
||||
public int getTimeToHome()
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
public static class DroneData
|
||||
{
|
||||
public float health = 0;
|
||||
public float energy = 0;
|
||||
public ItemStack[] inv = new ItemStack[3];
|
||||
|
||||
/** saves drone data to nbt */
|
||||
public NBTTagCompound saveData(NBTTagCompound tag)
|
||||
{
|
||||
return tag;
|
||||
}
|
||||
|
||||
public DroneData getDroneData(EntityFarmDrone drone)
|
||||
{
|
||||
this.health = drone.func_110143_aJ();
|
||||
return this;
|
||||
}
|
||||
|
||||
/** Loads drone data from nbt */
|
||||
public DroneData loadData(NBTTagCompound tag)
|
||||
{
|
||||
return this;
|
||||
}
|
||||
|
||||
/** Creates a new DroneData instances and load data from nbt into it */
|
||||
public static DroneData load(NBTTagCompound tag)
|
||||
{
|
||||
return new DroneData().loadData(tag);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setEnergyStored(float energy)
|
||||
{
|
||||
this.energy = energy;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getEnergyStored()
|
||||
{
|
||||
return this.energy;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getMaxEnergyStored()
|
||||
{
|
||||
return 50;
|
||||
}
|
||||
}
|
25
src/dark/farmtech/machines/farmer/TileEntityFarmBox.java
Normal file
25
src/dark/farmtech/machines/farmer/TileEntityFarmBox.java
Normal file
|
@ -0,0 +1,25 @@
|
|||
package dark.farmtech.machines.farmer;
|
||||
|
||||
import dark.farmtech.machines.TileEntityFT;
|
||||
import dark.farmtech.machines.farmer.EntityFarmDrone.DroneData;
|
||||
|
||||
public class TileEntityFarmBox extends TileEntityFT
|
||||
{
|
||||
/** Current amount of drone slots this box has */
|
||||
private int droneSlots = 1;
|
||||
/** Stores drone data while the drone is stored in the block */
|
||||
private DroneData[] droneData = new DroneData[4];
|
||||
/** Stores drone instances as drones are active outside the block */
|
||||
private EntityFarmDrone[] drones = new EntityFarmDrone[4];
|
||||
|
||||
public TileEntityFarmBox()
|
||||
{
|
||||
this.MAX_WATTS = 100;
|
||||
this.WATTS_PER_TICK = 5;
|
||||
}
|
||||
|
||||
public void updateEntity()
|
||||
{
|
||||
super.updateEntity();
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue