mirror of
https://github.com/Thorfusion/Mekanism-Community-Edition.git
synced 2026-11-27 15:23:16 +00:00
Cleanup, updated IC2 API
This commit is contained in:
1 parent
8f0243d4b1
commit
5513859216
34 files changed
+583
-208
No files matched your search
Binary file not shown.
Binary file not shown.
@@ -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;
|
||||
}
|
||||
}
|
||||
Binary file not shown.
@@ -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
|
||||
}
|
||||
Binary file not shown.
@@ -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<CropCard> 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);
|
||||
}
|
||||
Binary file not shown.
@@ -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);
|
||||
|
||||
|
||||
}
|
||||
Binary file not shown.
Binary file not shown.
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -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;
|
||||
}
|
||||
Binary file not shown.
Binary file not shown.
@@ -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);
|
||||
}
|
||||
Binary file not shown.
@@ -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);
|
||||
}
|
||||
Binary file not shown.
@@ -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);
|
||||
|
||||
}
|
||||
Binary file not shown.
@@ -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<IRecipeInput, RecipeOutput> getRecipes();
|
||||
public Map<IRecipeInput, RecipeOutput> getRecipes(); // TODO: Change to iterable/collection/list
|
||||
}
|
||||
Binary file not shown.
@@ -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);
|
||||
}
|
||||
Binary file not shown.
@@ -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
|
||||
|
||||
Binary file not shown.
@@ -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<ItemStack> inputs = OreDictionary.getOres(input);
|
||||
List<ItemStack> 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<ItemStack> getInputs() {
|
||||
List<ItemStack> ores = OreDictionary.getOres(input);
|
||||
List<ItemStack> 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<ItemStack> ret = new ArrayList<ItemStack>(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<ItemStack> 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<ItemStack> 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<ItemStack> ores;
|
||||
}
|
||||
Binary file not shown.
@@ -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<ItemStack> itA = items.iterator();
|
||||
Iterator<ItemStack> 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+">";
|
||||
|
||||
Reference in new issue
Block a user