本文整理汇总了Java中net.minecraftforge.energy.IEnergyStorage.extractEnergy方法的典型用法代码示例。如果您正苦于以下问题:Java IEnergyStorage.extractEnergy方法的具体用法?Java IEnergyStorage.extractEnergy怎么用?Java IEnergyStorage.extractEnergy使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类net.minecraftforge.energy.IEnergyStorage
的用法示例。
在下文中一共展示了IEnergyStorage.extractEnergy方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: protectedUpdate
import net.minecraftforge.energy.IEnergyStorage; //导入方法依赖的package包/类
@Override
public void protectedUpdate() {
super.protectedUpdate();
if (hasAddon(EnergyFieldAddon.class)) {
ItemStack addon = getAddonStack(EnergyFieldAddon.class);
if (addon.hasCapability(CapabilityEnergy.ENERGY, null)) {
IEnergyStorage storage = addon.getCapability(CapabilityEnergy.ENERGY, null);
storage.extractEnergy((int) this.getEnergyStorage().givePower(storage.extractEnergy(512, true)), false);
BlockPos pos = ItemRegistry.energyFieldAddon.getLinkedBlockPos(addon);
if (this.world.getBlockState(pos).getBlock() instanceof EnergyFieldProviderBlock && this.world.isAreaLoaded(pos, pos)) {
EnergyFieldProviderTile tile = (EnergyFieldProviderTile) this.world.getTileEntity(pos);
if (tile.getWorkingArea().grow(1).contains(new Vec3d(this.pos.getX(), this.pos.getY(), this.pos.getZ()))) {
float pull = tile.consumeWorkEnergy(Math.min(storage.getMaxEnergyStored() - storage.getEnergyStored(), 1000));
storage.receiveEnergy((int) pull, false);
}
}
this.forceSync();
}
}
}
示例2: updateIncomingEnergy
import net.minecraftforge.energy.IEnergyStorage; //导入方法依赖的package包/类
/**
* look for connected energy-compatble blocks and try to drain
*
* Basically all of this function was written by @Ellpeck and then I tweaked it to fit my needs
* https://github.com/Ellpeck/ActuallyAdditions/blob/9bed6f7ea59e8aa23fa3ba540d92cd61a04dfb2f/src/main/java/de/ellpeck/actuallyadditions/mod/util/WorldUtil.java#L151
*/
private void updateIncomingEnergy() {
TileEntity teConnected;
//check every side to see if I'm connected
for (EnumFacing side : EnumFacing.values()) {
//it would output energy on the opposite side
EnumFacing sideOpp = side.getOpposite();
teConnected = world.getTileEntity(pos.offset(side));
if (teConnected != null &&
teConnected.hasCapability(CapabilityEnergy.ENERGY, sideOpp)) {
//pull energy to myself, from the next one over if it has energy
IEnergyStorage handlerTo = this.getCapability(CapabilityEnergy.ENERGY, side);
IEnergyStorage handlerFrom = teConnected.getCapability(CapabilityEnergy.ENERGY, sideOpp);
if (handlerFrom != null && handlerTo != null) {
//true means simulate the extract. then if it worked go for real
int drain = handlerFrom.extractEnergy(EnergyStore.MAX_INPUT, true);
if (drain > 0) {
int filled = handlerTo.receiveEnergy(drain, false);
handlerFrom.extractEnergy(filled, false);
return;// stop now because only pull from one side at a time
}
}
}
}
}
示例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: 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;
}
示例5: 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;
}
示例6: 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;
}
示例7: pushEnergy
import net.minecraftforge.energy.IEnergyStorage; //导入方法依赖的package包/类
public static int pushEnergy(World world, BlockPos pos, IEnergyStorage energy, EnumFacing... sides){
if(!world.isRemote && energy.canExtract()){
for(EnumFacing side : sides){
TileEntity tile = world.getTileEntity(pos.offset(side));
if(tile != null && tile.hasCapability(CapabilityEnergy.ENERGY, side.getOpposite())){
IEnergyStorage storage = tile.getCapability(CapabilityEnergy.ENERGY, side.getOpposite());
if(storage != null && storage.canReceive()){
return energy.extractEnergy(storage.receiveEnergy(energy.extractEnergy(Integer.MAX_VALUE, true), false), false);
}
}
}
}
return 0;
}
示例8: drainEnergy
import net.minecraftforge.energy.IEnergyStorage; //导入方法依赖的package包/类
private void drainEnergy(int energy) {
if (RSAddons.INSTANCE.config.wirelessCraftingGridUsesEnergy && stack.getItemDamage() != ItemWirelessCraftingGrid.TYPE_CREATIVE) {
IEnergyStorage energyStorage = stack.getCapability(CapabilityEnergy.ENERGY, null);
energyStorage.extractEnergy(energy, false);
if (energyStorage.getEnergyStored() <= 0) {
handler.onClose(getPlayer());
getPlayer().closeScreen();
}
}
}
示例9: importFuel
import net.minecraftforge.energy.IEnergyStorage; //导入方法依赖的package包/类
protected void importFuel() {
ItemStack itemstack = this.getStackInSlot(this.fuelSlot);
//pull in item from fuel slot, if it has fuel burn time
int fuelFromStack = FUEL_FACTOR * TileEntityFurnace.getItemBurnTime(itemstack);
if (fuelFromStack > 0 && this.energyStorage.emptyCapacity() >= fuelFromStack
&& world.isRemote == false) {
int newEnergy = Math.min(this.getFuelMax(), this.getFuelCurrent() + fuelFromStack);
this.energyStorage.setEnergyStored(newEnergy);
if (itemstack.getItem() instanceof ItemBucket && itemstack.getCount() == 1) {
this.setInventorySlotContents(this.fuelSlot, new ItemStack(Items.BUCKET));
}
else {
itemstack.shrink(1);
}
}
//what if item in fuel slot is an RF battery type item? start draining it ya
if (itemstack.hasCapability(CapabilityEnergy.ENERGY, null)) {
IEnergyStorage storage = itemstack.getCapability(CapabilityEnergy.ENERGY, null);
if (storage != null && storage.getEnergyStored() > 0) {
int canWithdraw = Math.min(EnergyStore.MAX_INPUT, storage.getEnergyStored());
if (canWithdraw > 0 && this.getFuelCurrent() + canWithdraw <= this.getFuelMax()) {
storage.extractEnergy(canWithdraw, false);
this.setFuelCurrent(this.getFuelCurrent() + canWithdraw);
}
}
}
}
示例10: damageTool
import net.minecraftforge.energy.IEnergyStorage; //导入方法依赖的package包/类
private void damageTool() {
ItemStack equip = this.getStackInSlot(toolSlot);
if (equip.isEmpty()) {
return;
}
if (equip.hasCapability(CapabilityEnergy.ENERGY, null)) {
IEnergyStorage storage = equip.getCapability(CapabilityEnergy.ENERGY, null);
if (storage != null) {
storage.extractEnergy(ENERGY_PER_FISH, false);
if (storage.getEnergyStored() <= 0) {
this.sendOutputItem(equip);
this.setInventorySlotContents(toolSlot, ItemStack.EMPTY);
}
return;
}
}
equip.attemptDamageItem(1, getWorld().rand, null);//does respect unbreaking
//IF enchanted and IF about to break, then spit it out
int damageRem = equip.getMaxDamage() - equip.getItemDamage();
if (damageRem == 1 && EnchantmentHelper.getEnchantments(equip).size() > 0) {
sendOutputItem(equip);
this.setInventorySlotContents(toolSlot, ItemStack.EMPTY);
} //otherwise we also make sure if its fullly damanged
if (equip.getItemDamage() >= equip.getMaxDamage()) {
this.setInventorySlotContents(toolSlot, ItemStack.EMPTY);
}
}
示例11: onBlockDestroyed
import net.minecraftforge.energy.IEnergyStorage; //导入方法依赖的package包/类
@Override
public boolean onBlockDestroyed(ItemStack is, World world, IBlockState state, BlockPos pos, EntityLivingBase playerIn)
{
if(!world.isRemote)
{
if(state.getBlockHardness(world, pos) <= 0)
return true;
if(!isEffective(state))
return true;
IEnergyStorage energyStorage = is.getCapability(ENERGY_STORAGE_CAPABILITY, EnumFacing.DOWN);
if(energyStorage == null)
return true;
int currentEnergy = energyStorage.getEnergyStored();
if(currentEnergy <= 0)
return true;
int quality = getQuality(is);
int speed = getSpeed(is);
int tensionCost = ClockworkHelper.getTensionCostFromStats(ConfigValues.BASE_TENSION_COST_PER_BLOCK_BREAK, quality, speed);
energyStorage.extractEnergy(tensionCost, false);
}
return true;
}
示例12: extractEnergy
import net.minecraftforge.energy.IEnergyStorage; //导入方法依赖的package包/类
@Override
public int extractEnergy(int maxExtract, boolean simulate)
{
int remaining = maxExtract;
for (IEnergyStorage st : buffers)
{
if (st.canExtract())
remaining = st.extractEnergy(remaining, simulate);
}
return remaining;
}
示例13: diffuse
import net.minecraftforge.energy.IEnergyStorage; //导入方法依赖的package包/类
public static void diffuse(World world, BlockPos pos, IEnergyStorage host) {
ArrayList<IEnergyStorage> consumers = getAdjacentStorage(world, pos);
reorder(consumers); //We want to sample them in random order
for(IEnergyStorage consumer : consumers) {
//int totalEnergy = host.getEnergyStored() + consumer.getEnergyStored();
//float energyRatio = host.getMaxEnergyStored() / (float)consumer.getMaxEnergyStored();
float sourceLevel = host.getEnergyStored()/(float)host.getMaxEnergyStored();
float destLevel = consumer.getEnergyStored()/(float)consumer.getMaxEnergyStored();
if (sourceLevel>destLevel) {
//Figure out how many quanta to transfer
//int desiredSource = (int)(totalEnergy*energyRatio);
//int desiredDest = (int)(totalEnergy/energyRatio);
/*
* Example: 2200 source, 1700 dest, capacity for each is 4000.
*
* totalEnergy: 3900
* energyRatio: 1.0f
* sourceLevel: 0.55f
* destLevel: 0.425f
* availableQuanta: 500 / 2 - 1 = 249
*
*/
/*
* Transmission data:
* 0 blocks: 775.0
* 1 block : 393.6
* 2 blocks: 260.8
* 3 blocks: 196.6
* 4 blocks: 157.8
* 5 blocks: 131.8
*/
int availableQuanta = ((int)((sourceLevel-destLevel)*host.getMaxEnergyStored())/2); //trunc leaves fractional power differences where they are
if (availableQuanta<=0) continue;
//StringBuilder debugString = new StringBuilder("RFTransfer: ");
//debugString.append(host.getEnergyStored());
//debugString.append("("); debugString.append((int)(sourceLevel*100)); debugString.append("%) -> ");
//debugString.append(consumer.getEnergyStored());
//debugString.append("("); debugString.append((int)(destLevel*100)); debugString.append("%) :");
//debugString.append(" req="); debugString.append(availableQuanta);
int transferred = consumer.receiveEnergy(availableQuanta, true);
if (transferred>0) transferred = host.extractEnergy(transferred, false);
//debugString.append(" rec="); debugString.append(transferred);
//System.out.println(debugString.toString());
consumer.receiveEnergy(transferred, false);
}
}
}
示例14: onBlockDestroyed
import net.minecraftforge.energy.IEnergyStorage; //导入方法依赖的package包/类
@Override
public boolean onBlockDestroyed(ItemStack is, World world, IBlockState state, BlockPos pos, EntityLivingBase playerIn)
{
float blockHardness = state.getBlockHardness(world, pos);
if(blockHardness <= 0)
return true;
ItemStack mostSpeedyTool = ItemStack.EMPTY;
float greatestStrength = 0.0F;
ItemStack component;
ItemStackHandlerTemporalExcavator inventory = getInventoryHandler(is);
if(inventory != null)
{
for(int i = 0; i < inventory.getSlots(); i++)
{
component = inventory.getStackInSlot(i);
if(!component.isEmpty())
{
if(component.getItem() instanceof ItemToolUpgradeTemporalInfuser)
{
if(((ItemToolUpgradeTemporalInfuser) component.getItem()).getActive(component, is))
{
HourglassHelper.consumeTimeMostPossible(HourglassHelper.getHourglasses((EntityPlayer) playerIn), HourglassHelper.getTimeToBreakBlock(world, pos, state, playerIn, is));
break;
}
}
if(component.getItem() instanceof ItemClockworkTool)
{
float strength = component.getItem().getStrVsBlock(component, state);
if(mostSpeedyTool == null || strength > greatestStrength)
{
mostSpeedyTool = component;
greatestStrength = strength;
}
}
}
}
}
if(greatestStrength > 1.0F && !mostSpeedyTool.isEmpty() && mostSpeedyTool.getItem() instanceof IClockwork)
{
IClockwork clockworkConstruct = (IClockwork) mostSpeedyTool.getItem();
IEnergyStorage energyStorage = is.getCapability(ENERGY_STORAGE_CAPABILITY, EnumFacing.DOWN);
if(energyStorage == null)
return true;
int currentEnergy = energyStorage.getEnergyStored();
if(currentEnergy <= 0)
return true;
int quality = clockworkConstruct.getQuality(mostSpeedyTool);
int speed = clockworkConstruct.getSpeed(mostSpeedyTool);
int energyCost = ClockworkHelper.getTensionCostFromStats(ConfigValues.BASE_TENSION_COST_PER_BLOCK_BREAK, quality, speed);
energyStorage.extractEnergy(energyCost, false);
}
return true;
}
示例15: insertItem
import net.minecraftforge.energy.IEnergyStorage; //导入方法依赖的package包/类
@Override
public ItemStack insertItem(int slot, ItemStack stack, boolean simulate)
{
int stackSize = stack.getCount();
int cost = getEffectivePowerUsageToInsert(stackSize);
IEnergyStorage energyBuffer = owner.getEnergyBuffer();
IItemHandler inventory = owner.getInventory();
if (inventory == null)
return ItemStack.EMPTY;
boolean powerFailure = false;
while (cost > energyBuffer.getEnergyStored() && stackSize > 0)
{
powerFailure = true;
stackSize--;
}
if (powerFailure)
owner.setLowOnPowerTemporary();
if (stackSize <= 0)
return stack;
ItemStack temp = stack.copy();
temp.setCount(stackSize);
ItemStack remaining = inventory.insertItem(slot, temp, simulate);
if (!simulate)
{
stackSize -= remaining.getCount();
int actualCost = getEffectivePowerUsageToInsert(stackSize);
energyBuffer.extractEnergy(actualCost, false);
owner.setDirty();
}
return remaining;
}