2013-05-07 22:12:07 +02:00
|
|
|
package ic2.api.item;
|
2013-04-13 16:35:13 +02:00
|
|
|
|
|
|
|
import net.minecraft.entity.player.EntityPlayer;
|
|
|
|
import net.minecraft.item.ItemStack;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Allows for charging, discharging and using electric items (IElectricItem).
|
|
|
|
*
|
|
|
|
* The charge or remaining capacity of an item can be determined by calling charge/discharge with
|
|
|
|
* ignoreTransferLimit and simulate set to true.
|
|
|
|
*/
|
|
|
|
public final class ElectricItem {
|
2013-05-28 06:29:29 +02:00
|
|
|
/**
|
|
|
|
* 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;
|
|
|
|
|
2013-04-13 16:35:13 +02:00
|
|
|
/**
|
|
|
|
* 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
|
2013-05-28 06:29:29 +02:00
|
|
|
*
|
|
|
|
* @deprecated use manager.charge() instead
|
2013-04-13 16:35:13 +02:00
|
|
|
*/
|
2013-05-28 06:29:29 +02:00
|
|
|
@Deprecated
|
2013-04-13 16:35:13 +02:00
|
|
|
public static int charge(ItemStack itemStack, int amount, int tier, boolean ignoreTransferLimit, boolean simulate) {
|
2013-05-28 06:29:29 +02:00
|
|
|
return manager.charge(itemStack, amount, tier, ignoreTransferLimit, simulate);
|
2013-04-13 16:35:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Discharge an item by 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 discharging device, has to be at least as high as the item to discharge
|
|
|
|
* @param ignoreTransferLimit ignore the transfer limit specified by getTransferLimit()
|
|
|
|
* @param simulate don't actually discharge the item, just determine the return value
|
|
|
|
* @return Energy retrieved from the electric item
|
2013-05-28 06:29:29 +02:00
|
|
|
*
|
|
|
|
* @deprecated use manager.discharge() instead
|
2013-04-13 16:35:13 +02:00
|
|
|
*/
|
2013-05-28 06:29:29 +02:00
|
|
|
@Deprecated
|
2013-04-13 16:35:13 +02:00
|
|
|
public static int discharge(ItemStack itemStack, int amount, int tier, boolean ignoreTransferLimit, boolean simulate) {
|
2013-05-28 06:29:29 +02:00
|
|
|
return manager.discharge(itemStack, amount, tier, ignoreTransferLimit, simulate);
|
2013-04-13 16:35:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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
|
2013-05-28 06:29:29 +02:00
|
|
|
*
|
|
|
|
* @deprecated use manager.canUse() instead
|
2013-04-13 16:35:13 +02:00
|
|
|
*/
|
2013-05-28 06:29:29 +02:00
|
|
|
@Deprecated
|
2013-04-13 16:35:13 +02:00
|
|
|
public static boolean canUse(ItemStack itemStack, int amount) {
|
2013-05-28 06:29:29 +02:00
|
|
|
return manager.canUse(itemStack, amount);
|
2013-04-13 16:35:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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 player player holding the item
|
|
|
|
* @return true if the operation succeeded
|
2013-05-28 06:29:29 +02:00
|
|
|
*
|
|
|
|
* @deprecated use manager.use() instead
|
2013-04-13 16:35:13 +02:00
|
|
|
*/
|
2013-05-28 06:29:29 +02:00
|
|
|
@Deprecated
|
2013-04-13 16:35:13 +02:00
|
|
|
public static boolean use(ItemStack itemStack, int amount, EntityPlayer player) {
|
2013-05-28 06:29:29 +02:00
|
|
|
return manager.use(itemStack, amount, player);
|
2013-04-13 16:35:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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 player player holding the item
|
2013-05-28 06:29:29 +02:00
|
|
|
*
|
|
|
|
* @deprecated use manager.chargeFromArmor() instead
|
2013-04-13 16:35:13 +02:00
|
|
|
*/
|
2013-05-28 06:29:29 +02:00
|
|
|
@Deprecated
|
2013-04-13 16:35:13 +02:00
|
|
|
public static void chargeFromArmor(ItemStack itemStack, EntityPlayer player) {
|
2013-05-28 06:29:29 +02:00
|
|
|
manager.chargeFromArmor(itemStack, player);
|
2013-04-13 16:35:13 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|