當前位置: 首頁>>代碼示例>>Java>>正文


Java IEnergyReceiver.receiveEnergy方法代碼示例

本文整理匯總了Java中cofh.api.energy.IEnergyReceiver.receiveEnergy方法的典型用法代碼示例。如果您正苦於以下問題:Java IEnergyReceiver.receiveEnergy方法的具體用法?Java IEnergyReceiver.receiveEnergy怎麽用?Java IEnergyReceiver.receiveEnergy使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在cofh.api.energy.IEnergyReceiver的用法示例。


在下文中一共展示了IEnergyReceiver.receiveEnergy方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: onTick

import cofh.api.energy.IEnergyReceiver; //導入方法依賴的package包/類
public void onTick(){
	super.onTick();
	
	int counter = 0;
	for(ForgeDirection direction : ForgeDirection.VALID_DIRECTIONS){
		TileEntity te = reactor.getWorldObj().getTileEntity(direction.offsetX + reactor.xCoord, direction.offsetY + reactor.yCoord, direction.offsetZ + reactor.zCoord);
		if(te instanceof IEnergyReceiver){
			IEnergyReceiver ier = (IEnergyReceiver) te;
			int attemptedAmount = storedEnergy / (ForgeDirection.VALID_DIRECTIONS.length - counter++); //I support fourth-dimensional rights
			if(ier.canConnectEnergy(direction.getOpposite())){
				int actualAmount = ier.receiveEnergy(direction.getOpposite(), attemptedAmount, false);
				storedEnergy -= actualAmount;
			}
		}	
	}
}
 
開發者ID:UnderMybrella,項目名稱:Minegate,代碼行數:17,代碼來源:RFReactorConverter.java

示例2: emit_do_do

import cofh.api.energy.IEnergyReceiver; //導入方法依賴的package包/類
private static double emit_do_do(IEnergyWrapper from, TileEntity tileEntity, ForgeDirection side, double currentSending, boolean tryAgain)
{
	double sent = 0;

	if(tileEntity instanceof IStrictEnergyAcceptor)
	{
		IStrictEnergyAcceptor acceptor = (IStrictEnergyAcceptor)tileEntity;

		if(acceptor.canReceiveEnergy(side.getOpposite()))
		{
			sent += acceptor.transferEnergyToAcceptor(side.getOpposite(), currentSending);
		}
	}
	else if(MekanismUtils.useRF() && tileEntity instanceof IEnergyReceiver)
	{
		IEnergyReceiver handler = (IEnergyReceiver)tileEntity;

		if(handler.canConnectEnergy(side.getOpposite()))
		{
			int used = handler.receiveEnergy(side.getOpposite(), (int)Math.round(currentSending*general.TO_TE), false);
			sent += used*general.FROM_TE;
		}
	}
	else if(MekanismUtils.useIC2() && tileEntity instanceof IEnergySink)
	{
		if(((IEnergySink)tileEntity).acceptsEnergyFrom((TileEntity)from, side.getOpposite()))
		{
			double toSend = Math.min(currentSending, EnergyNet.instance.getPowerFromTier(((IEnergySink)tileEntity).getSinkTier())*general.FROM_IC2);
			toSend = Math.min(toSend, ((IEnergySink)tileEntity).getDemandedEnergy()*general.FROM_IC2);
			sent += (toSend - (((IEnergySink)tileEntity).injectEnergy(side.getOpposite(), toSend*general.TO_IC2, 0)*general.FROM_IC2));
		}
	}

	return sent;
}
 
開發者ID:Microsoft,項目名稱:vsminecraft,代碼行數:36,代碼來源:CableUtils.java

示例3: updateEntity

import cofh.api.energy.IEnergyReceiver; //導入方法依賴的package包/類
@Override
public void updateEntity(){
    super.updateEntity();

    if(!worldObj.isRemote) {
        if(worldObj.getTotalWorldTime() % 20 == 0) {
            int efficiency = Config.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(ForgeDirection.UNKNOWN) > PneumaticValues.MIN_PRESSURE_PNEUMATIC_DYNAMO && getMaxEnergyStored(ForgeDirection.UNKNOWN) - getEnergyStored(ForgeDirection.UNKNOWN) >= rfPerTick) {
            this.addAir(-airPerTick, ForgeDirection.UNKNOWN);
            heatExchanger.addHeat(airPerTick / 100D);
            energy.receiveEnergy(rfPerTick, false);
            newEnabled = true;
        } else {
            newEnabled = false;
        }
        if(worldObj.getTotalWorldTime() % 20 == 0 && newEnabled != isEnabled) {
            isEnabled = newEnabled;
            sendDescriptionPacket();
        }

        TileEntity receiver = getTileCache()[getRotation().getOpposite().ordinal()].getTileEntity();
        if(receiver instanceof IEnergyReceiver) {
            IEnergyReceiver recv = (IEnergyReceiver)receiver;
            if(recv.canConnectEnergy(getRotation())) {
                int extracted = energy.extractEnergy(rfPerTick * 2, true);
                int energyPushed = recv.receiveEnergy(getRotation(), extracted, true);

                if(energyPushed > 0) {
                    recv.receiveEnergy(getRotation(), energy.extractEnergy(energyPushed, false), false);
                }
            }
        }
    }
}
 
開發者ID:MineMaarten,項目名稱:PneumaticCraft,代碼行數:41,代碼來源:TileEntityPneumaticDynamo.java

示例4: doInteract

import cofh.api.energy.IEnergyReceiver; //導入方法依賴的package包/類
@Override
public boolean doInteract(ChunkPosition pos, IDrone drone, IBlockInteractHandler interactHandler, boolean simulate){
    IEnergyStorage droneEnergy = CoFHCore.getEnergyStorage(drone);
    if(droneEnergy.getEnergyStored() == 0) {
        interactHandler.abort();
        return false;
    } else {
        TileEntity te = drone.getWorld().getTileEntity(pos.chunkPosX, pos.chunkPosY, pos.chunkPosZ);
        if(te instanceof IEnergyReceiver) {
            IEnergyReceiver receiver = (IEnergyReceiver)te;
            for(ForgeDirection d : ForgeDirection.VALID_DIRECTIONS) {
                if(interactHandler.getSides()[d.ordinal()]) {
                    int transferedEnergy = droneEnergy.extractEnergy(receiver.receiveEnergy(d, interactHandler.useCount() ? interactHandler.getRemainingCount() : Integer.MAX_VALUE, true), true);
                    if(transferedEnergy > 0) {
                        if(!simulate) {
                            interactHandler.decreaseCount(transferedEnergy);
                            droneEnergy.extractEnergy(transferedEnergy, false);
                            receiver.receiveEnergy(d, transferedEnergy, false);
                        }
                        return true;
                    }
                }
            }
        }
        return false;
    }
}
 
開發者ID:MineMaarten,項目名稱:PneumaticCraft,代碼行數:28,代碼來源:DroneInteractRFExport.java

示例5: loadCart

import cofh.api.energy.IEnergyReceiver; //導入方法依賴的package包/類
public void loadCart(EnumFacing facing, IEnergyReceiver receiver)
{
	int amountToLoad = this.energyStorage.extractEnergy(this.energyStorage.getMaxExtract(), true);
	int amountLoadedIntoCart = receiver.receiveEnergy(facing.getOpposite(), amountToLoad, false);
	this.energyStorage.extractEnergy(amountLoadedIntoCart, false);
}
 
開發者ID:BrassGoggledCoders,項目名稱:MoarCarts,代碼行數:7,代碼來源:TileRFLoader.java

示例6: transferEnergy

import cofh.api.energy.IEnergyReceiver; //導入方法依賴的package包/類
@LuaFunction
public int transferEnergy(String source, ForgeDirection sourceSide, String target, ForgeDirection targetSide, int amount) throws Exception {
	if (!posByName.containsKey(source)) {
		throw new Exception("Invalid source '" + source + "'. Not specified, use setName(x,y,z,name) first.");
	}

	if (!posByName.containsKey(target)) {
		throw new Exception("Invalid target '" + target + "'. Not specified, use setName(x,y,z,name) first.");
	}

	if (amount <= 0) {
		throw new Exception("At least 1 RF needs to be transferred.");
	}

	RelativePos sourcePos = posByName.get(source);
	TileEntity sourceTile = worldObj.getTileEntity(xCoord + sourcePos.x, yCoord + sourcePos.y, zCoord + sourcePos.z);
	if (!(sourceTile instanceof IEnergyProvider)) {
		throw new Exception("Source tile is no energy provider.");
	}

	RelativePos targetPos = posByName.get(target);
	TileEntity targetTile = worldObj.getTileEntity(xCoord + targetPos.x, yCoord + targetPos.y, zCoord + targetPos.z);
	if (!(targetTile instanceof IEnergyReceiver)) {
		throw new Exception("Target tile is no energy receiver.");
	}

	IEnergyProvider provider = (IEnergyProvider) sourceTile;
	IEnergyReceiver receiver = (IEnergyReceiver) targetTile;

	int extractedSim = provider.extractEnergy(sourceSide, amount, true);
	if (extractedSim > 0) {
		int receivedSim = receiver.receiveEnergy(targetSide, extractedSim, true);
		if (receivedSim > 0) {
			int extracted = provider.extractEnergy(sourceSide, receivedSim, false);
			int received = receiver.receiveEnergy(targetSide, extracted, false);

			sourceTile.markDirty();
			targetTile.markDirty();

			return received;
		}
	}

	return 0;
}
 
開發者ID:thraaawn,項目名稱:CCFactoryManager,代碼行數:46,代碼來源:TileEntityFactoryController.java

示例7: updateEntity

import cofh.api.energy.IEnergyReceiver; //導入方法依賴的package包/類
@Override
public void updateEntity() {
			
	if (!worldObj.isRemote) {
				
		if (outputFE) {

			overclock = getCurrentRFScaled(40);
				
			for (int i = 0; i <= overclock; i++) {
								
				if (EnergyUtil.canAddEnergy(this, FERatio) && storage.getEnergyStored() >= RFRatio) {

					EnergyUtil.addEnergy(this, FERatio);
					storage.extractEnergy(RFRatio, false);
				}
				
				else break;
			}
		}

		else {
							
			overclock = getCurrentEnergyScaled(40);
							
			for (int i = 0; i <= overclock; i++) {
				
				if (EnergyUtil.canSubtractEnergy(this, FERatio) && (storage.getMaxEnergyStored() - storage.getEnergyStored()) >= RFRatio) {

					EnergyUtil.subtractEnergy(this, FERatio);
					storage.receiveEnergy(RFRatio, false);
				}
				
				else break;
			}			
			
			for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) {
				
				Location loc = new Location(worldObj, xCoord, yCoord, zCoord).add(dir);
				TileEntity entity = loc.getTileEntity();
				
				if (entity != null && entity instanceof IEnergyReceiver) {
					
					IEnergyReceiver receiver = (IEnergyReceiver) entity;
					
					int maxExtract = storage.getMaxExtract(); //Gets the maximum amount of energy that can be extracted from this tile in one tick.
					int maxAvailable = storage.extractEnergy(maxExtract, true); //Simulates removing "maxExtract" to find out how much energy is actually available.
					int energyTransferred = receiver.receiveEnergy(dir.getOpposite(), maxAvailable, false); //Sends "maxAvailable" to the target tile and records how much energy was accepted. 

					storage.extractEnergy(energyTransferred, false);//Extract the energy transferred from the internal storage.
				}
			}
		}
	}
}
 
開發者ID:TeamMonumental,項目名稱:FusionWarfare,代碼行數:56,代碼來源:TileEntityRFConverter.java


注:本文中的cofh.api.energy.IEnergyReceiver.receiveEnergy方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。