本文整理汇总了Java中net.minecraftforge.energy.IEnergyStorage.receiveEnergy方法的典型用法代码示例。如果您正苦于以下问题:Java IEnergyStorage.receiveEnergy方法的具体用法?Java IEnergyStorage.receiveEnergy怎么用?Java IEnergyStorage.receiveEnergy使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类net.minecraftforge.energy.IEnergyStorage
的用法示例。
在下文中一共展示了IEnergyStorage.receiveEnergy方法的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: onItemUse
import net.minecraftforge.energy.IEnergyStorage; //导入方法依赖的package包/类
@Nonnull
@Override
public EnumActionResult onItemUse(EntityPlayer player, World world, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
if(player.getHeldItem(hand).getCount() == 1){
TileEntity tile = world.getTileEntity(pos);
if(tile != null && tile.hasCapability(CapabilityEnergy.ENERGY, facing)){
if(!world.isRemote){
IEnergyStorage energy = tile.getCapability(CapabilityEnergy.ENERGY, facing);
if(energy != null && energy.canExtract()){
IEnergyStorage storage = player.getHeldItem(hand).getCapability(CapabilityEnergy.ENERGY, null);
if(storage != null && storage.canReceive()){
storage.receiveEnergy(energy.extractEnergy(storage.receiveEnergy(Integer.MAX_VALUE, true), false), false);
}
}
}
return EnumActionResult.SUCCESS;
}
}
return super.onItemUse(player, world, pos, hand, facing, hitX, hitY, hitZ);
}
示例3: transmitEnergy
import net.minecraftforge.energy.IEnergyStorage; //导入方法依赖的package包/类
public int transmitEnergy(BlockPos from, int energy, boolean simulate){
int oldEnergy = energy;
for(Map.Entry<BlockPos, EnumFacing> entry : this.receiver.entrySet()){
TileEntity tile = this.world.getTileEntity(entry.getKey());
if(tile != null && tile.hasCapability(CapabilityEnergy.ENERGY, entry.getValue())){
IEnergyStorage storage = tile.getCapability(CapabilityEnergy.ENERGY, entry.getValue());
if(storage != null && storage.canReceive()){
energy -= storage.receiveEnergy(energy, simulate);
}
}
if(energy <= 0){
return oldEnergy;
}
}
return oldEnergy - energy;
}
示例4: chargeItem
import net.minecraftforge.energy.IEnergyStorage; //导入方法依赖的package包/类
/**
*
* @param stack Inputstack
* @param energy Energy the item should receive
* @param simulate If true will only simulate
* @param tier IC2 charge tier
* @param ignoreChargeLimit IC2 ignore charge limit
* @return The amount of energy accepted
*/
public static int chargeItem(ItemStack stack, int energy, boolean simulate, int tier, boolean ignoreChargeLimit) {
if (stack.hasCapability(CapabilityEnergy.ENERGY, null)) {
IEnergyStorage cap = stack.getCapability(CapabilityEnergy.ENERGY, null);
return cap.receiveEnergy(energy, simulate);
} else if (Main.teslaLoaded && TeslaCompat.hasTesla(stack)) {
return TeslaCompat.chargeItem(stack, energy, simulate);
} else if (Main.redstonefluxLoaded && FluxCompat.hasFlux(stack)) {
return FluxCompat.chargeItem(stack, energy, simulate);
} else if (Main.immersiveLoaded && IECompat.hasIE(stack)) {
return IECompat.chargeItem(stack, energy, simulate);
} else if (Main.ic2Loaded && Config.allowIC2 && IC2Compat.hasIC2(stack)) {
return IC2Compat.chargeItem(stack, energy, simulate, tier, ignoreChargeLimit);
}
return 0;
}
示例5: 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);
}
}
}
}
示例6: sendPower
import net.minecraftforge.energy.IEnergyStorage; //导入方法依赖的package包/类
protected void sendPower() {
if (orientation == null) {
resetPowerDirection();
return;
}
feOutput = 0;
TileEntity tile = world.getTileEntity(new BlockPos(pos.getX() + orientation.getFrontOffsetX(),
pos.getY() + orientation.getFrontOffsetY(), pos.getZ() + orientation.getFrontOffsetZ()));
if (tile != null) {
IEnergyStorage energyStorage = tile.getCapability(CapabilityEnergy.ENERGY, orientation);
if (energyStorage != null) {
int maxFE = energyStorage.receiveEnergy(Math.min(1000, feLevel), true);
feOutput = maxFE;
feLevel -= energyStorage.receiveEnergy(maxFE, false);
} else {
orientation = null;
}
} else {
orientation = null;
}
}
示例7: 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
}
}
}
}
}
示例8: onBlockActivated
import net.minecraftforge.energy.IEnergyStorage; //导入方法依赖的package包/类
@Override
public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ)
{
if(!player.isSneaking())
{
ItemStack currentItem = player.getHeldItem(hand);
if(currentItem != null)
{
IEnergyStorage energyStorage = currentItem.getCapability(ENERGY, EnumFacing.DOWN);
if(energyStorage != null)
{
energyStorage.receiveEnergy(101 + world.rand.nextInt(100), false);
return true;
}
}
}
return false;
}
示例9: 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();
}
}
}
示例10: 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;
}
示例11: 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;
}
示例12: 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;
}
示例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() == 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;
}
示例14: 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;
}
示例15: update
import net.minecraftforge.energy.IEnergyStorage; //导入方法依赖的package包/类
@Override
public void update() {
super.update();
if (!world.isRemote) {
if (world.getTotalWorldTime() % 20 == 0) {
int efficiency = ConfigHandler.machineProperties.pneumaticDynamoEfficiency;
if (efficiency < 1) efficiency = 1;
airPerTick = (int) (40 * this.getSpeedUsageMultiplierFromUpgrades() * 100 / efficiency);
rfPerTick = (int) (40 * this.getSpeedUsageMultiplierFromUpgrades() * getEfficiency() / 100);
}
boolean newEnabled;
if (redstoneAllows() && getPressure() > PneumaticValues.MIN_PRESSURE_PNEUMATIC_DYNAMO && energy.getMaxEnergyStored() - energy.getEnergyStored() >= rfPerTick) {
this.addAir(-airPerTick);
heatExchanger.addHeat(airPerTick / 100D);
energy.receiveEnergy(rfPerTick, false);
newEnabled = true;
} else {
newEnabled = false;
}
if (world.getTotalWorldTime() % 20 == 0 && newEnabled != isEnabled) {
isEnabled = newEnabled;
sendDescriptionPacket();
}
TileEntity receiver = getTileCache()[getRotation().ordinal()].getTileEntity();
if (receiver != null && receiver.hasCapability(CapabilityEnergy.ENERGY, getRotation().getOpposite())) {
IEnergyStorage neighborStorage = receiver.getCapability(CapabilityEnergy.ENERGY, getRotation().getOpposite());
int extracted = energy.extractEnergy(rfPerTick * 2, true);
int energyPushed = neighborStorage.receiveEnergy(extracted, true);
if (energyPushed > 0) {
neighborStorage.receiveEnergy(energy.extractEnergy(energyPushed, false), false);
}
}
}
}