From c27baf4d65ce0ca9af8b6cb9e105e2319b64ec04 Mon Sep 17 00:00:00 2001 From: DarkGuardsman Date: Fri, 30 Aug 2013 20:11:28 -0400 Subject: [PATCH] Worked on farming drone idea --- src/dark/api/farm/CropAutomationHandler.java | 47 ++++++++++ src/dark/api/farm/ICropHandler.java | 30 +++++++ src/dark/farmtech/FarmTech.java | 5 +- .../machines/farmer/BlockFarmBox.java | 6 ++ .../farmtech/machines/farmer/CropHandler.java | 44 +++++++++ .../machines/farmer/CropHandlerCactus.java | 23 +++++ .../machines/farmer/EntityFarmDrone.java | 90 +++++++++++++++++++ .../machines/farmer/TileEntityFarmBox.java | 25 ++++++ 8 files changed, 268 insertions(+), 2 deletions(-) create mode 100644 src/dark/api/farm/CropAutomationHandler.java create mode 100644 src/dark/api/farm/ICropHandler.java create mode 100644 src/dark/farmtech/machines/farmer/BlockFarmBox.java create mode 100644 src/dark/farmtech/machines/farmer/CropHandler.java create mode 100644 src/dark/farmtech/machines/farmer/CropHandlerCactus.java create mode 100644 src/dark/farmtech/machines/farmer/EntityFarmDrone.java create mode 100644 src/dark/farmtech/machines/farmer/TileEntityFarmBox.java diff --git a/src/dark/api/farm/CropAutomationHandler.java b/src/dark/api/farm/CropAutomationHandler.java new file mode 100644 index 00000000..c45c49c8 --- /dev/null +++ b/src/dark/api/farm/CropAutomationHandler.java @@ -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> cropList = new HashMap, Pair>(); + public static HashMap> specialCropCases = new HashMap>(); + + 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 par = new Pair(stack.itemID, stack.getItemDamage()); + Pair par2 = new Pair(level, time); + if (!cropList.containsKey(par)) + { + cropList.put(par, par2); + } + } + } + + public static boolean isAllowedCrop(ItemStack stack) + { + return stack != null && cropList.containsKey(new Pair(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. + } +} diff --git a/src/dark/api/farm/ICropHandler.java b/src/dark/api/farm/ICropHandler.java new file mode 100644 index 00000000..5e326a88 --- /dev/null +++ b/src/dark/api/farm/ICropHandler.java @@ -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); +} diff --git a/src/dark/farmtech/FarmTech.java b/src/dark/farmtech/FarmTech.java index de2039a6..c59a2848 100644 --- a/src/dark/farmtech/FarmTech.java +++ b/src/dark/farmtech/FarmTech.java @@ -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 diff --git a/src/dark/farmtech/machines/farmer/BlockFarmBox.java b/src/dark/farmtech/machines/farmer/BlockFarmBox.java new file mode 100644 index 00000000..5964969b --- /dev/null +++ b/src/dark/farmtech/machines/farmer/BlockFarmBox.java @@ -0,0 +1,6 @@ +package dark.farmtech.machines.farmer; + +public class BlockFarmBox +{ + +} diff --git a/src/dark/farmtech/machines/farmer/CropHandler.java b/src/dark/farmtech/machines/farmer/CropHandler.java new file mode 100644 index 00000000..49a2885a --- /dev/null +++ b/src/dark/farmtech/machines/farmer/CropHandler.java @@ -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 + + } + +} diff --git a/src/dark/farmtech/machines/farmer/CropHandlerCactus.java b/src/dark/farmtech/machines/farmer/CropHandlerCactus.java new file mode 100644 index 00000000..1c23cc9c --- /dev/null +++ b/src/dark/farmtech/machines/farmer/CropHandlerCactus.java @@ -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; + } + +} diff --git a/src/dark/farmtech/machines/farmer/EntityFarmDrone.java b/src/dark/farmtech/machines/farmer/EntityFarmDrone.java new file mode 100644 index 00000000..e99d2e0e --- /dev/null +++ b/src/dark/farmtech/machines/farmer/EntityFarmDrone.java @@ -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; + } +} diff --git a/src/dark/farmtech/machines/farmer/TileEntityFarmBox.java b/src/dark/farmtech/machines/farmer/TileEntityFarmBox.java new file mode 100644 index 00000000..732dcbd4 --- /dev/null +++ b/src/dark/farmtech/machines/farmer/TileEntityFarmBox.java @@ -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(); + } +}