diff --git a/src/api/java/ic2/api/Direction.class b/src/api/java/ic2/api/Direction.class index 6d7f09a14..937799309 100644 Binary files a/src/api/java/ic2/api/Direction.class and b/src/api/java/ic2/api/Direction.class differ diff --git a/src/api/java/ic2/api/crops/BaseSeed.class b/src/api/java/ic2/api/crops/BaseSeed.class index 089320676..fd4b77b55 100644 Binary files a/src/api/java/ic2/api/crops/BaseSeed.class and b/src/api/java/ic2/api/crops/BaseSeed.class differ diff --git a/src/api/java/ic2/api/crops/BaseSeed.java b/src/api/java/ic2/api/crops/BaseSeed.java index de6296b39..89e7865fa 100644 --- a/src/api/java/ic2/api/crops/BaseSeed.java +++ b/src/api/java/ic2/api/crops/BaseSeed.java @@ -5,8 +5,54 @@ package ic2.api.crops; */ public class BaseSeed { /** - * Plant ID. + * Create a BaseSeed object. + * + * @param crop plant + * @param size plant size + * @param statGrowth1 plant growth stat + * @param statGain1 plant gain stat + * @param statResistance1 plant resistance stat + * @param stackSize1 for internal usage only */ + @SuppressWarnings("deprecation") + public BaseSeed(CropCard crop, int size, int statGrowth, int statGain, int statResistance, int stackSize) { + super(); + this.crop = crop; + this.id = Crops.instance.getIdFor(crop); + this.size = size; + this.statGrowth = statGrowth; + this.statGain = statGain; + this.statResistance = statResistance; + this.stackSize = stackSize; + } + + /** + * @deprecated Use the CropCard version. + */ + @Deprecated + public BaseSeed(int id, int size, int statGrowth, int statGain, int statResistance, int stackSize) { + this(getCropFromId(id), size, statGrowth, statGain, statResistance, stackSize); + } + + @SuppressWarnings("deprecation") + private static CropCard getCropFromId(int id) { + CropCard[] crops = Crops.instance.getCropList(); + + if (id < 0 || id >= crops.length) return null; + + return crops[id]; + } + + + /** + * Plant. + */ + public final CropCard crop; + + /** + * @deprecated IDs aren't used anymore. + */ + @Deprecated public int id; /** @@ -33,24 +79,4 @@ public class BaseSeed { * For internal usage only. */ public int stackSize; - - /** - * Create a BaseSeed object. - * - * @param id1 plant ID - * @param size1 plant size - * @param statGrowth1 plant growth stat - * @param statGain1 plant gain stat - * @param statResistance1 plant resistance stat - * @param stackSize1 for internal usage only - */ - public BaseSeed(int id1, int size1, int statGrowth1, int statGain1, int statResistance1, int stackSize1) { - super(); - this.id = id1; - this.size = size1; - this.statGrowth = statGrowth1; - this.statGain = statGain1; - this.statResistance = statResistance1; - this.stackSize = stackSize1; - } } diff --git a/src/api/java/ic2/api/crops/CropCard.class b/src/api/java/ic2/api/crops/CropCard.class index 8b2eb0dbf..e117b0c95 100644 Binary files a/src/api/java/ic2/api/crops/CropCard.class and b/src/api/java/ic2/api/crops/CropCard.class differ diff --git a/src/api/java/ic2/api/crops/CropCard.java b/src/api/java/ic2/api/crops/CropCard.java index 63f9844f2..091b9ad24 100644 --- a/src/api/java/ic2/api/crops/CropCard.java +++ b/src/api/java/ic2/api/crops/CropCard.java @@ -7,39 +7,80 @@ import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; import net.minecraft.util.IIcon; +import cpw.mods.fml.common.Loader; +import cpw.mods.fml.common.ModContainer; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; /** * Base agriculture crop. - * + * * Any crop extending this can be registered using registerCrop to be added into the game. */ public abstract class CropCard { + public CropCard() { + modId = getModId(); // initialize mod id while we should be in the real owner's init event + } + /** - * Plant name. Will be displayed to the player. - * + * Plant name for identifying this crop within your mod. + * + * The name has to be unique within the mod and is used for saving. + * By default this name will be also used to determine displayKey() and registerSprites(). + * + * @note changing name or owner will cause existing crops in users' worlds to disappear. + * * @return Plant name */ public abstract String name(); + /** + * Determine the mod id owning this crop. + * + * It's recommended to hard code this to your mod id. + * + * @note changing name or owner will cause existing crops in users' worlds to disappear. + * + * @return Mod id. + */ + public String owner() { + return modId; + } + + /** + * Translation key for display to the player. + * + * It's highly recommended to specify a valid key from your language file here, e.g. add + * "yourmod.crop.yourCropName = Your crop's name" to the language file, override name() to + * return "yourCropName" and override displayName() to return "yourmod.crop."+name(). + * + * @return Unlocalized name. + */ + public String displayName() { + return name(); // return the raw name for backwards compatibility + } + /** * Your name here, will be shown in "Discovered by:" when analyzing seeds. - * + * * @return Your name */ - public String discoveredBy() {return "Alblaka";} + public String discoveredBy() { + return "unknown"; + } /** * Description of your plant. Keep it short, a few characters per line for up to two lines. * Default is showing attributes of your plant, 2 per line. - * + * * @param i line to get, starting from 0 * @return The line */ public String desc(int i) { String[] att = attributes(); + if (att == null || att.length == 0) return ""; + if (i == 0) { String s = att[0]; if (att.length >= 2) { @@ -54,10 +95,19 @@ public abstract class CropCard { return s; } + /** + * * + * @param crop reference to ICropTile + * @return roots lengt use in isBlockBelow + */ + public int getrootslength(ICropTile crop) { + return 1; + } + /** * Tier of the plant. Ranges from 1 to 16, 0 is Weed. * Valuable and powerful crops have higher tiers, useless and weak ones have lower tiers. - * + * * @return Tier */ public abstract int tier(); @@ -65,14 +115,14 @@ public abstract class CropCard { /** * Describe the plant through a set of stats, influencing breeding. * Plants sharing stats and attributes will tend to cross-breed more often. - * + * * Stats: * - 0: Chemistry (Industrial uses based on chemical plant components) * - 1: Consumable (Food, potion ingredients, stuff meant to be eaten or similarly used) * - 2: Defensive (Plants with defense capabilities (damaging, explosive, chemical) or special abilities in general) * - 3: Colorful (How colorful/aesthetically/beautiful is the plant, like dye-plants or plants without actual effects) * - 4: Weed (Is this plant weed-like and rather unwanted/quick-spreading? Rare super-breed plants should have low values here) - * + * * @param n index of the requested stat * @return The requested value of the stats */ @@ -81,35 +131,39 @@ public abstract class CropCard { /** * Additional attributes of the plant, also influencing breeding. * Plants sharing stats and attributes will tend to cross-breed more often. - * + * * @return Attributes as an array of strings */ public abstract String[] attributes(); /** * Determine the max crop size. - * + * * Currently only used for texture allocation. */ public abstract int maxSize(); /** * Instantiate your Icons here. - * + * * This method will get called by IC2, don't call it yourself. + * + * It's highly recommended to use your own assert domain here, e.g. yourmod:crop/* instead of + * ic2:crop/*, which will then read assets/yourmod/textures/blocks/crop/*.png. */ @SideOnly(Side.CLIENT) public void registerSprites(IIconRegister iconRegister) { textures = new IIcon[maxSize()]; for (int i = 1; i <= textures.length; i++) { - textures[i-1] = iconRegister.registerIcon("ic2:crop/blockCrop."+name()+"."+i); + // ic2:crop/blockCrop.NAME.n is the legacy name for backwards compatiblity + textures[i - 1] = iconRegister.registerIcon("ic2:crop/blockCrop."+name()+"."+i); } } /** * Sprite the crop is meant to be rendered with. - * + * * @param crop reference to ICropTile * @return 0-255, representing the sprite index on the crop's spritesheet. */ @@ -120,34 +174,25 @@ public abstract class CropCard { return textures[crop.getSize() - 1]; } - /** - * Get the crop's spritesheet. - * Per default crops_0.png of ic2-sprites - * @return Texture file path - */ - public String getTextureFile() { - return "/ic2/sprites/crops_0.png"; - } - /** * Amount of growth points needed to increase the plant's size. * Default is 200 * tier. */ public int growthDuration(ICropTile crop) { - return tier()*200; + return tier() * 200; } /** * Check whether the plant can grow further. - * + * * Consider: * - Humidity, nutrients and air quality * - Current size * - Light level * - Special biomes or conditions, accessible through crop.worldObj - * + * * This method will be called upon empty upgraded crops to check whether a neighboring plant can cross onto it! Don't check if the size is greater than 0 and if the ID is real. - * + * * @param crop reference to ICropTile * @return Whether the crop can grow */ @@ -157,9 +202,9 @@ public abstract class CropCard { * Calculate the influence for the plant to grow based on humidity, nutrients and air. * Normal behavior is rating the three stats "normal", with each of them ranging from 0-30. * Basic rule: Assume everything returns 10. All together must equal 30. Add the factors to your likings, for example (humidity*0.7)+(nutrients*0.9)+(air*1.4) - * + * * Default is humidity + nutrients + air (no factors). - * + * * @param crop reference to ICropTile * @param humidity ground humidity, influenced by hydration * @param nutrients nutrient quality in ground, based on fertilizers @@ -173,7 +218,7 @@ public abstract class CropCard { /** * Used to determine whether the plant can crossbreed with another crop. * Default is allow crossbreeding if the size is greater or equal than 3. - * + * * @param crop crop to crossbreed with */ public boolean canCross(ICropTile crop) { @@ -184,9 +229,9 @@ public abstract class CropCard { /** * Called when the plant is rightclicked by a player. * Default action is harvesting. - * + * * Only called Serverside. - * + * * @param crop reference to ICropTile * @param player player rightclicking the crop * @return Whether the plant has changed @@ -197,7 +242,7 @@ public abstract class CropCard { /** * Use in Crop Havester with insert Cropnalyzer to get best Output. - * + * * @param crop reference to ICropTile * @return need crop size for best output. */ @@ -206,7 +251,7 @@ public abstract class CropCard { /** * Check whether the crop can be harvested. - * + * * @param crop reference to ICropTile * @return Whether the crop can be harvested in its current state. */ @@ -215,7 +260,7 @@ public abstract class CropCard { /** * Base chance for dropping the plant's gains, specify values greater than 1 for multiple drops. * Default is 0.95^tier. - * + * * @return Chance to drop the gains */ public float dropGainChance() { @@ -226,7 +271,7 @@ public abstract class CropCard { /** * Item obtained from harvesting the plant. - * + * * @param crop reference to ICropTile * @return Item obtained */ @@ -235,7 +280,7 @@ public abstract class CropCard { /** * Get the size of the plant after harvesting. * Default is 1. - * + * * @param crop reference to ICropTile * @return Plant size after harvesting */ @@ -245,9 +290,9 @@ public abstract class CropCard { /** * Called when the plant is leftclicked by a player. * Default action is picking the plant. - * + * * Only called Serverside. - * + * * @param crop reference to ICropTile * @param player player leftclicked the crop * @return Whether the plant has changed @@ -259,7 +304,7 @@ public abstract class CropCard { /** * Base chance for dropping seeds when the plant is picked. * Default is 0.5*0.8^tier with a bigger chance for sizes greater than 2 and absolutely no chance for size 0. - * + * * @param crop reference to ICropTile * @return Chance to drop the seeds */ @@ -275,17 +320,17 @@ public abstract class CropCard { * Obtain seeds dropped when the plant is picked. * Multiple drops of the returned ItemStack can occur. * Default action is generating a seed from this crop. - * + * * @param crop reference to ICropTile * @return Seeds */ public ItemStack getSeeds(ICropTile crop) { - return crop.generateSeeds(crop.getID(), crop.getGrowth(), crop.getGain(), crop.getResistance(), crop.getScanLevel()); + return crop.generateSeeds(crop.getCrop(), crop.getGrowth(), crop.getGain(), crop.getResistance(), crop.getScanLevel()); } /** * Called when a neighbor block to the crop has changed. - * + * * @param crop reference to ICropTile */ public void onNeighbourChange(ICropTile crop) { @@ -294,14 +339,14 @@ public abstract class CropCard { /** * Check if the crop should emit redstone. - * + * * @return Whether the crop should emit redstone */ public int emitRedstone(ICropTile crop) {return 0;} /** * Called when the crop is destroyed. - * + * * @param crop reference to ICropTile */ public void onBlockDestroyed(ICropTile crop) { @@ -310,15 +355,17 @@ public abstract class CropCard { /** * Get the light value emitted by the plant. - * + * * @param crop reference to ICropTile * @return Light value emitted */ - public int getEmittedLight(ICropTile crop) {return 0;} + public int getEmittedLight(ICropTile crop) { + return 0; + } /** * Default is true if the entity is an EntityLiving in jumping or sprinting state. - * + * * @param crop reference to ICropTile * @param entity entity colliding * @return Whether trampling calculation should happen, return false if the plant is no longer valid. @@ -327,6 +374,7 @@ public abstract class CropCard { if (entity instanceof EntityLivingBase) { return ((EntityLivingBase) entity).isSprinting(); } + return false; } @@ -334,34 +382,52 @@ public abstract class CropCard { /** * Called every time the crop ticks. * Should be called every 256 ticks or around 13 seconds. - * + * * @param crop reference to ICropTile */ public void tick(ICropTile crop) { - // + // nothing by default } /** * Check whether this plant spreads weed to surrounding tiles. * Default is true if the plant has a high growth stat (or is weeds) and size greater or equal than 2. - * + * * @param crop reference to ICropTile * @return Whether the plant spreads weed */ public boolean isWeed(ICropTile crop) { - return crop.getSize() >= 2 && (crop.getID() == 0 || crop.getGrowth() >= 24); + return crop.getSize() >= 2 && + (crop == Crops.weed || crop.getGrowth() >= 24); } /** * Get this plant's ID. - * + * * @return ID of this CropCard or -1 if it's not registered + * @deprecated IDs aren't used anymore. */ + @Deprecated public final int getId() { return Crops.instance.getIdFor(this); } + private static String getModId() { + ModContainer modContainer = Loader.instance().activeModContainer(); + + if (modContainer != null) { + return modContainer.getModId(); + } else { + // this is bad if you are not actually IC2 + assert false; + + return "unknown"; + } + } + @SideOnly(Side.CLIENT) protected IIcon textures[]; + + private final String modId; // TODO: make owner abstract, remove modId auto detection } diff --git a/src/api/java/ic2/api/crops/Crops.class b/src/api/java/ic2/api/crops/Crops.class index e0c5d9aec..1844fa959 100644 Binary files a/src/api/java/ic2/api/crops/Crops.class and b/src/api/java/ic2/api/crops/Crops.class differ diff --git a/src/api/java/ic2/api/crops/Crops.java b/src/api/java/ic2/api/crops/Crops.java index 53cc3239f..a11059a91 100644 --- a/src/api/java/ic2/api/crops/Crops.java +++ b/src/api/java/ic2/api/crops/Crops.java @@ -1,5 +1,7 @@ package ic2.api.crops; +import java.util.Collection; + import net.minecraft.client.renderer.texture.IIconRegister; import net.minecraft.item.ItemStack; import net.minecraft.world.biome.BiomeGenBase; @@ -15,31 +17,32 @@ import net.minecraftforge.common.BiomeDictionary.Type; public abstract class Crops { public static Crops instance; - /** - * Adds a crop humidity and nutrient biome bonus. - * - * 0 indicates no bonus and negative values indicate a penalty. - * - * @param biome Biome to apply the bonus in - * @param humidityBonus Humidity stat bonus - * @param nutrientsBonus Nutrient stat bonus - */ - public abstract void addBiomeBonus(BiomeGenBase biome, int humidityBonus, int nutrientsBonus); + public static CropCard weed; // weed has special properties, thus it's exposed here /** - * Adds a crop humidity and nutrient biome bonus. - * - * 0 indicates no bonus and negative values indicate a penalty. - * + * Adds a crop nutrient biome bonus. + * + * +10/-10 0 indicates no bonus and negative values indicate a penalty. + * * @param type Forge biome type to apply the bonus in - * @param humidityBonus Humidity stat bonus * @param nutrientsBonus Nutrient stat bonus */ - public abstract void addBiomeBonus(Type type, int humidityBonus, int nutrientsBonus); + public abstract void addBiomenutrientsBonus(Type type, int nutrientsBonus); + + /** + * Adds a crop humidity biome bonus. + * + * +10/-10 0 indicates no bonus and negative values indicate a penalty. + * + * @param type Forge biome type to apply the bonus in + * @param humidityBonus Humidity stat bonus + */ + public abstract void addBiomehumidityBonus(Type type, int humidityBonus); + /** * Gets the humidity bonus for a biome. - * + * * @param biome Biome to check * @return Humidity bonus or 0 if none */ @@ -47,41 +50,70 @@ public abstract class Crops { /** * Gets the nutrient bonus for a biome. - * + * * @param biome Biome to check * @return Nutrient bonus or 0 if none */ public abstract int getNutrientBiomeBonus(BiomeGenBase biome); + /** + * Get the crop card for the specified owner and name. + * + * @param owner CropCard owner mod id. + * @param name CropCard name. + * @return Matching CropCard. + */ + public abstract CropCard getCropCard(String owner, String name); + + /** + * Get the crop card for the specified seed item stack. + * + * @param stack ItemStack containing seeds for the crop. + * @return Matching CropCard. + */ + public abstract CropCard getCropCard(ItemStack stack); + + /** + * Returns a list of all crops. + * + * @return All registered crops. + */ + public abstract Collection getCrops(); + /** * Returns the list of registered crops. - * + * * @return Registered crops by ID */ + @Deprecated public abstract CropCard[] getCropList(); /** - * Auto-assign an ID to a plant and register it. - * Usage of this method is not recommended! Other plants could take your IDs and cause your plants to turn into other plants. - * - * @param crop plant to register - * @return The ID assigned to the plant + * Register a plant. + * + * @param crop Plant to register. + * @return Autoassigned id for legacy compatibility, TODO: change to void. */ public abstract short registerCrop(CropCard crop); /** - * Attempt to register a plant to an ID. - * If the ID is taken, the crop will not be registered and a console print will notify the user. - * - * @param crop plant to register - * @param i ID to register the plant to - * @return Whether the crop was registered + * Register a plant and provide a legacy id for migration. + * + * @param crop Plant to register. + * @param legacyId ID previously used for this crop. + * @return true, TODO: change to void. */ - public abstract boolean registerCrop(CropCard crop, int i); + public abstract boolean registerCrop(CropCard crop, int legacyId); + + /** + * @deprecated use the CropCard version. + */ + @Deprecated + public abstract boolean registerBaseSeed(ItemStack stack, int id, int size, int growth, int gain, int resistance); /** * Registers a base seed, an item used to plant a crop. - * + * * @param stack item * @param id plant ID * @param size initial size @@ -90,18 +122,18 @@ public abstract class Crops { * @param resistance initial resistance stat * @return True if successful */ - public abstract boolean registerBaseSeed(ItemStack stack, int id, int size, int growth, int gain, int resistance); + public abstract boolean registerBaseSeed(ItemStack stack, CropCard crop, int size, int growth, int gain, int resistance); /** * Finds a base seed from the given item. - * + * * @return Base seed or null if none found */ public abstract BaseSeed getBaseSeed(ItemStack stack); /** * Execute registerSprites for all registered crop cards. - * + * * This method will get called by IC2, don't call it yourself. */ @SideOnly(Side.CLIENT) @@ -109,9 +141,11 @@ public abstract class Crops { /** * Returns the ID for the given crop. - * + * * @param crop Crop to look up * @return ID, or -1 if not found + * @deprecated IDs aren't used anymore. */ + @Deprecated public abstract int getIdFor(CropCard crop); } diff --git a/src/api/java/ic2/api/crops/ICropTile.class b/src/api/java/ic2/api/crops/ICropTile.class index a7e6c5b73..b359a00f9 100644 Binary files a/src/api/java/ic2/api/crops/ICropTile.class and b/src/api/java/ic2/api/crops/ICropTile.class differ diff --git a/src/api/java/ic2/api/crops/ICropTile.java b/src/api/java/ic2/api/crops/ICropTile.java index 09b46d79f..6fd887ee0 100644 --- a/src/api/java/ic2/api/crops/ICropTile.java +++ b/src/api/java/ic2/api/crops/ICropTile.java @@ -11,29 +11,41 @@ import net.minecraft.world.World; */ public interface ICropTile { /** - * Get the crop's plant ID. - * - * @return Plant ID, or -1 if there is no plant currently on the crop + * Get the crop. + * + * @return CropCard, or null if there is no plant currently on the crop */ + public CropCard getCrop(); + + /** + * Set the crop. + * + * @param cropCard CropCard or null for no plant + */ + public void setCrop(CropCard cropCard); + + /** + * @deprecated IDs have been removed. + */ + @Deprecated public short getID(); /** - * Set the crop's plant ID. - * - * @param id Plant ID, or -1 for no plant + * @deprecated IDs have been removed. */ + @Deprecated public void setID(short id); /** * Get the crop's plant size. - * + * * @return Plant size, starting with 1 and maximum varies depending on plant */ public byte getSize(); /** * Set the crop's plant size. - * + * * @param size Plant size */ public void setSize(byte size); @@ -41,14 +53,14 @@ public interface ICropTile { /** * Get the crop's plant growth stat. * Higher values indicate faster growth. - * + * * @return Plant growth stat */ public byte getGrowth(); /** * Set the crop's plant growth stat. - * + * * @param growth Plant growth stat */ public void setGrowth(byte growth); @@ -56,14 +68,14 @@ public interface ICropTile { /** * Get the crop's plant gain stat. * Higher values indicate more drops. - * + * * @return Plant gain stat */ public byte getGain(); /** * Set the crop's plant gain stat. - * + * * @param gain Plant gain stat */ public void setGain(byte gain); @@ -71,14 +83,14 @@ public interface ICropTile { /** * Get the crop's plant resistance stat. * Higher values indicate more resistance against trampling. - * + * * @return Plant resistance stat */ public byte getResistance(); /** * Set the crop's plant resistance stat. - * + * * @param resistance Plant resistance stat */ public void setResistance(byte resistance); @@ -86,14 +98,14 @@ public interface ICropTile { /** * Get the crop's plant scan level. * Increases every time the seed is analyzed. - * + * * @return Plant scan level */ public byte getScanLevel(); /** * Set the crop's plant scan level. - * + * * @param scanLevel Plant scan level */ public void setScanLevel(byte scanLevel); @@ -101,7 +113,7 @@ public interface ICropTile { /** * Get the crop's plant custom data, stored alongside the crop. * Can be modified in place. - * + * * @return Plant custom data */ public NBTTagCompound getCustomData(); @@ -109,14 +121,14 @@ public interface ICropTile { /** * Get the crop's nutrient storage. * Ranges from 0 to 100. - * + * * @return Crop nutrient storage */ public int getNutrientStorage(); /** * Set the crop's nutrient storage. - * + * * @param nutrientStorage Crop nutrient storage */ public void setNutrientStorage(int nutrientStorage); @@ -124,28 +136,28 @@ public interface ICropTile { /** * Get the crop's hydration storage. * 0 indicates nothing, 1-10 indicate water hydration and 11-100 for hydration cells. - * + * * @return Crop hydration storage */ public int getHydrationStorage(); /** * Set the crop's hydration storage. - * + * * @param hydrationStorage Crop hydration storage */ public void setHydrationStorage(int hydrationStorage); /** * Get the crop's Weed-Ex storage. - * + * * @return Crop Weed-Ex storage */ public int getWeedExStorage(); /** * Set the crop's Weed-Ex storage. - * + * * @param weedExStorage Crop Weed-Ex storage */ public void setWeedExStorage(int weedExStorage); @@ -154,9 +166,9 @@ public interface ICropTile { * Get the crop's humidity. * Ranges from 0 (dry) to 10 (humid). * Updates every couple of seconds or when an update is requested. - * + * * @see #updateState() - * + * * @return Crop humidity level */ public byte getHumidity(); @@ -165,9 +177,9 @@ public interface ICropTile { * Get the crop's nutrient level. * Ranges from 0 (empty) to 10 (full). * Updates every couple of seconds or when an update is requested. - * + * * @see #updateState() - * + * * @return Crop nutrient level */ public byte getNutrients(); @@ -176,37 +188,37 @@ public interface ICropTile { * Get the crop's air quality. * Ranges from 0 (cluttered) to 10 (fresh). * Updates every couple of seconds or when an update is requested. - * + * * @see #updateState() - * + * * @return Crop air quality */ public byte getAirQuality(); /** * Get the crop's world. - * + * * @return Crop world */ public World getWorld(); /** * Get the crop's location. - * + * * @return Crop location */ public ChunkCoordinates getLocation(); /** * Get the crop's light level. - * + * * @return Crop light level */ public int getLightLevel(); /** * Pick the crop, removing and giving seeds for the plant. - * + * * @param manual whether it was done by hand (not automated) * @return true if successfully picked */ @@ -242,7 +254,7 @@ public interface ICropTile { /** * Check if a block is under the farmland containing the crop. * Searches up to 2 blocks below the farmland or an air space, whichever appears first. - * + * * @param block block to search * @return Whether the block was found */ @@ -250,15 +262,19 @@ public interface ICropTile { /** * Generate plant seeds with the given parameters. - * - * @param plant plant ID + * + * @param crop plant * @param growth plant growth stat * @param gain plant gain stat * @param resis plant resistance stat * @param scan plant scan level * @return Plant seed item */ + public ItemStack generateSeeds(CropCard crop, byte growth, byte gain, byte resis, byte scan); + + /** + * @deprecated Use the CropCard version instead. + */ + @Deprecated public ItemStack generateSeeds(short plant, byte growth, byte gain, byte resis, byte scan); - - } diff --git a/src/api/java/ic2/api/energy/NodeStats.class b/src/api/java/ic2/api/energy/NodeStats.class index 8571830ac..eceb34029 100644 Binary files a/src/api/java/ic2/api/energy/NodeStats.class and b/src/api/java/ic2/api/energy/NodeStats.class differ diff --git a/src/api/java/ic2/api/energy/event/EnergyTileEvent.class b/src/api/java/ic2/api/energy/event/EnergyTileEvent.class index 58444696d..25e3e25e4 100644 Binary files a/src/api/java/ic2/api/energy/event/EnergyTileEvent.class and b/src/api/java/ic2/api/energy/event/EnergyTileEvent.class differ diff --git a/src/api/java/ic2/api/energy/event/EnergyTileEvent.java b/src/api/java/ic2/api/energy/event/EnergyTileEvent.java index 2182e497c..86b8dc2b1 100644 --- a/src/api/java/ic2/api/energy/event/EnergyTileEvent.java +++ b/src/api/java/ic2/api/energy/event/EnergyTileEvent.java @@ -8,7 +8,7 @@ import ic2.api.energy.tile.IEnergyTile; /** * Base class for energy net events, don't use it directly. - * + * * See ic2/api/energy/usage.txt for an overall description of the energy net api. */ public class EnergyTileEvent extends WorldEvent { @@ -17,6 +17,8 @@ public class EnergyTileEvent extends WorldEvent { public EnergyTileEvent(IEnergyTile energyTile1) { super(((TileEntity) energyTile1).getWorldObj()); + if (world == null) throw new NullPointerException("world is null"); + this.energyTile = energyTile1; } } diff --git a/src/api/java/ic2/api/energy/prefab/BasicSink.class b/src/api/java/ic2/api/energy/prefab/BasicSink.class index 711723de2..b0b895ce0 100644 Binary files a/src/api/java/ic2/api/energy/prefab/BasicSink.class and b/src/api/java/ic2/api/energy/prefab/BasicSink.class differ diff --git a/src/api/java/ic2/api/energy/prefab/BasicSource.class b/src/api/java/ic2/api/energy/prefab/BasicSource.class index e387d5c3c..164213b2c 100644 Binary files a/src/api/java/ic2/api/energy/prefab/BasicSource.class and b/src/api/java/ic2/api/energy/prefab/BasicSource.class differ diff --git a/src/api/java/ic2/api/event/ExplosionEvent.class b/src/api/java/ic2/api/event/ExplosionEvent.class new file mode 100644 index 000000000..68a268d87 Binary files /dev/null and b/src/api/java/ic2/api/event/ExplosionEvent.class differ diff --git a/src/api/java/ic2/api/event/ExplosionEvent.java b/src/api/java/ic2/api/event/ExplosionEvent.java new file mode 100644 index 000000000..c2df41952 --- /dev/null +++ b/src/api/java/ic2/api/event/ExplosionEvent.java @@ -0,0 +1,44 @@ +package ic2.api.event; + +import net.minecraft.entity.Entity; +import net.minecraft.entity.EntityLivingBase; +import net.minecraft.world.World; + +import cpw.mods.fml.common.eventhandler.Cancelable; + +import net.minecraftforge.event.world.WorldEvent; + +@Cancelable +public class ExplosionEvent extends WorldEvent { + public ExplosionEvent(World world, Entity entity, + double x, double y, double z, + double power, + EntityLivingBase igniter, + int radiationRange, double rangeLimit) { + super(world); + + this.entity = entity; + this.x = x; + this.y = y; + this.z = z; + this.power = power; + this.igniter = igniter; + this.radiationRange = radiationRange; + this.rangeLimit = rangeLimit; + } + + /** + * Entity representing the explosive, may be null. + */ + public final Entity entity; + public double x; + public double y; + public double z; + public double power; + /** + * Entity causing the explosion, may be null. + */ + public final EntityLivingBase igniter; + public final int radiationRange; + public final double rangeLimit; +} diff --git a/src/api/java/ic2/api/item/ElectricItem.class b/src/api/java/ic2/api/item/ElectricItem.class index f2b886ac0..be9260675 100644 Binary files a/src/api/java/ic2/api/item/ElectricItem.class and b/src/api/java/ic2/api/item/ElectricItem.class differ diff --git a/src/api/java/ic2/api/item/ICustomDamageItem.class b/src/api/java/ic2/api/item/ICustomDamageItem.class new file mode 100644 index 000000000..80020b849 Binary files /dev/null and b/src/api/java/ic2/api/item/ICustomDamageItem.class differ diff --git a/src/api/java/ic2/api/item/ICustomDamageItem.java b/src/api/java/ic2/api/item/ICustomDamageItem.java new file mode 100644 index 000000000..4470fa0db --- /dev/null +++ b/src/api/java/ic2/api/item/ICustomDamageItem.java @@ -0,0 +1,56 @@ +package ic2.api.item; + +import net.minecraft.entity.EntityLivingBase; +import net.minecraft.item.ItemStack; + +/** + * ICustomDamageItem allows items to have custom damage handling without the massive overhead of + * Item.getDamage() / Item.setDamage(), which turn ItemStack.getItemDamage into virtual calls. + * + * The custom damage value is typically stored in the item stacks nbt data. + * + * If an Item implements ICusomDamageItem, the normal ItemStack damage won't be changed by IC2. + * It's up to the implementer to potentially manipulate it for suitable visual effect on the + * rendered damage bar or to provide a suitable item renderer. + * + * Item.isDamageable() still applies. + * + * @author Player + */ +public interface ICustomDamageItem { + /** + * Retrieve the custom damage value for the supplied item stack. + * + * @param stack ItemStack to be queried. + * @return Custom damage value. + */ + int getCustomDamage(ItemStack stack); + + /** + * Retrieve the maximum custom damage value for the supplied item stack. + * @param stack ItemStack to be queried. + * @return Custom damage value limit. + */ + int getMaxCustomDamage(ItemStack stack); + + /** + * Set the custom damage value for the supplied item stack. + * + * @param stack ItemStack to be manipulated. + * @param damage New damage value. + */ + void setCustomDamage(ItemStack stack, int damage); + + /** + * Increase the custom damage value for the supplied item stack. + * + * It's up to the implementation to not apply any damage, e.g. based on some randomness or + * properties of src. + * + * @param stack ItemStack to be manipulated. + * @param damage Extra damage to be applied. + * @param src Entity damaging the item, may be null. + * @return true if damage was applied. + */ + boolean applyCustomDamage(ItemStack stack, int damage, EntityLivingBase src); +} diff --git a/src/api/java/ic2/api/item/IKineticWindRotor.class b/src/api/java/ic2/api/item/IKineticWindRotor.class index 684dd536e..00f10fc86 100644 Binary files a/src/api/java/ic2/api/item/IKineticWindRotor.class and b/src/api/java/ic2/api/item/IKineticWindRotor.class differ diff --git a/src/api/java/ic2/api/item/IKineticWindRotor.java b/src/api/java/ic2/api/item/IKineticWindRotor.java index 62f1fdc36..de696e381 100644 --- a/src/api/java/ic2/api/item/IKineticWindRotor.java +++ b/src/api/java/ic2/api/item/IKineticWindRotor.java @@ -1,15 +1,16 @@ package ic2.api.item; +import net.minecraft.item.ItemStack; import net.minecraft.util.ResourceLocation; public interface IKineticWindRotor { - public int getDiameter(); + int getDiameter(ItemStack stack); - public ResourceLocation getRotorRenderTexture(); + ResourceLocation getRotorRenderTexture(ItemStack stack); - public float getefficiency(); + float getEfficiency(ItemStack stack); - int getminWindStrength(); + int getMinWindStrength(ItemStack stack); - int getmaxWindStrength(); + int getMaxWindStrength(ItemStack stack); } diff --git a/src/api/java/ic2/api/item/ILatheItem.class b/src/api/java/ic2/api/item/ILatheItem.class new file mode 100644 index 000000000..7bbb877de Binary files /dev/null and b/src/api/java/ic2/api/item/ILatheItem.class differ diff --git a/src/api/java/ic2/api/item/ILatheItem.java b/src/api/java/ic2/api/item/ILatheItem.java new file mode 100644 index 000000000..2baffc8f9 --- /dev/null +++ b/src/api/java/ic2/api/item/ILatheItem.java @@ -0,0 +1,47 @@ +package ic2.api.item; + +import net.minecraft.item.ItemStack; +import net.minecraft.util.ResourceLocation; + +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; + +public interface ILatheItem { + + /** + * Returns the radius of this Lathe Item + * Should be no more than 15 to still be able to display it properly. + */ + int getWidth(ItemStack stack); + + /** + * Returns the current state of this Lathe Item + * The length of the array should be 5 + * The value should be the current size of the item at this time. + * It should also not be greater than getWidth() + */ + int[] getCurrentState(ItemStack stack); + + /** + * This will set the current state of the Item on that position to that value. + */ + void setState(ItemStack stack, int position, int value); + + /** + * Returns the output Item (normally dust) when you lathe on this position. + */ + ItemStack getOutputItem(ItemStack stack, int position); + + /** + * How common it is if the above item will be put into the output slot. + * 1.0 means it will always be outputted, 0.0 means it will never be outputted. + */ + float getOutputChance(ItemStack stack, int position); + + /** + * Returns the ResourceLocation of the texture used to display the item inside of the Lathe GUI + */ + @SideOnly(Side.CLIENT) + ResourceLocation getTexture(ItemStack stack); + +} diff --git a/src/api/java/ic2/api/item/ItemWrapper.class b/src/api/java/ic2/api/item/ItemWrapper.class index 30dd16e14..7c6a6de70 100644 Binary files a/src/api/java/ic2/api/item/ItemWrapper.class and b/src/api/java/ic2/api/item/ItemWrapper.class differ diff --git a/src/api/java/ic2/api/recipe/IMachineRecipeManager.java b/src/api/java/ic2/api/recipe/IMachineRecipeManager.java index 388e394a7..d2d4382b7 100644 --- a/src/api/java/ic2/api/recipe/IMachineRecipeManager.java +++ b/src/api/java/ic2/api/recipe/IMachineRecipeManager.java @@ -7,26 +7,26 @@ import net.minecraft.nbt.NBTTagCompound; /** * Recipe manager interface for basic machines. - * + * * @author RichardG, Player */ -public interface IMachineRecipeManager { +public interface IMachineRecipeManager { // TODO: merge with IMachineRecipeManagerExt /** * Adds a recipe to the machine. - * + * * @param input Recipe input * @param metadata meta data for additional recipe properties, may be null * @param outputs Recipe outputs, zero or more depending on the machine - * + * * For the thermal centrifuge @param metadata meta data {"minHeat": 1-xxx} * For the ore washing plant @param metadata meta data {"amount": 1-8000} - * + * */ public void addRecipe(IRecipeInput input, NBTTagCompound metadata, ItemStack... outputs); /** * Gets the recipe output for the given input. - * + * * @param input Recipe input * @param adjustInput modify the input according to the recipe's requirements * @return Recipe output, or null if none @@ -35,10 +35,10 @@ public interface IMachineRecipeManager { /** * Gets a list of recipes. - * + * * You're a mad evil scientist if you ever modify this. - * + * * @return List of recipes */ - public Map getRecipes(); + public Map getRecipes(); // TODO: Change to iterable/collection/list } diff --git a/src/api/java/ic2/api/recipe/IMachineRecipeManagerExt.class b/src/api/java/ic2/api/recipe/IMachineRecipeManagerExt.class new file mode 100644 index 000000000..b6f9bac0e Binary files /dev/null and b/src/api/java/ic2/api/recipe/IMachineRecipeManagerExt.class differ diff --git a/src/api/java/ic2/api/recipe/IMachineRecipeManagerExt.java b/src/api/java/ic2/api/recipe/IMachineRecipeManagerExt.java new file mode 100644 index 000000000..9c68706d9 --- /dev/null +++ b/src/api/java/ic2/api/recipe/IMachineRecipeManagerExt.java @@ -0,0 +1,22 @@ +package ic2.api.recipe; + +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; + +public interface IMachineRecipeManagerExt extends IMachineRecipeManager { + /** + * Adds a recipe to the machine. + * + * @note Overwrite is only as reliable as IRecipeInput.getInputs(). + * + * @param input Recipe input + * @param metadata Meta data for additional recipe properties, may be null. + * @param overwrite Replace an existing recipe, not recommended, may be ignored. + * @param outputs Recipe outputs, zero or more depending on the machine. + * @return true on success, false otherwise, e.g. on conflicts. + * + * For the thermal centrifuge @param metadata meta data {"minHeat": 1-xxx} + * For the ore washing plant @param metadata meta data {"amount": 1-8000} + */ + public boolean addRecipe(IRecipeInput input, NBTTagCompound metadata, boolean overwrite, ItemStack... outputs); +} diff --git a/src/api/java/ic2/api/recipe/RecipeInputItemStack.class b/src/api/java/ic2/api/recipe/RecipeInputItemStack.class index 6fd10a58b..2f3a70ba1 100644 Binary files a/src/api/java/ic2/api/recipe/RecipeInputItemStack.class and b/src/api/java/ic2/api/recipe/RecipeInputItemStack.class differ diff --git a/src/api/java/ic2/api/recipe/RecipeInputItemStack.java b/src/api/java/ic2/api/recipe/RecipeInputItemStack.java index e1b65f947..84f86ea12 100644 --- a/src/api/java/ic2/api/recipe/RecipeInputItemStack.java +++ b/src/api/java/ic2/api/recipe/RecipeInputItemStack.java @@ -21,7 +21,8 @@ public class RecipeInputItemStack implements IRecipeInput { @Override public boolean matches(ItemStack subject) { - return subject.getItem() == input.getItem() && (subject.getItemDamage() == input.getItemDamage() || input.getItemDamage() == OreDictionary.WILDCARD_VALUE); + return subject.getItem() == input.getItem() && + (subject.getItemDamage() == input.getItemDamage() || input.getItemDamage() == OreDictionary.WILDCARD_VALUE); } @Override diff --git a/src/api/java/ic2/api/recipe/RecipeInputOreDict.class b/src/api/java/ic2/api/recipe/RecipeInputOreDict.class index a068e8fc9..5db862212 100644 Binary files a/src/api/java/ic2/api/recipe/RecipeInputOreDict.class and b/src/api/java/ic2/api/recipe/RecipeInputOreDict.class differ diff --git a/src/api/java/ic2/api/recipe/RecipeInputOreDict.java b/src/api/java/ic2/api/recipe/RecipeInputOreDict.java index 89f73dc2a..e6e4695d0 100644 --- a/src/api/java/ic2/api/recipe/RecipeInputOreDict.java +++ b/src/api/java/ic2/api/recipe/RecipeInputOreDict.java @@ -1,8 +1,10 @@ package ic2.api.recipe; import java.util.ArrayList; +import java.util.Collections; import java.util.List; +import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraftforge.oredict.OreDictionary; @@ -24,14 +26,19 @@ public class RecipeInputOreDict implements IRecipeInput { @Override public boolean matches(ItemStack subject) { - List inputs = OreDictionary.getOres(input); + List inputs = getOres(); + boolean useOreStackMeta = (meta == null); + Item subjectItem = subject.getItem(); + int subjectMeta = subject.getItemDamage(); - for (ItemStack input1 : inputs) { - if (input1.getItem() == null) continue; // ignore invalid - int metaRequired = meta == null ? input1.getItemDamage() : meta; + for (ItemStack oreStack : inputs) { + Item oreItem = oreStack.getItem(); + if (oreItem == null) continue; // ignore invalid - if (subject.getItem() == input1.getItem() && - (subject.getItemDamage() == metaRequired || metaRequired == OreDictionary.WILDCARD_VALUE)) { + int metaRequired = useOreStackMeta ? oreStack.getItemDamage() : meta; + + if (subjectItem == oreItem && + (subjectMeta == metaRequired || metaRequired == OreDictionary.WILDCARD_VALUE)) { return true; } } @@ -46,14 +53,27 @@ public class RecipeInputOreDict implements IRecipeInput { @Override public List getInputs() { - List ores = OreDictionary.getOres(input); + List ores = getOres(); + + // check if we have to filter the list first + boolean hasInvalidEntries = false; + + for (ItemStack stack : ores) { + if (stack.getItem() == null) { + hasInvalidEntries = true; + break; + } + } + + if (!hasInvalidEntries) return ores; + List ret = new ArrayList(ores.size()); for (ItemStack stack : ores) { if (stack.getItem() != null) ret.add(stack); // ignore invalid } - return ret; + return Collections.unmodifiableList(ret); } @Override @@ -65,7 +85,20 @@ public class RecipeInputOreDict implements IRecipeInput { } } + private List getOres() { + if (ores != null) return ores; + + // cache the ore list by making use of the fact that forge always uses the same list, + // unless it's EMPTY_LIST, which should never happen. + List ret = OreDictionary.getOres(input); + + if (ret != OreDictionary.EMPTY_LIST) ores = ret; + + return ret; + } + public final String input; public final int amount; public final Integer meta; + private List ores; } diff --git a/src/api/java/ic2/api/recipe/RecipeOutput.class b/src/api/java/ic2/api/recipe/RecipeOutput.class index 48a57872c..0dad69cfc 100644 Binary files a/src/api/java/ic2/api/recipe/RecipeOutput.class and b/src/api/java/ic2/api/recipe/RecipeOutput.class differ diff --git a/src/api/java/ic2/api/recipe/RecipeOutput.java b/src/api/java/ic2/api/recipe/RecipeOutput.java index 867cfa258..34c7fe9c3 100644 --- a/src/api/java/ic2/api/recipe/RecipeOutput.java +++ b/src/api/java/ic2/api/recipe/RecipeOutput.java @@ -1,6 +1,7 @@ package ic2.api.recipe; import java.util.Arrays; +import java.util.Iterator; import java.util.List; import net.minecraft.item.ItemStack; @@ -18,6 +19,31 @@ public final class RecipeOutput { this(metadata1, Arrays.asList(items1)); } + @Override + public boolean equals(Object obj) { + if (obj instanceof RecipeOutput) { + RecipeOutput ro = (RecipeOutput) obj; + + if (items.size() == ro.items.size() && + (metadata == null && ro.metadata == null || metadata != null && ro.metadata != null) && + metadata.equals(ro.metadata)) { + Iterator itA = items.iterator(); + Iterator itB = ro.items.iterator(); + + while (itA.hasNext() && itB.hasNext()) { + ItemStack stackA = itA.next(); + ItemStack stackB = itB.next(); + + if (ItemStack.areItemStacksEqual(stackA, stackB)) return false; + } + + return true; + } + } + + return false; + } + @Override public String toString() { return "ROutput<"+items+","+metadata+">"; diff --git a/src/main/java/mekanism/common/multipart/PartUniversalCable.java b/src/main/java/mekanism/common/multipart/PartUniversalCable.java index ffe85d1fc..9f35ce10e 100644 --- a/src/main/java/mekanism/common/multipart/PartUniversalCable.java +++ b/src/main/java/mekanism/common/multipart/PartUniversalCable.java @@ -82,58 +82,59 @@ public class PartUniversalCable extends PartTransmitter implement cacheEnergy = 0; } - List sides = getConnections(ConnectionType.PULL); - - if(!sides.isEmpty()) + List sides = getConnections(ConnectionType.PULL); + + if(!sides.isEmpty()) + { + TileEntity[] connectedOutputters = CableUtils.getConnectedOutputters(tile()); + + for(ForgeDirection side : sides) { - TileEntity[] connectedOutputters = CableUtils.getConnectedOutputters(tile()); - - for(ForgeDirection side : sides) + if(connectedOutputters[side.ordinal()] != null) { - if(connectedOutputters[side.ordinal()] != null) + TileEntity outputter = connectedOutputters[side.ordinal()]; + + if(outputter instanceof ICableOutputter && outputter instanceof IStrictEnergyStorage) { - TileEntity outputter = connectedOutputters[side.ordinal()]; - - if(outputter instanceof ICableOutputter && outputter instanceof IStrictEnergyStorage) + if(((ICableOutputter)outputter).canOutputTo(side.getOpposite())) { - if(((ICableOutputter)outputter).canOutputTo(side.getOpposite())) - { - double received = Math.min(((IStrictEnergyStorage)outputter).getEnergy(), drawAmount); - double toDraw = received; - - if(received > 0) - { - toDraw -= getTransmitterNetwork().emit(received, true); - } - ((IStrictEnergyStorage)outputter).setEnergy(((IStrictEnergyStorage)outputter).getEnergy() - toDraw); - } - } - else if(MekanismUtils.useRF() && outputter instanceof IEnergyProvider) - { - double received = ((IEnergyProvider)outputter).extractEnergy(side.getOpposite(), (int)drawAmount, true) * general.FROM_TE; + double received = Math.min(((IStrictEnergyStorage)outputter).getEnergy(), drawAmount); double toDraw = received; if(received > 0) { toDraw -= getTransmitterNetwork().emit(received, true); } - - ((IEnergyProvider)outputter).extractEnergy(side.getOpposite(), (int)toDraw, false); + ((IStrictEnergyStorage)outputter).setEnergy(((IStrictEnergyStorage)outputter).getEnergy() - toDraw); } - else if(MekanismUtils.useIC2() && outputter instanceof IEnergySource) + } + else if(MekanismUtils.useRF() && outputter instanceof IEnergyProvider) + { + double received = ((IEnergyProvider)outputter).extractEnergy(side.getOpposite(), (int)drawAmount, true) * general.FROM_TE; + double toDraw = received; + + if(received > 0) { - double received = Math.min(((IEnergySource)outputter).getOfferedEnergy() * general.FROM_IC2, drawAmount); - double toDraw = received; - - if(received > 0) - { - toDraw -= getTransmitterNetwork().emit(received, true); - } - ((IEnergySource)outputter).drawEnergy(toDraw * general.TO_IC2); + toDraw -= getTransmitterNetwork().emit(received, true); } + + ((IEnergyProvider)outputter).extractEnergy(side.getOpposite(), (int)toDraw, false); + } + else if(MekanismUtils.useIC2() && outputter instanceof IEnergySource) + { + double received = Math.min(((IEnergySource)outputter).getOfferedEnergy() * general.FROM_IC2, drawAmount); + double toDraw = received; + + if(received > 0) + { + toDraw -= getTransmitterNetwork().emit(received, true); + } + + ((IEnergySource)outputter).drawEnergy(toDraw * general.TO_IC2); } } } + } } super.update();