summaryrefslogtreecommitdiff
path: root/src/api/java/powercrystals
diff options
context:
space:
mode:
Diffstat (limited to 'src/api/java/powercrystals')
-rw-r--r--src/api/java/powercrystals/minefactoryreloaded/api/FactoryRegistry.java113
-rw-r--r--src/api/java/powercrystals/minefactoryreloaded/api/HarvestType.java44
-rw-r--r--src/api/java/powercrystals/minefactoryreloaded/api/IFactoryGrindable.java35
-rw-r--r--src/api/java/powercrystals/minefactoryreloaded/api/IFactoryHarvestable.java71
-rw-r--r--src/api/java/powercrystals/minefactoryreloaded/api/ILiquidDrinkHandler.java8
-rw-r--r--src/api/java/powercrystals/minefactoryreloaded/api/MobDrop.java21
-rw-r--r--src/api/java/powercrystals/minefactoryreloaded/api/ValuedItem.java72
7 files changed, 364 insertions, 0 deletions
diff --git a/src/api/java/powercrystals/minefactoryreloaded/api/FactoryRegistry.java b/src/api/java/powercrystals/minefactoryreloaded/api/FactoryRegistry.java
new file mode 100644
index 0000000..8eff88d
--- /dev/null
+++ b/src/api/java/powercrystals/minefactoryreloaded/api/FactoryRegistry.java
@@ -0,0 +1,113 @@
+package powercrystals.minefactoryreloaded.api;
+
+import cpw.mods.fml.common.Loader;
+import cpw.mods.fml.common.event.FMLInterModComms;
+import cpw.mods.fml.common.event.FMLInterModComms.IMCMessage;
+
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Method;
+
+/**
+ * @author PowerCrystals
+ *
+ * Class used to register plants and other farming-related things with MFR. Will do nothing if MFR does not exist.
+ *
+ */
+public class FactoryRegistry
+{
+ /*
+ * This may be called at any time during pre-init, init or post-init, assuming all blocks and items
+ * that are being accessed from the registry have been appropriately registered.
+ * Possible messages:
+ *
+ * // Registration:
+ * addLaserPreferredOre | NBTTag with an ItemStack saved on it, with the color on the "value" attribute,
+ * | A ValuedItem with item and value set.
+ * registerAutoSpawnerBlacklist | The String identifier of an entity,
+ * | A subclass of EntityLivingBase.
+ * registerFertilizable | An instance of IFactoryFertilizable.
+ * registerFertilizer | An instance of IFactoryFertilizer.
+ * registerFruitLog | The String identifier of a block.
+ * registerGrindable | An instance of IFactoryGrindable.
+ * registerGrinderBlacklist | A subclass of EntityLivingBase.
+ * registerHarvestable | An instance of IFactoryHarvestable.
+ * registerLaserOre | NBTTag with an ItemStack saved on it, with the weight on the "value" attribute,
+ * | A ValuedItem with item and value set.
+ * registerLiquidDrinkHandler | A ValuedItem with key and object set; ILiquidDrinkHandler expected.
+ * registerMobEggHandler | An instance of IMobEggHandler.
+ * registerPickableFruit | An instance of IFactoryFruit.
+ * registerPlantable | An instance of IFactoryPlantable.
+ * registerRanchable | An instance of IFactoryRanchable.
+ * registerRedNetLogicCircuit | An instance of IRedNetLogicCircuit.
+ * registerRubberTreeBiome | The biomeName field of a biome to white list for rubber trees to spawn in.
+ * registerSafariNetBlacklist | A subclass of EntityLivingBase.
+ * registerSafariNetHandler | An instance of ISafariNetHandler.
+ * registerSludgeDrop | NBTTag with an ItemStack saved on it, with the weight on the "value" attribute,
+ * | A ValuedItem with item and value set.
+ * registerSpawnHandler | An instance of IMobSpawnHandler.
+ * registerVillagerTradeMob | An instance of IRandomMobProvider.
+ *
+ * // Simple implementations:
+ * { Harvestables
+ * registerHarvestable_Standard | The String identifier of a block.
+ * registerHarvestable_Log | The String identifier of a block.
+ * registerHarvestable_Leaves | The String identifier of a block.
+ * registerHarvestable_Vine | The String identifier of a block.
+ * registerHarvestable_Shrub | The String identifier of a block.
+ * registerHarvestable_Mushroom | The String identifier of a block.
+ * registerHarvestable_Crop | An ItemStack of a block, with a damage value indicating the meta value to harvest at.
+ * | A ValuedItem with value and object set; Block expected.
+ * registerHarvestable_Gourd | An NBTTag with the stem and fruit attributes, both String identifiers of blocks.
+ * }
+ * { Plantables
+ * registerPlantable_Standard | An NBTTag with the seed (Item, String identifier), and
+ * crop (Block, String identifier) attributes set, optionally
+ * also having the meta (Integer, placed metadata value) attribute set.
+ * No special checks for location, just sustainability.
+ * registerPlantable_Crop | An NBTTag with the seed (Item, String identifier), and
+ * crop (Block, String identifier) attributes set, optionally
+ * also having the meta (Integer, placed metadata value) attribute set.
+ * Will automatically hoe dirt and grass into farmland when planting.
+ * registerPlantable_Sapling | An NBTTag with the sapling (Block, String identifier), and optionally
+ * the seed (Item, String identifier) attributes set.
+ * }
+ * { Fertilizer
+ * registerFertilizer | An NBTTag with the fert (Item, String identifier), meta (Integer), and
+ * type (Integer, index into FertilizerType.values()) attributes set.
+ * }
+ * { Fertilizables
+ * registerFertilizable_Grass | The String identifier of a block. Will bonemeal the block and expect
+ * tall grass be planted above and around it, must be IGrowable. Works with
+ * the GrowPlant and Grass type fertilizers, not recommended for crop plants.
+ * registerFertilizable_Gourd | The String identifier of a block. Must be IGrowable, and expects identical
+ * behavior to vanilla stems. Works with the GrowPlant fertilizers.
+ * registerFertilizable_Crop | An NBTTag with the plant (Block, String identifier, IGrowable), and
+ * meta (Integer, max growth phase) attributes set, optionally also having
+ * the type (Integer, index into FertilizerType) attribute set.
+ * registerFertilizable_Cocoa | An NBTTag with the plant (Block, String identifier), and optionally also
+ * the type (Integer, index into FertilizerType) attributes set.
+ * Expects metadata of the block to exactly match cocoa pods.
+ * registerFertilizable_Standard | An NBTTag with the plant (Block, String identifier, IGrowable), and
+ * optionally also the type (Integer, index into FertilizerType) attributes set.
+ * Expects the block to change when successfully grown (e.g., saplings).
+ * }
+ */
+ public static void sendMessage(String message, Object value)
+ {
+ if (!Loader.isModLoaded("MineFactoryReloaded") ||
+ Loader.instance().activeModContainer() == null)
+ return;
+ try
+ {
+ Method m = FMLInterModComms.class.getDeclaredMethod("enqueueMessage", Object.class, String.class, IMCMessage.class);
+ m.setAccessible(true);
+ Constructor<IMCMessage> c = IMCMessage.class.getDeclaredConstructor(String.class, Object.class);
+ c.setAccessible(true);
+ m.invoke(null, Loader.instance().activeModContainer(), "MineFactoryReloaded", c.newInstance(message, value));
+ }
+ catch(Exception e)
+ {
+ e.printStackTrace();
+ }
+ }
+}
diff --git a/src/api/java/powercrystals/minefactoryreloaded/api/HarvestType.java b/src/api/java/powercrystals/minefactoryreloaded/api/HarvestType.java
new file mode 100644
index 0000000..a56208e
--- /dev/null
+++ b/src/api/java/powercrystals/minefactoryreloaded/api/HarvestType.java
@@ -0,0 +1,44 @@
+package powercrystals.minefactoryreloaded.api;
+
+/**
+ * @author PowerCrystals
+ *
+ * Determines what algorithm the Harvester uses when it encounters this IFactoryHarvestable in the world.
+ */
+public enum HarvestType
+{
+ /**
+ * Just break the single block - no special action needed. e.g. Carrots, flowers, wheat.
+ */
+ Normal,
+ /**
+ * Search for harvestable blocks adjacent to this block but leave this block. e.g. Pumpkin, melon
+ */
+ Gourd,
+ /**
+ * Search for identical blocks above.
+ */
+ Column,
+ /**
+ * Search for identical blocks above but leave the bottom one for the future. e.g. Cactus, sugarcane.
+ */
+ LeaveBottom,
+ /**
+ * This block is the base of a tree and the harvester should enter tree-cutting mode.
+ */
+ Tree,
+ /**
+ * This block is the base of the tree and the harvester should enter tree-cutting mode.
+ * The tree is searched for in the negative y axis instead.
+ */
+ TreeFlipped,
+ /**
+ * This block is part of a tree as above.
+ */
+ TreeLeaf,
+ /**
+ * This block is part of a tree as above, but fruits are cut before logs. e.g. cocoa
+ * The tree is not searched for.
+ */
+ TreeFruit
+}
diff --git a/src/api/java/powercrystals/minefactoryreloaded/api/IFactoryGrindable.java b/src/api/java/powercrystals/minefactoryreloaded/api/IFactoryGrindable.java
new file mode 100644
index 0000000..edfb8c9
--- /dev/null
+++ b/src/api/java/powercrystals/minefactoryreloaded/api/IFactoryGrindable.java
@@ -0,0 +1,35 @@
+package powercrystals.minefactoryreloaded.api;
+
+import java.util.List;
+import java.util.Random;
+
+import net.minecraft.entity.EntityLivingBase;
+import net.minecraft.world.World;
+
+/**
+ * @author PowerCrystals
+ *
+ * Defines a grindable entity for the Grinder.
+ */
+public interface IFactoryGrindable
+{
+ /**
+ * @return The class that this grindable instance is handling. This must be a subtype of EntityLivingBase or the entity will never
+ * be noticed by the Grinder.
+ */
+ public Class<? extends EntityLivingBase> getGrindableEntity();
+
+ /**
+ * @param world The world this entity is in.
+ * @param entity The entity instance being ground.
+ * @param random A Random instance.
+ * @return The drops generated when this entity is killed.
+ */
+ public List<MobDrop> grind(World world, EntityLivingBase entity, Random random);
+
+ /**
+ * @param entity The entity instance being ground.
+ * @return Whether this entity has been fully processed or not.
+ */
+ public boolean processEntity(EntityLivingBase entity);
+}
diff --git a/src/api/java/powercrystals/minefactoryreloaded/api/IFactoryHarvestable.java b/src/api/java/powercrystals/minefactoryreloaded/api/IFactoryHarvestable.java
new file mode 100644
index 0000000..d4e620a
--- /dev/null
+++ b/src/api/java/powercrystals/minefactoryreloaded/api/IFactoryHarvestable.java
@@ -0,0 +1,71 @@
+package powercrystals.minefactoryreloaded.api;
+
+import java.util.List;
+import java.util.Map;
+import java.util.Random;
+
+import net.minecraft.block.Block;
+import net.minecraft.item.ItemStack;
+import net.minecraft.world.World;
+
+/**
+ * @author PowerCrystals
+ *
+ * Defines a harvestable block for the Harvester.
+ */
+public interface IFactoryHarvestable
+{
+ /**
+ * @return The block this harvestable instance is managing.
+ */
+ public Block getPlant();
+
+ /**
+ * @return The type of harvest the Harvester should perform on this block.
+ */
+ public HarvestType getHarvestType();
+
+ /**
+ * @return Whether or not the Harvester should break the block when harvesting. If false, no changes will be performed by the Harvester itself.
+ */
+ public boolean breakBlock();
+
+ /**
+ * @param world The world this block is in.
+ * @param harvesterSettings The harvester's current settings. Do not modify these.
+ * @param x The X coordinate of the block being harvested.
+ * @param y The Y coordinate of the block being harvested.
+ * @param z The Z coordinate of the block being harvested.
+ * @return True if this block can be harvested.
+ */
+ public boolean canBeHarvested(World world, Map<String, Boolean> harvesterSettings, int x, int y, int z);
+
+ /**
+ * @param world The world this block is in.
+ * @param rand A Random instance to use when generating drops.
+ * @param harvesterSettings The harvester's current settings. Do not modify these.
+ * @param x The X coordinate of the block being harvested.
+ * @param y The Y coordinate of the block being harvested.
+ * @param z The Z coordinate of the block being harvested.
+ * @return The drops generated by breaking this block. For a default implementation, calling Block.getBlockDropped() is usually sufficient.
+ */
+ public List<ItemStack> getDrops(World world, Random rand, Map<String, Boolean> harvesterSettings, int x, int y, int z);
+
+ /**
+ * Called before the block is going to be harvested. Usually empty.
+ * @param world The world this block is in.
+ * @param x The X coordinate of the block being harvested.
+ * @param y The Y coordinate of the block being harvested.
+ * @param z The Z coordinate of the block being harvested.
+ */
+ public void preHarvest(World world, int x, int y, int z);
+
+ /**
+ * Called after the block is going to be harvested. Used to re-till soil, for example.
+ * @param world The world this block is in.
+ * @param x The X coordinate of the block being harvested.
+ * @param y The Y coordinate of the block being harvested.
+ * @param z The Z coordinate of the block being harvested.
+ */
+ public void postHarvest(World world, int x, int y, int z);
+}
diff --git a/src/api/java/powercrystals/minefactoryreloaded/api/ILiquidDrinkHandler.java b/src/api/java/powercrystals/minefactoryreloaded/api/ILiquidDrinkHandler.java
new file mode 100644
index 0000000..31eba00
--- /dev/null
+++ b/src/api/java/powercrystals/minefactoryreloaded/api/ILiquidDrinkHandler.java
@@ -0,0 +1,8 @@
+package powercrystals.minefactoryreloaded.api;
+
+import net.minecraft.entity.EntityLivingBase;
+
+public interface ILiquidDrinkHandler
+{
+ public void onDrink(EntityLivingBase player);
+}
diff --git a/src/api/java/powercrystals/minefactoryreloaded/api/MobDrop.java b/src/api/java/powercrystals/minefactoryreloaded/api/MobDrop.java
new file mode 100644
index 0000000..7f5dd7c
--- /dev/null
+++ b/src/api/java/powercrystals/minefactoryreloaded/api/MobDrop.java
@@ -0,0 +1,21 @@
+package powercrystals.minefactoryreloaded.api;
+
+import net.minecraft.item.ItemStack;
+import net.minecraft.util.WeightedRandom;
+
+public class MobDrop extends WeightedRandom.Item
+{
+ private ItemStack _stack;
+
+ public MobDrop(int weight, ItemStack stack)
+ {
+ super(weight);
+ _stack = stack;
+ }
+
+ public ItemStack getStack()
+ {
+ if(_stack == null) return null;
+ return _stack.copy();
+ }
+}
diff --git a/src/api/java/powercrystals/minefactoryreloaded/api/ValuedItem.java b/src/api/java/powercrystals/minefactoryreloaded/api/ValuedItem.java
new file mode 100644
index 0000000..3d075fa
--- /dev/null
+++ b/src/api/java/powercrystals/minefactoryreloaded/api/ValuedItem.java
@@ -0,0 +1,72 @@
+package powercrystals.minefactoryreloaded.api;
+
+import net.minecraft.item.ItemStack;
+
+public class ValuedItem
+{
+ public final int value;
+ public final ItemStack item;
+ public final String key;
+ public final Object object;
+
+ public ValuedItem(int v, ItemStack i)
+ {
+ value = v;
+ item = i;
+ key = null;
+ object = null;
+ }
+
+ public ValuedItem(String v, Object i)
+ {
+ value = -1;
+ item = null;
+ key = v;
+ object = i;
+ }
+
+ /**
+ * Presently unused but included so that if they do get used in the future,
+ * people including this in their jar and loading before MFR don't destroy everyone
+ */
+
+ public ValuedItem(int v, Object i)
+ {
+ value = v;
+ item = null;
+ key = null;
+ object = i;
+ }
+
+ public ValuedItem(String v, ItemStack i)
+ {
+ value = -1;
+ item = i;
+ key = v;
+ object = null;
+ }
+
+ public ValuedItem(int v, String k, ItemStack i)
+ {
+ value = v;
+ item = i;
+ key = k;
+ object = null;
+ }
+
+ public ValuedItem(int v, String k, Object i)
+ {
+ value = v;
+ item = null;
+ key = k;
+ object = i;
+ }
+
+ public ValuedItem(int v, String k, ItemStack i, Object o)
+ {
+ value = v;
+ item = i;
+ key = k;
+ object = o;
+ }
+}