Added *experimental and untested* support for creating custom IC2 crops

This commit is contained in:
bculkin2442 committed 2015-07-26 12:14:29 -04:00
1 parent 5e3babe90a
commit 7d1e65dae6
3 files changed
+660

No files matched your search

@@ -0,0 +1,221 @@
package minetweaker.mods.ic2.crops;
import ic2.api.crops.CropCard;
import ic2.api.crops.Crops;
import minetweaker.MineTweakerAPI;
import minetweaker.OneWayAction;
import minetweaker.annotations.ModOnly;
import minetweaker.api.item.IItemStack;
import minetweaker.api.minecraft.MineTweakerMC;
import net.minecraftforge.common.BiomeDictionary;
import stanhebben.zenscript.annotations.ZenCaster;
import stanhebben.zenscript.annotations.ZenClass;
/**
* Provides access to IC2 crop system in general
* @author ben
*
*/
import stanhebben.zenscript.annotations.ZenMethod;
@ZenClass("mods.ic2.CropsConfig")
@ModOnly("IC2")
public class CropsConfig {
/**
* Action to add a new seed for a base crop
* @author ben
*
*/
private static final class RegisterBaseSeedAction extends OneWayAction {
private IItemStack seed;
private CropCard c;
private int sz;
private int growth;
private int gain;
private int resist;
public RegisterBaseSeedAction(IItemStack seed, CropCard c, int sz, int growth, int gain, int resist) {
this.seed = seed;
this.c = c;
this.sz = sz;
this.growth = growth;
this.gain = gain;
this.resist = resist;
}
@Override
public Object getOverrideKey() {
return null;
}
@Override
public String describe() {
return "Registering base seed for crop " + c.name();
}
@Override
public void apply() {
Crops.instance.registerBaseSeed(MineTweakerMC.getItemStack(seed), c, sz, growth, gain, resist);
}
}
/**
* Action to register a new crop
* @author ben
*
*/
private static final class RegisterCropCardAction extends OneWayAction {
private CropCard c;
public RegisterCropCardAction(CropCard c) {
this.c = c;
}
@Override
public Object getOverrideKey() {
return null;
}
@Override
public String describe() {
// TODO Auto-generated method stub
return "Registering crop " + c.name();
}
@Override
public void apply() {
Crops.instance.registerCrop(c);
}
}
/**
* Action to add a biome nutrient bonus
* @author ben
*
*/
private static final class AddBiomeNutrientBonusAction extends OneWayAction {
private String biomeType;
private int nutrientBonus;
public AddBiomeNutrientBonusAction(String biomeType, int nutrientBonus) {
this.biomeType = biomeType;
this.nutrientBonus = nutrientBonus;
}
@Override
public Object getOverrideKey() {
// TODO Auto-generated method stub
return null;
}
@Override
public String describe() {
return "Setting biome nutrient bonus for " + biomeType + " biomes to " +
nutrientBonus;
}
@Override
public void apply() {
Crops.instance.addBiomenutrientsBonus(BiomeDictionary.Type.valueOf(biomeType),
nutrientBonus);
}
}
/**
* Action to add a biome humidity bonus
* @author ben
*
*/
private static final class AddBiomeHumidityBonusAction extends OneWayAction {
private String biomeType;
private int humidityBonus;
public AddBiomeHumidityBonusAction(String biomeType, int humidityBonus) {
this.biomeType = biomeType;
this.humidityBonus = humidityBonus;
}
@Override
public Object getOverrideKey() {
// TODO Auto-generated method stub
return null;
}
@Override
public String describe() {
return "Setting biome humidity bonus for " + biomeType + " biomes to " +
humidityBonus;
}
@Override
public void apply() {
Crops.instance.addBiomehumidityBonus(BiomeDictionary.Type.valueOf(biomeType),
humidityBonus);
}
}
/**
* Add a nutrient bonus to crops in a specific biome
*/
@ZenMethod
public static void addBiomeNutrientBonus(String biomeType, int nutrientBonus) {
if(BiomeDictionary.Type.valueOf(biomeType) == null) {
MineTweakerAPI.logWarning("invalid biome type: " + biomeType);
} else if (nutrientBonus < -10 || nutrientBonus > 10) {
MineTweakerAPI.logWarning("nutrient bonus " + nutrientBonus +
" not in -10, +10 range");
} else {
MineTweakerAPI.apply(new AddBiomeNutrientBonusAction(biomeType, nutrientBonus));
}
}
/**
* Add a humidity bonus to crops in a specific biome
*/
@ZenMethod
public static void addBiomeHumidityBonus(String biomeType, int humidityBonus) {
if(BiomeDictionary.Type.valueOf(biomeType) == null) {
MineTweakerAPI.logWarning("invalid biome type: " + biomeType);
} else if (humidityBonus < -10 || humidityBonus > 10) {
MineTweakerAPI.logWarning("humidity bonus " + humidityBonus +
" not in -10, +10 range");
} else {
MineTweakerAPI.apply(new AddBiomeHumidityBonusAction(biomeType, humidityBonus));
}
}
/**
* Creates a new synthetic crop to manipulate
* @param cropOwner The mod that owns the crop
* @param cropName The name of the crop
*/
@ZenMethod
public static SyntheticCrop newCrop(String cropName, String cropOwner) {
return new SyntheticCrop(cropName, cropOwner);
}
/**
* Register a crop into the crop system
*/
@ZenMethod
public static void registerCrop(CropCard c) {
MineTweakerAPI.apply(new RegisterCropCardAction(c));
}
/**
* Register a new base seed item to plant a crop
*
* @param seed The item to plant with
* @param c The crop being planted
* @param sz The initial size of the planted crop
* @param growth The initial growth stat of the planted crop
* @param gain The initial gain stat of the planted crop
* @param resist The initial resistance of the planted crop
*/
public static void registerBaseSeed(IItemStack seed, CropCard c, int sz,
int growth, int gain, int resist) {
MineTweakerAPI.apply(new RegisterBaseSeedAction(seed, c, sz, growth, gain, resist));
}
}
@@ -0,0 +1,144 @@
package minetweaker.mods.ic2.crops;
import minetweaker.api.item.IItemStack;
import stanhebben.zenscript.annotations.ZenClass;
import stanhebben.zenscript.annotations.ZenGetter;
import stanhebben.zenscript.annotations.ZenSetter;
/**
* Contains all of the growth requirements for an IC2 crop in one easy place
* @author ben
*
*/
@ZenClass("mods.ic2.GrowthRequirements")
public class GrowthRequirements {
private int minNutrients;
private int minHumidity;
private int minAirQuality;
private int minLight;
private int maxLight = 17;
private IItemStack requiredBlock;
/**
* Get the minimum amount of nutrients this plant needs to grow
* @return The minimum amount of nutrients this plant needs
*/
@ZenGetter("minNutrients")
public int getMinNutrients() {
return minNutrients;
}
/**
* Set the minimum amount of nutrients this plant needs to grow
* @param minNutrients The new minimum amount of nutrients this plant requires
*/
@ZenSetter("minNutrients")
public void setMinNutrients(int minNutrients) {
this.minNutrients = minNutrients;
}
/**
* Get the minimum amount of humidity this plant requires
* @return The minimum amount of humidity this plant requires
*/
@ZenGetter("minHumidity")
public int getMinHumidity() {
return minHumidity;
}
/**
* Set the minimum amount of humidity this plant requires
* @param minHumidity The new minimum amount of humidity this plant requires
*/
@ZenSetter("minHumidity")
public void setMinHumidity(int minHumidity) {
this.minHumidity = minHumidity;
}
/**
* Get the minimum air quality this plant requires
* @return The minimum air quality this plant requires
*/
@ZenGetter("minAirQuality")
public int getMinAirQuality() {
return minAirQuality;
}
/**
* Set the minimum air quality this plant requires
* @param minAirQuality The new amount of air quality this plant requires
*/
@ZenSetter("minAirQuality")
public void setMinAirQuality(int minAirQuality) {
this.minAirQuality = minAirQuality;
}
/**
* Get the minimum amount of light this plant requires
* @return The minimum amount of light this plant requires
*/
@ZenGetter("minLight")
public int getMinLight() {
return minLight;
}
/**
* Set the minimum amount of light this plant requires
* @param minLight The new minimum amount of light this plant requires
*/
@ZenSetter("minLight")
public void setMinLight(int minLight) {
this.minLight = minLight;
}
/**
* Get the maximum amount of light this plant can have
* @return The maximum amount of light this plant can have
*/
@ZenGetter("maxLight")
public int getMaxLight() {
return maxLight;
}
/**
* Set the maximum amount of light this plant can have
* @param maxLight The new maximum amount of light thi plant can have
*/
@ZenSetter("maxLight")
public void setMaxLight(int maxLight) {
this.maxLight = maxLight;
}
/**
* Get the block that is required to be below this one
* @return The block required to be below this one
*/
@ZenGetter("requiredBlock")
public IItemStack getRequiredBlock() {
return requiredBlock;
}
/**
* Set the block required to be below this one
* @param requiredBlock The new block required to be below this one
*/
@ZenSetter("requiredBlock")
public void setRequiredBlock(IItemStack requiredBlock) {
this.requiredBlock = requiredBlock;
}
public GrowthRequirements(int minNutrients, int minHumidity, int minAirQuality, int minLight, int maxLight,
IItemStack requiredBlock) {
super();
this.minNutrients = minNutrients;
this.minHumidity = minHumidity;
this.minAirQuality = minAirQuality;
this.minLight = minLight;
this.maxLight = maxLight;
this.requiredBlock = requiredBlock;
}
}
@@ -0,0 +1,295 @@
package minetweaker.mods.ic2.crops;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import ic2.api.crops.CropCard;
import ic2.api.crops.ICropTile;
import minetweaker.MineTweakerAPI;
import minetweaker.api.item.IItemStack;
import minetweaker.api.minecraft.MineTweakerMC;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.item.ItemStack;
import net.minecraft.util.IIcon;
import stanhebben.zenscript.annotations.ZenClass;
import stanhebben.zenscript.annotations.ZenGetter;
import stanhebben.zenscript.annotations.ZenMethod;
import stanhebben.zenscript.annotations.ZenSetter;
/**
* A synthetic crop, created in ZS
*
* For your crop textures to be picked up, put them at owner + ":crops/crop" +
* name + "." + size where owner is the mod responsible for the crop name is the
* name of the crop size is the current size of the crop, starting at 0 for new
* crops
*
* Localizations will be looked for at owner + ".crop." + name where each field
* has the value it has above
*
* @author ben
*
*/
@ZenClass("mods.ic2.Crop")
public class SyntheticCrop extends CropCard {
private String name;
private String owner;
private int tier;
private int[] stats = new int[4];
private String[] attributes;
private int maxSize;
private float dropChance;
private IItemStack fruit;
private GrowthRequirements reqs;
/**
* Create a new synthetic crop
*
* @param cropName
* The name of this crop
* @param cropOwner
* The mod creating this crop
*/
public SyntheticCrop(String cropName, String cropOwner) {
name = cropName;
}
// Required IC2 Interface
/**
* Gets the name of this crop used as a identifier
*/
@Override
@ZenGetter("name")
public String name() {
return name;
}
/**
* Get the mod that owns this crop
*/
@Override
@ZenGetter("owner")
public String owner() {
return owner;
}
/**
* Gets the localization key used for this crop
*/
@Override
public String displayName() {
return owner + ".crop." + name;
}
/**
* Gets the seed tier of this crop.
*/
@Override
@ZenGetter("tier")
public int tier() {
return tier;
}
/**
* Gets the value of a particular stat for this crop
*
* 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)
*
*/
@Override
@ZenMethod
public int stat(int n) {
return stats[n];
}
/**
* Gets any additional attributes of this crop
*/
@Override
@ZenGetter("attributes")
public String[] attributes() {
return attributes;
}
/**
* Gets the maximum size of this crop
*/
@Override
@ZenGetter("maxSize")
public int maxSize() {
return maxSize;
}
@Override
@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(owner() + ":crop/crop" + name() + "." + i);
}
}
@Override
public boolean canGrow(ICropTile crop) {
if (crop.getSize() == maxSize) {
return false;
} else if (reqs == null) {
return true;
} else {
if(!crop.isBlockBelow(MineTweakerMC.getBlock(reqs.getRequiredBlock()))) {
return false;
} else if(crop.getAirQuality() < reqs.getMinAirQuality()){
return false;
} else if(crop.getHumidity() < reqs.getMinHumidity()) {
return false;
} else if(crop.getNutrients() < reqs.getMinNutrients()) {
return false;
} else {
int lgh = crop.getLightLevel();
return reqs.getMinLight() < lgh && reqs.getMaxLight() > lgh;
}
}
}
@Override
public int getOptimalHavestSize(ICropTile crop) {
return maxSize;
}
@Override
public boolean canBeHarvested(ICropTile crop) {
return crop.getSize() == maxSize;
}
@Override
public ItemStack getGain(ICropTile crop) {
return MineTweakerMC.getItemStack(fruit);
}
/**
* Gets the chance for this crop to drop an item
*/
@Override
@ZenGetter("dropChance")
public float dropGainChance() {
return dropChance;
};
// ZS Support
/**
* Sets the tier of this crop
*
* @param tier
* The new tier of this crop
*/
@ZenSetter("tier")
public void setTier(int tier) {
this.tier = tier;
}
/**
* Sets all of the stats for this crop
*
* @param stats
* The new stats to give to this crop
*/
@ZenSetter("stats")
public void setStats(int[] stats) {
this.stats = stats;
}
/**
* Sets an individual stat for this crop
*
* @param stat
* The stat to set a value for
* @param val
* The new value for this stat
*/
@ZenMethod
public void setStat(int stat, int val) {
if (stat < 0 || stat > 3) {
MineTweakerAPI.logWarning("invalid stat index " + stat);
} else {
stats[stat] = val;
}
}
/**
* Sets the additional attributes for this crop
*
* @param attributes
* Sets the attributes of this crop
*/
@ZenSetter("attributes")
public void setAttributes(String[] attributes) {
this.attributes = attributes;
}
/**
* Sets the maximum size this crop goes to
*
* @param maxSize
* The new max size of this crop
*/
@ZenSetter("maxSize")
public void setMaxSize(int maxSize) {
this.maxSize = maxSize;
}
/**
* Sets the item this crop gives when harvested
*
* @param fruit
* The item to give from the crop
*/
@ZenSetter("fruit")
public void setFruit(IItemStack fruit) {
this.fruit = fruit;
}
/**
* Sets the chance for this plant to yield its fruit
*
* @param dropChance
* The new chance for this plant to yield fruit
*/
@ZenSetter("dropChance")
public void setDropChance(int dropChance) {
this.dropChance = dropChance;
}
/**
* Get the current requirements for this plant to grow
*
* @return The current growth requirements for this plant
*/
public GrowthRequirements getReqs() {
return reqs;
}
/**
* Set the current growth requirements for this plant to grow
*
* @param reqs
* The new requirements for this plant to grow
*/
public void setReqs(GrowthRequirements reqs) {
this.reqs = reqs;
}
}