Update IC2 API

This commit is contained in:
aidancbrady committed 2016-06-22 12:13:18 -04:00
1 parent 3db054424f
commit 1cc41c8722
162 files changed
+3107 -1617

No files matched your search

Binary file not shown.
Binary file not shown.
+4 -30
View File
@@ -9,16 +9,14 @@ public class BaseSeed {
*
* @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
* @param statGrowth plant growth stat
* @param statGain plant gain stat
* @param statResistance plant resistance stat
* @param stackSize 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;
@@ -26,35 +24,11 @@ public class BaseSeed {
this.stackSize = stackSize;
}
/**
* @deprecated Use the CropCard version.
*/
@Deprecated
public BaseSeed(int id, int size, int statGrowth, int statGain, int statResistance, int stackSize) {
this(getCropFromId(id), size, statGrowth, statGain, statResistance, stackSize);
}
@SuppressWarnings("deprecation")
private static CropCard getCropFromId(int id) {
CropCard[] crops = Crops.instance.getCropList();
if (id < 0 || id >= crops.length) return null;
return crops[id];
}
/**
* Plant.
*/
public final CropCard crop;
/**
* @deprecated IDs aren't used anymore.
*/
@Deprecated
public int id;
/**
* Plant size.
*/
Binary file not shown.
+104 -106
View File
@@ -1,11 +1,15 @@
package ic2.api.crops;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraftforge.fml.common.Loader;
import net.minecraftforge.fml.common.ModContainer;
import net.minecraft.util.ResourceLocation;
import net.minecraft.world.World;
/**
* Base agriculture crop.
@@ -14,7 +18,6 @@ import net.minecraftforge.fml.common.ModContainer;
*/
public abstract class CropCard {
public CropCard() {
modId = getModId(); // initialize mod id while we should be in the real owner's init event
}
/**
@@ -27,20 +30,19 @@ public abstract class CropCard {
*
* @return Plant name
*/
public abstract String name();
public abstract String getName();
/**
* Determine the mod id owning this crop.
*
* It's recommended to hard code this to your mod id.
* The owner serves as a name space. With every mod using a different owner, a mod only has to
* make sure it doesn't have conflicts with name() in itself.
* It's recommended to hard code this to your mod id as specified in the @Mod annotation.
* Do not use IC2's mod id here.
*
* @note changing name or owner will cause existing crops in users' worlds to disappear.
*
* @return Mod id.
*/
public String owner() {
return modId;
}
public abstract String getOwner();
/**
* Translation key for display to the player.
@@ -51,8 +53,8 @@ public abstract class CropCard {
*
* @return Unlocalized name.
*/
public String displayName() {
return name(); // return the raw name for backwards compatibility
public String getDisplayName() {
return getName(); // return the raw name for backwards compatibility
}
/**
@@ -60,7 +62,7 @@ public abstract class CropCard {
*
* @return Your name
*/
public String discoveredBy() {
public String getDiscoveredBy() {
return "unknown";
}
@@ -72,7 +74,7 @@ public abstract class CropCard {
* @return The line
*/
public String desc(int i) {
String[] att = attributes();
String[] att = getAttributes();
if (att == null || att.length == 0) return "";
@@ -91,37 +93,18 @@ public abstract class CropCard {
}
/**
* *
* @param crop reference to ICropTile
* @return roots lengt use in isBlockBelow
* Crop roots length. Maximum roots length should be 5.
* @param cropTile reference to ICropTile
* @return roots length use in isBlockBelow
*/
public int getrootslength(ICropTile crop) {
public int getRootsLength(ICropTile cropTile) {
return 1;
}
/**
* Tier of the plant. Ranges from 1 to 16, 0 is Weed.
* Valuable and powerful crops have higher tiers, useless and weak ones have lower tiers.
*
* @return Tier
* Object containing the crop properties info - See ic2.api.crops.CropProperties for more info.
*/
public abstract int tier();
/**
* 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);
public abstract CropProperties getProperties();
/**
* Additional attributes of the plant, also influencing breeding.
@@ -129,21 +112,23 @@ public abstract class CropCard {
*
* @return Attributes as an array of strings
*/
public abstract String[] attributes();
public String[] getAttributes() {
return new String[] {};
}
/**
* Determine the max crop size.
*
* Currently only used for texture allocation.
*/
public abstract int maxSize();
public abstract int getMaxSize();
/**
* Amount of growth points needed to increase the plant's size.
* Default is 200 * tier.
*/
public int growthDuration(ICropTile crop) {
return tier() * 200;
public int getGrowthDuration(ICropTile cropTile) {
return getProperties().getTier() * 200;
}
/**
@@ -157,10 +142,12 @@ public abstract class CropCard {
*
* 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
* @param cropTile reference to ICropTile
* @return Whether the crop can grow
*/
public abstract boolean canGrow(ICropTile crop);
public boolean canGrow(ICropTile cropTile) {
return cropTile.getCurrentSize() < getMaxSize();
}
/**
* Calculate the influence for the plant to grow based on humidity, nutrients and air.
@@ -175,8 +162,8 @@ public abstract class CropCard {
* @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);
public int getWeightInfluences(ICropTile crop, int humidity, int nutrients, int air) {
return humidity + nutrients + air;
}
/**
@@ -186,7 +173,7 @@ public abstract class CropCard {
* @param crop crop to crossbreed with
*/
public boolean canCross(ICropTile crop) {
return crop.getSize() >= 3;
return crop.getCurrentSize() >= 3;
}
@@ -196,30 +183,34 @@ public abstract class CropCard {
*
* Only called Serverside.
*
* @param crop reference to ICropTile
* @param cropTile 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);
public boolean onRightClick(ICropTile cropTile, EntityPlayer player) {
return cropTile.performManualHarvest();
}
/**
* Use in Crop Havester with insert Cropnalyzer to get best Output.
* Use in Crop Harvester with insert Cropnalyzer to get best Output.
*
* @param crop reference to ICropTile
* @return need crop size for best output.
* @param cropTile reference to ICropTile
* @return need crop size for best output.
*/
public abstract int getOptimalHavestSize(ICropTile crop);
public int getOptimalHarvestSize(ICropTile cropTile) {
return getMaxSize();
}
/**
* Check whether the crop can be harvested.
*
* @param crop reference to ICropTile
* @param cropTile reference to ICropTile
* @return Whether the crop can be harvested in its current state.
*/
public abstract boolean canBeHarvested(ICropTile crop);
public boolean canBeHarvested(ICropTile cropTile) {
return cropTile.getCurrentSize() == getMaxSize();
}
/**
* Base chance for dropping the plant's gains, specify values greater than 1 for multiple drops.
@@ -227,10 +218,8 @@ public abstract class CropCard {
*
* @return Chance to drop the gains
*/
public float dropGainChance() {
float base = 1F;
for (int i = 0; i < tier(); i++) {base*=0.95;}
return base;
public double dropGainChance() {
return Math.pow(0.95, getProperties().getTier());
}
/**
@@ -245,24 +234,26 @@ public abstract class CropCard {
* Get the size of the plant after harvesting.
* Default is 1.
*
* @param crop reference to ICropTile
* @param cropTile reference to ICropTile
* @return Plant size after harvesting
*/
public byte getSizeAfterHarvest(ICropTile crop) {return 1;}
public int getSizeAfterHarvest(ICropTile cropTile) {
return 1;
}
/**
* Called when the plant is leftclicked by a player.
* Called when the plant is left clicked by a player.
* Default action is picking the plant.
*
* Only called Serverside.
* Only called server side.
*
* @param crop reference to ICropTile
* @param player player leftclicked the crop
* @param cropTile reference to ICropTile
* @param player player left clicked the crop
* @return Whether the plant has changed
*/
public boolean leftclick(ICropTile crop, EntityPlayer player) {
return crop.pick(true);
public boolean onLeftClick(ICropTile cropTile, EntityPlayer player) {
return cropTile.pick();
}
/**
@@ -273,10 +264,12 @@ public abstract class CropCard {
* @return Chance to drop the seeds
*/
public float dropSeedChance(ICropTile crop) {
if (crop.getSize() == 1) return 0;
if (crop.getCurrentSize() == 1) return 0;
float base = 0.5F;
if (crop.getSize() == 2) base/=2F;
for (int i = 0; i < tier(); i++) {base*=0.8;}
if (crop.getCurrentSize() == 2) base/=2F;
for (int i = 0; i < getProperties().getTier(); i++) {
base*=0.8;
}
return base;
}
@@ -289,7 +282,7 @@ public abstract class CropCard {
* @return Seeds
*/
public ItemStack getSeeds(ICropTile crop) {
return crop.generateSeeds(crop.getCrop(), crop.getGrowth(), crop.getGain(), crop.getResistance(), crop.getScanLevel());
return crop.generateSeeds(crop.getCrop(), crop.getStatGrowth(), crop.getStatGain(), crop.getStatResistance(), crop.getScanLevel());
}
/**
@@ -302,11 +295,22 @@ public abstract class CropCard {
}
/**
* Check if the crop should emit redstone.
* Check if the crop emits a redstone signal.
*
* @return Whether the crop should emit redstone
* @return Whether the crop emits a redstone signal.
*/
public int emitRedstone(ICropTile crop) {return 0;}
public boolean isRedstoneSignalEmitter(ICropTile cropTile) {
return false;
}
/***
* Get the emitted redstone signal strength.
*
* @return The redstone signal strength.
*/
public int getEmittedRedstoneSignal(ICropTile cropTile) {
return 0;
}
/**
* Called when the crop is destroyed.
@@ -335,11 +339,7 @@ public abstract class CropCard {
* @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;
return (entity instanceof EntityLivingBase && entity.isSprinting());
}
@@ -347,9 +347,9 @@ public abstract class CropCard {
* Called every time the crop ticks.
* Should be called every 256 ticks or around 13 seconds.
*
* @param crop reference to ICropTile
* @param cropTile reference to ICropTile
*/
public void tick(ICropTile crop) {
public void tick(ICropTile cropTile) {
// nothing by default
}
@@ -357,38 +357,36 @@ public abstract class CropCard {
* 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
* @param cropTile reference to ICropTile
* @return Whether the plant spreads weed
*/
public boolean isWeed(ICropTile crop) {
return crop.getSize() >= 2 &&
(crop == Crops.weed || crop.getGrowth() >= 24);
public boolean isWeed(ICropTile cropTile) {
return cropTile.getCurrentSize() >= 2 &&
(cropTile.getCrop() == Crops.weed || cropTile.getStatGrowth() >= 24);
}
/**
* Get this plant's ID.
*
* @return ID of this CropCard or -1 if it's not registered
* @deprecated IDs aren't used anymore.
* Retrieve the crop world.
* @param cropTile reference to ICropTile.
* @return The crop world object.
*/
@Deprecated
public final int getId() {
return Crops.instance.getIdFor(this);
public World getWorld(ICropTile cropTile) {
return cropTile.getWorld();
}
private static String getModId() {
ModContainer modContainer = Loader.instance().activeModContainer();
/**
* Retrieve the crop's unlocalized name.
* @return Unlocalized name
*/
public String getUnlocalizedName() {
return "crop." + getName() + ".name";
}
if (modContainer != null) {
return modContainer.getModId();
} else {
// this is bad if you are not actually IC2
assert false;
return "unknown";
public List<ResourceLocation> getModelLocation() {
List<ResourceLocation> ret = new ArrayList<ResourceLocation>();
for (int i = 1; i <= getMaxSize(); i++) {
ret.add(new ResourceLocation(getOwner().toLowerCase(Locale.ENGLISH), "blocks/crop/"+getName()+"_"+i));
}
return ret;
}
private final String modId; // TODO: make owner abstract, remove modId auto detection
}
Binary file not shown.
@@ -0,0 +1,78 @@
package ic2.api.crops;
/**
* Describe the plant through a set of properties, influencing breeding.
* Plants sharing properties and attributes will tend to cross-breed more often.
*
* Properties:
* - Tier (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.)
* - Chemistry (Industrial uses based on chemical plant components)
* - Consumable (Food, potion ingredients, stuff meant to be eaten or similarly used)
* - Defensive (Plants with defense capabilities (damaging, explosive, chemical) or special abilities in general)
* - Colorful (How colorful/aesthetically/beautiful is the plant, like dye-plants or plants without actual effects)
* - Weed (Is this plant weed-like and rather unwanted/quick-spreading? Rare super-breed plants should have low values here)
*
* @author IC2 Team
*/
public class CropProperties {
/**
* Create a CropProperties object.
*
* @param tier Tier property value
* @param chemistry Chemistry property value
* @param consumable Consumable property value
* @param defensive Defensive property value
* @param colorful Colorful property value
* @param weed Weed property value
*/
public CropProperties(int tier, int chemistry, int consumable, int defensive,
int colorful, int weed) {
this.tier = tier;
this.chemistry = chemistry;
this.consumable = consumable;
this.defensive = defensive;
this.colorful = colorful;
this.weed = weed;
}
public int getTier() {
return this.tier;
}
public int getChemistry() {
return this.chemistry;
}
public int getConsumable() {
return this.consumable;
}
public int getDefensive() {
return this.defensive;
}
public int getColorful() {
return this.colorful;
}
public int getWeed() {
return this.weed;
}
public int[] getAllProperties() {
return new int[] { this.getChemistry(), this.getConsumable(), this.getDefensive(),
this.getColorful(), this.getWeed() };
}
/**
* Fields
*/
private final int tier;
private final int chemistry;
private final int consumable;
private final int defensive;
private final int colorful;
private final int weed;
}
Binary file not shown.
+7 -32
View File
@@ -4,6 +4,7 @@ import java.util.Collection;
import net.minecraft.item.ItemStack;
import net.minecraft.world.biome.Biome;
import net.minecraftforge.common.BiomeDictionary.Type;
/**
@@ -75,42 +76,18 @@ public abstract class Crops {
*/
public abstract Collection<CropCard> getCrops();
/**
* Returns the list of registered crops.
*
* @return Registered crops by ID
*/
@Deprecated
public abstract CropCard[] getCropList();
/**
* 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);
public abstract void registerCrop(CropCard crop);
/**
* Registers a base seed, an item used to plant a crop.
*
* @param stack item
* @param id plant ID
* @param crop crop
* @param size initial size
* @param growth initial growth stat
* @param gain initial gain stat
@@ -127,12 +104,10 @@ public abstract class Crops {
public abstract BaseSeed getBaseSeed(ItemStack stack);
/**
* Returns the ID for the given crop.
* Execute registerSprites for all registered crop cards.
*
* @param crop Crop to look up
* @return ID, or -1 if not found
* @deprecated IDs aren't used anymore.
* This method will get called by IC2, don't call it yourself.
*/
@Deprecated
public abstract int getIdFor(CropCard crop);
//@SideOnly(Side.CLIENT)
//public abstract void startSpriteRegistration(IIconRegister iconRegister);
}
Binary file not shown.
+81
View File
@@ -0,0 +1,81 @@
package ic2.api.crops;
import net.minecraft.item.ItemStack;
/**
* Interface implemented by ItemCropSeed.
* @author estebes
*/
public interface ICropSeed {
/**
* Get the seed's crop.
* @param itemStack The seed's itemstack.
* @return Seed's crop.
*/
public CropCard getCropFromStack(ItemStack itemStack);
/**
* Set the seed's crop.
* @param itemStack The seed's itemstack.
* @param crop New CropCard object.
*/
public void setCropFromStack(ItemStack itemStack, CropCard crop);
/**
* Get the seed's growth.
* @param itemStack The seed's itemstack.
* @return Seed's growth.
*/
public int getGrowthFromStack(ItemStack itemStack);
/**
* Set the seed's growth.
* @param itemStack The seed's itemstack.
* @param value New growth value.
*/
public void setGrowthFromStack(ItemStack itemStack, int value);
/**
* Get the seed's gain.
* @param itemStack The seed's itemstack.
* @return Seed's gain.
*/
public int getGainFromStack(ItemStack itemStack);
/**
* Set the seed's growth.
* @param itemStack The seed's itemstack.
* @param value New growth value.
*/
public void setGainFromStack(ItemStack itemStack, int value);
/**
* Get the seed's resistance.
* @param itemStack The seed's itemstack.
* @return Seed's resistance.
*/
public int getResistanceFromStack(ItemStack itemStack);
/**
* Set the seed's resistance.
* @param itemStack The seed's itemstack.
* @param value New resistance value.
*/
public void setResistanceFromStack(ItemStack itemStack, int value);
/**
* Get the seed's scan level.
* @param itemStack The seed's itemstack.
* @return Seed's scan level.
*/
public int getScannedFromStack(ItemStack itemStack);
/**
* Set the seed's scan level.
* @param itemStack The seed's itemstack.
* @param value New scan level value.
*/
public void setScannedFromStack(ItemStack itemStack, int value);
public void incrementScannedFromStack(ItemStack itemStack);
}
Binary file not shown.
+83 -86
View File
@@ -1,5 +1,7 @@
package ic2.api.crops;
import java.util.List;
import net.minecraft.block.Block;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
@@ -24,31 +26,19 @@ public interface ICropTile {
*/
public void setCrop(CropCard cropCard);
/**
* @deprecated IDs have been removed.
*/
@Deprecated
public short getID();
/**
* @deprecated IDs have been removed.
*/
@Deprecated
public void setID(short id);
/**
* Get the crop's plant size.
*
* @return Plant size, starting with 1 and maximum varies depending on plant
*/
public byte getSize();
public int getCurrentSize();
/**
* Set the crop's plant size.
*
* @param size Plant size
*/
public void setSize(byte size);
public void setCurrentSize(int size);
/**
* Get the crop's plant growth stat.
@@ -56,14 +46,14 @@ public interface ICropTile {
*
* @return Plant growth stat
*/
public byte getGrowth();
public int getStatGrowth();
/**
* Set the crop's plant growth stat.
*
* @param growth Plant growth stat
*/
public void setGrowth(byte growth);
public void setStatGrowth(int growth);
/**
* Get the crop's plant gain stat.
@@ -71,14 +61,14 @@ public interface ICropTile {
*
* @return Plant gain stat
*/
public byte getGain();
public int getStatGain();
/**
* Set the crop's plant gain stat.
*
* @param gain Plant gain stat
*/
public void setGain(byte gain);
public void setStatGain(int gain);
/**
* Get the crop's plant resistance stat.
@@ -86,14 +76,58 @@ public interface ICropTile {
*
* @return Plant resistance stat
*/
public byte getResistance();
public int getStatResistance();
/**
* Set the crop's plant resistance stat.
*
* @param resistance Plant resistance stat
*/
public void setResistance(byte resistance);
public void setStatResistance(int resistance);
/**
* Get the crop's nutrient storage.
* Ranges from 0 to 100.
*
* @return Crop nutrient storage
*/
public int getStorageNutrient();
/**
* Set the crop's nutrient storage.
*
* @param storageNutrient Crop nutrient storage
*/
public void setStorageNutrient(int storageNutrient);
/**
* 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 getStorageWater();
/**
* Set the crop's water storage.
*
* @param storageWater Crop water storage
*/
public void setStorageWater(int storageWater);
/**
* Get the crop's Weed-Ex storage.
*
* @return Crop Weed-Ex storage
*/
public int getStorageWeedEX();
/**
* Set the crop's Weed-Ex storage.
*
* @param storageWeedEX Crop Weed-Ex storage
*/
public void setStorageWeedEX(int storageWeedEX);
/**
* Get the crop's plant scan level.
@@ -101,14 +135,22 @@ public interface ICropTile {
*
* @return Plant scan level
*/
public byte getScanLevel();
public int getScanLevel();
/**
* Set the crop's plant scan level.
*
* @param scanLevel Plant scan level
*/
public void setScanLevel(byte scanLevel);
public void setScanLevel(int scanLevel);
public int getGrowthPoints();
public void setGrowthPoints(int growthPoints);
public boolean isCrossingBase();
public void setCrossingBase(boolean crossingBase);
/**
* Get the crop's plant custom data, stored alongside the crop.
@@ -118,50 +160,6 @@ public interface ICropTile {
*/
public NBTTagCompound getCustomData();
/**
* Get the crop's nutrient storage.
* Ranges from 0 to 100.
*
* @return Crop nutrient storage
*/
public int getNutrientStorage();
/**
* Set the crop's nutrient storage.
*
* @param nutrientStorage Crop nutrient storage
*/
public void setNutrientStorage(int nutrientStorage);
/**
* Get the crop's hydration storage.
* 0 indicates nothing, 1-10 indicate water hydration and 11-100 for hydration cells.
*
* @return Crop hydration storage
*/
public int getHydrationStorage();
/**
* Set the crop's hydration storage.
*
* @param hydrationStorage Crop hydration storage
*/
public void setHydrationStorage(int hydrationStorage);
/**
* Get the crop's Weed-Ex storage.
*
* @return Crop Weed-Ex storage
*/
public int getWeedExStorage();
/**
* Set the crop's Weed-Ex storage.
*
* @param weedExStorage Crop Weed-Ex storage
*/
public void setWeedExStorage(int weedExStorage);
/**
* Get the crop's humidity.
* Ranges from 0 (dry) to 10 (humid).
@@ -171,7 +169,7 @@ public interface ICropTile {
*
* @return Crop humidity level
*/
public byte getHumidity();
public int getHumidity();
/**
* Get the crop's nutrient level.
@@ -182,7 +180,7 @@ public interface ICropTile {
*
* @return Crop nutrient level
*/
public byte getNutrients();
public int getNutrients();
/**
* Get the crop's air quality.
@@ -193,7 +191,7 @@ public interface ICropTile {
*
* @return Crop air quality
*/
public byte getAirQuality();
public int getAirQuality();
/**
* Get the crop's world.
@@ -219,27 +217,23 @@ public interface ICropTile {
/**
* 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);
public boolean pick();
/**
* 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);
public boolean performManualHarvest();
/**
* 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
* @return List<ItemStack> of harvest output
*/
ItemStack[] harvest_automated(boolean Optimal);
public List<ItemStack> performHarvest();
/**
* Fully clears the crop without dropping anything.
@@ -253,28 +247,31 @@ public interface ICropTile {
/**
* Check if a block is under the farmland containing the crop.
* Searches up to 2 blocks below the farmland or an air space, whichever appears first.
* Searches up to 4 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);
/**
* Check if a block is under the farmland containing the crop.
* Searches up to 4 blocks below the farmland or an air space, whichever appears first.
*
* @param oreDictionaryName blocks to search
* @return Whether the blocks were found
*/
public boolean isBlockBelow(String oreDictionaryName);
/**
* 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 resistance 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);
public ItemStack generateSeeds(CropCard crop, int growth, int gain, int resistance, int scan);
}
Binary file not shown.
Binary file not shown.
+38 -48
View File
@@ -1,76 +1,66 @@
package ic2.api.energy;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import ic2.api.energy.tile.IEnergyTile;
/**
* Interface representing the methods provided by the global EnergyNet class.
*
*
* 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.
*
* 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
* Get the EnergyNet-registered tile for the specified position.
*
* The returned tile is always the main tile implementing IEnergySource/-Sink/-Conductor, which
* is also what was registered to the energy net.
*
* For multi-blocks (IMetaDelegate) the connectivity handling is being done by sub tiles that
* may or may not include the main tile. Sub tiles have to be queried separately through the
* getSubTile method.
*
* As a consequence of always returning the main tile, the supplied position may not match the
* returned tile's position.
*
* Connectivity checking -> IEnergyEmitter/IEnergyAcceptor -> getSubTile
* Logic like energy I/O -> IEnergySource/IEnergySink/IEnergyConductor -> getTile
*
* @param world World containing the tile
* @param pos position
* @return main tile for the specified position or null if none is registered
*/
TileEntity getTileEntity(World world, BlockPos pos);
IEnergyTile getTile(World world, BlockPos pos);
/**
* 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
* Get the sub tile at the specified position.
*
* See the description of {@link #getTile} about whether getTile or getSubTile is applicable.
*
* @param world World containing the tile
* @param pos position
* @return sub tile at the specified position or null if none is registered
*/
TileEntity getNeighbor(TileEntity te, EnumFacing dir);
IEnergyTile getSubTile(World world, BlockPos pos);
/**
* 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);
World getWorld(IEnergyTile tile);
/**
* 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);
BlockPos getPos(IEnergyTile tile);
/**
* Retrieve statistics for the tile entity specified.
*
*
* The statistics apply to the last simulated tick.
*
* @param te Tile entity to check.
*
* @param tile Tile entity to check.
* @return Statistics for the tile entity.
*/
NodeStats getNodeStats(TileEntity te);
NodeStats getNodeStats(IEnergyTile tile);
/**
* 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
*/
@@ -78,7 +68,7 @@ public interface IEnergyNet {
/**
* Determine minimum tier required to handle the specified power, e.g. tier 2 for 128 eu/t.
*
*
* @param power in eu/t
* @return tier
*/
@@ -1,23 +1,24 @@
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.EnergyNet;
import ic2.api.energy.tile.IEnergyTile;
/**
* Base class for energy net events, don't use it directly.
*
* See ic2/api/energy/usage.txt for an overall description of the energy net api.
*/
public class EnergyTileEvent extends WorldEvent {
public final IEnergyTile energyTile;
public EnergyTileEvent(IEnergyTile energyTile1) {
super(((TileEntity) energyTile1).getWorld());
public EnergyTileEvent(IEnergyTile tile) {
super(EnergyNet.instance.getWorld(tile));
if (getWorld() == null) throw new NullPointerException("world is null");
this.energyTile = energyTile1;
this.tile = tile;
}
public final IEnergyTile tile;
}
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,374 @@
package ic2.api.energy.prefab;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.ITickable;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.fml.common.FMLCommonHandler;
import ic2.api.energy.event.EnergyTileLoadEvent;
import ic2.api.energy.event.EnergyTileUnloadEvent;
import ic2.api.energy.tile.IEnergyEmitter;
import ic2.api.energy.tile.IEnergySink;
import ic2.api.info.Info;
import ic2.api.item.ElectricItem;
/**
* BasicSink is a simple adapter to provide an ic2 energy sink.
*
* 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.
*
* 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.
*
* 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.
*
* 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.
* - call useEnergy whenever appropriate. canUseEnergy determines if enough energy is available
* 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)
*
* 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 update() {
* ic2EnergySink.update(); // 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, ITickable {
// **********************************
// *** 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;
}
// in-world te forwards >>
/**
* Forward for the base TileEntity's update(), used for creating the energy net link.
* Either updateEntity or onLoaded have to be used.
*/
@Override
public void update() {
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 &&
!parent.getWorld().isRemote &&
Info.isIc2Available()) {
worldObj = parent.getWorld();
pos = parent.getPos();
MinecraftForge.EVENT_BUS.post(new EnergyTileLoadEvent(this));
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();
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));
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);
NBTTagCompound data = tag.getCompoundTag("IC2BasicSink");
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 NBTTagCompound writeToNBT(NBTTagCompound tag) {
try {
super.writeToNBT(tag);
} catch (RuntimeException e) {
// happens if this is a delegate, ignore
}
NBTTagCompound data = new NBTTagCompound();
data.setDouble("energy", energyStored);
tag.setTag("IC2BasicSink", data);
return tag;
}
// << 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;
}
/**
* 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;
}
/**
* 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;
}
/**
* 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;
}
/**
* 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;
}
/**
* 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;
if (limit > 0 && limit < amount) amount = limit;
amount = ElectricItem.manager.discharge(stack, amount, tier, limit > 0, true, false);
energyStored += amount;
return amount > 0;
}
// << methods for using this adapter
// backwards compatibility (ignore these) >>
@Deprecated
public void onupdate() {
update();
}
@Deprecated
public void onInvalidate() {
invalidate();
}
@Deprecated
public void onOnChunkUnload() {
onChunkUnload();
}
@Deprecated
public void onReadFromNbt(NBTTagCompound tag) {
readFromNBT(tag);
}
@Deprecated
public void onWriteToNbt(NBTTagCompound tag) {
writeToNBT(tag);
}
// << backwards compatibility
// ******************************
// *** Methods for use by ic2 ***
// ******************************
// energy net interface >>
@Override
public boolean acceptsEnergyFrom(IEnergyEmitter emitter, EnumFacing direction) {
return true;
}
@Override
public double getDemandedEnergy() {
return Math.max(0, capacity - energyStored);
}
@Override
public double injectEnergy(EnumFacing directionFrom, double amount, double voltage) {
energyStored += amount;
return 0;
}
@Override
public int getSinkTier() {
return tier;
}
// << energy net interface
public final TileEntity parent;
protected int capacity;
protected int tier;
protected double energyStored;
protected boolean addedToEnet;
}
Binary file not shown.
@@ -0,0 +1,376 @@
package ic2.api.energy.prefab;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.ITickable;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.fml.common.FMLCommonHandler;
import ic2.api.energy.EnergyNet;
import ic2.api.energy.event.EnergyTileLoadEvent;
import ic2.api.energy.event.EnergyTileUnloadEvent;
import ic2.api.energy.tile.IEnergyAcceptor;
import ic2.api.energy.tile.IEnergySource;
import ic2.api.info.Info;
import ic2.api.item.ElectricItem;
/**
* BasicSource is a simple adapter to provide an ic2 energy source.
*
* 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.
*
* 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.
*
* 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.
*
* 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.
* - call addEnergy whenever appropriate, using getFreeCapacity may determine if e.g. the generator
* 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)
*
* 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 update() {
* ic2EnergySource.update(); // 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, ITickable {
// **********************************
// *** 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);
this.parent = parent1;
this.capacity = capacity1 < power ? power : capacity1;
this.tier = tier1;
this.power = power;
}
// in-world te forwards >>
/**
* Forward for the base TileEntity's update(), used for creating the energy net link.
* Either updateEntity or onLoaded have to be used.
*/
@Override
public void update() {
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 &&
!parent.getWorld().isRemote &&
Info.isIc2Available()) {
worldObj = parent.getWorld();
pos = parent.getPos();
MinecraftForge.EVENT_BUS.post(new EnergyTileLoadEvent(this));
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();
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));
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);
NBTTagCompound data = tag.getCompoundTag("IC2BasicSource");
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 NBTTagCompound writeToNBT(NBTTagCompound tag) {
try {
super.writeToNBT(tag);
} catch (RuntimeException e) {
// happens if this is a delegate, ignore
}
NBTTagCompound data = new NBTTagCompound();
data.setDouble("energy", energyStored);
tag.setTag("IC2BasicSource", data);
return tag;
}
// << 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;
}
/**
* 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;
}
/**
* 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);
if (capacity < power) capacity = 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;
}
/**
* 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;
}
/**
* 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;
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;
double amount = ElectricItem.manager.charge(stack, energyStored, tier, false, false);
energyStored -= amount;
return amount > 0;
}
// << methods for using this adapter
// backwards compatibility (ignore these) >>
@Deprecated
public void onupdate() {
update();
}
@Deprecated
public void onInvalidate() {
invalidate();
}
@Deprecated
public void onOnChunkUnload() {
onChunkUnload();
}
@Deprecated
public void onReadFromNbt(NBTTagCompound tag) {
readFromNBT(tag);
}
@Deprecated
public void onWriteToNbt(NBTTagCompound tag) {
writeToNBT(tag);
}
// << backwards compatibility
// ******************************
// *** Methods for use by ic2 ***
// ******************************
// energy net interface >>
@Override
public boolean emitsEnergyTo(IEnergyAcceptor receiver, EnumFacing direction) {
return true;
}
@Override
public double getOfferedEnergy() {
return Math.min(energyStored, power);
}
@Override
public void drawEnergy(double amount) {
energyStored -= amount;
}
@Override
public int getSourceTier() {
return tier;
}
// << energy net interface
public final TileEntity parent;
protected double capacity;
protected int tier;
protected double power;
protected double energyStored;
protected boolean addedToEnet;
}
@@ -1,6 +1,5 @@
package ic2.api.energy.tile;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumFacing;
/**
@@ -8,19 +7,19 @@ import net.minecraft.util.EnumFacing;
*
* @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.
*
*
* 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
* @param side side the energy is being received from
*/
boolean acceptsEnergyFrom(TileEntity emitter, EnumFacing direction);
boolean acceptsEnergyFrom(IEnergyEmitter emitter, EnumFacing side);
}
@@ -1,6 +1,5 @@
package ic2.api.energy.tile;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumFacing;
/**
@@ -8,20 +7,20 @@ import net.minecraft.util.EnumFacing;
*
* @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.
*
*
* 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
* @param side side the energy is to be sent to
* @return Whether energy should be emitted
*/
boolean emitsEnergyTo(TileEntity receiver, EnumFacing direction);
boolean emitsEnergyTo(IEnergyAcceptor receiver, EnumFacing side);
}
Binary file not shown.
@@ -0,0 +1,25 @@
package ic2.api.energy.tile;
/**
* Implement with an {@link IEnergySink} tile entity to change the force of the explosion when overpowered.
*/
public interface IExplosionPowerOverride {
/**
* Checks if the electric tile should explode. If you return false here,
* the explosion will just not happen at all and the block will stay.
* This is NOT recommended.
* @return Whether the block should explode.
*
* @note It should not be dependent on the tier of the power injected, consider {@link IOverloadHandler} if necessary.
*/
boolean shouldExplode();
/**
* The explosion force when too much power is received.
* @param tier The tier of power, that was injected into the energy sink, that caused it to explode.
* @param defaultPower The default explosion power.
* @return The explosion power
*/
float getExplosionPower(int tier, float defaultPower);
}
Binary file not shown.
Binary file not shown.
@@ -2,35 +2,33 @@ package ic2.api.energy.tile;
import java.util.List;
import net.minecraft.tileentity.TileEntity;
/**
* Interface for grouping multi-block structures to a single energy net delegate.
*
*
* 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.
*
*
* 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.
*
*
* 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.
*
*
* 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.
*
* Get the sub-Tiles belonging to this Meta Tile.
*
* @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
* @note The parent tile implementing IMetaDelegate isn't automatically included.
*
* @return sub-Tile array
*/
List<TileEntity> getSubTiles();
List<IEnergyTile> getSubTiles();
}
@@ -0,0 +1,24 @@
package ic2.api.energy.tile;
/**
* Allows an {@link IEnergySource} to emit more than one EU packet per tick.
* Note: support for this will be dropped in a future version of IC2.
* @author Aroma1997
*/
public interface IMultiEnergySource extends IEnergySource
{
/**
* If you want your machine to emit more than one EU packets per tick return true here.
* @return if the machine in its current state can emit more than one EU packet per tick.
*/
public boolean sendMultipleEnergyPackets();
/**
* If {@link #sendMultipleEnergyPackets()} returned true, this will get called.
* The value returned by this method will determine the amount of EU packets, this machine can emit.
* @return the amount of EU packets, this machine can emit per tick.
*/
public int getMultipleEnergyPacketAmount();
}
@@ -0,0 +1,17 @@
package ic2.api.energy.tile;
/**
* Complete control for when an {@link IEnergySink} is overloaded.
*/
public interface IOverloadHandler {
/**
* Called when overloaded. This will override the default explosion.
* The default explosion will therefore NOT happen, when you return true here.
* If you return false, you can use this as a onExplode hook, but still let the default explosion happen.
* @note Would set the block to air and cause an explosion of power 2.5 by default
* @param tier The tier of power, that was injected into the energy sink, that caused it to explode.
* @return Whether you the default explosion should be cancelled.
*/
boolean onOverload(int tier);
}
Binary file not shown.
+1 -1
View File
@@ -38,7 +38,7 @@ loading the chunk which contains it or after the user placing the block.
The energy net implementation will use the event to add it to its energy grid map, taking it into
account for further energy transfers.
You can detect the loading by either using the 1st iteration of updateEntity() or by waiting for
You can detect the loading by either using the 1st iteration of update() or by waiting for
the next world tick after TileEntity.validate(). The 2nd approach is obviously more sophisticated
and requires to use some tick queuing mechanism.
Binary file not shown.
@@ -2,23 +2,23 @@ package ic2.api.event;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.World;
import net.minecraftforge.event.world.WorldEvent;
import net.minecraftforge.fml.common.eventhandler.Cancelable;
@Cancelable
public class ExplosionEvent extends WorldEvent {
public ExplosionEvent(World world, Entity entity,
double x, double y, double z,
Vec3d pos,
double power,
EntityLivingBase igniter,
int radiationRange, double rangeLimit) {
super(world);
this.entity = entity;
this.x = x;
this.y = y;
this.z = z;
this.pos = pos;;
this.power = power;
this.igniter = igniter;
this.radiationRange = radiationRange;
@@ -29,10 +29,8 @@ public class ExplosionEvent extends WorldEvent {
* Entity representing the explosive, may be null.
*/
public final Entity entity;
public double x;
public double y;
public double z;
public double power;
public final Vec3d pos;
public final double power;
/**
* Entity causing the explosion, may be null.
*/
Binary file not shown.
+44 -38
View File
@@ -3,7 +3,10 @@ package ic2.api.event;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraftforge.event.world.WorldEvent;
import net.minecraftforge.fml.common.eventhandler.Cancelable;
@@ -25,88 +28,91 @@ public class LaserEvent extends WorldEvent {
// 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 world, Entity lasershot, EntityLivingBase owner, float range, float power, int blockBreaks, boolean explosive, boolean smelt) {
super(world);
this.lasershot = lasershot;
this.owner = owner;
this.range = range;
this.power = power;
this.blockBreaks = blockBreaks;
this.explosive = explosive;
this.smelt = smelt;
}
/**
* 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;
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 world, Entity lasershot, EntityLivingBase owner, float range, float power, int blockBreaks, boolean explosive, boolean smelt, ItemStack laseritem) {
super(world, lasershot, owner, range, power, blockBreaks, explosive, smelt);
this.laserItem = laseritem;
}
}
/**
* 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 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 world, Entity lasershot, EntityLivingBase owner, float range, float power, int blockBreaks, boolean explosive, boolean smelt, float explosionpower1, float explosiondroprate1, float explosionentitydamage1) {
super(world, lasershot, owner, range, power, blockBreaks, explosive, smelt);
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.
*
*
* 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;
public BlockPos pos;
public EnumFacing 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 world, Entity lasershot, EntityLivingBase owner, float range, float power, int blockBreaks, boolean explosive1, boolean smelt1, BlockPos pos, EnumFacing side, float dropChance, boolean removeBlock, boolean dropBlock) {
super(world, lasershot, owner, range, power, blockBreaks, explosive1, smelt1);
this.pos = pos;
this.side = side;
this.removeBlock = removeBlock;
this.dropBlock = dropBlock;
this.dropChance = dropChance;
}
}
/**
* 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 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 world, Entity lasershot, EntityLivingBase owner, float range, float power, int blockBreaks, boolean explosive, boolean smelt, Entity hitentity) {
super(world, lasershot, owner, range, power, blockBreaks, explosive, smelt);
this.hitEntity = hitentity;
}
}
}
Binary file not shown.
@@ -1,30 +0,0 @@
package ic2.api.event;
import net.minecraft.world.World;
import net.minecraftforge.event.world.WorldEvent;
import net.minecraftforge.fml.common.eventhandler.Cancelable;
@Cancelable
public class PaintEvent extends WorldEvent {
// 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;
// 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);
this.x = x1;
this.y = y1;
this.z = z1;
this.side = side1;
this.color = color1;
}
}
Binary file not shown.
+39 -20
View File
@@ -1,35 +1,54 @@
package ic2.api.event;
import net.minecraft.block.Block;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraftforge.event.world.WorldEvent;
import net.minecraftforge.fml.common.eventhandler.Cancelable;
@Cancelable
public class RetextureEvent extends WorldEvent {
public RetextureEvent(World world, BlockPos pos, IBlockState state, EnumFacing side, EntityPlayer player,
IBlockState refState, String refVariant, EnumFacing refSide, int[] refColorMultipliers) {
super(world);
if (world == null) throw new NullPointerException("null world");
if (world.isRemote) throw new IllegalStateException("remote world");
if (pos == null) throw new NullPointerException("null pos");
if (state == null) throw new NullPointerException("null state");
if (side == null) throw new NullPointerException("null side");
if (refState == null) throw new NullPointerException("null refState");
if (refVariant == null) throw new NullPointerException("null refVariant");
if (refSide == null) throw new NullPointerException("null refSide");
if (refColorMultipliers == null) throw new NullPointerException("null refColorMultipliers");
this.pos = pos;
this.state = state;
this.side = side;
this.player = player;
this.refState = refState;
this.refVariant = refVariant;
this.refSide = refSide;
this.refColorMultipliers = refColorMultipliers;
}
// target block
public final int x;
public final int y;
public final int z;
public final int side;
public final BlockPos pos;
public final IBlockState state;
public final EnumFacing side;
// player causing the action, may be null
public final EntityPlayer player;
// referenced block (to grab the texture from)
public final Block referencedBlock;
public final int referencedMeta;
public final int referencedSide;
public final IBlockState refState;
public final String refVariant;
public final EnumFacing refSide;
public final int[] refColorMultipliers;
// 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);
this.x = x1;
this.y = y1;
this.z = z1;
this.side = side1;
this.referencedBlock = referencedBlock;
this.referencedMeta = referencedMeta1;
this.referencedSide = referencedSide1;
}
}
Binary file not shown.
Binary file not shown.
@@ -1,17 +0,0 @@
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.
*
* 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);
}
Binary file not shown.
@@ -1,15 +0,0 @@
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);
}
Binary file not shown.
@@ -0,0 +1,27 @@
package ic2.api.info;
import net.minecraft.item.ItemStack;
public interface IInfoProvider {
/**
* 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 stack ItemStack containing the item to evaluate.
* @return energy in EU
*/
double getEnergyValue(ItemStack stack);
/**
* Determine the fuel value for a single item in the supplied stack.
* The information currently applies to Generators and the Iron Furnace.
*
* @param stack 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 stack, boolean allowLava);
}
Binary file not shown.
+9 -2
View File
@@ -1,12 +1,13 @@
package ic2.api.info;
import net.minecraft.potion.Potion;
import net.minecraft.util.DamageSource;
import net.minecraftforge.fml.common.Loader;
import net.minecraftforge.fml.common.LoaderState;
public class Info {
public static IEnergyValueProvider itemEnergy;
public static IFuelValueProvider itemFuel;
public static IInfoProvider itemInfo;
public static Object ic2ModInstance;
/**
@@ -15,6 +16,12 @@ public class Info {
*/
public static DamageSource DMG_ELECTRIC, DMG_NUKE_EXPLOSION, DMG_RADIATION;
/**
* Potions used by IC2.
* Getting assigned in preload.
*/
public static Potion POTION_RADIATION;
public static boolean isIc2Available() {
if (ic2Available != null) return ic2Available;
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -1,6 +1,7 @@
package ic2.api.item;
import net.minecraft.item.ItemStack;
public interface IBlockCuttingBlade {
int gethardness();
int getHardness(ItemStack stack);
}
+3 -3
View File
@@ -6,9 +6,9 @@ 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
*
* @param stack item to be stored
* @return Whether to store the item in the toolbox or not
*/
public abstract boolean canBeStoredInToolbox(ItemStack itemstack);
public abstract boolean canBeStoredInToolbox(ItemStack stack);
}
Binary file not shown.
File diff suppressed because it is too large. Load diff
Binary file not shown.
+7 -20
View File
@@ -1,6 +1,5 @@
package ic2.api.item;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
/**
@@ -14,42 +13,30 @@ public interface IElectricItem {
*
* @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 of 0.
*
* @return Item ID to use
*/
Item getEmptyItem(ItemStack itemStack);
boolean canProvideEnergy(ItemStack stack);
/**
* Get the item's maximum charge energy in EU.
*
* @return Maximum charge energy
*/
double getMaxCharge(ItemStack itemStack);
double getMaxCharge(ItemStack stack);
/**
* 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.
*
* Batteries are Tier 1, Advanced Batteries are Tier 2, Energy Crystals are Tier 3, Lapotron
* Crystals are Tier 4.
*
* @return Item's tier
*/
int getTier(ItemStack itemStack);
int getTier(ItemStack stack);
/**
* Get the item's transfer limit in EU per transfer operation.
*
* @return Transfer limit
*/
double getTransferLimit(ItemStack itemStack);
double getTransferLimit(ItemStack stack);
}
Binary file not shown.
@@ -11,7 +11,18 @@ import net.minecraft.item.ItemStack;
* - 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
*
*
* Implementation hints:
* - operations require the tier to be at least as high as the item being manipulated
* - ignoreTransferLimit = true should allow the total charge to be transferred in one pass
* - externally = false should always allow discharging
* - all simulated operations should be deterministic and repeatable until a non-simulated
* operation happens or the item had a chance to be manipulated elsewhere.
* - usually getCharge(stack) mirrors
* discharge(stack, Double.POSITIVE_INFINITY, Integer.MAX_VALUE, true, false, true)
* - usually getMaxCharge(stack) mirrors
* getCharge(stack) + charge(stack, Double.POSITIVE_INFINITY, Integer.MAX_VALUE, true, true)
*
* @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
@@ -21,10 +32,10 @@ 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 stack electric item's stack
* @param amount max 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 ignoreTransferLimit ignore any transfer limits, infinite charge rate
* @param simulate don't actually change the item, just determine the return value
* @return Energy transferred into the electric item
*/
@@ -33,10 +44,14 @@ public interface IElectricItemManager {
/**
* Discharge an item by a specified amount of energy
*
* @param itemStack electric item's stack
* @param amount amount of energy to discharge in EU
* The externally parameter is used to prevent non-battery-like items from providing power. For
* example discharge slots set externally to true, but items using energy for themselves don't.
* Special cases like the nano saber hitting armor will discharge with externally = false.
*
* @param stack electric item's stack
* @param amount max 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 ignoreTransferLimit ignore any transfer limits, infinite discharge rate
* @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
@@ -45,18 +60,29 @@ public interface IElectricItemManager {
/**
* Determine the charge level for the specified item.
*
* @param itemStack ItemStack containing the electric item
*
* @param stack ItemStack containing the electric item
* @return charge level in EU
*/
double getCharge(ItemStack stack);
/**
* Determine the charge level for the specified item.
*
* The item may not actually be chargeable to the returned level, e.g. if it is a
* non-rechargeable single use battery.
*
* @param stack ItemStack containing the electric item
* @return maximum charge level in EU
*/
double getMaxCharge(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 stack electric item's stack
* @param amount minimum amount of energy required
* @return true if there's enough energy
*/
@@ -66,7 +92,7 @@ public interface IElectricItemManager {
* 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 stack 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
@@ -78,18 +104,23 @@ public interface IElectricItemManager {
* 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 stack 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
*
* @param stack ItemStack to determine the tooltip for
* @return tool tip string or null for none
*/
String getToolTip(ItemStack stack);
// TODO: add tier getter
/**
* Get the tier of the specified item.
* @param stack the item to get the tier from.
* @return The tier of the item.
*/
int getTier(ItemStack stack);
}
Binary file not shown.
+43
View File
@@ -0,0 +1,43 @@
package ic2.api.item;
import net.minecraft.block.Block;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
/**
* A simple interface for the ItemAPI.
* @author Aroma1997
*
*/
public interface IItemAPI {
/**
* Get an ItemStack for a specific item name.
*
* @param name
* item name
* @param variant
* the variant/subtype for the Item.
* @return The item or null if the item does not exist or an error occurred
*/
ItemStack getItemStack(String name, String variant);
/**
* Get a Block for a specific block name.
*
* @param name
* block name
* @return The Block or null if the block does not exist or an error occurred
*/
Block getBlock(String name);
/**
* Get an Item for a specific block name.
*
* @param name
* item name
* @return The Item or null if the block does not exist or an error occurred
*/
Item getItem(String name);
}
+3 -3
View File
@@ -7,10 +7,10 @@ import net.minecraft.item.ItemStack;
public interface IItemHudInfo {
/*
Add Info to Nano- and Quantum-Suit Helm Hud
for itemStack
for stack
@Override
public List<String> getHudInfo(ItemStack itemStack) {
public List<String> getHudInfo(ItemStack stack) {
List<String> info = new LinkedList<String>();
info.add("i am a Cool Item");
info.add("and have Cool info");
@@ -20,5 +20,5 @@ public interface IItemHudInfo {
*/
public List<String> getHudInfo(ItemStack itemStack);
public List<String> getHudInfo(ItemStack stack);
}
Binary file not shown.
@@ -3,7 +3,7 @@ package ic2.api.item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ResourceLocation;
public interface IKineticWindRotor {
public interface IKineticRotor {
int getDiameter(ItemStack stack);
ResourceLocation getRotorRenderTexture(ItemStack stack);
@@ -13,4 +13,11 @@ public interface IKineticWindRotor {
int getMinWindStrength(ItemStack stack);
int getMaxWindStrength(ItemStack stack);
boolean isAcceptedType(ItemStack stack, GearboxType type);
public static enum GearboxType {
WATER,
WIND,
}
}
Binary file not shown.
Binary file not shown.
-46
View File
@@ -1,46 +0,0 @@
package ic2.api.item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
public interface ILatheItem {
/**
* Returns the radius of this Lathe Item
* Should be no more than 15 to still be able to display it properly.
*/
int getWidth(ItemStack stack);
/**
* Returns the current state of this Lathe Item
* The length of the array should be 5
* The value should be the current size of the item at this time.
* It should also not be greater than getWidth()
*/
int[] getCurrentState(ItemStack stack);
/**
* This will set the current state of the Item on that position to that value.
*/
void setState(ItemStack stack, int position, int value);
/**
* Returns the output Item (normally dust) when you lathe on this position.
*/
ItemStack getOutputItem(ItemStack stack, int position);
/**
* How common it is if the above item will be put into the output slot.
* 1.0 means it will always be outputted, 0.0 means it will never be outputted.
*/
float getOutputChance(ItemStack stack, int position);
/**
* Returns the ResourceLocation of the texture used to display the item inside of the Lathe GUI
*/
@SideOnly(Side.CLIENT)
ResourceLocation getTexture(ItemStack stack);
}
Binary file not shown.
@@ -2,12 +2,12 @@ package ic2.api.item;
import net.minecraft.item.ItemStack;
public interface ISpecialElectricItem extends IElectricItem {
public interface ISpecialElectricItem {
/**
* Supply a custom IElectricItemManager.
*
* @param itemStack ItemStack to get the manager for
*
* @param stack ItemStack to get the manager for
* @return IElectricItemManager instance
*/
IElectricItemManager getManager(ItemStack itemStack);
IElectricItemManager getManager(ItemStack stack);
}
Binary file not shown.
+16 -8
View File
@@ -1,5 +1,8 @@
package ic2.api.item;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
/**
@@ -8,27 +11,32 @@ import net.minecraft.world.World;
public interface ITerraformingBP {
/**
* Get the energy consumption per operation of the blueprint.
*
* @param stack TODO
*
* @return Energy consumption in EU
*/
public abstract int getConsume();
double getConsume(ItemStack stack);
/**
* Get the maximum range of the blueprint.
* Should be a divisor of 5.
*
* @param stack TODO
*
* @return Maximum range in blocks
*/
public abstract int getRange();
int getRange(ItemStack stack);
boolean canInsert(ItemStack stack, EntityPlayer player, World world, BlockPos pos);
/**
* Perform the terraforming operation.
*
* @param stack TODO
* @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);
boolean terraform(ItemStack stack, World world, BlockPos pos);
}
Binary file not shown.
+3 -3
View File
@@ -1,12 +1,12 @@
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.
*
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,10 @@
package ic2.api.network;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.FIELD)
public @interface ClientModifiable { }
@@ -4,13 +4,16 @@ import java.util.List;
/**
* Tile entities which want to synchronized specific fields between client and server have to implement this.
*
*
* 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.
*
*
* If a name contains =, the name will be split into the actual name and the value, avoiding a
* field read.
*
* @return Names of the synchronized fields
*/
List<String> getNetworkedFields();
@@ -10,7 +10,7 @@ public interface INetworkItemEventListener {
/**
* Called when a network event is received.
*
* @param itemStack item stack
* @param stack item stack
* @param player player containing the item
* @param event event ID
*/
Binary file not shown.
@@ -0,0 +1,28 @@
package ic2.api.network;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
/**
* This is just here for the API functions.
* Do not implement by yourself.
*
* @see NetworkHelper
*
* @author Aroma1997
*
*/
public interface INetworkManager {
void updateTileEntityField(TileEntity te, String field);
void initiateTileEntityEvent(TileEntity te, int event, boolean limitRange);
void initiateItemEvent(EntityPlayer player, ItemStack stack, int event, boolean limitRange);
void initiateClientTileEntityEvent(TileEntity te, int event);
void initiateClientItemEvent(ItemStack stack, int event);
}
Binary file not shown.
+35 -74
View File
@@ -1,11 +1,14 @@
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 net.minecraftforge.fml.common.FMLCommonHandler;
import net.minecraftforge.fml.common.Loader;
import net.minecraftforge.fml.common.ModContainer;
import net.minecraftforge.fml.relauncher.Side;
/**
* Provides methods to initiate events and synchronize tile entity fields in SMP.
*
@@ -40,7 +43,7 @@ public final class NetworkHelper {
* - ItemStack
* - NBTBase (includes NBTTagCompound)
* - Block, Item, Achievement, Potion, Enchantment
* - ChunkCoordinates, ChunkCoordIntPair
* - BlockPos, 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)
*
@@ -54,14 +57,7 @@ public final class NetworkHelper {
* @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);
}
getNetworkManager(FMLCommonHandler.instance().getEffectiveSide()).updateTileEntityField(te, field);
}
/**
@@ -76,14 +72,7 @@ public final class NetworkHelper {
* 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);
}
getNetworkManager(FMLCommonHandler.instance().getEffectiveSide()).initiateTileEntityEvent(te, event, limitRange);
}
/**
@@ -95,20 +84,13 @@ public final class NetworkHelper {
* INetworkItemEventListener.onNetworkEvent (if implemented by the item).
*
* @param player EntityPlayer holding the item
* @param itemStack ItemStack containing the item
* @param stack 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);
}
public static void initiateItemEvent(EntityPlayer player, ItemStack stack, int event, boolean limitRange) {
getNetworkManager(FMLCommonHandler.instance().getEffectiveSide()).initiateItemEvent(player, stack, event, limitRange);
}
@@ -123,14 +105,7 @@ public final class NetworkHelper {
* @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);
}
getNetworkManager(FMLCommonHandler.instance().getEffectiveSide()).initiateClientTileEntityEvent(te, event);
}
/**
@@ -140,55 +115,41 @@ public final class NetworkHelper {
*
* This method doesn't do anything if executed on the server.
*
* @param itemStack ItemStack containing the item
* @param stack 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);
}
public static void initiateClientItemEvent(ItemStack stack, int event) {
getNetworkManager(FMLCommonHandler.instance().getEffectiveSide()).initiateClientItemEvent(stack, event);
}
/**
* Get the base IC2 package name, used internally.
*
* @return IC2 package name, if unable to be determined defaults to ic2
* This will return the NetworkManager for the given side.
* @param side the side to get the NetworkManager for.
* @return The NetworkManager for the given side.
*/
private static String getPackage() {
Package pkg = NetworkHelper.class.getPackage();
if (pkg != null) {
String packageName = pkg.getName();
return packageName.substring(0, packageName.length() - ".api.network".length());
public static INetworkManager getNetworkManager(Side side) {
if (side.isClient()) {
return clientInstance;
}
else {
return serverInstance;
}
return "ic2";
}
private static INetworkManager serverInstance;
private static INetworkManager clientInstance;
/**
* Get the NetworkManager instance, used internally.
*
* @return NetworkManager instance
* Sets the internal INetworkManager instance.
* ONLY IC2 CAN DO THIS!!!!!!!
*/
private static Object getInstance() {
try {
return Class.forName(getPackage() + ".core.IC2").getDeclaredField("network").get(null);
} catch (Throwable e) {
throw new RuntimeException(e);
public static void setInstance(INetworkManager server, INetworkManager client) {
ModContainer mc = Loader.instance().activeModContainer();
if (mc == null || !"IC2".equals(mc.getModId())) {
throw new IllegalAccessError();
}
serverInstance = server;
clientInstance = client;
}
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;
}
Binary file not shown.
Binary file not shown.
Loaded 100 of 162 files, more files were not shown because too many files have changed in this diff. Show more