updated APIs and fixed #706

This commit is contained in:
Katrina Swales committed 2015-03-30 02:10:53 +02:00
1 parent 2bcc83bc87
commit ec26bfee98
111 files changed
+3483 -3387

No files matched your search

+1 -1
View File
@@ -96,7 +96,7 @@ if (project.hasProperty("releaseType"))
dependencies {
compile "codechicken:CodeChickenLib:1.7.10-1.1.1.106:dev"
compile "codechicken:CodeChickenCore:1.7.10-1.0.4.29:dev"
compile "mcp.mobius.waila:Waila:1.5.3a_1.7.10"
compile "mcp.mobius.waila:Waila:1.5.8_1.7.10"
compile "codechicken:ForgeMultipart:1.7.10-1.1.0.300:dev"
compile 'com.mod-buildcraft:buildcraft:6.3.3:dev'
+90 -100
View File
@@ -2,126 +2,116 @@ package ic2.api;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
import net.minecraftforge.common.util.ForgeDirection;
/**
* Represents the 6 possible directions along the axis of a block.
*/
public enum Direction {
/**
* -X
*/
XN(0),
/**
* +X
*/
XP(1),
/**
* -X
*/
XN,
/**
* +X
*/
XP,
/**
* -Y
*/
YN(2), //MC-Code starts with 0 here
/**
* +Y
*/
YP(3), // 1...
/**
* -Y
*/
YN, //MC-Code starts with 0 here
/**
* +Y
*/
YP, // 1...
/**
* -Z
*/
ZN(4),
/**
* +Z
*/
ZP(5);
/**
* -Z
*/
ZN,
/**
* +Z
*/
ZP;
public static Direction fromSideValue(int side) {
return directions[(side + 2) % 6];
}
public static Direction fromSideValue(int side) {
return directions[(side + 2) % 6];
}
public static Direction fromForgeDirection(ForgeDirection dir) {
if (dir == ForgeDirection.UNKNOWN) return null;
public static Direction fromForgeDirection(ForgeDirection dir) {
if (dir == ForgeDirection.UNKNOWN) return null;
return fromSideValue(dir.ordinal());
}
return fromSideValue(dir.ordinal());
}
private Direction(int dir1) {
this.dir = dir1;
}
/**
* Get the tile entity next to a tile entity following this direction.
*
* @param tileEntity tile entity to check
* @return Adjacent tile entity or null if none exists
*/
public TileEntity applyToTileEntity(TileEntity te) {
return applyTo(te.getWorldObj(), te.xCoord, te.yCoord, te.zCoord);
}
/**
* Get the tile entity next to a tile entity following this direction.
*
* @param tileEntity tile entity to check
* @return Adjacent tile entity or null if none exists
*/
public TileEntity applyToTileEntity(TileEntity te) {
return applyTo(te.getWorldObj(), te.xCoord, te.yCoord, te.zCoord);
}
/**
* Get the tile entity next to a position following this direction.
*
* @param world World to check
* @param x X coordinate to check from
* @param y Y coordinate to check from
* @param z Z coordinate to check from
* @return Adjacent tile entity or null if none exists
*/
public TileEntity applyTo(World world, int x, int y, int z) {
int coords[] = { x, y, z };
/**
* Get the tile entity next to a position following this direction.
*
* @param world World to check
* @param x X coordinate to check from
* @param y Y coordinate to check from
* @param z Z coordinate to check from
* @return Adjacent tile entity or null if none exists
*/
public TileEntity applyTo(World world, int x, int y, int z) {
int coords[] = {x, y, z};
coords[ordinal() / 2] += getSign();
coords[dir / 2] += getSign();
if (world != null && world.blockExists(coords[0], coords[1], coords[2])) {
try {
return world.getTileEntity(coords[0], coords[1], coords[2]);
} catch (Exception e) {
throw new RuntimeException("error getting TileEntity at dim "+world.provider.dimensionId+" "+coords[0]+"/"+coords[1]+"/"+coords[2]);
}
}
if (world != null && world.blockExists(coords[0], coords[1], coords[2])) {
try {
return world.getTileEntity(coords[0], coords[1], coords[2]);
} catch (Exception e) {
throw new RuntimeException("error getting TileEntity at dim " + world.provider.dimensionId + " " + coords[0] + "/" + coords[1] + "/" + coords[2]);
}
}
return null;
}
return null;
}
/**
* Get the inverse of this direction (XN -> XP, XP -> XN, etc.)
*
* @return Inverse direction
*/
public Direction getInverse() {
return directions[ordinal() ^ 1];
}
/**
* Get the inverse of this direction (XN -> XP, XP -> XN, etc.)
*
* @return Inverse direction
*/
public Direction getInverse() {
int inverseDir = dir - getSign();
/**
* Convert this direction to a Minecraft side value.
*
* @return Minecraft side value
*/
public int toSideValue() {
return (ordinal() + 4) % 6;
}
for (Direction direction : directions) {
if (direction.dir == inverseDir) return direction;
}
/**
* Determine direction sign (N for negative or P for positive).
*
* @return -1 if the direction is negative, +1 if the direction is positive
*/
private int getSign() {
return (ordinal() % 2) * 2 - 1;
}
return this;
}
public ForgeDirection toForgeDirection() {
return ForgeDirection.getOrientation(toSideValue());
}
/**
* Convert this direction to a Minecraft side value.
*
* @return Minecraft side value
*/
public int toSideValue() {
return (dir + 4) % 6;
}
/**
* Determine direction sign (N for negative or P for positive).
*
* @return -1 if the direction is negative, +1 if the direction is positive
*/
private int getSign() {
return (dir % 2) * 2 - 1;
}
public ForgeDirection toForgeDirection() {
return ForgeDirection.getOrientation(toSideValue());
}
private int dir;
public static final Direction[] directions = Direction.values();
public static final Direction[] directions = Direction.values();
}
+69 -43
View File
@@ -4,53 +4,79 @@ package ic2.api.crops;
* Base agriculture seed. Used to determine the state of a plant once it is planted from an item.
*/
public class BaseSeed {
/**
* Plant ID.
*/
public int 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;
}
/**
* Plant size.
*/
public int size;
/**
* @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);
}
/**
* Plant growth stat.
*/
public int statGrowth;
@SuppressWarnings("deprecation")
private static CropCard getCropFromId(int id) {
CropCard[] crops = Crops.instance.getCropList();
/**
* Plant gain stat.
*/
public int statGain;
if (id < 0 || id >= crops.length) return null;
/**
* Plant resistance stat.
*/
public int statResistance;
return crops[id];
}
/**
* 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;
}
/**
* Plant.
*/
public final CropCard crop;
/**
* @deprecated IDs aren't used anymore.
*/
@Deprecated
public int id;
/**
* Plant size.
*/
public int size;
/**
* Plant growth stat.
*/
public int statGrowth;
/**
* Plant gain stat.
*/
public int statGain;
/**
* Plant resistance stat.
*/
public int statResistance;
/**
* For internal usage only.
*/
public int stackSize;
}
+380 -326
View File
@@ -1,7 +1,5 @@
package ic2.api.crops;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
@@ -9,371 +7,427 @@ 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.
* <p/>
*
* Any crop extending this can be registered using registerCrop to be added into the game.
*/
public abstract class CropCard {
/**
* Plant name. Will be displayed to the player.
*
* @return Plant name
*/
public abstract String name();
public CropCard() {
modId = getModId(); // initialize mod id while we should be in the real owner's init event
}
/**
* Your name here, will be shown in "Discovered by:" when analyzing seeds.
*
* @return Your name
*/
public String discoveredBy() {
return "IC2 Team";
}
/**
* 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();
/**
* 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) {
s += ", " + att[1];
if (att.length >= 3) s += ",";
}
return s;
}
if (att.length < 3) return "";
String s = att[2];
if (att.length >= 4) s += ", " + att[3];
return s;
}
/**
* 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;
}
/**
* 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();
/**
* 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
}
/**
* Describe the plant through a set of stats, influencing breeding.
* Plants sharing stats and attributes will tend to cross-breed more often.
* <p/>
* 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
*/
public abstract int stat(int n);
/**
* Your name here, will be shown in "Discovered by:" when analyzing seeds.
*
* @return Your name
*/
public String discoveredBy() {
return "unknown";
}
/**
* 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();
/**
* 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();
/**
* Determine the max crop size.
* <p/>
* Currently only used for texture allocation.
*/
public abstract int maxSize();
if (att == null || att.length == 0) return "";
/**
* Instantiate your Icons here.
* <p/>
* This method will get called by IC2, don't call it yourself.
*/
@SideOnly(Side.CLIENT)
public void registerSprites(IIconRegister iconRegister) {
textures = new IIcon[maxSize()];
if (i == 0) {
String s = att[0];
if (att.length >= 2) {
s+=", "+att[1];
if (att.length >= 3) s+=",";
}
return s;
}
if (att.length < 3) return "";
String s = att[2];
if (att.length >= 4) s+=", "+att[3];
return s;
}
for (int i = 1; i <= textures.length; i++) {
textures[i - 1] = iconRegister.registerIcon("ic2:crop/blockCrop." + name() + "." + i);
}
}
/**
* *
* @param crop reference to ICropTile
* @return roots lengt use in isBlockBelow
*/
public int getrootslength(ICropTile crop) {
return 1;
}
/**
* 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.
*/
@SideOnly(Side.CLIENT)
public IIcon getSprite(ICropTile crop) {
if (crop.getSize() <= 0 || crop.getSize() > textures.length) return null;
/**
* 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();
return textures[crop.getSize() - 1];
}
/**
* 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
*/
public abstract int stat(int n);
/**
* 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";
}
/**
* 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();
/**
* Amount of growth points needed to increase the plant's size.
* Default is 200 * tier.
*/
public int growthDuration(ICropTile crop) {
return tier() * 200;
}
/**
* Determine the max crop size.
*
* Currently only used for texture allocation.
*/
public abstract int maxSize();
/**
* Check whether the plant can grow further.
* <p/>
* Consider:
* - Humidity, nutrients and air quality
* - Current size
* - Light level
* - Special biomes or conditions, accessible through crop.worldObj
* <p/>
* 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
*/
public abstract boolean canGrow(ICropTile crop);
/**
* 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()];
/**
* 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)
* <p/>
* 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
* @param air air quality, influences by open gardens and less crops surrounding this one
* @return 0-30
*/
public int weightInfluences(ICropTile crop, float humidity, float nutrients, float air) {
return (int) (humidity + nutrients + air);
}
for (int i = 1; i <= textures.length; i++) {
// ic2:crop/blockCrop.NAME.n is the legacy name for backwards compatiblity
textures[i - 1] = iconRegister.registerIcon("ic2:crop/blockCrop."+name()+"."+i);
}
}
/**
* 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) {
return crop.getSize() >= 3;
}
/**
* 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.
*/
@SideOnly(Side.CLIENT)
public IIcon getSprite(ICropTile crop) {
if (crop.getSize() <= 0 || crop.getSize() > textures.length) return null;
return textures[crop.getSize() - 1];
}
/**
* Amount of growth points needed to increase the plant's size.
* Default is 200 * tier.
*/
public int growthDuration(ICropTile crop) {
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
*/
public abstract boolean canGrow(ICropTile crop);
/**
* 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
* @param air air quality, influences by open gardens and less crops surrounding this one
* @return 0-30
*/
public int weightInfluences(ICropTile crop, float humidity, float nutrients, float air) {
return (int) (humidity+nutrients+air);
}
/**
* 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) {
return crop.getSize() >= 3;
}
/**
* Called when the plant is rightclicked by a player.
* Default action is harvesting.
* <p/>
* Only called Serverside.
*
* @param crop reference to ICropTile
* @param player player rightclicking the crop
* @return Whether the plant has changed
*/
public boolean rightclick(ICropTile crop, EntityPlayer player) {
return crop.harvest(true);
}
/**
* 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
*/
public boolean rightclick(ICropTile crop, EntityPlayer player) {
return crop.harvest(true);
}
/**
* Use in Crop Havester with insert Cropnalyzer to get best Output.
*
* @param crop reference to ICropTile
* @return need crop size for best output.
*/
/**
* Use in Crop Havester with insert Cropnalyzer to get best Output.
*
* @param crop reference to ICropTile
* @return need crop size for best output.
*/
public abstract int getOptimalHavestSize(ICropTile crop);
public abstract int getOptimalHavestSize(ICropTile crop);
/**
* Check whether the crop can be harvested.
*
* @param crop reference to ICropTile
* @return Whether the crop can be harvested in its current state.
*/
public abstract boolean canBeHarvested(ICropTile crop);
/**
* Check whether the crop can be harvested.
*
* @param crop reference to ICropTile
* @return Whether the crop can be harvested in its current state.
*/
public abstract boolean canBeHarvested(ICropTile crop);
/**
* 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() {
float base = 1F;
for (int i = 0; i < tier(); i++) {
base *= 0.95;
}
return base;
}
/**
* 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() {
float base = 1F;
for (int i = 0; i < tier(); i++) {base*=0.95;}
return base;
}
/**
* Item obtained from harvesting the plant.
*
* @param crop reference to ICropTile
* @return Item obtained
*/
public abstract ItemStack getGain(ICropTile crop);
/**
* Item obtained from harvesting the plant.
*
* @param crop reference to ICropTile
* @return Item obtained
*/
public abstract ItemStack getGain(ICropTile crop);
/**
* Get the size of the plant after harvesting.
* Default is 1.
*
* @param crop reference to ICropTile
* @return Plant size after harvesting
*/
public byte getSizeAfterHarvest(ICropTile crop) {
return 1;
}
/**
* Get the size of the plant after harvesting.
* Default is 1.
*
* @param crop reference to ICropTile
* @return Plant size after harvesting
*/
public byte getSizeAfterHarvest(ICropTile crop) {return 1;}
/**
* Called when the plant is leftclicked by a player.
* Default action is picking the plant.
* <p/>
* Only called Serverside.
*
* @param crop reference to ICropTile
* @param player player leftclicked the crop
* @return Whether the plant has changed
*/
public boolean leftclick(ICropTile crop, EntityPlayer player) {
return crop.pick(true);
}
/**
* 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
*/
public boolean leftclick(ICropTile crop, EntityPlayer player) {
return crop.pick(true);
}
/**
* 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
*/
public float dropSeedChance(ICropTile crop) {
if (crop.getSize() == 1) return 0;
float base = 0.5F;
if (crop.getSize() == 2) base /= 2F;
for (int i = 0; i < tier(); i++) {
base *= 0.8;
}
return base;
}
/**
* 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
*/
public float dropSeedChance(ICropTile crop) {
if (crop.getSize() == 1) return 0;
float base = 0.5F;
if (crop.getSize() == 2) base/=2F;
for (int i = 0; i < tier(); i++) {base*=0.8;}
return base;
}
/**
* 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());
}
/**
* 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.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) {
//
}
/**
* Called when a neighbor block to the crop has changed.
*
* @param crop reference to ICropTile
*/
public void onNeighbourChange(ICropTile crop) {
//
}
/**
* Check if the crop should emit redstone.
*
* @return Whether the crop should emit redstone
*/
public int emitRedstone(ICropTile crop) {
return 0;
}
/**
* 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) {
//
}
/**
* Called when the crop is destroyed.
*
* @param crop reference to ICropTile
*/
public void onBlockDestroyed(ICropTile crop) {
//
}
/**
* Get the light value emitted by the plant.
*
* @param crop reference to ICropTile
* @return Light value emitted
*/
public int getEmittedLight(ICropTile crop) {
return 0;
}
/**
* Get the light value emitted by the plant.
*
* @param crop reference to ICropTile
* @return Light value emitted
*/
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.
*/
public boolean onEntityCollision(ICropTile crop, Entity entity) {
if (entity instanceof EntityLivingBase) {
return ((EntityLivingBase) entity).isSprinting();
}
return false;
}
/**
* 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.
*/
public boolean onEntityCollision(ICropTile crop, Entity entity) {
if (entity instanceof EntityLivingBase) {
return ((EntityLivingBase) entity).isSprinting();
}
return false;
}
/**
* 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) {
//
}
/**
* 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);
}
/**
* 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 == Crops.weed || crop.getGrowth() >= 24);
}
/**
* Get this plant's ID.
*
* @return ID of this CropCard or -1 if it's not registered
*/
public final int getId() {
return Crops.instance.getIdFor(this);
}
/**
* 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);
}
@SideOnly(Side.CLIENT)
protected IIcon textures[];
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
}
+128 -92
View File
@@ -1,115 +1,151 @@
package ic2.api.crops;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import java.util.Collection;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.item.ItemStack;
import net.minecraft.world.biome.BiomeGenBase;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraftforge.common.BiomeDictionary.Type;
/**
* General management of the crop system.
*/
public abstract class Crops {
public static Crops instance;
public static Crops instance;
/**
* Adds a crop humidity and nutrient biome bonus.
* <p/>
* 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.
* <p/>
* 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);
/**
* 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 nutrientsBonus Nutrient stat bonus
*/
public abstract void addBiomenutrientsBonus(Type type, int nutrientsBonus);
/**
* Gets the humidity bonus for a biome.
*
* @param biome Biome to check
* @return Humidity bonus or 0 if none
*/
public abstract int getHumidityBiomeBonus(BiomeGenBase biome);
/**
* 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 nutrient bonus for a biome.
*
* @param biome Biome to check
* @return Nutrient bonus or 0 if none
*/
public abstract int getNutrientBiomeBonus(BiomeGenBase biome);
/**
* Returns the list of registered crops.
*
* @return Registered crops by ID
*/
public abstract CropCard[] getCropList();
/**
* Gets the humidity bonus for a biome.
*
* @param biome Biome to check
* @return Humidity bonus or 0 if none
*/
public abstract int getHumidityBiomeBonus(BiomeGenBase biome);
/**
* 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
*/
public abstract short registerCrop(CropCard crop);
/**
* 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);
/**
* 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
*/
public abstract boolean registerCrop(CropCard crop, int i);
/**
* 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);
/**
* Registers a base seed, an item used to plant a crop.
*
* @param stack item
* @param id plant ID
* @param size initial size
* @param growth initial growth stat
* @param gain initial gain stat
* @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);
/**
* 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);
/**
* Finds a base seed from the given item.
*
* @return Base seed or null if none found
*/
public abstract BaseSeed getBaseSeed(ItemStack stack);
/**
* Returns a list of all crops.
*
* @return All registered crops.
*/
public abstract Collection<CropCard> getCrops();
/**
* Execute registerSprites for all registered crop cards.
* <p/>
* This method will get called by IC2, don't call it yourself.
*/
@SideOnly(Side.CLIENT)
public abstract void startSpriteRegistration(IIconRegister iconRegister);
/**
* Returns the list of registered crops.
*
* @return Registered crops by ID
*/
@Deprecated
public abstract CropCard[] getCropList();
/**
* Returns the ID for the given crop.
*
* @param crop Crop to look up
* @return ID, or -1 if not found
*/
public abstract int getIdFor(CropCard crop);
/**
* Register a plant.
*
* @param crop Plant to register.
* @return Autoassigned id for legacy compatibility, TODO: change to void.
*/
public abstract short registerCrop(CropCard crop);
/**
* 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 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
* @param growth initial growth stat
* @param gain initial gain stat
* @param resistance initial resistance stat
* @return True if successful
*/
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)
public abstract void startSpriteRegistration(IIconRegister iconRegister);
/**
* 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);
}
+233 -216
View File
@@ -10,254 +10,271 @@ import net.minecraft.world.World;
* Interface implemented by the crop tile entity.
*/
public interface ICropTile {
/**
* Get the crop's plant ID.
*
* @return Plant ID, or -1 if there is no plant currently on the crop
*/
public short getID();
/**
* Get the crop.
*
* @return CropCard, or null if there is no plant currently on the crop
*/
public CropCard getCrop();
/**
* Set the crop's plant ID.
*
* @param id Plant ID, or -1 for no plant
*/
public void setID(short id);
/**
* Set the crop.
*
* @param cropCard CropCard or null for no plant
*/
public void setCrop(CropCard cropCard);
/**
* Get the crop's plant size.
*
* @return Plant size, starting with 1 and maximum varies depending on plant
*/
public byte getSize();
/**
* @deprecated IDs have been removed.
*/
@Deprecated
public short getID();
/**
* Set the crop's plant size.
*
* @param size Plant size
*/
public void setSize(byte size);
/**
* @deprecated IDs have been removed.
*/
@Deprecated
public void setID(short id);
/**
* Get the crop's plant growth stat.
* Higher values indicate faster growth.
*
* @return Plant growth stat
*/
public byte getGrowth();
/**
* 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 growth stat.
*
* @param growth Plant growth stat
*/
public void setGrowth(byte growth);
/**
* Set the crop's plant size.
*
* @param size Plant size
*/
public void setSize(byte size);
/**
* Get the crop's plant gain stat.
* Higher values indicate more drops.
*
* @return Plant gain stat
*/
public byte getGain();
/**
* Get the crop's plant growth stat.
* Higher values indicate faster growth.
*
* @return Plant growth stat
*/
public byte getGrowth();
/**
* Set the crop's plant gain stat.
*
* @param gain Plant gain stat
*/
public void setGain(byte gain);
/**
* Set the crop's plant growth stat.
*
* @param growth Plant growth stat
*/
public void setGrowth(byte growth);
/**
* Get the crop's plant resistance stat.
* Higher values indicate more resistance against trampling.
*
* @return Plant resistance stat
*/
public byte getResistance();
/**
* Get the crop's plant gain stat.
* Higher values indicate more drops.
*
* @return Plant gain stat
*/
public byte getGain();
/**
* Set the crop's plant resistance stat.
*
* @param resistance Plant resistance stat
*/
public void setResistance(byte resistance);
/**
* Set the crop's plant gain stat.
*
* @param gain Plant gain stat
*/
public void setGain(byte gain);
/**
* Get the crop's plant scan level.
* Increases every time the seed is analyzed.
*
* @return Plant scan level
*/
public byte getScanLevel();
/**
* 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 scan level.
*
* @param scanLevel Plant scan level
*/
public void setScanLevel(byte scanLevel);
/**
* Set the crop's plant resistance stat.
*
* @param resistance Plant resistance stat
*/
public void setResistance(byte resistance);
/**
* Get the crop's plant custom data, stored alongside the crop.
* Can be modified in place.
*
* @return Plant custom data
*/
public NBTTagCompound getCustomData();
/**
* Get the crop's plant scan level.
* Increases every time the seed is analyzed.
*
* @return Plant scan level
*/
public byte getScanLevel();
/**
* Get the crop's nutrient storage.
* Ranges from 0 to 100.
*
* @return Crop nutrient storage
*/
public int getNutrientStorage();
/**
* Set the crop's plant scan level.
*
* @param scanLevel Plant scan level
*/
public void setScanLevel(byte scanLevel);
/**
* Set the crop's nutrient storage.
*
* @param nutrientStorage Crop nutrient storage
*/
public void setNutrientStorage(int nutrientStorage);
/**
* Get the crop's plant custom data, stored alongside the crop.
* Can be modified in place.
*
* @return Plant custom data
*/
public NBTTagCompound getCustomData();
/**
* 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();
/**
* Get the crop's nutrient storage.
* Ranges from 0 to 100.
*
* @return Crop nutrient storage
*/
public int getNutrientStorage();
/**
* Set the crop's hydration storage.
*
* @param hydrationStorage Crop hydration storage
*/
public void setHydrationStorage(int hydrationStorage);
/**
* Set the crop's nutrient storage.
*
* @param nutrientStorage Crop nutrient storage
*/
public void setNutrientStorage(int nutrientStorage);
/**
* Get the crop's Weed-Ex storage.
*
* @return Crop Weed-Ex storage
*/
public int getWeedExStorage();
/**
* 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 Weed-Ex storage.
*
* @param weedExStorage Crop Weed-Ex storage
*/
public void setWeedExStorage(int weedExStorage);
/**
* Set the crop's hydration storage.
*
* @param hydrationStorage Crop hydration storage
*/
public void setHydrationStorage(int hydrationStorage);
/**
* Get the crop's humidity.
* Ranges from 0 (dry) to 10 (humid).
* Updates every couple of seconds or when an update is requested.
*
* @return Crop humidity level
* @see #updateState()
*/
public byte getHumidity();
/**
* Get the crop's Weed-Ex storage.
*
* @return Crop Weed-Ex storage
*/
public int getWeedExStorage();
/**
* Get the crop's nutrient level.
* Ranges from 0 (empty) to 10 (full).
* Updates every couple of seconds or when an update is requested.
*
* @return Crop nutrient level
* @see #updateState()
*/
public byte getNutrients();
/**
* Set the crop's Weed-Ex storage.
*
* @param weedExStorage Crop Weed-Ex storage
*/
public void setWeedExStorage(int weedExStorage);
/**
* Get the crop's air quality.
* Ranges from 0 (cluttered) to 10 (fresh).
* Updates every couple of seconds or when an update is requested.
*
* @return Crop air quality
* @see #updateState()
*/
public byte getAirQuality();
/**
* 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();
/**
* Get the crop's world.
*
* @return Crop world
*/
public World getWorld();
/**
* 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();
/**
* Get the crop's location.
*
* @return Crop location
*/
public ChunkCoordinates getLocation();
/**
* 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 light level.
*
* @return Crop light level
*/
public int getLightLevel();
/**
* Get the crop's world.
*
* @return Crop world
*/
public World getWorld();
/**
* 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
*/
public boolean pick(boolean manual);
/**
* Get the crop's location.
*
* @return Crop location
*/
public ChunkCoordinates getLocation();
/**
* Harvest the crop, turning it into gain and resetting its size.
* drop output on ground
*
* @param manual
* @return true if successfully harvested
*/
public boolean harvest(boolean manual);
/**
* Get the crop's light level.
*
* @return Crop light level
*/
public int getLightLevel();
/**
* Harvest the crop, turning it into gain and resetting its size.
* drop output on ground
*
* @param Optimal force check getOptimalHavestSize() for harvest
* @return ItemStack[] of harvest output
*/
/**
* 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
*/
public boolean pick(boolean manual);
ItemStack[] harvest_automated(boolean Optimal);
/**
* Harvest the crop, turning it into gain and resetting its size.
* drop output on ground
* @param manual
* @return true if successfully harvested
*/
public boolean harvest(boolean manual);
/**
* Fully clears the crop without dropping anything.
*/
public void reset();
/**
* Harvest the crop, turning it into gain and resetting its size.
* drop output on ground
* @param Optimal force check getOptimalHavestSize() for harvest
* @return ItemStack[] of harvest output
*/
/**
* Request a texture and lighting update.
*/
public void updateState();
ItemStack[] harvest_automated(boolean Optimal);
/**
* 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
*/
public boolean isBlockBelow(Block block);
/**
* Fully clears the crop without dropping anything.
*/
public void reset();
/**
* Generate plant seeds with the given parameters.
*
* @param plant plant ID
* @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(short plant, byte growth, byte gain, byte resis, byte scan);
/**
* Request a texture and lighting update.
*/
public void updateState();
/**
* 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
*/
public boolean isBlockBelow(Block block);
/**
* Generate plant seeds with the given parameters.
*
* @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);
}
+2 -2
View File
@@ -1,4 +1,4 @@
@API(apiVersion = "1.0", owner = "IC2", provides = "IC2API") package ic2.api.crops;
@API(apiVersion="1.0", owner="IC2", provides="IC2API")
package ic2.api.crops;
import cpw.mods.fml.common.API;
+6 -6
View File
@@ -3,16 +3,16 @@ package ic2.api.energy;
/**
* Provides access to the energy network.
* <p/>
*
* The old EnergyNet methods missing in IEnergyNet have been migrated to events (load, unload) or
* removed (tiles no longer emit energy actively, the energy net implementation requests it).
* <p/>
*
* See ic2/api/energy/usage.txt for an overall description of the energy net api.
*/
public final class EnergyNet {
/**
* Instance of the global EnergyNet class.
*/
public static IEnergyNet instance;
/**
* Instance of the global EnergyNet class.
*/
public static IEnergyNet instance;
}
+68 -65
View File
@@ -2,82 +2,85 @@ package ic2.api.energy;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
import net.minecraftforge.common.util.ForgeDirection;
/**
* Interface representing the methods provided by the global EnergyNet class.
* <p/>
*
* See ic2/api/energy/usage.txt for an overall description of the energy net api.
*/
public interface IEnergyNet {
/**
* Get the EnergyNet-registered tile entity at the specified position.
* <p/>
* This is not the same as World.getTileEntity(), it's possible to register delegate tile
* entities with the energy net which are different from what's actually in the world. Those
* delegates allow to use separate TileEntity objects just for the EnergyNet interfaces,
* simplifying cross-mod dependencies and multi-blocks.
*
* @param world World containing the tile entity
* @param x x-coordinate
* @param y y-coordinate
* @param z z-coordinate
* @return tile entity registered to the energy net or null if none is registered
*/
TileEntity getTileEntity(World world, int x, int y, int z);
/**
* Get the EnergyNet-registered tile entity at the specified position.
*
* This is not the same as World.getTileEntity(), it's possible to register delegate tile
* entities with the energy net which are different from what's actually in the world. Those
* delegates allow to use separate TileEntity objects just for the EnergyNet interfaces,
* simplifying cross-mod dependencies and multi-blocks.
*
* @param world World containing the tile entity
* @param x x-coordinate
* @param y y-coordinate
* @param z z-coordinate
* @return tile entity registered to the energy net or null if none is registered
*/
TileEntity getTileEntity(World world, int x, int y, int z);
/**
* Get the EnergyNet-registered neighbor tile entity at the specified position.
*
* @param te TileEntity indicating the world and position to search from
* @param dir direction the neighbor is to be found
* @return neighbor tile entity registered to the energy net or null if none is registered
*/
TileEntity getNeighbor(TileEntity te, ForgeDirection dir);
/**
* Get the EnergyNet-registered neighbor tile entity at the specified position.
*
* @param te TileEntity indicating the world and position to search from
* @param dir direction the neighbor is to be found
* @return neighbor tile entity registered to the energy net or null if none is registered
*/
TileEntity getNeighbor(TileEntity te, ForgeDirection dir);
/**
* determine how much energy has been emitted by the EnergyEmitter specified
*
* @param tileEntity energy emitter
* @note call this twice with x ticks delay to get the avg. emitted power p = (call2 - call1) / x EU/tick
* @deprecated Discontinued, use getNodeStats instead.
*/
@Deprecated
double getTotalEnergyEmitted(TileEntity tileEntity);
/**
* determine how much energy has been emitted by the EnergyEmitter specified
*
* @note call this twice with x ticks delay to get the avg. emitted power p = (call2 - call1) / x EU/tick
*
* @param tileEntity energy emitter
* @deprecated Discontinued, use getNodeStats instead.
*/
@Deprecated
double getTotalEnergyEmitted(TileEntity tileEntity);
/**
* determine how much energy has been sunken by the EnergySink specified
*
* @param tileEntity energy emitter
* @note call this twice with x ticks delay to get the avg. sunken power p = (call2 - call1) / x EU/tick
* @deprecated Discontinued, use getNodeStats instead.
*/
@Deprecated
double getTotalEnergySunken(TileEntity tileEntity);
/**
* determine how much energy has been sunken by the EnergySink specified
*
* @note call this twice with x ticks delay to get the avg. sunken power p = (call2 - call1) / x EU/tick
*
* @param tileEntity energy emitter
* @deprecated Discontinued, use getNodeStats instead.
*/
@Deprecated
double getTotalEnergySunken(TileEntity tileEntity);
/**
* Retrieve statistics for the tile entity specified.
* <p/>
* The statistics apply to the last simulated tick.
*
* @param te Tile entity to check.
* @return Statistics for the tile entity.
*/
NodeStats getNodeStats(TileEntity te);
/**
* Retrieve statistics for the tile entity specified.
*
* The statistics apply to the last simulated tick.
*
* @param te Tile entity to check.
* @return Statistics for the tile entity.
*/
NodeStats getNodeStats(TileEntity te);
/**
* Determine the typical power used by the specific tier, e.g. 128 eu/t for tier 2.
*
* @param tier tier
* @return power in eu/t
*/
double getPowerFromTier(int tier);
/**
* Determine the typical power used by the specific tier, e.g. 128 eu/t for tier 2.
*
* @param tier tier
* @return power in eu/t
*/
double getPowerFromTier(int tier);
/**
* Determine minimum tier required to handle the specified power, e.g. tier 2 for 128 eu/t.
*
* @param power in eu/t
* @return tier
*/
int getTierFromPower(double power);
/**
* Determine minimum tier required to handle the specified power, e.g. tier 2 for 128 eu/t.
*
* @param power in eu/t
* @return tier
*/
int getTierFromPower(double power);
}
+17 -17
View File
@@ -1,25 +1,25 @@
package ic2.api.energy;
public class NodeStats {
public NodeStats(double energyIn, double energyOut, double voltage) {
this.energyIn = energyIn;
this.energyOut = energyOut;
this.voltage = voltage;
}
public NodeStats(double energyIn, double energyOut, double voltage) {
this.energyIn = energyIn;
this.energyOut = energyOut;
this.voltage = voltage;
}
public double getEnergyIn() {
return energyIn;
}
public double getEnergyIn() {
return energyIn;
}
public double getEnergyOut() {
return energyOut;
}
public double getEnergyOut() {
return energyOut;
}
public double getVoltage() {
return voltage;
}
public double getVoltage() {
return voltage;
}
private final double energyIn;
private final double energyOut;
private final double voltage;
protected double energyIn;
protected double energyOut;
protected double voltage;
}
@@ -1,21 +1,25 @@
package ic2.api.energy.event;
import ic2.api.energy.tile.IEnergyTile;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.event.world.WorldEvent;
import ic2.api.energy.tile.IEnergyTile;
/**
* Base class for energy net events, don't use it directly.
* <p/>
*
* See ic2/api/energy/usage.txt for an overall description of the energy net api.
*/
public class EnergyTileEvent extends WorldEvent {
public final IEnergyTile energyTile;
public final IEnergyTile energyTile;
public EnergyTileEvent(IEnergyTile energyTile1) {
super(((TileEntity) energyTile1).getWorldObj());
public EnergyTileEvent(IEnergyTile energyTile1) {
super(((TileEntity) energyTile1).getWorldObj());
this.energyTile = energyTile1;
}
if (world == null) throw new NullPointerException("world is null");
this.energyTile = energyTile1;
}
}
@@ -4,23 +4,23 @@ import ic2.api.energy.tile.IEnergyTile;
/**
* Event announcing new energy tiles.
* <p/>
*
* This event notifies subscribers of loaded energy tiles, e.g. after getting
* loaded through the chunk they are in or after being placed down by the
* player or another deployer mechanism.
* <p/>
*
* Every energy tile which wants to get connected to the IC2 Energy Network has
* to either post this event or alternatively call EnergyNet.addTileEntity().
* <p/>
*
* You may use this event to build a static representation of energy tiles for
* your own energy grid implementation if you need to. It's not required if you
* always lookup energy paths on demand.
* <p/>
*
* See ic2/api/energy/usage.txt for an overall description of the energy net api.
*/
public class EnergyTileLoadEvent extends EnergyTileEvent {
public EnergyTileLoadEvent(IEnergyTile energyTile1) {
super(energyTile1);
}
public EnergyTileLoadEvent(IEnergyTile energyTile1) {
super(energyTile1);
}
}
@@ -4,24 +4,24 @@ import ic2.api.energy.tile.IEnergyTile;
/**
* Event announcing terminated energy tiles.
* <p/>
*
* This event notifies subscribers of unloaded energy tiles, e.g. after getting
* unloaded through the chunk they are in or after being destroyed by the
* player or another block pick/destruction mechanism.
* <p/>
*
* Every energy tile which wants to get disconnected from the IC2 Energy
* Network has to either post this event or alternatively call
* EnergyNet.removeTileEntity().
* <p/>
*
* You may use this event to build a static representation of energy tiles for
* your own energy grid implementation if you need to. It's not required if you
* always lookup energy paths on demand.
* <p/>
*
* See ic2/api/energy/usage.txt for an overall description of the energy net api.
*/
public class EnergyTileUnloadEvent extends EnergyTileEvent {
public EnergyTileUnloadEvent(IEnergyTile energyTile1) {
super(energyTile1);
}
public EnergyTileUnloadEvent(IEnergyTile energyTile1) {
super(energyTile1);
}
}
@@ -1,4 +1,4 @@
@API(apiVersion = "1.0", owner = "IC2", provides = "IC2API") package ic2.api.energy.event;
@API(apiVersion="1.0", owner="IC2", provides="IC2API")
package ic2.api.energy.event;
import cpw.mods.fml.common.API;
@@ -1,4 +1,4 @@
@API(apiVersion = "1.0", owner = "IC2", provides = "IC2API") package ic2.api.energy;
@API(apiVersion="1.0", owner="IC2", provides="IC2API")
package ic2.api.energy;
import cpw.mods.fml.common.API;
+291 -278
View File
@@ -1,360 +1,373 @@
package ic2.api.energy.prefab;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import cpw.mods.fml.common.FMLCommonHandler;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.common.util.ForgeDirection;
import ic2.api.energy.event.EnergyTileLoadEvent;
import ic2.api.energy.event.EnergyTileUnloadEvent;
import ic2.api.energy.tile.IEnergySink;
import ic2.api.info.Info;
import ic2.api.item.ElectricItem;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.common.util.ForgeDirection;
/**
* BasicSink is a simple adapter to provide an ic2 energy sink.
* <p/>
*
* It's designed to be attached to a tile entity as a delegate. Functionally BasicSink acts as a
* one-time configurable input energy buffer, thus providing a common use case for machines.
* <p/>
*
* Sub-classing BasicSink instead of using it as a delegate works as well, but isn't recommended.
* The delegate can be extended with additional functionality through a sub class though.
* <p/>
*
* The constraints set by BasicSink like the strict tank-like energy buffering should provide a
* more easy to use and stable interface than using IEnergySink directly while aiming for
* optimal performance.
* <p/>
*
* Using BasicSink involves the following steps:
* - create a BasicSink instance in your TileEntity, typically in a field
* - forward invalidate, onChunkUnload, readFromNBT, writeToNBT and updateEntity to the BasicSink
* instance.
* If you have other means of determining when the tile entity is fully loaded, notify onLoaded
* that way instead of forwarding updateEntity.
* instance.
* If you have other means of determining when the tile entity is fully loaded, notify onLoaded
* that way instead of forwarding updateEntity.
* - call useEnergy whenever appropriate. canUseEnergy determines if enough energy is available
* without consuming the energy.
* without consuming the energy.
* - optionally use getEnergyStored to display the output buffer charge level
* - optionally use setEnergyStored to sync the stored energy to the client (e.g. in the Container)
* <p/>
* Example implementation code:
*
* @code{.java} public class SomeTileEntity extends TileEntity {
* // new basic energy sink, 1000 EU buffer, tier 1 (32 EU/t, LV)
* private BasicSink ic2EnergySink = new BasicSink(this, 1000, 1);
* @Override public void invalidate() {
* ic2EnergySink.invalidate(); // notify the energy sink
* ...
* super.invalidate(); // this is important for mc!
* }
* @Override public void onChunkUnload() {
* ic2EnergySink.onChunkUnload(); // notify the energy sink
* ...
* }
* @Override public void readFromNBT(NBTTagCompound tag) {
* super.readFromNBT(tag);
* <p/>
* ic2EnergySink.readFromNBT(tag);
* ...
* }
* @Override public void writeToNBT(NBTTagCompound tag) {
* super.writeToNBT(tag);
* <p/>
* ic2EnergySink.writeToNBT(tag);
* ...
* }
* @Override public void updateEntity() {
* ic2EnergySink.updateEntity(); // notify the energy sink
* ...
* if (ic2EnergySink.useEnergy(5)) { // use 5 eu from the sink's buffer this tick
* ... // do something with the energy
* }
* ...
* }
* <p/>
* ...
* Example implementation code:
* @code{.java}
* public class SomeTileEntity extends TileEntity {
* // new basic energy sink, 1000 EU buffer, tier 1 (32 EU/t, LV)
* private BasicSink ic2EnergySink = new BasicSink(this, 1000, 1);
*
* @Override
* public void invalidate() {
* ic2EnergySink.invalidate(); // notify the energy sink
* ...
* super.invalidate(); // this is important for mc!
* }
*
* @Override
* public void onChunkUnload() {
* ic2EnergySink.onChunkUnload(); // notify the energy sink
* ...
* }
*
* @Override
* public void readFromNBT(NBTTagCompound tag) {
* super.readFromNBT(tag);
*
* ic2EnergySink.readFromNBT(tag);
* ...
* }
*
* @Override
* public void writeToNBT(NBTTagCompound tag) {
* super.writeToNBT(tag);
*
* ic2EnergySink.writeToNBT(tag);
* ...
* }
*
* @Override
* public void updateEntity() {
* ic2EnergySink.updateEntity(); // notify the energy sink
* ...
* if (ic2EnergySink.useEnergy(5)) { // use 5 eu from the sink's buffer this tick
* ... // do something with the energy
* }
* ...
* }
*
* ...
* }
* @endcode
*/
public class BasicSink extends TileEntity implements IEnergySink {
// **********************************
// *** Methods for use by the mod ***
// **********************************
// **********************************
// *** Methods for use by the mod ***
// **********************************
/**
* Constructor for a new BasicSink delegate.
*
* @param parent1 TileEntity represented by this energy sink.
* @param capacity1 Maximum amount of eu to store.
* @param tier1 IC2 tier, 1 = LV, 2 = MV, ...
*/
public BasicSink(TileEntity parent1, int capacity1, int tier1) {
this.parent = parent1;
this.capacity = capacity1;
this.tier = tier1;
}
/**
* Constructor for a new BasicSink delegate.
*
* @param parent1 TileEntity represented by this energy sink.
* @param capacity1 Maximum amount of eu to store.
* @param tier1 IC2 tier, 1 = LV, 2 = MV, ...
*/
public BasicSink(TileEntity parent1, int capacity1, int tier1) {
this.parent = parent1;
this.capacity = capacity1;
this.tier = tier1;
}
// in-world te forwards >>
// in-world te forwards >>
/**
* Forward for the base TileEntity's updateEntity(), used for creating the energy net link.
* Either updateEntity or onLoaded have to be used.
*/
@Override
public void updateEntity() {
if (!addedToEnet) onLoaded();
}
/**
* Forward for the base TileEntity's updateEntity(), used for creating the energy net link.
* Either updateEntity or onLoaded have to be used.
*/
@Override
public void updateEntity() {
if (!addedToEnet) onLoaded();
}
/**
* Notification that the base TileEntity finished loaded, for advanced uses.
* Either updateEntity or onLoaded have to be used.
*/
public void onLoaded() {
if (!addedToEnet &&
!FMLCommonHandler.instance().getEffectiveSide().isClient() &&
Info.isIc2Available()) {
worldObj = parent.getWorldObj();
xCoord = parent.xCoord;
yCoord = parent.yCoord;
zCoord = parent.zCoord;
/**
* Notification that the base TileEntity finished loaded, for advanced uses.
* Either updateEntity or onLoaded have to be used.
*/
public void onLoaded() {
if (!addedToEnet &&
!FMLCommonHandler.instance().getEffectiveSide().isClient() &&
Info.isIc2Available()) {
worldObj = parent.getWorldObj();
xCoord = parent.xCoord;
yCoord = parent.yCoord;
zCoord = parent.zCoord;
MinecraftForge.EVENT_BUS.post(new EnergyTileLoadEvent(this));
MinecraftForge.EVENT_BUS.post(new EnergyTileLoadEvent(this));
addedToEnet = true;
}
}
addedToEnet = true;
}
}
/**
* Forward for the base TileEntity's invalidate(), used for destroying the energy net link.
* Both invalidate and onChunkUnload have to be used.
*/
@Override
public void invalidate() {
super.invalidate();
/**
* Forward for the base TileEntity's invalidate(), used for destroying the energy net link.
* Both invalidate and onChunkUnload have to be used.
*/
@Override
public void invalidate() {
super.invalidate();
onChunkUnload();
}
onChunkUnload();
}
/**
* Forward for the base TileEntity's onChunkUnload(), used for destroying the energy net link.
* Both invalidate and onChunkUnload have to be used.
*/
@Override
public void onChunkUnload() {
if (addedToEnet &&
Info.isIc2Available()) {
MinecraftForge.EVENT_BUS.post(new EnergyTileUnloadEvent(this));
/**
* Forward for the base TileEntity's onChunkUnload(), used for destroying the energy net link.
* Both invalidate and onChunkUnload have to be used.
*/
@Override
public void onChunkUnload() {
if (addedToEnet &&
Info.isIc2Available()) {
MinecraftForge.EVENT_BUS.post(new EnergyTileUnloadEvent(this));
addedToEnet = false;
}
}
addedToEnet = false;
}
}
/**
* Forward for the base TileEntity's readFromNBT(), used for loading the state.
*
* @param tag Compound tag as supplied by TileEntity.readFromNBT()
*/
@Override
public void readFromNBT(NBTTagCompound tag) {
super.readFromNBT(tag);
/**
* Forward for the base TileEntity's readFromNBT(), used for loading the state.
*
* @param tag Compound tag as supplied by TileEntity.readFromNBT()
*/
@Override
public void readFromNBT(NBTTagCompound tag) {
super.readFromNBT(tag);
NBTTagCompound data = tag.getCompoundTag("IC2BasicSink");
NBTTagCompound data = tag.getCompoundTag("IC2BasicSink");
energyStored = data.getDouble("energy");
}
energyStored = data.getDouble("energy");
}
/**
* Forward for the base TileEntity's writeToNBT(), used for saving the state.
*
* @param tag Compound tag as supplied by TileEntity.writeToNBT()
*/
@Override
public void writeToNBT(NBTTagCompound tag) {
try {
super.writeToNBT(tag);
} catch (RuntimeException e) {
// happens if this is a delegate, ignore
}
/**
* Forward for the base TileEntity's writeToNBT(), used for saving the state.
*
* @param tag Compound tag as supplied by TileEntity.writeToNBT()
*/
@Override
public void writeToNBT(NBTTagCompound tag) {
try {
super.writeToNBT(tag);
} catch (RuntimeException e) {
// happens if this is a delegate, ignore
}
NBTTagCompound data = new NBTTagCompound();
NBTTagCompound data = new NBTTagCompound();
data.setDouble("energy", energyStored);
data.setDouble("energy", energyStored);
tag.setTag("IC2BasicSink", data);
}
tag.setTag("IC2BasicSink", data);
}
// << in-world te forwards
// methods for using this adapter >>
// << in-world te forwards
// methods for using this adapter >>
/**
* Get the maximum amount of energy this sink can hold in its buffer.
*
* @return Capacity in EU.
*/
public int getCapacity() {
return capacity;
}
/**
* Get the maximum amount of energy this sink can hold in its buffer.
*
* @return Capacity in EU.
*/
public int getCapacity() {
return capacity;
}
/**
* Set the maximum amount of energy this sink can hold in its buffer.
*
* @param capacity1 Capacity in EU.
*/
public void setCapacity(int capacity1) {
this.capacity = capacity1;
}
/**
* Set the maximum amount of energy this sink can hold in its buffer.
*
* @param capacity1 Capacity in EU.
*/
public void setCapacity(int capacity1) {
this.capacity = capacity1;
}
/**
* Get the IC2 energy tier for this sink.
*
* @return IC2 Tier.
*/
public int getTier() {
return tier;
}
/**
* Get the IC2 energy tier for this sink.
*
* @return IC2 Tier.
*/
public int getTier() {
return tier;
}
/**
* Set the IC2 energy tier for this sink.
*
* @param tier1 IC2 Tier.
*/
public void setTier(int tier1) {
this.tier = tier1;
}
/**
* Set the IC2 energy tier for this sink.
*
* @param tier1 IC2 Tier.
*/
public void setTier(int tier1) {
this.tier = tier1;
}
/**
* Determine the energy stored in the sink's input buffer.
*
* @return amount in EU, may be above capacity
*/
public double getEnergyStored() {
return energyStored;
}
/**
* Determine the energy stored in the sink's input buffer.
*
* @return amount in EU, may be above capacity
*/
public double getEnergyStored() {
return energyStored;
}
/**
* Set the stored energy to the specified amount.
* <p/>
* This is intended for server -> client synchronization, e.g. to display the stored energy in
* a GUI through getEnergyStored().
*
* @param amount
*/
public void setEnergyStored(double amount) {
energyStored = amount;
}
/**
* Set the stored energy to the specified amount.
*
* This is intended for server -> client synchronization, e.g. to display the stored energy in
* a GUI through getEnergyStored().
*
* @param amount
*/
public void setEnergyStored(double amount) {
energyStored = amount;
}
/**
* Determine if the specified amount of energy is available.
*
* @param amount in EU
* @return true if the amount is available
*/
public boolean canUseEnergy(double amount) {
return energyStored >= amount;
}
/**
* Determine if the specified amount of energy is available.
*
* @param amount in EU
* @return true if the amount is available
*/
public boolean canUseEnergy(double amount) {
return energyStored >= amount;
}
/**
* Use the specified amount of energy, if available.
*
* @param amount amount to use
* @return true if the amount was available
*/
public boolean useEnergy(double amount) {
if (canUseEnergy(amount) && !FMLCommonHandler.instance().getEffectiveSide().isClient()) {
energyStored -= amount;
/**
* Use the specified amount of energy, if available.
*
* @param amount amount to use
* @return true if the amount was available
*/
public boolean useEnergy(double amount) {
if (canUseEnergy(amount) && !FMLCommonHandler.instance().getEffectiveSide().isClient()) {
energyStored -= amount;
return true;
}
return false;
}
return true;
}
return false;
}
/**
* Discharge the supplied ItemStack into this sink's energy buffer.
*
* @param stack ItemStack to discharge (null is ignored)
* @param limit Transfer limit, values <= 0 will use the battery's limit
* @return true if energy was transferred
*/
public boolean discharge(ItemStack stack, int limit) {
if (stack == null || !Info.isIc2Available()) return false;
/**
* Discharge the supplied ItemStack into this sink's energy buffer.
*
* @param stack ItemStack to discharge (null is ignored)
* @param limit Transfer limit, values <= 0 will use the battery's limit
* @return true if energy was transferred
*/
public boolean discharge(ItemStack stack, int limit) {
if (stack == null || !Info.isIc2Available()) return false;
double amount = capacity - energyStored;
if (amount <= 0) return false;
double amount = capacity - energyStored;
if (amount <= 0) return false;
if (limit > 0 && limit < amount) amount = limit;
if (limit > 0 && limit < amount) amount = limit;
amount = ElectricItem.manager.discharge(stack, amount, tier, limit > 0, true, false);
amount = ElectricItem.manager.discharge(stack, amount, tier, limit > 0, true, false);
energyStored += amount;
energyStored += amount;
return amount > 0;
}
return amount > 0;
}
// << methods for using this adapter
// << methods for using this adapter
// backwards compatibility (ignore these) >>
// backwards compatibility (ignore these) >>
@Deprecated
public void onUpdateEntity() {
updateEntity();
}
@Deprecated
public void onUpdateEntity() {
updateEntity();
}
@Deprecated
public void onInvalidate() {
invalidate();
}
@Deprecated
public void onInvalidate() {
invalidate();
}
@Deprecated
public void onOnChunkUnload() {
onChunkUnload();
}
@Deprecated
public void onOnChunkUnload() {
onChunkUnload();
}
@Deprecated
public void onReadFromNbt(NBTTagCompound tag) {
readFromNBT(tag);
}
@Deprecated
public void onReadFromNbt(NBTTagCompound tag) {
readFromNBT(tag);
}
@Deprecated
public void onWriteToNbt(NBTTagCompound tag) {
writeToNBT(tag);
}
@Deprecated
public void onWriteToNbt(NBTTagCompound tag) {
writeToNBT(tag);
}
// << backwards compatibility
// << backwards compatibility
// ******************************
// *** Methods for use by ic2 ***
// ******************************
// ******************************
// *** Methods for use by ic2 ***
// ******************************
// energy net interface >>
// energy net interface >>
@Override
public boolean acceptsEnergyFrom(TileEntity emitter, ForgeDirection direction) {
return true;
}
@Override
public boolean acceptsEnergyFrom(TileEntity emitter, ForgeDirection direction) {
return true;
}
@Override
public double getDemandedEnergy() {
return Math.max(0, capacity - energyStored);
}
@Override
public double getDemandedEnergy() {
return Math.max(0, capacity - energyStored);
}
@Override
public double injectEnergy(ForgeDirection directionFrom, double amount, double voltage) {
energyStored += amount;
@Override
public double injectEnergy(ForgeDirection directionFrom, double amount, double voltage) {
energyStored += amount;
return 0;
}
return 0;
}
@Override
public int getSinkTier() {
return tier;
}
@Override
public int getSinkTier() {
return tier;
}
// << energy net interface
// << energy net interface
public final TileEntity parent;
public final TileEntity parent;
protected int capacity;
protected int tier;
protected double energyStored;
protected boolean addedToEnet;
protected int capacity;
protected int tier;
protected double energyStored;
protected boolean addedToEnet;
}
@@ -1,362 +1,375 @@
package ic2.api.energy.prefab;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import cpw.mods.fml.common.FMLCommonHandler;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.common.util.ForgeDirection;
import ic2.api.energy.EnergyNet;
import ic2.api.energy.event.EnergyTileLoadEvent;
import ic2.api.energy.event.EnergyTileUnloadEvent;
import ic2.api.energy.tile.IEnergySource;
import ic2.api.info.Info;
import ic2.api.item.ElectricItem;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.common.util.ForgeDirection;
/**
* BasicSource is a simple adapter to provide an ic2 energy source.
* <p/>
*
* It's designed to be attached to a tile entity as a delegate. Functionally BasicSource acts as a
* one-time configurable output energy buffer, thus providing a common use case for generators.
* <p/>
*
* Sub-classing BasicSource instead of using it as a delegate works as well, but isn't recommended.
* The delegate can be extended with additional functionality through a sub class though.
* <p/>
*
* The constraints set by BasicSource like the strict tank-like energy buffering should provide a
* more easy to use and stable interface than using IEnergySource directly while aiming for
* optimal performance.
* <p/>
*
* Using BasicSource involves the following steps:
* - create a BasicSource instance in your TileEntity, typically in a field
* - forward invalidate, onChunkUnload, readFromNBT, writeToNBT and updateEntity to the BasicSource
* instance.
* If you have other means of determining when the tile entity is fully loaded, notify onLoaded
* that way instead of forwarding updateEntity.
* instance.
* If you have other means of determining when the tile entity is fully loaded, notify onLoaded
* that way instead of forwarding updateEntity.
* - call addEnergy whenever appropriate, using getFreeCapacity may determine if e.g. the generator
* should run
* should run
* - optionally use getEnergyStored to display the output buffer charge level
* - optionally use setEnergyStored to sync the stored energy to the client (e.g. in the Container)
* <p/>
* Example implementation code:
*
* @code{.java} public class SomeTileEntity extends TileEntity {
* // new basic energy source, 1000 EU buffer, tier 1 (32 EU/t, LV)
* private BasicSource ic2EnergySource = new BasicSource(this, 1000, 1);
* @Override public void invalidate() {
* ic2EnergySource.invalidate(); // notify the energy source
* ...
* super.invalidate(); // this is important for mc!
* }
* @Override public void onChunkUnload() {
* ic2EnergySource.onChunkUnload(); // notify the energy source
* ...
* }
* @Override public void readFromNBT(NBTTagCompound tag) {
* super.readFromNBT(tag);
* <p/>
* ic2EnergySource.readFromNBT(tag);
* ...
* }
* @Override public void writeToNBT(NBTTagCompound tag) {
* super.writeToNBT(tag);
* <p/>
* ic2EnergySource.writeToNBT(tag);
* ...
* }
* @Override public void updateEntity() {
* ic2EnergySource.updateEntity(); // notify the energy source
* ...
* ic2EnergySource.addEnergy(5); // add 5 eu to the source's buffer this tick
* ...
* }
* <p/>
* ...
* Example implementation code:
* @code{.java}
* public class SomeTileEntity extends TileEntity {
* // new basic energy source, 1000 EU buffer, tier 1 (32 EU/t, LV)
* private BasicSource ic2EnergySource = new BasicSource(this, 1000, 1);
*
* @Override
* public void invalidate() {
* ic2EnergySource.invalidate(); // notify the energy source
* ...
* super.invalidate(); // this is important for mc!
* }
*
* @Override
* public void onChunkUnload() {
* ic2EnergySource.onChunkUnload(); // notify the energy source
* ...
* }
*
* @Override
* public void readFromNBT(NBTTagCompound tag) {
* super.readFromNBT(tag);
*
* ic2EnergySource.readFromNBT(tag);
* ...
* }
*
* @Override
* public void writeToNBT(NBTTagCompound tag) {
* super.writeToNBT(tag);
*
* ic2EnergySource.writeToNBT(tag);
* ...
* }
*
* @Override
* public void updateEntity() {
* ic2EnergySource.updateEntity(); // notify the energy source
* ...
* ic2EnergySource.addEnergy(5); // add 5 eu to the source's buffer this tick
* ...
* }
*
* ...
* }
* @endcode
*/
public class BasicSource extends TileEntity implements IEnergySource {
// **********************************
// *** Methods for use by the mod ***
// **********************************
// **********************************
// *** Methods for use by the mod ***
// **********************************
/**
* Constructor for a new BasicSource delegate.
*
* @param parent1 Base TileEntity represented by this energy source.
* @param capacity1 Maximum amount of eu to store.
* @param tier1 IC2 tier, 1 = LV, 2 = MV, ...
*/
public BasicSource(TileEntity parent1, double capacity1, int tier1) {
double power = EnergyNet.instance.getPowerFromTier(tier1);
/**
* Constructor for a new BasicSource delegate.
*
* @param parent1 Base TileEntity represented by this energy source.
* @param capacity1 Maximum amount of eu to store.
* @param tier1 IC2 tier, 1 = LV, 2 = MV, ...
*/
public BasicSource(TileEntity parent1, double capacity1, int tier1) {
double power = EnergyNet.instance.getPowerFromTier(tier1);
this.parent = parent1;
this.capacity = capacity1 < power ? power : capacity1;
this.tier = tier1;
this.power = power;
}
this.parent = parent1;
this.capacity = capacity1 < power ? power : capacity1;
this.tier = tier1;
this.power = power;
}
// in-world te forwards >>
// in-world te forwards >>
/**
* Forward for the base TileEntity's updateEntity(), used for creating the energy net link.
* Either updateEntity or onLoaded have to be used.
*/
@Override
public void updateEntity() {
if (!addedToEnet) onLoaded();
}
/**
* Forward for the base TileEntity's updateEntity(), used for creating the energy net link.
* Either updateEntity or onLoaded have to be used.
*/
@Override
public void updateEntity() {
if (!addedToEnet) onLoaded();
}
/**
* Notification that the base TileEntity finished loading, for advanced uses.
* Either updateEntity or onLoaded have to be used.
*/
public void onLoaded() {
if (!addedToEnet &&
!FMLCommonHandler.instance().getEffectiveSide().isClient() &&
Info.isIc2Available()) {
worldObj = parent.getWorldObj();
xCoord = parent.xCoord;
yCoord = parent.yCoord;
zCoord = parent.zCoord;
/**
* Notification that the base TileEntity finished loading, for advanced uses.
* Either updateEntity or onLoaded have to be used.
*/
public void onLoaded() {
if (!addedToEnet &&
!FMLCommonHandler.instance().getEffectiveSide().isClient() &&
Info.isIc2Available()) {
worldObj = parent.getWorldObj();
xCoord = parent.xCoord;
yCoord = parent.yCoord;
zCoord = parent.zCoord;
MinecraftForge.EVENT_BUS.post(new EnergyTileLoadEvent(this));
MinecraftForge.EVENT_BUS.post(new EnergyTileLoadEvent(this));
addedToEnet = true;
}
}
addedToEnet = true;
}
}
/**
* Forward for the base TileEntity's invalidate(), used for destroying the energy net link.
* Both invalidate and onChunkUnload have to be used.
*/
@Override
public void invalidate() {
super.invalidate();
/**
* Forward for the base TileEntity's invalidate(), used for destroying the energy net link.
* Both invalidate and onChunkUnload have to be used.
*/
@Override
public void invalidate() {
super.invalidate();
onChunkUnload();
}
onChunkUnload();
}
/**
* Forward for the base TileEntity's onChunkUnload(), used for destroying the energy net link.
* Both invalidate and onChunkUnload have to be used.
*/
@Override
public void onChunkUnload() {
if (addedToEnet &&
Info.isIc2Available()) {
MinecraftForge.EVENT_BUS.post(new EnergyTileUnloadEvent(this));
/**
* Forward for the base TileEntity's onChunkUnload(), used for destroying the energy net link.
* Both invalidate and onChunkUnload have to be used.
*/
@Override
public void onChunkUnload() {
if (addedToEnet &&
Info.isIc2Available()) {
MinecraftForge.EVENT_BUS.post(new EnergyTileUnloadEvent(this));
addedToEnet = false;
}
}
addedToEnet = false;
}
}
/**
* Forward for the base TileEntity's readFromNBT(), used for loading the state.
*
* @param tag Compound tag as supplied by TileEntity.readFromNBT()
*/
@Override
public void readFromNBT(NBTTagCompound tag) {
super.readFromNBT(tag);
/**
* Forward for the base TileEntity's readFromNBT(), used for loading the state.
*
* @param tag Compound tag as supplied by TileEntity.readFromNBT()
*/
@Override
public void readFromNBT(NBTTagCompound tag) {
super.readFromNBT(tag);
NBTTagCompound data = tag.getCompoundTag("IC2BasicSource");
NBTTagCompound data = tag.getCompoundTag("IC2BasicSource");
energyStored = data.getDouble("energy");
}
energyStored = data.getDouble("energy");
}
/**
* Forward for the base TileEntity's writeToNBT(), used for saving the state.
*
* @param tag Compound tag as supplied by TileEntity.writeToNBT()
*/
@Override
public void writeToNBT(NBTTagCompound tag) {
try {
super.writeToNBT(tag);
} catch (RuntimeException e) {
// happens if this is a delegate, ignore
}
/**
* Forward for the base TileEntity's writeToNBT(), used for saving the state.
*
* @param tag Compound tag as supplied by TileEntity.writeToNBT()
*/
@Override
public void writeToNBT(NBTTagCompound tag) {
try {
super.writeToNBT(tag);
} catch (RuntimeException e) {
// happens if this is a delegate, ignore
}
NBTTagCompound data = new NBTTagCompound();
NBTTagCompound data = new NBTTagCompound();
data.setDouble("energy", energyStored);
data.setDouble("energy", energyStored);
tag.setTag("IC2BasicSource", data);
}
tag.setTag("IC2BasicSource", data);
}
// << in-world te forwards
// methods for using this adapter >>
// << in-world te forwards
// methods for using this adapter >>
/**
* Get the maximum amount of energy this source can hold in its buffer.
*
* @return Capacity in EU.
*/
public double getCapacity() {
return capacity;
}
/**
* Get the maximum amount of energy this source can hold in its buffer.
*
* @return Capacity in EU.
*/
public double getCapacity() {
return capacity;
}
/**
* Set the maximum amount of energy this source can hold in its buffer.
*
* @param capacity1 Capacity in EU.
*/
public void setCapacity(double capacity1) {
if (capacity1 < power) capacity1 = power;
/**
* Set the maximum amount of energy this source can hold in its buffer.
*
* @param capacity1 Capacity in EU.
*/
public void setCapacity(double capacity1) {
if (capacity1 < power) capacity1 = power;
this.capacity = capacity1;
}
this.capacity = capacity1;
}
/**
* Get the IC2 energy tier for this source.
*
* @return IC2 Tier.
*/
public int getTier() {
return tier;
}
/**
* Get the IC2 energy tier for this source.
*
* @return IC2 Tier.
*/
public int getTier() {
return tier;
}
/**
* Set the IC2 energy tier for this source.
*
* @param tier1 IC2 Tier.
*/
public void setTier(int tier1) {
double power = EnergyNet.instance.getPowerFromTier(tier1);
/**
* Set the IC2 energy tier for this source.
*
* @param tier1 IC2 Tier.
*/
public void setTier(int tier1) {
double power = EnergyNet.instance.getPowerFromTier(tier1);
if (capacity < power) capacity = power;
if (capacity < power) capacity = power;
this.tier = tier1;
this.power = power;
}
this.tier = tier1;
this.power = power;
}
/**
* Determine the energy stored in the source's output buffer.
*
* @return amount in EU
*/
public double getEnergyStored() {
return energyStored;
}
/**
* Determine the energy stored in the source's output buffer.
*
* @return amount in EU
*/
public double getEnergyStored() {
return energyStored;
}
/**
* Set the stored energy to the specified amount.
* <p/>
* This is intended for server -> client synchronization, e.g. to display the stored energy in
* a GUI through getEnergyStored().
*
* @param amount
*/
public void setEnergyStored(double amount) {
energyStored = amount;
}
/**
* Set the stored energy to the specified amount.
*
* This is intended for server -> client synchronization, e.g. to display the stored energy in
* a GUI through getEnergyStored().
*
* @param amount
*/
public void setEnergyStored(double amount) {
energyStored = amount;
}
/**
* Determine the free capacity in the source's output buffer.
*
* @return amount in EU
*/
public double getFreeCapacity() {
return capacity - energyStored;
}
/**
* Determine the free capacity in the source's output buffer.
*
* @return amount in EU
*/
public double getFreeCapacity() {
return capacity - energyStored;
}
/**
* Add some energy to the output buffer.
*
* @param amount maximum amount of energy to add
* @return amount added/used, NOT remaining
*/
public double addEnergy(double amount) {
if (FMLCommonHandler.instance().getEffectiveSide().isClient()) return 0;
if (amount > capacity - energyStored) amount = capacity - energyStored;
/**
* Add some energy to the output buffer.
*
* @param amount maximum amount of energy to add
* @return amount added/used, NOT remaining
*/
public double addEnergy(double amount) {
if (FMLCommonHandler.instance().getEffectiveSide().isClient()) return 0;
if (amount > capacity - energyStored) amount = capacity - energyStored;
energyStored += amount;
energyStored += amount;
return amount;
}
return amount;
}
/**
* Charge the supplied ItemStack from this source's energy buffer.
*
* @param stack ItemStack to charge (null is ignored)
* @return true if energy was transferred
*/
public boolean charge(ItemStack stack) {
if (stack == null || !Info.isIc2Available()) return false;
/**
* Charge the supplied ItemStack from this source's energy buffer.
*
* @param stack ItemStack to charge (null is ignored)
* @return true if energy was transferred
*/
public boolean charge(ItemStack stack) {
if (stack == null || !Info.isIc2Available()) return false;
double amount = ElectricItem.manager.charge(stack, energyStored, tier, false, false);
double amount = ElectricItem.manager.charge(stack, energyStored, tier, false, false);
energyStored -= amount;
energyStored -= amount;
return amount > 0;
}
return amount > 0;
}
// << methods for using this adapter
// << methods for using this adapter
// backwards compatibility (ignore these) >>
// backwards compatibility (ignore these) >>
@Deprecated
public void onUpdateEntity() {
updateEntity();
}
@Deprecated
public void onUpdateEntity() {
updateEntity();
}
@Deprecated
public void onInvalidate() {
invalidate();
}
@Deprecated
public void onInvalidate() {
invalidate();
}
@Deprecated
public void onOnChunkUnload() {
onChunkUnload();
}
@Deprecated
public void onOnChunkUnload() {
onChunkUnload();
}
@Deprecated
public void onReadFromNbt(NBTTagCompound tag) {
readFromNBT(tag);
}
@Deprecated
public void onReadFromNbt(NBTTagCompound tag) {
readFromNBT(tag);
}
@Deprecated
public void onWriteToNbt(NBTTagCompound tag) {
writeToNBT(tag);
}
@Deprecated
public void onWriteToNbt(NBTTagCompound tag) {
writeToNBT(tag);
}
// << backwards compatibility
// << backwards compatibility
// ******************************
// *** Methods for use by ic2 ***
// ******************************
// ******************************
// *** Methods for use by ic2 ***
// ******************************
// energy net interface >>
// energy net interface >>
@Override
public boolean emitsEnergyTo(TileEntity receiver, ForgeDirection direction) {
return true;
}
@Override
public boolean emitsEnergyTo(TileEntity receiver, ForgeDirection direction) {
return true;
}
@Override
public double getOfferedEnergy() {
return Math.min(energyStored, power);
}
@Override
public double getOfferedEnergy() {
return Math.min(energyStored, power);
}
@Override
public void drawEnergy(double amount) {
energyStored -= amount;
}
@Override
public void drawEnergy(double amount) {
energyStored -= amount;
}
@Override
public int getSourceTier() {
return tier;
}
@Override
public int getSourceTier() {
return tier;
}
// << energy net interface
// << energy net interface
public final TileEntity parent;
public final TileEntity parent;
protected double capacity;
protected int tier;
protected double power;
protected double energyStored;
protected boolean addedToEnet;
protected double capacity;
protected int tier;
protected double power;
protected double energyStored;
protected boolean addedToEnet;
}
@@ -1,4 +1,4 @@
@API(apiVersion = "1.0", owner = "IC2", provides = "IC2API") package ic2.api.energy.prefab;
@API(apiVersion="1.0", owner="IC2", provides="IC2API")
package ic2.api.energy.prefab;
import cpw.mods.fml.common.API;
@@ -1,26 +1,27 @@
package ic2.api.energy.tile;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.util.ForgeDirection;
/**
* For internal/multi-block usage only.
*
* @see ic2.api.energy.tile.IEnergySink
* @see ic2.api.energy.tile.IEnergyConductor
* <p/>
* @see IEnergySink
* @see IEnergyConductor
*
* See ic2/api/energy/usage.txt for an overall description of the energy net api.
*/
public interface IEnergyAcceptor extends IEnergyTile {
/**
* Determine if this acceptor can accept current from an adjacent emitter in a direction.
* <p/>
* The TileEntity in the emitter parameter is what was originally added to the energy net,
* which may be normal in-world TileEntity, a delegate or an IMetaDelegate.
*
* @param emitter energy emitter, may also be null or an IMetaDelegate
* @param direction direction the energy is being received from
*/
boolean acceptsEnergyFrom(TileEntity emitter, ForgeDirection direction);
/**
* Determine if this acceptor can accept current from an adjacent emitter in a direction.
*
* The TileEntity in the emitter parameter is what was originally added to the energy net,
* which may be normal in-world TileEntity, a delegate or an IMetaDelegate.
*
* @param emitter energy emitter, may also be null or an IMetaDelegate
* @param direction direction the energy is being received from
*/
boolean acceptsEnergyFrom(TileEntity emitter, ForgeDirection direction);
}
@@ -3,51 +3,51 @@ package ic2.api.energy.tile;
/**
* Tile entities which conduct energy pulses without buffering (mostly cables) have to implement this
* interface.
* <p/>
*
* See ic2/api/energy/usage.txt for an overall description of the energy net api.
*/
public interface IEnergyConductor extends IEnergyAcceptor, IEnergyEmitter {
/**
* Energy loss for the conductor in EU per block.
*
* @return Energy loss
*/
double getConductionLoss();
/**
* Energy loss for the conductor in EU per block.
*
* @return Energy loss
*/
double getConductionLoss();
/**
* Amount of energy the insulation will handle before shocking nearby players and mobs.
*
* @return Insulation energy absorption in EU
*/
double getInsulationEnergyAbsorption();
/**
* Amount of energy the insulation will handle before shocking nearby players and mobs.
*
* @return Insulation energy absorption in EU
*/
double getInsulationEnergyAbsorption();
/**
* Amount of energy the insulation will handle before it is destroyed.
* Ensure that this value is greater than the insulation energy absorption + 64.
*
* @return Insulation-destroying energy in EU
*/
double getInsulationBreakdownEnergy();
/**
* Amount of energy the insulation will handle before it is destroyed.
* Ensure that this value is greater than the insulation energy absorption + 64.
*
* @return Insulation-destroying energy in EU
*/
double getInsulationBreakdownEnergy();
/**
* Amount of energy the conductor will handle before it melts.
*
* @return Conductor-destroying energy in EU
*/
double getConductorBreakdownEnergy();
/**
* Amount of energy the conductor will handle before it melts.
*
* @return Conductor-destroying energy in EU
*/
double getConductorBreakdownEnergy();
/**
* Remove the conductor's insulation if the insulation breakdown energy was exceeded.
*
* @see #getInsulationBreakdownEnergy()
*/
void removeInsulation();
/**
* Remove the conductor's insulation if the insulation breakdown energy was exceeded.
*
* @see #getInsulationBreakdownEnergy()
*/
void removeInsulation();
/**
* Remove the conductor if the conductor breakdown energy was exceeded.
*
* @see #getConductorBreakdownEnergy()
*/
void removeConductor();
/**
* Remove the conductor if the conductor breakdown energy was exceeded.
*
* @see #getConductorBreakdownEnergy()
*/
void removeConductor();
}
@@ -1,27 +1,28 @@
package ic2.api.energy.tile;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.util.ForgeDirection;
/**
* For internal/multi-block usage only.
*
* @see ic2.api.energy.tile.IEnergySource
* @see ic2.api.energy.tile.IEnergyConductor
* <p/>
* @see IEnergySource
* @see IEnergyConductor
*
* See ic2/api/energy/usage.txt for an overall description of the energy net api.
*/
public interface IEnergyEmitter extends IEnergyTile {
/**
* Determine if this emitter can emit energy to an adjacent receiver.
* <p/>
* The TileEntity in the receiver parameter is what was originally added to the energy net,
* which may be normal in-world TileEntity, a delegate or an IMetaDelegate.
*
* @param receiver receiver, may also be null or an IMetaDelegate
* @param direction direction the receiver is from the emitter
* @return Whether energy should be emitted
*/
boolean emitsEnergyTo(TileEntity receiver, ForgeDirection direction);
/**
* Determine if this emitter can emit energy to an adjacent receiver.
*
* The TileEntity in the receiver parameter is what was originally added to the energy net,
* which may be normal in-world TileEntity, a delegate or an IMetaDelegate.
*
* @param receiver receiver, may also be null or an IMetaDelegate
* @param direction direction the receiver is from the emitter
* @return Whether energy should be emitted
*/
boolean emitsEnergyTo(TileEntity receiver, ForgeDirection direction);
}
@@ -4,40 +4,42 @@ import net.minecraftforge.common.util.ForgeDirection;
/**
* Allows a tile entity (mostly a machine) to receive energy.
* <p/>
*
* See ic2/api/energy/usage.txt for an overall description of the energy net api.
*/
public interface IEnergySink extends IEnergyAcceptor {
/**
* Determine how much energy the sink accepts.
* <p/>
* Make sure that injectEnergy() does accepts energy if demandsEnergy() returns anything > 0.
*
* @return max accepted input in eu
* @note Modifying the energy net from this method is disallowed.
*/
double getDemandedEnergy();
/**
* Determine how much energy the sink accepts.
*
* Make sure that injectEnergy() does accepts energy if demandsEnergy() returns anything > 0.
*
* @note Modifying the energy net from this method is disallowed.
*
* @return max accepted input in eu
*/
double getDemandedEnergy();
/**
* Determine the tier of this energy sink.
* 1 = LV, 2 = MV, 3 = HV, 4 = EV etc.
*
* @return tier of this energy sink
* @note Modifying the energy net from this method is disallowed.
* @note Return Integer.MAX_VALUE to allow any voltage.
*/
int getSinkTier();
/**
* Determine the tier of this energy sink.
* 1 = LV, 2 = MV, 3 = HV, 4 = EV etc.
*
* @note Modifying the energy net from this method is disallowed.
* @note Return Integer.MAX_VALUE to allow any voltage.
*
* @return tier of this energy sink
*/
int getSinkTier();
/**
* Transfer energy to the sink.
* <p/>
* It's highly recommended to accept all energy by letting the internal buffer overflow to
* increase the performance and accuracy of the distribution simulation.
*
* @param directionFrom direction from which the energy comes from
* @param amount energy to be transferred
* @return Energy not consumed (leftover)
*/
double injectEnergy(ForgeDirection directionFrom, double amount, double voltage);
/**
* Transfer energy to the sink.
*
* It's highly recommended to accept all energy by letting the internal buffer overflow to
* increase the performance and accuracy of the distribution simulation.
*
* @param directionFrom direction from which the energy comes from
* @param amount energy to be transferred
* @return Energy not consumed (leftover)
*/
double injectEnergy(ForgeDirection directionFrom, double amount, double voltage);
}
@@ -2,35 +2,37 @@ package ic2.api.energy.tile;
/**
* Allows a tile entity (mostly a generator) to emit energy.
* <p/>
*
* See ic2/api/energy/usage.txt for an overall description of the energy net api.
*/
public interface IEnergySource extends IEnergyEmitter {
/**
* Energy output provided by the source this tick.
* This is typically Math.min(stored energy, max output/tick).
*
* @return Energy offered this tick
* @note Modifying the energy net from this method is disallowed.
*/
double getOfferedEnergy();
/**
* Energy output provided by the source this tick.
* This is typically Math.min(stored energy, max output/tick).
*
* @note Modifying the energy net from this method is disallowed.
*
* @return Energy offered this tick
*/
double getOfferedEnergy();
/**
* Draw energy from this source's buffer.
* <p/>
* If the source doesn't have a buffer, this is a no-op.
*
* @param amount amount of EU to draw, may be negative
*/
void drawEnergy(double amount);
/**
* Draw energy from this source's buffer.
*
* If the source doesn't have a buffer, this is a no-op.
*
* @param amount amount of EU to draw, may be negative
*/
void drawEnergy(double amount);
/**
* Determine the tier of this energy source.
* 1 = LV, 2 = MV, 3 = HV, 4 = EV etc.
*
* @return tier of this energy source
* @note Modifying the energy net from this method is disallowed.
*/
int getSourceTier();
/**
* Determine the tier of this energy source.
* 1 = LV, 2 = MV, 3 = HV, 4 = EV etc.
*
* @note Modifying the energy net from this method is disallowed.
*
* @return tier of this energy source
*/
int getSourceTier();
}
@@ -3,13 +3,13 @@ package ic2.api.energy.tile;
/**
* For internal usage only, base class for all energy tiles.
*
* @see ic2.api.energy.tile.IEnergySink
* @see ic2.api.energy.tile.IEnergySource
* @see ic2.api.energy.tile.IEnergyConductor
* <p/>
* @see IEnergySink
* @see IEnergySource
* @see IEnergyConductor
*
* See ic2/api/energy/usage.txt for an overall description of the energy net api.
*/
public interface IEnergyTile {
//
//
}
@@ -3,14 +3,14 @@ package ic2.api.energy.tile;
import net.minecraftforge.common.util.ForgeDirection;
public interface IHeatSource {
/*
* Return max heat transmission peer Tick (only theoretical bandwidth not available amount)
*/
int maxrequestHeatTick(ForgeDirection directionFrom);
/*
* @param requested amount of heat to transfer
* Return max heat transmission peer Tick (only theoretical bandwidth not available amount)
*/
int maxrequestHeatTick(ForgeDirection directionFrom);
/*
* @param requested amount of heat to transfer
*
* @return transmitted amount of heat
*
@@ -18,6 +18,6 @@ public interface IHeatSource {
*
* requestHeat(100) : return 50 : so 50 units of heat remove from HeatSource
*/
int requestHeat(ForgeDirection directionFrom, int requestheat);
int requestHeat(ForgeDirection directionFrom, int requestheat);
}
@@ -3,13 +3,13 @@ package ic2.api.energy.tile;
import net.minecraftforge.common.util.ForgeDirection;
public interface IKineticSource {
/*
* Return max kinetic energy transmission peer Tick (only theoretical bandwidth not available amount)
*/
int maxrequestkineticenergyTick(ForgeDirection directionFrom);
/*
* Return max kinetic energy transmission peer Tick (only theoretical bandwidth not available amount)
*/
int maxrequestkineticenergyTick(ForgeDirection directionFrom);
/*
* @param requested amount of kinetic energy to transfer
* @param requested amount of kinetic energy to transfer
*
* @return transmitted amount of kineticenergy
*
@@ -18,5 +18,5 @@ public interface IKineticSource {
* requestkineticenergy(100) : return 50 : so 50 units of kinetic energy remove from KineticSource
*/
int requestkineticenergy(ForgeDirection directionFrom, int requestkineticenergy);
int requestkineticenergy(ForgeDirection directionFrom, int requestkineticenergy);
}
@@ -1,35 +1,36 @@
package ic2.api.energy.tile;
import net.minecraft.tileentity.TileEntity;
import java.util.List;
import net.minecraft.tileentity.TileEntity;
/**
* Interface for grouping multi-block structures to a single energy net delegate.
* <p/>
*
* The energy net uses TileEntity to refer to a specific xyz+world position. If multiple of those
* positions should belong to the same functional structure, i.e. they consume or produce energy
* only once for the whole multi-block instead of once per every single block, this interface
* allows to do so.
* <p/>
*
* The tile entity implementing IMetaDelegate has to be added/removed to/from the energy net
* instead of every single sub-TileEntity. The energy net interaction will be handled by the
* IMetaDelegate TileEntity as well.
* <p/>
*
* The sub tile array TileEntity[] just provides optional connectivity (IEnergyAcceptor,
* IEnergyEmitter) and mandatory position (x, y, z, World) data.
* If the connectivity data on the sub tile is missing, the meta delegate is queried instead.
* <p/>
*
* See ic2/api/energy/usage.txt for an overall description of the energy net api.
*/
public interface IMetaDelegate extends IEnergyTile {
/**
* Get the sub-TileEntities belonging to this Meta TileEntity.
*
* @return sub-TileEntity array
* @note The list has to be consistent between the EnergyNet Load and Unload events.
* @note The list must have at least 1 element.
* @note The parent te implementing IMetaDelegate isn't automatically included.
*/
List<TileEntity> getSubTiles();
/**
* Get the sub-TileEntities belonging to this Meta TileEntity.
*
* @note The list has to be consistent between the EnergyNet Load and Unload events.
* @note The list must have at least 1 element.
* @note The parent te implementing IMetaDelegate isn't automatically included.
*
* @return sub-TileEntity array
*/
List<TileEntity> getSubTiles();
}
@@ -1,4 +1,4 @@
@API(apiVersion = "1.0", owner = "IC2", provides = "IC2API") package ic2.api.energy.tile;
@API(apiVersion="1.0", owner="IC2", provides="IC2API")
package ic2.api.energy.tile;
import cpw.mods.fml.common.API;
@@ -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;
}
+89 -87
View File
@@ -1,10 +1,12 @@
package ic2.api.event;
import cpw.mods.fml.common.eventhandler.Cancelable;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
import cpw.mods.fml.common.eventhandler.Cancelable;
import net.minecraftforge.event.world.WorldEvent;
/**
@@ -12,101 +14,101 @@ import net.minecraftforge.event.world.WorldEvent;
*/
@Cancelable
public class LaserEvent extends WorldEvent {
// the Laser Entity
public final Entity lasershot;
// the Laser Entity
public final Entity lasershot;
// the following variables can be changed and the Laser will adjust to them
// the following variables can be changed and the Laser will adjust to them
// the Player firing the Laser. If the Laser gets "reflected" the Player could change.
public EntityLivingBase owner;
// Range of the Laser Shot. Determine the amount of broken blocks, as well, as each broken block will subtract ~1F from range.
public float range, power;
public int blockBreaks;
// Determines whether the laser will explode upon hitting something
public boolean explosive, smelt;
// the Player firing the Laser. If the Laser gets "reflected" the Player could change.
public EntityLivingBase owner;
// Range of the Laser Shot. Determine the amount of broken blocks, as well, as each broken block will subtract ~1F from range.
public float range, power;
public int blockBreaks;
// Determines whether the laser will explode upon hitting something
public boolean explosive, smelt;
public LaserEvent(World world1, Entity lasershot1, EntityLivingBase owner1, float range1, float power1, int blockBreaks1, boolean explosive1, boolean smelt1) {
super(world1);
this.lasershot = lasershot1;
this.owner = owner1;
this.range = range1;
this.power = power1;
this.blockBreaks = blockBreaks1;
this.explosive = explosive1;
this.smelt = smelt1;
}
public LaserEvent(World world1, Entity lasershot1, EntityLivingBase owner1, float range1, float power1, int blockBreaks1, boolean explosive1, boolean smelt1) {
super(world1);
this.lasershot = lasershot1;
this.owner = owner1;
this.range = range1;
this.power = power1;
this.blockBreaks = blockBreaks1;
this.explosive = explosive1;
this.smelt = smelt1;
}
/**
* Event when the Laser is getting shot by a Player.
* <p/>
* The Item is the Laser Gun which the "Player" has shot
*/
public static class LaserShootEvent extends LaserEvent {
ItemStack laseritem;
/**
* Event when the Laser is getting shot by a Player.
*
* The Item is the Laser Gun which the "Player" has shot
*/
public static class LaserShootEvent extends LaserEvent {
ItemStack laseritem;
public LaserShootEvent(World world1, Entity lasershot1, EntityLivingBase owner1, float range1, float power1, int blockBreaks1, boolean explosive1, boolean smelt1, ItemStack laseritem1) {
super(world1, lasershot1, owner1, range1, power1, blockBreaks1, explosive1, smelt1);
this.laseritem = laseritem1;
}
}
public LaserShootEvent(World world1, Entity lasershot1, EntityLivingBase owner1, float range1, float power1, int blockBreaks1, boolean explosive1, boolean smelt1, ItemStack laseritem1) {
super(world1, lasershot1, owner1, range1, power1, blockBreaks1, explosive1, smelt1);
this.laseritem = laseritem1;
}
}
/**
* Event when the Laser is exploding for some Reason.
* <p/>
* The Laser will no longer exist after this Event is posted as it either Explodes or despawns after the Event is fired.
*/
public static class LaserExplodesEvent extends LaserEvent {
// explosion strength, even that can be changed!
public float explosionpower, explosiondroprate, explosionentitydamage;
/**
* Event when the Laser is exploding for some Reason.
*
* The Laser will no longer exist after this Event is posted as it either Explodes or despawns after the Event is fired.
*/
public static class LaserExplodesEvent extends LaserEvent {
// explosion strength, even that can be changed!
public float explosionpower, explosiondroprate, explosionentitydamage;
public LaserExplodesEvent(World world1, Entity lasershot1, EntityLivingBase owner1, float range1, float power1, int blockBreaks1, boolean explosive1, boolean smelt1, float explosionpower1, float explosiondroprate1, float explosionentitydamage1) {
super(world1, lasershot1, owner1, range1, power1, blockBreaks1, explosive1, smelt1);
this.explosionpower = explosionpower1;
this.explosiondroprate = explosiondroprate1;
this.explosionentitydamage = explosionentitydamage1;
}
}
public LaserExplodesEvent(World world1, Entity lasershot1, EntityLivingBase owner1, float range1, float power1, int blockBreaks1, boolean explosive1, boolean smelt1, float explosionpower1, float explosiondroprate1, float explosionentitydamage1) {
super(world1, lasershot1, owner1, range1, power1, blockBreaks1, explosive1, smelt1);
this.explosionpower = explosionpower1;
this.explosiondroprate = explosiondroprate1;
this.explosionentitydamage = explosionentitydamage1;
}
}
/**
* Event when the Laser is hitting a Block
* x, y and z are the Coords of the Block.
* <p/>
* Canceling this Event stops the Laser from attempting to break the Block, what is very useful for Glass.
* Use lasershot.setDead() to remove the Shot entirely.
*/
public static class LaserHitsBlockEvent extends LaserEvent {
// targeted block, even that can be changed!
public int x, y, z;
public int side;
// removeBlock determines if the Block will be removed. dropBlock determines if the Block should drop something.
public boolean removeBlock, dropBlock;
public float dropChance;
/**
* Event when the Laser is hitting a Block
* x, y and z are the Coords of the Block.
*
* Canceling this Event stops the Laser from attempting to break the Block, what is very useful for Glass.
* Use lasershot.setDead() to remove the Shot entirely.
*/
public static class LaserHitsBlockEvent extends LaserEvent {
// targeted block, even that can be changed!
public int x, y, z;
public int side;
// removeBlock determines if the Block will be removed. dropBlock determines if the Block should drop something.
public boolean removeBlock, dropBlock;
public float dropChance;
public LaserHitsBlockEvent(World world1, Entity lasershot1, EntityLivingBase owner1, float range1, float power1, int blockBreaks1, boolean explosive1, boolean smelt1, int x1, int y1, int z1, int side1, float dropChance1, boolean removeBlock1, boolean dropBlock1) {
super(world1, lasershot1, owner1, range1, power1, blockBreaks1, explosive1, smelt1);
this.x = x1;
this.y = y1;
this.z = z1;
this.side = side1;
this.removeBlock = removeBlock1;
this.dropBlock = dropBlock1;
this.dropChance = dropChance1;
}
}
public LaserHitsBlockEvent(World world1, Entity lasershot1, EntityLivingBase owner1, float range1, float power1, int blockBreaks1, boolean explosive1, boolean smelt1, int x1, int y1, int z1, int side1, float dropChance1, boolean removeBlock1, boolean dropBlock1) {
super(world1, lasershot1, owner1, range1, power1, blockBreaks1, explosive1, smelt1);
this.x = x1;
this.y = y1;
this.z = z1;
this.side = side1;
this.removeBlock = removeBlock1;
this.dropBlock = dropBlock1;
this.dropChance = dropChance1;
}
}
/**
* Event when the Laser is getting at a Living Entity
* <p/>
* Canceling this Event ignores the Entity
* Use lasershot.setDead() to remove the Shot entirely.
*/
public static class LaserHitsEntityEvent extends LaserEvent {
// the Entity which the Laser has shot at, even the target can be changed!
public Entity hitentity;
/**
* Event when the Laser is getting at a Living Entity
*
* Canceling this Event ignores the Entity
* Use lasershot.setDead() to remove the Shot entirely.
*/
public static class LaserHitsEntityEvent extends LaserEvent {
// the Entity which the Laser has shot at, even the target can be changed!
public Entity hitentity;
public LaserHitsEntityEvent(World world1, Entity lasershot1, EntityLivingBase owner1, float range1, float power1, int blockBreaks1, boolean explosive1, boolean smelt1, Entity hitentity1) {
super(world1, lasershot1, owner1, range1, power1, blockBreaks1, explosive1, smelt1);
this.hitentity = hitentity1;
}
}
public LaserHitsEntityEvent(World world1, Entity lasershot1, EntityLivingBase owner1, float range1, float power1, int blockBreaks1, boolean explosive1, boolean smelt1, Entity hitentity1) {
super(world1, lasershot1, owner1, range1, power1, blockBreaks1, explosive1, smelt1);
this.hitentity = hitentity1;
}
}
}
+20 -18
View File
@@ -1,30 +1,32 @@
package ic2.api.event;
import cpw.mods.fml.common.eventhandler.Cancelable;
import net.minecraft.world.World;
import cpw.mods.fml.common.eventhandler.Cancelable;
import net.minecraftforge.event.world.WorldEvent;
@Cancelable
public class PaintEvent extends WorldEvent {
// target block
public final int x;
public final int y;
public final int z;
public final int side;
// target block
public final int x;
public final int y;
public final int z;
public final int side;
// color to paint the block
public final int color;
// color to paint the block
public final int color;
// set to true to confirm the operation
public boolean painted = false;
// set to true to confirm the operation
public boolean painted = false;
public PaintEvent(World world1, int x1, int y1, int z1, int side1, int color1) {
super(world1);
public PaintEvent(World world1, int x1, int y1, int z1, int side1, int color1) {
super(world1);
this.x = x1;
this.y = y1;
this.z = z1;
this.side = side1;
this.color = color1;
}
this.x = x1;
this.y = y1;
this.z = z1;
this.side = side1;
this.color = color1;
}
}
+24 -22
View File
@@ -1,35 +1,37 @@
package ic2.api.event;
import cpw.mods.fml.common.eventhandler.Cancelable;
import net.minecraft.block.Block;
import net.minecraft.world.World;
import cpw.mods.fml.common.eventhandler.Cancelable;
import net.minecraftforge.event.world.WorldEvent;
@Cancelable
public class RetextureEvent extends WorldEvent {
// target block
public final int x;
public final int y;
public final int z;
public final int side;
// target block
public final int x;
public final int y;
public final int z;
public final int side;
// referenced block (to grab the texture from)
public final Block referencedBlock;
public final int referencedMeta;
public final int referencedSide;
// referenced block (to grab the texture from)
public final Block referencedBlock;
public final int referencedMeta;
public final int referencedSide;
// set to true to confirm the operation
public boolean applied = false;
// set to true to confirm the operation
public boolean applied = false;
public RetextureEvent(World world1, int x1, int y1, int z1, int side1, Block referencedBlock, int referencedMeta1, int referencedSide1) {
super(world1);
public RetextureEvent(World world1, int x1, int y1, int z1, int side1, Block referencedBlock, int referencedMeta1, int referencedSide1) {
super(world1);
this.x = x1;
this.y = y1;
this.z = z1;
this.side = side1;
this.referencedBlock = referencedBlock;
this.referencedMeta = referencedMeta1;
this.referencedSide = referencedSide1;
}
this.x = x1;
this.y = y1;
this.z = z1;
this.side = side1;
this.referencedBlock = referencedBlock;
this.referencedMeta = referencedMeta1;
this.referencedSide = referencedSide1;
}
}
+2 -2
View File
@@ -1,4 +1,4 @@
@API(apiVersion = "1.0", owner = "IC2", provides = "IC2API") package ic2.api.event;
@API(apiVersion="1.0", owner="IC2", provides="IC2API")
package ic2.api.event;
import cpw.mods.fml.common.API;
@@ -3,15 +3,15 @@ package ic2.api.info;
import net.minecraft.item.ItemStack;
public interface IEnergyValueProvider {
/**
* Determine the energy value for a single item in the supplied stack.
* The value is used by most machines in the discharge slot.
* <p/>
* This only applies to basic single use items, others are to be queried
* through e.g. ElectricItem.manager.getCharge().
*
* @param itemStack ItemStack containing the item to evaluate.
* @return energy in EU
*/
double getEnergyValue(ItemStack itemStack);
/**
* Determine the energy value for a single item in the supplied stack.
* The value is used by most machines in the discharge slot.
*
* This only applies to basic single use items, others are to be queried
* through e.g. ElectricItem.manager.getCharge().
*
* @param itemStack ItemStack containing the item to evaluate.
* @return energy in EU
*/
double getEnergyValue(ItemStack itemStack);
}
@@ -3,13 +3,13 @@ package ic2.api.info;
import net.minecraft.item.ItemStack;
public interface IFuelValueProvider {
/**
* Determine the fuel value for a single item in the supplied stack.
* The information currently applies to Generators and the Iron Furnace.
*
* @param itemStack ItemStack containing the item to evaluate.
* @param allowLava Determine if lava has a fuel value, currently only true for the Iron Furnace.
* @return fuel value
*/
int getFuelValue(ItemStack itemStack, boolean allowLava);
/**
* Determine the fuel value for a single item in the supplied stack.
* The information currently applies to Generators and the Iron Furnace.
*
* @param itemStack ItemStack containing the item to evaluate.
* @param allowLava Determine if lava has a fuel value, currently only true for the Iron Furnace.
* @return fuel value
*/
int getFuelValue(ItemStack itemStack, boolean allowLava);
}
+19 -18
View File
@@ -1,31 +1,32 @@
package ic2.api.info;
import net.minecraft.util.DamageSource;
import cpw.mods.fml.common.Loader;
import cpw.mods.fml.common.LoaderState;
import net.minecraft.util.DamageSource;
public class Info {
public static IEnergyValueProvider itemEnergy;
public static IFuelValueProvider itemFuel;
public static Object ic2ModInstance;
public static IEnergyValueProvider itemEnergy;
public static IFuelValueProvider itemFuel;
public static Object ic2ModInstance;
/**
* Damage Sources used by IC2.
* Getting assigned in preload.
*/
public static DamageSource DMG_ELECTRIC, DMG_NUKE_EXPLOSION, DMG_RADIATION;
/**
* Damage Sources used by IC2.
* Getting assigned in preload.
*/
public static DamageSource DMG_ELECTRIC, DMG_NUKE_EXPLOSION, DMG_RADIATION;
public static boolean isIc2Available() {
if (ic2Available != null) return ic2Available;
public static boolean isIc2Available() {
if (ic2Available != null) return ic2Available;
boolean loaded = Loader.isModLoaded("IC2");
boolean loaded = Loader.isModLoaded("IC2");
if (Loader.instance().hasReachedState(LoaderState.CONSTRUCTING)) {
ic2Available = loaded;
}
if (Loader.instance().hasReachedState(LoaderState.CONSTRUCTING)) {
ic2Available = loaded;
}
return loaded;
}
return loaded;
}
private static Boolean ic2Available = null;
private static Boolean ic2Available = null;
}
+2 -2
View File
@@ -1,4 +1,4 @@
@API(apiVersion = "1.0", owner = "IC2", provides = "IC2API") package ic2.api.info;
@API(apiVersion="1.0", owner="IC2", provides="IC2API")
package ic2.api.info;
import cpw.mods.fml.common.API;
+42 -42
View File
@@ -1,59 +1,59 @@
package ic2.api.item;
import net.minecraft.item.ItemStack;
import java.util.ArrayList;
import java.util.List;
import net.minecraft.item.ItemStack;
/**
* Allows for charging, discharging and using electric items (IElectricItem).
*/
public final class ElectricItem {
/**
* IElectricItemManager to use for interacting with IElectricItem ItemStacks.
* <p/>
* This manager will act as a gateway and delegate the tasks to the final implementation
* (rawManager or a custom one) as necessary.
*/
public static IElectricItemManager manager;
/**
* IElectricItemManager to use for interacting with IElectricItem ItemStacks.
*
* This manager will act as a gateway and delegate the tasks to the final implementation
* (rawManager or a custom one) as necessary.
*/
public static IElectricItemManager manager;
/**
* Standard IElectricItemManager implementation, only call it directly from another
* IElectricItemManager. Use manager instead.
*/
public static IElectricItemManager rawManager;
/**
* Standard IElectricItemManager implementation, only call it directly from another
* IElectricItemManager. Use manager instead.
*/
public static IElectricItemManager rawManager;
/**
* Register an electric item manager for items not implementing IElectricItem.
* <p/>
* This method is only designed for special purposes, implementing IElectricItem or
* ISpecialElectricItem instead of using this is faster.
* <p/>
* Managers used with ISpecialElectricItem shouldn't be registered.
*
* @param manager Manager to register.
*/
public static void registerBackupManager(IBackupElectricItemManager manager) {
backupManagers.add(manager);
}
/**
* Register an electric item manager for items not implementing IElectricItem.
*
* This method is only designed for special purposes, implementing IElectricItem or
* ISpecialElectricItem instead of using this is faster.
*
* Managers used with ISpecialElectricItem shouldn't be registered.
*
* @param manager Manager to register.
*/
public static void registerBackupManager(IBackupElectricItemManager manager) {
backupManagers.add(manager);
}
/**
* Get the electric item manager suitable for the supplied item stack.
* <p/>
* This method is for internal use only.
*
* @param stack ItemStack to be handled.
* @return First suitable electric item manager.
*/
public static IBackupElectricItemManager getBackupManager(ItemStack stack) {
for (IBackupElectricItemManager manager : backupManagers) {
if (manager.handles(stack)) return manager;
}
/**
* Get the electric item manager suitable for the supplied item stack.
*
* This method is for internal use only.
*
* @param stack ItemStack to be handled.
* @return First suitable electric item manager.
*/
public static IBackupElectricItemManager getBackupManager(ItemStack stack) {
for (IBackupElectricItemManager manager : backupManagers) {
if (manager.handles(stack)) return manager;
}
return null;
}
return null;
}
private static final List<IBackupElectricItemManager> backupManagers = new ArrayList<IBackupElectricItemManager>();
private static final List<IBackupElectricItemManager> backupManagers = new ArrayList<IBackupElectricItemManager>();
}
@@ -4,9 +4,9 @@ import net.minecraft.item.ItemStack;
/**
* This interface specifies a manager applicable to items not implementing IElectricItem.
* <p/>
*
* The manager implementing this has to be registered with ElectricItem.registerBackupManager().
*/
public interface IBackupElectricItemManager extends IElectricItemManager {
boolean handles(ItemStack stack);
boolean handles(ItemStack stack);
}
@@ -2,5 +2,5 @@ package ic2.api.item;
public interface IBlockCuttingBlade {
int gethardness();
int gethardness();
}
+7 -7
View File
@@ -4,11 +4,11 @@ import net.minecraft.item.ItemStack;
public interface IBoxable {
/**
* Determine whether an item can be stored in a toolbox or not.
*
* @param itemstack item to be stored
* @return Whether to store the item in the toolbox or not
*/
public abstract boolean canBeStoredInToolbox(ItemStack itemstack);
/**
* Determine whether an item can be stored in a toolbox or not.
*
* @param itemstack item to be stored
* @return Whether to store the item in the toolbox or not
*/
public abstract boolean canBeStoredInToolbox(ItemStack itemstack);
}
+39 -39
View File
@@ -4,40 +4,40 @@ import net.minecraft.item.ItemStack;
/**
* Provides access to IC2 blocks and items.
* <p/>
*
* Some items can be acquired through the ore dictionary which is the recommended way.
* The items are initialized while IC2 is being loaded - try to use ModsLoaded() or load your mod after IC2.
* Some blocks/items can be disabled by a config setting, so it's recommended to check if they're null first.
* <p/>
*
* Getting the associated Block/Item for an ItemStack x:
* Blocks: Block.blocksList[x.itemID]
* Items: x.getItem()
* Blocks: Block.blocksList[x.itemID]
* Items: x.getItem()
*/
public final class IC2Items {
/**
* Get an ItemStack for a specific item name, example: Items.getItem("resin")
* See the list below for item names.
* Make sure to copy() the ItemStack if you want to modify it.
*
* @param name item name
* @return The item or null if the item does not exist or an error occurred
*/
public static ItemStack getItem(String name) {
try {
if (Ic2Items == null) Ic2Items = Class.forName(getPackage() + ".core.Ic2Items");
/**
* Get an ItemStack for a specific item name, example: Items.getItem("resin")
* See the list below for item names.
* Make sure to copy() the ItemStack if you want to modify it.
*
* @param name item name
* @return The item or null if the item does not exist or an error occurred
*/
public static ItemStack getItem(String name) {
try {
if (Ic2Items == null) Ic2Items = Class.forName(getPackage() + ".core.Ic2Items");
Object ret = Ic2Items.getField(name).get(null);
Object ret = Ic2Items.getField(name).get(null);
if (ret instanceof ItemStack) {
return (ItemStack) ret;
}
return null;
} catch (Exception e) {
System.out.println("IC2 API: Call getItem failed for " + name);
if (ret instanceof ItemStack) {
return (ItemStack) ret;
}
return null;
} catch (Exception e) {
System.out.println("IC2 API: Call getItem failed for "+name);
return null;
}
}
return null;
}
}
/* Possible values:
@@ -576,23 +576,23 @@ public final class IC2Items {
*/
/**
* Get the base IC2 package name, used internally.
*
* @return IC2 package name, if unable to be determined defaults to ic2
*/
private static String getPackage() {
Package pkg = IC2Items.class.getPackage();
/**
* Get the base IC2 package name, used internally.
*
* @return IC2 package name, if unable to be determined defaults to ic2
*/
private static String getPackage() {
Package pkg = IC2Items.class.getPackage();
if (pkg != null) {
String packageName = pkg.getName();
if (pkg != null) {
String packageName = pkg.getName();
return packageName.substring(0, packageName.length() - ".api.item".length());
}
return packageName.substring(0, packageName.length() - ".api.item".length());
}
return "ic2";
}
return "ic2";
}
private static Class<?> Ic2Items;
private static Class<?> Ic2Items;
}
+38 -38
View File
@@ -5,51 +5,51 @@ import net.minecraft.item.ItemStack;
/**
* Provides the ability to store energy on the implementing item.
* <p/>
*
* The item should have a maximum damage of 13.
*/
public interface IElectricItem {
/**
* Determine if the item can be used in a machine or as an armor part to supply energy.
*
* @return Whether the item can supply energy
*/
boolean canProvideEnergy(ItemStack itemStack);
/**
* Determine if the item can be used in a machine or as an armor part to supply energy.
*
* @return Whether the item can supply energy
*/
boolean canProvideEnergy(ItemStack itemStack);
/**
* Get the item ID to use for a charge energy greater than 0.
*
* @return Item ID to use
*/
Item getChargedItem(ItemStack itemStack);
/**
* Get the item ID to use for a charge energy greater than 0.
*
* @return Item ID to use
*/
Item getChargedItem(ItemStack itemStack);
/**
* Get the item ID to use for a charge energy of 0.
*
* @return Item ID to use
*/
Item getEmptyItem(ItemStack itemStack);
/**
* Get the item ID to use for a charge energy of 0.
*
* @return Item ID to use
*/
Item getEmptyItem(ItemStack itemStack);
/**
* Get the item's maximum charge energy in EU.
*
* @return Maximum charge energy
*/
double getMaxCharge(ItemStack itemStack);
/**
* Get the item's maximum charge energy in EU.
*
* @return Maximum charge energy
*/
double getMaxCharge(ItemStack itemStack);
/**
* Get the item's tier, lower tiers can't send energy to higher ones.
* Batteries are Tier 1, Energy Crystals are Tier 2, Lapotron Crystals are Tier 3.
*
* @return Item's tier
*/
int getTier(ItemStack itemStack);
/**
* Get the item's tier, lower tiers can't send energy to higher ones.
* Batteries are Tier 1, Energy Crystals are Tier 2, Lapotron Crystals are Tier 3.
*
* @return Item's tier
*/
int getTier(ItemStack itemStack);
/**
* Get the item's transfer limit in EU per transfer operation.
*
* @return Transfer limit
*/
double getTransferLimit(ItemStack itemStack);
/**
* Get the item's transfer limit in EU per transfer operation.
*
* @return Transfer limit
*/
double getTransferLimit(ItemStack itemStack);
}
@@ -5,89 +5,91 @@ import net.minecraft.item.ItemStack;
/**
* This interface specifies a manager to handle the various tasks for electric items.
* <p/>
*
* The default implementation does the following:
* - store and retrieve the charge
* - handle charging, taking amount, tier, transfer limit, canProvideEnergy and simulate into account
* - replace item IDs if appropriate (getChargedItemId() and getEmptyItemId())
* - update and manage the damage value for the visual charge indicator
*
*
* @note If you're implementing your own variant (ISpecialElectricItem), you can delegate to the
* default implementations through ElectricItem.rawManager. The default implementation is designed
* to minimize its dependency on its own constraints/structure and delegates most work back to the
* more atomic features in the gateway manager.
*/
public interface IElectricItemManager {
/**
* Charge an item with a specified amount of energy.
*
* @param itemStack electric item's stack
* @param amount amount of energy to charge in EU
* @param tier tier of the charging device, has to be at least as high as the item to charge
* @param ignoreTransferLimit ignore the transfer limit specified by getTransferLimit()
* @param simulate don't actually change the item, just determine the return value
* @return Energy transferred into the electric item
*/
double charge(ItemStack stack, double amount, int tier, boolean ignoreTransferLimit, boolean simulate);
/**
* Charge an item with a specified amount of energy.
*
* @param itemStack electric item's stack
* @param amount amount of energy to charge in EU
* @param tier tier of the charging device, has to be at least as high as the item to charge
* @param ignoreTransferLimit ignore the transfer limit specified by getTransferLimit()
* @param simulate don't actually change the item, just determine the return value
* @return Energy transferred into the electric item
*/
double charge(ItemStack stack, double amount, int tier, boolean ignoreTransferLimit, boolean simulate);
/**
* Discharge an item by a specified amount of energy
*
* @param itemStack electric item's stack
* @param amount amount of energy to discharge in EU
* @param tier tier of the discharging device, has to be at least as high as the item to discharge
* @param ignoreTransferLimit ignore the transfer limit specified by getTransferLimit()
* @param externally use the supplied item externally, i.e. to power something else as if it was a battery
* @param simulate don't actually discharge the item, just determine the return value
* @return Energy retrieved from the electric item
*/
double discharge(ItemStack stack, double amount, int tier, boolean ignoreTransferLimit, boolean externally, boolean simulate);
/**
* Discharge an item by a specified amount of energy
*
* @param itemStack electric item's stack
* @param amount amount of energy to discharge in EU
* @param tier tier of the discharging device, has to be at least as high as the item to discharge
* @param ignoreTransferLimit ignore the transfer limit specified by getTransferLimit()
* @param externally use the supplied item externally, i.e. to power something else as if it was a battery
* @param simulate don't actually discharge the item, just determine the return value
* @return Energy retrieved from the electric item
*/
double discharge(ItemStack stack, double amount, int tier, boolean ignoreTransferLimit, boolean externally, boolean simulate);
/**
* Determine the charge level for the specified item.
*
* @param itemStack ItemStack containing the electric item
* @return charge level in EU
*/
double getCharge(ItemStack stack);
/**
* Determine the charge level for the specified item.
*
* @param itemStack ItemStack containing the electric item
* @return charge level in EU
*/
double getCharge(ItemStack stack);
/**
* Determine if the specified electric item has at least a specific amount of EU.
* This is supposed to be used in the item code during operation, for example if you want to implement your own electric item.
* BatPacks are not taken into account.
*
* @param itemStack electric item's stack
* @param amount minimum amount of energy required
* @return true if there's enough energy
*/
boolean canUse(ItemStack stack, double amount);
/**
* Determine if the specified electric item has at least a specific amount of EU.
* This is supposed to be used in the item code during operation, for example if you want to implement your own electric item.
* BatPacks are not taken into account.
*
* @param itemStack electric item's stack
* @param amount minimum amount of energy required
* @return true if there's enough energy
*/
boolean canUse(ItemStack stack, double amount);
/**
* Try to retrieve a specific amount of energy from an Item, and if applicable, a BatPack.
* This is supposed to be used in the item code during operation, for example if you want to implement your own electric item.
*
* @param itemStack electric item's stack
* @param amount amount of energy to discharge in EU
* @param entity entity holding the item
* @return true if the operation succeeded
*/
boolean use(ItemStack stack, double amount, EntityLivingBase entity);
/**
* Try to retrieve a specific amount of energy from an Item, and if applicable, a BatPack.
* This is supposed to be used in the item code during operation, for example if you want to implement your own electric item.
*
* @param itemStack electric item's stack
* @param amount amount of energy to discharge in EU
* @param entity entity holding the item
* @return true if the operation succeeded
*/
boolean use(ItemStack stack, double amount, EntityLivingBase entity);
/**
* Charge an item from the BatPack a player is wearing.
* This is supposed to be used in the item code during operation, for example if you want to implement your own electric item.
* use() already contains this functionality.
*
* @param itemStack electric item's stack
* @param entity entity holding the item
*/
void chargeFromArmor(ItemStack stack, EntityLivingBase entity);
/**
* Charge an item from the BatPack a player is wearing.
* This is supposed to be used in the item code during operation, for example if you want to implement your own electric item.
* use() already contains this functionality.
*
* @param itemStack electric item's stack
* @param entity entity holding the item
*/
void chargeFromArmor(ItemStack stack, EntityLivingBase entity);
/**
* Get the tool tip to display for electric items.
*
* @param itemStack ItemStack to determine the tooltip for
* @return tool tip string or null for none
*/
String getToolTip(ItemStack stack);
/**
* Get the tool tip to display for electric items.
*
* @param itemStack ItemStack to determine the tooltip for
* @return tool tip string or null for none
*/
String getToolTip(ItemStack stack);
// TODO: add tier getter
}
+4 -4
View File
@@ -1,11 +1,11 @@
package ic2.api.item;
import net.minecraft.item.ItemStack;
import java.util.List;
import net.minecraft.item.ItemStack;
public interface IItemHudInfo {
/*
/*
Add Info to Nano- and Quantum-Suit Helm Hud
for itemStack
@@ -20,5 +20,5 @@ public interface IItemHudInfo {
*/
public List<String> getHudInfo(ItemStack itemStack);
public List<String> getHudInfo(ItemStack itemStack);
}
@@ -3,13 +3,13 @@ package ic2.api.item;
import net.minecraft.util.ResourceLocation;
public interface IKineticWindRotor {
public int getDiameter();
public int getDiameter();
public ResourceLocation getRotorRenderTexture();
public ResourceLocation getRotorRenderTexture();
public float getefficiency();
public float getefficiency();
int getminWindStrength();
int getminWindStrength();
int getmaxWindStrength();
int getmaxWindStrength();
}
+47
View File
@@ -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);
}
+9 -9
View File
@@ -5,16 +5,16 @@ import net.minecraft.item.ItemStack;
/**
* Armor items implementing this can be considered metal armor.
* <p/>
*
* Currently used for determining which boots can be used to slide up a magnetic pole.
*/
public interface IMetalArmor {
/**
* Determine if the given armor piece is metal armor.
*
* @param itemstack Armor piece as worn by the player
* @param player The player
* @return Whether the armor piece is metal armor
*/
public boolean isMetalArmor(ItemStack itemstack, EntityPlayer player);
/**
* Determine if the given armor piece is metal armor.
*
* @param itemstack Armor piece as worn by the player
* @param player The player
* @return Whether the armor piece is metal armor
*/
public boolean isMetalArmor(ItemStack itemstack, EntityPlayer player);
}
@@ -3,11 +3,11 @@ package ic2.api.item;
import net.minecraft.item.ItemStack;
public interface ISpecialElectricItem extends IElectricItem {
/**
* Supply a custom IElectricItemManager.
*
* @param itemStack ItemStack to get the manager for
* @return IElectricItemManager instance
*/
IElectricItemManager getManager(ItemStack itemStack);
/**
* Supply a custom IElectricItemManager.
*
* @param itemStack ItemStack to get the manager for
* @return IElectricItemManager instance
*/
IElectricItemManager getManager(ItemStack itemStack);
}
+25 -25
View File
@@ -6,29 +6,29 @@ import net.minecraft.world.World;
* Allows an item to act as a terraformer blueprint.
*/
public interface ITerraformingBP {
/**
* Get the energy consumption per operation of the blueprint.
*
* @return Energy consumption in EU
*/
public abstract int getConsume();
/**
* Get the maximum range of the blueprint.
* Should be a divisor of 5.
*
* @return Maximum range in blocks
*/
public abstract int getRange();
/**
* Perform the terraforming operation.
*
* @param world world to terraform
* @param x X position to terraform
* @param z Z position to terraform
* @param yCoord Y position of the terraformer
* @return Whether the operation was successful and the terraformer should consume energy.
*/
public abstract boolean terraform(World world, int x, int z, int yCoord);
/**
* Get the energy consumption per operation of the blueprint.
*
* @return Energy consumption in EU
*/
public abstract int getConsume();
/**
* Get the maximum range of the blueprint.
* Should be a divisor of 5.
*
* @return Maximum range in blocks
*/
public abstract int getRange();
/**
* Perform the terraforming operation.
*
* @param world world to terraform
* @param x X position to terraform
* @param z Z position to terraform
* @param yCoord Y position of the terraformer
* @return Whether the operation was successful and the terraformer should consume energy.
*/
public abstract boolean terraform(World world, int x, int z, int yCoord);
}
+38 -37
View File
@@ -1,49 +1,50 @@
package ic2.api.item;
import com.google.common.collect.ArrayListMultimap;
import com.google.common.collect.Multimap;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import com.google.common.collect.ArrayListMultimap;
import com.google.common.collect.Multimap;
/**
* Wrapper for inserting interfaces into items you don't own.
*
*
* @author Richard
*/
public class ItemWrapper {
private static final Multimap<Item, IBoxable> boxableItems = ArrayListMultimap.create();
private static final Multimap<Item, IMetalArmor> metalArmorItems = ArrayListMultimap.create();
public static void registerBoxable(Item item, IBoxable boxable) {
boxableItems.put(item, boxable);
}
public static boolean canBeStoredInToolbox(ItemStack stack) {
Item item = stack.getItem();
// use customs first to allow for overriding behavior
for (IBoxable boxable : boxableItems.get(item)) {
if (boxable.canBeStoredInToolbox(stack)) return true;
}
if (item instanceof IBoxable && ((IBoxable) item).canBeStoredInToolbox(stack)) return true;
return false;
}
public static void registerMetalArmor(Item item, IMetalArmor armor) {
metalArmorItems.put(item, armor);
}
public static boolean isMetalArmor(ItemStack stack, EntityPlayer player) {
Item item = stack.getItem();
// use customs first to allow for overriding behavior
for (IMetalArmor metalArmor : metalArmorItems.get(item)) {
if (metalArmor.isMetalArmor(stack, player)) return true;
}
if (item instanceof IMetalArmor && ((IMetalArmor) item).isMetalArmor(stack, player)) return true;
return false;
}
private static final Multimap<Item, IBoxable> boxableItems = ArrayListMultimap.create();
private static final Multimap<Item, IMetalArmor> metalArmorItems = ArrayListMultimap.create();
public static void registerBoxable(Item item, IBoxable boxable) {
boxableItems.put(item, boxable);
}
public static boolean canBeStoredInToolbox(ItemStack stack) {
Item item = stack.getItem();
// use customs first to allow for overriding behavior
for (IBoxable boxable : boxableItems.get(item)) {
if (boxable.canBeStoredInToolbox(stack)) return true;
}
if (item instanceof IBoxable && ((IBoxable) item).canBeStoredInToolbox(stack)) return true;
return false;
}
public static void registerMetalArmor(Item item, IMetalArmor armor) {
metalArmorItems.put(item, armor);
}
public static boolean isMetalArmor(ItemStack stack, EntityPlayer player) {
Item item = stack.getItem();
// use customs first to allow for overriding behavior
for (IMetalArmor metalArmor : metalArmorItems.get(item)) {
if (metalArmor.isMetalArmor(stack, player)) return true;
}
if (item instanceof IMetalArmor && ((IMetalArmor) item).isMetalArmor(stack, player)) return true;
return false;
}
}
+2 -2
View File
@@ -1,4 +1,4 @@
@API(apiVersion = "1.0", owner = "IC2", provides = "IC2API") package ic2.api.item;
@API(apiVersion="1.0", owner="IC2", provides="IC2API")
package ic2.api.item;
import cpw.mods.fml.common.API;
@@ -6,12 +6,12 @@ import net.minecraft.entity.player.EntityPlayer;
* Allows a tile entity to receive network events received from clients.
*/
public interface INetworkClientTileEntityEventListener {
/**
* Called when a network event is received.
*
* @param player client which sent the event
* @param event event ID
*/
void onNetworkEvent(EntityPlayer player, int event);
/**
* Called when a network event is received.
*
* @param player client which sent the event
* @param event event ID
*/
void onNetworkEvent(EntityPlayer player, int event);
}
@@ -4,15 +4,15 @@ import java.util.List;
/**
* Tile entities which want to synchronized specific fields between client and server have to implement this.
* <p/>
*
* The fields don't update themselves, a field update must be sent every time a synchronized field changes.
*/
public interface INetworkDataProvider {
/**
* Get the list of synchronized fields.
*
* @return Names of the synchronized fields
*/
List<String> getNetworkedFields();
/**
* Get the list of synchronized fields.
*
* @return Names of the synchronized fields
*/
List<String> getNetworkedFields();
}
@@ -7,13 +7,13 @@ import net.minecraft.item.ItemStack;
* Allows an item to receive network events received from the server.
*/
public interface INetworkItemEventListener {
/**
* Called when a network event is received.
*
* @param itemStack item stack
* @param player player containing the item
* @param event event ID
*/
void onNetworkEvent(ItemStack stack, EntityPlayer player, int event);
/**
* Called when a network event is received.
*
* @param itemStack item stack
* @param player player containing the item
* @param event event ID
*/
void onNetworkEvent(ItemStack stack, EntityPlayer player, int event);
}
@@ -4,11 +4,11 @@ package ic2.api.network;
* Allows a tile entity to receive network events received from the server.
*/
public interface INetworkTileEntityEventListener {
/**
* Called when a network event is received.
*
* @param event Event ID
*/
void onNetworkEvent(int event);
/**
* Called when a network event is received.
*
* @param event Event ID
*/
void onNetworkEvent(int event);
}
@@ -1,14 +1,14 @@
package ic2.api.network;
/**
* Allows a tile entity to receive field sync updates received from the server.
* Allows a tile entity to receive field sync updates received from the server.
*/
public interface INetworkUpdateListener {
/**
* Called when a field is synchronized.
*
* @param field field synchronized
*/
void onNetworkUpdate(String field);
/**
* Called when a field is synchronized.
*
* @param field field synchronized
*/
void onNetworkUpdate(String field);
}
+156 -161
View File
@@ -1,199 +1,194 @@
package ic2.api.network;
import java.lang.reflect.Method;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import java.lang.reflect.Method;
/**
* Provides methods to initiate events and synchronize tile entity fields in SMP.
* <p/>
*
* The methods are transparent between singleplayer and multiplayer - if a method is called in
* singleplayer, the associated callback will be locally executed. The implementation is different
* between the client and server versions of IC2.
* <p/>
*
* You'll usually want to use the server->client methods defined here to synchronize information
* which is needed by the clients outside the GUI, such as rendering the block, playing sounds or
* producing effects. Anything which is only visible inside the GUI should be synchronized through
* the Container class associated to the GUI in Container.updateProgressBar().
*/
public final class NetworkHelper {
// server -> client
// server -> client
/**
* Schedule a TileEntity's field to be updated to the clients in range.
* <p/>
* The updater will query the field's value during the next update, updates happen usually
* every 2 ticks. If low latency is important use initiateTileEntityEvent instead.
* <p/>
* IC2's network updates have to get triggered every time, it doesn't continuously poll/send
* the field value. Just call updateTileEntityField after every change to a field which needs
* network synchronization.
* <p/>
* The following field data types are currently supported:
* - int, int[], short, short[], byte, byte[], long, long[]
* - float, float[], double, double[]
* - boolean, boolean[]
* - String, String[]
* - ItemStack
* - NBTBase (includes NBTTagCompound)
* - Block, Item, Achievement, Potion, Enchantment
* - ChunkCoordinates, ChunkCoordIntPair
* - TileEntity (does not sync the actual tile entity, instead looks up the tile entity by its position in the client world)
* - World (does not sync the actual world, instead looks up the world by its dimension ID)
* <p/>
* Once the update has been processed by the client, it'll call onNetworkUpdate on the client-
* side TileEntity if it implements INetworkUpdateListener.
* <p/>
* If this method is being executed on the client (i.e. Singleplayer), it'll just call
* INetworkUpdateListener.onNetworkUpdate (if implemented by the te).
*
* @param te TileEntity to update
* @param field Name of the field to update
*/
public static void updateTileEntityField(TileEntity te, String field) {
try {
if (NetworkManager_updateTileEntityField == null)
NetworkManager_updateTileEntityField = Class.forName(getPackage() + ".core.network.NetworkManager").getMethod("updateTileEntityField", TileEntity.class, String.class);
if (instance == null) instance = getInstance();
/**
* Schedule a TileEntity's field to be updated to the clients in range.
*
* The updater will query the field's value during the next update, updates happen usually
* every 2 ticks. If low latency is important use initiateTileEntityEvent instead.
*
* IC2's network updates have to get triggered every time, it doesn't continuously poll/send
* the field value. Just call updateTileEntityField after every change to a field which needs
* network synchronization.
*
* The following field data types are currently supported:
* - int, int[], short, short[], byte, byte[], long, long[]
* - float, float[], double, double[]
* - boolean, boolean[]
* - String, String[]
* - ItemStack
* - NBTBase (includes NBTTagCompound)
* - Block, Item, Achievement, Potion, Enchantment
* - ChunkCoordinates, ChunkCoordIntPair
* - TileEntity (does not sync the actual tile entity, instead looks up the tile entity by its position in the client world)
* - World (does not sync the actual world, instead looks up the world by its dimension ID)
*
* Once the update has been processed by the client, it'll call onNetworkUpdate on the client-
* side TileEntity if it implements INetworkUpdateListener.
*
* If this method is being executed on the client (i.e. Singleplayer), it'll just call
* INetworkUpdateListener.onNetworkUpdate (if implemented by the te).
*
* @param te TileEntity to update
* @param field Name of the field to update
*/
public static void updateTileEntityField(TileEntity te, String field) {
try {
if (NetworkManager_updateTileEntityField == null) NetworkManager_updateTileEntityField = Class.forName(getPackage() + ".core.network.NetworkManager").getMethod("updateTileEntityField", TileEntity.class, String.class);
if (instance == null) instance = getInstance();
NetworkManager_updateTileEntityField.invoke(instance, te, field);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
NetworkManager_updateTileEntityField.invoke(instance, te, field);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
/**
* Immediately send an event for the specified TileEntity to the clients in range.
* <p/>
* If this method is being executed on the client (i.e. Singleplayer), it'll just call
* INetworkTileEntityEventListener.onNetworkEvent (if implemented by the te).
*
* @param te TileEntity to notify, should implement INetworkTileEntityEventListener
* @param event Arbitrary integer to represent the event, choosing the values is up to you
* @param limitRange Limit the notification range to (currently) 20 blocks instead of the
* tracking distance if true
*/
public static void initiateTileEntityEvent(TileEntity te, int event, boolean limitRange) {
try {
if (NetworkManager_initiateTileEntityEvent == null)
NetworkManager_initiateTileEntityEvent = Class.forName(getPackage() + ".core.network.NetworkManager").getMethod("initiateTileEntityEvent", TileEntity.class, Integer.TYPE, Boolean.TYPE);
if (instance == null) instance = getInstance();
/**
* Immediately send an event for the specified TileEntity to the clients in range.
*
* If this method is being executed on the client (i.e. Singleplayer), it'll just call
* INetworkTileEntityEventListener.onNetworkEvent (if implemented by the te).
*
* @param te TileEntity to notify, should implement INetworkTileEntityEventListener
* @param event Arbitrary integer to represent the event, choosing the values is up to you
* @param limitRange Limit the notification range to (currently) 20 blocks instead of the
* tracking distance if true
*/
public static void initiateTileEntityEvent(TileEntity te, int event, boolean limitRange) {
try {
if (NetworkManager_initiateTileEntityEvent == null) NetworkManager_initiateTileEntityEvent = Class.forName(getPackage() + ".core.network.NetworkManager").getMethod("initiateTileEntityEvent", TileEntity.class, Integer.TYPE, Boolean.TYPE);
if (instance == null) instance = getInstance();
NetworkManager_initiateTileEntityEvent.invoke(instance, te, event, limitRange);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
NetworkManager_initiateTileEntityEvent.invoke(instance, te, event, limitRange);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
/**
* Immediately send an event for the specified Item to the clients in range.
* <p/>
* The item should implement INetworkItemEventListener to receive the event.
* <p/>
* If this method is being executed on the client (i.e. Singleplayer), it'll just call
* INetworkItemEventListener.onNetworkEvent (if implemented by the item).
*
* @param player EntityPlayer holding the item
* @param itemStack ItemStack containing the item
* @param event Arbitrary integer to represent the event, choosing the values is up to you
* @param limitRange Limit the notification range to (currently) 20 blocks instead of the
* tracking distance if true
*/
public static void initiateItemEvent(EntityPlayer player, ItemStack itemStack, int event, boolean limitRange) {
try {
if (NetworkManager_initiateItemEvent == null)
NetworkManager_initiateItemEvent = Class.forName(getPackage() + ".core.network.NetworkManager").getMethod("initiateItemEvent", EntityPlayer.class, ItemStack.class, Integer.TYPE, Boolean.TYPE);
if (instance == null) instance = getInstance();
/**
* Immediately send an event for the specified Item to the clients in range.
*
* The item should implement INetworkItemEventListener to receive the event.
*
* If this method is being executed on the client (i.e. Singleplayer), it'll just call
* INetworkItemEventListener.onNetworkEvent (if implemented by the item).
*
* @param player EntityPlayer holding the item
* @param itemStack ItemStack containing the item
* @param event Arbitrary integer to represent the event, choosing the values is up to you
* @param limitRange Limit the notification range to (currently) 20 blocks instead of the
* tracking distance if true
*/
public static void initiateItemEvent(EntityPlayer player, ItemStack itemStack, int event, boolean limitRange) {
try {
if (NetworkManager_initiateItemEvent == null) NetworkManager_initiateItemEvent = Class.forName(getPackage() + ".core.network.NetworkManager").getMethod("initiateItemEvent", EntityPlayer.class, ItemStack.class, Integer.TYPE, Boolean.TYPE);
if (instance == null) instance = getInstance();
NetworkManager_initiateItemEvent.invoke(instance, player, itemStack, event, limitRange);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
NetworkManager_initiateItemEvent.invoke(instance, player, itemStack, event, limitRange);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
// client -> server
// client -> server
/**
* Immediately send an event for the specified TileEntity to the server.
* <p/>
* This method doesn't do anything if executed on the server.
*
* @param te TileEntity to notify, should implement INetworkClientTileEntityEventListener
* @param event Arbitrary integer to represent the event, choosing the values is up to you
*/
public static void initiateClientTileEntityEvent(TileEntity te, int event) {
try {
if (NetworkManager_initiateClientTileEntityEvent == null)
NetworkManager_initiateClientTileEntityEvent = Class.forName(getPackage() + ".core.network.NetworkManager").getMethod("initiateClientTileEntityEvent", TileEntity.class, Integer.TYPE);
if (instance == null) instance = getInstance();
/**
* Immediately send an event for the specified TileEntity to the server.
*
* This method doesn't do anything if executed on the server.
*
* @param te TileEntity to notify, should implement INetworkClientTileEntityEventListener
* @param event Arbitrary integer to represent the event, choosing the values is up to you
*/
public static void initiateClientTileEntityEvent(TileEntity te, int event) {
try {
if (NetworkManager_initiateClientTileEntityEvent == null) NetworkManager_initiateClientTileEntityEvent = Class.forName(getPackage() + ".core.network.NetworkManager").getMethod("initiateClientTileEntityEvent", TileEntity.class, Integer.TYPE);
if (instance == null) instance = getInstance();
NetworkManager_initiateClientTileEntityEvent.invoke(instance, te, event);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
NetworkManager_initiateClientTileEntityEvent.invoke(instance, te, event);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
/**
* Immediately send an event for the specified Item to the clients in range.
* <p/>
* The item should implement INetworkItemEventListener to receive the event.
* <p/>
* This method doesn't do anything if executed on the server.
*
* @param itemStack ItemStack containing the item
* @param event Arbitrary integer to represent the event, choosing the values is up to you
*/
public static void initiateClientItemEvent(ItemStack itemStack, int event) {
try {
if (NetworkManager_initiateClientItemEvent == null)
NetworkManager_initiateClientItemEvent = Class.forName(getPackage() + ".core.network.NetworkManager").getMethod("initiateClientItemEvent", ItemStack.class, Integer.TYPE);
if (instance == null) instance = getInstance();
/**
* Immediately send an event for the specified Item to the clients in range.
*
* The item should implement INetworkItemEventListener to receive the event.
*
* This method doesn't do anything if executed on the server.
*
* @param itemStack ItemStack containing the item
* @param event Arbitrary integer to represent the event, choosing the values is up to you
*/
public static void initiateClientItemEvent(ItemStack itemStack, int event) {
try {
if (NetworkManager_initiateClientItemEvent == null) NetworkManager_initiateClientItemEvent = Class.forName(getPackage() + ".core.network.NetworkManager").getMethod("initiateClientItemEvent", ItemStack.class, Integer.TYPE);
if (instance == null) instance = getInstance();
NetworkManager_initiateClientItemEvent.invoke(instance, itemStack, event);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
NetworkManager_initiateClientItemEvent.invoke(instance, itemStack, event);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
/**
* Get the base IC2 package name, used internally.
*
* @return IC2 package name, if unable to be determined defaults to ic2
*/
private static String getPackage() {
Package pkg = NetworkHelper.class.getPackage();
/**
* Get the base IC2 package name, used internally.
*
* @return IC2 package name, if unable to be determined defaults to ic2
*/
private static String getPackage() {
Package pkg = NetworkHelper.class.getPackage();
if (pkg != null) {
String packageName = pkg.getName();
if (pkg != null) {
String packageName = pkg.getName();
return packageName.substring(0, packageName.length() - ".api.network".length());
}
return packageName.substring(0, packageName.length() - ".api.network".length());
}
return "ic2";
}
return "ic2";
}
/**
* Get the NetworkManager instance, used internally.
*
* @return NetworkManager instance
*/
private static Object getInstance() {
try {
return Class.forName(getPackage() + ".core.IC2").getDeclaredField("network").get(null);
} catch (Throwable e) {
throw new RuntimeException(e);
}
}
/**
* Get the NetworkManager instance, used internally.
*
* @return NetworkManager instance
*/
private static Object getInstance() {
try {
return Class.forName(getPackage() + ".core.IC2").getDeclaredField("network").get(null);
} catch (Throwable e) {
throw new RuntimeException(e);
}
}
private static Object instance;
private static Method NetworkManager_updateTileEntityField;
private static Method NetworkManager_initiateTileEntityEvent;
private static Method NetworkManager_initiateItemEvent;
private static Method NetworkManager_initiateClientTileEntityEvent;
private static Method NetworkManager_initiateClientItemEvent;
private static Object instance;
private static Method NetworkManager_updateTileEntityField;
private static Method NetworkManager_initiateTileEntityEvent;
private static Method NetworkManager_initiateItemEvent;
private static Method NetworkManager_initiateClientTileEntityEvent;
private static Method NetworkManager_initiateClientItemEvent;
}
@@ -1,4 +1,4 @@
@API(apiVersion = "1.0", owner = "IC2", provides = "IC2API") package ic2.api.network;
@API(apiVersion="1.0", owner="IC2", provides="IC2API")
package ic2.api.network;
import cpw.mods.fml.common.API;
+2 -2
View File
@@ -1,4 +1,4 @@
@API(apiVersion = "1.0", owner = "IC2", provides = "IC2API") package ic2.api;
@API(apiVersion="1.0", owner="IC2", provides="IC2API")
package ic2.api;
import cpw.mods.fml.common.API;
+124 -124
View File
@@ -8,151 +8,151 @@ import net.minecraft.world.World;
* Interface implemented by the tile entity of nuclear reactors.
*/
public interface IReactor {
/**
* Get the reactor's position in the world.
*
* @return Position of the reactor
*/
public ChunkCoordinates getPosition();
/**
* Get the reactor's position in the world.
*
* @return Position of the reactor
*/
public ChunkCoordinates getPosition();
/**
* Get the reactor's corresponding world.
*
* @return The reactor's world
*/
public World getWorld();
/**
* Get the reactor's corresponding world.
*
* @return The reactor's world
*/
public World getWorld();
/**
* Get the reactor's heat.
*
* @return The reactor's heat
*/
public int getHeat();
/**
* Get the reactor's heat.
*
* @return The reactor's heat
*/
public int getHeat();
/**
* Set the reactor's heat.
*
* @param heat reactor heat
*/
public void setHeat(int heat);
/**
* Set the reactor's heat.
*
* @param heat reactor heat
*/
public void setHeat(int heat);
/**
* Increase the reactor's heat.
* <p/>
* Use negative values to decrease.
*
* @param amount amount of heat to add
* @return The reactor's heat after adding the specified amount
*/
public int addHeat(int amount);
/**
* Increase the reactor's heat.
*
* Use negative values to decrease.
*
* @param amount amount of heat to add
* @return The reactor's heat after adding the specified amount
*/
public int addHeat(int amount);
/**
* Get the reactor's maximum heat before exploding.
*
* @return Maximum heat value
*/
public int getMaxHeat();
/**
* Get the reactor's maximum heat before exploding.
*
* @return Maximum heat value
*/
public int getMaxHeat();
/**
* Set the reactor's stored maxHeat variable.
* Used by plating to increase the reactors MaxHeat capacity.
* Needs to be called during each cycle process.
*/
public void setMaxHeat(int newMaxHeat);
/**
* Set the reactor's stored maxHeat variable.
* Used by plating to increase the reactors MaxHeat capacity.
* Needs to be called during each cycle process.
*/
public void setMaxHeat(int newMaxHeat);
/**
* add Heat to a EmitHeat Buffer
* for use in Reactor operation.. need to be use
* for all Componetents with self-cooling
* no more magic heat disappear
*/
/**
* add Heat to a EmitHeat Buffer
* for use in Reactor operation.. need to be use
* for all Componetents with self-cooling
* no more magic heat disappear
*/
public void addEmitHeat(int heat);
public void addEmitHeat(int heat);
/**
* Get's the reactor's HEM (Heat Effect Modifier)
* Basic value is 1.0F.
* Reducing the value causes a weakening/reduction of the heat-based sideeffects of reactors
* (F.e. water evaporation, melting, damaging entitys, etc)
*
* @return HEM
*/
public float getHeatEffectModifier();
/**
* Get's the reactor's HEM (Heat Effect Modifier)
* Basic value is 1.0F.
* Reducing the value causes a weakening/reduction of the heat-based sideeffects of reactors
* (F.e. water evaporation, melting, damaging entitys, etc)
*
* @return HEM
*/
public float getHeatEffectModifier();
/**
* Set's the reactor's HEM
* Needs to be called during each cycle process.
*/
public void setHeatEffectModifier(float newHEM);
/**
* Set's the reactor's HEM
* Needs to be called during each cycle process.
*/
public void setHeatEffectModifier(float newHEM);
/**
* Get the reactor's energy output.
*
* @return Energy output, not multiplied by the base EU/t value
*/
public float getReactorEnergyOutput();
/**
* Get the reactor's energy output.
*
* @return Energy output, not multiplied by the base EU/t value
*/
public float getReactorEnergyOutput();
/**
* Get the reactor's energy output.
*
* @return Energy output, multiplied with base EU/t value and MainConfig.get().getFloat("balance/energy/generator/nuclear")
*/
public double getReactorEUEnergyOutput();
/**
* Get the reactor's energy output.
*
* @return Energy output, multiplied with base EU/t value and MainConfig.get().getFloat("balance/energy/generator/nuclear")
*/
public double getReactorEUEnergyOutput();
/**
* Add's the given amount of energy to the Reactor's output.
*
* @return Energy output after adding the value, not multiplied by the base EU/t value
*/
public float addOutput(float energy);
/**
* Add's the given amount of energy to the Reactor's output.
*
* @return Energy output after adding the value, not multiplied by the base EU/t value
*/
public float addOutput(float energy);
/**
* Get the item at the specified grid coordinates.
*
* @param x X position of the item, out of bounds returns null
* @param y Y position of the item, out of bounds returns null
* @return The item or null if there is no item
*/
public ItemStack getItemAt(int x, int y);
/**
* Get the item at the specified grid coordinates.
*
* @param x X position of the item, out of bounds returns null
* @param y Y position of the item, out of bounds returns null
* @return The item or null if there is no item
*/
public ItemStack getItemAt(int x, int y);
/**
* Set the item at the specified grid coordinates.
*
* @param x X position of the item, out of bounds is a no-op
* @param y Y position of the item, out of bounds is a no-op
* @param item The item to set.
*/
public void setItemAt(int x, int y, ItemStack item);
/**
* Set the item at the specified grid coordinates.
*
* @param x X position of the item, out of bounds is a no-op
* @param y Y position of the item, out of bounds is a no-op
* @param item The item to set.
*/
public void setItemAt(int x, int y, ItemStack item);
/**
* Explode the reactor.
*/
public void explode();
/**
* Explode the reactor.
*/
public void explode();
/**
* Get the reactor's tick rate (game ticks per reactor tick).
*
* @return Tick rate
*/
public int getTickRate();
/**
* Get the reactor's tick rate (game ticks per reactor tick).
*
* @return Tick rate
*/
public int getTickRate();
/**
* Get whether the reactor is active and supposed to produce energy
*
* @return Whether the reactor is active
*/
public boolean produceEnergy();
/**
* Get whether the reactor is active and supposed to produce energy
* @return Whether the reactor is active
*/
public boolean produceEnergy();
/**
* Set Redstone Signal without direct contact
*/
/**
* Set Redstone Signal without direct contact
*
*/
public void setRedstoneSignal(boolean redstone);
public void setRedstoneSignal(boolean redstone);
/**
* @return true if the reactor is FluidCooled
*/
/**
* @return true if the reactor is FluidCooled
*/
public boolean isFluidCooled();
public boolean isFluidCooled();
}
@@ -4,16 +4,17 @@ package ic2.api.reactor;
* Interface implemented by the reactor chamber tile entity.
*/
public interface IReactorChamber {
/**
* Get the chamber's reactor.
*
* @return The reactor
*/
public IReactor getReactor();
/**
* Get the chamber's reactor.
*
* @return The reactor
*/
public IReactor getReactor();
/**
* Set Redstone Signal without direct contact
*/
public void setRedstoneSignal(boolean redstone);
/**
* Set Redstone Signal without direct contact
*
*/
public void setRedstoneSignal(boolean redstone);
}
@@ -6,96 +6,93 @@ import net.minecraft.item.ItemStack;
* Design custom Reactor components by implementing this Interface
* Items implementing the interface will not be ejected from Reactors in their clean-up
* and can/will be interacted with by other elements, f.e. Uranium Cells.
* <p/>
*
* All IC2 ReactorComponents implement and use this Interface
*
*/
public interface IReactorComponent {
/**
* Called by reactor upon iterating through it's inventory (every cycle).
* Perform all necessary calculation/interaction here
*
* @param reactor Reference to the Reactor
* @param yourStack Reference to the specific instance of iterated ItemStack
* @param x X-coordinate of the stack in the grid
* @param y Y-coordinate of the stack in the grid
* @param heatrun every Stack will cycle 2 time (true, false) first run for heat, sec for Eu calculation
*/
public void processChamber(IReactor reactor, ItemStack yourStack, int x, int y, boolean heatrun);
/**
* Called by reactor upon iterating through it's inventory (every cycle).
* Perform all necessary calculation/interaction here
*
* @param reactor Reference to the Reactor
* @param yourStack Reference to the specific instance of iterated ItemStack
* @param x X-coordinate of the stack in the grid
* @param y Y-coordinate of the stack in the grid
* @param heatrun every Stack will cycle 2 time (true, false) first run for heat, sec for Eu calculation
*/
public void processChamber(IReactor reactor, ItemStack yourStack, int x, int y, boolean heatrun);
/**
* Can be called by Uranium-Components who attempt to generate energy by pulsing to other components.
* Uranium-Uranium interaction (f.e.) uses this method.
*
* @param reactor Reference to the Reactor
* @param yourStack Reference to the specific instance of called ItemStack
* @param pulsingStack Reference to the specific instance of pulsing ItemStack
* @param youX X-coordinate of your stack in the grid
* @param youY Y-coordinate of your stack in the grid
* @param pulseX X-coordinate of pulsing stack in the grid
* @param pulseY Y-coordinate of pulsing stack in the grid
* @param heatrun true for only create heat not EU, false for only EU not heat
* @return true if this component reacts to the pulse (and pulse is therefore meant to produce heat)
*/
public boolean acceptUraniumPulse(IReactor reactor, ItemStack yourStack, ItemStack pulsingStack, int youX, int youY, int pulseX, int pulseY, boolean heatrun);
/**
* Can be called by Uranium-Components who attempt to generate energy by pulsing to other components.
* Uranium-Uranium interaction (f.e.) uses this method.
* @param reactor Reference to the Reactor
* @param yourStack Reference to the specific instance of called ItemStack
* @param pulsingStack Reference to the specific instance of pulsing ItemStack
* @param youX X-coordinate of your stack in the grid
* @param youY Y-coordinate of your stack in the grid
* @param pulseX X-coordinate of pulsing stack in the grid
* @param pulseY Y-coordinate of pulsing stack in the grid
* @param heatrun true for only create heat not EU, false for only EU not heat
* @return true if this component reacts to the pulse (and pulse is therefore meant to produce heat)
*/
public boolean acceptUraniumPulse(IReactor reactor, ItemStack yourStack, ItemStack pulsingStack, int youX, int youY, int pulseX, int pulseY, boolean heatrun);
/**
* Called by components to determine whether your component can be heated.
*
* @param reactor Reference to the Reactor
* @param yourStack Reference to the specific instance of iterated ItemStack
* @param x X-coordinate of the stack in the grid
* @param y Y-coordinate of the stack in the grid
* @return true if your component can take heat
*/
public boolean canStoreHeat(IReactor reactor, ItemStack yourStack, int x, int y);
/**
* Called by components to determine whether your component can be heated.
* @param reactor Reference to the Reactor
* @param yourStack Reference to the specific instance of iterated ItemStack
* @param x X-coordinate of the stack in the grid
* @param y Y-coordinate of the stack in the grid
* @return true if your component can take heat
*/
public boolean canStoreHeat(IReactor reactor, ItemStack yourStack, int x, int y);
/**
* Called by heat-switches to determine how much heat to distribute into which direction.
* Please return the maximum capacity of your heat-containing component here.
*
* @param reactor Reference to the Reactor
* @param yourStack Reference to the specific instance of iterated ItemStack
* @param x X-coordinate of the stack in the grid
* @param y Y-coordinate of the stack in the grid
* @return Maximum heat
*/
public int getMaxHeat(IReactor reactor, ItemStack yourStack, int x, int y);
/**
* Called by heat-switches to determine how much heat to distribute into which direction.
* Please return the maximum capacity of your heat-containing component here.
* @param reactor Reference to the Reactor
* @param yourStack Reference to the specific instance of iterated ItemStack
* @param x X-coordinate of the stack in the grid
* @param y Y-coordinate of the stack in the grid
* @return Maximum heat
*/
public int getMaxHeat(IReactor reactor, ItemStack yourStack, int x, int y);
/**
* Called by heat-switches to determine how much heat to distribute into which direction.
* Please return the current amount of heat stored in this component
*
* @param reactor Reference to the Reactor
* @param yourStack Reference to the specific instance of iterated ItemStack
* @param x X-coordinate of the stack in the grid
* @param y Y-coordinate of the stack in the grid
* @return Current Heat
*/
public int getCurrentHeat(IReactor reactor, ItemStack yourStack, int x, int y);
/**
* Called by heat-switches to determine how much heat to distribute into which direction.
* Please return the current amount of heat stored in this component
* @param reactor Reference to the Reactor
* @param yourStack Reference to the specific instance of iterated ItemStack
* @param x X-coordinate of the stack in the grid
* @param y Y-coordinate of the stack in the grid
* @return Current Heat
*/
public int getCurrentHeat(IReactor reactor, ItemStack yourStack, int x, int y);
/**
* Called by components to distribute heat to your component.
* Perform heating-calculations and increase your heat (dmg) level accordingly.
* This method will as well be called to REDUCE heat, by providing a negative amount.
*
* @param reactor Reference to the Reactor
* @param yourStack Reference to the specific instance of iterated ItemStack
* @param x X-coordinate of the stack in the grid
* @param y Y-coordinate of the stack in the grid
* @param heat Amount of heat to be added (may be negative to subtract heat)
* @return 0 if the 'order' was accepted, return >0 to indicate the 'remaining' heat which couldn't be absorbed (and vice versa for <0)
*/
public int alterHeat(IReactor reactor, ItemStack yourStack, int x, int y, int heat);
/**
* Called by components to distribute heat to your component.
* Perform heating-calculations and increase your heat (dmg) level accordingly.
* This method will as well be called to REDUCE heat, by providing a negative amount.
*
* @param reactor Reference to the Reactor
* @param yourStack Reference to the specific instance of iterated ItemStack
* @param x X-coordinate of the stack in the grid
* @param y Y-coordinate of the stack in the grid
* @param heat Amount of heat to be added (may be negative to subtract heat)
* @return 0 if the 'order' was accepted, return >0 to indicate the 'remaining' heat which couldn't be absorbed (and vice versa for <0)
*/
public int alterHeat(IReactor reactor, ItemStack yourStack, int x, int y, int heat);
/**
* Called upon reactor explosion
* Alter the explosion size.
* Returning a float 0 < f < 1 will be counted as multiplier.
* Anything else will be counted as a flat addition (in case of <0 = reduction).
*
* @param reactor Reference to the Reactor
* @param yourStack Reference to the specific instance of iterated ItemStack
* @return your explosion modifier
*/
public float influenceExplosion(IReactor reactor, ItemStack yourStack);
/**
* Called upon reactor explosion
* Alter the explosion size.
* Returning a float 0 < f < 1 will be counted as multiplier.
* Anything else will be counted as a flat addition (in case of <0 = reduction).
*
* @param reactor Reference to the Reactor
* @param yourStack Reference to the specific instance of iterated ItemStack
* @return your explosion modifier
*/
public float influenceExplosion(IReactor reactor, ItemStack yourStack);
}
@@ -1,4 +1,4 @@
@API(apiVersion = "1.0", owner = "IC2", provides = "IC2API") package ic2.api.reactor;
@API(apiVersion="1.0", owner="IC2", provides="IC2API")
package ic2.api.reactor;
import cpw.mods.fml.common.API;
@@ -1,51 +1,51 @@
package ic2.api.recipe;
import net.minecraft.item.ItemStack;
import java.util.Map;
import net.minecraft.item.ItemStack;
public interface ICannerBottleRecipeManager {
/**
* Adds a recipe to the machine.
*
* @param container Container to be filled
* @param fill Item to fill into the container
* @param output Filled container
*/
public void addRecipe(IRecipeInput container, IRecipeInput fill, ItemStack output);
/**
* Adds a recipe to the machine.
*
* @param container Container to be filled
* @param fill Item to fill into the container
* @param output Filled container
*/
public void addRecipe(IRecipeInput container, IRecipeInput fill, ItemStack output);
/**
* Gets the recipe output for the given input.
*
* @param container Container to be filled
* @param fill Item to fill into the container
* @param adjustInput modify the input according to the recipe's requirements
* @param acceptTest allow either container or fill to be null to see if either of them is part of a recipe
* @return Recipe output, or null if none
*/
public RecipeOutput getOutputFor(ItemStack container, ItemStack fill, boolean adjustInput, boolean acceptTest);
/**
* Gets the recipe output for the given input.
*
* @param container Container to be filled
* @param fill Item to fill into the container
* @param adjustInput modify the input according to the recipe's requirements
* @param acceptTest allow either container or fill to be null to see if either of them is part of a recipe
* @return Recipe output, or null if none
*/
public RecipeOutput getOutputFor(ItemStack container, ItemStack fill, boolean adjustInput, boolean acceptTest);
/**
* Gets a list of recipes.
* <p/>
* You're a mad evil scientist if you ever modify this.
*
* @return List of recipes
*/
public Map<Input, RecipeOutput> getRecipes();
/**
* Gets a list of recipes.
*
* You're a mad evil scientist if you ever modify this.
*
* @return List of recipes
*/
public Map<Input, RecipeOutput> getRecipes();
public static class Input {
public Input(IRecipeInput container1, IRecipeInput fill1) {
this.container = container1;
this.fill = fill1;
}
public static class Input {
public Input(IRecipeInput container1, IRecipeInput fill1) {
this.container = container1;
this.fill = fill1;
}
public boolean matches(ItemStack container1, ItemStack fill1) {
return this.container.matches(container1) && this.fill.matches(fill1);
}
public boolean matches(ItemStack container1, ItemStack fill1) {
return this.container.matches(container1) && this.fill.matches(fill1);
}
public final IRecipeInput container;
public final IRecipeInput fill;
}
public final IRecipeInput container;
public final IRecipeInput fill;
}
}
@@ -1,53 +1,54 @@
package ic2.api.recipe;
import net.minecraft.item.ItemStack;
import net.minecraftforge.fluids.FluidStack;
import java.util.Map;
import net.minecraft.item.ItemStack;
import net.minecraftforge.fluids.FluidStack;
public interface ICannerEnrichRecipeManager {
/**
* Adds a recipe to the machine.
*
* @param input Fluid input
* @param additive Item to enrich the fluid with
* @param output Output fluid
*/
public void addRecipe(FluidStack input, IRecipeInput additive, FluidStack output);
/**
* Adds a recipe to the machine.
*
* @param input Fluid input
* @param additive Item to enrich the fluid with
* @param output Output fluid
*/
public void addRecipe(FluidStack input, IRecipeInput additive, FluidStack output);
/**
* Gets the recipe output for the given input.
*
* @param input Fluid input
* @param additive Item to enrich the fluid with
* @param adjustInput modify the input according to the recipe's requirements
* @param acceptTest allow input or additive to be null to see if either of them is part of a recipe
* @return Recipe output, or null if none, output fluid in nbt
*/
public RecipeOutput getOutputFor(FluidStack input, ItemStack additive, boolean adjustInput, boolean acceptTest);
/**
* Gets the recipe output for the given input.
*
* @param input Fluid input
* @param additive Item to enrich the fluid with
* @param adjustInput modify the input according to the recipe's requirements
* @param acceptTest allow input or additive to be null to see if either of them is part of a recipe
* @return Recipe output, or null if none, output fluid in nbt
*/
public RecipeOutput getOutputFor(FluidStack input, ItemStack additive, boolean adjustInput, boolean acceptTest);
/**
* Gets a list of recipes.
* <p/>
* You're a mad evil scientist if you ever modify this.
*
* @return List of recipes
*/
public Map<Input, FluidStack> getRecipes();
/**
* Gets a list of recipes.
*
* You're a mad evil scientist if you ever modify this.
*
* @return List of recipes
*/
public Map<Input, FluidStack> getRecipes();
public static class Input {
public Input(FluidStack fluid1, IRecipeInput additive1) {
this.fluid = fluid1;
this.additive = additive1;
}
public static class Input {
public Input(FluidStack fluid1, IRecipeInput additive1) {
this.fluid = fluid1;
this.additive = additive1;
}
public boolean matches(FluidStack fluid1, ItemStack additive1) {
return (this.fluid == null || this.fluid.isFluidEqual(fluid1)) &&
this.additive.matches(additive1);
}
public boolean matches(FluidStack fluid1, ItemStack additive1) {
return (this.fluid == null || this.fluid.isFluidEqual(fluid1)) &&
this.additive.matches(additive1);
}
public final FluidStack fluid;
public final IRecipeInput additive;
}
public final FluidStack fluid;
public final IRecipeInput additive;
}
}
@@ -4,23 +4,23 @@ import net.minecraft.item.ItemStack;
/**
* Recipe manager interface for crafting recipes.
*
*
* @author Richard
*/
public interface ICraftingRecipeManager {
/**
* Adds a shaped crafting recipe.
*
* @param output Recipe output
* @param input Recipe input format
*/
public void addRecipe(ItemStack output, Object... input);
/**
* Adds a shapeless crafting recipe.
*
* @param output Recipe output
* @param input Recipe input
*/
public void addShapelessRecipe(ItemStack output, Object... input);
/**
* Adds a shaped crafting recipe.
*
* @param output Recipe output
* @param input Recipe input format
*/
public void addRecipe(ItemStack output, Object... input);
/**
* Adds a shapeless crafting recipe.
*
* @param output Recipe output
* @param input Recipe input
*/
public void addShapelessRecipe(ItemStack output, Object... input);
}
@@ -1,32 +1,32 @@
package ic2.api.recipe;
import net.minecraftforge.fluids.Fluid;
import java.util.Map;
import net.minecraftforge.fluids.Fluid;
public interface IFluidHeatManager extends ILiquidAcceptManager {
/**
* Add a new fluid to the Fluid Heat Generator.
*
* @param fluidName the fluid to burn
* @param amount amount of fluid to consume per tick
* @param heat amount of heat generated per tick
*/
void addFluid(String fluidName, int amount, int heat);
/**
* Add a new fluid to the Fluid Heat Generator.
*
* @param fluidName the fluid to burn
* @param amount amount of fluid to consume per tick
* @param heat amount of heat generated per tick
*/
void addFluid(String fluidName, int amount, int heat);
BurnProperty getBurnProperty(Fluid fluid);
BurnProperty getBurnProperty(Fluid fluid);
Map<String, BurnProperty> getBurnProperties();
Map<String, BurnProperty> getBurnProperties();
public static class BurnProperty {
public BurnProperty(int amount1, int heat1) {
this.amount = amount1;
this.heat = heat1;
}
public static class BurnProperty {
public BurnProperty(int amount1, int heat1) {
this.amount = amount1;
this.heat = heat1;
}
public final int amount;
public final int heat;
}
public final int amount;
public final int heat;
}
}
@@ -1,11 +1,10 @@
package ic2.api.recipe;
import net.minecraftforge.fluids.Fluid;
import java.util.Set;
public interface ILiquidAcceptManager {
boolean acceptsFluid(Fluid fluid);
import net.minecraftforge.fluids.Fluid;
Set<Fluid> getAcceptedFluids();
public interface ILiquidAcceptManager {
boolean acceptsFluid(Fluid fluid);
Set<Fluid> getAcceptedFluids();
}
@@ -1,41 +1,41 @@
package ic2.api.recipe;
import net.minecraft.item.ItemStack;
import java.util.List;
import net.minecraft.item.ItemStack;
/**
* Recipe manager interface for basic lists.
*
*
* @author Richard
*/
public interface IListRecipeManager extends Iterable<IRecipeInput> {
/**
* Adds a stack to the list.
*
* @param stack Stack to add
*/
public void add(IRecipeInput input);
/**
* Adds a stack to the list.
*
* @param stack Stack to add
*/
public void add(IRecipeInput input);
/**
* Checks whether the specified stack is in the list.
*
* @param stack Stack to check
* @return Whether the stack is in the list
*/
public boolean contains(ItemStack stack);
/**
* Checks whether the specified stack is in the list.
*
* @param stack Stack to check
* @return Whether the stack is in the list
*/
public boolean contains(ItemStack stack);
/**
* @return if the List is Empty
*/
public boolean isEmpty();
/**
* @return if the List is Empty
*/
public boolean isEmpty();
/**
* Gets the list of stacks.
* <p/>
* You're a mad evil scientist if you ever modify this.
*
* @return List of stacks
*/
public List<IRecipeInput> getInputs();
/**
* Gets the list of stacks.
*
* You're a mad evil scientist if you ever modify this.
*
* @return List of stacks
*/
public List<IRecipeInput> getInputs();
}
@@ -1,43 +1,44 @@
package ic2.api.recipe;
import java.util.Map;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import java.util.Map;
/**
* Recipe manager interface for basic machines.
*
*
* @author RichardG, Player
*/
public interface IMachineRecipeManager {
/**
* 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
* <p/>
* 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);
/**
* 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
*/
public RecipeOutput getOutputFor(ItemStack input, boolean adjustInput);
/**
* 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
*/
public RecipeOutput getOutputFor(ItemStack input, boolean adjustInput);
/**
* Gets a list of recipes.
* <p/>
* You're a mad evil scientist if you ever modify this.
*
* @return List of recipes
*/
public Map<IRecipeInput, RecipeOutput> getRecipes();
/**
* 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();
}
@@ -1,11 +1,11 @@
package ic2.api.recipe;
import net.minecraft.item.ItemStack;
import java.util.List;
public interface IPatternStorage {
boolean addPattern(ItemStack itemstack);
import net.minecraft.item.ItemStack;
List<ItemStack> getPatterns();
public interface IPatternStorage {
boolean addPattern(ItemStack itemstack);
List<ItemStack> getPatterns();
}
+23 -23
View File
@@ -1,31 +1,31 @@
package ic2.api.recipe;
import net.minecraft.item.ItemStack;
import java.util.List;
import net.minecraft.item.ItemStack;
public interface IRecipeInput {
/**
* Check if subject matches this recipe input, ignoring the amount.
*
* @param subject ItemStack to check
* @return true if it matches the requirement
*/
boolean matches(ItemStack subject);
/**
* Check if subject matches this recipe input, ignoring the amount.
*
* @param subject ItemStack to check
* @return true if it matches the requirement
*/
boolean matches(ItemStack subject);
/**
* Determine the minimum input stack size.
*
* @return input amount required
*/
int getAmount();
/**
* Determine the minimum input stack size.
*
* @return input amount required
*/
int getAmount();
/**
* List all possible inputs (best effort).
* <p/>
* The stack size is undefined, use getAmount to get the correct one.
*
* @return list of inputs, may be incomplete
*/
List<ItemStack> getInputs();
/**
* List all possible inputs (best effort).
*
* The stack size is undefined, use getAmount to get the correct one.
*
* @return list of inputs, may be incomplete
*/
List<ItemStack> getInputs();
}
@@ -1,13 +1,13 @@
package ic2.api.recipe;
import net.minecraft.item.ItemStack;
import java.util.Map;
import net.minecraft.item.ItemStack;
public interface IScrapboxManager {
void addDrop(ItemStack drop, float rawChance);
void addDrop(ItemStack drop, float rawChance);
ItemStack getDrop(ItemStack input, boolean adjustInput);
ItemStack getDrop(ItemStack input, boolean adjustInput);
Map<ItemStack, Float> getDrops();
Map<ItemStack, Float> getDrops();
}
@@ -1,32 +1,32 @@
package ic2.api.recipe;
import net.minecraftforge.fluids.Fluid;
import java.util.Map;
import net.minecraftforge.fluids.Fluid;
public interface ISemiFluidFuelManager extends ILiquidAcceptManager {
/**
* Add a new fluid to the semi fluid generator.
*
* @param fluidName the fluid to burn
* @param amount amount of fluid to consume per tick
* @param power amount of energy generated per tick
*/
void addFluid(String fluidName, int amount, double power);
/**
* Add a new fluid to the semi fluid generator.
*
* @param fluidName the fluid to burn
* @param amount amount of fluid to consume per tick
* @param power amount of energy generated per tick
*/
void addFluid(String fluidName, int amount, double power);
BurnProperty getBurnProperty(Fluid fluid);
BurnProperty getBurnProperty(Fluid fluid);
Map<String, BurnProperty> getBurnProperties();
Map<String, BurnProperty> getBurnProperties();
public static class BurnProperty {
public BurnProperty(int amount1, double power1) {
this.amount = amount1;
this.power = power1;
}
public static class BurnProperty {
public BurnProperty(int amount1, double power1) {
this.amount = amount1;
this.power = power1;
}
public final int amount;
public final double power;
}
public final int amount;
public final double power;
}
}
@@ -1,53 +1,54 @@
package ic2.api.recipe;
import java.util.ArrayList;
import java.util.List;
import net.minecraft.item.ItemStack;
import net.minecraftforge.fluids.Fluid;
import net.minecraftforge.fluids.FluidContainerRegistry;
import net.minecraftforge.fluids.FluidContainerRegistry.FluidContainerData;
import net.minecraftforge.fluids.FluidStack;
import java.util.ArrayList;
import java.util.List;
public class RecipeInputFluidContainer implements IRecipeInput {
public RecipeInputFluidContainer(Fluid fluid) {
this(fluid, FluidContainerRegistry.BUCKET_VOLUME);
}
public RecipeInputFluidContainer(Fluid fluid) {
this(fluid, FluidContainerRegistry.BUCKET_VOLUME);
}
public RecipeInputFluidContainer(Fluid fluid, int amount) {
this.fluid = fluid;
this.amount = amount;
}
public RecipeInputFluidContainer(Fluid fluid, int amount) {
this.fluid = fluid;
this.amount = amount;
}
@Override
public boolean matches(ItemStack subject) {
FluidStack fs = FluidContainerRegistry.getFluidForFilledItem(subject);
if (fs == null) return false;
@Override
public boolean matches(ItemStack subject) {
FluidStack fs = FluidContainerRegistry.getFluidForFilledItem(subject);
if (fs == null) return false;
return fs.getFluid() == fluid;
}
return fs.getFluid() == fluid;
}
@Override
public int getAmount() {
return amount;
}
@Override
public int getAmount() {
return amount;
}
@Override
public List<ItemStack> getInputs() {
List<ItemStack> ret = new ArrayList<ItemStack>();
@Override
public List<ItemStack> getInputs() {
List<ItemStack> ret = new ArrayList<ItemStack>();
for (FluidContainerData data : FluidContainerRegistry.getRegisteredFluidContainerData()) {
if (data.fluid.getFluid() == fluid) ret.add(data.filledContainer);
}
for (FluidContainerData data : FluidContainerRegistry.getRegisteredFluidContainerData()) {
if (data.fluid.getFluid() == fluid) ret.add(data.filledContainer);
}
return ret;
}
return ret;
}
@Override
public String toString() {
return "RInputFluidContainer<" + amount + "x" + fluid.getName() + ">";
}
@Override
public String toString() {
return "RInputFluidContainer<"+amount+"x"+fluid.getName()+">";
}
public final Fluid fluid;
public final int amount;
public final Fluid fluid;
public final int amount;
}
@@ -1,45 +1,46 @@
package ic2.api.recipe;
import net.minecraft.item.ItemStack;
import net.minecraftforge.oredict.OreDictionary;
import java.util.Arrays;
import java.util.List;
import net.minecraft.item.ItemStack;
import net.minecraftforge.oredict.OreDictionary;
public class RecipeInputItemStack implements IRecipeInput {
public RecipeInputItemStack(ItemStack aInput) {
this(aInput, aInput.stackSize);
}
public RecipeInputItemStack(ItemStack aInput) {
this(aInput, aInput.stackSize);
}
public RecipeInputItemStack(ItemStack aInput, int aAmount) {
if (aInput.getItem() == null) throw new IllegalArgumentException("Invalid item stack specfied");
public RecipeInputItemStack(ItemStack aInput, int aAmount) {
if (aInput.getItem() == null) throw new IllegalArgumentException("Invalid item stack specfied");
input = aInput.copy(); // Never forget to copy.
amount = aAmount;
}
input = aInput.copy(); // Never forget to copy.
amount = aAmount;
}
@Override
public boolean matches(ItemStack subject) {
return subject.getItem() == input.getItem() && (subject.getItemDamage() == input.getItemDamage() || input.getItemDamage() == OreDictionary.WILDCARD_VALUE);
}
@Override
public boolean matches(ItemStack subject) {
return subject.getItem() == input.getItem() && (subject.getItemDamage() == input.getItemDamage() || input.getItemDamage() == OreDictionary.WILDCARD_VALUE);
}
@Override
public int getAmount() {
return amount;
}
@Override
public int getAmount() {
return amount;
}
@Override
public List<ItemStack> getInputs() {
return Arrays.asList(input);
}
@Override
public List<ItemStack> getInputs() {
return Arrays.asList(input);
}
@Override
public String toString() {
ItemStack stack = input.copy();
input.stackSize = amount;
return "RInputItemStack<" + stack + ">";
}
@Override
public String toString() {
ItemStack stack = input.copy();
input.stackSize = amount;
return "RInputItemStack<"+stack+">";
}
public final ItemStack input;
public final int amount;
public final ItemStack input;
public final int amount;
}
@@ -1,70 +1,71 @@
package ic2.api.recipe;
import net.minecraft.item.ItemStack;
import net.minecraftforge.oredict.OreDictionary;
import java.util.ArrayList;
import java.util.List;
import net.minecraft.item.ItemStack;
import net.minecraftforge.oredict.OreDictionary;
public class RecipeInputOreDict implements IRecipeInput {
public RecipeInputOreDict(String input1) {
this(input1, 1);
}
public RecipeInputOreDict(String input1) {
this(input1, 1);
}
public RecipeInputOreDict(String input1, int amount1) {
this(input1, amount1, null);
}
public RecipeInputOreDict(String input1, int amount1) {
this(input1, amount1, null);
}
public RecipeInputOreDict(String input1, int amount1, Integer meta) {
this.input = input1;
this.amount = amount1;
this.meta = meta;
}
public RecipeInputOreDict(String input1, int amount1, Integer meta) {
this.input = input1;
this.amount = amount1;
this.meta = meta;
}
@Override
public boolean matches(ItemStack subject) {
List<ItemStack> inputs = OreDictionary.getOres(input);
@Override
public boolean matches(ItemStack subject) {
List<ItemStack> inputs = OreDictionary.getOres(input);
for (ItemStack input1 : inputs) {
if (input1.getItem() == null) continue; // ignore invalid
int metaRequired = meta == null ? input1.getItemDamage() : meta;
for (ItemStack input1 : inputs) {
if (input1.getItem() == null) continue; // ignore invalid
int metaRequired = meta == null ? input1.getItemDamage() : meta;
if (subject.getItem() == input1.getItem() &&
(subject.getItemDamage() == metaRequired || metaRequired == OreDictionary.WILDCARD_VALUE)) {
return true;
}
}
if (subject.getItem() == input1.getItem() &&
(subject.getItemDamage() == metaRequired || metaRequired == OreDictionary.WILDCARD_VALUE)) {
return true;
}
}
return false;
}
return false;
}
@Override
public int getAmount() {
return amount;
}
@Override
public int getAmount() {
return amount;
}
@Override
public List<ItemStack> getInputs() {
List<ItemStack> ores = OreDictionary.getOres(input);
List<ItemStack> ret = new ArrayList<ItemStack>(ores.size());
@Override
public List<ItemStack> getInputs() {
List<ItemStack> ores = OreDictionary.getOres(input);
List<ItemStack> ret = new ArrayList<ItemStack>(ores.size());
for (ItemStack stack : ores) {
if (stack.getItem() != null) ret.add(stack); // ignore invalid
}
for (ItemStack stack : ores) {
if (stack.getItem() != null) ret.add(stack); // ignore invalid
}
return ret;
}
return ret;
}
@Override
public String toString() {
if (meta == null) {
return "RInputOreDict<" + amount + "x" + input + ">";
} else {
return "RInputOreDict<" + amount + "x" + input + "@" + meta + ">";
}
}
@Override
public String toString() {
if (meta == null) {
return "RInputOreDict<"+amount+"x"+input+">";
} else {
return "RInputOreDict<"+amount+"x"+input+"@"+meta+">";
}
}
public final String input;
public final int amount;
public final Integer meta;
public final String input;
public final int amount;
public final Integer meta;
}
+17 -17
View File
@@ -1,28 +1,28 @@
package ic2.api.recipe;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import java.util.Arrays;
import java.util.List;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
public final class RecipeOutput {
public RecipeOutput(NBTTagCompound metadata1, List<ItemStack> items1) {
assert !items1.contains(null);
public RecipeOutput(NBTTagCompound metadata1, List<ItemStack> items1) {
assert !items1.contains(null);
this.metadata = metadata1;
this.items = items1;
}
this.metadata = metadata1;
this.items = items1;
}
public RecipeOutput(NBTTagCompound metadata1, ItemStack... items1) {
this(metadata1, Arrays.asList(items1));
}
public RecipeOutput(NBTTagCompound metadata1, ItemStack... items1) {
this(metadata1, Arrays.asList(items1));
}
@Override
public String toString() {
return "ROutput<" + items + "," + metadata + ">";
}
@Override
public String toString() {
return "ROutput<"+items+","+metadata+">";
}
public final List<ItemStack> items;
public final NBTTagCompound metadata;
public final List<ItemStack> items;
public final NBTTagCompound metadata;
}
+49 -49
View File
@@ -3,58 +3,58 @@ package ic2.api.recipe;
/**
* General recipe registry.
*
*
* @author Richard
*/
public class Recipes {
public static IMachineRecipeManager macerator;
public static IMachineRecipeManager extractor;
public static IMachineRecipeManager compressor;
public static IMachineRecipeManager centrifuge;
public static IMachineRecipeManager blockcutter;
public static IMachineRecipeManager blastfurance;
public static IMachineRecipeManager recycler;
public static IMachineRecipeManager metalformerExtruding;
public static IMachineRecipeManager metalformerCutting;
public static IMachineRecipeManager metalformerRolling;
public static IMachineRecipeManager oreWashing;
public static ICannerBottleRecipeManager cannerBottle;
public static ICannerEnrichRecipeManager cannerEnrich;
public static IMachineRecipeManager macerator;
public static IMachineRecipeManager extractor;
public static IMachineRecipeManager compressor;
public static IMachineRecipeManager centrifuge;
public static IMachineRecipeManager blockcutter;
public static IMachineRecipeManager blastfurance;
public static IMachineRecipeManager recycler;
public static IMachineRecipeManager metalformerExtruding;
public static IMachineRecipeManager metalformerCutting;
public static IMachineRecipeManager metalformerRolling;
public static IMachineRecipeManager oreWashing;
public static ICannerBottleRecipeManager cannerBottle;
public static ICannerEnrichRecipeManager cannerEnrich;
/**
* Reference amplifier values:
* <p/>
* 5000: Scrap
* 45000: Scrapbox
* <p/>
* As Parameter for the Amplification Value you have to use the NBTTagCompound
* <p/>
* NBTTagCompound nbt = new NBTTagCompound();
* nbt.setInteger("amplification", aValue);
* matterAmplifier.addRecipe(yourStack, nbt);
*/
public static IMachineRecipeManager matterAmplifier;
/**
* Reference scrap box chance values:
* <p/>
* 0.1: Diamond
* 0.5: Cake, Gold Helmet, Iron Ore, Gold Ore
* 1.0: Wooden tools, Soul Sand, Sign, Leather, Feather, Bone
* 1.5: Apple, Bread
* 2.0: Netherrack, Rotten Flesh
* 3.0: Grass, Gravel
* 4.0: Stick
* 5.0: Dirt, Wooden Hoe
*/
public static IScrapboxManager scrapboxDrops;
public static IListRecipeManager recyclerBlacklist;
/**
* Do not add anything to this Whitelist. This is for Configuration only.
* You may need this if you have an own Recycler in your Mod, just to check if something can be recycled. but don't add anything to this List
*/
public static IListRecipeManager recyclerWhitelist;
public static ICraftingRecipeManager advRecipes;
/**
* Reference amplifier values:
*
* 5000: Scrap
* 45000: Scrapbox
*
* As Parameter for the Amplification Value you have to use the NBTTagCompound
*
* NBTTagCompound nbt = new NBTTagCompound();
* nbt.setInteger("amplification", aValue);
* matterAmplifier.addRecipe(yourStack, nbt);
*/
public static IMachineRecipeManager matterAmplifier;
/**
* Reference scrap box chance values:
*
* 0.1: Diamond
* 0.5: Cake, Gold Helmet, Iron Ore, Gold Ore
* 1.0: Wooden tools, Soul Sand, Sign, Leather, Feather, Bone
* 1.5: Apple, Bread
* 2.0: Netherrack, Rotten Flesh
* 3.0: Grass, Gravel
* 4.0: Stick
* 5.0: Dirt, Wooden Hoe
*/
public static IScrapboxManager scrapboxDrops;
public static IListRecipeManager recyclerBlacklist;
/**
* Do not add anything to this Whitelist. This is for Configuration only.
* You may need this if you have an own Recycler in your Mod, just to check if something can be recycled. but don't add anything to this List
*/
public static IListRecipeManager recyclerWhitelist;
public static ICraftingRecipeManager advRecipes;
public static ISemiFluidFuelManager semiFluidGenerator;
public static IFluidHeatManager FluidHeatGenerator;
public static ISemiFluidFuelManager semiFluidGenerator;
public static IFluidHeatManager FluidHeatGenerator;
}
@@ -1,4 +1,4 @@
@API(apiVersion = "1.0", owner = "IC2", provides = "IC2API") package ic2.api.recipe;
@API(apiVersion="1.0", owner="IC2", provides="IC2API")
package ic2.api.recipe;
import cpw.mods.fml.common.API;
@@ -1,47 +1,47 @@
package ic2.api.tile;
import net.minecraft.block.Block;
import java.util.HashSet;
import java.util.Set;
import net.minecraft.block.Block;
/**
* Blocks on this whitelist will not resist an explosion but won't be destroyed.
* <p/>
*
* The explosion code by default ignores blocks which absorb more than 1000 explosion power to
* prevent abusing personal safes, Trade-O-Mats and other blocks to serve as a cheap and
* invulnerable reactor chambers. Said blocks will not shield the explosion and won't get
* destroyed.
*/
public final class ExplosionWhitelist {
/**
* Add a block to the whitelist.
*
* @param block block to add
*/
public static void addWhitelistedBlock(Block block) {
whitelist.add(block);
}
/**
* Add a block to the whitelist.
*
* @param block block to add
*/
public static void addWhitelistedBlock(Block block) {
whitelist.add(block);
}
/**
* Remove a block from the whitelist.
*
* @param block block to remove
*/
public static void removeWhitelistedBlock(Block block) {
whitelist.remove(block);
}
/**
* Check if a block is on the whitelist.
*
* @param block block to check if whitelisted
* @return Whether the block is whitelisted
*/
public static boolean isBlockWhitelisted(Block block) {
return whitelist.contains(block);
}
/**
* Remove a block from the whitelist.
*
* @param block block to remove
*/
public static void removeWhitelistedBlock(Block block) {
whitelist.remove(block);
}
/**
* Check if a block is on the whitelist.
*
* @param block block to check if whitelisted
* @return Whether the block is whitelisted
*/
public static boolean isBlockWhitelisted(Block block) {
return whitelist.contains(block);
}
private static Set<Block> whitelist = new HashSet<Block>();
private static Set<Block> whitelist = new HashSet<Block>();
}
+46 -46
View File
@@ -6,56 +6,56 @@ import net.minecraftforge.common.util.ForgeDirection;
* Interface implemented by the tile entity of energy storage blocks.
*/
public interface IEnergyStorage {
/**
* Get the amount of energy currently stored in the block.
*
* @return Energy stored in the block
*/
public int getStored();
/**
* Get the amount of energy currently stored in the block.
*
* @return Energy stored in the block
*/
public int getStored();
/**
* Set the amount of energy currently stored in the block.
*
* @param energy stored energy
*/
public void setStored(int energy);
/**
* Set the amount of energy currently stored in the block.
*
* @param energy stored energy
*/
public void setStored(int energy);
/**
* Add the specified amount of energy.
* <p/>
* Use negative values to decrease.
*
* @param amount of energy to add
* @return Energy stored in the block after adding the specified amount
*/
public int addEnergy(int amount);
/**
* Add the specified amount of energy.
*
* Use negative values to decrease.
*
* @param amount of energy to add
* @return Energy stored in the block after adding the specified amount
*/
public int addEnergy(int amount);
/**
* Get the maximum amount of energy the block can store.
*
* @return Maximum energy stored
*/
public int getCapacity();
/**
* Get the maximum amount of energy the block can store.
*
* @return Maximum energy stored
*/
public int getCapacity();
/**
* Get the block's energy output.
*
* @return Energy output in EU/t
*/
public int getOutput();
/**
* Get the block's energy output.
*
* @return Energy output in EU/t
*/
public int getOutput();
/**
* Get the block's energy output.
*
* @return Energy output in EU/t
*/
public double getOutputEnergyUnitsPerTick();
/**
* Get the block's energy output.
*
* @return Energy output in EU/t
*/
public double getOutputEnergyUnitsPerTick();
/**
* Get whether this block can have its energy used by an adjacent teleporter.
*
* @param side side the teleporter is draining energy from
* @return Whether the block is teleporter compatible
*/
public boolean isTeleporterCompatible(ForgeDirection side);
/**
* Get whether this block can have its energy used by an adjacent teleporter.
*
* @param side side the teleporter is draining energy from
* @return Whether the block is teleporter compatible
*/
public boolean isTeleporterCompatible(ForgeDirection side);
}
+45 -45
View File
@@ -7,55 +7,55 @@ import net.minecraft.item.ItemStack;
* Allows a tile entity to make use of the wrench's removal and rotation functions.
*/
public interface IWrenchable {
/**
* Determine if the wrench can be used to set the block's facing.
* Called before wrenchCanRemove().
*
* @param entityPlayer player using the wrench, may be null
* @param side block's side the wrench was clicked on
* @return Whether the wrenching was done and the wrench should be damaged
*/
boolean wrenchCanSetFacing(EntityPlayer entityPlayer, int side);
/**
* Determine if the wrench can be used to set the block's facing.
* Called before wrenchCanRemove().
*
* @param entityPlayer player using the wrench, may be null
* @param side block's side the wrench was clicked on
* @return Whether the wrenching was done and the wrench should be damaged
*/
boolean wrenchCanSetFacing(EntityPlayer entityPlayer, int side);
/**
* Get the block's facing.
*
* @return Block facing
*/
short getFacing();
/**
* Get the block's facing.
*
* @return Block facing
*/
short getFacing();
/**
* Set the block's facing
*
* @param facing facing to set the block to
*/
void setFacing(short facing);
/**
* Set the block's facing
*
* @param facing facing to set the block to
*/
void setFacing(short facing);
/**
* Determine if the wrench can be used to remove the block.
* Called if wrenchSetFacing fails.
*
* @param entityPlayer player using the wrench, may be null
* @return Whether the wrenching was done and the wrench should be damaged
*/
boolean wrenchCanRemove(EntityPlayer entityPlayer);
/**
* Determine if the wrench can be used to remove the block.
* Called if wrenchSetFacing fails.
*
* @param entityPlayer player using the wrench, may be null
* @return Whether the wrenching was done and the wrench should be damaged
*/
boolean wrenchCanRemove(EntityPlayer entityPlayer);
/**
* Determine the probability to drop the block as it is.
* The first entry in getDrops will be replaced by blockid:meta if the drop is successful.
*
* @return Probability from 0 to 1
*/
float getWrenchDropRate();
/**
* Determine the probability to drop the block as it is.
* The first entry in getDrops will be replaced by blockid:meta if the drop is successful.
*
* @return Probability from 0 to 1
*/
float getWrenchDropRate();
/**
* Determine the item the block will drop when the wrenching is successful.
* <p/>
* The ItemStack will be copied before creating the EntityItem.
*
* @param entityPlayer player using the wrench, may be null
* @return ItemStack to drop, may be null
*/
ItemStack getWrenchDrop(EntityPlayer entityPlayer);
/**
* Determine the item the block will drop when the wrenching is successful.
*
* The ItemStack will be copied before creating the EntityItem.
*
* @param entityPlayer player using the wrench, may be null
* @return ItemStack to drop, may be null
*/
ItemStack getWrenchDrop(EntityPlayer entityPlayer);
}
+2 -2
View File
@@ -1,4 +1,4 @@
@API(apiVersion = "1.0", owner = "IC2", provides = "IC2API") package ic2.api.tile;
@API(apiVersion="1.0", owner="IC2", provides="IC2API")
package ic2.api.tile;
import cpw.mods.fml.common.API;
+8 -15
View File
@@ -3,19 +3,12 @@ package ic2.api.util;
import net.minecraft.entity.player.EntityPlayer;
public interface IKeyboard {
boolean isAltKeyDown(EntityPlayer player);
boolean isBoostKeyDown(EntityPlayer player);
boolean isForwardKeyDown(EntityPlayer player);
boolean isJumpKeyDown(EntityPlayer player);
boolean isModeSwitchKeyDown(EntityPlayer player);
boolean isSideinventoryKeyDown(EntityPlayer player);
boolean isHudModeKeyDown(EntityPlayer player);
boolean isSneakKeyDown(EntityPlayer player);
boolean isAltKeyDown(EntityPlayer player);
boolean isBoostKeyDown(EntityPlayer player);
boolean isForwardKeyDown(EntityPlayer player);
boolean isJumpKeyDown(EntityPlayer player);
boolean isModeSwitchKeyDown(EntityPlayer player);
boolean isSideinventoryKeyDown(EntityPlayer player);
boolean isHudModeKeyDown(EntityPlayer player);
boolean isSneakKeyDown(EntityPlayer player);
}
+1 -1
View File
@@ -2,5 +2,5 @@ package ic2.api.util;
public class Keys {
public static IKeyboard instance;
public static IKeyboard instance;
}
+2 -2
View File
@@ -1,4 +1,4 @@
@API(apiVersion = "1.0", owner = "IC2", provides = "IC2API") package ic2.api.util;
@API(apiVersion="1.0", owner="IC2", provides="IC2API")
package ic2.api.util;
import cpw.mods.fml.common.API;
@@ -1,34 +0,0 @@
package mcp.mobius.waila.api;
import net.minecraft.item.ItemStack;
import java.util.List;
@Deprecated
public interface IWailaBlock {
/*
* Use this method to return an item stack in case the default lookup system fails.
* Return null if you want to use the default lookup system.
* You get the world, the player and the location of the block. With that, it is easy to gather information & tile entities
*/
ItemStack getWailaStack(IWailaDataAccessor accessor, IWailaConfigHandler config);
/* Waila HUD is divided into 3 zones. The head corresponds to the item name,
* body to where you mostly want to put informations, and I reserve the tail for modname display
*/
/* Those 2 methods works exactly the same way, except they are related to a different zone in Waila HUD.
* You get in input world, player and the block location. You also get the itemstack as returned by the default lookup system or getWailaStack().
* ConfigHandler provides the current Waila config state so you can show/hide elements depending on the configuration. Refer the ConfigHandler class for more info.
* currenttip represents the current list of text lines in the tooltip zone.
* For example, getWailaHead() will have the current item name as currenttip.
* You can modify the tips, add more, remove some, etc.
* When you are done, just returns the currenttip and it will display in Waila.
*
* Always return the currenttip is you don't want to modify the current zone.
*/
List<String> getWailaHead(ItemStack itemStack, List<String> currenttip, IWailaDataAccessor accessor, IWailaConfigHandler config);
List<String> getWailaBody(ItemStack itemStack, List<String> currenttip, IWailaDataAccessor accessor, IWailaConfigHandler config);
List<String> getWailaTail(ItemStack itemStack, List<String> currenttip, IWailaDataAccessor accessor, IWailaConfigHandler config);
}
@@ -1,9 +0,0 @@
package mcp.mobius.waila.api;
import net.minecraft.item.ItemStack;
public interface IWailaBlockDecorator {
void decorateBlock(ItemStack itemStack, IWailaDataAccessor accessor, IWailaConfigHandler config);
}
@@ -1,28 +0,0 @@
package mcp.mobius.waila.api;
import java.util.HashMap;
import java.util.Set;
public interface IWailaConfigHandler {
/* Returns a set of all the currently loaded modules in the config handler */
public Set<String> getModuleNames();
/* Returns all the currently available options for a given module */
public HashMap<String, String> getConfigKeys(String modName);
/* Add a new option to a given module
*
* modName is the name of the module to add the option to (ie : Buildcraft, IndustrialCraft2, etc)
* key is the config key (ie : bc.tankcontent, ic2.inputvalue)
* name is the human readable name of the option (ie : "Tank content", "Max EU Input")
* */
//public void addConfig(String modName, String key, String name);
/* Returns the current value of an option (true/false) with a default value defvalue if not set*/
public boolean getConfig(String key, boolean defvalue);
/* Returns the current value of an option (true/false) with a default value true if not set*/
public boolean getConfig(String key);
//public void setConfig(String key, boolean value);
}
@@ -1,33 +0,0 @@
package mcp.mobius.waila.api;
import net.minecraft.block.Block;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.MovingObjectPosition;
import net.minecraft.util.Vec3;
import net.minecraft.world.World;
import net.minecraftforge.common.util.ForgeDirection;
/* The Accessor is used to get some basic data out of the game without having to request
* direct access to the game engine.
* It will also return things that are unmodified by the overriding systems (like getWailaStack).
*/
public interface IWailaDataAccessor {
World getWorld();
EntityPlayer getPlayer();
Block getBlock();
int getBlockID();
int getMetadata();
TileEntity getTileEntity();
MovingObjectPosition getPosition();
Vec3 getRenderingPosition();
NBTTagCompound getNBTData();
int getNBTInteger(NBTTagCompound tag, String keyname);
double getPartialFrame();
ForgeDirection getSide();
ItemStack getStack();
}
@@ -1,33 +0,0 @@
package mcp.mobius.waila.api;
import net.minecraft.item.ItemStack;
import java.util.List;
public interface IWailaDataProvider{
/*
* Use this method to return an item stack in case the default lookup system fails.
* Return null if you want to use the default lookup system.
* You get the world, the player and the location of the block. With that, it is easy to gather information & tile entities
*/
ItemStack getWailaStack(IWailaDataAccessor accessor, IWailaConfigHandler config);
/* Waila HUD is divided into 3 zones. The head corresponds to the item name,
* body to where you mostly want to put informations, and I reserve the tail for modname display
*/
/* Those 2 methods works exactly the same way, except they are related to a different zone in Waila HUD.
* You get in input world, player and the block location. You also get the itemstack as returned by the default lookup system or getWailaStack().
* ConfigHandler provides the current Waila config state so you can show/hide elements depending on the configuration. Refer the ConfigHandler class for more info.
* currenttip represents the current list of text lines in the tooltip zone.
* For example, getWailaHead() will have the current item name as currenttip.
* You can modify the tips, add more, remove some, etc.
* When you are done, just returns the currenttip and it will display in Waila.
*
* Always return the currenttip is you don't want to modify the current zone.
*/
List<String> getWailaHead(ItemStack itemStack, List<String> currenttip, IWailaDataAccessor accessor, IWailaConfigHandler config);
List<String> getWailaBody(ItemStack itemStack, List<String> currenttip, IWailaDataAccessor accessor, IWailaConfigHandler config);
List<String> getWailaTail(ItemStack itemStack, List<String> currenttip, IWailaDataAccessor accessor, IWailaConfigHandler config);
}
@@ -1,24 +0,0 @@
package mcp.mobius.waila.api;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.MovingObjectPosition;
import net.minecraft.util.Vec3;
import net.minecraft.world.World;
/* The Accessor is used to get some basic data out of the game without having to request
* direct access to the game engine.
* It will also return things that are unmodified by the overriding systems (like getWailaStack).
*/
public interface IWailaEntityAccessor {
World getWorld();
EntityPlayer getPlayer();
Entity getEntity();
MovingObjectPosition getPosition();
Vec3 getRenderingPosition();
NBTTagCompound getNBTData();
int getNBTInteger(NBTTagCompound tag, String keyname);
double getPartialFrame();
}
@@ -1,16 +0,0 @@
package mcp.mobius.waila.api;
import net.minecraft.entity.Entity;
import java.util.List;
public interface IWailaEntityProvider {
/* A way to get an override on the entity returned by the raytracing */
Entity getWailaOverride(IWailaEntityAccessor accessor, IWailaConfigHandler config);
/* The classical HEAD/BODY/TAIL text getters */
List<String> getWailaHead(Entity entity, List<String> currenttip, IWailaEntityAccessor accessor, IWailaConfigHandler config);
List<String> getWailaBody(Entity entity, List<String> currenttip, IWailaEntityAccessor accessor, IWailaConfigHandler config);
List<String> getWailaTail(Entity entity, List<String> currenttip, IWailaEntityAccessor accessor, IWailaConfigHandler config);
}
@@ -1,26 +0,0 @@
package mcp.mobius.waila.api;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.MovingObjectPosition;
import net.minecraft.util.Vec3;
import net.minecraft.world.World;
/* The Accessor is used to get some basic data out of the game without having to request
* direct access to the game engine.
* It will also return things that are unmodified by the overriding systems (like getWailaStack).
*/
public interface IWailaFMPAccessor {
World getWorld();
EntityPlayer getPlayer();
TileEntity getTileEntity();
MovingObjectPosition getPosition();
NBTTagCompound getNBTData();
NBTTagCompound getFullNBTData();
int getNBTInteger(NBTTagCompound tag, String keyname);
double getPartialFrame();
Vec3 getRenderingPosition();
String getID();
}
@@ -1,7 +0,0 @@
package mcp.mobius.waila.api;
import net.minecraft.item.ItemStack;
public interface IWailaFMPDecorator {
void decorateBlock(ItemStack itemStack, IWailaFMPAccessor accessor, IWailaConfigHandler config);
}
@@ -1,12 +0,0 @@
package mcp.mobius.waila.api;
import net.minecraft.item.ItemStack;
import java.util.List;
public interface IWailaFMPProvider {
/* The classical HEAD/BODY/TAIL text getters */
List<String> getWailaHead(ItemStack itemStack, List<String> currenttip, IWailaFMPAccessor accessor, IWailaConfigHandler config);
List<String> getWailaBody(ItemStack itemStack, List<String> currenttip, IWailaFMPAccessor accessor, IWailaConfigHandler config);
List<String> getWailaTail(ItemStack itemStack, List<String> currenttip, IWailaFMPAccessor accessor, IWailaConfigHandler config);
}
@@ -1,44 +0,0 @@
package mcp.mobius.waila.api;
public interface IWailaRegistrar {
/* Add a config option in the section modname with displayed text configtext and access key keyname */
public void addConfig(String modname, String keyname, String configtext);
public void addConfigRemote(String modname, String keyname, String configtext);
public void addConfig(String modname, String keyname);
public void addConfigRemote(String modname, String keyname);
/* Register a stack overrider for the given blockID */
public void registerStackProvider(IWailaDataProvider dataProvider, Class block);
/* Same thing, but works on a class hierarchy instead */
public void registerHeadProvider(IWailaDataProvider dataProvider, Class block);
public void registerBodyProvider(IWailaDataProvider dataProvider, Class block);
public void registerTailProvider(IWailaDataProvider dataProvider, Class block);
/* Entity text registration methods */
public void registerHeadProvider(IWailaEntityProvider dataProvider, Class entity);
public void registerBodyProvider(IWailaEntityProvider dataProvider, Class entity);
public void registerTailProvider(IWailaEntityProvider dataProvider, Class entity);
public void registerOverrideEntityProvider(IWailaEntityProvider dataProvider, Class entity);
/* FMP Providers */
public void registerHeadProvider(IWailaFMPProvider dataProvider, String name);
public void registerBodyProvider(IWailaFMPProvider dataProvider, String name);
public void registerTailProvider(IWailaFMPProvider dataProvider, String name);
/* The block decorators */
public void registerDecorator(IWailaBlockDecorator decorator, Class block);
public void registerDecorator(IWailaFMPDecorator decorator, String name);
/* Selective NBT key syncing. Will register a key to sync over the network for the given class (block, te or ent).
* Accept * as a ending wildcard
* registerNBTKey("bob.*", MyBlock.class)
* registerNBTKey("data.life", MyEntity.class)
* registerNBTKey("*", MyTileEntity.class) will reproduce the full tag syncing from 1.4.5
* */
public void registerSyncedNBTKey(String key, Class target);
/* UNUSED FOR NOW (Will be used for the ingame wiki */
public void registerDocTextFile(String filename);
public void registerShortDataProvider(IWailaSummaryProvider dataProvider, Class item);
}
@@ -1,21 +0,0 @@
package mcp.mobius.waila.api;
import net.minecraft.item.ItemStack;
import java.util.LinkedHashMap;
public interface IWailaSummaryProvider {
/* This interface is used to control the display data in the description screen */
/* BASIC TOOLS & ITEMS DATA */
//EnumToolMaterial getMaterial(ItemStack stack);
//String getMaterialName(ItemStack stack);
//String getEffectiveBlock(ItemStack stack);
//int getHarvestLevel(ItemStack stack);
//float getEfficiencyOnProperMaterial(ItemStack stack);
//int getEnchantability(ItemStack stack);
//int getDamageVsEntity(ItemStack stack);
//int getDurability(ItemStack stack);
LinkedHashMap<String, String> getSummary(ItemStack stack, LinkedHashMap<String, String> currentSummary, IWailaConfigHandler config);
}
Loaded 100 of 111 files, more files were not shown because too many files have changed in this diff. Show more