cofh.api.energy.IEnergyReceiver Java Examples

The following examples show how to use cofh.api.energy.IEnergyReceiver. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TileEntityPneumaticDynamo.java    From PneumaticCraft with GNU General Public License v3.0 5 votes vote down vote up
@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);
                }
            }
        }
    }
}
 
Example #2
Source File: DroneInteractRFExport.java    From PneumaticCraft with GNU General Public License v3.0 5 votes vote down vote up
@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;
    }
}
 
Example #3
Source File: TileEntityTurbinePowerTap.java    From BigReactors with MIT License 5 votes vote down vote up
/**
 * Check for a world connection, if we're assembled.
 * @param world
 * @param x
 * @param y
 * @param z
 */
protected void checkForConnections(IBlockAccess world, int x, int y, int z) {
	boolean wasConnected = (rfNetwork != null);
	ForgeDirection out = getOutwardsDir();
	if(out == ForgeDirection.UNKNOWN) {
		wasConnected = false;
		rfNetwork = null;
	}
	else {
		// See if our adjacent non-reactor coordinate has a TE
		rfNetwork = null;

		TileEntity te = world.getTileEntity(x + out.offsetX, y + out.offsetY, z + out.offsetZ);
		if(!(te instanceof TileEntityReactorPowerTap)) {
			// Skip power taps, as they implement these APIs and we don't want to shit energy back and forth
			if(te instanceof IEnergyReceiver) {
				IEnergyReceiver handler = (IEnergyReceiver)te;
				if(handler.canConnectEnergy(out.getOpposite())) {
					rfNetwork = handler;
				}
			}
		}
	}
	
	boolean isConnected = (rfNetwork != null);
	if(wasConnected != isConnected && worldObj.isRemote) {
		// Re-render on clients
           worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
	}
}
 
Example #4
Source File: TileEntityReactorPowerTap.java    From BigReactors with MIT License 5 votes vote down vote up
/**
 * Check for a world connection, if we're assembled.
 * @param world
 * @param x
 * @param y
 * @param z
 */
protected void checkForConnections(IBlockAccess world, int x, int y, int z) {
	boolean wasConnected = (rfNetwork != null);
	ForgeDirection out = getOutwardsDir();
	if(out == ForgeDirection.UNKNOWN) {
		wasConnected = false;
		rfNetwork = null;
	}
	else {
		// See if our adjacent non-reactor coordinate has a TE
		rfNetwork = null;

		TileEntity te = world.getTileEntity(x + out.offsetX, y + out.offsetY, z + out.offsetZ);
		if(!(te instanceof TileEntityReactorPowerTap)) {
			// Skip power taps, as they implement these APIs and we don't want to shit energy back and forth
			if(te instanceof IEnergyReceiver) {
				IEnergyReceiver handler = (IEnergyReceiver)te;
				if(handler.canConnectEnergy(out.getOpposite())) {
					rfNetwork = handler;
				}
			}
		}
		
	}
	
	boolean isConnected = (rfNetwork != null);
	if(wasConnected != isConnected) {
		worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
	}
}
 
Example #5
Source File: AdapterEnergyReceiver.java    From OpenPeripheral-Integration with MIT License 4 votes vote down vote up
@Override
public Class<?> getTargetClass() {
	return IEnergyReceiver.class;
}
 
Example #6
Source File: AdapterEnergyReceiver.java    From OpenPeripheral-Integration with MIT License 4 votes vote down vote up
@ScriptCallable(description = "Get the energy stored in the machine.", returnTypes = ReturnType.NUMBER)
public int getEnergyStored(IEnergyReceiver tileEntity,
		@Optionals @Arg(name = "side", description = "The direction you are interested in. (north, south, east, west, up or down)") ForgeDirection side) {
	return tileEntity.getEnergyStored(side != null? side : ForgeDirection.UNKNOWN);
}
 
Example #7
Source File: AdapterEnergyReceiver.java    From OpenPeripheral-Integration with MIT License 4 votes vote down vote up
@ScriptCallable(description = "Get the max energy stored in the machine.", returnTypes = ReturnType.NUMBER)
public int getMaxEnergyStored(IEnergyReceiver tileEntity,
		@Optionals @Arg(name = "side", description = "The direction you are interested in. (north, south, east, west, up or down)") ForgeDirection side) {
	return tileEntity.getMaxEnergyStored(side != null? side : ForgeDirection.UNKNOWN);
}