本文整理汇总了Java中net.minecraftforge.energy.IEnergyStorage.getEnergyStored方法的典型用法代码示例。如果您正苦于以下问题:Java IEnergyStorage.getEnergyStored方法的具体用法?Java IEnergyStorage.getEnergyStored怎么用?Java IEnergyStorage.getEnergyStored使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类net.minecraftforge.energy.IEnergyStorage
的用法示例。
在下文中一共展示了IEnergyStorage.getEnergyStored方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: update
import net.minecraftforge.energy.IEnergyStorage; //导入方法依赖的package包/类
@Override
public void update() {
super.updateBase();
if(!world.isRemote){
if(this.energy.getEnergyStored() > 0){
IEnergyStorage itemEnergy = this.getItemEnergy();
if(itemEnergy != null && itemEnergy.getEnergyStored() < itemEnergy.getMaxEnergyStored()){
this.isWorking = true;
this.energy.extractEnergy(itemEnergy.receiveEnergy(this.energy.extractEnergy(this.energy.getExtractTransfer(), true), false), false);
} else {
this.isWorking = false;
this.syncToClients();
}
} else {
this.isWorking = false;
this.syncToClients();
}
}
}
示例2: chargeItem
import net.minecraftforge.energy.IEnergyStorage; //导入方法依赖的package包/类
@Override
public void chargeItem(ItemStack stack) {
if(!canChargeItem(stack))return;
IEnergyStorage cap = stack.getCapability(CapabilityEnergy.ENERGY, null);
if(cap == null)return;
int max = cap.getMaxEnergyStored();
int cur = cap.getEnergyStored();
int canUse = Math.min(energyStorage.getEnergyStored(), max - cur);
if(cur < max) {
int used = cap.receiveEnergy(canUse, true);
if(used > 0) {
if(energyStorage.extractEnergy(used, false) >=used){
cap.receiveEnergy(used, false);
}
}
}
}
示例3: hitEntity
import net.minecraftforge.energy.IEnergyStorage; //导入方法依赖的package包/类
@Override
public boolean hitEntity(ItemStack stack, EntityLivingBase target, EntityLivingBase attacker)
{
if(attacker instanceof EntityPlayer)
{
IEnergyStorage energyStorage = stack.getCapability(ENERGY_STORAGE_CAPABILITY, EnumFacing.DOWN);
if(energyStorage != null)
{
int energy = energyStorage.getEnergyStored();
if(energy <= 0)
{
target.attackEntityFrom(DamageSource.causePlayerDamage((EntityPlayer) attacker), 0.0F);
return true;
}
int quality = getQuality(stack);
int speed = getSpeed(stack);
int energyCost = ClockworkHelper.getTensionCostFromStats(ConfigValues.BASE_TENSION_COST_PER_ATTACK, quality, speed);
energyStorage.extractEnergy(energyCost, false);
}
}
return true;
}
示例4: addEnergyInformation
import net.minecraftforge.energy.IEnergyStorage; //导入方法依赖的package包/类
public static void addEnergyInformation(ItemStack stack, List<String> tooltip)
{
int currentEnergy = 0;
int maxEnergy = 0;
NBTTagCompound nbt = stack.getTagCompound();
if(nbt != null && nbt.hasKey("energy") && nbt.hasKey("energy_max"))
{
currentEnergy = nbt.getInteger("energy");
maxEnergy = nbt.getInteger("energy_max");
}
else
{
IEnergyStorage energyStorage = stack.getCapability(CapabilityEnergy.ENERGY, null);
if(energyStorage != null)
{
currentEnergy = energyStorage.getEnergyStored();
maxEnergy = energyStorage.getMaxEnergyStored();
}
}
String color = getColorFromTension(currentEnergy, maxEnergy);
tooltip.add("Energy: " + color + currentEnergy + " / " + maxEnergy + " " + Names.ENERGY_ACRONYM);
}
示例5: update
import net.minecraftforge.energy.IEnergyStorage; //导入方法依赖的package包/类
@Override
public void update(IUpgradableBlock chest, ItemStack stack) {
if (UpgradeHelper.INSTANCE.getFrequencyTick(chest, stack, 64) != 0) {
return;
}
IEnergyStorage storage = chest.getEnergyStorage();
if (storage.getEnergyStored() >= storage.getMaxEnergyStored()) {
return;
}
IBetterChest inv = (IBetterChest) chest;
IFilter filter = inv.getFilterFor(stack);
int slot = InvUtil.findInInvInternal(inv, null, test -> TileEntityFurnace.getItemBurnTime(test) > 0 && filter.matchesStack(test));
if (slot != -1) {
ItemStack current = inv.getStackInSlot(slot);
int provided = TileEntityFurnace.getItemBurnTime(current) * Config.INSTANCE.energyFueled;
if (storage.receiveEnergy(provided, true) == provided) {
storage.receiveEnergy(provided, false);
current.setCount(current.getCount() - 1);
inv.markDirty();
}
}
}
示例6: chargeItems
import net.minecraftforge.energy.IEnergyStorage; //导入方法依赖的package包/类
@Override
public boolean chargeItems(NonNullList<ItemStack> items) {
boolean chargedItem = false;
int available = Math.min(CapacitorKey.WIRELESS_POWER_OUTPUT.get(DefaultCapacitorData.BASIC_CAPACITOR), storedEnergyRF);
for (int i = 0, end = items.size(); i < end && available > 0; i++) {
ItemStack item = items.get(i);
if (!item.isEmpty()) {
IEnergyStorage chargable = PowerHandlerUtil.getCapability(item, null);
if (chargable != null && item.getCount() == 1) {
int max = chargable.getMaxEnergyStored();
int cur = chargable.getEnergyStored();
int canUse = Math.min(available, max - cur);
if (cur < max) {
int used = chargable.receiveEnergy(canUse, false);
if (used > 0) {
storedEnergyRF = storedEnergyRF - used;
chargedItem = true;
available -= used;
}
}
}
}
}
return chargedItem;
}
示例7: getValidPair
import net.minecraftforge.energy.IEnergyStorage; //导入方法依赖的package包/类
public static NNList<Triple<ItemStack, ItemStack, Integer>> getValidPair(List<ItemStack> validItems) {
NNList<Triple<ItemStack, ItemStack, Integer>> result = new NNList<>();
for (ItemStack stack : validItems) {
if (PowerHandlerUtil.getCapability(stack, null) != null) {
ItemStack copy = stack.copy();
IEnergyStorage emptyCap = PowerHandlerUtil.getCapability(copy, null);
if (emptyCap != null) {
int extracted = 1, maxloop = 200;
while (extracted > 0 && emptyCap.canExtract() && maxloop-- > 0) {
extracted = emptyCap.extractEnergy(Integer.MAX_VALUE, false);
}
if (emptyCap.canReceive() && emptyCap.getEnergyStored() < emptyCap.getMaxEnergyStored()) {
ItemStack empty = copy.copy();
int added = emptyCap.receiveEnergy(Integer.MAX_VALUE, false);
int power = added;
maxloop = 200;
while (added > 0 && maxloop-- > 0) {
power += added = emptyCap.receiveEnergy(Integer.MAX_VALUE, false);
}
result.add(Triple.of(empty, copy, power));
}
}
}
}
return result;
}
示例8: chargeItems
import net.minecraftforge.energy.IEnergyStorage; //导入方法依赖的package包/类
public boolean chargeItems(NNList<ItemStack> items) {
if (items == null) {
return false;
}
boolean chargedItem = false;
int available = getEnergyAvailableForTick(getMaxIO());
for (ItemStack item : items) {
if (item != null && Prep.isValid(item) && available > 0 && item.getCount() == 1) {
IEnergyStorage chargable = PowerHandlerUtil.getCapability(item);
if (chargable != null) {
int max = chargable.getMaxEnergyStored();
int cur = chargable.getEnergyStored();
if (cur < max) {
int canUse = Math.min(available, max - cur);
int used = chargable.receiveEnergy(canUse, false);
if (used > 0) {
addEnergy(-used);
chargedItem = true;
available -= used;
}
}
}
}
}
return chargedItem;
}
示例9: mapItemDynamicOverlayRender
import net.minecraftforge.energy.IEnergyStorage; //导入方法依赖的package包/类
@Override
@SideOnly(Side.CLIENT)
public ItemQuadCollector mapItemDynamicOverlayRender(@Nonnull Block block, @Nonnull ItemStack stack) {
IEnergyStorage energyItem = PowerHandlerUtil.getCapability(stack, null);
if (energyItem != null) {
int maxEnergy = energyItem.getMaxEnergyStored();
if (maxEnergy > 0) {
int energy = energyItem.getEnergyStored();
FillGaugeBakery gauge = new FillGaugeBakery(BlockCapBank.getGaugeIcon(), (double) energy / maxEnergy);
if (gauge.canRender()) {
ItemQuadCollector result = new ItemQuadCollector();
List<BakedQuad> quads = new ArrayList<BakedQuad>();
gauge.bake(quads);
result.addQuads(null, quads);
return result;
}
}
}
return null;
}
示例10: render
import net.minecraftforge.energy.IEnergyStorage; //导入方法依赖的package包/类
public boolean render(@Nonnull ItemStack stack, int xPosition, int yPosition, boolean alwaysShow) {
IEnergyStorage energyItem = PowerHandlerUtil.getCapability(stack, null);
if (energyItem != null) {
int maxEnergy = energyItem.getMaxEnergyStored();
if (maxEnergy > 0) {
int energy = energyItem.getEnergyStored();
if (alwaysShow || shouldShowBar(maxEnergy, energy)) {
double level = (double) energy / (double) maxEnergy;
boolean up = stack.getItem().showDurabilityBar(stack);
boolean top = stack.getCount() != 1;
render(level, xPosition, yPosition, top ? 12 : up ? 2 : 0, true);
return true;
}
}
}
if (HIDE_VANILLA_RENDERBUG && stack.getItem().showDurabilityBar(stack)) {
overpaintVanillaRenderBug(xPosition, yPosition);
}
return false;
}
示例11: doesItemPassFilter
import net.minecraftforge.energy.IEnergyStorage; //导入方法依赖的package包/类
@Override
public boolean doesItemPassFilter(@Nullable INetworkedInventory inv, @Nonnull ItemStack item) {
IEnergyStorage chargable = PowerHandlerUtil.getCapability(item, null);
if (chargable != null) {
int max = chargable.getMaxEnergyStored();
int cur = chargable.getEnergyStored();
int ref = (int) ((long) max * level / MAX_LEVEL);
switch (mode) {
case LESS:
return cur < ref;
case LESS_EQUAL:
return cur <= ref;
case EQUAL:
return cur == ref;
case MORE_EQUAL:
return cur >= ref;
case MORE:
return cur > ref;
default:
return false;
}
}
return false;
}
示例12: doInteract
import net.minecraftforge.energy.IEnergyStorage; //导入方法依赖的package包/类
@Override
public boolean doInteract(BlockPos pos, IDrone drone, IBlockInteractHandler interactHandler, boolean simulate) {
if (!drone.hasCapability(CapabilityEnergy.ENERGY, null)) return false;
IEnergyStorage droneStorage = drone.getCapability(CapabilityEnergy.ENERGY, null);
if (droneStorage.getEnergyStored() == droneStorage.getMaxEnergyStored()) {
interactHandler.abort();
return false;
} else {
TileEntity te = drone.world().getTileEntity(pos);
if (te == null) return false;
for (EnumFacing face : EnumFacing.values()) {
if (te.hasCapability(CapabilityEnergy.ENERGY, face)) {
IEnergyStorage teStorage = te.getCapability(CapabilityEnergy.ENERGY, face);
int transferredEnergy = droneStorage.receiveEnergy(
teStorage.extractEnergy(interactHandler.useCount() ? interactHandler.getRemainingCount() : Integer.MAX_VALUE, true), true);
if (transferredEnergy > 0) {
if (!simulate) {
interactHandler.decreaseCount(transferredEnergy);
droneStorage.receiveEnergy(transferredEnergy, false);
teStorage.extractEnergy(transferredEnergy, false);
}
return true;
}
}
}
}
return false;
}
示例13: doInteract
import net.minecraftforge.energy.IEnergyStorage; //导入方法依赖的package包/类
@Override
public boolean doInteract(BlockPos pos, IDrone drone, IBlockInteractHandler interactHandler, boolean simulate) {
if (!drone.hasCapability(CapabilityEnergy.ENERGY, null)) return false;
IEnergyStorage droneStorage = drone.getCapability(CapabilityEnergy.ENERGY, null);
if (droneStorage.getEnergyStored() == 0) {
interactHandler.abort();
return false;
} else {
TileEntity te = drone.world().getTileEntity(pos);
if (te == null) return false;
for (EnumFacing face : EnumFacing.values()) {
if (te.hasCapability(CapabilityEnergy.ENERGY, face)) {
IEnergyStorage teStorage = te.getCapability(CapabilityEnergy.ENERGY, face);
int transferredEnergy = droneStorage.extractEnergy(
teStorage.receiveEnergy(interactHandler.useCount() ? interactHandler.getRemainingCount() : Integer.MAX_VALUE, true), true);
if (transferredEnergy > 0) {
if (!simulate) {
interactHandler.decreaseCount(transferredEnergy);
droneStorage.extractEnergy(transferredEnergy, false);
teStorage.receiveEnergy(transferredEnergy, false);
}
return true;
}
}
}
}
return false;
}
示例14: getDurabilityForDisplay
import net.minecraftforge.energy.IEnergyStorage; //导入方法依赖的package包/类
@Override
public double getDurabilityForDisplay(ItemStack stack) {
if (stack.hasCapability(CapabilityEnergy.ENERGY, null)) {
IEnergyStorage storage = stack.getCapability(CapabilityEnergy.ENERGY, null);
if (storage != null)
return (storage.getMaxEnergyStored() - storage.getEnergyStored()) / (double) storage.getMaxEnergyStored();
}
return 0;
}
示例15: getChargingState
import net.minecraftforge.energy.IEnergyStorage; //导入方法依赖的package包/类
public int getChargingState(){
IEnergyStorage storage = getItemEnergy();
if(storage != null && storage.getMaxEnergyStored() > 0){
return (int) (storage.getEnergyStored() / (storage.getMaxEnergyStored() * 1.0F) * 10.0F);
}
return 0;
}